Added gameplay.block-potions.

This commit is contained in:
sk89q 2012-11-04 13:42:55 -08:00
parent 1bdd7f9a6b
commit fede549b51
2 changed files with 32 additions and 1 deletions

View File

@ -31,6 +31,7 @@
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
import java.io.File;
import java.io.FileNotFoundException;
@ -74,6 +75,7 @@ public class WorldConfiguration {
public boolean simulateSponge;
public int spongeRadius;
public boolean disableExpDrops;
public Set<PotionEffectType> blockPotions;
public boolean pumpkinScuba;
public boolean redstoneSponges;
public boolean noPhysicsGravel;
@ -288,6 +290,17 @@ private void loadConfiguration() {
disableExpDrops = getBoolean("protection.disable-xp-orb-drops", false);
disableObsidianGenerators = getBoolean("protection.disable-obsidian-generators", false);
blockPotions = new HashSet<PotionEffectType>();
for (String potionName : getStringList("gameplay.block-potions", null)) {
PotionEffectType effect = PotionEffectType.getByName(potionName);
if (effect == null) {
plugin.getLogger().warning("Unknown potion effect type '" + potionName + "'");
} else {
blockPotions.add(effect);
}
}
simulateSponge = getBoolean("simulation.sponge.enable", true);
spongeRadius = Math.max(1, getInt("simulation.sponge.radius", 3)) - 1;
redstoneSponges = getBoolean("simulation.sponge.redstone", false);

View File

@ -27,6 +27,7 @@
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
@ -54,7 +55,8 @@
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.PluginManager;
import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionEffect;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldguard.LocalPlayer;
@ -420,6 +422,22 @@ public void onPlayerInteract(PlayerInteractEvent event) {
player.sendMessage(ChatColor.RED + "Infinite stack removed.");
}
}
if (wcfg.blockPotions.size() > 0
&& !plugin.hasPermission(player, "worldguard.override.potions")) {
ItemStack item = event.getItem();
if (item.getType() == Material.POTION) {
Potion potion = Potion.fromItemStack(item);
for (PotionEffect effect : potion.getEffects()) {
if (wcfg.blockPotions.contains(effect.getType())) {
player.sendMessage(ChatColor.RED + "Sorry, potions with "
+ effect.getType().getName() + " are presently disabled.");
event.setUseItemInHand(Result.DENY);
break;
}
}
}
}
}
/**