diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..be86bf9
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.gitignore b/.gitignore
index 6143e53..b18c726 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,3 +20,6 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
+
+bin/
+target/
diff --git a/.project b/.project
new file mode 100644
index 0000000..159ef42
--- /dev/null
+++ b/.project
@@ -0,0 +1,23 @@
+
+
+ RandomTeleport_
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.m2e.core.maven2Builder
+
+
+
+
+
+ org.eclipse.m2e.core.maven2Nature
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..672496e
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,12 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 0000000..f897a7f
--- /dev/null
+++ b/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/plugin.yml b/plugin.yml
new file mode 100644
index 0000000..a694840
--- /dev/null
+++ b/plugin.yml
@@ -0,0 +1,6 @@
+main: randomTP.Main
+version: 1.0.0
+name: RandomTP
+commands:
+ randomtp:
+ description: teleport player to random location within world border. Every five players teleport to the same general area, and then a new general area is randomly selected for the next five players.
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..2309391
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,55 @@
+
+ 4.0.0
+ TBMCPlugins
+ RandomTeleport
+ 0.0.1-SNAPSHOT
+
+ src
+
+
+ src
+
+ **/*.java
+
+
+
+ .
+
+
+
+
+ maven-compiler-plugin
+ 3.5.1
+
+ 1.8
+ 1.8
+
+
+
+
+
+
+ spigot-repo
+ https://hub.spigotmc.org/nexus/content/repositories/snapshots/
+
+
+ jitpack.io
+ https://jitpack.io/
+
+
+
+
+ org.spigotmc
+ spigot-api
+ 1.12-R0.1-SNAPSHOT
+ provided
+
+
+ org.bukkit
+ craftbukkit
+ 1.12-R0.1-SNAPSHOT
+ provided
+
+
+
\ No newline at end of file
diff --git a/src/randomTP/Main.java b/src/randomTP/Main.java
new file mode 100644
index 0000000..ecf2d50
--- /dev/null
+++ b/src/randomTP/Main.java
@@ -0,0 +1,235 @@
+package randomTP;
+
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import net.minecraft.server.v1_12_R1.WorldBorder;
+
+public class Main extends JavaPlugin
+{
+ private final int radius = 70; //set how far apart the five teleport positions are
+
+ private CraftWorld world;
+ private WorldBorder border;
+ private double size,
+ usableSize,
+ borderCenterX,
+ borderCenterZ,
+
+ x,z;
+
+ private int centerX, centerZ, centerY,
+ northZ, southZ, eastX, westX,
+ northY, southY, eastY, westY;
+
+ private Material centerGroundMaterial, centerFeetMaterial, centerHeadMaterial,
+ northGroundMaterial, northFeetMaterial, northHeadMaterial,
+ southGroundMaterial, southFeetMaterial, southHeadMaterial,
+ eastGroundMaterial, eastFeetMaterial, eastHeadMaterial,
+ westGroundMaterial, westFeetMaterial, westHeadMaterial;
+
+ private Location center,
+ north,
+ south,
+ east,
+ west;
+
+ private boolean centerUsed,
+ northUsed,
+ southUsed,
+ eastUsed,
+ westUsed;
+
+ private StringBuilder availableDirections = new StringBuilder(5);
+ private char[] chars = {1,2,3,4,5};
+ private int dir;
+
+ /*================================================================================================*/
+
+ public void onEnable()
+ {
+ getCommand("randomtp").setExecutor(this);
+
+ world = (CraftWorld) Bukkit.getWorld("World");
+ border = world.getHandle().getWorldBorder();
+ newLocation();
+ }
+
+ /*================================================================================================*/
+
+ public boolean onCommand(CommandSender sender, Command label, String command, String[] args)
+ {
+ if (sender.isOp()) return rtp(Bukkit.getPlayer(args[0])); else return false;
+ }
+
+ /*================================================================================================*/
+
+ public synchronized boolean rtp(Player player)
+ {
+ if (player == null)
+ return false;
+
+ //if border has changed, or no positions available, find new location
+ if ((centerUsed && northUsed && southUsed && eastUsed && westUsed) ||
+
+ (borderCenterX != border.getCenterX() ||
+ borderCenterZ != border.getCenterZ() ||
+ size != border.getSize())
+
+ && !newLocation())
+ {
+ //message player and return false if unable to find new location
+ player.sendMessage("§c could not find a location in 10,000 attempts");
+ player.sendMessage("§c (sorry bud... I did try!)");
+ return false;
+ }
+
+ //randomly select one of the open positions and teleport the player there, then remove the position
+ switch(availableDirections.charAt(dir = (int) Math.floor(Math.random() * availableDirections.length())))
+ {
+ case (char) 1: player.teleport(center); centerUsed = true; break;
+ case (char) 2: player.teleport(north ); northUsed = true; break;
+ case (char) 3: player.teleport(south ); southUsed = true; break;
+ case (char) 4: player.teleport(east ); eastUsed = true; break;
+ case (char) 5: player.teleport(west ); westUsed = true; break;
+ }
+ availableDirections.deleteCharAt(dir);
+
+ //imply that our server has a personality
+ player.sendMessage("§7 *poof*");
+
+ //if all 5 positions have been teleported to, choose a new location
+ if (centerUsed && northUsed && southUsed && eastUsed && westUsed)
+ newLocation();
+
+ return true;
+ }
+
+ /*================================================================================================*/
+
+ public synchronized boolean newLocation()
+ {
+ size = border.getSize();
+ usableSize = size - (radius * 2);
+ borderCenterX = border.getCenterX();
+ borderCenterZ = border.getCenterZ();
+
+ //maximum ten thousand attempts
+ for (int i = 0; i < 10000; i++)
+ {
+ //choose an x and z inside the current world border, allowing a margin for the outer positions
+ centerX = (int) (Math.floor((Math.random() - 0.5) * usableSize) + border.getCenterX());
+ centerZ = (int) (Math.floor((Math.random() - 0.5) * usableSize) + border.getCenterZ());
+
+ //get center of block
+ x = centerX + .5;
+ z = centerZ + .5;
+
+ //get other coordinates
+ northZ = centerZ - radius;
+ southZ = centerZ + radius;
+ eastX = centerX + radius;
+ westX = centerX - radius;
+
+ centerY = world.getHighestBlockYAt( centerX , centerZ );
+ northY = world.getHighestBlockYAt( centerX , northZ );
+ southY = world.getHighestBlockYAt( centerX , southZ );
+ eastY = world.getHighestBlockYAt( eastX , centerZ );
+ westY = world.getHighestBlockYAt( westX , centerZ );
+
+ //get materials for ground, feet-height and head-height blocks at each of the five positions
+ centerGroundMaterial = world.getBlockAt( centerX , centerY -1 , centerZ ).getType();
+ northGroundMaterial = world.getBlockAt( centerX , northY -1 , northZ ).getType();
+ southGroundMaterial = world.getBlockAt( centerX , southY -1 , southZ ).getType();
+ eastGroundMaterial = world.getBlockAt( eastX , eastY -1 , centerZ ).getType();
+ westGroundMaterial = world.getBlockAt( westX , westY -1 , centerZ ).getType();
+
+ centerFeetMaterial = world.getBlockAt( centerX , centerY , centerZ ).getType();
+ northFeetMaterial = world.getBlockAt( centerX , northY , northZ ).getType();
+ southFeetMaterial = world.getBlockAt( centerX , southY , southZ ).getType();
+ eastFeetMaterial = world.getBlockAt( eastX , eastY , centerZ ).getType();
+ westFeetMaterial = world.getBlockAt( westX , westY , centerZ ).getType();
+
+ centerHeadMaterial = world.getBlockAt( centerX , centerY +1 , centerZ ).getType();
+ northHeadMaterial = world.getBlockAt( centerX , northY +1 , northZ ).getType();
+ southHeadMaterial = world.getBlockAt( centerX , southY +1 , southZ ).getType();
+ eastHeadMaterial = world.getBlockAt( eastX , eastY +1 , centerZ ).getType();
+ westHeadMaterial = world.getBlockAt( westX , westY +1 , centerZ ).getType();
+
+ //test that all five positions are on solid ground with air at head height
+ if (centerHeadMaterial == Material.AIR &&
+ northHeadMaterial == Material.AIR &&
+ southHeadMaterial == Material.AIR &&
+ eastHeadMaterial == Material.AIR &&
+ westHeadMaterial == Material.AIR &&
+
+ centerFeetMaterial == Material.AIR &&
+ northFeetMaterial == Material.AIR &&
+ southFeetMaterial == Material.AIR &&
+ eastFeetMaterial == Material.AIR &&
+ westFeetMaterial == Material.AIR &&
+
+ centerGroundMaterial != Material.AIR &&
+ northGroundMaterial != Material.AIR &&
+ southGroundMaterial != Material.AIR &&
+ eastGroundMaterial != Material.AIR &&
+ westGroundMaterial != Material.AIR &&
+
+ centerGroundMaterial != Material.STATIONARY_WATER &&
+ northGroundMaterial != Material.STATIONARY_WATER &&
+ southGroundMaterial != Material.STATIONARY_WATER &&
+ eastGroundMaterial != Material.STATIONARY_WATER &&
+ westGroundMaterial != Material.STATIONARY_WATER &&
+
+ centerGroundMaterial != Material.WATER &&
+ northGroundMaterial != Material.WATER &&
+ southGroundMaterial != Material.WATER &&
+ eastGroundMaterial != Material.WATER &&
+ westGroundMaterial != Material.WATER &&
+
+ centerGroundMaterial != Material.STATIONARY_LAVA &&
+ northGroundMaterial != Material.STATIONARY_LAVA &&
+ southGroundMaterial != Material.STATIONARY_LAVA &&
+ eastGroundMaterial != Material.STATIONARY_LAVA &&
+ westGroundMaterial != Material.STATIONARY_LAVA &&
+
+ centerGroundMaterial != Material.LAVA &&
+ northGroundMaterial != Material.LAVA &&
+ southGroundMaterial != Material.LAVA &&
+ eastGroundMaterial != Material.LAVA &&
+ westGroundMaterial != Material.LAVA)
+ {
+ //set new positions and reset
+ center = new Location( world, x , (double) centerY , z );
+ north = new Location( world, x , (double) northY , northZ + .5 );
+ south = new Location( world, x , (double) southY , southZ + .5 );
+ east = new Location( world, eastX + .5 , (double) eastY , z );
+ west = new Location( world, westX + .5 , (double) westY , z );
+
+ availableDirections.setLength(0);
+ availableDirections.append(chars);
+
+ centerUsed =
+ northUsed =
+ southUsed =
+ eastUsed =
+ westUsed = false;
+
+ return true;
+ }
+ }
+ centerUsed =
+ northUsed =
+ southUsed =
+ eastUsed =
+ westUsed = true;
+
+ return false;
+ }
+}