mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-06 07:07:35 +01:00
Improved the RevID command - no longer errors when used alongside outdated items
Lootsplosions now properly error if MythicMobs isn't found
This commit is contained in:
parent
f7e021b4f7
commit
d1e3f4471a
@ -208,8 +208,11 @@ public class MMOItems extends JavaPlugin {
|
||||
Bukkit.getPluginManager().registerEvents(new GuiListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ElementListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new CustomBlockListener(), this);
|
||||
if (getConfig().getBoolean("lootsplosion.enabled"))
|
||||
Bukkit.getPluginManager().registerEvents(new LootsplosionListener(), this);
|
||||
if (getConfig().getBoolean("lootsplosion.enabled")) {
|
||||
if(Bukkit.getPluginManager().isPluginEnabled("MythicMobs"))
|
||||
Bukkit.getPluginManager().registerEvents(new LootsplosionListener(), this);
|
||||
else getLogger().warning("Lootsplosions are enabled, but MythicMobs was not found!");
|
||||
}
|
||||
|
||||
/*
|
||||
* this class implements the Listener, if the option
|
||||
|
@ -10,11 +10,17 @@ import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class RevDecreaseCommandTreeNode extends CommandTreeNode {
|
||||
public RevDecreaseCommandTreeNode(CommandTreeNode parent) {
|
||||
super(parent, "decrease");
|
||||
public class RevIDActionCommandTreeNode extends CommandTreeNode {
|
||||
private final String cmdType;
|
||||
private final Function<Integer, Integer> modifier;
|
||||
|
||||
public RevIDActionCommandTreeNode(CommandTreeNode parent, String type, Function<Integer, Integer> modifier) {
|
||||
super(parent, type);
|
||||
|
||||
this.cmdType = type;
|
||||
this.modifier = modifier;
|
||||
addParameter(RevisionIDCommandTreeNode.TYPE_OR_ALL);
|
||||
}
|
||||
|
||||
@ -30,14 +36,19 @@ public class RevDecreaseCommandTreeNode extends CommandTreeNode {
|
||||
|
||||
Type type = args[2].equalsIgnoreCase("all") ? null : Type.get(args[2]);
|
||||
List<MMOItemTemplate> templates = new ArrayList<>(type == null ? MMOItems.plugin.getTemplates().collectTemplates() : MMOItems.plugin.getTemplates().getTemplates(type));
|
||||
int failed = 0;
|
||||
for(MMOItemTemplate template : templates) {
|
||||
ConfigFile file = template.getType().getConfigFile();
|
||||
file.getConfig().getConfigurationSection(template.getId() + ".base")
|
||||
.set("revision-id", Math.max(template.getRevisionId() - 1, 1));
|
||||
file.registerTemplateEdition(template);
|
||||
if(!file.getConfig().isConfigurationSection(template.getId() + ".base"))
|
||||
failed++;
|
||||
else {
|
||||
file.getConfig().getConfigurationSection(template.getId() + ".base").set("revision-id", modifier.apply(template.getRevisionId()));
|
||||
file.registerTemplateEdition(template);
|
||||
}
|
||||
}
|
||||
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.GREEN + "Successfully decreased Rev IDs" + (type != null ? " for " + type.getName() : "") + "!");
|
||||
if(failed > 0) sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Couldn't find ConfigurationSection for " + failed + " of the specified items.");
|
||||
else sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.GREEN + "Successfully " + cmdType + "d Rev IDs" + (type != null ? " for " + type.getName() : "") + "!");
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package net.Indyuce.mmoitems.command.mmoitems.revid;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.ConfigFile;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
|
||||
import net.mmogroup.mmolib.command.api.CommandTreeNode;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RevIncreaseCommandTreeNode extends CommandTreeNode {
|
||||
public RevIncreaseCommandTreeNode(CommandTreeNode parent) {
|
||||
super(parent, "increase");
|
||||
|
||||
addParameter(RevisionIDCommandTreeNode.TYPE_OR_ALL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandSender sender, String[] args) {
|
||||
if (args.length < 3) return CommandResult.THROW_USAGE;
|
||||
|
||||
if (!Type.isValid(args[2]) && !args[2].equalsIgnoreCase("all")) {
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called " + args[2].toUpperCase().replace("-", "_") + ".");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Type " + ChatColor.GREEN + "/mi list type" + ChatColor.RED + " to see all the available item types.");
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
Type type = args[2].equalsIgnoreCase("all") ? null : Type.get(args[2]);
|
||||
List<MMOItemTemplate> templates = new ArrayList<>(type == null ? MMOItems.plugin.getTemplates().collectTemplates() : MMOItems.plugin.getTemplates().getTemplates(type));
|
||||
for(MMOItemTemplate template : templates) {
|
||||
ConfigFile file = template.getType().getConfigFile();
|
||||
file.getConfig().getConfigurationSection(template.getId() + ".base")
|
||||
.set("revision-id", Math.min(template.getRevisionId() + 1, Integer.MAX_VALUE));
|
||||
file.registerTemplateEdition(template);
|
||||
}
|
||||
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.GREEN + "Successfully increased Rev IDs" + (type != null ? " for " + type.getName() : "") + "!");
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
@ -14,8 +14,10 @@ public class RevisionIDCommandTreeNode extends CommandTreeNode {
|
||||
public RevisionIDCommandTreeNode(CommandTreeNode parent) {
|
||||
super(parent, "revid");
|
||||
|
||||
addChild(new RevIncreaseCommandTreeNode(this));
|
||||
addChild(new RevDecreaseCommandTreeNode(this));
|
||||
addChild(new RevIDActionCommandTreeNode(this, "increase", (revId) -> Math.min(revId + 1, Integer.MAX_VALUE)));
|
||||
addChild(new RevIDActionCommandTreeNode(this, "decrease", (revId) -> Math.max(revId - 1, 1)));
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user