Skip to content

Commit

Permalink
Merge pull request #2 from Nocsy-Workshop/main
Browse files Browse the repository at this point in the history
Bug fixes:
  • Loading branch information
jhqwqmc authored Feb 11, 2024
2 parents a2ab5f7 + 0bb5533 commit 0fe0eae
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 31 deletions.
20 changes: 16 additions & 4 deletions src/main/java/fr/nocsy/mcpets/data/flags/DismountFlyPetFlag.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -48,19 +49,30 @@ 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();
if(model.getMountData() == null ||
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);

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/fr/nocsy/mcpets/data/inventories/PetMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/fr/nocsy/mcpets/listeners/EventListener.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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());
Expand All @@ -39,6 +39,9 @@ public static void init(JavaPlugin plugin) {
plugin.getServer().getPluginManager().registerEvents(l, plugin);
}

if(GlobalConfig.getInstance().isWorldguardsupport())
listeners.add(new PetDamageFlagListener());

}

}
53 changes: 28 additions & 25 deletions src/main/java/fr/nocsy/mcpets/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,37 +32,39 @@
public class Utils {

public static ItemStack createHead(String name, List<String> 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) {
Expand Down

0 comments on commit 0fe0eae

Please sign in to comment.