Skip to content

Commit

Permalink
variety of minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 21, 2022
1 parent 69e5b56 commit a3ee8ab
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 22 deletions.
Expand Up @@ -1151,7 +1151,7 @@ else if (comparedto.startsWith("material_flagged:")) {
}

public static boolean tryEntity(EntityTag entity, String comparedto) {
if (comparedto == null || comparedto.isEmpty() || entity == null) {
if (entity == null) {
return false;
}
return entity.tryAdvancedMatcher(comparedto);
Expand Down
Expand Up @@ -26,7 +26,7 @@ public class PlayerCompletesAdvancementScriptEvent extends BukkitScriptEvent imp
//
// @Context
// <context.criteria> returns all the criteria present in this advancement.
// <context.advancement> returns the name of advancement completed.
// <context.advancement> returns the completed advancement's minecraft ID key.
//
// @Player Always.
//
Expand Down
Expand Up @@ -284,7 +284,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {

@Override
public void applyProperty(Mechanism mechanism) {
Debug.echoError("Cannot apply properties to a biome!");
mechanism.echoError("Cannot apply properties to a biome!");
}

@Override
Expand Down
Expand Up @@ -694,7 +694,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
}

public void applyProperty(Mechanism mechanism) {
Debug.echoError("Cannot apply properties to a chunk!");
mechanism.echoError("Cannot apply properties to a chunk!");
}

@Override
Expand Down
Expand Up @@ -1511,7 +1511,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {

public void applyProperty(Mechanism mechanism) {
if (NoteManager.isExactSavedObject(this)) {
Debug.echoError("Cannot apply properties to noted objects.");
mechanism.echoError("Cannot apply properties to noted objects.");
return;
}
adjust(mechanism);
Expand Down
Expand Up @@ -465,6 +465,9 @@ else if (text.startsWith("npc_flagged:")) {
}

public final boolean tryAdvancedMatcher(String text) {
if (text == null || text.isEmpty()) {
return false;
}
ScriptEvent.MatchHelper matcher = ScriptEvent.createMatcher(CoreUtilities.toLowerCase(text));
if (isCitizensNPC()) {
return matcher.doesMatch("npc", this::tryExactMatcher);
Expand Down Expand Up @@ -3011,7 +3014,7 @@ public void applyProperty(Mechanism mechanism) {
mechanism.fulfill();
}
else {
Debug.echoError("Cannot apply properties to an already-spawned entity!");
mechanism.echoError("Cannot apply properties to an already-spawned entity!");
}
}

Expand All @@ -3026,10 +3029,10 @@ public void adjust(Mechanism mechanism) {

if (getBukkitEntity() == null) {
if (isCitizensNPC()) {
Debug.echoError("Cannot adjust not-spawned NPC " + getDenizenNPC());
mechanism.echoError("Cannot adjust not-spawned NPC " + getDenizenNPC());
}
else {
Debug.echoError("Cannot adjust entity " + this);
mechanism.echoError("Cannot adjust entity " + this);
}
return;
}
Expand Down Expand Up @@ -4049,6 +4052,6 @@ else if (getBukkitEntity() instanceof Creeper) {

@Override
public boolean advancedMatches(String matcher) {
return BukkitScriptEvent.tryEntity(this, matcher);
return tryAdvancedMatcher(matcher);
}
}
Expand Up @@ -2330,7 +2330,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
}

public void applyProperty(Mechanism mechanism) {
Debug.echoError("Cannot apply properties to non-generic inventory!");
mechanism.echoError("Cannot apply properties to non-generic inventory!");
}

@Override
Expand All @@ -2349,7 +2349,7 @@ public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("matrix") && mechanism.requireObject(ListTag.class)) {
if (!(inventory instanceof CraftingInventory)) {
Debug.echoError("Inventory is not a crafting inventory, cannot set matrix.");
mechanism.echoError("Inventory is not a crafting inventory, cannot set matrix.");
return;
}
CraftingInventory craftingInventory = (CraftingInventory) inventory;
Expand Down
Expand Up @@ -4109,7 +4109,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
}

public void applyProperty(Mechanism mechanism) {
Debug.echoError("Cannot apply properties to a location!");
mechanism.echoError("Cannot apply properties to a location!");
}

@Override
Expand All @@ -4129,7 +4129,7 @@ public void adjust(Mechanism mechanism) {
Block block = getBlock();
MaterialTag material = new MaterialTag(block);
if (!MaterialDirectional.describes(material)) {
Debug.echoError("LocationTag.block_facing mechanism failed: block is not directional.");
mechanism.echoError("LocationTag.block_facing mechanism failed: block is not directional.");
return;
}
MaterialDirectional.getFrom(material).setFacing(Utilities.faceFor(faceVec.toVector()));
Expand Down
Expand Up @@ -1277,7 +1277,7 @@ public ObjectTag getNextObjectTypeDown() {
}

public void applyProperty(Mechanism mechanism) {
Debug.echoError("Cannot apply properties to an NPC!");
mechanism.echoError("Cannot apply properties to an NPC!");
}

@Override
Expand Down
Expand Up @@ -2501,7 +2501,7 @@ public ObjectTag getNextObjectTypeDown() {
}

public void applyProperty(Mechanism mechanism) {
Debug.echoError("Cannot apply properties to a player!");
mechanism.echoError("Cannot apply properties to a player!");
}

@Override
Expand Down
Expand Up @@ -714,7 +714,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {

public void applyProperty(Mechanism mechanism) {
if (NoteManager.isExactSavedObject(this)) {
Debug.echoError("Cannot apply properties to noted objects.");
mechanism.echoError("Cannot apply properties to noted objects.");
return;
}
adjust(mechanism);
Expand Down
Expand Up @@ -924,7 +924,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
}

public void applyProperty(Mechanism mechanism) {
Debug.echoError("Cannot apply properties to a world!");
mechanism.echoError("Cannot apply properties to a world!");
}

@Override
Expand Down
Expand Up @@ -32,9 +32,13 @@ public static int getWidth(char c) {
public static AsciiMatcher formatCharCodeMatcher = new AsciiMatcher("klmnoKLMNO");

public static int getWidth(String str) {
return getWidth(false, str);
}

public static int getWidth(boolean wasBold, String str) {
int maxWidth = 0;
int total = 0;
boolean bold = false;
boolean bold = wasBold;
char[] rawChars = str.toCharArray();
for (int i = 0; i < rawChars.length; i++) {
char c = rawChars[i];
Expand Down Expand Up @@ -94,14 +98,18 @@ public static String splitLines(String str, int width) {
mainloop:
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (c == ChatColor.COLOR_CHAR) {
i++;
continue;
}
if (c == '\n') {
String lastLine = str.substring(lineStart, i + 1);
bold = isBold(bold, lastLine);
output.append(lastLine);
lineStart = i + 1;
continue;
}
if (getWidth(((bold ? ChatColor.BOLD.toString() : "") + str.substring(lineStart, i))) > width) {
if (getWidth(bold, str.substring(lineStart, i)) > width) {
for (int x = i - 1; x > lineStart; x--) {
char xc = str.charAt(x);
if (xc == ' ') {
Expand Down
3 changes: 0 additions & 3 deletions plugin/src/main/resources/config.yml
Expand Up @@ -54,9 +54,6 @@ Scripts:
Queue speed: instant
# Default speed for new queues (via run command usually)
Queue speed: instant
Scripts location:
Use default script folder: true
Alternative folder path: 'plugins/Denizen'
# What character encoding to use. 'default' indicates system default, 'utf8' is suggested as a preferred encoding in most cases.
Encoding: utf8
Command:
Expand Down

0 comments on commit a3ee8ab

Please sign in to comment.