Search in sources :

Example 1 with Wand

use of me.botsko.prism.wands.Wand in project Prism-Bukkit by prism.

the class WandUtils method playerUsesWandOnClick.

public static boolean playerUsesWandOnClick(Player player, Location loc) {
    if (Prism.playersWithActiveTools.containsKey(player.getName())) {
        final Wand wand = Prism.playersWithActiveTools.get(player.getName());
        if (wand == null)
            return false;
        final int item_id = wand.getItemId();
        final byte item_subid = wand.getItemSubId();
        if (player.getItemInHand().getTypeId() == item_id && player.getItemInHand().getDurability() == item_subid) {
            // Left click is for current location
            wand.playerLeftClick(player, loc);
            return true;
        }
    }
    return false;
}
Also used : Wand(me.botsko.prism.wands.Wand)

Example 2 with Wand

use of me.botsko.prism.wands.Wand in project Prism-Bukkit by prism.

the class Preview method apply.

/**
     * 
     * @return
     */
@Override
public void apply() {
    if (!worldChangeQueue.isEmpty()) {
        if (!is_preview && player != null) {
            Wand oldwand = null;
            if (Prism.playersWithActiveTools.containsKey(player.getName())) {
                // Pull the wand in use
                oldwand = Prism.playersWithActiveTools.get(player.getName());
            }
            boolean show_nearby = true;
            if (oldwand != null && oldwand instanceof RollbackWand) {
                show_nearby = false;
            }
            if (show_nearby) {
                // Inform nearby players
                plugin.notifyNearby(player, parameters.getRadius(), player.getDisplayName() + " is performing a " + processType.name().toLowerCase() + " near you.");
                // Inform staff
                if (plugin.getConfig().getBoolean("prism.alerts.alert-staff-to-applied-process")) {
                    final String cmd = parameters.getOriginalCommand();
                    if (cmd != null) {
                        plugin.alertPlayers(player, ChatColor.WHITE + processType.name().toLowerCase() + " by " + player.getDisplayName() + ChatColor.GRAY + parameters.getOriginalCommand());
                    }
                }
            }
        }
        // Offload the work of world changes
        // to a scheduled sync task
        processWorldChanges();
    }
}
Also used : RollbackWand(me.botsko.prism.wands.RollbackWand) RollbackWand(me.botsko.prism.wands.RollbackWand) Wand(me.botsko.prism.wands.Wand)

Example 3 with Wand

use of me.botsko.prism.wands.Wand in project Prism-Bukkit by prism.

the class ResetmyCommand method handle.

/**
     * Handle the command
     */
@Override
public void handle(CallInfo call) {
    String setType = null;
    if (call.getArgs().length >= 2) {
        setType = call.getArg(1);
    }
    /**
         * Inspector wand
         */
    if (setType != null && !setType.equalsIgnoreCase("wand")) {
        call.getPlayer().sendMessage(Prism.messenger.playerError("Invalid arguments. Use /prism ? for help."));
        return;
    }
    if (!plugin.getConfig().getBoolean("prism.wands.allow-user-override")) {
        call.getPlayer().sendMessage(Prism.messenger.playerError("Sorry, but personalizing the wand is currently not allowed."));
    }
    // way to handle this - some way to centralize it at least
    if (!call.getPlayer().hasPermission("prism.rollback") && !call.getPlayer().hasPermission("prism.restore") && !call.getPlayer().hasPermission("prism.wand.*") && !call.getPlayer().hasPermission("prism.wand.inspect") && !call.getPlayer().hasPermission("prism.wand.profile") && !call.getPlayer().hasPermission("prism.wand.rollback") && !call.getPlayer().hasPermission("prism.wand.restore")) {
        call.getPlayer().sendMessage(Prism.messenger.playerError("You do not have permission for this."));
        return;
    }
    // Disable any current wand
    if (Prism.playersWithActiveTools.containsKey(call.getPlayer().getName())) {
        final Wand oldwand = Prism.playersWithActiveTools.get(call.getPlayer().getName());
        oldwand.disable(call.getPlayer());
        Prism.playersWithActiveTools.remove(call.getPlayer().getName());
        call.getPlayer().sendMessage(Prism.messenger.playerHeaderMsg("Current wand " + ChatColor.RED + "disabled" + ChatColor.WHITE + "."));
    }
    Settings.deleteSetting("wand.item", call.getPlayer());
    Settings.deleteSetting("wand.mode", call.getPlayer());
    call.getPlayer().sendMessage(Prism.messenger.playerHeaderMsg("Your personal wand settings have been reset to server defaults."));
}
Also used : Wand(me.botsko.prism.wands.Wand)

Example 4 with Wand

use of me.botsko.prism.wands.Wand in project Prism-Bukkit by prism.

the class SetmyCommand method handle.

/**
     * Handle the command
     */
@Override
public void handle(CallInfo call) {
    String setType = null;
    if (call.getArgs().length >= 2) {
        setType = call.getArg(1);
    }
    /**
         * Inspector wand
         */
    if (setType != null && !setType.equalsIgnoreCase("wand")) {
        call.getPlayer().sendMessage(Prism.messenger.playerError("Invalid arguments. Use /prism ? for help."));
        return;
    }
    if (!plugin.getConfig().getBoolean("prism.wands.allow-user-override")) {
        call.getPlayer().sendMessage(Prism.messenger.playerError("Sorry, but personalizing the wand is currently not allowed."));
    }
    // way to handle this - some way to centralize it at least
    if (!call.getPlayer().hasPermission("prism.rollback") && !call.getPlayer().hasPermission("prism.restore") && !call.getPlayer().hasPermission("prism.wand.*") && !call.getPlayer().hasPermission("prism.wand.inspect") && !call.getPlayer().hasPermission("prism.wand.profile") && !call.getPlayer().hasPermission("prism.wand.rollback") && !call.getPlayer().hasPermission("prism.wand.restore")) {
        call.getPlayer().sendMessage(Prism.messenger.playerError("You do not have permission for this."));
        return;
    }
    // Disable any current wand
    if (Prism.playersWithActiveTools.containsKey(call.getPlayer().getName())) {
        final Wand oldwand = Prism.playersWithActiveTools.get(call.getPlayer().getName());
        oldwand.disable(call.getPlayer());
        Prism.playersWithActiveTools.remove(call.getPlayer().getName());
        call.getPlayer().sendMessage(Prism.messenger.playerHeaderMsg("Current wand " + ChatColor.RED + "disabled" + ChatColor.WHITE + "."));
    }
    String setSubType = null;
    if (call.getArgs().length >= 3) {
        setSubType = call.getArg(2);
    }
    /**
         * Set your custom wand mode to "hand", "item", or "block"
         */
    if (setSubType != null && setSubType.equalsIgnoreCase("mode")) {
        String setWandMode = null;
        if (call.getArgs().length >= 4) {
            setWandMode = call.getArg(3);
        }
        if (setWandMode != null && (setWandMode.equals("hand") || setWandMode.equals("item") || setWandMode.equals("block"))) {
            Settings.saveSetting("wand.mode", setWandMode, call.getPlayer());
            // Delete the item so we don't confuse people.
            Settings.deleteSetting("wand.item", call.getPlayer());
            call.getPlayer().sendMessage(Prism.messenger.playerHeaderMsg("Changed your personal wand to " + ChatColor.GREEN + setWandMode + ChatColor.WHITE + " mode."));
            return;
        }
        call.getPlayer().sendMessage(Prism.messenger.playerError("Invalid arguments. Use /prism ? for help."));
        return;
    }
    /**
         * Set your custom wand item for either "item" or "block" modes
         */
    if (!setSubType.equalsIgnoreCase("item")) {
        return;
    }
    String setWandItem = null;
    if (call.getArgs().length >= 4) {
        setWandItem = call.getArg(3);
    }
    if (setWandItem != null) {
        // If non-numeric, check for name
        if (!TypeUtils.isNumeric(setWandItem)) {
            final ArrayList<int[]> itemIds = Prism.getItems().getIdsByAlias(setWandItem);
            if (itemIds.size() > 0) {
                final int[] ids = itemIds.get(0);
                setWandItem = ids[0] + ":" + ids[1];
            } else {
                call.getPlayer().sendMessage(Prism.messenger.playerError("There's no item matching that name."));
                return;
            }
        }
        // Standardize
        if (!setWandItem.contains(":")) {
            setWandItem += ":0";
        }
        int item_id = -1;
        byte item_subid = 0;
        final String[] itemIds = setWandItem.split(":");
        if (itemIds.length == 2) {
            item_id = Integer.parseInt(itemIds[0]);
            item_subid = Byte.parseByte(itemIds[1]);
        }
        if (item_id > -1) {
            final String item_name = Prism.getItems().getAlias(item_id, item_subid);
            if (item_name != null) {
                if (!ItemUtils.isAcceptableWand(item_id, item_subid)) {
                    call.getPlayer().sendMessage(Prism.messenger.playerError("Sorry, but you may not use " + item_name + " for a wand."));
                    return;
                }
                Settings.saveSetting("wand.item", setWandItem, call.getPlayer());
                call.getPlayer().sendMessage(Prism.messenger.playerHeaderMsg("Changed your personal wand item to " + ChatColor.GREEN + item_name + ChatColor.WHITE + "."));
                return;
            }
        }
    }
    call.getPlayer().sendMessage(Prism.messenger.playerError("Invalid arguments. Use /prism ? for help."));
}
Also used : Wand(me.botsko.prism.wands.Wand)

Example 5 with Wand

use of me.botsko.prism.wands.Wand in project Prism-Bukkit by prism.

the class PrismPlayerEvents method onPlayerInteract.

/**
     * 
     * @param event
     */
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerInteract(final PlayerInteractEvent event) {
    final Player player = event.getPlayer();
    Block block = event.getClickedBlock();
    // Are they using a wand (or do we always allow it)
    if (Prism.playersWithActiveTools.containsKey(player.getName())) {
        final Wand wand = Prism.playersWithActiveTools.get(player.getName());
        // The wand will tell us what to use.
        final int item_id = wand.getItemId();
        final byte item_subid = wand.getItemSubId();
        // Prism.debug("Checking active wand for player, Mode: " +
        // wand.getWandMode() + " Item:" + item_id + ":" + item_subid +
        // " Item in hand:" + player.getItemInHand().getTypeId() + ":" +
        // player.getItemInHand().getDurability());
        // In Spigot 1.10 and newer, the durability value of an ItemStack representing
        // an empty hand is 0 instead of -1.
        short itemInHandDurability = player.getItemInHand().getDurability();
        if (player.getItemInHand().getTypeId() == 0 && itemInHandDurability == 0) {
            itemInHandDurability = -1;
        }
        // Does the player have such item?
        if (wand != null && player.getItemInHand().getTypeId() == item_id && itemInHandDurability == item_subid) {
            // Left click is for current block
            if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
                wand.playerLeftClick(player, block.getLocation());
            }
            // blockplace.
            if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                block = block.getRelative(event.getBlockFace());
                wand.playerRightClick(player, block.getLocation());
            }
            if ((event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK)) {
                Prism.debug("Cancelling event for wand use.");
                event.setCancelled(true);
                player.updateInventory();
                return;
            }
        }
    }
    if (event.isCancelled())
        return;
    // as of 1.4
    if (block != null && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        String coord_key;
        switch(block.getType()) {
            case FURNACE:
            case DISPENSER:
            case CHEST:
            case ENDER_CHEST:
            case ENCHANTMENT_TABLE:
            case ANVIL:
            case BREWING_STAND:
            case TRAPPED_CHEST:
            case HOPPER:
            case DROPPER:
                if (!Prism.getIgnore().event("container-access", player))
                    return;
                RecordingQueue.addToQueue(ActionFactory.createBlock("container-access", block, player.getName()));
                break;
            case JUKEBOX:
                recordDiscInsert(block, player);
                break;
            case CAKE_BLOCK:
                recordCakeEat(block, player);
                break;
            case WOODEN_DOOR:
            case ACACIA_DOOR:
            case BIRCH_DOOR:
            case DARK_OAK_DOOR:
            case JUNGLE_DOOR:
            case SPRUCE_DOOR:
            case TRAP_DOOR:
            case FENCE_GATE:
            case LEVER:
            case STONE_BUTTON:
            case WOOD_BUTTON:
                if (!Prism.getIgnore().event("block-use", player))
                    return;
                RecordingQueue.addToQueue(ActionFactory.createBlock("block-use", block, player.getName()));
                break;
            case LOG:
                recordCocoaPlantEvent(block, player.getItemInHand(), event.getBlockFace(), player.getName());
                break;
            case CROPS:
            case GRASS:
            case MELON_STEM:
            case PUMPKIN_STEM:
            case SAPLING:
            case CARROT:
            case POTATO:
                recordBonemealEvent(block, player.getItemInHand(), event.getBlockFace(), player.getName());
                break;
            case RAILS:
            case DETECTOR_RAIL:
            case POWERED_RAIL:
            case ACTIVATOR_RAIL:
                coord_key = block.getX() + ":" + block.getY() + ":" + block.getZ();
                plugin.preplannedVehiclePlacement.put(coord_key, player.getName());
                break;
            case TNT:
                if (player.getItemInHand().getType().equals(Material.FLINT_AND_STEEL)) {
                    if (!Prism.getIgnore().event("tnt-prime", player))
                        return;
                    RecordingQueue.addToQueue(ActionFactory.createUse("tnt-prime", "tnt", block, player.getName()));
                }
                break;
            default:
                break;
        }
        // if they're holding a spawner egg
        if (player.getItemInHand().getType().equals(Material.MONSTER_EGG)) {
            recordMonsterEggUse(block, player.getItemInHand(), player.getName());
        }
        // if they're holding a rocket
        if (player.getItemInHand().getType().equals(Material.FIREWORK)) {
            recordRocketLaunch(block, player.getItemInHand(), event.getBlockFace(), player.getName());
        }
        // anything...)
        if (player.getItemInHand().getType().equals(Material.BOAT)) {
            coord_key = block.getX() + ":" + (block.getY() + 1) + ":" + block.getZ();
            plugin.preplannedVehiclePlacement.put(coord_key, player.getName());
        }
    }
    // Punching fire
    if (block != null && event.getAction() == Action.LEFT_CLICK_BLOCK) {
        final Block above = block.getRelative(BlockFace.UP);
        if (above.getType().equals(Material.FIRE)) {
            RecordingQueue.addToQueue(ActionFactory.createBlock("block-break", above, player.getName()));
        }
    }
    if (!plugin.getConfig().getBoolean("prism.tracking.crop-trample"))
        return;
    if (block != null && event.getAction() == Action.PHYSICAL) {
        if (block.getType() == Material.SOIL) {
            // soil
            if (!Prism.getIgnore().event("crop=trample", player))
                return;
            RecordingQueue.addToQueue(ActionFactory.createBlock("crop-trample", block.getRelative(BlockFace.UP), player.getName()));
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) ProfileWand(me.botsko.prism.wands.ProfileWand) Wand(me.botsko.prism.wands.Wand) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Wand (me.botsko.prism.wands.Wand)6 ProfileWand (me.botsko.prism.wands.ProfileWand)2 Player (org.bukkit.entity.Player)2 EventHandler (org.bukkit.event.EventHandler)2 RollbackWand (me.botsko.prism.wands.RollbackWand)1 Block (org.bukkit.block.Block)1 Entity (org.bukkit.entity.Entity)1