From 63991cb38d02edf6dbaf21cd16b8af8083afb4be Mon Sep 17 00:00:00 2001 From: snowleo Date: Tue, 22 Nov 2011 03:02:08 +0100 Subject: Moved all dependency on craftbukkit to one package in the main jar. The rest is now clean bukkit code. Also cleaned PlayerExtension class. --- Essentials/nbproject/project.properties | 2 +- .../com/earth2me/essentials/PlayerExtension.java | 54 ++-------------------- .../earth2me/essentials/TNTExplodeListener.java | 51 +++----------------- Essentials/src/com/earth2me/essentials/User.java | 15 ++++++ .../src/com/earth2me/essentials/UserData.java | 4 +- .../essentials/commands/Commandspawner.java | 8 ++-- .../essentials/craftbukkit/FakeExplosion.java | 51 ++++++++++++++++++++ .../essentials/craftbukkit/ShowInventory.java | 47 +++++++++++++++++++ .../earth2me/essentials/signs/SignDisposal.java | 7 +-- .../com/earth2me/essentials/signs/SignFree.java | 9 +--- EssentialsProtect/nbproject/project.properties | 6 +-- .../protect/EssentialsProtectEntityListener.java | 45 +----------------- 12 files changed, 142 insertions(+), 157 deletions(-) create mode 100644 Essentials/src/com/earth2me/essentials/craftbukkit/FakeExplosion.java create mode 100644 Essentials/src/com/earth2me/essentials/craftbukkit/ShowInventory.java diff --git a/Essentials/nbproject/project.properties b/Essentials/nbproject/project.properties index 3710d86d8..0d7673bbd 100644 --- a/Essentials/nbproject/project.properties +++ b/Essentials/nbproject/project.properties @@ -66,7 +66,7 @@ endorsed.classpath= excludes= file.reference.BOSEconomy7.jar=../lib/BOSEconomy7.jar file.reference.bPermissions.jar=../lib/bPermissions.jar -file.reference.craftbukkit-1.0.0-SNAPSHOT.jar=..\\lib\\craftbukkit-1.0.0-SNAPSHOT.jar +file.reference.craftbukkit-1.0.0-SNAPSHOT.jar=../lib/craftbukkit-1.0.0-SNAPSHOT.jar file.reference.iCo4.jar=../lib/iCo4.jar file.reference.iCo5.jar=../lib/iCo5.jar file.reference.iCo6.jar=../lib/iCo6.jar diff --git a/Essentials/src/com/earth2me/essentials/PlayerExtension.java b/Essentials/src/com/earth2me/essentials/PlayerExtension.java index aef0aeebb..7c52e40d1 100644 --- a/Essentials/src/com/earth2me/essentials/PlayerExtension.java +++ b/Essentials/src/com/earth2me/essentials/PlayerExtension.java @@ -1,12 +1,8 @@ package com.earth2me.essentials; import lombok.Delegate; -import net.minecraft.server.EntityPlayer; -import net.minecraft.server.IInventory; import org.bukkit.command.CommandSender; import org.bukkit.configuration.serialization.ConfigurationSerializable; -import org.bukkit.craftbukkit.entity.CraftPlayer; -import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer; import org.bukkit.entity.Entity; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.LivingEntity; @@ -17,21 +13,19 @@ import org.bukkit.permissions.ServerOperator; public class PlayerExtension implements Player { - protected final transient IEssentials ess; @Delegate(types = { - Player.class, Entity.class, CommandSender.class, ServerOperator.class, + Player.class, Entity.class, CommandSender.class, ServerOperator.class, HumanEntity.class, ConfigurationSerializable.class, LivingEntity.class, Permissible.class }) protected Player base; - - public PlayerExtension(final Player base, final IEssentials ess) + + public PlayerExtension(final Player base) { this.base = base; - this.ess = ess; } - + public final Player getBase() { return base; @@ -41,44 +35,4 @@ public class PlayerExtension implements Player { return this.base = base; } - - public void showInventory(final IInventory inventory) - { - getHandle().a(inventory); - } - - public void showInventory(final CraftInventoryPlayer inventory) - { - showInventory((IInventory)inventory.getInventory()); - } - - public TargetBlock getTarget() - { - return new TargetBlock(getBase()); - } - - public String getGroup() - { - return ess.getPermissionsHandler().getGroup(base); - } - - public boolean inGroup(final String group) - { - return ess.getPermissionsHandler().inGroup(base, group); - } - - public boolean canBuild() - { - return ess.getPermissionsHandler().canBuild(base, getGroup()); - } - - public EntityPlayer getHandle() - { - return getCraftPlayer().getHandle(); - } - - public CraftPlayer getCraftPlayer() - { - return (CraftPlayer)base; - } } diff --git a/Essentials/src/com/earth2me/essentials/TNTExplodeListener.java b/Essentials/src/com/earth2me/essentials/TNTExplodeListener.java index 5f207fd51..4ae259a32 100644 --- a/Essentials/src/com/earth2me/essentials/TNTExplodeListener.java +++ b/Essentials/src/com/earth2me/essentials/TNTExplodeListener.java @@ -1,31 +1,20 @@ package com.earth2me.essentials; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; -import net.minecraft.server.ChunkPosition; -import net.minecraft.server.Packet60Explosion; -import org.bukkit.Location; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.CraftWorld; +import com.earth2me.essentials.craftbukkit.FakeExplosion; import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityListener; public class TNTExplodeListener extends EntityListener implements Runnable { - private final IEssentials ess; - private boolean enabled = false; - private int timer = -1; + private final transient IEssentials ess; + private transient boolean enabled = false; + private transient int timer = -1; - public TNTExplodeListener(IEssentials ess) + public TNTExplodeListener(final IEssentials ess) { + super(); this.ess = ess; } @@ -55,33 +44,7 @@ public class TNTExplodeListener extends EntityListener implements Runnable { return; } - try - { - final Set set = new HashSet(event.blockList().size()); - final Player[] players = ess.getServer().getOnlinePlayers(); - final List blocksUnderPlayers = new ArrayList(players.length); - final Location loc = event.getLocation(); - for (Player player : players) - { - if (player.getWorld().equals(loc.getWorld())) - { - blocksUnderPlayers.add(new ChunkPosition(player.getLocation().getBlockX(), player.getLocation().getBlockY() - 1, player.getLocation().getBlockZ())); - } - } - for (Block block : event.blockList()) - { - final ChunkPosition cp = new ChunkPosition(block.getX(), block.getY(), block.getZ()); - if (!blocksUnderPlayers.contains(cp)) - { - set.add(cp); - } - } - ((CraftServer)ess.getServer()).getHandle().sendPacketNearby(loc.getX(), loc.getY(), loc.getZ(), 64.0, ((CraftWorld)loc.getWorld()).getHandle().worldProvider.dimension, new Packet60Explosion(loc.getX(), loc.getY(), loc.getZ(), 3.0F, set)); - } - catch (Throwable ex) - { - Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex); - } + FakeExplosion.createExplosion(event, ess.getServer(), ess.getServer().getOnlinePlayers()); event.setCancelled(true); } diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java index 7a4534cc7..e58cbfb50 100644 --- a/Essentials/src/com/earth2me/essentials/User.java +++ b/Essentials/src/com/earth2me/essentials/User.java @@ -515,4 +515,19 @@ public class User extends UserData implements Comparable, IReplyTo, IUser { return super.isGodModeEnabled() || (isAfk() && ess.getSettings().getFreezeAfkPlayers()); } + + public String getGroup() + { + return ess.getPermissionsHandler().getGroup(base); + } + + public boolean inGroup(final String group) + { + return ess.getPermissionsHandler().inGroup(base, group); + } + + public boolean canBuild() + { + return ess.getPermissionsHandler().canBuild(base, getGroup()); + } } diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java index 404c557ea..777ea981d 100644 --- a/Essentials/src/com/earth2me/essentials/UserData.java +++ b/Essentials/src/com/earth2me/essentials/UserData.java @@ -11,12 +11,14 @@ import org.bukkit.inventory.ItemStack; public abstract class UserData extends PlayerExtension implements IConf { + protected final transient IEssentials ess; private final EssentialsConf config; private static final Logger logger = Logger.getLogger("Minecraft"); protected UserData(Player base, IEssentials ess) { - super(base, ess); + super(base); + this.ess = ess; File folder = new File(ess.getDataFolder(), "userdata"); if (!folder.exists()) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java index dba77b5b4..e92b29a93 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java @@ -3,6 +3,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Mob; import com.earth2me.essentials.User; +import com.earth2me.essentials.Util; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Server; import org.bukkit.block.Block; @@ -25,8 +27,8 @@ public class Commandspawner extends EssentialsCommand //TODO: user.sendMessage("ยง7Mobs: Zombie PigZombie Skeleton Slime Chicken Pig Monster Spider Creeper Ghast Squid Giant Cow Sheep Wolf"); } - final Block target = user.getTarget().getTargetBlock(); - if (target.getType() != Material.MOB_SPAWNER) + final Location target = Util.getTarget(user); + if (target == null || target.getBlock().getType() != Material.MOB_SPAWNER) { throw new Exception(_("mobSpawnTarget")); } @@ -42,7 +44,7 @@ public class Commandspawner extends EssentialsCommand user.sendMessage(_("invalidMob")); return; } - ((CreatureSpawner)target.getState()).setCreatureType(mob.getType()); + ((CreatureSpawner)target.getBlock().getState()).setCreatureType(mob.getType()); user.sendMessage(_("setSpawner", mob.name)); } catch (Throwable ex) diff --git a/Essentials/src/com/earth2me/essentials/craftbukkit/FakeExplosion.java b/Essentials/src/com/earth2me/essentials/craftbukkit/FakeExplosion.java new file mode 100644 index 000000000..934d94fa2 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/craftbukkit/FakeExplosion.java @@ -0,0 +1,51 @@ +package com.earth2me.essentials.craftbukkit; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; +import net.minecraft.server.ChunkPosition; +import net.minecraft.server.Packet60Explosion; +import org.bukkit.Location; +import org.bukkit.Server; +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.entity.Player; +import org.bukkit.event.entity.EntityExplodeEvent; + + +public class FakeExplosion +{ + public static void createExplosion(final EntityExplodeEvent event, final Server server, final Player[] players) + { + try + { + final Set set = new HashSet(event.blockList().size()); + final List blocksUnderPlayers = new ArrayList(players.length); + final Location loc = event.getLocation(); + for (Player player : players) + { + if (player.getWorld().equals(loc.getWorld())) + { + blocksUnderPlayers.add(new ChunkPosition(player.getLocation().getBlockX(), player.getLocation().getBlockY() - 1, player.getLocation().getBlockZ())); + } + } + for (Block block : event.blockList()) + { + final ChunkPosition cp = new ChunkPosition(block.getX(), block.getY(), block.getZ()); + if (!blocksUnderPlayers.contains(cp)) + { + set.add(cp); + } + } + ((CraftServer)server).getHandle().sendPacketNearby(loc.getX(), loc.getY(), loc.getZ(), 64.0, ((CraftWorld)loc.getWorld()).getHandle().worldProvider.dimension, new Packet60Explosion(loc.getX(), loc.getY(), loc.getZ(), 3.0F, set)); + } + catch (Throwable ex) + { + Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex); + } + } +} diff --git a/Essentials/src/com/earth2me/essentials/craftbukkit/ShowInventory.java b/Essentials/src/com/earth2me/essentials/craftbukkit/ShowInventory.java new file mode 100644 index 000000000..f77b20208 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/craftbukkit/ShowInventory.java @@ -0,0 +1,47 @@ +package com.earth2me.essentials.craftbukkit; + +import com.earth2me.essentials.InventoryWorkaround; +import java.util.logging.Level; +import java.util.logging.Logger; +import net.minecraft.server.EntityPlayer; +import net.minecraft.server.IInventory; +import net.minecraft.server.InventoryPlayer; +import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + + +public class ShowInventory +{ + public static void showEmptyInventory(final Player player) + { + try + { + final EntityPlayer entityPlayer = ((CraftPlayer)player).getHandle(); + final CraftInventoryPlayer inv = new CraftInventoryPlayer(new InventoryPlayer(((CraftPlayer)player).getHandle())); + inv.clear(); + entityPlayer.a((IInventory)inv.getInventory()); + } + catch (Throwable ex) + { + Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex); + } + } + + public static void showFilledInventory(final Player player, final ItemStack stack) + { + try + { + final EntityPlayer entityPlayer = ((CraftPlayer)player).getHandle(); + final CraftInventoryPlayer inv = new CraftInventoryPlayer(new InventoryPlayer(((CraftPlayer)player).getHandle())); + inv.clear(); + InventoryWorkaround.addItem(inv, true, stack); + entityPlayer.a((IInventory)inv.getInventory()); + } + catch (Throwable ex) + { + Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex); + } + } +} diff --git a/Essentials/src/com/earth2me/essentials/signs/SignDisposal.java b/Essentials/src/com/earth2me/essentials/signs/SignDisposal.java index e4d050305..46272a6b8 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignDisposal.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignDisposal.java @@ -2,8 +2,7 @@ package com.earth2me.essentials.signs; import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.User; -import net.minecraft.server.InventoryPlayer; -import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer; +import com.earth2me.essentials.craftbukkit.ShowInventory; public class SignDisposal extends EssentialsSign @@ -16,9 +15,7 @@ public class SignDisposal extends EssentialsSign @Override protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) { - final CraftInventoryPlayer inv = new CraftInventoryPlayer(new InventoryPlayer(player.getHandle())); - inv.clear(); - player.showInventory(inv); + ShowInventory.showEmptyInventory(player); return true; } } diff --git a/Essentials/src/com/earth2me/essentials/signs/SignFree.java b/Essentials/src/com/earth2me/essentials/signs/SignFree.java index 3293f6467..197c0606f 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignFree.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignFree.java @@ -2,12 +2,10 @@ package com.earth2me.essentials.signs; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.InventoryWorkaround; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; -import net.minecraft.server.InventoryPlayer; +import com.earth2me.essentials.craftbukkit.ShowInventory; import org.bukkit.Material; -import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer; import org.bukkit.inventory.ItemStack; @@ -35,10 +33,7 @@ public class SignFree extends EssentialsSign } item.setAmount(item.getType().getMaxStackSize() * 9 * 4); - final CraftInventoryPlayer inv = new CraftInventoryPlayer(new InventoryPlayer(player.getHandle())); - inv.clear(); - InventoryWorkaround.addItem(inv, true, item); - player.showInventory(inv); + ShowInventory.showFilledInventory(player, item); Trade.log("Sign", "Free", "Interact", username, null, username, new Trade(item, ess), sign.getBlock().getLocation(), ess); return true; } diff --git a/EssentialsProtect/nbproject/project.properties b/EssentialsProtect/nbproject/project.properties index d0bbb3ce2..5e8639402 100644 --- a/EssentialsProtect/nbproject/project.properties +++ b/EssentialsProtect/nbproject/project.properties @@ -63,16 +63,16 @@ dist.jar=${dist.dir}/original-EssentialsProtect.jar dist.javadoc.dir=${dist.dir}/javadoc endorsed.classpath= excludes= +file.reference.bukkit-1.0.0-R1-SNAPSHOT.jar=../lib/bukkit-1.0.0-R1-SNAPSHOT.jar file.reference.c3p0-0.9.1.2.jar=..\\lib\\c3p0-0.9.1.2.jar -file.reference.craftbukkit-1.0.0-SNAPSHOT.jar=..\\lib\\craftbukkit-1.0.0-SNAPSHOT.jar includes=** jar.archive.disabled=${jnlp.enabled} jar.compress=true jar.index=${jnlp.enabled} javac.classpath=\ ${reference.Essentials.jar}:\ - ${file.reference.craftbukkit-1.0.0-SNAPSHOT.jar}:\ - ${file.reference.c3p0-0.9.1.2.jar} + ${file.reference.c3p0-0.9.1.2.jar}:\ + ${file.reference.bukkit-1.0.0-R1-SNAPSHOT.jar} # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java index b0a6b8521..2c4d1dbab 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java @@ -2,19 +2,11 @@ package com.earth2me.essentials.protect; import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.User; -import java.util.HashSet; +import com.earth2me.essentials.craftbukkit.FakeExplosion; import java.util.Locale; -import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; -import net.minecraft.server.ChunkPosition; -import net.minecraft.server.Packet60Explosion; -import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.entity.*; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityTargetEvent.TargetReason; @@ -204,40 +196,7 @@ public class EssentialsProtectEntityListener extends EntityListener || prot.getSettingBool(ProtectConfig.prevent_creeper_blockdmg) || (maxHeight >= 0 && event.getLocation().getBlockY() > maxHeight))) { - try - { - final Set set = new HashSet(event.blockList().size()); - final Player[] players = ess.getServer().getOnlinePlayers(); - final Set blocksUnderPlayers = new HashSet(players.length); - final Location loc = event.getLocation(); - for (Player player : players) - { - if (player.getWorld().equals(loc.getWorld())) - { - blocksUnderPlayers.add( - new ChunkPosition( - player.getLocation().getBlockX(), - player.getLocation().getBlockY() - 1, - player.getLocation().getBlockZ())); - } - } - ChunkPosition cp; - for (Block block : event.blockList()) - { - cp = new ChunkPosition(block.getX(), block.getY(), block.getZ()); - if (!blocksUnderPlayers.contains(cp)) - { - set.add(cp); - } - } - - ((CraftServer)ess.getServer()).getHandle().sendPacketNearby(loc.getX(), loc.getY(), loc.getZ(), 64.0D, ((CraftWorld)loc.getWorld()).getHandle().worldProvider.dimension, - new Packet60Explosion(loc.getX(), loc.getY(), loc.getZ(), 3.0f, set)); - } - catch (Throwable ex) - { - Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex); - } + FakeExplosion.createExplosion(event, ess.getServer(), ess.getServer().getOnlinePlayers()); event.setCancelled(true); return; } -- cgit v1.2.3