From 0bb55337b154f82a274071182c87f2b1013b3505 Mon Sep 17 00:00:00 2001 From: AlexandreChaussard Date: Sat, 10 Feb 2024 14:35:07 +0100 Subject: [PATCH] =?UTF-8?q?Bug=20fixes:=20=F0=9F=94=B8=20Fixing=20inventor?= =?UTF-8?q?y=20with=20fixed=20sized=20to=20have=20correct=20pages=20implem?= =?UTF-8?q?entation=20=F0=9F=94=B8=20Fixing=20a=20WorldGuard=20dependency?= =?UTF-8?q?=20issue=20=F0=9F=94=B8=20Provides=20a=20temporary=20patch=20to?= =?UTF-8?q?=20the=20"mcpets-dismount-flying"=20flag=20for=20MEG4.=20But=20?= =?UTF-8?q?the=20issue=20seems=20to=20be=20present=20deeper=20in=20MEG=20c?= =?UTF-8?q?ode.=20The=20current=20patch=20should=20still=20work=20fine,=20?= =?UTF-8?q?but=20may=20not=20work=20on=20future=20MEG4=20releases.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mcpets/data/flags/DismountFlyPetFlag.java | 20 +++++-- .../mcpets/data/inventories/PetMenu.java | 6 ++- .../nocsy/mcpets/listeners/EventListener.java | 5 +- .../java/fr/nocsy/mcpets/utils/Utils.java | 53 ++++++++++--------- 4 files changed, 53 insertions(+), 31 deletions(-) diff --git a/src/main/java/fr/nocsy/mcpets/data/flags/DismountFlyPetFlag.java b/src/main/java/fr/nocsy/mcpets/data/flags/DismountFlyPetFlag.java index 6aa14cc..68aecad 100644 --- a/src/main/java/fr/nocsy/mcpets/data/flags/DismountFlyPetFlag.java +++ b/src/main/java/fr/nocsy/mcpets/data/flags/DismountFlyPetFlag.java @@ -6,6 +6,7 @@ import fr.nocsy.mcpets.MCPets; import fr.nocsy.mcpets.data.Pet; import fr.nocsy.mcpets.data.config.Language; +import fr.nocsy.mcpets.utils.Utils; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -48,7 +49,8 @@ public void run() { if (!pet.isMountable()) continue; - ModeledEntity model = ModelEngineAPI.getModeledEntity(pet.getActiveMob().getUniqueId()); + UUID uuid = pet.getActiveMob().getUniqueId(); + ModeledEntity model = ModelEngineAPI.getModeledEntity(uuid); if(model == null) continue; MountManager mountManager = model.getMountData().getMainMountManager(); @@ -56,11 +58,21 @@ public void run() { model.getMountData().getMainMountManager() == null || model.getMountData().getMainMountManager().getType() == null) continue; + if(!mountManager.hasRiders()) + continue; - String name = model.getMountData().getMainMountManager().getType().getId(); - - if(name == null || !name.toUpperCase().contains("FLY")) + try + { + String controllerClass = ModelEngineAPI.getMountPairManager().getController(owner).getClass().getSimpleName(); + String petMountType = pet.getMountType(); + String type = petMountType + " " + model.getMountData().getMainMountManager().getType().getId() + " " + controllerClass; + if(!type.toUpperCase().contains("FLY")) + continue; + } + catch (Exception e) + { continue; + } Player p = Bukkit.getPlayer(owner); diff --git a/src/main/java/fr/nocsy/mcpets/data/inventories/PetMenu.java b/src/main/java/fr/nocsy/mcpets/data/inventories/PetMenu.java index 8541bcb..3b83fa4 100644 --- a/src/main/java/fr/nocsy/mcpets/data/inventories/PetMenu.java +++ b/src/main/java/fr/nocsy/mcpets/data/inventories/PetMenu.java @@ -41,7 +41,11 @@ public PetMenu(Player p, int page) { // Let's see if we need to add a pager to the inventory // Either we have more than 53 pets or we are at a page greater than 0 boolean addPager = page > 0; - for(int i = 53 * page; i < availablePets.size(); i++) + int pageSize = 53; + if (GlobalConfig.getInstance().getAdaptiveInventory() > 0) { + pageSize = GlobalConfig.getInstance().getAdaptiveInventory() - 1; + } + for(int i = pageSize * page; i < availablePets.size(); i++) { // We can not have more than 53 pets selected at a given page if(selectedPets.size() >= 53) diff --git a/src/main/java/fr/nocsy/mcpets/listeners/EventListener.java b/src/main/java/fr/nocsy/mcpets/listeners/EventListener.java index 0060857..af2ec31 100644 --- a/src/main/java/fr/nocsy/mcpets/listeners/EventListener.java +++ b/src/main/java/fr/nocsy/mcpets/listeners/EventListener.java @@ -1,5 +1,6 @@ package fr.nocsy.mcpets.listeners; +import fr.nocsy.mcpets.MCPets; import fr.nocsy.mcpets.data.config.GlobalConfig; import fr.nocsy.mcpets.listeners.editor.EditorConversationListener; import fr.nocsy.mcpets.listeners.editor.EditorGlobalListener; @@ -18,7 +19,6 @@ public static void init(JavaPlugin plugin) { listeners.add(new PetMenuListener()); listeners.add(new PetInteractionMenuListener()); listeners.add(new PetListener()); - listeners.add(new PetDamageFlagListener()); listeners.add(new CategoriesMenuListener()); listeners.add(new CategoryMenuListener()); listeners.add(new PetInventoryListener()); @@ -39,6 +39,9 @@ public static void init(JavaPlugin plugin) { plugin.getServer().getPluginManager().registerEvents(l, plugin); } + if(GlobalConfig.getInstance().isWorldguardsupport()) + listeners.add(new PetDamageFlagListener()); + } } diff --git a/src/main/java/fr/nocsy/mcpets/utils/Utils.java b/src/main/java/fr/nocsy/mcpets/utils/Utils.java index 3c05d5f..d7091ab 100644 --- a/src/main/java/fr/nocsy/mcpets/utils/Utils.java +++ b/src/main/java/fr/nocsy/mcpets/utils/Utils.java @@ -14,6 +14,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.profile.PlayerProfile; import org.bukkit.profile.PlayerTextures; @@ -31,37 +32,39 @@ public class Utils { public static ItemStack createHead(String name, List lore, String base64) { - ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1, (short)3); - SkullMeta meta = (SkullMeta) head.getItemMeta(); - + ItemStack item = new ItemStack(Material.PLAYER_HEAD); + SkullMeta meta = (SkullMeta) item.getItemMeta(); meta.setDisplayName(name); + try { + byte[] decodedBytes = Base64.getDecoder().decode(base64); + String decodedString = new String(decodedBytes); - byte[] decodedBytes = Base64.getDecoder().decode(base64); - String decodedString = new String(decodedBytes); - - JsonParser parser = new JsonParser(); - JsonObject jsonObject = parser.parse(decodedString).getAsJsonObject(); - String url = jsonObject.getAsJsonObject("textures").getAsJsonObject("SKIN").get("url").getAsString(); + JsonParser parser = new JsonParser(); + JsonObject jsonObject = parser.parse(decodedString).getAsJsonObject(); + String url = jsonObject.getAsJsonObject("textures").getAsJsonObject("SKIN").get("url").getAsString(); - ItemStack item = new ItemStack(Material.PLAYER_HEAD); - PlayerProfile pp = Bukkit.createPlayerProfile(UUID.fromString("4fbecd49-c7d4-4c18-8410-adf7a7348728")); - PlayerTextures pt = pp.getTextures(); - URL urlObject = null; - try { - urlObject = new URL(url); - } catch (MalformedURLException e) { + PlayerProfile pp = Bukkit.createPlayerProfile(UUID.fromString("4fbecd49-c7d4-4c18-8410-adf7a7348728")); + PlayerTextures pt = pp.getTextures(); + URL urlObject = null; try { - urlObject = new URL("http://textures.minecraft.net/texture/8dcfabbbb4d7b0381135bf07b6af3de920ab4c366c06c37fa4c4e8b8f43bbb2b"); - } catch (MalformedURLException malformedURLException) { - malformedURLException.printStackTrace(); + urlObject = new URL(url); + } catch (MalformedURLException e) { + try { + urlObject = new URL("http://textures.minecraft.net/texture/8dcfabbbb4d7b0381135bf07b6af3de920ab4c366c06c37fa4c4e8b8f43bbb2b"); + } catch (MalformedURLException malformedURLException) { + malformedURLException.printStackTrace(); + } } - } - pt.setSkin(urlObject); - pp.setTextures(pt); - meta.setOwnerProfile(pp); - item.setItemMeta(meta); - return item; + pt.setSkin(urlObject); + pp.setTextures(pt); + meta.setOwnerProfile(pp); + item.setItemMeta(meta); + return item; + } catch (Exception e) { + item.setItemMeta(meta); + return item; + } } public static double distance(Location loc1, Location loc2) {