This commit is contained in:
BuildTools 2016-10-22 21:03:38 -04:00
commit 740ac21fec
3 changed files with 57 additions and 52 deletions

View file

@ -0,0 +1,27 @@
package alisolarflare;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class DebugRTP implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)){
sender.sendMessage("You must be a Player to use this command!");
sender.sendMessage(sender.toString());
return false;
}
Player player = (Player) sender;
if(player.getWorld().getName() != "hardcore"){
sender.sendMessage("You must be in the hardcore world to use this command!");
sender.sendMessage("Current World: " + player.getWorld().getName());
return false;
}
RandomTPModule.rtp(player, player.getWorld(), new Location(player.getWorld(), 644, 65, -944), new Location(player.getWorld(), 1700, 65, 464));
return false;
}
}

View file

@ -1,38 +1,32 @@
package alisolarflare;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import iie.HelloWorldPlugin;
public class RandomTP implements CommandExecutor{
private int conflictX;
private int conflictZ;
private int conflictRadius = 70;
private boolean northUsed;
private boolean southUsed;
private boolean eastUsed;
private boolean westUsed;
public class RandomTPModule{
private static int conflictX;
private static int conflictZ;
private static int conflictRadius = 70;
private static boolean northUsed;
private static boolean southUsed;
private static boolean eastUsed;
private static boolean westUsed;
@SuppressWarnings("unused")
private HelloWorldPlugin helloWorldPlugin;
public RandomTP(HelloWorldPlugin helloWorldPlugin) {
public RandomTPModule(HelloWorldPlugin helloWorldPlugin) {
this.helloWorldPlugin = helloWorldPlugin;
}
//every 4 players who use it will be teleported near each other.
//ex. iie > 1200, ali -> 1210, byz -> 1190, charles -> 1195, wind -> 300, zan -> 310, etc
public void conflictRtp(Player player, World world, Location minLocation, Location maxLocation){
//ex. iie 2000, ali 2010, byz 2005, charles 1995, wind 300, zan 310, etc
public static void conflictRtp(Player player, World world, Location minLocation, Location maxLocation){
//INIT - xDifference, xAverage
int xdifference = minLocation.getBlockX() - maxLocation.getBlockX();
@ -66,10 +60,10 @@ public class RandomTP implements CommandExecutor{
//TRANSFER - data to class
if (groundIsSafe && (northIsSafe || southIsSafe || eastIsSafe || westIsSafe)){
northUsed = northIsSafe;
eastUsed = eastIsSafe;
westUsed = westIsSafe;
southUsed = southIsSafe;
northUsed = !northIsSafe;
eastUsed = !eastIsSafe;
westUsed = !westIsSafe;
southUsed = !southIsSafe;
conflictX = attemptedX;
conflictZ = attemptedZ;
@ -81,6 +75,7 @@ public class RandomTP implements CommandExecutor{
String dir = "north";
//CHOOSES A RANDOM DIRECTION
ArrayList<String> directions = new ArrayList<String>();
if(!northUsed) directions.add("north");
if(!southUsed) directions.add("south");
@ -88,29 +83,29 @@ public class RandomTP implements CommandExecutor{
if(!eastUsed) directions.add("east");
dir = directions.get((int) Math.floor(Math.random() * directions.size()));
//CHOOSES A RANDOM DIRECTION
/*for(int i = 0; i < 1000; i++){
/*
for(int i = 0; i < 1000; i++){
double randomDirection = Math.random();
if (randomDirection < 0.25){
if(northUsed){
if(!northUsed){
northUsed = true;
dir = "north";
break;
}
}else if(randomDirection < 0.50){
if(eastUsed){
if(!eastUsed){
eastUsed = true;
dir = "east";
break;
}
}else if(randomDirection < 0.75){
if(southUsed){
if(!southUsed){
southUsed = true;
dir = "south";
break;
}
}else{
if(westUsed){
if(!westUsed){
westUsed = true;
dir = "west";
break;
@ -123,19 +118,15 @@ public class RandomTP implements CommandExecutor{
//TELEPORT - teleports player to the conflict point
switch(dir){
case "north":
northUsed = false;
player.teleport(world.getHighestBlockAt(conflictX, conflictZ - conflictRadius).getLocation());
break;
case "east":
eastUsed = false;
player.teleport(world.getHighestBlockAt(conflictX + conflictRadius, conflictZ).getLocation());
break;
case "south":
southUsed = false;
player.teleport(world.getHighestBlockAt(conflictX, conflictZ + conflictRadius).getLocation());
break;
case "west":
westUsed = false;
player.teleport(world.getHighestBlockAt(conflictX - conflictRadius, conflictZ).getLocation());
break;
default:
@ -145,7 +136,7 @@ public class RandomTP implements CommandExecutor{
}
//Randomly teleports a player, into the hardcore world
public void rtp(Player player, World world, Location minLocation, Location maxLocation){
public static void rtp(Player player, World world, Location minLocation, Location maxLocation){
player.sendMessage("TELEPORT INITIATED");
player.sendMessage("minLocation: " + minLocation.toString());
player.sendMessage("maxLocation: " + maxLocation.toString());
@ -178,21 +169,4 @@ public class RandomTP implements CommandExecutor{
//player.teleport(arg0)
}
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)){
sender.sendMessage("You must be a Player to use this command!");
sender.sendMessage(sender.toString());
return false;
}
Player player = (Player) sender;
if(player.getWorld().getName() != "hardcore"){
sender.sendMessage("You must be in the hardcore world to use this command!");
sender.sendMessage("Current World: " + player.getWorld().getName());
return false;
}
rtp(player, player.getWorld(), new Location(player.getWorld(), 644, 65, -944), new Location(player.getWorld(), 1700, 65, 464));
return false;
}
}

View file

@ -9,7 +9,9 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
import alisolarflare.RandomTP;
import alisolarflare.DebugRTP;
import alisolarflare.RandomTPModule;
import alisolarflare.listeners.CompassLobby;
import alisolarflare.listeners.ConflictCompassCraftingListener;
import alisolarflare.listeners.DiamondArmorBlocker;
@ -46,14 +48,16 @@ public class HelloWorldPlugin extends JavaPlugin {
getServer().getPluginManager().registerEvents(new JoinListener(this), this);
getServer().getPluginManager().registerEvents(new DeathListener(this), this);
getServer().getPluginManager().registerEvents(new BoundaryListener(this), this);
getServer().getPluginManager().registerEvents(new DiamondArmorBlocker(), this);
getServer().getPluginManager().registerEvents(new ConflictCompassCraftingListener(), this);
getServer().getPluginManager().registerEvents(new CompassLobby(), this);
}
public void registerCommands(){
getCommand("hardcore").setExecutor(new HelloWorld(this));
getCommand("debugRTP").setExecutor(new RandomTP(this));
getCommand("debugRTP").setExecutor(new DebugRTP());
}
}