From e3153596b4d3abc0e85d67e055cd2e56696555b6 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Fri, 10 Feb 2012 23:03:42 +0100 Subject: [PATCH] v0.9.1: - fixed pistons moving multiple blocks - added compatibility to AuthMe - added '*'-BlackList to prevent any item/block usage/break in creative - added region-flag to prevent any item from spawning --- plugin.yml | 4 +- .../integration/AbstractCommunicator.java | 80 ++++++++++++++++++ .../minecraft/integration/AuthMe.java | 32 ++++++++ .../integration/CommunicationBridge.java | 21 +++++ .../minecraft/integration/Communicator.java | 34 ++++++++ .../minecraft/limitedcreative/BlackList.java | 81 ++++++++++++------- .../minecraft/limitedcreative/Commands.java | 2 +- .../limitedcreative/Configuration.java | 46 ++++++----- .../limitedcreative/LimitedCreativeCore.java | 4 + .../listeners/MainListener.java | 5 ++ .../limitedcreative/regions/Flags.java | 1 + .../regions/RegionListener.java | 39 ++++++--- .../regions/WorldGuardIntegration.java | 1 + 13 files changed, 287 insertions(+), 63 deletions(-) create mode 100644 src/de/jaschastarke/minecraft/integration/AbstractCommunicator.java create mode 100644 src/de/jaschastarke/minecraft/integration/AuthMe.java create mode 100644 src/de/jaschastarke/minecraft/integration/CommunicationBridge.java create mode 100644 src/de/jaschastarke/minecraft/integration/Communicator.java diff --git a/plugin.yml b/plugin.yml index 5c03bf0..2ab6c99 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,7 +1,7 @@ name: LimitedCreative main: de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore -version: 0.9-beta -softdepend: [WorldGuard, WorldEdit, MultiInv] +version: 0.9.1-beta +softdepend: [WorldGuard, WorldEdit, MultiInv, AuthMe] dev-url: http://dev.bukkit.org/server-mods/limited-creative/ commands: limitedcreative: diff --git a/src/de/jaschastarke/minecraft/integration/AbstractCommunicator.java b/src/de/jaschastarke/minecraft/integration/AbstractCommunicator.java new file mode 100644 index 0000000..4f458f3 --- /dev/null +++ b/src/de/jaschastarke/minecraft/integration/AbstractCommunicator.java @@ -0,0 +1,80 @@ +/* + * 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 . + */ +package de.jaschastarke.minecraft.integration; + +//import java.util.HashMap; +//import java.util.Map; + +//import org.bukkit.event.EventHandler; +//import org.bukkit.event.Listener; +/*import org.bukkit.event.server.PluginDisableEvent; +import org.bukkit.event.server.PluginEnableEvent;*/ +import org.bukkit.plugin.java.JavaPlugin; + +abstract public class AbstractCommunicator /*implements Listener*/ { + private JavaPlugin plugin; + //private Map, CommunicationBridge> bridges = new HashMap, CommunicationBridge>(); + + public AbstractCommunicator(JavaPlugin plugin) { + this.plugin = plugin; + //plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + protected boolean isPluginEnabled(String plugin) { + return this.plugin.getServer().getPluginManager().isPluginEnabled(plugin); + } + /*@SuppressWarnings("unchecked") + protected T getBridge(Class cls) { + if (!bridges.containsKey(cls)) { + try { + bridges.put(cls, cls.newInstance()); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + return (T) bridges.get(cls); + }*/ + + /*@EventHandler + public void onPluginEnable(PluginEnableEvent event) { + + } + @EventHandler + public void onPluginDisable(PluginDisableEvent event) { + + } + protected boolean isPluginEnabled(String plugin, Class cls) { + if (!bridges.containsKey(plugin)) { + if (this.plugin.getServer().getPluginManager().isPluginEnabled(plugin)) { + + } else { + bridges.put(plugin, null); + } + } + return bridges.get(plugin) != null; + } + protected + protected T whenPluginEnabled(String plugin, Class cls) { + if (isPluginEnabled(plugin)) { + + } + }*/ +} diff --git a/src/de/jaschastarke/minecraft/integration/AuthMe.java b/src/de/jaschastarke/minecraft/integration/AuthMe.java new file mode 100644 index 0000000..76727e5 --- /dev/null +++ b/src/de/jaschastarke/minecraft/integration/AuthMe.java @@ -0,0 +1,32 @@ +/* + * 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 . + */ +package de.jaschastarke.minecraft.integration; + +import org.bukkit.entity.Player; + +import uk.org.whoami.authme.cache.auth.PlayerCache; +import uk.org.whoami.authme.cache.limbo.LimboCache; + +public class AuthMe implements CommunicationBridge { + public static boolean isLoggedIn(Player player) { + return PlayerCache.getInstance().isAuthenticated(player.getName()); + } + public static boolean isLoggedInComplete(Player player) { + return isLoggedIn(player) && LimboCache.getInstance().getLimboPlayer(player.getName()) == null; + } +} diff --git a/src/de/jaschastarke/minecraft/integration/CommunicationBridge.java b/src/de/jaschastarke/minecraft/integration/CommunicationBridge.java new file mode 100644 index 0000000..0894ff2 --- /dev/null +++ b/src/de/jaschastarke/minecraft/integration/CommunicationBridge.java @@ -0,0 +1,21 @@ +/* + * 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 . + */ +package de.jaschastarke.minecraft.integration; + +public interface CommunicationBridge { +} diff --git a/src/de/jaschastarke/minecraft/integration/Communicator.java b/src/de/jaschastarke/minecraft/integration/Communicator.java new file mode 100644 index 0000000..d3f17cc --- /dev/null +++ b/src/de/jaschastarke/minecraft/integration/Communicator.java @@ -0,0 +1,34 @@ +/* + * 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 . + */ +package de.jaschastarke.minecraft.integration; + +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +public class Communicator extends AbstractCommunicator { + public Communicator(JavaPlugin plugin) { + super(plugin); + } + + public boolean isLoggedIn(Player player) { + if (isPluginEnabled("AuthMe")) + return AuthMe.isLoggedInComplete(player); + //return getBridge(AuthMe.class).isLoggedIn(player);*/ + return true; + } +} diff --git a/src/de/jaschastarke/minecraft/limitedcreative/BlackList.java b/src/de/jaschastarke/minecraft/limitedcreative/BlackList.java index 31fe8b9..0f77bf4 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/BlackList.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/BlackList.java @@ -6,38 +6,11 @@ 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; - } +abstract public class BlackList { + abstract public boolean matches(Block b); + abstract public boolean matches(ItemStack item); + public static boolean isBlackListed(List list, Block block) { for (BlackList bl : list) { if (bl.matches(block)) @@ -52,4 +25,50 @@ public class BlackList { } return false; } + + public static class Some extends BlackList { + private Material mat; + private int data = -1; + public Some(Material material, int data) { + mat = material; + this.data = data; + } + public Some(Material material) { + mat = material; + } + public boolean matches(Block block) { + if (this.mat == null) + return true; + 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 == null) + return true; + 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 class All extends BlackList { + public boolean matches(Block b) { + return true; + } + public boolean matches(ItemStack item) { + return true; + } + } } diff --git a/src/de/jaschastarke/minecraft/limitedcreative/Commands.java b/src/de/jaschastarke/minecraft/limitedcreative/Commands.java index 1fae2f7..8738240 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/Commands.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/Commands.java @@ -123,7 +123,7 @@ public class Commands { str.append(options.get(i).name().toLowerCase()); if (i < options.size() - 1) str.append(", "); - if ((i - 1) % 5 == 0) { + if ((i - 1) % 4 == 0) { sender.sendMessage(str.toString()); str = new StringBuilder(); } diff --git a/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java b/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java index 0df985b..70a6e02 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java @@ -176,27 +176,33 @@ public class Configuration { 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)); - } catch (NumberFormatException ex) { - e = Material.matchMaterial(m); - } - if (e == null) { - plugin.warn(L("exception.config.material_not_found", m)); + if (m.equals("*")) { + list.clear(); + list.add(new BlackList.All()); + break; } else { - list.add(new BlackList(e, d)); + 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)); + } catch (NumberFormatException ex) { + e = Material.matchMaterial(m); + } + if (e == null) { + plugin.warn(L("exception.config.material_not_found", m)); + } else { + list.add(new BlackList.Some(e, d)); + } } } } diff --git a/src/de/jaschastarke/minecraft/limitedcreative/LimitedCreativeCore.java b/src/de/jaschastarke/minecraft/limitedcreative/LimitedCreativeCore.java index f8bab7b..5c4d026 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/LimitedCreativeCore.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/LimitedCreativeCore.java @@ -22,6 +22,7 @@ import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; import static de.jaschastarke.minecraft.utils.Locale.L; +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.regions.WorldGuardIntegration; @@ -34,6 +35,7 @@ public class LimitedCreativeCore extends JavaPlugin { public Configuration config; public Permissions perm; public WorldGuardIntegration worldguard; + public Communicator com; public static LimitedCreativeCore plugin; public NoBlockItemSpawn spawnblock; @@ -44,6 +46,7 @@ public class LimitedCreativeCore extends JavaPlugin { worldguard = null; config = null; spawnblock = null; + com = null; try { Locale.unload(); } catch (NoClassDefFoundError e) {} // prevent unload issue @@ -54,6 +57,7 @@ public class LimitedCreativeCore extends JavaPlugin { plugin = this; config = new Configuration(this); perm = new Permissions(this); + com = new Communicator(this); new Locale(this); diff --git a/src/de/jaschastarke/minecraft/limitedcreative/listeners/MainListener.java b/src/de/jaschastarke/minecraft/limitedcreative/listeners/MainListener.java index 16f36bf..da9fbda 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/listeners/MainListener.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/listeners/MainListener.java @@ -50,7 +50,10 @@ public class MainListener implements Listener { LimitedCreativeCore.debug("onPlayerGameModeChange: "+event.getPlayer().getName()); LimitedCreativeCore.debug("Current GameMode: "+event.getPlayer().getGameMode()); LimitedCreativeCore.debug("New GameMode: "+event.getNewGameMode()); + LimitedCreativeCore.debug("isLoggedin: "+plugin.com.isLoggedIn(event.getPlayer())); LimitedCreativeCore.debug("isCancelled: "+event.isCancelled()); + if (!plugin.com.isLoggedIn(event.getPlayer())) + return; if (event.getNewGameMode() == GameMode.CREATIVE) { if (!LCPlayer.get(event.getPlayer()).onSetCreative()) event.setCancelled(true); @@ -65,6 +68,8 @@ public class MainListener implements Listener { */ @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); diff --git a/src/de/jaschastarke/minecraft/limitedcreative/regions/Flags.java b/src/de/jaschastarke/minecraft/limitedcreative/regions/Flags.java index bcc784b..16a5c4f 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/regions/Flags.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/regions/Flags.java @@ -4,6 +4,7 @@ import com.sk89q.worldguard.protection.flags.RegionGroupFlag; import com.sk89q.worldguard.protection.flags.StateFlag; public final class Flags { + public static final StateFlag SPAWNDROPS = new StateFlag("spawndrops", true); public static final StateFlag CREATIVE = new StateFlag("creative", false); public static final RegionGroupFlag CREATIVE_GROUP = new RegionGroupFlag("creative-group", RegionGroupFlag.RegionGroup.MEMBERS); static { diff --git a/src/de/jaschastarke/minecraft/limitedcreative/regions/RegionListener.java b/src/de/jaschastarke/minecraft/limitedcreative/regions/RegionListener.java index 1833419..01b3599 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/regions/RegionListener.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/regions/RegionListener.java @@ -7,17 +7,20 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; +import org.bukkit.entity.Item; 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.entity.ItemSpawnEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerTeleportEvent; import com.sk89q.worldedit.Vector; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.managers.RegionManager; import de.jaschastarke.minecraft.limitedcreative.LCPlayer; @@ -36,8 +39,10 @@ public class RegionListener implements Listener { 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)); + return new ApplicableRegions(mgr.getApplicableRegions(loc), rm.world(world)); + } + private ApplicableRegions regionSet(Location loc) { + return regionSet(loc.getWorld(), loc); } private ApplicableRegions regionSet(Block block) { return regionSet(block.getWorld(), block.getLocation()); @@ -86,8 +91,9 @@ public class RegionListener implements Listener { LCPlayer player = LCPlayer.get(event.getPlayer()); RegionManager mgr = wg.getGlobalRegionManager().get(event.getPlayer().getWorld()); - Vector pt = new Vector(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ()); - ApplicableRegions set = new ApplicableRegions(mgr.getApplicableRegions(pt), rm.world(event.getPlayer().getWorld())); + ApplicableRegionSet applicableRegions = mgr.getApplicableRegions(event.getTo()); + LimitedCreativeCore.debug(applicableRegions.toString()); + ApplicableRegions set = new ApplicableRegions(applicableRegions, rm.world(event.getPlayer().getWorld())); player.setRegionCreativeAllowed(set.allows(Flags.CREATIVE, player), event); } @@ -119,11 +125,16 @@ public class RegionListener implements Listener { 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); + for (int i = 1; i <= 12; i++) { + Block dest = source.getRelative(event.getDirection(), i); + LimitedCreativeCore.debug("dest "+i+": "+dest.getType()); + if (!regionSet(dest).allows(Flags.CREATIVE)) { + plugin.logger.warning(L("blocked.piston", source.getRelative(event.getDirection(), i - 1).getType().toString(), Util.toString(source.getLocation()))); + event.setCancelled(true); + break; + } else if (dest.getType() == Material.AIR) { + break; + } } } } @@ -150,4 +161,14 @@ public class RegionListener implements Listener { } } } + + @EventHandler + public void onItemSpawn(ItemSpawnEvent event) { + if (event.isCancelled()) + return; + if (event.getEntity() instanceof Item) { + if (!regionSet(event.getLocation()).allows(Flags.SPAWNDROPS)) + event.setCancelled(true); + } + } } diff --git a/src/de/jaschastarke/minecraft/limitedcreative/regions/WorldGuardIntegration.java b/src/de/jaschastarke/minecraft/limitedcreative/regions/WorldGuardIntegration.java index c15ff3f..51545d7 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/regions/WorldGuardIntegration.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/regions/WorldGuardIntegration.java @@ -38,6 +38,7 @@ public class WorldGuardIntegration { FlagList.addFlag(Flags.CREATIVE); FlagList.addFlag(Flags.CREATIVE_GROUP); + FlagList.addFlag(Flags.SPAWNDROPS); plugin.getServer().getPluginManager().registerEvents(new RegionListener(this), plugin); }