Skip to content

Commit

Permalink
Defer to the server's scoreboard string length limits
Browse files Browse the repository at this point in the history
  • Loading branch information
PseudoKnight committed Aug 3, 2018
1 parent 935ba10 commit 887c7d6
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions src/main/java/com/laytonsmith/core/functions/Scoreboards.java
Expand Up @@ -650,11 +650,11 @@ public Construct exec(Target t, Environment environment, Construct... args) thro
} else { } else {
dname = dis.get("displayname", t).val(); dname = dis.get("displayname", t).val();
} }
if(dname.length() > 32) { try {
throw new CRELengthException("Displayname can only be 32 characters but was " o.setDisplayName(dname);
+ dname.length(), t); } catch (IllegalArgumentException ex) {
throw new CRELengthException(ex.getMessage(), t);
} }
o.setDisplayName(dname);
} }
return CVoid.VOID; return CVoid.VOID;
} }
Expand All @@ -677,7 +677,7 @@ public String docs() {
+ " with keys 'displayname' and/or 'slot', affecting their respective properties." + " with keys 'displayname' and/or 'slot', affecting their respective properties."
+ " Null name resets it to the actual name, and null slot removes it from" + " Null name resets it to the actual name, and null slot removes it from"
+ " all displays. Slot can be one of: " + StringUtils.Join(MCDisplaySlot.values(), ", ", ", or ") + " all displays. Slot can be one of: " + StringUtils.Join(MCDisplaySlot.values(), ", ", ", or ")
+ ". Displayname can be a max of 32 characters, otherwise it throws a LengthException. " + DEF_MSG; + ". " + DEF_MSG;
} }


@Override @Override
Expand Down Expand Up @@ -714,11 +714,11 @@ public Construct exec(Target t, Environment environment, Construct... args) thro
} else { } else {
dname = dis.get("displayname", t).val(); dname = dis.get("displayname", t).val();
} }
if(dname.length() > 32) { try {
throw new CRELengthException("Displayname can only be 32 characters but was " o.setDisplayName(dname);
+ dname.length(), t); } catch (IllegalArgumentException ex) {
throw new CRELengthException(ex.getMessage(), t);
} }
o.setDisplayName(dname);
} }
if(dis.containsKey("prefix")) { if(dis.containsKey("prefix")) {
String prefix; String prefix;
Expand All @@ -727,11 +727,11 @@ public Construct exec(Target t, Environment environment, Construct... args) thro
} else { } else {
prefix = dis.get("prefix", t).val(); prefix = dis.get("prefix", t).val();
} }
if(prefix.length() > 16) { try {
throw new CRELengthException("Prefix can only be 16 characters but was " o.setPrefix(prefix);
+ prefix.length(), t); } catch (IllegalArgumentException ex) {
throw new CRELengthException(ex.getMessage(), t);
} }
o.setPrefix(prefix);
} }
if(dis.containsKey("suffix")) { if(dis.containsKey("suffix")) {
String suffix; String suffix;
Expand All @@ -740,11 +740,11 @@ public Construct exec(Target t, Environment environment, Construct... args) thro
} else { } else {
suffix = dis.get("suffix", t).val(); suffix = dis.get("suffix", t).val();
} }
if(suffix.length() > 16) { try {
throw new CRELengthException("Suffix can only be 16 characters but was " o.setSuffix(suffix);
+ suffix.length(), t); } catch (IllegalArgumentException ex) {
throw new CRELengthException(ex.getMessage(), t);
} }
o.setSuffix(suffix);
} }
return CVoid.VOID; return CVoid.VOID;
} }
Expand All @@ -767,8 +767,7 @@ public String docs() {
+ " otherwise arg 2 should be an array with keys 'displayname', 'prefix'," + " otherwise arg 2 should be an array with keys 'displayname', 'prefix',"
+ " and/or 'suffix', affecting their respective properties." + " and/or 'suffix', affecting their respective properties."
+ " Null name resets it to the actual name, and null prefix or suffix removes it from" + " Null name resets it to the actual name, and null prefix or suffix removes it from"
+ " all displays. Displayname can be a max of 32 characters," + " all displays. " + DEF_MSG;
+ " prefix and suffix can only be 16, otherwise a LengthException is thrown. " + DEF_MSG;
} }


@Override @Override
Expand Down Expand Up @@ -1074,10 +1073,11 @@ public Construct exec(Target t, Environment environment, Construct... args) thro
if(o == null) { if(o == null) {
throw new CREScoreboardException("The given objective does not exist.", t); throw new CREScoreboardException("The given objective does not exist.", t);
} }
if(args[1].val().length() > 40) { try {
throw new CRELengthException("Player names can only be 40 characters.", t); o.getScore(args[1].val()).setScore(Static.getInt32(args[2], t));
} catch (IllegalArgumentException ex) {
throw new CRELengthException(ex.getMessage(), t);
} }
o.getScore(args[1].val()).setScore(Static.getInt32(args[2], t));
return CVoid.VOID; return CVoid.VOID;
} }


Expand All @@ -1094,7 +1094,8 @@ public Integer[] numArgs() {
@Override @Override
public String docs() { public String docs() {
return "void {objectiveName, name, int, [scoreboard]} Sets the player's score for the given objective." return "void {objectiveName, name, int, [scoreboard]} Sets the player's score for the given objective."
+ " You can set scores for fake players with up to 40 characters. " + DEF_MSG; + " The name can be anything, not just player names. An LengthException is thrown if it's too long."
+ DEF_MSG;
} }


@Override @Override
Expand Down

0 comments on commit 887c7d6

Please sign in to comment.