Skip to content

Commit

Permalink
various minor code cleanings
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 18, 2019
1 parent 7076dd5 commit fc29383
Show file tree
Hide file tree
Showing 16 changed files with 22 additions and 31 deletions.
Expand Up @@ -13,7 +13,6 @@
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Vehicle;

import java.util.List;
import java.util.regex.Pattern;

public abstract class BukkitScriptEvent extends ScriptEvent {
Expand Down
Expand Up @@ -113,9 +113,7 @@ public boolean applyDetermination(ScriptContainer container, String determinatio
cancelled = true;

// Get the list of entities
Object list = dList.valueOf(determination).filter(dEntity.class);
@SuppressWarnings("unchecked")
List<dEntity> newProjectiles = (List<dEntity>) list;
List<dEntity> newProjectiles = dList.valueOf(determination).filter(dEntity.class);
// Go through all the entities, spawning/teleporting them
for (dEntity newProjectile : newProjectiles) {
newProjectile.spawnAt(entity.getEyeLocation()
Expand Down
Expand Up @@ -11,7 +11,6 @@
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand Down
Expand Up @@ -10,7 +10,6 @@
import net.aufdemrand.denizen.objects.properties.entity.EntityTame;
import net.aufdemrand.denizen.scripts.containers.core.EntityScriptContainer;
import net.aufdemrand.denizen.scripts.containers.core.EntityScriptHelper;
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.MaterialCompat;
import net.aufdemrand.denizen.utilities.entity.AreaEffectCloudHelper;
Expand Down
Expand Up @@ -743,7 +743,7 @@ public void setContents(ItemStack[] contents) {
public void setContents(dList list) {
int size;
if (inventory == null) {
size = (int) Math.ceil(list.size() / 9) * 9;
size = (int) Math.ceil(list.size() / 9.0) * 9;
if (size == 0) {
size = 9;
}
Expand Down
Expand Up @@ -304,14 +304,13 @@ public int comparesTo(dItem item) {
return comparesTo(item.getItemStack());
}

public int comparesTo(ItemStack item) {
public int comparesTo(ItemStack compared_to) {
if (item == null) {
return -1;
}

int determination = 0;
ItemStack compared = getItemStack();
ItemStack compared_to = item;

// Will return -1 if these are not the same
// Material IDs
Expand Down
Expand Up @@ -864,11 +864,11 @@ else if (getBlock().getType() == Material.FLOWER_POT) {
// along with the permanently cached texture property.
// -->
if (attribute.startsWith("full")) {
return new Element((uuid != null ? uuid : name != null ? name : null)
return new Element((uuid != null ? uuid : name)
+ (texture != null ? "|" + texture : ""))
.getAttribute(attribute.fulfill(1));
}
return new Element(uuid != null ? uuid.toString() : name != null ? name : null).getAttribute(attribute);
return new Element(uuid != null ? uuid.toString() : name).getAttribute(attribute);
}
else {
return null;
Expand Down
Expand Up @@ -45,7 +45,7 @@ private EntityHealth(dEntity ent) {

@Override
public String getPropertyString() {
return String.valueOf(entity.getLivingEntity().getHealth() + "/" + entity.getLivingEntity().getMaxHealth());
return entity.getLivingEntity().getHealth() + "/" + entity.getLivingEntity().getMaxHealth();
}

@Override
Expand Down
Expand Up @@ -6,7 +6,6 @@
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.objects.properties.Property;
import net.aufdemrand.denizencore.tags.Attribute;
import org.bukkit.entity.EnderCrystal;
import org.bukkit.entity.Spellcaster;

public class EntitySpell implements Property {
Expand Down
Expand Up @@ -15,6 +15,8 @@
import net.citizensnpcs.trait.Anchors;
import net.citizensnpcs.util.Anchor;

import java.util.Arrays;

public class AnchorCommand extends AbstractCommand {

private enum Action {ADD, REMOVE, ASSUME, WALKTO, WALKNEAR}
Expand Down Expand Up @@ -53,7 +55,7 @@ else if (!scriptEntry.hasObject("location")
}

if (!scriptEntry.hasObject("action")) {
throw new InvalidArgumentsException("Must specify an 'Anchor Action'. Valid: " + Action.values()); // TODO: Fix output (array stringifier)
throw new InvalidArgumentsException("Must specify an 'Anchor Action'. Valid: " + Arrays.asList(Action.values()));
}

}
Expand Down
Expand Up @@ -180,9 +180,9 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
players.debug();
}

if (scriptEntry.dbCallShouldDebug()) {
if (scriptEntry.dbCallShouldDebug()) {

dB.report(scriptEntry, getName(), debug);
dB.report(scriptEntry, getName(), debug);

}

Expand Down Expand Up @@ -279,7 +279,7 @@ else if (value != null) {
for (String line : value) {
for (int i = 0; i < current.size(); i++) {
if (current.get(i).equalsIgnoreCase(line)) {
current.remove(i);
current.remove(i--);
}
}
}
Expand Down
Expand Up @@ -137,7 +137,7 @@ public dInventory getInventoryFrom(dPlayer player, dNPC npc) {
dB.echoError("Inventory size can't be 0. Assuming default of inventory type...");
}
if (size % 9 != 0) {
size = (int) Math.ceil(size / 9) * 9;
size = (int) Math.ceil(size / 9.0) * 9;
dB.echoError("Inventory size must be a multiple of 9! Rounding up to " + size + "...");
}
if (size < 0) {
Expand Down Expand Up @@ -194,7 +194,7 @@ else if (dItem.matches(item)) {
}
}
if (inventory == null) {
size = finalItems.length % 9 == 0 ? finalItems.length : Math.round(finalItems.length / 9) * 9;
size = finalItems.length % 9 == 0 ? finalItems.length : (int) (Math.ceil(finalItems.length / 9.0) * 9);
inventory = new dInventory(size == 0 ? 9 : size,
contains("TITLE") ? TagManager.tag(getString("TITLE"), context) : "Chest");
}
Expand Down
Expand Up @@ -485,7 +485,7 @@ public int hashCode() {
private static String capitalize(Object string) {
String capitalize = string.toString();
return capitalize.length() == 0 ? "" : Character.toUpperCase(capitalize.charAt(0))
+ capitalize.substring(1, capitalize.length());
+ capitalize.substring(1);
}

private static String format(Command command, String alias) {
Expand All @@ -508,9 +508,9 @@ else if (m == 0) {
return n;
}

int p[] = new int[n + 1]; // 'previous' cost array, horizontally
int d[] = new int[n + 1]; // cost array, horizontally
int _d[]; // placeholder to assist in swapping p and d
int[] p = new int[n + 1]; // 'previous' cost array, horizontally
int[] d = new int[n + 1]; // cost array, horizontally
int[] _d; // placeholder to assist in swapping p and d

// indexes into strings s and t
int i; // iterates through s
Expand Down
Expand Up @@ -43,27 +43,25 @@ public int getX(dPlayer player, UUID uuid) {
int x = (int) aH.getDoubleFrom(tag(xTag, player));
currentX.put(uuid, x);
//}
int tx = x;
if (worldCoordinates && lastMap != null) {
float f = (float) (tx - lastMap.getCenterX()) / (1 << (lastMap.getScale().getValue()));
float f = (float) (x - lastMap.getCenterX()) / (1 << (lastMap.getScale().getValue()));
int bx = ((int) ((f * 2.0F) + 0.5D));
return (bx < -127 ? -127 : (bx > 127 ? 127 : bx));
}
return tx;
return x;
}

public int getY(dPlayer player, UUID uuid) {
//if (!currentY.containsKey(uuid)) {
int y = (int) aH.getDoubleFrom(tag(yTag, player));
currentY.put(uuid, y);
//}
int ty = y;
if (worldCoordinates && lastMap != null) {
float f1 = (float) (ty - lastMap.getCenterZ()) / (1 << (lastMap.getScale().getValue()));
float f1 = (float) (y - lastMap.getCenterZ()) / (1 << (lastMap.getScale().getValue()));
int by = ((int) ((f1 * 2.0F) + 0.5D));
return (by < -127 ? -127 : (by > 127 ? 127 : by));
}
return ty;
return y;
}

public boolean isVisibleTo(dPlayer player, UUID uuid) {
Expand Down
Expand Up @@ -27,7 +27,6 @@
import org.bukkit.Location;
import org.bukkit.block.Biome;
import org.bukkit.craftbukkit.v1_12_R1.CraftServer;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
Expand Down
Expand Up @@ -30,7 +30,6 @@
import org.bukkit.block.data.Openable;
import org.bukkit.block.data.Powerable;
import org.bukkit.craftbukkit.v1_13_R2.CraftServer;
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
Expand Down

0 comments on commit fc29383

Please sign in to comment.