Initial commit
Dieser Commit ist enthalten in:
Commit
4064f28caf
4
.gitignore
vendored
Normale Datei
4
.gitignore
vendored
Normale Datei
@ -0,0 +1,4 @@
|
||||
|
||||
/.idea
|
||||
/target
|
||||
/lib
|
65
pom.xml
Normale Datei
65
pom.xml
Normale Datei
@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>de.steamwar</groupId>
|
||||
<artifactId>LobbySystem</artifactId>
|
||||
<version>1.0</version>
|
||||
<packaging>jar</packaging>
|
||||
<url>https://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<main.basedir>${project.basedir}</main.basedir>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src</directory>
|
||||
<excludes>
|
||||
<exclude>**/*.java</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.6.1</version>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<finalName>lobbysystem</finalName>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>steamwar</groupId>
|
||||
<artifactId>Spigot</artifactId>
|
||||
<version>1.15</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${main.basedir}/lib/Spigot-1.15.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>steamwar</groupId>
|
||||
<artifactId>WorldEdit</artifactId>
|
||||
<version>1.15</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${main.basedir}/lib/WorldEdit-1.15.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>steamwar</groupId>
|
||||
<artifactId>SpigotCore</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${main.basedir}/lib/SpigotCore.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
46
src/de/steamwar/lobby/Config.java
Normale Datei
46
src/de/steamwar/lobby/Config.java
Normale Datei
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.lobby;
|
||||
|
||||
import de.steamwar.lobby.portal.CommandPortal;
|
||||
import de.steamwar.lobby.portal.TeleportPortal;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||
|
||||
public class Config {
|
||||
|
||||
private final FileConfiguration yml;
|
||||
|
||||
public Config(FileConfiguration yml) {
|
||||
this.yml = yml;
|
||||
|
||||
ConfigurationSerialization.registerClass(CommandPortal.class);
|
||||
ConfigurationSerialization.registerClass(TeleportPortal.class);
|
||||
yml.getList("commandPortals", CommandPortal.getPortals());
|
||||
yml.getList("teleportPortals", TeleportPortal.getPortals());
|
||||
}
|
||||
|
||||
public void save() {
|
||||
yml.set("commandPortals", CommandPortal.getPortals());
|
||||
yml.set("teleportPortals", TeleportPortal.getPortals());
|
||||
|
||||
LobbySystem.getPlugin().saveConfig();
|
||||
}
|
||||
}
|
52
src/de/steamwar/lobby/LobbySystem.java
Normale Datei
52
src/de/steamwar/lobby/LobbySystem.java
Normale Datei
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.lobby;
|
||||
|
||||
import de.steamwar.lobby.listener.Fightservers;
|
||||
import de.steamwar.lobby.listener.Join;
|
||||
import de.steamwar.lobby.listener.Portals;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class LobbySystem extends JavaPlugin {
|
||||
|
||||
private static LobbySystem plugin;
|
||||
private static Config config;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
plugin = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
new Join();
|
||||
new Fightservers();
|
||||
new Portals();
|
||||
config = new Config(getConfig());
|
||||
}
|
||||
|
||||
public static LobbySystem getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public static Config config() {
|
||||
return config;
|
||||
}
|
||||
}
|
31
src/de/steamwar/lobby/listener/BasicListener.java
Normale Datei
31
src/de/steamwar/lobby/listener/BasicListener.java
Normale Datei
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.lobby.listener;
|
||||
|
||||
import de.steamwar.lobby.LobbySystem;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class BasicListener implements Listener {
|
||||
|
||||
public BasicListener () {
|
||||
Bukkit.getPluginManager().registerEvents(this, LobbySystem.getPlugin());
|
||||
}
|
||||
}
|
34
src/de/steamwar/lobby/listener/Fightservers.java
Normale Datei
34
src/de/steamwar/lobby/listener/Fightservers.java
Normale Datei
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.lobby.listener;
|
||||
|
||||
import de.steamwar.comms.BungeeReceiver;
|
||||
import de.steamwar.comms.PacketIdManager;
|
||||
import de.steamwar.lobby.LobbySystem;
|
||||
import de.steamwar.lobby.servers.Fightserver;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class Fightservers {
|
||||
|
||||
public Fightservers() {
|
||||
BungeeReceiver.registerHandler(PacketIdManager.FIGHT_INFO, Fightserver::newFightInfo);
|
||||
Bukkit.getScheduler().runTaskTimer(LobbySystem.getPlugin(), Fightserver::removeStopped, 20, 20);
|
||||
}
|
||||
}
|
38
src/de/steamwar/lobby/listener/Join.java
Normale Datei
38
src/de/steamwar/lobby/listener/Join.java
Normale Datei
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.lobby.listener;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class Join extends BasicListener {
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
Player player = e.getPlayer();
|
||||
|
||||
player.setGameMode(GameMode.ADVENTURE);
|
||||
player.setWalkSpeed(5.0f);
|
||||
|
||||
//new ImALobbyPacket().send(player);
|
||||
}
|
||||
}
|
69
src/de/steamwar/lobby/listener/Portals.java
Normale Datei
69
src/de/steamwar/lobby/listener/Portals.java
Normale Datei
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.lobby.listener;
|
||||
|
||||
import de.steamwar.lobby.portal.Portal;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Portals extends BasicListener {
|
||||
|
||||
private static final Map<Player, Deque<Portal>> portalStack = new HashMap<>();
|
||||
|
||||
public static Deque<Portal> getStack(Player player) {
|
||||
return portalStack.get(player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
portalStack.put(e.getPlayer(), new ArrayDeque<>());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onMove(PlayerMoveEvent e) {
|
||||
Location to = e.getTo();
|
||||
assert to != null;
|
||||
|
||||
Portal portal = Portal.getPortal(to);
|
||||
if (portal == null)
|
||||
return;
|
||||
|
||||
Player player = e.getPlayer();
|
||||
Deque<Portal> lastPortals = portalStack.get(player);
|
||||
if(!lastPortals.isEmpty() && lastPortals.peek() == portal)
|
||||
return;
|
||||
|
||||
portal.handle(player, to);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent e) {
|
||||
portalStack.remove(e.getPlayer());
|
||||
}
|
||||
}
|
72
src/de/steamwar/lobby/portal/CommandPortal.java
Normale Datei
72
src/de/steamwar/lobby/portal/CommandPortal.java
Normale Datei
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.lobby.portal;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CommandPortal extends Portal {
|
||||
|
||||
private static final List<CommandPortal> portals = new ArrayList<>();
|
||||
|
||||
public static List<CommandPortal> getPortals() {
|
||||
return portals;
|
||||
}
|
||||
|
||||
private final String command;
|
||||
|
||||
public CommandPortal(Map<String, Object> section) {
|
||||
super(section);
|
||||
this.command = (String) section.get("command");
|
||||
init();
|
||||
}
|
||||
|
||||
public CommandPortal(String id, Location pos1, Location pos2, String command) {
|
||||
super(id, pos1, pos2);
|
||||
this.command = command;
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
portals.add(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(Player player, Location loc) {
|
||||
player.sendMessage("Folgender Command wäre jetzt ausgeführt worden, könnte der Bungee das schon: " + command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> map = super.serialize();
|
||||
map.put("command", command);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() {
|
||||
portals.remove(this);
|
||||
super.delete();
|
||||
}
|
||||
}
|
23
src/de/steamwar/lobby/portal/FightserverPortal.java
Normale Datei
23
src/de/steamwar/lobby/portal/FightserverPortal.java
Normale Datei
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.lobby.portal;
|
||||
|
||||
public class FightserverPortal extends TeleportPortal {
|
||||
}
|
127
src/de/steamwar/lobby/portal/Portal.java
Normale Datei
127
src/de/steamwar/lobby/portal/Portal.java
Normale Datei
@ -0,0 +1,127 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.lobby.portal;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class Portal implements PortalHandler, ConfigurationSerializable {
|
||||
|
||||
private static final Map<String, Portal> portals = new HashMap<>();
|
||||
private static final Map<Vector, Portal> posMap = new HashMap<>();
|
||||
|
||||
public static Portal getPortal(Location loc) {
|
||||
return posMap.get(new Vector(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
||||
}
|
||||
|
||||
public static Portal getPortal(String id) {
|
||||
return portals.get(id);
|
||||
}
|
||||
|
||||
private final Location pos1;
|
||||
private final Location pos2;
|
||||
private final String id;
|
||||
private final PortalType type;
|
||||
private final PortalHandler handler;
|
||||
|
||||
public Portal(Map<String, Object> map) {
|
||||
this.id = (String) map.get("id");
|
||||
this.pos1 = (Location) map.get("pos1");
|
||||
this.pos2 = (Location) map.get("pos2");
|
||||
this.type = PortalType.valueOf((String) map.get("type"));
|
||||
this.handler = type.deserialize(map, this);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
public Portal(String id, Location pos1, Location pos2, Function<Portal, PortalHandler> handlerConstructor) {
|
||||
this.id = id;
|
||||
this.pos1 = pos1;
|
||||
this.pos2 = pos2;
|
||||
this.handler = handlerConstructor.apply(this);
|
||||
this.type = handler.type();
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
portals.put(id, this);
|
||||
Vector diff = pos2.subtract(pos1).toVector();
|
||||
diff.divide(new Vector(Math.abs(diff.getBlockX()), Math.abs(diff.getBlockY()), Math.abs(diff.getBlockZ())));
|
||||
for(int x = pos1.getBlockX(); x <= pos2.getBlockX(); x += diff.getBlockX()) {
|
||||
for(int y = pos1.getBlockY(); y <= pos2.getBlockY(); y += diff.getBlockY()) {
|
||||
for(int z = pos1.getBlockZ(); z <= pos2.getBlockZ(); z += diff.getBlockZ()) {
|
||||
posMap.put(new Vector(x, y, z), this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(Player player, Location from) {
|
||||
handler.handle(player, from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(Map<String, Object> map) {
|
||||
map.put("id", id);
|
||||
map.put("pos1", pos1);
|
||||
map.put("pos2", pos2);
|
||||
map.put("type", type.name());
|
||||
handler.serialize(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PortalType type() {
|
||||
return handler.type();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() {
|
||||
portals.remove("id");
|
||||
posMap.values().removeIf(this::equals);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
serialize(map);
|
||||
return map;
|
||||
}
|
||||
|
||||
public Location getPos1() {
|
||||
return pos1;
|
||||
}
|
||||
|
||||
public Location getPos2() {
|
||||
return pos2;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
35
src/de/steamwar/lobby/portal/PortalHandler.java
Normale Datei
35
src/de/steamwar/lobby/portal/PortalHandler.java
Normale Datei
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.lobby.portal;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface PortalHandler {
|
||||
void handle(Player player, Location from);
|
||||
|
||||
void serialize(Map<String, Object> map);
|
||||
|
||||
PortalType type();
|
||||
|
||||
void delete();
|
||||
}
|
39
src/de/steamwar/lobby/portal/PortalType.java
Normale Datei
39
src/de/steamwar/lobby/portal/PortalType.java
Normale Datei
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.lobby.portal;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public enum PortalType {
|
||||
TELEPORT(deserializer),
|
||||
COMMAND(deserializer),
|
||||
FIGHTSERVER(deserializer);
|
||||
|
||||
private final BiFunction<Map<String, Object>, Portal, PortalHandler> deserializer;
|
||||
|
||||
PortalType(BiFunction<Map<String, Object>, Portal, PortalHandler> deserializer) {
|
||||
this.deserializer = deserializer;
|
||||
}
|
||||
|
||||
public PortalHandler deserialize(Map<String, Object> map, Portal portal) {
|
||||
return deserializer.apply(map, portal);
|
||||
}
|
||||
}
|
83
src/de/steamwar/lobby/portal/TeleportPortal.java
Normale Datei
83
src/de/steamwar/lobby/portal/TeleportPortal.java
Normale Datei
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.lobby.portal;
|
||||
|
||||
import de.steamwar.lobby.listener.Portals;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class TeleportPortal extends Portal {
|
||||
|
||||
private static final List<TeleportPortal> portals = new ArrayList<>();
|
||||
|
||||
public static List<TeleportPortal> getPortals() {
|
||||
return portals;
|
||||
}
|
||||
|
||||
private final Set<TeleportPortal> sources = new HashSet<>();
|
||||
private final String target;
|
||||
|
||||
protected TeleportPortal(Map<String, Object> section) {
|
||||
super(section);
|
||||
this.target = (String) section.get("target");
|
||||
init();
|
||||
}
|
||||
|
||||
protected TeleportPortal(String id, Location pos1, Location pos2, String target) {
|
||||
super(id, pos1, pos2);
|
||||
this.target = target;
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
portals.stream().filter(portal -> portal.target.equals(this.id)).forEach(sources::add);
|
||||
portals.add(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(Player player, Location loc) {
|
||||
Deque<Portal> stack = Portals.getStack(player);
|
||||
if(!stack.isEmpty() && sources.contains(stack.peek())) {
|
||||
teleport(player, loc, stack.pop());
|
||||
} else {
|
||||
teleport(player, loc, getPortal(target));
|
||||
}
|
||||
}
|
||||
|
||||
protected void teleport(Player player, Location from, Portal target) {
|
||||
player.sendMessage("Symbolisierter teleport zu " + target.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> map = super.serialize();
|
||||
map.put("target", target);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() {
|
||||
portals.remove(this);
|
||||
portals.forEach(portal -> portal.sources.remove(this));
|
||||
super.delete();
|
||||
}
|
||||
}
|
90
src/de/steamwar/lobby/servers/Fightserver.java
Normale Datei
90
src/de/steamwar/lobby/servers/Fightserver.java
Normale Datei
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.lobby.servers;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import de.steamwar.comms.packets.FightInfoPacket;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class Fightserver {
|
||||
|
||||
private static final List<Consumer<Fightserver>> listeners = new ArrayList<>();
|
||||
|
||||
public static void registerListener(Consumer<Fightserver> listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
private static final Map<String, Fightserver> servers = new HashMap<>();
|
||||
|
||||
private Instant lastUpdate;
|
||||
private final String serverName;
|
||||
private final String gameMode;
|
||||
private final Observable<Set<Integer>> bluePlayers = new Observable<>();
|
||||
private final Observable<Set<Integer>> redPlayers = new Observable<>();
|
||||
private final Observable<Integer> playerCount = new Observable<>();
|
||||
|
||||
private Fightserver(FightInfoPacket fightInfo) {
|
||||
serverName = fightInfo.getServerName();
|
||||
gameMode = fightInfo.getGameMode();
|
||||
|
||||
update(fightInfo);
|
||||
listeners.forEach(listener -> listener.accept(this));
|
||||
|
||||
servers.put(serverName, this);
|
||||
}
|
||||
|
||||
private void update(FightInfoPacket fightInfo) {
|
||||
bluePlayers.update(new HashSet<>(fightInfo.getBluePlayers()));
|
||||
redPlayers.update(new HashSet<>(fightInfo.getRedPlayers()));
|
||||
playerCount.update(fightInfo.getBluePlayers().size() + fightInfo.getRedPlayers().size() + fightInfo.getSpectators().size());
|
||||
lastUpdate = Instant.now();
|
||||
}
|
||||
|
||||
private void remove() {
|
||||
|
||||
}
|
||||
|
||||
public static void newFightInfo(ByteArrayDataInput in) {
|
||||
FightInfoPacket fightInfo = new FightInfoPacket(in);
|
||||
Fightserver server = servers.get(fightInfo.getServerName());
|
||||
if (server == null) {
|
||||
new Fightserver(fightInfo);
|
||||
} else {
|
||||
server.update(fightInfo);
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeStopped() {
|
||||
Instant timeout = Instant.now().minus(5, ChronoUnit.SECONDS);
|
||||
|
||||
Iterator<Map.Entry<String, Fightserver>> it = servers.entrySet().iterator();
|
||||
while(it.hasNext()) {
|
||||
Map.Entry<String, Fightserver> server = it.next();
|
||||
if(timeout.isBefore(server.getValue().lastUpdate)) {
|
||||
server.getValue().remove();
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
50
src/de/steamwar/lobby/servers/Observable.java
Normale Datei
50
src/de/steamwar/lobby/servers/Observable.java
Normale Datei
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.lobby.servers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class Observable<T> {
|
||||
|
||||
private final List<Consumer<T>> observers = new ArrayList<>();
|
||||
|
||||
private T value;
|
||||
|
||||
public Observable() {
|
||||
value = null;
|
||||
}
|
||||
|
||||
public Observable(T initial) {
|
||||
value = initial;
|
||||
}
|
||||
|
||||
public void register(Consumer<T> observer) {
|
||||
observers.add(observer);
|
||||
}
|
||||
|
||||
public void update(T value) {
|
||||
if(!value.equals(this.value)) {
|
||||
this.value = value;
|
||||
observers.forEach(observer -> observer.accept(value));
|
||||
}
|
||||
}
|
||||
}
|
10
src/plugin.yml
Normale Datei
10
src/plugin.yml
Normale Datei
@ -0,0 +1,10 @@
|
||||
name: LobbySystem
|
||||
version: "1.0"
|
||||
authors:
|
||||
- Lixfel
|
||||
main: de.steamwar.lobby.LobbySystem
|
||||
depend: [SpigotCore, WorldEdit]
|
||||
api-version: "1.13"
|
||||
|
||||
commands:
|
||||
ak:
|
In neuem Issue referenzieren
Einen Benutzer sperren