Release 2.1

- Prevent Drops of Killed Mobs
 - Prevent Minecart-Drops (when TrainCarts is installed)
This commit is contained in:
Jascha Starke 2013-10-13 23:04:57 +02:00
parent 8e3b771d61
commit 65a50d30c0
7 changed files with 112 additions and 18 deletions

View file

@ -3,12 +3,12 @@
<groupId>de.jaschastarke</groupId> <groupId>de.jaschastarke</groupId>
<artifactId>LimitedCreative</artifactId> <artifactId>LimitedCreative</artifactId>
<name>LimitedCreative</name> <name>LimitedCreative</name>
<version>2.1-SNAPSHOT</version> <version>2.1</version>
<url>https://github.com/possi/LimitedCreative</url> <url>https://github.com/possi/LimitedCreative</url>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<plib.version>1.3-SNAPSHOT</plib.version> <plib.version>1.3</plib.version>
</properties> </properties>
<scm> <scm>

View file

@ -1,21 +1,19 @@
package de.jaschastarke.minecraft.limitedcreative; package de.jaschastarke.minecraft.limitedcreative;
import java.util.WeakHashMap;
import org.bukkit.entity.Entity;
import de.jaschastarke.bukkit.lib.CoreModule; import de.jaschastarke.bukkit.lib.CoreModule;
import de.jaschastarke.bukkit.lib.modules.AdditionalBlockBreaks; import de.jaschastarke.bukkit.lib.modules.AdditionalBlockBreaks;
import de.jaschastarke.minecraft.limitedcreative.limits.BlockListener; import de.jaschastarke.minecraft.limitedcreative.limits.BlockListener;
import de.jaschastarke.minecraft.limitedcreative.limits.EntityListener; import de.jaschastarke.minecraft.limitedcreative.limits.EntityListener;
import de.jaschastarke.minecraft.limitedcreative.limits.EntityNoDrop;
import de.jaschastarke.minecraft.limitedcreative.limits.LimitConfig; import de.jaschastarke.minecraft.limitedcreative.limits.LimitConfig;
import de.jaschastarke.minecraft.limitedcreative.limits.PlayerListener; import de.jaschastarke.minecraft.limitedcreative.limits.PlayerListener;
import de.jaschastarke.minecraft.limitedcreative.limits.VehicleListener;
import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.IModule;
import de.jaschastarke.modularize.ModuleEntry; import de.jaschastarke.modularize.ModuleEntry;
public class ModCreativeLimits extends CoreModule<LimitedCreative> { public class ModCreativeLimits extends CoreModule<LimitedCreative> {
protected LimitConfig config; protected LimitConfig config;
private WeakHashMap<Entity, Void> no_xp_mobs = new WeakHashMap<Entity, Void>(); private EntityNoDrop noDropsMobs = null;
public ModCreativeLimits(LimitedCreative plugin) { public ModCreativeLimits(LimitedCreative plugin) {
super(plugin); super(plugin);
@ -34,6 +32,7 @@ public class ModCreativeLimits extends CoreModule<LimitedCreative> {
listeners.addListener(new PlayerListener(this)); listeners.addListener(new PlayerListener(this));
listeners.addListener(new EntityListener(this)); listeners.addListener(new EntityListener(this));
listeners.addListener(new BlockListener(this)); listeners.addListener(new BlockListener(this));
listeners.addListener(new VehicleListener(this));
config = plugin.getPluginConfig().registerSection(new LimitConfig(this, entry)); config = plugin.getPluginConfig().registerSection(new LimitConfig(this, entry));
blockDrops = modules.linkSharedModule(FeatureBlockItemSpawn.class, plugin.getModules()); blockDrops = modules.linkSharedModule(FeatureBlockItemSpawn.class, plugin.getModules());
@ -54,8 +53,10 @@ public class ModCreativeLimits extends CoreModule<LimitedCreative> {
return config; return config;
} }
public WeakHashMap<Entity, Void> getNoXPMobs() { public EntityNoDrop getNoDropMobs() {
return no_xp_mobs; if (noDropsMobs == null)
noDropsMobs = new EntityNoDrop();
return noDropsMobs;
} }
} }

View file

@ -70,10 +70,10 @@ public class BlockStateConfig extends Configuration implements IConfigurationSub
/** /**
* BlockStateEnabled * BlockStateEnabled
* *
* This experimental Feature stores the GameMode a Block was created in, and prevents drops if a Block was created * This Feature stores the GameMode a Block was created in, and prevents drops if a Block was created
* in creative mode. * in creative mode.
* *
* Due to the Experimental state this Feature isn't enabled by default. It uses the Database-credentials from * Due to the huge load of this Feature, it isn't enabled by default. It uses the Database-credentials from
* bukkit.yml (http://wiki.bukkit.org/Bukkit.yml#database) in the server-directory. * bukkit.yml (http://wiki.bukkit.org/Bukkit.yml#database) in the server-directory.
* *
* default: false * default: false
@ -86,9 +86,9 @@ public class BlockStateConfig extends Configuration implements IConfigurationSub
/** /**
* BlockStateThreading * BlockStateThreading
* *
* This experimental variant of the experimental Feature uses Threading to minimize lag. This fully relies on * Uses Threading to minimize lag. This fully relies on Bukkit metadata implementation. You only should need this,
* Bukkit metadata implementation. You only should need this, if there are often plays more then 10 players at once * if there are often plays more then 10 players at once on your server. Be aware that this requires more memory,
* on your server. Be aware that this requires more memory. * to increase the performance
* *
* default: false * default: false
*/ */

View file

@ -54,11 +54,15 @@ public class EntityListener implements Listener {
@EventHandler @EventHandler
public void onEntityDeath(EntityDeathEvent event) { public void onEntityDeath(EntityDeathEvent event) {
if (event.getEntity() instanceof LivingEntity && event.getDroppedExp() > 0) { if (event.getEntity() instanceof LivingEntity && event.getDroppedExp() > 0) {
if (mod.getNoXPMobs().containsKey(event.getEntity())) { if (mod.getNoDropMobs().isXPPrevented(event.getEntity())) {
event.setDroppedExp(0); event.setDroppedExp(0);
mod.getNoXPMobs().remove(event.getEntity()); event.getDrops().clear();
} }
} }
if (event.getDrops().size() > 0 && mod.getNoDropMobs().isDropPrevented(event.getEntity())) {
event.getDrops().clear();
}
mod.getNoDropMobs().remove(event.getEntity());
} }
private boolean checkPermission(Player player, IAbstractPermission perm) { private boolean checkPermission(Player player, IAbstractPermission perm) {

View file

@ -0,0 +1,37 @@
package de.jaschastarke.minecraft.limitedcreative.limits;
import java.util.Map;
import java.util.WeakHashMap;
import org.bukkit.entity.Entity;
public class EntityNoDrop {
private Map<Entity, Prevent> nodrop = new WeakHashMap<Entity, Prevent>();
private Prevent get(Entity entity) {
if (!nodrop.containsKey(entity))
nodrop.put(entity, new Prevent());
return nodrop.get(entity);
}
public void preventXP(Entity entity) {
get(entity).xp = true;
}
public void preventDrop(Entity entity) {
get(entity).drops = true;
}
public boolean isXPPrevented(Entity entity) {
return nodrop.containsKey(entity) && nodrop.get(entity).xp;
}
public boolean isDropPrevented(Entity entity) {
return nodrop.containsKey(entity) && nodrop.get(entity).drops;
}
public void remove(Entity entity) {
nodrop.remove(entity);
}
private class Prevent {
boolean xp = false;
boolean drops = false;
}
}

View file

@ -218,7 +218,7 @@ public class PlayerListener implements Listener {
} }
} }
@EventHandler @EventHandler(ignoreCancelled = true)
public void onEntityDamageByEntity(EntityDamageEvent rawevent) { public void onEntityDamageByEntity(EntityDamageEvent rawevent) {
if (rawevent instanceof EntityDamageByEntityEvent && !rawevent.isCancelled()) { if (rawevent instanceof EntityDamageByEntityEvent && !rawevent.isCancelled()) {
EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) rawevent; EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) rawevent;
@ -240,7 +240,12 @@ public class PlayerListener implements Listener {
} }
} else if (event.getEntity() instanceof LivingEntity) { } else if (event.getEntity() instanceof LivingEntity) {
if (!checkPermission(player, NoLimitPermissions.STATS_XP)) { if (!checkPermission(player, NoLimitPermissions.STATS_XP)) {
mod.getNoXPMobs().put(event.getEntity(), null); mod.getNoDropMobs().preventXP(event.getEntity());
}
}
if (!event.isCancelled()) {
if (!checkPermission(player, NoLimitPermissions.DROP)) {
mod.getNoDropMobs().preventDrop(event.getEntity());
} }
} }
} }

View file

@ -0,0 +1,47 @@
package de.jaschastarke.minecraft.limitedcreative.limits;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.vehicle.VehicleDestroyEvent;
import de.jaschastarke.minecraft.limitedcreative.ModCreativeLimits;
public class VehicleListener implements Listener {
private ModCreativeLimits mod;
public VehicleListener(ModCreativeLimits mod) {
this.mod = mod;
}
@EventHandler(ignoreCancelled = true)
public void onVehicleDestroy(VehicleDestroyEvent event) {
if (event.getAttacker() instanceof Player) {
Player player = (Player) event.getAttacker();
if (player.getGameMode() == GameMode.CREATIVE && !mod.getPlugin().getPermManager().hasPermission(player, NoLimitPermissions.DROP)) {
switch (event.getVehicle().getType()) {
case MINECART:
mod.getBlockSpawn().block(event.getVehicle().getLocation().getBlock().getLocation(), Material.MINECART);
break;
case MINECART_CHEST:
mod.getBlockSpawn().block(event.getVehicle().getLocation().getBlock().getLocation(), Material.STORAGE_MINECART);
break;
case MINECART_FURNACE:
mod.getBlockSpawn().block(event.getVehicle().getLocation().getBlock().getLocation(), Material.POWERED_MINECART);
break;
case MINECART_HOPPER:
mod.getBlockSpawn().block(event.getVehicle().getLocation().getBlock().getLocation(), Material.HOPPER_MINECART);
break;
case MINECART_TNT:
mod.getBlockSpawn().block(event.getVehicle().getLocation().getBlock().getLocation(), Material.EXPLOSIVE_MINECART);
break;
default:
break;
}
}
}
}
}