From 79b568fbdfd03051154633d56ed636f68a5b24d5 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 3 Mar 2019 18:53:36 -0800 Subject: [PATCH] Updates locales. Fixes nether and end warping. Fixes issue with warp level checking wrong environment. Adds warning when warping to PVP enabled islands. https://github.com/BentoBoxWorld/addon-welcomewarpsigns/issues/21 --- .../bentobox/warps/WarpSignsListener.java | 7 +-- .../bentobox/warps/WarpSignsManager.java | 45 +++++++++++-------- .../bentobox/warps/commands/WarpCommand.java | 26 +++++------ src/main/resources/locales/en-US.yml | 45 ++++++++++--------- src/main/resources/locales/fr-FR.yml | 44 +++++++++--------- src/main/resources/locales/ja-JP.yml | 33 ++++++++++++++ src/main/resources/locales/zh-CN.yml | 42 +++++++++-------- .../bentobox/warps/WarpSignsListenerTest.java | 33 +++++++++----- 8 files changed, 167 insertions(+), 108 deletions(-) create mode 100755 src/main/resources/locales/ja-JP.yml diff --git a/src/main/java/world/bentobox/warps/WarpSignsListener.java b/src/main/java/world/bentobox/warps/WarpSignsListener.java index 3ed5495..8fdd38a 100644 --- a/src/main/java/world/bentobox/warps/WarpSignsListener.java +++ b/src/main/java/world/bentobox/warps/WarpSignsListener.java @@ -15,9 +15,10 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.SignChangeEvent; -import world.bentobox.warps.event.WarpRemoveEvent; import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.api.user.User; +import world.bentobox.bentobox.util.Util; +import world.bentobox.warps.event.WarpRemoveEvent; /** * Handles warping. Players can add one sign @@ -99,8 +100,8 @@ public class WarpSignsListener implements Listener { user.sendMessage("general.errors.you-need", "[permission]", addon.getPermPrefix(b.getWorld()) + ".island.addwarp"); return; } - // Get level is level addon is available - Long level = addon.getLevel(b.getWorld(), user.getUniqueId()); + // Get level if level addon is available + Long level = addon.getLevel(Util.getWorld(b.getWorld()), user.getUniqueId()); if (level != null && level < addon.getSettings().getWarpLevelRestriction()) { user.sendMessage("warps.error.not-enough-level"); user.sendMessage("warps.error.your-level-is", diff --git a/src/main/java/world/bentobox/warps/WarpSignsManager.java b/src/main/java/world/bentobox/warps/WarpSignsManager.java index 1eee454..80ceb57 100644 --- a/src/main/java/world/bentobox/warps/WarpSignsManager.java +++ b/src/main/java/world/bentobox/warps/WarpSignsManager.java @@ -24,15 +24,15 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; -import world.bentobox.bentobox.lists.Flags; -import world.bentobox.warps.objects.WarpsData; -import world.bentobox.warps.event.WarpInitiateEvent; -import world.bentobox.warps.event.WarpListEvent; import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.database.Database; import world.bentobox.bentobox.database.objects.Island; +import world.bentobox.bentobox.lists.Flags; import world.bentobox.bentobox.util.Util; +import world.bentobox.warps.event.WarpInitiateEvent; +import world.bentobox.warps.event.WarpListEvent; +import world.bentobox.warps.objects.WarpsData; /** * Handles warping. Players can add one sign @@ -56,8 +56,7 @@ public class WarpSignsManager { * @return map of warps */ public Map getWarpMap(World world) { - worldsWarpList.putIfAbsent(world, new HashMap<>()); - return worldsWarpList.get(world); + return worldsWarpList.computeIfAbsent(Util.getWorld(world), k -> new HashMap<>()); } /** @@ -282,7 +281,7 @@ public class WarpSignsManager { inFront.getBlockZ() + 0.5D, yaw, 30F); user.teleport(actualWarp); if (pvp) { - user.sendRawMessage(user.getTranslation("protection.flags.PVP_OVERWORLD.active")); + user.sendMessage("protection.flags.PVP_OVERWORLD.active"); user.getWorld().playSound(user.getLocation(), Sound.ENTITY_ARROW_HIT, 1F, 1F); } else { user.getWorld().playSound(user.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 1F, 1F); @@ -356,23 +355,31 @@ public class WarpSignsManager { } if (this.plugin.getIWM().inWorld(user.getWorld()) && - Flags.PREVENT_TELEPORT_WHEN_FALLING.isSetForWorld(user.getWorld()) && - user.getPlayer().getFallDistance() > 0) { + Flags.PREVENT_TELEPORT_WHEN_FALLING.isSetForWorld(user.getWorld()) && + user.getPlayer().getFallDistance() > 0) { // We're sending the "hint" to the player to tell them they cannot teleport while falling. user.sendMessage(Flags.PREVENT_TELEPORT_WHEN_FALLING.getHintReference()); return; } - // Find out if island is locked - // TODO: Fire event - Island island = addon.getPlugin().getIslands().getIsland(world, owner); boolean pvp = false; if (island != null) { - //if ((warpSpot.getWorld().equals(IslandWorld.getIslandWorld()) && island.getFlag(SettingsFlag.PVP_OVERWORLD)) - // || (warpSpot.getWorld().equals(IslandWorld.getNetherWorld()) && island.getFlag(SettingsFlag.PVP_NETHER))) { - // pvp = true; - //} + // Check for PVP + switch (warpSpot.getWorld().getEnvironment()) { + case NETHER: + pvp = island.isAllowed(Flags.PVP_NETHER); + break; + case NORMAL: + pvp = island.isAllowed(Flags.PVP_OVERWORLD); + break; + case THE_END: + pvp = island.isAllowed(Flags.PVP_END); + break; + default: + break; + + } } // Find out which direction the warp is facing Block b = warpSpot.getBlock(); @@ -397,7 +404,7 @@ public class WarpSignsManager { return; } if (!(plugin.getIslands().isSafeLocation(warpSpot))) { - user.sendMessage("warps.error.NotSafe"); + user.sendMessage("warps.error.not-safe"); // WALL_SIGN's will always be unsafe if the place in front is obscured. if (b.getType().equals(Material.SIGN)) { addon.getLogger().warning( @@ -408,13 +415,13 @@ public class WarpSignsManager { } else { final Location actualWarp = new Location(warpSpot.getWorld(), warpSpot.getBlockX() + 0.5D, warpSpot.getBlockY(), warpSpot.getBlockZ() + 0.5D); - user.teleport(actualWarp); if (pvp) { - //user.sendLegacyMessage(user.getTranslation("igs." + SettingsFlag.PVP_OVERWORLD) + " " + user.getTranslation("igs.Allowed")); + user.sendMessage("protection.flags.PVP_OVERWORLD.active"); user.getWorld().playSound(user.getLocation(), Sound.ENTITY_ARROW_HIT, 1F, 1F); } else { user.getWorld().playSound(user.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 1F, 1F); } + user.teleport(actualWarp); return; } } diff --git a/src/main/java/world/bentobox/warps/commands/WarpCommand.java b/src/main/java/world/bentobox/warps/commands/WarpCommand.java index 9ce0bf7..c3bb85c 100644 --- a/src/main/java/world/bentobox/warps/commands/WarpCommand.java +++ b/src/main/java/world/bentobox/warps/commands/WarpCommand.java @@ -6,9 +6,9 @@ import java.util.Optional; import java.util.Set; import java.util.UUID; -import world.bentobox.warps.Warp; import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.user.User; +import world.bentobox.warps.Warp; /** * The /is warp command @@ -33,18 +33,6 @@ public class WarpCommand extends CompositeCommand { this.setDescription("warp.help.description"); } - @Override - public Optional> tabComplete(User user, String alias, List args) { - List options = new ArrayList<>(); - final Set warpList = addon.getWarpSignsManager().listWarps(getWorld()); - - for (UUID warp : warpList) { - options.add(addon.getPlugin().getPlayers().getName(warp)); - } - - return Optional.of(options); - } - @Override public boolean execute(User user, String label, List args) { if (args.size() == 1) { @@ -71,5 +59,17 @@ public class WarpCommand extends CompositeCommand { return false; } + @Override + public Optional> tabComplete(User user, String alias, List args) { + List options = new ArrayList<>(); + final Set warpList = addon.getWarpSignsManager().listWarps(getWorld()); + + for (UUID warp : warpList) { + options.add(addon.getPlugin().getPlayers().getName(warp)); + } + + return Optional.of(options); + } + } diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index 3810b4e..9c98c0e 100755 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -3,30 +3,31 @@ # the one at http://yaml-online-parser.appspot.com # ########################################################################################### -warps: +warp: + help: + description: "warp to the player's warp sign" + parameters: +warps: deactivate: "&cOld warp sign deactivated!" - success: "&ASuccess!" - sign-removed: "&CWarp sign removed!" - title: "Warp Signs" + error: + does-not-exist: "&cOh snap! That warp no longer exists!" + duplicate: "&CDuplicate sign placed" + no-permission: "&CYou do not have permission to do that!" + no-remove: "&CYou cannot remove that sign!" + no-warps-yet: "&CThere are no warps available yet" + not-enough-level: "&CYour island level is not high enough!" + not-on-island: "&CYou must be on your island to do that!" + not-safe: "&cThat warp is not safe!" + your-level-is: "&cYou island level is only [level] and must be higher than [required]" + help: + description: "open the warps panel" + next: "&6Next page" player-warped: "&2[name] warped to your warp sign!" previous: "&6Previous page" - next: "&6Next page" - warpToPlayersSign: "&6Warping to [player]'s sign" - # The [text] is replaced with the welcome line text from config.yml + sign-removed: "&CWarp sign removed!" + success: "&ASuccess!" + title: "Warp Signs" warpTip: "&6Place a warp sign with [text] on the top" - error: - does-not-exist: "&cOh snap! That warp no longer exists!" - no-remove: "&CYou cannot remove that sign!" - not-enough-level: "&CYour island level is not high enough!" - no-permission: "&CYou do not have permission to do that!" - not-on-island: "&CYou must be on your island to do that!" - duplicate: "&CDuplicate sign placed" - no-warps-yet: "&CThere are no warps available yet" - your-level-is: "&cYou island level is only [level] and must be higher than [required]" - help: - description: "open the warps panel" -warp: - help: - parameters: "" - description: "warp to the player's warp sign" + warpToPlayersSign: "&6Warping to [player]'s sign" + \ No newline at end of file diff --git a/src/main/resources/locales/fr-FR.yml b/src/main/resources/locales/fr-FR.yml index 941beec..d581453 100644 --- a/src/main/resources/locales/fr-FR.yml +++ b/src/main/resources/locales/fr-FR.yml @@ -3,29 +3,29 @@ # the one at http://yaml-online-parser.appspot.com # ########################################################################################### -warps: +warp: + help: + description: "te téléporte au Warp d'un autre joueur" + parameters: +warps: deactivate: "&cAncien panneau de Warp désactivé !" - success: "&aSuccès !" - sign-removed: "&cPanneau de Warp supprimé !" - title: "Panneau Warp" + error: + does-not-exist: "&cCe Warp n'existe plus !" + duplicate: "&cPanneau dupliqué placé." + no-permission: "&cVous n'avez pas la permission pour faire cela !" + no-remove: "&cVous ne pouvez pas supprimer ce panneau !" + no-warps-yet: "&cIl n'y a encore aucun Warp sur ce serveur." + not-enough-level: "&cVotre niveau d'île n'est pas assez élevé pour faire cela !" + not-on-island: "&cVous devez être sur votre île pour faire cela !" + not-safe: "&cCe Warp n'est pas sûr!" + your-level-is: "&cVotre île est seulement niveau [level] et doit être niveau [required]." + help: + description: "Ouvre le menu des Warps" + next: "&6Page suivante" player-warped: "&2[name] s'est téléporté sur votre île !" previous: "&6Page précédente" - next: "&6Page suivante" - warpToPlayersSign: "&6Téléportation sur l'île de [player]..." - # The [text] is replaced with the welcome line text from config.yml + sign-removed: "&cPanneau de Warp supprimé !" + success: "&aSuccès !" + title: "Panneau Warp" warpTip: "&6Placez un panneau et écrivez [text] sur la première ligne." - error: - does-not-exist: "&cCe Warp n'existe plus !" - no-remove: "&cVous ne pouvez pas supprimer ce panneau !" - not-enough-level: "&cVotre niveau d'île n'est pas assez élevé pour faire cela !" - no-permission: "&cVous n'avez pas la permission pour faire cela !" - not-on-island: "&cVous devez être sur votre île pour faire cela !" - duplicate: "&cPanneau dupliqué placé." - no-warps-yet: "&cIl n'y a encore aucun Warp sur ce serveur." - your-level-is: "&cVotre île est seulement niveau [level] et doit être niveau [required]." - help: - description: "Ouvre le menu des Warps" -warp: - help: - parameters: "" - description: "te téléporte au Warp d'un autre joueur" + warpToPlayersSign: "&6Téléportation sur l'île de [player]..." diff --git a/src/main/resources/locales/ja-JP.yml b/src/main/resources/locales/ja-JP.yml new file mode 100755 index 0000000..3dc80a3 --- /dev/null +++ b/src/main/resources/locales/ja-JP.yml @@ -0,0 +1,33 @@ +########################################################################################### +# This is a YML file. Be careful when editing. Check your edits in a YAML checker like # +# the one at http://yaml-online-parser.appspot.com # +########################################################################################### + +warp: + help: + description: "プレイヤーのワープサインにワープする" + parameters: <名> +warps: + deactivate: "&c前のワープサインが無効になりました!" + error: + does-not-exist: "&cそのワープはもう存在しません!" + duplicate: "&C重複サインを配置" + no-permission: "&C許可がありません!" + no-remove: "&Cワープサインは外せません!" + no-warps-yet: "&C利用可能なワープはまだありません" + not-enough-level: "&C島のレベルは十分に高くありません!" + not-on-island: "&Cあなたの島にいなければなりません!" + not-safe: "&cワープは安全ではありません。!" + your-level-is: "&c島レベルはわずか[level]で、[required]より高くなければなりません" + help: + description: "ワープパネルを開く" + next: "&6次のページ" + player-warped: "&2[name]はあなたのワープサインに反った!" + previous: "&6前のページ" + sign-removed: "&Cワープサインを削除!" + success: "&A完了!" + title: "ワープサイン" + warpTip: "&6最初の行に[text]と一緒にワープサインを置きます" + warpToPlayersSign: "&6[player]のサインに反っている" + + \ No newline at end of file diff --git a/src/main/resources/locales/zh-CN.yml b/src/main/resources/locales/zh-CN.yml index 47e91d2..8e6d69c 100644 --- a/src/main/resources/locales/zh-CN.yml +++ b/src/main/resources/locales/zh-CN.yml @@ -3,27 +3,31 @@ # 请在 http://yaml-online-parser.appspot.com 等 YAML 检查器中检查您的编辑. # ########################################################################################### +warp: + help: + description: 传送到该玩家的传送木牌处 + parameters: <玩家名称> warps: - removed: "&C传送木牌已移除" - success: "&A成功!" - sign-removed: "&C传送木牌已移除!" - title: "传送木牌" - previous: "&6上一页" - next: "&6下一页" - warpToPlayersSign: "&6正传送到 [player] 的传送木牌" - warpTip: "&6放置一个第一行是 [text] 的木牌以创建传送木牌" - error: - no-remove: "&C无权移除传送木牌!" - not-enough-level: "&C岛屿等级不够高!" - no-permission: "&C权限不足!" - not-on-island: "&C操作必须在空岛上进行!" + deactivate: "&c禁用的旧转移标志!" + error: + does-not-exist: "&c转移不再存在!" duplicate: "&C木牌重复" + no-permission: "&C权限不足!" + no-remove: "&C无权移除传送木牌!" no-warps-yet: "&C暂无可用传送木牌" + not-enough-level: "&C岛屿等级不够高!" + not-on-island: "&C操作必须在空岛上进行!" + not-safe: "&c转移不安全!" your-level-is: "&c岛屿当前等级 [level], 需要等级 [required]" - help: - description: "打开传送面板" -warp: - help: - parameters: "<玩家名称>" - description: "传送到该玩家的传送木牌处" + help: + description: 打开传送面板 + next: "&6下一页" + player-warped: "&2[name]转移到你的标志!" + previous: "&6上一页" + sign-removed: "&C传送木牌已移除!" + success: "&A成功!" + title: 传送木牌 + warpTip: "&6放置一个第一行是 [text] 的木牌以创建传送木牌" + warpToPlayersSign: "&6正传送到 [player] 的传送木牌" + diff --git a/src/test/java/world/bentobox/warps/WarpSignsListenerTest.java b/src/test/java/world/bentobox/warps/WarpSignsListenerTest.java index 1f5dd3b..b045625 100644 --- a/src/test/java/world/bentobox/warps/WarpSignsListenerTest.java +++ b/src/test/java/world/bentobox/warps/WarpSignsListenerTest.java @@ -1,7 +1,23 @@ package world.bentobox.warps; -import org.bukkit.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.Sign; import org.bukkit.configuration.file.FileConfiguration; @@ -18,24 +34,17 @@ import org.mockito.stubbing.Answer; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.LocalesManager; +import world.bentobox.bentobox.util.Util; import world.bentobox.warps.config.Settings; -import static org.junit.Assert.*; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - @RunWith(PowerMockRunner.class) -@PrepareForTest({Bukkit.class}) +@PrepareForTest({Bukkit.class, Util.class}) public class WarpSignsListenerTest { private Warp addon; @@ -118,6 +127,10 @@ public class WarpSignsListenerTest { IslandWorldManager iwm = mock(IslandWorldManager.class); when(plugin.getIWM()).thenReturn(iwm); when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty()); + + // Util + PowerMockito.mockStatic(Util.class); + when(Util.getWorld(Mockito.any())).thenReturn(world); } @Test