Skip to content

Commit

Permalink
Merge pull request #143 from BentoBoxWorld/develop
Browse files Browse the repository at this point in the history
Release 1.16.0
  • Loading branch information
tastybento authored Nov 26, 2024
2 parents 5cca037 + 8347e73 commit 039ccff
Show file tree
Hide file tree
Showing 26 changed files with 705 additions and 181 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Add-on for BentoBox to add personal warp signs for players of BSkyBlock or AcidI
This add-on will work for all game modes installed on a BentoBox server. Use config settings
to disable use by gamemode.

![warps](https://github.com/user-attachments/assets/3454b7ec-d9bf-4631-9e5a-d6e603ac5f15)



## How to use

### Note: Java 16 and Minecraft 17, or later are required.
Expand Down
18 changes: 9 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,9 @@
</issueManagement>

<distributionManagement>
<snapshotRepository>
<id>codemc-snapshots</id>
<url>https://repo.codemc.org/repository/maven-snapshots</url>
</snapshotRepository>
<repository>
<id>codemc-releases</id>
<url>https://repo.codemc.org/repository/maven-releases</url>
<id>bentoboxworld</id>
<url>https://repo.codemc.org/repository/bentoboxworld/</url>
</repository>
</distributionManagement>

Expand All @@ -58,15 +54,15 @@
<!-- Non-minecraft related dependencies -->
<powermock.version>2.0.9</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.19.4-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>2.0.0-SNAPSHOT</bentobox.version>
<spigot.version>1.21.3-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>3.0.0-SNAPSHOT</bentobox.version>
<level.version>2.7.0-SNAPSHOT</level.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>1.14.0</build.version>
<build.version>1.16.0</build.version>
<!-- Sonar Cloud -->
<sonar.projectKey>BentoBoxWorld_Warps</sonar.projectKey>
<sonar.organization>bentobox-world</sonar.organization>
Expand Down Expand Up @@ -120,6 +116,10 @@
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots</url>
</repository>
<repository>
<id>bentoboxworld</id>
<url>https://repo.codemc.org/repository/bentoboxworld/</url>
</repository>
<repository>
<id>codemc</id>
<url>https://repo.codemc.org/repository/maven-snapshots/</url>
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/world/bentobox/warps/Warp.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.util.Util;
import world.bentobox.level.Level;
import world.bentobox.warps.commands.ToggleWarpCommand;
import world.bentobox.warps.commands.WarpCommand;
import world.bentobox.warps.commands.WarpsCommand;
import world.bentobox.warps.config.Settings;
Expand Down Expand Up @@ -100,6 +101,7 @@ public void onLoad()
// Load the master warp and warps command
new WarpCommand(this);
new WarpsCommand(this);
new ToggleWarpCommand(this);
}
}

Expand Down Expand Up @@ -140,6 +142,7 @@ public void onEnable() {

new WarpCommand(this, gameModeAddon.getPlayerCommand().get());
new WarpsCommand(this, gameModeAddon.getPlayerCommand().get());
new ToggleWarpCommand(this, gameModeAddon.getPlayerCommand().get());
this.hooked = true;
}
});
Expand Down Expand Up @@ -288,7 +291,7 @@ public Object request(String requestLabel, Map<String, Object> metaData) {
}
return switch (requestLabel) {
case "getSortedWarps" -> getWarpSignsManager().getSortedWarps(world);
case "getWarp" -> uuid == null ? null : getWarpSignsManager().getWarp(world, uuid);
case "getWarp" -> uuid == null ? null : getWarpSignsManager().getWarpLocation(world, uuid);
case "getWarpMap" -> getWarpSignsManager().getWarpMap(world);
case "hasWarp" -> uuid == null ? null : getWarpSignsManager().hasWarp(world, uuid);
case "listWarps" -> getWarpSignsManager().listWarps(world);
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/world/bentobox/warps/WarpsPladdon.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@


public class WarpsPladdon extends Pladdon {
private Addon addon;

@Override
public Addon getAddon() {
return new Warp();
if (addon == null) {
addon = new Warp();
}
return addon;
}
}
61 changes: 61 additions & 0 deletions src/main/java/world/bentobox/warps/commands/ToggleWarpCommand.java
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;
}
}
4 changes: 2 additions & 2 deletions src/main/java/world/bentobox/warps/commands/WarpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public boolean execute(User user, String label, List<String> args) {
user.sendMessage("warps.warpTip", "[text]", addon.getSettings().getWelcomeLine());
return false;
} else {
// Attemp to find warp with exact player's name
// Attempt to find warp with exact player's name
UUID foundWarp = warpList.stream().filter(u -> getPlayers().getName(u).equalsIgnoreCase(args.get(0))).findFirst().orElse(null);

if (foundWarp == null) {

// Atempt to find warp which starts with the given name
// Attempt to find warp which starts with the given name
UUID foundAlernativeWarp = warpList.stream().filter(u -> getPlayers().getName(u).toLowerCase().startsWith(args.get(0).toLowerCase())).findFirst().orElse(null);

if (foundAlernativeWarp == null) {
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/world/bentobox/warps/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class Settings implements ConfigObject
String warpCommand = "warp";
@ConfigEntry(path = "warps-command")
String warpsCommand = "warps";
@ConfigEntry(path = "togglewarp-command")
String toggleWarpCommand = "togglewarp";

// ---------------------------------------------------------------------
// Section: Constructor
Expand Down Expand Up @@ -205,6 +207,21 @@ public void setWarpsCommand(String warpsCommand) {
this.warpsCommand = warpsCommand;
}


/**
* @return the toggleWarpCommand
*/
public String getToggleWarpCommand() {
return toggleWarpCommand;
}

/**
* @param toggleWarpCommand the toggleWarpCommand to set
*/
public void setToggleWarpCommand(String toggleWarpCommand) {
this.toggleWarpCommand = toggleWarpCommand;
}

/**
* @return the removeExistingWarpsWhenFlagChanges
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Poslovitch
*
*/
public class WarpCreateEvent extends Event{
public class WarpCreateEvent extends Event {
private static final HandlerList handlers = new HandlerList();

private final Location warpLoc;
Expand Down
72 changes: 72 additions & 0 deletions src/main/java/world/bentobox/warps/event/WarpToggleEvent.java
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;
}
}
28 changes: 17 additions & 11 deletions src/main/java/world/bentobox/warps/listeners/WarpSignsListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.util.Util;
import world.bentobox.warps.objects.PlayerWarp;
import world.bentobox.warps.Warp;
import world.bentobox.warps.event.WarpRemoveEvent;

Expand Down Expand Up @@ -60,12 +61,12 @@ public void onChunkLoad(ChunkLoadEvent event) {
@Override
public void run() {
boolean changed = false;
Iterator<Map.Entry<UUID, Location>> iterator =
Iterator<Map.Entry<UUID, PlayerWarp>> iterator =
addon.getWarpSignsManager().getWarpMap(event.getWorld()).entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<UUID, Location> entry = iterator.next();
Map.Entry<UUID, PlayerWarp> entry = iterator.next();
UUID uuid = entry.getKey();
Location location = entry.getValue();
Location location = entry.getValue().getLocation();
if (event.getChunk().getX() == location.getBlockX() >> 4
&& event.getChunk().getZ() == location.getBlockZ() >> 4
&& !Tag.SIGNS.isTagged(location.getBlock().getType())) {
Expand Down Expand Up @@ -126,16 +127,16 @@ public void onSignBreak(BlockBreakEvent e) {

private boolean isPlayersSign(Player player, Block b, boolean inWorld) {
// Welcome sign detected - check to see if it is this player's sign
Map<UUID, Location> list = addon.getWarpSignsManager().getWarpMap(b.getWorld());
Map<UUID, PlayerWarp> list = addon.getWarpSignsManager().getWarpMap(b.getWorld());
String reqPerm = inWorld ? addon.getPermPrefix(b.getWorld()) + "mod.removesign" : Warp.WELCOME_WARP_SIGNS + ".mod.removesign";
return ((list.containsKey(player.getUniqueId()) && list.get(player.getUniqueId()).equals(b.getLocation()))
return ((list.containsKey(player.getUniqueId()) && list.get(player.getUniqueId()).getLocation().equals(b.getLocation()))
|| player.isOp() || player.hasPermission(reqPerm));
}

private boolean isWarpSign(Block b) {
Sign s = (Sign) b.getState();
return s.getLine(0).equalsIgnoreCase(ChatColor.GREEN + addon.getSettings().getWelcomeLine())
&& addon.getWarpSignsManager().getWarpMap(b.getWorld()).containsValue(s.getLocation());
&& addon.getWarpSignsManager().getWarpMap(b.getWorld()).values().stream().anyMatch(playerWarp -> playerWarp.getLocation().equals(s.getLocation()));
}

/**
Expand All @@ -158,19 +159,24 @@ public void onSignWarpCreate(SignChangeEvent e) {
if (noPerms(user, b.getWorld(), inWorld)) {
return;
}
// TODO: These checks are useless if the sign is placed outside a BSB world.
// This will mean level and rank requirements are nil in the case of allow-in-other-worlds: true.
// I'm not sure if there is a better way around this without adding new API checking for primary
// or last island accessed with relevant permissions.
// ignored.
if (inWorld && noLevelOrIsland(user, b.getWorld())) {
e.setLine(0, ChatColor.RED + addon.getSettings().getWelcomeLine());
return;
}

if(!hasCorrectIslandRank(b, user)) {
if (inWorld && !hasCorrectIslandRank(b, user)) {
e.setLine(0, ChatColor.RED + addon.getSettings().getWelcomeLine());
user.sendMessage("warps.error.not-correct-rank");
return;
}

// Check if the player already has a sign
final Location oldSignLoc = addon.getWarpSignsManager().getWarp(b.getWorld(), user.getUniqueId());
final Location oldSignLoc = addon.getWarpSignsManager().getWarpLocation(b.getWorld(), user.getUniqueId());
if (oldSignLoc != null) {
// A sign already exists. Check if it still there and if
// so,
Expand Down Expand Up @@ -216,15 +222,15 @@ public void onFlagChange(FlagProtectionChangeEvent e) {

final Island island = e.getIsland();

final Map<UUID, Location> islandWarps = addon
final Map<UUID, PlayerWarp> islandWarps = addon
.getWarpSignsManager()
.getWarpMap(island.getWorld())
.entrySet()
.stream()
.filter(x -> island.inIslandSpace(x.getValue()))
.filter(x -> island.inIslandSpace(x.getValue().getLocation()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

for(Map.Entry<UUID, Location> entry : islandWarps.entrySet()) {
for(Map.Entry<UUID, PlayerWarp> entry : islandWarps.entrySet()) {
if(island.getRank(entry.getKey()) >= e.getSetTo()) continue;

//The user has a lower rank than the new set value.
Expand Down
Loading

0 comments on commit 039ccff

Please sign in to comment.