diff --git a/pom.xml b/pom.xml index 8e13d8f..85037d9 100644 --- a/pom.xml +++ b/pom.xml @@ -49,5 +49,11 @@ 1.15 provided + + steamwar + SpigotCore + 2.0 + provided + \ No newline at end of file diff --git a/src/de/steamwar/spectatesystem/Config.java b/src/de/steamwar/spectatesystem/Config.java index 26432e5..8526a2f 100644 --- a/src/de/steamwar/spectatesystem/Config.java +++ b/src/de/steamwar/spectatesystem/Config.java @@ -1,4 +1,161 @@ package de.steamwar.spectatesystem; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.File; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.logging.Level; + public class Config { + private Config(){} + + //arena parameter + public static final int SchemsizeX; + public static final int SchemsizeY; + public static final int SchemsizeZ; + public static final int TeamBlueCornerX; + public static final int TeamBlueCornerY; + public static final int TeamBlueCornerZ; + private static final int TeamBluePasteX; + private static final int TeamBluePasteZ; + public static final int TeamRedCornerX; + public static final int TeamRedCornerY; + public static final int TeamRedCornerZ; + private static final int TeamRedPasteX; + private static final int TeamRedPasteZ; + private static final int TeamBluetoReddistanceX; + private static final int TeamBluetoReddistanceY; + public static final int TeamBluetoReddistanceZ; + public static final Location SpecSpawn; + public static final int underArenaBorder; + public static final int BorderFromSchematic; + public static final int upperArenaBorder; + private static final int Schem2BorderX; + private static final int Schem2BorderZ; + public static final int ArenaMinX; + public static final int ArenaMinZ; + public static final int ArenaMaxX; + public static final int ArenaMaxZ; + + //tech hider parameter + public static final boolean TechhiderActive; + public static final Set HiddenBlocks; + public static final Set HiddenBlockTags; + public static final Set HiddenBlockEntities; + public static final int ObfuscateWith; + public static final String ObfuscateWithTag; + + public static final int port = 2222; + + static{ + World world = Bukkit.getWorlds().get(0); + File worldConfigFile = new File(world.getWorldFolder(), "config.yml"); + if(!worldConfigFile.exists()) { + Bukkit.getLogger().log(Level.SEVERE, "Weltconfig fehlt!"); + Bukkit.shutdown(); + } + FileConfiguration worldconfig = YamlConfiguration.loadConfiguration(worldConfigFile); + + int schemsizeX = worldconfig.getInt("Arena.Schemsize.x"); + int schemsizeY = worldconfig.getInt("Arena.Schemsize.y"); + int schemsizeZ = worldconfig.getInt("Arena.Schemsize.z"); + int teamBlueCornerX = worldconfig.getInt("Arena.TeamBlueCorner.x"); + int teamBlueCornerY = worldconfig.getInt("Arena.TeamBlueCorner.y"); + int teamBlueCornerZ = worldconfig.getInt("Arena.TeamBlueCorner.z"); + TeamBluetoReddistanceX = worldconfig.getInt("Arena.TeamBluetoReddistance.x"); + TeamBluetoReddistanceY = worldconfig.getInt("Arena.TeamBluetoReddistance.y"); + TeamBluetoReddistanceZ = worldconfig.getInt("Arena.TeamBluetoReddistance.z"); + Schem2BorderX = worldconfig.getInt("Arena.Schem2Border.x"); + Schem2BorderZ = worldconfig.getInt("Arena.Schem2Border.z"); + underArenaBorder = worldconfig.getInt("Arena.underArenaBorder"); + BorderFromSchematic = worldconfig.getInt("Arena.BorderFromSchematic"); + + if(schemsizeX < 0){ + SchemsizeX = -schemsizeX; + TeamBlueCornerX = teamBlueCornerX - SchemsizeX; + }else{ + SchemsizeX = schemsizeX; + TeamBlueCornerX = teamBlueCornerX; + } + if(schemsizeY < 0){ + SchemsizeY = -schemsizeY; + TeamBlueCornerY = teamBlueCornerY - SchemsizeY; + }else{ + SchemsizeY = schemsizeY; + TeamBlueCornerY = teamBlueCornerY; + } + if(schemsizeZ < 0){ + SchemsizeZ = -schemsizeZ; + TeamBlueCornerZ = teamBlueCornerZ - SchemsizeZ; + }else{ + SchemsizeZ = schemsizeZ; + TeamBlueCornerZ = teamBlueCornerZ; + } + + upperArenaBorder = TeamBlueCornerY + SchemsizeY + BorderFromSchematic; + + TeamRedCornerX = TeamBluetoReddistanceX + TeamBlueCornerX; + TeamRedCornerY = TeamBluetoReddistanceY + TeamBlueCornerY; + TeamRedCornerZ = TeamBluetoReddistanceZ + TeamBlueCornerZ; + + TeamBluePasteX = TeamBlueCornerX + SchemsizeX / 2; + TeamBluePasteZ = TeamBlueCornerZ + SchemsizeZ / 2; + TeamRedPasteX = TeamBluePasteX + TeamBluetoReddistanceX; + TeamRedPasteZ = TeamBluePasteZ + TeamBluetoReddistanceZ; + + SpecSpawn = new Location(world, + TeamBluePasteX + TeamBluetoReddistanceX/2.0, + TeamBlueCornerY + TeamBluetoReddistanceY/2.0 + SchemsizeY/2.0, + TeamBluePasteZ + TeamBluetoReddistanceZ/2.0); + + if(TeamBluetoReddistanceX > 0){ + ArenaMinX = TeamBlueCornerX - Schem2BorderX; + ArenaMaxX = TeamRedCornerX + SchemsizeX + Schem2BorderX; + }else{ + ArenaMinX = TeamRedCornerX - Schem2BorderX; + ArenaMaxX = TeamBlueCornerX + SchemsizeX + Schem2BorderX; + } + if(TeamBluetoReddistanceZ > 0){ + ArenaMinZ = TeamBlueCornerZ - Schem2BorderZ; + ArenaMaxZ = TeamRedCornerZ + SchemsizeZ + Schem2BorderZ; + }else{ + ArenaMinZ = TeamRedCornerZ - Schem2BorderZ; + ArenaMaxZ = TeamBlueCornerZ + SchemsizeZ + Schem2BorderZ; + } + + if(!new File(SpectateSystem.get().getDataFolder(), "config.yml").exists()) { + Bukkit.getLogger().log(Level.SEVERE, "Arenaconfig fehlt!"); + Bukkit.shutdown(); + } + FileConfiguration config = SpectateSystem.get().getConfig(); + + ConfigurationSection techhiderConfig = config.getConfigurationSection("Techhider.HiddenBlocks"); + Set blocks = new HashSet<>(); + Set blockTags = new HashSet<>(); + for(String key : techhiderConfig.getKeys(false)){ + blockTags.add(key); + if(techhiderConfig.isInt(key)) + blocks.add(techhiderConfig.getInt(key)); + else{ + List minmax = techhiderConfig.getIntegerList(key); // Entry 0: Minimum, Entry 1: Maximum + for(int i = minmax.get(0); i <= minmax.get(1); i++) + blocks.add(i); + } + + } + HiddenBlocks = Collections.unmodifiableSet(blocks); + HiddenBlockTags = Collections.unmodifiableSet(blockTags); + HiddenBlockEntities = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlockEntities"))); + ObfuscateWith = config.getInt("Techhider.ObfuscateWith"); + ObfuscateWithTag = config.getString("Techhider.ObfuscateWithTag"); + TechhiderActive = config.getBoolean("Techhider.Active"); + } } diff --git a/src/de/steamwar/spectatesystem/ConnectionAcceptor.java b/src/de/steamwar/spectatesystem/ConnectionAcceptor.java new file mode 100644 index 0000000..b9f7e2f --- /dev/null +++ b/src/de/steamwar/spectatesystem/ConnectionAcceptor.java @@ -0,0 +1,35 @@ +package de.steamwar.spectatesystem; + +import org.bukkit.Bukkit; + +import java.io.IOException; +import java.net.ServerSocket; +import java.util.logging.Level; + +public class ConnectionAcceptor { + + private final ServerSocket socket; + + public ConnectionAcceptor() throws IOException { + socket = new ServerSocket(Config.port); + Bukkit.getScheduler().runTaskAsynchronously(SpectateSystem.get(), this::acceptConnections); + } + + public void close(){ + try { + socket.close(); + } catch (IOException e) { + Bukkit.getLogger().log(Level.SEVERE, "Could not close socket", e); + } + } + + private void acceptConnections(){ + try { + while(!socket.isClosed()){ + new FightserverConnection(socket.accept()); + } + } catch (IOException e) { + Bukkit.getLogger().log(Level.WARNING, "Stopping accepting connections", e); + } + } +} diff --git a/src/de/steamwar/spectatesystem/FightServerConnection.java b/src/de/steamwar/spectatesystem/FightServerConnection.java deleted file mode 100644 index a9afe4a..0000000 --- a/src/de/steamwar/spectatesystem/FightServerConnection.java +++ /dev/null @@ -1,186 +0,0 @@ -package de.steamwar.spectatesystem; - -import org.bukkit.Bukkit; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.ServerSocket; -import java.net.Socket; - -public class FightServerConnection { - - public static FightServerConnection getInstance() { - return fightServerConnection; - } - - public static FightServerConnection build(int port) { - fightServerConnection = new FightServerConnection(port); - return fightServerConnection; - } - - public static void cleanUp() { - if (fightServerConnection == null) { - return; - } - fightServerConnection.internalCleanUp(); - fightServerConnection = null; - } - - private static FightServerConnection fightServerConnection = null; - - private void internalCleanUp() { - internalPreCleanUp(); - try { - serverSocket.close(); - } catch (IOException e) { - errorCode = 2; - } - } - - private void internalPreCleanUp() { - if (socket != null) { - try { - socket.close(); - } catch (IOException e) { - errorCode = 3; - } - } - if (inputStream != null) { - try { - inputStream.close(); - } catch (IOException e) { - errorCode = 3; - } - } - if (outputStream != null) { - try { - outputStream.close(); - } catch (IOException e) { - errorCode = 3; - } - } - } - - /** - * 0 - OK - * 1 - No Connect - * 2 - Error while cleanup - * 3 - Error while pre cleanup - * 4 - Error while writing - * 5 - Error while reading - * 6 - Error while flushing - */ - private int errorCode = 0; - - private ServerSocket serverSocket; - private Socket socket = null; - private InputStream inputStream = null; - private OutputStream outputStream = null; - - private FightServerConnection(int port) { - try { - this.serverSocket = new ServerSocket(port); - Bukkit.getScheduler().runTaskAsynchronously(SpectateSystem.get(), () -> { - while (serverSocket != null) { - while (socket == null) { - try { - socket = serverSocket.accept(); - } catch (IOException e) { - - } - } - try { - inputStream = socket.getInputStream(); - outputStream = socket.getOutputStream(); - } catch (IOException e) { - socket = null; - } - if (socket == null) continue; - while (true) { - try { - outputStream.write(0); - } catch (IOException e) { - break; - } - } - internalPreCleanUp(); - socket = null; - inputStream = null; - outputStream = null; - } - }); - } catch (IOException e) { - errorCode = 1; - } - } - - public int getErrorCode() { - return errorCode; - } - - public InputStream getInputStream() { - return inputStream; - } - - public OutputStream getOutputStream() { - return outputStream; - } - - public int read() { - try { - return inputStream.read(); - } catch (IOException e) { - errorCode = 5; - return -2; - } - } - - public byte[] lazyRead(int length) { - try { - byte[] bytes = new byte[length]; - inputStream.read(bytes); - return bytes; - } catch (IOException e) { - errorCode = 5; - return new byte[length]; - } - } - - public byte[] read(int length) { - byte[] bytes = new byte[length]; - for (int i = 0; i < length; i++) { - bytes[i] = (byte) read(); - if (errorCode != 0) { - break; - } - } - return bytes; - } - - public void write(byte b) { - try { - outputStream.write(b); - } catch (IOException e) { - errorCode = 4; - } - } - - public void write(byte... bytes) { - try { - outputStream.write(bytes); - } catch (IOException e) { - errorCode = 4; - } - flush(); - } - - public void flush() { - try { - outputStream.flush(); - } catch (IOException e) { - errorCode = 6; - } - } - -} diff --git a/src/de/steamwar/spectatesystem/FightserverConnection.java b/src/de/steamwar/spectatesystem/FightserverConnection.java new file mode 100644 index 0000000..e551d1f --- /dev/null +++ b/src/de/steamwar/spectatesystem/FightserverConnection.java @@ -0,0 +1,69 @@ +package de.steamwar.spectatesystem; + +import org.bukkit.Bukkit; + +import java.io.DataInputStream; +import java.io.IOException; +import java.net.Socket; +import java.util.logging.Level; + +public class FightserverConnection implements PacketSource { + private final Socket socket; + private final DataInputStream inputStream; + + FightserverConnection(Socket socket) throws IOException{ + this.socket = socket; + this.inputStream = new DataInputStream(socket.getInputStream()); + new PacketProcessor(this); + } + + @Override + public byte rByte() throws IOException { + return inputStream.readByte(); + } + + @Override + public short rShort() throws IOException { + return inputStream.readShort(); + } + + @Override + public int rInt() throws IOException { + return inputStream.readInt(); + } + + @Override + public long rLong() throws IOException { + return inputStream.readLong(); + } + + @Override + public float rFloat() throws IOException { + return inputStream.readFloat(); + } + + @Override + public double rDouble() throws IOException { + return inputStream.readDouble(); + } + + @Override + public String rString() throws IOException { + return inputStream.readUTF(); + } + + @Override + public void close() { + try { + socket.close(); + inputStream.close(); + } catch (IOException e) { + Bukkit.getLogger().log(Level.SEVERE, "IOException on close", e); + } + } + + @Override + public boolean isClosed() { + return socket.isClosed(); + } +} diff --git a/src/de/steamwar/spectatesystem/PacketProcessor.java b/src/de/steamwar/spectatesystem/PacketProcessor.java new file mode 100644 index 0000000..aa4b553 --- /dev/null +++ b/src/de/steamwar/spectatesystem/PacketProcessor.java @@ -0,0 +1,70 @@ +package de.steamwar.spectatesystem; + +import de.steamwar.spectatesystem.elements.REntity; +import de.steamwar.spectatesystem.elements.RPlayer; +import de.steamwar.sql.SteamwarUser; +import org.bukkit.Bukkit; + +import java.io.IOException; +import java.util.logging.Level; + +class PacketProcessor { + + private final PacketSource source; + + public PacketProcessor(PacketSource source){ + this.source = source; + Bukkit.getScheduler().runTaskAsynchronously(SpectateSystem.get(), this::process); + } + + private void playerJoins() throws IOException{ + int entityId = source.rInt(); + int userId = source.rInt(); + SteamwarUser user = SteamwarUser.get(userId); + if(user == null) + throw new IOException("Unknown user " + userId); + + new RPlayer(user.getUUID(), user.getUserName(), entityId); + } + + private void entityMoves() throws IOException{ + int entityId = source.rInt(); + double locX = source.rDouble(); + double locY = source.rDouble(); + double locZ = source.rDouble(); + float pitch = source.rFloat(); + float yaw = source.rFloat(); + + REntity.getEntity(entityId).move(locX, locY, locZ, yaw, pitch); + } + + private void entityDespawns() throws IOException{ + int entityId = source.rInt(); + + REntity.getEntity(entityId).remove(); + } + + private void process(){ + try{ + while(!source.isClosed()){ + switch(source.rByte()){ + case 0x00: + playerJoins(); + break; + case 0x01: + entityMoves(); + break; + case 0x02: + entityDespawns(); + break; + default: + Bukkit.getLogger().log(Level.SEVERE, "Unknown packet recieved, closing"); + source.close(); + } + } + }catch(IOException e){ + Bukkit.getLogger().log(Level.WARNING, "Could not recieve packet", e); + source.close(); + } + } +} diff --git a/src/de/steamwar/spectatesystem/PacketSource.java b/src/de/steamwar/spectatesystem/PacketSource.java new file mode 100644 index 0000000..3dde6ab --- /dev/null +++ b/src/de/steamwar/spectatesystem/PacketSource.java @@ -0,0 +1,17 @@ +package de.steamwar.spectatesystem; + +import java.io.IOException; + +public interface PacketSource { + + byte rByte() throws IOException; + short rShort() throws IOException; + int rInt() throws IOException; + long rLong() throws IOException; + float rFloat() throws IOException; + double rDouble() throws IOException; + String rString() throws IOException; + + void close(); + boolean isClosed(); +} diff --git a/src/de/steamwar/spectatesystem/Region.java b/src/de/steamwar/spectatesystem/Region.java new file mode 100644 index 0000000..9ea6fdc --- /dev/null +++ b/src/de/steamwar/spectatesystem/Region.java @@ -0,0 +1,36 @@ +package de.steamwar.spectatesystem; + +import org.bukkit.Location; + +public class Region { + + private Region(){} + + public static boolean isInRange(Location location, int minX, int minY, int minZ, int xRange, int yRange, int zRange, int margin) { + return isInRegion(location, minX, minY, minZ, minX + xRange, minY + yRange, minZ + zRange, margin); + } + + public static boolean isInRegion(Location location, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, int margin) { + return isIn2DRegion(location, minX, minZ, maxX, maxZ, margin) && inRange(location.getBlockY(), minY, maxY, margin); + } + + public static boolean isIn2DRange(Location location, int minX, int minZ, int xRange, int zRange, int margin){ + return isIn2DRegion(location, minX, minZ, minX + xRange, minZ + zRange, margin); + } + + private static boolean isIn2DRegion(Location location, int minX, int minZ, int maxX, int maxZ, int margin){ + return inRange(location.getBlockX(), minX, maxX, margin) && inRange(location.getBlockZ(), minZ, maxZ, margin); + } + + public static boolean isIn2DRegion(Location location, int minX, int minZ, int maxX, int maxZ){ + return inRange(location.getBlockX(), minX, maxX) && inRange(location.getBlockZ(), minZ, maxZ); + } + + private static boolean inRange(double value, int min, int max, int margin){ + return inRange(value, min-margin, max+margin); + } + + private static boolean inRange(double value, int min, int max){ + return min <= value && value <= max; + } +} diff --git a/src/de/steamwar/spectatesystem/SpectateSystem.java b/src/de/steamwar/spectatesystem/SpectateSystem.java index d3694cf..2d4b728 100644 --- a/src/de/steamwar/spectatesystem/SpectateSystem.java +++ b/src/de/steamwar/spectatesystem/SpectateSystem.java @@ -1,21 +1,33 @@ package de.steamwar.spectatesystem; +import de.steamwar.spectatesystem.listener.ArenaListener; import de.steamwar.spectatesystem.listener.JoinListener; +import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; +import java.io.IOException; +import java.util.logging.Level; + public class SpectateSystem extends JavaPlugin { private static SpectateSystem instance; + private ConnectionAcceptor acceptor; @Override public void onEnable() { instance = this; new JoinListener(); + new ArenaListener(); + try { + acceptor = new ConnectionAcceptor(); + } catch (IOException e) { + Bukkit.getLogger().log(Level.SEVERE, "Could not open ConnectionAcceptor", e); + } } @Override public void onDisable() { - + acceptor.close(); } public static SpectateSystem get(){ diff --git a/src/de/steamwar/spectatesystem/elements/RBlockchange.java b/src/de/steamwar/spectatesystem/elements/RBlockchange.java index 6f94f56..66d99e1 100644 --- a/src/de/steamwar/spectatesystem/elements/RBlockchange.java +++ b/src/de/steamwar/spectatesystem/elements/RBlockchange.java @@ -1,5 +1,6 @@ package de.steamwar.spectatesystem.elements; +import de.steamwar.spectatesystem.Config; import net.minecraft.server.v1_15_R1.Block; import net.minecraft.server.v1_15_R1.BlockPosition; import net.minecraft.server.v1_15_R1.IBlockData; @@ -12,6 +13,8 @@ public class RBlockchange { private static final WorldServer WORLD = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle(); public RBlockchange(int x, int y, int z, int stateId){ + if(Config.TechhiderActive && Config.HiddenBlocks.contains(stateId)) + stateId = Config.ObfuscateWith; IBlockData blockData = Block.REGISTRY_ID.fromId(stateId); BlockPosition pos = new BlockPosition(x, y, z); WORLD.setTypeAndData(pos, blockData, 1042); diff --git a/src/de/steamwar/spectatesystem/elements/RChatmessage.java b/src/de/steamwar/spectatesystem/elements/RChatmessage.java new file mode 100644 index 0000000..1bb10ef --- /dev/null +++ b/src/de/steamwar/spectatesystem/elements/RChatmessage.java @@ -0,0 +1,8 @@ +package de.steamwar.spectatesystem.elements; + +public class RChatmessage { + + public RChatmessage(){ + + } +} diff --git a/src/de/steamwar/spectatesystem/elements/RPlayer.java b/src/de/steamwar/spectatesystem/elements/RPlayer.java index 2da139e..def72b0 100644 --- a/src/de/steamwar/spectatesystem/elements/RPlayer.java +++ b/src/de/steamwar/spectatesystem/elements/RPlayer.java @@ -21,6 +21,9 @@ public class RPlayer extends REntity { public RPlayer(UUID uuid, String name, int internalId){ super(internalId, createPlayer(uuid, name)); + //TODO Item in Hand + //TODO Armor + //TODO Damage } @Override diff --git a/src/de/steamwar/spectatesystem/listener/ArenaListener.java b/src/de/steamwar/spectatesystem/listener/ArenaListener.java new file mode 100644 index 0000000..73fa312 --- /dev/null +++ b/src/de/steamwar/spectatesystem/listener/ArenaListener.java @@ -0,0 +1,52 @@ +package de.steamwar.spectatesystem.listener; + +import de.steamwar.spectatesystem.Config; +import de.steamwar.spectatesystem.Region; +import de.steamwar.spectatesystem.SpectateSystem; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerTeleportEvent; + +public class ArenaListener extends BasicListener { + + private static final String DENY_ARENA = "§cDu darfst die Arena nicht verlassen"; + private static final String DENY_TEAM = "§cDu darfst nicht zu den Teams"; + + @EventHandler + public void onMove(PlayerMoveEvent event) { + Location to = event.getTo(); + + assert to != null; + if(!Region.isIn2DRegion(to, Config.ArenaMinX, Config.ArenaMinZ, Config.ArenaMaxX, Config.ArenaMaxZ) || to.getY() <= Config.underArenaBorder) { + reset(event, DENY_ARENA); + return; + } + + boolean inArenaY = to.getY() + 1.8 <= Config.upperArenaBorder; + boolean inBlueArea = inArenaY && Region.isIn2DRange(to, Config.TeamBlueCornerX, Config.TeamBlueCornerZ, Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic); + boolean inRedArea = inArenaY && Region.isIn2DRange(to, Config.TeamRedCornerX, Config.TeamRedCornerZ, Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic); + + if(inBlueArea || inRedArea) + reset(event, DENY_TEAM); + } + + private void reset(PlayerMoveEvent event, String message){ + Player player = event.getPlayer(); + player.teleport(event.getFrom()); + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message)); + } + + @EventHandler + public void onTpGM3(PlayerTeleportEvent e) { + if (e.getCause() == PlayerTeleportEvent.TeleportCause.SPECTATE) { + e.setCancelled(true); + e.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§cDu darfst diese Teleportfunktion nicht benutzen!")); + Bukkit.getScheduler().runTaskLater(SpectateSystem.get(), () -> e.getPlayer().teleport(e.getFrom()), 2); + } + } +} diff --git a/src/de/steamwar/spectatesystem/listener/BasicListener.java b/src/de/steamwar/spectatesystem/listener/BasicListener.java new file mode 100644 index 0000000..944989c --- /dev/null +++ b/src/de/steamwar/spectatesystem/listener/BasicListener.java @@ -0,0 +1,12 @@ +package de.steamwar.spectatesystem.listener; + +import de.steamwar.spectatesystem.SpectateSystem; +import org.bukkit.Bukkit; +import org.bukkit.event.Listener; + +abstract class BasicListener implements Listener { + + BasicListener(){ + Bukkit.getPluginManager().registerEvents(this, SpectateSystem.get()); + } +} diff --git a/src/de/steamwar/spectatesystem/listener/JoinListener.java b/src/de/steamwar/spectatesystem/listener/JoinListener.java index b84a00e..b428e06 100644 --- a/src/de/steamwar/spectatesystem/listener/JoinListener.java +++ b/src/de/steamwar/spectatesystem/listener/JoinListener.java @@ -1,20 +1,15 @@ package de.steamwar.spectatesystem.listener; -import de.steamwar.spectatesystem.SpectateSystem; import de.steamwar.spectatesystem.elements.REntity; -import org.bukkit.Bukkit; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; -public class JoinListener implements Listener { - - public JoinListener(){ - Bukkit.getPluginManager().registerEvents(this, SpectateSystem.get()); - } +public class JoinListener extends BasicListener { @EventHandler public void onJoin(PlayerJoinEvent e){ - REntity.playerJoins(e.getPlayer()); + Player player = e.getPlayer(); + REntity.playerJoins(player); } } diff --git a/src/plugin.yml b/src/plugin.yml index f1beecb..d799d5b 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -2,4 +2,6 @@ authors: - Lixfel name: SpectateSystem version: 1.0 -main: de.steamwar.spectatesystem.SpectateSystem \ No newline at end of file +main: de.steamwar.spectatesystem.SpectateSystem +depends: + - SpigotCore \ No newline at end of file