diff --git a/src/randomSpawn/EventListener.java b/src/randomSpawn/EventListener.java index bafc73e..a2a1ff5 100644 --- a/src/randomSpawn/EventListener.java +++ b/src/randomSpawn/EventListener.java @@ -7,41 +7,36 @@ * version: 1.0.0 */ -//import randomSpawn; import cn.nukkit.Player; import cn.nukkit.event.EventHandler; import cn.nukkit.event.Listener; import cn.nukkit.event.player.PlayerRespawnEvent; -import cn.nukkit.level.Location; import cn.nukkit.level.Position; -//import cn.nukkit.plugin.PluginBase; + import java.util.Random; public class EventListener implements Listener { + //final variables private final randomSpawn rndspawn; - //private int x; - //private int y; - //private int z; - private Location pos; + + //mutable variables + private int x; + private int y; + private int z; + public EventListener(randomSpawn rndspawn){ this.rndspawn = rndspawn; } - @EventHandler(ignoreCancelled = false) //watch out + @EventHandler public void onRespawn(PlayerRespawnEvent event){ Player player = event.getPlayer(); - // player.sendChat("debug: "+ rndspawn.maxRange); //test code - //this.getLogger() Random rnd = new Random(); - int x = rnd.nextInt(rndspawn.maxRange); - int z = rnd.nextInt(rndspawn.maxRange); - //int y = player.getLevel().getHighestBlockAt(x, z) + 1; - int y = 100; - //player.sendChat("debug: "+ x + ", " + y + " ," + z); //test code - //pos = new Location(x, y, z, player.getLevel()); - //player.teleportImmediate(pos); + x = rnd.nextInt(rndspawn.maxRange); + z = rnd.nextInt(rndspawn.maxRange); + y = player.getLevel().getHeightMap(x, z) + 3; event.setRespawnPosition(new Position(x,y,z,player.getLevel())); } diff --git a/src/randomSpawn/randomSpawn.java b/src/randomSpawn/randomSpawn.java index 465e8be..74626fe 100644 --- a/src/randomSpawn/randomSpawn.java +++ b/src/randomSpawn/randomSpawn.java @@ -23,7 +23,6 @@ public class randomSpawn extends PluginBase{ public String maxRangeInStr; public int rnge; - //private EventListener event; @Override public void onLoad() { this.getLogger().info(TextFormat.GREEN + "randomSpawn is loaded!"); @@ -35,14 +34,7 @@ public void onLoad() { public void onEnable() { this .getServer().getPluginManager().registerEvents(new EventListener(this), this); - this.getLogger().info(TextFormat.WHITE + "randomSpawn enabled!"); - - - //this.getLogger().info(String.valueOf(this.getDataFolder().mkdirs())); - -// this.getServer().getScheduler().scheduleRepeatingTask(new BroadcastPluginTask(this), 200); - -// this.saveResource("test.txt"); + this.getLogger().info(TextFormat.YELLOW + "randomSpawn enabled!"); Config config = new Config( @@ -63,9 +55,6 @@ public void onEnable() { maxRangeInStr = String.valueOf(config.get("spawnRange")); - - //this.getLogger().info(String.valueOf(getMaxRange(maxRangeInStr))); //test code - //this.getLogger().info("this is just a test"); //test code config.save(); setMaxRange(getMaxRange(maxRangeInStr)); @@ -76,10 +65,7 @@ public void onEnable() { public int getMaxRange(String rangeInStr) { - //@SuppressWarnings("deprecation") - //Integer newInt = new Integer(maxRangeInStr); int range = Integer.valueOf(rangeInStr); - return range; } @@ -90,7 +76,7 @@ public void setMaxRange(int range) { public void onDisable() { - this.getLogger().info("randomSpawn disabled!"); + this.getLogger().info(TextFormat.RED + "randomSpawn disabled!"); }