commit
a34bada348
8 changed files with 358 additions and 0 deletions
20
.classpath
Normal file
20
.classpath
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
|
</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
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
hs_err_pid*
|
hs_err_pid*
|
||||||
|
|
||||||
|
bin/
|
||||||
|
target/
|
||||||
|
|
23
.project
Normal file
23
.project
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?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>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
12
.settings/org.eclipse.jdt.core.prefs
Normal file
12
.settings/org.eclipse.jdt.core.prefs
Normal file
|
@ -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
|
4
.settings/org.eclipse.m2e.core.prefs
Normal file
4
.settings/org.eclipse.m2e.core.prefs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
activeProfiles=
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
resolveWorkspaceProjects=true
|
||||||
|
version=1
|
6
plugin.yml
Normal file
6
plugin.yml
Normal file
|
@ -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.
|
55
pom.xml
Normal file
55
pom.xml
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>TBMCPlugins</groupId>
|
||||||
|
<artifactId>RandomTeleport</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<build>
|
||||||
|
<sourceDirectory>src</sourceDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src</directory>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/*.java</exclude>
|
||||||
|
</excludes>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>.</directory>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.5.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>spigot-repo</id>
|
||||||
|
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>jitpack.io</id>
|
||||||
|
<url>https://jitpack.io/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.12-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>craftbukkit</artifactId>
|
||||||
|
<version>1.12-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
235
src/randomTP/Main.java
Normal file
235
src/randomTP/Main.java
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue