diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..a55e7a1
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 3220ab9..9e65dc8 100755
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -16,6 +16,8 @@
+
+
\ No newline at end of file
diff --git a/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java b/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java
index ca4c6bc..0df0374 100755
--- a/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java
+++ b/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java
@@ -65,6 +65,7 @@ public class MainPlugin extends JavaPlugin {
TBMCCoreAPI.SendException("Failed to write plugin list!", e);
}
ess = Essentials.getPlugin(Essentials.class);
+ new RandomTP().onEnable(this); //It registers it's command
logger.info(pdfFile.getName() + " has been Enabled (V." + pdfFile.getVersion() + ") Test: " + Test + ".");
}
diff --git a/ButtonCore/src/main/java/buttondevteam/core/RandomTP.java b/ButtonCore/src/main/java/buttondevteam/core/RandomTP.java
new file mode 100644
index 0000000..bc5d224
--- /dev/null
+++ b/ButtonCore/src/main/java/buttondevteam/core/RandomTP.java
@@ -0,0 +1,251 @@
+package buttondevteam.core;
+
+import buttondevteam.lib.chat.CommandClass;
+import buttondevteam.lib.chat.TBMCChatAPI;
+import buttondevteam.lib.chat.TBMCCommandBase;
+import org.bukkit.*;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.java.JavaPlugin;
+
+// @formatter:off
+@CommandClass
+public class RandomTP extends TBMCCommandBase
+{
+ private final int radius = 70; //set how far apart the five teleport positions are
+
+ private World 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(JavaPlugin plugin)
+ {
+ TBMCChatAPI.AddCommand(plugin, this);
+
+ world = Bukkit.getWorld("World");
+ border = world.getWorldBorder();
+ newLocation();
+ }
+
+ /*================================================================================================*/
+
+ public String[] GetHelpText(String alias)
+ {
+ return new String[]
+ {
+ "§6---- Random Teleport ----",
+ "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."
+ };
+ }
+
+ /*================================================================================================*/
+
+ public boolean OnCommand(CommandSender sender, String command, String[] args)
+ {
+ if (args.length == 0) return false;
+
+ if (sender.isOp()) return rtp(Bukkit.getPlayer(args[0]));
+
+ else sender.sendMessage("§7 hmm, " + sender.getName() + "... " + sender.getName() + "... nope, no operator permissions.");
+
+ return false;
+ }
+
+ /*================================================================================================*/
+
+ public synchronized boolean rtp(Player player)
+ {
+ if (player == null)
+ return false; //Pretend it rtp'd an imaginary player successfully
+
+ //if border has changed, or no positions available, find new location
+ if ((centerUsed && northUsed && southUsed && eastUsed && westUsed) ||
+
+ (borderCenterX != border.getCenter().getX() ||
+ borderCenterZ != border.getCenter().getZ() ||
+ size != border.getSize())
+
+ && !newLocation())
+ {
+ //if unable to find new location, message player and return false
+ 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.getCenter().getX();
+ borderCenterZ = border.getCenter().getZ();
+
+ //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.getCenter().getX());
+ centerZ = (int) (Math.floor((Math.random() - 0.5) * usableSize) + border.getCenter().getZ());
+
+ //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;
+ }
+}
diff --git a/ButtonCore/src/main/resources/plugin.yml b/ButtonCore/src/main/resources/plugin.yml
index e60f586..c638c1c 100755
--- a/ButtonCore/src/main/resources/plugin.yml
+++ b/ButtonCore/src/main/resources/plugin.yml
@@ -9,3 +9,5 @@ commands:
description: Schedules a restart for a given time.
primerestart:
description: Restarts the server as soon as nobody is online.
+ 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