From 48fc7c3d1295d8b7c8ca840f0cd35bce8b3d2b82 Mon Sep 17 00:00:00 2001 From: cyilin Date: Wed, 24 Apr 2019 20:47:29 +0800 Subject: [PATCH] update to 1.14-pre5 --- .travis.yml | 2 +- build.gradle | 4 +- .../mc/lockettepro/BlockDebugListener.java | 4 +- .../mc/lockettepro/BlockPlayerListener.java | 19 +++---- .../me/crafter/mc/lockettepro/Config.java | 4 +- .../mc/lockettepro/DependencyProtocolLib.java | 2 +- .../crafter/mc/lockettepro/LockettePro.java | 4 +- .../mc/lockettepro/LocketteProAPI.java | 20 ++++---- .../java/me/crafter/mc/lockettepro/Utils.java | 51 ++++++++++++++----- .../me/crafter/mc/lockettepro/Version.java | 5 +- src/main/resources/config.yml | 3 ++ 11 files changed, 71 insertions(+), 47 deletions(-) diff --git a/.travis.yml b/.travis.yml index e481687..796da7b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ deploy: provider: releases api_key: $GITHUB_KEY file: - - build/libs/LockettePro-2.9.${TRAVIS_BUILD_NUMBER}-1.13.2.jar + - build/libs/LockettePro-2.9.${TRAVIS_BUILD_NUMBER}-1.14-pre5.jar on: tags: false skip_cleanup: true diff --git a/build.gradle b/build.gradle index 92d186d..cb27780 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'java' sourceCompatibility = 1.8 targetCompatibility = 1.8 -version = "2.9.%s-1.13.2" +version = "2.9.%s-1.14-pre5" if (System.getenv("TRAVIS_BUILD_NUMBER") != null) { project.version = String.format(project.version, System.getenv("TRAVIS_BUILD_NUMBER")) @@ -41,7 +41,7 @@ repositories { } dependencies { - compile 'org.bukkit:bukkit:1.13.2-R0.1-SNAPSHOT' + compile 'org.bukkit:bukkit:1.14-pre5-SNAPSHOT' compile('net.milkbowl.vault:VaultAPI:1.7') { transitive = false } diff --git a/src/main/java/me/crafter/mc/lockettepro/BlockDebugListener.java b/src/main/java/me/crafter/mc/lockettepro/BlockDebugListener.java index 83c9a43..41461c7 100644 --- a/src/main/java/me/crafter/mc/lockettepro/BlockDebugListener.java +++ b/src/main/java/me/crafter/mc/lockettepro/BlockDebugListener.java @@ -1,7 +1,7 @@ package me.crafter.mc.lockettepro; import org.bukkit.ChatColor; -import org.bukkit.Material; +import org.bukkit.Tag; import org.bukkit.block.Block; import org.bukkit.block.Sign; import org.bukkit.entity.Player; @@ -36,7 +36,7 @@ public void onDebugClick(PlayerInteractEvent event){ p.sendMessage("Block: " + b.getType().toString() + " " + b.getData()); - if (b.getType() == Material.WALL_SIGN){ + if (Tag.WALL_SIGNS.isTagged(b.getType())){ for (String line : ((Sign)b.getState()).getLines()){ p.sendMessage(ChatColor.GREEN + line); } diff --git a/src/main/java/me/crafter/mc/lockettepro/BlockPlayerListener.java b/src/main/java/me/crafter/mc/lockettepro/BlockPlayerListener.java index 3f51eaf..39081cb 100644 --- a/src/main/java/me/crafter/mc/lockettepro/BlockPlayerListener.java +++ b/src/main/java/me/crafter/mc/lockettepro/BlockPlayerListener.java @@ -3,6 +3,7 @@ import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; +import org.bukkit.Tag; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; @@ -35,7 +36,7 @@ public void onPlayerQuickLockChest(PlayerInteractEvent event){ Action action = event.getAction(); Player player = event.getPlayer(); // Check action correctness - if (action == Action.RIGHT_CLICK_BLOCK && player.getInventory().getItemInMainHand().getType() == Material.SIGN){ + if (action == Action.RIGHT_CLICK_BLOCK && Tag.SIGNS.isTagged(player.getInventory().getItemInMainHand().getType())) { if (player.getGameMode().equals(GameMode.SPECTATOR)) { return; } @@ -67,15 +68,15 @@ public void onPlayerQuickLockChest(PlayerInteractEvent event){ // Send message Utils.sendMessages(player, Config.getLang("locked-quick")); // Put sign on - Block newsign = Utils.putSignOn(block, blockface, Config.getDefaultPrivateString(), player.getName()); + Block newsign = Utils.putSignOn(block, blockface, Config.getDefaultPrivateString(), player.getName(), player.getInventory().getItemInMainHand().getType()); Utils.resetCache(block); // Cleanups - UUID if (Config.isUuidEnabled()){ Utils.updateLineByPlayer(newsign, 1, player); } // Cleanups - Expiracy - if (Config.isLockExpire()){ - if (player.hasPermission("lockettepro.noexpire")){ + if (Config.isLockExpire()) { + if (player.hasPermission("lockettepro.noexpire")) { Utils.updateLineWithTime(newsign, true); // set created to -1 (no expire) } else { Utils.updateLineWithTime(newsign, false); // set created to now @@ -86,12 +87,12 @@ public void onPlayerQuickLockChest(PlayerInteractEvent event){ // Not locked, (is locked door nearby), is owner of locked door nearby Utils.removeASign(player); Utils.sendMessages(player, Config.getLang("additional-sign-added-quick")); - Utils.putSignOn(block, blockface, Config.getDefaultAdditionalString(), ""); + Utils.putSignOn(block, blockface, Config.getDefaultAdditionalString(), "", player.getInventory().getItemInMainHand().getType()); Dependency.logPlacement(player, block.getRelative(blockface)); - } else if (LocketteProAPI.isOwner(block, player)){ + } else if (LocketteProAPI.isOwner(block, player)) { // Locked, (not locked door nearby), is owner of locked block Utils.removeASign(player); - Utils.putSignOn(block, blockface, Config.getDefaultAdditionalString(), ""); + Utils.putSignOn(block, blockface, Config.getDefaultAdditionalString(), "", player.getInventory().getItemInMainHand().getType()); Utils.sendMessages(player, Config.getLang("additional-sign-added-quick")); Dependency.logPlacement(player, block.getRelative(blockface)); } else { @@ -106,7 +107,7 @@ public void onPlayerQuickLockChest(PlayerInteractEvent event){ // Manual protection @EventHandler(priority = EventPriority.NORMAL) public void onManualLock(SignChangeEvent event){ - if (event.getBlock().getType() != Material.WALL_SIGN) return; + if (!Tag.WALL_SIGNS.isTagged(event.getBlock().getType())) return; String topline = event.getLine(0); Player player = event.getPlayer(); /* Issue #46 - Old version of Minecraft trim signs in unexpected way. @@ -177,7 +178,7 @@ public void onManualLock(SignChangeEvent event){ // Player select sign @EventHandler(priority = EventPriority.LOW) public void playerSelectSign(PlayerInteractEvent event){ - if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.WALL_SIGN){ + if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.hasBlock() && Tag.WALL_SIGNS.isTagged(event.getClickedBlock().getType())) { Block block = event.getClickedBlock(); Player player = event.getPlayer(); if (!player.hasPermission("lockettepro.edit")) return; diff --git a/src/main/java/me/crafter/mc/lockettepro/Config.java b/src/main/java/me/crafter/mc/lockettepro/Config.java index ed2a43d..ff78b8f 100644 --- a/src/main/java/me/crafter/mc/lockettepro/Config.java +++ b/src/main/java/me/crafter/mc/lockettepro/Config.java @@ -2,6 +2,7 @@ import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.Tag; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.Plugin; @@ -144,7 +145,8 @@ public static void reload(){ } } } - lockables.remove(Material.WALL_SIGN); + lockables.removeAll(Tag.SIGNS.getValues()); + lockables.remove(Material.SCAFFOLDING); } public static void initDefaultConfig(){ diff --git a/src/main/java/me/crafter/mc/lockettepro/DependencyProtocolLib.java b/src/main/java/me/crafter/mc/lockettepro/DependencyProtocolLib.java index 31fc154..9465539 100644 --- a/src/main/java/me/crafter/mc/lockettepro/DependencyProtocolLib.java +++ b/src/main/java/me/crafter/mc/lockettepro/DependencyProtocolLib.java @@ -19,7 +19,7 @@ public class DependencyProtocolLib { public static void setUpProtocolLib(Plugin plugin){ switch (LockettePro.getBukkitVersion()){ - case v1_13_R2: + case v1_14_R1: addTileEntityDataListener(plugin); addMapChunkListener(plugin); break; diff --git a/src/main/java/me/crafter/mc/lockettepro/LockettePro.java b/src/main/java/me/crafter/mc/lockettepro/LockettePro.java index 9abe568..11cb1fb 100644 --- a/src/main/java/me/crafter/mc/lockettepro/LockettePro.java +++ b/src/main/java/me/crafter/mc/lockettepro/LockettePro.java @@ -3,7 +3,6 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; -import org.bukkit.Tag; import org.bukkit.block.Block; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -31,8 +30,7 @@ public void onEnable(){ getLogger().warning("==================================="); getLogger().warning("Unsupported server version: " + Bukkit.getBukkitVersion()); try { - Tag.ANVIL.getValues(); - Material.TRIDENT.isItem(); + Material.BARREL.isItem(); } catch (Exception e) { setEnabled(false); getLogger().warning("This plugin is not compatible with your server version!"); diff --git a/src/main/java/me/crafter/mc/lockettepro/LocketteProAPI.java b/src/main/java/me/crafter/mc/lockettepro/LocketteProAPI.java index ae8c20f..7add94d 100644 --- a/src/main/java/me/crafter/mc/lockettepro/LocketteProAPI.java +++ b/src/main/java/me/crafter/mc/lockettepro/LocketteProAPI.java @@ -1,8 +1,6 @@ package me.crafter.mc.lockettepro; -import org.bukkit.Effect; -import org.bukkit.Material; -import org.bukkit.Tag; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Container; @@ -210,12 +208,8 @@ public static boolean isOwnerOfSign(Block block, Player player){ // Requires isS public static boolean isLockable(Block block){ Material material = block.getType(); //Bad blocks - switch (material){ - case SIGN: - case WALL_SIGN: + if(Tag.SIGNS.isTagged(material)){ return false; - default: - break; } if (Config.isLockable(material)){ // Directly lockable return true; @@ -313,8 +307,12 @@ public static boolean mayInterfere(Block block, Player player){ // End temp workaround bad code for checking up and down signs case CHEST: case TRAPPED_CHEST: - case WALL_SIGN: - case SIGN: + case OAK_WALL_SIGN: + case SPRUCE_SIGN: + case BIRCH_SIGN: + case JUNGLE_SIGN: + case ACACIA_SIGN: + case DARK_OAK_SIGN: for (BlockFace blockface : allfaces){ Block newblock = block.getRelative(blockface); switch (newblock.getType()){ @@ -356,7 +354,7 @@ public static boolean mayInterfere(Block block, Player player){ } public static boolean isSign(Block block){ - return block.getType() == Material.WALL_SIGN; + return Tag.WALL_SIGNS.isTagged(block.getType()); } public static boolean isLockSign(Block block){ diff --git a/src/main/java/me/crafter/mc/lockettepro/Utils.java b/src/main/java/me/crafter/mc/lockettepro/Utils.java index 0faf2fd..1d7d6bd 100644 --- a/src/main/java/me/crafter/mc/lockettepro/Utils.java +++ b/src/main/java/me/crafter/mc/lockettepro/Utils.java @@ -1,11 +1,15 @@ package me.crafter.mc.lockettepro; import com.comphenix.protocol.wrappers.WrappedChatComponent; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; +import org.bukkit.Tag; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; @@ -21,19 +25,33 @@ import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; -import java.util.*; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.TimeUnit; public class Utils { - + public static final String usernamepattern = "^[a-zA-Z0-9_]*$"; - - private static Map selectedsign = new HashMap(); - private static Set notified = new HashSet(); - + private static LoadingCache selectedsign = CacheBuilder.newBuilder() + .expireAfterAccess(30, TimeUnit.SECONDS) + .build(new CacheLoader() { + public Block load(UUID key) { + return null; + } + }); + private static Set notified = new HashSet<>(); + // Helper functions - public static Block putSignOn(Block block, BlockFace blockface, String line1, String line2){ + public static Block putSignOn(Block block, BlockFace blockface, String line1, String line2, Material material) { Block newsign = block.getRelative(blockface); - newsign.setType(Material.WALL_SIGN); + Material blockType = Material.getMaterial(material.name().replace("_SIGN", "_WALL_SIGN")); + if (blockType != null && Tag.WALL_SIGNS.isTagged(blockType)) { + newsign.setType(blockType); + } else { + newsign.setType(Material.OAK_WALL_SIGN); + } BlockData data = newsign.getBlockData(); if(data instanceof Directional){ ((Directional) data).setFacing(blockface); @@ -65,13 +83,18 @@ public static void removeASign(Player player){ public static void updateSign(Block block){ ((Sign)block.getState()).update(); } - - public static Block getSelectedSign(Player player){ - return selectedsign.get(player); + + public static Block getSelectedSign(Player player) { + Block b = selectedsign.getIfPresent(player.getUniqueId()); + if (b != null && !player.getWorld().getName().equals(b.getWorld().getName())) { + selectedsign.invalidate(player.getUniqueId()); + return null; + } + return b; } public static void selectSign(Player player, Block block){ - selectedsign.put(player, block); + selectedsign.put(player.getUniqueId(), block); } public static void playLockEffect(Player player, Block block){ @@ -90,10 +113,10 @@ public static void sendMessages(CommandSender sender, String messages){ } public static boolean shouldNotify(Player player){ - if (notified.contains(player)){ + if (notified.contains(player.getUniqueId())){ return false; } else { - notified.add(player); + notified.add(player.getUniqueId()); return true; } } diff --git a/src/main/java/me/crafter/mc/lockettepro/Version.java b/src/main/java/me/crafter/mc/lockettepro/Version.java index f79ca14..fa8e2c1 100644 --- a/src/main/java/me/crafter/mc/lockettepro/Version.java +++ b/src/main/java/me/crafter/mc/lockettepro/Version.java @@ -2,7 +2,6 @@ public enum Version { - v1_13_R2, - LEGACY, UNKNOWN; - + v1_14_R1, UNKNOWN; + } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 606f9ce..366734d 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -32,7 +32,10 @@ timer-signs: lockables: - CHEST - TRAPPED_CHEST +- BARREL - FURNACE +- SMOKER +- BLAST_FURNACE - HOPPER - BREWING_STAND - DIAMOND_BLOCK