Skip to content

Commit 1c17163

Browse files
authored
Merge pull request #230 from WhiteProject1/main
🐛 Fix 70+ bugs, add DeathMessage module, fix 1.21.11 compatibility
2 parents 5b6d833 + 89c1641 commit 1c17163

80 files changed

Lines changed: 358 additions & 118 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

API/src/main/java/fr/maxlego08/essentials/api/cache/SimpleCache.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ public V get(K key, Loader<V> loader) {
4242
}
4343

4444

45+
/**
46+
* Clears all entries from the cache.
47+
*/
48+
public void clear() {
49+
this.cache.clear();
50+
}
51+
4552
/**
4653
* Functional interface for loading values into the cache. Implementations of this interface
4754
* provide a method to load a value, typically involving an operation such as fetching data

API/src/main/java/fr/maxlego08/essentials/api/commands/Permission.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,10 @@ public enum Permission {
308308
ESSENTIALS_STEP_START,
309309
ESSENTIALS_STEP_FINISH,
310310
ESSENTIALS_ITEMFRAME,
311-
ESSENTIALS_SILENT_DEATH("Allows you to die silently without a death message");
311+
ESSENTIALS_SILENT_DEATH("Allows you to die silently without a death message"),
312+
ESSENTIALS_DEATH_MESSAGE_TELEPORT("Allows clicking death messages to teleport to death location"),
313+
ESSENTIALS_DEATH_MESSAGE_TOGGLE("Allows toggling death messages visibility"),
314+
ESSENTIALS_DEATH_MESSAGE_TOGGLE_OTHER("Allows toggling death messages for other players");
312315

313316
private final String description;
314317
private final String[] args;

API/src/main/java/fr/maxlego08/essentials/api/messages/Message.java

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,9 @@ public enum Message {
436436

437437
TELEPORT_DAMAGE("<error>You must not take damage during teleportation."),
438438
TELEPORT_ERROR_LOCATION("<error>Unable to teleport you safely."),
439+
TELEPORT_CROSS_SERVER_NOT_SUPPORTED("<error>Cross-server teleportation is not supported on this server."),
440+
TELEPORT_CROSS_SERVER_CONNECTING("<success>Connecting to server &f%server%<success>..."),
441+
TELEPORT_CROSS_SERVER_PLAYER_NOT_FOUND("<error>Player &f%player% <error>was not found on any server."),
439442

440443
// RTP Queue System Messages
441444
TELEPORT_ALREADY_IN_QUEUE("<error>You are already in the teleportation queue!"),
@@ -970,12 +973,41 @@ public enum Message {
970973
COMMAND_ITEMFRAME_VISIBLE("<success>Item frame is now <white>visible<success>."),
971974
COMMAND_ITEMFRAME_NOT_FOUND("<error>No item frame found. Look at an item frame and try again."),
972975

973-
// Death Messages
974-
DEATH_MESSAGE_GENERIC("#99E0FF%player% &7died."),
975-
DEATH_MESSAGE_PLAYER("#99E0FF%player% &7was slain by #34cfe0%killer% &7using %weapon%&7."),
976-
DEATH_MESSAGE_FISTS("&7fists"),
977-
DEATH_MESSAGE_MOB("#99E0FF%player% &7was killed by &c%mob%&7."),
978-
DEATH_MESSAGE_MYTHIC_MOB("#99E0FF%player% &7was slain by <gradient:#ff6600:#ff0000>%mob%</gradient>&7!"),
976+
// Death Message Module
977+
DESCRIPTION_DEATH_MESSAGE("Custom death messages"),
978+
979+
DEATH_GENERIC("#C084FC☠ #E9D5FF%player% #B794F4died."),
980+
DEATH_BY_PLAYER("#C084FC⚔ #E9D5FF%player% #B794F4was slain by #E9D5FF%killer%#B794F4."),
981+
DEATH_BY_MOB("#C084FC☠ #E9D5FF%player% #B794F4was killed by #E9D5FF%killer%#B794F4."),
982+
DEATH_BY_PROJECTILE("#C084FC🏹 #E9D5FF%player% #B794F4was shot by #E9D5FF%killer%#B794F4."),
983+
DEATH_BY_MOB_EXPLOSION("#C084FC💥 #E9D5FF%player% #B794F4was blown up by #E9D5FF%killer%#B794F4."),
984+
DEATH_BY_FALL("#C084FC⬇ #E9D5FF%player% #B794F4fell from a high place."),
985+
DEATH_BY_FIRE("#C084FC🔥 #E9D5FF%player% #B794F4burned to death."),
986+
DEATH_BY_LAVA("#C084FC🌋 #E9D5FF%player% #B794F4tried to swim in lava."),
987+
DEATH_BY_DROWNING("#C084FC💧 #E9D5FF%player% #B794F4drowned."),
988+
DEATH_BY_EXPLOSION("#C084FC💥 #E9D5FF%player% #B794F4was blown up."),
989+
DEATH_BY_LIGHTNING("#C084FC⚡ #E9D5FF%player% #B794F4was struck by lightning."),
990+
DEATH_BY_SUFFOCATION("#C084FC▓ #E9D5FF%player% #B794F4suffocated in a wall."),
991+
DEATH_BY_STARVATION("#C084FC🍖 #E9D5FF%player% #B794F4starved to death."),
992+
DEATH_BY_POISON("#C084FC☣ #E9D5FF%player% #B794F4was poisoned."),
993+
DEATH_BY_MAGIC("#C084FC✦ #E9D5FF%player% #B794F4was killed by magic."),
994+
DEATH_BY_WITHER("#C084FC💀 #E9D5FF%player% #B794F4withered away."),
995+
DEATH_BY_FALLING_BLOCK("#C084FC▼ #E9D5FF%player% #B794F4was squashed by a falling block."),
996+
DEATH_BY_FLY_INTO_WALL("#C084FC💨 #E9D5FF%player% #B794F4experienced kinetic energy."),
997+
DEATH_BY_VOID("#C084FC✧ #E9D5FF%player% #B794F4fell out of the world."),
998+
DEATH_BY_CACTUS("#C084FC🌵 #E9D5FF%player% #B794F4was pricked to death."),
999+
DEATH_BY_CRAMMING("#C084FC⊞ #E9D5FF%player% #B794F4was squished too much."),
1000+
DEATH_BY_FREEZE("#C084FC❄ #E9D5FF%player% #B794F4froze to death."),
1001+
DEATH_BY_SONIC_BOOM("#C084FC◈ #E9D5FF%player% #B794F4was obliterated by a sonic boom."),
1002+
DEATH_BY_MAGMA("#C084FC♨ #E9D5FF%player% #B794F4discovered that the floor was lava."),
1003+
DEATH_BY_THORNS("#C084FC✵ #E9D5FF%player% #B794F4was killed trying to hurt someone."),
1004+
DEATH_BY_CAMPFIRE("#C084FC🔥 #E9D5FF%player% #B794F4walked into a campfire."),
1005+
1006+
DEATH_HOVER_DETAILS("#D8B4FE☠ Death Location#B794F4:\n#E9D5FF▸ World: #D8B4FE%world%\n#E9D5FF▸ Position: #D8B4FE%x%#E9D5FF, #D8B4FE%y%#E9D5FF, #D8B4FE%z%\n\n#9F7AEA&oClick to teleport"),
1007+
1008+
COMMAND_DEATH_MESSAGE_TOGGLE_DISABLE("#C084FC☠ #B794F4Death messages are now #E9D5FFhidden #B794F4for %player%#B794F4."),
1009+
COMMAND_DEATH_MESSAGE_TOGGLE_ENABLE("#C084FC☠ #B794F4Death messages are now #E9D5FFvisible #B794F4for %player%#B794F4."),
1010+
DESCRIPTION_DEATH_MESSAGE_TOGGLE("Toggle death messages visibility"),
9791011
;
9801012

9811013
private EssentialsPlugin plugin;

API/src/main/java/fr/maxlego08/essentials/api/modules/Module.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,11 @@ public interface Module extends Listener {
5757
*/
5858
boolean isRegisterEvent();
5959

60+
/**
61+
* Called when the module is being disabled.
62+
*/
63+
default void onDisable() {
64+
}
65+
6066
}
6167

API/src/main/java/fr/maxlego08/essentials/api/user/Option.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ public enum Option {
3232
WORLDEDIT_INVENTORY,
3333
WORLDEDIT_BOSSBAR_DISABLE,
3434
TELEPORT_REQUEST_DISABLE,
35+
DEATH_MESSAGE_DISABLE,
3536
}

API/src/main/java/fr/maxlego08/essentials/api/utils/SafeLocation.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ public void setPitch(float pitch) {
7878

7979
public Location getLocation() {
8080
if (this.location == null) {
81-
this.location = new Location(Bukkit.getWorld(this.world), this.x, this.y, this.z, this.yaw, this.pitch);
81+
var bukkitWorld = Bukkit.getWorld(this.world);
82+
if (bukkitWorld == null) return null;
83+
this.location = new Location(bukkitWorld, this.x, this.y, this.z, this.yaw, this.pitch);
8284
}
8385
return location;
8486
}

build.gradle.kts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ allprojects {
3232
maven(url = "https://repo.tcoded.com/releases")
3333
}
3434

35+
configurations.all {
36+
resolutionStrategy.eachDependency {
37+
if (requested.group == "net.kyori" && requested.name == "adventure-text-serializer-ansi" && (requested.version.isNullOrBlank() || requested.version == ".")) {
38+
useVersion("4.20.0")
39+
}
40+
}
41+
}
42+
3543
java {
3644
withSourcesJar()
3745

src/main/java/fr/maxlego08/essentials/buttons/sanction/ButtonSanctions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ private void displaySanction(int slot, Sanction sanction, Player player, User ta
6060
placeholders.register("reason", sanction.getReason());
6161
placeholders.register("duration", TimerBuilder.getStringTime(sanction.getDuration()));
6262
placeholders.register("remaining", sanction.isActive() ? TimerBuilder.getStringTime(sanction.getDurationRemaining().toMillis()) : Message.EXPIRED.getMessageAsString());
63-
placeholders.register("created_at", simpleDateFormat.format(sanction.getCreatedAt()));
64-
placeholders.register("expired_at", simpleDateFormat.format(sanction.getExpiredAt()));
63+
placeholders.register("created_at", sanction.getCreatedAt() != null ? simpleDateFormat.format(sanction.getCreatedAt()) : "N/A");
64+
placeholders.register("expired_at", sanction.getExpiredAt() != null ? simpleDateFormat.format(sanction.getExpiredAt()) : "N/A");
6565
placeholders.register("sender", sanctionModule.getSanctionBy(sanction.getSenderUniqueId()));
6666

6767
inventory.addItem(slot, menuItemStack.build(player, false, placeholders));

src/main/java/fr/maxlego08/essentials/commands/CommandLoader.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import fr.maxlego08.essentials.commands.commands.chat.CommandShowItem;
1313
import fr.maxlego08.essentials.commands.commands.clearinventory.ClearInventoryCommand;
1414
import fr.maxlego08.essentials.commands.commands.cooldown.CommandCooldown;
15+
import fr.maxlego08.essentials.commands.commands.deathmessage.CommandDeathMessageToggle;
1516
import fr.maxlego08.essentials.commands.commands.discord.CommandLink;
1617
import fr.maxlego08.essentials.commands.commands.discord.CommandUnLink;
1718
import fr.maxlego08.essentials.commands.commands.economy.CommandBalanceTop;
@@ -285,6 +286,7 @@ public void loadCommands(CommandManager commandManager) {
285286
register("pub", CommandPub.class);
286287
register("step", CommandStep.class);
287288
register("itemframe", CommandItemFrame.class, "iframe");
289+
register("deathmessage", CommandDeathMessageToggle.class, "dm", "deathmsg");
288290

289291
for (RegisterCommand registerCommand : this.commands) {
290292
try {

src/main/java/fr/maxlego08/essentials/commands/ZCommandManager.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ public class ZCommandManager extends ZUtils implements CommandManager {
4545
commandMap = (CommandMap) bukkitCommandMap.get(Bukkit.getServer());
4646
constructor = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
4747
constructor.setAccessible(true);
48-
} catch (Exception ignored) {
48+
} catch (Exception exception) {
49+
Bukkit.getLogger().severe("[zEssentials] Failed to initialize command map or PluginCommand constructor: " + exception.getMessage());
50+
exception.printStackTrace();
4951
}
5052
}
5153

@@ -283,6 +285,11 @@ public void registerCommand(Plugin plugin, String mainCommand, EssentialsCommand
283285
}
284286

285287
try {
288+
if (constructor == null || commandMap == null) {
289+
this.plugin.getLogger().severe("Cannot register command '" + mainCommand + "': CommandMap or PluginCommand constructor is not initialized!");
290+
return;
291+
}
292+
286293
PluginCommand command = constructor.newInstance(mainCommand, plugin);
287294
command.setExecutor(this);
288295
command.setTabCompleter(this);
@@ -296,7 +303,7 @@ public void registerCommand(Plugin plugin, String mainCommand, EssentialsCommand
296303
commands.add(essentialsCommand);
297304

298305
if (!commandMap.register(command.getName(), plugin.getDescription().getName(), command)) {
299-
plugin.getLogger().info("Unable to add the command " + essentialsCommand.getSyntax());
306+
plugin.getLogger().warning("Unable to add the command /" + mainCommand + " (already registered by another plugin). Use /zessentials:" + mainCommand + " instead.");
300307
}
301308

302309
if (essentialsCommand.getPermission() != null) {
@@ -307,6 +314,7 @@ public void registerCommand(Plugin plugin, String mainCommand, EssentialsCommand
307314
Bukkit.getPluginManager().addPermission(new Permission(essentialsCommand.getPermission(), essentialsCommand.getDescription() == null ? "No description" : essentialsCommand.getDescription()));
308315
}
309316
} catch (Exception exception) {
317+
this.plugin.getLogger().severe("Failed to register command '" + mainCommand + "': " + exception.getMessage());
310318
exception.printStackTrace();
311319
}
312320
}

0 commit comments

Comments
 (0)