- 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
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:

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,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<BlackList> 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;
}
}
}

View file

@ -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();
}

View file

@ -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));
}
}
}
}

View file

@ -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);

View file

@ -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);

View file

@ -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 {

View file

@ -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);
}
}
}

View file

@ -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);
}