Skip to content

Commit

Permalink
Release 6.11.3
Browse files Browse the repository at this point in the history
Fixed duplicate Join Items.

Signed-off-by: Fabricio20 <[email protected]>
  • Loading branch information
Fabricio20 committed Feb 16, 2020
1 parent fb48a7a commit 862b9f1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import net.notfab.hubbasics.spigot.entities.EnumModules;
import net.notfab.hubbasics.spigot.entities.Module;
import net.notfab.hubbasics.spigot.nms.CraftBukkitVersion;
import net.notfab.hubbasics.spigot.nms.nbt.NBTItem;
import net.notfab.spigot.simpleconfig.SimpleConfig;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -66,6 +69,7 @@ public void onJoin(PlayerJoinEvent event) {
CustomItem item = HubBasics.getItemManager().get(id);
if (item == null) return;
if (item.getPermission() != null && !event.getPlayer().hasPermission(item.getPermission())) return;
this.removeItem(item, event.getPlayer().getInventory());
if (item.getSlot() == null || item.getSlot() == -1) {
event.getPlayer().getInventory().addItem(item.toItemStack(event.getPlayer()));
} else {
Expand All @@ -86,6 +90,7 @@ public void onWorldChange(PlayerChangedWorldEvent event) {
CustomItem item = HubBasics.getItemManager().get(id);
if (item == null) return;
if (item.getPermission() != null && !event.getPlayer().hasPermission(item.getPermission())) return;
this.removeItem(item, event.getPlayer().getInventory());
if (item.getSlot() == null || item.getSlot() == -1) {
event.getPlayer().getInventory().addItem(item.toItemStack(event.getPlayer()));
} else {
Expand All @@ -94,4 +99,18 @@ public void onWorldChange(PlayerChangedWorldEvent event) {
});
}

@SuppressWarnings("ConstantConditions")
private void removeItem(CustomItem item, Inventory inventory) {
for (ItemStack content : inventory.getContents()) {
if (content == null || (content.getType() != item.getMaterial())) {
continue;
}
NBTItem nbtItem = new NBTItem(content);
if (nbtItem.hasKey("HubBasics")
&& item.getId().equalsIgnoreCase(nbtItem.getString("HubBasics"))) {
inventory.remove(content);
}
}
}

}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
allprojects {
group 'net.notfab.hubbasics'
version = '6.11.2'
version = '6.11.3'
wrapper {
gradleVersion = '6.0.1'
}
Expand Down

0 comments on commit 862b9f1

Please sign in to comment.