Implement silence

This commit is contained in:
fullwall 2016-07-20 00:41:25 +08:00
parent 4ccce99ad1
commit 212157d509
2 changed files with 16 additions and 5 deletions

View File

@ -1586,7 +1586,7 @@ public class NPCCommands {
usage = "sound (--death [death sound|d]) (--ambient [ambient sound|d]) (--hurt [hurt sound|d]) (-n(one)) (-d(efault))",
desc = "Sets an NPC's played sounds",
modifiers = { "sound" },
flags = "dn",
flags = "dns",
min = 1,
max = 1,
permission = "citizens.npc.sound")
@ -1600,8 +1600,9 @@ public class NPCCommands {
return;
}
if (args.hasFlag('n')) {
if (args.hasFlag('n') || args.hasFlag('s')) {
ambientSound = deathSound = hurtSound = "";
npc.data().setPersistent(NPC.SILENT_METADATA, true);
}
if (args.hasFlag('d')) {
ambientSound = deathSound = hurtSound = null;
@ -1632,12 +1633,18 @@ public class NPCCommands {
npc.data().setPersistent(NPC.AMBIENT_SOUND_METADATA, ambientSound);
}
if (ambientSound != null && ambientSound.isEmpty())
if (ambientSound != null && ambientSound.isEmpty()) {
ambientSound = "none";
if (hurtSound != null && hurtSound.isEmpty())
}
if (hurtSound != null && hurtSound.isEmpty()) {
hurtSound = "none";
if (deathSound != null && deathSound.isEmpty())
}
if (deathSound != null && deathSound.isEmpty()) {
deathSound = "none";
}
if (ambientSound != null || deathSound != null || hurtSound != null) {
npc.data().setPersistent(NPC.SILENT_METADATA, false);
}
Messaging.sendTr(sender, Messages.SOUND_SET, npc.getName(), ambientSound, hurtSound, deathSound);
}

View File

@ -322,6 +322,10 @@ public class CitizensNPC extends AbstractNPC {
NMS.setKnockbackResistance((LivingEntity) getEntity(), 0D);
}
}
if (data().has(NPC.SILENT_METADATA)) {
getEntity().setSilent(Boolean.parseBoolean(data().get(NPC.SILENT_METADATA).toString()));
}
} catch (Exception ex) {
Throwable error = Throwables.getRootCause(ex);
Messaging.logTr(Messages.EXCEPTION_UPDATING_NPC, getId(), error.getMessage());