-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from BentoBoxWorld/develop
Release 1.16.0
- Loading branch information
Showing
26 changed files
with
705 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/world/bentobox/warps/commands/ToggleWarpCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package world.bentobox.warps.commands; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.World; | ||
import world.bentobox.bentobox.api.commands.CompositeCommand; | ||
import world.bentobox.bentobox.api.user.User; | ||
import world.bentobox.warps.Warp; | ||
import world.bentobox.warps.event.WarpToggleEvent; | ||
import world.bentobox.warps.objects.PlayerWarp; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public class ToggleWarpCommand extends CompositeCommand { | ||
|
||
private final Warp addon; | ||
|
||
public ToggleWarpCommand(Warp addon, CompositeCommand bsbIslandCmd) { | ||
super(bsbIslandCmd, addon.getSettings().getToggleWarpCommand()); | ||
this.addon = addon; | ||
} | ||
|
||
public ToggleWarpCommand(Warp addon) { | ||
super(addon.getSettings().getToggleWarpCommand()); | ||
this.addon = addon; | ||
} | ||
|
||
|
||
@Override | ||
public void setup() { | ||
this.setPermission(this.getParent() == null ? Warp.WELCOME_WARP_SIGNS + ".togglewarp" : "island.warp.toggle"); | ||
this.setOnlyPlayer(true); | ||
this.setDescription("togglewarp.help.description"); | ||
} | ||
|
||
@Override | ||
public boolean execute(User user, String s, List<String> list) { | ||
UUID userUUID = user.getUniqueId(); | ||
World userWorld = user.getWorld(); | ||
|
||
// Check if the user has a warp | ||
boolean hasWarp = addon.getWarpSignsManager().hasWarp(userWorld, userUUID); | ||
|
||
if (hasWarp) { | ||
// If the user has a warp, toggle its visibility | ||
PlayerWarp warp = addon.getWarpSignsManager().getPlayerWarp(userWorld, userUUID); | ||
// Check extreme case if PlayerWarp is null | ||
if (warp == null) { | ||
user.sendMessage("togglewarp.error.generic"); | ||
return false; | ||
} | ||
warp.toggle(); | ||
Bukkit.getPluginManager().callEvent(new WarpToggleEvent(userUUID, warp)); | ||
String message = warp.isEnabled() ? "togglewarp.enabled" : "togglewarp.disabled"; | ||
user.sendMessage(message); | ||
} else { | ||
user.sendMessage("togglewarp.error.no-warp"); | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/main/java/world/bentobox/warps/event/WarpToggleEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.