Skip to content

Commit

Permalink
Changed death-keep functions
Browse files Browse the repository at this point in the history
  • Loading branch information
RockinChaos committed Mar 16, 2024
1 parent 6137712 commit aea3e08
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/me/RockinChaos/itemjoin/item/ItemUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ private void handleItems(final Player player, World world, final TriggerType typ
item.setAnimations(player);
if (((type.equals(TriggerType.JOIN) && item.isGiveOnJoin())
|| (type.equals(TriggerType.TELEPORT) && item.isGiveOnTeleport())
|| (type.equals(TriggerType.RESPAWN) && (item.isGiveOnRespawn() || item.isDeathKeepable()))
|| (type.equals(TriggerType.RESPAWN_POINT) && (item.isGiveOnRespawnPoint() || item.isGiveOnRespawn() || item.isDeathKeepable()))
|| (type.equals(TriggerType.RESPAWN) && (item.isGiveOnRespawn()))
|| (type.equals(TriggerType.RESPAWN_POINT) && (item.isGiveOnRespawnPoint() || item.isGiveOnRespawn()))
|| (type.equals(TriggerType.WORLD_SWITCH) && item.isGiveOnWorldSwitch())
|| (type.equals(TriggerType.LIMIT_SWITCH) && item.isUseOnLimitSwitch() && (StringUtils.containsValue(regions, "IJ_WORLD") || item.inRegion(regions) || item.getEnabledRegions() == null || item.getEnabledRegions().isEmpty()))
|| (type.equals(TriggerType.REGION_ENTER) && (item.isGiveOnRegionEnter() || item.isGiveOnRegionAccess()) && item.inRegion(regions))
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/me/RockinChaos/itemjoin/listeners/Drops.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import me.RockinChaos.core.utils.SchedulerUtils;
import me.RockinChaos.core.utils.api.LegacyAPI;
import me.RockinChaos.itemjoin.PluginData;
import me.RockinChaos.itemjoin.item.ItemMap;
import me.RockinChaos.itemjoin.item.ItemUtilities;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -143,6 +144,26 @@ private void onDeathDrops(PlayerDeathEvent event) {
List<ItemStack> drops = new ArrayList<>(event.getDrops());
for (final ItemStack stack : drops) {
if (stack != null && (!ItemUtilities.getUtilities().isAllowed(player, stack, "death-drops") || !ItemUtilities.getUtilities().isAllowed(player, stack, "death-keep"))) {
if (!ItemUtilities.getUtilities().isAllowed(player, stack, "death-keep")) {
int slot = -1;
final ItemStack keepItem = stack.clone();
for (int inventory = 0; inventory < event.getEntity().getInventory().getSize(); inventory++) {
ItemStack item = event.getEntity().getInventory().getItem(inventory);
final ItemMap itemMap = ItemUtilities.getUtilities().getItemMap(item);
if (itemMap != null && itemMap.isSimilar(player, stack)) {
slot = inventory;
break;
}
}
int setSlot = slot;
SchedulerUtils.run(() -> {
if (setSlot == -1) {
player.getInventory().addItem(keepItem);
} else {
player.getInventory().setItem(setSlot, keepItem);
}
});
}
event.getEntity().getInventory().remove(stack);
event.getDrops().remove(stack);
}
Expand Down

0 comments on commit aea3e08

Please sign in to comment.