From 193dbb9365ce61a14c44292a83f54fe42f83275d Mon Sep 17 00:00:00 2001 From: iie Date: Sat, 27 May 2017 12:42:00 +0200 Subject: [PATCH 1/8] v1 --- .classpath | 6 ++ .gitignore | 3 + .project | 17 ++++ .settings/org.eclipse.jdt.core.prefs | 11 +++ src/randomTP/Main.java | 141 +++++++++++++++++++++++++++ src/randomTP/plugin.yml | 3 + 6 files changed, 181 insertions(+) create mode 100644 .classpath create mode 100644 .project create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 src/randomTP/Main.java create mode 100644 src/randomTP/plugin.yml diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..fceb480 --- /dev/null +++ b/.classpath @@ -0,0 +1,6 @@ + + + + + + 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..3ada7bc --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + RandomTeleport_ + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + 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..3a21537 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +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.source=1.8 diff --git a/src/randomTP/Main.java b/src/randomTP/Main.java new file mode 100644 index 0000000..769dcd7 --- /dev/null +++ b/src/randomTP/Main.java @@ -0,0 +1,141 @@ +package randomTP; + +import java.util.Random; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.craftbukkit.v1_11_R1.CraftWorld; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import net.minecraft.server.v1_11_R1.WorldBorder; + +public class Main extends JavaPlugin +{ + private static final Random random = new Random(); + + private static World world; + private static WorldBorder border; + private static double size, + borderCenterX, + borderCenterZ; + + private static int x,z; + private static final int radius = 70, + diameter = radius * 2; + + private static Location center, + north, + south, + east, + west; + + private static boolean centerUsed, + northUsed, + southUsed, + eastUsed, + westUsed; + + private static StringBuffer availableDirections = new StringBuffer(5); + private static int dir; + + /*================================================================================================*/ + + public void onEnable() + { + world = Bukkit.getWorld("World"); + border = ((CraftWorld) world).getHandle().getWorldBorder(); + + size = border.getSize(); + borderCenterX = border.getCenterX(); + borderCenterZ = border.getCenterZ(); + + getCommand("randomtp").setExecutor(this); + } + + /*================================================================================================*/ + + 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 newLocation() + { + //MAXIMUM TEN THOUSAND ATTEMPTS + for (int i = 0; i < 10000; i++) + { + //CHOOSE A RANDOM LOCATION WITHIN THE WORLDBORDER, ALLOWING SPACE FOR OUTER POSITIONS + x = (int) Math.floor((random.nextDouble() - 0.5) * (size - diameter)) + center.getBlockX(); + z = (int) Math.floor((random.nextDouble() - 0.5) * (size - diameter)) + center.getBlockY(); + + //CHECK THAT CENTER AND OUTER POSITIONS DO NOT HAVE WATER AT THEIR HIGHEST BLOCKS + if (world.getHighestBlockAt( x , z ).getType() != Material.WATER && + world.getHighestBlockAt( x , z - radius ).getType() != Material.WATER && + world.getHighestBlockAt( x , z + radius ).getType() != Material.WATER && + world.getHighestBlockAt( x - radius , z ).getType() != Material.WATER && + world.getHighestBlockAt( x + radius , z ).getType() != Material.WATER) + { + //IF NEW LOCATION CHECKS OUT, RESET VALUES + availableDirections.setCharAt(0, (char) 1); + availableDirections.setCharAt(1, (char) 2); + availableDirections.setCharAt(2, (char) 3); + availableDirections.setCharAt(3, (char) 4); + availableDirections.setCharAt(4, (char) 5); + + center = world.getHighestBlockAt( x , z ).getLocation(); + north = world.getHighestBlockAt( x , z - radius ).getLocation(); + south = world.getHighestBlockAt( x , z + radius ).getLocation(); + east = world.getHighestBlockAt( x + radius , z ).getLocation(); + west = world.getHighestBlockAt( x - radius , z ).getLocation(); + + centerUsed = northUsed = southUsed = eastUsed = westUsed = false; + + return true; + } + } + return false; + } + + + public synchronized boolean rtp(Player player) + { + if (player == null) + return false; + + //IF ALL POSITIONS USED, CHOOSE NEW LOCATION, AND IF NEW LOCATION FAILS RETURN FALSE + if (centerUsed && northUsed && southUsed && eastUsed && westUsed && !newLocation()) + return false; + + //IF BORDER HAS CHANGED, CHOOSE NEW LOCATION, AND IF NEW LOCATION FAILS RETURN FALSE + if ((borderCenterX != (borderCenterX = border.getCenterX()) || + borderCenterZ != (borderCenterZ = border.getCenterZ()) || + size != (size = border.getSize())) && !newLocation()) + return false; + + //CHOOSE ONE OF THE FIVE POSITIONS RANDOMLY AND TELEPORT THE PLAYER THERE, THEN REMOVE THAT POSITION + switch(dir = availableDirections.charAt((int) Math.floor(random.nextDouble() * 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); + + //IF ALL POSITIONS USED, CHOOSE A NEW LOCATION FOR NEXT ROUND + if (centerUsed && northUsed && southUsed && eastUsed && westUsed) + newLocation(); + + return true; + } +} diff --git a/src/randomTP/plugin.yml b/src/randomTP/plugin.yml new file mode 100644 index 0000000..4061ef4 --- /dev/null +++ b/src/randomTP/plugin.yml @@ -0,0 +1,3 @@ +main: randomTP.Main +version: 1.0.0 +name: RandomTP \ No newline at end of file From 9cf9f5f72ec250d4608dcc739fb6040689c02ef3 Mon Sep 17 00:00:00 2001 From: iie Date: Sun, 28 May 2017 12:00:00 +0200 Subject: [PATCH 2/8] v2 --- src/randomTP/Main.java | 96 +++++++++++++++++++++-------------------- src/randomTP/plugin.yml | 5 ++- 2 files changed, 53 insertions(+), 48 deletions(-) diff --git a/src/randomTP/Main.java b/src/randomTP/Main.java index 769dcd7..bd144c5 100644 --- a/src/randomTP/Main.java +++ b/src/randomTP/Main.java @@ -1,7 +1,5 @@ package randomTP; -import java.util.Random; - import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -16,45 +14,45 @@ import net.minecraft.server.v1_11_R1.WorldBorder; public class Main extends JavaPlugin { - private static final Random random = new Random(); + private World world; + private WorldBorder border; + private double size, + borderCenterX, + borderCenterZ; - private static World world; - private static WorldBorder border; - private static double size, - borderCenterX, - borderCenterZ; + private int x,z; + private final int radius = 70; - private static int x,z; - private static final int radius = 70, - diameter = radius * 2; - - private static Location center, - north, - south, - east, - west; + private Location center, + north, + south, + east, + west; - private static boolean centerUsed, - northUsed, - southUsed, - eastUsed, - westUsed; + private boolean centerUsed, + northUsed, + southUsed, + eastUsed, + westUsed; - private static StringBuffer availableDirections = new StringBuffer(5); - private static int dir; + 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 = Bukkit.getWorld("World"); border = ((CraftWorld) world).getHandle().getWorldBorder(); - size = border.getSize(); + size = border.getSize() - (radius * 2); borderCenterX = border.getCenterX(); borderCenterZ = border.getCenterZ(); - getCommand("randomtp").setExecutor(this); + newLocation(); } /*================================================================================================*/ @@ -73,23 +71,20 @@ public class Main extends JavaPlugin //MAXIMUM TEN THOUSAND ATTEMPTS for (int i = 0; i < 10000; i++) { - //CHOOSE A RANDOM LOCATION WITHIN THE WORLDBORDER, ALLOWING SPACE FOR OUTER POSITIONS - x = (int) Math.floor((random.nextDouble() - 0.5) * (size - diameter)) + center.getBlockX(); - z = (int) Math.floor((random.nextDouble() - 0.5) * (size - diameter)) + center.getBlockY(); + //CHOOSE A RANDOM AREA WITHIN THE WORLDBORDER, ALLOWING SPACE FOR OUTER POSITIONS + x = (int) (Math.floor((Math.random() - 0.5) * size) + border.getCenterX()); + z = (int) (Math.floor((Math.random() - 0.5) * size) + border.getCenterZ()); //CHECK THAT CENTER AND OUTER POSITIONS DO NOT HAVE WATER AT THEIR HIGHEST BLOCKS - if (world.getHighestBlockAt( x , z ).getType() != Material.WATER && - world.getHighestBlockAt( x , z - radius ).getType() != Material.WATER && - world.getHighestBlockAt( x , z + radius ).getType() != Material.WATER && - world.getHighestBlockAt( x - radius , z ).getType() != Material.WATER && - world.getHighestBlockAt( x + radius , z ).getType() != Material.WATER) + if (!world.getHighestBlockAt( x , z ).getType().equals(Material.WATER) && + !world.getHighestBlockAt( x , z - radius ).getType().equals(Material.WATER) && + !world.getHighestBlockAt( x , z + radius ).getType().equals(Material.WATER) && + !world.getHighestBlockAt( x - radius , z ).getType().equals(Material.WATER) && + !world.getHighestBlockAt( x + radius , z ).getType().equals(Material.WATER)) { - //IF NEW LOCATION CHECKS OUT, RESET VALUES - availableDirections.setCharAt(0, (char) 1); - availableDirections.setCharAt(1, (char) 2); - availableDirections.setCharAt(2, (char) 3); - availableDirections.setCharAt(3, (char) 4); - availableDirections.setCharAt(4, (char) 5); + //IF NEW LOCATION IS VALID, RESET VALUES + availableDirections.setLength(0); + availableDirections.append(chars); center = world.getHighestBlockAt( x , z ).getLocation(); north = world.getHighestBlockAt( x , z - radius ).getLocation(); @@ -102,6 +97,8 @@ public class Main extends JavaPlugin return true; } } + centerUsed = northUsed = southUsed = eastUsed = westUsed = true; + return false; } @@ -111,18 +108,23 @@ public class Main extends JavaPlugin if (player == null) return false; - //IF ALL POSITIONS USED, CHOOSE NEW LOCATION, AND IF NEW LOCATION FAILS RETURN FALSE - if (centerUsed && northUsed && southUsed && eastUsed && westUsed && !newLocation()) - return false; + //IF NO POSITIONS AVAILABLE, OR BORDER HAS CHANGED, FIND NEW LOCATION + if (((centerUsed && northUsed && southUsed && eastUsed && westUsed) || - //IF BORDER HAS CHANGED, CHOOSE NEW LOCATION, AND IF NEW LOCATION FAILS RETURN FALSE - if ((borderCenterX != (borderCenterX = border.getCenterX()) || + borderCenterX != (borderCenterX = border.getCenterX()) || borderCenterZ != (borderCenterZ = border.getCenterZ()) || - size != (size = border.getSize())) && !newLocation()) + size != (size = border.getSize())) + + && !newLocation()) + { + //RETURN FALSE AND MESSAGE PLAYER IF UNABLE TO FIND NEW LOCATION. + player.sendMessage("could not find a location in 10,000 attempts"); + player.sendMessage("... sorry bud. I did try. 10,000 times."); return false; + } //CHOOSE ONE OF THE FIVE POSITIONS RANDOMLY AND TELEPORT THE PLAYER THERE, THEN REMOVE THAT POSITION - switch(dir = availableDirections.charAt((int) Math.floor(random.nextDouble() * availableDirections.length()))) + 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; diff --git a/src/randomTP/plugin.yml b/src/randomTP/plugin.yml index 4061ef4..a694840 100644 --- a/src/randomTP/plugin.yml +++ b/src/randomTP/plugin.yml @@ -1,3 +1,6 @@ main: randomTP.Main version: 1.0.0 -name: RandomTP \ No newline at end of file +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 From 29cfa66ae368f3dea175f48814d057e9952f890b Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Tue, 30 May 2017 22:16:36 +0200 Subject: [PATCH 3/8] Converted to Maven project --- .classpath | 20 ++++++++++-- .project | 6 ++++ .settings/org.eclipse.jdt.core.prefs | 1 + .settings/org.eclipse.m2e.core.prefs | 4 +++ pom.xml | 46 ++++++++++++++++++++++++++++ 5 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 .settings/org.eclipse.m2e.core.prefs create mode 100644 pom.xml diff --git a/.classpath b/.classpath index fceb480..be86bf9 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,20 @@ - - - + + + + + + + + + + + + + + + + + diff --git a/.project b/.project index 3ada7bc..159ef42 100644 --- a/.project +++ b/.project @@ -10,8 +10,14 @@ + + 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 index 3a21537..672496e 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -8,4 +8,5 @@ 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/pom.xml b/pom.xml new file mode 100644 index 0000000..acdc756 --- /dev/null +++ b/pom.xml @@ -0,0 +1,46 @@ + + 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.9.2-R0.1-SNAPSHOT + provided + + + \ No newline at end of file From d5edd0cfe664e7800e0b877f3a699d66b14b92c9 Mon Sep 17 00:00:00 2001 From: iie Date: Wed, 31 May 2017 00:30:00 +0200 Subject: [PATCH 4/8] v3 --- src/randomTP/Main.java | 139 +++++++++++++++++++++++++++++------------ 1 file changed, 98 insertions(+), 41 deletions(-) diff --git a/src/randomTP/Main.java b/src/randomTP/Main.java index bd144c5..20276ab 100644 --- a/src/randomTP/Main.java +++ b/src/randomTP/Main.java @@ -4,6 +4,7 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.block.Block; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.craftbukkit.v1_11_R1.CraftWorld; @@ -14,15 +15,25 @@ import net.minecraft.server.v1_11_R1.WorldBorder; public class Main extends JavaPlugin { - private World world; + private final int radius = 70; //set how far apart the five teleport positions are + + private CraftWorld world; private WorldBorder border; - private double size, + private double size, + usableSize, borderCenterX, borderCenterZ; - private int x,z; - private final int radius = 70; + private int x,z, + centerY, northY, southY, eastY, westY, + northZ, southZ, eastX, westX; + private Material centerGroundMaterial, centerHeadMaterial, + northGroundMaterial, northHeadMaterial, + southGroundMaterial, southHeadMaterial, + eastGroundMaterial, eastHeadMaterial, + westGroundMaterial, westHeadMaterial; + private Location center, north, south, @@ -43,17 +54,13 @@ public class Main extends JavaPlugin public void onEnable() { - getCommand("randomtp").setExecutor(this); - - world = Bukkit.getWorld("World"); - border = ((CraftWorld) world).getHandle().getWorldBorder(); - - size = border.getSize() - (radius * 2); - borderCenterX = border.getCenterX(); - borderCenterZ = border.getCenterZ(); + world = (CraftWorld) Bukkit.getWorld("World"); + border = world.getHandle().getWorldBorder(); newLocation(); - } + + getCommand("randomtp").setExecutor(this); + } /*================================================================================================*/ @@ -68,30 +75,79 @@ public class Main extends JavaPlugin 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 A RANDOM AREA WITHIN THE WORLDBORDER, ALLOWING SPACE FOR OUTER POSITIONS - x = (int) (Math.floor((Math.random() - 0.5) * size) + border.getCenterX()); - z = (int) (Math.floor((Math.random() - 0.5) * size) + border.getCenterZ()); + //RANDOMLY CHOOSE AN X AND Z WITHIN WORLD BORDER + x = (int) (Math.floor((Math.random() - 0.5) * usableSize) + border.getCenterX()); + z = (int) (Math.floor((Math.random() - 0.5) * usableSize) + border.getCenterZ()); - //CHECK THAT CENTER AND OUTER POSITIONS DO NOT HAVE WATER AT THEIR HIGHEST BLOCKS - if (!world.getHighestBlockAt( x , z ).getType().equals(Material.WATER) && - !world.getHighestBlockAt( x , z - radius ).getType().equals(Material.WATER) && - !world.getHighestBlockAt( x , z + radius ).getType().equals(Material.WATER) && - !world.getHighestBlockAt( x - radius , z ).getType().equals(Material.WATER) && - !world.getHighestBlockAt( x + radius , z ).getType().equals(Material.WATER)) + //GET OTHER COORDINATES + centerY = world.getHighestBlockYAt( x , z ); + northZ = z - radius; northY = world.getHighestBlockYAt( x , northZ ); + southZ = z + radius; southY = world.getHighestBlockYAt( x , southZ ); + eastX = x + radius; eastY = world.getHighestBlockYAt( eastX , z ); + westX = x - radius; westY = world.getHighestBlockYAt( westX , z ); + + //GET MATERIALS FOR GROUND AND HEAD-HEIGHT BLOCKS AT EACH POSITION + centerGroundMaterial = world.getBlockAt( x , centerY -1 , z ).getType(); + northGroundMaterial = world.getBlockAt( x , northY -1 , northZ ).getType(); + southGroundMaterial = world.getBlockAt( x , southY -1 , southZ ).getType(); + eastGroundMaterial = world.getBlockAt( eastX , eastY -1 , z ).getType(); + westGroundMaterial = world.getBlockAt( westX , westY -1 , z ).getType(); + + centerHeadMaterial = world.getBlockAt( x , centerY +1 , z ).getType(); + northHeadMaterial = world.getBlockAt( x , northY +1 , northZ ).getType(); + southHeadMaterial = world.getBlockAt( x , southY +1 , southZ ).getType(); + eastHeadMaterial = world.getBlockAt( eastX , eastY +1 , z ).getType(); + westHeadMaterial = world.getBlockAt( westX , westY +1 , z ).getType(); + + //CONFIRM 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 && + + 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) { - //IF NEW LOCATION IS VALID, RESET VALUES + //IF LOCATION VALID, SET NEW POSITIONS AND RESET TRACKING VARIABLES + center = world.getBlockAt( x , centerY , z ).getLocation(); + north = world.getBlockAt( x , northY , northZ ).getLocation(); + south = world.getBlockAt( x , southY , southZ ).getLocation(); + east = world.getBlockAt( eastX , eastY , z ).getLocation(); + west = world.getBlockAt( westX , westY , z ).getLocation(); + availableDirections.setLength(0); availableDirections.append(chars); - center = world.getHighestBlockAt( x , z ).getLocation(); - north = world.getHighestBlockAt( x , z - radius ).getLocation(); - south = world.getHighestBlockAt( x , z + radius ).getLocation(); - east = world.getHighestBlockAt( x + radius , z ).getLocation(); - west = world.getHighestBlockAt( x - radius , z ).getLocation(); - centerUsed = northUsed = southUsed = eastUsed = westUsed = false; return true; @@ -102,28 +158,29 @@ public class Main extends JavaPlugin return false; } + /*================================================================================================*/ public synchronized boolean rtp(Player player) { if (player == null) return false; - //IF NO POSITIONS AVAILABLE, OR BORDER HAS CHANGED, FIND NEW LOCATION - if (((centerUsed && northUsed && southUsed && eastUsed && westUsed) || - - borderCenterX != (borderCenterX = border.getCenterX()) || - borderCenterZ != (borderCenterZ = border.getCenterZ()) || - size != (size = border.getSize())) + //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()) { - //RETURN FALSE AND MESSAGE PLAYER IF UNABLE TO FIND NEW LOCATION. - player.sendMessage("could not find a location in 10,000 attempts"); - player.sendMessage("... sorry bud. I did try. 10,000 times."); + //MESSAGE PLAYER AND RETURN FALSE IF UNABLE TO FIND NEW LOCATION. + player.sendMessage("could not find location in 10,000 attempts"); + player.sendMessage("... sorry bud. I did try."); return false; } - //CHOOSE ONE OF THE FIVE POSITIONS RANDOMLY AND TELEPORT THE PLAYER THERE, THEN REMOVE THAT POSITION + //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; @@ -132,9 +189,9 @@ public class Main extends JavaPlugin case (char) 4: player.teleport(east ); eastUsed = true; break; case (char) 5: player.teleport(west ); westUsed = true; break; } - availableDirections.deleteCharAt(dir); + availableDirections.deleteCharAt(dir); - //IF ALL POSITIONS USED, CHOOSE A NEW LOCATION FOR NEXT ROUND + //IF ALL 5 POSITIONS HAVE BEEN TELEPORTED TO, CHOOSE NEW LOCATION if (centerUsed && northUsed && southUsed && eastUsed && westUsed) newLocation(); From 442c32f17bf0e2dbb73434941eaf0817350e6772 Mon Sep 17 00:00:00 2001 From: iie Date: Wed, 31 May 2017 01:10:00 +0200 Subject: [PATCH 5/8] v4 --- src/randomTP/Main.java | 56 +++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/src/randomTP/Main.java b/src/randomTP/Main.java index 20276ab..cc5676b 100644 --- a/src/randomTP/Main.java +++ b/src/randomTP/Main.java @@ -108,35 +108,41 @@ public class Main extends JavaPlugin westHeadMaterial = world.getBlockAt( westX , westY +1 , z ).getType(); //CONFIRM 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 && + if (centerHeadMaterial .equals(Material.AIR) && + northHeadMaterial .equals(Material.AIR) && + southHeadMaterial .equals(Material.AIR) && + eastHeadMaterial .equals(Material.AIR) && + westHeadMaterial .equals(Material.AIR) && - centerGroundMaterial != Material.STATIONARY_WATER && - northGroundMaterial != Material.STATIONARY_WATER && - southGroundMaterial != Material.STATIONARY_WATER && - eastGroundMaterial != Material.STATIONARY_WATER && - westGroundMaterial != Material.STATIONARY_WATER && + !centerGroundMaterial.equals(Material.STATIONARY_WATER) && + !northGroundMaterial .equals(Material.STATIONARY_WATER) && + !southGroundMaterial .equals(Material.STATIONARY_WATER) && + !eastGroundMaterial .equals(Material.STATIONARY_WATER) && + !westGroundMaterial .equals(Material.STATIONARY_WATER) && - centerGroundMaterial != Material.WATER && - northGroundMaterial != Material.WATER && - southGroundMaterial != Material.WATER && - eastGroundMaterial != Material.WATER && - westGroundMaterial != Material.WATER && + !centerGroundMaterial.equals(Material.WATER) && + !northGroundMaterial .equals(Material.WATER) && + !southGroundMaterial .equals(Material.WATER) && + !eastGroundMaterial .equals(Material.WATER) && + !westGroundMaterial .equals(Material.WATER) && - centerGroundMaterial != Material.STATIONARY_LAVA && - northGroundMaterial != Material.STATIONARY_LAVA && - southGroundMaterial != Material.STATIONARY_LAVA && - eastGroundMaterial != Material.STATIONARY_LAVA && - westGroundMaterial != Material.STATIONARY_LAVA && + !centerGroundMaterial.equals(Material.STATIONARY_LAVA) && + !northGroundMaterial .equals(Material.STATIONARY_LAVA) && + !southGroundMaterial .equals(Material.STATIONARY_LAVA) && + !eastGroundMaterial .equals(Material.STATIONARY_LAVA) && + !westGroundMaterial .equals(Material.STATIONARY_LAVA) && - centerGroundMaterial != Material.LAVA && - northGroundMaterial != Material.LAVA && - southGroundMaterial != Material.LAVA && - eastGroundMaterial != Material.LAVA && - westGroundMaterial != Material.LAVA) + !centerGroundMaterial.equals(Material.LAVA) && + !northGroundMaterial .equals(Material.LAVA) && + !southGroundMaterial .equals(Material.LAVA) && + !eastGroundMaterial .equals(Material.LAVA) && + !westGroundMaterial .equals(Material.LAVA) && + + !centerGroundMaterial.equals(Material.AIR) && + !northGroundMaterial .equals(Material.AIR) && + !southGroundMaterial .equals(Material.AIR) && + !eastGroundMaterial .equals(Material.AIR) && + !westGroundMaterial .equals(Material.AIR)) { //IF LOCATION VALID, SET NEW POSITIONS AND RESET TRACKING VARIABLES center = world.getBlockAt( x , centerY , z ).getLocation(); From b8e9810e18e74edc58cc67338516ea3c694f4a73 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Wed, 31 May 2017 16:40:31 +0200 Subject: [PATCH 6/8] Moved plugin.yml --- src/randomTP/plugin.yml => plugin.yml | 0 pom.xml | 3 +++ 2 files changed, 3 insertions(+) rename src/randomTP/plugin.yml => plugin.yml (100%) diff --git a/src/randomTP/plugin.yml b/plugin.yml similarity index 100% rename from src/randomTP/plugin.yml rename to plugin.yml diff --git a/pom.xml b/pom.xml index acdc756..69254d8 100644 --- a/pom.xml +++ b/pom.xml @@ -13,6 +13,9 @@ **/*.java + + . + From 0b3743cb01d5f79215e4d90f2fb515a82007ecb0 Mon Sep 17 00:00:00 2001 From: iie Date: Wed, 31 May 2017 21:54:00 +0200 Subject: [PATCH 7/8] v5 --- src/randomTP/Main.java | 271 +++++++++++++++++++++++------------------ 1 file changed, 151 insertions(+), 120 deletions(-) diff --git a/src/randomTP/Main.java b/src/randomTP/Main.java index cc5676b..d18d59e 100644 --- a/src/randomTP/Main.java +++ b/src/randomTP/Main.java @@ -22,17 +22,19 @@ public class Main extends JavaPlugin private double size, usableSize, borderCenterX, - borderCenterZ; + borderCenterZ, + + x,z; + + private int centerX, centerZ, centerY, + northZ, southZ, eastX, westX, + northY, southY, eastY, westY; - private int x,z, - centerY, northY, southY, eastY, westY, - northZ, southZ, eastX, westX; - - private Material centerGroundMaterial, centerHeadMaterial, - northGroundMaterial, northHeadMaterial, - southGroundMaterial, southHeadMaterial, - eastGroundMaterial, eastHeadMaterial, - westGroundMaterial, westHeadMaterial; + private Material centerGroundMaterial, centerFeetMaterial, centerHeadMaterial, + northGroundMaterial, northFeetMaterial, northHeadMaterial, + southGroundMaterial, southFeetMaterial, southHeadMaterial, + eastGroundMaterial, eastFeetMaterial, eastHeadMaterial, + westGroundMaterial, westFeetMaterial, westHeadMaterial; private Location center, north, @@ -54,21 +56,61 @@ public class Main extends JavaPlugin public void onEnable() { - world = (CraftWorld) Bukkit.getWorld("World"); - border = world.getHandle().getWorldBorder(); - - newLocation(); - 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])); + if (sender.isOp()) return rtp(Bukkit.getPlayer(args[0])); else return false; + } + + /*================================================================================================*/ + + public synchronized boolean rtp(Player player) + { + if (player == null) + return false; - else 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; } /*================================================================================================*/ @@ -80,127 +122,116 @@ public class Main extends JavaPlugin borderCenterX = border.getCenterX(); borderCenterZ = border.getCenterZ(); - //MAXIMUM TEN THOUSAND ATTEMPTS + //maximum ten thousand attempts for (int i = 0; i < 10000; i++) { - //RANDOMLY CHOOSE AN X AND Z WITHIN WORLD BORDER - x = (int) (Math.floor((Math.random() - 0.5) * usableSize) + border.getCenterX()); - z = (int) (Math.floor((Math.random() - 0.5) * usableSize) + border.getCenterZ()); + //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 OTHER COORDINATES - centerY = world.getHighestBlockYAt( x , z ); - northZ = z - radius; northY = world.getHighestBlockYAt( x , northZ ); - southZ = z + radius; southY = world.getHighestBlockYAt( x , southZ ); - eastX = x + radius; eastY = world.getHighestBlockYAt( eastX , z ); - westX = x - radius; westY = world.getHighestBlockYAt( westX , z ); + //get center of block + x = centerX + .5; + z = centerZ + .5; - //GET MATERIALS FOR GROUND AND HEAD-HEIGHT BLOCKS AT EACH POSITION - centerGroundMaterial = world.getBlockAt( x , centerY -1 , z ).getType(); - northGroundMaterial = world.getBlockAt( x , northY -1 , northZ ).getType(); - southGroundMaterial = world.getBlockAt( x , southY -1 , southZ ).getType(); - eastGroundMaterial = world.getBlockAt( eastX , eastY -1 , z ).getType(); - westGroundMaterial = world.getBlockAt( westX , westY -1 , z ).getType(); + //get other coordinates + northZ = centerZ - radius; + southZ = centerZ + radius; + eastX = centerX + radius; + westX = centerX - radius; - centerHeadMaterial = world.getBlockAt( x , centerY +1 , z ).getType(); - northHeadMaterial = world.getBlockAt( x , northY +1 , northZ ).getType(); - southHeadMaterial = world.getBlockAt( x , southY +1 , southZ ).getType(); - eastHeadMaterial = world.getBlockAt( eastX , eastY +1 , z ).getType(); - westHeadMaterial = world.getBlockAt( westX , westY +1 , z ).getType(); + 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 ); - //CONFIRM THAT ALL FIVE POSITIONS ARE ON SOLID GROUND WITH AIR AT HEAD HEIGHT - if (centerHeadMaterial .equals(Material.AIR) && - northHeadMaterial .equals(Material.AIR) && - southHeadMaterial .equals(Material.AIR) && - eastHeadMaterial .equals(Material.AIR) && - westHeadMaterial .equals(Material.AIR) && - - !centerGroundMaterial.equals(Material.STATIONARY_WATER) && - !northGroundMaterial .equals(Material.STATIONARY_WATER) && - !southGroundMaterial .equals(Material.STATIONARY_WATER) && - !eastGroundMaterial .equals(Material.STATIONARY_WATER) && - !westGroundMaterial .equals(Material.STATIONARY_WATER) && - - !centerGroundMaterial.equals(Material.WATER) && - !northGroundMaterial .equals(Material.WATER) && - !southGroundMaterial .equals(Material.WATER) && - !eastGroundMaterial .equals(Material.WATER) && - !westGroundMaterial .equals(Material.WATER) && + //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 && - !centerGroundMaterial.equals(Material.STATIONARY_LAVA) && - !northGroundMaterial .equals(Material.STATIONARY_LAVA) && - !southGroundMaterial .equals(Material.STATIONARY_LAVA) && - !eastGroundMaterial .equals(Material.STATIONARY_LAVA) && - !westGroundMaterial .equals(Material.STATIONARY_LAVA) && + centerFeetMaterial == Material.AIR && + northFeetMaterial == Material.AIR && + southFeetMaterial == Material.AIR && + eastFeetMaterial == Material.AIR && + westFeetMaterial == Material.AIR && - !centerGroundMaterial.equals(Material.LAVA) && - !northGroundMaterial .equals(Material.LAVA) && - !southGroundMaterial .equals(Material.LAVA) && - !eastGroundMaterial .equals(Material.LAVA) && - !westGroundMaterial .equals(Material.LAVA) && + centerGroundMaterial != Material.AIR && + northGroundMaterial != Material.AIR && + southGroundMaterial != Material.AIR && + eastGroundMaterial != Material.AIR && + westGroundMaterial != Material.AIR && - !centerGroundMaterial.equals(Material.AIR) && - !northGroundMaterial .equals(Material.AIR) && - !southGroundMaterial .equals(Material.AIR) && - !eastGroundMaterial .equals(Material.AIR) && - !westGroundMaterial .equals(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) { - //IF LOCATION VALID, SET NEW POSITIONS AND RESET TRACKING VARIABLES - center = world.getBlockAt( x , centerY , z ).getLocation(); - north = world.getBlockAt( x , northY , northZ ).getLocation(); - south = world.getBlockAt( x , southY , southZ ).getLocation(); - east = world.getBlockAt( eastX , eastY , z ).getLocation(); - west = world.getBlockAt( westX , westY , z ).getLocation(); + //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; + centerUsed = + northUsed = + southUsed = + eastUsed = + westUsed = false; return true; } } - centerUsed = northUsed = southUsed = eastUsed = westUsed = true; + centerUsed = + northUsed = + southUsed = + eastUsed = + westUsed = true; 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("could not find location in 10,000 attempts"); - player.sendMessage("... 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); - - //IF ALL 5 POSITIONS HAVE BEEN TELEPORTED TO, CHOOSE NEW LOCATION - if (centerUsed && northUsed && southUsed && eastUsed && westUsed) - newLocation(); - - return true; - } } From b2ecc27f86cdc4f0e7c18c8d1fd647c0ba90e6d8 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Fri, 23 Jun 2017 17:49:49 +0200 Subject: [PATCH 8/8] Updated to 1.12 --- pom.xml | 8 +++++++- src/randomTP/Main.java | 6 ++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 69254d8..2309391 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,13 @@ org.spigotmc spigot-api - 1.9.2-R0.1-SNAPSHOT + 1.12-R0.1-SNAPSHOT + provided + + + org.bukkit + craftbukkit + 1.12-R0.1-SNAPSHOT provided diff --git a/src/randomTP/Main.java b/src/randomTP/Main.java index d18d59e..ecf2d50 100644 --- a/src/randomTP/Main.java +++ b/src/randomTP/Main.java @@ -3,15 +3,13 @@ package randomTP; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import org.bukkit.craftbukkit.v1_11_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; -import net.minecraft.server.v1_11_R1.WorldBorder; +import net.minecraft.server.v1_12_R1.WorldBorder; public class Main extends JavaPlugin {