use of io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer in project TriggerReactor by wysohn.
the class LocationBasedTriggerManager method onClick.
@Listener(order = Order.LATE)
@Exclude({ InteractBlockEvent.Primary.OffHand.class, InteractBlockEvent.Secondary.OffHand.class })
public void onClick(InteractBlockEvent e) {
Player player = e.getCause().first(Player.class).orElse(null);
// maybe something other than a player can interact with a block?
if (player == null)
return;
ItemStack IS = player.getItemInHand(HandTypes.MAIN_HAND).orElse(null);
BlockSnapshot clicked = e.getTargetBlock();
if (clicked == null)
return;
Location<World> loc = clicked.getLocation().orElse(null);
if (loc == null)
return;
T trigger = getTriggerForLocation(loc);
if (IS != null && !e.isCancelled() && player.hasPermission("triggerreactor.admin")) {
if (IS.getType() == INSPECTION_TOOL) {
if (trigger != null && e instanceof InteractBlockEvent.Primary) {
removeTriggerForLocation(loc);
player.sendMessage(Text.builder("A trigger has deleted.").color(TextColors.GREEN).build());
e.setCancelled(true);
} else if (trigger != null && e instanceof InteractBlockEvent.Secondary) {
if (player.get(Keys.IS_SNEAKING).orElse(false)) {
handleScriptEdit(player, trigger);
e.setCancelled(true);
} else {
this.showTriggerInfo(new SpongePlayer(player), clicked);
e.setCancelled(true);
}
}
} else if (IS.getType() == CUT_TOOL) {
if (e instanceof InteractBlockEvent.Primary) {
if (pasteTrigger(player, loc)) {
player.sendMessage(Text.builder("Successfully pasted the trigger!").color(TextColors.GREEN).build());
this.showTriggerInfo(new SpongePlayer(player), clicked);
e.setCancelled(true);
}
} else if (trigger != null && e instanceof InteractBlockEvent.Secondary) {
if (cutTrigger(player, loc)) {
player.sendMessage(Text.builder("Cut Complete!").color(TextColors.GREEN).build());
player.sendMessage(Text.builder("Now you can paste it by left click on any block!").color(TextColors.GREEN).build());
e.setCancelled(true);
}
}
} else if (IS.getType() == COPY_TOOL) {
if (e instanceof InteractBlockEvent.Primary) {
if (pasteTrigger(player, loc)) {
player.sendMessage(Text.builder("Successfully pasted the trigger!").color(TextColors.GREEN).build());
this.showTriggerInfo(new SpongePlayer(player), clicked);
e.setCancelled(true);
}
} else if (e instanceof InteractBlockEvent.Secondary) {
if (trigger != null && copyTrigger(player, loc)) {
player.sendMessage(Text.builder("Copy Complete!").color(TextColors.GREEN).build());
player.sendMessage(Text.builder("Now you can paste it by left click on any block!").color(TextColors.GREEN).build());
e.setCancelled(true);
}
}
}
}
if (!e.isCancelled() && isLocationSetting(new SpongePlayer(player))) {
handleLocationSetting(clicked, player);
e.setCancelled(true);
}
}
use of io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer in project TriggerReactor by wysohn.
the class LocationBasedTriggerManager method handleLocationSetting.
private void handleLocationSetting(BlockSnapshot clicked, Player p) {
IPlayer player = new SpongePlayer(p);
Location<World> loc = clicked.getLocation().orElse(null);
if (loc == null)
return;
T trigger = getTriggerForLocation(loc);
if (trigger != null) {
p.sendMessage(Text.builder("Another trigger is set at there!").color(TextColors.RED).build());
showTriggerInfo(player, clicked);
return;
}
String script = getSettingLocationScript(player);
if (script == null) {
p.sendMessage(Text.builder("Could not find script... but how?").color(TextColors.RED).build());
return;
}
File file = getTriggerFile(folder, LocationUtil.convertToSimpleLocation(loc).toString(), true);
try {
String name = TriggerInfo.extractName(file);
IConfigSource config = configSourceFactory.create(folder, name);
TriggerInfo info = TriggerInfo.defaultInfo(file, config);
trigger = newTrigger(info, script);
} catch (Exception e1) {
p.sendMessage(Text.builder("Encounterd an error!").color(TextColors.RED).build());
p.sendMessage(Text.builder(e1.getMessage()).color(TextColors.RED).build());
p.sendMessage(Text.builder("If you are an administrator, check console to see details.").color(TextColors.RED).build());
e1.printStackTrace();
stopLocationSet(player);
return;
}
setTriggerForLocation(loc, trigger);
showTriggerInfo(player, clicked);
stopLocationSet(player);
plugin.saveAsynchronously(this);
}
use of io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer in project TriggerReactor by wysohn.
the class TriggerReactor method onInitialize.
@Listener
public void onInitialize(GameAboutToStartServerEvent e) {
Sponge.getCommandManager().register(this, new CommandCallable() {
@Override
public CommandResult process(CommandSource src, String args) throws CommandException {
if (src instanceof Player) {
onCommand(new SpongePlayer((Player) src), "triggerreactor", args.split(" "));
} else {
onCommand(new SpongeCommandSender(src), "triggerreactor", args.split(" "));
}
return CommandResult.success();
}
@Override
public List<String> getSuggestions(CommandSource source, String arguments, Location<World> targetPosition) throws CommandException {
// return io.github.wysohn.triggerreactor.core.main.TriggerReactor.onTabComplete(arguments.split(" "));
return new ArrayList<>();
}
@Override
public boolean testPermission(CommandSource source) {
return source.hasPermission("triggerreactor.admin");
}
@Override
public Optional<Text> getShortDescription(CommandSource source) {
return Optional.of(Text.of("TriggerReactor"));
}
@Override
public Optional<Text> getHelp(CommandSource source) {
return Optional.of(Text.of("/trg for details"));
}
@Override
public Text getUsage(CommandSource source) {
return Text.of("/trg for details");
}
}, "trg", "trigger");
migrateOldConfig();
}
use of io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer in project TriggerReactor by wysohn.
the class InventoryEditManager method onQuit.
@Listener
public void onQuit(ClientConnectionEvent.Disconnect e) {
Player player = e.getTargetEntity();
stopEdit(new SpongePlayer(player));
}
use of io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer in project TriggerReactor by wysohn.
the class InventoryTriggerManager method onClose.
@Listener
public void onClose(InteractInventoryEvent.Close e, @First Player player) {
if (player == null)
return;
Inventory inv = e.getTargetInventory();
if (!(inv instanceof CarriedInventory))
return;
CarriedInventory inventory = (CarriedInventory) inv;
Carrier carrier = (Carrier) inventory.getCarrier().orElse(null);
if (carrier == null)
return;
onInventoryClose(e, new SpongePlayer(player), new SpongeInventory(inv, carrier));
}
Aggregations