Skip to content

Commit 3303a4b

Browse files
committed
enhanced rekit-on-kill settings
1 parent 49939af commit 3303a4b

3 files changed

Lines changed: 123 additions & 7 deletions

File tree

CONFIG.md

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ feature:
336336

337337
**Kit Loading Features:**
338338
- **rekit-on-respawn**: Automatically loads the player's last used kit when they respawn after death
339-
- **rekit-on-kill**: Automatically loads the player's last used kit when they kill another player
339+
- **rekit-on-kill**: Automatically loads the killer's last used kit when they kill another player. See [Rekit on Kill Configuration](#rekit-on-kill-configuration) for advanced options
340340
- **broadcast-kit-messages**: Controls whether broadcast messages are sent when players load kits or enderchesets (e.g., "Player loaded a kit"). When set to `false`, these specific kit-loading broadcast messages are suppressed
341341

342342
**Action Broadcast Features:**
@@ -351,3 +351,70 @@ feature:
351351
- **feed-on-enderchest-load**: Sets player hunger to full when loading an enderchest
352352
- **set-saturation-on-enderchest-load**: Sets player saturation to full when loading an enderchest
353353
- **remove-potion-effects-on-enderchest-load**: Removes all potion effects when loading an enderchest
354+
355+
---
356+
357+
### **Rekit on Kill Configuration**
358+
359+
The `rekit-on-kill` feature automatically loads the killer's last used kit when they kill another player. This feature supports world-based filtering to control where it activates, based on the killer's current world.
360+
361+
```yaml
362+
feature:
363+
rekit-on-kill:
364+
enabled: false
365+
# World filtering based on killer's current world
366+
# If world-whitelist is not empty, rekit-on-kill only works in those worlds
367+
# If world-whitelist is empty and world-blacklist is not empty, rekit-on-kill works everywhere except those worlds
368+
# If both are empty, rekit-on-kill works in all worlds
369+
world-whitelist: []
370+
world-blacklist: []
371+
```
372+
373+
#### Configuration Options:
374+
375+
- **enabled**: Set to `true` to enable the rekit-on-kill feature
376+
- **world-whitelist**: List of world names where rekit-on-kill is allowed. If this list is not empty, the feature only works in these worlds
377+
- **world-blacklist**: List of world names where rekit-on-kill is disabled. Only used if `world-whitelist` is empty
378+
379+
#### World Filtering Logic:
380+
381+
1. If `world-whitelist` contains worlds → only allow rekit-on-kill in those worlds
382+
2. If `world-whitelist` is empty but `world-blacklist` contains worlds → allow rekit-on-kill everywhere except those worlds
383+
3. If both lists are empty → allow rekit-on-kill in all worlds
384+
385+
#### Example Configurations:
386+
387+
**Enable globally (all worlds):**
388+
```yaml
389+
feature:
390+
rekit-on-kill:
391+
enabled: true
392+
world-whitelist: []
393+
world-blacklist: []
394+
```
395+
396+
**Only enable in specific arena worlds:**
397+
```yaml
398+
feature:
399+
rekit-on-kill:
400+
enabled: true
401+
world-whitelist:
402+
- "pvp_arena"
403+
- "duel_world"
404+
world-blacklist: []
405+
```
406+
407+
**Enable everywhere except spawn/lobby:**
408+
```yaml
409+
feature:
410+
rekit-on-kill:
411+
enabled: true
412+
world-whitelist: []
413+
world-blacklist:
414+
- "spawn"
415+
- "lobby"
416+
```
417+
418+
#### Backwards Compatibility:
419+
420+
Existing configurations using the old boolean format (`rekit-on-kill: false` or `rekit-on-kill: true`) will continue to work. When the plugin updates, it will automatically add the new configuration keys with default values. No manual changes are required.

src/main/java/dev/noah/perplayerkit/listeners/AutoRekitListener.java

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@
1919
package dev.noah.perplayerkit.listeners;
2020

2121
import dev.noah.perplayerkit.KitManager;
22+
import org.bukkit.configuration.ConfigurationSection;
2223
import org.bukkit.entity.Player;
2324
import org.bukkit.event.EventHandler;
2425
import org.bukkit.event.Listener;
2526
import org.bukkit.event.entity.PlayerDeathEvent;
2627
import org.bukkit.event.player.PlayerRespawnEvent;
2728
import org.bukkit.plugin.Plugin;
2829

30+
import java.util.List;
31+
2932
public class AutoRekitListener implements Listener {
3033

3134
private final Plugin plugin;
@@ -37,7 +40,6 @@ public AutoRekitListener(Plugin plugin) {
3740
@EventHandler
3841
public void onRespawn(PlayerRespawnEvent e) {
3942

40-
4143
if (!plugin.getConfig().getBoolean("feature.rekit-on-respawn", true)) {
4244
return;
4345
}
@@ -47,14 +49,12 @@ public void onRespawn(PlayerRespawnEvent e) {
4749
}
4850

4951
KitManager.get().loadLastKit(e.getPlayer());
50-
5152
}
5253

5354
@EventHandler
5455
public void onPlayerKill(PlayerDeathEvent e) {
5556

56-
57-
if (!plugin.getConfig().getBoolean("feature.rekit-on-kill", false)) {
57+
if (!isRekitOnKillEnabled()) {
5858
return;
5959
}
6060

@@ -67,8 +67,50 @@ public void onPlayerKill(PlayerDeathEvent e) {
6767
return;
6868
}
6969

70-
KitManager.get().loadLastKit(killer);
70+
String killerWorld = killer.getWorld().getName();
71+
if (isWorldAllowedForRekitOnKill(killerWorld)) {
72+
KitManager.get().loadLastKit(killer);
73+
}
74+
}
75+
76+
/**
77+
* Checks if rekit-on-kill is enabled, supporting both old boolean format and new section format.
78+
*/
79+
private boolean isRekitOnKillEnabled() {
80+
// Check if it's a section (new format)
81+
ConfigurationSection section = plugin.getConfig().getConfigurationSection("feature.rekit-on-kill");
82+
if (section != null) {
83+
return section.getBoolean("enabled", false);
84+
}
85+
// Fall back to old boolean format for backwards compatibility
86+
return plugin.getConfig().getBoolean("feature.rekit-on-kill", false);
87+
}
88+
89+
/**
90+
* Checks if a world is allowed for rekit-on-kill based on whitelist/blacklist settings.
91+
*/
92+
private boolean isWorldAllowedForRekitOnKill(String worldName) {
93+
ConfigurationSection section = plugin.getConfig().getConfigurationSection("feature.rekit-on-kill");
94+
if (section == null) {
95+
// Old format - no world filtering, allow all
96+
return true;
97+
}
98+
99+
List<String> whitelist = section.getStringList("world-whitelist");
100+
List<String> blacklist = section.getStringList("world-blacklist");
101+
102+
// If whitelist is not empty, only allow worlds in the whitelist
103+
if (whitelist != null && !whitelist.isEmpty()) {
104+
return whitelist.contains(worldName);
105+
}
106+
107+
// If blacklist is not empty, allow all worlds except those in the blacklist
108+
if (blacklist != null && !blacklist.isEmpty()) {
109+
return !blacklist.contains(worldName);
110+
}
71111

112+
// Both empty - allow all worlds
113+
return true;
72114
}
73115

74116
}

src/main/resources/config.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,14 @@ feature:
184184
heal-remove-effects: false #makes the /heal command remove potion effects in addition to healing
185185

186186
rekit-on-respawn: true
187-
rekit-on-kill: false
187+
rekit-on-kill:
188+
enabled: false
189+
# World filtering based on killer's current world
190+
# If world-whitelist is not empty, rekit-on-kill only works in those worlds
191+
# If world-whitelist is empty and world-blacklist is not empty, rekit-on-kill works everywhere except those worlds
192+
# If both are empty, rekit-on-kill works in all worlds
193+
world-whitelist: []
194+
world-blacklist: []
188195

189196
broadcast-kit-messages: true #broadcasts when a player loads a kit (applies to both kits and enderchesets)
190197

0 commit comments

Comments
 (0)