Solved WitherSkull not invisible? (1.8)

Discussion in 'Plugin Development' started by KarimAKL, Jun 15, 2018.

Thread Status:
Not open for further replies.
  1. Offline

    KarimAKL

    Hey, i want to create a floating barrier on a invisible WitherSkull but the witherskull doesn't seem to go invisible when i do this:
    Code:Java
    1.  
    2. WitherSkull skull = (WitherSkull) op.getWorld().spawn(op.getLocation().add(0, +1, 0), WitherSkull.class);
    3. skull.setDirection(new Vector(0, 0, 0));
    4. skull.setVelocity(new Vector(0, 0, 0));
    5. Item barrier = (Item) op.getWorld().dropItem(op.getLocation().add(0, +2, 0), new ItemStack(Material.BARRIER));
    6. barrier.setPickupDelay(Integer.MAX_VALUE);
    7. skull.setPassenger(barrier);
    8. new BukkitRunnable() {
    9. @Override
    10. public void run() {
    11. if (plugin.getAfk(op.getUniqueId()) < 60*5) {
    12. skull.remove();
    13. barrier.remove();
    14. cancel();
    15. }
    16. }
    17. }.runTaskTimer(plugin, 0, 20);
    18.  

    And i can't find any other way to do this, what is the reason it doesn't go invisible?
    Here is the full class if needed:
    Code:Java
    1.  
    2. public class RepeatRun {
    3.  
    4. @SuppressWarnings("unused")
    5. private Main plugin;
    6.  
    7. public RepeatRun(Main plugin) {
    8. this.plugin = plugin;
    9. new BukkitRunnable() {
    10. @Override
    11. public void run() {
    12. if (!plugin.getServer().getOnlinePlayers().isEmpty()) {
    13. for (Player op : Bukkit.getOnlinePlayers()) {
    14. if (op.isOnline()) {
    15. if (plugin.existAfk(op.getUniqueId())) {
    16. if (plugin.getAfk(op.getUniqueId()) >= 60*5) {
    17. WitherSkull skull = (WitherSkull) op.getWorld().spawn(op.getLocation().add(0, +1, 0), WitherSkull.class);
    18. skull.setDirection(new Vector(0, 0, 0));
    19. skull.setVelocity(new Vector(0, 0, 0));
    20. Item barrier = (Item) op.getWorld().dropItem(op.getLocation().add(0, +2, 0), new ItemStack(Material.BARRIER));
    21. barrier.setPickupDelay(Integer.MAX_VALUE);
    22. skull.setPassenger(barrier);
    23. new BukkitRunnable() {
    24. @Override
    25. public void run() {
    26. if (plugin.getAfk(op.getUniqueId()) < 60*5) {
    27. skull.remove();
    28. barrier.remove();
    29. cancel();
    30. }
    31. }
    32. }.runTaskTimer(plugin, 0, 20);
    33. } else {
    34. plugin.setAfk(op.getUniqueId(), plugin.getAfk(op.getUniqueId())+1);
    35. }
    36. } else {
    37. plugin.setAfk(op.getUniqueId(), 1);
    38. }
    39. }
    40. }
    41. }
    42. }
    43. }.runTaskTimer(plugin, 0, 20);
    44. }
    45. }
    46.  

    EDIT: Here is a screenshot of what it looks like:
    2018-06-15_14.23.12.png As you can see, it's not invisible. :p
     
    Last edited: Jun 15, 2018
  2. Online

    timtower Ninja on the waves Moderator

    @KarimAKL
    Code:
      skull.setPassenger(barrier);
      new BukkitRunnable() {
      @Override
      public void run() {
      if (plugin.getAfk(op.getUniqueId()) < 60*5) {
      skull.remove();
      barrier.remove();
      cancel();
      }
      }
      }.runTaskTimer(plugin, 0, 20);
    Just use runTask there, no need to cancel, no need to run it as a timer.
     
  3. Offline

    KarimAKL

    @timtower ".runTask(plugin);"? If that's what you mean then how would i remove the skull and barrier? (It doesn't remove the skull and barrier when the getAfk is lower than 60*5 as it should)
    Anyway, this works for now and i'm probably gonna remove that and make it so it'll remove it in a PlayerMoveEvent or something like that. (Just need to find out how exactly. :p)
     
  4. Online

    timtower Ninja on the waves Moderator

    @KarimAKL Missed that part about the timer thingy.
     
  5. Offline

    KarimAKL

    @timtower Oh, okay. :p

    EDIT: Just added a picture of how it looks. (not invisible skull)
     
  6. Offline

    KarimAKL

    Bump, does anyone know why it does this and how i can change it?
     
  7. Offline

    CommonSenze

    @KarimAKL
    Hi again, I remember you from last time :D

    Have you made sure that its even being called?
     
  8. Offline

    KarimAKL

    @CommonSenze Made sure that what's being called? Do you mean that it might not go through all the code? Btw when you say
    when do you mean by last time?
     
  9. Offline

    CommonSenze

    @KarimAKL
    I remember that name from the last time I came on Bukkit Forums. I don't remember when exactly.
    I just looked back at your code and you didn't do anything to make the skull invisible.
    Code:java
    1.  
    2. WitherSkull skull = (WitherSkull) op.getWorld().spawn(op.getLocation().add(0, +1, 0), WitherSkull.class);
    3. skull.setDirection(new [URL='http://www.google.com/search?hl=en&q=allinurl%3Avector+java.sun.com&btnI=I%27m%20Feeling%20Lucky']Vector[/URL](0, 0, 0));
    4. skull.setVelocity(new [URL='http://www.google.com/search?hl=en&q=allinurl%3Avector+java.sun.com&btnI=I%27m%20Feeling%20Lucky']Vector[/URL](0, 0, 0));
    5. Item barrier = (Item) op.getWorld().dropItem(op.getLocation().add(0, +2, 0), new ItemStack(Material.BARRIER));
    6. barrier.setPickupDelay([URL='http://www.google.com/search?hl=en&q=allinurl%3Ainteger+java.sun.com&btnI=I%27m%20Feeling%20Lucky']Integer[/URL].MAX_VALUE);
    7. skull.setPassenger(barrier);
    8. new BukkitRunnable() {
    9. @Override
    10. public void run() {
    11. if (plugin.getAfk(op.getUniqueId()) < 60*5) {
    12. skull.remove();
    13. barrier.remove();
    14. cancel();
    15. }
    16. }

    If I'm correct this is the part where the player is afk. What you can do is just place a barrier block instead of a skull so it can already be invisible and not have to worry about how to make it invisible.
     
    MightyOne likes this.
  10. Offline

    KarimAKL

    @CommonSenze
    1. Oh, okay. :p
    2. I haven't found any methods to make it invisible and i read that setting the direction and velocity should make it invis aswell, doesn't seem to work tho. :/
    3. If i place a barrier block it would block players from walking through. :7
     
  11. Offline

    CommonSenze

    @KarimAKL
    I don't think there is a real way to make it invisible then if it's not working.
     
  12. Offline

    KarimAKL

    @CommonSenze What about packets? Would it be possible with them?
     
  13. Offline

    CommonSenze

  14. Offline

    KarimAKL

    @CommonSenze I see, do you have any idea how people do it then? Do they use armor stands? If i use armor stands will the item go around in circles like it does on the ground?
     
  15. Offline

    CommonSenze

    @KarimAKL Thats the research you need to find out. I never needed this type of problem before. If you would like me to personally help you with it, however, I can assist on discord if you would like to PM it to me.
     
  16. Offline

    KarimAKL

    @CommonSenze I see, i just thought i'd ask you if you knew, anyway thanks. :)
    I'll mark this as solved now because it doesn't really have anything to do with the witherskulls anymore. (i guess) :p
    EDIT: For anyone wanting to know i found out that armor stands work very well for this. :)
     
    Last edited: Jun 20, 2018
Thread Status:
Not open for further replies.

Share This Page