Command trigger for stations, can now be ran as player, op or console

This commit is contained in:
ASangarin 2020-10-05 15:12:35 +02:00
parent d3867cc920
commit 5b637a21f7
2 changed files with 21 additions and 5 deletions

View File

@ -3,22 +3,38 @@ package net.Indyuce.mmoitems.api.crafting.trigger;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.mmogroup.mmolib.api.MMOLineConfig;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class CommandTrigger extends Trigger {
private final String command;
private final boolean player;
private final String sender;
public CommandTrigger(MMOLineConfig config) {
super("command");
config.validate("format");
player = config.getBoolean("player", false);
sender = config.getString("sender", "PLAYER").toUpperCase();
command = config.getString("format");
}
@Override
public void whenCrafting(PlayerData data) {
Bukkit.dispatchCommand(player ? data.getPlayer() : Bukkit.getConsoleSender(),
command.replace("%player%", data.getPlayer().getName()));
dispatchCommand(data.getPlayer(), sender.equals("CONSOLE"), sender.equals("OP"));
}
private void dispatchCommand(Player player, boolean console, boolean op) {
if (console) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
return;
}
if (op && !player.isOp()) {
player.setOp(true);
try {
Bukkit.dispatchCommand(player, command);
} catch (Exception e1) {}
player.setOp(false);
} else
Bukkit.dispatchCommand(player, command);
}
}

View File

@ -119,7 +119,7 @@ public class DisableInteractions implements Listener {
@EventHandler
public void i(CraftItemEvent event) {
if (event.getRecipe() instanceof Keyed)
if (((Keyed) event.getRecipe()).getKey().getNamespace().equalsIgnoreCase("mmoitems"))
if (((Keyed) event.getRecipe()).getKey().getNamespace().equals("mmoitems"))
return;
boolean disableCrafting = MMOItems.plugin.getConfig().getBoolean("disable-interactions.craft");