- 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
This commit is contained in:
Jascha Starke 2012-02-10 23:03:42 +01:00
parent 5b23ffa500
commit e3153596b4
13 changed files with 287 additions and 63 deletions

View file

@ -1,7 +1,7 @@
name: LimitedCreative name: LimitedCreative
main: de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore main: de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore
version: 0.9-beta version: 0.9.1-beta
softdepend: [WorldGuard, WorldEdit, MultiInv] softdepend: [WorldGuard, WorldEdit, MultiInv, AuthMe]
dev-url: http://dev.bukkit.org/server-mods/limited-creative/ dev-url: http://dev.bukkit.org/server-mods/limited-creative/
commands: commands:
limitedcreative: limitedcreative:

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
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<Class<?>, CommunicationBridge> bridges = new HashMap<Class<?>, 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 extends CommunicationBridge> T getBridge(Class<T> 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 <T extends CommunicationBridge> boolean isPluginEnabled(String plugin, Class<T> 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 extends CommunicationBridge> T whenPluginEnabled(String plugin, Class<T> cls) {
if (isPluginEnabled(plugin)) {
}
}*/
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
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;
}
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
package de.jaschastarke.minecraft.integration;
public interface CommunicationBridge {
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
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;
}
}

View file

@ -6,37 +6,10 @@ import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public class BlackList { abstract public class BlackList {
private Material mat;
private int data = -1; abstract public boolean matches(Block b);
public BlackList(Material material, int data) { abstract public boolean matches(ItemStack item);
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) { public static boolean isBlackListed(List<BlackList> list, Block block) {
for (BlackList bl : list) { for (BlackList bl : list) {
@ -52,4 +25,50 @@ public class BlackList {
} }
return false; 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;
}
}
} }

View file

@ -123,7 +123,7 @@ public class Commands {
str.append(options.get(i).name().toLowerCase()); str.append(options.get(i).name().toLowerCase());
if (i < options.size() - 1) if (i < options.size() - 1)
str.append(", "); str.append(", ");
if ((i - 1) % 5 == 0) { if ((i - 1) % 4 == 0) {
sender.sendMessage(str.toString()); sender.sendMessage(str.toString());
str = new StringBuilder(); str = new StringBuilder();
} }

View file

@ -176,6 +176,11 @@ public class Configuration {
if (s != null) { if (s != null) {
for (String m : s) { for (String m : s) {
int d = -1; int d = -1;
if (m.equals("*")) {
list.clear();
list.add(new BlackList.All());
break;
} else {
if (m.contains(":")) { if (m.contains(":")) {
String[] t = m.split(":"); String[] t = m.split(":");
m = t[0]; m = t[0];
@ -196,7 +201,8 @@ public class Configuration {
if (e == null) { if (e == null) {
plugin.warn(L("exception.config.material_not_found", m)); plugin.warn(L("exception.config.material_not_found", m));
} else { } else {
list.add(new BlackList(e, d)); list.add(new BlackList.Some(e, d));
}
} }
} }
} }

View file

@ -22,6 +22,7 @@ import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import static de.jaschastarke.minecraft.utils.Locale.L; 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.LimitListener;
import de.jaschastarke.minecraft.limitedcreative.listeners.MainListener; import de.jaschastarke.minecraft.limitedcreative.listeners.MainListener;
import de.jaschastarke.minecraft.limitedcreative.regions.WorldGuardIntegration; import de.jaschastarke.minecraft.limitedcreative.regions.WorldGuardIntegration;
@ -34,6 +35,7 @@ public class LimitedCreativeCore extends JavaPlugin {
public Configuration config; public Configuration config;
public Permissions perm; public Permissions perm;
public WorldGuardIntegration worldguard; public WorldGuardIntegration worldguard;
public Communicator com;
public static LimitedCreativeCore plugin; public static LimitedCreativeCore plugin;
public NoBlockItemSpawn spawnblock; public NoBlockItemSpawn spawnblock;
@ -44,6 +46,7 @@ public class LimitedCreativeCore extends JavaPlugin {
worldguard = null; worldguard = null;
config = null; config = null;
spawnblock = null; spawnblock = null;
com = null;
try { try {
Locale.unload(); Locale.unload();
} catch (NoClassDefFoundError e) {} // prevent unload issue } catch (NoClassDefFoundError e) {} // prevent unload issue
@ -54,6 +57,7 @@ public class LimitedCreativeCore extends JavaPlugin {
plugin = this; plugin = this;
config = new Configuration(this); config = new Configuration(this);
perm = new Permissions(this); perm = new Permissions(this);
com = new Communicator(this);
new Locale(this); new Locale(this);

View file

@ -50,7 +50,10 @@ public class MainListener implements Listener {
LimitedCreativeCore.debug("onPlayerGameModeChange: "+event.getPlayer().getName()); LimitedCreativeCore.debug("onPlayerGameModeChange: "+event.getPlayer().getName());
LimitedCreativeCore.debug("Current GameMode: "+event.getPlayer().getGameMode()); LimitedCreativeCore.debug("Current GameMode: "+event.getPlayer().getGameMode());
LimitedCreativeCore.debug("New GameMode: "+event.getNewGameMode()); LimitedCreativeCore.debug("New GameMode: "+event.getNewGameMode());
LimitedCreativeCore.debug("isLoggedin: "+plugin.com.isLoggedIn(event.getPlayer()));
LimitedCreativeCore.debug("isCancelled: "+event.isCancelled()); LimitedCreativeCore.debug("isCancelled: "+event.isCancelled());
if (!plugin.com.isLoggedIn(event.getPlayer()))
return;
if (event.getNewGameMode() == GameMode.CREATIVE) { if (event.getNewGameMode() == GameMode.CREATIVE) {
if (!LCPlayer.get(event.getPlayer()).onSetCreative()) if (!LCPlayer.get(event.getPlayer()).onSetCreative())
event.setCancelled(true); event.setCancelled(true);
@ -65,6 +68,8 @@ public class MainListener implements Listener {
*/ */
@EventHandler @EventHandler
public void onItemSpawn(ItemSpawnEvent event) { public void onItemSpawn(ItemSpawnEvent event) {
if (event.isCancelled())
return;
if (event.getEntity() instanceof Item) { if (event.getEntity() instanceof Item) {
if (plugin.spawnblock.isBlocked(event.getLocation().getBlock().getLocation(), ((Item) event.getEntity()).getItemStack().getType())) { if (plugin.spawnblock.isBlocked(event.getLocation().getBlock().getLocation(), ((Item) event.getEntity()).getItemStack().getType())) {
event.setCancelled(true); event.setCancelled(true);

View file

@ -4,6 +4,7 @@ import com.sk89q.worldguard.protection.flags.RegionGroupFlag;
import com.sk89q.worldguard.protection.flags.StateFlag; import com.sk89q.worldguard.protection.flags.StateFlag;
public final class Flags { 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 StateFlag CREATIVE = new StateFlag("creative", false);
public static final RegionGroupFlag CREATIVE_GROUP = new RegionGroupFlag("creative-group", RegionGroupFlag.RegionGroup.MEMBERS); public static final RegionGroupFlag CREATIVE_GROUP = new RegionGroupFlag("creative-group", RegionGroupFlag.RegionGroup.MEMBERS);
static { static {

View file

@ -7,17 +7,20 @@ import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Item;
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.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.managers.RegionManager;
import de.jaschastarke.minecraft.limitedcreative.LCPlayer; import de.jaschastarke.minecraft.limitedcreative.LCPlayer;
@ -36,8 +39,10 @@ public class RegionListener implements Listener {
private ApplicableRegions regionSet(World world, Location loc) { private ApplicableRegions regionSet(World world, Location loc) {
RegionManager mgr = wg.getGlobalRegionManager().get(world); RegionManager mgr = wg.getGlobalRegionManager().get(world);
Vector pt = new Vector(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); return new ApplicableRegions(mgr.getApplicableRegions(loc), rm.world(world));
return new ApplicableRegions(mgr.getApplicableRegions(pt), rm.world(world)); }
private ApplicableRegions regionSet(Location loc) {
return regionSet(loc.getWorld(), loc);
} }
private ApplicableRegions regionSet(Block block) { private ApplicableRegions regionSet(Block block) {
return regionSet(block.getWorld(), block.getLocation()); return regionSet(block.getWorld(), block.getLocation());
@ -86,8 +91,9 @@ public class RegionListener implements Listener {
LCPlayer player = LCPlayer.get(event.getPlayer()); LCPlayer player = LCPlayer.get(event.getPlayer());
RegionManager mgr = wg.getGlobalRegionManager().get(event.getPlayer().getWorld()); RegionManager mgr = wg.getGlobalRegionManager().get(event.getPlayer().getWorld());
Vector pt = new Vector(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ()); ApplicableRegionSet applicableRegions = mgr.getApplicableRegions(event.getTo());
ApplicableRegions set = new ApplicableRegions(mgr.getApplicableRegions(pt), rm.world(event.getPlayer().getWorld())); LimitedCreativeCore.debug(applicableRegions.toString());
ApplicableRegions set = new ApplicableRegions(applicableRegions, rm.world(event.getPlayer().getWorld()));
player.setRegionCreativeAllowed(set.allows(Flags.CREATIVE, player), event); player.setRegionCreativeAllowed(set.allows(Flags.CREATIVE, player), event);
} }
@ -119,11 +125,16 @@ public class RegionListener implements Listener {
LimitedCreativeCore.debug("PistonExtend "+source.getType()+" "+event.getDirection()); LimitedCreativeCore.debug("PistonExtend "+source.getType()+" "+event.getDirection());
if (source.getType() != Material.AIR) { if (source.getType() != Material.AIR) {
if (regionSet(source).allows(Flags.CREATIVE)) { if (regionSet(source).allows(Flags.CREATIVE)) {
Block dest = source.getRelative(event.getDirection()); for (int i = 1; i <= 12; i++) {
LimitedCreativeCore.debug("dest "+dest.getType()); Block dest = source.getRelative(event.getDirection(), i);
LimitedCreativeCore.debug("dest "+i+": "+dest.getType());
if (!regionSet(dest).allows(Flags.CREATIVE)) { if (!regionSet(dest).allows(Flags.CREATIVE)) {
plugin.logger.warning(L("blocked.piston", source.getType().toString(), Util.toString(source.getLocation()))); plugin.logger.warning(L("blocked.piston", source.getRelative(event.getDirection(), i - 1).getType().toString(), Util.toString(source.getLocation())));
event.setCancelled(true); 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);
}
}
} }

View file

@ -38,6 +38,7 @@ public class WorldGuardIntegration {
FlagList.addFlag(Flags.CREATIVE); FlagList.addFlag(Flags.CREATIVE);
FlagList.addFlag(Flags.CREATIVE_GROUP); FlagList.addFlag(Flags.CREATIVE_GROUP);
FlagList.addFlag(Flags.SPAWNDROPS);
plugin.getServer().getPluginManager().registerEvents(new RegionListener(this), plugin); plugin.getServer().getPluginManager().registerEvents(new RegionListener(this), plugin);
} }