Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Rothes committed Jul 16, 2023
1 parent e24ce97 commit 4759d9a
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 8 deletions.
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repositories {
}

dependencies {
compileOnly(files(projectDir.path + '/libs/MMOItems-6.9.4.jar'))
// compileOnly(files(projectDir.path + '/libs/MMOItems-6.9.4.jar'))
compileOnly 'org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT'
compileOnly "io.lumine:MythicLib-dist:1.5.2-SNAPSHOT"
compileOnly "net.Indyuce:MMOItems-API:6.9.2-SNAPSHOT"
Expand All @@ -36,4 +36,6 @@ shadowJar {

test {
useJUnitPlatform()
}
}
sourceCompatibility = JavaVersion.VERSION_14
targetCompatibility = JavaVersion.VERSION_14
134 changes: 129 additions & 5 deletions src/main/java/io/github/rothes/mmoitemstrim/Listeners.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package io.github.rothes.mmoitemstrim;

import de.tr7zw.changeme.nbtapi.NBTItem;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.item.mmoitem.LiveMMOItem;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.stat.data.GemSocketsData;
import net.Indyuce.mmoitems.stat.data.GemstoneData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.event.EventHandler;
Expand All @@ -15,6 +22,8 @@
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.trim.TrimPattern;

import java.util.UUID;

public class Listeners implements Listener {

@EventHandler
Expand All @@ -23,7 +32,7 @@ public void onTrim(InventoryClickEvent e) {
if (inv instanceof SmithingInventory) {
SmithingInventory inventory = (SmithingInventory) inv;
ItemStack result = inventory.getResult();
if (result == null) {
if (result == null || result.getType() == Material.AIR) {
return;
}
ItemStack converted = convertMmoItem(result);
Expand Down Expand Up @@ -78,11 +87,126 @@ private ItemStack convertMmoItem(ItemStack itemStack) {
//// nbtItem = nbtItem.addTag(new ItemTag("MMOITEMS_ITEM_TYPE", type.getName()), new ItemTag("MMOITEMS_ITEM_ID", id));
// return nbtItem.toItem();

ItemStack mmoItem = MMOItems.plugin.getItem(type, id);
NBTItem itemNbt = new NBTItem(mmoItem);
// MMOItem mmoItem = MMOItems.plugin.getMMOItem(type, id);
// NBTItem itemNbt = new NBTItem(mmoItem);
// NBTItem nbtItem = new NBTItem(itemStack);
// nbtItem.mergeCompound(itemNbt);


MMOItem mmoItem = MMOItems.plugin.getMMOItem(type, id);
if (mmoItem == null) {
return itemStack;
}

NBTItem nbtItem = new NBTItem(itemStack);
nbtItem.mergeCompound(itemNbt);
return nbtItem.getItem();
if (nbtItem.hasTag("MMOITEMSTRIM_APPLIED")) {
return itemStack;
}

String thisType = nbtItem.getString("MMOITEMS_ITEM_TYPE");
String thisId = nbtItem.getString("MMOITEMS_ITEM_ID");
if (MMOItems.plugin.getTypes().has(thisType) && thisId != null) {
LiveMMOItem liveMMOItem = new LiveMMOItem(itemStack);
GemSocketsData data = (GemSocketsData) liveMMOItem.getData(ItemStats.GEM_SOCKETS);
String emptySocket = data == null ? null : data.getEmptySocket(liveMMOItem.getNBT().getString(ItemStats.GEM_COLOR.getNBTPath()));
GemstoneData gemstoneData = emptySocket == null ? null : new GemstoneData(liveMMOItem, emptySocket);
UUID uuid = gemstoneData == null ? null : gemstoneData.getHistoricUUID();

for (ItemStat<?, ?> stat : liveMMOItem.getStats()) {
mmoItem.mergeData(stat, liveMMOItem.getData(stat), uuid);
}

itemStack = mmoItem.newBuilder().build();
nbtItem = new NBTItem(itemStack);
} else {
NBTItem itemNbt = new NBTItem(mmoItem.newBuilder().build());
nbtItem.mergeCompound(itemNbt);
}
nbtItem.setBoolean("MMOITEMSTRIM_APPLIED", true);
nbtItem.applyNBT(itemStack);
return itemStack;
}

// private void merge(ItemStack itemStack, MMOItem mmoitem) {
// NBTItem miNbt = new NBTItem(mmoitem.newBuilder().build());
// NBTItem nbtItem = new NBTItem(itemStack);
// merge(nbtItem, miNbt);
// nbtItem.applyNBT(itemStack);
// }

// private void merge(NBTCompound target, NBTCompound merge) {
// for (String key : merge.getKeys()) {
// NBTType keyType = merge.getType(key);
// switch (keyType) {
// case NBTTagEnd -> {}
// case NBTTagByte -> {
// Byte get = merge.getByte(key);
// Byte t = target.getByte(key);
// if (t != null) {
// target.setByte(key, (byte) (t + get));
// } else {
// target.setByte(key, get);
// }
// }
// case NBTTagShort -> {
// Short get = merge.getShort(key);
// Short t = target.getShort(key);
// if (t != null) {
// target.setShort(key, (short) (t + get));
// } else {
// target.setShort(key, get);
// }
// }
// case NBTTagInt -> {
// Integer get = merge.getInteger(key);
// Integer t = target.getInteger(key);
// if (t != null) {
// target.setInteger(key, t + get);
// } else {
// target.setInteger(key, get);
// }
// }
// case NBTTagLong -> {
// Long get = merge.getLong(key);
// Long t = target.getLong(key);
// if (t != null) {
// target.setLong(key, t + get);
// } else {
// target.setLong(key, get);
// }
// }
// case NBTTagFloat -> {
// Float get = merge.getFloat(key);
// Float t = target.getFloat(key);
// if (t != null) {
// target.setFloat(key, t + get);
// } else {
// target.setFloat(key, get);
// }
// }
// case NBTTagDouble -> {
// Double get = merge.getDouble(key);
// Double t = target.getDouble(key);
// if (t != null) {
// target.setDouble(key, t + get);
// } else {
// target.setDouble(key, get);
// }
// }
// case NBTTagList -> target.getCompoundList(key).addAll(merge.getCompoundList(key));
// case NBTTagString -> target.setString(key, merge.getString(key));
// case NBTTagIntArray -> target.setIntArray(key, merge.getIntArray(key));
// case NBTTagByteArray -> target.setByteArray(key, merge.getByteArray(key));
// case NBTTagCompound -> {
// if (target.hasTag(key)) {
// merge(target.getCompound(key), merge.getCompound(key));
// } else {
// target.addCompound(key).mergeCompound(merge.getCompound(key));
// }
// }
// default -> throw new AssertionError();
// }
// }
// }

}
26 changes: 26 additions & 0 deletions src/main/java/io/github/rothes/mmoitemstrim/MMOItemsTrim.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package io.github.rothes.mmoitemstrim;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.Arrays;
import java.util.List;

public class MMOItemsTrim extends JavaPlugin {

public static ConfigManager configManager;
Expand All @@ -11,6 +17,26 @@ public class MMOItemsTrim extends JavaPlugin {
public void onEnable() {
configManager = new ConfigManager(this);
Bukkit.getPluginManager().registerEvents(new Listeners(), this);
PluginCommand cmd = Bukkit.getPluginCommand("mmoitemstrim");
cmd.setExecutor(this);
cmd.setTabCompleter(this);
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender.isOp() && args.length == 1 && args[0].equalsIgnoreCase("reload")) {
configManager = new ConfigManager(this);
sender.sendMessage("§a配置文件已重载");
}
return true;
}

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
if (sender.isOp()) {
return Arrays.asList("reload");
}
return null;
}

}
5 changes: 4 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ version: 1.0
api-version: '1.20'
depend:
- MMOItems
- MythicLib
- MythicLib
commands:
mmoitemstrim:
permission: op

0 comments on commit 4759d9a

Please sign in to comment.