diff --git a/src/main/java/net/aufdemrand/denizen/Denizen.java b/src/main/java/net/aufdemrand/denizen/Denizen.java index c04a5813a5..8681cb6b8b 100644 --- a/src/main/java/net/aufdemrand/denizen/Denizen.java +++ b/src/main/java/net/aufdemrand/denizen/Denizen.java @@ -552,7 +552,7 @@ public void onEnable() { new EntityTags(this); new LocationTags(this); new PlayerTags(this); - new UtilTags(this); + new ServerTags(this); new TextTags(this); new ParseTags(this); if (Depends.citizens != null) { diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/core/AdjustCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/AdjustCommand.java index 05f5594384..4b8a336328 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/core/AdjustCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/AdjustCommand.java @@ -1,6 +1,6 @@ package net.aufdemrand.denizen.scripts.commands.core; -import net.aufdemrand.denizen.tags.core.UtilTags; +import net.aufdemrand.denizen.tags.core.ServerTags; import net.aufdemrand.denizencore.exceptions.CommandExecutionException; import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException; import net.aufdemrand.denizencore.objects.*; @@ -60,7 +60,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException { for (String object: objects) { if (object.equalsIgnoreCase("server")) { - UtilTags.adjustServer(new Mechanism(mechanism, value)); + ServerTags.adjustServer(new Mechanism(mechanism, value)); continue; } diff --git a/src/main/java/net/aufdemrand/denizen/tags/core/UtilTags.java b/src/main/java/net/aufdemrand/denizen/tags/core/ServerTags.java similarity index 76% rename from src/main/java/net/aufdemrand/denizen/tags/core/UtilTags.java rename to src/main/java/net/aufdemrand/denizen/tags/core/ServerTags.java index 12569a808c..288294ae66 100644 --- a/src/main/java/net/aufdemrand/denizen/tags/core/UtilTags.java +++ b/src/main/java/net/aufdemrand/denizen/tags/core/ServerTags.java @@ -41,9 +41,9 @@ import java.util.*; import java.util.regex.Pattern; -public class UtilTags implements Listener { +public class ServerTags implements Listener { - public UtilTags(Denizen denizen) { + public ServerTags(Denizen denizen) { denizen.getServer().getPluginManager().registerEvents(this, denizen); TagManager.registerTagEvents(this); } @@ -912,233 +912,4 @@ public static void adjustServer(Mechanism mechanism) { if (!mechanism.fulfilled()) mechanism.reportInvalid(); } - - - @TagManager.TagEvents - public void utilTag(ReplaceableTagEvent event) { - if (!event.matches("util", "u")) return; - - String type = event.getType() != null ? event.getType() : ""; - String typeContext = event.getTypeContext() != null ? event.getTypeContext() : ""; - String subType = event.getSubType() != null ? event.getSubType() : ""; - String subTypeContext = event.getSubTypeContext() != null ? event.getSubTypeContext().toUpperCase() : ""; - String specifier = event.getSpecifier() != null ? event.getSpecifier() : ""; - String specifierContext = event.getSpecifierContext() != null ? event.getSpecifierContext().toUpperCase() : ""; - Attribute attribute = event.getAttributes().fulfill(1); - - if (type.equalsIgnoreCase("RANDOM")) { - - // <--[tag] - // @attribute ].to[<#>]> - // @returns Element(Number) - // @description - // Returns a random number between the 2 specified numbers, inclusive. - // EG, random.int[1].to[3] could return 1, 2, or 3. - // --> - if (subType.equalsIgnoreCase("INT")) { - if (specifier.equalsIgnoreCase("TO")) { - if (aH.matchesInteger(subTypeContext) && aH.matchesInteger(specifierContext)) { - int min = aH.getIntegerFrom(subTypeContext); - int max = aH.getIntegerFrom(specifierContext); - - // in case the first number is larger than the second, reverse them - if (min > max) { - int store = min; - min = max; - max = store; - } - - event.setReplaced(new Element( - String.valueOf(CoreUtilities.getRandom().nextInt(max - min + 1) + min)) - .getAttribute(attribute.fulfill(3))); - } - } - } - - // <--[tag] - // @attribute - // @returns Element - // @description - // Returns a random decimal number from 0 to 1 - // --> - else if (subType.equalsIgnoreCase("DECIMAL")) - event.setReplaced(new Element(CoreUtilities.getRandom().nextDouble()) - .getAttribute(attribute.fulfill(2))); - - // <--[tag] - // @attribute - // @returns Element - // @description - // Returns a random decimal number with a gaussian distribution. - // 70% of all results will be within the range of -1 to 1. - // --> - else if (subType.equalsIgnoreCase("GAUSS")) - event.setReplaced(new Element(CoreUtilities.getRandom().nextGaussian()) - .getAttribute(attribute.fulfill(2))); - - // <--[tag] - // @attribute - // @returns Element - // @description - // Returns a random unique ID. - // --> - else if (subType.equalsIgnoreCase("UUID")) - event.setReplaced(new Element(UUID.randomUUID().toString()) - .getAttribute(attribute.fulfill(2))); - - // <--[tag] - // @attribute - // @returns Element - // @description - // Returns a random 'denizen' unique ID, which is made of a randomly generated sentence. - // --> - else if (subType.equalsIgnoreCase("DUUID")) - event.setReplaced(new Element(ScriptQueue - .getNextId(event.hasSubTypeContext() ? event.getSubTypeContext(): "DUUID")) - .getAttribute(attribute.fulfill(2))); - } - - // <--[tag] - // @attribute - // @returns Element - // @description - // Returns PI: 3.141592653589793 - // --> - else if (type.equalsIgnoreCase("pi")) { - event.setReplaced(new Element(Math.PI) - .getAttribute(attribute.fulfill(1))); - } - - // <--[tag] - // @attribute - // @returns Element - // @description - // Returns Tau: 6.283185307179586 - // --> - else if (type.equalsIgnoreCase("tau")) { - event.setReplaced(new Element(Math.PI * 2) - .getAttribute(attribute.fulfill(1))); - } - - // <--[tag] - // @attribute - // @returns Element - // @description - // Returns the current system date. - // --> - else if (type.equalsIgnoreCase("DATE")) { - Calendar calendar = Calendar.getInstance(); - Date currentDate = new Date(); - SimpleDateFormat format = new SimpleDateFormat(); - - // <--[tag] - // @attribute - // @returns Element - // @description - // Returns the current system time. - // --> - if (subType.equalsIgnoreCase("TIME")) { - - // <--[tag] - // @attribute - // @returns Element - // @description - // Returns the current system time in 24-hour format. - // --> - if (specifier.equalsIgnoreCase("TWENTYFOUR_HOUR")) { - format.applyPattern("k:mm"); - event.setReplaced(new Element(format.format(currentDate)) - .getAttribute(attribute.fulfill(3))); - } - // <--[tag] - // @attribute - // @returns Element(Number) - // @description - // Returns the current year of the system time. - // --> - else if (specifier.equalsIgnoreCase("year")) - event.setReplaced(new Element(calendar.get(Calendar.YEAR)).getAttribute(attribute.fulfill(3))); - // <--[tag] - // @attribute - // @returns Element(Number) - // @description - // Returns the current month of the system time. - // --> - else if (specifier.equalsIgnoreCase("month")) - event.setReplaced(new Element(calendar.get(Calendar.MONTH) + 1).getAttribute(attribute.fulfill(3))); - // <--[tag] - // @attribute - // @returns Element(Number) - // @description - // Returns the current day of the system time. - // --> - else if (specifier.equalsIgnoreCase("day")) - event.setReplaced(new Element(calendar.get(Calendar.DAY_OF_MONTH)).getAttribute(attribute.fulfill(3))); - // <--[tag] - // @attribute - // @returns Element(Number) - // @description - // Returns the current hour of the system time. - // --> - else if (specifier.equalsIgnoreCase("hour")) - event.setReplaced(new Element(calendar.get(Calendar.HOUR_OF_DAY)).getAttribute(attribute.fulfill(3))); - // <--[tag] - // @attribute - // @returns Element(Number) - // @description - // Returns the current minute of the system time. - // --> - else if (specifier.equalsIgnoreCase("minute")) - event.setReplaced(new Element(calendar.get(Calendar.MINUTE)).getAttribute(attribute.fulfill(3))); - // <--[tag] - // @attribute - // @returns Element(Number) - // @description - // Returns the current second of the system time. - // --> - else if (specifier.equalsIgnoreCase("second")) - event.setReplaced(new Element(calendar.get(Calendar.SECOND)).getAttribute(attribute.fulfill(3))); - // <--[tag] - // @attribute - // @returns Duration - // @description - // Returns the current system time as a duration. - // To get the exact millisecond count, use <@link tag server.current_time_millis>. - // --> - else if (specifier.equalsIgnoreCase("duration")) - event.setReplaced(new Duration(System.currentTimeMillis() / 50).getAttribute(attribute.fulfill(3))); - else { - format.applyPattern("K:mm a"); - event.setReplaced(format.format(currentDate)); - } - - } - - // @description - // Returns the current system time, formatted as specified - // Example format: [EEE, MMM d, yyyy K:mm a] will become "Mon, Jan 1, 2112 0:01 AM" - // --> - else if (subType.equalsIgnoreCase("FORMAT") && !subTypeContext.equalsIgnoreCase("")) { - try { - format.applyPattern(subTypeContext); - event.setReplaced(format.format(currentDate)); - } - catch (Exception ex) { - dB.echoError("Error: invalid pattern '" + subTypeContext + "'"); - dB.echoError(ex); - } - } - else { - format.applyPattern("EEE, MMM d, yyyy"); - event.setReplaced(format.format(currentDate)); - } - - } - - // Deprecated - else if (type.equalsIgnoreCase("AS_ELEMENT")) { - event.setReplaced(new Element(typeContext).getAttribute(attribute.fulfill(1))); - } - - } }