Glowing for one Person

Discussion in 'Plugin Development' started by TheLastDeamon, Mar 5, 2017.

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

    TheLastDeamon

    @AlvinB
    I made it with an ArrayList But Thank you SOOOO much!

    How would you do a SET ?
     
    Last edited: Mar 7, 2017
  2. @TheLastDeamon
    A Set is a bit more appropriate (since duplicates and order aren't important in this case), but it doesn't really make any difference.

    Anyways, glad that you solved it! Would you mind marking this thread as solved?
     
  3. Offline

    TheLastDeamon

    After I tried :D

    @AlvinB

    Only one porblem:
    The Players glow for themselves, too
    Probably also for other Players but I'm not sure about that. Yep for other players too!
    Code:java
    1.  
    2. ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(this, PacketType.Play.Server.ENTITY_METADATA, PacketType.Play.Server.NAMED_ENTITY_SPAWN) {
    3. @Override
    4. public void onPacketSending(PacketEvent event) {
    5.  
    6. if (seeGlow.contains(event.getPlayer()))
    7. {
    8. for (Player player : Bukkit.getOnlinePlayers())
    9. {
    10. if (/*has a player with*/player.getEntityId() == event.getPacket().getIntegers().read(0)) {
    11. if (event.getPacketType() == PacketType.Play.Server.ENTITY_METADATA) {
    12. List<WrappedWatchableObject> watchableObjectList = event.getPacket().getWatchableCollectionModifier().read(0);
    13. for (WrappedWatchableObject metadata : watchableObjectList)
    14. {
    15. if (metadata.getIndex() == 0) {
    16. byte b = (byte) metadata.getValue();
    17. b |= 0b01000000;
    18. metadata.setValue(b);
    19. }
    20. }
    21. } else {
    22. WrappedDataWatcher watcher = event.getPacket().getDataWatcherModifier().read(0);
    23. if (watcher.hasIndex(0)) {
    24. byte b = watcher.getByte(0);
    25. b |= 0b01000000;
    26. watcher.setObject(0, b);
    27. }
    28. }
    29. }
    30. }
    31. }
    32. }
    33. });


    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent e)
    3. {
    4. if(e.getPlayer().getInventory().getItemInMainHand().getType() == Material.SPECTRAL_ARROW)
    5. if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK)
    6. {
    7. e.getPlayer().sendMessage("Click accepted!");
    8. seeGlow.add(e.getPlayer());
    9. for (Player p : Bukkit.getOnlinePlayers())
    10. {
    11. if(p != e.getPlayer())
    12. {
    13. e.getPlayer().hidePlayer(p);
    14. e.getPlayer().showPlayer(p);
    15. }
    16. }
    17. }
    18. }
     
    Last edited: Mar 8, 2017
  4. @TheLastDeamon
    Just add a check to make sure that event.getPlayer() doesn't equal player in the for loop.
     
  5. Offline

    TheLastDeamon

    @AlvinB
    What I ment was that the players, who are supposed to glow, see themselves and everyone else glow!
    The one who clicked doesn't glow!
    and do you mean like this:
    Code:java
    1. ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(this, PacketType.Play.Server.ENTITY_METADATA, PacketType.Play.Server.NAMED_ENTITY_SPAWN) {
    2. @Override
    3. public void onPacketSending(PacketEvent event) {
    4.  
    5. if (seeGlow.contains(event.getPlayer()))
    6. {
    7. for (Player player : Bukkit.getOnlinePlayers())
    8. {
    9. if(player != event.getPlayer())
    10. if (/*has a player with*/player.getEntityId() == event.getPacket().getIntegers().read(0)) {
    11. if (event.getPacketType() == PacketType.Play.Server.ENTITY_METADATA) {
    12. List<WrappedWatchableObject> watchableObjectList = event.getPacket().getWatchableCollectionModifier().read(0);
    13. for (WrappedWatchableObject metadata : watchableObjectList)
    14. {
    15. if (metadata.getIndex() == 0) {
    16. byte b = (byte) metadata.getValue();
    17. b |= 0b01000000;
    18. metadata.setValue(b);
    19. }
    20. }
    21. } else {
    22. WrappedDataWatcher watcher = event.getPacket().getDataWatcherModifier().read(0);
    23. if (watcher.hasIndex(0)) {
    24. byte b = watcher.getByte(0);
    25. b |= 0b01000000;
    26. watcher.setObject(0, b);
    27. }
    28. }
    29. }
    30. }
    31. }
    32. }
    33. });
     
  6. Offline

    TheLastDeamon

  7. Offline

    TheLastDeamon

Thread Status:
Not open for further replies.

Share This Page