Skip to content

Commit

Permalink
Merge pull request #1 from maxxie114/update
Browse files Browse the repository at this point in the history
Fix randomSpawn drop players to death issue
  • Loading branch information
maxxie114 authored Jul 27, 2018
2 parents 46e47d2 + bbd47a2 commit 63bfea0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 33 deletions.
29 changes: 12 additions & 17 deletions src/randomSpawn/EventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}

Expand Down
18 changes: 2 additions & 16 deletions src/randomSpawn/randomSpawn.java
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand All @@ -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(
Expand All @@ -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));
Expand All @@ -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;
}

Expand All @@ -90,7 +76,7 @@ public void setMaxRange(int range) {


public void onDisable() {
this.getLogger().info("randomSpawn disabled!");
this.getLogger().info(TextFormat.RED + "randomSpawn disabled!");
}


Expand Down

0 comments on commit 63bfea0

Please # to comment.