From e12cb6879980f87ac0f1d50ea08cedd433b22114 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Sat, 27 Aug 2016 01:07:32 -0400 Subject: [PATCH] Created an RTP method --- src/alisolarflare/RandomTP.java | 39 +++++++++++++++++++++++++++++++++ src/iie/HelloWorld.java | 1 + 2 files changed, 40 insertions(+) create mode 100644 src/alisolarflare/RandomTP.java diff --git a/src/alisolarflare/RandomTP.java b/src/alisolarflare/RandomTP.java new file mode 100644 index 0000000..a2378d4 --- /dev/null +++ b/src/alisolarflare/RandomTP.java @@ -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) + } + } +} diff --git a/src/iie/HelloWorld.java b/src/iie/HelloWorld.java index 972943f..9f08ff6 100644 --- a/src/iie/HelloWorld.java +++ b/src/iie/HelloWorld.java @@ -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;