diff --git a/api/src/main/java/com/alttd/essentia/events/EssentiaEvent.java b/api/src/main/java/com/alttd/essentia/events/EssentiaEvent.java new file mode 100644 index 0000000..1187c8f --- /dev/null +++ b/api/src/main/java/com/alttd/essentia/events/EssentiaEvent.java @@ -0,0 +1,20 @@ +package com.alttd.essentia.events; + +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; + +public abstract class EssentiaEvent extends Event implements Cancellable { + + private boolean cancelled; + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean b) { + this.cancelled = true; + } + +} diff --git a/api/src/main/java/com/alttd/essentia/events/PlayerRemoveHomeEvent.java b/api/src/main/java/com/alttd/essentia/events/PlayerRemoveHomeEvent.java new file mode 100644 index 0000000..5f6d3a2 --- /dev/null +++ b/api/src/main/java/com/alttd/essentia/events/PlayerRemoveHomeEvent.java @@ -0,0 +1,39 @@ +package com.alttd.essentia.events; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +public class PlayerRemoveHomeEvent extends EssentiaEvent { + + private static final HandlerList handlerList = new HandlerList(); + + private final Player player; + private final String homeName; + + public PlayerRemoveHomeEvent(Player player, String homeName) { + this.player = player; + this.homeName = homeName; + } + + public Player getPlayer() { + return player; + } + + public String getHomeName() { + return homeName; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlerList; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlerList; + } + +} diff --git a/api/src/main/java/com/alttd/essentia/events/PlayerSetHomeEvent.java b/api/src/main/java/com/alttd/essentia/events/PlayerSetHomeEvent.java new file mode 100644 index 0000000..785052f --- /dev/null +++ b/api/src/main/java/com/alttd/essentia/events/PlayerSetHomeEvent.java @@ -0,0 +1,45 @@ +package com.alttd.essentia.events; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +public class PlayerSetHomeEvent extends EssentiaEvent { + + private static final HandlerList handlerList = new HandlerList(); + + private final Player player; + private final Location location; + private final String homeName; + + public PlayerSetHomeEvent(Player player, Location location, String homeName) { + this.player = player; + this.location = location; + this.homeName = homeName; + } + + public Player getPlayer() { + return player; + } + + public Location getLocation() { + return location; + } + + public String getHomeName() { + return homeName; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlerList; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlerList; + } + +} diff --git a/api/src/main/java/com/alttd/essentia/events/PlayerTeleportBackEvent.java b/api/src/main/java/com/alttd/essentia/events/PlayerTeleportBackEvent.java new file mode 100644 index 0000000..400d1de --- /dev/null +++ b/api/src/main/java/com/alttd/essentia/events/PlayerTeleportBackEvent.java @@ -0,0 +1,39 @@ +package com.alttd.essentia.events; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +public class PlayerTeleportBackEvent extends EssentiaEvent { + + private static final HandlerList handlerList = new HandlerList(); + + private final Player player; + private final Location location; + + public PlayerTeleportBackEvent(Player player, Location location) { + this.player = player; + this.location = location; + } + + public Player getPlayer() { + return player; + } + + public Location getLocation() { + return location; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlerList; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlerList; + } + +} diff --git a/api/src/main/java/com/alttd/essentia/events/PlayerTeleportHomeEvent.java b/api/src/main/java/com/alttd/essentia/events/PlayerTeleportHomeEvent.java new file mode 100644 index 0000000..c8c4bc7 --- /dev/null +++ b/api/src/main/java/com/alttd/essentia/events/PlayerTeleportHomeEvent.java @@ -0,0 +1,45 @@ +package com.alttd.essentia.events; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +public class PlayerTeleportHomeEvent extends EssentiaEvent { + + private static final HandlerList handlerList = new HandlerList(); + + private final Player player; + private final Location location; + private final String homeName; + + public PlayerTeleportHomeEvent(Player player, Location location, String homeName) { + this.player = player; + this.location = location; + this.homeName = homeName; + } + + public Player getPlayer() { + return player; + } + + public Location getLocation() { + return location; + } + + public String getHomeName() { + return homeName; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlerList; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlerList; + } + +} diff --git a/api/src/main/java/com/alttd/essentia/events/PlayerTeleportSpawnEvent.java b/api/src/main/java/com/alttd/essentia/events/PlayerTeleportSpawnEvent.java new file mode 100644 index 0000000..9183e29 --- /dev/null +++ b/api/src/main/java/com/alttd/essentia/events/PlayerTeleportSpawnEvent.java @@ -0,0 +1,39 @@ +package com.alttd.essentia.events; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +public class PlayerTeleportSpawnEvent extends EssentiaEvent { + + private static final HandlerList handlerList = new HandlerList(); + + private final Player player; + private final Location location; + + public PlayerTeleportSpawnEvent(Player player, Location location) { + this.player = player; + this.location = location; + } + + public Player getPlayer() { + return player; + } + + public Location getLocation() { + return location; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlerList; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlerList; + } + +} diff --git a/plugin/src/main/java/com/alttd/essentia/commands/player/BackCommand.java b/plugin/src/main/java/com/alttd/essentia/commands/player/BackCommand.java index 19d4c1c..0883644 100644 --- a/plugin/src/main/java/com/alttd/essentia/commands/player/BackCommand.java +++ b/plugin/src/main/java/com/alttd/essentia/commands/player/BackCommand.java @@ -4,6 +4,8 @@ import com.alttd.essentia.EssentiaPlugin; import com.alttd.essentia.commands.PlayerSubCommand; import com.alttd.essentia.configuration.Config; import com.alttd.essentia.configuration.PlayerConfig; +import com.alttd.essentia.events.EssentiaEvent; +import com.alttd.essentia.events.PlayerTeleportBackEvent; import com.alttd.essentia.tasks.TeleportSounds; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -22,7 +24,10 @@ public class BackCommand extends PlayerSubCommand { player.sendRichMessage(Config.NO_BACK_LOCATION); return true; } - + EssentiaEvent event = new PlayerTeleportBackEvent(player, back); + if (!event.callEvent()) { + return true; + } new TeleportSounds(back, player.getLocation()) .runTaskLater(plugin, 1); diff --git a/plugin/src/main/java/com/alttd/essentia/commands/player/DeathBackCommand.java b/plugin/src/main/java/com/alttd/essentia/commands/player/DeathBackCommand.java index 460ec25..6d50d6b 100644 --- a/plugin/src/main/java/com/alttd/essentia/commands/player/DeathBackCommand.java +++ b/plugin/src/main/java/com/alttd/essentia/commands/player/DeathBackCommand.java @@ -4,6 +4,8 @@ import com.alttd.essentia.EssentiaPlugin; import com.alttd.essentia.commands.PlayerSubCommand; import com.alttd.essentia.configuration.Config; import com.alttd.essentia.configuration.PlayerConfig; +import com.alttd.essentia.events.EssentiaEvent; +import com.alttd.essentia.events.PlayerTeleportBackEvent; import com.alttd.essentia.tasks.TeleportSounds; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -22,7 +24,10 @@ public class DeathBackCommand extends PlayerSubCommand { player.sendRichMessage(Config.NO_DEATH_LOCATION); return true; } - + EssentiaEvent event = new PlayerTeleportBackEvent(player, back); + if (!event.callEvent()) { + return true; + } new TeleportSounds(back, player.getLocation()) .runTaskLater(plugin, 1); diff --git a/plugin/src/main/java/com/alttd/essentia/commands/player/DelHomeCommand.java b/plugin/src/main/java/com/alttd/essentia/commands/player/DelHomeCommand.java index 38bf049..6760fc9 100644 --- a/plugin/src/main/java/com/alttd/essentia/commands/player/DelHomeCommand.java +++ b/plugin/src/main/java/com/alttd/essentia/commands/player/DelHomeCommand.java @@ -4,6 +4,9 @@ import com.alttd.essentia.EssentiaPlugin; import com.alttd.essentia.commands.PlayerSubCommand; import com.alttd.essentia.configuration.Config; import com.alttd.essentia.configuration.PlayerConfig; +import com.alttd.essentia.events.EssentiaEvent; +import com.alttd.essentia.events.PlayerRemoveHomeEvent; +import com.alttd.essentia.events.PlayerTeleportBackEvent; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.entity.Player; @@ -27,7 +30,10 @@ public class DelHomeCommand extends PlayerSubCommand { player.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.unparsed("home", home)); return true; } - + EssentiaEvent event = new PlayerRemoveHomeEvent(player, home); + if (!event.callEvent()) { + return true; + } playerConfig.setHome(home, null); player.sendRichMessage(Config.HOME_DELETED, Placeholder.unparsed("home", home)); return true; diff --git a/plugin/src/main/java/com/alttd/essentia/commands/player/HomeCommand.java b/plugin/src/main/java/com/alttd/essentia/commands/player/HomeCommand.java index 7dac302..9220768 100644 --- a/plugin/src/main/java/com/alttd/essentia/commands/player/HomeCommand.java +++ b/plugin/src/main/java/com/alttd/essentia/commands/player/HomeCommand.java @@ -4,6 +4,9 @@ import com.alttd.essentia.EssentiaPlugin; import com.alttd.essentia.commands.PlayerSubCommand; import com.alttd.essentia.configuration.Config; import com.alttd.essentia.configuration.PlayerConfig; +import com.alttd.essentia.events.EssentiaEvent; +import com.alttd.essentia.events.PlayerTeleportBackEvent; +import com.alttd.essentia.events.PlayerTeleportHomeEvent; import com.alttd.essentia.tasks.TeleportSounds; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.Location; @@ -57,7 +60,10 @@ public class HomeCommand extends PlayerSubCommand { player.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.parsed("home", home)); return true; } - + EssentiaEvent event = new PlayerTeleportHomeEvent(player, homeLoc, home); + if (!event.callEvent()) { + return true; + } new TeleportSounds(homeLoc, player.getLocation()) .runTaskLater(plugin, 1); diff --git a/plugin/src/main/java/com/alttd/essentia/commands/player/SetHomeCommand.java b/plugin/src/main/java/com/alttd/essentia/commands/player/SetHomeCommand.java index 840b32a..c232f04 100644 --- a/plugin/src/main/java/com/alttd/essentia/commands/player/SetHomeCommand.java +++ b/plugin/src/main/java/com/alttd/essentia/commands/player/SetHomeCommand.java @@ -4,7 +4,11 @@ import com.alttd.essentia.EssentiaPlugin; import com.alttd.essentia.commands.PlayerSubCommand; import com.alttd.essentia.configuration.Config; import com.alttd.essentia.configuration.PlayerConfig; +import com.alttd.essentia.events.EssentiaEvent; +import com.alttd.essentia.events.PlayerSetHomeEvent; +import com.alttd.essentia.events.PlayerTeleportHomeEvent; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; +import org.bukkit.Location; import org.bukkit.entity.Player; public class SetHomeCommand extends PlayerSubCommand { @@ -35,8 +39,12 @@ public class SetHomeCommand extends PlayerSubCommand { player.sendRichMessage(Config.HOME_SET_MAX, Placeholder.unparsed("limit", String.valueOf(limit))); return true; } - - playerConfig.setHome(home, player.getLocation()); + Location homeLoc = player.getLocation(); + EssentiaEvent event = new PlayerSetHomeEvent(player, homeLoc, home); + if (!event.callEvent()) { + return true; + } + playerConfig.setHome(home, homeLoc); player.sendRichMessage(Config.HOME_SET, Placeholder.unparsed("home", home)); return true; } diff --git a/plugin/src/main/java/com/alttd/essentia/commands/player/SpawnCommand.java b/plugin/src/main/java/com/alttd/essentia/commands/player/SpawnCommand.java index 98e36cf..25f1c7e 100644 --- a/plugin/src/main/java/com/alttd/essentia/commands/player/SpawnCommand.java +++ b/plugin/src/main/java/com/alttd/essentia/commands/player/SpawnCommand.java @@ -4,6 +4,9 @@ import com.alttd.essentia.EssentiaPlugin; import com.alttd.essentia.commands.PlayerSubCommand; import com.alttd.essentia.configuration.Config; import com.alttd.essentia.configuration.PlayerConfig; +import com.alttd.essentia.events.EssentiaEvent; +import com.alttd.essentia.events.PlayerSetHomeEvent; +import com.alttd.essentia.events.PlayerTeleportSpawnEvent; import com.alttd.essentia.tasks.TeleportSounds; import org.bukkit.Location; import org.bukkit.World; @@ -23,6 +26,10 @@ public class SpawnCommand extends PlayerSubCommand { return true; } Location spawnLocation = world.getSpawnLocation(); + EssentiaEvent event = new PlayerTeleportSpawnEvent(player, spawnLocation); + if (!event.callEvent()) { + return true; + } new TeleportSounds(spawnLocation, player.getLocation()) .runTaskLater(plugin, 1);