Skip to content

Commit

Permalink
📦 同步主仓库 (0099a415faa73f0c31c5c9ee2eda6c35f3188b5a)
Browse files Browse the repository at this point in the history
  • Loading branch information
INSide-734 committed Aug 28, 2024
1 parent dcb8d33 commit c899fb3
Show file tree
Hide file tree
Showing 35 changed files with 101 additions and 87 deletions.
6 changes: 3 additions & 3 deletions MMOItems-API/src/main/java/net/Indyuce/mmoitems/MMOItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void onLoad() {
new WorldEditSupport();
getLogger().log(Level.INFO, "挂钩至 WorldEdit");
} catch (Exception exception) {
getLogger().log(Level.WARNING, "无法初始化 WorldEdit 7 支持: ", exception);
getLogger().log(Level.SEVERE, "无法初始化 WorldEdit 7 支持: ", exception);
}
});

Expand Down Expand Up @@ -241,7 +241,7 @@ public void run() {
try {
new MMOItemsRewardTypes().register();
} catch (NullPointerException ignored) {
getLogger().log(Level.WARNING, "无法挂勾到 BossShopPro");
getLogger().log(Level.SEVERE, "无法挂勾到 BossShopPro");
}
}
}).runTaskLater(this, 1L);
Expand Down Expand Up @@ -356,7 +356,7 @@ public void findRpgPlugins() {
}

} catch (Exception exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "无法初始化 RPG 插件兼容性 " + enumPlugin.getName() + ":");
MMOItems.plugin.getLogger().log(Level.SEVERE, "无法初始化 RPG 插件兼容性 " + enumPlugin.getName() + ":");
exception.printStackTrace();
}

Expand Down
13 changes: 6 additions & 7 deletions MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.player.cooldown.CooldownObject;
import io.lumine.mythic.lib.player.modifier.ModifierSource;
import io.lumine.mythic.lib.script.Script;
import io.lumine.mythic.lib.skill.handler.SkillHandler;
import io.lumine.mythic.lib.util.PostLoadAction;
import io.lumine.mythic.lib.util.PreloadedObject;
Expand All @@ -19,6 +18,7 @@
import net.Indyuce.mmoitems.manager.TypeManager;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.Indyuce.mmoitems.util.MMOUtils;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -97,19 +97,16 @@ public class Type implements CooldownObject, PreloadedObject {
* - types of modifiers an item of this type would give
* - the lore format
*/
private Type parent;
private final Type parent;

private UnidentifiedItem unidentifiedTemplate;

private SkillHandler<?> onLeftClick, onRightClick, onAttack, onEntityInteract;

public Script ent;

private boolean meleeAttacks, hideInGame;

/**
* List of stats which can be applied onto an item which has this type. This
* improves performance when generating an item by a significant amount.
* Cached list of stats which can be applied onto an item with this type
*/
private final List<ItemStat> available = new ArrayList<>();

Expand All @@ -132,14 +129,16 @@ public Type(@NotNull String id, @NotNull ModifierSource modifierSource, @NotNull
this.id = UtilityMethods.enumName(id);
this.modifierSource = modifierSource;
this.interactionProvider = interactionProvider;
this.parent = null;
}

/**
* Load custom type from a configuration file
*/
public Type(@NotNull TypeManager manager, @NotNull ConfigurationSection config) {
id = UtilityMethods.enumName(config.getName());
parent = manager.get(config.getString("parent", "").toUpperCase().replace("-", "_").replace(" ", "_"));
Validate.isTrue(config.contains("parent"), "Custom types require a parent type");
parent = manager.getOrThrow(UtilityMethods.enumName(config.getString("parent")));
modifierSource = config.contains("modifier-source") ? ModifierSource.valueOf(UtilityMethods.enumName(config.getString("modifier-source"))) : (parent != null ? parent.modifierSource : ModifierSource.OTHER);
interactionProvider = parent.interactionProvider;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public CraftingStation(String id, FileConfiguration config) {
try {
registerRecipe(loadRecipe(config.getConfigurationSection("recipes." + key)));
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING,
MMOItems.plugin.getLogger().log(Level.SEVERE,
"An issue occurred registering recipe '" + key + "' from crafting station '" + id + "': " + exception.getMessage());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void load(PlayerData data, ConfigurationSection config) {

for (String stationId : config.getKeys(false)) {
if (!MMOItems.plugin.getCrafting().hasStation(stationId)) {
MMOItems.plugin.getLogger().log(Level.WARNING,
MMOItems.plugin.getLogger().log(Level.SEVERE,
"An error occurred while trying to load crafting station recipe data of '" + name + "': "
+ "could not find crafting station with ID '" + stationId
+ "', make sure you backup that player data file before the user logs off.");
Expand All @@ -44,7 +44,7 @@ public void load(PlayerData data, ConfigurationSection config) {
for (String recipeConfigId : config.getConfigurationSection(stationId).getKeys(false)) {
String recipeId = config.getString(stationId + "." + recipeConfigId + ".recipe");
if (recipeId == null || !station.hasRecipe(recipeId)) {
MMOItems.plugin.getLogger().log(Level.WARNING,
MMOItems.plugin.getLogger().log(Level.SEVERE,
"An error occurred while trying to load crafting station recipe data of '" + name + "': "
+ "could not find recipe with ID '" + recipeId
+ "', make sure you backup that player data file before the user logs off.");
Expand All @@ -53,7 +53,7 @@ public void load(PlayerData data, ConfigurationSection config) {

Recipe recipe = station.getRecipe(recipeId);
if (!(recipe instanceof CraftingRecipe)) {
MMOItems.plugin.getLogger().log(Level.WARNING, "An error occurred while trying to load crafting station recipe data of '"
MMOItems.plugin.getLogger().log(Level.SEVERE, "An error occurred while trying to load crafting station recipe data of '"
+ name + "': " + "recipe '" + recipe.getId() + "' is not a CRAFTING recipe.");
continue;
}
Expand Down Expand Up @@ -110,9 +110,12 @@ public void remove(QueueItem item) {
final int index = crafts.indexOf(item);
Validate.isTrue(index >= 0, "Could not find item in queue");
crafts.remove(index);
final long remaining = item.getLeft();

// Time elapsed for that item
final long gain = Math.min(item.getLeft(), (long) (1000 * item.getRecipe().getCraftingTime()));

for (int j = index; j < crafts.size(); j++)
crafts.get(j).removeDelay(remaining);
crafts.get(j).removeDelay(gain);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public boolean isMet(PlayerData data) {
throw new RuntimeException("Comparator not recognized");
}
} catch (RuntimeException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not evaluate placeholder condition expression: " + exception.getMessage());
MMOItems.plugin.getLogger().log(Level.SEVERE, "Could not evaluate placeholder condition expression: " + exception.getMessage());
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public DropTable(ConfigurationSection config) {
subtables.put(key, new Subtable(config.getConfigurationSection(key)));

} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not read subtable '" + key + "' from drop table '" + config.getName() + "': " + exception.getMessage());
MMOItems.plugin.getLogger().log(Level.SEVERE, "Could not read subtable '" + key + "' from drop table '" + config.getName() + "': " + exception.getMessage());
}

Validate.notEmpty(subtablesList, "Your droptable must contain at least one subtable");
Expand All @@ -51,7 +51,7 @@ public List<ItemStack> read(@Nullable PlayerData player, boolean silkTouch) {
if (dropItem.rollDrop()) {
ItemStack drop = dropItem.getItem(player);
if (drop == null)
MMOItems.plugin.getLogger().log(Level.WARNING, "Couldn't read the subtable item " + dropItem.getKey());
MMOItems.plugin.getLogger().log(Level.SEVERE, "Couldn't read the subtable item " + dropItem.getKey());
else
dropped.add(drop);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Random;

Expand Down Expand Up @@ -116,8 +117,9 @@ private void dispatchCommand(String parsed, boolean console, boolean op) {
}

@Deprecated
@Nullable
public static UseItem getItem(Player player, NBTItem item, String type) {
return getItem(player, item, Type.get(type));
return Type.get(type).toUseItem(player, item);
}

@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,17 @@ public NBTItem buildNBT(boolean forDisplay) {
* Enchantment data must never be clear and lack history. This is
* the basis for when an item is 'old'
*/
if (!builtMMOItem.hasData(ItemStats.ENCHANTS)) {
builtMMOItem.setData(ItemStats.ENCHANTS, ItemStats.ENCHANTS.getClearStatData());
}
builtMMOItem.computeData(ItemStats.ENCHANTS);
builtMMOItem.computeStatHistory(ItemStats.ENCHANTS);
//GEM// else {MMOItems.log("\u00a73 -?- \u00a77Apparently found enchantment data \u00a7b" + (mmoitem.getData(ItemStats.ENCHANTS) == null ? "null" : ((EnchantListData) mmoitem.getData(ItemStats.ENCHANTS)).getEnchants().size())); }

/*
* Similar to how enchantments are saved because they can be modified
* through non-MMOItems supported sources, the name can be changed in
* an anvil, so the very original name must be saved.
*/
if (!builtMMOItem.hasData(ItemStats.NAME))
builtMMOItem.setData(ItemStats.NAME, ItemStats.NAME.getClearStatData());
builtMMOItem.computeStatHistory(ItemStats.NAME); // Ignore result
builtMMOItem.computeData(ItemStats.NAME);
builtMMOItem.computeStatHistory(ItemStats.NAME);

// For every stat within this item
for (ItemStat stat : builtMMOItem.getStats())
Expand Down Expand Up @@ -194,7 +192,7 @@ public NBTItem buildNBT(boolean forDisplay) {
} catch (IllegalArgumentException | NullPointerException exception) {

// That
MMOItems.print(Level.WARNING, "An error occurred while trying to generate item '$f{0}$b' with stat '$f{1}$b': {2}",
MMOItems.print(Level.SEVERE, "An error occurred while trying to generate item '$f{0}$b' with stat '$f{1}$b': {2}",
"ItemStackBuilder", builtMMOItem.getId(), stat.getId(), exception.getMessage());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public LiveMMOItem(NBTItem item) {

// Some unknown error happened
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING,
MMOItems.plugin.getLogger().log(Level.SEVERE,
ChatColor.GRAY + "Could not load stat '"
+ ChatColor.GOLD + stat.getId() + ChatColor.GRAY + "'item data from '"
+ ChatColor.RED + getId() + ChatColor.GRAY + "': "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public boolean hasData(@NotNull ItemStat stat) {
} catch (RuntimeException exception) {

// Log a warning
MMOItems.plugin.getLogger().log(Level.WARNING,
MMOItems.plugin.getLogger().log(Level.SEVERE,
ChatColor.GRAY + "Could not load stat '"
+ ChatColor.GOLD + stat.getId() + ChatColor.GRAY + "'item data from '"
+ ChatColor.RED + getId() + ChatColor.GRAY + "': "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class ModifierNode implements PreloadedObject {
child.getPostLoadAction().performAction();
ModifierNode.this.children.add(child);
} catch (RuntimeException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load parent modifier node '" + key + "' of modifier group '" + getId() + "': " + exception.getMessage());
MMOItems.plugin.getLogger().log(Level.SEVERE, "Could not load parent modifier node '" + key + "' of modifier group '" + getId() + "': " + exception.getMessage());
}

// Post-load stat data
Expand All @@ -69,7 +69,7 @@ public class ModifierNode implements PreloadedObject {
Validate.notNull(stat, "Could not find stat with ID '" + statId + "'");
ModifierNode.this.data.put(stat, stat.whenInitialized(statSection.get(key)));
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "An error occurred while trying to load modifier node " + getId() + ": " + exception.getMessage());
MMOItems.plugin.getLogger().log(Level.SEVERE, "An error occurred while trying to load modifier node " + getId() + ": " + exception.getMessage());
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private ItemStack stripItemData(ItemStack oldItem) {
final Object oldProfile = MythicLib.plugin.getVersion().getWrapper().getProfile((SkullMeta) oldItem.getItemMeta());
MythicLib.plugin.getVersion().getWrapper().setProfile((SkullMeta) newItemMeta, oldProfile);
} catch (RuntimeException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not set skull texture on stripItemData method in the NoClipItem class. Please report this issue!");
MMOItems.plugin.getLogger().log(Level.SEVERE, "Could not set skull texture on stripItemData method in the NoClipItem class. Please report this issue!");
}

// Copy Leather colors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.Indyuce.mmoitems.command.mmoitems;

import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.util.SmartGive;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
Expand Down Expand Up @@ -74,8 +75,11 @@ public CommandResult execute(CommandSender sender, String[] args) {
mmoitem.setData(ItemStats.SOULBOUND, new SoulboundData(target, 1));

// generate item
ItemStack item = random.nextDouble() < unidentify ? type.getUnidentifiedTemplate().newBuilder(mmoitem.newBuilder().buildNBT()).build()
: mmoitem.newBuilder().build();
ItemStack item = mmoitem.newBuilder().build();

// roll unidentification
if (random.nextDouble() < unidentify)
item = type.getUnidentifiedTemplate().newBuilder(NBTItem.get(item)).build();

// set amount
Validate.isTrue(item != null && item.getType() != Material.AIR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public CommandResult execute(CommandSender sender, String[] args) {
}

Player player = (Player) sender;
NBTItem item = MythicLib.plugin.getVersion().getWrapper().getNBTItem(player.getInventory().getItemInMainHand());
NBTItem item = NBTItem.get(player.getInventory().getItemInMainHand());
if (item.getType() == null) {
sender.sendMessage(MMOItems.plugin.getPrefix() + "Couldn't unidentify the item you are holding.");
return CommandResult.FAILURE;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.Indyuce.mmoitems.comp.mmocore.load;

import io.lumine.mythic.lib.api.item.NBTItem;
import org.apache.commons.lang.Validate;
import org.bukkit.inventory.ItemStack;

Expand Down Expand Up @@ -43,13 +44,15 @@ public MMOItem rollMMOItem(MMOItemTemplate template, RPGPlayer rpgPlayer) {
: template.hasOption(TemplateOption.LEVEL_ITEM) ? MMOItems.plugin.getTemplates().rollLevel(rpgPlayer.getLevel()) : 0;
final ItemTier itemTier = tier != null ? tier : template.hasOption(TemplateOption.TIERED) ? MMOItems.plugin.getTemplates().rollTier() : null;
return new MMOItemBuilder(template, itemLevel, itemTier).build();
}

@NotNull
public ItemStack rollUnidentification(MMOItem mmoitem) {
return random.nextDouble() < unidentified ? mmoitem.getType().getUnidentifiedTemplate().newBuilder(mmoitem.newBuilder().buildNBT()).build()
: mmoitem.newBuilder().build();
}
}

@NotNull
public ItemStack rollUnidentification(MMOItem mmoitem) {
ItemStack item = mmoitem.newBuilder().build();
if (random.nextDouble() < unidentified)
item = mmoitem.getType().getUnidentifiedTemplate().newBuilder(NBTItem.get(item)).build();
return item;
}

public boolean rollSoulbound() {
return random.nextDouble() < soulbound;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void reload() {
eastIds.contains(id), southIds.contains(id), northIds.contains(id));
register(new CustomBlock(state, mmoitem));
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load custom block '" + id + "': " + exception.getMessage());
MMOItems.plugin.getLogger().log(Level.SEVERE, "Could not load custom block '" + id + "': " + exception.getMessage());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ public ConfigManager() {
}
jarFile.close();
} catch (IOException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load default crafting stations.");
MMOItems.plugin.getLogger().log(Level.SEVERE, "Could not load default crafting stations.");
}
} else MMOItems.plugin.getLogger().log(Level.WARNING, "Could not create directory!");
} else MMOItems.plugin.getLogger().log(Level.SEVERE, "Could not create directory!");
}

// Load files with default configuration
Expand Down Expand Up @@ -208,7 +208,7 @@ public void reload() {
defaultItemCapacity = new NumericStatFormula(MMOItems.plugin.getConfig().getConfigurationSection("default-item-capacity"));
} catch (IllegalArgumentException exception) {
defaultItemCapacity = new NumericStatFormula(5, .05, .1, .3);
MMOItems.plugin.getLogger().log(Level.WARNING,
MMOItems.plugin.getLogger().log(Level.SEVERE,
"An error occurred while trying to load default capacity formula for the item generator, using default: "
+ exception.getMessage());
}
Expand Down Expand Up @@ -296,7 +296,7 @@ private void mkdir(String path) {
File folder = new File(MMOItems.plugin.getDataFolder() + "/" + path);
if (!folder.exists())
if (!folder.mkdir())
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not create directory!");
MMOItems.plugin.getLogger().log(Level.SEVERE, "Could not create directory!");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ public void reload() {
CraftingStation station = new CraftingStation(file.getName().substring(0, file.getName().length() - 4), YamlConfiguration.loadConfiguration(file));
stations.put(station.getId(), station);
} catch (IllegalArgumentException|NullPointerException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load station '" + file.getName() + "': " + exception.getMessage());
MMOItems.plugin.getLogger().log(Level.SEVERE, "Could not load station '" + file.getName() + "': " + exception.getMessage());
}

for (CraftingStation station : stations.values())
try {
station.getPostLoadAction().performAction();
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING,
MMOItems.plugin.getLogger().log(Level.SEVERE,
"Could not post-load station '" + station.getId() + "': " + exception.getMessage());
}
}
Expand Down
Loading

0 comments on commit c899fb3

Please sign in to comment.