diff --git a/src/com/cnaude/chairs/core/Chairs.java b/src/com/cnaude/chairs/core/Chairs.java index 04f7129..babdf2c 100644 --- a/src/com/cnaude/chairs/core/Chairs.java +++ b/src/com/cnaude/chairs/core/Chairs.java @@ -6,6 +6,7 @@ import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.UUID; @@ -31,10 +32,10 @@ import com.cnaude.chairs.vehiclearrow.NMSAccess; public class Chairs extends JavaPlugin { - public HashSet sitDisabled = new HashSet(); - public ChairEffects chairEffects; - public List allowedBlocks; - public List validSigns; + public final HashSet sitDisabled = new HashSet<>(); + public final HashMap validChairs = new HashMap<>(); + public final List validSigns = new ArrayList(); + public final HashSet sitDisabledCommands = new HashSet<>(); public boolean autoRotate, signCheck, notifyplayer; public boolean ignoreIfBlockInHand; public double distance; @@ -45,8 +46,6 @@ public class Chairs extends JavaPlugin { public int sitHealInterval; public boolean sitPickupEnabled; public boolean sitDisableAllCommands = false; - public HashSet sitDisabledCommands = new HashSet(); - private Logger log; public String msgSitting, msgStanding, msgOccupied, msgNoPerm, msgReloaded, msgDisabled, msgEnabled, msgCommandRestricted; @@ -59,6 +58,9 @@ public class Chairs extends JavaPlugin { return nmsaccess; } + + public ChairEffects chairEffects; + @Override public void onEnable() { log = this.getLogger(); @@ -125,7 +127,8 @@ public class Chairs extends JavaPlugin { sitPickupEnabled = config.getBoolean("sit-effects.itempickup.enabled", false); sitDisableAllCommands = config.getBoolean("sit-restrictions.commands.all"); - sitDisabledCommands = new HashSet(config.getStringList("sit-restrictions.commands.list")); + sitDisabledCommands.clear(); + sitDisabledCommands.addAll(config.getStringList("sit-restrictions.commands.list")); msgSitting = ChatColor.translateAlternateColorCodes('&',config.getString("messages.sitting")); msgStanding = ChatColor.translateAlternateColorCodes('&',config.getString("messages.standing")); @@ -136,7 +139,7 @@ public class Chairs extends JavaPlugin { msgReloaded = ChatColor.translateAlternateColorCodes('&',config.getString("messages.reloaded")); msgCommandRestricted = ChatColor.translateAlternateColorCodes('&',config.getString("messages.command-restricted")); - allowedBlocks = new ArrayList(); + validChairs.clear(); for (String s : config.getStringList("sit-blocks")) { String type; double sh = 0.7; @@ -148,18 +151,17 @@ public class Chairs extends JavaPlugin { Material mat = Material.matchMaterial(type); if (mat != null) { logInfo("Allowed block: " + mat.toString() + " => " + sh); - allowedBlocks.add(new ChairBlock(mat,sh)); + validChairs.put(mat, sh); } else { logError("Invalid block: " + type); } } - validSigns = new ArrayList(); + validSigns.clear(); for (String type : config.getStringList("valid-signs")) { try { validSigns.add(Material.matchMaterial(type)); - } - catch (Exception e) { + } catch (Exception e) { logError(e.getMessage()); } } @@ -199,6 +201,8 @@ public class Chairs extends JavaPlugin { } } + private Logger log; + public void logInfo(String _message) { log.log(Level.INFO, _message); } diff --git a/src/com/cnaude/chairs/listeners/TrySitEventListener.java b/src/com/cnaude/chairs/listeners/TrySitEventListener.java index cc5ea0c..cd9f395 100644 --- a/src/com/cnaude/chairs/listeners/TrySitEventListener.java +++ b/src/com/cnaude/chairs/listeners/TrySitEventListener.java @@ -156,13 +156,10 @@ public class TrySitEventListener implements Listener { } private Location getSitLocation(Block block, Float playerYaw) { - double sh = 0.7; - for (ChairBlock cb : plugin.allowedBlocks) { - if (cb.getMat().equals(block.getType())) { - sh = cb.getSitHeight(); - break; - } + Double sh = plugin.validChairs.get(block.getType()); + if (sh == null) { + sh = 0.7; } Stairs stairs = null; @@ -204,12 +201,7 @@ public class TrySitEventListener implements Listener { private boolean isValidChair(Block block) { - for (ChairBlock cb : plugin.allowedBlocks) { - if (cb.getMat().equals(block.getType())) { - return true; - } - } - return false; + return plugin.validChairs.containsKey(block.getType()); } private boolean isSitting(Player player) {