v0.8-beta:

- RB 1.1-R1 (no longer supporting 1.0.1)
 - dropping items removes them from quickbar/inventory
 - external localization may be loaded
 - new bukkit event api
 - cleaned up listener code
 - external localization
 - permission nolimit.use/break bugfix
This commit is contained in:
Jascha Starke 2012-01-27 11:06:07 +01:00
parent 85602d4922
commit 295a93b384
15 changed files with 467 additions and 429 deletions

View file

@ -1,3 +1,7 @@
basic:
loaded:
worldguard: Successfully loaded with WorldGuard-Integration
no_worldguard: Successfully loaded (without WorldGuard)
command: command:
player: player player: player
switch: switch:
@ -39,4 +43,7 @@ blocked:
sign: To interact with signs is not allowed in creative mode sign: To interact with signs 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
place: You are not allowed to place this type of block
break: You are not allowed to break this type of block

View file

@ -1,6 +1,6 @@
name: LimitedCreative name: LimitedCreative
main: de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore main: de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore
version: 0.6-beta version: 0.8-beta
softdepend: [WorldGuard] softdepend: [WorldGuard]
dev-url: http://dev.bukkit.org/server-mods/limited-creative/ dev-url: http://dev.bukkit.org/server-mods/limited-creative/
commands: commands:

View file

@ -42,6 +42,13 @@ public class Configuration {
c = plugin.getConfig(); c = plugin.getConfig();
} }
/**
* Intended to be undocumented ;)
*/
public boolean getDebug() {
return c.getBoolean("debug", false);
}
public boolean getStoreEnabled() { public boolean getStoreEnabled() {
return c.getBoolean("store.enabled", true); return c.getBoolean("store.enabled", true);
@ -150,5 +157,4 @@ public class Configuration {
} }
return list; return list;
} }
} }

View file

@ -17,8 +17,6 @@
*/ */
package de.jaschastarke.minecraft.limitedcreative; package de.jaschastarke.minecraft.limitedcreative;
import static de.jaschastarke.minecraft.utils.Locale.L;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
@ -44,6 +42,7 @@ import org.bukkit.inventory.ItemStack;
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;
import static de.jaschastarke.minecraft.utils.Locale.L;
public class LCPlayer { public class LCPlayer {
private static LimitedCreativeCore plugin = LimitedCreativeCore.plugin; private static LimitedCreativeCore plugin = LimitedCreativeCore.plugin;
@ -153,7 +152,7 @@ public class LCPlayer {
if (player.getGameMode() == GameMode.CREATIVE) { if (player.getGameMode() == GameMode.CREATIVE) {
if (plugin.config.getPermissionsEnabled() && event.getPlayer().hasPermission("limitedcreative.nolimit.drop")) if (plugin.config.getPermissionsEnabled() && event.getPlayer().hasPermission("limitedcreative.nolimit.drop"))
return; return;
event.setCancelled(true); event.getItemDrop().remove();
} }
} }
public void onPickupItem(PlayerPickupItemEvent event) { public void onPickupItem(PlayerPickupItemEvent event) {
@ -239,7 +238,7 @@ public class LCPlayer {
Location newloc = event.getTo().clone(); Location newloc = event.getTo().clone();
newloc.setX(event.getFrom().getX()); newloc.setX(event.getFrom().getX());
//newloc.setY(event.getFrom().getY()); newloc.setY(event.getFrom().getY()); // well, otherwise flying high out of the region is possible
newloc.setZ(event.getFrom().getZ()); newloc.setZ(event.getFrom().getZ());
event.setTo(newloc); event.setTo(newloc);
} else { } else {

View file

@ -22,6 +22,8 @@ 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.limitedcreative.listeners.LimitListener;
import de.jaschastarke.minecraft.limitedcreative.listeners.MainListener;
import de.jaschastarke.minecraft.limitedcreative.regions.WorldGuardIntegration; import de.jaschastarke.minecraft.limitedcreative.regions.WorldGuardIntegration;
import de.jaschastarke.minecraft.utils.Locale; import de.jaschastarke.minecraft.utils.Locale;
@ -32,41 +34,53 @@ public class LimitedCreativeCore extends JavaPlugin {
public WorldGuardIntegration worldguard; public WorldGuardIntegration worldguard;
public static LimitedCreativeCore plugin; public static LimitedCreativeCore plugin;
public NoBlockItemSpawn spawnblock; public NoBlockItemSpawn spawnblock;
public static boolean serializeFallBack = false;
@Override @Override
public void onDisable() { public void onDisable() {
plugin = null;
worldguard = null;
config = null;
spawnblock = null;
Locale.unload(); Locale.unload();
logger.info("["+this.getDescription().getName()+"] cleanly unloaded."); //info("cleanly unloaded.");
} }
@Override @Override
public void onEnable() { public void onEnable() {
plugin = this; plugin = this;
config = new Configuration(this); config = new Configuration(this);
try {
Class.forName("org.bukkit.configuration.file.YamlConstructor", false, getClassLoader());
} catch (ClassNotFoundException e) {
serializeFallBack = true;
}
new Locale(this); new Locale(this);
spawnblock = new NoBlockItemSpawn(); spawnblock = new NoBlockItemSpawn();
Listener.register(this); getServer().getPluginManager().registerEvents(new MainListener(this), this);
if (config.getLimitEnabled())
getServer().getPluginManager().registerEvents(new LimitListener(this), this);
if (config.getRegionEnabled() && WorldGuardIntegration.available()) { if (config.getRegionEnabled() && WorldGuardIntegration.available()) {
worldguard = new WorldGuardIntegration(this); worldguard = new WorldGuardIntegration(this);
worldguard.init(); } else if(config.getRegionEnabled()) {
} else { warn(L("warning.no_worldguard_found"));
logger.info("["+this.getDescription().getName()+"] "+L("warning.no_worldguard_found"));
} }
Commands.register(this); Commands.register(this);
PluginDescriptionFile df = this.getDescription(); PluginDescriptionFile df = this.getDescription();
logger.info("["+df.getName() + " v" + df.getVersion() + "] done loading."); if (worldguard != null)
logger.info("["+df.getName() + " v" + df.getVersion() + "] "+L("basic.loaded.worldguard"));
else
logger.info("["+df.getName() + " v" + df.getVersion() + "] "+L("basic.loaded.no_worldguard"));
}
public void info(String s) {
logger.info("["+this.getDescription().getName()+"] " + s);
}
public void warn(String s) {
logger.warning("["+this.getDescription().getName()+"] " + s);
}
public static void debug(String s) {
if (plugin.config.getDebug())
plugin.info("DEBUG: " + s);
} }
} }

View file

@ -1,277 +0,0 @@
/*
* 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.limitedcreative;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.ContainerBlock;
import org.bukkit.block.Sign;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.entity.StorageMinecart;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockListener;
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.EntityListener;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.plugin.PluginManager;
public final class Listener {
private static LimitedCreativeCore plugin;
private static PluginManager pm;
public static class PlayerListen extends PlayerListener {
@Override
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
if (event.getNewGameMode() == GameMode.CREATIVE) {
if (!LCPlayer.get(event.getPlayer()).onSetCreative())
event.setCancelled(true);
} else if (event.getNewGameMode() == GameMode.SURVIVAL) {
if (!LCPlayer.get(event.getPlayer()).onSetSurvival())
event.setCancelled(true);
}
}
@Override
public void onPlayerRespawn(PlayerRespawnEvent event) {
LCPlayer.get(event.getPlayer()).onRespawn(event);
}
@Override
public void onPlayerDropItem(PlayerDropItemEvent event) {
LCPlayer.get(event.getPlayer()).onDropItem(event);
}
@Override
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
LCPlayer.get(event.getPlayer()).onPickupItem(event);
}
@Override
public void onPlayerInteract(PlayerInteractEvent event) {
if (isCancelled(event) || event.getPlayer().getGameMode() != GameMode.CREATIVE)
return;
if (!plugin.config.getPermissionsEnabled() || event.getPlayer().hasPermission("limitedcreative.nolimit.use")) {
if (event.getItem() != null && plugin.config.getBlockedUse().contains(event.getItem().getType())) {
event.setCancelled(true);
event.setUseItemInHand(Event.Result.DENY);
return;
}
}
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
return;
Block block = event.getClickedBlock();
if (block.getState() instanceof ContainerBlock) {
LCPlayer.get(event.getPlayer()).onChestAccess(event);
}
if (block.getState() instanceof Sign) {
LCPlayer.get(event.getPlayer()).onSignAccess(event);
}
}
/**
* The isCancelled in PlayerInteractEvent doesn't check useItemInHand, even this decides (when clicking on
* entity with e.g. a bucket)
* @param event
* @return The relevant "isCancelled"
*/
public static boolean isCancelled(PlayerInteractEvent event) {
return event.useInteractedBlock() == Event.Result.DENY && event.useItemInHand() == Event.Result.DENY;
}
@Override
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
if (event.isCancelled() || event.getPlayer().getGameMode() != GameMode.CREATIVE)
return;
if (!plugin.config.getPermissionsEnabled() || event.getPlayer().hasPermission("limitedcreative.nolimit.use")) {
if (event.getPlayer().getItemInHand() != null && plugin.config.getBlockedUse().contains(event.getPlayer().getItemInHand().getType())) {
event.setCancelled(true);
return;
}
}
Entity entity = event.getRightClicked();
if (entity instanceof StorageMinecart) {
LCPlayer.get(event.getPlayer()).onChestAccess(event);
}
}
private void register() {
pm.registerEvent(Event.Type.PLAYER_GAME_MODE_CHANGE, this, Priority.Normal, plugin);
if (plugin.config.getLimitEnabled()) {
pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, this, Priority.Normal, plugin);
pm.registerEvent(Event.Type.PLAYER_PICKUP_ITEM, this, Priority.Normal, plugin);
pm.registerEvent(Event.Type.PLAYER_INTERACT, this, Priority.Lowest, plugin);
pm.registerEvent(Event.Type.PLAYER_INTERACT_ENTITY, this, Priority.Lowest, plugin);
pm.registerEvent(Event.Type.PLAYER_RESPAWN, this, Priority.Normal, plugin);
}
}
}
public static class EntityListen extends EntityListener {
@Override
public void onEntityDamage(EntityDamageEvent meta_event) {
if (meta_event instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) meta_event;
if (event.getEntity() instanceof Player) {
LCPlayer.get((Player) event.getEntity()).onDamage(event);
}
}
}
@Override
public void onEntityDeath(EntityDeathEvent event) {
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
LCPlayer.get(player).onDie(event);
}
}
@Override
public void onItemSpawn(ItemSpawnEvent event) {
if (event.getEntity() instanceof Item) {
if (plugin.spawnblock.isBlocked(event.getLocation().getBlock().getLocation(), ((Item) event.getEntity()).getItemStack().getType())) {
event.setCancelled(true);
}
}
}
private void register() {
if (plugin.config.getLimitEnabled() || plugin.worldguard != null) {
pm.registerEvent(Event.Type.ITEM_SPAWN, this, Priority.Normal, plugin);
}
if (plugin.config.getLimitEnabled()) {
pm.registerEvent(Event.Type.ENTITY_DAMAGE, this, Priority.Normal, plugin);
pm.registerEvent(Event.Type.ENTITY_DEATH, this, Priority.Low, plugin);
}
}
}
public static class BlockListen extends BlockListener {
@Override
public void onBlockBreak(BlockBreakEvent event) {
if (event.isCancelled())
return;
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
if (!plugin.config.getPermissionsEnabled() || event.getPlayer().hasPermission("limitedcreative.nolimit.break")) {
if (plugin.config.getBlockedBreaks().contains(event.getBlock().getType())) {
event.setCancelled(true);
}
}
if (plugin.config.getPermissionsEnabled() && event.getPlayer().hasPermission("limitedcreative.nolimit.drop"))
return;
// Prevent dropping of doors and beds when destroying the wrong part
Block block = event.getBlock();
Material mat = block.getType();
switch (event.getBlock().getType()) {
case WOODEN_DOOR:
mat = Material.WOOD_DOOR;
plugin.spawnblock.block(block.getRelative(BlockFace.DOWN).getLocation(), mat);
break;
case IRON_DOOR_BLOCK:
mat = Material.IRON_DOOR;
plugin.spawnblock.block(block.getRelative(BlockFace.DOWN).getLocation(), mat);
break;
case BED_BLOCK:
mat = Material.BED;
plugin.spawnblock.block(block.getRelative(BlockFace.NORTH).getLocation(), mat);
plugin.spawnblock.block(block.getRelative(BlockFace.EAST).getLocation(), mat);
plugin.spawnblock.block(block.getRelative(BlockFace.SOUTH).getLocation(), mat);
plugin.spawnblock.block(block.getRelative(BlockFace.WEST).getLocation(), mat);
break;
default:
plugin.spawnblock.block(event.getBlock().getLocation(), mat);
}
}
}
@Override
public void onBlockPlace(BlockPlaceEvent event) {
if (event.isCancelled())
return;
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
if (!plugin.config.getPermissionsEnabled() || event.getPlayer().hasPermission("limitedcreative.nolimit.use")) {
if (plugin.config.getBlockedUse().contains(event.getBlock().getType())) {
event.setCancelled(true);
}
}
}
}
private void register() {
if (plugin.config.getLimitEnabled()) {
pm.registerEvent(Event.Type.BLOCK_BREAK, this, Priority.Normal, plugin);
pm.registerEvent(Event.Type.BLOCK_PLACE, this, Priority.Normal, plugin);
}
}
}
/*
public static class VehicleListen extends VehicleListener {
@Override
public void onVehicleDestroy(VehicleDestroyEvent event) {
if (event.isCancelled())
return;
if (event.getAttacker() instanceof Player) {
Player player = (Player) event.getAttacker();
if (player.getGameMode() == GameMode.CREATIVE) {
if (plugin.config.getPermissionsEnabled() && player.hasPermission("limitedcreative.nolimit.drop"))
return;
plugin.logger.info("Vehicle destroy: "+event.getVehicle() + " - "+event.getVehicle().getEntityId());
}
}
}
private void register() {
if (plugin.config.getLimitEnabled()) {
pm.registerEvent(Event.Type.VEHICLE_DESTROY, this, Priority.Normal, plugin);
}
}
}*/
public static void register(LimitedCreativeCore pplugin) {
plugin = pplugin;
pm = plugin.getServer().getPluginManager();
new PlayerListen().register();
new EntityListen().register();
new BlockListen().register();
//new VehicleListen().register();
}
}

View file

@ -25,10 +25,11 @@ import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
public class NoBlockItemSpawn { public class NoBlockItemSpawn {
public final static long TIME_OFFSET = 1000; public final static long TIME_OFFSET = 250;
private List<BlockItemDrop> list = new ArrayList<BlockItemDrop>(); private List<BlockItemDrop> list = new ArrayList<BlockItemDrop>();
@ -70,12 +71,14 @@ public class NoBlockItemSpawn {
} }
public void block(Block block, LCPlayer player) { public void block(Block block, LCPlayer player) {
Material mat = block.getType(); if (player.getRaw().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
if (player == null || !player.getRaw().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) { // different drop type prevention block(block.getLocation(), block.getType());
net.minecraft.server.Block type = net.minecraft.server.Block.byId[mat.getId()]; } else {
mat = Material.getMaterial(type.getDropType(block.getData(), null, 0)); // doesn't include silktouch
for (ItemStack i : block.getDrops(player.getRaw().getItemInHand())) {
block(block.getLocation(), i.getType());
}
} }
block(block.getLocation(), mat);
} }
public void block(Block block) { public void block(Block block) {

View file

@ -0,0 +1,186 @@
/*
* 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.limitedcreative.listeners;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.ContainerBlock;
import org.bukkit.block.Sign;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.StorageMinecart;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
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.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 de.jaschastarke.minecraft.limitedcreative.LCPlayer;
import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore;
import static de.jaschastarke.minecraft.utils.Locale.L;
public class LimitListener implements Listener {
private LimitedCreativeCore plugin;
public LimitListener(LimitedCreativeCore plugin) {
this.plugin = plugin;
}
@EventHandler
public void onPlayerRespawn(PlayerRespawnEvent event) {
LCPlayer.get(event.getPlayer()).onRespawn(event);
}
@EventHandler
public void onPlayerDropItem(PlayerDropItemEvent event) {
LCPlayer.get(event.getPlayer()).onDropItem(event);
}
@EventHandler
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
LCPlayer.get(event.getPlayer()).onPickupItem(event);
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (MainListener.isCancelled(event) || event.getPlayer().getGameMode() != GameMode.CREATIVE)
return;
if (!plugin.config.getPermissionsEnabled() || !event.getPlayer().hasPermission("limitedcreative.nolimit.use")) {
if (event.getItem() != null && plugin.config.getBlockedUse().contains(event.getItem().getType())) {
event.setCancelled(true);
event.setUseItemInHand(Event.Result.DENY);
event.getPlayer().sendMessage(L("blocked.use"));
return;
}
}
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
return;
Block block = event.getClickedBlock();
if (block.getState() instanceof ContainerBlock) {
LCPlayer.get(event.getPlayer()).onChestAccess(event);
}
if (block.getState() instanceof Sign) {
LCPlayer.get(event.getPlayer()).onSignAccess(event);
}
}
@EventHandler
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
if (event.isCancelled() || event.getPlayer().getGameMode() != GameMode.CREATIVE)
return;
if (!plugin.config.getPermissionsEnabled() || !event.getPlayer().hasPermission("limitedcreative.nolimit.use")) {
if (event.getPlayer().getItemInHand() != null && plugin.config.getBlockedUse().contains(event.getPlayer().getItemInHand().getType())) {
event.setCancelled(true);
event.getPlayer().sendMessage(L("blocked.use"));
return;
}
}
Entity entity = event.getRightClicked();
if (entity instanceof StorageMinecart) {
LCPlayer.get(event.getPlayer()).onChestAccess(event);
}
}
@EventHandler
public void onEntityDamage(EntityDamageEvent meta_event) {
if (meta_event instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) meta_event;
if (event.getEntity() instanceof Player) {
LCPlayer.get((Player) event.getEntity()).onDamage(event);
}
}
}
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
LCPlayer.get(player).onDie(event);
}
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
if (event.isCancelled())
return;
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
if (!plugin.config.getPermissionsEnabled() || !event.getPlayer().hasPermission("limitedcreative.nolimit.break")) {
if (plugin.config.getBlockedBreaks().contains(event.getBlock().getType())) {
event.setCancelled(true);
event.getPlayer().sendMessage(L("blocked.break"));
}
}
if (plugin.config.getPermissionsEnabled() && event.getPlayer().hasPermission("limitedcreative.nolimit.drop"))
return;
// Prevent dropping of doors and beds when destroying the wrong part
Block block = event.getBlock();
Material mat = block.getType();
switch (event.getBlock().getType()) {
case WOODEN_DOOR:
mat = Material.WOOD_DOOR;
plugin.spawnblock.block(block.getRelative(BlockFace.DOWN).getLocation(), mat);
break;
case IRON_DOOR_BLOCK:
mat = Material.IRON_DOOR;
plugin.spawnblock.block(block.getRelative(BlockFace.DOWN).getLocation(), mat);
break;
case BED_BLOCK:
mat = Material.BED;
plugin.spawnblock.block(block.getRelative(BlockFace.NORTH).getLocation(), mat);
plugin.spawnblock.block(block.getRelative(BlockFace.EAST).getLocation(), mat);
plugin.spawnblock.block(block.getRelative(BlockFace.SOUTH).getLocation(), mat);
plugin.spawnblock.block(block.getRelative(BlockFace.WEST).getLocation(), mat);
break;
default:
plugin.spawnblock.block(event.getBlock().getLocation(), mat);
}
}
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
if (event.isCancelled())
return;
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
if (!plugin.config.getPermissionsEnabled() || !event.getPlayer().hasPermission("limitedcreative.nolimit.use")) {
if (plugin.config.getBlockedUse().contains(event.getBlock().getType())) {
event.setCancelled(true);
event.getPlayer().sendMessage(L("blocked.place"));
}
}
}
}
}

View file

@ -0,0 +1,94 @@
/*
* 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.limitedcreative.listeners;
import org.bukkit.GameMode;
import org.bukkit.entity.Item;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import de.jaschastarke.minecraft.limitedcreative.LCPlayer;
import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore;
public class MainListener implements Listener {
private LimitedCreativeCore plugin;
public MainListener(LimitedCreativeCore plugin) {
this.plugin = plugin;
}
/**
* The isCancelled in PlayerInteractEvent doesn't check useItemInHand, even this decides (when clicking on
* entity with e.g. a bucket)
* @param event
* @return The relevant "isCancelled"
*/
public static boolean isCancelled(PlayerInteractEvent event) {
return event.useInteractedBlock() == Event.Result.DENY && event.useItemInHand() == Event.Result.DENY;
}
@EventHandler
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
if (event.getNewGameMode() == GameMode.CREATIVE) {
if (!LCPlayer.get(event.getPlayer()).onSetCreative())
event.setCancelled(true);
} else if (event.getNewGameMode() == GameMode.SURVIVAL) {
if (!LCPlayer.get(event.getPlayer()).onSetSurvival())
event.setCancelled(true);
}
}
/**
* Also needed if WorldGuard-Feature is enabled, so can not moved to optional Listener "Limit".
*/
@EventHandler
public void onItemSpawn(ItemSpawnEvent event) {
if (event.getEntity() instanceof Item) {
if (plugin.spawnblock.isBlocked(event.getLocation().getBlock().getLocation(), ((Item) event.getEntity()).getItemStack().getType())) {
event.setCancelled(true);
}
}
}
/*
public static class VehicleListen extends VehicleListener {
@EventHandler
public void onVehicleDestroy(VehicleDestroyEvent event) {
if (event.isCancelled())
return;
if (event.getAttacker() instanceof Player) {
Player player = (Player) event.getAttacker();
if (player.getGameMode() == GameMode.CREATIVE) {
if (plugin.config.getPermissionsEnabled() && player.hasPermission("limitedcreative.nolimit.drop"))
return;
plugin.logger.info("Vehicle destroy: "+event.getVehicle() + " - "+event.getVehicle().getEntityId());
}
}
}
private void register() {
if (plugin.config.getLimitEnabled()) {
pm.registerEvent(Event.Type.VEHICLE_DESTROY, this, Priority.Normal, plugin);
}
}
}*/
}

View file

@ -0,0 +1,12 @@
package de.jaschastarke.minecraft.limitedcreative.regions;
import com.sk89q.worldguard.protection.flags.RegionGroupFlag;
import com.sk89q.worldguard.protection.flags.StateFlag;
public final class Flags {
public static final StateFlag CREATIVE = new StateFlag("creative", false);
public static final RegionGroupFlag CREATIVE_GROUP = new RegionGroupFlag("creative-group", RegionGroupFlag.RegionGroup.MEMBERS);
static {
CREATIVE.setGroupFlag(CREATIVE_GROUP);
}
}

View file

@ -0,0 +1,97 @@
package de.jaschastarke.minecraft.limitedcreative.regions;
import static de.jaschastarke.minecraft.utils.Locale.L;
import org.bukkit.GameMode;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
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.managers.RegionManager;
import de.jaschastarke.minecraft.limitedcreative.LCPlayer;
import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore;
import de.jaschastarke.minecraft.worldguard.ApplicableRegions;
import de.jaschastarke.minecraft.worldguard.CRegionManager;
public class RegionListener implements Listener {
private static LimitedCreativeCore plugin = WorldGuardIntegration.plugin;
private static WorldGuardPlugin wg = WorldGuardIntegration.wg;
private CRegionManager rm;
public RegionListener(WorldGuardIntegration wgi) {
rm = wgi.getRegionManager();
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
if (event.isCancelled())
return;
LCPlayer player = LCPlayer.get(event.getPlayer());
RegionManager mgr = wg.getGlobalRegionManager().get(event.getPlayer().getWorld());
Vector pt = new Vector(event.getBlock().getLocation().getBlockX(), event.getBlock().getLocation().getBlockY(), event.getBlock().getLocation().getBlockZ());
ApplicableRegions set = new ApplicableRegions(mgr.getApplicableRegions(pt), rm.world(event.getPlayer().getWorld()));
if (player.isRegionCreative() && !set.allows(Flags.CREATIVE, player)) {
event.getPlayer().sendMessage(L("blocked.outside_creative_break"));
event.setCancelled(true);
} else if (set.allows(Flags.CREATIVE) && player.getRaw().getGameMode() != GameMode.CREATIVE) {
plugin.spawnblock.block(event.getBlock(), player);
}
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
if (event.isCancelled())
return;
LCPlayer player = LCPlayer.get(event.getPlayer());
if (player.isRegionCreative()) {
// do not build outside of creative regions, when in the region
RegionManager mgr = wg.getGlobalRegionManager().get(event.getPlayer().getWorld());
Vector pt = new Vector(event.getBlock().getLocation().getBlockX(), event.getBlock().getLocation().getBlockY(), event.getBlock().getLocation().getBlockZ());
ApplicableRegions set = new ApplicableRegions(mgr.getApplicableRegions(pt), rm.world(event.getPlayer().getWorld()));
if (!set.allows(Flags.CREATIVE, player)) {
event.getPlayer().sendMessage(L("blocked.outside_creative"));
event.setCancelled(true);
}
}
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
if (event.isCancelled())
return;
if (event.getFrom().getBlockX() != event.getTo().getBlockX()
|| event.getFrom().getBlockY() != event.getTo().getBlockY()
|| event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {
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()));
player.setRegionCreativeAllowed(set.allows(Flags.CREATIVE, player), event);
}
}
@EventHandler
public void onPlayerTeleport(PlayerTeleportEvent event) {
if (event.isCancelled())
return;
if (event.getFrom().getBlockX() != event.getTo().getBlockX()
|| event.getFrom().getBlockY() != event.getTo().getBlockY()
|| event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {
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()));
player.setRegionCreativeAllowed(set.allows(Flags.CREATIVE, player), event);
}
}
}

View file

@ -19,144 +19,34 @@ package de.jaschastarke.minecraft.limitedcreative.regions;
import java.io.File; import java.io.File;
import org.bukkit.GameMode;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerListener;
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.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.RegionGroupFlag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import de.jaschastarke.minecraft.limitedcreative.LCPlayer;
import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore; import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore;
import de.jaschastarke.minecraft.worldguard.ApplicableRegions;
import de.jaschastarke.minecraft.worldguard.CRegionManager; import de.jaschastarke.minecraft.worldguard.CRegionManager;
import de.jaschastarke.minecraft.worldguard.FlagList; import de.jaschastarke.minecraft.worldguard.FlagList;
import static de.jaschastarke.minecraft.utils.Locale.L;
public class WorldGuardIntegration { public class WorldGuardIntegration {
public static LimitedCreativeCore plugin; public static LimitedCreativeCore plugin;
public static WorldGuardPlugin wg; public static WorldGuardPlugin wg;
private CRegionManager rm; private CRegionManager rm;
public WorldGuardIntegration(LimitedCreativeCore pplugin) { public WorldGuardIntegration(LimitedCreativeCore plugin) {
plugin = pplugin; WorldGuardIntegration.plugin = plugin;
wg = (WorldGuardPlugin) plugin.getServer().getPluginManager().getPlugin("WorldGuard"); wg = (WorldGuardPlugin) plugin.getServer().getPluginManager().getPlugin("WorldGuard");
rm = new CRegionManager(new File(plugin.getDataFolder(), "regions.yml"));
FlagList.addFlag(Flags.CREATIVE);
FlagList.addFlag(Flags.CREATIVE_GROUP);
plugin.getServer().getPluginManager().registerEvents(new RegionListener(this), plugin);
} }
public static boolean available() { public static boolean available() {
return LimitedCreativeCore.plugin.getServer().getPluginManager().getPlugin("WorldGuard") != null; return LimitedCreativeCore.plugin.getServer().getPluginManager().getPlugin("WorldGuard") != null;
} }
public static final StateFlag CREATIVE = new StateFlag("creative", false);
public static final RegionGroupFlag CREATIVE_GROUP = new RegionGroupFlag("creative-group", RegionGroupFlag.RegionGroup.MEMBERS);
static {
CREATIVE.setGroupFlag(CREATIVE_GROUP);
}
public void init() {
rm = new CRegionManager(new File(plugin.getDataFolder(), "regions.yml"));
FlagList.addFlag(CREATIVE);
FlagList.addFlag(CREATIVE_GROUP);
new WGIPlayerListen().register();
new WGIBlockListen().register();
}
public CRegionManager getRegionManager() { public CRegionManager getRegionManager() {
return rm; return rm;
} }
public class WGIBlockListen extends BlockListener {
@Override
public void onBlockBreak(BlockBreakEvent event) {
if (event.isCancelled())
return;
LCPlayer player = LCPlayer.get(event.getPlayer());
RegionManager mgr = wg.getGlobalRegionManager().get(event.getPlayer().getWorld());
Vector pt = new Vector(event.getBlock().getLocation().getBlockX(), event.getBlock().getLocation().getBlockY(), event.getBlock().getLocation().getBlockZ());
ApplicableRegions set = new ApplicableRegions(mgr.getApplicableRegions(pt), rm.world(event.getPlayer().getWorld()));
if (player.isRegionCreative() && !set.allows(CREATIVE, player)) {
event.getPlayer().sendMessage(L("blocked.outside_creative_break"));
event.setCancelled(true);
} else if (set.allows(CREATIVE) && player.getRaw().getGameMode() != GameMode.CREATIVE) {
plugin.spawnblock.block(event.getBlock(), player);
}
}
@Override
public void onBlockPlace(BlockPlaceEvent event) {
if (event.isCancelled())
return;
LCPlayer player = LCPlayer.get(event.getPlayer());
if (player.isRegionCreative()) {
// do not build outside of creative regions, when in the region
RegionManager mgr = wg.getGlobalRegionManager().get(event.getPlayer().getWorld());
Vector pt = new Vector(event.getBlock().getLocation().getBlockX(), event.getBlock().getLocation().getBlockY(), event.getBlock().getLocation().getBlockZ());
ApplicableRegions set = new ApplicableRegions(mgr.getApplicableRegions(pt), rm.world(event.getPlayer().getWorld()));
if (!set.allows(CREATIVE, player)) {
event.getPlayer().sendMessage(L("blocked.outside_creative"));
event.setCancelled(true);
}
}
}
private void register() {
plugin.getServer().getPluginManager().registerEvent(Event.Type.BLOCK_BREAK, this, Priority.Normal, plugin);
plugin.getServer().getPluginManager().registerEvent(Event.Type.BLOCK_PLACE, this, Priority.Normal, plugin);
}
}
public class WGIPlayerListen extends PlayerListener {
@Override
public void onPlayerMove(PlayerMoveEvent event) {
if (event.isCancelled())
return;
if (event.getFrom().getBlockX() != event.getTo().getBlockX()
|| event.getFrom().getBlockY() != event.getTo().getBlockY()
|| event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {
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()));
player.setRegionCreativeAllowed(set.allows(CREATIVE, player), event);
}
}
@Override
public void onPlayerTeleport(PlayerTeleportEvent event) {
if (event.isCancelled())
return;
if (event.getFrom().getBlockX() != event.getTo().getBlockX()
|| event.getFrom().getBlockY() != event.getTo().getBlockY()
|| event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {
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()));
player.setRegionCreativeAllowed(set.allows(CREATIVE, player), event);
}
}
private void register() {
plugin.getServer().getPluginManager().registerEvent(Event.Type.PLAYER_MOVE, this, Priority.Normal, plugin);
plugin.getServer().getPluginManager().registerEvent(Event.Type.PLAYER_TELEPORT, this, Priority.Normal, plugin);
}
}
} }

View file

@ -52,9 +52,9 @@ public class Items implements Storeable {
} }
public static void sectionSetItem(ConfigurationSection section, String path, ItemStack item) { public static void sectionSetItem(ConfigurationSection section, String path, ItemStack item) {
if (!LimitedCreativeCore.serializeFallBack && !LimitedCreativeCore.plugin.config.getUnsafeStorage()) { if (!LimitedCreativeCore.plugin.config.getUnsafeStorage()) {
section.set(path, item); section.set(path, item);
} else { // compatibility fallback } else { // unsafe enchants fallback
Map<String, Object> serialize = item.serialize(); Map<String, Object> serialize = item.serialize();
if (serialize.containsKey("type") && serialize.get("type") instanceof Material) if (serialize.containsKey("type") && serialize.get("type") instanceof Material)
serialize.put("type", serialize.get("type").toString()); serialize.put("type", serialize.get("type").toString());
@ -68,8 +68,6 @@ public class Items implements Storeable {
ConfigurationSection s = section.getConfigurationSection(path); ConfigurationSection s = section.getConfigurationSection(path);
Map<String, Object> serialize = s.getValues(false); Map<String, Object> serialize = s.getValues(false);
serialize.remove("enchantments"); serialize.remove("enchantments");
if (s.contains("damage") && LimitedCreativeCore.serializeFallBack)
serialize.put("damage", new Integer(s.getInt("damage")).shortValue());
ItemStack result = ItemStack.deserialize(serialize); ItemStack result = ItemStack.deserialize(serialize);
Map<String, Object> item = section.getConfigurationSection(path).getValues(false); Map<String, Object> item = section.getConfigurationSection(path).getValues(false);
item.remove("enchantments"); item.remove("enchantments");

View file

@ -17,6 +17,7 @@
*/ */
package de.jaschastarke.minecraft.utils; package de.jaschastarke.minecraft.utils;
import java.io.File;
import java.text.MessageFormat; import java.text.MessageFormat;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@ -27,9 +28,17 @@ public class Locale {
private static Locale inst = null; private static Locale inst = null;
public Locale(JavaPlugin plugin) { public Locale(JavaPlugin plugin) {
lang = YamlConfiguration.loadConfiguration(plugin.getResource("lang/default.yml")); String fn = getFilename("default");
File localefile = new File(plugin.getDataFolder(), fn);
if (localefile.exists())
lang = YamlConfiguration.loadConfiguration(localefile);
else
lang = YamlConfiguration.loadConfiguration(plugin.getResource(fn));
inst = this; inst = this;
} }
private String getFilename(String locale) {
return "lang/"+locale+".yml";
}
public String get(String msg) { public String get(String msg) {
if (lang.contains(msg)) if (lang.contains(msg))
return lang.getString(msg); return lang.getString(msg);

View file

@ -63,7 +63,7 @@ public class CCommand implements CommandExecutor {
return false; return false;
} }
if (!sender.hasPermission("limitedcreative.regions")) { if (!sender.hasPermission("limitedcreative.regions")) {
sender.sendMessage(ChatColor.DARK_RED + "exception.command.lackingpermission"); sender.sendMessage(ChatColor.DARK_RED + L("exception.command.lackingpermission"));
return true; return true;
} }
Player player = sender instanceof Player ? (Player) sender : null; Player player = sender instanceof Player ? (Player) sender : null;
@ -117,7 +117,7 @@ public class CCommand implements CommandExecutor {
private void onInfo(CommandSender sender, Player player, CRegion region) { private void onInfo(CommandSender sender, Player player, CRegion region) {
String[] args = new String[]{"info", region.getWorld().getName(), region.getProtectedRegion().getId()}; String[] args = new String[]{"info", region.getWorld().getName(), region.getProtectedRegion().getId()};
wg.onCommand(sender, wg.getCommand("region"), "/region", args); wg.onCommand(sender, wg.getCommand("region"), "region", args);
StringBuilder list = new StringBuilder(); StringBuilder list = new StringBuilder();
for (FlagValue data : region.getFlags()) { for (FlagValue data : region.getFlags()) {