Created an RTP method

This commit is contained in:
alisolarflare 2016-08-27 01:07:32 -04:00
parent 090430c864
commit e12cb68799
2 changed files with 40 additions and 0 deletions

View file

@ -0,0 +1,39 @@
package alisolarflare;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;
public class RandomTP{
//Randomly teleports a player, into the hardcore world
public void rtp(Player player, World world, Location minLocation, Location maxLocation){
//INIT - xDifference, xAverage
int xdifference = minLocation.getBlockX() - maxLocation.getBlockX();
int xAverage = (int) Math.floor(minLocation.getBlockX() + maxLocation.getBlockX() / 2);
//INIT - zDifference, zAverage
int zdifference = minLocation.getBlockX() - maxLocation.getBlockY();
int zAverage = (int) Math.floor(minLocation.getBlockZ() + maxLocation.getBlockZ());
//TELEPORTS - Tries 20 times to find a location
for(int i = 0; i < 20; i ++){
//INIT - attemptedX, attemptedZ
int attemptedX = (int) Math.floor((Math.random()-0.5)*xdifference) + xAverage;
int attemptedZ = (int) Math.floor((Math.random()-0.5)*zdifference) + zAverage;
//CHECKS - if ground is safe
boolean groundisSafe = world.getHighestBlockAt(attemptedX, attemptedZ).getType() != Material.WATER;
if (groundisSafe){
player.teleport(world.getHighestBlockAt(attemptedX, attemptedZ).getLocation());
return;
}
//player.teleport(arg0)
}
}
}

View file

@ -7,6 +7,7 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class HelloWorld implements CommandExecutor {
HelloWorldPlugin plugin;