mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-09 07:37:34 +01:00
Command trigger for stations, can now be ran as player, op or console
This commit is contained in:
parent
d3867cc920
commit
5b637a21f7
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user