Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
jhqwqmc committed Aug 4, 2024
2 parents df39af1 + f1ddbea commit 4a58e2d
Show file tree
Hide file tree
Showing 17 changed files with 63 additions and 58 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.20.2-R0.1-SNAPSHOT</version>
<version>1.21-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.20.4-R0.1-SNAPSHOT</version>
<version>1.21-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -142,7 +142,7 @@
<dependency>
<groupId>com.ticxo.modelengine</groupId>
<artifactId>ModelEngine</artifactId>
<version>R4.0.3</version>
<version>R4.0.6</version>
</dependency>

</dependencies>
Expand Down
24 changes: 14 additions & 10 deletions src/main/java/fr/nocsy/mcpets/data/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,15 @@ public boolean openInventory(Player p, int page)
if(showedPets.isEmpty() && page > 0)
return false;

invSize = showedPets.size();
if(maxPages > 1)
invSize++;
while(invSize <= 0 || invSize % 9 != 0)
invSize++;
// Adaptive inventory setting
if(GlobalConfig.getInstance().getAdaptiveInventory() <= 0)
{
invSize = showedPets.size();
if(maxPages > 1)
invSize++;
while(invSize <= 0 || invSize % 9 != 0)
invSize++;
}

Inventory inventory = Bukkit.createInventory(null, invSize, displayName);

Expand Down Expand Up @@ -148,7 +152,7 @@ public void setIcon(ItemStack it)
private void setupData()
{
ItemMeta meta = icon.getItemMeta();
meta.setLocalizedName("MCPetsCategory;" + this.getId());
meta.setItemName("MCPetsCategory;" + this.getId());
meta.setDisplayName(iconName);

icon.setItemMeta(meta);
Expand All @@ -169,9 +173,9 @@ public int getCurrentPage(Inventory inventory)
if(pager != null
&& !pager.getType().isAir()
&& pager.hasItemMeta()
&& pager.getItemMeta().hasLocalizedName())
&& pager.getItemMeta().hasItemName())
{
String[] data = pager.getItemMeta().getLocalizedName().split(";");
String[] data = pager.getItemMeta().getItemName().split(";");
if(data.length != 3)
return -1;

Expand Down Expand Up @@ -247,9 +251,9 @@ public static Category getFromInventory(Inventory inventory)
if(pager != null
&& !pager.getType().isAir()
&& pager.hasItemMeta()
&& pager.getItemMeta().hasLocalizedName())
&& pager.getItemMeta().hasItemName())
{
String[] data = pager.getItemMeta().getLocalizedName().split(";");
String[] data = pager.getItemMeta().getItemName().split(";");
if(data.length != 3)
return null;

Expand Down
28 changes: 14 additions & 14 deletions src/main/java/fr/nocsy/mcpets/data/Items.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void setItem(ItemStack item)
private void prepareItem()
{
ItemMeta meta = item.getItemMeta();
meta.setLocalizedName(getLocalizedName());
meta.setItemName(getLocalizedName());
item.setItemMeta(meta);
}

Expand All @@ -95,7 +95,7 @@ private static ItemStack unknown()
ItemMeta meta = it.getItemMeta();
meta.setDisplayName("未知");
meta.setLore(lore);
meta.setLocalizedName("AlmPet;Unknown");
meta.setItemName("AlmPet;Unknown");

it.setItemMeta(meta);

Expand Down Expand Up @@ -134,7 +134,7 @@ private static ItemStack petmenu() {
ItemMeta meta = it.getItemMeta();
meta.setDisplayName(Language.BACK_TO_PETMENU_ITEM_NAME.getMessage());
meta.setLore(lore);
meta.setLocalizedName("AlmPet;BackToPetMenu");
meta.setItemName("AlmPet;BackToPetMenu");

it.setItemMeta(meta);

Expand All @@ -147,7 +147,7 @@ private static ItemStack inventory() {
ItemStack it = new ItemStack(Material.CHEST);
ItemMeta meta = it.getItemMeta();
meta.setDisplayName(Language.INVENTORY_ITEM_NAME.getMessage());
meta.setLocalizedName("AlmPet;Inventory");
meta.setItemName("AlmPet;Inventory");

it.setItemMeta(meta);

Expand All @@ -160,7 +160,7 @@ private static ItemStack skins() {
ItemStack it = new ItemStack(Material.MAGMA_CREAM);
ItemMeta meta = it.getItemMeta();
meta.setDisplayName(Language.SKINS_ITEM_NAME.getMessage());
meta.setLocalizedName("AlmPet;Skins");
meta.setItemName("AlmPet;Skins");

it.setItemMeta(meta);

Expand All @@ -173,7 +173,7 @@ private static ItemStack equipment() {
ItemStack it = new ItemStack(Material.LEATHER_HORSE_ARMOR);
ItemMeta meta = it.getItemMeta();
meta.setDisplayName(Language.EQUIPMENT_ITEM_NAME.getMessage());
meta.setLocalizedName("AlmPet;Inventory");
meta.setItemName("AlmPet;Inventory");

it.setItemMeta(meta);

Expand All @@ -194,7 +194,7 @@ public static ItemStack page(int index, Player p) {
meta.setDisplayName(Language.TURNPAGE_ITEM_NAME.getMessageFormatted(new FormatArg("%currentPage%", Integer.toString(index+1)),
new FormatArg("%maxPage%", Integer.toString((int)(Pet.getAvailablePets(p).size()/54 + 0.5)))));

meta.setLocalizedName("AlmPetPage;" + index);
meta.setItemName("AlmPetPage;" + index);

ArrayList<String> lore = new ArrayList<>(Arrays.asList(Language.TURNPAGE_ITEM_DESCRIPTION.getMessage().split("\n")));
meta.setLore(lore);
Expand All @@ -208,7 +208,7 @@ public static ItemStack page(Category category, int index) {
ItemMeta meta = it.getItemMeta();
meta.setDisplayName(Language.TURNPAGE_ITEM_NAME.getMessageFormatted(new FormatArg("%currentPage%", Integer.toString(index+1)),
new FormatArg("%maxPage%", Integer.toString(category.getMaxPages()))));
meta.setLocalizedName("MCPetsPage;" + category.getId() + ";" + index);
meta.setItemName("MCPetsPage;" + category.getId() + ";" + index);

ArrayList<String> lore = new ArrayList<>(Arrays.asList(Language.TURNPAGE_ITEM_DESCRIPTION.getMessageFormatted(
new FormatArg("%currentPage%", Integer.toString(index)),
Expand Down Expand Up @@ -241,7 +241,7 @@ public static ItemStack petInfo(Pet pet) {
lore.addAll(Arrays.asList(Language.NICKNAME_ITEM_LORE.getMessage().split("\n")));

meta.setLore(lore);
meta.setLocalizedName(null);
meta.setItemName(null);
it.setItemMeta(meta);
return it;
}
Expand All @@ -262,8 +262,8 @@ public static ItemStack deco(Material mat) {
public static boolean isSignalStick(ItemStack it) {
return it != null &&
it.hasItemMeta() &&
it.getItemMeta().hasLocalizedName() &&
it.getItemMeta().getLocalizedName().contains(Pet.SIGNAL_STICK_TAG);
it.getItemMeta().hasItemName() &&
it.getItemMeta().getItemName().contains(Pet.SIGNAL_STICK_TAG);
}

public static ItemStack turnIntoSignalStick(ItemStack it, Pet pet)
Expand All @@ -273,7 +273,7 @@ public static ItemStack turnIntoSignalStick(ItemStack it, Pet pet)
pet == null)
return it;
ItemMeta meta = it.getItemMeta();
meta.setLocalizedName(buildSignalStickTag(pet));
meta.setItemName(buildSignalStickTag(pet));
it.setItemMeta(meta);
return it;
}
Expand All @@ -289,9 +289,9 @@ public static String getPetTag(ItemStack it)
{
if(it != null &&
it.hasItemMeta() &&
it.getItemMeta().hasLocalizedName())
it.getItemMeta().hasItemName())
{
String[] split = it.getItemMeta().getLocalizedName().split(";");
String[] split = it.getItemMeta().getItemName().split(";");
if(split.length == 2)
return split[1];
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/fr/nocsy/mcpets/data/Pet.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityMountEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull;
import org.spigotmc.event.entity.EntityMountEvent;

import java.util.*;

Expand Down Expand Up @@ -307,8 +307,8 @@ public static Pet getFromId(String id) {
* @return
*/
public static Pet getFromIcon(ItemStack icon) {
if (icon.hasItemMeta() && icon.getItemMeta().hasLocalizedName()) {
return fromString(icon.getItemMeta().getLocalizedName());
if (icon.hasItemMeta() && icon.getItemMeta().hasItemName()) {
return fromString(icon.getItemMeta().getItemName());
}
return null;
}
Expand Down Expand Up @@ -1430,20 +1430,20 @@ public ItemStack buildItem(ItemStack item, boolean showStats, String localizedNa
&& textureBase64 != null) {
item = Utils.createHead(iconName, desc, textureBase64);
ItemMeta meta = item.getItemMeta();
meta.setLocalizedName(localizedName);
meta.setItemName(localizedName);
item.setItemMeta(meta);
} else if (mat != null) {
item = new ItemStack(mat);
ItemMeta meta = item.getItemMeta();
meta.setLocalizedName(localizedName);
meta.setItemName(localizedName);
meta.setCustomModelData(customModelData);
meta.setDisplayName(iconName);
meta.setLore(desc);
item.setItemMeta(meta);
} else if(item == null){
item = Utils.createHead(iconName, desc, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOWQ5Y2M1OGFkMjVhMWFiMTZkMzZiYjVkNmQ0OTNjOGY1ODk4YzJiZjMwMmI2NGUzMjU5MjFjNDFjMzU4NjcifX19");
ItemMeta meta = item.getItemMeta();
meta.setLocalizedName(localizedName);
meta.setItemName(localizedName);
item.setItemMeta(meta);
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/fr/nocsy/mcpets/data/PetSkin.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ public static void load(String pathId, Pet objectPet, String modelSkinId, String
public static PetSkin fromIcon(ItemStack it)
{
if(it.hasItemMeta() &&
it.getItemMeta().hasLocalizedName())
it.getItemMeta().hasItemName())
{
String[] code = it.getItemMeta().getLocalizedName().split(";");
String[] code = it.getItemMeta().getItemName().split(";");
if(code.length > 0 && code[0].equals("MCPetsSkins"))
{
String petId = code[1];
Expand Down Expand Up @@ -209,7 +209,7 @@ private void initIcon()
private void prepareIcon()
{
ItemMeta meta = icon.getItemMeta();
meta.setLocalizedName("MCPetsSkins;" + objectPet.getId() + ";" + uuid);
meta.setItemName("MCPetsSkins;" + objectPet.getId() + ";" + uuid);
icon.setItemMeta(meta);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private ItemStack setupUnkownIcon()
{
ItemStack it = Items.UNKNOWN.getItem().clone();
ItemMeta meta = it.getItemMeta();
meta.setLocalizedName("MCPets;" + id);
meta.setItemName("MCPets;" + id);
meta.setDisplayName("§6" + id);
it.setItemMeta(meta);
return it;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fr/nocsy/mcpets/data/config/Language.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public enum Language {

REQUIRES_MODELENGINE("§c此插件需要 ModelEngine r2.3.1.似乎未满足此要求."),

USAGE("§c此命令不存在.\n§7查看 wiki:§nhttps://alexandre-chaussard.gitbook.io/mcpets/tutorials/plugin-features/commands"),
USAGE("§c此命令不存在.\n§7查看 wiki:§nhttps://mcpets.gitbook.io/mcpets/tutorials/plugin-features/commands"),
NO_PERM("§c您无权使用此命令."),
BLACKLISTED_WORLD("§cMCPets 在此世界中已禁用."),

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fr/nocsy/mcpets/data/config/PetConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ private ItemStack legacyItemRead(ItemStack item, boolean showStats, String local
{
itemStack = getConfig().getItemStack(path + ".Raw");
ItemMeta meta = itemStack.getItemMeta();
meta.setLocalizedName(localName);
meta.setItemName(localName);
itemStack.setItemMeta(meta);
if(showStats)
itemStack = pet.applyStats(itemStack);
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/fr/nocsy/mcpets/data/editor/EditorItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public ItemStack getItem()
ItemMeta meta = it.getItemMeta();
if(it.getType().equals(Material.FILLED_MAP))
it.setType(Material.MAP);
meta.setLocalizedName(editorTag + getId());
meta.setItemName(editorTag + getId());

// Basically, we are replacing the placeholder for the value within the lores
List<String> lores = meta.getLore();
Expand Down Expand Up @@ -428,7 +428,6 @@ else if(valueStr.equalsIgnoreCase("false"))
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
meta.addItemFlags(ItemFlag.HIDE_PLACED_ON);
meta.addItemFlags(ItemFlag.HIDE_DYE);
meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
meta.addItemFlags(ItemFlag.HIDE_DESTROYS);
it.setItemMeta(meta);
return it;
Expand All @@ -439,7 +438,7 @@ public static EditorItems getFromItemstack(ItemStack it)
if(it == null || !it.hasItemMeta())
return null;

String localName = it.getItemMeta().getLocalizedName();
String localName = it.getItemMeta().getItemName();
// Item does not have the editor tag, so it's not an editor item
if(!localName.contains(editorTag))
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public static Category findCategory(ItemStack icon)
return null;

if(icon.hasItemMeta() &&
icon.getItemMeta().hasLocalizedName() &&
icon.getItemMeta().getLocalizedName().contains("MCPetsCategory"))
icon.getItemMeta().hasItemName() &&
icon.getItemMeta().getItemName().contains("MCPetsCategory"))
{
String[] data = icon.getItemMeta().getLocalizedName().split(";");
String[] data = icon.getItemMeta().getItemName().split(";");
if(data.length == 2)
{
String catId = data[1];
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/fr/nocsy/mcpets/data/livingpets/PetFood.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public ItemStack getItemStack()
itemStack = Items.UNKNOWN.getItem().clone();
}
ItemMeta meta = itemStack.getItemMeta();
meta.setLocalizedName("MCPets;Food;" + itemId);
meta.setItemName("MCPets;Food;" + itemId);
itemStack.setItemMeta(meta);
}

Expand Down Expand Up @@ -332,7 +332,7 @@ public static PetFood getFromItem(ItemStack it)
if(it == null)
return null;
// if the item is a default MC item, then look for possible matches
if(!it.hasItemMeta() || !it.getItemMeta().hasLocalizedName())
if(!it.hasItemMeta() || !it.getItemMeta().hasItemName())
{
return PetFoodConfig.getInstance().list().stream()
.filter(petFood -> petFood.isDefaultMCItem()
Expand All @@ -344,7 +344,7 @@ public static PetFood getFromItem(ItemStack it)
// if the item isn't a default MCItem, go through the localized informations
return PetFoodConfig.getInstance().list().stream()
.filter(petFood -> petFood.getItemStack() != null
&& petFood.getItemStack().getItemMeta().getLocalizedName().equals(it.getItemMeta().getLocalizedName()))
&& petFood.getItemStack().getItemMeta().getItemName().equals(it.getItemMeta().getItemName()))
.findFirst()
.orElse(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void click(InventoryClickEvent e) {

ItemStack it = e.getCurrentItem();
if (it != null) {
if (it.hasItemMeta() && it.getItemMeta().hasLocalizedName() && it.getItemMeta().getLocalizedName().contains("MCPetsPage;")) {
if (it.hasItemMeta() && it.getItemMeta().hasItemName() && it.getItemMeta().getItemName().contains("MCPetsPage;")) {

int currentPage = category.getCurrentPage(e.getClickedInventory());
if (e.getClick() == ClickType.LEFT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ public void click(InventoryClickEvent e) {
}

ItemStack it = e.getCurrentItem();
if (it != null && it.hasItemMeta() && it.getItemMeta().hasDisplayName() && it.getItemMeta().hasLocalizedName()) {
if (it != null && it.hasItemMeta() && it.getItemMeta().hasDisplayName() && it.getItemMeta().hasItemName()) {

String localizedName = it.getItemMeta().getLocalizedName();
String localizedName = it.getItemMeta().getItemName();
if (localizedName.contains("AlmPetPage;"))
return;

Expand Down
8 changes: 5 additions & 3 deletions src/main/java/fr/nocsy/mcpets/listeners/PetListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,11 @@ public void death(MythicMobDeathEvent e) {
if (pet != null) {
if (!pet.isRemoved()) {
pet.despawn(PetDespawnReason.DEATH);
Player owner = Bukkit.getPlayer(pet.getOwner());
if (owner != null) {
Language.REVOKED.sendMessage(owner);
if (pet.getOwner() != null) {
Player owner = Bukkit.getPlayer(pet.getOwner());
if (owner != null) {
Language.REVOKED.sendMessage(owner);
}
}
}
}
Expand Down
Loading

0 comments on commit 4a58e2d

Please sign in to comment.