Created an RTP method
This commit is contained in:
parent
090430c864
commit
e12cb68799
2 changed files with 40 additions and 0 deletions
39
src/alisolarflare/RandomTP.java
Normal file
39
src/alisolarflare/RandomTP.java
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
||||||
public class HelloWorld implements CommandExecutor {
|
public class HelloWorld implements CommandExecutor {
|
||||||
|
|
||||||
HelloWorldPlugin plugin;
|
HelloWorldPlugin plugin;
|
||||||
|
|
Loading…
Reference in a new issue