Skip to content

Commit

Permalink
update for Major core rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 25, 2018
1 parent 5f12b12 commit 9aa9860
Show file tree
Hide file tree
Showing 32 changed files with 370 additions and 339 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public dPlayer getPlayer() {
}

public dNPC getNPC() {
return npc;
return npc != null && npc.getCitizen() != null ? npc : null;
}

public boolean hasNPC() {
return npc != null;
return npc != null && npc.getCitizen() != null;
}

public boolean hasPlayer() {
Expand Down
212 changes: 119 additions & 93 deletions plugin/src/main/java/net/aufdemrand/denizen/Denizen.java

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions plugin/src/main/java/net/aufdemrand/denizen/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public static boolean overrideHelp() {

public static int consoleWidth() {
return DenizenAPI.getCurrentInstance().getConfig()
.getInt("Debug.Console width", 60);
.getInt("Debug.Line length", 128);
}

public static int trimLength() {
return DenizenAPI.getCurrentInstance().getConfig()
.getInt("Debug.Trim length", 512);
.getInt("Debug.Trim length limit", 1024);
}

public static boolean showExHelp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;

// <--[event]
// @Events
// player crafts item
// player crafts <item>
//
// @Regex ^on player crafts [^\s]+$
//
// @Cancellable true
//
// @Triggers when a player fully crafts an item.
// @Context
// <context.inventory> returns the dInventory of the crafting inventory.
// <context.item> returns the dItem to be crafted.
// <context.recipe> returns a dList of dItems in the recipe.
//
// @Determine
// dItem to change the item that is crafted.
//
// -->

public class PlayerCraftsItemScriptEvent extends BukkitScriptEvent implements Listener {

// <--[event]
// @Events
// player crafts item
// player crafts <item>
//
// @Regex ^on player crafts [^\s]+$
//
// @Cancellable true
//
// @Triggers when a player fully crafts an item.
// @Context
// <context.inventory> returns the dInventory of the crafting inventory.
// <context.item> returns the dItem to be crafted.
// <context.recipe> returns a dList of dItems in the recipe.
//
// @Determine
// dItem to change the item that is crafted.
//
// -->

public PlayerCraftsItemScriptEvent() {
instance = this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ public String getAttribute(Attribute attribute) {
// Works with offline players.
// -->
if (attribute.startsWith("chat_history_list")) {
return new dList(PlayerTags.playerChatHistory.get(getName())) // TODO: UUID?
return new dList(PlayerTags.playerChatHistory.get(getPlayerEntity().getUniqueId()))
.getAttribute(attribute.fulfill(1));
}

Expand All @@ -713,10 +713,10 @@ public String getAttribute(Attribute attribute) {
x = attribute.getIntContext(1);
}
// No playerchathistory? Return null.
if (!PlayerTags.playerChatHistory.containsKey(getName())) { // TODO: UUID?
if (!PlayerTags.playerChatHistory.containsKey(getPlayerEntity().getUniqueId())) {
return null;
}
List<String> messages = PlayerTags.playerChatHistory.get(getName()); // TODO: UUID?
List<String> messages = PlayerTags.playerChatHistory.get(getPlayerEntity().getUniqueId());
if (messages.size() < x || x < 1) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,74 +34,17 @@ private BukkitElementProperties(Element element) {
this.element = element;
}

public static final String[] handledAttribs = new String[] {
"aschunk", "as_chunk", "ascolor", "as_color", "ascuboid", "as_cuboid", "asentity", "as_entity",
"asinventory", "as_inventory", "asitem", "as_item", "aslocation", "as_location", "asmaterial",
"as_material", "asnpc", "as_npc", "asplayer", "as_player", "asworld", "as_world", "asplugin",
"as_plugin", "last_color", "format", "strip_color", "parse_color", "to_itemscript_hash" };

Element element;

@Override
public String getAttribute(Attribute attribute) {

// <--[tag]
// @attribute <el@element.is[<operator>].to[<element>]>
// @returns Element(Boolean)
// @group comparison
// @description
// Takes an operator, and compares the value of the element to the supplied
// element. Returns the outcome of the comparable, either true or false. For
// information on operators, see <@link language operator>.
// Equivalent to <@link tag el@element.is[<operator>].than[<element>]>
// -->

// <--[tag]
// @attribute <el@element.is[<operator>].than[<element>]>
// @returns Element(Boolean)
// @group comparison
// @description
// Takes an operator, and compares the value of the element to the supplied
// element. Returns the outcome of the comparable, either true or false. For
// information on operators, see <@link language operator>.
// Equivalent to <@link tag el@element.is[<operator>].to[<element>]>
// -->
if (attribute.startsWith("is") && attribute.hasContext(1)
&& (attribute.startsWith("to", 2) || attribute.startsWith("than", 2)) && attribute.hasContext(2)) {

// Use the Comparable object as implemented for the IF command. First, a new Comparable!
Comparable com = new Comparable();

// Check for negative logic
String operator;
if (attribute.getContext(1).startsWith("!")) {
operator = attribute.getContext(1).substring(1);
com.setNegativeLogic();
}
else {
operator = attribute.getContext(1);
}

// Operator is the value of the .is[] context. Valid are Comparable.Operators, same
// as used by the IF command.
Comparable.Operator comparableOperator = null;
try {
comparableOperator = Comparable.Operator.valueOf(operator.replace("==", "EQUALS")
.replace(">=", "OR_MORE").replace("<=", "OR_LESS").replace("<", "LESS")
.replace(">", "MORE").replace("=", "EQUALS").toUpperCase());
}
catch (IllegalArgumentException e) {
}

if (comparableOperator != null) {
com.setOperator(comparableOperator);

// Comparable is the value of this element
com.setComparable(element.asString());
// Compared_to is the value of the .to[] context.
com.setComparedto(attribute.getContext(2));

return new Element(com.determineOutcome()).getAttribute(attribute.fulfill(2));
}
else {
net.aufdemrand.denizencore.utilities.debugging.dB.echoError("Unknown operator '" + operator + "'.");
}
}

// <--[tag]
// @attribute <el@element.as_chunk>
// @returns dChunk
Expand Down Expand Up @@ -295,18 +238,6 @@ public String getAttribute(Attribute attribute) {
}
}

// <--[tag]
// @attribute <el@element.debug.no_color>
// @returns Element
// @group debug
// @description
// Returns a standard debug representation of the Element with colors stripped.
// -->
if (attribute.startsWith("debug.no_color")) {
return new Element(ChatColor.stripColor(element.debug()))
.getAttribute(attribute.fulfill(2));
}

// <--[tag]
// @attribute <el@element.last_color>
// @returns Element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4263,7 +4263,7 @@ public void registerCoreMembers() {

// <--[command]
// @Name While
// @Syntax while [stop/next/<comparison tag>] [<commands>]
// @Syntax while [stop/next/[<value>] (!)(<operator> <value>) (&&/|| ...)] [<commands>]
// @Required 1
// @Stable stable
// @Short Runs a series of braced commands until the tag returns false.
Expand All @@ -4278,11 +4278,10 @@ public void registerCoreMembers() {
// <def[loop_index]> to get the number of loops so far.
//
// @Usage
// Use loop through a command several times.
// - define value 1
// - while <def[value].is[OR_LESS].than[5]> {
// - announce "Loop <def[loop_index]> value <def[value]>"
// - define value <def[value].add[1]>
// Use to loop until a player sneaks, or the player goes offline.
// - while !<player.is_sneaking> && <player.is_online> {
// - narrate "Waiting for you to sneak..."
// - wait 1s
// }
//
// @Usage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ else if (scriptEntry.hasObject("path")) {
}

// For determine
ScriptBuilder.addObjectToEntries(entries, "ReqId", scriptEntry.getObject("ReqId"));
ScriptBuilder.addObjectToEntries(entries, "ReqId", scriptEntry.getObject("reqid"));

// If 'instantly' was specified, run the commands immediately.
if (scriptEntry.hasObject("instant")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

}
else {
queue.injectEntry(bracedCommands.get(selected).addObject("reqID", scriptEntry.getObject("reqID")), 0);
queue.injectEntry(bracedCommands.get(selected).addObject("reqID", scriptEntry.getObject("reqid")), 0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,26 @@ else if (callback != null && callback.asBoolean()) {
bracedCommands.add(callbackEntry);
for (int i = 0; i < bracedCommands.size(); i++) {
bracedCommands.get(i).setInstant(true);
bracedCommands.get(i).addObject("reqId", scriptEntry.getObject("reqId"));
bracedCommands.get(i).addObject("reqId", scriptEntry.getObject("reqid"));
}
scriptEntry.getResidingQueue().injectEntries(bracedCommands, 0);
}
else {
dB.echoDebug(scriptEntry, DebugElement.Header, "Repeat loop complete");
}
}
else {
dB.echoError("Repeat CALLBACK invalid: not a real callback!");
}
}
else {

// Get objects
List<ScriptEntry> bracedCommandsList =
((List<BracedData>) scriptEntry.getObject("braces")).get(0).value;
List<BracedData> data = ((List<BracedData>) scriptEntry.getObject("braces"));
if (data == null || data.isEmpty()) {
dB.echoError(scriptEntry.getResidingQueue(), "Empty braces (internal)!");
dB.echoError(scriptEntry.getResidingQueue(), "Empty braces!");
return;
}
List<ScriptEntry> bracedCommandsList = data.get(0).value;

if (bracedCommandsList == null || bracedCommandsList.isEmpty()) {
dB.echoError("Empty braces!");
Expand Down Expand Up @@ -197,7 +203,7 @@ else if (callback != null && callback.asBoolean()) {
scriptEntry.getResidingQueue().addDefinition("value", "1");
for (int i = 0; i < bracedCommandsList.size(); i++) {
bracedCommandsList.get(i).setInstant(true);
bracedCommandsList.get(i).addObject("reqId", scriptEntry.getObject("reqId"));
bracedCommandsList.get(i).addObject("reqId", scriptEntry.getObject("reqid"));
}
scriptEntry.getResidingQueue().injectEntries(bracedCommandsList, 0);
}
Expand Down
Loading

0 comments on commit 9aa9860

Please sign in to comment.