3
0
Mirror von https://github.com/St3venAU/ArmorStandTools.git synchronisiert 2024-12-26 03:20:07 +01:00

v4.4.6 Fix bug where tools are kept when returning inventory in 1.20.6

Dieser Commit ist enthalten in:
Steven 2024-05-23 22:44:18 +08:00
Ursprung d401855aaf
Commit 0726fde530
2 geänderte Dateien mit 17 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.st3venau.plugins</groupId> <groupId>com.gmail.st3venau.plugins</groupId>
<artifactId>ArmorStandTools</artifactId> <artifactId>ArmorStandTools</artifactId>
<version>4.4.5</version> <version>4.4.6</version>
<name>ArmorStandTools</name> <name>ArmorStandTools</name>
<repositories> <repositories>

Datei anzeigen

@ -26,6 +26,7 @@ import org.bukkit.scheduler.BukkitRunnable;
import java.util.AbstractMap; import java.util.AbstractMap;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -117,7 +118,6 @@ public class AST extends JavaPlugin {
waitingForName.clear(); waitingForName.clear();
waitingForSkull.clear(); waitingForSkull.clear();
} }
static void returnArmorStand(ArmorStand as) { static void returnArmorStand(ArmorStand as) {
if(as == null) return; if(as == null) return;
if(as.hasMetadata("clone")) { if(as.hasMetadata("clone")) {
@ -139,19 +139,31 @@ public class AST extends JavaPlugin {
as.remove(); as.remove();
} }
private static boolean matches(ItemStack one, ItemStack two) {
if(one == null || two == null || one.getItemMeta() == null || two.getItemMeta() == null) return false;
String NameOne = one.getItemMeta().getDisplayName();
List<String> LoreOne = one.getItemMeta().getLore();
if(LoreOne == null) return false;
String NameTwo = two.getItemMeta().getDisplayName();
List<String> LoreTwo = two.getItemMeta().getLore();
if(LoreTwo == null) return false;
return NameOne.equals(NameTwo) && LoreOne.equals(LoreTwo);
}
private static void removeAllTools(Player p) { private static void removeAllTools(Player p) {
PlayerInventory i = p.getInventory(); PlayerInventory i = p.getInventory();
for(ArmorStandTool t : ArmorStandTool.values()) { for(ArmorStandTool t : ArmorStandTool.values()) {
i.remove(t.getItem()); for(int slot = 0; slot < i.getSize(); slot++) {
if(matches(t.getItem(), i.getItem(slot))) {
i.setItem(slot, null);
}
}
} }
} }
void saveInventoryAndClear(Player p) { void saveInventoryAndClear(Player p) {
ItemStack[] inv = p.getInventory().getContents().clone(); ItemStack[] inv = p.getInventory().getContents().clone();
savedInventories.put(p.getUniqueId(), inv); savedInventories.put(p.getUniqueId(), inv);
p.getInventory().clear(); p.getInventory().clear();
} }
static void restoreInventory(Player p) { static void restoreInventory(Player p) {
removeAllTools(p); removeAllTools(p);
UUID uuid = p.getUniqueId(); UUID uuid = p.getUniqueId();