Skip to content

Commit

Permalink
semi-automated cleanup to match new core
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 4, 2020
1 parent 8db114c commit f5620d0
Show file tree
Hide file tree
Showing 29 changed files with 71 additions and 119 deletions.
Expand Up @@ -359,7 +359,6 @@ public void onEnable() {
OldEventManager.registerSmartEvent(new CuboidEnterExitSmartEvent());
OldEventManager.registerSmartEvent(new FlagSmartEvent());
OldEventManager.registerSmartEvent(new NPCNavigationSmartEvent());
eventManager().registerCoreMembers();

// Register all the modern script events
ScriptEventRegistry.registerMainEvents();
Expand Down
Expand Up @@ -623,16 +623,16 @@ public String expirationTime() {
String timeString = "";

if (days > 0) {
timeString = String.valueOf(days) + "d ";
timeString = days + "d ";
}
if (hours > 0) {
timeString = timeString + String.valueOf(hours) + "h ";
timeString = timeString + hours + "h ";
}
if (minutes > 0 && days == 0) {
timeString = timeString + String.valueOf(minutes) + "m ";
timeString = timeString + minutes + "m ";
}
if (seconds > 0 && minutes < 10 && hours == 0 && days == 0) {
timeString = timeString + String.valueOf(seconds) + "s";
timeString = timeString + seconds + "s";
}

return timeString.trim();
Expand Down
Expand Up @@ -52,7 +52,7 @@ public abstract class ImprovedOfflinePlayer {
protected UUID player;
protected File file;
protected CompoundTag compound;
protected boolean exists = false;
protected boolean exists;
protected boolean autosave = true;
public static Map<UUID, PlayerInventory> offlineInventories = new HashMap<>();
public static Map<UUID, Inventory> offlineEnderChests = new HashMap<>();
Expand Down
Expand Up @@ -1558,7 +1558,7 @@ else if (object.getBukkitEntityType() == EntityType.PIG) {
EntityHelper.MapTraceResult mtr = NMSHandler.getEntityHelper().mapTrace(object.getLivingEntity(), 200);
if (mtr != null) {
double x = 0;
double y = 0;
double y;
double basex = mtr.hitLocation.getX() - Math.floor(mtr.hitLocation.getX());
double basey = mtr.hitLocation.getY() - Math.floor(mtr.hitLocation.getY());
double basez = mtr.hitLocation.getZ() - Math.floor(mtr.hitLocation.getZ());
Expand Down
Expand Up @@ -2109,8 +2109,7 @@ else if (item != null && item.hasItemMeta() && item.getItemMeta().hasDisplayName
// Returns the location of this inventory's holder.
// -->
registerTag("location", (attribute, object) -> {
LocationTag location = object.getLocation();
return location;
return object.getLocation();
});

// <--[tag]
Expand Down Expand Up @@ -2239,8 +2238,7 @@ else if (slot > object.getInventory().getSize() - 1) {
// For horses, the order is saddle|armor.
// -->
registerTag("equipment", (attribute, object) -> {
ListTag equipment = object.getEquipment();
return equipment;
return object.getEquipment();
});

// <--[tag]
Expand Down Expand Up @@ -2339,8 +2337,7 @@ else if ((object.inventory instanceof FurnaceInventory)) {
// Returns the item currently in the fuel section of a furnace or brewing stand inventory.
// -->
registerTag("fuel", (attribute, object) -> {
ItemTag fuel = object.getFuel();
return fuel;
return object.getFuel();
});

// <--[tag]
Expand All @@ -2351,8 +2348,7 @@ else if ((object.inventory instanceof FurnaceInventory)) {
// Returns the item currently in the smelting slot of a furnace inventory, or the ingredient slot of a brewing stand inventory.
// -->
registerTag("input", (attribute, object) -> {
ItemTag smelting = object.getInput();
return smelting;
return object.getInput();
});
registerTag("smelting", tagProcessor.registeredObjectTags.get("input"));

Expand Down
Expand Up @@ -233,7 +233,7 @@ public PlayerTag(Player player) {
// INSTANCE FIELDS/METHODS
/////////////////

OfflinePlayer offlinePlayer = null;
OfflinePlayer offlinePlayer;

public boolean isValid() {
return getPlayerEntity() != null || getOfflinePlayer() != null;
Expand Down
Expand Up @@ -156,8 +156,7 @@ public static void registerTags() {
// Returns Denizen's holder ID for this inventory. (player object, location object, etc.)
// -->
PropertyParser.<InventoryHolder>registerTag("id_holder", (attribute, object) -> {
ObjectTag holder = object.holder;
return holder;
return object.holder;
});
}

Expand Down
Expand Up @@ -94,7 +94,7 @@ public void execute(final ScriptEntry scriptEntry) {
boolean lock = scriptEntry.hasObject("lock");

if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), (lock ? ArgumentHelper.debugObj("lock", lock) : "") +
Debug.report(scriptEntry, getName(), (lock ? ArgumentHelper.debugObj("lock", true) : "") +
(ageType != null ? ArgumentHelper.debugObj("agetype", ageType)
: ArgumentHelper.debugObj("age", age)) +
ArgumentHelper.debugObj("entities", entities.toString()));
Expand Down
Expand Up @@ -85,7 +85,7 @@ else if (!scriptEntry.hasObject("type")
}
else if (!scriptEntry.hasObject("format")
&& arg.matchesPrefix("format")) {
FormatScriptContainer format = null;
FormatScriptContainer format;
String formatStr = arg.getValue();
format = ScriptRegistry.getScriptContainer(formatStr);
if (format == null) {
Expand Down
Expand Up @@ -94,7 +94,7 @@ public void timeEvent() {
doEvents(Arrays.asList
("time changes",
"time changes in " + currentWorld.identifySimple(),
"time " + String.valueOf(hour) + " in " + currentWorld.identifySimple()),
"time " + hour + " in " + currentWorld.identifySimple()),
null, null, context, true);

current_time.put(currentWorld.identifySimple(), hour);
Expand Down
Expand Up @@ -67,7 +67,7 @@ public EntityTag getEntityFrom() {
}

public EntityTag getEntityFrom(PlayerTag player, NPCTag npc) {
EntityTag entity = null;
EntityTag entity;
try {
if (contains("entity_type")) {
String entityType = TagManager.tag((getString("entity_type", "")), new BukkitTagContext(player, npc, new ScriptTag(this)));
Expand Down
Expand Up @@ -72,7 +72,7 @@ public static InteractScriptContainer getInteractScript(NPCTag npc, PlayerTag pl
entry = entry.toUpperCase();

// Initialize the fields that will make up the PriorityPair
String name = null;
String name;
int priority;

// Make sure a priority exists, deal with it if it doesn't.
Expand Down
Expand Up @@ -186,7 +186,7 @@ public ItemTag getItemFrom(BukkitTagContext context) {
context.script = new ScriptTag(this);
}
// Try to use this script to make an item.
ItemTag stack = null;
ItemTag stack;
isProcessing = true;
try {
if (!contains("material")) {
Expand Down
Expand Up @@ -3,7 +3,6 @@
import com.denizenscript.denizen.scripts.containers.core.InteractScriptContainer;
import com.denizenscript.denizen.utilities.DenizenAPI;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizen.events.bukkit.ScriptReloadEvent;
import com.denizenscript.denizen.npc.traits.TriggerTrait;
import com.denizenscript.denizen.objects.NPCTag;
import com.denizenscript.denizen.objects.PlayerTag;
Expand All @@ -13,7 +12,6 @@
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

import java.util.*;
Expand Down Expand Up @@ -281,24 +279,6 @@ private boolean isCloseEnough(Player player, NPCTag npc) {
return true;
}

/**
* Checks all proximity ranges in scripts and finds the largest number. No need to
* calculate distances that exceed the largest number.
*
* @param event dScriptReloadEvent, fired upon server startup or '/denizen reload scripts'
*/
@EventHandler // TODO: Does this have any point?
public void checkMaxProximities(ScriptReloadEvent event) {

//for (String script : ScriptRegistry._getScriptNames()) {
//
// TODO: Check interact scripts for proximity triggers and ranges.
// Find largest number, add 10, and set it as maxProximityRange.
// For now, let's assume 25.
//
//}
}

private static Map<UUID, Set<Integer>> proximityTracker = new HashMap<>();

//
Expand Down
Expand Up @@ -57,7 +57,7 @@ public static void _recallScoreboards() {
return;
}

Scoreboard board = null;
Scoreboard board;

// Iterate through scoreboards
for (String id : rootSection.getKeys(false)) {
Expand Down
Expand Up @@ -203,17 +203,6 @@ public static boolean isWalkable(Location location) {
&& blockHelper.isSafeBlock(location.clone().add(0, 1, 0).getBlock().getType());
}

public static String[] wrapWords(String text, int width) {
StringBuilder sb = new StringBuilder(text);

int i = 0;
while (i + width < sb.length() && (i = sb.lastIndexOf(" ", i + width)) != -1) {
sb.replace(i, i + 1, "\n");
}

return sb.toString().split("\n");
}

/**
* @param player the player doing the talking
* @param npc the npc being talked to
Expand Down
Expand Up @@ -433,54 +433,54 @@ public static boolean shouldDebug(Debuggable caller) {

// Handles checking whether the provided debuggable should submit to the debugger
private static void echo(String string, Debuggable caller) {
if (shouldDebug(caller)) {
if (showSources && caller != null) {
String callerId;
if (caller instanceof ScriptContainer) {
callerId = "Script:" + ((ScriptContainer) caller).getName();
}
else if (caller instanceof ScriptEntry) {
if (((ScriptEntry) caller).getScript() != null) {
callerId = "Command:" + ((ScriptEntry) caller).getCommandName() + " in Script:" + ((ScriptEntry) caller).getScript().getName();
}
else {
callerId = "Command:" + ((ScriptEntry) caller).getCommandName();
}
}
else if (caller instanceof ScriptQueue) {
if (((ScriptQueue) caller).script != null) {
callerId = "Queue:" + ((ScriptQueue) caller).id + " running Script:" + ((ScriptQueue) caller).script.getName();
}
else {
callerId = "Queue:" + ((ScriptQueue) caller).id;
}
}
else if (caller instanceof TagContext) {
if (((TagContext) caller).entry != null) {
ScriptEntry sent = ((TagContext) caller).entry;
if (sent.getScript() != null) {
callerId = "Tag in Command:" + sent.getCommandName() + " in Script:" + sent.getScript().getName();
}
else {
callerId = "Tag in Command:" + sent.getCommandName();
}
}
else if (((TagContext) caller).script != null) {
callerId = "Tag in Script:" + ((TagContext) caller).script.getName();
}
else {
callerId = "Tag:" + caller.toString();
}
if (!shouldDebug(caller)) {
return;
}
if (!showSources || caller == null) {
finalOutputDebugText(string, caller);
return;
}
String callerId;
if (caller instanceof ScriptContainer) {
callerId = "Script:" + ((ScriptContainer) caller).getName();
}
else if (caller instanceof ScriptEntry) {
if (((ScriptEntry) caller).getScript() != null) {
callerId = "Command:" + ((ScriptEntry) caller).getCommandName() + " in Script:" + ((ScriptEntry) caller).getScript().getName();
}
else {
callerId = "Command:" + ((ScriptEntry) caller).getCommandName();
}
}
else if (caller instanceof ScriptQueue) {
if (((ScriptQueue) caller).script != null) {
callerId = "Queue:" + ((ScriptQueue) caller).id + " running Script:" + ((ScriptQueue) caller).script.getName();
}
else {
callerId = "Queue:" + ((ScriptQueue) caller).id;
}
}
else if (caller instanceof TagContext) {
if (((TagContext) caller).entry != null) {
ScriptEntry sent = ((TagContext) caller).entry;
if (sent.getScript() != null) {
callerId = "Tag in Command:" + sent.getCommandName() + " in Script:" + sent.getScript().getName();
}
else {
callerId = caller.toString();
callerId = "Tag in Command:" + sent.getCommandName();
}
finalOutputDebugText(ChatColor.DARK_GRAY + "[Src:" + ChatColor.GRAY + callerId + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + string, caller);
}
else if (((TagContext) caller).script != null) {
callerId = "Tag in Script:" + ((TagContext) caller).script.getName();
}
else {
finalOutputDebugText(string, caller);
callerId = "Tag:" + caller.toString();
}
}
else {
callerId = caller.toString();
}
finalOutputDebugText(ChatColor.DARK_GRAY + "[Src:" + ChatColor.GRAY + callerId + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + string, caller);
}

static void finalOutputDebugText(String message, Debuggable caller) {
Expand Down
Expand Up @@ -33,7 +33,7 @@ public class DenizenCoreImplementation implements DenizenImplementation {

@Override
public File getScriptFolder() {
File file = null;
File file;
// Get the script directory
if (Settings.useDefaultScriptPath()) {
file = new File(DenizenAPI.getCurrentInstance().getDataFolder() + File.separator + "scripts");
Expand Down
Expand Up @@ -14,7 +14,7 @@ public abstract class MapObject {

protected String xTag;
protected String yTag;
protected String visibilityTag = "true";
protected String visibilityTag;
protected Map<UUID, Integer> currentX = new HashMap<>();
protected Map<UUID, Integer> currentY = new HashMap<>();
protected Map<UUID, Boolean> currentVisibility = new HashMap<>();
Expand Down
Expand Up @@ -26,7 +26,7 @@ public class NoteBlockReceiver implements Receiver, MetaEventListener {
private List<EntityTag> entities;
private LocationTag location;
private Map<Integer, Integer> channelPatches;
public String key = null;
public String key;
public Sequencer sequencer;
public boolean closing = false;

Expand Down
Expand Up @@ -33,7 +33,7 @@ public PacketOutWindowItemsImpl(PacketPlayOutWindowItems internal) {

@Override
public org.bukkit.inventory.ItemStack[] getContents() {
return contents.toArray(new org.bukkit.inventory.ItemStack[contents.size()]);
return contents.toArray(new org.bukkit.inventory.ItemStack[0]);
}

@Override
Expand Down
Expand Up @@ -34,8 +34,7 @@ public class ItemHelperImpl extends ItemHelper {
public static IRecipe getNMSRecipe(NamespacedKey key) {
MinecraftKey nmsKey = CraftNamespacedKey.toMinecraft(key);
Object2ObjectLinkedOpenHashMap<MinecraftKey, IRecipe> recipeMap = ((CraftServer) Bukkit.getServer()).getServer().getCraftingManager().recipes;
IRecipe recipe = recipeMap.get(nmsKey);
return recipe;
return recipeMap.get(nmsKey);
}

@Override
Expand Down Expand Up @@ -92,7 +91,7 @@ public void registerShapelessRecipe(String keyName, String group, ItemStack resu
itemRecipe.exact = exact[i];
ingredientList.add(itemRecipe);
}
ShapelessRecipes recipe = new ShapelessRecipes(key, group, CraftItemStack.asNMSCopy(result), NonNullList.a(null, ingredientList.toArray(new RecipeItemStack[ingredientList.size()])));
ShapelessRecipes recipe = new ShapelessRecipes(key, group, CraftItemStack.asNMSCopy(result), NonNullList.a(null, ingredientList.toArray(new RecipeItemStack[0])));
((CraftServer) Bukkit.getServer()).getServer().getCraftingManager().a(recipe);
}

Expand Down
Expand Up @@ -33,7 +33,7 @@ public PacketOutWindowItemsImpl(PacketPlayOutWindowItems internal) {

@Override
public org.bukkit.inventory.ItemStack[] getContents() {
return contents.toArray(new org.bukkit.inventory.ItemStack[contents.size()]);
return contents.toArray(new org.bukkit.inventory.ItemStack[0]);
}

@Override
Expand Down
Expand Up @@ -120,7 +120,7 @@ public void registerShapelessRecipe(String keyName, String group, ItemStack resu
itemRecipe.exact = exact[i];
ingredientList.add(itemRecipe);
}
ShapelessRecipes recipe = new ShapelessRecipes(key, group, CraftItemStack.asNMSCopy(result), NonNullList.a(null, ingredientList.toArray(new RecipeItemStack[ingredientList.size()])));
ShapelessRecipes recipe = new ShapelessRecipes(key, group, CraftItemStack.asNMSCopy(result), NonNullList.a(null, ingredientList.toArray(new RecipeItemStack[0])));
((CraftServer) Bukkit.getServer()).getServer().getCraftingManager().addRecipe(recipe);
}

Expand Down

0 comments on commit f5620d0

Please sign in to comment.