RandomTeleport moved in #45
6 changed files with 181 additions and 0 deletions
6
.classpath
Normal file
6
.classpath
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -20,3 +20,6 @@
|
|||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
bin/
|
||||
target/
|
||||
|
|
17
.project
Normal file
17
.project
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>RandomTeleport_</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
11
.settings/org.eclipse.jdt.core.prefs
Normal file
11
.settings/org.eclipse.jdt.core.prefs
Normal file
|
@ -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
|
141
src/randomTP/Main.java
Normal file
141
src/randomTP/Main.java
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
3
src/randomTP/plugin.yml
Normal file
3
src/randomTP/plugin.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
main: randomTP.Main
|
||||
version: 1.0.0
|
||||
name: RandomTP
|
Loading…
Reference in a new issue