mirror of
https://github.com/songoda/EpicEnchants.git
synced 2025-01-09 09:57:40 +01:00
Merge branch 'development'
This commit is contained in:
commit
657aa3856e
4
pom.xml
4
pom.xml
@ -2,7 +2,7 @@
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>EpicEnchants</artifactId>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>1.1.6</version>
|
||||
<version>1.1.7</version>
|
||||
<build>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<finalName>EpicEnchants-${project.version}</finalName>
|
||||
@ -94,7 +94,7 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.15</version>
|
||||
<version>1.16.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.mrmicky</groupId>
|
||||
|
BIN
src/main/java/com/songoda/epicenchants/.DS_Store
vendored
Normal file
BIN
src/main/java/com/songoda/epicenchants/.DS_Store
vendored
Normal file
Binary file not shown.
@ -2,11 +2,12 @@ package com.songoda.epicenchants;
|
||||
|
||||
import com.songoda.core.SongodaCore;
|
||||
import com.songoda.core.SongodaPlugin;
|
||||
import com.songoda.core.commands.CommandManager;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.configuration.Config;
|
||||
import com.songoda.core.gui.GuiManager;
|
||||
import com.songoda.core.hooks.EconomyManager;
|
||||
import com.songoda.epicenchants.command.CommandManager;
|
||||
import com.songoda.epicenchants.command.commands.*;
|
||||
import com.songoda.epicenchants.listeners.ArmorListener;
|
||||
import com.songoda.epicenchants.listeners.EntityListener;
|
||||
import com.songoda.epicenchants.listeners.PlayerListener;
|
||||
@ -58,6 +59,21 @@ public class EpicEnchants extends SongodaPlugin {
|
||||
// Run Songoda Updater
|
||||
SongodaCore.registerPlugin(this, 67, CompatibleMaterial.DIAMOND_SWORD);
|
||||
|
||||
// setup commands
|
||||
this.commandManager = new com.songoda.core.commands.CommandManager(this);
|
||||
this.commandManager.addMainCommand("ee")
|
||||
.addSubCommand(new CommandReload(this))
|
||||
.addSubCommand(new CommandAlchemist(this))
|
||||
.addSubCommand(new CommandApply(this))
|
||||
.addSubCommand(new CommandEnchanter(this))
|
||||
.addSubCommand(new CommandGiveBook(this))
|
||||
.addSubCommand(new CommandGiveItemDust(this))
|
||||
.addSubCommand(new CommandGiveRandomBook(this))
|
||||
.addSubCommand(new CommandGiveScroll(this))
|
||||
.addSubCommand(new CommandList(this))
|
||||
.addSubCommand(new CommandSettings(this))
|
||||
.addSubCommand(new CommandTinkerer(this));
|
||||
|
||||
EconomyManager.load();
|
||||
|
||||
// Setup Config
|
||||
@ -75,7 +91,7 @@ public class EpicEnchants extends SongodaPlugin {
|
||||
this.specialItems = new SpecialItems(this);
|
||||
this.commandManager = new CommandManager(this);
|
||||
this.hookManager = new HookManager();
|
||||
this.itemGroup = new ItemGroup(this);
|
||||
this.itemGroup = new ItemGroup();
|
||||
|
||||
groupManager.loadGroups();
|
||||
enchantManager.loadEnchants();
|
||||
|
@ -1,71 +0,0 @@
|
||||
package com.songoda.epicenchants.command;
|
||||
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractCommand {
|
||||
|
||||
private final boolean noConsole;
|
||||
private AbstractCommand parent = null;
|
||||
private boolean hasArgs = false;
|
||||
private String command;
|
||||
|
||||
private List<String> subCommand = new ArrayList<>();
|
||||
|
||||
protected AbstractCommand(AbstractCommand parent, boolean noConsole, String... command) {
|
||||
if (parent != null) {
|
||||
this.subCommand = Arrays.asList(command);
|
||||
} else {
|
||||
this.command = Arrays.asList(command).get(0);
|
||||
}
|
||||
this.parent = parent;
|
||||
this.noConsole = noConsole;
|
||||
}
|
||||
|
||||
protected AbstractCommand(boolean noConsole, boolean hasArgs, String... command) {
|
||||
this.command = Arrays.asList(command).get(0);
|
||||
|
||||
this.hasArgs = hasArgs;
|
||||
this.noConsole = noConsole;
|
||||
}
|
||||
|
||||
public AbstractCommand getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public List<String> getSubCommand() {
|
||||
return subCommand;
|
||||
}
|
||||
|
||||
public void addSubCommand(String command) {
|
||||
subCommand.add(command);
|
||||
}
|
||||
|
||||
protected abstract ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args);
|
||||
|
||||
protected abstract List<String> onTab(EpicEnchants instance, CommandSender sender, String... args);
|
||||
|
||||
public abstract String getPermissionNode();
|
||||
|
||||
public abstract String getSyntax();
|
||||
|
||||
public abstract String getDescription();
|
||||
|
||||
public boolean hasArgs() {
|
||||
return hasArgs;
|
||||
}
|
||||
|
||||
public boolean isNoConsole() {
|
||||
return noConsole;
|
||||
}
|
||||
|
||||
public enum ReturnType {SUCCESS, FAILURE, SYNTAX_ERROR}
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
package com.songoda.epicenchants.command;
|
||||
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.command.commands.*;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandManager implements CommandExecutor {
|
||||
|
||||
private static final List<AbstractCommand> commands = new ArrayList<>();
|
||||
private EpicEnchants plugin;
|
||||
private TabManager tabManager;
|
||||
|
||||
public CommandManager(EpicEnchants plugin) {
|
||||
this.plugin = plugin;
|
||||
this.tabManager = new TabManager(this);
|
||||
|
||||
plugin.getCommand("EpicEnchants").setExecutor(this);
|
||||
|
||||
AbstractCommand commandEpicEnchants = addCommand(new CommandEpicEnchants());
|
||||
|
||||
addCommand(new CommandSettings(commandEpicEnchants));
|
||||
addCommand(new CommandReload(commandEpicEnchants));
|
||||
addCommand(new CommandApply(commandEpicEnchants));
|
||||
addCommand(new CommandList(commandEpicEnchants));
|
||||
addCommand(new CommandGiveBook(commandEpicEnchants));
|
||||
addCommand(new CommandGiveRandomBook(commandEpicEnchants));
|
||||
addCommand(new CommandGiveItemDust(commandEpicEnchants));
|
||||
addCommand(new CommandGiveScroll(commandEpicEnchants));
|
||||
addCommand(new CommandAlchemist(commandEpicEnchants));
|
||||
addCommand(new CommandEnchanter(commandEpicEnchants));
|
||||
addCommand(new CommandTinkerer(commandEpicEnchants));
|
||||
|
||||
for (AbstractCommand abstractCommand : commands) {
|
||||
if (abstractCommand.getParent() != null) continue;
|
||||
plugin.getCommand(abstractCommand.getCommand()).setTabCompleter(tabManager);
|
||||
}
|
||||
}
|
||||
|
||||
private AbstractCommand addCommand(AbstractCommand abstractCommand) {
|
||||
commands.add(abstractCommand);
|
||||
return abstractCommand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
|
||||
for (AbstractCommand abstractCommand : commands) {
|
||||
if (abstractCommand.getCommand() != null && abstractCommand.getCommand().equalsIgnoreCase(command.getName().toLowerCase())) {
|
||||
if (strings.length == 0 || abstractCommand.hasArgs()) {
|
||||
processRequirements(abstractCommand, commandSender, strings);
|
||||
return true;
|
||||
}
|
||||
} else if (strings.length != 0 && abstractCommand.getParent() != null && abstractCommand.getParent().getCommand().equalsIgnoreCase(command.getName())) {
|
||||
String cmd = strings[0];
|
||||
String cmd2 = strings.length >= 2 ? String.join(" ", strings[0], strings[1]) : null;
|
||||
for (String cmds : abstractCommand.getSubCommand()) {
|
||||
if (cmd.equalsIgnoreCase(cmds) || (cmd2 != null && cmd2.equalsIgnoreCase(cmds))) {
|
||||
processRequirements(abstractCommand, commandSender, strings);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
plugin.getLocale().newMessage("&7The command you entered does not exist or is spelt incorrectly.").sendPrefixedMessage(commandSender);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void processRequirements(AbstractCommand command, CommandSender sender, String[] strings) {
|
||||
if (!(sender instanceof Player) && command.isNoConsole()) {
|
||||
sender.sendMessage("You must be a player to use this commands.");
|
||||
return;
|
||||
}
|
||||
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
|
||||
AbstractCommand.ReturnType returnType = command.runCommand(plugin, sender, strings);
|
||||
if (returnType == AbstractCommand.ReturnType.SYNTAX_ERROR) {
|
||||
plugin.getLocale().newMessage("&cInvalid Syntax!").sendPrefixedMessage(sender);
|
||||
plugin.getLocale().newMessage("&7The valid syntax is: &6" + command.getSyntax() + "&7.").sendPrefixedMessage(sender);
|
||||
}
|
||||
return;
|
||||
}
|
||||
plugin.getLocale().getMessage("event.general.nopermission").sendPrefixedMessage(sender);
|
||||
}
|
||||
|
||||
public List<AbstractCommand> getCommands() {
|
||||
return Collections.unmodifiableList(commands);
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package com.songoda.epicenchants.command;
|
||||
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TabManager implements TabCompleter {
|
||||
|
||||
private final CommandManager commandManager;
|
||||
|
||||
TabManager(CommandManager commandManager) {
|
||||
this.commandManager = commandManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] strings) {
|
||||
for (AbstractCommand abstractCommand : commandManager.getCommands()) {
|
||||
if (abstractCommand.getCommand() != null && abstractCommand.getCommand().equalsIgnoreCase(command.getName().toLowerCase())) {
|
||||
if (strings.length == 1) {
|
||||
List<String> subs = new ArrayList<>();
|
||||
for (AbstractCommand ac : commandManager.getCommands()) {
|
||||
if (ac.getSubCommand() == null) continue;
|
||||
subs.addAll(ac.getSubCommand());
|
||||
}
|
||||
subs.removeIf(s -> !s.toLowerCase().startsWith(strings[0].toLowerCase()));
|
||||
return subs;
|
||||
}
|
||||
} else if (strings.length != 0 && abstractCommand.getParent() != null && abstractCommand.getParent().getCommand().equalsIgnoreCase(command.getName().toLowerCase())) {
|
||||
String cmd = strings[0];
|
||||
String cmd2 = strings.length >= 2 ? String.join(" ", strings[0], strings[1]) : null;
|
||||
for (String cmds : abstractCommand.getSubCommand()) {
|
||||
if (cmd.equalsIgnoreCase(cmds) || (cmd2 != null && cmd2.equalsIgnoreCase(cmds))) {
|
||||
List<String> list = abstractCommand.onTab(EpicEnchants.getInstance(), sender, strings);
|
||||
String str = strings[strings.length - 1];
|
||||
if (list != null && str != null && str.length() >= 1) {
|
||||
try {
|
||||
list.removeIf(s -> !s.toLowerCase().startsWith(str.toLowerCase()));
|
||||
} catch (UnsupportedOperationException ignored) {
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package com.songoda.epicenchants.command.commands;
|
||||
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.command.AbstractCommand;
|
||||
import com.songoda.epicenchants.utils.Methods;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandEpicEnchants extends AbstractCommand {
|
||||
|
||||
public CommandEpicEnchants() {
|
||||
super(null, false, "EpicEnchants");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractCommand.ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
sender.sendMessage("");
|
||||
instance.getLocale().newMessage("&7Version " + instance.getDescription().getVersion()
|
||||
+ " Created with <3 by &5&l&oSongoda").sendPrefixedMessage(sender);
|
||||
|
||||
for (AbstractCommand command : instance.getCommandManager().getCommands()) {
|
||||
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
|
||||
sender.sendMessage(Methods.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription()));
|
||||
}
|
||||
}
|
||||
sender.sendMessage("");
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/EpicEnchants";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Displays this page.";
|
||||
}
|
||||
}
|
@ -1,9 +1,8 @@
|
||||
package com.songoda.epicenchants.command.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.command.AbstractCommand;
|
||||
import com.songoda.epicenchants.menus.AlchemistMenu;
|
||||
import com.songoda.epicenchants.menus.TinkererMenu;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -11,19 +10,23 @@ import java.util.List;
|
||||
|
||||
public class CommandAlchemist extends AbstractCommand {
|
||||
|
||||
public CommandAlchemist(AbstractCommand parent) {
|
||||
super(parent, true, "alchemist");
|
||||
private final EpicEnchants plugin;
|
||||
|
||||
public CommandAlchemist(EpicEnchants plugin) {
|
||||
super(true, "alchemist");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
Player player = (Player)sender;
|
||||
new AlchemistMenu(instance, instance.getFileManager().getConfiguration("menus/alchemist-menu")).open(player);
|
||||
new AlchemistMenu(plugin, plugin.getFileManager().getConfiguration("menus/alchemist-menu")).open(player);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -34,7 +37,7 @@ public class CommandAlchemist extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ee alchemist";
|
||||
return "alchemist";
|
||||
}
|
||||
|
||||
@Override
|
@ -1,12 +1,11 @@
|
||||
package com.songoda.epicenchants.command.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epicenchants.CommandCommons;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.command.AbstractCommand;
|
||||
import com.songoda.epicenchants.enums.EnchantResult;
|
||||
import com.songoda.epicenchants.objects.Enchant;
|
||||
import com.songoda.epicenchants.utils.Tuple;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -21,47 +20,50 @@ import static com.songoda.epicenchants.utils.single.GeneralUtils.getMessageFromR
|
||||
|
||||
public class CommandApply extends AbstractCommand {
|
||||
|
||||
public CommandApply(AbstractCommand parent) {
|
||||
super(parent, true, "apply");
|
||||
private final EpicEnchants plugin;
|
||||
|
||||
public CommandApply(EpicEnchants plugin) {
|
||||
super(true, "apply");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
//ee apply [enchant] [level] <success-rate> <destroy-rate>
|
||||
//apply [enchant] [level] <success-rate> <destroy-rate>
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
if (args.length < 3 || args.length > 5)
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length < 2 || args.length > 4)
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
Optional<Enchant> optionalEnchant = instance.getEnchantManager().getValue(args[1].replaceAll("_", " "));
|
||||
Optional<Enchant> optionalEnchant = plugin.getEnchantManager().getValue(args[0].replaceAll("_", " "));
|
||||
|
||||
if (!optionalEnchant.isPresent()) {
|
||||
instance.getLocale().newMessage("&cNo enchants exist with that name...").sendPrefixedMessage(sender);
|
||||
plugin.getLocale().newMessage("&cNo enchants exist with that name...").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
if (!CommandCommons.isInt(args[2], sender))
|
||||
if (!CommandCommons.isInt(args[1], sender))
|
||||
return ReturnType.FAILURE;
|
||||
|
||||
int successRate = 100;
|
||||
int destroyRate = 0;
|
||||
|
||||
if (args.length > 2) {
|
||||
if (!CommandCommons.isInt(args[2], sender))
|
||||
return ReturnType.FAILURE;
|
||||
successRate = Integer.parseInt(args[2]);
|
||||
}
|
||||
|
||||
if (args.length > 3) {
|
||||
if (!CommandCommons.isInt(args[3], sender))
|
||||
return ReturnType.FAILURE;
|
||||
successRate = Integer.parseInt(args[3]);
|
||||
}
|
||||
|
||||
if (args.length > 4) {
|
||||
if (!CommandCommons.isInt(args[4], sender))
|
||||
return ReturnType.FAILURE;
|
||||
destroyRate = Integer.parseInt(args[4]);
|
||||
destroyRate = Integer.parseInt(args[3]);
|
||||
}
|
||||
Enchant enchant = optionalEnchant.get();
|
||||
int level = Integer.parseInt(args[2]);
|
||||
int level = Integer.parseInt(args[1]);
|
||||
Player player = (Player) sender;
|
||||
|
||||
if (!enchant.getItemWhitelist().contains(player.getItemInHand().getType())) {
|
||||
System.out.println("List = " + enchant.getItemWhitelist());
|
||||
instance.getLocale().getMessage("command.apply.invaliditem")
|
||||
plugin.getLocale().getMessage("command.apply.invaliditem")
|
||||
.processPlaceholder("enchant", enchant.getIdentifier())
|
||||
.sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
@ -69,10 +71,10 @@ public class CommandApply extends AbstractCommand {
|
||||
|
||||
int slot = player.getInventory().getHeldItemSlot();
|
||||
ItemStack before = player.getItemInHand();
|
||||
Tuple<ItemStack, EnchantResult> result = instance.getEnchantUtils().apply(before, enchant, level,
|
||||
Tuple<ItemStack, EnchantResult> result = plugin.getEnchantUtils().apply(before, enchant, level,
|
||||
successRate, destroyRate);
|
||||
|
||||
instance.getLocale().getMessage(getMessageFromResult(result.getRight()))
|
||||
plugin.getLocale().getMessage(getMessageFromResult(result.getRight()))
|
||||
.processPlaceholder("enchant", enchant.getIdentifier())
|
||||
.sendPrefixedMessage(player);
|
||||
|
||||
@ -86,12 +88,12 @@ public class CommandApply extends AbstractCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
if (args.length == 2) {
|
||||
return instance.getEnchantManager().getValues()
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
if (args.length == 1) {
|
||||
return plugin.getEnchantManager().getValues()
|
||||
.stream().map(Enchant::getIdentifier).collect(Collectors.toList());
|
||||
} else if (args.length == 3) {
|
||||
Enchant enchant = instance.getEnchantManager().getValues()
|
||||
} else if (args.length == 2) {
|
||||
Enchant enchant = plugin.getEnchantManager().getValues()
|
||||
.stream().findFirst().orElse(null);
|
||||
List<String> levels = new ArrayList<>();
|
||||
if (enchant != null) {
|
||||
@ -99,7 +101,7 @@ public class CommandApply extends AbstractCommand {
|
||||
levels.add(String.valueOf(i));
|
||||
}
|
||||
return levels;
|
||||
} else if (args.length == 4 || args.length == 5) {
|
||||
} else if (args.length == 3 || args.length == 4) {
|
||||
List<String> rates = new ArrayList<>();
|
||||
for (int i = 1; i <= 100; i ++)
|
||||
rates.add(String.valueOf(i));
|
||||
@ -115,7 +117,7 @@ public class CommandApply extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ee apply <enchant> <level> [success-rate] [destroy-rate]";
|
||||
return "apply <enchant> <level> [success-rate] [destroy-rate]";
|
||||
}
|
||||
|
||||
@Override
|
@ -1,7 +1,7 @@
|
||||
package com.songoda.epicenchants.command.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.command.AbstractCommand;
|
||||
import com.songoda.epicenchants.menus.EnchanterMenu;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -10,19 +10,22 @@ import java.util.List;
|
||||
|
||||
public class CommandEnchanter extends AbstractCommand {
|
||||
|
||||
public CommandEnchanter(AbstractCommand parent) {
|
||||
super(parent, true, "enchanter");
|
||||
private final EpicEnchants plugin;
|
||||
|
||||
public CommandEnchanter(EpicEnchants plugin) {
|
||||
super(true, "enchanter");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
Player player = (Player)sender;
|
||||
new EnchanterMenu(instance, instance.getFileManager().getConfiguration("menus/enchanter-menu"), player).open(player);
|
||||
new EnchanterMenu(plugin, plugin.getFileManager().getConfiguration("menus/enchanter-menu"), player).open(player);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -33,7 +36,7 @@ public class CommandEnchanter extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ee enchanter";
|
||||
return "enchanter";
|
||||
}
|
||||
|
||||
@Override
|
@ -1,8 +1,8 @@
|
||||
package com.songoda.epicenchants.command.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epicenchants.CommandCommons;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.command.AbstractCommand;
|
||||
import com.songoda.epicenchants.objects.Enchant;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@ -16,27 +16,30 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class CommandGiveBook extends AbstractCommand {
|
||||
|
||||
public CommandGiveBook(AbstractCommand parent) {
|
||||
super(parent, false, "givebook");
|
||||
private final EpicEnchants plugin;
|
||||
|
||||
public CommandGiveBook(EpicEnchants plugin) {
|
||||
super(false, "givebook");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
//ee givebook <player> <enchant> [level] [success-rate] [destroy-rate]
|
||||
//givebook <player> <enchant> [level] [success-rate] [destroy-rate]
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
if (args.length < 3 || args.length > 6)
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length < 2 || args.length > 5)
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
OfflinePlayer target = Bukkit.getPlayer(args[1]);
|
||||
OfflinePlayer target = Bukkit.getPlayer(args[0]);
|
||||
|
||||
if (target == null) {
|
||||
instance.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
|
||||
plugin.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
Optional<Enchant> optionalEnchant = instance.getEnchantManager().getValue(args[2].replaceAll("_", " "));
|
||||
Optional<Enchant> optionalEnchant = plugin.getEnchantManager().getValue(args[1].replaceAll("_", " "));
|
||||
|
||||
if (!optionalEnchant.isPresent()) {
|
||||
instance.getLocale().newMessage("&cNo enchants exist with that name...").sendPrefixedMessage(sender);
|
||||
plugin.getLocale().newMessage("&cNo enchants exist with that name...").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
@ -45,26 +48,26 @@ public class CommandGiveBook extends AbstractCommand {
|
||||
int successRate = -1;
|
||||
int destroyRate = -1;
|
||||
|
||||
if (args.length > 2) {
|
||||
if (!CommandCommons.isInt(args[2], sender))
|
||||
return ReturnType.FAILURE;
|
||||
level = Integer.parseInt(args[2]);
|
||||
}
|
||||
|
||||
if (args.length > 3) {
|
||||
if (!CommandCommons.isInt(args[3], sender))
|
||||
return ReturnType.FAILURE;
|
||||
level = Integer.parseInt(args[3]);
|
||||
successRate = Integer.parseInt(args[3]);
|
||||
}
|
||||
|
||||
if (args.length > 4) {
|
||||
if (!CommandCommons.isInt(args[4], sender))
|
||||
return ReturnType.FAILURE;
|
||||
successRate = Integer.parseInt(args[4]);
|
||||
destroyRate = Integer.parseInt(args[4]);
|
||||
}
|
||||
|
||||
if (args.length > 5) {
|
||||
if (!CommandCommons.isInt(args[5], sender))
|
||||
return ReturnType.FAILURE;
|
||||
destroyRate = Integer.parseInt(args[5]);
|
||||
}
|
||||
|
||||
if (level != -1 && (level > enchant.getMaxLevel() || level < 1)) {
|
||||
instance.getLocale().getMessage("command.book." + (level > enchant.getMaxLevel() ? "maxlevel" : "minlevel"))
|
||||
if (level != -0 && (level > enchant.getMaxLevel() || level < 0)) {
|
||||
plugin.getLocale().getMessage("command.book." + (level > enchant.getMaxLevel() ? "maxlevel" : "minlevel"))
|
||||
.processPlaceholder("enchant", enchant.getIdentifier())
|
||||
.processPlaceholder("max_level", enchant.getMaxLevel())
|
||||
.sendPrefixedMessage(sender);
|
||||
@ -72,10 +75,10 @@ public class CommandGiveBook extends AbstractCommand {
|
||||
}
|
||||
|
||||
target.getPlayer().getInventory().addItem(enchant.getBook().get(enchant, level, successRate, destroyRate));
|
||||
instance.getLocale().getMessage("command.book.received")
|
||||
plugin.getLocale().getMessage("command.book.received")
|
||||
.processPlaceholder("enchant", enchant.getIdentifier())
|
||||
.sendPrefixedMessage(target.getPlayer());
|
||||
instance.getLocale().getMessage("command.book.gave")
|
||||
plugin.getLocale().getMessage("command.book.gave")
|
||||
.processPlaceholder("player", target.getPlayer().getName())
|
||||
.processPlaceholder("enchant", enchant.getIdentifier())
|
||||
.sendPrefixedMessage(sender);
|
||||
@ -83,14 +86,14 @@ public class CommandGiveBook extends AbstractCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
if (args.length == 2) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
if (args.length == 1) {
|
||||
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||
} else if (args.length == 3) {
|
||||
return instance.getEnchantManager().getValues()
|
||||
} else if (args.length == 2) {
|
||||
return plugin.getEnchantManager().getValues()
|
||||
.stream().map(Enchant::getIdentifier).collect(Collectors.toList());
|
||||
} else if (args.length == 4) {
|
||||
Enchant enchant = instance.getEnchantManager().getValues()
|
||||
} else if (args.length == 3) {
|
||||
Enchant enchant = plugin.getEnchantManager().getValues()
|
||||
.stream().findFirst().orElse(null);
|
||||
List<String> levels = new ArrayList<>();
|
||||
if (enchant != null) {
|
||||
@ -98,7 +101,7 @@ public class CommandGiveBook extends AbstractCommand {
|
||||
levels.add(String.valueOf(i));
|
||||
}
|
||||
return levels;
|
||||
} else if (args.length == 5 || args.length == 6) {
|
||||
} else if (args.length == 4 || args.length == 5) {
|
||||
List<String> rates = new ArrayList<>();
|
||||
for (int i = 1; i <= 100; i ++)
|
||||
rates.add(String.valueOf(i));
|
||||
@ -114,7 +117,7 @@ public class CommandGiveBook extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ee givebook <player> <enchant> [level] [success-rate] [destroy-rate]";
|
||||
return "givebook <player> <enchant> [level] [success-rate] [destroy-rate]";
|
||||
}
|
||||
|
||||
@Override
|
@ -1,9 +1,8 @@
|
||||
package com.songoda.epicenchants.command.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epicenchants.CommandCommons;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.command.AbstractCommand;
|
||||
import com.songoda.epicenchants.objects.Enchant;
|
||||
import com.songoda.epicenchants.objects.Group;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@ -13,33 +12,35 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandGiveItemDust extends AbstractCommand {
|
||||
|
||||
public CommandGiveItemDust(AbstractCommand parent) {
|
||||
super(parent, false, "giveitemdust");
|
||||
private final EpicEnchants plugin;
|
||||
|
||||
public CommandGiveItemDust(EpicEnchants plugin) {
|
||||
super(false, "giveitemdust");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
//ee giveitemdust <player> <group> [type] [percentage]
|
||||
//giveitemdust <player> <group> [type] [percentage]
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
if (args.length < 3 || args.length > 6)
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length < 2 || args.length > 5)
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
OfflinePlayer target = Bukkit.getPlayer(args[1]);
|
||||
OfflinePlayer target = Bukkit.getPlayer(args[0]);
|
||||
|
||||
if (target == null) {
|
||||
instance.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
|
||||
plugin.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
List<Group> groups = instance.getGroupManager().getValues().stream()
|
||||
.filter(group -> group.getIdentifier().equalsIgnoreCase(args[2])).collect(Collectors.toList());
|
||||
List<Group> groups = plugin.getGroupManager().getValues().stream()
|
||||
.filter(group -> group.getIdentifier().equalsIgnoreCase(args[1])).collect(Collectors.toList());
|
||||
|
||||
if (groups.isEmpty()) {
|
||||
instance.getLocale().newMessage("&cThe group you entered was no found...").sendPrefixedMessage(sender);
|
||||
plugin.getLocale().newMessage("&cThe group you entered was no found...").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
@ -48,21 +49,21 @@ public class CommandGiveItemDust extends AbstractCommand {
|
||||
String dustType = null;
|
||||
int percentage = -1;
|
||||
|
||||
if (args.length > 2) {
|
||||
dustType = args[2];
|
||||
}
|
||||
|
||||
if (args.length > 3) {
|
||||
dustType = args[3];
|
||||
}
|
||||
|
||||
if (args.length > 4) {
|
||||
if (!CommandCommons.isInt(args[4], sender))
|
||||
if (!CommandCommons.isInt(args[3], sender))
|
||||
return ReturnType.FAILURE;
|
||||
percentage = Integer.parseInt(args[4]);
|
||||
percentage = Integer.parseInt(args[3]);
|
||||
}
|
||||
|
||||
target.getPlayer().getInventory().addItem(instance.getSpecialItems().getDust(group, dustType, percentage, true));
|
||||
instance.getLocale().getMessage("command.dust.received")
|
||||
target.getPlayer().getInventory().addItem(plugin.getSpecialItems().getDust(group, dustType, percentage, true));
|
||||
plugin.getLocale().getMessage("command.dust.received")
|
||||
.processPlaceholder("group", group.getIdentifier())
|
||||
.sendPrefixedMessage(target.getPlayer());
|
||||
instance.getLocale().getMessage("command.dust.gave")
|
||||
plugin.getLocale().getMessage("command.dust.gave")
|
||||
.processPlaceholder("player", target.getPlayer().getName())
|
||||
.processPlaceholder("group", group.getIdentifier())
|
||||
.sendPrefixedMessage(sender);
|
||||
@ -70,19 +71,19 @@ public class CommandGiveItemDust extends AbstractCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
if (args.length == 2) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
if (args.length == 1) {
|
||||
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||
} else if (args.length == 3) {
|
||||
return instance.getGroupManager().getValues().stream()
|
||||
} else if (args.length == 2) {
|
||||
return plugin.getGroupManager().getValues().stream()
|
||||
.map(Group::getIdentifier).collect(Collectors.toList());
|
||||
} else if (args.length == 4) {
|
||||
} else if (args.length == 3) {
|
||||
List<String> dusts = new ArrayList<>();
|
||||
|
||||
FileConfiguration dustConfig = instance.getFileManager().getConfiguration("items/dusts");
|
||||
FileConfiguration dustConfig = plugin.getFileManager().getConfiguration("items/dusts");
|
||||
dusts.addAll(dustConfig.getConfigurationSection("dusts").getKeys(false));
|
||||
return dusts;
|
||||
} else if (args.length == 5) {
|
||||
} else if (args.length == 4) {
|
||||
List<String> rates = new ArrayList<>();
|
||||
for (int i = 1; i <= 100; i ++)
|
||||
rates.add(String.valueOf(i));
|
||||
@ -98,7 +99,7 @@ public class CommandGiveItemDust extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ee giveitemdust <player> <group> [type] [percentage]";
|
||||
return "giveitemdust <player> <group> [type] [percentage]";
|
||||
}
|
||||
|
||||
@Override
|
@ -1,7 +1,7 @@
|
||||
package com.songoda.epicenchants.command.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.command.AbstractCommand;
|
||||
import com.songoda.epicenchants.objects.Group;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@ -13,49 +13,52 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class CommandGiveRandomBook extends AbstractCommand {
|
||||
|
||||
public CommandGiveRandomBook(AbstractCommand parent) {
|
||||
super(parent, false, "giverandombook");
|
||||
private final EpicEnchants plugin;
|
||||
|
||||
public CommandGiveRandomBook(EpicEnchants plugin) {
|
||||
super(false, "giverandombook");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
//ee giverandombook <player> <group>
|
||||
//giverandombook <player> <group>
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
if (args.length < 3 || args.length > 6)
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length < 2 || args.length > 6)
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
OfflinePlayer target = Bukkit.getPlayer(args[1]);
|
||||
OfflinePlayer target = Bukkit.getPlayer(args[0]);
|
||||
|
||||
if (target == null) {
|
||||
instance.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
|
||||
plugin.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
|
||||
List<Group> groups = instance.getGroupManager().getValues().stream()
|
||||
.filter(group -> group.getIdentifier().equalsIgnoreCase(args[2])).collect(Collectors.toList());
|
||||
List<Group> groups = plugin.getGroupManager().getValues().stream()
|
||||
.filter(group -> group.getIdentifier().equalsIgnoreCase(args[1])).collect(Collectors.toList());
|
||||
|
||||
if (groups.isEmpty()) {
|
||||
instance.getLocale().newMessage("&cThe group you entered was no found...").sendPrefixedMessage(sender);
|
||||
plugin.getLocale().newMessage("&cThe group you entered was no found...").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
Group group = groups.get(0);
|
||||
|
||||
target.getPlayer().getInventory().addItem(instance.getSpecialItems().getMysteryBook(group));
|
||||
instance.getLocale().getMessage("command.randombook.received")
|
||||
target.getPlayer().getInventory().addItem(plugin.getSpecialItems().getMysteryBook(group));
|
||||
plugin.getLocale().getMessage("command.randombook.received")
|
||||
.sendPrefixedMessage(target.getPlayer());
|
||||
instance.getLocale().getMessage("command.randombook.gave")
|
||||
plugin.getLocale().getMessage("command.randombook.gave")
|
||||
.processPlaceholder("player", target.getPlayer().getName())
|
||||
.sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
if (args.length == 2) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
if (args.length == 1) {
|
||||
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||
} else if (args.length == 3) {
|
||||
return instance.getGroupManager().getValues().stream()
|
||||
} else if (args.length == 2) {
|
||||
return plugin.getGroupManager().getValues().stream()
|
||||
.map(Group::getIdentifier).collect(Collectors.toList());
|
||||
}
|
||||
return null;
|
||||
@ -68,7 +71,7 @@ public class CommandGiveRandomBook extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ee giverandombook <player> <group>";
|
||||
return "giverandombook <player> <group>";
|
||||
}
|
||||
|
||||
@Override
|
@ -1,9 +1,8 @@
|
||||
package com.songoda.epicenchants.command.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epicenchants.CommandCommons;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.command.AbstractCommand;
|
||||
import com.songoda.epicenchants.objects.Enchant;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -16,21 +15,24 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class CommandGiveScroll extends AbstractCommand {
|
||||
|
||||
public CommandGiveScroll(AbstractCommand parent) {
|
||||
super(parent, false, "givescroll");
|
||||
private final EpicEnchants plugin;
|
||||
|
||||
public CommandGiveScroll(EpicEnchants plugin) {
|
||||
super(false, "givescroll");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
//ee givescroll <giveType> <player> [amount] [success-rate]
|
||||
//givescroll <giveType> <player> [amount] [success-rate]
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
if (args.length < 3 || args.length > 6)
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length < 2 || args.length > 5)
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
String giveType = args[1];
|
||||
OfflinePlayer target = Bukkit.getPlayer(args[2]);
|
||||
String giveType = args[0];
|
||||
OfflinePlayer target = Bukkit.getPlayer(args[1]);
|
||||
|
||||
if (target == null) {
|
||||
instance.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
|
||||
plugin.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
@ -38,52 +40,52 @@ public class CommandGiveScroll extends AbstractCommand {
|
||||
int successRate = -1;
|
||||
|
||||
|
||||
if (args.length > 2) {
|
||||
if (!CommandCommons.isInt(args[2], sender))
|
||||
return ReturnType.FAILURE;
|
||||
amount = Integer.parseInt(args[2]);
|
||||
}
|
||||
|
||||
if (args.length > 3) {
|
||||
if (!CommandCommons.isInt(args[3], sender))
|
||||
return ReturnType.FAILURE;
|
||||
amount = Integer.parseInt(args[3]);
|
||||
}
|
||||
|
||||
if (args.length > 4) {
|
||||
if (!CommandCommons.isInt(args[4], sender))
|
||||
return ReturnType.FAILURE;
|
||||
successRate = Integer.parseInt(args[4]);
|
||||
successRate = Integer.parseInt(args[3]);
|
||||
}
|
||||
|
||||
String messageKey;
|
||||
switch (giveType.toLowerCase()) {
|
||||
case "whitescroll":
|
||||
target.getPlayer().getInventory().addItem(instance.getSpecialItems().getWhiteScroll(amount));
|
||||
target.getPlayer().getInventory().addItem(plugin.getSpecialItems().getWhiteScroll(amount));
|
||||
messageKey = "whitescroll";
|
||||
break;
|
||||
case "blackscroll":
|
||||
messageKey = "blackscroll";
|
||||
target.getPlayer().getInventory().addItem(instance.getSpecialItems().getBlackScroll(amount, successRate));
|
||||
target.getPlayer().getInventory().addItem(plugin.getSpecialItems().getBlackScroll(amount, successRate));
|
||||
break;
|
||||
default:
|
||||
instance.getLocale().getMessage("command.giveunknown")
|
||||
plugin.getLocale().getMessage("command.giveunknown")
|
||||
.processPlaceholder("unknown", giveType)
|
||||
.sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
instance.getLocale().getMessage("command." + messageKey + ".received")
|
||||
plugin.getLocale().getMessage("command." + messageKey + ".received")
|
||||
.sendPrefixedMessage(target.getPlayer());
|
||||
instance.getLocale().getMessage("command." + messageKey + ".gave")
|
||||
plugin.getLocale().getMessage("command." + messageKey + ".gave")
|
||||
.processPlaceholder("player", target.getName())
|
||||
.sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
if (args.length == 2) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
if (args.length == 1) {
|
||||
return Arrays.asList("whitescroll", "blackscroll");
|
||||
} else if (args.length == 3) {
|
||||
} else if (args.length == 2) {
|
||||
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||
} else if (args.length == 4 || args.length == 5) {
|
||||
} else if (args.length == 3 || args.length == 4) {
|
||||
List<String> rates = new ArrayList<>();
|
||||
for (int i = 1; i <= (args.length == 4 ? 10 : 100); i ++)
|
||||
for (int i = 1; i <= (args.length == 3 ? 10 : 100); i ++)
|
||||
rates.add(String.valueOf(i));
|
||||
return rates;
|
||||
}
|
||||
@ -97,7 +99,7 @@ public class CommandGiveScroll extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ee givescroll <whitescroll/blackscroll> <player> [amount] [success-rate]";
|
||||
return "givescroll <whitescroll/blackscroll> <player> [amount] [success-rate]";
|
||||
}
|
||||
|
||||
@Override
|
@ -1,44 +1,38 @@
|
||||
package com.songoda.epicenchants.command.commands;
|
||||
|
||||
import com.songoda.epicenchants.CommandCommons;
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.command.AbstractCommand;
|
||||
import com.songoda.epicenchants.enums.EnchantResult;
|
||||
import com.songoda.epicenchants.objects.Enchant;
|
||||
import com.songoda.epicenchants.utils.Tuple;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.songoda.epicenchants.enums.EnchantResult.BROKEN_FAILURE;
|
||||
import static com.songoda.epicenchants.utils.single.GeneralUtils.getMessageFromResult;
|
||||
|
||||
public class CommandList extends AbstractCommand {
|
||||
|
||||
public CommandList(AbstractCommand parent) {
|
||||
super(parent, true, "list");
|
||||
private final EpicEnchants plugin;
|
||||
|
||||
public CommandList(EpicEnchants plugin) {
|
||||
super(true, "list");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length > 1 && args[1].equalsIgnoreCase("chat")) {
|
||||
instance.getLocale().newMessage(instance.getEnchantManager().getValues().stream()
|
||||
plugin.getLocale().newMessage(plugin.getEnchantManager().getValues().stream()
|
||||
.sorted(Comparator.comparing(enchant -> enchant.getGroup().getOrder()))
|
||||
.map(enchant -> enchant.getColoredIdentifier(true)).collect(Collectors.joining("&7, ")))
|
||||
.sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
instance.getInfoManager().getMainInfoMenu().open((Player)sender);
|
||||
plugin.getInfoManager().getMainInfoMenu().open((Player)sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -49,7 +43,7 @@ public class CommandList extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ee list [chat]";
|
||||
return "list [chat]";
|
||||
}
|
||||
|
||||
@Override
|
@ -1,26 +1,29 @@
|
||||
package com.songoda.epicenchants.command.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.command.AbstractCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandReload extends AbstractCommand {
|
||||
|
||||
public CommandReload(AbstractCommand parent) {
|
||||
super(parent, false, "reload");
|
||||
private final EpicEnchants plugin;
|
||||
|
||||
public CommandReload(EpicEnchants plugin) {
|
||||
super(false, "reload");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractCommand.ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
instance.reloadConfig();
|
||||
instance.getLocale().getMessage("command.reload").sendPrefixedMessage(sender);
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
plugin.reloadConfig();
|
||||
plugin.getLocale().getMessage("command.reload").sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -31,7 +34,7 @@ public class CommandReload extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ee reload";
|
||||
return "reload";
|
||||
}
|
||||
|
||||
@Override
|
@ -1,8 +1,8 @@
|
||||
package com.songoda.epicenchants.command.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.core.configuration.editor.PluginConfigGui;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.command.AbstractCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -10,18 +10,21 @@ import java.util.List;
|
||||
|
||||
public class CommandSettings extends AbstractCommand {
|
||||
|
||||
public CommandSettings(AbstractCommand parent) {
|
||||
super(parent, true, "Settings");
|
||||
private final EpicEnchants plugin;
|
||||
|
||||
public CommandSettings(EpicEnchants plugin) {
|
||||
super(true, "Settings");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
instance.getGuiManager().showGUI((Player) sender, new PluginConfigGui(instance));
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
plugin.getGuiManager().showGUI((Player) sender, new PluginConfigGui(plugin));
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -32,7 +35,7 @@ public class CommandSettings extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ee settings";
|
||||
return "settings";
|
||||
}
|
||||
|
||||
@Override
|
@ -1,8 +1,7 @@
|
||||
package com.songoda.epicenchants.command.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.command.AbstractCommand;
|
||||
import com.songoda.epicenchants.menus.EnchanterMenu;
|
||||
import com.songoda.epicenchants.menus.TinkererMenu;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -11,19 +10,22 @@ import java.util.List;
|
||||
|
||||
public class CommandTinkerer extends AbstractCommand {
|
||||
|
||||
public CommandTinkerer(AbstractCommand parent) {
|
||||
super(parent, true, "tinkerer");
|
||||
private final EpicEnchants plugin;
|
||||
|
||||
public CommandTinkerer(EpicEnchants plugin) {
|
||||
super(true, "tinkerer");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
Player player = (Player)sender;
|
||||
new TinkererMenu(instance, instance.getFileManager().getConfiguration("menus/tinkerer-menu")).open(player);
|
||||
new TinkererMenu(plugin, plugin.getFileManager().getConfiguration("menus/tinkerer-menu")).open(player);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -34,7 +36,7 @@ public class CommandTinkerer extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ee tinkerer";
|
||||
return "tinkerer";
|
||||
}
|
||||
|
||||
@Override
|
@ -31,9 +31,6 @@ public class DropHead extends EffectExecutor {
|
||||
case CHICKEN:
|
||||
skin = "MHF_Chicken";
|
||||
break;
|
||||
case PIG_ZOMBIE:
|
||||
skin = "MHF_PigZombie";
|
||||
break;
|
||||
case PIG:
|
||||
skin = "MHF_Pig";
|
||||
break;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.songoda.epicenchants.menus;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.objects.Enchant;
|
||||
import com.songoda.epicenchants.objects.Group;
|
||||
@ -48,7 +49,7 @@ public class InfoMenu extends FastInv {
|
||||
slots.stream().filter(slot -> enchantIterator.hasNext()).forEach(slot -> {
|
||||
Enchant enchant = enchantIterator.next();
|
||||
|
||||
String whitelist = instance.getItemGroup().getGroups(enchant.getItemWhitelist())
|
||||
String whitelist = instance.getItemGroup().getGroups(enchant.getItemWhitelist().stream().map(CompatibleMaterial::getMaterial).collect(Collectors.toSet()))
|
||||
.stream()
|
||||
.map(s -> StringUtils.capitalize(s.toLowerCase()))
|
||||
.collect(Collectors.joining(", "));
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.songoda.epicenchants.objects;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.NBTItem;
|
||||
import com.songoda.epicenchants.utils.objects.ItemBuilder;
|
||||
@ -64,7 +65,8 @@ public class BookItem {
|
||||
}
|
||||
|
||||
string = string
|
||||
.replace("{item_group}", "" + instance.getItemGroup().getGroup(enchant.getItemWhitelist()).map(ItemGroup.Group::getName).orElse("N/A"))
|
||||
.replace("{item_group}", "" + instance.getItemGroup().getGroup(enchant.getItemWhitelist()
|
||||
.stream().map(CompatibleMaterial::getMaterial).collect(Collectors.toSet())).map(ItemGroup.Group::getName).orElse("N/A"))
|
||||
.replace("{success_rate}", "" + finalSuccessRate)
|
||||
.replace("{destroy_rate}", "" + finalDestroyRate);
|
||||
|
||||
|
@ -11,7 +11,6 @@ import com.songoda.epicenchants.utils.itemnbtapi.NBTItem;
|
||||
import com.songoda.epicenchants.utils.objects.ItemBuilder;
|
||||
import com.songoda.epicenchants.utils.settings.Settings;
|
||||
import com.songoda.epicenchants.utils.single.GeneralUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -1,19 +1,31 @@
|
||||
package com.songoda.epicenchants.utils.itemnbtapi;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.utils.MinecraftVersion;
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.utils.nmsmappings.ReflectionMethod;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Base class representing NMS Compounds. For a standalone implementation check
|
||||
* {@link NBTContainer}
|
||||
*
|
||||
* @author tr7zw
|
||||
*
|
||||
*/
|
||||
public class NBTCompound {
|
||||
|
||||
private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
|
||||
private final Lock readLock = readWriteLock.readLock();
|
||||
private final Lock writeLock = readWriteLock.writeLock();
|
||||
|
||||
private String compundName;
|
||||
private NBTCompound parent;
|
||||
|
||||
@ -22,6 +34,14 @@ public class NBTCompound {
|
||||
this.parent = owner;
|
||||
}
|
||||
|
||||
protected Lock getReadLock() {
|
||||
return readLock;
|
||||
}
|
||||
|
||||
protected Lock getWriteLock() {
|
||||
return writeLock;
|
||||
}
|
||||
|
||||
protected void saveCompound() {
|
||||
if (parent != null)
|
||||
parent.saveCompound();
|
||||
@ -59,8 +79,13 @@ public class NBTCompound {
|
||||
* @param comp
|
||||
*/
|
||||
public void mergeCompound(NBTCompound comp) {
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.mergeOtherNBTCompound(this, comp);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,8 +95,13 @@ public class NBTCompound {
|
||||
* @param value
|
||||
*/
|
||||
public void setString(String key, String value) {
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_STRING, key, value);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,7 +111,12 @@ public class NBTCompound {
|
||||
* @return The stored value or NMS fallback
|
||||
*/
|
||||
public String getString(String key) {
|
||||
try {
|
||||
readLock.lock();
|
||||
return (String) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_STRING, key);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
protected String getContent(String key) {
|
||||
@ -95,8 +130,13 @@ public class NBTCompound {
|
||||
* @param value
|
||||
*/
|
||||
public void setInteger(String key, Integer value) {
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_INT, key, value);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -106,7 +146,12 @@ public class NBTCompound {
|
||||
* @return The stored value or NMS fallback
|
||||
*/
|
||||
public Integer getInteger(String key) {
|
||||
try {
|
||||
readLock.lock();
|
||||
return (Integer) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_INT, key);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -116,8 +161,13 @@ public class NBTCompound {
|
||||
* @param value
|
||||
*/
|
||||
public void setDouble(String key, Double value) {
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_DOUBLE, key, value);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -127,7 +177,12 @@ public class NBTCompound {
|
||||
* @return The stored value or NMS fallback
|
||||
*/
|
||||
public Double getDouble(String key) {
|
||||
try {
|
||||
readLock.lock();
|
||||
return (Double) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_DOUBLE, key);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,8 +192,13 @@ public class NBTCompound {
|
||||
* @param value
|
||||
*/
|
||||
public void setByte(String key, Byte value) {
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_BYTE, key, value);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -148,7 +208,12 @@ public class NBTCompound {
|
||||
* @return The stored value or NMS fallback
|
||||
*/
|
||||
public Byte getByte(String key) {
|
||||
try {
|
||||
readLock.lock();
|
||||
return (Byte) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_BYTE, key);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -158,8 +223,13 @@ public class NBTCompound {
|
||||
* @param value
|
||||
*/
|
||||
public void setShort(String key, Short value) {
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_SHORT, key, value);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -169,7 +239,12 @@ public class NBTCompound {
|
||||
* @return The stored value or NMS fallback
|
||||
*/
|
||||
public Short getShort(String key) {
|
||||
try {
|
||||
readLock.lock();
|
||||
return (Short) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_SHORT, key);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -179,8 +254,13 @@ public class NBTCompound {
|
||||
* @param value
|
||||
*/
|
||||
public void setLong(String key, Long value) {
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_LONG, key, value);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -190,7 +270,12 @@ public class NBTCompound {
|
||||
* @return The stored value or NMS fallback
|
||||
*/
|
||||
public Long getLong(String key) {
|
||||
try {
|
||||
readLock.lock();
|
||||
return (Long) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_LONG, key);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -200,8 +285,13 @@ public class NBTCompound {
|
||||
* @param value
|
||||
*/
|
||||
public void setFloat(String key, Float value) {
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_FLOAT, key, value);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -211,7 +301,12 @@ public class NBTCompound {
|
||||
* @return The stored value or NMS fallback
|
||||
*/
|
||||
public Float getFloat(String key) {
|
||||
try {
|
||||
readLock.lock();
|
||||
return (Float) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_FLOAT, key);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -221,8 +316,13 @@ public class NBTCompound {
|
||||
* @param value
|
||||
*/
|
||||
public void setByteArray(String key, byte[] value) {
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_BYTEARRAY, key, value);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -232,7 +332,12 @@ public class NBTCompound {
|
||||
* @return The stored value or NMS fallback
|
||||
*/
|
||||
public byte[] getByteArray(String key) {
|
||||
try {
|
||||
readLock.lock();
|
||||
return (byte[]) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_BYTEARRAY, key);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -242,8 +347,13 @@ public class NBTCompound {
|
||||
* @param value
|
||||
*/
|
||||
public void setIntArray(String key, int[] value) {
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_INTARRAY, key, value);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -253,7 +363,12 @@ public class NBTCompound {
|
||||
* @return The stored value or NMS fallback
|
||||
*/
|
||||
public int[] getIntArray(String key) {
|
||||
try {
|
||||
readLock.lock();
|
||||
return (int[]) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_INTARRAY, key);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -263,8 +378,13 @@ public class NBTCompound {
|
||||
* @param value
|
||||
*/
|
||||
public void setBoolean(String key, Boolean value) {
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_BOOLEAN, key, value);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
protected void set(String key, Object val) {
|
||||
@ -279,7 +399,12 @@ public class NBTCompound {
|
||||
* @return The stored value or NMS fallback
|
||||
*/
|
||||
public Boolean getBoolean(String key) {
|
||||
try {
|
||||
readLock.lock();
|
||||
return (Boolean) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_BOOLEAN, key);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -289,8 +414,13 @@ public class NBTCompound {
|
||||
* @param value
|
||||
*/
|
||||
public void setObject(String key, Object value) {
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.setObject(this, key, value);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -301,7 +431,75 @@ public class NBTCompound {
|
||||
* @return The created Object or null if empty
|
||||
*/
|
||||
public <T> T getObject(String key, Class<T> type) {
|
||||
try {
|
||||
readLock.lock();
|
||||
return NBTReflectionUtil.getObject(this, key, type);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save an ItemStack as a compound under a given key
|
||||
*
|
||||
* @param key
|
||||
* @param item
|
||||
*/
|
||||
public void setItemStack(String key, ItemStack item) {
|
||||
try {
|
||||
writeLock.lock();
|
||||
removeKey(key);
|
||||
addCompound(key).mergeCompound(NBTItem.convertItemtoNBT(item));
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an ItemStack that was saved at the given key
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public ItemStack getItemStack(String key) {
|
||||
try {
|
||||
readLock.lock();
|
||||
NBTCompound comp = getCompound(key);
|
||||
return NBTItem.convertNBTtoItem(comp);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
public void setUUID(String key, UUID value) {
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_UUID, key, value);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter
|
||||
*
|
||||
* @param key
|
||||
* @return The stored value or NMS fallback
|
||||
*/
|
||||
public UUID getUUID(String key) {
|
||||
try {
|
||||
readLock.lock();
|
||||
return (UUID) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_UUID, key);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -309,25 +507,40 @@ public class NBTCompound {
|
||||
* @return True if the key is set
|
||||
*/
|
||||
public Boolean hasKey(String key) {
|
||||
try {
|
||||
readLock.lock();
|
||||
Boolean b = (Boolean) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_HAS_KEY, key);
|
||||
if (b == null)
|
||||
return false;
|
||||
return b;
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key Deletes the given Key
|
||||
*/
|
||||
public void removeKey(String key) {
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.remove(this, key);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Set of all stored Keys
|
||||
*/
|
||||
public Set<String> getKeys() {
|
||||
try {
|
||||
readLock.lock();
|
||||
return NBTReflectionUtil.getKeys(this);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -337,6 +550,8 @@ public class NBTCompound {
|
||||
* @return The subCompound Object
|
||||
*/
|
||||
public NBTCompound addCompound(String name) {
|
||||
try {
|
||||
writeLock.lock();
|
||||
if (getType(name) == NBTType.NBTTagCompound)
|
||||
return getCompound(name);
|
||||
NBTReflectionUtil.addNBTTagCompound(this, name);
|
||||
@ -345,6 +560,9 @@ public class NBTCompound {
|
||||
throw new NbtApiException("Error while adding Compound, got null!");
|
||||
saveCompound();
|
||||
return comp;
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -352,12 +570,17 @@ public class NBTCompound {
|
||||
* @return The Compound instance or null
|
||||
*/
|
||||
public NBTCompound getCompound(String name) {
|
||||
try {
|
||||
readLock.lock();
|
||||
if (getType(name) != NBTType.NBTTagCompound)
|
||||
return null;
|
||||
NBTCompound next = new NBTCompound(this, name);
|
||||
if (NBTReflectionUtil.valideCompound(next))
|
||||
return next;
|
||||
return null;
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -365,9 +588,14 @@ public class NBTCompound {
|
||||
* @return The retrieved String List
|
||||
*/
|
||||
public NBTList<String> getStringList(String name) {
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTList<String> list = NBTReflectionUtil.getList(this, name, NBTType.NBTTagString, String.class);
|
||||
saveCompound();
|
||||
return list;
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -375,9 +603,59 @@ public class NBTCompound {
|
||||
* @return The retrieved Integer List
|
||||
*/
|
||||
public NBTList<Integer> getIntegerList(String name) {
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTList<Integer> list = NBTReflectionUtil.getList(this, name, NBTType.NBTTagInt, Integer.class);
|
||||
saveCompound();
|
||||
return list;
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @return The retrieved Float List
|
||||
*/
|
||||
public NBTList<Float> getFloatList(String name) {
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTList<Float> list = NBTReflectionUtil.getList(this, name, NBTType.NBTTagFloat, Float.class);
|
||||
saveCompound();
|
||||
return list;
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @return The retrieved Double List
|
||||
*/
|
||||
public NBTList<Double> getDoubleList(String name) {
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTList<Double> list = NBTReflectionUtil.getList(this, name, NBTType.NBTTagDouble, Double.class);
|
||||
saveCompound();
|
||||
return list;
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @return The retrieved Long List
|
||||
*/
|
||||
public NBTList<Long> getLongList(String name) {
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTList<Long> list = NBTReflectionUtil.getList(this, name, NBTType.NBTTagLong, Long.class);
|
||||
saveCompound();
|
||||
return list;
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -385,9 +663,15 @@ public class NBTCompound {
|
||||
* @return The retrieved Compound List
|
||||
*/
|
||||
public NBTCompoundList getCompoundList(String name) {
|
||||
NBTCompoundList list = (NBTCompoundList) NBTReflectionUtil.getList(this, name, NBTType.NBTTagCompound, NBTListCompound.class);
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTCompoundList list = (NBTCompoundList) NBTReflectionUtil.getList(this, name, NBTType.NBTTagCompound,
|
||||
NBTListCompound.class);
|
||||
saveCompound();
|
||||
return list;
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -395,55 +679,91 @@ public class NBTCompound {
|
||||
* @return The type of the given stored key or null
|
||||
*/
|
||||
public NBTType getType(String name) {
|
||||
if (MinecraftVersion.getVersion() == MinecraftVersion.MC1_7_R4)
|
||||
try {
|
||||
readLock.lock();
|
||||
if (MinecraftVersion.getVersion() == MinecraftVersion.MC1_7_R4) {
|
||||
Object nbtbase = NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET, name);
|
||||
if(nbtbase == null)
|
||||
return null;
|
||||
return NBTType.valueOf((byte)ReflectionMethod.COMPOUND_OWN_TYPE.run(nbtbase));
|
||||
}
|
||||
Object o = NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_TYPE, name);
|
||||
if (o == null)
|
||||
return null;
|
||||
return NBTType.valueOf((byte) o);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void writeCompound(OutputStream stream) {
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.writeApiNBT(this, stream);
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
/*StringBuilder result = new StringBuilder();
|
||||
for (String key : getKeys()) {
|
||||
result.append(toString(key));
|
||||
}
|
||||
return result.toString();*/
|
||||
/*
|
||||
* StringBuilder result = new StringBuilder(); for (String key : getKeys()) {
|
||||
* result.append(toString(key)); } return result.toString();
|
||||
*/
|
||||
return asNBTString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Just use toString()
|
||||
* @param key
|
||||
* @return A string representation of the given key
|
||||
* @deprecated Just use toString()
|
||||
*/
|
||||
@Deprecated
|
||||
public String toString(String key) {
|
||||
/*StringBuilder result = new StringBuilder();
|
||||
NBTCompound compound = this;
|
||||
while (compound.getParent() != null) {
|
||||
result.append(" ");
|
||||
compound = compound.getParent();
|
||||
}
|
||||
if (this.getType(key) == NBTType.NBTTagCompound) {
|
||||
return this.getCompound(key).toString();
|
||||
} else {
|
||||
return result + "-" + key + ": " + getContent(key) + System.lineSeparator();
|
||||
}*/
|
||||
/*
|
||||
* StringBuilder result = new StringBuilder(); NBTCompound compound = this;
|
||||
* while (compound.getParent() != null) { result.append(" "); compound =
|
||||
* compound.getParent(); } if (this.getType(key) == NBTType.NBTTagCompound) {
|
||||
* return this.getCompound(key).toString(); } else { return result + "-" + key +
|
||||
* ": " + getContent(key) + System.lineSeparator(); }
|
||||
*/
|
||||
return asNBTString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A json valid nbt string for this Compound
|
||||
* @deprecated Just use toString()
|
||||
* @return A {@link String} representation of the NBT in Mojang JSON. This is different from normal JSON!
|
||||
*/
|
||||
@Deprecated
|
||||
public String asNBTString() {
|
||||
try {
|
||||
readLock.lock();
|
||||
Object comp = NBTReflectionUtil.gettoCompount(getCompound(), this);
|
||||
if (comp == null)
|
||||
return "{}";
|
||||
return comp.toString();
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return toString().hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the nbt-string to match this compound with another object. This allows
|
||||
* two "technically" different Compounds to match, if they have the same content
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
return toString().equals(obj.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package com.songoda.epicenchants.utils.itemnbtapi;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.utils.nmsmappings.ClassWrapper;
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.utils.nmsmappings.ObjectCreator;
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.utils.nmsmappings.ReflectionMethod;
|
||||
|
||||
@ -29,9 +32,25 @@ public class NBTContainer extends NBTCompound {
|
||||
*/
|
||||
public NBTContainer(Object nbt) {
|
||||
super(null, null);
|
||||
if (nbt == null) {
|
||||
throw new NullPointerException("The NBT-Object can't be null!");
|
||||
}
|
||||
if (!ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz().isAssignableFrom(nbt.getClass())) {
|
||||
throw new NbtApiException("The object '" + nbt.getClass() + "' is not a valid NBT-Object!");
|
||||
}
|
||||
this.nbt = nbt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads in a NBT InputStream
|
||||
*
|
||||
* @param inputsteam
|
||||
*/
|
||||
public NBTContainer(InputStream inputsteam) {
|
||||
super(null, null);
|
||||
this.nbt = NBTReflectionUtil.readNBT(inputsteam);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses in a NBT String to a standalone {@link NBTCompound}. Can throw a
|
||||
* {@link NbtApiException} in case something goes wrong.
|
||||
@ -40,6 +59,9 @@ public class NBTContainer extends NBTCompound {
|
||||
*/
|
||||
public NBTContainer(String nbtString) {
|
||||
super(null, null);
|
||||
if (nbtString == null) {
|
||||
throw new NullPointerException("The String can't be null!");
|
||||
}
|
||||
try {
|
||||
nbt = ReflectionMethod.PARSE_NBT.run(null, nbtString);
|
||||
} catch (Exception ex) {
|
||||
|
@ -0,0 +1,45 @@
|
||||
package com.songoda.epicenchants.utils.itemnbtapi;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.utils.nmsmappings.ClassWrapper;
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.utils.nmsmappings.ReflectionMethod;
|
||||
|
||||
/**
|
||||
* Double implementation for NBTLists
|
||||
*
|
||||
* @author tr7zw
|
||||
*
|
||||
*/
|
||||
public class NBTDoubleList extends NBTList<Double> {
|
||||
|
||||
protected NBTDoubleList(NBTCompound owner, String name, NBTType type, Object list) {
|
||||
super(owner, name, type, list);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object asTag(Double object) {
|
||||
try {
|
||||
Constructor<?> con = ClassWrapper.NMS_NBTTAGDOUBLE.getClazz().getDeclaredConstructor(double.class);
|
||||
con.setAccessible(true);
|
||||
return con.newInstance(object);
|
||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
|
||||
| NoSuchMethodException | SecurityException e) {
|
||||
throw new NbtApiException("Error while wrapping the Object " + object + " to it's NMS object!", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double get(int index) {
|
||||
try {
|
||||
Object obj = ReflectionMethod.LIST_GET.run(listObject, index);
|
||||
return Double.valueOf(obj.toString());
|
||||
} catch (NumberFormatException nf) {
|
||||
return 0d;
|
||||
} catch (Exception ex) {
|
||||
throw new NbtApiException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -2,6 +2,10 @@ package com.songoda.epicenchants.utils.itemnbtapi;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.utils.MinecraftVersion;
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.utils.annotations.AvaliableSince;
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.utils.annotations.CheckUtil;
|
||||
|
||||
/**
|
||||
* NBT class to access vanilla tags from Entities. Entities don't support custom
|
||||
* tags. Use the NBTInjector for custom tags. Changes will be instantly applied
|
||||
@ -19,6 +23,9 @@ public class NBTEntity extends NBTCompound {
|
||||
*/
|
||||
public NBTEntity(Entity entity) {
|
||||
super(null, null);
|
||||
if (entity == null) {
|
||||
throw new NullPointerException("Entity can't be null!");
|
||||
}
|
||||
ent = entity;
|
||||
}
|
||||
|
||||
@ -32,4 +39,23 @@ public class NBTEntity extends NBTCompound {
|
||||
NBTReflectionUtil.setEntityNBTTag(compound, NBTReflectionUtil.getNMSEntity(ent));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the NBTCompound used by spigots PersistentDataAPI. This method is only
|
||||
* available for 1.14+!
|
||||
*
|
||||
* @return NBTCompound containing the data of the PersistentDataAPI
|
||||
*/
|
||||
@AvaliableSince(version = MinecraftVersion.MC1_14_R1)
|
||||
public NBTCompound getPersistentDataContainer() {
|
||||
if (hasKey("BukkitValues")) {
|
||||
return getCompound("BukkitValues");
|
||||
} else {
|
||||
NBTContainer container = new NBTContainer();
|
||||
container.addCompound("BukkitValues").setString("__nbtapi",
|
||||
"Marker to make the PersistentDataContainer have content");
|
||||
mergeCompound(container);
|
||||
return getCompound("BukkitValues");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,10 +27,13 @@ public class NBTFile extends NBTCompound {
|
||||
*/
|
||||
public NBTFile(File file) throws IOException {
|
||||
super(null, null);
|
||||
if (file == null) {
|
||||
throw new NullPointerException("File can't be null!");
|
||||
}
|
||||
this.file = file;
|
||||
if (file.exists()) {
|
||||
FileInputStream inputsteam = new FileInputStream(file);
|
||||
nbt = NBTReflectionUtil.readNBTFile(inputsteam);
|
||||
nbt = NBTReflectionUtil.readNBT(inputsteam);
|
||||
} else {
|
||||
nbt = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
|
||||
save();
|
||||
@ -43,13 +46,18 @@ public class NBTFile extends NBTCompound {
|
||||
* @throws IOException
|
||||
*/
|
||||
public void save() throws IOException {
|
||||
try {
|
||||
getWriteLock().lock();
|
||||
if (!file.exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
if (!file.createNewFile())
|
||||
throw new IOException("Unable to create file at " + file.getAbsolutePath());
|
||||
}
|
||||
FileOutputStream outStream = new FileOutputStream(file);
|
||||
NBTReflectionUtil.saveNBTFile(nbt, outStream);
|
||||
NBTReflectionUtil.writeNBT(nbt, outStream);
|
||||
} finally {
|
||||
getWriteLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,45 @@
|
||||
package com.songoda.epicenchants.utils.itemnbtapi;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.utils.nmsmappings.ClassWrapper;
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.utils.nmsmappings.ReflectionMethod;
|
||||
|
||||
/**
|
||||
* Float implementation for NBTLists
|
||||
*
|
||||
* @author tr7zw
|
||||
*
|
||||
*/
|
||||
public class NBTFloatList extends NBTList<Float> {
|
||||
|
||||
protected NBTFloatList(NBTCompound owner, String name, NBTType type, Object list) {
|
||||
super(owner, name, type, list);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object asTag(Float object) {
|
||||
try {
|
||||
Constructor<?> con = ClassWrapper.NMS_NBTTAGFLOAT.getClazz().getDeclaredConstructor(float.class);
|
||||
con.setAccessible(true);
|
||||
return con.newInstance(object);
|
||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
|
||||
| NoSuchMethodException | SecurityException e) {
|
||||
throw new NbtApiException("Error while wrapping the Object " + object + " to it's NMS object!", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float get(int index) {
|
||||
try {
|
||||
Object obj = ReflectionMethod.LIST_GET.run(listObject, index);
|
||||
return Float.valueOf(obj.toString());
|
||||
} catch (NumberFormatException nf) {
|
||||
return 0f;
|
||||
} catch (Exception ex) {
|
||||
throw new NbtApiException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.songoda.epicenchants.utils.itemnbtapi;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.utils.nmsmappings.ObjectCreator;
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.utils.nmsmappings.ReflectionMethod;
|
||||
|
||||
public class NBTGameProfile {
|
||||
|
||||
/**
|
||||
* Convert a GameProfile to NBT. The NBT then can be modified or be stored
|
||||
*
|
||||
* @param profile
|
||||
* @return A NBTContainer with all the GameProfile data
|
||||
*/
|
||||
public static NBTCompound toNBT(GameProfile profile) {
|
||||
return new NBTContainer(ReflectionMethod.GAMEPROFILE_SERIALIZE.run(null, ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance(), profile));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconstructs a GameProfile from a NBTCompound
|
||||
*
|
||||
* @param compound Has to contain GameProfile data
|
||||
* @return The reconstructed GameProfile
|
||||
*/
|
||||
public static GameProfile fromNBT(NBTCompound compound) {
|
||||
return (GameProfile) ReflectionMethod.GAMEPROFILE_DESERIALIZE.run(null, NBTReflectionUtil.gettoCompount(compound.getCompound(), compound));
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
package com.songoda.epicenchants.utils.itemnbtapi;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.utils.nmsmappings.ReflectionMethod;
|
||||
|
||||
@ -14,6 +16,8 @@ import com.songoda.epicenchants.utils.itemnbtapi.utils.nmsmappings.ReflectionMet
|
||||
public class NBTItem extends NBTCompound {
|
||||
|
||||
private ItemStack bukkitItem;
|
||||
private boolean directApply;
|
||||
private ItemStack originalSrcStack = null;
|
||||
|
||||
/**
|
||||
* Constructor for NBTItems. The ItemStack will be cloned!
|
||||
@ -21,11 +25,27 @@ public class NBTItem extends NBTCompound {
|
||||
* @param item
|
||||
*/
|
||||
public NBTItem(ItemStack item) {
|
||||
super(null, null);
|
||||
if (item == null) {
|
||||
throw new NullPointerException("ItemStack can't be null!");
|
||||
this(item, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for NBTItems. The ItemStack will be cloned! If directApply is true,
|
||||
* all changed will be mapped to the original item. Changes to the NBTItem will overwrite changes done
|
||||
* to the original item in that case.
|
||||
*
|
||||
* @param item
|
||||
* @param directApply
|
||||
*/
|
||||
public NBTItem(ItemStack item, boolean directApply) {
|
||||
super(null, null);
|
||||
if (item == null || item.getType() == Material.AIR) {
|
||||
throw new NullPointerException("ItemStack can't be null/Air!");
|
||||
}
|
||||
this.directApply = directApply;
|
||||
bukkitItem = item.clone();
|
||||
if(directApply) {
|
||||
this.originalSrcStack = item;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -40,6 +60,58 @@ public class NBTItem extends NBTCompound {
|
||||
bukkitItem = (ItemStack) ReflectionMethod.ITEMSTACK_BUKKITMIRROR.run(null, stack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply stored NBT tags to the provided ItemStack.
|
||||
* <p>
|
||||
* Note: This will completely override current item's {@link ItemMeta}.
|
||||
* If you still want to keep the original item's NBT tags, see
|
||||
* {@link #mergeNBT(ItemStack)} and {@link #mergeCustomNBT(ItemStack)}.
|
||||
*
|
||||
* @param item ItemStack that should get the new NBT data
|
||||
*/
|
||||
public void applyNBT(ItemStack item) {
|
||||
if (item == null || item.getType() == Material.AIR) {
|
||||
throw new NullPointerException("ItemStack can't be null/Air!");
|
||||
}
|
||||
NBTItem nbti = new NBTItem(new ItemStack(item.getType()));
|
||||
nbti.mergeCompound(this);
|
||||
item.setItemMeta(nbti.getItem().getItemMeta());
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge all NBT tags to the provided ItemStack.
|
||||
*
|
||||
* @param item ItemStack that should get the new NBT data
|
||||
*/
|
||||
public void mergeNBT(ItemStack item) {
|
||||
NBTItem nbti = new NBTItem(item);
|
||||
nbti.mergeCompound(this);
|
||||
item.setItemMeta(nbti.getItem().getItemMeta());
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge only custom (non-vanilla) NBT tags to the provided ItemStack.
|
||||
*
|
||||
* @param item ItemStack that should get the new NBT data
|
||||
*/
|
||||
public void mergeCustomNBT(ItemStack item) {
|
||||
if (item == null || item.getType() == Material.AIR) {
|
||||
throw new NullPointerException("ItemStack can't be null/Air!");
|
||||
}
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
NBTReflectionUtil.getUnhandledNBTTags(meta).putAll(NBTReflectionUtil.getUnhandledNBTTags(bukkitItem.getItemMeta()));
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all custom (non-vanilla) NBT tags from the NBTItem.
|
||||
*/
|
||||
public void clearCustomNBT() {
|
||||
ItemMeta meta = bukkitItem.getItemMeta();
|
||||
NBTReflectionUtil.getUnhandledNBTTags(meta).clear();
|
||||
bukkitItem.setItemMeta(meta);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The modified ItemStack
|
||||
*/
|
||||
@ -83,4 +155,11 @@ public class NBTItem extends NBTCompound {
|
||||
NBTReflectionUtil.convertNBTCompoundtoNMSItem(comp));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveCompound() {
|
||||
if(directApply) {
|
||||
applyNBT(originalSrcStack);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ public abstract class NBTList<T> implements List<T> {
|
||||
@Override
|
||||
public boolean add(T element) {
|
||||
try {
|
||||
parent.getWriteLock().lock();
|
||||
if (MinecraftVersion.getVersion().getVersionId() >= MinecraftVersion.MC1_14_R1.getVersionId()) {
|
||||
ReflectionMethod.LIST_ADD.run(listObject, size(), asTag(element));
|
||||
} else {
|
||||
@ -64,12 +65,15 @@ public abstract class NBTList<T> implements List<T> {
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
throw new NbtApiException(ex);
|
||||
} finally {
|
||||
parent.getWriteLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, T element) {
|
||||
try {
|
||||
parent.getWriteLock().lock();
|
||||
if (MinecraftVersion.getVersion().getVersionId() >= MinecraftVersion.MC1_14_R1.getVersionId()) {
|
||||
ReflectionMethod.LIST_ADD.run(listObject, index, asTag(element));
|
||||
} else {
|
||||
@ -78,37 +82,48 @@ public abstract class NBTList<T> implements List<T> {
|
||||
save();
|
||||
} catch (Exception ex) {
|
||||
throw new NbtApiException(ex);
|
||||
} finally {
|
||||
parent.getWriteLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T set(int index, T element) {
|
||||
try {
|
||||
parent.getWriteLock().lock();
|
||||
T prev = get(index);
|
||||
ReflectionMethod.LIST_SET.run(listObject, index, asTag(element));
|
||||
save();
|
||||
return prev;
|
||||
} catch (Exception ex) {
|
||||
throw new NbtApiException(ex);
|
||||
} finally {
|
||||
parent.getWriteLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public T remove(int i) {
|
||||
try {
|
||||
parent.getWriteLock().lock();
|
||||
T old = get(i);
|
||||
ReflectionMethod.LIST_REMOVE_KEY.run(listObject, i);
|
||||
save();
|
||||
return old;
|
||||
} catch (Exception ex) {
|
||||
throw new NbtApiException(ex);
|
||||
} finally {
|
||||
parent.getWriteLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public int size() {
|
||||
try {
|
||||
parent.getReadLock().lock();
|
||||
return (int) ReflectionMethod.LIST_SIZE.run(listObject);
|
||||
} catch (Exception ex) {
|
||||
throw new NbtApiException(ex);
|
||||
} finally {
|
||||
parent.getReadLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,70 +148,107 @@ public abstract class NBTList<T> implements List<T> {
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
try {
|
||||
parent.getReadLock().lock();
|
||||
for (int i = 0; i < size(); i++) {
|
||||
if (o.equals(get(i)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} finally {
|
||||
parent.getReadLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(Object o) {
|
||||
try {
|
||||
parent.getReadLock().lock();
|
||||
for (int i = 0; i < size(); i++) {
|
||||
if (o.equals(get(i)))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
} finally {
|
||||
parent.getReadLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends T> c) {
|
||||
try {
|
||||
parent.getWriteLock().lock();
|
||||
int size = size();
|
||||
for (T ele : c) {
|
||||
add(ele);
|
||||
}
|
||||
return size != size();
|
||||
} finally {
|
||||
parent.getWriteLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(int index, Collection<? extends T> c) {
|
||||
try {
|
||||
parent.getWriteLock().lock();
|
||||
int size = size();
|
||||
for (T ele : c) {
|
||||
add(index++, ele);
|
||||
}
|
||||
return size != size();
|
||||
} finally {
|
||||
parent.getWriteLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
try {
|
||||
parent.getReadLock().lock();
|
||||
for (Object ele : c) {
|
||||
if (!contains(ele))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} finally {
|
||||
parent.getReadLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lastIndexOf(Object o) {
|
||||
try {
|
||||
parent.getReadLock().lock();
|
||||
int index = -1;
|
||||
for (int i = 0; i < size(); i++) {
|
||||
if (o.equals(get(i)))
|
||||
index = i;
|
||||
}
|
||||
return index;
|
||||
} finally {
|
||||
parent.getReadLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> c) {
|
||||
try {
|
||||
parent.getWriteLock().lock();
|
||||
int size = size();
|
||||
for (Object obj : c) {
|
||||
remove(obj);
|
||||
}
|
||||
return size != size();
|
||||
} finally {
|
||||
parent.getWriteLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> c) {
|
||||
try {
|
||||
parent.getWriteLock().lock();
|
||||
int size = size();
|
||||
for (Object obj : c) {
|
||||
for (int i = 0; i < size(); i++) {
|
||||
@ -206,23 +258,31 @@ public abstract class NBTList<T> implements List<T> {
|
||||
}
|
||||
}
|
||||
return size != size();
|
||||
} finally {
|
||||
parent.getWriteLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
try {
|
||||
parent.getWriteLock().lock();
|
||||
int size = size();
|
||||
int id = -1;
|
||||
while ((id = indexOf(o)) != -1) {
|
||||
remove(id);
|
||||
}
|
||||
return size != size();
|
||||
} finally {
|
||||
parent.getWriteLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return new Iterator<T>() {
|
||||
|
||||
private int index = 0;
|
||||
private int index = -1;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
@ -235,6 +295,12 @@ public abstract class NBTList<T> implements List<T> {
|
||||
throw new NoSuchElementException();
|
||||
return get(++index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
NBTList.this.remove(index);
|
||||
index--;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -248,7 +314,7 @@ public abstract class NBTList<T> implements List<T> {
|
||||
final NBTList<T> list = this;
|
||||
return new ListIterator<T>() {
|
||||
|
||||
int index = startIndex;
|
||||
int index = startIndex - 1;
|
||||
|
||||
@Override
|
||||
public void add(T e) {
|
||||
@ -262,7 +328,7 @@ public abstract class NBTList<T> implements List<T> {
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return index > 0;
|
||||
return index >= 0 && index <= size();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -279,7 +345,9 @@ public abstract class NBTList<T> implements List<T> {
|
||||
|
||||
@Override
|
||||
public T previous() {
|
||||
return get(--index);
|
||||
if (!hasPrevious())
|
||||
throw new NoSuchElementException("Id: " + (index - 1));
|
||||
return get(index--);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -290,6 +358,7 @@ public abstract class NBTList<T> implements List<T> {
|
||||
@Override
|
||||
public void remove() {
|
||||
list.remove(index);
|
||||
index--;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -301,15 +370,22 @@ public abstract class NBTList<T> implements List<T> {
|
||||
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
try {
|
||||
parent.getReadLock().lock();
|
||||
Object[] ar = new Object[size()];
|
||||
for (int i = 0; i < size(); i++)
|
||||
ar[i] = get(i);
|
||||
return ar;
|
||||
} finally {
|
||||
parent.getReadLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <E> E[] toArray(E[] a) {
|
||||
try {
|
||||
parent.getReadLock().lock();
|
||||
E[] ar = Arrays.copyOf(a, size());
|
||||
Arrays.fill(ar, null);
|
||||
Class<?> arrayclass = a.getClass().getComponentType();
|
||||
@ -322,14 +398,32 @@ public abstract class NBTList<T> implements List<T> {
|
||||
}
|
||||
}
|
||||
return ar;
|
||||
} finally {
|
||||
parent.getReadLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> subList(int fromIndex, int toIndex) {
|
||||
try {
|
||||
parent.getReadLock().lock();
|
||||
ArrayList<T> list = new ArrayList<>();
|
||||
for (int i = fromIndex; i < toIndex; i++)
|
||||
list.add(get(i));
|
||||
return list;
|
||||
} finally {
|
||||
parent.getReadLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
try {
|
||||
parent.getReadLock().lock();
|
||||
return listObject.toString();
|
||||
} finally {
|
||||
parent.getReadLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,45 @@
|
||||
package com.songoda.epicenchants.utils.itemnbtapi;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.utils.nmsmappings.ClassWrapper;
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.utils.nmsmappings.ReflectionMethod;
|
||||
|
||||
/**
|
||||
* Long implementation for NBTLists
|
||||
*
|
||||
* @author tr7zw
|
||||
*
|
||||
*/
|
||||
public class NBTLongList extends NBTList<Long> {
|
||||
|
||||
protected NBTLongList(NBTCompound owner, String name, NBTType type, Object list) {
|
||||
super(owner, name, type, list);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object asTag(Long object) {
|
||||
try {
|
||||
Constructor<?> con = ClassWrapper.NMS_NBTTAGLONG.getClazz().getDeclaredConstructor(long.class);
|
||||
con.setAccessible(true);
|
||||
return con.newInstance(object);
|
||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
|
||||
| NoSuchMethodException | SecurityException e) {
|
||||
throw new NbtApiException("Error while wrapping the Object " + object + " to it's NMS object!", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long get(int index) {
|
||||
try {
|
||||
Object obj = ReflectionMethod.LIST_GET.run(listObject, index);
|
||||
return Long.valueOf(obj.toString().replace("L", ""));
|
||||
} catch (NumberFormatException nf) {
|
||||
return 0l;
|
||||
} catch (Exception ex) {
|
||||
throw new NbtApiException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +1,17 @@
|
||||
package com.songoda.epicenchants.utils.itemnbtapi;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.utils.GsonWrapper;
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.utils.MinecraftVersion;
|
||||
@ -25,6 +28,17 @@ import com.songoda.epicenchants.utils.itemnbtapi.utils.nmsmappings.ReflectionMet
|
||||
*/
|
||||
public class NBTReflectionUtil {
|
||||
|
||||
private static Field field_unhandledTags = null;
|
||||
|
||||
static {
|
||||
try {
|
||||
field_unhandledTags = ClassWrapper.CRAFT_METAITEM.getClazz().getDeclaredField("unhandledTags");
|
||||
field_unhandledTags.setAccessible(true);
|
||||
} catch (NoSuchFieldException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hidden constructor
|
||||
*/
|
||||
@ -47,12 +61,12 @@ public class NBTReflectionUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads in a FileInputStream as NMS Compound
|
||||
* Reads in a InputStream as NMS Compound
|
||||
*
|
||||
* @param stream InputStream of any NBT file
|
||||
* @return NMS Compound
|
||||
*/
|
||||
public static Object readNBTFile(FileInputStream stream) {
|
||||
public static Object readNBT(InputStream stream) {
|
||||
try {
|
||||
return ReflectionMethod.NBTFILE_READ.run(null, stream);
|
||||
} catch (Exception e) {
|
||||
@ -61,17 +75,38 @@ public class NBTReflectionUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a NMS Compound to a FileOutputStream
|
||||
* Writes a NMS Compound to an OutputStream
|
||||
*
|
||||
* @param nbt NMS Compound
|
||||
* @param stream Stream to write to
|
||||
* @return ???
|
||||
*/
|
||||
public static Object saveNBTFile(Object nbt, FileOutputStream stream) {
|
||||
public static Object writeNBT(Object nbt, OutputStream stream) {
|
||||
try {
|
||||
return ReflectionMethod.NBTFILE_WRITE.run(null, nbt, stream);
|
||||
} catch (Exception e) {
|
||||
throw new NbtApiException("Exception while saving a NBT File!", e);
|
||||
throw new NbtApiException("Exception while writing NBT!", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a Compound to an OutputStream
|
||||
*
|
||||
* @param comp Compound
|
||||
* @param stream Stream to write to
|
||||
*/
|
||||
public static void writeApiNBT(NBTCompound comp, OutputStream stream) {
|
||||
try {
|
||||
Object nbttag = comp.getCompound();
|
||||
if (nbttag == null) {
|
||||
nbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
|
||||
}
|
||||
if (!valideCompound(comp))
|
||||
return;
|
||||
Object workingtag = gettoCompount(nbttag, comp);
|
||||
ReflectionMethod.NBTFILE_WRITE.run(null, workingtag, stream);
|
||||
} catch (Exception e) {
|
||||
throw new NbtApiException("Exception while writing NBT!", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,10 +134,11 @@ public class NBTReflectionUtil {
|
||||
*/
|
||||
public static Object convertNBTCompoundtoNMSItem(NBTCompound nbtcompound) {
|
||||
try {
|
||||
Object nmsComp = gettoCompount(nbtcompound.getCompound(), nbtcompound);
|
||||
if (MinecraftVersion.getVersion().getVersionId() >= MinecraftVersion.MC1_11_R1.getVersionId()) {
|
||||
return ObjectCreator.NMS_COMPOUNDFROMITEM.getInstance(nbtcompound.getCompound());
|
||||
return ObjectCreator.NMS_COMPOUNDFROMITEM.getInstance(nmsComp);
|
||||
} else {
|
||||
return ReflectionMethod.NMSITEM_CREATESTACK.run(null, nbtcompound.getCompound());
|
||||
return ReflectionMethod.NMSITEM_CREATESTACK.run(null, nmsComp);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new NbtApiException("Exception while converting NBTCompound to NMS ItemStack!", e);
|
||||
@ -124,6 +160,21 @@ public class NBTReflectionUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a live copy of non-vanilla NBT tags.
|
||||
*
|
||||
* @param meta ItemMeta from which tags should be retrieved
|
||||
* @return Map containing unhandled (custom) NBT tags
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Map<String, Object> getUnhandledNBTTags(ItemMeta meta) {
|
||||
try {
|
||||
return (Map<String, Object>) field_unhandledTags.get(meta);
|
||||
} catch (Exception e) {
|
||||
throw new NbtApiException("Exception while getting unhandled tags from ItemMeta!", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Vanilla NBT Compound from a given NMS Entity
|
||||
*
|
||||
@ -166,10 +217,15 @@ public class NBTReflectionUtil {
|
||||
*/
|
||||
public static Object getTileEntityNBTTagCompound(BlockState tile) {
|
||||
try {
|
||||
Object pos = ObjectCreator.NMS_BLOCKPOSITION.getInstance(tile.getX(), tile.getY(), tile.getZ());
|
||||
Object cworld = ClassWrapper.CRAFT_WORLD.getClazz().cast(tile.getWorld());
|
||||
Object nmsworld = ReflectionMethod.CRAFT_WORLD_GET_HANDLE.run(cworld);
|
||||
Object o = ReflectionMethod.NMS_WORLD_GET_TILEENTITY.run(nmsworld, pos);
|
||||
Object o = null;
|
||||
if(MinecraftVersion.getVersion() == MinecraftVersion.MC1_7_R4) {
|
||||
o = ReflectionMethod.NMS_WORLD_GET_TILEENTITY_1_7_10.run(nmsworld, tile.getX(), tile.getY(), tile.getZ());
|
||||
}else {
|
||||
Object pos = ObjectCreator.NMS_BLOCKPOSITION.getInstance(tile.getX(), tile.getY(), tile.getZ());
|
||||
o = ReflectionMethod.NMS_WORLD_GET_TILEENTITY.run(nmsworld, pos);
|
||||
}
|
||||
Object tag = ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz().newInstance();
|
||||
Object answer = ReflectionMethod.TILEENTITY_GET_NBT.run(o, tag);
|
||||
if (answer == null)
|
||||
@ -188,11 +244,21 @@ public class NBTReflectionUtil {
|
||||
*/
|
||||
public static void setTileEntityNBTTagCompound(BlockState tile, Object comp) {
|
||||
try {
|
||||
Object pos = ObjectCreator.NMS_BLOCKPOSITION.getInstance(tile.getX(), tile.getY(), tile.getZ());
|
||||
Object cworld = ClassWrapper.CRAFT_WORLD.getClazz().cast(tile.getWorld());
|
||||
Object nmsworld = ReflectionMethod.CRAFT_WORLD_GET_HANDLE.run(cworld);
|
||||
Object o = ReflectionMethod.NMS_WORLD_GET_TILEENTITY.run(nmsworld, pos);
|
||||
ReflectionMethod.TILEENTITY_SET_NBT.run(o, comp);
|
||||
Object o = null;
|
||||
if(MinecraftVersion.getVersion() == MinecraftVersion.MC1_7_R4) {
|
||||
o = ReflectionMethod.NMS_WORLD_GET_TILEENTITY_1_7_10.run(nmsworld, tile.getX(), tile.getY(), tile.getZ());
|
||||
}else {
|
||||
Object pos = ObjectCreator.NMS_BLOCKPOSITION.getInstance(tile.getX(), tile.getY(), tile.getZ());
|
||||
o = ReflectionMethod.NMS_WORLD_GET_TILEENTITY.run(nmsworld, pos);
|
||||
}
|
||||
if(MinecraftVersion.getVersion().getVersionId() >= MinecraftVersion.MC1_16_R1.getVersionId()) {
|
||||
Object blockData = ReflectionMethod.TILEENTITY_GET_BLOCKDATA.run(o);
|
||||
ReflectionMethod.TILEENTITY_SET_NBT.run(o, blockData, comp);
|
||||
}else {
|
||||
ReflectionMethod.TILEENTITY_SET_NBT_LEGACY1151.run(o, comp);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new NbtApiException("Exception while setting NBTData for a TileEntity!", e);
|
||||
}
|
||||
@ -232,8 +298,9 @@ public class NBTReflectionUtil {
|
||||
if (nbttag == null) {
|
||||
nbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
|
||||
}
|
||||
if (!valideCompound(comp))
|
||||
if (!valideCompound(comp)) {
|
||||
return;
|
||||
}
|
||||
Object workingtag = gettoCompount(nbttag, comp);
|
||||
try {
|
||||
ReflectionMethod.COMPOUND_SET.run(workingtag, name,
|
||||
@ -278,9 +345,9 @@ public class NBTReflectionUtil {
|
||||
* Merges the second {@link NBTCompound} into the first one
|
||||
*
|
||||
* @param comp Target for the merge
|
||||
* @param nbtcompound Data to merge
|
||||
* @param nbtcompoundSrc Data to merge
|
||||
*/
|
||||
public static void mergeOtherNBTCompound(NBTCompound comp, NBTCompound nbtcompound) {
|
||||
public static void mergeOtherNBTCompound(NBTCompound comp, NBTCompound nbtcompoundSrc) {
|
||||
Object rootnbttag = comp.getCompound();
|
||||
if (rootnbttag == null) {
|
||||
rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
|
||||
@ -288,8 +355,15 @@ public class NBTReflectionUtil {
|
||||
if (!valideCompound(comp))
|
||||
throw new NbtApiException("The Compound wasn't able to be linked back to the root!");
|
||||
Object workingtag = gettoCompount(rootnbttag, comp);
|
||||
Object rootnbttagSrc = nbtcompoundSrc.getCompound();
|
||||
if (rootnbttagSrc == null) {
|
||||
rootnbttagSrc = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
|
||||
}
|
||||
if (!valideCompound(nbtcompoundSrc))
|
||||
throw new NbtApiException("The Compound wasn't able to be linked back to the root!");
|
||||
Object workingtagSrc = gettoCompount(rootnbttagSrc, nbtcompoundSrc);
|
||||
try {
|
||||
ReflectionMethod.COMPOUND_MERGE.run(workingtag, nbtcompound.getCompound());
|
||||
ReflectionMethod.COMPOUND_MERGE.run(workingtag, workingtagSrc);
|
||||
comp.setCompound(rootnbttag);
|
||||
} catch (Exception e) {
|
||||
throw new NbtApiException("Exception while merging two NBTCompounds!", e);
|
||||
@ -372,6 +446,12 @@ public class NBTReflectionUtil {
|
||||
return (NBTList<T>) new NBTCompoundList(comp, key, type, nbt);
|
||||
} else if (clazz == Integer.class) {
|
||||
return (NBTList<T>) new NBTIntegerList(comp, key, type, nbt);
|
||||
} else if (clazz == Float.class) {
|
||||
return (NBTList<T>) new NBTFloatList(comp, key, type, nbt);
|
||||
} else if (clazz == Double.class) {
|
||||
return (NBTList<T>) new NBTDoubleList(comp, key, type, nbt);
|
||||
} else if (clazz == Long.class) {
|
||||
return (NBTList<T>) new NBTLongList(comp, key, type, nbt);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -2,6 +2,10 @@ package com.songoda.epicenchants.utils.itemnbtapi;
|
||||
|
||||
import org.bukkit.block.BlockState;
|
||||
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.utils.MinecraftVersion;
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.utils.annotations.AvaliableSince;
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.utils.annotations.CheckUtil;
|
||||
|
||||
/**
|
||||
* NBT class to access vanilla tags from TileEntities. TileEntities don't
|
||||
* support custom tags. Use the NBTInjector for custom tags. Changes will be
|
||||
@ -20,6 +24,9 @@ public class NBTTileEntity extends NBTCompound {
|
||||
*/
|
||||
public NBTTileEntity(BlockState tile) {
|
||||
super(null, null);
|
||||
if (tile == null || (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_8_R3) && !tile.isPlaced())) {
|
||||
throw new NullPointerException("Tile can't be null/not placed!");
|
||||
}
|
||||
this.tile = tile;
|
||||
}
|
||||
|
||||
@ -33,4 +40,23 @@ public class NBTTileEntity extends NBTCompound {
|
||||
NBTReflectionUtil.setTileEntityNBTTagCompound(tile, compound);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the NBTCompound used by spigots PersistentDataAPI. This method is only
|
||||
* available for 1.14+!
|
||||
*
|
||||
* @return NBTCompound containing the data of the PersistentDataAPI
|
||||
*/
|
||||
@AvaliableSince(version = MinecraftVersion.MC1_14_R1)
|
||||
public NBTCompound getPersistentDataContainer() {
|
||||
if (hasKey("PublicBukkitValues")) {
|
||||
return getCompound("PublicBukkitValues");
|
||||
} else {
|
||||
NBTContainer container = new NBTContainer();
|
||||
container.addCompound("PublicBukkitValues").setString("__nbtapi",
|
||||
"Marker to make the PersistentDataContainer have content");
|
||||
mergeCompound(container);
|
||||
return getCompound("PublicBukkitValues");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -34,8 +34,6 @@ import static com.songoda.epicenchants.utils.itemnbtapi.utils.MinecraftVersion.l
|
||||
public class ApiMetricsLite {
|
||||
|
||||
private static final String PLUGINNAME = "ItemNBTAPI"; // DO NOT CHANGE THE NAME! else it won't link the data on bStats
|
||||
private static final String PLUGINVERSION = "2.2.0-SNAPSHOT"; // In case you fork the nbt-api for internal use in your network, plugins and so on, you *may* add that to the version here. (2.x.x-Timolia or something like that?)
|
||||
// Not sure how good of an idea that is, so maybe just leave it as is ¯\_(ツ)_/¯
|
||||
|
||||
// The version of this bStats class
|
||||
public static final int B_STATS_VERSION = 1;
|
||||
@ -132,13 +130,25 @@ public class ApiMetricsLite {
|
||||
break;
|
||||
} catch (NoSuchFieldException ignored) { }
|
||||
}
|
||||
boolean fFound = found;
|
||||
// Register our service
|
||||
if(Bukkit.isPrimaryThread()){
|
||||
Bukkit.getServicesManager().register(ApiMetricsLite.class, this, plugin, ServicePriority.Normal);
|
||||
if (!found) {
|
||||
if (!fFound) {
|
||||
logger.info("[NBTAPI] Using the plugin '" + plugin.getName() + "' to create a bStats instance!");
|
||||
// We are the first!
|
||||
startSubmitting();
|
||||
}
|
||||
}else{
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
Bukkit.getServicesManager().register(ApiMetricsLite.class, this, plugin, ServicePriority.Normal);
|
||||
if (!fFound) {
|
||||
logger.info("[NBTAPI] Using the plugin '" + plugin.getName() + "' to create a bStats instance!");
|
||||
// We are the first!
|
||||
startSubmitting();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -183,7 +193,7 @@ public class ApiMetricsLite {
|
||||
JsonObject data = new JsonObject();
|
||||
|
||||
data.addProperty("pluginName", PLUGINNAME); // Append the name of the plugin
|
||||
data.addProperty("pluginVersion", PLUGINVERSION); // Append the version of the plugin
|
||||
data.addProperty("pluginVersion", MinecraftVersion.VERSION); // Append the version of the plugin
|
||||
data.add("customCharts", new JsonArray());
|
||||
|
||||
return data;
|
||||
|
@ -16,27 +16,22 @@ import org.bukkit.Bukkit;
|
||||
@SuppressWarnings("javadoc")
|
||||
public enum MinecraftVersion {
|
||||
UNKNOWN(Integer.MAX_VALUE), // Use the newest known mappings
|
||||
MC1_7_R4(174),
|
||||
MC1_8_R3(183),
|
||||
MC1_9_R1(191),
|
||||
MC1_9_R2(192),
|
||||
MC1_10_R1(1101),
|
||||
MC1_11_R1(1111),
|
||||
MC1_12_R1(1121),
|
||||
MC1_13_R1(1131),
|
||||
MC1_13_R2(1132),
|
||||
MC1_14_R1(1141),
|
||||
MC1_15_R1(1151);
|
||||
MC1_7_R4(174), MC1_8_R3(183), MC1_9_R1(191), MC1_9_R2(192), MC1_10_R1(1101), MC1_11_R1(1111), MC1_12_R1(1121),
|
||||
MC1_13_R1(1131), MC1_13_R2(1132), MC1_14_R1(1141), MC1_15_R1(1151), MC1_16_R1(1161);
|
||||
|
||||
private static MinecraftVersion version;
|
||||
private static Boolean hasGsonSupport;
|
||||
private static boolean bStatsDisabled = false;
|
||||
private static boolean disablePackageWarning = false;
|
||||
private static boolean updateCheckDisabled = false;
|
||||
/**
|
||||
* Logger used by the api
|
||||
*/
|
||||
public static final Logger logger = Logger.getLogger("NBTAPI");
|
||||
|
||||
// NBT-API Version
|
||||
protected static final String VERSION = "2.5.0-SNAPSHOT";
|
||||
|
||||
private final int versionId;
|
||||
|
||||
MinecraftVersion(int versionId) {
|
||||
@ -50,6 +45,16 @@ public enum MinecraftVersion {
|
||||
return versionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the current versions is at least the given Version
|
||||
*
|
||||
* @param version The minimum version
|
||||
* @return
|
||||
*/
|
||||
public static boolean isAtLeastVersion(MinecraftVersion version) {
|
||||
return getVersion().getVersionId() >= version.getVersionId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for this servers MinecraftVersion. Also init's bStats and checks the
|
||||
* shading.
|
||||
@ -78,11 +83,20 @@ public enum MinecraftVersion {
|
||||
|
||||
private static void init() {
|
||||
try {
|
||||
if (!bStatsDisabled)
|
||||
if (hasGsonSupport() && !bStatsDisabled)
|
||||
new ApiMetricsLite();
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.WARNING, "[NBTAPI] Error enabeling Metrics!", ex);
|
||||
logger.log(Level.WARNING, "[NBTAPI] Error enabling Metrics!", ex);
|
||||
}
|
||||
|
||||
if (hasGsonSupport() && !updateCheckDisabled)
|
||||
new Thread(() -> {
|
||||
try {
|
||||
VersionChecker.checkForUpdates();
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.WARNING, "[NBTAPI] Error while checking for updates!", ex);
|
||||
}
|
||||
}).start();
|
||||
// Maven's Relocate is clever and changes strings, too. So we have to use this
|
||||
// little "trick" ... :D (from bStats)
|
||||
final String defaultPackage = new String(new byte[] { 'd', 'e', '.', 't', 'r', '7', 'z', 'w', '.', 'c', 'h',
|
||||
@ -128,6 +142,14 @@ public enum MinecraftVersion {
|
||||
bStatsDisabled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the update check. Uses Spiget to get the current version and prints
|
||||
* a warning when outdated.
|
||||
*/
|
||||
public static void disableUpdateCheck() {
|
||||
updateCheckDisabled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forcefully disables the log message for plugins not shading the API to
|
||||
* another location. This may be helpful for networks or development
|
||||
|
@ -0,0 +1,106 @@
|
||||
package com.songoda.epicenchants.utils.itemnbtapi.utils;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.NBTItem;
|
||||
|
||||
/**
|
||||
* This class uses the Spiget API to check for updates
|
||||
*
|
||||
*/
|
||||
public class VersionChecker {
|
||||
|
||||
private static final String USER_AGENT = "nbt-api Version check";
|
||||
private static final String REQUEST_URL = "https://api.spiget.org/v2/resources/7939/versions?size=100";
|
||||
|
||||
protected static void checkForUpdates() throws Exception {
|
||||
URL url = new URL(REQUEST_URL);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.addRequestProperty("User-Agent", USER_AGENT);// Set
|
||||
// User-Agent
|
||||
|
||||
// If you're not sure if the request will be successful,
|
||||
// you need to check the response code and use #getErrorStream if it
|
||||
// returned an error code
|
||||
InputStream inputStream = connection.getInputStream();
|
||||
InputStreamReader reader = new InputStreamReader(inputStream);
|
||||
|
||||
// This could be either a JsonArray or JsonObject
|
||||
JsonElement element = new JsonParser().parse(reader);
|
||||
if (element.isJsonArray()) {
|
||||
// Is JsonArray
|
||||
JsonArray updates = (JsonArray) element;
|
||||
JsonObject latest = (JsonObject) updates.get(updates.size() - 1);
|
||||
int versionDifference = getVersionDifference(latest.get("name").getAsString());
|
||||
if (versionDifference == -1) { // Outdated
|
||||
MinecraftVersion.logger.log(Level.WARNING,
|
||||
"[NBTAPI] The NBT-API at '" + NBTItem.class.getPackage() + "' seems to be outdated!");
|
||||
MinecraftVersion.logger.log(Level.WARNING, "[NBTAPI] Current Version: '" + MinecraftVersion.VERSION
|
||||
+ "' Newest Version: " + latest.get("name").getAsString() + "'");
|
||||
MinecraftVersion.logger.log(Level.WARNING,
|
||||
"[NBTAPI] Please update the nbt-api or the plugin that contains the api!");
|
||||
|
||||
} else if (versionDifference == 0) {
|
||||
MinecraftVersion.logger.log(Level.INFO, "[NBTAPI] The NBT-API seems to be up-to-date!");
|
||||
} else if (versionDifference == 1) {
|
||||
MinecraftVersion.logger.log(Level.WARNING, "[NBTAPI] The NBT-API at '" + NBTItem.class.getPackage()
|
||||
+ "' seems to be a future Version, not yet released on Spigot!");
|
||||
MinecraftVersion.logger.log(Level.WARNING, "[NBTAPI] Current Version: '" + MinecraftVersion.VERSION
|
||||
+ "' Newest Version: " + latest.get("name").getAsString() + "'");
|
||||
}
|
||||
} else {
|
||||
// wut?!
|
||||
MinecraftVersion.logger.log(Level.WARNING,
|
||||
"[NBTAPI] Error when looking for Updates! Got non Json Array: '" + element.toString() + "'");
|
||||
}
|
||||
}
|
||||
|
||||
// -1 = we are outdated
|
||||
// 0 = up to date
|
||||
// 1 = using a future version
|
||||
// This method is only able to compare the Format 0.0.0(-SNAPSHOT)
|
||||
private static int getVersionDifference(String version) {
|
||||
String current = MinecraftVersion.VERSION;
|
||||
if (current.equals(version))
|
||||
return 0;
|
||||
String pattern = "\\.";
|
||||
if (current.split(pattern).length != 3 || version.split(pattern).length != 3)
|
||||
return -1;
|
||||
int curMaj = Integer.parseInt(current.split(pattern)[0]);
|
||||
int curMin = Integer.parseInt(current.split(pattern)[1]);
|
||||
String curPatch = current.split(pattern)[2];
|
||||
int relMaj = Integer.parseInt(version.split(pattern)[0]);
|
||||
int relMin = Integer.parseInt(version.split(pattern)[1]);
|
||||
String relPatch = version.split(pattern)[2];
|
||||
if (curMaj < relMaj)
|
||||
return -1;
|
||||
if (curMaj > relMaj)
|
||||
return 1;
|
||||
if (curMin < relMin)
|
||||
return -1;
|
||||
if (curMin > relMin)
|
||||
return 1;
|
||||
int curPatchN = Integer.parseInt(curPatch.split("-")[0]);
|
||||
int relPatchN = Integer.parseInt(relPatch.split("-")[0]);
|
||||
if (curPatchN < relPatchN)
|
||||
return -1;
|
||||
if (curPatchN > relPatchN)
|
||||
return 1;
|
||||
if (!relPatch.contains("-") && curPatch.contains("-"))
|
||||
return -1; // Release has no - but we do = We use a Snapshot of the
|
||||
// release
|
||||
if (relPatch.contains("-") && curPatch.contains("-"))
|
||||
return 0; // Release and cur are Snapshots/alpha/beta
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.songoda.epicenchants.utils.itemnbtapi.utils.annotations;
|
||||
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.utils.MinecraftVersion;
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target({ METHOD })
|
||||
public @interface AvaliableSince {
|
||||
|
||||
MinecraftVersion version();
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.songoda.epicenchants.utils.itemnbtapi.utils.annotations;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.NbtApiException;
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.utils.MinecraftVersion;
|
||||
|
||||
public class CheckUtil {
|
||||
|
||||
public static boolean isAvaliable(Method method) {
|
||||
if(MinecraftVersion.getVersion().getVersionId() < method.getAnnotation(AvaliableSince.class).version().getVersionId())
|
||||
throw new NbtApiException("The Method '" + method.getName() + "' is only avaliable for the Versions " + method.getAnnotation(AvaliableSince.class).version() + "+, but still got called!");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -15,18 +15,22 @@ import static com.songoda.epicenchants.utils.itemnbtapi.utils.MinecraftVersion.l
|
||||
@SuppressWarnings("javadoc")
|
||||
public enum ClassWrapper {
|
||||
CRAFT_ITEMSTACK(PackageWrapper.CRAFTBUKKIT, "inventory.CraftItemStack"),
|
||||
CRAFT_METAITEM(PackageWrapper.CRAFTBUKKIT, "inventory.CraftMetaItem"),
|
||||
CRAFT_ENTITY(PackageWrapper.CRAFTBUKKIT, "entity.CraftEntity"),
|
||||
CRAFT_WORLD(PackageWrapper.CRAFTBUKKIT, "CraftWorld"),
|
||||
NMS_NBTBASE(PackageWrapper.NMS, "NBTBase"),
|
||||
NMS_NBTTAGSTRING(PackageWrapper.NMS, "NBTTagString"),
|
||||
NMS_NBTTAGINT(PackageWrapper.NMS, "NBTTagInt"),
|
||||
NMS_NBTTAGFLOAT(PackageWrapper.NMS, "NBTTagFloat"),
|
||||
NMS_NBTTAGDOUBLE(PackageWrapper.NMS, "NBTTagDouble"),
|
||||
NMS_NBTTAGLONG(PackageWrapper.NMS, "NBTTagLong"),
|
||||
NMS_ITEMSTACK(PackageWrapper.NMS, "ItemStack"),
|
||||
NMS_NBTTAGCOMPOUND(PackageWrapper.NMS, "NBTTagCompound"),
|
||||
NMS_NBTTAGLIST(PackageWrapper.NMS, "NBTTagList"),
|
||||
NMS_NBTCOMPRESSEDSTREAMTOOLS(PackageWrapper.NMS, "NBTCompressedStreamTools"),
|
||||
NMS_MOJANGSONPARSER(PackageWrapper.NMS, "MojangsonParser"),
|
||||
NMS_TILEENTITY(PackageWrapper.NMS, "TileEntity"),
|
||||
NMS_BLOCKPOSITION(PackageWrapper.NMS, "BlockPosition"),
|
||||
NMS_BLOCKPOSITION(PackageWrapper.NMS, "BlockPosition", MinecraftVersion.MC1_8_R3, null),
|
||||
NMS_WORLDSERVER(PackageWrapper.NMS, "WorldServer"),
|
||||
NMS_MINECRAFTSERVER(PackageWrapper.NMS, "MinecraftServer"),
|
||||
NMS_WORLD(PackageWrapper.NMS, "World"),
|
||||
@ -35,7 +39,11 @@ NMS_ENTITYTYPES(PackageWrapper.NMS, "EntityTypes"),
|
||||
NMS_REGISTRYSIMPLE(PackageWrapper.NMS, "RegistrySimple", MinecraftVersion.MC1_11_R1, MinecraftVersion.MC1_12_R1),
|
||||
NMS_REGISTRYMATERIALS(PackageWrapper.NMS, "RegistryMaterials"),
|
||||
NMS_IREGISTRY(PackageWrapper.NMS, "IRegistry"),
|
||||
NMS_MINECRAFTKEY(PackageWrapper.NMS, "MinecraftKey");
|
||||
NMS_MINECRAFTKEY(PackageWrapper.NMS, "MinecraftKey", MinecraftVersion.MC1_8_R3, null),
|
||||
NMS_GAMEPROFILESERIALIZER(PackageWrapper.NMS, "GameProfileSerializer"),
|
||||
NMS_IBLOCKDATA(PackageWrapper.NMS, "IBlockData", MinecraftVersion.MC1_8_R3, null),
|
||||
GAMEPROFILE("com.mojang.authlib.GameProfile", MinecraftVersion.MC1_8_R3)
|
||||
;
|
||||
|
||||
private Class<?> clazz;
|
||||
private boolean enabled = false;
|
||||
@ -60,6 +68,18 @@ NMS_MINECRAFTKEY(PackageWrapper.NMS, "MinecraftKey");
|
||||
}
|
||||
}
|
||||
|
||||
ClassWrapper(String path, MinecraftVersion from){
|
||||
if(from != null && MinecraftVersion.getVersion().getVersionId() < from.getVersionId()) {
|
||||
return;
|
||||
}
|
||||
enabled = true;
|
||||
try{
|
||||
clazz = Class.forName(path);
|
||||
}catch(Exception ex){
|
||||
logger.log(Level.WARNING, "[NBTAPI] Error while trying to resolve the class '" + path + "'!", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The wrapped class
|
||||
*/
|
||||
|
@ -18,13 +18,14 @@ import static com.songoda.epicenchants.utils.itemnbtapi.utils.MinecraftVersion.l
|
||||
public enum ObjectCreator {
|
||||
NMS_NBTTAGCOMPOUND(null, null, ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()),
|
||||
NMS_BLOCKPOSITION(null, null, ClassWrapper.NMS_BLOCKPOSITION.getClazz(), int.class, int.class, int.class),
|
||||
NMS_COMPOUNDFROMITEM(MinecraftVersion.MC1_11_R1, null, ClassWrapper.NMS_ITEMSTACK.getClazz(), ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()),
|
||||
;
|
||||
NMS_COMPOUNDFROMITEM(MinecraftVersion.MC1_11_R1, null, ClassWrapper.NMS_ITEMSTACK.getClazz(), ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()),;
|
||||
|
||||
private Constructor<?> construct;
|
||||
private Class<?> targetClass;
|
||||
|
||||
ObjectCreator(MinecraftVersion from, MinecraftVersion to, Class<?> clazz, Class<?>... args) {
|
||||
if (clazz == null)
|
||||
return;
|
||||
if (from != null && MinecraftVersion.getVersion().getVersionId() < from.getVersionId())
|
||||
return;
|
||||
if (to != null && MinecraftVersion.getVersion().getVersionId() > to.getVersionId())
|
||||
|
@ -8,13 +8,13 @@ package com.songoda.epicenchants.utils.itemnbtapi.utils.nmsmappings;
|
||||
*/
|
||||
@SuppressWarnings("javadoc")
|
||||
public enum PackageWrapper {
|
||||
NMS("net.minecraft.server"),
|
||||
CRAFTBUKKIT("org.bukkit.craftbukkit"),
|
||||
NMS(new String(new byte[] {'n', 'e', 't', '.', 'm', 'i', 'n', 'e', 'c', 'r', 'a', 'f', 't', '.', 's', 'e', 'r', 'v', 'e', 'r'})),
|
||||
CRAFTBUKKIT(new String(new byte[] {'o', 'r', 'g', '.', 'b', 'u', 'k', 'k', 'i', 't', '.', 'c', 'r', 'a', 'f', 't', 'b', 'u', 'k', 'k', 'i', 't'})),
|
||||
;
|
||||
|
||||
private final String uri;
|
||||
|
||||
PackageWrapper(String uri) {
|
||||
private PackageWrapper(String uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,8 @@ package com.songoda.epicenchants.utils.itemnbtapi.utils.nmsmappings;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.NbtApiException;
|
||||
@ -27,10 +29,12 @@ public enum ReflectionMethod {
|
||||
COMPOUND_SET_BYTE(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, byte.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setByte")),
|
||||
COMPOUND_SET_DOUBLE(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, double.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setDouble")),
|
||||
COMPOUND_SET_BOOLEAN(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, boolean.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setBoolean")),
|
||||
COMPOUND_MERGE(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "a")), //FIXME: No Spigot mapping!
|
||||
COMPOUND_SET_UUID(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, UUID.class}, MinecraftVersion.MC1_16_R1, new Since(MinecraftVersion.MC1_16_R1, "a")),
|
||||
COMPOUND_MERGE(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "a")), //FIXME: No Spigot mapping!
|
||||
COMPOUND_SET(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, ClassWrapper.NMS_NBTBASE.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "set")),
|
||||
COMPOUND_GET(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "get")),
|
||||
COMPOUND_GET_LIST(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, int.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getList")),
|
||||
COMPOUND_OWN_TYPE(ClassWrapper.NMS_NBTBASE.getClazz(), new Class[]{}, MinecraftVersion.MC1_7_R4, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getTypeId")), // Only needed for 1.7.10 getType
|
||||
|
||||
COMPOUND_GET_FLOAT(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getFloat")),
|
||||
COMPOUND_GET_STRING(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getString")),
|
||||
@ -42,6 +46,7 @@ public enum ReflectionMethod {
|
||||
COMPOUND_GET_BYTE(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getByte")),
|
||||
COMPOUND_GET_DOUBLE(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getDouble")),
|
||||
COMPOUND_GET_BOOLEAN(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getBoolean")),
|
||||
COMPOUND_GET_UUID(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_16_R1, new Since(MinecraftVersion.MC1_16_R1, "a")),
|
||||
COMPOUND_GET_COMPOUND(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getCompound")),
|
||||
|
||||
NMSITEM_GETTAG(ClassWrapper.NMS_ITEMSTACK.getClazz(), new Class[] {}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getTag")),
|
||||
@ -50,45 +55,49 @@ public enum ReflectionMethod {
|
||||
|
||||
COMPOUND_REMOVE_KEY(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "remove")),
|
||||
COMPOUND_HAS_KEY(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "hasKey")),
|
||||
COMPOUND_GET_TYPE(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "b"), new Since(MinecraftVersion.MC1_9_R1, "d"), new Since(MinecraftVersion.MC1_15_R1, "e")), //FIXME: No Spigot mapping!
|
||||
COMPOUND_GET_TYPE(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "b"), new Since(MinecraftVersion.MC1_9_R1, "d"), new Since(MinecraftVersion.MC1_15_R1, "e"), new Since(MinecraftVersion.MC1_16_R1, "d")), //FIXME: No Spigot mapping!
|
||||
COMPOUND_GET_KEYS(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "c"), new Since(MinecraftVersion.MC1_13_R1, "getKeys")),
|
||||
|
||||
LISTCOMPOUND_GET_KEYS(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "c"), new Since(MinecraftVersion.MC1_13_R1, "getKeys")),
|
||||
LIST_REMOVE_KEY(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{int.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "a"), new Since(MinecraftVersion.MC1_9_R1, "remove")),
|
||||
LIST_REMOVE_KEY(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{int.class}, MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "a"), new Since(MinecraftVersion.MC1_9_R1, "remove")),
|
||||
LIST_SIZE(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "size")),
|
||||
LIST_SET(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{int.class, ClassWrapper.NMS_NBTBASE.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "a"), new Since(MinecraftVersion.MC1_13_R1, "set")),
|
||||
LIST_SET(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{int.class, ClassWrapper.NMS_NBTBASE.getClazz()}, MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "a"), new Since(MinecraftVersion.MC1_13_R1, "set")),
|
||||
LEGACY_LIST_ADD(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{ClassWrapper.NMS_NBTBASE.getClazz()}, MinecraftVersion.MC1_7_R4, MinecraftVersion.MC1_13_R2, new Since(MinecraftVersion.MC1_7_R4, "add")),
|
||||
LIST_ADD(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{int.class, ClassWrapper.NMS_NBTBASE.getClazz()}, MinecraftVersion.MC1_14_R1, new Since(MinecraftVersion.MC1_14_R1, "add")),
|
||||
LIST_GET_STRING(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{int.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getString")),
|
||||
LIST_GET_COMPOUND(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{int.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "get")),
|
||||
LIST_GET(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{int.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "g"), new Since(MinecraftVersion.MC1_9_R1, "h"), new Since(MinecraftVersion.MC1_12_R1, "i"), new Since(MinecraftVersion.MC1_13_R1, "get")),
|
||||
LIST_GET(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{int.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "get"), new Since(MinecraftVersion.MC1_8_R3, "g"), new Since(MinecraftVersion.MC1_9_R1, "h"), new Since(MinecraftVersion.MC1_12_R1, "i"), new Since(MinecraftVersion.MC1_13_R1, "get")),
|
||||
|
||||
ITEMSTACK_SET_TAG(ClassWrapper.NMS_ITEMSTACK.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setTag")),
|
||||
ITEMSTACK_NMSCOPY(ClassWrapper.CRAFT_ITEMSTACK.getClazz(), new Class[]{ItemStack.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "asNMSCopy")),
|
||||
ITEMSTACK_BUKKITMIRROR(ClassWrapper.CRAFT_ITEMSTACK.getClazz(), new Class[]{ClassWrapper.NMS_ITEMSTACK.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "asCraftMirror")),
|
||||
|
||||
CRAFT_WORLD_GET_HANDLE(ClassWrapper.CRAFT_WORLD.getClazz(), new Class[]{}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getHandle")),
|
||||
NMS_WORLD_GET_TILEENTITY(ClassWrapper.NMS_WORLDSERVER.getClazz(), new Class[]{ClassWrapper.NMS_BLOCKPOSITION.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getTileEntity")),
|
||||
NMS_WORLD_SET_TILEENTITY(ClassWrapper.NMS_WORLDSERVER.getClazz(), new Class[]{ClassWrapper.NMS_BLOCKPOSITION.getClazz(), ClassWrapper.NMS_TILEENTITY.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setTileEntity")),
|
||||
NMS_WORLD_REMOVE_TILEENTITY(ClassWrapper.NMS_WORLDSERVER.getClazz(), new Class[]{ClassWrapper.NMS_BLOCKPOSITION.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "t"), new Since(MinecraftVersion.MC1_9_R1, "s"), new Since(MinecraftVersion.MC1_13_R1, "n"), new Since(MinecraftVersion.MC1_14_R1, "removeTileEntity")),
|
||||
NMS_WORLD_GET_TILEENTITY(ClassWrapper.NMS_WORLDSERVER.getClazz(), new Class[]{ClassWrapper.NMS_BLOCKPOSITION.getClazz()}, MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "getTileEntity")),
|
||||
NMS_WORLD_SET_TILEENTITY(ClassWrapper.NMS_WORLDSERVER.getClazz(), new Class[]{ClassWrapper.NMS_BLOCKPOSITION.getClazz(), ClassWrapper.NMS_TILEENTITY.getClazz()}, MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "setTileEntity")),
|
||||
NMS_WORLD_REMOVE_TILEENTITY(ClassWrapper.NMS_WORLDSERVER.getClazz(), new Class[]{ClassWrapper.NMS_BLOCKPOSITION.getClazz()}, MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "t"), new Since(MinecraftVersion.MC1_9_R1, "s"), new Since(MinecraftVersion.MC1_13_R1, "n"), new Since(MinecraftVersion.MC1_14_R1, "removeTileEntity")),
|
||||
|
||||
NMS_WORLD_GET_TILEENTITY_1_7_10(ClassWrapper.NMS_WORLDSERVER.getClazz(), new Class[]{int.class, int.class, int.class}, MinecraftVersion.MC1_7_R4, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getTileEntity")),
|
||||
|
||||
TILEENTITY_LOAD_LEGACY191(ClassWrapper.NMS_TILEENTITY.getClazz(), new Class[]{ClassWrapper.NMS_MINECRAFTSERVER.getClazz(), ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_9_R1, MinecraftVersion.MC1_9_R1, new Since(MinecraftVersion.MC1_9_R1, "a")), //FIXME: No Spigot mapping!
|
||||
TILEENTITY_LOAD_LEGACY183(ClassWrapper.NMS_TILEENTITY.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_8_R3, MinecraftVersion.MC1_9_R2, new Since(MinecraftVersion.MC1_8_R3, "c"), new Since(MinecraftVersion.MC1_9_R1, "a"), new Since(MinecraftVersion.MC1_9_R2, "c")), //FIXME: No Spigot mapping!
|
||||
TILEENTITY_LOAD_LEGACY1121(ClassWrapper.NMS_TILEENTITY.getClazz(), new Class[]{ClassWrapper.NMS_WORLD.getClazz(), ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_10_R1, MinecraftVersion.MC1_12_R1, new Since(MinecraftVersion.MC1_10_R1, "a"), new Since(MinecraftVersion.MC1_12_R1, "create")),
|
||||
TILEENTITY_LOAD(ClassWrapper.NMS_TILEENTITY.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_13_R1, new Since(MinecraftVersion.MC1_12_R1, "create")),
|
||||
TILEENTITY_LOAD_LEGACY1151(ClassWrapper.NMS_TILEENTITY.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_13_R1, MinecraftVersion.MC1_15_R1, new Since(MinecraftVersion.MC1_12_R1, "create")),
|
||||
TILEENTITY_LOAD(ClassWrapper.NMS_TILEENTITY.getClazz(), new Class[]{ClassWrapper.NMS_IBLOCKDATA.getClazz(), ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_16_R1, new Since(MinecraftVersion.MC1_16_R1, "create")),
|
||||
|
||||
TILEENTITY_GET_NBT(ClassWrapper.NMS_TILEENTITY.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "b"), new Since(MinecraftVersion.MC1_9_R1, "save")),
|
||||
TILEENTITY_SET_NBT(ClassWrapper.NMS_TILEENTITY.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "a"), new Since(MinecraftVersion.MC1_12_R1, "load")),
|
||||
TILEENTITY_GET_NBT(ClassWrapper.NMS_TILEENTITY.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "b"), new Since(MinecraftVersion.MC1_9_R1, "save")),
|
||||
TILEENTITY_SET_NBT_LEGACY1151(ClassWrapper.NMS_TILEENTITY.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_7_R4, MinecraftVersion.MC1_15_R1, new Since(MinecraftVersion.MC1_7_R4, "a"), new Since(MinecraftVersion.MC1_12_R1, "load")),
|
||||
TILEENTITY_SET_NBT(ClassWrapper.NMS_TILEENTITY.getClazz(), new Class[]{ClassWrapper.NMS_IBLOCKDATA.getClazz(), ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_16_R1, new Since(MinecraftVersion.MC1_16_R1, "load")),
|
||||
TILEENTITY_GET_BLOCKDATA(ClassWrapper.NMS_TILEENTITY.getClazz(), new Class[]{}, MinecraftVersion.MC1_16_R1, new Since(MinecraftVersion.MC1_16_R1, "getBlock")),
|
||||
|
||||
CRAFT_ENTITY_GET_HANDLE(ClassWrapper.CRAFT_ENTITY.getClazz(), new Class[]{}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getHandle")),
|
||||
NMS_ENTITY_SET_NBT(ClassWrapper.NMS_ENTITY.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "f")), //FIXME: No Spigot mapping!
|
||||
NMS_ENTITY_GET_NBT(ClassWrapper.NMS_ENTITY.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "e"), new Since(MinecraftVersion.MC1_12_R1, "save")),
|
||||
NMS_ENTITY_SET_NBT(ClassWrapper.NMS_ENTITY.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "f"), new Since(MinecraftVersion.MC1_16_R1, "load")), //FIXME: No Spigot mapping!
|
||||
NMS_ENTITY_GET_NBT(ClassWrapper.NMS_ENTITY.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "e"), new Since(MinecraftVersion.MC1_12_R1, "save")),
|
||||
NMS_ENTITY_GETSAVEID(ClassWrapper.NMS_ENTITY.getClazz(), new Class[]{}, MinecraftVersion.MC1_14_R1,new Since(MinecraftVersion.MC1_14_R1, "getSaveID")),
|
||||
|
||||
NBTFILE_READ(ClassWrapper.NMS_NBTCOMPRESSEDSTREAMTOOLS.getClazz(), new Class[]{InputStream.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "a")), //FIXME: No Spigot mapping!
|
||||
NBTFILE_WRITE(ClassWrapper.NMS_NBTCOMPRESSEDSTREAMTOOLS.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), OutputStream.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "a")), //FIXME: No Spigot mapping!
|
||||
|
||||
|
||||
PARSE_NBT(ClassWrapper.NMS_MOJANGSONPARSER.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "parse")),
|
||||
REGISTRY_KEYSET (ClassWrapper.NMS_REGISTRYSIMPLE.getClazz(), new Class[]{}, MinecraftVersion.MC1_11_R1, MinecraftVersion.MC1_13_R1, new Since(MinecraftVersion.MC1_11_R1, "keySet")),
|
||||
REGISTRY_GET (ClassWrapper.NMS_REGISTRYSIMPLE.getClazz(), new Class[]{Object.class}, MinecraftVersion.MC1_11_R1, MinecraftVersion.MC1_13_R1, new Since(MinecraftVersion.MC1_11_R1, "get")),
|
||||
@ -96,9 +105,10 @@ public enum ReflectionMethod {
|
||||
REGISTRY_GET_INVERSE (ClassWrapper.NMS_REGISTRYMATERIALS.getClazz(), new Class[]{Object.class}, MinecraftVersion.MC1_11_R1, MinecraftVersion.MC1_13_R1, new Since(MinecraftVersion.MC1_11_R1, "b")), //FIXME: No Spigot mapping!
|
||||
REGISTRYMATERIALS_KEYSET (ClassWrapper.NMS_REGISTRYMATERIALS.getClazz(), new Class[]{}, MinecraftVersion.MC1_13_R1, new Since(MinecraftVersion.MC1_13_R1, "keySet")),
|
||||
REGISTRYMATERIALS_GET (ClassWrapper.NMS_REGISTRYMATERIALS.getClazz(), new Class[]{ClassWrapper.NMS_MINECRAFTKEY.getClazz()}, MinecraftVersion.MC1_13_R1, new Since(MinecraftVersion.MC1_13_R1, "get")),
|
||||
REGISTRYMATERIALS_GETKEY (ClassWrapper.NMS_REGISTRYMATERIALS.getClazz(), new Class[]{Object.class}, MinecraftVersion.MC1_13_R2, new Since(MinecraftVersion.MC1_13_R2, "getKey")),
|
||||
|
||||
|
||||
;
|
||||
GAMEPROFILE_DESERIALIZE (ClassWrapper.NMS_GAMEPROFILESERIALIZER.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "deserialize")),
|
||||
GAMEPROFILE_SERIALIZE (ClassWrapper.NMS_GAMEPROFILESERIALIZER.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), ClassWrapper.GAMEPROFILE.getClazz()}, MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "serialize"));
|
||||
|
||||
private MinecraftVersion removedAfter;
|
||||
private Since targetVersion;
|
||||
|
@ -2,87 +2,60 @@ package com.songoda.epicenchants.utils.single;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.songoda.core.compatibility.CompatibleMaterial.*;
|
||||
import static com.songoda.epicenchants.utils.single.ItemGroup.Group.*;
|
||||
import static org.bukkit.Material.*;
|
||||
|
||||
public class ItemGroup {
|
||||
|
||||
private Multimap<Group, Material> groupMap;
|
||||
private final Multimap<Group, CompatibleMaterial> groupMap;
|
||||
|
||||
public ItemGroup(EpicEnchants instance) {
|
||||
public ItemGroup() {
|
||||
groupMap = HashMultimap.create();
|
||||
if (com.songoda.core.compatibility.ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) setupMaster();
|
||||
else setupLegacy();
|
||||
}
|
||||
|
||||
private void setupMaster() {
|
||||
groupMap.putAll(AXES, Arrays.asList(DIAMOND_AXE, GOLDEN_AXE, IRON_AXE, STONE_AXE, WOODEN_AXE));
|
||||
groupMap.putAll(AXES, Arrays.asList(NETHERITE_AXE, DIAMOND_AXE, GOLDEN_AXE, IRON_AXE, STONE_AXE, WOODEN_AXE));
|
||||
|
||||
groupMap.putAll(PICKAXES, Arrays.asList(DIAMOND_PICKAXE, GOLDEN_PICKAXE, IRON_PICKAXE, STONE_PICKAXE, WOODEN_PICKAXE));
|
||||
groupMap.putAll(PICKAXES, Arrays.asList(NETHERITE_PICKAXE, DIAMOND_PICKAXE, GOLDEN_PICKAXE, IRON_PICKAXE, STONE_PICKAXE, WOODEN_PICKAXE));
|
||||
|
||||
groupMap.putAll(HOES, Arrays.asList(DIAMOND_HOE, GOLDEN_HOE, IRON_HOE, STONE_HOE, WOODEN_HOE));
|
||||
groupMap.putAll(HOES, Arrays.asList(NETHERITE_HOE, DIAMOND_HOE, GOLDEN_HOE, IRON_HOE, STONE_HOE, WOODEN_HOE));
|
||||
|
||||
groupMap.putAll(SHOVELS, Arrays.asList(DIAMOND_SHOVEL, GOLDEN_SHOVEL, IRON_SHOVEL, STONE_SHOVEL, WOODEN_SHOVEL));
|
||||
groupMap.putAll(SHOVELS, Arrays.asList(NETHERITE_SHOVEL, DIAMOND_SHOVEL, GOLDEN_SHOVEL, IRON_SHOVEL, STONE_SHOVEL, WOODEN_SHOVEL));
|
||||
|
||||
groupMap.putAll(SWORDS, Arrays.asList(DIAMOND_SWORD, GOLDEN_SWORD, IRON_SWORD, STONE_SWORD, WOODEN_SWORD));
|
||||
groupMap.putAll(SWORDS, Arrays.asList(NETHERITE_SWORD, DIAMOND_SWORD, GOLDEN_SWORD, IRON_SWORD, STONE_SWORD, WOODEN_SWORD));
|
||||
|
||||
groupMap.put(BOWS, BOW);
|
||||
|
||||
groupMap.putAll(BOOTS, Arrays.asList(DIAMOND_BOOTS, GOLDEN_BOOTS, IRON_BOOTS, LEATHER_BOOTS));
|
||||
groupMap.putAll(BOOTS, Arrays.asList(NETHERITE_BOOTS, DIAMOND_BOOTS, GOLDEN_BOOTS, IRON_BOOTS, LEATHER_BOOTS));
|
||||
|
||||
groupMap.putAll(LEGGINGS, Arrays.asList(DIAMOND_LEGGINGS, GOLDEN_LEGGINGS, IRON_LEGGINGS, LEATHER_LEGGINGS));
|
||||
groupMap.putAll(LEGGINGS, Arrays.asList(NETHERITE_LEGGINGS, DIAMOND_LEGGINGS, GOLDEN_LEGGINGS, IRON_LEGGINGS, LEATHER_LEGGINGS));
|
||||
|
||||
groupMap.putAll(CHESTPLATES, Arrays.asList(DIAMOND_CHESTPLATE, GOLDEN_CHESTPLATE, IRON_CHESTPLATE, LEATHER_CHESTPLATE));
|
||||
groupMap.putAll(CHESTPLATES, Arrays.asList(NETHERITE_CHESTPLATE, DIAMOND_CHESTPLATE, GOLDEN_CHESTPLATE, IRON_CHESTPLATE, LEATHER_CHESTPLATE));
|
||||
|
||||
groupMap.putAll(HELMETS, Arrays.asList(DIAMOND_HELMET, GOLDEN_HELMET, IRON_HELMET, LEATHER_HELMET));
|
||||
groupMap.putAll(HELMETS, Arrays.asList(NETHERITE_HELMET, DIAMOND_HELMET, GOLDEN_HELMET, IRON_HELMET, LEATHER_HELMET));
|
||||
|
||||
groupMap.put(TRIDENTS, TRIDENT);
|
||||
}
|
||||
|
||||
private void setupLegacy() {
|
||||
groupMap.putAll(AXES, Arrays.asList(DIAMOND_AXE, Material.valueOf("GOLD_AXE"), IRON_AXE, STONE_AXE, Material.valueOf("WOOD_AXE")));
|
||||
|
||||
groupMap.putAll(PICKAXES, Arrays.asList(DIAMOND_PICKAXE, Material.valueOf("GOLD_PICKAXE"), IRON_PICKAXE, STONE_PICKAXE, Material.valueOf("WOOD_PICKAXE")));
|
||||
|
||||
groupMap.putAll(HOES, Arrays.asList(DIAMOND_HOE, Material.valueOf("GOLD_HOE"), IRON_HOE, STONE_HOE, Material.valueOf("WOOD_HOE")));
|
||||
|
||||
groupMap.putAll(SHOVELS, Arrays.asList(Material.valueOf("DIAMOND_SPADE"), Material.valueOf("GOLD_SPADE"), Material.valueOf("IRON_SPADE"), Material.valueOf("STONE_SPADE"), Material.valueOf("WOOD_SPADE")));
|
||||
|
||||
groupMap.putAll(SWORDS, Arrays.asList(DIAMOND_SWORD, Material.valueOf("GOLD_SWORD"), IRON_SWORD, STONE_SWORD, Material.valueOf("WOOD_SWORD")));
|
||||
|
||||
groupMap.put(BOWS, BOW);
|
||||
|
||||
groupMap.putAll(BOOTS, Arrays.asList(DIAMOND_BOOTS, Material.valueOf("GOLD_BOOTS"), IRON_BOOTS, LEATHER_BOOTS));
|
||||
|
||||
groupMap.putAll(LEGGINGS, Arrays.asList(DIAMOND_LEGGINGS, Material.valueOf("GOLD_LEGGINGS"), IRON_LEGGINGS, LEATHER_LEGGINGS));
|
||||
|
||||
groupMap.putAll(CHESTPLATES, Arrays.asList(DIAMOND_CHESTPLATE, Material.valueOf("GOLD_CHESTPLATE"), IRON_CHESTPLATE, LEATHER_CHESTPLATE));
|
||||
|
||||
groupMap.putAll(HELMETS, Arrays.asList(DIAMOND_HELMET, Material.valueOf("GOLD_HELMET"), IRON_HELMET, LEATHER_HELMET));
|
||||
}
|
||||
|
||||
public Set<Material> get(String key) {
|
||||
Optional<Group> optionalGroup = Group.from(key);
|
||||
Set<Material> output = new HashSet<>();
|
||||
|
||||
optionalGroup.ifPresent(group -> output.addAll(getMaterials(group)));
|
||||
|
||||
if (Material.matchMaterial(key) != null) {
|
||||
output.add(Material.matchMaterial(key));
|
||||
if (CompatibleMaterial.getMaterial(key) != null) {
|
||||
output.add(CompatibleMaterial.getMaterial(key).getMaterial());
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
public Set<String> getGroups(Set<Material> materials) {
|
||||
public Set<String> getGroups(Set<CompatibleMaterial> materials) {
|
||||
Set<String> groups = new HashSet<>();
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
@ -92,11 +65,11 @@ public class ItemGroup {
|
||||
});
|
||||
}
|
||||
|
||||
groups.addAll(materials.stream().map(Material::toString).collect(Collectors.toSet()));
|
||||
groups.addAll(materials.stream().map(CompatibleMaterial::toString).collect(Collectors.toSet()));
|
||||
return groups;
|
||||
}
|
||||
|
||||
public Optional<Group> getGroup(Set<Material> materials) {
|
||||
public Optional<Group> getGroup(Set<CompatibleMaterial> materials) {
|
||||
Optional<Group> group = Arrays.stream(Group.values())
|
||||
.filter(s -> !s.getChildren().isEmpty() && s.getChildren().stream().allMatch(child -> materials.containsAll(groupMap.get(child))))
|
||||
.findFirst();
|
||||
@ -113,7 +86,7 @@ public class ItemGroup {
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (group.getChildren().isEmpty())
|
||||
out.addAll(groupMap.get(group));
|
||||
out.addAll(groupMap.get(group).stream().map(CompatibleMaterial::getMaterial).collect(Collectors.toList()));
|
||||
else
|
||||
out.addAll(group.getChildren().stream().map(this::getMaterials).flatMap(Collection::stream).collect(Collectors.toSet()));
|
||||
}
|
||||
|
@ -6,6 +6,6 @@ website: https://songoda.com/
|
||||
softdepend: [Vault, PlayerPoints, UltimateBottles, PlaceholderAPI]
|
||||
api-version: 1.13
|
||||
commands:
|
||||
epicenchants:
|
||||
aliases: [ee]
|
||||
ussage: /ee reload
|
||||
ee:
|
||||
aliases: [epicenchants]
|
||||
ussage: reload
|
@ -15,7 +15,7 @@ contents:
|
||||
- "&7Examine to receive a random"
|
||||
- "&fsimple &7enchantment book."
|
||||
- ""
|
||||
- "&fUse &f/ee list simple &7to view a list"
|
||||
- "&fUse &flist simple &7to view a list"
|
||||
- "&fof possible enchants you could unlock!"
|
||||
- ""
|
||||
- "&b&lCOST &r&f{exp_cost} EXP"
|
||||
@ -31,7 +31,7 @@ contents:
|
||||
- "&7Examine to receive a random"
|
||||
- "&aunique &7enchantment book."
|
||||
- ""
|
||||
- "&fUse &a/ee list unique &7to view a list"
|
||||
- "&fUse &alist unique &7to view a list"
|
||||
- "&fof possible enchants you could unlock!"
|
||||
- ""
|
||||
- "&b&lCOST &r&f{exp_cost} EXP"
|
||||
@ -47,7 +47,7 @@ contents:
|
||||
- "&7Examine to receive a random"
|
||||
- "&belite &7enchantment book."
|
||||
- ""
|
||||
- "&fUse &b/ee list elite &7to view a list"
|
||||
- "&fUse &blist elite &7to view a list"
|
||||
- "&fof possible enchants you could unlock!"
|
||||
- ""
|
||||
- "&b&lCOST &r&f{exp_cost} EXP"
|
||||
@ -63,7 +63,7 @@ contents:
|
||||
- "&7Examine to receive a random"
|
||||
- "&eultimate &7enchantment book."
|
||||
- ""
|
||||
- "&fUse &e/ee list simple &7to view a list"
|
||||
- "&fUse &elist simple &7to view a list"
|
||||
- "&fof possible enchants you could unlock!"
|
||||
- ""
|
||||
- "&b&lCOST &r&f{exp_cost} EXP"
|
||||
@ -79,7 +79,7 @@ contents:
|
||||
- "&7Examine to receive a random"
|
||||
- "&6legendary &7enchantment book."
|
||||
- ""
|
||||
- "&fUse &6/ee list simple &7to view a list"
|
||||
- "&fUse &6list simple &7to view a list"
|
||||
- "&fof possible enchants you could unlock!"
|
||||
- ""
|
||||
- "&b&lCOST &r&f{exp_cost} EXP"
|
||||
|
@ -14,7 +14,7 @@ contents:
|
||||
- "&7Examine to receive a random"
|
||||
- "&fsimple &7enchantment book."
|
||||
- ""
|
||||
- "&fUse &f/ee list simple &7to view a list"
|
||||
- "&fUse &flist simple &7to view a list"
|
||||
- "&fof possible enchants you could unlock!"
|
||||
- ""
|
||||
- "&b&lCOST &r&f{exp_cost} EXP"
|
||||
@ -29,7 +29,7 @@ contents:
|
||||
- "&7Examine to receive a random"
|
||||
- "&aunique &7enchantment book."
|
||||
- ""
|
||||
- "&fUse &a/ee list unique &7to view a list"
|
||||
- "&fUse &alist unique &7to view a list"
|
||||
- "&fof possible enchants you could unlock!"
|
||||
- ""
|
||||
- "&b&lCOST &r&f{exp_cost} EXP"
|
||||
@ -44,7 +44,7 @@ contents:
|
||||
- "&7Examine to receive a random"
|
||||
- "&belite &7enchantment book."
|
||||
- ""
|
||||
- "&fUse &b/ee list elite &7to view a list"
|
||||
- "&fUse &blist elite &7to view a list"
|
||||
- "&fof possible enchants you could unlock!"
|
||||
- ""
|
||||
- "&b&lCOST &r&f{exp_cost} EXP"
|
||||
@ -59,7 +59,7 @@ contents:
|
||||
- "&7Examine to receive a random"
|
||||
- "&eultimate &7enchantment book."
|
||||
- ""
|
||||
- "&fUse &e/ee list simple &7to view a list"
|
||||
- "&fUse &elist simple &7to view a list"
|
||||
- "&fof possible enchants you could unlock!"
|
||||
- ""
|
||||
- "&b&lCOST &r&f{exp_cost} EXP"
|
||||
@ -74,7 +74,7 @@ contents:
|
||||
- "&7Examine to receive a random"
|
||||
- "&6legendary &7enchantment book."
|
||||
- ""
|
||||
- "&fUse &6/ee list simple &7to view a list"
|
||||
- "&fUse &6list simple &7to view a list"
|
||||
- "&fof possible enchants you could unlock!"
|
||||
- ""
|
||||
- "&b&lCOST &r&f{exp_cost} EXP"
|
||||
|
Loading…
Reference in New Issue
Block a user