diff --git a/plugins/randomspawn-paper/Random Spawn/.classpath b/plugins/randomspawn-paper/Random Spawn/.classpath index 47647761b..4c02a858b 100644 --- a/plugins/randomspawn-paper/Random Spawn/.classpath +++ b/plugins/randomspawn-paper/Random Spawn/.classpath @@ -2,6 +2,6 @@ - + diff --git a/plugins/randomspawn-paper/Random Spawn/Random Spawn.jardesc b/plugins/randomspawn-paper/Random Spawn/Random Spawn.jardesc new file mode 100644 index 000000000..f2b5c12c1 --- /dev/null +++ b/plugins/randomspawn-paper/Random Spawn/Random Spawn.jardesc @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/randomspawn-paper/Random Spawn/plugin.yml b/plugins/randomspawn-paper/Random Spawn/plugin.yml index 4c974bcbc..b44a2d8df 100644 --- a/plugins/randomspawn-paper/Random Spawn/plugin.yml +++ b/plugins/randomspawn-paper/Random Spawn/plugin.yml @@ -5,76 +5,62 @@ author: Josvth commands: randomspawn: description: The main command. - usage: Incorrect usage! Try /rs help + usage: Command not found! Try /rs help aliases: rs - help: + rs help: description: Shows a list with all the commands. usage: /rs help [1/2/3] permission: RandomSpawn.help - prefix: randomspawn - reload: + rs reload: description: Reloads the Random Spawn config files. usage: /rs reload [config/worlds/spawnlocations] permission: RandomSpawn.reload - prefix: randomspawn - info: + rs info: description: Shows the Random Spawn settings for this world. usage: /rs info permission: RandomSpawn.info - prefix: randomspawn - enable: + rs enable: description: Enables Random Spawn in this world. usage: /rs enable permission: RandomSpawn.configure - prefix: randomspawn - disable: + rs disable: description: Disables Random Spawn in this world. usage: /rs disable permission: RandomSpawn.configure - prefix: randomspawn - - setarea: + rs setarea: description: Sets the Random Spawn area. usage: /rs setarea [square/circle] or /rs setarea or /rs setarea permission: RandomSpawn.configure - prefix: randomspawn - usebeds: + rs usebeds: description: Toggles using beds. usage: /rs usebeds [true/false] permission: RandomSpawn.configure - prefix: randomspawn - keepfirstspawns: + rs keepfirstspawns: description: Toggles spawn saving. usage: /rs keepfirstspawns [true/false] aliases: kfs permission: RandomSpawn.configure - prefix: randomspawn - firstjoin: + rs firstjoin: description: Toggles randomspawning on first join. usage: /rs firstjoin [true/false] aliases: fj permission: RandomSpawn.configure - prefix: randomspawn - - setfirstspawn: + rs setfirstspawn: description: Sets the first spawn location for this world. usage: /rs setfirstspawn aliases: sfs permission: RandomSpawn.setfirstspawn - prefix: randomspawn - tpfirstspawn: + rs tpfirstspawn: description: Teleports you to the first spawn location of this world. usage: /rs tpfirstspawn aliases: tfs permission: RandomSpawn.tpfirstspawn - prefix: randomspawn - unsetfirstspawn: + rs unsetfirstspawn: description: Unsets the first spawn location for this world. usage: /rs unsetfirstspawn aliases: unsfs permission: RandomSpawn.setfirstspawn - prefix: randomspawn - + permissions: RandomSpawn.*: description: Gives access to all Random Spawn commands. diff --git a/plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/Listeners/RandomSpawnDeathListener.java b/plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/Listeners/RandomSpawnDebugListener.java similarity index 70% rename from plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/Listeners/RandomSpawnDeathListener.java rename to plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/Listeners/RandomSpawnDebugListener.java index e0b308346..8a53eeb10 100644 --- a/plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/Listeners/RandomSpawnDeathListener.java +++ b/plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/Listeners/RandomSpawnDebugListener.java @@ -6,23 +6,21 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDeathEvent; - -public class RandomSpawnDeathListener implements Listener { - - RandomSpawn plugin; - - public RandomSpawnDeathListener(RandomSpawn instance){ + +public class RandomSpawnDebugListener implements Listener { + private RandomSpawn plugin; + + public RandomSpawnDebugListener(RandomSpawn instance) { plugin = instance; - plugin.getServer().getPluginManager().registerEvents(this, this.plugin); + plugin.getServer().getPluginManager().registerEvents(this, plugin); } - + @EventHandler public void onPlayerDeath(EntityDeathEvent event){ if(event.getEntity() instanceof Player){ - Player player = (Player) event.getEntity(); + Player player = (Player)event.getEntity(); plugin.logDebug(player.getName() + " died from " + player.getLastDamageCause().getCause().name()); plugin.logDebug(player.getName() + " Falldistance: " + player.getFallDistance() + " Velocity: " + player.getVelocity() + " No damage tickes: " + player.getNoDamageTicks() + " Location: " + player.getLocation()); } } - } diff --git a/plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/Listeners/RandomSpawnJoinListener.java b/plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/Listeners/RandomSpawnJoinListener.java index 1f3000f3d..b32e9c0a9 100644 --- a/plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/Listeners/RandomSpawnJoinListener.java +++ b/plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/Listeners/RandomSpawnJoinListener.java @@ -28,7 +28,7 @@ public class RandomSpawnJoinListener implements Listener { World world = player.getWorld(); String worldName = world.getName(); - File file = new File(world.getWorldFolder() + "/players/" + player.getName() + ".dat"); + File file = new File(world.getWorldFolder() + File.separator + "players" + File.separator + player.getName() + ".dat"); if(file.exists()){ return; } // checks if its not the first join of a player diff --git a/plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/Listeners/RandomSpawnRespawnListener.java b/plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/Listeners/RandomSpawnRespawnListener.java index d031915b7..d66f362cd 100644 --- a/plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/Listeners/RandomSpawnRespawnListener.java +++ b/plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/Listeners/RandomSpawnRespawnListener.java @@ -14,12 +14,13 @@ public class RandomSpawnRespawnListener implements Listener { private RandomSpawn plugin; public RandomSpawnRespawnListener(RandomSpawn instance){ - this.plugin = instance; - this.plugin.getServer().getPluginManager().registerEvents(this, this.plugin); + plugin = instance; + plugin.getServer().getPluginManager().registerEvents(this, plugin); } @EventHandler public void onPlayerRespawn(PlayerRespawnEvent event){ + Player player = event.getPlayer(); String playerName = player.getName(); @@ -28,17 +29,17 @@ public class RandomSpawnRespawnListener implements Listener { Location deathLocation = player.getLocation(); - if (player.hasPermission("RandomSpawn.exclude")){ // checks if player should be excluded + if (player.hasPermission("RandomSpawn.exclude")){ // checks if player should be excluded this.plugin.logDebug(playerName + " is excluded from Random Spawning."); return; } - if (event.isBedSpawn() && this.plugin.getYamlHandler().worlds.getBoolean(worldName + ".usebeds", true)){ + if (event.isBedSpawn() && this.plugin.getYamlHandler().worlds.getBoolean(worldName + ".usebeds", true)){ // checks if player should be spawned at his bed this.plugin.logDebug(playerName + " is spawned at his bed!"); return; } - if (this.plugin.getYamlHandler().worlds.getBoolean(worldName + ".keeprandomspawns", false)){ // checks if player should be spawned at a saved spawn + if (this.plugin.getYamlHandler().worlds.getBoolean(worldName + ".keeprandomspawns", false)){ // checks if player should be spawned at a saved spawn Location savedSpawn = getPlayerSpawn(player, world); if (savedSpawn != null){ event.setRespawnLocation(savedSpawn); @@ -54,6 +55,7 @@ public class RandomSpawnRespawnListener implements Listener { this.plugin.logDebug(playerName + " is teleported somewhere in the sky."); plugin.randomSpawnPlayer(player, world); + } } diff --git a/plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/RandomSpawn.java b/plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/RandomSpawn.java index 42cab3dd1..67e9320d4 100644 --- a/plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/RandomSpawn.java +++ b/plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/RandomSpawn.java @@ -1,27 +1,30 @@ package me.Josvth.RandomSpawn; import java.util.HashMap; +import java.util.logging.Logger; +import org.bukkit.ChatColor; import org.bukkit.World; +import org.bukkit.World.Environment; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import me.Josvth.RandomSpawn.Listeners.*; public class RandomSpawn extends JavaPlugin{ - - protected RandomSpawnLogger logger; - RandomSpawnYamlHandler yamlHandler; + + Logger logger; + + private RandomSpawnYamlHandler yamlHandler; RandomSpawnCommandHandler commandHandler; RandomSpawnRespawnListener respawnListener; RandomSpawnJoinListener joinListener; - RandomSpawnDeathListener deathListener; RandomSpawnSignListener signListener; + RandomSpawnDebugListener debugListener; public HashMap tasks = new HashMap(); - - + @Override public void onDisable() { for(RandomSpawnSpawner spawner : tasks.values()){ @@ -32,47 +35,48 @@ public class RandomSpawn extends JavaPlugin{ @Override public void onEnable() { - //setup handlers - this.logger = new RandomSpawnLogger(this); + logger = Logger.getLogger("Minecraft"); - this.yamlHandler = new RandomSpawnYamlHandler(this); + //setup handlers + yamlHandler = new RandomSpawnYamlHandler(this); logDebug("Yamls loaded!"); - this.commandHandler = new RandomSpawnCommandHandler(this); + commandHandler = new RandomSpawnCommandHandler(this); logDebug("Commands registered!"); //setup listeners - this.respawnListener = new RandomSpawnRespawnListener(this); - this.joinListener = new RandomSpawnJoinListener(this); - this.deathListener = new RandomSpawnDeathListener(this); - this.signListener = new RandomSpawnSignListener(this); + respawnListener = new RandomSpawnRespawnListener(this); + joinListener = new RandomSpawnJoinListener(this); + signListener = new RandomSpawnSignListener(this); + + if(getYamlHandler().config.getBoolean("debug",false)){ + debugListener = new RandomSpawnDebugListener(this); + } } - - public void playerInfo(Player player, String message){ - this.logger.playerInfo(player, message); - } - + public void logInfo(String message){ - this.logger.info(message); + logger.info("[Random Spawn] " + message); } public void logDebug(String message){ - if (yamlHandler.config.getBoolean("debug",false)) { - this.logger.debug(message); - } + if (yamlHandler.config.getBoolean("debug",false)) { logger.info("[Random Spawn] (DEBUG) " + message); } } - public void logWarning(String message){ - this.logger.warn(message); + public void playerInfo(Player player, String message){ + player.sendMessage(ChatColor.AQUA + "[RandomSpawn] " + ChatColor.RESET + message); } - + public RandomSpawnYamlHandler getYamlHandler(){ return yamlHandler; } - + + public boolean hasValidEnviroment(World world){ + return world.getEnvironment() != Environment.NETHER; + } + public void randomSpawnPlayer(Player player, World spawnWorld) { RandomSpawnSpawner spawner = new RandomSpawnSpawner(this, player, spawnWorld); - spawner.setTaskId(this.getServer().getScheduler().scheduleSyncRepeatingTask(this, spawner, 0, this.yamlHandler.config.getInt("generator.interval",4))); + spawner.setTaskId(getServer().getScheduler().scheduleSyncRepeatingTask(this, spawner, 0, yamlHandler.config.getInt("generator.interval",4))); player.setMaximumNoDamageTicks(12000); player.setNoDamageTicks(12000); player.sendMessage(yamlHandler.config.getString("messages.pleasewait", "Please wait while your spawn is being loaded.")); diff --git a/plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/RandomSpawnCommandExecutor.java b/plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/RandomSpawnCommandExecutor.java index dc9b0644b..222de6ec3 100644 --- a/plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/RandomSpawnCommandExecutor.java +++ b/plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/RandomSpawnCommandExecutor.java @@ -4,25 +4,29 @@ import java.util.List; import org.bukkit.command.CommandSender; - public abstract class RandomSpawnCommandExecutor { protected RandomSpawn plugin; protected String name; public void setPlugin(RandomSpawn instance) { - this.plugin = instance; + plugin = instance; } public abstract boolean onCommand(CommandSender sender, List args); + public boolean onConsoleCommand(CommandSender sender, List args){ + return onCommand(sender,args); + } + public String getName() { return name; } + public String getDescription() { try { - return plugin.getCommand(name).getDescription(); + return plugin.getCommand("rs " + name).getDescription(); } catch (NullPointerException e){ return null; } @@ -30,15 +34,23 @@ public abstract class RandomSpawnCommandExecutor { public String getUsage() { try { - return plugin.getCommand(name).getUsage(); + return plugin.getCommand("rs " + name).getUsage(); } catch (NullPointerException e){ return null; } } - + + public String getPermission() { + try { + return plugin.getCommand("rs " + name).getPermission(); + } catch (NullPointerException e){ + return null; + } + } + public List getAliases() { try { - return plugin.getCommand(name).getAliases(); + return plugin.getCommand("rs " + name).getAliases(); } catch (NullPointerException e) { return null; } diff --git a/plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/RandomSpawnCommandHandler.java b/plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/RandomSpawnCommandHandler.java index e51b5dc1b..3e5fd041b 100644 --- a/plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/RandomSpawnCommandHandler.java +++ b/plugins/randomspawn-paper/Random Spawn/src/me/Josvth/RandomSpawn/RandomSpawnCommandHandler.java @@ -38,7 +38,6 @@ public class RandomSpawnCommandHandler implements CommandExecutor{ } } } - } @Override @@ -52,7 +51,11 @@ public class RandomSpawnCommandHandler implements CommandExecutor{ sender.sendMessage("This command can only be used in game!"); return true; } - + + if (!sender.hasPermission(commandExecutor.getPermission())){ + sender.sendMessage("You don't have the permission to use this command!"); + } + if (commandExecutor.onCommand(sender, Arrays.asList(args).subList(1, args.length)) == false){ sender.sendMessage(commandExecutor.getUsage()); }