use of io.github.wysohn.triggerreactor.core.manager.trigger.Trigger in project TriggerReactor by wysohn.
the class TriggerReactor method showGlowStones.
@Override
protected void showGlowStones(ICommandSender sender, Set<Entry<SimpleLocation, Trigger>> set) {
CommandSource source = sender.get();
if (source instanceof Player) {
Player player = (Player) source;
for (Entry<SimpleLocation, Trigger> entry : set) {
SimpleLocation sloc = entry.getKey();
player.sendBlockChange(sloc.getX(), sloc.getY(), sloc.getZ(), BlockTypes.GLOWSTONE.getDefaultState());
}
}
}
use of io.github.wysohn.triggerreactor.core.manager.trigger.Trigger in project TriggerReactor by wysohn.
the class TriggerReactor method createInterrupter.
@Override
public ProcessInterrupter createInterrupter(Object e, Interpreter interpreter, Map<UUID, Long> cooldowns) {
return new ProcessInterrupter() {
@Override
public boolean onNodeProcess(Node node) {
return false;
}
@Override
public boolean onCommand(Object context, String command, Object[] args) {
if ("CALL".equalsIgnoreCase(command)) {
if (args.length < 1)
throw new RuntimeException("Need parameter [String] or [String, boolean]");
if (args[0] instanceof String) {
Trigger trigger = getNamedTriggerManager().get((String) args[0]);
if (trigger == null)
throw new RuntimeException("No trigger found for Named Trigger " + args[0]);
if (args.length > 1 && args[1] instanceof Boolean) {
trigger.setSync((boolean) args[1]);
} else {
trigger.setSync(true);
}
if (trigger.isSync()) {
trigger.activate(e, interpreter.getVars());
} else {
// use snapshot to avoid concurrent modification
trigger.activate(e, new HashMap<>(interpreter.getVars()));
}
return true;
} else {
throw new RuntimeException("Parameter type not match; it should be a String." + " Make sure to put double quotes, if you provided String literal.");
}
} else if ("CANCELEVENT".equalsIgnoreCase(command)) {
if (!interpreter.isSync())
throw new RuntimeException("CANCELEVENT is illegal in async mode!");
if (context instanceof Cancellable) {
((Cancellable) context).setCancelled(true);
return true;
} else {
throw new RuntimeException(context + " is not a Cancellable event!");
}
} else if ("COOLDOWN".equalsIgnoreCase(command)) {
if (!(args[0] instanceof Number))
throw new RuntimeException(args[0] + " is not a number!");
long mills = (long) (((Number) args[0]).doubleValue() * 1000L);
if (e instanceof Event) {
((Event) e).getCause().first(Player.class).ifPresent((player) -> {
UUID uuid = player.getUniqueId();
cooldowns.put(uuid, System.currentTimeMillis() + mills);
});
}
return true;
}
return false;
}
@Override
public Object onPlaceholder(Object context, String placeholder, Object[] args) {
// }
return null;
}
};
}
use of io.github.wysohn.triggerreactor.core.manager.trigger.Trigger in project TriggerReactor by wysohn.
the class LocationBasedTriggerManager method showTriggerInfo.
protected void showTriggerInfo(ICommandSender sender, BlockSnapshot clicked) {
Trigger trigger = getTriggerForLocation(LocationUtil.convertToSimpleLocation(clicked.getLocation().orElse(null)));
if (trigger == null) {
return;
}
Location<World> loc = clicked.getLocation().orElse(null);
sender.sendMessage("- - - - - - - - - - - - - -");
sender.sendMessage("Trigger: " + getTriggerTypeName());
sender.sendMessage("Block Type: " + clicked.getState().getType().getName());
sender.sendMessage("Location: " + loc.getExtent().getName() + "@" + loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ());
sender.sendMessage("");
sender.sendMessage("Script:");
sender.sendMessage(trigger.getScript());
sender.sendMessage("- - - - - - - - - - - - - -");
}
use of io.github.wysohn.triggerreactor.core.manager.trigger.Trigger in project TriggerReactor by wysohn.
the class TriggerReactor method createInterrupterForInv.
@Override
public ProcessInterrupter createInterrupterForInv(Object e, Interpreter interpreter, Map<UUID, Long> cooldowns, Map<IInventory, InventoryTrigger> inventoryMap) {
return new ProcessInterrupter() {
@Override
public boolean onNodeProcess(Node node) {
// is still running after the inventory is closed.
if (e instanceof InteractInventoryEvent.Open || e instanceof InteractInventoryEvent.Close) {
Inventory inv = ((InteractInventoryEvent) e).getTargetInventory();
if (!(inv instanceof CarriedInventory))
return false;
CarriedInventory inventory = (CarriedInventory) inv;
Carrier carrier = (Carrier) inventory.getCarrier().orElse(null);
if (carrier == null)
return false;
// it's not GUI so stop execution
return !inventoryMap.containsKey(new SpongeInventory(inv, carrier));
}
return false;
}
@Override
public boolean onCommand(Object context, String command, Object[] args) {
if ("CALL".equalsIgnoreCase(command)) {
if (args.length < 1)
throw new RuntimeException("Need parameter [String] or [String, boolean]");
if (args[0] instanceof String) {
Trigger trigger = getNamedTriggerManager().get((String) args[0]);
if (trigger == null)
throw new RuntimeException("No trigger found for Named Trigger " + args[0]);
if (args.length > 1 && args[1] instanceof Boolean) {
trigger.setSync((boolean) args[1]);
} else {
trigger.setSync(true);
}
if (trigger.isSync()) {
trigger.activate(e, interpreter.getVars());
} else {
// use snapshot to avoid concurrent modification
trigger.activate(e, new HashMap<>(interpreter.getVars()));
}
return true;
} else {
throw new RuntimeException("Parameter type not match; it should be a String." + " Make sure to put double quotes, if you provided String literal.");
}
} else if ("CANCELEVENT".equalsIgnoreCase(command)) {
if (!interpreter.isSync())
throw new RuntimeException("CANCELEVENT is illegal in async mode!");
if (context instanceof Cancellable) {
((Cancellable) context).setCancelled(true);
return true;
} else {
throw new RuntimeException(context + " is not a Cancellable event!");
}
} else if ("COOLDOWN".equalsIgnoreCase(command)) {
if (!(args[0] instanceof Number))
throw new RuntimeException(args[0] + " is not a number!");
long mills = (long) (((Number) args[0]).doubleValue() * 1000L);
if (e instanceof Event) {
((Event) e).getCause().first(Player.class).ifPresent((player) -> {
UUID uuid = player.getUniqueId();
cooldowns.put(uuid, System.currentTimeMillis() + mills);
});
}
return true;
}
return false;
}
@Override
public Object onPlaceholder(Object context, String placeholder, Object[] args) {
// }
return null;
}
};
}
use of io.github.wysohn.triggerreactor.core.manager.trigger.Trigger in project TriggerReactor by wysohn.
the class LocationBasedTriggerManager method showTriggerInfo.
@Override
protected void showTriggerInfo(ICommandSender sender, SimpleLocation sloc) {
Trigger trigger = getTriggerForLocation(sloc);
if (trigger == null) {
return;
}
Location<World> loc = LocationUtil.convertToBukkitLocation(sloc);
BlockState clicked = loc.getBlock();
sender.sendMessage("- - - - - - - - - - - - - -");
sender.sendMessage("Trigger: " + getTriggerTypeName());
sender.sendMessage("Block Type: " + clicked.getType().getName());
sender.sendMessage("Location: " + loc.getExtent().getName() + "@" + loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ());
sender.sendMessage("");
sender.sendMessage("Script:");
sender.sendMessage(trigger.getScript());
sender.sendMessage("- - - - - - - - - - - - - -");
}
Aggregations