- blocking pistons region bypass
 - reworked config/blacklist and configuration commands
 - added optional feature: prevent dealing damage to creatures
 - added optional feautre: prevent usage of buttons/levers
 - added possibility to blacklist items with spec. data
 - * supporting monster_eggs
This commit is contained in:
Jascha Starke 2012-02-03 22:47:56 +01:00
parent 700d8f54c1
commit 147e453299
10 changed files with 316 additions and 117 deletions

View file

@ -62,12 +62,25 @@ limit:
# default: true # default: true
sign: true sign: true
# BlockButtons
# When enabled also blocks usage of Buttons & Levers while in creative mode.
# default: false
button: false
# BlockDamageToMobs
# Prevents dealing damage to all creatures in creative (friendly sheeps as well as hostile creepers).
# default: false
damagemob: false
# UseBlackList # UseBlackList
# Prevents using or placing of the given blocks in creative mode (and only in creative). # 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/d7/dd9/namespaceorg_1_1bukkit.html#ab7fa290bb19b9a830362aa88028ec80a)
# or the id of the block/item (better use the id, if you're not sure). # 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 # To prevent Lava you need to add "LAVA_BUCKET", because lava-blocks aren't "placed", therefore Lava-Buckets are
# "used". # "used".
# You may add the data separated with a colon e.g.: "35:11" blocks blue wool. But be sure to put it in quotes, to
# not break yml-configuration! Also supporting Eggs (e.g: "MONSTER_EGG:56" blocks Ghasts-Eggs). Named data values aren't
# supported yet.
# This option can only changed by reloading the plugin (not via ingame commands). # This option can only changed by reloading the plugin (not via ingame commands).
# default: [] # default: []
use: [] use: []
@ -77,6 +90,9 @@ limit:
# 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/d7/dd9/namespaceorg_1_1bukkit.html#ab7fa290bb19b9a830362aa88028ec80a)
# or the id of the block/item (better use the id, if you're not sure). # or the id of the block/item (better use the id, if you're not sure).
# This option can only changed by reloading the plugin (not via ingame commands). # This option can only changed by reloading the plugin (not via ingame commands).
# You may add the data separated with a colon e.g.: "WOOL:11" blocks blue wool. But be sure to put it in quotes, to
# not break yml-configuration!
# supported yet.
# default: [bedrock] # default: [bedrock]
break: break:
- bedrock - bedrock

View file

@ -9,7 +9,7 @@ basic:
conflict: Due to conflict with the plugin {0}, the feature {1} is disabled conflict: Due to conflict with the plugin {0}, the feature {1} is disabled
warning: warning:
worldguard_not_found: WorldGuard isn''t found, the feature {0} is disabled worldguard_not_found: WorldGuard isn''t found, the feature {0} is disabled
# double single-quote '' because of MessageFormater to insert {0} # double single-quote '' because of MessageFormater to insert {0}
command: command:
player: player player: player
switch: switch:
@ -17,10 +17,7 @@ command:
creative: Changes the game mode of a player to creative creative: Changes the game mode of a player to creative
config: config:
overview: "[setting] - empty for list of settings" overview: "[setting] - empty for list of settings"
settings: settings: "Available Settings: "
- "Available Settings: storecreative,"
- "removedrop, removepickup, blockpickup, blocksign,"
- "permissions, perm_keepinventory"
reload: Reloads plugin (doesn't work on update!) reload: Reloads plugin (doesn't work on update!)
gamemode: gamemode:
changed: "{0}'s game mode has been changed" changed: "{0}'s game mode has been changed"
@ -54,9 +51,13 @@ exception:
blocked: blocked:
chest: Access to chests is not allowed in creative mode chest: Access to chests is not allowed in creative mode
sign: To interact with signs is not allowed in creative mode sign: To interact with signs is not allowed in creative mode
button: To interact with buttons is not allowed in creative mode
lever: To interact with levers is not allowed in creative mode
survival_flying: You should stay on ground, when leaving a creative-area survival_flying: You should stay on ground, when leaving a creative-area
outside_creative: You can not place blocks outside of the creative-area outside_creative: You can not place blocks outside of the creative-area
outside_creative_break: You can not destroy blocks outside of the creative-area outside_creative_break: You can not destroy blocks outside of the creative-area
use: You are not allowed to use this type of item use: You are not allowed to use this type of item
place: You are not allowed to place this type of block place: You are not allowed to place this type of block
break: You are not allowed to break this type of block break: You are not allowed to break this type of block
piston: Moving {0} block out of creative area was blocked at {1}
piston_in: Moving {0} block into creative area was blocked at {1}

View file

@ -1,6 +1,6 @@
name: LimitedCreative name: LimitedCreative
main: de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore main: de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore
version: 0.8.2-beta version: 0.9-beta
softdepend: [WorldGuard, WorldEdit, MultiInv] softdepend: [WorldGuard, WorldEdit, MultiInv]
dev-url: http://dev.bukkit.org/server-mods/limited-creative/ dev-url: http://dev.bukkit.org/server-mods/limited-creative/
commands: commands:
@ -43,9 +43,18 @@ permissions:
limitedcreative.nolimit.sign: limitedcreative.nolimit.sign:
description: Allows bypassing the "do not interact with signs"-limitation description: Allows bypassing the "do not interact with signs"-limitation
default: false default: false
limitedcreative.nolimit.button:
description: Allows bypassing the "do not interact with buttons"-limitation
default: false
limitedcreative.nolimit.lever:
description: Allows bypassing the "do not interact with levers"-limitation
default: false
limitedcreative.nolimit.pvp: limitedcreative.nolimit.pvp:
description: Allows bypassing the "no pvp"-limitation description: Allows bypassing the "no pvp"-limitation
default: false default: false
limitedcreative.nolimit.mob_damage:
description: Allows bypassing the "no dealing damage to creatures"-limitation
default: false
limitedcreative.nolimit.use: limitedcreative.nolimit.use:
description: Allows bypassing the "block place/item use"-limitation description: Allows bypassing the "block place/item use"-limitation
default: false default: false

View file

@ -0,0 +1,55 @@
package de.jaschastarke.minecraft.limitedcreative;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
public class BlackList {
private Material mat;
private int data = -1;
public BlackList(Material material, int data) {
mat = material;
this.data = data;
}
public BlackList(Material material) {
mat = material;
}
public boolean matches(Block block) {
if (this.mat != block.getType())
return false;
if (this.data != -1 && this.data != block.getData())
return false;
return true;
}
public boolean matches(ItemStack item) {
if (this.mat != item.getType())
return false;
if (this.data != -1) {
if (this.mat == Material.MONSTER_EGG) {
if (this.data != item.getDurability())
return false;
} else {
if (this.data != item.getData().getData())
return false;
}
}
return true;
}
public static boolean isBlackListed(List<BlackList> list, Block block) {
for (BlackList bl : list) {
if (bl.matches(block))
return true;
}
return false;
}
public static boolean isBlackListed(List<BlackList> list, ItemStack item) {
for (BlackList bl : list) {
if (bl.matches(item))
return true;
}
return false;
}
}

View file

@ -18,6 +18,7 @@
package de.jaschastarke.minecraft.limitedcreative; package de.jaschastarke.minecraft.limitedcreative;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -108,18 +109,6 @@ public class Commands {
} }
return false; return false;
} }
public enum Option {
STORECREATIVE,
BLOCKPICKUP,
BLOCKSIGN,
PERMISSIONS,
PERM_KEEPINVENTORY,
REMOVEDROP,
REMOVEPICKUP,
DEBUG,
};
private void setOption(CommandSender sender, String[] args, boolean b) throws CommandException { private void setOption(CommandSender sender, String[] args, boolean b) throws CommandException {
if (sender instanceof Player && !plugin.perm.hasPermission(sender, "limitedcreative.config")) { if (sender instanceof Player && !plugin.perm.hasPermission(sender, "limitedcreative.config")) {
@ -128,44 +117,30 @@ public class Commands {
if (args.length > 2) if (args.length > 2)
throw new InvalidCommandException("exception.command.tomuchparameter"); throw new InvalidCommandException("exception.command.tomuchparameter");
if (args.length < 2) { if (args.length < 2) {
for (String l : L("command.config.settings").split("\n")) StringBuilder str = new StringBuilder(L("command.config.settings"));
sender.sendMessage(l); List<Configuration.Option> options = Configuration.Option.getAvailableOptions();
for (int i = 0; i < options.size(); i++) {
str.append(options.get(i).name().toLowerCase());
if (i < options.size() - 1)
str.append(", ");
if ((i - 1) % 5 == 0) {
sender.sendMessage(str.toString());
str = new StringBuilder();
}
}
if (str.length() > 0)
sender.sendMessage(str.toString());
return; return;
} }
Option opt = null; Configuration.Option opt = null;
try { try {
opt = Option.valueOf(args[1].toUpperCase()); opt = Configuration.Option.valueOf(args[1].toUpperCase());
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
throw new InvalidCommandException("exception.command.invalidoption"); throw new InvalidCommandException("exception.command.invalidoption");
} }
switch (opt) { plugin.config.set(opt, b);
case STORECREATIVE:
plugin.config.setStoreCreative(b);
break;
case BLOCKPICKUP:
plugin.config.setBlockPickupInCreative(b);
break;
case BLOCKSIGN:
plugin.config.setSignBlock(b);
break;
case PERMISSIONS:
plugin.config.setPermissionsEnabled(b);
break;
case PERM_KEEPINVENTORY:
plugin.config.setPermissionToKeepInventory(b);
break;
case REMOVEDROP:
plugin.config.setRemoveDrop(b);
break;
case REMOVEPICKUP:
plugin.config.setRemovePickup(b);
break;
case DEBUG:
plugin.config.setDebug(b);
break;
}
sender.sendMessage(L("command.option.done")); sender.sendMessage(L("command.option.done"));
} }

View file

@ -19,6 +19,7 @@ package de.jaschastarke.minecraft.limitedcreative;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import org.bukkit.Material; import org.bukkit.Material;
@ -32,6 +33,38 @@ public class Configuration {
private File file; private File file;
public static LimitedCreativeCore plugin; public static LimitedCreativeCore plugin;
public enum Option {
STORECREATIVE("store.creative", true),
REGION_OPTIONAL("region.optional", true),
BLOCKPICKUP("limit.pickup", true),
BLOCKSIGN("limit.sign", true),
BLOCKBUTTON("limit.button", false),
BLOCKDAMAGEMOB("limit.damagemob", false),
REMOVEDROP("limit.remove_drops", true),
REMOVEPICKUP("limit.remove_pickup", false),
PERMISSIONS("permissions.enabled", false),
PERM_KEEPINVENTORY("permissions.keepinventory", false),
DEBUG("debug", false);
private String key;
private boolean _default;
private Option(String key, boolean def) {
this.key = key;
this._default = def;
}
public String getKey() {
return key;
}
public boolean getDefault() {
return _default;
}
public static List<Option> getAvailableOptions() {
List<Option> ret = new ArrayList<Option>(Arrays.asList(Option.values()));
ret.remove(Option.DEBUG); // keep it undocumented ;)
return ret;
}
}
public Configuration(LimitedCreativeCore pplugin) { public Configuration(LimitedCreativeCore pplugin) {
plugin = pplugin; plugin = pplugin;
@ -42,12 +75,26 @@ public class Configuration {
c = plugin.getConfig(); c = plugin.getConfig();
} }
public void set(Option opt, boolean value) {
/*if (!opt.isSetAble())
throw new IllegalArgumentException("Setting this option is not allowed");*/
this.reload();
c.set(opt.getKey(), value);
if (value && opt == Option.PERM_KEEPINVENTORY && !this.getPermissionsEnabled())
c.set(Option.PERMISSIONS.getKey(), true);
this.save();
}
public boolean getBoolean(Option opt) {
return c.getBoolean(opt.getKey(), opt.getDefault());
}
/** /**
* Intended to be undocumented ;) * Intended to be undocumented ;)
*/ */
public boolean getDebug() { public boolean getDebug() {
return c.getBoolean("debug", false); return this.getBoolean(Option.DEBUG);
} }
public boolean getStoreEnabled() { public boolean getStoreEnabled() {
@ -61,7 +108,7 @@ public class Configuration {
} }
public boolean getStoreCreative() { public boolean getStoreCreative() {
return c.getBoolean("store.creative", true); return this.getBoolean(Option.STORECREATIVE);
} }
public boolean getUnsafeStorage() { public boolean getUnsafeStorage() {
return c.getBoolean("store.unsafe", false); return c.getBoolean("store.unsafe", false);
@ -70,72 +117,35 @@ public class Configuration {
return c.getString("store.folder", "inventories"); return c.getString("store.folder", "inventories");
} }
public boolean getBlockPickupInCreative() { public boolean getBlockPickupInCreative() {
return c.getBoolean("limit.pickup", true); return this.getBoolean(Option.BLOCKPICKUP);
} }
public boolean getSignBlock() { public boolean getSignBlock() {
return c.getBoolean("limit.sign", true); return this.getBoolean(Option.BLOCKSIGN);
}
public boolean getButtonBlock() {
return this.getBoolean(Option.BLOCKBUTTON);
} }
public boolean getRemoveDrop() { public boolean getRemoveDrop() {
return c.getBoolean("limit.remove_drops", true); return this.getBoolean(Option.REMOVEDROP);
} }
public boolean getRemovePickup() { public boolean getRemovePickup() {
return c.getBoolean("limit.remove_pickup", false); return this.getBoolean(Option.REMOVEPICKUP);
}
public boolean getMobDamageBlock() {
return this.getBoolean(Option.BLOCKDAMAGEMOB);
} }
public boolean getPermissionsEnabled() { public boolean getPermissionsEnabled() {
return c.getBoolean("permissions.enabled", false); return this.getBoolean(Option.PERMISSIONS);
} }
public boolean getPermissionToKeepInventory() { public boolean getPermissionToKeepInventory() {
return this.getPermissionsEnabled() && c.getBoolean("permissions.keepinventory", false); return this.getPermissionsEnabled() && this.getBoolean(Option.PERM_KEEPINVENTORY);
} }
public boolean getRegionOptional() { public boolean getRegionOptional() {
return c.getBoolean("region.optional", true); return this.getBoolean(Option.REGION_OPTIONAL);
} }
public void setDebug(boolean value) {
this.reload();
c.set("debug", value);
this.save();
}
public void setStoreCreative(boolean value) {
this.reload();
c.set("store.creative", value);
this.save();
}
public void setBlockPickupInCreative(boolean value) {
this.reload();
c.set("limit.pickup", value);
this.save();
}
public void setSignBlock(boolean value) {
this.reload();
c.set("limit.sign", value);
this.save();
}
public void setPermissionsEnabled(boolean value) {
this.reload();
c.set("permissions.enabled", value);
this.save();
}
public void setPermissionToKeepInventory(boolean value) {
this.reload();
if (value == true)
this.setPermissionsEnabled(true);
c.set("permissions.keepinventory", value);
this.save();
}
public void setRemoveDrop(boolean value) {
this.reload();
c.set("limit.remove_drops", value);
this.save();
}
public void setRemovePickup(boolean value) {
this.reload();
c.set("limit.remove_pickup", value);
this.save();
}
protected void reload() { protected void reload() {
_block_break = null; _block_break = null;
_block_use = null; _block_use = null;
@ -146,24 +156,37 @@ public class Configuration {
plugin.saveConfig(); plugin.saveConfig();
} }
private List<Material> _block_break = null; private List<BlackList> _block_break = null;
private List<Material> _block_use = null; private List<BlackList> _block_use = null;
public List<Material> getBlockedBreaks() { public List<BlackList> getBlockedBreaks() {
if (_block_break == null) if (_block_break == null)
_block_break = parseMaterialList(c.getStringList("limit.break")); _block_break = parseMaterialList(c.getStringList("limit.break"));
return _block_break; return _block_break;
} }
public List<Material> getBlockedUse() {
public List<BlackList> getBlockedUse() {
if (_block_use == null) if (_block_use == null)
_block_use = parseMaterialList(c.getStringList("limit.use")); _block_use = parseMaterialList(c.getStringList("limit.use"));
return _block_use; return _block_use;
} }
private List<Material> parseMaterialList(List<String> s) { private List<BlackList> parseMaterialList(List<String> s) {
List<Material> list = new ArrayList<Material>(); List<BlackList> list = new ArrayList<BlackList>();
if (s != null) { if (s != null) {
for (String m : s) { for (String m : s) {
int d = -1;
if (m.contains(":")) {
String[] t = m.split(":");
m = t[0];
try {
d = Integer.parseInt(t[1]);
} catch (NumberFormatException ex) {
// TODO: try to find the data value by
if (d == -1)
plugin.warn(L("exception.config.materiak_data_not_found", t[1]));
}
}
Material e = null; Material e = null;
try { try {
e = Material.getMaterial(Integer.parseInt(m)); e = Material.getMaterial(Integer.parseInt(m));
@ -171,9 +194,9 @@ public class Configuration {
e = Material.matchMaterial(m); e = Material.matchMaterial(m);
} }
if (e == null) { if (e == null) {
plugin.logger.warning("["+plugin.getDescription().getName()+"] "+L("exception.config.material_not_found", m)); plugin.warn(L("exception.config.material_not_found", m));
} else { } else {
list.add(e); list.add(new BlackList(e, d));
} }
} }
} }

View file

@ -30,9 +30,11 @@ import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
@ -40,6 +42,7 @@ import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Lever;
import de.jaschastarke.minecraft.limitedcreative.Commands.LackingPermissionException; import de.jaschastarke.minecraft.limitedcreative.Commands.LackingPermissionException;
import de.jaschastarke.minecraft.limitedcreative.serialize.Items; import de.jaschastarke.minecraft.limitedcreative.serialize.Items;
@ -54,7 +57,7 @@ public class LCPlayer {
private boolean _isPermanentCreative = false; private boolean _isPermanentCreative = false;
private boolean _isRegionCreative = false; private boolean _isRegionCreative = false;
private long _timestamp; private long _timestamp;
public static final long CLEANUP_TIMEOUT = 90000; // 90s * 20ticks public static final long CLEANUP_TIMEOUT = 300000; // 300s = 5m
private static File _store_file = new File(plugin.getDataFolder(), "players.yml"); private static File _store_file = new File(plugin.getDataFolder(), "players.yml");
public static YamlConfiguration store = YamlConfiguration.loadConfiguration(_store_file); public static YamlConfiguration store = YamlConfiguration.loadConfiguration(_store_file);
@ -237,7 +240,7 @@ public class LCPlayer {
tempinv = null; tempinv = null;
} }
public void onDamage(EntityDamageByEntityEvent event) { public void onDamage(EntityDamageByEntityEvent event) { // receives damage
if (event.getDamager() instanceof Player) { if (event.getDamager() instanceof Player) {
// its PVP // its PVP
Player attacker = (Player) event.getDamager(); Player attacker = (Player) event.getDamager();
@ -254,6 +257,29 @@ public class LCPlayer {
} }
} }
} }
public void onDealDamage(EntityDamageByEntityEvent event) { // deals damage
if (event.getEntity() instanceof Creature) {
if (player.getGameMode() == GameMode.CREATIVE && plugin.config.getMobDamageBlock()) {
if (!plugin.config.getPermissionsEnabled() || !hasPermission("limitedcreative.nolimit.mob_damage")) {
event.setCancelled(true);
}
}
}
}
/**
* don't let the player be target by creatures he can't kill
*/
public void onTarget(EntityTargetEvent event) {
if (event.getEntity() instanceof Creature) {
if (player.getGameMode() == GameMode.CREATIVE && plugin.config.getMobDamageBlock()) {
if (!plugin.config.getPermissionsEnabled() || !hasPermission("limitedcreative.nolimit.mob_damage")) {
event.setCancelled(true);
}
}
}
}
public void onChestAccess(PlayerInteractEvent event) { public void onChestAccess(PlayerInteractEvent event) {
if (player.getGameMode() != GameMode.CREATIVE) if (player.getGameMode() != GameMode.CREATIVE)
return; return;
@ -278,6 +304,21 @@ public class LCPlayer {
event.getPlayer().sendMessage(L("blocked.sign")); event.getPlayer().sendMessage(L("blocked.sign"));
event.setCancelled(true); event.setCancelled(true);
} }
public void onButtonAccess(PlayerInteractEvent event) {
if (!plugin.config.getButtonBlock() || player.getGameMode() != GameMode.CREATIVE)
return;
if (event.getClickedBlock().getState() instanceof Lever) {
if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.lever"))
return;
event.getPlayer().sendMessage(L("blocked.lever"));
event.setCancelled(true);
} else {
if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.button"))
return;
event.getPlayer().sendMessage(L("blocked.button"));
event.setCancelled(true);
}
}
private long lastFloatingTimeWarning = 0; private long lastFloatingTimeWarning = 0;

View file

@ -36,12 +36,16 @@ import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.material.Button;
import org.bukkit.material.Lever;
import de.jaschastarke.minecraft.limitedcreative.BlackList;
import de.jaschastarke.minecraft.limitedcreative.LCPlayer; import de.jaschastarke.minecraft.limitedcreative.LCPlayer;
import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore; import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore;
import static de.jaschastarke.minecraft.utils.Locale.L; import static de.jaschastarke.minecraft.utils.Locale.L;
@ -75,7 +79,7 @@ public class LimitListener implements Listener {
LCPlayer player = LCPlayer.get(event.getPlayer()); LCPlayer player = LCPlayer.get(event.getPlayer());
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission("limitedcreative.nolimit.use")) { if (!plugin.config.getPermissionsEnabled() || !player.hasPermission("limitedcreative.nolimit.use")) {
if (event.getItem() != null && plugin.config.getBlockedUse().contains(event.getItem().getType())) { if (event.getItem() != null && BlackList.isBlackListed(plugin.config.getBlockedUse(), event.getItem())) {
event.setCancelled(true); event.setCancelled(true);
event.setUseItemInHand(Event.Result.DENY); event.setUseItemInHand(Event.Result.DENY);
event.getPlayer().sendMessage(L("blocked.use")); event.getPlayer().sendMessage(L("blocked.use"));
@ -90,9 +94,10 @@ public class LimitListener implements Listener {
if (block.getState() instanceof ContainerBlock) { if (block.getState() instanceof ContainerBlock) {
player.onChestAccess(event); player.onChestAccess(event);
} } else if (block.getState() instanceof Sign) {
if (block.getState() instanceof Sign) {
player.onSignAccess(event); player.onSignAccess(event);
} else if (block.getState() instanceof Lever || block.getState() instanceof Button) {
player.onButtonAccess(event);
} }
} }
@ -103,7 +108,7 @@ public class LimitListener implements Listener {
LCPlayer player = LCPlayer.get(event.getPlayer()); LCPlayer player = LCPlayer.get(event.getPlayer());
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission("limitedcreative.nolimit.use")) { if (!plugin.config.getPermissionsEnabled() || !player.hasPermission("limitedcreative.nolimit.use")) {
if (event.getPlayer().getItemInHand() != null && plugin.config.getBlockedUse().contains(event.getPlayer().getItemInHand().getType())) { if (event.getPlayer().getItemInHand() != null && BlackList.isBlackListed(plugin.config.getBlockedUse(), event.getPlayer().getItemInHand())) {
event.setCancelled(true); event.setCancelled(true);
event.getPlayer().sendMessage(L("blocked.use")); event.getPlayer().sendMessage(L("blocked.use"));
return; return;
@ -119,11 +124,24 @@ public class LimitListener implements Listener {
@EventHandler @EventHandler
public void onEntityDamage(EntityDamageEvent meta_event) { public void onEntityDamage(EntityDamageEvent meta_event) {
if (meta_event.isCancelled())
return;
if (meta_event instanceof EntityDamageByEntityEvent) { if (meta_event instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) meta_event; EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) meta_event;
if (event.getEntity() instanceof Player) { if (event.getEntity() instanceof Player) {
LCPlayer.get((Player) event.getEntity()).onDamage(event); LCPlayer.get((Player) event.getEntity()).onDamage(event);
} }
if (!event.isCancelled() && event.getDamager() instanceof Player){
LCPlayer.get((Player) event.getDamager()).onDealDamage(event);
}
}
}
@EventHandler
public void onEntityTarget(EntityTargetEvent event) {
if (event.isCancelled())
return;
if (event.getTarget() instanceof Player) {
LCPlayer.get((Player) event.getTarget()).onTarget(event);
} }
} }
@ -142,7 +160,7 @@ public class LimitListener implements Listener {
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) { if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
LCPlayer player = LCPlayer.get(event.getPlayer()); LCPlayer player = LCPlayer.get(event.getPlayer());
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission("limitedcreative.nolimit.break")) { if (!plugin.config.getPermissionsEnabled() || !player.hasPermission("limitedcreative.nolimit.break")) {
if (plugin.config.getBlockedBreaks().contains(event.getBlock().getType())) { if (BlackList.isBlackListed(plugin.config.getBlockedBreaks(), event.getBlock())) {
event.setCancelled(true); event.setCancelled(true);
event.getPlayer().sendMessage(L("blocked.break")); event.getPlayer().sendMessage(L("blocked.break"));
} }
@ -181,7 +199,7 @@ public class LimitListener implements Listener {
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) { if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
LCPlayer player = LCPlayer.get(event.getPlayer()); LCPlayer player = LCPlayer.get(event.getPlayer());
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission("limitedcreative.nolimit.use")) { if (!plugin.config.getPermissionsEnabled() || !player.hasPermission("limitedcreative.nolimit.use")) {
if (plugin.config.getBlockedUse().contains(event.getBlock().getType())) { if (BlackList.isBlackListed(plugin.config.getBlockedUse(), event.getBlock())) {
event.setCancelled(true); event.setCancelled(true);
event.getPlayer().sendMessage(L("blocked.place")); event.getPlayer().sendMessage(L("blocked.place"));
} }

View file

@ -3,9 +3,15 @@ package de.jaschastarke.minecraft.limitedcreative.regions;
import static de.jaschastarke.minecraft.utils.Locale.L; import static de.jaschastarke.minecraft.utils.Locale.L;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
@ -16,6 +22,7 @@ import com.sk89q.worldguard.protection.managers.RegionManager;
import de.jaschastarke.minecraft.limitedcreative.LCPlayer; import de.jaschastarke.minecraft.limitedcreative.LCPlayer;
import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore; import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore;
import de.jaschastarke.minecraft.utils.Util;
import de.jaschastarke.minecraft.worldguard.ApplicableRegions; import de.jaschastarke.minecraft.worldguard.ApplicableRegions;
import de.jaschastarke.minecraft.worldguard.CRegionManager; import de.jaschastarke.minecraft.worldguard.CRegionManager;
@ -27,6 +34,14 @@ public class RegionListener implements Listener {
rm = wgi.getRegionManager(); rm = wgi.getRegionManager();
} }
private ApplicableRegions regionSet(World world, Location loc) {
RegionManager mgr = wg.getGlobalRegionManager().get(world);
Vector pt = new Vector(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
return new ApplicableRegions(mgr.getApplicableRegions(pt), rm.world(world));
}
private ApplicableRegions regionSet(Block block) {
return regionSet(block.getWorld(), block.getLocation());
}
@EventHandler @EventHandler
public void onBlockBreak(BlockBreakEvent event) { public void onBlockBreak(BlockBreakEvent event) {
if (event.isCancelled()) if (event.isCancelled())
@ -94,4 +109,45 @@ public class RegionListener implements Listener {
player.setRegionCreativeAllowed(set.allows(Flags.CREATIVE, player), event); player.setRegionCreativeAllowed(set.allows(Flags.CREATIVE, player), event);
} }
} }
@EventHandler
public void onPistonExtend(BlockPistonExtendEvent event) {
if (event.isCancelled())
return;
Block source = event.getBlock().getRelative(event.getDirection());
LimitedCreativeCore.debug("PistonExtend "+source.getType()+" "+event.getDirection());
if (source.getType() != Material.AIR) {
if (regionSet(source).allows(Flags.CREATIVE)) {
Block dest = source.getRelative(event.getDirection());
LimitedCreativeCore.debug("dest "+dest.getType());
if (!regionSet(dest).allows(Flags.CREATIVE)) {
plugin.logger.warning(L("blocked.piston", source.getType().toString(), Util.toString(source.getLocation())));
event.setCancelled(true);
}
}
}
}
@EventHandler
public void onPistonRetract(BlockPistonRetractEvent event) {
if (event.isCancelled())
return;
Block source = event.getBlock().getRelative(event.getDirection(), 2);
Block dest = source.getRelative(event.getDirection().getOppositeFace());
LimitedCreativeCore.debug("PistonRetract "+source.getType()+" "+event.getDirection() + " " + event.isSticky());
if (event.isSticky() && source.getType() != Material.AIR) {
LimitedCreativeCore.debug("dest "+dest.getType());
if (regionSet(source).allows(Flags.CREATIVE)) {
if (!regionSet(dest).allows(Flags.CREATIVE)) {
plugin.logger.warning(L("blocked.piston", source.getType().toString(), Util.toString(source.getLocation())));
event.setCancelled(true);
}
} else if (regionSet(dest).allows(Flags.CREATIVE)) {
// source isn't creative
plugin.logger.warning(L("blocked.piston_in", source.getType().toString(), Util.toString(source.getLocation())));
event.setCancelled(true);
}
}
}
} }

View file

@ -25,6 +25,8 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import org.bukkit.Location;
final public class Util { final public class Util {
public static int versionCompare(String vers1, String vers2) { public static int versionCompare(String vers1, String vers2) {
String[] v1 = vers1.split("\\."); String[] v1 = vers1.split("\\.");
@ -86,4 +88,7 @@ final public class Util {
public static String join(String[] list, String sep) { public static String join(String[] list, String sep) {
return join(list, sep, 0, list.length); return join(list, sep, 0, list.length);
} }
public static String toString(Location loc) {
return "{X: "+loc.getBlockX()+", Y: "+loc.getBlockY()+", Z: "+loc.getBlockZ()+"}";
}
} }