Skip to content

Commit 896957e

Browse files
committed
Update length limits for fake players in scoreboards
1 parent 53481b4 commit 896957e

File tree

4 files changed

+24
-30
lines changed

4 files changed

+24
-30
lines changed

src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCObjective.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import com.laytonsmith.abstraction.MCScore;
66
import com.laytonsmith.abstraction.MCScoreboard;
77
import com.laytonsmith.abstraction.enums.MCDisplaySlot;
8+
import com.laytonsmith.abstraction.enums.MCVersion;
89
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCDisplaySlot;
10+
import com.laytonsmith.core.Static;
911
import org.bukkit.Bukkit;
1012
import org.bukkit.OfflinePlayer;
1113
import org.bukkit.scoreboard.DisplaySlot;
@@ -45,10 +47,9 @@ public String getName() {
4547

4648
@Override
4749
public MCScore getScore(String entry) {
48-
if(ReflectionUtils.hasMethod(o.getClass(), "getScore", null, String.class)){
50+
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_7_10)){
4951
return new BukkitMCScore(o.getScore(entry));
5052
} else {
51-
// Old style
5253
OfflinePlayer player = Bukkit.getOfflinePlayer(entry);
5354
return new BukkitMCScore((Score) ReflectionUtils.invokeMethod(o, "getScore", player));
5455
}

src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCScoreboard.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import com.laytonsmith.abstraction.MCScoreboard;
88
import com.laytonsmith.abstraction.MCTeam;
99
import com.laytonsmith.abstraction.enums.MCDisplaySlot;
10+
import com.laytonsmith.abstraction.enums.MCVersion;
1011
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCDisplaySlot;
12+
import com.laytonsmith.core.Static;
1113
import org.bukkit.Bukkit;
1214
import org.bukkit.OfflinePlayer;
1315
import org.bukkit.scoreboard.Objective;
@@ -72,7 +74,7 @@ public Set<MCObjective> getObjectivesByCriteria(String criteria) {
7274

7375
@Override
7476
public Set<String> getEntries() {
75-
if(ReflectionUtils.hasMethod(s.getClass(), "getEntries", null)){
77+
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_7_10)){
7678
return s.getEntries();
7779
} else {
7880
// Old style, where we have to build it from the list of players
@@ -96,12 +98,11 @@ public MCTeam getPlayerTeam(MCOfflinePlayer player) {
9698
@Override
9799
public Set<MCScore> getScores(String entry) {
98100
Set<MCScore> ret = new HashSet<>();
99-
if(ReflectionUtils.hasMethod(s.getClass(), "getScores", null, String.class)){
101+
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_7_10)){
100102
for (Score o : s.getScores(entry)) {
101103
ret.add(new BukkitMCScore(o));
102104
}
103105
} else {
104-
// Old style, we have to build the list of offline players ourselves
105106
OfflinePlayer player = Bukkit.getOfflinePlayer(entry);
106107
for (Score o : (Set<Score>) ReflectionUtils.invokeMethod(s, "getScores", player)) {
107108
ret.add(new BukkitMCScore(o));
@@ -140,7 +141,7 @@ public MCTeam registerNewTeam(String name) {
140141

141142
@Override
142143
public void resetScores(String entry) {
143-
if(ReflectionUtils.hasMethod(s.getClass(), "resetScores", null, String.class)){
144+
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_7_10)){
144145
s.resetScores(entry);
145146
} else {
146147
OfflinePlayer player = Bukkit.getOfflinePlayer(entry);

src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCTeam.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import java.util.Set;
88

99
import com.laytonsmith.abstraction.enums.MCNameTagVisibility;
10+
import com.laytonsmith.abstraction.enums.MCVersion;
1011
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCNameTagVisibility;
12+
import com.laytonsmith.core.Static;
1113
import org.bukkit.Bukkit;
1214
import org.bukkit.OfflinePlayer;
1315
import org.bukkit.scoreboard.NameTagVisibility;
@@ -22,11 +24,9 @@ public BukkitMCTeam(Team team) {
2224

2325
@Override
2426
public void addEntry(String entry) {
25-
if(ReflectionUtils.hasMethod(t.getClass(), "addEntry", null, String.class)){
26-
// Spigot method
27+
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_8_7)){
2728
t.addEntry(entry);
2829
} else {
29-
// Bukkit method
3030
OfflinePlayer player = Bukkit.getOfflinePlayer(entry);
3131
ReflectionUtils.invokeMethod(t, "addPlayer", player);
3232
}
@@ -61,13 +61,11 @@ public MCNameTagVisibility getNameTagVisibility() {
6161
@Override
6262
public Set<String> getEntries() {
6363
Set<String> ret = new HashSet<String>();
64-
if(ReflectionUtils.hasMethod(t.getClass(), "getEntries", null)) {
65-
// Spigot method
64+
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_8_7)){
6665
for (String e : t.getEntries()) {
6766
ret.add(e);
6867
}
6968
} else {
70-
// Bukkit method
7169
for (OfflinePlayer o : (Set<OfflinePlayer>) ReflectionUtils.invokeMethod(t, "getPlayers")) {
7270
ret.add(o.getName());
7371
}
@@ -97,23 +95,19 @@ public String getSuffix() {
9795

9896
@Override
9997
public boolean hasEntry(String entry) {
100-
if(ReflectionUtils.hasMethod(t.getClass(), "hasEntry", null, String.class)){
101-
// Spigot method
98+
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_8_7)){
10299
return t.hasEntry(entry);
103100
} else {
104-
// Bukkit method
105101
OfflinePlayer player = Bukkit.getOfflinePlayer(entry);
106102
return (boolean) ReflectionUtils.invokeMethod(t, "hasPlayer", player);
107103
}
108104
}
109105

110106
@Override
111107
public boolean removeEntry(String entry) {
112-
if(ReflectionUtils.hasMethod(t.getClass(), "removeEntry", null, String.class)){
113-
// Spigot method
108+
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_8_7)){
114109
return t.removeEntry(entry);
115110
} else {
116-
// Bukkit method
117111
OfflinePlayer player = Bukkit.getOfflinePlayer(entry);
118112
return (boolean) ReflectionUtils.invokeMethod(t, "removePlayer", player);
119113
}

src/main/java/com/laytonsmith/core/functions/Scoreboards.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -738,8 +738,9 @@ public Construct exec(Target t, Environment environment,
738738
if (team == null) {
739739
throw new ScoreboardException("No team by that name exists.", t);
740740
}
741-
if (args[1].val().length() > 16) {
742-
throw new Exceptions.LengthException("Player names can only be 16 characters.", t);
741+
if (args[1].val().length() > 40
742+
|| (args[1].val().length() > 16 && Static.getServer().getMinecraftVersion().lt(MCVersion.MC1_8_7))){
743+
throw new Exceptions.LengthException("Player name is too long.", t);
743744
}
744745
team.addEntry(args[1].val());
745746
return CVoid.VOID;
@@ -757,10 +758,9 @@ public Integer[] numArgs() {
757758

758759
@Override
759760
public String docs() {
760-
return "void {teamName, player, [scoreboard]} Adds a player to a team, given the team exists."
761-
+ " Offline players can be added, so the name must be exact. Alternatively,"
762-
+ " this allows you to add fake players, but names can still only be 16 characters."
763-
+ " The player will be removed from any other team on the same scoreboard. " + DEF_MSG;
761+
return "void {teamName, player, [scoreboard]} Adds a player to a team, given the team exists. This allows"
762+
+ " you to add fake players with up to 40 characters. (16 characters prior to 1.8.7) The player"
763+
+ " will be removed from any other team on the same scoreboard. " + DEF_MSG;
764764
}
765765
}
766766

@@ -962,8 +962,8 @@ public Construct exec(Target t, Environment environment,
962962
if (o == null) {
963963
throw new ScoreboardException("The given objective does not exist.", t);
964964
}
965-
if (args[1].val().length() > 16) {
966-
throw new Exceptions.LengthException("Player names can only be 16 characters.", t);
965+
if (args[1].val().length() > 40){
966+
throw new Exceptions.LengthException("Player names can only be 40 characters.", t);
967967
}
968968
o.getScore(args[1].val()).setScore(Static.getInt32(args[2], t));
969969
return CVoid.VOID;
@@ -981,10 +981,8 @@ public Integer[] numArgs() {
981981

982982
@Override
983983
public String docs() {
984-
return "void {objectiveName, name, int, [scoreboard]} Sets the player's score for the given objective,"
985-
+ " or an arbitrary name if not a valid player name."
986-
+ " You can set scores for fake players to create custom displays,"
987-
+ " but the 16 character name limit still applies. " + DEF_MSG;
984+
return "void {objectiveName, name, int, [scoreboard]} Sets the player's score for the given objective."
985+
+ " You can set scores for fake players with up to 40 characters. " + DEF_MSG;
988986
}
989987
}
990988

0 commit comments

Comments
 (0)