org.spongepowered.api.item.ItemType Java Examples
The following examples show how to use
org.spongepowered.api.item.ItemType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GlobalListener.java From RedProtect with GNU General Public License v3.0 | 6 votes |
private boolean canUse(Player p, Region r) { boolean claimRps = RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).deny_item_usage.allow_on_claimed_rps; boolean wilderness = RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).deny_item_usage.allow_on_wilderness; ItemType item = RedProtect.get().getVersionHelper().getItemInHand(p); //deny item usage if (!RedProtect.get().ph.hasPerm(p, "redprotect.world.bypass") && !item.equals(ItemTypes.NONE) && RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).deny_item_usage.items.stream().anyMatch(item.getType().getName()::matches)) { if (r != null && ((!claimRps && r.canBuild(p)) || (claimRps && !r.canBuild(p)))) { RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse"); return false; } if (r == null && !wilderness) { RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse"); return false; } } return true; }
Example #2
Source File: Region.java From RedProtect with GNU General Public License v3.0 | 6 votes |
public boolean denyEnterWithItens(Player p) { if (!flagExists("deny-enter-items")) { return true; } if (checkAllowedPlayer(p, "deny-enter-items")) { return true; } Iterable<Slot> SlotItems = p.getInventory().slots(); List<String> items = Arrays.asList(flags.get("deny-enter-items").toString().replace(" ", "").split(",")); for (Slot slot : SlotItems) { if (slot.peek().isPresent()) { if (items.stream().anyMatch(k -> Sponge.getRegistry().getType(ItemType.class, k).orElse(null) == slot.peek().get().getItem())) { return false; } } } return true; }
Example #3
Source File: Region.java From RedProtect with GNU General Public License v3.0 | 6 votes |
public boolean canEnterWithItens(Player p) { if (!flagExists("allow-enter-items")) { return true; } if (checkAllowedPlayer(p, "allow-enter-items")) { return true; } List<String> items = Arrays.asList(flags.get("allow-enter-items").toString().replace(" ", "").split(",")); Iterable<Slot> SlotItems = p.getInventory().slots(); for (Slot slot : SlotItems) { if (slot.peek().isPresent()) { if (items.stream().anyMatch(k -> Sponge.getRegistry().getType(ItemType.class, k).orElse(null) == slot.peek().get().getItem())) { return true; } } } return false; }
Example #4
Source File: Region.java From RedProtect with GNU General Public License v3.0 | 6 votes |
public boolean canExitWithItens(Player p) { if (!flagExists("deny-exit-items")) { return true; } if (checkAllowedPlayer(p, "deny-exit-items")) { return true; } List<String> items = Arrays.asList(flags.get("deny-exit-items").toString().replace(" ", "").split(",")); Iterable<Slot> SlotItems = p.getInventory().slots(); for (Slot slot : SlotItems) { if (slot.peek().isPresent()) { if (items.stream().anyMatch(k -> Sponge.getRegistry().getType(ItemType.class, k).orElse(null) == slot.peek().get().getItem())) { return false; } } } return true; }
Example #5
Source File: WandCommand.java From RedProtect with GNU General Public License v3.0 | 6 votes |
public CommandSpec register() { return CommandSpec.builder() .description(Text.of("Command to get wand tool")) .permission("redprotect.command.wand") .executor((src, args) -> { if (!(src instanceof Player)) { HandleHelpPage(src, 1); } else { Player player = (Player) src; if (RedProtect.get().config.getWorldClaimType(player.getWorld().getName()).equalsIgnoreCase("BLOCK") && !RedProtect.get().ph.hasPerm(player, "redprotect.command.admin.wand")) return CommandResult.success(); Inventory inv = player.getInventory(); ItemType mat = Sponge.getRegistry().getType(ItemType.class, RedProtect.get().config.configRoot().wands.adminWandID).orElse(ItemTypes.GLASS_BOTTLE); ItemStack item = ItemStack.of(mat, 1); item.offer(Keys.ITEM_ENCHANTMENTS, new ArrayList<>()); if (inv.query(Hotbar.class).offer(item).getType().equals(InventoryTransactionResult.Type.SUCCESS)) { RedProtect.get().lang.sendMessage(player, RedProtect.get().lang.get("cmdmanager.wand.given").replace("{item}", mat.getName())); } else { RedProtect.get().lang.sendMessage(player, RedProtect.get().lang.get("cmdmanager.wand.nospace").replace("{item}", mat.getName())); } } return CommandResult.success(); }).build(); }
Example #6
Source File: UIRenderer.java From SubServers-2 with Apache License 2.0 | 6 votes |
/** * Parse an ItemStack from a String * * @param str String to parse * @param def Default to return if unable to parse * @return ItemStack */ public ItemStack parseItem(String str, ItemStack def) { final Container<String> item = new Container<String>(str); // minecraft:name if (item.get().toLowerCase().startsWith("minecraft:")) { item.set(item.get().substring(10)); } else // bukkit:name (ignored on sponge) if (item.get().toLowerCase().startsWith("bukkit:")) { item.set(item.get().substring(7)); } // material name if (!Util.isException(() -> ItemTypes.class.getDeclaredField(item.get().toUpperCase()).get(null))) { return ItemStack.builder().itemType((ItemType) Util.getDespiteException(() -> ItemTypes.class.getDeclaredField(item.get().toUpperCase()).get(null), null)).quantity(1).build(); } return def; }
Example #7
Source File: BlockListener.java From RedProtect with GNU General Public License v3.0 | 6 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onInteractBlock(InteractBlockEvent event, @First Player p) { BlockSnapshot b = event.getTargetBlock(); Location<World> l; RedProtect.get().logger.debug(LogLevel.PLAYER, "BlockListener - Is InteractBlockEvent event"); if (!b.getState().getType().equals(BlockTypes.AIR)) { l = b.getLocation().get(); RedProtect.get().logger.debug(LogLevel.PLAYER, "BlockListener - Is InteractBlockEvent event. The block is " + b.getState().getType().getName()); } else { l = p.getLocation(); } Region r = RedProtect.get().rm.getTopRegion(l, this.getClass().getName()); if (r != null) { ItemType itemInHand = RedProtect.get().getVersionHelper().getItemInHand(p); if (itemInHand.equals(ItemTypes.ARMOR_STAND) && !r.canBuild(p)) { RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbuild"); event.setCancelled(true); } } }
Example #8
Source File: PlayerListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Listener(order = Order.FIRST) public void onInteractLeft(InteractBlockEvent.Primary event, @First Player p) { BlockSnapshot b = event.getTargetBlock(); Location<World> l; RedProtect.get().logger.debug(LogLevel.PLAYER, "PlayerListener - Is InteractBlockEvent.Primary event"); if (!b.getState().getType().equals(BlockTypes.AIR)) { l = b.getLocation().get(); RedProtect.get().logger.debug(LogLevel.PLAYER, "PlayerListener - Is InteractBlockEvent.Primary event. The block is " + b.getState().getType().getName()); } else { l = p.getLocation(); } ItemType itemInHand = RedProtect.get().getVersionHelper().getItemInHand(p); String claimmode = RedProtect.get().config.getWorldClaimType(p.getWorld().getName()); if (event instanceof InteractBlockEvent.Primary.MainHand && itemInHand.getId().equalsIgnoreCase(RedProtect.get().config.configRoot().wands.adminWandID) && ((claimmode.equalsIgnoreCase("WAND") || claimmode.equalsIgnoreCase("BOTH")) || RedProtect.get().ph.hasPerm(p, "redprotect.admin.claim"))) { if (!RedProtect.get().getUtil().canBuildNear(p, l)) { event.setCancelled(true); return; } RedProtect.get().firstLocationSelections.put(p, l); p.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().lang.get("playerlistener.wand1") + RedProtect.get().lang.get("general.color") + " (&e" + l.getBlockX() + RedProtect.get().lang.get("general.color") + ", &e" + l.getBlockY() + RedProtect.get().lang.get("general.color") + ", &e" + l.getBlockZ() + RedProtect.get().lang.get("general.color") + ").")); event.setCancelled(true); //show preview border previewSelection(p); } }
Example #9
Source File: ItemStackSnapshotDeserializer.java From Web-API with MIT License | 5 votes |
@Override public ItemStackSnapshot deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { JsonNode root = p.readValueAsTree(); if (root.path("type").isMissingNode()) throw new IOException("Missing item type"); String id = root.path("type").isTextual() ? root.path("type").asText() : root.path("type").path("id").asText(); Optional<ItemType> optType = Sponge.getRegistry().getType(ItemType.class, id); if (!optType.isPresent()) throw new IOException("Invalid item type " + id); Integer amount = root.path("quantity").isMissingNode() ? 1 : root.path("quantity").asInt(); ItemType type = optType.get(); ItemStack.Builder builder = ItemStack.builder().itemType(type).quantity(amount); ItemStack item = builder.build(); if (!root.path("data").isMissingNode()) { Iterator<Map.Entry<String, JsonNode>> it = root.path("data").fields(); while (it.hasNext()) { Map.Entry<String, JsonNode> entry = it.next(); Class<? extends DataManipulator> c = WebAPI.getSerializeService().getSupportedData().get(entry.getKey()); if (c == null) continue; Optional<? extends DataManipulator> optData = item.getOrCreate(c); if (!optData.isPresent()) throw new IOException("Invalid item data: " + entry.getKey()); DataManipulator data = optData.get(); item.offer(data); } } return item.createSnapshot(); }
Example #10
Source File: PlayerUtils.java From GriefPrevention with MIT License | 5 votes |
public static boolean hasItemInOneHand(Player player, ItemType itemType) { ItemStack mainHand = player.getItemInHand(HandTypes.MAIN_HAND).orElse(null); ItemStack offHand = player.getItemInHand(HandTypes.OFF_HAND).orElse(null); if ((mainHand != null && mainHand.getType().equals(itemType)) || (offHand != null && offHand.getType().equals(itemType))) { return true; } return false; }
Example #11
Source File: CommandHelper.java From GriefPrevention with MIT License | 5 votes |
private static boolean validateItemTarget(String target) { Optional<ItemType> itemType = Sponge.getRegistry().getType(ItemType.class, target); if (itemType.isPresent()) { return true; } // target could be an item block, so validate blockstate Optional<BlockState> blockState = Sponge.getRegistry().getType(BlockState.class, target); if (blockState.isPresent()) { return true; } return false; }
Example #12
Source File: VersionHelper56.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Override public ItemType getItemInHand(Player player) { if (player.getItemInHand(HandTypes.MAIN_HAND).isPresent()) { return player.getItemInHand(HandTypes.MAIN_HAND).get().getItem(); } else if (player.getItemInHand(HandTypes.OFF_HAND).isPresent()) { return player.getItemInHand(HandTypes.OFF_HAND).get().getItem(); } return ItemTypes.NONE; }
Example #13
Source File: GlobalListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onBlockPlace(ChangeBlockEvent.Place e, @Root Player p) { RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Is ChangeBlockEvent event! Cancelled? " + false); BlockSnapshot b = e.getTransactions().get(0).getFinal(); ItemType item = RedProtect.get().getVersionHelper().getItemInHand(p); Region r = RedProtect.get().rm.getTopRegion(e.getTransactions().get(0).getOriginal().getLocation().get(), this.getClass().getName()); if (r != null) { return; } if (!RedProtect.get().getUtil().canBuildNear(p, b.getLocation().get())) { e.setCancelled(true); return; } if (item.getName().contains("minecart") || item.getName().contains("boat")) { if (!RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).use_minecart && !p.hasPermission("redprotect.world.bypass")) { e.setCancelled(true); RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Can't place minecart/boat!"); } } else { if (!bypassBuild(p, b, 1)) { e.setCancelled(true); RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Can't Build!"); } } }
Example #14
Source File: EntityListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onAttemptInteractAS(InteractEntityEvent e, @First Player p) { Entity ent = e.getTargetEntity(); Location<World> l = ent.getLocation(); Region r = RedProtect.get().rm.getTopRegion(l, this.getClass().getName()); if (r == null) { //global flags if (ent.getType().equals(EntityTypes.ARMOR_STAND)) { if (!RedProtect.get().config.globalFlagsRoot().worlds.get(l.getExtent().getName()).build) { e.setCancelled(true); return; } } return; } ItemType itemInHand = RedProtect.get().getVersionHelper().getItemInHand(p); if (!itemInHand.equals(ItemTypes.NONE) && itemInHand.getType().equals(ItemTypes.ARMOR_STAND)) { if (!r.canBuild(p)) { e.setCancelled(true); RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbuild"); return; } } //TODO Not working! if (ent.getType().equals(EntityTypes.ARMOR_STAND)) { if (!r.canBuild(p)) { if (!RedProtect.get().ph.hasPerm(p, "redprotect.bypass")) { RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantedit"); e.setCancelled(true); } } } }
Example #15
Source File: ConfigManager.java From RedProtect with GNU General Public License v3.0 | 5 votes |
public ItemStack getGuiSeparator() { ItemStack separator = ItemStack.of(Sponge.getRegistry().getType(ItemType.class, guiRoot.gui_separator.material).orElse(ItemTypes.GLASS_PANE), 1); separator.offer(Keys.DISPLAY_NAME, RedProtect.get().guiLang.getFlagString("separator")); separator.offer(Keys.ITEM_DURABILITY, guiRoot.gui_separator.data); separator.offer(Keys.ITEM_LORE, Arrays.asList(Text.EMPTY, RedProtect.get().guiLang.getFlagString("separator"))); return separator; }
Example #16
Source File: ItemFlagGui.java From RedProtect with GNU General Public License v3.0 | 5 votes |
public ItemFlagGui(Player player, Region region, String flag) { this.flag = flag; this.player = player; this.region = region; this.guiItems = Arrays.stream(region.getFlagString(flag).replace(" ", "").toUpperCase().split(",")).sorted() .filter(item -> Sponge.getRegistry().getType(ItemType.class, item).isPresent()) .map(i -> ItemStack.of(Sponge.getRegistry().getType(ItemType.class, i).get(), 1)).toArray(ItemStack[]::new); }
Example #17
Source File: MobFlagGui.java From RedProtect with GNU General Public License v3.0 | 5 votes |
public MobFlagGui(Player player, Region region, String flag) { this.flag = flag; this.player = player; this.region = region; this.guiItems = Arrays.stream(region.getFlagString(flag).replace(" ", "").toUpperCase().split(",")).sorted() .filter(item -> Sponge.getRegistry().getType(ItemType.class, item).isPresent()) .map(i -> ItemStack.of(Sponge.getRegistry().getType(ItemType.class, i).get(), 1)).toArray(ItemStack[]::new); }
Example #18
Source File: ItemTypeFilter.java From Web-API with MIT License | 5 votes |
public ItemTypeFilter(WebHook hook, ConfigurationNode config) { super(hook, config); try { items = config.getList(TypeToken.of(ItemType.class)); } catch (ObjectMappingException e) { e.printStackTrace(); } }
Example #19
Source File: ItemStackDeserializer.java From Web-API with MIT License | 5 votes |
@Override public ItemStack deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { JsonNode root = p.readValueAsTree(); if (root.path("type").isMissingNode()) throw new IOException("Missing item type"); String id = root.path("type").isTextual() ? root.path("type").asText() : root.path("type").path("id").asText(); Optional<ItemType> optType = Sponge.getRegistry().getType(ItemType.class, id); if (!optType.isPresent()) throw new IOException("Invalid item type " + id); Integer amount = root.path("quantity").isMissingNode() ? 1 : root.path("quantity").asInt(); ItemType type = optType.get(); ItemStack.Builder builder = ItemStack.builder().itemType(type).quantity(amount); ItemStack item = builder.build(); if (!root.path("data").isMissingNode()) { Iterator<Map.Entry<String, JsonNode>> it = root.path("data").fields(); while (it.hasNext()) { Map.Entry<String, JsonNode> entry = it.next(); Class<? extends DataManipulator> c = WebAPI.getSerializeService().getSupportedData().get(entry.getKey()); if (c == null) continue; Optional<? extends DataManipulator> optData = item.getOrCreate(c); if (!optData.isPresent()) throw new IOException("Invalid item data: " + entry.getKey()); DataManipulator data = optData.get(); item.offer(data); } } return item; }
Example #20
Source File: MMCRestrictServlet.java From Web-API with MIT License | 5 votes |
@PUT @Path("/item/{id}") @Permission({ "item", "modify" }) @ApiOperation( value = "Modify an item", notes = "Modify an existing restricted item.") public CachedItemData modifyItem(@PathParam("id") String id, CachedItemData req) throws NotFoundException { if (req == null) { throw new BadRequestException("Request body is required"); } return WebAPI.runOnMain(() -> { Main plugin = getMMCRestrictPlugin(); ItemData item = plugin.removeItem(id); if (item == null) { throw new NotFoundException("The specified item is not restricted"); } // Transfer the item type of the old item to the new one Optional<ItemType> optType = Sponge.getRegistry().getType(ItemType.class, item.getItemid()); if (!optType.isPresent()) { plugin.addItem(item); // Add the old item because we removed it throw new InternalServerErrorException("Could not get item type"); } req.setItem(new CachedCatalogType<>(optType.get())); Optional<ItemData> optData = req.getLive(); if (!optData.isPresent()) { plugin.addItem(item); // Add the old item because we removed it throw new InternalServerErrorException("Could not create item data"); } plugin.addItem(optData.get()); saveData(plugin); return new CachedItemData(optData.get()); }); }
Example #21
Source File: CachedItemData.java From Web-API with MIT License | 5 votes |
public CachedItemData(ItemData value) { super(value); this.item = new CachedCatalogType<>(Sponge.getRegistry().getType(ItemType.class, value.getItemid()).orElse(null)); this.banReason = value.getBanreason(); this.ownershipBanned = value.getOwnershipbanned(); this.usageBanned = value.getUsagebanned(); this.breakingBanned = value.getBreakingbanned(); this.placingBanned = value.getPlacingbanned(); this.dropBanned = value.getDropbanned(); this.craftBanned = value.getCraftbanned(); this.worldBanned = value.getWorldbanned(); this.hidden = value.getHidden(); }
Example #22
Source File: VersionHelper7.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Override public ItemType getItemInHand(Player player) { if (player.getItemInHand(HandTypes.MAIN_HAND).isPresent()) { return player.getItemInHand(HandTypes.MAIN_HAND).get().getType(); } else if (player.getItemInHand(HandTypes.OFF_HAND).isPresent()) { return player.getItemInHand(HandTypes.OFF_HAND).get().getType(); } return ItemTypes.NONE; }
Example #23
Source File: VersionHelper8.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Override public ItemType getItemInHand(Player player) { if (!player.getItemInHand(HandTypes.MAIN_HAND).isEmpty()) { return player.getItemInHand(HandTypes.MAIN_HAND).getType(); } else if (!player.getItemInHand(HandTypes.OFF_HAND).isEmpty()) { return player.getItemInHand(HandTypes.OFF_HAND).getType(); } return ItemTypes.NONE; }
Example #24
Source File: SpongeDeathListener.java From Plan with GNU Lesser General Public License v3.0 | 5 votes |
private Runnable handlePlayerKill(long time, UUID victimUUID, Player killer) { Optional<ItemStack> inMainHand = killer.getItemInHand(HandTypes.MAIN_HAND); ItemStack inHand = inMainHand.orElse(killer.getItemInHand(HandTypes.OFF_HAND).orElse(ItemStack.empty())); ItemType type = inHand.isEmpty() ? ItemTypes.AIR : inHand.getType(); return victimUUID != null ? new PlayerKillProcessor(killer.getUniqueId(), time, victimUUID, new ItemNameFormatter().apply(type.getName())) : new MobKillProcessor(killer.getUniqueId()); }
Example #25
Source File: PlayerUtil.java From GriefDefender with MIT License | 5 votes |
public boolean hasItemInOneHand(Player player, ItemType itemType) { ItemStack mainHand = player.getItemInHand(HandTypes.MAIN_HAND).orElse(null); ItemStack offHand = player.getItemInHand(HandTypes.OFF_HAND).orElse(null); if ((mainHand != null && mainHand.getType().equals(itemType)) || (offHand != null && offHand.getType().equals(itemType))) { return true; } return false; }
Example #26
Source File: CommandHelper.java From GriefDefender with MIT License | 5 votes |
private static boolean validateItemTarget(String target) { Optional<ItemType> itemType = Sponge.getRegistry().getType(ItemType.class, target); if (itemType.isPresent()) { return true; } // target could be an item block, so validate blockstate Optional<BlockState> blockState = Sponge.getRegistry().getType(BlockState.class, target); if (blockState.isPresent()) { return true; } return false; }
Example #27
Source File: SpongeMaterial.java From PlotMe-Core with GNU General Public License v3.0 | 4 votes |
public ItemType getItemType() { return itemtype; }
Example #28
Source File: PlayerListener.java From RedProtect with GNU General Public License v3.0 | 4 votes |
@Listener(order = Order.FIRST) public void onInteractRight(InteractBlockEvent.Secondary event, @First Player p) { BlockSnapshot b = event.getTargetBlock(); Location<World> l; RedProtect.get().logger.debug(LogLevel.PLAYER, "PlayerListener - Is InteractBlockEvent.Secondary event"); if (!b.getState().getType().equals(BlockTypes.AIR)) { l = b.getLocation().get(); RedProtect.get().logger.debug(LogLevel.PLAYER, "PlayerListener - Is InteractBlockEvent.Secondary event. The block is " + b.getState().getType().getName()); } else { l = p.getLocation(); } Region r = RedProtect.get().rm.getTopRegion(l, this.getClass().getName()); ItemType itemInHand = RedProtect.get().getVersionHelper().getItemInHand(p); String claimmode = RedProtect.get().config.getWorldClaimType(p.getWorld().getName()); if (event instanceof InteractBlockEvent.Secondary.MainHand && itemInHand.getId().equalsIgnoreCase(RedProtect.get().config.configRoot().wands.adminWandID) && ((claimmode.equalsIgnoreCase("WAND") || claimmode.equalsIgnoreCase("BOTH")) || RedProtect.get().ph.hasPerm(p, "redprotect.admin.claim"))) { if (!RedProtect.get().getUtil().canBuildNear(p, l)) { event.setCancelled(true); return; } RedProtect.get().secondLocationSelections.put(p, l); p.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().lang.get("playerlistener.wand2") + RedProtect.get().lang.get("general.color") + " (&e" + l.getBlockX() + RedProtect.get().lang.get("general.color") + ", &e" + l.getBlockY() + RedProtect.get().lang.get("general.color") + ", &e" + l.getBlockZ() + RedProtect.get().lang.get("general.color") + ").")); event.setCancelled(true); //show preview border previewSelection(p); return; } //other blocks and interactions if (r != null) { if ((itemInHand.equals(ItemTypes.ENDER_PEARL) || itemInHand.getName().equals("minecraft:chorus_fruit")) && !r.canTeleport(p)) { RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse"); event.setUseItemResult(Tristate.FALSE); event.setCancelled(true); } else if ((itemInHand.equals(ItemTypes.BOW) || itemInHand.equals(ItemTypes.SNOWBALL) || itemInHand.equals(ItemTypes.EGG)) && !r.canProtectiles(p)) { RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse"); event.setUseItemResult(Tristate.FALSE); event.setCancelled(true); } else if (itemInHand.equals(ItemTypes.POTION) && !r.usePotions(p)) { RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse"); event.setUseItemResult(Tristate.FALSE); event.setCancelled(true); } else if (itemInHand.equals(ItemTypes.MONSTER_EGG) && !r.canInteractPassives(p)) { RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse"); event.setUseItemResult(Tristate.FALSE); event.setCancelled(true); } else if ((itemInHand.equals(ItemTypes.BOAT) || itemInHand.getType().getName().contains("_minecart")) && !r.canMinecart(p)) { RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse"); event.setUseItemResult(Tristate.FALSE); event.setCancelled(true); } } }
Example #29
Source File: BlockListener.java From RedProtect with GNU General Public License v3.0 | 4 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onBlockPlace(ChangeBlockEvent.Place e, @First Player p) { RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is BlockPlaceEvent event!"); BlockSnapshot b = e.getTransactions().get(0).getOriginal(); Location<World> bloc = b.getLocation().get(); World w = bloc.getExtent(); ItemType m = RedProtect.get().getVersionHelper().getItemInHand(p); boolean antih = RedProtect.get().config.configRoot().region_settings.anti_hopper; Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get(), this.getClass().getName()); if (r == null && canPlaceList(w, b.getState().getType().getName())) { return; } if (r != null) { if (!r.canMinecart(p) && m.getName().contains("minecart")) { RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantplace"); e.setCancelled(true); return; } if (b.getState().getType().equals(BlockTypes.MOB_SPAWNER) && r.allowSpawner(p)) { return; } try { if (!r.canBuild(p) && !r.canPlace(b)) { RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbuild"); e.setCancelled(true); } else { if (!RedProtect.get().ph.hasPerm(p, "redprotect.bypass") && antih && (m.equals(ItemTypes.HOPPER) || m.getName().contains("rail"))) { int x = bloc.getBlockX(); int y = bloc.getBlockY(); int z = bloc.getBlockZ(); BlockSnapshot ib = w.createSnapshot(x, y + 1, z); if (!cont.canBreak(p, ib) || !cont.canBreak(p, b)) { RedProtect.get().lang.sendMessage(p, "blocklistener.container.chestinside"); e.setCancelled(true); } } } } catch (Throwable t) { t.printStackTrace(); } } }
Example #30
Source File: VersionHelper7.java From RedProtect with GNU General Public License v3.0 | 4 votes |
@Override public ItemType getItemType(ItemStack itemStack) { return itemStack.getType(); }