Patch skin command, rename command (#1524)

* Fix npc skin -t argument order

Command input is doc'd as (and should function as) data then signature, but the called method was signature then data... update calls it in correct order. Also, fixes doc to indicate that a name is valid input, not just uuid (not entirely sure how that is handled when sent out in a packet, but it seems to be correct to feed a name)

* Ensure rename command will handle scoreboard changes

Always update prefix/suffix, not just only when team is newly created
Guarantee removal entity from scoreboard team on remove
Also removes a fileheader screwup (first line changed in 1_12_R1 file)
Also removes non-used code bits (the two coloredName lines - they don't actually functionally do anything)
Also removes a duplicated data get call

* patch gamemode command

Uppercase + unique permission node

* patch for names of length 30
This commit is contained in:
Alex "mcmonkey" Goodwin 2018-06-26 21:00:03 -07:00 committed by fullwall
parent 432e92ac25
commit 42fda25ceb
6 changed files with 88 additions and 45 deletions

View File

@ -515,7 +515,7 @@ public class NPCCommands {
modifiers = { "gamemode" },
min = 1,
max = 2,
permission = "citizens.npc.gravity")
permission = "citizens.npc.gamemode")
@Requirements(selected = true, ownership = true, types = { EntityType.PLAYER })
public void gamemode(CommandContext args, CommandSender sender, NPC npc) {
Player player = (Player) npc.getEntity();
@ -530,7 +530,7 @@ public class NPCCommands {
mode = GameMode.getByValue(value);
} catch (NumberFormatException ex) {
try {
mode = GameMode.valueOf(args.getString(1));
mode = GameMode.valueOf(args.getString(1).toUpperCase());
} catch (IllegalArgumentException e) {
}
}
@ -1459,7 +1459,7 @@ public class NPCCommands {
@Command(
aliases = { "npc" },
usage = "skin (-c -l(atest)) [name] (or -t [uuid] [data] [signature])",
usage = "skin (-c -l(atest)) [name] (or -t [uuid/name] [data] [signature])",
desc = "Sets an NPC's skin name. Use -l to set the skin to always update to the latest",
modifiers = { "skin" },
min = 1,
@ -1479,7 +1479,7 @@ public class NPCCommands {
if (skinnable == null) {
throw new CommandException("Must be spawned.");
}
skinnable.setSkinPersistent(args.getString(1), args.getString(2), args.getString(3));
skinnable.setSkinPersistent(args.getString(1), args.getString(3), args.getString(2));
Messaging.sendTr(sender, Messages.SKIN_SET, npc.getName(), args.getString(1));
return;
} else {

View File

@ -229,6 +229,7 @@ permissions:
citizens.npc.edit.path: {default: false}
citizens.npc.edit.text: {default: false}
citizens.npc.gravity: {default: false}
citizens.npc.gamemode: {default: false}
citizens.npc.help: {default: false}
citizens.npc.help: {default: false}
citizens.npc.horse: {default: false}
@ -644,6 +645,7 @@ permissions:
citizens.npc.edit.path: true
citizens.npc.edit.text: true
citizens.npc.gravity: true
citizens.npc.gamemode: true
citizens.npc.help: true
citizens.npc.help: true
citizens.npc.horse: true
@ -1055,6 +1057,7 @@ permissions:
citizens.npc.edit.path: true
citizens.npc.edit.text: true
citizens.npc.gravity: true
citizens.npc.gamemode: true
citizens.npc.help: true
citizens.npc.help: true
citizens.npc.horse: true

View File

@ -38,7 +38,7 @@ public class HumanController extends AbstractEntityController {
String name = coloredName, prefix = null, suffix = null;
if (coloredName.length() > 16) {
prefix = coloredName.substring(0, 16);
if (coloredName.length() > 30) {
if (coloredName.length() >= 30) {
int len = 30;
name = coloredName.substring(16, 30);
if (NON_ALPHABET_MATCHER.matcher(name).matches()) {
@ -63,7 +63,6 @@ public class HumanController extends AbstractEntityController {
name = name.substring(0, 16);
}
}
coloredName = coloredName.substring(0, 16);
}
final String prefixCapture = prefix, suffixCapture = suffix;
@ -93,8 +92,7 @@ public class HumanController extends AbstractEntityController {
return;
boolean removeFromPlayerList = npc.data().get("removefromplayerlist",
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
NMS.addOrRemoveFromPlayerList(getBukkitEntity(),
npc.data().get("removefromplayerlist", removeFromPlayerList));
NMS.addOrRemoveFromPlayerList(getBukkitEntity(), removeFromPlayerList);
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
@ -103,12 +101,12 @@ public class HumanController extends AbstractEntityController {
Team team = scoreboard.getTeam(teamName);
if (team == null) {
team = scoreboard.registerNewTeam(teamName);
if (prefixCapture != null) {
team.setPrefix(prefixCapture);
}
if (suffixCapture != null) {
team.setSuffix(suffixCapture);
}
}
if (prefixCapture != null) {
team.setPrefix(prefixCapture);
}
if (suffixCapture != null) {
team.setSuffix(suffixCapture);
}
team.addPlayer(handle.getBukkitEntity());
@ -131,6 +129,18 @@ public class HumanController extends AbstractEntityController {
public void remove() {
Player entity = getBukkitEntity();
if (entity != null) {
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
String teamName = entity.getUniqueId().toString().substring(0, 16);
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
Team team = scoreboard.getTeam(teamName);
if (team != null && team.hasPlayer(entity)) {
if (team.getSize() == 1) {
team.setPrefix("");
team.setSuffix("");
}
team.removePlayer(entity);
}
}
NMS.removeFromWorld(entity);
SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null;
npc.getSkinTracker().onRemoveNPC();

View File

@ -38,7 +38,7 @@ public class HumanController extends AbstractEntityController {
String name = coloredName, prefix = null, suffix = null;
if (coloredName.length() > 16) {
prefix = coloredName.substring(0, 16);
if (coloredName.length() > 30) {
if (coloredName.length() >= 30) {
int len = 30;
name = coloredName.substring(16, 30);
if (NON_ALPHABET_MATCHER.matcher(name).matches()) {
@ -63,7 +63,6 @@ public class HumanController extends AbstractEntityController {
name = name.substring(0, 16);
}
}
coloredName = coloredName.substring(0, 16);
}
final String prefixCapture = prefix, suffixCapture = suffix;
@ -93,8 +92,7 @@ public class HumanController extends AbstractEntityController {
return;
boolean removeFromPlayerList = npc.data().get("removefromplayerlist",
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
NMS.addOrRemoveFromPlayerList(getBukkitEntity(),
npc.data().get("removefromplayerlist", removeFromPlayerList));
NMS.addOrRemoveFromPlayerList(getBukkitEntity(), removeFromPlayerList);
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
@ -103,12 +101,12 @@ public class HumanController extends AbstractEntityController {
Team team = scoreboard.getTeam(teamName);
if (team == null) {
team = scoreboard.registerNewTeam(teamName);
if (prefixCapture != null) {
team.setPrefix(prefixCapture);
}
if (suffixCapture != null) {
team.setSuffix(suffixCapture);
}
}
if (prefixCapture != null) {
team.setPrefix(prefixCapture);
}
if (suffixCapture != null) {
team.setSuffix(suffixCapture);
}
team.addPlayer(handle.getBukkitEntity());
@ -131,6 +129,18 @@ public class HumanController extends AbstractEntityController {
public void remove() {
Player entity = getBukkitEntity();
if (entity != null) {
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
String teamName = entity.getUniqueId().toString().substring(0, 16);
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
Team team = scoreboard.getTeam(teamName);
if (team != null && team.hasPlayer(entity)) {
if (team.getSize() == 1) {
team.setPrefix("");
team.setSuffix("");
}
team.removePlayer(entity);
}
}
NMS.removeFromWorld(entity);
SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null;
npc.getSkinTracker().onRemoveNPC();

View File

@ -1,4 +1,4 @@
package net.citizensnpcs.nms.v1_12_R1.entity; import net.minecraft.server.v1_12_R1.DamageSource;
package net.citizensnpcs.nms.v1_12_R1.entity;
import java.util.UUID;
import java.util.regex.Pattern;
@ -38,7 +38,7 @@ public class HumanController extends AbstractEntityController {
String name = coloredName, prefix = null, suffix = null;
if (coloredName.length() > 16) {
prefix = coloredName.substring(0, 16);
if (coloredName.length() > 30) {
if (coloredName.length() >= 30) {
int len = 30;
name = coloredName.substring(16, 30);
if (NON_ALPHABET_MATCHER.matcher(name).matches()) {
@ -63,7 +63,6 @@ public class HumanController extends AbstractEntityController {
name = name.substring(0, 16);
}
}
coloredName = coloredName.substring(0, 16);
}
final String prefixCapture = prefix, suffixCapture = suffix;
@ -93,8 +92,7 @@ public class HumanController extends AbstractEntityController {
return;
boolean removeFromPlayerList = npc.data().get("removefromplayerlist",
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
NMS.addOrRemoveFromPlayerList(getBukkitEntity(),
npc.data().get("removefromplayerlist", removeFromPlayerList));
NMS.addOrRemoveFromPlayerList(getBukkitEntity(), removeFromPlayerList);
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
@ -103,12 +101,12 @@ public class HumanController extends AbstractEntityController {
Team team = scoreboard.getTeam(teamName);
if (team == null) {
team = scoreboard.registerNewTeam(teamName);
if (prefixCapture != null) {
team.setPrefix(prefixCapture);
}
if (suffixCapture != null) {
team.setSuffix(suffixCapture);
}
}
if (prefixCapture != null) {
team.setPrefix(prefixCapture);
}
if (suffixCapture != null) {
team.setSuffix(suffixCapture);
}
team.addPlayer(handle.getBukkitEntity());
@ -131,6 +129,18 @@ public class HumanController extends AbstractEntityController {
public void remove() {
Player entity = getBukkitEntity();
if (entity != null) {
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
String teamName = entity.getUniqueId().toString().substring(0, 16);
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
Team team = scoreboard.getTeam(teamName);
if (team != null && team.hasPlayer(entity)) {
if (team.getSize() == 1) {
team.setPrefix("");
team.setSuffix("");
}
team.removePlayer(entity);
}
}
NMS.removeFromWorld(entity);
SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null;
npc.getSkinTracker().onRemoveNPC();

View File

@ -38,7 +38,7 @@ public class HumanController extends AbstractEntityController {
String name = coloredName, prefix = null, suffix = null;
if (coloredName.length() > 16) {
prefix = coloredName.substring(0, 16);
if (coloredName.length() > 30) {
if (coloredName.length() >= 30) {
int len = 30;
name = coloredName.substring(16, 30);
if (NON_ALPHABET_MATCHER.matcher(name).matches()) {
@ -63,7 +63,6 @@ public class HumanController extends AbstractEntityController {
name = name.substring(0, 16);
}
}
coloredName = coloredName.substring(0, 16);
}
final String prefixCapture = prefix, suffixCapture = suffix;
@ -93,8 +92,7 @@ public class HumanController extends AbstractEntityController {
return;
boolean removeFromPlayerList = npc.data().get("removefromplayerlist",
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
NMS.addOrRemoveFromPlayerList(getBukkitEntity(),
npc.data().get("removefromplayerlist", removeFromPlayerList));
NMS.addOrRemoveFromPlayerList(getBukkitEntity(), removeFromPlayerList);
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
@ -103,12 +101,12 @@ public class HumanController extends AbstractEntityController {
Team team = scoreboard.getTeam(teamName);
if (team == null) {
team = scoreboard.registerNewTeam(teamName);
if (prefixCapture != null) {
team.setPrefix(prefixCapture);
}
if (suffixCapture != null) {
team.setSuffix(suffixCapture);
}
}
if (prefixCapture != null) {
team.setPrefix(prefixCapture);
}
if (suffixCapture != null) {
team.setSuffix(suffixCapture);
}
team.addPlayer(handle.getBukkitEntity());
@ -131,6 +129,18 @@ public class HumanController extends AbstractEntityController {
public void remove() {
Player entity = getBukkitEntity();
if (entity != null) {
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
String teamName = entity.getUniqueId().toString().substring(0, 16);
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
Team team = scoreboard.getTeam(teamName);
if (team != null && team.hasPlayer(entity)) {
if (team.getSize() == 1) {
team.setPrefix("");
team.setSuffix("");
}
team.removePlayer(entity);
}
}
NMS.removeFromWorld(entity);
SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null;
npc.getSkinTracker().onRemoveNPC();