Пример #1
0
  @Override
  public boolean doPowerSign(
      PowerSigns plugin, Block signBlock, String action, Matcher argsm, Boolean isOn) {
    Sign signState = (Sign) signBlock.getState();

    BlockFace signDir = PowerSigns.getSignDirection(signBlock);

    Vector dir = PowerSigns.strToVector(argsm.group(1), signDir);

    Block invBlock = signBlock.getRelative(dir.getBlockX(), dir.getBlockY(), dir.getBlockZ());

    Inventory inventory;
    BlockState state = invBlock.getState();
    if (state instanceof InventoryHolder) inventory = ((InventoryHolder) state).getInventory();
    else return plugin.debugFail("bad inv:" + invBlock.getType().toString() + " " + dir.toString());

    Material[] materials = PowerSigns.getMaterials(signState.getLine(1));

    int count = 0;

    for (Material material : materials) count += PowerSigns.inventoryCount(inventory, material);

    signState.setLine(2, Integer.toString(count));

    plugin.updateSignState(signState);

    return true;
  }
 public static boolean doCollectParallel(final MinecartManiaMinecart minecart) {
   final ArrayList<Block> blockList = minecart.getParallelBlocks();
   for (final Block block : blockList) {
     if (block.getState() instanceof Chest) {
       final MinecartManiaChest chest =
           MinecartManiaWorld.getMinecartManiaChest((Chest) block.getState());
       final ArrayList<Sign> signList =
           SignUtils.getAdjacentMinecartManiaSignList(chest.getLocation(), 1);
       for (final Sign sign : signList) {
         for (int i = 0; i < sign.getNumLines(); i++) {
           if (sign.getLine(i).toLowerCase().contains("parallel")) {
             sign.setLine(i, "[Parallel]");
             if (!minecart.isMovingAway(block.getLocation())) {
               if (chest.addItem(minecart.getType().getId())) {
                 minecart.kill(false);
                 return true;
               }
             }
           }
         }
       }
     }
   }
   return false;
 }
Пример #3
0
  @EventHandler(priority = EventPriority.NORMAL)
  public void onSignChange(SignChangeEvent event) {
    Player player = event.getPlayer();
    Block block = event.getBlock();
    String[] lines = event.getLines();
    EditWorld eworld = EditWorld.get(player.getWorld());

    // Group Signs
    if (eworld == null) {
      if (player.isOp() || P.p.permission.has(player, "dxl.sign")) {
        if (lines[0].equalsIgnoreCase("[DXL]")) {
          if (lines[1].equalsIgnoreCase("Group")) {
            String dungeonName = lines[2];

            String[] data = lines[3].split("\\,");
            if (data.length == 2) {
              int maxGroups = P.p.parseInt(data[0]);
              int maxPlayersPerGroup = P.p.parseInt(data[1]);
              if (maxGroups > 0 && maxPlayersPerGroup > 0) {
                if (DGSign.tryToCreate(event.getBlock(), dungeonName, maxGroups, maxPlayersPerGroup)
                    != null) {
                  event.setCancelled(true);
                }
              }
            }
          } else if (lines[1].equalsIgnoreCase("Leave")) {
            if (block.getState() instanceof Sign) {
              Sign sign = (Sign) block.getState();
              new LeaveSign(sign);
            }
            event.setCancelled(true);
          }
        }
      }
    } else { // Editworld Signs
      Sign sign = (Sign) block.getState();
      if (sign != null) {
        sign.setLine(0, lines[0]);
        sign.setLine(1, lines[1]);
        sign.setLine(2, lines[2]);
        sign.setLine(3, lines[3]);

        DSign dsign = DSign.create(sign, null);

        if (dsign != null) {
          if (player.isOp() || P.p.permission.has(player, dsign.getPermissions())) {
            if (dsign.check()) {
              eworld.checkSign(block);
              eworld.sign.add(block);
              P.p.msg(player, P.p.language.get("Player_SignCreated"));
            } else {
              P.p.msg(player, P.p.language.get("Error_SignWrongFormat"));
            }
          } else {
            P.p.msg(player, P.p.language.get("Error_NoPermissions"));
          }
        }
      }
    }
  }
Пример #4
0
  /**
   * Sets the toggled state of a single lever<br>
   * <b>No Lever type check is performed</b>
   *
   * @param lever block
   * @param down state to set to
   */
  private static void setLever(org.bukkit.block.Block lever, boolean down) {
    if (lever.getType() != Material.LEVER) {
      return;
    }

    byte data = lever.getData();
    int newData;
    if (down) {
      newData = data | 0x8;
    } else {
      newData = data & 0x7;
    }
    if (newData != data) {
      // CraftBukkit start - Redstone event for lever
      int old = !down ? 1 : 0;
      int current = down ? 1 : 0;
      BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(lever, old, current);
      Bukkit.getServer().getPluginManager().callEvent(eventRedstone);
      if ((eventRedstone.getNewCurrent() > 0) != down) {
        return;
      }
      // CraftBukkit end
      lever.setData((byte) newData, true);
      lever.getState().update();
      Block attached =
          lever.getRelative(((Attachable) lever.getState().getData()).getAttachedFace());
    }
  }
Пример #5
0
  /** Check the four sides of the base block to see if there's room for a large chest */
  public static Block findLarge(Block base) {
    // Check all 4 sides for air.
    Block block;

    block = base.getRelative(BlockFace.NORTH);
    if (canBeReplaced(block.getState())
        && (!Config.getInstance().getNoInterfere() || !checkChest(block, Material.CHEST))) {
      return block;
    }

    block = base.getRelative(BlockFace.EAST);
    if (canBeReplaced(block.getState())
        && (!Config.getInstance().getNoInterfere() || !checkChest(block, Material.CHEST))) {
      return block;
    }

    block = base.getRelative(BlockFace.SOUTH);
    if (canBeReplaced(block.getState())
        && (!Config.getInstance().getNoInterfere() || !checkChest(block, Material.CHEST))) {
      return block;
    }

    block = base.getRelative(BlockFace.WEST);
    if (canBeReplaced(block.getState())
        && (!Config.getInstance().getNoInterfere() || !checkChest(block, Material.CHEST))) {
      return block;
    }

    return null;
  }
 /**
  * Remove a island from SkyBlock.
  *
  * @param l given location
  */
 public void removeIsland(Location l) {
   if (l != null) {
     int px = l.getBlockX();
     int py = l.getBlockY();
     int pz = l.getBlockZ();
     for (int x = -15; x <= 15; x++) {
       for (int y = -15; y <= 15; y++) {
         for (int z = -15; z <= 15; z++) {
           Block b = new Location(l.getWorld(), px + x, py + y, pz + z).getBlock();
           if (b.getType() != Material.AIR) {
             if (b.getType() == Material.CHEST) {
               Chest c = (Chest) b.getState();
               ItemStack[] items = new ItemStack[c.getInventory().getContents().length];
               c.getInventory().setContents(items);
             } else if (b.getType() == Material.FURNACE) {
               Furnace f = (Furnace) b.getState();
               ItemStack[] items = new ItemStack[f.getInventory().getContents().length];
               f.getInventory().setContents(items);
             } else if (b.getType() == Material.DISPENSER) {
               Dispenser d = (Dispenser) b.getState();
               ItemStack[] items = new ItemStack[d.getInventory().getContents().length];
               d.getInventory().setContents(items);
             }
             b.setType(Material.AIR);
           }
         }
       }
     }
   }
 }
 public void run() {
   for (String s : lifewalkers.toArray(strArr)) {
     Player player = Bukkit.getServer().getPlayer(s);
     if (player != null) {
       if (isExpired(player)) {
         turnOff(player);
         continue;
       }
       Block feet = player.getLocation().getBlock();
       Block ground = feet.getRelative(BlockFace.DOWN);
       if (feet.getType() == Material.AIR
           && (ground.getType() == Material.DIRT || ground.getType() == Material.GRASS)) {
         if (ground.getType() == Material.DIRT) {
           ground.setType(Material.GRASS);
         }
         int rand = random.nextInt(100);
         if (rand < redFlowerChance) {
           feet.setType(Material.RED_ROSE);
           addUse(player);
           chargeUseCost(player);
         } else {
           rand -= redFlowerChance;
           if (rand < yellowFlowerChance) {
             feet.setType(Material.YELLOW_FLOWER);
             addUse(player);
             chargeUseCost(player);
           } else {
             rand -= yellowFlowerChance;
             if (rand < saplingChance) {
               feet.setType(Material.SAPLING);
               addUse(player);
               chargeUseCost(player);
             } else {
               rand -= saplingChance;
               if (rand < tallgrassChance) {
                 BlockState state = feet.getState();
                 state.setType(Material.LONG_GRASS);
                 state.setData(new LongGrass(GrassSpecies.NORMAL));
                 state.update(true);
                 addUse(player);
                 chargeUseCost(player);
               } else {
                 rand -= tallgrassChance;
                 if (rand < fernChance) {
                   BlockState state = feet.getState();
                   state.setType(Material.LONG_GRASS);
                   state.setData(new LongGrass(GrassSpecies.FERN_LIKE));
                   state.update(true);
                   addUse(player);
                   chargeUseCost(player);
                 }
               }
             }
           }
         }
       }
     }
   }
 }
Пример #8
0
  public boolean handleCommand(String[] args, CommandSender sender) {
    Player p = null;
    if (sender instanceof Player) p = (Player) sender;
    if (args.length >= 1) {
      if (p == null) {
        sender.sendMessage(playerOnly);
        return true;
      }
      if (args[0].equalsIgnoreCase("add")) {
        if (!Main.cmdhandler.pm.hasPlayerPermission(p, Permission.MPVP_RS_ADD)) {
          sender.sendMessage(this.noPermMsg);
          return true;
        }
        Block tb = p.getTargetBlock((HashSet<Byte>) null, 10);
        if (tb != null && (tb.getType().equals(Material.WALL_SIGN))) {
          String name = "";
          boolean sky = true;
          if (args.length >= 2) {
            name = args[1];
            if (args.length >= 3) {
              try {
                sky = Boolean.parseBoolean(args[2]);
              } catch (Exception ex) {
              }
              ;
            }
          }
          Sign sign = (Sign) tb.getState();
          RadioStation.buildRadioStation(sign, RadioStation.getFacing(sign));
          Main.gameEngine.configuration.addRadioStation(new RadioStationContainer(sign, name, sky));
          Main.gameEngine.configuration.addNewProtectedRegion(
              sign.getLocation().clone().subtract(11d, 11d, 11d),
              sign.getLocation().clone().add(11d, 11d, 11d));
          sender.sendMessage(ChatColor.DARK_GREEN + Main.gameEngine.dict.get("addRs"));
        } else {
          sender.sendMessage(ChatColor.DARK_RED + Main.gameEngine.dict.get("mustPointOnSign"));
        }
        return true;
      }

      if (args[0].equalsIgnoreCase("remove")) {
        if (!Main.cmdhandler.pm.hasPlayerPermission(p, Permission.MPVP_RS_DEL)) {
          sender.sendMessage(this.noPermMsg);
          return true;
        }
        Block tb = p.getTargetBlock((HashSet<Byte>) null, 10);
        if (tb != null && (tb.getType().equals(Material.WALL_SIGN))) {
          Sign sign = (Sign) tb.getState();
          Main.gameEngine.configuration.removeRadioStation(sign);
          sender.sendMessage(ChatColor.DARK_GREEN + Main.gameEngine.dict.get("rmRs"));
        } else {
          sender.sendMessage(ChatColor.DARK_RED + Main.gameEngine.dict.get("mustPointOnSign"));
        }
        return true;
      }
    }
    return false;
  }
Пример #9
0
 private void chestCheck(String player, Block block) {
   if (block.getState() instanceof Chest) {
     Chest chest = (Chest) block.getState();
     BBPlayerInfo pi = BBUsersTable.getInstance().getUserByName(player);
     bystanders.add(
         new DeltaChest(
             player, chest, pi.getOldChestContents(), chest.getInventory().getContents()));
   }
 }
Пример #10
0
  public static void setSellSign(final World world, final AthionPlot plot) {
    removeSellSign(world, plot.id);

    if (plot.forsale || plot.auctionned) {
      final Location pillar =
          new Location(
              world,
              bottomX(plot.id, world) - 1,
              getMap(world).RoadHeight + 1,
              bottomZ(plot.id, world) - 1);

      Block bsign = pillar.clone().add(-1, 0, 0).getBlock();
      bsign.setType(Material.AIR);
      bsign.setTypeIdAndData(Material.WALL_SIGN.getId(), (byte) 4, false);

      Sign sign = (Sign) bsign.getState();

      if (plot.forsale) {
        sign.setLine(0, AthionPlots.caption("SignForSale"));
        sign.setLine(1, AthionPlots.caption("SignPrice"));
        if ((plot.customprice % 1) == 0) {
          sign.setLine(2, AthionPlots.caption("SignPriceColor") + Math.round(plot.customprice));
        } else {
          sign.setLine(2, AthionPlots.caption("SignPriceColor") + plot.customprice);
        }
        sign.setLine(3, "/ap " + AthionPlots.caption("CommandBuy"));

        sign.update(true);
      }

      if (plot.auctionned) {
        if (plot.forsale) {
          bsign = pillar.clone().add(-1, 0, 1).getBlock();
          bsign.setType(Material.AIR);
          bsign.setTypeIdAndData(Material.WALL_SIGN.getId(), (byte) 4, false);

          sign = (Sign) bsign.getState();
        }

        sign.setLine(0, "" + AthionPlots.caption("SignOnAuction"));
        if (plot.currentbidder.equals("")) {
          sign.setLine(1, AthionPlots.caption("SignMinimumBid"));
        } else {
          sign.setLine(1, AthionPlots.caption("SignCurrentBid"));
        }
        if ((plot.currentbid % 1) == 0) {
          sign.setLine(2, AthionPlots.caption("SignCurrentBidColor") + Math.round(plot.currentbid));
        } else {
          sign.setLine(2, AthionPlots.caption("SignCurrentBidColor") + plot.currentbid);
        }
        sign.setLine(3, "/ap " + AthionPlots.caption("CommandBid") + " <x>");

        sign.update(true);
      }
    }
  }
  @SuppressWarnings("deprecation")
  private boolean signFinder(
      Player player,
      Block block,
      BlockFace[] testBlocks,
      BlockFace[] testFaces,
      final Block lever) {

    Block newBlock;
    BlockFace testFace;

    for (int c = 0; c < 5; c++) {
      if (c == 2) {
        newBlock = block.getRelative(testBlocks[c], 2);
        testFace = testFaces[1];
      } else {
        newBlock = block.getRelative(testBlocks[c]);
        testFace = testFaces[0];
      }
      if (!(newBlock.getState() instanceof Sign)) continue;
      if (((org.bukkit.material.Sign) newBlock.getState().getData()).getFacing() != testFace)
        continue;

      int s = signConverter(player, newBlock);
      if (s > 0) {
        boolean n = s == 1;

        if (n || !enableBL) return n;
        if (lever.getType() != Material.LEVER) return n;
        Lever l = (Lever) lever.getState().getData();
        // if (l.isPowered())
        //	return n;
        l.setPowered(false);
        l.setPowered(true);
        lever.setData(l.getData());
        lever.getWorld().playEffect(lever.getLocation(), Effect.SMOKE, 4);
        Bukkit.getScheduler()
            .scheduleSyncDelayedTask(
                PLUGIN,
                new Runnable() {
                  @Override
                  public void run() {
                    if (lever.getType() != Material.LEVER) return;
                    Lever l = (Lever) lever.getState().getData();
                    if (!l.isPowered()) return;
                    l.setPowered(false);
                    lever.setData(l.getData());
                    lever.getWorld().playEffect(lever.getLocation(), Effect.SMOKE, 4);
                  }
                },
                20L);
      }
    }
    return false;
  }
Пример #12
0
 public ChestSpawn(Block block, boolean setItems) {
   super(block, setItems);
   if (setItems && block.getState() instanceof Chest) {
     Chest chest = (Chest) block.getState();
     ItemStack[] contents = chest.getInventory().getContents();
     items = new ItemStack[contents.length];
     for (int i = 0; i < contents.length; i++) {
       items[i] = (contents[i] != null) ? contents[i].clone() : null;
     }
   }
 }
Пример #13
0
  private static void interactSign(Block block, Player player) {
    Sign sign = (Sign) block.getState();
    String text = sign.getLine(0).replaceAll("(?i)\u00A7[0-F]", "").toLowerCase();
    Block signBlock = block;

    // Check if it is our sign that was clicked.

    if (text.equals("[private]") || text.equalsIgnoreCase(Lockette.altPrivate)) {
    } else if (text.equals("[more users]") || text.equalsIgnoreCase(Lockette.altMoreUsers)) {
      Block checkBlock = Lockette.getSignAttachedBlock(block);
      if (checkBlock == null) return;

      signBlock = Lockette.findBlockOwner(checkBlock);
      if (signBlock == null) return;

      sign = (Sign) signBlock.getState();
    } else return;

    int length = player.getName().length();

    if (length > 15) length = 15;

    // Check owner.
    if (sign.getLine(1)
            .replaceAll("(?i)\u00A7[0-F]", "")
            .equals(player.getName().substring(0, length))
        || player.getName().equals("Acru")) { // Temp for Debugging.
      // if(sign.getLine(1).replaceAll("(?i)\u00A7[0-F]", "").equals(player.getName().substring(0,
      // length))){
      if (!block.equals(plugin.playerList.get(player.getName()))) {
        // Associate the user with the owned sign.
        plugin.playerList.put(player.getName(), block);
        plugin.localizedMessage(player, null, "msg-help-select");
      }
    } else {
        /*
        int fee = getSignOption(signBlock, "fee", Lockette.altFee, 0);

        if(fee != 0){
        	if(!signBlock.equals(plugin.playerList.get(player.getName()))){
        		// First half of fee approval.
        		plugin.playerList.put(player.getName(), signBlock);
        		plugin.localizedMessage(player, null, "msg-user-touch-fee", sign.getLine(1), plugin.economyFormat(fee));
        	}
        }
        else{*/
      if (!block.equals(plugin.playerList.get(player.getName()))) {
        // Only print this message once as well.
        plugin.playerList.put(player.getName(), block);
        plugin.localizedMessage(player, null, "msg-user-touch-owned", sign.getLine(1));
      }
      // }
    }
  }
Пример #14
0
  @Override
  public void run() {
    BlockState tmp_state = block.getState();

    block.setType(type); // set the block to tnt

    List<BlockState> list = cEx.getBlockList();
    list.add(block.getState()); // record it

    tmp_state.update(true); // set it back to what it was
  }
Пример #15
0
 public void onPlayerInteract(PlayerInteractEvent event) {
   Block b = event.getClickedBlock();
   Player p = event.getPlayer();
   Action a = event.getAction();
   // Handle field building tool operations
   if (p.getItemInHand().getTypeId() == 276) {
     Builder fb = plugin.getBattlefieldManager().getBuilder(p);
     if (fb != null) {
       if (fb.getTool() != null) {
         Tool tool = fb.getTool();
         switch (a) {
           case RIGHT_CLICK_BLOCK:
             tool.rightClick(b);
             break;
           case LEFT_CLICK_BLOCK:
             tool.leftClick(b);
             break;
           case RIGHT_CLICK_AIR:
             tool.rightClick();
             break;
           case LEFT_CLICK_AIR:
             tool.leftClick();
             break;
           default:
             break;
         }
       }
     }
   }
   TeamMember m = plugin.getBattlefieldManager().getPlayer(p);
   if (m != null) {
     Battlefield field = m.getTeam().getField();
     // Handle sign clicks
     if (b != null) {
       if (b.getState() instanceof Sign) {
         Sign sign = (Sign) b.getState();
         String line = sign.getLine(0);
         if (line.equals("[Options]")) {
           BattlefieldSign bs = field.getSign(b);
           if (bs != null) {
             if (field.isActive())
               Format.sendMessage(m, "You cannot change settings during a game.");
             else if (a == Action.LEFT_CLICK_BLOCK) bs.executeOption(m);
             else if (a == Action.RIGHT_CLICK_BLOCK) bs.cycleOption(m);
           }
         }
       }
     }
     if (field.isActive())
       field.getGametype().getListener().onClick(m, event.getClickedBlock(), event.getAction());
   }
 }
 @Override
 public void toggleLeverOrButton(Block block) {
   if (block.getType() == Material.STONE_BUTTON || block.getType() == Material.WOOD_BUTTON) {
     BlockState state = block.getState();
     Button button = (Button) state.getData();
     button.setPowered(true);
     state.update();
   } else if (block.getType() == Material.LEVER) {
     BlockState state = block.getState();
     Lever lever = (Lever) state.getData();
     lever.setPowered(!lever.isPowered());
     state.update();
   }
 }
Пример #17
0
    /**
     * Explore around the trigger to find a functional elevator; throw if things look funny.
     *
     * @param pt the trigger (should be a signpost)
     * @return an Elevator if we could make a valid one, or null if this looked nothing like an
     *     elevator.
     * @throws InvalidMechanismException if the area looked like it was intended to be an elevator,
     *     but it failed.
     */
    @Override
    public Teleporter detect(BlockWorldVector pt) throws InvalidMechanismException {

      Block block = BukkitUtil.toBlock(pt);
      // check if this looks at all like something we're interested in first

      if (block.getState() instanceof Sign) {
        Sign s = (Sign) block.getState();
        if (!s.getLine(1).equalsIgnoreCase("[Teleport]")) return null;
        String[] pos = s.getLine(2).split(":");
        if (pos.length > 2) return new Teleporter(block, plugin);
      }

      return null;
    }
Пример #18
0
 /**
  * Detect if a Block can be broken by a Player or by something else (Explosion...)
  *
  * @param b the Block to be broken
  * @param player the Player that want to break the Block, if there is one, null otherwise
  * @return true if the block can be broken [by the Player], false otherwise
  */
 public boolean canBreak(final Block b, final Player player) {
   final Material blockType = b.getType();
   final String userId = player != null ? PlayerIdsUtil.getId(player.getName()) : null;
   if (blockType == Material.SIGN_POST || blockType == Material.WALL_SIGN) {
     final Sign sign = (Sign) b.getState();
     return !sign.getLine(0).equals(PROTECTION)
         || player != null && ColorUtil.stripColorCodes(sign.getLine(3)).equals(userId)
         || player != null && Perms.hasProtectionSignBreak(player);
   } else {
     final List<Sign> signLines;
     if (blockType == Material.CHEST || blockType == Material.TRAPPED_CHEST) {
       signLines = SignUtil.getSignsForChest(b);
     } else if (getProtectedMaterials().contains(blockType)) {
       signLines = SignUtil.getSignsForBlock(b);
     } else {
       return true;
     }
     for (final Sign sign : signLines) {
       if (sign.getLine(0).equals(PROTECTION)) {
         return false;
       }
     }
     return true;
   }
 }
 @EventHandler
 public void onBreak(BlockBreakEvent bbe) {
   if (!(bbe.isCancelled())) {
     Block block = bbe.getBlock();
     if (bbe.getPlayer() != null) {
       Player breaker = bbe.getPlayer();
       UUID uuid = breaker.getUniqueId();
       if (block.getState().getType().equals(Material.REDSTONE_ORE)
           || block.getType().equals(Material.REDSTONE_ORE)) {
         boolean notSilkTouch = true;
         if (breaker.getInventory().getItemInHand() != null) {
           ItemStack handItem = breaker.getInventory().getItemInHand();
           if (handItem.containsEnchantment(Enchantment.SILK_TOUCH)) {
             notSilkTouch = false;
           }
         }
         boolean lowLevel = true;
         int level = LevelManager.getLevel(breaker);
         if (level > 30) {
           lowLevel = false;
         }
         if (notSilkTouch && lowLevel) {
           int broke = LevelingXP_Breaking.get(uuid);
           broke += 1;
           if (broke >= (10 * LevelManager.getLevel(breaker))) {
             XPmanager.giveXP(breaker, 80);
           } else {
             LevelingXP_Breaking.set(uuid, broke);
           }
         }
       }
     }
   }
 }
  @Override
  public void onBlockPlace(BlockPlaceEvent inEvent) {
    Player thePlayer = inEvent.getPlayer();

    Block theBlock = inEvent.getBlock();

    if ((theBlock.getType() != Material.MOB_SPAWNER) || (inEvent.isCancelled())) return;

    if (creaturebox.permissions != null) {
      if (creaturebox.permissions.has(thePlayer, "creaturebox.placespawner") == false) {
        return;
      }
    }

    ItemStack theItem = inEvent.getItemInHand();
    int theCreatureIndex = inEvent.getItemInHand().getDurability();

    if (theCreatureIndex >= plugin.creatureTypes.length) theCreatureIndex = 0;

    CreatureSpawner theSpawner = (CreatureSpawner) theBlock.getState();
    theSpawner.setCreatureType(plugin.creatureTypes[theCreatureIndex]);

    thePlayer.sendMessage(
        String.format(
            ChatColor.YELLOW + "creaturebox: %s spawner placed.", theSpawner.getCreatureTypeId()));
  }
  @Override
  public void onBlockBreak(BlockBreakEvent inEvent) {
    Player thePlayer = inEvent.getPlayer();
    Block theBlock = inEvent.getBlock();

    if ((theBlock.getType() != Material.MOB_SPAWNER) || (inEvent.isCancelled())) return;

    if (creaturebox.permissions != null) {
      if (creaturebox.permissions.has(thePlayer, "creaturebox.dropspawner") == false) {
        return;
      }
    } else {
      if (thePlayer.isOp() == false) {
        return;
      }
    }

    World theWorld = theBlock.getWorld();
    Location theLocation =
        new Location(theWorld, theBlock.getX(), theBlock.getY(), theBlock.getZ(), 0, 0);
    CreatureSpawner theSpawner = (CreatureSpawner) theBlock.getState();
    int theCreatureIndex = plugin.creatureIndex(theSpawner.getCreatureTypeId());

    MaterialData theMaterial = new MaterialData(Material.MOB_SPAWNER, (byte) theCreatureIndex);
    ItemStack theItem = new ItemStack(Material.MOB_SPAWNER, 1, (short) theCreatureIndex);

    theWorld.dropItemNaturally(theLocation, theItem);

    thePlayer.sendMessage(
        String.format(
            ChatColor.YELLOW + "creaturebox: %s spawner dropped.", theSpawner.getCreatureTypeId()));
  }
Пример #22
0
  /** Update the command signs to display the next player's name. */
  private void updateSigns() {
    Set<Object[]> badSigns = new HashSet<Object[]>();

    for (Object[] location : signs) {
      final World world = getServer().getWorld((String) location[0]);
      final int x = (Integer) location[1];
      final int y = (Integer) location[2];
      final int z = (Integer) location[3];

      if (world.isChunkLoaded(x / 16, z / 16)) {
        final Block block = world.getBlockAt(x, y, z);
        final BlockState state = block.getState();
        if (state instanceof Sign) {
          final Sign sign = (Sign) state;

          String token = sign.getLine(2);
          final Route route = routes.get(token.replaceAll(" ", ""));

          if (route != null) {
            String nextName = route.pickWinner(counter);
            if (nextName == null) {
              nextName = ChatColor.ITALIC + "No one";
            }
            sign.setLine(3, nextName);
            sign.update();
          }

          continue; // Avoid adding this to badSigns
        }
        badSigns.add(location);
      }
    }
    signs.removeAll(badSigns);
    counter++;
  }
Пример #23
0
 /**
  * Blocks block breaking inside an arena for players not in that arena,<br>
  * or if the block's material is not whitelisted for breaking.
  *
  * <p>Stops blocks with ug signs attached from breaking.
  */
 @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 public void onBlockBreak(BlockBreakEvent event) {
   Arena arena = ultimateGames.getArenaManager().getLocationArena(event.getBlock().getLocation());
   if (arena != null) {
     String playerName = event.getPlayer().getName();
     if (ultimateGames.getPlayerManager().isPlayerInArena(playerName)) {
       if (!ultimateGames.getPlayerManager().getArenaPlayer(playerName).isEditing()) {
         if (arena.getStatus() == ArenaStatus.RUNNING
             && ultimateGames
                 .getWhitelistManager()
                 .getBlockBreakWhitelist()
                 .canBreakMaterial(arena.getGame(), event.getBlock().getType())) {
           Block block = event.getBlock();
           if ((block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN)
               && ultimateGames.getUGSignManager().isUGSign((Sign) block.getState())) {
             event.setCancelled(true);
             return;
           }
           for (Sign attachedSign : UGUtils.getAttachedSigns(block, true)) {
             if (ultimateGames.getUGSignManager().isUGSign(attachedSign)) {
               event.setCancelled(true);
               return;
             }
           }
           arena.getGame().getGamePlugin().onBlockBreak(arena, event);
         } else {
           event.setCancelled(true);
         }
       }
     } else {
       event.setCancelled(true);
     }
   }
 }
Пример #24
0
  // RŽcupŽration du Relative et ajout du SignManager dans le Set
  public static boolean registerSign(Location locsign) {
    try {
      locsign.getBlock();
    } catch (Exception e) {
      return false;
    } // VŽrifie sur la locsign est un block

    if (!(locsign.getBlock().getState() instanceof org.bukkit.block.Sign)) return false;

    Block bs = locsign.getBlock();
    org.bukkit.material.Sign signmat = (org.bukkit.material.Sign) bs.getState().getData();
    Location relative = null;

    if (!signmat.isWallSign()) relative = bs.getRelative(BlockFace.DOWN).getLocation();
    else if (signmat.getAttachedFace() == BlockFace.EAST)
      relative = bs.getRelative(BlockFace.EAST).getLocation();
    else if (signmat.getAttachedFace() == BlockFace.WEST)
      relative = bs.getRelative(BlockFace.WEST).getLocation();
    else if (signmat.getAttachedFace() == BlockFace.NORTH)
      relative = bs.getRelative(BlockFace.NORTH).getLocation();
    else if (signmat.getAttachedFace() == BlockFace.SOUTH)
      relative = bs.getRelative(BlockFace.SOUTH).getLocation();

    SignManager sm = new SignManager(locsign, relative);
    sm.RefreshSign();
    return true;
  }
Пример #25
0
  /*
   * (non-Javadoc)
   * @see com.nitnelave.CreeperHeal.block.Replaceable#replace(boolean)
   */
  @Override
  public boolean replace(boolean shouldDrop) {
    Block block = getBlock();
    int blockId = block.getTypeId();

    if (!CreeperConfig.overwriteBlocks && !isEmpty(blockId)) {
      if (CreeperConfig.dropDestroyedBlocks) drop();
      return true;
    } else if (CreeperConfig.overwriteBlocks
        && !isEmpty(blockId)
        && CreeperConfig.dropDestroyedBlocks) {
      CreeperBlock.newBlock(block.getState()).drop();
      block.setTypeIdAndData(0, (byte) 0, false);
    }

    if (!shouldDrop
        && isDependent(getTypeId())
        && isEmpty(getBlock().getRelative(getAttachingFace()).getTypeId())) {
      delay_replacement();
      return true;
    } else update();

    // TODO: Check the necessity, and move to CreeperRail if possible.
    checkForAscendingRails();

    return true;
  }
Пример #26
0
  /**
   * copies a map of Items to a chest
   *
   * @param toDrop the items to copy
   * @param chest
   * @return items copied
   */
  private LinkedList<ItemStack> copyInventoryToChest(
      HashMap<Integer, ItemStack> toDrop, Chest chest) {
    Inventory chestInv = chest.getInventory();

    Block doubleChestBlock = getDoubleChest(chest.getBlock());
    boolean isDoubleChest = !(doubleChestBlock == null);

    LinkedList<ItemStack> toRemove = new LinkedList<ItemStack>();

    if (chestInv == null) return toRemove;

    for (Integer key : toDrop.keySet()) {
      ItemStack item = toDrop.get(key);
      if (item == null) continue;
      if (chestInv.firstEmpty() == -1) {
        if (!isDoubleChest) break;
        isDoubleChest = false;

        chestInv = ((Chest) doubleChestBlock.getState()).getInventory();
        if (chestInv.firstEmpty() == -1) break;
      }
      chestInv.addItem(item);
      toRemove.add(item);
    }
    return toRemove;
  }
Пример #27
0
  @Override
  public void changeBlock(Block block) {
    currentJob.addBlock(block.getState());

    block.setType(item.getItemType());
    block.setData(item.getData());
  }
Пример #28
0
 private Sign getSign(World w, int x, int y, int z) {
   Block b = w.getBlockAt(x, y, z);
   Material t = b.getType();
   return t == Material.SIGN || t == Material.SIGN_POST || t == Material.WALL_SIGN
       ? (Sign) b.getState()
       : null;
 }
Пример #29
0
 /**
  * @param mechname
  * @return true if the bracketed keyword on the sign matches the given mechname; false otherwise
  *     or if no sign.
  * @throws ClassCastException if the declarative constructor was used in such a way that a
  *     non-sign block was specified for a sign.
  */
 public boolean matches(String mechname) {
   return (sign == null)
       ? false
       : (((Sign) sign.getState()).getLine(1).equalsIgnoreCase("[" + mechname + "]"));
   // the astute will notice there's a problem coming up here with the one dang thing that had to
   // go and break the mold with second line definer.
 }
  private boolean editSign(CommandSender sender, String[] args) {
    if (!(sender instanceof Player)) return true;

    if (args.length == 0) return false;
    if (!args[0].matches("^[0-9]+$")) return false;

    int lineNo = Integer.parseInt(args[0]) - 1;
    String newLine = "";
    for (int i = 1; i < args.length; i++) {
      newLine += args[i] + " ";
    }
    newLine = newLine.trim();
    System.out.println("-" + newLine + "-");

    Player player = (Player) sender;
    Block b = player.getTargetBlock(null, 5);
    System.out.println(b);
    if (b != null && (b.getType() == Material.SIGN_POST || b.getType() == Material.WALL_SIGN)) {
      Sign sign = (Sign) b.getState();
      String[] lines = sign.getLines();
      lines[lineNo] = newLine;
      SignChangeEvent event = new SignChangeEvent(b, player, lines);
      Bukkit.getPluginManager().callEvent(event);
      if (!event.isCancelled()) {
        sign.setLine(lineNo, newLine);
        sign.update();
      }
    }

    return true;
  }