Search in sources :

Example 1 with BukkitPlayer

use of io.github.wysohn.triggerreactor.bukkit.bridge.player.BukkitPlayer in project TriggerReactor by wysohn.

the class LocationBasedTriggerManager method onClick.

@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOWEST)
public void onClick(PlayerInteractEvent e) {
    if (!BukkitUtil.isLeftHandClick(e))
        return;
    Player player = e.getPlayer();
    ItemStack IS = player.getInventory().getItemInHand();
    Block clicked = e.getClickedBlock();
    if (clicked == null)
        return;
    T trigger = getTriggerForLocation(clicked.getLocation());
    if (IS != null && !e.isCancelled() && player.hasPermission("triggerreactor.admin")) {
        if (IS.getType() == INSPECTION_TOOL) {
            if (trigger != null && e.getAction() == Action.LEFT_CLICK_BLOCK) {
                removeTriggerForLocation(clicked.getLocation());
                player.sendMessage(ChatColor.GREEN + "A trigger has deleted.");
                e.setCancelled(true);
            } else if (trigger != null && e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                if (e.getPlayer().isSneaking()) {
                    handleScriptEdit(player, trigger);
                    e.setCancelled(true);
                } else {
                    this.showTriggerInfo(new BukkitPlayer(player), clicked);
                    e.setCancelled(true);
                }
            }
        } else if (IS.getType() == CUT_TOOL) {
            if (e.getAction() == Action.LEFT_CLICK_BLOCK) {
                if (pasteTrigger(player, clicked.getLocation())) {
                    player.sendMessage(ChatColor.GREEN + "Successfully pasted the trigger!");
                    this.showTriggerInfo(new BukkitPlayer(player), clicked);
                    e.setCancelled(true);
                }
            } else if (trigger != null && e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                if (cutTrigger(player, clicked.getLocation())) {
                    player.sendMessage(ChatColor.GREEN + "Cut Complete!");
                    player.sendMessage(ChatColor.GREEN + "Now you can paste it by left click on any block!");
                    e.setCancelled(true);
                }
            }
        } else if (IS.getType() == COPY_TOOL) {
            if (e.getAction() == Action.LEFT_CLICK_BLOCK) {
                if (pasteTrigger(player, clicked.getLocation())) {
                    player.sendMessage(ChatColor.GREEN + "Successfully pasted the trigger!");
                    this.showTriggerInfo(new BukkitPlayer(player), clicked);
                    e.setCancelled(true);
                }
            } else if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                if (trigger != null && copyTrigger(player, clicked.getLocation())) {
                    player.sendMessage(ChatColor.GREEN + "Copy Complete!");
                    player.sendMessage(ChatColor.GREEN + "Now you can paste it by left click on any block!");
                    e.setCancelled(true);
                }
            }
        }
    }
    if (!e.isCancelled() && isLocationSetting(new BukkitPlayer(player))) {
        handleLocationSetting(clicked, player);
        e.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) BukkitPlayer(io.github.wysohn.triggerreactor.bukkit.bridge.player.BukkitPlayer) IPlayer(io.github.wysohn.triggerreactor.core.bridge.player.IPlayer) Block(org.bukkit.block.Block) ItemStack(org.bukkit.inventory.ItemStack) BukkitPlayer(io.github.wysohn.triggerreactor.bukkit.bridge.player.BukkitPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 2 with BukkitPlayer

use of io.github.wysohn.triggerreactor.bukkit.bridge.player.BukkitPlayer in project TriggerReactor by wysohn.

the class LocationBasedTriggerManager method handleLocationSetting.

private void handleLocationSetting(Block clicked, Player p) {
    IPlayer player = new BukkitPlayer(p);
    Location loc = clicked.getLocation();
    T trigger = getTriggerForLocation(loc);
    if (trigger != null) {
        player.sendMessage(ChatColor.RED + "Another trigger is set at there!");
        showTriggerInfo(player, clicked);
        return;
    }
    String script = getSettingLocationScript(player);
    if (script == null) {
        player.sendMessage(ChatColor.RED + "Could not find script... but how?");
        return;
    }
    try {
        trigger = constructTrigger(LocationUtil.convertToSimpleLocation(loc), script);
    } catch (TriggerInitFailedException e1) {
        player.sendMessage(ChatColor.RED + "Encounterd an error!");
        player.sendMessage(ChatColor.RED + e1.getMessage());
        player.sendMessage(ChatColor.RED + "If you are an administrator, check console to see details.");
        e1.printStackTrace();
        stopLocationSet(player);
        return;
    }
    setTriggerForLocation(loc, trigger);
    showTriggerInfo(player, clicked);
    stopLocationSet(player);
    plugin.saveAsynchronously(this);
}
Also used : IPlayer(io.github.wysohn.triggerreactor.core.bridge.player.IPlayer) BukkitPlayer(io.github.wysohn.triggerreactor.bukkit.bridge.player.BukkitPlayer) Location(org.bukkit.Location) SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation) SimpleChunkLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation)

Aggregations

BukkitPlayer (io.github.wysohn.triggerreactor.bukkit.bridge.player.BukkitPlayer)2 IPlayer (io.github.wysohn.triggerreactor.core.bridge.player.IPlayer)2 SimpleChunkLocation (io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation)1 SimpleLocation (io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation)1 Location (org.bukkit.Location)1 Block (org.bukkit.block.Block)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 ItemStack (org.bukkit.inventory.ItemStack)1