Add Sharing is Caring, Heavy Duty, Locked Out, and Organising advancements.
Award on key copy, iron door/trapdoor lock, renamed keys, and dropped keys destroyed by lava/fire. Co-authored-by: Cursor <cursoragent@cursor.com>
@@ -32,6 +32,7 @@ The supplied texture is the user's 16x16 key sprite and is selected through the
32
32
- Locked doors/trapdoors/fence gates may always be closed, but cannot be opened without the matching key. Redstone may close them but may not open them.
33
33
- Locked iron doors and iron trapdoors can be toggled open/closed by right-clicking with the matching key in hand.
34
34
- Rename a bound key with `/keyname <name>` or an anvil; all copies with the same binding update. Blank keys cannot be named.
35
- Advancements (toast only, no chat): Burglar, Oops..., Sharing is Caring, Heavy Duty, Locked Out, Organising.
35
36
- Hopper transfers, hopper pickup/search and Copper Golem target validation are denied for locked containers.
36
37
- Breaking either half of a double chest or either half of a door breaks the binding.
37
38
- Keys found online are immediately blanked when their bound block is broken. Keys elsewhere are lazily blanked the next time the plugin encounters them.
@@ -32,6 +32,7 @@ The supplied texture is the user's 16x16 key sprite and is selected through the32
- Locked doors/trapdoors/fence gates may always be closed, but cannot be opened without the matching key. Redstone may close them but may not open them.32
- Locked doors/trapdoors/fence gates may always be closed, but cannot be opened without the matching key. Redstone may close them but may not open them.33
- Locked iron doors and iron trapdoors can be toggled open/closed by right-clicking with the matching key in hand.33
- Locked iron doors and iron trapdoors can be toggled open/closed by right-clicking with the matching key in hand.34
- Rename a bound key with `/keyname <name>` or an anvil; all copies with the same binding update. Blank keys cannot be named.34
- Rename a bound key with `/keyname <name>` or an anvil; all copies with the same binding update. Blank keys cannot be named.35
- Advancements (toast only, no chat): Burglar, Oops..., Sharing is Caring, Heavy Duty, Locked Out, Organising.35
- Hopper transfers, hopper pickup/search and Copper Golem target validation are denied for locked containers.36
- Hopper transfers, hopper pickup/search and Copper Golem target validation are denied for locked containers.36
- Breaking either half of a double chest or either half of a door breaks the binding.37
- Breaking either half of a double chest or either half of a door breaks the binding.37
- Keys found online are immediately blanked when their bound block is broken. Keys elsewhere are lazily blanked the next time the plugin encounters them.38
- Keys found online are immediately blanked when their bound block is broken. Keys elsewhere are lazily blanked the next time the plugin encounters them.@@ -19,6 +19,7 @@ import org.bukkit.block.data.Bisected;
19
19
import org.bukkit.block.data.Openable;
20
20
import org.bukkit.block.data.type.Door;
21
21
import org.bukkit.entity.HumanEntity;
22
import org.bukkit.entity.Item;
22
23
import org.bukkit.entity.Player;
23
24
import org.bukkit.event.EventHandler;
24
25
import org.bukkit.event.block.Action;
@@ -29,8 +30,10 @@ import org.bukkit.event.block.BlockBurnEvent;
29
30
import org.bukkit.event.block.BlockExplodeEvent;
30
31
import org.bukkit.event.block.BlockRedstoneEvent;
31
32
import org.bukkit.event.block.CrafterCraftEvent;
33
import org.bukkit.event.entity.EntityDamageEvent;
32
34
import org.bukkit.event.entity.EntityExplodeEvent;
33
35
import org.bukkit.event.entity.EntityPickupItemEvent;
36
import org.bukkit.event.entity.PlayerDeathEvent;
34
37
import org.bukkit.event.inventory.CraftItemEvent;
35
38
import org.bukkit.event.inventory.HopperInventorySearchEvent;
36
39
import org.bukkit.event.inventory.InventoryClickEvent;
@@ -41,6 +44,7 @@ import org.bukkit.event.inventory.InventoryOpenEvent;
41
44
import org.bukkit.event.inventory.InventoryPickupItemEvent;
42
45
import org.bukkit.event.inventory.PrepareAnvilEvent;
43
46
import org.bukkit.event.inventory.PrepareItemCraftEvent;
47
import org.bukkit.event.player.PlayerDropItemEvent;
44
48
import org.bukkit.event.player.PlayerInteractEvent;
45
49
import org.bukkit.event.player.PlayerJoinEvent;
46
50
import org.bukkit.inventory.AnvilInventory;
@@ -74,6 +78,10 @@ public final class CopperKeysPlugin extends JavaPlugin implements Listener {
74
78
private NamespacedKey copyRecipeKey;
75
79
private NamespacedKey burglarAdvancementKey;
76
80
private NamespacedKey oopsAdvancementKey;
81
private NamespacedKey sharingIsCaringAdvancementKey;
82
private NamespacedKey heavyDutyAdvancementKey;
83
private NamespacedKey lockedOutAdvancementKey;
84
private NamespacedKey organisingAdvancementKey;
77
85
78
86
@Override
79
87
public void onEnable() {
@@ -84,6 +92,10 @@ public final class CopperKeysPlugin extends JavaPlugin implements Listener {
84
92
copyRecipeKey = new NamespacedKey(this, "copy_key");
85
93
burglarAdvancementKey = new NamespacedKey(this, "burglar");
86
94
oopsAdvancementKey = new NamespacedKey(this, "oops");
95
sharingIsCaringAdvancementKey = new NamespacedKey(this, "sharing_is_caring");
96
heavyDutyAdvancementKey = new NamespacedKey(this, "heavy_duty");
97
lockedOutAdvancementKey = new NamespacedKey(this, "locked_out");
98
organisingAdvancementKey = new NamespacedKey(this, "organising");
87
99
88
100
registerRecipes();
89
101
registerAdvancements();
@@ -94,7 +106,7 @@ public final class CopperKeysPlugin extends JavaPlugin implements Listener {
94
106
getLogger().warning("Command 'keyname' missing from plugin.yml");
95
107
}
96
108
getServer().getPluginManager().registerEvents(this, this);
97
getLogger().info("CopperKeys 1.0.7 enabled with event-driven lock handling.");
109
getLogger().info("CopperKeys 1.0.9 enabled with event-driven lock handling.");
98
110
}
99
111
100
112
LockStore lockStore() {
@@ -105,7 +117,7 @@ public final class CopperKeysPlugin extends JavaPlugin implements Listener {
105
117
return keyItems;
106
118
}
107
119
108
void renameKeyBinding(UUID bindingId, String keyName) {
120
void renameKeyBinding(UUID bindingId, String keyName, Player renamer) {
109
121
LockRecord updated = lockStore.setKeyName(bindingId, keyName);
110
122
if (updated == null) {
111
123
return;
@@ -115,6 +127,9 @@ public final class CopperKeysPlugin extends JavaPlugin implements Listener {
115
127
keyItems.applyNameInInventory(online.getEnderChest(), bindingId);
116
128
online.updateInventory();
117
129
}
130
if (renamer != null) {
131
awardAdvancement(renamer, organisingAdvancementKey);
132
}
118
133
}
119
134
120
135
private void registerRecipes() {
@@ -134,22 +149,17 @@ public final class CopperKeysPlugin extends JavaPlugin implements Listener {
134
149
}
135
150
136
151
private void registerAdvancements() {
137
if (Bukkit.getAdvancement(burglarAdvancementKey) != null
138
&& Bukkit.getAdvancement(oopsAdvancementKey) != null) {
139
return;
140
}
141
142
String burglarJson = readAdvancementJson("advancements/burglar.json", "Burglar");
143
String oopsJson = readAdvancementJson("advancements/oops.json", "Oops");
144
if (burglarJson == null || oopsJson == null) {
152
Map<NamespacedKey, String> definitions = new HashMap<>();
153
addAdvancementDefinition(definitions, burglarAdvancementKey, "advancements/burglar.json", "Burglar");
154
addAdvancementDefinition(definitions, oopsAdvancementKey, "advancements/oops.json", "Oops");
155
addAdvancementDefinition(definitions, sharingIsCaringAdvancementKey, "advancements/sharing_is_caring.json", "Sharing is Caring");
156
addAdvancementDefinition(definitions, heavyDutyAdvancementKey, "advancements/heavy_duty.json", "Heavy Duty");
157
addAdvancementDefinition(definitions, lockedOutAdvancementKey, "advancements/locked_out.json", "Locked Out");
158
addAdvancementDefinition(definitions, organisingAdvancementKey, "advancements/organising.json", "Organising");
159
if (definitions.isEmpty()) {
145
160
return;
146
161
}
147
162
148
Map<NamespacedKey, String> definitions = Map.of(
149
burglarAdvancementKey, burglarJson,
150
oopsAdvancementKey, oopsJson
151
);
152
153
163
try {
154
164
List<Advancement> loaded = Bukkit.getUnsafe().loadAdvancements(definitions, false);
155
165
if (loaded.size() != definitions.size()) {
@@ -160,6 +170,21 @@ public final class CopperKeysPlugin extends JavaPlugin implements Listener {
160
170
}
161
171
}
162
172
173
private void addAdvancementDefinition(
174
Map<NamespacedKey, String> definitions,
175
NamespacedKey key,
176
String resourcePath,
177
String label
178
) {
179
if (Bukkit.getAdvancement(key) != null) {
180
return;
181
}
182
String json = readAdvancementJson(resourcePath, label);
183
if (json != null) {
184
definitions.put(key, json);
185
}
186
}
187
163
188
private String readAdvancementJson(String resourcePath, String label) {
164
189
try (InputStream in = getResource(resourcePath)) {
165
190
if (in == null) {
@@ -262,6 +287,9 @@ public final class CopperKeysPlugin extends JavaPlugin implements Listener {
262
287
}
263
288
event.setCancelled(true); // The binding click itself never opens/toggles the target.
264
289
player.sendActionBar(Component.text("Key bound to " + record.displayName(), NamedTextColor.GOLD));
290
if (clicked.getType() == Material.IRON_DOOR || clicked.getType() == Material.IRON_TRAPDOOR) {
291
awardAdvancement(player, heavyDutyAdvancementKey);
292
}
265
293
}
266
294
267
295
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@@ -348,7 +376,10 @@ public final class CopperKeysPlugin extends JavaPlugin implements Listener {
348
376
if (name == null || bindingId == null || lockStore.get(bindingId) == null) {
349
377
return;
350
378
}
351
Bukkit.getScheduler().runTask(this, () -> renameKeyBinding(bindingId, name));
379
Bukkit.getScheduler().runTask(this, () -> {
380
Player renamer = event.getWhoClicked() instanceof Player player ? player : null;
381
renameKeyBinding(bindingId, name, renamer);
382
});
352
383
}
353
384
354
385
private static String sanitizeKeyName(String raw) {
@@ -527,6 +558,7 @@ public final class CopperKeysPlugin extends JavaPlugin implements Listener {
527
558
}
528
559
player.updateInventory();
529
560
});
561
awardAdvancement(player, sharingIsCaringAdvancementKey);
530
562
}
531
563
532
564
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@@ -545,6 +577,73 @@ public final class CopperKeysPlugin extends JavaPlugin implements Listener {
545
577
}
546
578
}
547
579
580
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
581
public void onPlayerDropItem(PlayerDropItemEvent event) {
582
Item dropped = event.getItemDrop();
583
if (!isBoundKeyStack(dropped.getItemStack())) {
584
return;
585
}
586
dropped.setThrower(event.getPlayer().getUniqueId());
587
}
588
589
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
590
public void onPlayerDeath(PlayerDeathEvent event) {
591
Player player = event.getEntity();
592
boolean dropsBoundKey = false;
593
for (ItemStack drop : event.getDrops()) {
594
if (isBoundKeyStack(drop)) {
595
dropsBoundKey = true;
596
break;
597
}
598
}
599
if (!dropsBoundKey) {
600
return;
601
}
602
UUID playerId = player.getUniqueId();
603
Location deathLocation = player.getLocation().clone();
604
Bukkit.getScheduler().runTask(this, () -> {
605
for (Item item : deathLocation.getNearbyEntitiesByType(Item.class, 4.0)) {
606
if (isBoundKeyStack(item.getItemStack()) && item.getThrower() == null) {
607
item.setThrower(playerId);
608
}
609
}
610
});
611
}
612
613
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
614
public void onKeyBurnInLava(EntityDamageEvent event) {
615
if (!(event.getEntity() instanceof Item item)) {
616
return;
617
}
618
EntityDamageEvent.DamageCause cause = event.getCause();
619
if (cause != EntityDamageEvent.DamageCause.LAVA
620
&& cause != EntityDamageEvent.DamageCause.FIRE
621
&& cause != EntityDamageEvent.DamageCause.FIRE_TICK) {
622
return;
623
}
624
if (!isBoundKeyStack(item.getItemStack())) {
625
return;
626
}
627
UUID throwerId = item.getThrower();
628
if (throwerId == null) {
629
return;
630
}
631
// Item entities are removed after lethal lava/fire ticks; award once they disappear.
632
Bukkit.getScheduler().runTask(this, () -> {
633
if (item.isValid() && !item.isDead()) {
634
return;
635
}
636
Player thrower = Bukkit.getPlayer(throwerId);
637
if (thrower != null) {
638
awardAdvancement(thrower, lockedOutAdvancementKey);
639
}
640
});
641
}
642
643
private boolean isBoundKeyStack(ItemStack stack) {
644
return keyItems.isKey(stack) && !keyItems.isBlank(stack);
645
}
646
548
647
private ItemStack keyCloneResult(CraftingInventory inventory) {
549
648
ItemStack blank = null;
550
649
ItemStack bound = null;
@@ -19,6 +19,7 @@ import org.bukkit.block.data.Bisected;19
import org.bukkit.block.data.Openable;19
import org.bukkit.block.data.Openable;20
import org.bukkit.block.data.type.Door;20
import org.bukkit.block.data.type.Door;21
import org.bukkit.entity.HumanEntity;21
import org.bukkit.entity.HumanEntity;22
import org.bukkit.entity.Item;22
import org.bukkit.entity.Player;23
import org.bukkit.entity.Player;23
import org.bukkit.event.EventHandler;24
import org.bukkit.event.EventHandler;24
import org.bukkit.event.block.Action;25
import org.bukkit.event.block.Action;@@ -29,8 +30,10 @@ import org.bukkit.event.block.BlockBurnEvent;29
import org.bukkit.event.block.BlockExplodeEvent;30
import org.bukkit.event.block.BlockExplodeEvent;30
import org.bukkit.event.block.BlockRedstoneEvent;31
import org.bukkit.event.block.BlockRedstoneEvent;31
import org.bukkit.event.block.CrafterCraftEvent;32
import org.bukkit.event.block.CrafterCraftEvent;33
import org.bukkit.event.entity.EntityDamageEvent;32
import org.bukkit.event.entity.EntityExplodeEvent;34
import org.bukkit.event.entity.EntityExplodeEvent;33
import org.bukkit.event.entity.EntityPickupItemEvent;35
import org.bukkit.event.entity.EntityPickupItemEvent;36
import org.bukkit.event.entity.PlayerDeathEvent;34
import org.bukkit.event.inventory.CraftItemEvent;37
import org.bukkit.event.inventory.CraftItemEvent;35
import org.bukkit.event.inventory.HopperInventorySearchEvent;38
import org.bukkit.event.inventory.HopperInventorySearchEvent;36
import org.bukkit.event.inventory.InventoryClickEvent;39
import org.bukkit.event.inventory.InventoryClickEvent;@@ -41,6 +44,7 @@ import org.bukkit.event.inventory.InventoryOpenEvent;41
import org.bukkit.event.inventory.InventoryPickupItemEvent;44
import org.bukkit.event.inventory.InventoryPickupItemEvent;42
import org.bukkit.event.inventory.PrepareAnvilEvent;45
import org.bukkit.event.inventory.PrepareAnvilEvent;43
import org.bukkit.event.inventory.PrepareItemCraftEvent;46
import org.bukkit.event.inventory.PrepareItemCraftEvent;47
import org.bukkit.event.player.PlayerDropItemEvent;44
import org.bukkit.event.player.PlayerInteractEvent;48
import org.bukkit.event.player.PlayerInteractEvent;45
import org.bukkit.event.player.PlayerJoinEvent;49
import org.bukkit.event.player.PlayerJoinEvent;46
import org.bukkit.inventory.AnvilInventory;50
import org.bukkit.inventory.AnvilInventory;@@ -74,6 +78,10 @@ public final class CopperKeysPlugin extends JavaPlugin implements Listener {74
private NamespacedKey copyRecipeKey;78
private NamespacedKey copyRecipeKey;75
private NamespacedKey burglarAdvancementKey;79
private NamespacedKey burglarAdvancementKey;76
private NamespacedKey oopsAdvancementKey;80
private NamespacedKey oopsAdvancementKey;81
private NamespacedKey sharingIsCaringAdvancementKey;82
private NamespacedKey heavyDutyAdvancementKey;83
private NamespacedKey lockedOutAdvancementKey;84
private NamespacedKey organisingAdvancementKey;77
85
78
@Override86
@Override79
public void onEnable() {87
public void onEnable() {@@ -84,6 +92,10 @@ public final class CopperKeysPlugin extends JavaPlugin implements Listener {84
copyRecipeKey = new NamespacedKey(this, "copy_key");92
copyRecipeKey = new NamespacedKey(this, "copy_key");85
burglarAdvancementKey = new NamespacedKey(this, "burglar");93
burglarAdvancementKey = new NamespacedKey(this, "burglar");86
oopsAdvancementKey = new NamespacedKey(this, "oops");94
oopsAdvancementKey = new NamespacedKey(this, "oops");95
sharingIsCaringAdvancementKey = new NamespacedKey(this, "sharing_is_caring");96
heavyDutyAdvancementKey = new NamespacedKey(this, "heavy_duty");97
lockedOutAdvancementKey = new NamespacedKey(this, "locked_out");98
organisingAdvancementKey = new NamespacedKey(this, "organising");87
99
88
registerRecipes();100
registerRecipes();89
registerAdvancements();101
registerAdvancements();@@ -94,7 +106,7 @@ public final class CopperKeysPlugin extends JavaPlugin implements Listener {94
getLogger().warning("Command 'keyname' missing from plugin.yml");106
getLogger().warning("Command 'keyname' missing from plugin.yml");95
}107
}96
getServer().getPluginManager().registerEvents(this, this);108
getServer().getPluginManager().registerEvents(this, this);97
getLogger().info("CopperKeys 1.0.7 enabled with event-driven lock handling.");109
getLogger().info("CopperKeys 1.0.9 enabled with event-driven lock handling.");98
}110
}99
111
100
LockStore lockStore() {112
LockStore lockStore() {@@ -105,7 +117,7 @@ public final class CopperKeysPlugin extends JavaPlugin implements Listener {105
return keyItems;117
return keyItems;106
}118
}107
119
108
void renameKeyBinding(UUID bindingId, String keyName) {120
void renameKeyBinding(UUID bindingId, String keyName, Player renamer) {109
LockRecord updated = lockStore.setKeyName(bindingId, keyName);121
LockRecord updated = lockStore.setKeyName(bindingId, keyName);110
if (updated == null) {122
if (updated == null) {111
return;123
return;@@ -115,6 +127,9 @@ public final class CopperKeysPlugin extends JavaPlugin implements Listener {115
keyItems.applyNameInInventory(online.getEnderChest(), bindingId);127
keyItems.applyNameInInventory(online.getEnderChest(), bindingId);116
online.updateInventory();128
online.updateInventory();117
}129
}130
if (renamer != null) {131
awardAdvancement(renamer, organisingAdvancementKey);132
}118
}133
}119
134
120
private void registerRecipes() {135
private void registerRecipes() {@@ -134,22 +149,17 @@ public final class CopperKeysPlugin extends JavaPlugin implements Listener {134
}149
}135
150
136
private void registerAdvancements() {151
private void registerAdvancements() {137
if (Bukkit.getAdvancement(burglarAdvancementKey) != null152
Map<NamespacedKey, String> definitions = new HashMap<>();138
&& Bukkit.getAdvancement(oopsAdvancementKey) != null) {153
addAdvancementDefinition(definitions, burglarAdvancementKey, "advancements/burglar.json", "Burglar");139
return;154
addAdvancementDefinition(definitions, oopsAdvancementKey, "advancements/oops.json", "Oops");140
}155
addAdvancementDefinition(definitions, sharingIsCaringAdvancementKey, "advancements/sharing_is_caring.json", "Sharing is Caring");141
156
addAdvancementDefinition(definitions, heavyDutyAdvancementKey, "advancements/heavy_duty.json", "Heavy Duty");142
String burglarJson = readAdvancementJson("advancements/burglar.json", "Burglar");157
addAdvancementDefinition(definitions, lockedOutAdvancementKey, "advancements/locked_out.json", "Locked Out");143
String oopsJson = readAdvancementJson("advancements/oops.json", "Oops");158
addAdvancementDefinition(definitions, organisingAdvancementKey, "advancements/organising.json", "Organising");144
if (burglarJson == null || oopsJson == null) {159
if (definitions.isEmpty()) {145
return;160
return;146
}161
}147
162
148
Map<NamespacedKey, String> definitions = Map.of(149
burglarAdvancementKey, burglarJson,150
oopsAdvancementKey, oopsJson151
);152
153
try {163
try {154
List<Advancement> loaded = Bukkit.getUnsafe().loadAdvancements(definitions, false);164
List<Advancement> loaded = Bukkit.getUnsafe().loadAdvancements(definitions, false);155
if (loaded.size() != definitions.size()) {165
if (loaded.size() != definitions.size()) {@@ -160,6 +170,21 @@ public final class CopperKeysPlugin extends JavaPlugin implements Listener {160
}170
}161
}171
}162
172
173
private void addAdvancementDefinition(174
Map<NamespacedKey, String> definitions,175
NamespacedKey key,176
String resourcePath,177
String label178
) {179
if (Bukkit.getAdvancement(key) != null) {180
return;181
}182
String json = readAdvancementJson(resourcePath, label);183
if (json != null) {184
definitions.put(key, json);185
}186
}187
163
private String readAdvancementJson(String resourcePath, String label) {188
private String readAdvancementJson(String resourcePath, String label) {164
try (InputStream in = getResource(resourcePath)) {189
try (InputStream in = getResource(resourcePath)) {165
if (in == null) {190
if (in == null) {@@ -262,6 +287,9 @@ public final class CopperKeysPlugin extends JavaPlugin implements Listener {262
}287
}263
event.setCancelled(true); // The binding click itself never opens/toggles the target.288
event.setCancelled(true); // The binding click itself never opens/toggles the target.264
player.sendActionBar(Component.text("Key bound to " + record.displayName(), NamedTextColor.GOLD));289
player.sendActionBar(Component.text("Key bound to " + record.displayName(), NamedTextColor.GOLD));290
if (clicked.getType() == Material.IRON_DOOR || clicked.getType() == Material.IRON_TRAPDOOR) {291
awardAdvancement(player, heavyDutyAdvancementKey);292
}265
}293
}266
294
267
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)295
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)@@ -348,7 +376,10 @@ public final class CopperKeysPlugin extends JavaPlugin implements Listener {348
if (name == null || bindingId == null || lockStore.get(bindingId) == null) {376
if (name == null || bindingId == null || lockStore.get(bindingId) == null) {349
return;377
return;350
}378
}351
Bukkit.getScheduler().runTask(this, () -> renameKeyBinding(bindingId, name));379
Bukkit.getScheduler().runTask(this, () -> {380
Player renamer = event.getWhoClicked() instanceof Player player ? player : null;381
renameKeyBinding(bindingId, name, renamer);382
});352
}383
}353
384
354
private static String sanitizeKeyName(String raw) {385
private static String sanitizeKeyName(String raw) {@@ -527,6 +558,7 @@ public final class CopperKeysPlugin extends JavaPlugin implements Listener {527
}558
}528
player.updateInventory();559
player.updateInventory();529
});560
});561
awardAdvancement(player, sharingIsCaringAdvancementKey);530
}562
}531
563
532
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)564
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)@@ -545,6 +577,73 @@ public final class CopperKeysPlugin extends JavaPlugin implements Listener {545
}577
}546
}578
}547
579
580
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)581
public void onPlayerDropItem(PlayerDropItemEvent event) {582
Item dropped = event.getItemDrop();583
if (!isBoundKeyStack(dropped.getItemStack())) {584
return;585
}586
dropped.setThrower(event.getPlayer().getUniqueId());587
}588
589
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)590
public void onPlayerDeath(PlayerDeathEvent event) {591
Player player = event.getEntity();592
boolean dropsBoundKey = false;593
for (ItemStack drop : event.getDrops()) {594
if (isBoundKeyStack(drop)) {595
dropsBoundKey = true;596
break;597
}598
}599
if (!dropsBoundKey) {600
return;601
}602
UUID playerId = player.getUniqueId();603
Location deathLocation = player.getLocation().clone();604
Bukkit.getScheduler().runTask(this, () -> {605
for (Item item : deathLocation.getNearbyEntitiesByType(Item.class, 4.0)) {606
if (isBoundKeyStack(item.getItemStack()) && item.getThrower() == null) {607
item.setThrower(playerId);608
}609
}610
});611
}612
613
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)614
public void onKeyBurnInLava(EntityDamageEvent event) {615
if (!(event.getEntity() instanceof Item item)) {616
return;617
}618
EntityDamageEvent.DamageCause cause = event.getCause();619
if (cause != EntityDamageEvent.DamageCause.LAVA620
&& cause != EntityDamageEvent.DamageCause.FIRE621
&& cause != EntityDamageEvent.DamageCause.FIRE_TICK) {622
return;623
}624
if (!isBoundKeyStack(item.getItemStack())) {625
return;626
}627
UUID throwerId = item.getThrower();628
if (throwerId == null) {629
return;630
}631
// Item entities are removed after lethal lava/fire ticks; award once they disappear.632
Bukkit.getScheduler().runTask(this, () -> {633
if (item.isValid() && !item.isDead()) {634
return;635
}636
Player thrower = Bukkit.getPlayer(throwerId);637
if (thrower != null) {638
awardAdvancement(thrower, lockedOutAdvancementKey);639
}640
});641
}642
643
private boolean isBoundKeyStack(ItemStack stack) {644
return keyItems.isKey(stack) && !keyItems.isBlank(stack);645
}646
548
private ItemStack keyCloneResult(CraftingInventory inventory) {647
private ItemStack keyCloneResult(CraftingInventory inventory) {549
ItemStack blank = null;648
ItemStack blank = null;550
ItemStack bound = null;649
ItemStack bound = null;@@ -57,7 +57,7 @@ final class KeyNameCommand implements CommandExecutor {
57
57
return true;
58
58
}
59
59
60
plugin.renameKeyBinding(bindingId, name);
60
plugin.renameKeyBinding(bindingId, name, player);
61
61
player.sendActionBar(Component.text("Key renamed to " + name, NamedTextColor.GOLD));
62
62
return true;
63
63
}
@@ -57,7 +57,7 @@ final class KeyNameCommand implements CommandExecutor {57
return true;57
return true;58
}58
}59
59
60
plugin.renameKeyBinding(bindingId, name);60
plugin.renameKeyBinding(bindingId, name, player);61
player.sendActionBar(Component.text("Key renamed to " + name, NamedTextColor.GOLD));61
player.sendActionBar(Component.text("Key renamed to " + name, NamedTextColor.GOLD));62
return true;62
return true;63
}63
}@@ -0,0 +1,27 @@
1
{
2
"parent": "minecraft:adventure/root",
3
"display": {
4
"icon": {
5
"id": "minecraft:iron_door"
6
},
7
"title": {
8
"text": "Heavy Duty"
9
},
10
"description": {
11
"text": "Lock an iron door with a key"
12
},
13
"frame": "goal",
14
"show_toast": true,
15
"announce_to_chat": false,
16
"hidden": true
17
},
18
"criteria": {
19
"heavy_duty": {
20
"trigger": "minecraft:impossible"
21
}
22
},
23
"requirements": [
24
["heavy_duty"]
25
],
26
"sends_telemetry_event": false
27
}
@@ -0,0 +1,27 @@1
{2
"parent": "minecraft:adventure/root",3
"display": {4
"icon": {5
"id": "minecraft:iron_door"6
},7
"title": {8
"text": "Heavy Duty"9
},10
"description": {11
"text": "Lock an iron door with a key"12
},13
"frame": "goal",14
"show_toast": true,15
"announce_to_chat": false,16
"hidden": true17
},18
"criteria": {19
"heavy_duty": {20
"trigger": "minecraft:impossible"21
}22
},23
"requirements": [24
["heavy_duty"]25
],26
"sends_telemetry_event": false27
}@@ -0,0 +1,27 @@
1
{
2
"parent": "minecraft:adventure/root",
3
"display": {
4
"icon": {
5
"id": "minecraft:lava_bucket"
6
},
7
"title": {
8
"text": "Locked Out"
9
},
10
"description": {
11
"text": "Watch your key burn in lava"
12
},
13
"frame": "goal",
14
"show_toast": true,
15
"announce_to_chat": false,
16
"hidden": true
17
},
18
"criteria": {
19
"locked_out": {
20
"trigger": "minecraft:impossible"
21
}
22
},
23
"requirements": [
24
["locked_out"]
25
],
26
"sends_telemetry_event": false
27
}
@@ -0,0 +1,27 @@1
{2
"parent": "minecraft:adventure/root",3
"display": {4
"icon": {5
"id": "minecraft:lava_bucket"6
},7
"title": {8
"text": "Locked Out"9
},10
"description": {11
"text": "Watch your key burn in lava"12
},13
"frame": "goal",14
"show_toast": true,15
"announce_to_chat": false,16
"hidden": true17
},18
"criteria": {19
"locked_out": {20
"trigger": "minecraft:impossible"21
}22
},23
"requirements": [24
["locked_out"]25
],26
"sends_telemetry_event": false27
}@@ -0,0 +1,27 @@
1
{
2
"parent": "minecraft:adventure/root",
3
"display": {
4
"icon": {
5
"id": "minecraft:name_tag"
6
},
7
"title": {
8
"text": "Organising"
9
},
10
"description": {
11
"text": "Give a key a custom name"
12
},
13
"frame": "goal",
14
"show_toast": true,
15
"announce_to_chat": false,
16
"hidden": true
17
},
18
"criteria": {
19
"organising": {
20
"trigger": "minecraft:impossible"
21
}
22
},
23
"requirements": [
24
["organising"]
25
],
26
"sends_telemetry_event": false
27
}
@@ -0,0 +1,27 @@1
{2
"parent": "minecraft:adventure/root",3
"display": {4
"icon": {5
"id": "minecraft:name_tag"6
},7
"title": {8
"text": "Organising"9
},10
"description": {11
"text": "Give a key a custom name"12
},13
"frame": "goal",14
"show_toast": true,15
"announce_to_chat": false,16
"hidden": true17
},18
"criteria": {19
"organising": {20
"trigger": "minecraft:impossible"21
}22
},23
"requirements": [24
["organising"]25
],26
"sends_telemetry_event": false27
}@@ -0,0 +1,27 @@
1
{
2
"parent": "minecraft:adventure/root",
3
"display": {
4
"icon": {
5
"id": "minecraft:clock"
6
},
7
"title": {
8
"text": "Sharing is Caring"
9
},
10
"description": {
11
"text": "Copy a key so someone else can open it too"
12
},
13
"frame": "goal",
14
"show_toast": true,
15
"announce_to_chat": false,
16
"hidden": true
17
},
18
"criteria": {
19
"sharing_is_caring": {
20
"trigger": "minecraft:impossible"
21
}
22
},
23
"requirements": [
24
["sharing_is_caring"]
25
],
26
"sends_telemetry_event": false
27
}
@@ -0,0 +1,27 @@1
{2
"parent": "minecraft:adventure/root",3
"display": {4
"icon": {5
"id": "minecraft:clock"6
},7
"title": {8
"text": "Sharing is Caring"9
},10
"description": {11
"text": "Copy a key so someone else can open it too"12
},13
"frame": "goal",14
"show_toast": true,15
"announce_to_chat": false,16
"hidden": true17
},18
"criteria": {19
"sharing_is_caring": {20
"trigger": "minecraft:impossible"21
}22
},23
"requirements": [24
["sharing_is_caring"]25
],26
"sends_telemetry_event": false27
}