use of org.bukkit.Material in project acidisland by tastybento.
the class IslandGuard method onPlayerHitEntity.
/**
* Handles hitting minecarts or feeding animals
* @param e - event
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerHitEntity(PlayerInteractEntityEvent e) {
Player p = e.getPlayer();
if (DEBUG) {
plugin.getLogger().info("Hit entity event " + e.getEventName());
}
if (!inWorld(p)) {
return;
}
if (p.isOp() || VaultHelper.checkPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) {
// You can do anything if you are Op of have the bypass
return;
}
/*
* Leashes are deal with mostly using the PlayerLeashEvent and PlayerUnleashEvent
* however, skeleton and zombie horses cannot be leashed, so those should be exempted
*/
if (Util.playerIsHolding(p, Material.LEASH) && e.getRightClicked() != null) {
if (DEBUG)
plugin.getLogger().info("DEBUG: checking horse types");
// Pre 1.11
if (e.getRightClicked() instanceof Horse) {
boolean skellyZombieHorse = false;
if (DEBUG)
plugin.getLogger().info("DEBUG: horse clicked ");
Horse horse = (Horse) e.getRightClicked();
if (DEBUG)
plugin.getLogger().info("DEBUG: horse variant = " + horse.getVariant());
if (horse.getVariant().equals(Variant.SKELETON_HORSE) || horse.getVariant().equals(Variant.UNDEAD_HORSE)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: skelly or zombie horse");
skellyZombieHorse = true;
}
if (DEBUG)
plugin.getLogger().info("DEBUG: Checking entity types :" + e.getRightClicked().getType().name());
// For 1.11 onwards
if (e.getRightClicked().getType().name().equals("ZOMBIE_HORSE") || e.getRightClicked().getType().name().equals("SKELETON_HORSE")) {
skellyZombieHorse = true;
}
if (!skellyZombieHorse)
return;
if (DEBUG)
plugin.getLogger().info("DEBUG: zombie horse or skelly horse");
}
}
Island island = plugin.getGrid().getProtectedIslandAt(e.getPlayer().getLocation());
if (!plugin.getGrid().playerIsOnIsland(e.getPlayer())) {
// Handle village trading
if (e.getRightClicked() != null && e.getRightClicked().getType().equals(EntityType.VILLAGER)) {
if (island != null) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: island is not null");
plugin.getLogger().info("DEBUG: island is not spawn");
plugin.getLogger().info("DEBUG: villager trading is " + island.getIgsFlag(SettingsFlag.VILLAGER_TRADING));
}
if ((!island.getIgsFlag(SettingsFlag.VILLAGER_TRADING) && !island.getMembers().contains(p.getUniqueId()))) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
}
}
// Handle name tags and dyes
if (Util.playerIsHolding(p, Material.NAME_TAG) || Util.playerIsHolding(p, Material.INK_SACK)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
e.getPlayer().updateInventory();
return;
}
// Handle cookies (to animals)
if (Util.playerIsHolding(p, Material.COOKIE) && e.getRightClicked() instanceof Animals) {
if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.HURT_MOBS)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
if (island != null) {
if ((!island.getIgsFlag(SettingsFlag.HURT_MOBS) && !island.getMembers().contains(p.getUniqueId()))) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
}
}
// Handle breeding
if (e.getRightClicked() instanceof Animals) {
for (ItemStack item : Util.getPlayerInHandItems(p)) {
Material type = item.getType();
if (type == Material.EGG || type == Material.WHEAT || type == Material.CARROT_ITEM || type == Material.SEEDS) {
if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.BREEDING)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
if (island != null) {
if ((!island.getIgsFlag(SettingsFlag.BREEDING) && !island.getMembers().contains(p.getUniqueId()))) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
}
}
}
}
switch(e.getRightClicked().getType()) {
case CREEPER:
// This seems to be called when the player is in Creative mode...
if (!Settings.allowCreeperGriefing) {
for (ItemStack item : Util.getPlayerInHandItems(e.getPlayer())) {
if (item != null && item.getType().equals(Material.FLINT_AND_STEEL)) {
if (!island.getMembers().contains(e.getPlayer().getUniqueId())) {
// Visitor
litCreeper.add(e.getRightClicked().getUniqueId());
if (DEBUG) {
plugin.getLogger().info("DEBUG: visitor lit creeper");
}
}
}
}
}
break;
case LLAMA:
case SKELETON_HORSE:
case ZOMBIE_HORSE:
case HORSE:
// plugin.getLogger().info("Horse riding");
if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.HORSE_RIDING)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
e.getPlayer().updateInventory();
}
if (island != null && !island.getIgsFlag(SettingsFlag.HORSE_RIDING)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
e.getPlayer().updateInventory();
}
break;
case ITEM_FRAME:
// This is to place items in an item frame
if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.PLACE_BLOCKS)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
}
if (island != null) {
if (!island.getIgsFlag(SettingsFlag.PLACE_BLOCKS)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
}
}
break;
case MINECART_CHEST:
case MINECART_FURNACE:
case MINECART_HOPPER:
// plugin.getLogger().info("Minecarts");
if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.CHEST)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
}
if (island != null) {
if (!island.getIgsFlag(SettingsFlag.CHEST)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
}
}
break;
default:
break;
}
}
}
use of org.bukkit.Material in project acidisland by tastybento.
the class LavaCheck method generatesCobble.
public boolean generatesCobble(Block block, Block toBlock) {
Material mirrorID1 = (block.getType().equals(Material.WATER)) || (block.getType().equals(Material.STATIONARY_WATER)) ? Material.LAVA : Material.WATER;
Material mirrorID2 = (block.getType().equals(Material.WATER)) || (block.getType().equals(Material.STATIONARY_WATER)) ? Material.STATIONARY_LAVA : Material.STATIONARY_WATER;
for (BlockFace face : FACES) {
Block r = toBlock.getRelative(face);
if ((r.getType().equals(mirrorID1)) || (r.getType().equals(mirrorID2))) {
return true;
}
}
return false;
}
use of org.bukkit.Material in project acidisland by tastybento.
the class ControlPanel method loadShop.
// The first parameter, is the inventory owner. I make it null to let
// everyone use it.
// The second parameter, is the slots in a inventory. Must be a multiple of
// 9. Can be up to 54.
// The third parameter, is the inventory name. This will accept chat colors.
/**
* This loads the minishop from the minishop.yml file
*/
public static void loadShop() {
// The first parameter is the Material, then the durability (if wanted),
// slot, descriptions
// Minishop
store.clear();
miniShopFile = Util.loadYamlFile("minishop.yml");
allowSelling = miniShopFile.getBoolean("config.allowselling", false);
ConfigurationSection items = miniShopFile.getConfigurationSection("items");
ASkyBlock plugin = ASkyBlock.getPlugin();
if (DEBUG)
plugin.getLogger().info("DEBUG: loading the shop. items = " + items.toString());
if (items != null) {
// Create the store
// Get how many the store should be
int size = items.getKeys(false).size() + 8;
size -= (size % 9);
miniShop = Bukkit.createInventory(null, size, plugin.myLocale().islandMiniShopTitle);
// Run through items
int slot = 0;
for (String item : items.getKeys(false)) {
try {
String m = items.getString(item + ".material");
// plugin.getLogger().info("Material = " + m);
Material material = Material.matchMaterial(m);
int quantity = items.getInt(item + ".quantity", 0);
String extra = items.getString(item + ".extra", "");
double price = items.getDouble(item + ".price", -1D);
double sellPrice = items.getDouble(item + ".sellprice", -1D);
if (!allowSelling) {
sellPrice = -1;
}
String description = ChatColor.translateAlternateColorCodes('&', items.getString(item + ".description", ""));
MiniShopItem shopItem = new MiniShopItem(material, extra, slot, description, quantity, price, sellPrice);
store.put(slot, shopItem);
miniShop.setItem(slot, shopItem.getItem());
slot++;
} catch (Exception e) {
plugin.getLogger().warning("Problem loading minishop item #" + slot);
plugin.getLogger().warning(e.getMessage());
e.printStackTrace();
}
}
}
}
use of org.bukkit.Material in project acidisland by tastybento.
the class ControlPanel method loadControlPanel.
/**
* This loads the control panel from the controlpanel.yml file
*/
public static void loadControlPanel() {
ASkyBlock plugin = ASkyBlock.getPlugin();
// Map of known panel contents by name
panels.clear();
// Map of panel inventories by name
controlPanel.clear();
cpFile = Util.loadYamlFile("controlpanel.yml");
ConfigurationSection controlPanels = cpFile.getRoot();
if (controlPanels == null) {
plugin.getLogger().severe("Controlpanel.yml is corrupted! Delete so it can be regenerated or fix!");
return;
}
// Go through the yml file and create inventories and panel maps
for (String panel : controlPanels.getKeys(false)) {
// plugin.getLogger().info("DEBUG: Panel " + panel);
ConfigurationSection panelConf = cpFile.getConfigurationSection(panel);
if (panelConf != null) {
// New panel map
HashMap<Integer, CPItem> cp = new HashMap<Integer, CPItem>();
String panelName = ChatColor.translateAlternateColorCodes('&', panelConf.getString("panelname", "Commands"));
if (panel.equalsIgnoreCase("default")) {
defaultPanelName = panelName;
}
// plugin.getLogger().info("DEBUG: Panel section " + panelName);
// plugin.getLogger().info("DEBUG: putting panel " +
// newPanel.getName());
ConfigurationSection buttons = cpFile.getConfigurationSection(panel + ".buttons");
if (buttons != null) {
// Get how many buttons can be in the CP
int size = buttons.getKeys(false).size() + 8;
size -= (size % 9);
// Add inventory to map of inventories
controlPanel.put(panelName, Bukkit.createInventory(null, size, panelName));
// Run through buttons
int slot = 0;
for (String item : buttons.getKeys(false)) {
try {
String m = buttons.getString(item + ".material", "BOOK");
// Split off damage
String[] icon = m.split(":");
// plugin.getLogger().info("Material = " + m);
Material material = Material.matchMaterial(icon[0]);
if (material == null) {
material = Material.PAPER;
plugin.getLogger().severe("Error in controlpanel.yml " + icon[0] + " is an unknown material, using paper.");
}
String description = ChatColor.translateAlternateColorCodes('&', buttons.getString(item + ".description", ""));
String command = buttons.getString(item + ".command", "").replace("[island]", Settings.ISLANDCOMMAND);
String nextSection = buttons.getString(item + ".nextsection", "");
ItemStack i = new ItemStack(material);
if (icon.length == 2) {
i.setDurability(Short.parseShort(icon[1]));
}
CPItem cpItem = new CPItem(i, description, command, nextSection);
cp.put(slot, cpItem);
controlPanel.get(panelName).setItem(slot, cpItem.getItem());
slot++;
} catch (Exception e) {
plugin.getLogger().warning("Problem loading control panel " + panel + " item #" + slot);
plugin.getLogger().warning(e.getMessage());
e.printStackTrace();
}
}
// Add overall control panel
panels.put(panelName, cp);
}
}
}
}
use of org.bukkit.Material in project acidisland by tastybento.
the class SafeSpotTeleport method checkBlock.
/**
* Returns true if the location is a safe one.
* @param chunk
* @param x
* @param y
* @param z
* @param worldHeight
* @return true if this is a safe spot, false if this is a portal scan
*/
@SuppressWarnings("deprecation")
private boolean checkBlock(ChunkSnapshot chunk, int x, int y, int z, int worldHeight) {
World world = location.getWorld();
Material type = Material.getMaterial(chunk.getBlockTypeId(x, y, z));
if (!type.equals(Material.AIR)) {
// AIR
Material space1 = Material.getMaterial(chunk.getBlockTypeId(x, Math.min(y + 1, worldHeight), z));
Material space2 = Material.getMaterial(chunk.getBlockTypeId(x, Math.min(y + 2, worldHeight), z));
if ((space1.equals(Material.AIR) && space2.equals(Material.AIR)) || (space1.equals(Material.PORTAL) && space2.equals(Material.PORTAL)) && (!type.toString().contains("FENCE") && !type.toString().contains("DOOR") && !type.toString().contains("GATE") && !type.toString().contains("PLATE"))) {
switch(type) {
// Unsafe
case ANVIL:
case BARRIER:
case BOAT:
case CACTUS:
case DOUBLE_PLANT:
case ENDER_PORTAL:
case FIRE:
case FLOWER_POT:
case LADDER:
case LAVA:
case LEVER:
case LONG_GRASS:
case PISTON_EXTENSION:
case PISTON_MOVING_PIECE:
case SIGN_POST:
case SKULL:
case STANDING_BANNER:
case STATIONARY_LAVA:
case STATIONARY_WATER:
case STONE_BUTTON:
case TORCH:
case TRIPWIRE:
case WATER:
case WEB:
case WOOD_BUTTON:
// Block is dangerous
break;
case PORTAL:
if (portal) {
// A portal has been found, switch to non-portal mode now
portal = false;
}
break;
default:
return safe(chunk, x, y, z, world);
}
}
}
return false;
}
Aggregations