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);
}
}
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);
}
Aggregations