v0.9:
- 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:
parent
700d8f54c1
commit
147e453299
10 changed files with 316 additions and 117 deletions
16
config.yml
16
config.yml
|
@ -62,12 +62,25 @@ limit:
|
|||
# default: 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
|
||||
# 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)
|
||||
# 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".
|
||||
# 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).
|
||||
# default: []
|
||||
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)
|
||||
# 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).
|
||||
# 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]
|
||||
break:
|
||||
- bedrock
|
||||
|
|
|
@ -17,10 +17,7 @@ command:
|
|||
creative: Changes the game mode of a player to creative
|
||||
config:
|
||||
overview: "[setting] - empty for list of settings"
|
||||
settings:
|
||||
- "Available Settings: storecreative,"
|
||||
- "removedrop, removepickup, blockpickup, blocksign,"
|
||||
- "permissions, perm_keepinventory"
|
||||
settings: "Available Settings: "
|
||||
reload: Reloads plugin (doesn't work on update!)
|
||||
gamemode:
|
||||
changed: "{0}'s game mode has been changed"
|
||||
|
@ -54,9 +51,13 @@ exception:
|
|||
blocked:
|
||||
chest: Access to chests 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
|
||||
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
|
||||
use: You are not allowed to use this type of item
|
||||
place: You are not allowed to place 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}
|
11
plugin.yml
11
plugin.yml
|
@ -1,6 +1,6 @@
|
|||
name: LimitedCreative
|
||||
main: de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore
|
||||
version: 0.8.2-beta
|
||||
version: 0.9-beta
|
||||
softdepend: [WorldGuard, WorldEdit, MultiInv]
|
||||
dev-url: http://dev.bukkit.org/server-mods/limited-creative/
|
||||
commands:
|
||||
|
@ -43,9 +43,18 @@ permissions:
|
|||
limitedcreative.nolimit.sign:
|
||||
description: Allows bypassing the "do not interact with signs"-limitation
|
||||
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:
|
||||
description: Allows bypassing the "no pvp"-limitation
|
||||
default: false
|
||||
limitedcreative.nolimit.mob_damage:
|
||||
description: Allows bypassing the "no dealing damage to creatures"-limitation
|
||||
default: false
|
||||
limitedcreative.nolimit.use:
|
||||
description: Allows bypassing the "block place/item use"-limitation
|
||||
default: false
|
||||
|
|
55
src/de/jaschastarke/minecraft/limitedcreative/BlackList.java
Normal file
55
src/de/jaschastarke/minecraft/limitedcreative/BlackList.java
Normal 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;
|
||||
}
|
||||
}
|
|
@ -18,6 +18,7 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
|
@ -109,18 +110,6 @@ public class Commands {
|
|||
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 {
|
||||
if (sender instanceof Player && !plugin.perm.hasPermission(sender, "limitedcreative.config")) {
|
||||
throw new LackingPermissionException();
|
||||
|
@ -128,44 +117,30 @@ public class Commands {
|
|||
if (args.length > 2)
|
||||
throw new InvalidCommandException("exception.command.tomuchparameter");
|
||||
if (args.length < 2) {
|
||||
for (String l : L("command.config.settings").split("\n"))
|
||||
sender.sendMessage(l);
|
||||
StringBuilder str = new StringBuilder(L("command.config.settings"));
|
||||
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;
|
||||
}
|
||||
|
||||
Option opt = null;
|
||||
Configuration.Option opt = null;
|
||||
try {
|
||||
opt = Option.valueOf(args[1].toUpperCase());
|
||||
opt = Configuration.Option.valueOf(args[1].toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new InvalidCommandException("exception.command.invalidoption");
|
||||
}
|
||||
|
||||
switch (opt) {
|
||||
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;
|
||||
}
|
||||
plugin.config.set(opt, b);
|
||||
sender.sendMessage(L("command.option.done"));
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ package de.jaschastarke.minecraft.limitedcreative;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
@ -32,6 +33,38 @@ public class Configuration {
|
|||
private File file;
|
||||
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) {
|
||||
plugin = pplugin;
|
||||
|
||||
|
@ -43,11 +76,25 @@ public class Configuration {
|
|||
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 ;)
|
||||
*/
|
||||
public boolean getDebug() {
|
||||
return c.getBoolean("debug", false);
|
||||
return this.getBoolean(Option.DEBUG);
|
||||
}
|
||||
|
||||
public boolean getStoreEnabled() {
|
||||
|
@ -61,7 +108,7 @@ public class Configuration {
|
|||
}
|
||||
|
||||
public boolean getStoreCreative() {
|
||||
return c.getBoolean("store.creative", true);
|
||||
return this.getBoolean(Option.STORECREATIVE);
|
||||
}
|
||||
public boolean getUnsafeStorage() {
|
||||
return c.getBoolean("store.unsafe", false);
|
||||
|
@ -70,72 +117,35 @@ public class Configuration {
|
|||
return c.getString("store.folder", "inventories");
|
||||
}
|
||||
public boolean getBlockPickupInCreative() {
|
||||
return c.getBoolean("limit.pickup", true);
|
||||
return this.getBoolean(Option.BLOCKPICKUP);
|
||||
}
|
||||
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() {
|
||||
return c.getBoolean("limit.remove_drops", true);
|
||||
return this.getBoolean(Option.REMOVEDROP);
|
||||
}
|
||||
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() {
|
||||
return c.getBoolean("permissions.enabled", false);
|
||||
return this.getBoolean(Option.PERMISSIONS);
|
||||
}
|
||||
public boolean getPermissionToKeepInventory() {
|
||||
return this.getPermissionsEnabled() && c.getBoolean("permissions.keepinventory", false);
|
||||
return this.getPermissionsEnabled() && this.getBoolean(Option.PERM_KEEPINVENTORY);
|
||||
}
|
||||
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() {
|
||||
_block_break = null;
|
||||
_block_use = null;
|
||||
|
@ -146,24 +156,37 @@ public class Configuration {
|
|||
plugin.saveConfig();
|
||||
}
|
||||
|
||||
private List<Material> _block_break = null;
|
||||
private List<Material> _block_use = null;
|
||||
private List<BlackList> _block_break = null;
|
||||
private List<BlackList> _block_use = null;
|
||||
|
||||
public List<Material> getBlockedBreaks() {
|
||||
public List<BlackList> getBlockedBreaks() {
|
||||
if (_block_break == null)
|
||||
_block_break = parseMaterialList(c.getStringList("limit.break"));
|
||||
return _block_break;
|
||||
}
|
||||
public List<Material> getBlockedUse() {
|
||||
|
||||
public List<BlackList> getBlockedUse() {
|
||||
if (_block_use == null)
|
||||
_block_use = parseMaterialList(c.getStringList("limit.use"));
|
||||
return _block_use;
|
||||
}
|
||||
|
||||
private List<Material> parseMaterialList(List<String> s) {
|
||||
List<Material> list = new ArrayList<Material>();
|
||||
private List<BlackList> parseMaterialList(List<String> s) {
|
||||
List<BlackList> list = new ArrayList<BlackList>();
|
||||
if (s != null) {
|
||||
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;
|
||||
try {
|
||||
e = Material.getMaterial(Integer.parseInt(m));
|
||||
|
@ -171,9 +194,9 @@ public class Configuration {
|
|||
e = Material.matchMaterial(m);
|
||||
}
|
||||
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 {
|
||||
list.add(e);
|
||||
list.add(new BlackList(e, d));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,9 +30,11 @@ import org.bukkit.Material;
|
|||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Creature;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
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;
|
||||
|
@ -40,6 +42,7 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
|||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.Lever;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.Commands.LackingPermissionException;
|
||||
import de.jaschastarke.minecraft.limitedcreative.serialize.Items;
|
||||
|
@ -54,7 +57,7 @@ public class LCPlayer {
|
|||
private boolean _isPermanentCreative = false;
|
||||
private boolean _isRegionCreative = false;
|
||||
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");
|
||||
public static YamlConfiguration store = YamlConfiguration.loadConfiguration(_store_file);
|
||||
|
@ -237,7 +240,7 @@ public class LCPlayer {
|
|||
tempinv = null;
|
||||
}
|
||||
|
||||
public void onDamage(EntityDamageByEntityEvent event) {
|
||||
public void onDamage(EntityDamageByEntityEvent event) { // receives damage
|
||||
if (event.getDamager() instanceof Player) {
|
||||
// its PVP
|
||||
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) {
|
||||
if (player.getGameMode() != GameMode.CREATIVE)
|
||||
return;
|
||||
|
@ -278,6 +304,21 @@ public class LCPlayer {
|
|||
event.getPlayer().sendMessage(L("blocked.sign"));
|
||||
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;
|
||||
|
||||
|
|
|
@ -36,12 +36,16 @@ 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.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.LimitedCreativeCore;
|
||||
import static de.jaschastarke.minecraft.utils.Locale.L;
|
||||
|
@ -75,7 +79,7 @@ public class LimitListener implements Listener {
|
|||
|
||||
LCPlayer player = LCPlayer.get(event.getPlayer());
|
||||
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.setUseItemInHand(Event.Result.DENY);
|
||||
event.getPlayer().sendMessage(L("blocked.use"));
|
||||
|
@ -90,9 +94,10 @@ public class LimitListener implements Listener {
|
|||
|
||||
if (block.getState() instanceof ContainerBlock) {
|
||||
player.onChestAccess(event);
|
||||
}
|
||||
if (block.getState() instanceof Sign) {
|
||||
} else if (block.getState() instanceof Sign) {
|
||||
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());
|
||||
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.getPlayer().sendMessage(L("blocked.use"));
|
||||
return;
|
||||
|
@ -119,11 +124,24 @@ public class LimitListener implements Listener {
|
|||
|
||||
@EventHandler
|
||||
public void onEntityDamage(EntityDamageEvent meta_event) {
|
||||
if (meta_event.isCancelled())
|
||||
return;
|
||||
if (meta_event instanceof EntityDamageByEntityEvent) {
|
||||
EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) meta_event;
|
||||
if (event.getEntity() instanceof Player) {
|
||||
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) {
|
||||
LCPlayer player = LCPlayer.get(event.getPlayer());
|
||||
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.getPlayer().sendMessage(L("blocked.break"));
|
||||
}
|
||||
|
@ -181,7 +199,7 @@ public class LimitListener implements Listener {
|
|||
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||
LCPlayer player = LCPlayer.get(event.getPlayer());
|
||||
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.getPlayer().sendMessage(L("blocked.place"));
|
||||
}
|
||||
|
|
|
@ -3,9 +3,15 @@ package de.jaschastarke.minecraft.limitedcreative.regions;
|
|||
import static de.jaschastarke.minecraft.utils.Locale.L;
|
||||
|
||||
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.Listener;
|
||||
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.player.PlayerMoveEvent;
|
||||
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.LimitedCreativeCore;
|
||||
import de.jaschastarke.minecraft.utils.Util;
|
||||
import de.jaschastarke.minecraft.worldguard.ApplicableRegions;
|
||||
import de.jaschastarke.minecraft.worldguard.CRegionManager;
|
||||
|
||||
|
@ -27,6 +34,14 @@ public class RegionListener implements Listener {
|
|||
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
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (event.isCancelled())
|
||||
|
@ -94,4 +109,45 @@ public class RegionListener implements Listener {
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
final public class Util {
|
||||
public static int versionCompare(String vers1, String vers2) {
|
||||
String[] v1 = vers1.split("\\.");
|
||||
|
@ -86,4 +88,7 @@ final public class Util {
|
|||
public static String join(String[] list, String sep) {
|
||||
return join(list, sep, 0, list.length);
|
||||
}
|
||||
public static String toString(Location loc) {
|
||||
return "{X: "+loc.getBlockX()+", Y: "+loc.getBlockY()+", Z: "+loc.getBlockZ()+"}";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue