From 1e17a1dab64be5d91a6755496bdd2f7afde18241 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 22 Oct 2016 20:51:34 -0400 Subject: [PATCH 1/2] picking a random direction without a loop --- src/alisolarflare/RandomTP.java | 23 +++++++++++++++++++---- src/iie/HelloWorldPlugin.java | 1 - 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/alisolarflare/RandomTP.java b/src/alisolarflare/RandomTP.java index d92800c..6369198 100644 --- a/src/alisolarflare/RandomTP.java +++ b/src/alisolarflare/RandomTP.java @@ -1,5 +1,8 @@ package alisolarflare; +import java.util.ArrayList; +import java.util.Arrays; + import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -28,6 +31,9 @@ public class RandomTP implements CommandExecutor{ //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){ + + + //INIT - xDifference, xAverage int xdifference = minLocation.getBlockX() - maxLocation.getBlockX(); int xAverage = (int) Math.floor(minLocation.getBlockX() + maxLocation.getBlockX() / 2); @@ -37,7 +43,7 @@ public class RandomTP implements CommandExecutor{ int zAverage = (int) Math.floor(minLocation.getBlockZ() + maxLocation.getBlockZ()); //CHECK - Reset Cycle - if ((northUsed || southUsed || eastUsed || westUsed) == false){ + if (!(northUsed || southUsed || eastUsed || westUsed)){ //Tries 20 times to find a location for(int i = 0; i < 20; i ++){ @@ -52,9 +58,10 @@ public class RandomTP implements CommandExecutor{ //CHECKS - if ground is safe boolean groundIsSafe = world.getHighestBlockAt(attemptedX, attemptedZ).getType() != Material.WATER; boolean northIsSafe = world.getHighestBlockAt(attemptedX, attemptedZ-cr).getType() != Material.WATER; - boolean eastIsSafe = world.getHighestBlockAt(attemptedX+cr, attemptedZ).getType() != Material.WATER; boolean southIsSafe = world.getHighestBlockAt(attemptedX, attemptedZ+cr).getType() != Material.WATER; boolean westIsSafe = world.getHighestBlockAt(attemptedX-cr, attemptedZ).getType() != Material.WATER; + boolean eastIsSafe = world.getHighestBlockAt(attemptedX+cr, attemptedZ).getType() != Material.WATER; + //TRANSFER - data to class if (groundIsSafe && (northIsSafe || southIsSafe || eastIsSafe || westIsSafe)){ @@ -73,8 +80,16 @@ public class RandomTP implements CommandExecutor{ } String dir = "north"; + + ArrayList directions = new ArrayList(); + if(!northUsed) directions.add("north"); + if(!southUsed) directions.add("south"); + if(!westUsed) directions.add("west"); + 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){ @@ -102,7 +117,7 @@ public class RandomTP implements CommandExecutor{ } } - } + }*/ //TELEPORT - teleports player to the conflict point diff --git a/src/iie/HelloWorldPlugin.java b/src/iie/HelloWorldPlugin.java index 3028230..0e19edf 100644 --- a/src/iie/HelloWorldPlugin.java +++ b/src/iie/HelloWorldPlugin.java @@ -2,7 +2,6 @@ package iie; import java.util.AbstractMap; import java.util.HashMap; -import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.entity.Player; From e86754efcb9e933c4d5c4f5e872470c6ad32ab53 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 22 Oct 2016 21:10:26 -0400 Subject: [PATCH 2/2] removing commented-out for loop --- src/alisolarflare/RandomTPModule.java | 32 --------------------------- 1 file changed, 32 deletions(-) diff --git a/src/alisolarflare/RandomTPModule.java b/src/alisolarflare/RandomTPModule.java index 77da768..fca4de7 100644 --- a/src/alisolarflare/RandomTPModule.java +++ b/src/alisolarflare/RandomTPModule.java @@ -83,38 +83,6 @@ public class RandomTPModule{ if(!eastUsed) directions.add("east"); dir = directions.get((int) Math.floor(Math.random() * directions.size())); - /* - for(int i = 0; i < 1000; i++){ - double randomDirection = Math.random(); - if (randomDirection < 0.25){ - if(!northUsed){ - northUsed = true; - dir = "north"; - break; - } - }else if(randomDirection < 0.50){ - if(!eastUsed){ - eastUsed = true; - dir = "east"; - break; - } - }else if(randomDirection < 0.75){ - if(!southUsed){ - southUsed = true; - dir = "south"; - break; - } - }else{ - if(!westUsed){ - westUsed = true; - dir = "west"; - break; - } - - } - }*/ - - //TELEPORT - teleports player to the conflict point switch(dir){ case "north":