mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-08 07:27:39 +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 GuiListener(), this);
|
||||||
Bukkit.getPluginManager().registerEvents(new ElementListener(), this);
|
Bukkit.getPluginManager().registerEvents(new ElementListener(), this);
|
||||||
Bukkit.getPluginManager().registerEvents(new CustomBlockListener(), this);
|
Bukkit.getPluginManager().registerEvents(new CustomBlockListener(), this);
|
||||||
if (getConfig().getBoolean("lootsplosion.enabled"))
|
if (getConfig().getBoolean("lootsplosion.enabled")) {
|
||||||
Bukkit.getPluginManager().registerEvents(new LootsplosionListener(), this);
|
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
|
* this class implements the Listener, if the option
|
||||||
|
@ -10,11 +10,17 @@ import org.bukkit.command.CommandSender;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class RevDecreaseCommandTreeNode extends CommandTreeNode {
|
public class RevIDActionCommandTreeNode extends CommandTreeNode {
|
||||||
public RevDecreaseCommandTreeNode(CommandTreeNode parent) {
|
private final String cmdType;
|
||||||
super(parent, "decrease");
|
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);
|
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]);
|
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));
|
List<MMOItemTemplate> templates = new ArrayList<>(type == null ? MMOItems.plugin.getTemplates().collectTemplates() : MMOItems.plugin.getTemplates().getTemplates(type));
|
||||||
|
int failed = 0;
|
||||||
for(MMOItemTemplate template : templates) {
|
for(MMOItemTemplate template : templates) {
|
||||||
ConfigFile file = template.getType().getConfigFile();
|
ConfigFile file = template.getType().getConfigFile();
|
||||||
file.getConfig().getConfigurationSection(template.getId() + ".base")
|
if(!file.getConfig().isConfigurationSection(template.getId() + ".base"))
|
||||||
.set("revision-id", Math.max(template.getRevisionId() - 1, 1));
|
failed++;
|
||||||
file.registerTemplateEdition(template);
|
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;
|
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) {
|
public RevisionIDCommandTreeNode(CommandTreeNode parent) {
|
||||||
super(parent, "revid");
|
super(parent, "revid");
|
||||||
|
|
||||||
addChild(new RevIncreaseCommandTreeNode(this));
|
addChild(new RevIDActionCommandTreeNode(this, "increase", (revId) -> Math.min(revId + 1, Integer.MAX_VALUE)));
|
||||||
addChild(new RevDecreaseCommandTreeNode(this));
|
addChild(new RevIDActionCommandTreeNode(this, "decrease", (revId) -> Math.max(revId - 1, 1)));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user