mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-30 17:59:53 +02:00
Events WIP
This commit is contained in:
22
Essentials/src/net/ess3/api/ondemand/OnDemand.java
Normal file
22
Essentials/src/net/ess3/api/ondemand/OnDemand.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package net.ess3.api.ondemand;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
|
|
||||||
|
public abstract class OnDemand<T>
|
||||||
|
{
|
||||||
|
protected WeakReference<T> reference = null;
|
||||||
|
|
||||||
|
public final T get()
|
||||||
|
{
|
||||||
|
T obj = reference == null ? null : reference.get();
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
obj = getNew();
|
||||||
|
reference = new WeakReference<T>(obj);
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract T getNew();
|
||||||
|
}
|
29
Essentials/src/net/ess3/api/ondemand/UserOnDemand.java
Normal file
29
Essentials/src/net/ess3/api/ondemand/UserOnDemand.java
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package net.ess3.api.ondemand;
|
||||||
|
|
||||||
|
import net.ess3.api.IUser;
|
||||||
|
import net.ess3.api.server.Player;
|
||||||
|
import net.ess3.api.server.Server;
|
||||||
|
|
||||||
|
|
||||||
|
public class UserOnDemand extends OnDemand<IUser>
|
||||||
|
{
|
||||||
|
private final String name;
|
||||||
|
private final Server server;
|
||||||
|
|
||||||
|
public UserOnDemand(String name, Server server)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
this.server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected IUser getNew()
|
||||||
|
{
|
||||||
|
Player player = server.getPlayer(name);
|
||||||
|
if (player == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return player.getUser();
|
||||||
|
}
|
||||||
|
}
|
24
Essentials/src/net/ess3/api/server/Block.java
Normal file
24
Essentials/src/net/ess3/api/server/Block.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package net.ess3.api.server;
|
||||||
|
|
||||||
|
import lombok.Delegate;
|
||||||
|
|
||||||
|
public class Block {
|
||||||
|
|
||||||
|
public Block(ItemStack stack, Location location)
|
||||||
|
{
|
||||||
|
this.stack = stack;
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Delegate
|
||||||
|
private final ItemStack stack;
|
||||||
|
@Delegate
|
||||||
|
private final Location location;
|
||||||
|
|
||||||
|
public ItemStack convertToItem()
|
||||||
|
{
|
||||||
|
final ItemStack is = ItemStack.create(this.getType(), 1, this.getDurability());
|
||||||
|
return this.getType().convertToItem(is);
|
||||||
|
}
|
||||||
|
}
|
@@ -27,12 +27,18 @@ public abstract class ItemStack implements Cloneable
|
|||||||
|
|
||||||
public abstract Material getType();
|
public abstract Material getType();
|
||||||
|
|
||||||
|
public abstract void setType(Material mat);
|
||||||
|
|
||||||
|
public abstract void setType(int id);
|
||||||
|
|
||||||
public abstract int getAmount();
|
public abstract int getAmount();
|
||||||
|
|
||||||
public abstract void setAmount(int value);
|
public abstract void setAmount(int value);
|
||||||
|
|
||||||
public abstract short getDurability();
|
public abstract short getDurability();
|
||||||
|
|
||||||
|
public abstract void setDurability(short value);
|
||||||
|
|
||||||
public abstract int getMaxStackSize();
|
public abstract int getMaxStackSize();
|
||||||
|
|
||||||
public abstract boolean isAir();
|
public abstract boolean isAir();
|
||||||
|
@@ -34,4 +34,6 @@ public abstract class Material {
|
|||||||
public abstract int getMaxDurability();
|
public abstract int getMaxDurability();
|
||||||
|
|
||||||
protected abstract Material matchMaterial(String string);
|
protected abstract Material matchMaterial(String string);
|
||||||
|
|
||||||
|
public abstract ItemStack convertToItem(ItemStack is);
|
||||||
}
|
}
|
||||||
|
@@ -58,4 +58,6 @@ public interface Player extends CommandSender
|
|||||||
void setCompassTarget(Location loc);
|
void setCompassTarget(Location loc);
|
||||||
|
|
||||||
void damage(int value);
|
void damage(int value);
|
||||||
|
|
||||||
|
boolean isInSurvivalMode();
|
||||||
}
|
}
|
||||||
|
@@ -34,4 +34,6 @@ public interface Plugin
|
|||||||
void callSuicideEvent(Player player);
|
void callSuicideEvent(Player player);
|
||||||
|
|
||||||
Logger getLogger();
|
Logger getLogger();
|
||||||
|
|
||||||
|
Server getServer();
|
||||||
}
|
}
|
||||||
|
@@ -25,4 +25,6 @@ public interface Server
|
|||||||
String getVersion();
|
String getVersion();
|
||||||
|
|
||||||
public void unbanIP(String string);
|
public void unbanIP(String string);
|
||||||
|
|
||||||
|
public Player getPlayer(String name);
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,7 @@
|
|||||||
|
package net.ess3.api.server.events;
|
||||||
|
|
||||||
|
|
||||||
|
public interface EventFactory
|
||||||
|
{
|
||||||
|
public void register(EventListener listener, EventType type, EventPriority priority, boolean ignoreCancelled);
|
||||||
|
}
|
21
Essentials/src/net/ess3/api/server/events/EventListener.java
Normal file
21
Essentials/src/net/ess3/api/server/events/EventListener.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package net.ess3.api.server.events;
|
||||||
|
|
||||||
|
import net.ess3.api.IUser;
|
||||||
|
import net.ess3.api.ondemand.OnDemand;
|
||||||
|
import net.ess3.api.server.Block;
|
||||||
|
|
||||||
|
|
||||||
|
public abstract class EventListener
|
||||||
|
{
|
||||||
|
private static EventFactory eventFactory;
|
||||||
|
|
||||||
|
public final void register(EventType type, EventPriority priority, boolean ignoreCancelled)
|
||||||
|
{
|
||||||
|
eventFactory.register(this, type, priority, ignoreCancelled);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onBlockPlace(Block block, OnDemand<IUser> user)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
12
Essentials/src/net/ess3/api/server/events/EventPriority.java
Normal file
12
Essentials/src/net/ess3/api/server/events/EventPriority.java
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package net.ess3.api.server.events;
|
||||||
|
|
||||||
|
|
||||||
|
public enum EventPriority
|
||||||
|
{
|
||||||
|
LOWEST,
|
||||||
|
LOW,
|
||||||
|
NORMAL,
|
||||||
|
HIGH,
|
||||||
|
HIGHEST,
|
||||||
|
MONITOR
|
||||||
|
}
|
7
Essentials/src/net/ess3/api/server/events/EventType.java
Normal file
7
Essentials/src/net/ess3/api/server/events/EventType.java
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package net.ess3.api.server.events;
|
||||||
|
|
||||||
|
|
||||||
|
public enum EventType
|
||||||
|
{
|
||||||
|
PLACE_BLOCK
|
||||||
|
}
|
13
Essentials/src/net/ess3/bukkit/BukkitBlockFactory.java
Normal file
13
Essentials/src/net/ess3/bukkit/BukkitBlockFactory.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package net.ess3.bukkit;
|
||||||
|
|
||||||
|
import net.ess3.api.server.Block;
|
||||||
|
import net.ess3.api.server.ItemStack;
|
||||||
|
import net.ess3.api.server.Location;
|
||||||
|
|
||||||
|
public class BukkitBlockFactory {
|
||||||
|
|
||||||
|
public static Block convert(org.bukkit.block.Block block) {
|
||||||
|
Location loc = Location.create(block.getWorld().getName(), block.getX(), block.getY(), block.getZ());
|
||||||
|
return new Block(ItemStack.create(block.getTypeId(), 1, block.getData()), loc);
|
||||||
|
}
|
||||||
|
}
|
@@ -54,6 +54,18 @@ public class BukkitItemStack extends net.ess3.api.server.ItemStack
|
|||||||
return Material.get(itemStack.getTypeId());
|
return Material.get(itemStack.getTypeId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setType(Material type)
|
||||||
|
{
|
||||||
|
itemStack.setTypeId(type.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setType(int id)
|
||||||
|
{
|
||||||
|
itemStack.setTypeId(id);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAir()
|
public boolean isAir()
|
||||||
{
|
{
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
package net.ess3.bukkit;
|
package net.ess3.bukkit;
|
||||||
|
|
||||||
import net.ess3.api.server.Material;
|
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import lombok.Delegate;
|
import lombok.Delegate;
|
||||||
|
import net.ess3.api.server.ItemStack;
|
||||||
|
import net.ess3.api.server.Material;
|
||||||
|
|
||||||
|
|
||||||
public class BukkitMaterial extends Material
|
public class BukkitMaterial extends Material
|
||||||
@@ -16,6 +17,7 @@ public class BukkitMaterial extends Material
|
|||||||
materials.put(material, new BukkitMaterial(material));
|
materials.put(material, new BukkitMaterial(material));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private interface Excludes {
|
private interface Excludes {
|
||||||
short getMaxDurability();
|
short getMaxDurability();
|
||||||
}
|
}
|
||||||
@@ -59,4 +61,86 @@ public class BukkitMaterial extends Material
|
|||||||
{
|
{
|
||||||
return (short)this.material.getMaxDurability();
|
return (short)this.material.getMaxDurability();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack convertToItem(ItemStack is)
|
||||||
|
{
|
||||||
|
switch (org.bukkit.Material.getMaterial(is.getType().getId()))
|
||||||
|
{
|
||||||
|
case WOODEN_DOOR:
|
||||||
|
is.setType(org.bukkit.Material.WOOD_DOOR.getId());
|
||||||
|
is.setDurability((short)0);
|
||||||
|
break;
|
||||||
|
case IRON_DOOR_BLOCK:
|
||||||
|
is.setType(org.bukkit.Material.IRON_DOOR.getId());
|
||||||
|
is.setDurability((short)0);
|
||||||
|
break;
|
||||||
|
case SIGN_POST:
|
||||||
|
case WALL_SIGN:
|
||||||
|
is.setType(org.bukkit.Material.SIGN.getId());
|
||||||
|
is.setDurability((short)0);
|
||||||
|
break;
|
||||||
|
case CROPS:
|
||||||
|
is.setType(org.bukkit.Material.SEEDS.getId());
|
||||||
|
is.setDurability((short)0);
|
||||||
|
break;
|
||||||
|
case CAKE_BLOCK:
|
||||||
|
is.setType(org.bukkit.Material.CAKE.getId());
|
||||||
|
is.setDurability((short)0);
|
||||||
|
break;
|
||||||
|
case BED_BLOCK:
|
||||||
|
is.setType(org.bukkit.Material.BED.getId());
|
||||||
|
is.setDurability((short)0);
|
||||||
|
break;
|
||||||
|
case REDSTONE_WIRE:
|
||||||
|
is.setType(org.bukkit.Material.REDSTONE.getId());
|
||||||
|
is.setDurability((short)0);
|
||||||
|
break;
|
||||||
|
case REDSTONE_TORCH_OFF:
|
||||||
|
case REDSTONE_TORCH_ON:
|
||||||
|
is.setType(org.bukkit.Material.REDSTONE_TORCH_ON.getId());
|
||||||
|
is.setDurability((short)0);
|
||||||
|
break;
|
||||||
|
case DIODE_BLOCK_OFF:
|
||||||
|
case DIODE_BLOCK_ON:
|
||||||
|
is.setType(org.bukkit.Material.DIODE.getId());
|
||||||
|
is.setDurability((short)0);
|
||||||
|
break;
|
||||||
|
case DOUBLE_STEP:
|
||||||
|
is.setType(org.bukkit.Material.STEP.getId());
|
||||||
|
break;
|
||||||
|
case TORCH:
|
||||||
|
case RAILS:
|
||||||
|
case LADDER:
|
||||||
|
case WOOD_STAIRS:
|
||||||
|
case COBBLESTONE_STAIRS:
|
||||||
|
case LEVER:
|
||||||
|
case STONE_BUTTON:
|
||||||
|
case FURNACE:
|
||||||
|
case DISPENSER:
|
||||||
|
case PUMPKIN:
|
||||||
|
case JACK_O_LANTERN:
|
||||||
|
case WOOD_PLATE:
|
||||||
|
case STONE_PLATE:
|
||||||
|
case PISTON_STICKY_BASE:
|
||||||
|
case PISTON_BASE:
|
||||||
|
case IRON_FENCE:
|
||||||
|
case THIN_GLASS:
|
||||||
|
case TRAP_DOOR:
|
||||||
|
case FENCE:
|
||||||
|
case FENCE_GATE:
|
||||||
|
case NETHER_FENCE:
|
||||||
|
is.setDurability((short)0);
|
||||||
|
break;
|
||||||
|
case FIRE:
|
||||||
|
return null;
|
||||||
|
case PUMPKIN_STEM:
|
||||||
|
is.setType(org.bukkit.Material.PUMPKIN_SEEDS.getId());
|
||||||
|
break;
|
||||||
|
case MELON_STEM:
|
||||||
|
is.setType(org.bukkit.Material.MELON_SEEDS.getId());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return is;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,8 +7,8 @@ import net.ess3.api.server.IInventory;
|
|||||||
import net.ess3.api.server.Location;
|
import net.ess3.api.server.Location;
|
||||||
import net.ess3.api.server.Player;
|
import net.ess3.api.server.Player;
|
||||||
import net.ess3.api.server.World;
|
import net.ess3.api.server.World;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.LivingEntity;
|
|
||||||
|
|
||||||
|
|
||||||
public class BukkitPlayer extends BukkitCommandSender implements Player
|
public class BukkitPlayer extends BukkitCommandSender implements Player
|
||||||
@@ -33,7 +33,7 @@ public class BukkitPlayer extends BukkitCommandSender implements Player
|
|||||||
}
|
}
|
||||||
@Delegate(types =
|
@Delegate(types =
|
||||||
{
|
{
|
||||||
org.bukkit.entity.Player.class, LivingEntity.class
|
org.bukkit.entity.Player.class, org.bukkit.entity.LivingEntity.class
|
||||||
}, excludes =
|
}, excludes =
|
||||||
{
|
{
|
||||||
OfflinePlayer.class, org.bukkit.command.CommandSender.class, Excludes.class
|
OfflinePlayer.class, org.bukkit.command.CommandSender.class, Excludes.class
|
||||||
@@ -50,6 +50,7 @@ public class BukkitPlayer extends BukkitCommandSender implements Player
|
|||||||
@Getter
|
@Getter
|
||||||
private transient OfflinePlayer safePlayer;
|
private transient OfflinePlayer safePlayer;
|
||||||
private final transient BukkitServer server;
|
private final transient BukkitServer server;
|
||||||
|
private transient IUser user = null;
|
||||||
|
|
||||||
public BukkitPlayer(final OfflinePlayer player, final BukkitServer server)
|
public BukkitPlayer(final OfflinePlayer player, final BukkitServer server)
|
||||||
{
|
{
|
||||||
@@ -85,7 +86,7 @@ public class BukkitPlayer extends BukkitCommandSender implements Player
|
|||||||
@Override
|
@Override
|
||||||
public IUser getUser()
|
public IUser getUser()
|
||||||
{
|
{
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -202,4 +203,11 @@ public class BukkitPlayer extends BukkitCommandSender implements Player
|
|||||||
{
|
{
|
||||||
onlinePlayer.setCompassTarget(((BukkitLocation)loc).getBukkitLocation());
|
onlinePlayer.setCompassTarget(((BukkitLocation)loc).getBukkitLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isInSurvivalMode()
|
||||||
|
{
|
||||||
|
return onlinePlayer.getGameMode() == GameMode.SURVIVAL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,6 +5,8 @@ import net.ess3.api.server.Plugin;
|
|||||||
import net.ess3.api.server.Location;
|
import net.ess3.api.server.Location;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import lombok.Delegate;
|
import lombok.Delegate;
|
||||||
|
import lombok.Getter;
|
||||||
|
import net.ess3.api.server.Server;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
import org.bukkit.plugin.java.JavaPluginLoader;
|
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||||
@@ -12,66 +14,73 @@ import org.bukkit.plugin.java.JavaPluginLoader;
|
|||||||
|
|
||||||
public class BukkitPlugin implements Plugin
|
public class BukkitPlugin implements Plugin
|
||||||
{
|
{
|
||||||
@Delegate
|
private interface Excludes {
|
||||||
private final org.bukkit.plugin.Plugin plugin;
|
public org.bukkit.Server getServer();
|
||||||
|
}
|
||||||
|
@Delegate(excludes={Excludes.class})
|
||||||
|
@Getter
|
||||||
|
private final org.bukkit.plugin.Plugin bukkitPlugin;
|
||||||
|
@Getter
|
||||||
|
private final Server server;
|
||||||
|
|
||||||
public BukkitPlugin(final org.bukkit.plugin.Plugin plugin)
|
public BukkitPlugin(final org.bukkit.plugin.Plugin plugin, final Server server)
|
||||||
{
|
{
|
||||||
this.plugin = plugin;
|
this.bukkitPlugin = plugin;
|
||||||
|
this.server = server;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int scheduleAsyncDelayedTask(final Runnable run)
|
public int scheduleAsyncDelayedTask(final Runnable run)
|
||||||
{
|
{
|
||||||
return plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, run);
|
return bukkitPlugin.getServer().getScheduler().scheduleAsyncDelayedTask(bukkitPlugin, run);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int scheduleSyncDelayedTask(final Runnable run)
|
public int scheduleSyncDelayedTask(final Runnable run)
|
||||||
{
|
{
|
||||||
return plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, run);
|
return bukkitPlugin.getServer().getScheduler().scheduleSyncDelayedTask(bukkitPlugin, run);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int scheduleSyncDelayedTask(final Runnable run, final long delay)
|
public int scheduleSyncDelayedTask(final Runnable run, final long delay)
|
||||||
{
|
{
|
||||||
return plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, run, delay);
|
return bukkitPlugin.getServer().getScheduler().scheduleSyncDelayedTask(bukkitPlugin, run, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int scheduleSyncRepeatingTask(final Runnable run, final long delay, final long period)
|
public int scheduleSyncRepeatingTask(final Runnable run, final long delay, final long period)
|
||||||
{
|
{
|
||||||
return plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, run, delay, period);
|
return bukkitPlugin.getServer().getScheduler().scheduleSyncRepeatingTask(bukkitPlugin, run, delay, period);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int scheduleAsyncRepeatingTask(final Runnable run, final long delay, final long period)
|
public int scheduleAsyncRepeatingTask(final Runnable run, final long delay, final long period)
|
||||||
{
|
{
|
||||||
return plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, run, delay, period);
|
return bukkitPlugin.getServer().getScheduler().scheduleAsyncRepeatingTask(bukkitPlugin, run, delay, period);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getRootFolder()
|
public File getRootFolder()
|
||||||
{
|
{
|
||||||
return plugin.getDataFolder().getParentFile().getParentFile();
|
return bukkitPlugin.getDataFolder().getParentFile().getParentFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cancelTask(final int taskId)
|
public void cancelTask(final int taskId)
|
||||||
{
|
{
|
||||||
plugin.getServer().getScheduler().cancelTask(taskId);
|
bukkitPlugin.getServer().getScheduler().cancelTask(taskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getVersion()
|
public String getVersion()
|
||||||
{
|
{
|
||||||
return plugin.getDescription().getVersion();
|
return bukkitPlugin.getDescription().getVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class getClassByName(final String name)
|
public Class getClassByName(final String name)
|
||||||
{
|
{
|
||||||
final JavaPluginLoader jpl = (JavaPluginLoader)plugin.getPluginLoader();
|
final JavaPluginLoader jpl = (JavaPluginLoader)bukkitPlugin.getPluginLoader();
|
||||||
return jpl.getClassByName(name);
|
return jpl.getClassByName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +88,7 @@ public class BukkitPlugin implements Plugin
|
|||||||
public Location callRespawnEvent(Player player, Location loc, boolean bedSpawn)
|
public Location callRespawnEvent(Player player, Location loc, boolean bedSpawn)
|
||||||
{
|
{
|
||||||
final PlayerRespawnEvent pre = new PlayerRespawnEvent(((BukkitPlayer)player).getOnlinePlayer(), ((BukkitLocation)loc).getBukkitLocation() , bedSpawn);
|
final PlayerRespawnEvent pre = new PlayerRespawnEvent(((BukkitPlayer)player).getOnlinePlayer(), ((BukkitLocation)loc).getBukkitLocation() , bedSpawn);
|
||||||
getServer().getPluginManager().callEvent(pre);
|
getBukkitServer().getPluginManager().callEvent(pre);
|
||||||
return new BukkitLocation(pre.getRespawnLocation());
|
return new BukkitLocation(pre.getRespawnLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +96,11 @@ public class BukkitPlugin implements Plugin
|
|||||||
public void callSuicideEvent(Player player)
|
public void callSuicideEvent(Player player)
|
||||||
{
|
{
|
||||||
EntityDamageEvent ede = new EntityDamageEvent(((BukkitPlayer)player).getOnlinePlayer(), EntityDamageEvent.DamageCause.SUICIDE, 1000);
|
EntityDamageEvent ede = new EntityDamageEvent(((BukkitPlayer)player).getOnlinePlayer(), EntityDamageEvent.DamageCause.SUICIDE, 1000);
|
||||||
getServer().getPluginManager().callEvent(ede);
|
getBukkitServer().getPluginManager().callEvent(ede);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public org.bukkit.Server getBukkitServer()
|
||||||
|
{
|
||||||
|
return bukkitPlugin.getServer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -30,6 +30,8 @@ public class BukkitServer implements Server, Listener
|
|||||||
org.bukkit.entity.Player[] getOnlinePlayers();
|
org.bukkit.entity.Player[] getOnlinePlayers();
|
||||||
|
|
||||||
BukkitCommandSender getConsoleSender();
|
BukkitCommandSender getConsoleSender();
|
||||||
|
|
||||||
|
org.bukkit.entity.Player getPlayer(String name);
|
||||||
}
|
}
|
||||||
@Delegate(excludes = Excludes.class)
|
@Delegate(excludes = Excludes.class)
|
||||||
private final org.bukkit.Server server;
|
private final org.bukkit.Server server;
|
||||||
@@ -81,6 +83,7 @@ public class BukkitServer implements Server, Listener
|
|||||||
{
|
{
|
||||||
final HashMap<String, Player> oplayersMap = new HashMap<String, Player>(onlinePlayersMap);
|
final HashMap<String, Player> oplayersMap = new HashMap<String, Player>(onlinePlayersMap);
|
||||||
BukkitPlayer p = new BukkitPlayer(event.getPlayer(), this);
|
BukkitPlayer p = new BukkitPlayer(event.getPlayer(), this);
|
||||||
|
|
||||||
oplayersMap.put(event.getPlayer().getName(), p);
|
oplayersMap.put(event.getPlayer().getName(), p);
|
||||||
onlinePlayersMap = Collections.unmodifiableMap(oplayersMap);
|
onlinePlayersMap = Collections.unmodifiableMap(oplayersMap);
|
||||||
onlinePlayers = Collections.unmodifiableCollection(oplayersMap.values());
|
onlinePlayers = Collections.unmodifiableCollection(oplayersMap.values());
|
||||||
@@ -121,6 +124,11 @@ public class BukkitServer implements Server, Listener
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Player getPlayer(final org.bukkit.entity.Player player) {
|
public Player getPlayer(final org.bukkit.entity.Player player) {
|
||||||
return onlinePlayersMap.get(player);
|
return onlinePlayersMap.get(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Player getPlayer(final String playerName) {
|
||||||
|
return onlinePlayersMap.get(playerName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,11 +1,10 @@
|
|||||||
package net.ess3.bukkit;
|
package net.ess3.bukkit;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import net.ess3.api.server.World;
|
|
||||||
import net.ess3.api.server.ItemStack;
|
|
||||||
import net.ess3.api.server.Location;
|
|
||||||
import lombok.Delegate;
|
import lombok.Delegate;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import net.ess3.api.server.ItemStack;
|
||||||
|
import net.ess3.api.server.Location;
|
||||||
|
import net.ess3.api.server.World;
|
||||||
import org.bukkit.TreeType;
|
import org.bukkit.TreeType;
|
||||||
|
|
||||||
public class BukkitWorld implements World {
|
public class BukkitWorld implements World {
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
package net.ess3.bukkit;
|
package net.ess3.bukkit;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
import net.ess3.Essentials;
|
import net.ess3.Essentials;
|
||||||
import static net.ess3.I18n._;
|
import static net.ess3.I18n._;
|
||||||
import net.ess3.api.server.*;
|
import net.ess3.api.server.*;
|
||||||
import java.util.logging.Level;
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@@ -33,7 +33,7 @@ public class EssentialsPlugin extends JavaPlugin
|
|||||||
BukkitServer server = new BukkitServer(getServer());
|
BukkitServer server = new BukkitServer(getServer());
|
||||||
final PluginManager pm = this.getServer().getPluginManager();
|
final PluginManager pm = this.getServer().getPluginManager();
|
||||||
pm.registerEvents(server, this);
|
pm.registerEvents(server, this);
|
||||||
ess = new Essentials(server, getLogger(), new BukkitPlugin(this));
|
ess = new Essentials(server, getLogger(), new BukkitPlugin(this, server));
|
||||||
if (VersionCheck.checkVersion(this))
|
if (VersionCheck.checkVersion(this))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
21
Essentials/src/net/ess3/bukkit/events/BaseEventExecutor.java
Normal file
21
Essentials/src/net/ess3/bukkit/events/BaseEventExecutor.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package net.ess3.bukkit.events;
|
||||||
|
|
||||||
|
import net.ess3.api.server.events.EventListener;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.EventException;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.plugin.EventExecutor;
|
||||||
|
|
||||||
|
|
||||||
|
public abstract class BaseEventExecutor implements EventExecutor
|
||||||
|
{
|
||||||
|
protected final EventListener listener;
|
||||||
|
|
||||||
|
public BaseEventExecutor(final EventListener listener)
|
||||||
|
{
|
||||||
|
this.listener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract void execute(Listener ll, Event event) throws EventException;
|
||||||
|
}
|
@@ -0,0 +1,25 @@
|
|||||||
|
package net.ess3.bukkit.events;
|
||||||
|
|
||||||
|
import net.ess3.api.server.Plugin;
|
||||||
|
import net.ess3.api.server.events.EventFactory;
|
||||||
|
import net.ess3.api.server.events.EventListener;
|
||||||
|
import net.ess3.api.server.events.EventPriority;
|
||||||
|
import net.ess3.api.server.events.EventType;
|
||||||
|
|
||||||
|
|
||||||
|
public class BukkitEventFactory implements EventFactory
|
||||||
|
{
|
||||||
|
private Plugin plugin;
|
||||||
|
|
||||||
|
public BukkitEventFactory(Plugin plugin)
|
||||||
|
{
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void register(EventListener listener, EventType type, EventPriority priority, boolean ignoreCancelled)
|
||||||
|
{
|
||||||
|
BukkitListener bukkitListener = new BukkitListener(plugin);
|
||||||
|
bukkitListener.register(listener, type, priority, ignoreCancelled);
|
||||||
|
}
|
||||||
|
}
|
70
Essentials/src/net/ess3/bukkit/events/BukkitListener.java
Normal file
70
Essentials/src/net/ess3/bukkit/events/BukkitListener.java
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
package net.ess3.bukkit.events;
|
||||||
|
|
||||||
|
import net.ess3.api.server.Plugin;
|
||||||
|
import net.ess3.api.server.events.EventListener;
|
||||||
|
import net.ess3.api.server.events.EventPriority;
|
||||||
|
import net.ess3.api.server.events.EventType;
|
||||||
|
import net.ess3.bukkit.BukkitPlugin;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
|
import org.bukkit.plugin.EventExecutor;
|
||||||
|
|
||||||
|
|
||||||
|
public class BukkitListener implements Listener
|
||||||
|
{
|
||||||
|
private Plugin plugin;
|
||||||
|
|
||||||
|
public BukkitListener(final Plugin plugin)
|
||||||
|
{
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void register(EventListener listener, EventType type, EventPriority priority, boolean ignoreCancelled)
|
||||||
|
{
|
||||||
|
Class<? extends Event> event = getEventClass(type);
|
||||||
|
org.bukkit.event.EventPriority bukkitPriority = getEventPriority(priority);
|
||||||
|
EventExecutor executor = getEventExecutor(type, listener);
|
||||||
|
((BukkitPlugin)plugin).getBukkitServer().getPluginManager().registerEvent(event, this, bukkitPriority, executor, ((BukkitPlugin)plugin).getBukkitPlugin(), ignoreCancelled);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class<? extends Event> getEventClass(final EventType type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case PLACE_BLOCK:
|
||||||
|
return BlockPlaceEvent.class;
|
||||||
|
}
|
||||||
|
throw new RuntimeException("Missing Event Class");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static org.bukkit.event.EventPriority getEventPriority(final EventPriority priority)
|
||||||
|
{
|
||||||
|
switch (priority)
|
||||||
|
{
|
||||||
|
case LOWEST:
|
||||||
|
return org.bukkit.event.EventPriority.LOWEST;
|
||||||
|
case LOW:
|
||||||
|
return org.bukkit.event.EventPriority.LOW;
|
||||||
|
case NORMAL:
|
||||||
|
return org.bukkit.event.EventPriority.NORMAL;
|
||||||
|
case HIGH:
|
||||||
|
return org.bukkit.event.EventPriority.HIGH;
|
||||||
|
case HIGHEST:
|
||||||
|
return org.bukkit.event.EventPriority.HIGHEST;
|
||||||
|
case MONITOR:
|
||||||
|
return org.bukkit.event.EventPriority.MONITOR;
|
||||||
|
}
|
||||||
|
throw new RuntimeException("Missing Event Priority");
|
||||||
|
}
|
||||||
|
|
||||||
|
private EventExecutor getEventExecutor(final EventType type, final EventListener listener)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case PLACE_BLOCK:
|
||||||
|
return new PlaceBlockExecutor(listener, plugin.getServer());
|
||||||
|
}
|
||||||
|
throw new RuntimeException("Missing Event Executor");
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,31 @@
|
|||||||
|
package net.ess3.bukkit.events;
|
||||||
|
|
||||||
|
import net.ess3.api.ondemand.UserOnDemand;
|
||||||
|
import net.ess3.api.server.Block;
|
||||||
|
import net.ess3.api.server.Server;
|
||||||
|
import net.ess3.api.server.events.EventListener;
|
||||||
|
import net.ess3.bukkit.BukkitBlockFactory;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.EventException;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
|
|
||||||
|
|
||||||
|
public class PlaceBlockExecutor extends BaseEventExecutor
|
||||||
|
{
|
||||||
|
private final Server server;
|
||||||
|
public PlaceBlockExecutor(EventListener listener, Server server)
|
||||||
|
{
|
||||||
|
super(listener);
|
||||||
|
this.server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Listener ll, Event event) throws EventException
|
||||||
|
{
|
||||||
|
org.bukkit.block.Block bukkitBlock = ((BlockPlaceEvent)event).getBlockPlaced();
|
||||||
|
Block block = BukkitBlockFactory.convert(bukkitBlock);
|
||||||
|
String playername = ((BlockPlaceEvent)event).getPlayer().getName();
|
||||||
|
listener.onBlockPlace(block, new UserOnDemand(playername, server));
|
||||||
|
}
|
||||||
|
}
|
@@ -2,16 +2,15 @@ package net.ess3.listener;
|
|||||||
|
|
||||||
import net.ess3.api.IEssentials;
|
import net.ess3.api.IEssentials;
|
||||||
import net.ess3.api.IUser;
|
import net.ess3.api.IUser;
|
||||||
import net.ess3.utils.Util;
|
import net.ess3.api.ondemand.OnDemand;
|
||||||
import org.bukkit.GameMode;
|
import net.ess3.api.server.Block;
|
||||||
import org.bukkit.event.EventHandler;
|
import net.ess3.api.server.ItemStack;
|
||||||
import org.bukkit.event.EventPriority;
|
import net.ess3.api.server.events.EventListener;
|
||||||
import org.bukkit.event.Listener;
|
import net.ess3.api.server.events.EventPriority;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import net.ess3.api.server.events.EventType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
|
|
||||||
public class EssentialsBlockListener implements Listener
|
public class EssentialsBlockListener extends EventListener
|
||||||
{
|
{
|
||||||
private final transient IEssentials ess;
|
private final transient IEssentials ess;
|
||||||
|
|
||||||
@@ -19,21 +18,20 @@ public class EssentialsBlockListener implements Listener
|
|||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
this.ess = ess;
|
this.ess = ess;
|
||||||
|
register(EventType.PLACE_BLOCK, EventPriority.LOW, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
@Override
|
||||||
public void onBlockPlace(final BlockPlaceEvent event)
|
public boolean onBlockPlace(final Block placedBlock, final OnDemand<IUser> user)
|
||||||
{
|
{
|
||||||
// Do not rely on getItemInHand();
|
final ItemStack itemstack = placedBlock.convertToItem();
|
||||||
// http://leaky.bukkit.org/issues/663
|
if (placedBlock == null)
|
||||||
final ItemStack itemstack = Util.convertBlockToItem(event.getBlockPlaced());
|
|
||||||
if (itemstack == null)
|
|
||||||
{
|
{
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
final IUser user = ess.getUserMap().getUser(event.getPlayer());
|
|
||||||
final boolean unlimitedForUser = user.getData().hasUnlimited(itemstack.getType());
|
final boolean unlimitedForUser = user.get().getData().hasUnlimited(itemstack.getType());
|
||||||
if (unlimitedForUser && user.getGameMode() == GameMode.SURVIVAL)
|
if (unlimitedForUser && user.get().isInSurvivalMode())
|
||||||
{
|
{
|
||||||
ess.getPlugin().scheduleSyncDelayedTask(
|
ess.getPlugin().scheduleSyncDelayedTask(
|
||||||
new Runnable()
|
new Runnable()
|
||||||
@@ -41,10 +39,11 @@ public class EssentialsBlockListener implements Listener
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
user.getInventory().addItem(itemstack);
|
user.get().getInventory().addItem(itemstack);
|
||||||
user.updateInventory();
|
user.get().updateInventory();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -750,6 +750,4 @@ public class User extends UserBase implements IUser
|
|||||||
final boolean set = !vanished;
|
final boolean set = !vanished;
|
||||||
this.setVanished(set);
|
this.setVanished(set);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user