bad rework begin
This commit is contained in:
parent
f382d56df5
commit
8cba7af0e0
11 changed files with 494 additions and 10 deletions
|
@ -101,7 +101,8 @@ limit:
|
|||
|
||||
# UseBlackList
|
||||
# Prevents using or placing of the given blocks in creative mode (and only in creative).
|
||||
# You can use the technical name (see http://jd.bukkit.org/doxygen/d7/dd9/namespaceorg_1_1bukkit.html#ab7fa290bb19b9a830362aa88028ec80a)
|
||||
# You can use the technical name (see http://jd.bukkit.org/doxygen/d6/d0e/enumorg_1_1bukkit_1_1Material.html
|
||||
# or https://github.com/Bukkit/Bukkit/blob/master/src/main/java/org/bukkit/Material.java)
|
||||
# or the id of the block/item (better use the id, if you're not sure).
|
||||
# To prevent Lava you need to add "LAVA_BUCKET", because lava-blocks aren't "placed", therefore Lava-Buckets are
|
||||
# "used".
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
name: LimitedCreative
|
||||
main: de.jaschastarke.minecraft.limitedcreative.Core
|
||||
version: 1.3.0c
|
||||
softdepend: [WorldGuard, WorldEdit, MultiInv]
|
||||
version: 1.4.0a
|
||||
softdepend: [WorldGuard, WorldEdit, MultiInv, Vault]
|
||||
dev-url: http://dev.bukkit.org/server-mods/limited-creative/
|
||||
commands:
|
||||
limitedcreative:
|
||||
|
@ -72,4 +72,7 @@ permissions:
|
|||
default: false
|
||||
limitedcreative.nolimit.break:
|
||||
description: Allows bypassing the "block break"-limitation
|
||||
default: false
|
||||
limitedcreative.permissions.keep:
|
||||
description: Allows bypassing the permission based limitations settet temporary via Vault (TESTING)
|
||||
default: false
|
10
pom.xml
10
pom.xml
|
@ -3,7 +3,7 @@
|
|||
<groupId>de.jaschastarke</groupId>
|
||||
<artifactId>LimitedCreative</artifactId>
|
||||
<name>LimitedCreative</name>
|
||||
<version>1.3.0c</version>
|
||||
<version>1.4.0a</version>
|
||||
<url>https://github.com/possi/LimitedCreative</url>
|
||||
<scm>
|
||||
<connection>scm:git:git://github.com/possi/LimitedCreative.git</connection>
|
||||
|
@ -31,6 +31,10 @@
|
|||
<id>onarandombox</id>
|
||||
<url>http://repo.onarandombox.com/content/groups/public</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://ci.herocraftonline.com/plugin/repository/everything</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<build>
|
||||
<sourceDirectory>${basedir}/src</sourceDirectory>
|
||||
|
@ -68,12 +72,12 @@
|
|||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.3.1-R1.0</version>
|
||||
<version>1.4.2-R0.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldguard</artifactId>
|
||||
<version>5.5.4-SNAPSHOT</version>
|
||||
<version>5.6.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>uk.org.whoami</groupId>
|
||||
|
|
31
src/de/jaschastarke/minecraft/lib/Core.java
Normal file
31
src/de/jaschastarke/minecraft/lib/Core.java
Normal file
|
@ -0,0 +1,31 @@
|
|||
package de.jaschastarke.minecraft.lib;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class Core extends JavaPlugin {
|
||||
public final Logger logger = Logger.getLogger("Minecraft");
|
||||
|
||||
private List<Module> modules = new ArrayList<Module>();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Module> T getModule(Class<T> modclass) {
|
||||
for (Module module : modules) {
|
||||
if (modclass.isInstance(module)) {
|
||||
return (T) module;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Module getModule(String modid) {
|
||||
for (Module module : modules) {
|
||||
if (module.getIdentifier().equals(modid)) {
|
||||
return module;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
10
src/de/jaschastarke/minecraft/lib/Module.java
Normal file
10
src/de/jaschastarke/minecraft/lib/Module.java
Normal file
|
@ -0,0 +1,10 @@
|
|||
package de.jaschastarke.minecraft.lib;
|
||||
|
||||
abstract public class Module {
|
||||
abstract public String getIdentifier();
|
||||
abstract public void init();
|
||||
|
||||
public void unload() {
|
||||
|
||||
}
|
||||
}
|
|
@ -25,20 +25,25 @@ import org.bukkit.plugin.PluginDescriptionFile;
|
|||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import de.jaschastarke.minecraft.integration.Communicator;
|
||||
import de.jaschastarke.minecraft.limitedcreative.listeners.LimitListener;
|
||||
import de.jaschastarke.minecraft.limitedcreative.listeners.MainListener;
|
||||
import de.jaschastarke.minecraft.limitedcreative.prot.LimitListener;
|
||||
import de.jaschastarke.minecraft.limitedcreative.regions.WorldGuardIntegration;
|
||||
import de.jaschastarke.minecraft.limitedcreative.sepinv.MainListener;
|
||||
import de.jaschastarke.minecraft.limitedcreative.utils.NoBlockItemSpawn;
|
||||
import de.jaschastarke.minecraft.utils.Locale;
|
||||
import de.jaschastarke.minecraft.utils.Permissions;
|
||||
|
||||
|
||||
public class Core extends JavaPlugin {
|
||||
public static Core plugin;
|
||||
public final Logger logger = Logger.getLogger("Minecraft");
|
||||
public Configuration config;
|
||||
|
||||
|
||||
public Permissions perm;
|
||||
public WorldGuardIntegration worldguard;
|
||||
public Communicator com;
|
||||
public static Core plugin;
|
||||
|
||||
/* Utils */
|
||||
public Configuration config;
|
||||
public NoBlockItemSpawn spawnblock;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.prot;
|
||||
|
||||
import de.jaschastarke.minecraft.lib.Module;
|
||||
|
||||
public class InventorySeparation extends Module {
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "inventory_separation";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,225 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.limitedcreative.prot;
|
||||
|
||||
import static de.jaschastarke.minecraft.utils.Locale.L;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.StorageMinecart;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.EntityTargetEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.material.Button;
|
||||
import org.bukkit.material.Lever;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.BlackList;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Core;
|
||||
import de.jaschastarke.minecraft.limitedcreative.LCPlayer;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Perms;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Players;
|
||||
import de.jaschastarke.minecraft.limitedcreative.sepinv.MainListener;
|
||||
|
||||
public class LimitListener implements Listener {
|
||||
private Core plugin;
|
||||
public LimitListener(Core plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
Players.get(event.getPlayer()).onDropItem(event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
|
||||
Players.get(event.getPlayer()).onPickupItem(event);
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.LOWEST)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (MainListener.isCancelled(event) || event.getPlayer().getGameMode() != GameMode.CREATIVE)
|
||||
return;
|
||||
|
||||
LCPlayer player = Players.get(event.getPlayer());
|
||||
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission(Perms.NoLimit.USE)) {
|
||||
if (event.getItem() != null && BlackList.isBlackListed(plugin.config.getBlockedUse(), event.getItem())) {
|
||||
event.setCancelled(true);
|
||||
event.setUseItemInHand(Event.Result.DENY);
|
||||
event.getPlayer().sendMessage(L("blocked.use"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
||||
return;
|
||||
|
||||
Block block = event.getClickedBlock();
|
||||
|
||||
if (block.getState() instanceof InventoryHolder || block.getType() == Material.ENDER_CHEST) { // Workaround, Bukkit not recognize a Enderchest
|
||||
player.onChestAccess(event);
|
||||
} else if (block.getState() instanceof Sign) {
|
||||
player.onSignAccess(event);
|
||||
} else if (block.getState() instanceof Lever || block.getState() instanceof Button) {
|
||||
player.onButtonAccess(event);
|
||||
} else if (block.getType() == Material.WORKBENCH) {
|
||||
player.onBenchAccess(event);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.LOWEST)
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
if (event.isCancelled() || event.getPlayer().getGameMode() != GameMode.CREATIVE)
|
||||
return;
|
||||
|
||||
LCPlayer player = Players.get(event.getPlayer());
|
||||
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission(Perms.NoLimit.USE)) {
|
||||
if (event.getPlayer().getItemInHand() != null && BlackList.isBlackListed(plugin.config.getBlockedUse(), event.getPlayer().getItemInHand())) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(L("blocked.use"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Entity entity = event.getRightClicked();
|
||||
|
||||
if (entity instanceof StorageMinecart) {
|
||||
player.onChestAccess(event);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
if (event instanceof EntityDamageByEntityEvent)
|
||||
onEntityDamageByEntity((EntityDamageByEntityEvent) event);
|
||||
}
|
||||
|
||||
/*
|
||||
* Registering to that event works, but causes a SEVERE:
|
||||
* Plugin attempted to register delegated event class class org.bukkit.event.entity.EntityDamageByEntityEvent.
|
||||
* It should be using class org.bukkit.event.entity.EntityDamageEvent!
|
||||
*/
|
||||
protected void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
Entity source = event.getDamager();
|
||||
if (source instanceof Projectile)
|
||||
source = ((Projectile) source).getShooter();
|
||||
|
||||
if (event.getEntity() instanceof Player) {
|
||||
Players.get((Player) event.getEntity()).onDamage(source, event);
|
||||
}
|
||||
if (!event.isCancelled() && source instanceof Player) {
|
||||
Players.get((Player) source).onDealDamage(event);
|
||||
}
|
||||
}
|
||||
@EventHandler
|
||||
public void onEntityTarget(EntityTargetEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
if (event.getTarget() instanceof Player) {
|
||||
Players.get((Player) event.getTarget()).onTarget(event);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.LOW)
|
||||
public void onEntityDeath(EntityDeathEvent event) {
|
||||
if (event.getEntity() instanceof Player) {
|
||||
Player player = (Player) event.getEntity();
|
||||
Players.get(player).onDie(event);
|
||||
}
|
||||
}
|
||||
/*@EventHandler
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
Players.get(event.getPlayer()).onRespawn(event);
|
||||
}*/
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||
LCPlayer player = Players.get(event.getPlayer());
|
||||
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission(Perms.NoLimit.BREAK)) {
|
||||
if (BlackList.isBlackListed(plugin.config.getBlockedBreaks(), event.getBlock())) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(L("blocked.break"));
|
||||
}
|
||||
}
|
||||
|
||||
if (plugin.config.getPermissionsEnabled() && player.hasPermission(Perms.NoLimit.DROP))
|
||||
return;
|
||||
// Prevent dropping of doors and beds when destroying the wrong part
|
||||
Block block = event.getBlock();
|
||||
Material mat = block.getType();
|
||||
switch (event.getBlock().getType()) {
|
||||
case WOODEN_DOOR:
|
||||
mat = Material.WOOD_DOOR;
|
||||
plugin.spawnblock.block(block.getRelative(BlockFace.DOWN).getLocation(), mat);
|
||||
break;
|
||||
case IRON_DOOR_BLOCK:
|
||||
mat = Material.IRON_DOOR;
|
||||
plugin.spawnblock.block(block.getRelative(BlockFace.DOWN).getLocation(), mat);
|
||||
break;
|
||||
case BED_BLOCK:
|
||||
mat = Material.BED;
|
||||
plugin.spawnblock.block(block.getRelative(BlockFace.NORTH).getLocation(), mat);
|
||||
plugin.spawnblock.block(block.getRelative(BlockFace.EAST).getLocation(), mat);
|
||||
plugin.spawnblock.block(block.getRelative(BlockFace.SOUTH).getLocation(), mat);
|
||||
plugin.spawnblock.block(block.getRelative(BlockFace.WEST).getLocation(), mat);
|
||||
break;
|
||||
default:
|
||||
plugin.spawnblock.block(event.getBlock().getLocation(), mat);
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||
LCPlayer player = Players.get(event.getPlayer());
|
||||
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission(Perms.NoLimit.USE)) {
|
||||
if (BlackList.isBlackListed(plugin.config.getBlockedUse(), event.getBlock())) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(L("blocked.place"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.limitedcreative.sepinv;
|
||||
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.Core;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Players;
|
||||
|
||||
public class MainListener implements Listener {
|
||||
private Core plugin;
|
||||
public MainListener(Core plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* The isCancelled in PlayerInteractEvent doesn't check useItemInHand, even this decides (when clicking on
|
||||
* entity with e.g. a bucket)
|
||||
* @param event
|
||||
* @return The relevant "isCancelled"
|
||||
*/
|
||||
public static boolean isCancelled(PlayerInteractEvent event) {
|
||||
return event.useInteractedBlock() == Event.Result.DENY && event.useItemInHand() == Event.Result.DENY;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
|
||||
if (Core.isDebug()) {
|
||||
Core.debug("onPlayerGameModeChange: "+event.getPlayer().getName());
|
||||
Core.debug("Current GameMode: "+event.getPlayer().getGameMode());
|
||||
Core.debug("New GameMode: "+event.getNewGameMode());
|
||||
Core.debug("isLoggedin: "+plugin.com.isLoggedIn(event.getPlayer()));
|
||||
Core.debug("isCancelled: "+event.isCancelled());
|
||||
}
|
||||
if (!plugin.com.isLoggedIn(event.getPlayer()))
|
||||
return;
|
||||
|
||||
if (!Players.get(event.getPlayer()).onSetGameMode(event.getNewGameMode()))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@EventHandler
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
Players.get(event.getPlayer()).onRevive();
|
||||
}
|
||||
|
||||
/**
|
||||
* Also needed if WorldGuard-Feature is enabled, so can not moved to optional Listener "Limit".
|
||||
*/
|
||||
@EventHandler
|
||||
public void onItemSpawn(ItemSpawnEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
if (event.getEntity() instanceof Item) {
|
||||
if (plugin.spawnblock.isBlocked(event.getLocation().getBlock().getLocation(), ((Item) event.getEntity()).getItemStack().getType())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onLogout(PlayerQuitEvent event) {
|
||||
// what? i can't cancel a logout event? but how to chain the user to the server than? xD
|
||||
Players.remove(event.getPlayer().getName());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.limitedcreative.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.LCPlayer;
|
||||
|
||||
|
||||
/**
|
||||
* The "Block" means a Minecraft-Block, not "blocking". So this Class is used to prevent ItemSpawn which are Drops from
|
||||
* specified Blocks.
|
||||
*/
|
||||
public class NoBlockItemSpawn {
|
||||
public final static long TIME_OFFSET = 250;
|
||||
|
||||
private List<BlockItemDrop> list = new ArrayList<BlockItemDrop>();
|
||||
|
||||
public boolean isBlocked(Location l, Material type) {
|
||||
cleanup();
|
||||
for (BlockItemDrop block : list) {
|
||||
if (block.getLocation().equals(l) && block.getType().equals(type))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private void cleanup() {
|
||||
Iterator<BlockItemDrop> i = list.iterator();
|
||||
while (i.hasNext()) {
|
||||
BlockItemDrop block = i.next();
|
||||
if (block.getTimestamp() < System.currentTimeMillis() - TIME_OFFSET)
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
|
||||
private class BlockItemDrop {
|
||||
public BlockItemDrop(Location l, Material type) {
|
||||
this.l = l;
|
||||
this.type = type;
|
||||
this.timestamp = System.currentTimeMillis();
|
||||
}
|
||||
private Location l;
|
||||
private Material type;
|
||||
private long timestamp;
|
||||
public Location getLocation() {
|
||||
return l;
|
||||
}
|
||||
public Material getType() {
|
||||
return type;
|
||||
}
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
public void block(Block block, LCPlayer player) {
|
||||
if (player.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
|
||||
block(block.getLocation(), block.getType());
|
||||
} else {
|
||||
// doesn't include silktouch
|
||||
for (ItemStack i : block.getDrops(player.getPlayer().getItemInHand())) {
|
||||
block(block.getLocation(), i.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void block(Block block) {
|
||||
block(block, null);
|
||||
}
|
||||
public void block(Location l, Material type) {
|
||||
list.add(new BlockItemDrop(l, type));
|
||||
}
|
||||
}
|
5
src/de/jaschastarke/minecraft/utils/Configuration.java
Normal file
5
src/de/jaschastarke/minecraft/utils/Configuration.java
Normal file
|
@ -0,0 +1,5 @@
|
|||
package de.jaschastarke.minecraft.utils;
|
||||
|
||||
public class Configuration {
|
||||
|
||||
}
|
Loading…
Reference in a new issue