Hello. I have my own system of murders on the server. When the damage is greater than the health of the player, it teleports to spawn. The problem is that when the player teleports, PlayerTeleportEvent is triggered. I have a question. Can I cancel it at the right time? I say to those who do not understand, teleportation create particles, I need to cancel them if the player teleports to spawn. After that he should work, as before(PlayerTeleportEvent). Sorry for my english, he's not the best.
@ewrs There is no good way to do this. You can try canceling and undoing the cancel the event for the priorities above and below the one the other plugin uses, but that also risks other plugins breaking if they also listen for that event.
@ewrs Basically, you should not be doing this unless you are okay with potentially breaking other plugins. If you are okay with that, using different event priorities, cancel the event in a higher priority so that other plugin does not run its code, while also un-canceling it in a lower priority so the player will teleport.
I need to cancel not a given event, but a close one. I.e TeleportEvent { ... } EntityDamageByEntityEvent { Cancel TeleportEvent p.teleport (loc); }
@ewrs Alright, then create a List for players where the telepotation should be canceled, add the player to the list when you need, and only cancel the event if the player is in the List.
@ewrs What is this other 'death' plugin? If it is the plugin you are working on, the list only needs to be for your plugin.
1 plugin is responsible for the partys at the output, input and teleportation 2 plugin for death (teleport to spawn and playing effects)
Kinda like this. All of the code would go in your 'death' plugin. Code: public class DeathPlugin extends JavaPlugin { private ArrayList<Player> deadPlayers; @Override public void onEnable() { this.deadPlayers = new ArrayList(); this.loadListeners(); } private void loadListeners() { PluginManager pluginManager = this.getServer().getPluginManager(); pluginManager.registerEvents(new TeleportE (this), this); pluginManager.registerEvents(new DeathE(this), this); } public void addDeadPlayer(Player user) { this.deadPlayers.add(user); } public void removeDeadPlayer(Player user) { this.deadPlayers.remove(user); } public ArrayList<Player> getDeadPlayers() { return this.deadPlayers; } } Code: public class DeathE implements Listener { private DeathPlugin plugin; public DeathE(DeathPlugin plugin) { this.plugin = plugin; } @EventHandler public void onDeathE(EntityDamageByEntityEvent e) { Player user = e.getEntity(); if ((user.getHealth() - e.getDamage()) <= 0) { this.plugin.addDeadPlayer(user); user.teleport(spawnLocation); } } } Code: public class TeleportE implements Listener { private DeathPlugin plugin; public TeleportE (DeathPlugin plugin) { this.plugin = plugin; } @EventHandler(priority = EventPriority.HIGHEST) public void onTeleportE(PlayerTeleportEvent e) { Player user = e.getPlayer(); if (!this.plugin.getDeadPlayers().contains(user)) return; e.setCancelled(true); this.plugin.removeDeadPlayer(user); } } Sent from my SM-G920P using Tapatalk