Java Code Examples for org.bukkit.Material#ENDER_CHEST

The following examples show how to use org.bukkit.Material#ENDER_CHEST . 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: TeamChestListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onTeamChestBuilt(BedwarsPlayerBuildBlock event) {
    if (event.isCancelled()) {
        return;
    }

    Block block = event.getBlock();
    RunningTeam team = event.getTeam();

    if (block.getType() != Material.ENDER_CHEST) {
        return;
    }

    String unhidden = APIUtils.unhashFromInvisibleStringStartsWith(event.getItemInHand(), TEAM_CHEST_PREFIX);

    if (unhidden != null || Main.getConfigurator().config.getBoolean("specials.teamchest.turn-all-enderchests-to-teamchests")) {
        team.addTeamChest(block);
        String message = i18n("team_chest_placed");
        for (Player pl : team.getConnectedPlayers()) {
            pl.sendMessage(message);
        }
    }
}
 
Example 2
Source File: TeamChestListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onTeamChestBuilt(BedwarsPlayerBuildBlock event) {
    if (event.isCancelled()) {
        return;
    }

    Block block = event.getBlock();
    RunningTeam team = event.getTeam();

    if (block.getType() != Material.ENDER_CHEST) {
        return;
    }

    String unhidden = APIUtils.unhashFromInvisibleStringStartsWith(event.getItemInHand(), TEAM_CHEST_PREFIX);

    if (unhidden != null || Main.getConfigurator().config.getBoolean("specials.teamchest.turn-all-enderchests-to-teamchests")) {
        team.addTeamChest(block);
        String message = i18n("team_chest_placed");
        for (Player pl : team.getConnectedPlayers()) {
            pl.sendMessage(message);
        }
    }
}
 
Example 3
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Prevents crafting of EnderChest unless the player has permission
 *
 * @param event
 */
@EventHandler(priority = EventPriority.LOW)
public void onCraft(CraftItemEvent event) {
    if (DEBUG) {
        plugin.getLogger().info(event.getEventName());
    }
    Player player = (Player) event.getWhoClicked();
    if (inWorld(player) || player.getWorld().equals(ASkyBlock.getNetherWorld())) {
        if (event.getRecipe().getResult().getType() == Material.ENDER_CHEST) {
            if (!(player.hasPermission(Settings.PERMPREFIX + "craft.enderchest"))) {
                Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
                event.setCancelled(true);
            }
        }
    }
}
 
Example 4
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Prevents usage of an Ender Chest
 *
 * @param event
 */

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEnderChestEvent(final PlayerInteractEvent event) {
    if (DEBUG) {
        plugin.getLogger().info("Ender chest " + event.getEventName());
    }
    Player player = event.getPlayer();
    if (inWorld(player) || player.getWorld().equals(ASkyBlock.getNetherWorld())) {
        if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
            if (event.getClickedBlock().getType() == Material.ENDER_CHEST) {
                if (!(event.getPlayer().hasPermission(Settings.PERMPREFIX + "craft.enderchest"))) {
                    Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
                    event.setCancelled(true);
                }
            }
        }
    }
}
 
Example 5
Source File: EventFilterMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerBlockChange(final PlayerBlockTransformEvent event) {
  cancelUnlessInteracting(event, event.getPlayerState());

  if (!event.isCancelled() && event.getNewState().getType() == Material.ENDER_CHEST) {
    cancel(
        event,
        true,
        event.getWorld(),
        event.getPlayer(),
        TranslatableComponent.of("match.disabled.enderChest"));
  }
}
 
Example 6
Source File: EventFilterMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerBlockChange(final PlayerBlockTransformEvent event) {
    cancelUnlessInteracting(event, event.getPlayerState());

    if(!event.isCancelled() && event.getNewState().getType() == Material.ENDER_CHEST) {
        cancel(event, true, event.getWorld(), event.getPlayer(), new TranslatableComponent("match.enderChestsDisabled"));
    }
}
 
Example 7
Source File: NewItemShop.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
private VillagerTrade getTradingItem(MerchantCategory category, ItemStack stack, Game game,
    Player player) {
  for (VillagerTrade trade : category.getOffers()) {
    if (trade.getItem1().getType() == Material.AIR
        && trade.getRewardItem().getType() == Material.AIR) {
      continue;
    }
    ItemStack iStack = this.toItemStack(trade, player, game);
    if (iStack.getType() == Material.ENDER_CHEST && stack.getType() == Material.ENDER_CHEST) {
      return trade;
    } else if ((iStack.getType() == Material.POTION
        || (!BedwarsRel.getInstance().getCurrentVersion().startsWith("v1_8")
        && (iStack.getType().equals(Material.valueOf("TIPPED_ARROW"))
        || iStack.getType().equals(Material.valueOf("LINGERING_POTION"))
        || iStack.getType().equals(Material.valueOf("SPLASH_POTION")))))) {
      if (BedwarsRel.getInstance().getCurrentVersion().startsWith("v1_8")) {
        if (iStack.getItemMeta().equals(stack.getItemMeta())) {
          return trade;
        }
      } else {
        PotionMeta iStackMeta = (PotionMeta) iStack.getItemMeta();
        PotionMeta stackMeta = (PotionMeta) stack.getItemMeta();
        if (iStackMeta.getBasePotionData().equals(stackMeta.getBasePotionData()) && iStackMeta
            .getCustomEffects().equals(stackMeta.getCustomEffects())) {
          return trade;
        }
      }
    } else if (iStack.equals(stack)) {
      return trade;
    }
  }

  return null;
}
 
Example 8
Source File: CrateDropEvent.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
public CrateDropEvent(GameMap map, boolean b) {
	this.gMap = map;
	this.enabled = b;
	File dataDirectory = SkyWarsReloaded.get().getDataFolder();
       File mapDataDirectory = new File(dataDirectory, "mapsData");

       if (!mapDataDirectory.exists() && !mapDataDirectory.mkdirs()) {
       	return;
       }
       
       File mapFile = new File(mapDataDirectory, gMap.getName() + ".yml");
    if (mapFile.exists()) {
    	eventName = "CrateDropEvent";
    	slot = 6;
    	material = new ItemStack(Material.ENDER_CHEST, 1);
        FileConfiguration fc = YamlConfiguration.loadConfiguration(mapFile);
        this.min = fc.getInt("events." + eventName + ".minStart");
        this.max = fc.getInt("events." + eventName + ".maxStart");
        this.length = fc.getInt("events." + eventName + ".length");
        this.chance = fc.getInt("events." + eventName + ".chance");
        this.title = fc.getString("events." + eventName + ".title");
        this.subtitle = fc.getString("events." + eventName + ".subtitle");
        this.startMessage = fc.getString("events." + eventName + ".startMessage");
        this.endMessage = fc.getString("events." + eventName + ".endMessage");
        this.announceEvent = fc.getBoolean("events." + eventName + ".announceTimer");
        this.repeatable = fc.getBoolean("events." + eventName + ".repeatable");
        this.maxItemsPerCrate = fc.getInt("events." + eventName + ".maxItemsPerCrate");
        this.maxNumOfCrates = fc.getInt("events." + eventName + ".maxNumOfCrates");
    }
}
 
Example 9
Source File: TestEnderBackpack.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public EnderBackpack registerSlimefunItem(SlimefunPlugin plugin, String id) {
    SlimefunItemStack item = new SlimefunItemStack(id, Material.ENDER_CHEST, "&5Test Ender Backpack");
    EnderBackpack backpack = new EnderBackpack(TestUtilities.getCategory(plugin, "ender_backpack"), item, RecipeType.NULL, new ItemStack[9]);
    backpack.register(plugin);
    return backpack;
}
 
Example 10
Source File: SignListener.java    From PlayerVaults with GNU General Public License v3.0 5 votes vote down vote up
private boolean isInvalidBlock(Material material) {
    if (PlayerVaults.getInstance().getVersion().contains("v1_13")) {
        PlayerVaults.debug("[PlayerVaults] [Debug/SignListener] Block material checked for >= 1.13");
        return material == Material.CHEST || material == Material.TRAPPED_CHEST
                || material == Material.ENDER_CHEST || material == Material.FURNACE
                || material == Material.BREWING_STAND || material == Material.ENCHANTING_TABLE
                || material == Material.BEACON;
    }
    PlayerVaults.debug("[PlayerVaults] [Debug/SignListener] Block material checked for < 1.13");
    return material == Material.CHEST || material == Material.TRAPPED_CHEST
            || material == Material.ENDER_CHEST || material == Material.FURNACE
            || material == Material.valueOf("BURNING_FURNACE") || material == Material.BREWING_STAND
            || material == Material.valueOf("ENCHANTMENT_TABLE") || material == Material.BEACON;
}
 
Example 11
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
public void onPlayerBucketEvent(PlayerBucketEvent event) {
    final Player player = event.getPlayer();
    final Block clickedBlock = event.getBlockClicked();
    GDCauseStackManager.getInstance().pushCause(player);
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUID())) {
        return;
    }
    if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.INTERACT_BLOCK_SECONDARY.getName(), clickedBlock, player.getWorld().getUID())) {
        return;
    }

    GDTimings.PLAYER_INTERACT_BLOCK_SECONDARY_EVENT.startTiming();
    final Object source = player;
    final Location location = clickedBlock.getLocation();
    final GDClaim claim = this.dataStore.getClaimAt(location);
    final TrustType trustType = NMSUtil.getInstance().isTileInventory(location) || clickedBlock != null && clickedBlock.getType() == Material.ENDER_CHEST ? TrustTypes.CONTAINER : TrustTypes.ACCESSOR;

    Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.INTERACT_BLOCK_SECONDARY, source, clickedBlock, player, trustType, true);
    if (result == Tristate.FALSE) {
        event.setCancelled(true);
        GDTimings.PLAYER_INTERACT_BLOCK_SECONDARY_EVENT.stopTiming();
        return;
    }

    GDTimings.PLAYER_INTERACT_BLOCK_SECONDARY_EVENT.stopTiming();

    if (event instanceof PlayerBucketEmptyEvent) {
        // check block place
        result = GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.BLOCK_PLACE, source, event.getBucket().name().toLowerCase().replace("_bucket", ""), player, TrustTypes.BUILDER, true);
        if (result == Tristate.FALSE) {
            event.setCancelled(true);
            return;
        }
    } else if (event instanceof PlayerBucketFillEvent) {
        // check block break
        result = GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.BLOCK_BREAK, source, event.getBlockClicked(), player, TrustTypes.BUILDER, true);
        if (result == Tristate.FALSE) {
            event.setCancelled(true);
            return;
        }
    }
}
 
Example 12
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerInteractBlockSecondary(PlayerInteractEvent event) {
    final Block clickedBlock = event.getClickedBlock();
    if (clickedBlock == null) {
        return;
    }

    final String id = GDPermissionManager.getInstance().getPermissionIdentifier(clickedBlock);
    final GDBlockType gdBlock = BlockTypeRegistryModule.getInstance().getById(id).orElse(null);
    if (gdBlock == null || (!gdBlock.isInteractable() && event.getAction() != Action.PHYSICAL)) {
        return;
    }
    if (NMSUtil.getInstance().isBlockStairs(clickedBlock) && event.getAction() != Action.PHYSICAL) {
        return;
    }

    final Player player = event.getPlayer();
    GDCauseStackManager.getInstance().pushCause(player);
    final GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) {
        onPlayerInteractBlockPrimary(event, player);
        return;
    }

    final Location location = clickedBlock.getLocation();
    GDClaim claim = this.dataStore.getClaimAt(location);
    final Sign sign = SignUtil.getSign(location);
    // check sign
    if (SignUtil.isSellSign(sign)) {
        EconomyUtil.getInstance().buyClaimConsumerConfirmation(player, claim, sign);
        return;
    }
    if (SignUtil.isRentSign(claim, sign)) {
        EconomyUtil.getInstance().rentClaimConsumerConfirmation(player, claim, sign);
        return;
    }

    final BlockState state = clickedBlock.getState();
    final ItemStack itemInHand = event.getItem();
    final boolean hasInventory = NMSUtil.getInstance().isTileInventory(location) || clickedBlock.getType() == Material.ENDER_CHEST;
    if (hasInventory) {
        onInventoryOpen(event, state.getLocation(), state, player);
        return;
    }

    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUID())) {
        return;
    }
    if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.INTERACT_BLOCK_SECONDARY.getName(), event.getClickedBlock(), player.getWorld().getUID())) {
        return;
    }

    GDTimings.PLAYER_INTERACT_BLOCK_SECONDARY_EVENT.startTiming();
    final Object source = player;

    final TrustType trustType = NMSUtil.getInstance().isTileInventory(location) || clickedBlock.getType() == Material.ENDER_CHEST ? TrustTypes.CONTAINER : TrustTypes.ACCESSOR;
    if (GDFlags.INTERACT_BLOCK_SECONDARY && playerData != null) {
        Flag flag = Flags.INTERACT_BLOCK_SECONDARY;
        if (event.getAction() == Action.PHYSICAL) {
            flag = Flags.COLLIDE_BLOCK;
        }
        Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, claim, flag, source, clickedBlock, player, trustType, true);
        if (result == Tristate.FALSE) {
            // if player is holding an item, check if it can be placed
            if (GDFlags.BLOCK_PLACE && itemInHand != null && itemInHand.getType().isBlock()) {
                if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.BLOCK_PLACE.getName(), itemInHand, player.getWorld().getUID())) {
                    GDTimings.PLAYER_INTERACT_BLOCK_SECONDARY_EVENT.stopTiming();
                    return;
                }
                if (GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.BLOCK_PLACE, source, itemInHand, player, TrustTypes.BUILDER, true) == Tristate.TRUE) {
                    GDTimings.PLAYER_INTERACT_BLOCK_SECONDARY_EVENT.stopTiming();
                    return;
                }
            }
            // Don't send a deny message if the player is in claim mode or is holding an investigation tool
            if (lastInteractItemCancelled != true) {
                if (!playerData.claimMode && (GriefDefenderPlugin.getInstance().investigationTool == null || !NMSUtil.getInstance().hasItemInOneHand(player, GriefDefenderPlugin.getInstance().investigationTool))) {
                    if (event.getAction() == Action.PHYSICAL) {
                        if (player.getWorld().getTime() % 100 == 0L) {
                            this.sendInteractBlockDenyMessage(itemInHand, clickedBlock, claim, player, playerData);
                        }
                    } else {
                        if (gdBlock != null && gdBlock.isInteractable()) {
                            this.sendInteractBlockDenyMessage(itemInHand, clickedBlock, claim, player, playerData);
                        }
                    }
                }
            }

            event.setUseInteractedBlock(Result.DENY);
            GDTimings.PLAYER_INTERACT_BLOCK_SECONDARY_EVENT.stopTiming();
            return;
        }
    }

    GDTimings.PLAYER_INTERACT_BLOCK_SECONDARY_EVENT.stopTiming();
}
 
Example 13
Source File: BlockListener.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onClick(PlayerInteractEvent event) {
	Player player = event.getPlayer();

	ItemStack norm = null;
	if (event.getHand() == EquipmentSlot.HAND) {
		norm = player.getInventory().getItemInMainHand();
	} else if (event.getHand() == EquipmentSlot.OFF_HAND) {
		norm = player.getInventory().getItemInOffHand();
	}

	if (norm == null) return;

	if (event.getAction() == Action.RIGHT_CLICK_AIR) {
		if (modManager.isModifierItem(norm)) {
			event.setCancelled(true);
		}
	} else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
		Block block = event.getClickedBlock();

		if (block == null) {
			return;
		}
		if (!player.isSneaking()) {
			Material type = block.getType();

			if (type == Material.ANVIL || type == Material.CRAFTING_TABLE
					|| type == Material.CHEST || type == Material.ENDER_CHEST
					|| type == Material.DROPPER || type == Material.HOPPER
					|| type == Material.DISPENSER || type == Material.TRAPPED_CHEST
					|| type == Material.FURNACE || type == Material.ENCHANTING_TABLE) {

				return;
			}
		}

		if (modManager.isModifierItem(norm)) {
			event.setCancelled(true);
			return;
		}

		if (block.getType() == Material.getMaterial(MineTinker.getPlugin().getConfig().getString("BlockToEnchantModifiers", Material.BOOKSHELF.name()))) {
			ItemStack item = player.getInventory().getItemInMainHand();

			for (Modifier m : modManager.getAllMods()) {
				if (m.getModItem().getType().equals(item.getType())) {
					if (!m.isEnchantable()) continue;
					m.enchantItem(player);
					event.setCancelled(true);
					break;
				}
			}
		}
	}
}
 
Example 14
Source File: EnderChest.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public EnderChest() {
    super(Material.ENDER_CHEST);
}
 
Example 15
Source File: BlockListener.java    From BedwarsRel with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onPlace(BlockPlaceEvent bpe) {
  Player player = bpe.getPlayer();
  Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);

  if (game == null) {
    return;
  }

  if (game.getState() == GameState.STOPPED) {
    return;
  }

  if (game.getState() == GameState.WAITING) {
    bpe.setCancelled(true);
    bpe.setBuild(false);
    return;
  }

  if (game.getState() == GameState.RUNNING) {
    if (game.isSpectator(player)) {
      bpe.setCancelled(true);
      bpe.setBuild(false);
      return;
    }

    Block placeBlock = bpe.getBlockPlaced();
    BlockState replacedBlock = bpe.getBlockReplacedState();

    if (placeBlock.getType() == game.getTargetMaterial()) {
      bpe.setCancelled(true);
      bpe.setBuild(false);
      return;
    }

    if (!game.getRegion().isInRegion(placeBlock.getLocation())) {
      bpe.setCancelled(true);
      bpe.setBuild(false);
      return;
    }

    if (replacedBlock != null && !BedwarsRel
        .getInstance().getBooleanConfig("place-in-liquid", true)
        && (replacedBlock.getType().equals(Material.WATER)
        || replacedBlock.getType().equals(Material.STATIONARY_WATER)
        || replacedBlock.getType().equals(Material.LAVA)
        || replacedBlock.getType().equals(Material.STATIONARY_LAVA))) {
      bpe.setCancelled(true);
      bpe.setBuild(false);
      return;
    }

    if (replacedBlock != null && placeBlock.getType().equals(Material.WEB)
        && (replacedBlock.getType().equals(Material.WATER)
        || replacedBlock.getType().equals(Material.STATIONARY_WATER)
        || replacedBlock.getType().equals(Material.LAVA)
        || replacedBlock.getType().equals(Material.STATIONARY_LAVA))) {
      bpe.setCancelled(true);
      bpe.setBuild(false);
      return;
    }

    if (placeBlock.getType() == Material.ENDER_CHEST) {
      Team playerTeam = game.getPlayerTeam(player);
      if (playerTeam.getInventory() == null) {
        playerTeam.createTeamInventory();
      }

      playerTeam.addChest(placeBlock);
    }

    if (!bpe.isCancelled()) {
      game.getRegion().addPlacedBlock(placeBlock,
          (replacedBlock.getType().equals(Material.AIR) ? null : replacedBlock));
    }
  }
}