Skip to content

Commit

Permalink
Fix some code, leave TODO notes
Browse files Browse the repository at this point in the history
Lots of little things to be worked on, some of them I have worked on
now.
  • Loading branch information
mcmonkey4eva committed Dec 11, 2014
1 parent d0c8184 commit f5dfb79
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 190 deletions.
Expand Up @@ -182,7 +182,7 @@ public void debug(CommandContext args, CommandSender sender) throws CommandExcep

} if (args.hasValueFlag("filter")) {
if (!dB.showDebug) dB.toggle();
for (String filter : args.getFlag("filter").split("\\|"))
for (String filter : args.getFlag("filter").split("\\|")) // TODO: addAll?
dB.filter.add(filter);
Messaging.sendInfo(sender, "Denizen dBugger filter now: " + dB.filter.toString());

Expand Down
Expand Up @@ -93,6 +93,7 @@ public void onBlockPhysics(BlockPhysicsEvent event) {
for (dCuboid cuboid : cuboids) {
events.add("block physics in " + cuboid.identifySimple());
events.add(mat.identifySimple() + " physics in " + cuboid.identifySimple());
cuboid_context.add(cuboid.identify());
}
// Add in cuboids context, with either the cuboids or an empty list
context.put("cuboids", cuboid_context);
Expand Down
Expand Up @@ -99,8 +99,10 @@ public void onEntityInteract(EntityInteractEvent event) {
dList cuboid_context = new dList();
List<String> cuboidevents = new ArrayList<String>();
for (dCuboid cuboid : cuboids) {
for (String evt: events)
for (String evt: events) {
cuboidevents.add(evt + " in " + cuboid.identifySimple());
}
cuboid_context.add(cuboid.identify());
}
// Add in cuboids context, with either the cuboids or an empty list
context.put("cuboids", cuboid_context);
Expand Down
Expand Up @@ -122,6 +122,7 @@ public void creatureSpawn(CreatureSpawnEvent event) {
events.add(entity.identifyType() + " spawns in " + cuboid.identifySimple() + " because " + reason);
events.add(entity.identifySimple() + " spawns in " + cuboid.identifySimple());
events.add(entity.identifySimple() + " spawns in " + cuboid.identifySimple() + " because " + reason);
cuboid_context.add(cuboid.identify());
}
// Add in cuboids context, with either the cuboids or an empty list
context.put("cuboids", cuboid_context);
Expand Down
Expand Up @@ -104,6 +104,7 @@ public void onPlayerMove(PlayerMoveEvent event) {
for (dCuboid cuboid : cuboids) {
events.add("player steps on block in " + cuboid.identifySimple());
events.add("player steps on " + mat.identifySimple() + " in " + cuboid.identifySimple());
cuboid_context.add(cuboid.identify());
}
// Add in cuboids context, with either the cuboids or an empty list
context.put("cuboids", cuboid_context);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/aufdemrand/denizen/objects/dEntity.java
Expand Up @@ -647,8 +647,9 @@ public void spawnAt(Location location) {
if (entity_type != null) {
if (despawned_entity != null) {
// If entity had a custom_script, use the script to rebuild the base entity.
if (despawned_entity.custom_script != null)
{ } // TODO: Build entity from custom script
if (despawned_entity.custom_script != null) {
// TODO: Build entity from custom script
}
// Else, use the entity_type specified/remembered
else entity = location.getWorld().spawnEntity(location, entity_type);

Expand Down
Expand Up @@ -425,7 +425,7 @@ else if (inventory == null) {
ItemStack[] oldContents = inventory.getContents();
ItemStack[] newContents = new ItemStack[size];
if (oldSize > size)
for (int i = 0; i < size; i++)
for (int i = 0; i < size; i++) // TODO: Why is this a manual copy?
newContents[i] = oldContents[i];
else
newContents = oldContents;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/aufdemrand/denizen/objects/dList.java
Expand Up @@ -203,11 +203,11 @@ public String[] toArray() {
* @param arraySize the size of the new array
* @return the array copy
*/
public String[] toArray(int arraySize) {
public String[] toArray(int arraySize) { // TODO: Why does this exist?
List<String> list = new ArrayList<String>();

for (String string : this) {
list.add(string);
list.add(string); // TODO: Why is this a manual copy?
}

return list.toArray(new String[arraySize]);
Expand Down
Expand Up @@ -947,6 +947,7 @@ public void signChange(final SignChangeEvent event) {
for (dCuboid cuboid : cuboids) {
events.add("player changes sign in " + cuboid.identifySimple());
events.add("player changes " + material.identifySimple() + " in " + cuboid.identifySimple());
cuboid_context.add(cuboid.identify());
}
// Add in cuboids context, with either the cuboids or an empty list
context.put("cuboids", cuboid_context);
Expand Down Expand Up @@ -1320,6 +1321,7 @@ public void entityChangeBlock(EntityChangeBlockEvent event) {
+ cuboid.identifySimple());
events.add(entity.identifyType() + " changes " + oldMaterial.identifySimple() + " into "
+ newMaterial.identifySimple() + " in " + cuboid.identifySimple());
cuboid_context.add(cuboid.identify());
}
// Add in cuboids context, with either the cuboids or an empty list
context.put("cuboids", cuboid_context);
Expand Down Expand Up @@ -3369,7 +3371,7 @@ else if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK)
else interactions = new String[]{"player stands on"};
context.put("click_type", new Element(action.name()));

for (String interaction : interactions)
for (String interaction : interactions) // TODO: addAll?
events.add(interaction);

if (event.hasItem()) {
Expand Down
Expand Up @@ -103,11 +103,11 @@ public class ProximityTrigger extends AbstractTrigger implements Listener {
*/

//
// Default to 25, but dynamically set by checkMaxProximities().
// Default to 75, but dynamically set by checkMaxProximities().
// If a Player is further than this distance from an NPC, less
// logic is run in checking.
//
private static int maxProximityDistance = 50;
private static int maxProximityDistance = 75; // TODO: is this reasonable to have?


// <--[action]
Expand Down Expand Up @@ -337,7 +337,7 @@ private boolean isCloseEnough(Player player, dNPC npc) {
* @param event dScriptReloadEvent, fired upon server startup or '/denizen reload scripts'
*
*/
@EventHandler
@EventHandler // TODO: Does this have any point?
public void checkMaxProximities(ScriptReloadEvent event) {

for (String script : ScriptRegistry._getScriptNames()) {
Expand Down
Expand Up @@ -13,6 +13,8 @@
/**
* Example replaceable tag class.
*
* TODO: Update me!
*
*/
public class _templateTag {

Expand Down
180 changes: 1 addition & 179 deletions src/main/java/net/aufdemrand/denizen/utilities/Utilities.java
Expand Up @@ -30,8 +30,6 @@

/**
* This class has utility methods for various tasks.
*
* @author aufdemrand, dbixler, AgentK
*/
public class Utilities {

Expand All @@ -53,29 +51,13 @@ public static Location getWalkableLocationNear(Location location, int range) {

// TODO: Javadocs, comments
//
public static boolean isWalkable(Location location) {
public static boolean isWalkable(Location location) { // TODO: Why does this exist - surely it can be written better
return ((location.getBlock().getType() == Material.AIR
|| location.getBlock().getType() == Material.GRASS)
&& (location.add(0, 1, 0).getBlock().getType() == Material.AIR));
}


// TODO: Javadocs, comments
//
public static String arrayToString(String[] input, String glue) {
String output="";
int length = input.length;
int i = 1;
for(String s : input) { // TODO: Should this be? : output = output.concat(s);
output.concat(s);
i++;
if(i!=length){
output.concat(glue); // TODO: Same as above
}
}
return output;
}


// TODO: Javadocs, comments
//
Expand Down Expand Up @@ -147,142 +129,6 @@ public static boolean isBetween(double a, double b, double c) {
}


/**
* Gets the plugin version from the maven info in the jar, if available.
*
* @return the version string
*/
@Deprecated // TODO: Can this be removed?
public String getVersionNumber() {
Properties props = new Properties();
//Set a default just in case.
props.put("version", "Unknown development build");
try { props.load(this.getClass()
.getResourceAsStream("/META-INF/maven/net.aufdemrand/denizen/pom.properties"));
} catch(Exception e) { }

return props.getProperty("version");
}


// TODO: Finish?
//
public static List<Block> getRandomSolidBlocks(Location location, int range, int count) {
List<Block> blocks = new ArrayList<Block>();

int x = 0;
int f = 0;

while (x < count) {

if (f > 1000) break;
f++;

Location loc = location.clone()
.add(CoreUtilities.getRandom().nextInt(range * 2) - range,
CoreUtilities.getRandom().nextInt(range * 2) - range,
CoreUtilities.getRandom().nextInt(range * 2) - range);

if (loc.getBlock().getType().isSolid()) {
blocks.add(loc.getBlock());
x++;
}

}

dB.log(blocks.size() + " blocksize");

return blocks;
}


// TODO: Check why this is no longer used. Possible duplication of code?
//
/**
* Finds the closest Player to a particular location.
*
* @param location The location to find the closest Player to.
* @param range The maximum range to look for the Player.
* @return The closest Player to the location, or null if no Player was found
* within the range specified.
*/
public static Player getClosestPlayer (Location location, int range) {

Player closestPlayer = null;
double closestDistance = Math.pow(range, 2);
// TODO: Why is this manually iterating?
List<Player> playerList = new ArrayList<Player>(Bukkit.getOnlinePlayers());
Iterator<Player> it = playerList.iterator();
while (it.hasNext()) {
Player player = it.next();
Location loc = player.getLocation();
if (loc.getWorld().equals(location.getWorld())
&& loc.distanceSquared(location) < closestDistance) {
closestPlayer = player;
closestDistance = player.getLocation().distanceSquared(location);
}
}
return closestPlayer;
}


// TODO: Check why this is no longer used. Possible duplication of code?
//
/**
* Finds the closest Players to a particular location.
*
* @param location The location to find the closest Player to.
* @param range The maximum range to look for the Player.
* @return The closest Player to the location, or null if no Player was found
* within the range specified.
*/
public static List<dPlayer> getClosestPlayers(Location location, int range) {

List<dPlayer> closestPlayers = new ArrayList<dPlayer>();
double closestDistance = Math.pow(range, 2);
// TODO: Why is this manually iterating?
List<Player> playerList = new ArrayList<Player>(Bukkit.getOnlinePlayers());
Iterator<Player> it = playerList.iterator();
while (it.hasNext()) {
Player player = it.next();
Location loc = player.getLocation();
if (loc.getWorld().equals(location.getWorld())
&& loc.distanceSquared(location) < closestDistance) {
closestPlayers.add(dPlayer.mirrorBukkitPlayer(player));
}
}
return closestPlayers;
}


// TODO: Check why this is no longer used. Possible duplication of code?
//
/**
* Finds the closest NPC to a particular location.
*
* @param location The location to find the closest NPC to.
* @param range The maximum range to look for the NPC.
* @return The closest NPC to the location, or null if no NPC was found
* within the range specified.
*/
public static dNPC getClosestNPC (Location location, int range) {
dNPC closestNPC = null;
double closestDistance = Math.pow(range, 2);
// TODO: Why is this manually iterating?
Iterator<dNPC> it = DenizenAPI.getSpawnedNPCs().iterator();
while (it.hasNext()) {
dNPC npc = it.next();
Location loc = npc.getLocation();
if (loc.getWorld().equals(location.getWorld())
&& loc.distanceSquared(location) < closestDistance) {
closestNPC = npc;
closestDistance = npc.getLocation().distanceSquared(location);
}
}
return closestNPC;
}


/**
* Finds the closest NPC to a particular location.
*
Expand Down Expand Up @@ -310,30 +156,6 @@ public static dNPC getClosestNPC_ChatTrigger (Location location, int range) {
}


/**
* Returns a list of all NPCs within a certain range.
*
* @param location The location to search.
* @param maxRange The maximum range of the NPCs
*
* @return The list of NPCs within the max range.
*/
public static Set<dNPC> getClosestNPCs (Location location, int maxRange) {
maxRange = (int) Math.pow(maxRange, 2);
Set<dNPC> closestNPCs = new HashSet<dNPC> ();
// TODO: Why is this manually iterating?
Iterator<dNPC> it = DenizenAPI.getSpawnedNPCs().iterator();
while (it.hasNext ()) {
dNPC npc = it.next ();
Location loc = npc.getLocation();
if (loc.getWorld().equals(location.getWorld()) && loc.distanceSquared(location) < maxRange) {
closestNPCs.add(npc);
}
}
return closestNPCs;
}


/**
* Checks entity's location against a Location (with leeway). Should be faster than
* bukkit's built in Location.distance(Location) since there's no sqrt math.
Expand Down

0 comments on commit f5dfb79

Please sign in to comment.