mirror of
https://github.com/BentoBoxWorld/Warps.git
synced 2024-11-25 12:06:24 +01:00
feat: add toggle event
This commit is contained in:
parent
eeead7fb49
commit
abd526b06d
@ -1,9 +1,11 @@
|
|||||||
package world.bentobox.warps.commands;
|
package world.bentobox.warps.commands;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.warps.Warp;
|
import world.bentobox.warps.Warp;
|
||||||
|
import world.bentobox.warps.event.WarpToggleEvent;
|
||||||
import world.bentobox.warps.objects.PlayerWarp;
|
import world.bentobox.warps.objects.PlayerWarp;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -48,6 +50,7 @@ public class ToggleWarpCommand extends CompositeCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
warp.toggle();
|
warp.toggle();
|
||||||
|
Bukkit.getPluginManager().callEvent(new WarpToggleEvent(userUUID, warp));
|
||||||
String message = warp.isEnabled() ? "togglewarp.enabled" : "togglewarp.disabled";
|
String message = warp.isEnabled() ? "togglewarp.enabled" : "togglewarp.disabled";
|
||||||
user.sendMessage(message);
|
user.sendMessage(message);
|
||||||
} else {
|
} else {
|
||||||
|
@ -0,0 +1,72 @@
|
|||||||
|
package world.bentobox.warps.event;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import world.bentobox.warps.objects.PlayerWarp;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This event is fired when a warp is toggled
|
||||||
|
* A Listener to this event can use it only to get information. e.g: broadcast something
|
||||||
|
*
|
||||||
|
* @since 1.16.0
|
||||||
|
* @author TreemanKing
|
||||||
|
*/
|
||||||
|
public class WarpToggleEvent extends Event {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
private final UUID user;
|
||||||
|
private final PlayerWarp playerWarp;
|
||||||
|
|
||||||
|
public WarpToggleEvent(UUID user, PlayerWarp playerWarp) {
|
||||||
|
this.playerWarp = playerWarp;
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the user who has toggled the warp
|
||||||
|
*
|
||||||
|
* @return the UUID of the player who toggled the warp
|
||||||
|
*/
|
||||||
|
public UUID getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the state of the warp
|
||||||
|
*
|
||||||
|
* @return true if the warp is enabled, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return playerWarp.isEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the PlayerWarp object
|
||||||
|
*
|
||||||
|
* @return the PlayerWarp object
|
||||||
|
*/
|
||||||
|
public PlayerWarp getPlayerWarp() {
|
||||||
|
return playerWarp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the location of the toggled warp
|
||||||
|
*
|
||||||
|
* @return the location of the warp
|
||||||
|
*/
|
||||||
|
public Location getLocation() {
|
||||||
|
return playerWarp.getLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user