@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();
    }
  }
Exemplo n.º 2
0
    @EventHandler
    private void onPlayerInteract(PlayerInteractEvent event) {
      if (!mIsLoaded) return;
      if (mLocation.getWorld() != event.getPlayer().getWorld()) return;

      if (event.getAction() == Action.RIGHT_CLICK_BLOCK
          && event.hasBlock()
          && event.getClickedBlock().getLocation().distanceSquared(mLocation) < 1D) {
        onPlayerActivatePedestal(event.getPlayer());
        // event.setUseInteractedBlock(Result.DENY);
        event.setCancelled(true);
      }
    }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
0
  @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;
        }
    }
  }
 @EventHandler
 public void onPlayerInteract(PlayerInteractEvent event) {
   if (event.hasBlock()) {
     if (event.getClickedBlock().getState() instanceof Sign) {
       Sign sign = (Sign) event.getClickedBlock().getState();
       // Banks
       if (sign.getLine(0).equalsIgnoreCase(ChatColor.GOLD + "[bank]")) {
         event.setCancelled(true);
         RegisteredServiceProvider<CharacterPlugin> characterPluginProvider =
             plugin.getServer().getServicesManager().getRegistration(CharacterPlugin.class);
         if (characterPluginProvider != null) {
           CharacterPlugin characterPlugin = characterPluginProvider.getProvider();
           Character character = characterPlugin.getActiveCharacter(event.getPlayer());
           Currency currency = plugin.getCurrency(sign.getLine(3));
           if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
             switch (sign.getLine(2)) {
               case "1":
                 sign.setLine(2, "10");
                 sign.update();
                 break;
               case "10":
                 sign.setLine(2, "100");
                 sign.update();
                 break;
               case "100":
                 sign.setLine(2, "1000");
                 sign.update();
                 break;
               case "1000":
                 sign.setLine(2, "1");
                 sign.update();
                 break;
               default:
                 break;
             }
           } else if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
             if (sign.getLine(1).equalsIgnoreCase("withdraw")) {
               if (plugin.getMoney(character, currency) + Integer.parseInt(sign.getLine(2))
                   > plugin.getMaximumMoney()) {
                 event
                     .getPlayer()
                     .sendMessage(
                         plugin.getPrefix()
                             + ChatColor.RED
                             + "You cannot withdraw that amount, it would not fit in your wallet.");
               } else if (Integer.parseInt(sign.getLine(2))
                   > plugin.getBankBalance(character, currency)) {
                 event
                     .getPlayer()
                     .sendMessage(
                         plugin.getPrefix()
                             + ChatColor.RED
                             + "You cannot withdraw that amount, your bank balance is not high enough.");
               } else {
                 plugin.setBankBalance(
                     character,
                     currency,
                     plugin.getBankBalance(character, currency)
                         - Integer.parseInt(sign.getLine(2)));
                 plugin.addMoney(character, currency, Integer.parseInt(sign.getLine(2)));
                 event
                     .getPlayer()
                     .sendMessage(
                         new String[] {
                           plugin.getPrefix()
                               + ChatColor.GREEN
                               + "Withdrew "
                               + sign.getLine(2)
                               + " "
                               + (Integer.parseInt(sign.getLine(2)) == 1
                                   ? currency.getNameSingular()
                                   : currency.getNamePlural()),
                           ChatColor.GRAY
                               + "Wallet balance: "
                               + plugin.getMoney(character, currency),
                           ChatColor.GRAY
                               + "Bank balance: "
                               + plugin.getBankBalance(character, currency)
                         });
               }
             } else if (sign.getLine(1).equalsIgnoreCase("deposit")) {
               if (Integer.parseInt(sign.getLine(2)) > plugin.getMoney(character, currency)) {
                 event
                     .getPlayer()
                     .sendMessage(
                         plugin.getPrefix()
                             + ChatColor.RED
                             + "You cannot deposit that amount, your wallet balance is not high enough.");
               } else {
                 plugin.setBankBalance(
                     character,
                     currency,
                     plugin.getBankBalance(character, currency)
                         + Integer.parseInt(sign.getLine(2)));
                 plugin.addMoney(character, currency, -Integer.parseInt(sign.getLine(2)));
                 event
                     .getPlayer()
                     .sendMessage(
                         new String[] {
                           plugin.getPrefix()
                               + ChatColor.GREEN
                               + "Deposited "
                               + sign.getLine(2)
                               + " "
                               + (Integer.parseInt(sign.getLine(2)) == 1
                                   ? currency.getNameSingular()
                                   : currency.getNamePlural()),
                           ChatColor.GRAY
                               + "Wallet balance: "
                               + plugin.getMoney(character, currency),
                           ChatColor.GRAY
                               + "Bank balance: "
                               + plugin.getBankBalance(character, currency)
                         });
               }
             } else if (sign.getLine(1).equalsIgnoreCase("balance")) {
               event
                   .getPlayer()
                   .sendMessage(
                       plugin.getPrefix()
                           + ChatColor.GREEN
                           + "Balance: "
                           + plugin.getBankBalance(character, currency));
             }
           }
         }
       }
       // Shops
       if (event.getClickedBlock().getRelative(BlockFace.DOWN).getType() == Material.CHEST) {
         if (event.getClickedBlock().getRelative(BlockFace.DOWN).getState() instanceof Chest) {
           Chest chest = (Chest) event.getClickedBlock().getRelative(BlockFace.DOWN).getState();
           if (sign.getLine(0).equalsIgnoreCase(ChatColor.DARK_PURPLE + "[shop]")) {
             event.setCancelled(true);
             if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
               RegisteredServiceProvider<CharacterPlugin> characterPluginProvider =
                   plugin.getServer().getServicesManager().getRegistration(CharacterPlugin.class);
               if (characterPluginProvider != null) {
                 CharacterPlugin characterPlugin = characterPluginProvider.getProvider();
                 if ((sign.getLine(3).equalsIgnoreCase("admin")
                         && event.getPlayer().hasPermission("wayward.economy.shop.admin"))
                     || characterPlugin.getActiveCharacter(event.getPlayer()).getId()
                         == Integer.parseInt(sign.getLine(3))) {
                   event.getClickedBlock().setType(Material.AIR);
                   plugin.addMoney(
                       characterPlugin.getActiveCharacter(event.getPlayer()),
                       plugin.getConfig().getInt("shop.sell", 50));
                   event
                       .getPlayer()
                       .sendMessage(
                           plugin.getPrefix()
                               + ChatColor.GREEN
                               + "Sold shop for "
                               + plugin.getConfig().getInt("shop.sell", 50)
                               + " "
                               + plugin.getPrimaryCurrency().getNamePlural());
                   return;
                 }
               }
             }
             if (validateShopSign(sign, event.getPlayer())) {
               if (sign.getLine(1).toLowerCase().contains("buy")) {
                 event.getPlayer().openInventory(chest.getInventory());
               } else if (sign.getLine(1).toLowerCase().contains("sell")) {
                 if (event.getPlayer().getItemInHand().getType()
                     == Material.matchMaterial(sign.getLine(1).split(" ")[1].replace(' ', '_'))) {
                   if (event.getPlayer().getItemInHand().getAmount()
                       >= Integer.parseInt(sign.getLine(1).split(" ")[2])) {
                     RegisteredServiceProvider<CharacterPlugin> characterPluginProvider =
                         Bukkit.getServer()
                             .getServicesManager()
                             .getRegistration(CharacterPlugin.class);
                     if (characterPluginProvider != null) {
                       CharacterPlugin characterPlugin = characterPluginProvider.getProvider();
                       try {
                         event
                             .getPlayer()
                             .sendMessage(
                                 plugin.getPrefix()
                                     + ChatColor.GREEN
                                     + "Sold "
                                     + Integer.parseInt(sign.getLine(1).split(" ")[2])
                                     + " x "
                                     + event
                                         .getPlayer()
                                         .getItemInHand()
                                         .getType()
                                         .toString()
                                         .toLowerCase()
                                         .replace('_', ' ')
                                     + " for "
                                     + Integer.parseInt(sign.getLine(2).replace("for ", ""))
                                     + " "
                                     + (Integer.parseInt(sign.getLine(2).replace("for ", "")) == 1
                                         ? plugin.getPrimaryCurrency().getNameSingular()
                                         : plugin.getPrimaryCurrency().getNamePlural()));
                         if (characterPlugin
                             .getCharacter(Integer.parseInt(sign.getLine(3)))
                             .getPlayer()
                             .isOnline()) {
                           characterPlugin
                               .getCharacter(Integer.parseInt(sign.getLine(3)))
                               .getPlayer()
                               .getPlayer()
                               .sendMessage(
                                   plugin.getPrefix()
                                       + ChatColor.GREEN
                                       + "Your shop bought "
                                       + Integer.parseInt(sign.getLine(1).split(" ")[2])
                                       + " x "
                                       + event
                                           .getPlayer()
                                           .getItemInHand()
                                           .getType()
                                           .toString()
                                           .toLowerCase()
                                           .replace('_', ' ')
                                       + " for "
                                       + Integer.parseInt(sign.getLine(2).replace("for ", ""))
                                       + (Integer.parseInt(sign.getLine(2).replace("for ", ""))
                                               == 1
                                           ? plugin.getPrimaryCurrency().getNameSingular()
                                           : plugin.getPrimaryCurrency().getNamePlural())
                                       + " from "
                                       + event.getPlayer().getDisplayName());
                         }
                         if (sign.getLine(3).equalsIgnoreCase("admin")) {
                           plugin.addMoney(
                               event.getPlayer(),
                               -Integer.parseInt(sign.getLine(2).split(" ")[1]));
                         } else {
                           plugin.transferMoney(
                               characterPlugin.getCharacter(Integer.parseInt(sign.getLine(3))),
                               characterPlugin.getActiveCharacter(event.getPlayer()),
                               Integer.parseInt(sign.getLine(2).replace("for ", "")));
                         }
                         ItemStack item = new ItemStack(event.getPlayer().getItemInHand());
                         item.setAmount(Integer.parseInt(sign.getLine(1).split(" ")[2]));
                         chest.getInventory().addItem(item);
                         if (event.getPlayer().getItemInHand().getAmount()
                             > Integer.parseInt(sign.getLine(1).split(" ")[2])) {
                           event
                               .getPlayer()
                               .getItemInHand()
                               .setAmount(
                                   event.getPlayer().getItemInHand().getAmount()
                                       - Integer.parseInt(sign.getLine(1).split(" ")[2]));
                         } else {
                           event.getPlayer().setItemInHand(null);
                         }
                       } catch (NumberFormatException ignored) {
                       }
                     }
                   } else {
                     event
                         .getPlayer()
                         .sendMessage(
                             plugin.getPrefix()
                                 + ChatColor.RED
                                 + "You do not have enough "
                                 + event
                                     .getPlayer()
                                     .getItemInHand()
                                     .getType()
                                     .toString()
                                     .toLowerCase()
                                     .replace('_', ' ')
                                 + "s to sell");
                   }
                 } else {
                   event
                       .getPlayer()
                       .sendMessage(
                           plugin.getPrefix()
                               + ChatColor.RED
                               + "You must be holding at least "
                               + Integer.parseInt(sign.getLine(1).split(" ")[2])
                               + " "
                               + Material.matchMaterial(
                                       sign.getLine(1).split(" ")[1].replace(' ', '_'))
                                   .toString()
                                   .toLowerCase()
                                   .replace('_', ' ')
                               + "s");
                 }
               }
             }
           }
         }
       }
     }
   }
 }