From 40a41f1a70d8594471f27c15e2d6e01b3c679038 Mon Sep 17 00:00:00 2001 From: Maxopoly Date: Sun, 12 Jan 2020 23:20:32 +0100 Subject: [PATCH] Update to 1.14 --- pom.xml | 20 +- .../me/josvth/randomspawn/RandomSpawn.java | 257 ++++++++++-------- .../commands/AddSpawnPointCommand.java | 2 +- .../randomspawn/handlers/CommandHandler.java | 3 +- .../randomspawn/handlers/YamlHandler.java | 19 +- .../listeners/RespawnListener.java | 26 +- .../randomspawn/listeners/SignListener.java | 15 +- 7 files changed, 179 insertions(+), 163 deletions(-) diff --git a/pom.xml b/pom.xml index b206302..21611a4 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 me.josvth.randomspawn.randomspawn RandomSpawn - 2.7.6 + 2.8.0 RandomSpawn https://github.com/DevotedMC/random-spawn @@ -22,34 +22,28 @@ org.spigotmc spigot - 1.10.2-R0.1-SNAPSHOT + 1.14.4-R0.1-SNAPSHOT provided com.wimbli.WorldBorder WorldBorder - 1.8.7 + 1.9.10 jar provided isaac Bastion - 2.0.2 + 2.3.0 jar provided vg.civcraft.mc.civmodcore CivModCore - 1.5.09 + 1.7.7 provided - - - org.mcstats.bukkit - metrics - - @@ -66,8 +60,8 @@ maven-compiler-plugin 3.0 - 1.7 - 1.7 + 1.8 + 1.8 diff --git a/src/main/java/me/josvth/randomspawn/RandomSpawn.java b/src/main/java/me/josvth/randomspawn/RandomSpawn.java index d43e6f8..410a843 100644 --- a/src/main/java/me/josvth/randomspawn/RandomSpawn.java +++ b/src/main/java/me/josvth/randomspawn/RandomSpawn.java @@ -5,16 +5,14 @@ import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.LinkedList; import java.util.List; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.World.Environment; -import org.bukkit.block.Block; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; @@ -26,7 +24,7 @@ import me.josvth.randomspawn.handlers.YamlHandler; import me.josvth.randomspawn.listeners.*; -public class RandomSpawn extends JavaPlugin{ +public class RandomSpawn extends JavaPlugin { public YamlHandler yamlHandler; CommandHandler commandHandler; @@ -37,120 +35,123 @@ public class RandomSpawn extends JavaPlugin{ DamageListener damageListener; private boolean isWorldBorderEnabled = false; private boolean isBastionsEnabled = false; - private static List defaultBlacklist = Arrays.asList(new Integer[]{8,9,10,11,18,51,81}); - + + private static List defaultBlackList = Arrays.asList( + new Material[] { Material.WATER, Material.LAVA, Material.FIRE, Material.CACTUS, Material.MAGMA_BLOCK }); + @Override public void onEnable() { - //setup handlers + // setup handlers yamlHandler = new YamlHandler(this); logDebug("Yamls loaded!"); commandHandler = new CommandHandler(this); logDebug("Commands registered!"); - //setup listeners + // setup listeners respawnListener = new RespawnListener(this); joinListener = new JoinListener(this); worldChangeListener = new WorldChangeListener(this); signListener = new SignListener(this); damageListener = new DamageListener(this); - + isWorldBorderEnabled = getServer().getPluginManager().isPluginEnabled("WorldBorder"); isBastionsEnabled = getServer().getPluginManager().isPluginEnabled("Bastion"); } - public void logInfo(String message){ + public void logInfo(String message) { getLogger().info(message); } - public void logDebug(String message){ - if (yamlHandler.config.getBoolean("debug",false)) { getLogger().info("(DEBUG) " + message); } + public void logDebug(String message) { + if (yamlHandler.config.getBoolean("debug", false)) { + getLogger().info("(DEBUG) " + message); + } } - public void logWarning(String message){ + public void logWarning(String message) { getLogger().warning(message); } - public void playerInfo(Player player, String message){ + public void playerInfo(Player player, String message) { player.sendMessage(ChatColor.AQUA + "[RandomSpawn] " + ChatColor.RESET + message); } // *------------------------------------------------------------------------------------------------------------* - // | The following chooseSpawn methods contains code made by NuclearW | - // | based on his SpawnArea plugin: | - // | http://forums.bukkit.org/threads/tp-spawnarea-v0-1-spawns-targetPlayers-in-a-set-area-randomly-1060.20408/ | + // | The following chooseSpawn methods contains code made by NuclearW | + // | based on his SpawnArea plugin: | + // | + // http://forums.bukkit.org/threads/tp-spawnarea-v0-1-spawns-targetPlayers-in-a-set-area-randomly-1060.20408/ + // | // *------------------------------------------------------------------------------------------------------------* - public Location chooseSpawn(World world){ + public Location chooseSpawn(World world) { String worldName = world.getName(); + List blacklist = getMaterialBlackList(worldName); + if (yamlHandler.worlds.getBoolean(worldName + ".spawnbyplayer")) { + List playersOnline = world.getPlayers(); - List blacklist = defaultBlacklist; - if( yamlHandler.worlds.contains( worldName + ".spawnblacklist") ) - blacklist = yamlHandler.worlds.getIntegerList(worldName + ".spawnblacklist"); - - if(yamlHandler.worlds.getBoolean(worldName + ".spawnbyplayer")) { - List playersOnline = (List) world.getPlayers(); - - if(playersOnline.size() > 0) { - Player randomPlayer = playersOnline.get((int)(Math.random() * playersOnline.size())); + if (!playersOnline.isEmpty()) { + Player randomPlayer = playersOnline.get((int) (Math.random() * playersOnline.size())); Location spawnNear = randomPlayer.getLocation(); - + double radius = yamlHandler.worlds.getDouble(worldName + ".spawnbyplayerarea.radius", 500); - - double exclusionRadius = yamlHandler.worlds.getDouble(worldName + ".spawnbyplayerarea.exclusionradius", 0); - + + double exclusionRadius = yamlHandler.worlds.getDouble(worldName + ".spawnbyplayerarea.exclusionradius", + 0); + return chooseSpawn(radius, exclusionRadius, spawnNear, blacklist); } } - - String type = yamlHandler.worlds.getString(worldName +".spawnarea.type", "square"); + + String type = yamlHandler.worlds.getString(worldName + ".spawnarea.type", "square"); Location ret; - if(type.equalsIgnoreCase("square")) { - double xmin = yamlHandler.worlds.getDouble(worldName +".spawnarea.x-min", -100); - double xmax = yamlHandler.worlds.getDouble(worldName +".spawnarea.x-max", 100); - double zmin = yamlHandler.worlds.getDouble(worldName +".spawnarea.z-min", -100); - double zmax = yamlHandler.worlds.getDouble(worldName +".spawnarea.z-max", 100); + if (type.equalsIgnoreCase("square")) { + double xmin = yamlHandler.worlds.getDouble(worldName + ".spawnarea.x-min", -100); + double xmax = yamlHandler.worlds.getDouble(worldName + ".spawnarea.x-max", 100); + double zmin = yamlHandler.worlds.getDouble(worldName + ".spawnarea.z-min", -100); + double zmax = yamlHandler.worlds.getDouble(worldName + ".spawnarea.z-max", 100); // Spawn area thickness near border. If 0 spawns whole area - int thickness = yamlHandler.worlds.getInt(worldName +".spawnarea.thickness", 0); - + int thickness = yamlHandler.worlds.getInt(worldName + ".spawnarea.thickness", 0); + ret = chooseSpawn(world, xmin, xmax, zmin, zmax, thickness, blacklist); - }else if(type.equalsIgnoreCase("circle")) { + } else if (type.equalsIgnoreCase("circle")) { double exclusionRadius = yamlHandler.worlds.getDouble(worldName + ".spawnarea.exclusionradius", 0); double radius = yamlHandler.worlds.getDouble(worldName + ".spawnarea.radius", 100); double xcenter = yamlHandler.worlds.getDouble(worldName + ".spawnarea.xcenter", 0); double zcenter = yamlHandler.worlds.getDouble(worldName + ".spawnarea.zcenter", 0); - - ret = chooseSpawn(radius, exclusionRadius, new Location(world, xcenter, 0, zcenter), blacklist); - } else{ + + ret = chooseSpawn(radius, exclusionRadius, new Location(world, xcenter, 0, zcenter), blacklist); + } else { return null; } - - if (isWorldBorderEnabled){ + + if (isWorldBorderEnabled) { BorderData border = WorldBorder.plugin.getWorldBorder(world.getName()); - if (border != null){ - if (border.insideBorder(ret) == false){ + if (border != null) { + if (!border.insideBorder(ret)) { return chooseSpawn(world); } } } - if (isBastionsEnabled){ - BastionBlockManager bm = Bastion.getBastionManager(); - if (bm != null){ - if (bm.getBlockingBastion(ret) != null){ + if (isBastionsEnabled) { + BastionBlockManager bm = Bastion.getBastionManager(); + if (bm != null) { + if (bm.getBlockingBastion(ret) != null) { return chooseSpawn(world); } } } - + return ret; - + } - - private Location chooseSpawn(double radius, double exclusionRadius, Location center, List blacklist) { + + private Location chooseSpawn(double radius, double exclusionRadius, Location center, List blacklist) { Location result = new Location(center.getWorld(), center.getX(), center.getY(), center.getZ()); - + int maxTries = 50 * (int) radius; if (maxTries < 50) { maxTries = 50; @@ -158,7 +159,7 @@ private Location chooseSpawn(double radius, double exclusionRadius, Location cen if (maxTries > 1000) { maxTries = 1000; // sensible limits plz } - + do { double r = exclusionRadius + Math.random() * (radius - exclusionRadius); double phi = Math.random() * 2d * Math.PI; @@ -169,41 +170,39 @@ private Location chooseSpawn(double radius, double exclusionRadius, Location cen result.setX(x); result.setZ(z); result.setY(getValidHighestY(center.getWorld(), x, z, blacklist)); - } while (result.getY() == -1 && --maxTries >= 0); + } while (result.getY() == -1 && --maxTries >= 0); return result; } - - private Location chooseSpawn(World world, double xmin, double xmax, double zmin, double zmax, double thickness, List blacklist) { + + private Location chooseSpawn(World world, double xmin, double xmax, double zmin, double zmax, double thickness, + List blacklist) { Location result = new Location(world, xmin, 0, zmin); - - if(thickness <= 0) { + + if (thickness <= 0) { do { - double x = xmin + Math.random()*(xmax - xmin + 1); - double z = zmin + Math.random()*(zmax - zmin + 1); + double x = xmin + Math.random() * (xmax - xmin + 1); + double z = zmin + Math.random() * (zmax - zmin + 1); result.setX(x); result.setZ(z); result.setY(getValidHighestY(world, x, z, blacklist)); - } while(result.getY() == -1); - }else { + } while (result.getY() == -1); + } else { do { double x = 0, z = 0; int side = (int) (Math.random() * 4d); - double borderOffset = Math.random() * (double) thickness; + double borderOffset = Math.random() * thickness; if (side == 0) { x = xmin + borderOffset; // Also balancing probability considering thickness - z = zmin + Math.random() * (zmax - zmin + 1 - 2*thickness) + thickness; - } - else if (side == 1) { + z = zmin + Math.random() * (zmax - zmin + 1 - 2 * thickness) + thickness; + } else if (side == 1) { x = xmax - borderOffset; - z = zmin + Math.random() * (zmax - zmin + 1 - 2*thickness) + thickness; - } - else if (side == 2) { + z = zmin + Math.random() * (zmax - zmin + 1 - 2 * thickness) + thickness; + } else if (side == 2) { x = xmin + Math.random() * (xmax - xmin + 1); z = zmin + borderOffset; - } - else { + } else { x = xmin + Math.random() * (xmax - xmin + 1); z = zmax - borderOffset; } @@ -216,33 +215,34 @@ else if (side == 2) { return result; } - private double getValidHighestY(World world, double x, double z, List blacklist) { + private double getValidHighestY(World world, double x, double z, List blacklist) { world.getChunkAt(new Location(world, x, 0, z)).load(); - double y = 0; - int blockid = 0; - - if(world.getEnvironment().equals(Environment.NETHER)) { - int blockYid = world.getBlockTypeIdAt((int) x, (int) y, (int) z); - int blockY2id = world.getBlockTypeIdAt((int) x, (int) (y+1), (int) z); - while(y < 128 && !(blockYid == 0 && blockY2id == 0)) { + Material blockMat = Material.AIR; + if (world.getEnvironment() == Environment.NETHER) { + Material blockYMat = world.getBlockAt((int)x,(int) y,(int) z).getType(); + Material blockY2Mat = world.getBlockAt((int)x,(int) y+1,(int) z).getType(); + while (y < 128 && !(blockYMat == Material.AIR && blockY2Mat == Material.AIR)) { y++; - blockYid = blockY2id; - blockY2id = world.getBlockTypeIdAt((int) x, (int) (y+1), (int) z); + blockYMat = blockY2Mat; + blockY2Mat = world.getBlockAt((int)x,(int) y+1,(int) z).getType(); } - if(y == 127) return -1; - }else { + if (y == 127) + return -1; + } else { y = 257; - while(y >= 0 && blockid == 0) { + while (y >= 0 && blockMat == Material.AIR) { y--; - blockid = world.getBlockTypeIdAt((int) x, (int) y, (int) z); + blockMat = world.getBlockAt((int)x,(int) y,(int) z).getType(); } - if(y == 0) return -1; - y++; + if (y == 0) + return -1; + y++; } - if (blacklist.contains(blockid)) return -1; - if (blacklist.contains(81) && world.getBlockTypeIdAt((int) x, (int) (y+1), (int) z) == 81) return -1; // Check for cacti + if (blacklist.contains(blockMat)) { + return -1; + } return y; } @@ -255,50 +255,51 @@ public void sendGround(Player player, Location location) { } /** - * Finds all the valid spawn points from the full set of configured spawn points in the world. What is valid? - * Spawn points can configurably require another player to be nearby, or allow spawn there regardless of nearby - * players. This function checks that, and checks it against the online players. If a player is sufficiently near - * as determined by the "checkradius", or if not set, the "radius" of the spawn point, then use that point. - * Of course if a nearby player is not required, the spawn point is added. + * Finds all the valid spawn points from the full set of configured spawn points + * in the world. What is valid? Spawn points can configurably require another + * player to be nearby, or allow spawn there regardless of nearby players. This + * function checks that, and checks it against the online players. If a player + * is sufficiently near as determined by the "checkradius", or if not set, the + * "radius" of the spawn point, then use that point. Of course if a nearby + * player is not required, the spawn point is added. * - * The final result of these checks is returned as the set of eligible spawn points; from which one will ultimately - * be chosen and used. + * The final result of these checks is returned as the set of eligible spawn + * points; from which one will ultimately be chosen and used. * * @author ProgrammerDan - * @param world The world to restrict the check to. Only players from that world are considered. + * @param world The world to restrict the check to. Only players from that world + * are considered. * @return The set of locations near valid spawn points; or an empty list. */ - @SuppressWarnings("unchecked") public List findSpawnPoints(World world) { String worldName = world.getName(); - + if (!yamlHandler.worlds.contains(worldName + ".spawnpoints")) { - return new ArrayList(0); + return new ArrayList<>(0); } - - LinkedList spawnLocs = new LinkedList(); - - List blacklist = defaultBlacklist; - if( yamlHandler.worlds.contains( worldName + ".spawnblacklist") ) - blacklist = yamlHandler.worlds.getIntegerList(worldName + ".spawnblacklist"); - + + LinkedList spawnLocs = new LinkedList<>(); + + List blacklist = getMaterialBlackList(world.getName()); + // reserve list of online players : TODO make sure this is just online players List playersOnline = world.getPlayers(); // For each potential spawn location ... ConfigurationSection spawnpoints = yamlHandler.worlds.getConfigurationSection(worldName + ".spawnpoints"); if (spawnpoints == null) { - return new ArrayList(0); + return new ArrayList<>(0); } for (String spawnpointlabel : spawnpoints.getKeys(false)) { ConfigurationSection spawnpoint = spawnpoints.getConfigurationSection(spawnpointlabel); - Location location = new Location(world, spawnpoint.getDouble("x"), - spawnpoint.getDouble("y"), spawnpoint.getDouble("z")); + Location location = new Location(world, spawnpoint.getDouble("x"), spawnpoint.getDouble("y"), + spawnpoint.getDouble("z")); boolean skip = true; // check if a player must be nearby and look for a player if so if (spawnpoint.getBoolean("nearby")) { for (Player player : playersOnline) { - if (location.distance(player.getLocation()) < spawnpoint.getDouble("checkradius", spawnpoint.getDouble("radius", 0d))) { + if (location.distance(player.getLocation()) < spawnpoint.getDouble("checkradius", + spawnpoint.getDouble("radius", 0d))) { skip = false; break; } @@ -308,13 +309,33 @@ public List findSpawnPoints(World world) { } if (!skip) { // Now pick a location to spawn the player. - Location derive = chooseSpawn(spawnpoint.getDouble("radius"), spawnpoint.getDouble("exclusion"), location, blacklist); + Location derive = chooseSpawn(spawnpoint.getDouble("radius"), spawnpoint.getDouble("exclusion"), + location, blacklist); if (derive != null) { spawnLocs.add(derive); } } } - + return spawnLocs; } + + private List getMaterialBlackList(String worldName) { + if (yamlHandler.worlds.isList(worldName + ".spawnblacklist")) { + List result = new LinkedList<>(); + List matIdentifiers = yamlHandler.worlds.getStringList(worldName + ".spawnblacklist"); + for (String identifier : matIdentifiers) { + Material mat; + try { + mat = Material.valueOf(identifier); + } + catch (IllegalArgumentException e) { + getLogger().severe(identifier + " is not a valid material"); + continue; + } + result.add(mat); + } + } + return defaultBlackList; + } } diff --git a/src/main/java/me/josvth/randomspawn/commands/AddSpawnPointCommand.java b/src/main/java/me/josvth/randomspawn/commands/AddSpawnPointCommand.java index 8020e15..b1f4511 100644 --- a/src/main/java/me/josvth/randomspawn/commands/AddSpawnPointCommand.java +++ b/src/main/java/me/josvth/randomspawn/commands/AddSpawnPointCommand.java @@ -6,7 +6,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.MemorySection; import org.bukkit.entity.Player; /** @@ -21,6 +20,7 @@ public AddSpawnPointCommand(RandomSpawn instance){ super(instance,"addspawn"); } + @Override public boolean onCommand(CommandSender sender, List args){ if (!(sender instanceof Player)) { sender.sendMessage("For console users, please manually add spawn points to the worlds.yml and reload."); diff --git a/src/main/java/me/josvth/randomspawn/handlers/CommandHandler.java b/src/main/java/me/josvth/randomspawn/handlers/CommandHandler.java index 8fcfab2..79b5b6f 100644 --- a/src/main/java/me/josvth/randomspawn/handlers/CommandHandler.java +++ b/src/main/java/me/josvth/randomspawn/handlers/CommandHandler.java @@ -16,7 +16,7 @@ public class CommandHandler implements CommandExecutor{ final RandomSpawn plugin; - HashMap commands = new HashMap(); + HashMap commands = new HashMap<>(); public CommandHandler(RandomSpawn instance) { plugin = instance; @@ -56,6 +56,7 @@ private void registerCommands(AbstractCommand[] abstractCommands) { } } + @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (args.length == 0 || !commands.containsKey(args[0])) return false; diff --git a/src/main/java/me/josvth/randomspawn/handlers/YamlHandler.java b/src/main/java/me/josvth/randomspawn/handlers/YamlHandler.java index da124a4..43b7593 100644 --- a/src/main/java/me/josvth/randomspawn/handlers/YamlHandler.java +++ b/src/main/java/me/josvth/randomspawn/handlers/YamlHandler.java @@ -6,22 +6,23 @@ import me.josvth.randomspawn.RandomSpawn; +import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; public class YamlHandler{ - RandomSpawn plugin; + private RandomSpawn plugin; File configFile; - File worldsFile; + File worldsFile; File spawnLocationsFile; public FileConfiguration config; public FileConfiguration worlds; - public YamlHandler(RandomSpawn instance) { - plugin = instance; + public YamlHandler(RandomSpawn plugin) { + this.plugin = plugin; setupYamls(); loadYamls(); } @@ -48,8 +49,8 @@ public void loadYamls() { public void loadConfig(){ try { config.load(configFile); - } catch (Exception e) { - e.printStackTrace(); + } catch (IOException | InvalidConfigurationException e) { + plugin.getLogger().severe("Failed to load config" + e.toString()); } } @@ -57,7 +58,7 @@ public void loadWorlds(){ try { worlds.load(worldsFile); } catch (Exception e) { - e.printStackTrace(); + plugin.getLogger().severe("Failed to load config" + e.toString()); } } @@ -70,7 +71,7 @@ public void saveConfig() { try { config.save(configFile); } catch (IOException e) { - e.printStackTrace(); + plugin.getLogger().severe("Failed to save config" + e.toString()); } } @@ -78,7 +79,7 @@ public void saveWorlds() { try { worlds.save(worldsFile); } catch (IOException e) { - e.printStackTrace(); + plugin.getLogger().severe("Failed to save worlds" + e.toString()); } } diff --git a/src/main/java/me/josvth/randomspawn/listeners/RespawnListener.java b/src/main/java/me/josvth/randomspawn/listeners/RespawnListener.java index 4bfba34..1acc5a7 100644 --- a/src/main/java/me/josvth/randomspawn/listeners/RespawnListener.java +++ b/src/main/java/me/josvth/randomspawn/listeners/RespawnListener.java @@ -1,37 +1,35 @@ package me.josvth.randomspawn.listeners; import java.util.List; -import java.util.Set; +import java.util.Random; import me.josvth.randomspawn.RandomSpawn; import me.josvth.randomspawn.events.NewPlayerSpawn; import org.bukkit.ChatColor; import org.bukkit.Location; -import org.bukkit.Material; +import org.bukkit.Tag; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.metadata.FixedMetadataValue; -import net.minecraft.server.v1_10_R1.BlockPosition; - public class RespawnListener implements Listener{ - RandomSpawn plugin; + private RandomSpawn plugin; + private Random rng; - public RespawnListener (RandomSpawn instance){ - plugin = instance; + public RespawnListener (RandomSpawn plugin){ + this.plugin = plugin; + this.rng = new Random(); plugin.getServer().getPluginManager().registerEvents(this, plugin); } @EventHandler public void onPlayerRespawn(PlayerRespawnEvent event){ - Player player = event.getPlayer(); String playerName = player.getName(); @@ -47,10 +45,10 @@ public void onPlayerRespawn(PlayerRespawnEvent event){ List spawnPointFlags = plugin.yamlHandler.worlds.getStringList(worldName + ".spawnpointson"); if (event.isBedSpawn() && !randomSpawnFlags.contains("bedrespawn")){ // checks if player should be spawned at his bed - BlockPosition pos = ((CraftPlayer)event.getPlayer()).getHandle().getBed(); - if (pos != null) { - Block bed = new Location(event.getRespawnLocation().getWorld(), pos.getX(), pos.getY(), pos.getZ()).getBlock(); - if(bed.getType() == Material.BED_BLOCK) { + Location loc = event.getPlayer().getBedSpawnLocation(); + if (loc != null) { + Block bed = loc.getBlock(); + if(Tag.BEDS.isTagged(bed.getType())) { plugin.logDebug(playerName + " is spawned at his bed!"); return; } @@ -73,7 +71,7 @@ public void onPlayerRespawn(PlayerRespawnEvent event){ int totalTries = spawnLocations.size(); for (int i = 0 ; i < totalTries ; i++) { - int j = (int) ( Math.random() * spawnLocations.size() ); + int j = rng.nextInt(spawnLocations.size()); Location newSpawn = spawnLocations.get(j); NewPlayerSpawn nps = new NewPlayerSpawn(player, newSpawn ); plugin.getServer().getPluginManager().callEvent(nps); diff --git a/src/main/java/me/josvth/randomspawn/listeners/SignListener.java b/src/main/java/me/josvth/randomspawn/listeners/SignListener.java index 22cab33..d43ee86 100644 --- a/src/main/java/me/josvth/randomspawn/listeners/SignListener.java +++ b/src/main/java/me/josvth/randomspawn/listeners/SignListener.java @@ -3,8 +3,9 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Tag; import org.bukkit.World; -import org.bukkit.block.Block; import org.bukkit.block.Sign; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -17,19 +18,19 @@ import me.josvth.randomspawn.RandomSpawn; public class SignListener implements Listener { - RandomSpawn plugin; + private RandomSpawn plugin; - public SignListener(RandomSpawn instance) { - plugin = instance; + public SignListener(RandomSpawn plugin) { + this.plugin = plugin; plugin.getServer().getPluginManager().registerEvents(this, plugin); } @EventHandler public void onPlayerSignInteract(PlayerInteractEvent event){ if(event.getAction() == Action.RIGHT_CLICK_BLOCK){ - Block block = event.getClickedBlock(); - if (block.getTypeId() == 68 || block.getTypeId() == 63){ - Sign sign = (Sign)block.getState(); + Material mat = event.getClickedBlock().getType(); + if (Tag.WALL_SIGNS.isTagged(mat)){ + Sign sign = (Sign)event.getClickedBlock().getState(); final Player player = event.getPlayer(); if (sign.getLine(0).equalsIgnoreCase(plugin.yamlHandler.config.getString("rs-sign-text","[RandomSpawn]") ) ){