From 19ee538416a1e91ab6540a299c5e09446d7fd259 Mon Sep 17 00:00:00 2001 From: Penal Buffalo Date: Thu, 5 Jan 2023 15:00:44 -0600 Subject: [PATCH] v3.9.2 b733 * if `creature-death-nametag` in rules.yml doesn't contain `%displayname%` it will no longer display strange death nametags --- pom.xml | 2 +- .../subcommands/SpawnerEggCommand.java | 28 ++----- .../subcommands/SpawnerSubCommand.java | 82 +++++++------------ .../subcommands/SummonSubcommand.java | 16 ++-- .../listeners/paper/PlayerDeathListener.java | 9 +- 5 files changed, 57 insertions(+), 80 deletions(-) diff --git a/pom.xml b/pom.xml index 7bcba8c4f..8506351ae 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.lokka30 LevelledMobs - 3.9.2 b732 + 3.9.2 b733 LevelledMobs The Ultimate RPG Mob Levelling Solution diff --git a/src/main/java/me/lokka30/levelledmobs/commands/subcommands/SpawnerEggCommand.java b/src/main/java/me/lokka30/levelledmobs/commands/subcommands/SpawnerEggCommand.java index d18fb920a..7e61f8a91 100644 --- a/src/main/java/me/lokka30/levelledmobs/commands/subcommands/SpawnerEggCommand.java +++ b/src/main/java/me/lokka30/levelledmobs/commands/subcommands/SpawnerEggCommand.java @@ -97,30 +97,20 @@ private void parseEggCommand(final String[] args) { } switch (command) { - case "/name": - info.customName = foundValue; - break; - case "/customdropid": - info.customDropId = foundValue; - break; - case "/lore": - info.customLore = foundValue; - break; - case "/entity": + case "/name" -> info.customName = foundValue; + case "/customdropid" -> info.customDropId = foundValue; + case "/lore" -> info.customLore = foundValue; + case "/entity" -> { try { info.spawnType = EntityType.valueOf(foundValue.toUpperCase()); } catch (final Exception ignored) { commandSender.sendMessage("Invalid spawn type: " + foundValue); return; } - break; - case "/minlevel": - info.minLevel = Integer.parseInt(foundValue); - break; - case "/maxlevel": - info.maxLevel = Integer.parseInt(foundValue); - break; - case "/giveplayer": + } + case "/minlevel" -> info.minLevel = Integer.parseInt(foundValue); + case "/maxlevel" -> info.maxLevel = Integer.parseInt(foundValue); + case "/giveplayer" -> { if (Utils.isNullOrEmpty(foundValue)) { showMessage("command.levelledmobs.spawn_egg.no-player-specified"); return; @@ -135,7 +125,7 @@ private void parseEggCommand(final String[] args) { showMessage("common.player-offline", "%player%", foundValue); return; } - break; + } } } diff --git a/src/main/java/me/lokka30/levelledmobs/commands/subcommands/SpawnerSubCommand.java b/src/main/java/me/lokka30/levelledmobs/commands/subcommands/SpawnerSubCommand.java index f7f676a34..d28984b4f 100644 --- a/src/main/java/me/lokka30/levelledmobs/commands/subcommands/SpawnerSubCommand.java +++ b/src/main/java/me/lokka30/levelledmobs/commands/subcommands/SpawnerSubCommand.java @@ -181,51 +181,27 @@ private void parseCreateCommand(final String[] args) { } switch (command) { - case "/name": - info.customName = foundValue; - break; - case "/customdropid": - info.customDropId = foundValue; - break; - case "/lore": - info.customLore = foundValue; - break; - case "/spawntype": + case "/name" -> info.customName = foundValue; + case "/customdropid" -> info.customDropId = foundValue; + case "/lore" -> info.customLore = foundValue; + case "/spawntype" -> { try { info.spawnType = EntityType.valueOf(foundValue.toUpperCase()); } catch (final Exception ignored) { commandSender.sendMessage("Invalid spawn type: " + foundValue); return; } - break; - case "/minlevel": - info.minLevel = Integer.parseInt(foundValue); - break; - case "/maxlevel": - info.maxLevel = Integer.parseInt(foundValue); - break; - case "/delay": - info.delay = Integer.parseInt(foundValue); - break; - case "/maxnearbyentities": - info.maxNearbyEntities = Integer.parseInt(foundValue); - break; - case "/minspawndelay": - info.minSpawnDelay = Integer.parseInt(foundValue); - break; - case "/maxspawndelay": - info.maxSpawnDelay = Integer.parseInt(foundValue); - break; - case "/requiredplayerrange": - info.requiredPlayerRange = Integer.parseInt(foundValue); - break; - case "/spawncount": - info.spawnCount = Integer.parseInt(foundValue); - break; - case "/spawnrange": - info.spawnRange = Integer.parseInt(foundValue); - break; - case "/giveplayer": + } + case "/minlevel" -> info.minLevel = Integer.parseInt(foundValue); + case "/maxlevel" -> info.maxLevel = Integer.parseInt(foundValue); + case "/delay" -> info.delay = Integer.parseInt(foundValue); + case "/maxnearbyentities" -> info.maxNearbyEntities = Integer.parseInt(foundValue); + case "/minspawndelay" -> info.minSpawnDelay = Integer.parseInt(foundValue); + case "/maxspawndelay" -> info.maxSpawnDelay = Integer.parseInt(foundValue); + case "/requiredplayerrange" -> info.requiredPlayerRange = Integer.parseInt(foundValue); + case "/spawncount" -> info.spawnCount = Integer.parseInt(foundValue); + case "/spawnrange" -> info.spawnRange = Integer.parseInt(foundValue); + case "/giveplayer" -> { if (Utils.isNullOrEmpty(foundValue)) { showMessage("command.levelledmobs.spawner.no-player-specified"); return; @@ -240,7 +216,7 @@ private void parseCreateCommand(final String[] args) { showMessage("common.player-offline", "%player%", foundValue); return; } - break; + } } } @@ -380,7 +356,7 @@ public List parseTabCompletions(final LevelledMobs main, if ("create".equalsIgnoreCase(args[1])) { return tabCompletions_Create(args); } else if (("info".equalsIgnoreCase(args[1]) || "copy".equalsIgnoreCase(args[1])) - && args.length <= 3) { + && args.length == 3) { return Arrays.asList("on", "off"); } @@ -390,32 +366,36 @@ public List parseTabCompletions(final LevelledMobs main, @NotNull private List tabCompletions_Create(@NotNull final String @NotNull [] args) { if (!Utils.isNullOrEmpty(args[args.length - 2])) { switch (args[args.length - 2].toLowerCase()) { - case "/spawntype": + case "/spawntype" -> { final List entityNames = new LinkedList<>(); for (final EntityType entityType : EntityType.values()) { entityNames.add(entityType.toString().toLowerCase()); } - return entityNames; - case "/delay": + } + case "/delay" -> { return Collections.singletonList("0"); - case "/minspawndelay": + } + case "/minspawndelay" -> { return Collections.singletonList("200"); - case "/maxspawndelay": + } + case "/maxspawndelay" -> { return Collections.singletonList("800"); - case "/maxnearbyentities": - case "/requiredplayerrange": + } + case "/maxnearbyentities", "/requiredplayerrange" -> { return Collections.singletonList("16"); - case "/spawncount": - case "/spawnrange": + } + case "/spawncount", "/spawnrange" -> { return Collections.singletonList("4"); - case "/giveplayer": + } + case "/giveplayer" -> { final List players = new LinkedList<>(); for (final Player player : Bukkit.getOnlinePlayers()) { players.add(player.getName()); } players.sort(String.CASE_INSENSITIVE_ORDER); return players; + } } } diff --git a/src/main/java/me/lokka30/levelledmobs/commands/subcommands/SummonSubcommand.java b/src/main/java/me/lokka30/levelledmobs/commands/subcommands/SummonSubcommand.java index b420e608b..50fa8f85e 100644 --- a/src/main/java/me/lokka30/levelledmobs/commands/subcommands/SummonSubcommand.java +++ b/src/main/java/me/lokka30/levelledmobs/commands/subcommands/SummonSubcommand.java @@ -339,7 +339,7 @@ public List parseTabCompletions(final LevelledMobs main, // these are for atPlayer and atLocation if (args.length > 5) { switch (args[4].toLowerCase()) { - case "atplayer": + case "atplayer" -> { if (args.length == 6) { final List suggestions = new LinkedList<>(); for (final Player onlinePlayer : Bukkit.getOnlinePlayers()) { @@ -359,9 +359,8 @@ public List parseTabCompletions(final LevelledMobs main, return List.of(); } } - break; - - case "atlocation": + } + case "atlocation" -> { if (args.length < 9) { // args 6, 7 and 8 = x, y and z return List.of("~"); } else if (args.length == 9) { @@ -375,16 +374,17 @@ public List parseTabCompletions(final LevelledMobs main, return List.of(); } } - - break; - case "here": + } + case "here" -> { if (!skipOverride) { return List.of("/override"); } else { return List.of(); } - default: + } + default -> { return List.of(); + } } } diff --git a/src/main/java/me/lokka30/levelledmobs/listeners/paper/PlayerDeathListener.java b/src/main/java/me/lokka30/levelledmobs/listeners/paper/PlayerDeathListener.java index 67a1ece60..51f927f74 100644 --- a/src/main/java/me/lokka30/levelledmobs/listeners/paper/PlayerDeathListener.java +++ b/src/main/java/me/lokka30/levelledmobs/listeners/paper/PlayerDeathListener.java @@ -124,6 +124,7 @@ private void updateDeathMessage(final @NotNull PlayerDeathEvent event, final @No return; } final String mobName = nametagResult.getNametagNonNull(); + final int displayNameIndex = mobName.indexOf("{DisplayName}"); Component newCom; if (nametagResult.hadCustomDeathMessage){ @@ -132,8 +133,14 @@ private void updateDeathMessage(final @NotNull PlayerDeathEvent event, final @No newCom = LegacyComponentSerializer.legacyAmpersand().deserialize(mobName) .replaceText(replacementConfig); } + else if (displayNameIndex < 0){ + // creature-death-nametag in rules.yml doesn't contain %displayname% + // so we'll just send the whole thing as text + newCom = Component.translatable(tc.key(), + buildPlayerComponent(event.getEntity()), + LegacyComponentSerializer.legacyAmpersand().deserialize(mobName)); + } else { - final int displayNameIndex = mobName.indexOf("{DisplayName}"); final Component leftComp = displayNameIndex > 0 ? LegacyComponentSerializer.legacyAmpersand().deserialize(mobName.substring(0, displayNameIndex)) : Component.empty();