@EventHandler
  public void onPlayerInteractEvent(PlayerInteractEvent event) {
    if (!isEnabled()) return;
    try {
      if (event.hasBlock() && event.getClickedBlock().getType() == Material.SIGN) return;
      if (event.hasItem() && event.useItemInHand() != Event.Result.DENY) {
        ForgePermittor.log(
            "ItemType: " + getValidator().CheckItem(event.getItem()).toString(), true);
        if (!getProtectionManager()
            .CanUseItem(
                event.getPlayer(),
                event.getPlayer().getLocation(),
                getValidator().CheckItem(event.getItem()))) {
          event.setUseItemInHand(Event.Result.DENY);
          event.setUseInteractedBlock(Event.Result.DENY);

          return;
        }
      }
      if (event.hasBlock() && event.useInteractedBlock() != Event.Result.DENY) {
        ForgePermittor.log(
            "BlockType: " + getValidator().CheckBlock(event.getClickedBlock()).toString(), true);
        if (!getProtectionManager()
            .CanUseBlock(
                event.getPlayer(),
                event.getClickedBlock(),
                getValidator().CheckBlock(event.getClickedBlock()))) {
          event.setUseInteractedBlock(Event.Result.DENY);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onPlayerInteract(PlayerInteractEvent e) {
    if (e.getItem() != null
        && e.getItem().getType() == selectionTools
        && e.getClickedBlock() != null
        && e.getPlayer().isOp()) {

      Region v = this.selections.get(e.getPlayer().getName());

      if (v == null) {
        v = new Region(null, null);
        this.selections.put(e.getPlayer().getName(), v);
      }

      Location l = e.getClickedBlock().getLocation();

      if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
        v.setEnd(l);
        if (plugin.portalRegionSelectionMessage)
          e.getPlayer().sendMessage("[BungeeSuiteBukkit] Second point set");
      } else if (e.getAction() == Action.LEFT_CLICK_BLOCK) {
        v.setFirst(l);
        if (plugin.portalRegionSelectionMessage)
          e.getPlayer().sendMessage("[BungeeSuiteBukkit] First point set");
      }
    }
  }
示例#3
0
  @Override
  public void shoot(PlayerInteractEvent event) {
    if (event.getMaterial() == null) return;
    final List<String> itemLore = event.getItem().getItemMeta().getLore();

    if (WeaponWatch.durability.get(itemLore) == null) WeaponWatch.durability.put(itemLore, 4);
    if (WeaponWatch.durability.get(itemLore) == 0) return;
    if (WeaponWatch.cooldown.contains(itemLore)) return;

    if (shotsLeft.get(itemLore) != null && shotsLeft.get(itemLore) == 0) {
      WeaponWatch.cooldown.add(itemLore);
      shotsLeft.remove(itemLore);
      new BukkitRunnable() {
        @Override
        public void run() {
          WeaponWatch.durability.put(itemLore, WeaponWatch.durability.get(itemLore) - 1);
          WeaponWatch.cooldown.remove(itemLore);
        }
      }.runTaskLater(DuckMain.getPlugin(), 80);
    }

    int shotsPerRound = 6; // @Balancing: Specify shots per round here

    if (shotsLeft.get(itemLore) == null) shotsLeft.put(itemLore, shotsPerRound);
    else shotsLeft.put(itemLore, shotsLeft.get(itemLore) - 1);

    DuckMain.getWorld().playSound(event.getPlayer().getLocation(), Sound.ENTITY_BLAZE_HURT, 10, 1);
    Arrow a =
        event
            .getPlayer()
            .launchProjectile(Arrow.class, event.getPlayer().getLocation().getDirection());
    a.setShooter(event.getPlayer());
    a.setVelocity(a.getVelocity().multiply(6));
    a.setCustomName("MachineGun");
  }
  @SuppressWarnings("deprecation")
  @EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.isCancelled()) return;

    final Player player = event.getPlayer();
    final Block block = event.getClickedBlock();
    final ItemStack item = event.getItem();

    if (player.getWorld() != plugin.getIslandWorld()) return;
    if (player.isOp()) return;
    if (player.hasPermission("islandworld.bypass.island")) return;

    if (block != null) {
      final Material t = block.getType();

      plugin.debug("Interact with block: " + t.getId() + " : " + block);

      if (!(plugin.getConfig().getBoolean("flags.use-switches", false) && isSwitch(t))) {
        if (!(isOnAllowedList(t) || plugin.canBuildOnLocation(player, block.getLocation())))
          event.setCancelled(true);
      }
    } else {
      if (item != null) {
        plugin.debug("Using item: " + item.getTypeId());

        if (!(isOnAllowedList(item.getType())
            || plugin.canBuildOnLocation(player, player.getLocation()))) event.setCancelled(true);
      }
    }
    plugin.debug("Event :" + event.getEventName() + ", cancelled:" + event.isCancelled());
  }
  @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
  public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.getAction() != Action.RIGHT_CLICK_BLOCK || event.useInteractedBlock() == Result.DENY)
      return;

    // For using a hoe for farming
    if (event.getItem() != null
        && event.getItem().getType() != null
        && (event.getMaterial() == Material.DIRT || event.getMaterial() == Material.GRASS)
        && ((event.getItem().getType() == Material.WOOD_HOE)
            || (event.getItem().getType() == Material.IRON_HOE)
            || (event.getItem().getType() == Material.GOLD_HOE)
            || (event.getItem().getType() == Material.DIAMOND_HOE))) {
      BlockUpdate.update(event.getClickedBlock());
    }
  }
 @EventHandler(priority = EventPriority.MONITOR)
 public void onPlayerInteract(PlayerInteractEvent e) {
   ItemStack stack = e.getItem();
   if (e.getPlayer().isOp()) {
     if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)
         && stack != null
         && stack.getType().equals(wand)) {
       if (a.get(e.getPlayer().getName()) == null
           || (b.get(e.getPlayer().getName()) != null && a.get(e.getPlayer().getName()) != null)) {
         a.put(e.getPlayer().getName(), e.getClickedBlock().getLocation());
         b.remove(e.getPlayer().getName());
         e.getPlayer()
             .sendMessage(
                 ChatColor.AQUA
                     + "Selected block A: "
                     + e.getClickedBlock().getLocation().toVector().toString());
       } else if (b.get(e.getPlayer().getName()) == null) {
         b.put(e.getPlayer().getName(), e.getClickedBlock().getLocation());
         e.getPlayer()
             .sendMessage(
                 ChatColor.AQUA
                     + "Selected block B: "
                     + e.getClickedBlock().getLocation().toVector().toString());
       }
     }
   }
 }
  @EventHandler
  public void onPlayerInteract(PlayerInteractEvent event) {
    final PlayerInteractEvent Event = event;

    // If not right clicking air, do nothing
    if (!event.getAction().equals(Action.RIGHT_CLICK_AIR)
        && !event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
      return;
    }
    // If the event doesn't involve an item
    if (!event.hasItem()) {
      return;
    }
    // If the item is null
    if (event.getItem() == null) {
      return;
    }
    // If the item isn't a potion
    if (event.getItem().getType() != Material.POTION) {
      return;
    }
    // Removes the potion effects
    plugin
        .getServer()
        .getScheduler()
        .scheduleSyncDelayedTask(
            plugin,
            new Runnable() {
              public void run() {
                // If the player currently has potion effects
                if (Event.getPlayer().getActivePotionEffects() == null) {
                  return;
                }
                // If the player has less than or eqaul to 0 potion effects
                if (Event.getPlayer().getActivePotionEffects().size() <= 0) {
                  return;
                }

                for (PotionEffect x : Event.getPlayer().getActivePotionEffects()) {
                  if (plugin.getConfig().getBoolean("Potions." + x.getType().getName())) {
                    Event.getPlayer().removePotionEffect(x.getType());
                  }
                }
              }
            },
            40);
  }
  @EventHandler
  public void onPlayerInteract(PlayerInteractEvent arg0) {
    Player player = arg0.getPlayer();

    if (arg0.getItem().getType() == Material.STICK) {
      if (userMap.containsKey(player)) {
        player.performCommand(userMap.get(player));
      }
    }
  }
示例#9
0
  @EventHandler(priority = EventPriority.HIGH)
  public void CropTrampleOrFireCharge(PlayerInteractEvent event) {
    if (event.getClickedBlock() == null) {
      return;
    }

    Player p = event.getPlayer();

    // trampling crops
    if (p != null
        && event.getAction().equals(Action.PHYSICAL)
        && event.getClickedBlock().getType().toString().equals("SOIL")) {
      OwnedLand land = OwnedLand.getApplicableLand(event.getClickedBlock().getLocation());
      if (land == null) {
        return;
      }
      if (land.hasPermTo(p, this)) {
        return;
      }
      p.sendMessage(
          ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.cropDestroy"));
      event.setCancelled(true);
      return;
    }

    // Using fire charge
    ItemStack item = event.getItem();
    if (p != null
        && item != null
        && event.getAction().equals(Action.RIGHT_CLICK_BLOCK)
        && event.getItem().getType().equals(Material.FIREBALL)) {
      OwnedLand land = OwnedLand.getApplicableLand(event.getClickedBlock().getLocation());
      if (land == null) {
        return;
      }
      if (land.hasPermTo(p, this)) {
        return;
      }
      p.sendMessage(
          ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.useFireCharge"));
      event.setCancelled(true);
    }
  }
示例#10
0
 @EventHandler
 protected static void onPlayerInteract(PlayerInteractEvent event) {
   Action action = event.getAction();
   ItemStack item = event.getItem();
   if (action == Action.RIGHT_CLICK_BLOCK || action == Action.RIGHT_CLICK_AIR) {
     if (item != null
         && item.getType() == ITEM.getType()
         && item.getItemMeta().getLore() == ITEM.getItemMeta().getLore()) {
       openGUI(event.getPlayer());
     }
   }
 }
示例#11
0
 @EventHandler
 public void onInteract(PlayerInteractEvent event) {
   if (GameManager.INSTANCE.getSession(event.getPlayer()) == null) return;
   ItemStack item = event.getItem();
   if (item == null
       || (!event.getAction().equals(Action.RIGHT_CLICK_AIR)
           && !event.getAction().equals(Action.RIGHT_CLICK_BLOCK))) return;
   if (item.getType().equals(Material.PAPER) && event.getPlayer().getHealth() != 20) {
     GeneralUtils.subtractItemInHand(event.getPlayer());
     GeneralUtils.addHealthByPaper(event.getPlayer());
   }
   if (event.hasBlock() && !Material.WORKBENCH.equals(event.getClickedBlock().getType()))
     event.setCancelled(true);
 }
示例#12
0
  @EventHandler
  public void onPlayerShoot(PlayerInteractEvent e) {

    Player p = e.getPlayer();

    if (ArenaManager.isPlayerPlaying(p)) {
      if (e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_AIR) {
        if ((e.getItem() != null) && (p.getItemInHand() != null)) {
          if (Objects.equals(
              e.getItem().getItemMeta().getDisplayName(), WeaponManager.WEAPON_NAME)) {
            if (NexusGame.isParticleEffectLibInstalled()) {
              Effect line = new ShootEffect(NexusGame.effects.getEffectManager());
              line.color = Color.PURPLE;
              line.setEntity(p);
              line.setTargetLocation(
                  p.getTargetBlock(Sets.<Material>newHashSet(), 100).getLocation());

              NexusGame.effects.playEffect(line);
            }
          }
        }
      }
    }
  }
 @EventHandler(priority = EventPriority.LOWEST)
 public void onPlayerInteract(PlayerInteractEvent event) {
   if (PConfManager.getPValBoolean(event.getPlayer(), "jailed")) event.setCancelled(true);
   Action act = event.getAction();
   if (act.equals(Action.PHYSICAL)) return;
   ItemStack id = event.getItem();
   if (id == null) return;
   int idn = id.getTypeId();
   if (idn == 0) return;
   List<String> cmds = PConfManager.getPValStringList(event.getPlayer(), "assign." + idn);
   if (cmds == null) return;
   for (String s : cmds) {
     if (s.toLowerCase().trim().startsWith("c:")) event.getPlayer().chat(s.trim().substring(2));
     else event.getPlayer().performCommand(s.trim());
   }
 }
示例#14
0
  /** GUI Trigger Item Listener */
  @EventHandler
  public void onPlayerInteract(PlayerInteractEvent event) {
    Action a = event.getAction();
    ItemStack is = event.getItem();

    if ((a == Action.RIGHT_CLICK_AIR || a == Action.RIGHT_CLICK_BLOCK)
        && is != null
        && is.getType()
            == new ItemStack(
                    SubPlugin.config.getBlockID("Settings.GUI.Trigger-Item")[0],
                    1,
                    (short) SubPlugin.config.getBlockID("Settings.GUI.Trigger-Item")[1])
                .getType()
        && event.getPlayer().hasPermission("SubServer.Command")
        && SubPlugin.config.getBoolean("Settings.GUI.Enabled")) {
      new SubGUI(event.getPlayer(), 0, null, SubPlugin);
      event.setCancelled(true);
    }
  }
示例#15
0
 @Override
 public void shoot(final PlayerInteractEvent e) {
   if (!WeaponWatch.durability.containsKey(e.getItem().getItemMeta().getLore())) {
     WeaponWatch.durability.put(e.getItem().getItemMeta().getLore(), ammo);
   }
   if (WeaponWatch.durability.get(e.getItem().getItemMeta().getLore()) > 0
       && (!WeaponWatch.cooldown.contains(e.getItem().getItemMeta().getLore()))) {
     WeaponWatch.durability.put(
         e.getItem().getItemMeta().getLore(),
         WeaponWatch.durability.get(e.getItem().getItemMeta().getLore()) - 1);
     WeaponWatch.cooldown.add(e.getItem().getItemMeta().getLore());
     safeShoot(e);
     new BukkitRunnable() {
       @Override
       public void run() {
         WeaponWatch.cooldown.remove(e.getItem().getItemMeta().getLore());
       }
     }.runTaskLater(DuckMain.getPlugin(), delay);
   }
 }
示例#16
0
 @Override
 public boolean callPlayerInteractEvent(PlayerInteractEvent event, Integer level) {
   if (event.getAction() == Action.RIGHT_CLICK_AIR
       || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
     ItemStack item = event.getItem();
     if (item != null) {
       Material itype = item.getType();
       if (itype == Material.GOLD_AXE) {
         item.setDurability((short) 0);
         event.getPlayer().sendMessage("Mana decreesed!");
         event.getPlayer().setItemInHand(item);
         return true;
       } else if (itype == Material.GOLD_HOE) {
         item.setDurability((short) 0);
         event.getPlayer().sendMessage("Mana decreesed!");
         event.getPlayer().setItemInHand(item);
         return true;
       } else if (itype == Material.GOLD_PICKAXE) {
         item.setDurability((short) 0);
         event.getPlayer().sendMessage("Mana decreesed!");
         event.getPlayer().setItemInHand(item);
         return true;
       } else if (itype == Material.GOLD_SPADE) {
         item.setDurability((short) 0);
         event.getPlayer().sendMessage("Mana decreesed!");
         event.getPlayer().setItemInHand(item);
         return true;
       } else if (itype == Material.GOLD_SWORD) {
         item.setDurability((short) 0);
         event.getPlayer().sendMessage("Mana decreesed!");
         event.getPlayer().setItemInHand(item);
         return true;
       }
     }
   }
   return false;
 }
示例#17
0
 @EventHandler
 public final void PIE(final PlayerInteractEvent event) {
   if (event.getAction() != Action.RIGHT_CLICK_AIR
       && event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
   final Player player = event.getPlayer();
   if (!player.isSneaking()) return;
   final ItemStack item = event.getItem();
   if (item == null
       || item.getType()
           != Material.getMaterial(
               getConfig().getString("id").trim().toUpperCase().replace(' ', '_'))) return;
   final String name = getConfig().getString("name");
   if (!name.isEmpty()
       && (!item.hasItemMeta()
           || !item.getItemMeta().hasDisplayName()
           || !item.getItemMeta()
               .getDisplayName()
               .equals(ChatColor.translateAlternateColorCodes('&', name)))) return;
   final Item entity =
       player
           .getWorld()
           .dropItem(
               player.getEyeLocation().clone().subtract(0, 0.3, 0), new ItemStack(item.getType()));
   entity.setVelocity(
       player.getLocation().getDirection().normalize().multiply(getConfig().getDouble("speed")));
   entity.setMetadata("isminebomb", new FixedMetadataValue(this, player.getName()));
   if (getConfig().getBoolean("use")) {
     if (item.getAmount() == 1) player.setItemInHand(new ItemStack(Material.AIR));
     else {
       item.setAmount(item.getAmount() - 1);
       player.setItemInHand(item);
     }
   }
   new ExplodeTimer(entity, getConfig().getInt("power"))
       .runTaskLater(this, getConfig().getInt("delay") * 20L);
 }
 @EventHandler
 public void onPlayerInteract(PlayerInteractEvent event) {
   // Open the backpack when the player clicks while holding it
   switch (event.getAction()) {
     case RIGHT_CLICK_AIR:
     case RIGHT_CLICK_BLOCK:
       // Verify that the item has lore
       if (event.hasItem()) {
         ItemStack hand = event.getItem();
         if (hand.hasItemMeta()) {
           ItemMeta meta = hand.getItemMeta();
           if (meta.hasLore()) {
             // Scan the lore for linked PhatLoots
             List<String> lore = meta.getLore();
             for (String line : lore) {
               if (line.startsWith(PhatLootsConfig.lootBagKey)) {
                 PhatLoot phatLoot =
                     PhatLoots.getPhatLoot(line.substring(PhatLootsConfig.lootBagKey.length()));
                 if (phatLoot != null) { // Valid PhatLoot
                   event.setCancelled(true);
                   // Remove the bag from the player's inventory
                   if (hand.getAmount() > 1) {
                     hand.setAmount(hand.getAmount() - 1);
                   } else {
                     event.getPlayer().setItemInHand(new ItemStack(0));
                   }
                   // Give loot to the player
                   phatLoot.rollForLoot(event.getPlayer());
                 }
               }
             }
           }
         }
       }
   }
 }
示例#19
0
  @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
  public void onPlayerInteract(PlayerInteractEvent event) {
    // Prevent trampling
    switch (event.getAction()) {
      case PHYSICAL:
        final Block top = event.getClickedBlock().getRelative((BlockFace.UP));
        if (plugin
            .getWorldRegistry()
            .contains(top.getWorld().getName(), top.getX(), top.getY(), top.getZ())) {
          event.setCancelled(true);
          break;
        }
      case RIGHT_CLICK_BLOCK:
        // Exit this method if player clicking on chest, door, button, etc.
        switch (event.getClickedBlock().getType()) {
          case CHEST:
          case WOOD_BUTTON:
          case STONE_BUTTON:
          case WOOD_DOOR:
          case IRON_DOOR:
          case IRON_DOOR_BLOCK:
          case FENCE_GATE:
          case BREWING_STAND:
          case FURNACE:
          case BURNING_FURNACE:
            return;
        }
        final Player interacter = event.getPlayer();
        final ItemStack held = event.getItem();
        if (held == null) {
          return;
        }
        final Block interacted = event.getClickedBlock();
        final SpoutItemStack stack = new SpoutItemStack(held);
        final String name;

        // Grab the material's name
        if (stack.isCustomItem()) {
          name = stack.getMaterial().getNotchianName();
        } else {
          name = held.getType().name();
        }

        // Fertilizer logic
        final Sprout dispersed =
            plugin
                .getWorldRegistry()
                .get(
                    interacted.getWorld().getName(),
                    interacted.getX(),
                    interacted.getY(),
                    interacted.getZ());
        if (dispersed != null
            && !((SimpleSprout) dispersed).isOnLastStage()
            && dispersed.getVariables().allowFertilization()) {
          final Stage current = dispersed.getCurrentStage();
          final Fertilizer fertilizer;
          if (current == null) {
            fertilizer = dispersed.getFertilizerSource();
          } else {
            fertilizer = current.getFertilizer();
          }

          boolean toContinue = false;

          // Bonemeal
          if ((fertilizer.getName().equals("bonemeal") && name.equals("INK_SACK"))) {
            toContinue = true;
            // Custom Block
          } else if (fertilizer.getName().endsWith(name)) {
            toContinue = true;
            // Material
          } else if (fertilizer.getName().equals(name.toLowerCase())) {
            toContinue = true;
          }
          if (!toContinue) {
            return;
          }
          event.setCancelled(true);

          Stage stage;
          org.getspout.spoutapi.material.Material customMaterial;
          Material material;

          // Stage 0
          if (current == null) {
            stage = dispersed.getStage(1);
            customMaterial = MaterialData.getCustomBlock(stage.getName());
            material = Material.getMaterial(stage.getName().toUpperCase());

            if (customMaterial == null) {
              if (material == null) {
                return;
              }
            }

            // Grow to stage 1
            ((SimpleSprout) dispersed).grow(stage);

            if (customMaterial != null) {
              ((SpoutBlock) interacted).setCustomBlock((CustomBlock) customMaterial);
            } else {
              ((SpoutBlock) interacted).setCustomBlock(null);
              interacted.setType(material);
            }
          } else {
            stage = ((SimpleSprout) dispersed).getNextStage();
            if (stage == null) {
              return;
            }
            customMaterial = MaterialData.getCustomBlock(stage.getName());
            material = Material.getMaterial(stage.getName().toUpperCase());

            if (customMaterial == null) {
              if (material == null) {
                return;
              }
            }

            ((SimpleSprout) dispersed).incrementFertilizerCount(stage);
            if (((SimpleSprout) dispersed).getFertilizerCount(stage) >= fertilizer.getAmount()) {
              if (customMaterial != null) {
                ((SpoutBlock) interacted).setCustomBlock((CustomBlock) customMaterial);
              } else {
                ((SpoutBlock) interacted).setCustomBlock(null);
                interacted.setType(material);
              }
              ((SimpleSprout) dispersed).grow(stage);
            }
            if (((SimpleSprout) dispersed).isOnLastStage()) {
              ((SimpleSprout) dispersed).setFullyGrown(true);
              final SaveThread thread =
                  ((SaveThread) ThreadRegistry.get(interacted.getWorld().getName()));
              if (thread != null) {
                thread.add(interacted.getLocation(), (SimpleSprout) dispersed);
              }
            }
          }
          decrementInventory(interacter, interacter.getItemInHand());
        } else {
          // Non-fertilizer logic
          final Sprout sprout = plugin.getSproutRegistry().find(name);
          if (sprout == null) {
            return;
          }

          event.setCancelled(true);

          // Block face logic. TODO Customizable?
          if (event.getBlockFace() != BlockFace.UP) {
            return;
          }

          // Soil logic
          org.getspout.spoutapi.material.Material customMaterial =
              MaterialData.getCustomItem(sprout.getPlacementSource());
          Material material = Material.getMaterial(sprout.getPlacementSource().toUpperCase());
          if (customMaterial == null
              || !(((SpoutBlock) interacted).getBlockType() instanceof CustomBlock)
              || !((CustomBlock) ((SpoutBlock) interacted).getBlockType())
                  .getFullName()
                  .equalsIgnoreCase(customMaterial.getName())) {
            if (material == null || !interacted.getType().equals(material)) {
              return;
            }
          }

          final Block where = interacted.getRelative(BlockFace.UP);

          // Make sure where we are setting the block won't be already obstructed.
          if (where.getType() != Material.AIR) {
            return;
          }

          // Handle Jobs Integration Calls
          if (SproutConfiguration.jobsEnabled) {
            if (!Jobs.hasRequiredJobAndLevel(
                event.getPlayer(), "Farmer", sprout.getMinimumLevelRequired())) {
              event
                  .getPlayer()
                  .sendMessage(
                      ChatColor.DARK_AQUA
                          + "[Sprout]"
                          + ChatColor.WHITE
                          + " Planting this seed requires the job "
                          + ChatColor.GOLD
                          + "[Farmer]"
                          + ChatColor.WHITE
                          + ", at level "
                          + ChatColor.GOLD
                          + sprout.getMinimumLevelRequired()
                          + ChatColor.WHITE
                          + " or higher.");
              return;
            }
            // Planting experience within jobs is handled by block place of the vanilla block of
            // "CROP"
          }

          final Sprout toInject = cloner.deepClone(sprout);
          plugin
              .getWorldRegistry()
              .add(where.getWorld().getName(), where.getX(), where.getY(), where.getZ(), toInject);
          final SaveThread thread = ((SaveThread) ThreadRegistry.get(where.getWorld().getName()));
          if (thread != null) {
            thread.add(where.getLocation(), (SimpleSprout) toInject);
          }

          // Set material
          if (stack.isCustomItem()) {
            final CustomBlock block = MaterialData.getCustomBlock(sprout.getBlockSource());
            ((SpoutBlock) where).setCustomBlock(block);
            interacter.playSound(interacter.getLocation(), Sound.DIG_GRASS, 1.0F, 0.7936508F);
            decrementInventory(interacter, held);
          }
          // Handle Jobs Integration Calls

          if (SproutConfiguration.jobsEnabled) {
            JobsWorker.jobsPlace(event.getPlayer(), where);
          }
        }
    }
  }
示例#20
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void PlayerInteractEvent(PlayerInteractEvent e) {

    Player p = e.getPlayer();

    CEventHandler.handleEvent(p, e, interact);

    if (e.getAction().toString().startsWith("LEFT")) CEventHandler.handleEvent(p, e, interactL);
    else if (e.getAction().toString().startsWith("RIGHT")) {
      CEventHandler.handleEvent(p, e, interactR);

      // Check if the player has put armor on by rightclicking
      if (p.getItemInHand().getType() != Material.AIR) {
        ItemStack i = p.getItemInHand();
        String mat = i.getType().toString();
        PlayerInventory inv = p.getInventory();
        if ((mat.endsWith("BOOTS") && inv.getBoots() == null)
            || (mat.endsWith("LEGGINGS") && inv.getLeggings() == null)
            || (mat.endsWith("CHESTPLATE") && inv.getChestplate() == null)
            || (mat.endsWith("HELMET") && inv.getHelmet() == null))
          CEventHandler.handleArmor(p, e.getItem(), false, e);
      }
    }

    // Sign shop
    if (e.getClickedBlock() != null && e.getClickedBlock().getType().toString().contains("SIGN"))
      if (((Sign) e.getClickedBlock().getState()).getLine(0).equals("[CustomEnchant]")) {
        if (!Main.hasEconomy) {
          p.performCommand("ce menu");
        } else if (p.getItemInHand().getType() != Material.AIR) {
          Sign sign = ((Sign) e.getClickedBlock().getState());
          CEnchantment ce = Tools.getEnchantmentByDisplayname(sign.getLine(1));
          if (ce == null) Tools.getEnchantmentByOriginalname(sign.getLine(1));
          if (ce == null)
            for (CEnchantment ceT : Main.enchantments)
              if (Tools.checkForEnchantment(sign.getLine(1), ceT)) ce = ceT;
          if (ce == null) return;

          ItemStack inHand = p.getItemInHand();
          if (!Tools.isApplicable(inHand, ce)) {
            p.sendMessage(ChatColor.RED + "[CE] This enchantment can not be applied to this item.");
            return;
          }

          int cost = 0;
          try {
            cost = Integer.parseInt(sign.getLine(3).replaceAll("\\D+", ""));
          } catch (NumberFormatException ex) {
            return;
          }

          if (inHand.hasItemMeta() && inHand.getItemMeta().hasLore()) {
            List<String> lore = inHand.getItemMeta().getLore();
            for (int i = 0; i < lore.size(); i++)
              if (Tools.checkForEnchantment(lore.get(i), ce)) {
                int newLevel = Tools.getLevel(lore.get(i)) + 1;
                if (newLevel <= ce.getEnchantmentMaxLevel()) {
                  if (Main.econ.getBalance(p.getName()) >= cost) {
                    EconomyResponse ecr = Main.econ.withdrawPlayer(p.getName(), cost);
                    if (ecr.transactionSuccess())
                      p.sendMessage(
                          ChatColor.GREEN
                              + "[CE] Upgraded enchantment "
                              + ce.getDisplayName()
                              + ChatColor.RESET
                              + ""
                              + ChatColor.GREEN
                              + " for "
                              + cost
                              + " "
                              + ((cost == 1)
                                  ? Main.econ.currencyNameSingular()
                                  : Main.econ.currencyNamePlural()));
                    else {
                      p.sendMessage(ChatColor.RED + "[CE] An economy error has occured:");
                      p.sendMessage(ChatColor.RED + ecr.errorMessage);
                      p.closeInventory();
                      return;
                    }
                  } else {
                    p.sendMessage(ChatColor.RED + "[CE] You do not have enough money to buy this!");
                    p.closeInventory();
                    return;
                  }
                  lore.set(i, ce.getDisplayName() + " " + Tools.intToLevel(newLevel));
                  ItemMeta im = inHand.getItemMeta();
                  im.setLore(lore);
                  inHand.setItemMeta(im);
                  return;
                } else {
                  p.sendMessage(
                      ChatColor.RED
                          + "[CE] You already have the maximum level of this enchantment!");
                  return;
                }
              }
          }

          List<String> lore = new ArrayList<String>();
          ItemMeta im = inHand.getItemMeta();

          if (inHand.getItemMeta().hasLore()) lore = im.getLore();

          if (Main.econ.getBalance(p.getName()) >= cost) {
            EconomyResponse ecr = Main.econ.withdrawPlayer(p.getName(), cost);
            if (ecr.transactionSuccess())
              p.sendMessage(
                  ChatColor.GREEN
                      + "[CE] Bought enchantment "
                      + ce.getDisplayName()
                      + ChatColor.RESET
                      + ""
                      + ChatColor.GREEN
                      + " for "
                      + cost
                      + " "
                      + ((cost == 1)
                          ? Main.econ.currencyNameSingular()
                          : Main.econ.currencyNamePlural()));
            else {
              Bukkit.getConsoleSender()
                  .sendMessage(ChatColor.RED + "[CE] An economy error has occured:");
              Bukkit.getConsoleSender().sendMessage(ChatColor.RED + ecr.errorMessage);
              p.closeInventory();
              return;
            }
          } else {
            p.sendMessage(ChatColor.RED + "[CE] You do not have enough money to buy this!");
            p.closeInventory();
            return;
          }

          lore.add(ce.getDisplayName() + " I");
          im.setLore(lore);
          inHand.setItemMeta(im);
          return;

        } else {
          p.sendMessage(ChatColor.RED + "[CE] You do not have an item in your hand.");
          return;
        }
      }
  }
示例#21
0
  @Override
  public void onInteract(PlayerInteractEvent event) {

    try {

      if (War.isWarTime()) {
        throw new CivException("Cannot use spy missions during war time.");
      }

      ConfigMission mission = CivSettings.missions.get(this.getId());
      if (mission == null) {
        throw new CivException("Unknown mission " + this.getId());
      }

      Resident resident = CivGlobal.getResident(event.getPlayer());
      if (resident == null || !resident.hasTown()) {
        throw new CivException("Only residents of towns can perform spy missions.");
      }

      Date now = new Date();

      if (!event.getPlayer().isOp()) {
        try {
          int spyRegisterTime =
              CivSettings.getInteger(CivSettings.espionageConfig, "espionage.spy_register_time");
          int spyOnlineTime =
              CivSettings.getInteger(CivSettings.espionageConfig, "espionage.spy_online_time");

          long expire = resident.getRegistered() + (spyRegisterTime * 60 * 1000);
          if (now.getTime() <= expire) {
            throw new CivException(
                "You cannot use a spy yet, you must play CivCraft a bit longer before you can use it.");
          }

          expire = resident.getLastOnline() + (spyOnlineTime * 60 * 1000);
          if (now.getTime() <= expire) {
            throw new CivException("You must be online longer before you can use a spy.");
          }
        } catch (InvalidConfiguration e) {
          e.printStackTrace();
        }
      }

      ConfigUnit unit = Unit.getPlayerUnit(event.getPlayer());
      if (unit == null || !unit.id.equals("u_spy")) {
        event.getPlayer().getInventory().remove(event.getItem());
        throw new CivException("Only spies can use mission books.");
      }

      ChunkCoord coord = new ChunkCoord(event.getPlayer().getLocation());
      CultureChunk cc = CivGlobal.getCultureChunk(coord);
      TownChunk tc = CivGlobal.getTownChunk(coord);

      if (cc == null || cc.getCiv() == resident.getCiv()) {
        throw new CivException(
            "You must be in a civilization's culture that's not your own to spy on them.");
      }

      if ((cc != null && cc.getCiv().isAdminCiv())
          || (tc != null && tc.getTown().getCiv().isAdminCiv())) {
        throw new CivException("You cannot spy on an admin civ.");
      }

      if (CivGlobal.isCasualMode()) {
        if (!cc.getCiv().getDiplomacyManager().isHostileWith(resident.getCiv())
            && !cc.getCiv().getDiplomacyManager().atWarWith(resident.getCiv())) {
          throw new CivException(
              "You must be hostile or at war with "
                  + cc.getCiv().getName()
                  + " in order to perform spy missions in casual mode.");
        }
      }

      resident.setInteractiveMode(
          new InteractiveSpyMission(
              mission, event.getPlayer().getName(), event.getPlayer().getLocation(), cc.getTown()));
    } catch (CivException e) {
      CivMessage.sendError(event.getPlayer(), e.getMessage());
    }
  }
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onPlayerInteract(PlayerInteractEvent event) {
    if (!event.hasBlock()) return;

    Action action = event.getAction();
    Player player = event.getPlayer();
    Block block = event.getClickedBlock();
    int type = block.getTypeId();
    BlockFace face = event.getBlockFace();

    if (action == Action.RIGHT_CLICK_BLOCK) {
      if (Lockette.protectTrapDoors)
        if (type == Material.TRAP_DOOR.getId()) {
          if (interactDoor(block, player)) return;

          event.setUseInteractedBlock(Result.DENY);
          event.setUseItemInHand(Result.DENY);
          return;
        }

      if (Lockette.protectDoors)
        if ((type == Material.WOODEN_DOOR.getId())
            || (type == Material.IRON_DOOR_BLOCK.getId())
            || (type == materialFenceGate)) {
          if (interactDoor(block, player)) return;

          event.setUseInteractedBlock(Result.DENY);
          event.setUseItemInHand(Result.DENY);
          return;
        }

      if (type == Material.WALL_SIGN.getId()) {
        interactSign(block, player);
        return;
      }

      if (type == Material.CHEST.getId()) {
        // Try at making a 1.7->1.8 chest fixer.
        Lockette.rotateChestOrientation(block, face);
      }

      if ((type == Material.CHEST.getId())
          || (type == Material.DISPENSER.getId())
          || (type == Material.FURNACE.getId())
          || (type == Material.BURNING_FURNACE.getId())
          || (type == Material.BREWING_STAND.getId())
          || Lockette.isInList(type, Lockette.customBlockList)) {

        // Trying something out....
        if (Lockette.directPlacement)
          if (event.hasItem())
            if ((face != BlockFace.UP) && (face != BlockFace.DOWN)) {
              ItemStack item = event.getItem();

              if (item.getTypeId() == Material.SIGN.getId()) {
                Block checkBlock = block.getRelative(face);

                type = checkBlock.getTypeId();

                if (type == Material.AIR.getId()) {
                  boolean place = false;

                  if (Lockette.isProtected(block)) {
                    // Add a users sign only if owner.
                    if (Lockette.isOwner(block, player.getName())) place = true;
                  } else place = true;
                  // if(Lockette.altPrivate == null){}//if(Lockette.altMoreUsers == null){}
                  if (place) {
                    // player.sendMessage(ChatColor.RED + "Lockette: Using a sign on a container");

                    event.setUseItemInHand(Result.ALLOW); // ? seems to work in 568
                    event.setUseInteractedBlock(Result.DENY);
                    return;
                  }
                }
              }
            }

        if (interactContainer(block, player)) return;

        event.setUseInteractedBlock(Result.DENY);
        event.setUseItemInHand(Result.DENY);
        return;
      }

      if (type == Material.DIRT.getId())
        if (event.hasItem()) {
          ItemStack item = event.getItem();

          type = item.getTypeId();

          if ((type == Material.DIAMOND_HOE.getId())
              || (type == Material.GOLD_HOE.getId())
              || (type == Material.IRON_HOE.getId())
              || (type == Material.STONE_HOE.getId())
              || (type == Material.WOOD_HOE.getId())) {
            Block checkBlock = block.getRelative(BlockFace.UP);

            type = checkBlock.getTypeId();

            if ((type == Material.WOODEN_DOOR.getId())
                || (type == Material.IRON_DOOR_BLOCK.getId())
                || (type == materialFenceGate)) {
              event.setUseInteractedBlock(Result.DENY);
              return;
            }
          }
        }
    } else if (action == Action.LEFT_CLICK_BLOCK) {
      if (Lockette.protectTrapDoors)
        if (type == Material.TRAP_DOOR.getId()) {
          if (interactDoor(block, player)) return;

          event.setUseInteractedBlock(Result.DENY);
          event.setUseItemInHand(Result.DENY);
          return;
        }

      if (Lockette.protectDoors)
        if ((type == Material.WOODEN_DOOR.getId())
            || (type == Material.IRON_DOOR_BLOCK.getId())
            || (type == materialFenceGate)) {
          if (interactDoor(block, player)) return;

          event.setUseInteractedBlock(Result.DENY);
          event.setUseItemInHand(Result.DENY);
          return;
        }
    }
  }
  public static void onInteract(PlayerInteractEvent e) {
    Player p = e.getPlayer();
    if (gunBuilder.get(p) == true) {
      if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if (e.getItem() == null || e.getItem().getType() == Material.AIR) return;
        if (gunBuilderStep.get(p) == 1) {
          e.setCancelled(true);
          ItemStack gun =
              new ItemStack(p.getItemInHand().getType(), 1, p.getItemInHand().getData().getData());
          Gun.put(p, gun);
          p.sendMessage(" §f» §8Set gun item to§7 " + gun.getType());
          p.sendMessage("§22. §aPut the ammo in your hand and right-click");
          gunBuilderStep.put(p, 2);
        } else if (gunBuilderStep.get(p) == 2) {
          e.setCancelled(true);
          ItemStack ammo =
              new ItemStack(
                  p.getItemInHand().getType(),
                  p.getItemInHand().getAmount(),
                  p.getItemInHand().getData().getData());
          Ammo.put(p, ammo);
          // if (gamemode.get(p) != null)
          // p.setGameMode(gamemode.get(p));
          p.sendMessage(" §f» §8Set ammo to§7 " + ammo.getType());
          p.sendMessage("§23. §aNow type the name of the gun in the chat");
          gunBuilderStep.put(p, 3);
        } else if (gunBuilderStep.get(p) == 7) {
          e.setCancelled(true);
          if ((e.getItem().getType().equals(Material.WOOL))
              && (e.getItem().getData().getData() == (byte) 14)) {
            type.put(p, "primary");
            p.getInventory().clear();
            p.getInventory().setItem(1, confirm);
            p.getInventory().setItem(7, abort);
            p.getInventory().setHeldItemSlot(4);

            p.sendMessage(" §f» §8Set gun type to §7primary");
            p.sendMessage(
                "§28. §aNow right-click the green dye to confirm gun creation or right-click the purple dye to cancel gun creation");

            p.updateInventory();
            gunBuilderStep.put(p, 8);
          } else if ((e.getItem().getType().equals(Material.WOOL))
              && (e.getItem().getData().getData() == (byte) 5)) {
            type.put(p, "secondary");
            p.getInventory().clear();
            p.getInventory().setItem(1, confirm);
            p.getInventory().setItem(7, abort);
            p.getInventory().setHeldItemSlot(4);

            p.sendMessage(" §f» §8Set gun type to §7secondary");
            p.sendMessage(
                "§28. §aNow right-click the green dye to confirm gun creation or right-click the purple dye to cancel gun creation");

            p.updateInventory();
            gunBuilderStep.put(p, 8);
          }
        } else if (gunBuilderStep.get(p) == 8) {
          e.setCancelled(true);
          if (e.getItem().getType().equals(Material.INK_SACK)
              && (e.getItem().getData().getData() == (byte) 10)) {
            p.sendMessage(" §e» §6Finalizing gun creation...");
            if (!(makeAutoGun(p))) {
              p.sendMessage("§cGun creation failed");
            } else {
              p.sendMessage(" §b» §3Successfully created gun!");
            }
            endGunCreation(p, false);
          } else if (e.getItem().getType().equals(Material.INK_SACK)
              && (e.getItem().getData().getData() == (byte) 5)) {
            endGunCreation(p, true);
          }
        }
      }
    } else {
      return;
    }
  }
  @SuppressWarnings("deprecation")
  @EventHandler(priority = EventPriority.LOWEST)
  public void onPlayerInteract(PlayerInteractEvent event) {
    // ignore stepping onto or into a block
    if (event.getAction() == Action.PHYSICAL) {
      return;
    }

    final Player player = event.getPlayer();
    Block block = event.getClickedBlock();

    ItemStack item = event.getItem();
    if (item == null) {
      item = player.getItemInHand();
    }

    // ignore all vanilla items and edible items in vanilla blocks actions
    if (block != null
        && (item.getData().getItemType().isEdible() || isVanilla(item.getType()))
        && isVanilla(block.getType())) {
      return;
    }

    // whitelisted item check
    if (this.instance.config.matchWhitelistItem(
            item.getType(), item.getData().getData(), player.getWorld().getName())
        != null) {
      return;
    }

    // special aoe items list (needs to check a wide area...)
    ListedRangedItem rangeItem =
        this.instance.config.matchAoEItem(
            item.getType(), item.getData().getData(), player.getWorld().getName());
    if (rangeItem != null) {
      // check players location
      for (ProtectionHandler protection : ProtectionPlugins.getHandlers()) {
        if (!protection.canUseAoE(player, player.getLocation(), rangeItem.range)) {
          event.setUseInteractedBlock(Result.DENY);
          event.setUseItemInHand(Result.DENY);
          event.setCancelled(true);
          this.confiscateInventory(player);
          return;
        }
      }
      return;
    }

    if (block == null) {
      // check if the item in hand is a ranged item
      rangeItem =
          this.instance.config.matchRangedItem(
              item.getType(), item.getData().getData(), player.getWorld().getName());
      if (rangeItem != null) {
        block = getTargetBlock(player, rangeItem.range);
      }
    }

    Location targetLocation;
    if (block == null) {
      targetLocation = player.getLocation();
    } else {
      targetLocation = block.getLocation();
    }

    // check permissions on that location
    for (ProtectionHandler protection : ProtectionPlugins.getHandlers()) {
      if (!protection.canInteract(player, targetLocation)) {
        event.setUseInteractedBlock(Result.DENY);
        event.setUseItemInHand(Result.DENY);
        event.setCancelled(true);
        this.confiscateInventory(player);
        return;
      }
    }
  }
 @EventHandler
 public void onInteract(PlayerInteractEvent e) {
   if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
     ItemStack item = e.getItem();
     Player p = e.getPlayer();
     if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BACKPACK_SMALL, false)) {
       e.setCancelled(true);
       if (Slimefun.hasUnlocked(p, SlimefunItems.BACKPACK_SMALL, true)) {
         if (item.getAmount() == 1) {
           for (int line = 0; line < item.getItemMeta().getLore().size(); line++) {
             if (item.getItemMeta().getLore().get(line).equals("§7ID: <ID>")) {
               ItemMeta im = item.getItemMeta();
               List<String> lore = im.getLore();
               lore.set(line, lore.get(line).replace("<ID>", Backpacks.createBackpack(p, 9)));
               im.setLore(lore);
               item.setItemMeta(im);
               break;
             }
           }
           Backpacks.openBackpack(p, item);
           p.playSound(p.getLocation(), Sound.HORSE_ARMOR, 1F, 1F);
           Variables.backpack.put(p.getUniqueId(), item);
         } else Messages.local.sendTranslation(p, "backpack.no-stack", true);
       }
     } else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BACKPACK_MEDIUM, false)) {
       e.setCancelled(true);
       if (Slimefun.hasUnlocked(p, SlimefunItems.BACKPACK_MEDIUM, true)) {
         if (item.getAmount() == 1) {
           for (int line = 0; line < item.getItemMeta().getLore().size(); line++) {
             if (item.getItemMeta().getLore().get(line).equals("§7ID: <ID>")) {
               ItemMeta im = item.getItemMeta();
               List<String> lore = im.getLore();
               lore.set(line, lore.get(line).replace("<ID>", Backpacks.createBackpack(p, 18)));
               im.setLore(lore);
               item.setItemMeta(im);
               break;
             }
           }
           Backpacks.openBackpack(p, item);
           p.playSound(p.getLocation(), Sound.HORSE_ARMOR, 1F, 1F);
           Variables.backpack.put(p.getUniqueId(), item);
         } else Messages.local.sendTranslation(p, "backpack.no-stack", true);
       }
     } else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BACKPACK_LARGE, false)) {
       e.setCancelled(true);
       if (Slimefun.hasUnlocked(p, SlimefunItems.BACKPACK_LARGE, true)) {
         if (item.getAmount() == 1) {
           for (int line = 0; line < item.getItemMeta().getLore().size(); line++) {
             if (item.getItemMeta().getLore().get(line).equals("§7ID: <ID>")) {
               ItemMeta im = item.getItemMeta();
               List<String> lore = im.getLore();
               lore.set(line, lore.get(line).replace("<ID>", Backpacks.createBackpack(p, 27)));
               im.setLore(lore);
               item.setItemMeta(im);
               break;
             }
           }
           Backpacks.openBackpack(p, item);
           p.playSound(p.getLocation(), Sound.HORSE_ARMOR, 1F, 1F);
           Variables.backpack.put(p.getUniqueId(), item);
         } else Messages.local.sendTranslation(p, "backpack.no-stack", true);
       }
     } else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.WOVEN_BACKPACK, false)) {
       e.setCancelled(true);
       if (Slimefun.hasUnlocked(p, SlimefunItems.WOVEN_BACKPACK, true)) {
         if (item.getAmount() == 1) {
           for (int line = 0; line < item.getItemMeta().getLore().size(); line++) {
             if (item.getItemMeta().getLore().get(line).equals("§7ID: <ID>")) {
               ItemMeta im = item.getItemMeta();
               List<String> lore = im.getLore();
               lore.set(line, lore.get(line).replace("<ID>", Backpacks.createBackpack(p, 36)));
               im.setLore(lore);
               item.setItemMeta(im);
               break;
             }
           }
           Backpacks.openBackpack(p, item);
           p.playSound(p.getLocation(), Sound.HORSE_ARMOR, 1F, 1F);
           Variables.backpack.put(p.getUniqueId(), item);
         } else Messages.local.sendTranslation(p, "backpack.no-stack", true);
       }
     } else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.GILDED_BACKPACK, false)) {
       e.setCancelled(true);
       if (Slimefun.hasUnlocked(p, SlimefunItems.GILDED_BACKPACK, true)) {
         if (item.getAmount() == 1) {
           for (int line = 0; line < item.getItemMeta().getLore().size(); line++) {
             if (item.getItemMeta().getLore().get(line).equals("§7ID: <ID>")) {
               ItemMeta im = item.getItemMeta();
               List<String> lore = im.getLore();
               lore.set(line, lore.get(line).replace("<ID>", Backpacks.createBackpack(p, 45)));
               im.setLore(lore);
               item.setItemMeta(im);
               break;
             }
           }
           Backpacks.openBackpack(p, item);
           p.playSound(p.getLocation(), Sound.HORSE_ARMOR, 1F, 1F);
           Variables.backpack.put(p.getUniqueId(), item);
         } else Messages.local.sendTranslation(p, "backpack.no-stack", true);
       }
     } else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BOUND_BACKPACK, false)) {
       e.setCancelled(true);
       if (Slimefun.hasUnlocked(p, SlimefunItems.BOUND_BACKPACK, true)) {
         if (item.getAmount() == 1) {
           for (int line = 0; line < item.getItemMeta().getLore().size(); line++) {
             if (item.getItemMeta().getLore().get(line).equals("§7ID: <ID>")) {
               ItemMeta im = item.getItemMeta();
               List<String> lore = im.getLore();
               lore.set(line, lore.get(line).replace("<ID>", Backpacks.createBackpack(p, 36)));
               im.setLore(lore);
               item.setItemMeta(im);
               break;
             }
           }
           Backpacks.openBackpack(p, item);
           p.playSound(p.getLocation(), Sound.HORSE_ARMOR, 1F, 1F);
           Variables.backpack.put(p.getUniqueId(), item);
         } else Messages.local.sendTranslation(p, "backpack.no-stack", true);
       }
     } else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.COOLER, false)) {
       e.setCancelled(true);
       if (Slimefun.hasUnlocked(p, SlimefunItems.COOLER, true)) {
         if (item.getAmount() == 1) {
           for (int line = 0; line < item.getItemMeta().getLore().size(); line++) {
             if (item.getItemMeta().getLore().get(line).equals("§7ID: <ID>")) {
               ItemMeta im = item.getItemMeta();
               List<String> lore = im.getLore();
               lore.set(line, lore.get(line).replace("<ID>", Backpacks.createBackpack(p, 27)));
               im.setLore(lore);
               item.setItemMeta(im);
               break;
             }
           }
           Backpacks.openBackpack(p, item);
           p.playSound(p.getLocation(), Sound.HORSE_ARMOR, 1F, 1F);
           Variables.backpack.put(p.getUniqueId(), item);
         } else Messages.local.sendTranslation(p, "backpack.no-stack", true);
       }
     }
   }
 }
示例#26
0
  @SuppressWarnings("deprecation")
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
      return; // Not using on a block!
    }
    Block target = event.getClickedBlock();
    ItemStack item = event.getItem();

    if (item == null
        || (item.getType() != Material.INK_SACK && item.getType() != Material.MAGMA_CREAM)) {
      return; // Not clicked with dye
    }

    if (event.getPlayer().hasPermission("wooddye.candye")) {
      return;
    }

    boolean hasDyed = false;

    Material tt = target.getType();

    if (item.getType() == Material.INK_SACK) {

      boolean lighten = false;
      boolean darken = false;

      switch (item.getData().getData()) {
        case 0: // black
        case 3: // brown
          darken = true;
          break;
        case 7: // silver
        case 15: // white
          lighten = true;
          break;
      }
      if (item.getData().getData() == 0 || item.getData().getData() == 3) {
        darken = true;
      } // black - brown : darken
      if (item.getData().getData() == 15 || item.getData().getData() == 7) {
        lighten = true;
      } // white or silver :lighten

      if (WoodDye.debugMode) {
        System.out.print(
            "WoodDye Click: "
                + target.getType()
                + ":"
                + target.getData()
                + " - "
                + item.getType()
                + ":"
                + item.getData().getData());
      }

      switch (tt) {
        case WOOD:
        case WOOD_DOUBLE_STEP:
        case WOOD_STEP:
          /* 2 Birch Wood - white (15)
           * 0 Oak Wood - Light Gray (7)
           * 3 Jungle Wood - yellow (11)
           * 4 Acacia Word - orange (14)
           * 1 spruce - brown (3)
           * 5 Dark Oak - black (0) */
          switch (target.getData()) {
            case 2: // birch
              if (darken) {
                target.setData((byte) 0);
                hasDyed = true;
              }
              break;
            case 0: // oak
              if (darken) {
                target.setData((byte) 3);
                hasDyed = true;
              } else if (lighten) {
                target.setData((byte) 2);
                hasDyed = true;
              }
              break;
            case 3: // jungle
              if (darken) {
                target.setData((byte) 4);
                hasDyed = true;
              } else if (lighten) {
                target.setData((byte) 0);
                hasDyed = true;
              }
              break;
            case 4: // accacia
              if (darken) {
                target.setData((byte) 1);
                hasDyed = true;
              } else if (lighten) {
                target.setData((byte) 3);
                hasDyed = true;
              }
              break;
            case 1: // spruce
              if (darken) {
                target.setData((byte) 5);
                hasDyed = true;
              } else if (lighten) {
                target.setData((byte) 4);
                hasDyed = true;
              }
              break;
            case 5: // dark oak
              if (lighten) { // white or silver :lighten
                target.setData((byte) 1);
                hasDyed = true;
              }
              break;

            case 10: // birch slab top
              if (darken) {
                target.setData((byte) 8);
                hasDyed = true;
              }
              break;
            case 8: // oak slab top
              if (darken) {
                target.setData((byte) 11);
                hasDyed = true;
              } else if (lighten) {
                target.setData((byte) 10);
                hasDyed = true;
              }
              break;
            case 11: // jungle slab top
              if (darken) {
                target.setData((byte) 12);
                hasDyed = true;
              } else if (lighten) {
                target.setData((byte) 8);
                hasDyed = true;
              }
              break;
            case 12: // accacia slab top
              if (darken) {
                target.setData((byte) 9);
                hasDyed = true;
              } else if (lighten) {
                target.setData((byte) 11);
                hasDyed = true;
              }
              break;
            case 9: // spruce slab top
              if (darken) {
                target.setData((byte) 13);
                hasDyed = true;
              } else if (lighten) {
                target.setData((byte) 12);
                hasDyed = true;
              }
              break;
            case 13: // dark oak slab top
              if (lighten) {
                target.setData((byte) 9);
                hasDyed = true;
              }
              break;

            default:
              System.out.print("New wood type? - " + item.getType());
          }

          break;
        case BIRCH_WOOD_STAIRS:
          if (darken) {
            target.setType(Material.WOOD_STAIRS);
            hasDyed = true;
          }
          break;
        case WOOD_STAIRS:
          if (darken) {
            target.setType(Material.JUNGLE_WOOD_STAIRS);
            hasDyed = true;
          } else if (lighten) {
            target.setType(Material.BIRCH_WOOD_STAIRS);
            hasDyed = true;
          }
          break;
        case JUNGLE_WOOD_STAIRS:
          if (darken) {
            target.setType(Material.ACACIA_STAIRS);
            hasDyed = true;
          } else if (lighten) {
            target.setType(Material.BIRCH_WOOD_STAIRS);
            hasDyed = true;
          }
          break;
        case ACACIA_STAIRS:
          if (darken) {
            target.setType(Material.SPRUCE_WOOD_STAIRS);
            hasDyed = true;
          } else if (lighten) {
            target.setType(Material.JUNGLE_WOOD_STAIRS);
            hasDyed = true;
          }
          break;
        case SPRUCE_WOOD_STAIRS:
          if (darken) {
            target.setType(Material.DARK_OAK_STAIRS);
            hasDyed = true;
          } else if (lighten) {
            target.setType(Material.ACACIA_STAIRS);
            hasDyed = true;
          }
          break;
        case DARK_OAK_STAIRS:
          if (lighten) {
            target.setType(Material.SPRUCE_WOOD_STAIRS);
            hasDyed = true;
          }
          break;
        default:
          break;
      }
    } else if (item.getType() == Material.MAGMA_CREAM && WoodDye.fireProof) {
      switch (tt) {
        case WOOD:
        case WOOD_DOUBLE_STEP:
          target.setType(Material.DOUBLE_STEP);
          target.setData((byte) 2);
          hasDyed = true;
          break;
        case WOOD_STEP:
          if (target.getData() > 7) {
            target.setType(Material.STEP);
            target.setData((byte) 10);
          } else {
            target.setType(Material.STEP);
            target.setData((byte) 2);
          }
          hasDyed = true;
          break;
      }
    }

    if (WoodDye.useItems && hasDyed) {
      ItemStack holding = item;
      holding.setAmount(holding.getAmount() - 1);
      event.getPlayer().setItemInHand(holding);
    }
  }
  @EventHandler(priority = EventPriority.HIGH)
  public void onPlayerInteract(PlayerInteractEvent event) {
    final Player player = event.getPlayer();
    final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);

    switch (event.getAction()) {
      case RIGHT_CLICK_AIR:
      case RIGHT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case WATER_BUCKET:
              {
                if (TFM_AdminList.isSuperAdmin(player)
                    || TFM_ConfigEntry.ALLOW_WATER_PLACE.getBoolean()) {
                  break;
                }

                player
                    .getInventory()
                    .setItem(
                        player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
                player.sendMessage(ChatColor.GRAY + "Water buckets are currently disabled.");
                event.setCancelled(true);
                break;
              }

            case LAVA_BUCKET:
              {
                if (TFM_AdminList.isSuperAdmin(player)
                    || TFM_ConfigEntry.ALLOW_LAVA_PLACE.getBoolean()) {
                  break;
                }

                player
                    .getInventory()
                    .setItem(
                        player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
                player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled.");
                event.setCancelled(true);
                break;
              }

            case EXPLOSIVE_MINECART:
              {
                if (TFM_ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean()) {
                  break;
                }

                player.getInventory().clear(player.getInventory().getHeldItemSlot());
                player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled.");
                event.setCancelled(true);
                break;
              }
          }
          break;
        }

      case LEFT_CLICK_AIR:
      case LEFT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case STICK:
              {
                if (!TFM_AdminList.isSuperAdmin(player)) {
                  break;
                }

                event.setCancelled(true);

                final Location location =
                    TFM_DepreciationAggregator.getTargetBlock(player, null, 5).getLocation();
                final List<RollbackEntry> entries =
                    TFM_RollbackManager.getEntriesAtLocation(location);

                if (entries.isEmpty()) {
                  TFM_Util.playerMsg(player, "No block edits at that location.");
                  break;
                }

                TFM_Util.playerMsg(
                    player,
                    "Block edits at ("
                        + ChatColor.WHITE
                        + "x"
                        + location.getBlockX()
                        + ", y"
                        + location.getBlockY()
                        + ", z"
                        + location.getBlockZ()
                        + ChatColor.BLUE
                        + ")"
                        + ChatColor.WHITE
                        + ":",
                    ChatColor.BLUE);
                for (RollbackEntry entry : entries) {
                  TFM_Util.playerMsg(
                      player,
                      " - "
                          + ChatColor.BLUE
                          + entry.author
                          + " "
                          + entry.getType()
                          + " "
                          + StringUtils.capitalize(entry.getMaterial().toString().toLowerCase())
                          + (entry.data == 0 ? "" : ":" + entry.data));
                }

                break;
              }

            case BONE:
              {
                if (!playerdata.mobThrowerEnabled()) {
                  break;
                }

                Location player_pos = player.getLocation();
                Vector direction = player_pos.getDirection().normalize();

                LivingEntity rezzed_mob =
                    (LivingEntity)
                        player
                            .getWorld()
                            .spawnEntity(
                                player_pos.add(direction.multiply(2.0)),
                                playerdata.mobThrowerCreature());
                rezzed_mob.setVelocity(direction.multiply(playerdata.mobThrowerSpeed()));
                playerdata.enqueueMob(rezzed_mob);

                event.setCancelled(true);
                break;
              }

            case SULPHUR:
              {
                if (!playerdata.isMP44Armed()) {
                  break;
                }

                event.setCancelled(true);

                if (playerdata.toggleMP44Firing()) {
                  playerdata.startArrowShooter(TotalFreedomMod.plugin);
                } else {
                  playerdata.stopArrowShooter();
                }
                break;
              }

            case BLAZE_ROD:
              {
                if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
                  break;
                }

                if (!TFM_AdminList.isSeniorAdmin(player, true)) {
                  break;
                }

                event.setCancelled(true);
                Block targetBlock;

                if (event.getAction().equals(Action.LEFT_CLICK_AIR)) {
                  targetBlock = TFM_DepreciationAggregator.getTargetBlock(player, null, 120);
                } else {
                  targetBlock = event.getClickedBlock();
                }

                if (targetBlock == null) {
                  player.sendMessage("Can't resolve target block.");
                  break;
                }

                player.getWorld().createExplosion(targetBlock.getLocation(), 4F, true);
                player.getWorld().strikeLightning(targetBlock.getLocation());

                break;
              }

            case CARROT:
              {
                if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
                  break;
                }

                if (!TFM_AdminList.isSeniorAdmin(player, true)) {
                  break;
                }

                Location location = player.getLocation().clone();

                Vector playerPostion = location.toVector().add(new Vector(0.0, 1.65, 0.0));
                Vector playerDirection = location.getDirection().normalize();

                double distance = 150.0;
                Block targetBlock =
                    TFM_DepreciationAggregator.getTargetBlock(
                        player, null, Math.round((float) distance));
                if (targetBlock != null) {
                  distance = location.distance(targetBlock.getLocation());
                }

                final List<Block> affected = new ArrayList<Block>();

                Block lastBlock = null;
                for (double offset = 0.0; offset <= distance; offset += (distance / 25.0)) {
                  Block block =
                      playerPostion
                          .clone()
                          .add(playerDirection.clone().multiply(offset))
                          .toLocation(player.getWorld())
                          .getBlock();

                  if (!block.equals(lastBlock)) {
                    if (block.isEmpty()) {
                      affected.add(block);
                      block.setType(Material.TNT);
                    } else {
                      break;
                    }
                  }

                  lastBlock = block;
                }

                new BukkitRunnable() {
                  @Override
                  public void run() {
                    for (Block tntBlock : affected) {
                      TNTPrimed tnt =
                          tntBlock.getWorld().spawn(tntBlock.getLocation(), TNTPrimed.class);
                      tnt.setFuseTicks(5);
                      tntBlock.setType(Material.AIR);
                    }
                  }
                }.runTaskLater(TotalFreedomMod.plugin, 30L);

                event.setCancelled(true);
                break;
              }

            case RAW_FISH:
              {
                final int RADIUS_HIT = 5;
                final int STRENGTH = 4;

                // Clownfish
                if (TFM_DepreciationAggregator.getData_MaterialData(event.getItem().getData())
                    == 2) {
                  if (TFM_AdminList.isSeniorAdmin(player, true)
                      || TFM_AdminList.isTelnetAdmin(player, true)) {
                    boolean didHit = false;

                    final Location playerLoc = player.getLocation();
                    final Vector playerLocVec = playerLoc.toVector();

                    final List<Player> players = player.getWorld().getPlayers();
                    for (final Player target : players) {
                      if (target == player) {
                        continue;
                      }

                      final Location targetPos = target.getLocation();
                      final Vector targetPosVec = targetPos.toVector();

                      try {
                        if (targetPosVec.distanceSquared(playerLocVec)
                            < (RADIUS_HIT * RADIUS_HIT)) {
                          TFM_Util.setFlying(player, false);
                          target.setVelocity(
                              targetPosVec.subtract(playerLocVec).normalize().multiply(STRENGTH));
                          didHit = true;
                        }
                      } catch (IllegalArgumentException ex) {
                      }
                    }

                    if (didHit) {
                      final Sound[] sounds = Sound.values();
                      for (Sound sound : sounds) {
                        if (sound.toString().contains("HIT")) {
                          playerLoc
                              .getWorld()
                              .playSound(
                                  randomOffset(playerLoc, 5.0),
                                  sound,
                                  100.0f,
                                  randomDoubleRange(0.5, 2.0).floatValue());
                        }
                      }
                    }
                  } else {
                    final StringBuilder msg = new StringBuilder();
                    final char[] chars = (player.getName() + " is a clown.").toCharArray();
                    for (char c : chars) {
                      msg.append(TFM_Util.randomChatColor()).append(c);
                    }
                    TFM_Util.bcastMsg(msg.toString());

                    player.getInventory().getItemInHand().setType(Material.POTATO_ITEM);
                  }

                  event.setCancelled(true);
                  break;
                }
              }
          }
          break;
        }
    }
  }
  @SuppressWarnings("deprecation")
  @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
  public void onPlayerInteract(final PlayerInteractEvent event) {
    Block b = event.getClickedBlock();

    if (PlotManager.isPlotWorld(b)) {
      PlotMapInfo pmi = PlotManager.getMap(b);
      boolean blocked = false;
      Player player = event.getPlayer();
      boolean canbuild = PlotMe.cPerms(player, "plotme.admin.buildanywhere");

      if (event.isBlockInHand() && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        BlockFace face = event.getBlockFace();
        Block builtblock =
            b.getWorld()
                .getBlockAt(
                    b.getX() + face.getModX(),
                    b.getY() + face.getModY(),
                    b.getZ() + face.getModZ());

        String id = PlotManager.getPlotId(builtblock.getLocation());

        Player p = event.getPlayer();

        if (id.equalsIgnoreCase("")) {
          if (!canbuild) {
            p.sendMessage(PlotMe.caption("ErrCannotBuild"));
            event.setCancelled(true);
          }
        } else {
          Plot plot = PlotManager.getPlotById(p, id);

          if (plot == null) {
            if (!canbuild) {
              p.sendMessage(PlotMe.caption("ErrCannotBuild"));
              event.setCancelled(true);
            }
          } else {
            if (!plot.isAllowed(p.getName())) {
              if (!canbuild) {
                p.sendMessage(PlotMe.caption("ErrCannotBuild"));
                event.setCancelled(true);
              }
            } else {
              plot.resetExpire(PlotManager.getMap(b).DaysToExpiration);
            }
          }
        }
      } else {
        /*for(int blockid : pmi.ProtectedBlocks)
        {
        	if(blockid == b.getTypeId())
        	{
        		if(!PlotMe.cPerms(player, "plotme.unblock." + blockid))
        			blocked = true;

        		break;
        	}
        }*/

        if (pmi.ProtectedBlocks.contains(b.getTypeId())) {
          if (!PlotMe.cPerms(player, "plotme.unblock." + b.getTypeId())) blocked = true;
        }

        ItemStack is = event.getItem();

        if (is != null && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
          int itemid = is.getType().getId();
          byte itemdata = is.getData().getData();

          if (pmi.PreventedItems.contains("" + itemid)
              || pmi.PreventedItems.contains("" + itemid + ":" + itemdata)) {
            if (!PlotMe.cPerms(player, "plotme.unblock." + itemid)) blocked = true;
          }
        }

        if (blocked) {
          String id = PlotManager.getPlotId(b.getLocation());

          Player p = event.getPlayer();

          if (id.equalsIgnoreCase("")) {
            if (!canbuild) {
              if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                p.sendMessage(PlotMe.caption("ErrCannotUse"));
              }
              event.setCancelled(true);
            }
          } else {
            Plot plot = PlotManager.getPlotById(p, id);

            if (plot == null) {
              if (!canbuild) {
                if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                  p.sendMessage(PlotMe.caption("ErrCannotUse"));
                }
                event.setCancelled(true);
              }
            } else if (!plot.isAllowed(p.getName())) {
              if (!canbuild) {
                if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                  p.sendMessage(PlotMe.caption("ErrCannotUse"));
                }
                event.setCancelled(true);
              }
            }
          }
        }
      }
    }
  }