SteamWar/FightSystem
Archiviert
13
1

Refactoring + Arena reset

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2021-03-20 14:49:43 +01:00
Ursprung 7b085d8ee6
Commit 9098a26aa9
37 geänderte Dateien mit 714 neuen und 514 gelöschten Zeilen

Datei anzeigen

@ -22,7 +22,9 @@ public enum ArenaMode {
public static final Set<ArenaMode> Prepare = Collections.unmodifiableSet(EnumSet.of(PREPARE));
public static final Set<ArenaMode> AntiTest = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK)));
public static final Set<ArenaMode> VariableTeams = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(RANKED, EVENT)));
public static final Set<ArenaMode> AntiEvent = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(EVENT)));
public static final Set<ArenaMode> AntiPrepare = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(PREPARE)));
public static final Set<ArenaMode> VariableTeams = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(RANKED, EVENT)));
public static final Set<ArenaMode> RankedEvent = Collections.unmodifiableSet(EnumSet.of(RANKED, EVENT));
public static final Set<ArenaMode> Restartable = Collections.unmodifiableSet(EnumSet.of(NORMAL, RANKED));
}

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.fightsystem;
import de.steamwar.fightsystem.utils.Region;
import de.steamwar.fightsystem.winconditions.Winconditions;
import de.steamwar.sql.Event;
import de.steamwar.sql.EventFight;
@ -50,6 +51,12 @@ public class Config {
public static final List<Integer> EnterStages;
//arena parameter
public static final Region BluePasteRegion;
public static final Region RedPasteRegion;
public static final Region BlueExtendRegion;
public static final Region RedExetendRegion;
public static final Region ArenaRegion;
public static final int SchemsizeX;
public static final int SchemsizeY;
public static final int SchemsizeZ;
@ -309,6 +316,12 @@ public class Config {
TeamRedRotate = teamRedRotate;
TeamBlueRotate = teamBlueRotate;
RedPasteRegion = new Region(TeamRedCornerX, TeamRedCornerY, TeamRedCornerZ, SchemsizeX, SchemsizeY, SchemsizeZ);
BluePasteRegion = new Region(TeamBlueCornerX, TeamBlueCornerY, TeamBlueCornerZ, SchemsizeX, SchemsizeY, SchemsizeZ);
RedExetendRegion = new Region(TeamRedCornerX, underArenaBorder, TeamRedCornerZ, SchemsizeX, upperArenaBorder, SchemsizeZ, BorderFromSchematic, BorderFromSchematic);
BlueExtendRegion = new Region(TeamBlueCornerX, underArenaBorder, TeamBlueCornerZ, SchemsizeX, upperArenaBorder, SchemsizeZ, BorderFromSchematic, BorderFromSchematic);
ArenaRegion = new Region(ArenaMinX, underArenaBorder, ArenaMinZ, ArenaMaxX - ArenaMinX, upperArenaBorder - underArenaBorder, ArenaMaxZ - ArenaMinZ);
EventKampfID = Integer.parseInt(System.getProperty("fightID", "0"));
if(EventKampfID >= 1){
EventFight eventFight = EventFight.get(EventKampfID);

Datei anzeigen

@ -41,35 +41,8 @@ public class ITechHider {
static final Map<PacketContainer, PacketContainer> packetCache = new HashMap<>();
static final Material obfuscateMaterial;
static final int threadMultiplier;
static final int arenaMinX;
static final int arenaMaxX;
static final int arenaMinZ;
static final int arenaMaxZ;
private static final int blueMinX;
private static final int blueMaxX;
private static final int blueMinZ;
private static final int blueMaxZ;
private static final int redMinX;
private static final int redMaxX;
private static final int redMinZ;
private static final int redMaxZ;
static{
int areaExtension = Config.EnterStages.isEmpty() ? Config.BorderFromSchematic : 0;
blueMinX = ITechHider.posToChunk(Config.TeamBlueCornerX - areaExtension);
blueMaxX = ITechHider.posToChunk(Config.TeamBlueCornerX + Config.SchemsizeX + areaExtension) + 1;
blueMinZ = ITechHider.posToChunk(Config.TeamBlueCornerZ - areaExtension);
blueMaxZ = ITechHider.posToChunk(Config.TeamBlueCornerZ + Config.SchemsizeZ + areaExtension) + 1;
redMinX = ITechHider.posToChunk(Config.TeamRedCornerX - areaExtension);
redMaxX = ITechHider.posToChunk(Config.TeamRedCornerX + Config.SchemsizeX + areaExtension) + 1;
redMinZ = ITechHider.posToChunk(Config.TeamRedCornerZ - areaExtension);
redMaxZ = ITechHider.posToChunk(Config.TeamRedCornerZ + Config.SchemsizeZ + areaExtension) + 1;
arenaMinX = ITechHider.posToChunk(Config.ArenaMinX);
arenaMaxX = ITechHider.posToChunk(Config.ArenaMaxX) + 1;
arenaMinZ = ITechHider.posToChunk(Config.ArenaMinZ);
arenaMaxZ = ITechHider.posToChunk(Config.ArenaMaxZ) + 1;
obfuscateMaterial = Material.getMaterial(Config.ObfuscateWith);
Bukkit.getScheduler().runTaskTimer(IFightSystem.getPlugin(), packetCache::clear, 1, 1);
@ -85,27 +58,15 @@ public class ITechHider {
IFightTeam ft = IFight.getPlayerTeam(p);
if(ft == null){
//Außerhalb der Arena
return arenaMinX > chunkX ||
chunkX > arenaMaxX ||
arenaMinZ > chunkZ ||
chunkZ > arenaMaxZ;
return Config.ArenaRegion.chunkOutside(chunkX, chunkZ);
}else if(ft.isBlue()){
return ft.canPlayerEntern(p) ||
redMinX > chunkX ||
chunkX > redMaxX ||
redMinZ > chunkZ ||
chunkZ > redMaxZ;
return ft.canPlayerEntern(p) || Config.BlueExtendRegion.chunkOutside(chunkX, chunkZ);
}else{
return ft.canPlayerEntern(p) ||
blueMinX > chunkX ||
chunkX > blueMaxX ||
blueMinZ > chunkZ ||
chunkZ > blueMaxZ;
return ft.canPlayerEntern(p) || Config.RedExetendRegion.chunkOutside(chunkX, chunkZ);
}
}
static int posToChunk(int c){
public static int posToChunk(int c){
int chunk = c / 16;
if(c<0)
chunk--;

Datei anzeigen

@ -0,0 +1,101 @@
package de.steamwar.fightsystem.utils;
import org.bukkit.Location;
import org.bukkit.block.Block;
import java.util.function.ObjIntConsumer;
public class Region {
private final int minX;
private final int minY;
private final int minZ;
private final int maxX;
private final int maxY;
private final int maxZ;
public Region(int minX, int minY, int minZ, int sizeX, int maxY, int sizeZ, int extendX, int extendZ) {
this(minX - extendX, minY, minZ - extendZ,
minX + sizeX + extendX, maxY, minZ + sizeZ + extendZ);
}
public Region(int minX, int minY, int minZ, int sizeX, int sizeY, int sizeZ) {
this.minX = minX;
this.minY = minY;
this.minZ = minZ;
this.maxX = minX + sizeX;
this.maxY = minY + sizeY;
this.maxZ = minZ + sizeZ;
}
public int getMinX() {
return minX;
}
public int getMinY() {
return minY;
}
public int getMinZ() {
return minZ;
}
public int getMaxX() {
return maxX;
}
public int getMaxY() {
return maxY;
}
public int getMaxZ() {
return maxZ;
}
public int getMinChunkX(){
return ITechHider.posToChunk(minX);
}
public int getMaxChunkX(){
return ITechHider.posToChunk(maxX);
}
public int getMinChunkZ(){
return ITechHider.posToChunk(minZ);
}
public int getMaxChunkZ(){
return ITechHider.posToChunk(maxZ);
}
public boolean chunkOutside(int cX, int cZ) {
return getMinChunkX() > cX || cX > getMaxChunkX() ||
getMinChunkZ() > cZ || cZ > getMaxChunkZ();
}
public void forEachChunk(ObjIntConsumer<Integer> executor) {
for(int x = getMinChunkX(); x <= getMaxChunkX(); x++)
for(int z = getMinChunkZ(); z <= getMaxChunkZ(); z++)
executor.accept(x, z);
}
public boolean in2dRegion(Location location){
return minX <= location.getX() && location.getX() < maxX && minZ <= location.getZ() && location.getZ() <= maxZ;
}
public boolean inRegion(Location location){
return in2dRegion(location) && minY < location.getY() && location.getY() < maxY;
}
public boolean playerInRegion(Location location){
return in2dRegion(location) && minY < location.getY() && location.getY() + 1.8 < maxY;
}
public boolean in2dRegion(Block block){
return minX <= block.getX() && block.getX() < maxX && minZ <= block.getZ() && block.getZ() <= maxZ;
}
public boolean inRegion(Block block){
return in2dRegion(block) && minY <= block.getY() && block.getY() < maxY;
}
}

Datei anzeigen

@ -26,6 +26,7 @@ import de.steamwar.fightsystem.countdown.*;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.fight.FightWorld;
import de.steamwar.fightsystem.listener.*;
import de.steamwar.fightsystem.record.RecordSystem;
import de.steamwar.fightsystem.record.Recorder;
@ -65,15 +66,18 @@ public class FightSystem extends JavaPlugin {
new PistonListener();
new Chat();
new HotbarGUI();
new Move();
new ConnectionListener();
new ArenaBorder();
new TeamArea();
new IngameDeath();
new InFightDamage();
new InFightInventory();
new DenyWorldInteraction();
new EventJoin();
new Recording();
new Check();
new PrepareJoin();
new Shutdown();
new SetupQuit();
new PrepareSchem();
new TestJoin();
new NormalJoin();
new RankedJoin();
@ -85,6 +89,7 @@ public class FightSystem extends JavaPlugin {
new EnterHandler();
new TechHider();
new FightWorld();
new WinconditionAllDead();
new WinconditionCaptainDead();
@ -101,10 +106,11 @@ public class FightSystem extends JavaPlugin {
new WinconditionPercentTimeout();
new NoPlayersOnlineCountdown();
new PreSchemPasteCountdown();
new SetupOverCountdown();
new PreSchemCountdown();
new PostSchemCountdown();
new PreRunningCountdown();
new SpectateOverCountdown();
new EventSpectateCountdown();
new LeaveCommand();
new KitCommand();
@ -122,16 +128,14 @@ public class FightSystem extends JavaPlugin {
CommandInjector.injectCommand(new GamemodeCommand());
} catch (Exception e) {
getLogger().log(Level.SEVERE, "Failed to replace commands", e);
Bukkit.shutdown();
return;
}
if(Config.mode == ArenaMode.EVENT) {
setPreSchemState();
}else if(Config.mode == ArenaMode.CHECK){
Fight.getBlueTeam().setNotPastingSchem(Schematic.getSchemFromDB(Config.CheckSchemID));
Fight.getBlueTeam().setSchem(Schematic.getSchemFromDB(Config.CheckSchemID));
}else if(Config.mode == ArenaMode.PREPARE) {
Fight.getBlueTeam().setNotPastingSchem(Schematic.getSchemFromDB(Config.PrepareSchemID));
Fight.getBlueTeam().setSchem(Schematic.getSchemFromDB(Config.PrepareSchemID));
}
}
@ -140,15 +144,18 @@ public class FightSystem extends JavaPlugin {
Recorder.closeAll();
}
public static void setPreLeaderState() {
FightState.setFightState(FightState.PRE_LEADER_SETUP);
}
public static void setPreSchemState() {
FightState.setFightState(FightState.PRE_SCHEM_SETUP);
}
public static void setPostSchemState() {
FightState.setFightState(FightState.POST_SCHEM_SETUP);
Fight.getBlueTeam().pasteSchematic();
Fight.getRedTeam().pasteSchematic();
}
public static void setPreRunningState() {
@ -177,8 +184,6 @@ public class FightSystem extends JavaPlugin {
Fight.getRedTeam().teleportToSpawn();
Bukkit.getOnlinePlayers().forEach(player -> player.getInventory().clear());
Bukkit.broadcastMessage(" ");
if(winFightTeam != null) {
Bukkit.broadcastMessage(PREFIX + "§aDas Team " + winFightTeam.getColoredName() + " §ahat gewonnen!");
} else {

Datei anzeigen

@ -106,9 +106,8 @@ public class Commands {
if(team == null)
return;
FightPlayer leader = team.getLeader();
p.sendMessage(FightSystem.PREFIX + "§aDu bist Team " + team.getColoredName() + " §abeigetreten!");
leader.sendMessage(FightSystem.PREFIX + "§aDer Spieler §e" + p.getName() + " §aist deinem Team beigetreten!");
team.broadcast(FightSystem.PREFIX + "§aDer Spieler §e" + p.getName() + " §aist dem Team beigetreten!");
team.addMember(p);
}
@ -120,9 +119,8 @@ public class Commands {
if(team == null)
return;
FightPlayer leader = team.getLeader();
p.sendMessage(FightSystem.PREFIX + "§aDu hast die Einladung von " + team.getColoredName() + " §aabgelehnt!");
leader.sendMessage(FightSystem.PREFIX + "§cDer Spieler §e" + p.getName() + " §chat deine Einladung abgelehnt!");
team.broadcast(FightSystem.PREFIX + "§cDer Spieler §e" + p.getName() + " §chat die Einladung abgelehnt!");
team.getInvited().remove(p);
}

Datei anzeigen

@ -184,7 +184,7 @@ public class GUI {
if(fightTeam == null)
return;
if(Config.test() || FightState.getFightState() != FightState.POST_SCHEM_SETUP)
fightTeam.setSchematic(s);
fightTeam.pasteSchem(s);
p.closeInventory();
});
inv.setCallback(-999, (ClickType click) -> p.closeInventory());

Datei anzeigen

@ -43,9 +43,9 @@ public class LeaderCommand implements CommandExecutor {
if(args.length == 0){
if(Fight.getFightPlayer(player) == null){
if(!Fight.getBlueTeam().hasTeamLeader())
if(Fight.getBlueTeam().isLeaderless())
Fight.getBlueTeam().setLeader(Fight.getBlueTeam().addMember(player));
else if(!Fight.getRedTeam().hasTeamLeader())
else if(Fight.getRedTeam().isLeaderless())
Fight.getRedTeam().setLeader(Fight.getRedTeam().addMember(player));
else
player.sendMessage(FightSystem.PREFIX + "§cEs sind bereits 2 Teamleader vorhanden");

Datei anzeigen

@ -22,7 +22,6 @@ package de.steamwar.fightsystem.commands;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCommand;
@ -71,10 +70,7 @@ public class LockschemCommand implements CommandExecutor {
}
Schematic.getSchemFromDB(fightTeam.getSchematic()).setSchemType(SchematicType.Normal);
player.sendMessage(FightSystem.PREFIX + "Schematic von " + fightTeam.getColoredName() + " §cgesperrt!");
FightPlayer leader = fightTeam.getLeader();
if(leader != null){
leader.sendMessage(FightSystem.PREFIX + "§cDeine Schematic wurde von " + player.getName() + " gesperrt!");
}
fightTeam.broadcast(FightSystem.PREFIX + "§cDie Schematic wurde von " + player.getName() + " gesperrt!");
return false;
}

Datei anzeigen

@ -0,0 +1,44 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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.fightsystem.countdown;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCountdown;
public class EventSpectateCountdown extends Countdown {
public EventSpectateCountdown() {
super(Config.SpectatorDuration, SWSound.BLOCK_NOTE_PLING, false);
new StateDependentCountdown(ArenaMode.Event, FightState.Spectate, this);
}
@Override
public String countdownCounting() {
return "bis der Server gestoppt wird!";
}
@Override
public void countdownFinished() {
FightSystem.shutdown(null);
}
}

Datei anzeigen

@ -25,9 +25,9 @@ import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCountdown;
public class SetupOverCountdown extends Countdown {
public class PostSchemCountdown extends Countdown {
public SetupOverCountdown() {
public PostSchemCountdown() {
super(Config.SetupDuration, null, false);
new StateDependentCountdown(ArenaMode.AntiTest, FightState.PostSchemSetup, this);
}

Datei anzeigen

@ -25,9 +25,9 @@ import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCountdown;
public class PreSchemPasteCountdown extends Countdown {
public class PreSchemCountdown extends Countdown {
public PreSchemPasteCountdown() {
public PreSchemCountdown() {
super(Config.PreSchemPasteDuration, SWSound.BLOCK_NOTE_PLING, false);
new StateDependentCountdown(ArenaMode.All, FightState.PreSchemSetup, this);
}

Datei anzeigen

@ -29,16 +29,16 @@ public class SpectateOverCountdown extends Countdown {
public SpectateOverCountdown() {
super(Config.SpectatorDuration, SWSound.BLOCK_NOTE_PLING, false);
new StateDependentCountdown(ArenaMode.AntiTest, FightState.Spectate, this);
new StateDependentCountdown(ArenaMode.Restartable, FightState.Spectate, this);
}
@Override
public String countdownCounting() {
return "bis der Server gestoppt wird!";
return "bis die Arena zurückgesetzt wird!";
}
@Override
public void countdownFinished() {
FightSystem.shutdown(null);
FightSystem.setPreLeaderState();
}
}

Datei anzeigen

@ -42,8 +42,8 @@ import java.util.logging.Level;
public class Fight {
private Fight(){}
private static final FightTeam redTeam = new FightTeam(Config.TeamRedName, Config.TeamRedColor, Config.TeamRedSpawn, Config.TeamRedCornerX, Config.TeamRedCornerY, Config.TeamRedCornerZ, Config.TeamRedRotate, false, Config.RedLeader);
private static final FightTeam blueTeam = new FightTeam(Config.TeamBlueName, Config.TeamBlueColor, Config.TeamBlueSpawn, Config.TeamBlueCornerX, Config.TeamBlueCornerY, Config.TeamBlueCornerZ, Config.TeamBlueRotate, true, Config.BlueLeader);
private static final FightTeam redTeam = new FightTeam(Config.TeamRedName, Config.TeamRedColor, Config.TeamRedSpawn, Config.RedPasteRegion, Config.RedExetendRegion, Config.TeamRedRotate, false, Config.RedLeader);
private static final FightTeam blueTeam = new FightTeam(Config.TeamBlueName, Config.TeamBlueColor, Config.TeamBlueSpawn, Config.BluePasteRegion, Config.BlueExtendRegion, Config.TeamBlueRotate, true, Config.BlueLeader);
public static void init(){
IFight.init(redTeam, blueTeam);
@ -159,8 +159,8 @@ public class Fight {
return 1000;
}
if(redTeam.getLeader() == null || redTeam.getLeader().getPlayer() == null ||
blueTeam.getLeader() == null || blueTeam.getLeader().getPlayer() == null){
if(redTeam.getLeader() == null || blueTeam.getLeader() == null){
return 1000;
}

Datei anzeigen

@ -22,12 +22,13 @@ package de.steamwar.fightsystem.fight;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.core.VersionedRunnable;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.IFightSystem;
import de.steamwar.fightsystem.record.RecordSystem;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.IStateDependent;
import de.steamwar.fightsystem.states.StateDependent;
import de.steamwar.fightsystem.utils.ColorConverter;
import de.steamwar.sql.NoClipboardException;
import de.steamwar.sql.Schematic;
@ -42,10 +43,9 @@ import org.bukkit.event.inventory.InventoryMoveItemEvent;
import java.io.IOException;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.logging.Level;
public class FightSchematic implements IStateDependent {
public class FightSchematic extends StateDependent {
private final FightTeam team;
private final int pasteX;
@ -60,6 +60,7 @@ public class FightSchematic implements IStateDependent {
private int schematic = 0;
public FightSchematic(FightTeam team, int pasteX, int pasteY, int pasteZ, int cornerX, int cornerY, int cornerZ, boolean rotate) {
super(ArenaMode.All, FightState.Schem);
this.team = team;
this.pasteX = pasteX;
this.pasteY = pasteY;
@ -68,7 +69,6 @@ public class FightSchematic implements IStateDependent {
this.cornerY = cornerY;
this.cornerZ = cornerZ;
this.rotate = rotate;
FightState.registerStateDependent(this);
}
public boolean hasSchematic(){
@ -89,11 +89,6 @@ public class FightSchematic implements IStateDependent {
}
}
@Override
public Set<FightState> enabled() {
return FightState.Schem;
}
@Override
public void enable() {
if(FightState.getFightState() == FightState.SPECTATE)
@ -107,6 +102,12 @@ public class FightSchematic implements IStateDependent {
setSchematic(publics.get(new Random().nextInt(publics.size())));
}
if(!ArenaMode.Test.contains(Config.mode)){
FightPlayer leader = team.getLeader();
if(leader != null)
leader.getPlayer().getInventory().clear(0);
}
if(team.isBlue())
RecordSystem.blueSchem(schematic);
else
@ -175,7 +176,7 @@ public class FightSchematic implements IStateDependent {
@Override
public void disable() {
//TODO: Reset team area
team.teleportToSpawn();
}
private static class FreezeWorld implements Listener {

Datei anzeigen

@ -30,6 +30,7 @@ import de.steamwar.fightsystem.record.RecordSystem;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.listener.FightScoreboard;
import de.steamwar.fightsystem.utils.ItemBuilder;
import de.steamwar.fightsystem.utils.Region;
import de.steamwar.fightsystem.utils.TechHider;
import de.steamwar.inventory.SWItem;
import de.steamwar.sql.Schematic;
@ -59,27 +60,20 @@ public class FightTeam implements IFightTeam{
private final boolean blue;
private final Location spawn;
private final int pasteX;
private final int pasteY;
private final int pasteZ;
private final int cornerX;
private final int cornerY;
private final int cornerZ;
private final boolean rotate;
private final Region schemRegion;
private final Region extendRegion;
public FightTeam(String name, String prefix, Location spawn, int cornerX, int cornerY, int cornerZ, boolean rotate, boolean blue, UUID designatedLeader) {
public FightTeam(String name, String prefix, Location spawn, Region schemRegion, Region extendRegion, boolean rotate, boolean blue, UUID designatedLeader) {
this.spawn = spawn;
this.pasteX = cornerX + Config.SchemsizeX/2;
this.pasteY = cornerY;
this.pasteZ = cornerZ + Config.SchemsizeZ/2;
this.schemRegion = schemRegion;
this.extendRegion = extendRegion;
int pasteX = schemRegion.getMinX() + Config.SchemsizeX / 2;
int pasteY = schemRegion.getMinY();
int pasteZ = schemRegion.getMinZ() + Config.SchemsizeZ / 2;
this.name = name;
this.prefix = prefix;
this.ready = false;
this.rotate = rotate;
this.cornerX = cornerX;
this.cornerY = cornerY;
this.cornerZ = cornerZ;
this.schematic = new FightSchematic(this, pasteX, pasteY, pasteZ, cornerX, cornerY, cornerZ, rotate);
this.schematic = new FightSchematic(this, pasteX, pasteY, pasteZ, schemRegion.getMinX(), schemRegion.getMinY(), schemRegion.getMinZ(), rotate);
this.blue = blue;
this.designatedLeader = designatedLeader;
color = ChatColor.getByChar(ChatColor.getLastColors(prefix).replace("§", ""));
@ -94,20 +88,28 @@ public class FightTeam implements IFightTeam{
team.setAllowFriendlyFire(false);
}
public Region getSchemRegion() {
return schemRegion;
}
public Region getExtendRegion() {
return extendRegion;
}
public final int getCornerX() {
return cornerX;
return schemRegion.getMinX();
}
public final int getCornerY() {
return cornerY;
return schemRegion.getMinY();
}
public final int getCornerZ() {
return cornerZ;
return schemRegion.getMinZ();
}
public boolean canbeLeader(Player p){
return !hasTeamLeader() && (designatedLeader == null || designatedLeader.equals(p.getUniqueId()));
return isLeaderless() && (designatedLeader == null || designatedLeader.equals(p.getUniqueId()));
}
public void teleportToSpawn(){
@ -172,24 +174,24 @@ public class FightTeam implements IFightTeam{
public void removePlayer(Player player) {
FightPlayer fightPlayer = getFightPlayer(player);
final List<TechHider.ChunkPos> chunksToReload = TechHider.prepareChunkReload(player);
List<TechHider.ChunkPos> chunksToReload = TechHider.prepareChunkReload(player);
players.remove(player);
team.removeEntry(player.getName());
fightPlayer.getPlayer().getInventory().clear();
if(fightPlayer.equals(leader) && FightState.setup())
if(fightPlayer.equals(leader))
setLeader(null);
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
player.teleport(Config.SpecSpawn);
if(!Config.test())
player.getInventory().clear();
if(!ArenaMode.Test.contains(Config.mode))
new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7" + player.getName()).send(player);
RecordSystem.entityDespawns(player);
TechHider.reloadChunks(player, chunksToReload);
}
public boolean hasTeamLeader() {
return leader != null;
public boolean isLeaderless() {
return leader == null;
}
@Override
@ -207,7 +209,7 @@ public class FightTeam implements IFightTeam{
setLeader(players.values().iterator().next());
Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §e" + this.leader.getPlayer().getName() + " §aist nun Leader von Team " + getColoredName() + "§a!");
}else if(!ArenaMode.RankedEvent.contains(Config.mode)){
FightSystem.shutdown(FightSystem.PREFIX + "§cTeam " + getColoredName() + " §chat keine Spieler mehr.\n Arena schließt...");
FightSystem.setPreLeaderState();
}
return;
}
@ -248,27 +250,19 @@ public class FightTeam implements IFightTeam{
return ready;
}
public void pasteSchematic(){
if(!Config.test() && leader != null)
leader.getPlayer().getInventory().clear(0);
}
public void pasteSchem(Schematic schematic){
setSchem(schematic);
public void setSchematic(Schematic schematic){
setNotPastingSchem(schematic);
broadcast(FightSystem.PREFIX + "§7Das §e" + Config.GameName + " " + schematic.getSchemName() + " §7wird für den Kampf verwendet!");
if(!Config.test())
leader.getPlayer().getInventory().clear(0);
if(Config.test())
pasteSchematic();
if(ArenaMode.Test.contains(Config.mode))
this.schematic.enable();
else if(Fight.getOpposite(this).hasSchematic()){
FightSystem.setPostSchemState();
}
}
public void setNotPastingSchem(Schematic schematic){
public void setSchem(Schematic schematic){
this.schematic.setSchematic(schematic);
broadcast(FightSystem.PREFIX + "§7Das §e" + Config.GameName + " " + schematic.getSchemName() + " §7wird für den Kampf verwendet!");
}
public boolean hasSchematic(){

Datei anzeigen

@ -0,0 +1,49 @@
package de.steamwar.fightsystem.fight;
import de.steamwar.core.events.ChunkListener;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent;
import net.minecraft.server.v1_15_R1.Chunk;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
import org.bukkit.entity.Player;
public class FightWorld extends StateDependent {
private final World world = Bukkit.getWorlds().get(0);
public FightWorld() {
super(ArenaMode.Restartable, FightState.Schem);
}
@Override
public void enable() {
//unused
}
@Override
public void disable() {
World backup = new WorldCreator(world.getName() + "/backup").createWorld();
assert backup != null;
Config.ArenaRegion.forEachChunk((x, z) -> resetChunk(backup, x, z));
Bukkit.unloadWorld(backup, false);
}
private void resetChunk(World backup, int x, int z){
Chunk chunk = ((CraftWorld) world).getHandle().getChunkAt(x, z);
Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z);
System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length);
chunk.tileEntities.clear();
chunk.tileEntities.putAll(backupChunk.tileEntities);
chunk.heightMap.clear();
chunk.heightMap.putAll(backupChunk.heightMap);
for(Player p : Bukkit.getOnlinePlayers()){
ChunkListener.sendChunk(p, x, z);
}
}
}

Datei anzeigen

@ -0,0 +1,72 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
public class ArenaBorder implements Listener {
public ArenaBorder() {
new StateDependentListener(ArenaMode.All, FightState.All, this);
}
@EventHandler
public void arenaBorder(PlayerMoveEvent event){
Player player = event.getPlayer();
Location to = event.getTo();
assert to != null;
if(!Config.ArenaRegion.in2dRegion(to)){
reset(event);
return;
}
FightTeam team = Fight.getPlayerTeam(player);
if(team == null || player.getGameMode() == GameMode.SPECTATOR)
return;
if(to.getY() <= Config.underArenaBorder) {
if(FightState.infight())
player.damage(2);
else if(!Config.GroundWalkable)
player.teleport(team.getSpawn());
}else if(to.getY() + 1.8 <= Config.upperArenaBorder){
reset(event);
}
}
private void reset(PlayerMoveEvent event){
Player player = event.getPlayer();
player.teleport(event.getFrom());
BasicListener.toActionbar(player, TextComponent.fromLegacyText("§cDu darfst die Arena nicht verlassen"));
}
}

Datei anzeigen

@ -1,118 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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.fightsystem.listener;
import de.steamwar.comms.packets.TablistNamePacket;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.Countdown;
import de.steamwar.fightsystem.countdown.SWSound;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.record.RecordSystem;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class ConnectionListener implements Listener {
public ConnectionListener() {
new StateDependentListener(ArenaMode.All, FightState.All, this);
}
@EventHandler(priority = EventPriority.HIGH)
public void handlePlayerJoin(PlayerJoinEvent event) {
event.setJoinMessage(null);
Player player = event.getPlayer();
FightTeam fightTeam = Fight.getPlayerTeam(player);
if (fightTeam == null) {
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
player.teleport(Config.SpecSpawn);
if(!Config.test())
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7" + player.getName()).send(player), 5);
} else {
player.teleport(fightTeam.getSpawn());
if(FightState.setup())
Fight.setPlayerGamemode(player, GameMode.SURVIVAL);
else
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void handlePlayerDeath(PlayerDeathEvent event) {
event.setDeathMessage(null);
Player player = event.getEntity().getPlayer();
FightTeam fightTeam = Fight.getPlayerTeam(player);
if(fightTeam == null)
return;
assert player != null;
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler " + fightTeam.getPrefix() + player.getName() + " §cist gestorben!");
fightTeam.getFightPlayer(player).setOut();
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
player.teleport(fightTeam.getSpawn());
Fight.playSound(Countdown.getSound(SWSound.ENTITY_WITHER_DEATH), 100.0F, 1.0F);
RecordSystem.entityDespawns(player);
}
@EventHandler(priority = EventPriority.HIGH)
public void handlePlayerQuit(PlayerQuitEvent event) {
event.setQuitMessage(null);
Player player = event.getPlayer();
FightTeam fightTeam = Fight.getPlayerTeam(player);
if(fightTeam == null)
return;
if(FightState.setup()){
fightTeam.removePlayer(player);
RecordSystem.entityDespawns(player);
}else if(FightState.ingame()){
FightPlayer fightPlayer = fightTeam.getFightPlayer(player);
if(fightPlayer.isLiving()) {
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler " + fightTeam.getPrefix() + player.getName() + " §chat den Kampf verlassen!");
fightTeam.getFightPlayer(player).setOut();
RecordSystem.entityDespawns(player);
}
}
//Shutdown server if nobody online and its not an event server
if(Config.mode != ArenaMode.EVENT && (Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(player))))
FightSystem.shutdown(null);
}
}

Datei anzeigen

@ -81,7 +81,7 @@ public class EventJoin implements Listener {
if(team != null && team.getPlayers().size() < Config.MaximumTeamMembers){
FightPlayer fp = team.addMember(player);
if(!team.hasTeamLeader())
if(team.isLeaderless())
team.setLeader(fp);
return;
}

Datei anzeigen

@ -0,0 +1,77 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.Countdown;
import de.steamwar.fightsystem.countdown.SWSound;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.record.RecordSystem;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class IngameDeath implements Listener {
public IngameDeath() {
new StateDependentListener(ArenaMode.All, FightState.Ingame, this);
}
@EventHandler(priority = EventPriority.HIGH)
public void handlePlayerDeath(PlayerDeathEvent event) {
event.setDeathMessage(null);
Player player = event.getEntity();
FightTeam team = Fight.getPlayerTeam(player);
if(team == null)
return;
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler " + team.getPrefix() + player.getName() + " §cist gestorben!");
Fight.playSound(Countdown.getSound(SWSound.ENTITY_WITHER_DEATH), 100.0F, 1.0F);
team.getFightPlayer(player).setOut();
}
@EventHandler(priority = EventPriority.HIGH)
public void handlePlayerQuit(PlayerQuitEvent event) {
event.setQuitMessage(null);
Player player = event.getPlayer();
FightTeam team = Fight.getPlayerTeam(player);
if(team == null)
return;
FightPlayer fightPlayer = team.getFightPlayer(player);
if(fightPlayer.isLiving()) {
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler " + team.getPrefix() + player.getName() + " §chat den Kampf verlassen!");
team.getFightPlayer(player).setOut();
RecordSystem.entityDespawns(player);
}
}
}

Datei anzeigen

@ -1,127 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.utils.Region;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import java.util.logging.Level;
public class Move implements Listener {
private static final String DENY_ARENA = "§cDu darfst die Arena nicht verlassen";
private static final String DENY_TEAM = "§cDu darfst nicht zu den Teams";
private static final String DENY_ENTERN = "§cDu darfst nicht entern";
public Move() {
new StateDependentListener(ArenaMode.All, FightState.All, this);
}
@EventHandler
public void teamAreas(PlayerMoveEvent event) {
Player player = event.getPlayer();
if(player == FightSystem.getEventLeiter() || Config.test())
return;
Location to = event.getTo();
FightTeam fightTeam = Fight.getPlayerTeam(player);
assert to != null;
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){
if(fightTeam == null)
reset(event, DENY_TEAM);
else if(fightTeam == Fight.getRedTeam() && (player.getGameMode() == GameMode.SPECTATOR || !fightTeam.canPlayerEntern(player)))
reset(event, DENY_ENTERN);
else
return; // Is allowed in area
checkInInnerArea(event.getPlayer(), to, Config.TeamBlueCornerX, Config.TeamBlueCornerZ);
}else if(inRedArea){
if(fightTeam == null)
reset(event, DENY_TEAM);
else if(fightTeam == Fight.getBlueTeam() && (player.getGameMode() == GameMode.SPECTATOR || !fightTeam.canPlayerEntern(player)))
reset(event, DENY_ENTERN);
else
return; // Is allowed in area
checkInInnerArea(event.getPlayer(), to, Config.TeamRedCornerX, Config.TeamRedCornerZ);
}else if(fightTeam != null && player.getGameMode() != GameMode.SPECTATOR && !fightTeam.canPlayerEntern(player))
reset(event, DENY_ENTERN);
}
private void checkInInnerArea(Player player, Location to, int teamCornerX, int teamCornerZ){
boolean inArenaY = to.getY() + 1.8 <= Config.TeamBlueCornerY + Config.SchemsizeY;
boolean inArea = inArenaY && Region.isIn2DRange(to, teamCornerX, teamCornerZ, Config.SchemsizeX, Config.SchemsizeZ, 0);
if(inArea && Config.BorderFromSchematic >= 5){ // Preventing false positives due to small extension
player.kickPlayer(null);
Bukkit.getLogger().log(Level.SEVERE, player.getName() + " ist in einen Teambereich eingedrungen.");
}
}
@EventHandler
public void arenaBorder(PlayerMoveEvent event){
Player player = event.getPlayer();
Location to = event.getTo();
//Check in Arena
assert to != null;
if(!Region.isIn2DRegion(to, Config.ArenaMinX, Config.ArenaMinZ, Config.ArenaMaxX, Config.ArenaMaxZ)){
reset(event, DENY_ARENA);
return;
}
FightTeam team = Fight.getPlayerTeam(player);
boolean inArenaY = to.getY() + 1.8 <= Config.upperArenaBorder;
if(to.getY() <= Config.underArenaBorder) {
if(player.getGameMode() == GameMode.SPECTATOR || team == null)
reset(event, DENY_ARENA);
else if(FightState.infight())
player.damage(2);
else if(!Config.GroundWalkable)
player.teleport(team.getSpawn());
}else if(team != null && !inArenaY){
reset(event, DENY_ARENA);
}
}
private void reset(PlayerMoveEvent event, String message){
Player player = event.getPlayer();
player.teleport(event.getFrom());
BasicListener.toActionbar(player, TextComponent.fromLegacyText(message));
}
}

Datei anzeigen

@ -23,6 +23,7 @@ import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
@ -50,8 +51,9 @@ public class NormalJoin implements Listener {
}
}
if(Fight.getRedTeam().hasTeamLeader() && Fight.getBlueTeam().hasTeamLeader()
&& (Fight.getRedTeam().getLeader().getPlayer() == player || Fight.getBlueTeam().getLeader().getPlayer() == player)) {
FightPlayer redLeader = Fight.getRedTeam().getLeader();
FightPlayer blueLeader = Fight.getBlueTeam().getLeader();
if(redLeader != null && blueLeader != null && (Fight.getRedTeam().getLeader().getPlayer() == player || Fight.getBlueTeam().getLeader().getPlayer() == player)) {
FightSystem.setPreSchemState();
}
}

Datei anzeigen

@ -19,26 +19,30 @@
package de.steamwar.fightsystem.listener;
import de.steamwar.comms.packets.TablistNamePacket;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.sql.SteamwarUser;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.SpawnerSpawnEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.FurnaceSmeltEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.*;
import org.bukkit.event.weather.WeatherChangeEvent;
import org.bukkit.event.world.WorldLoadEvent;
public class Permanent implements Listener {
@ -46,6 +50,39 @@ public class Permanent implements Listener {
new StateDependentListener(ArenaMode.All, FightState.All, this);
}
@EventHandler
public void handlePlayerRespawn(PlayerRespawnEvent event){
Player player = event.getPlayer();
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
FightTeam team = Fight.getPlayerTeam(player);
event.setRespawnLocation(team == null ? Config.SpecSpawn : team.getSpawn());
}
@EventHandler
public void onTpGM3(PlayerTeleportEvent e) {
if (e.getCause() == PlayerTeleportEvent.TeleportCause.SPECTATE) {
e.setCancelled(true);
BasicListener.toActionbar(e.getPlayer(), TextComponent.fromLegacyText("§cDu darfst diese Teleportfunktion nicht benutzen!"));
e.getPlayer().kickPlayer("§cDu darfst diese Teleportfunktion nicht benutzen!");
}
}
@EventHandler(priority = EventPriority.HIGH)
public void handlePlayerJoin(PlayerJoinEvent event) {
event.setJoinMessage(null);
Player player = event.getPlayer();
FightTeam fightTeam = Fight.getPlayerTeam(player);
if (fightTeam == null) {
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
player.teleport(Config.SpecSpawn);
if(!ArenaMode.Test.contains(Config.mode))
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7" + player.getName()).send(player), 5);
}
}
@EventHandler
public void handleFoodLevelChange(FoodLevelChangeEvent event) {
event.setCancelled(true);
@ -87,21 +124,7 @@ public class Permanent implements Listener {
}
@EventHandler
public void handlePlayerRespawn(PlayerRespawnEvent event) {
Player player = event.getPlayer();
FightTeam team = Fight.getPlayerTeam(player);
if(team == null)
event.setRespawnLocation(Config.SpecSpawn);
else
event.setRespawnLocation(team.getSpawn());
}
@EventHandler
public void onTpGM3(PlayerTeleportEvent e) {
if (e.getCause() == PlayerTeleportEvent.TeleportCause.SPECTATE) {
e.setCancelled(true);
BasicListener.toActionbar(e.getPlayer(), TextComponent.fromLegacyText("§cDu darfst diese Teleportfunktion nicht benutzen!"));
e.getPlayer().kickPlayer("§cDu darfst diese Teleportfunktion nicht benutzen!");
}
public void onWorldLoad(WorldLoadEvent e) {
e.getWorld().setAutoSave(false);
}
}

Datei anzeigen

@ -22,7 +22,6 @@ package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.utils.Region;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.event.EventHandler;
@ -40,13 +39,9 @@ public class PistonListener implements Listener {
@EventHandler
public void handlePistonExtend(BlockPistonExtendEvent e){
BlockFace b = e.getDirection();
BlockFace b = e.getDirection().getOppositeFace();
for(Block block : e.getBlocks()){
if(
block.getY() > Config.upperArenaBorder ||
(!Region.isIn2DRange(block.getLocation(), Config.TeamBlueCornerX + b.getModX(), Config.TeamBlueCornerZ + b.getModZ(), Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic) &&
!Region.isIn2DRange(block.getLocation(), Config.TeamRedCornerX + b.getModX(), Config.TeamRedCornerZ + b.getModZ(), Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic))
){
if(Config.BlueExtendRegion.inRegion(block.getRelative(b)) && Config.RedExetendRegion.inRegion(block.getRelative(b))){
e.setCancelled(true);
return;
}
@ -55,13 +50,9 @@ public class PistonListener implements Listener {
@EventHandler
public void handlePistonRetract(BlockPistonRetractEvent e){
BlockFace b = e.getDirection();
BlockFace b = e.getDirection().getOppositeFace();
for(Block block : e.getBlocks()){
if(
block.getY() > Config.upperArenaBorder ||
(!Region.isIn2DRange(block.getLocation(), Config.TeamBlueCornerX + b.getModX(), Config.TeamBlueCornerZ + b.getModZ(), Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic) &&
!Region.isIn2DRange(block.getLocation(), Config.TeamRedCornerX + b.getModX(), Config.TeamRedCornerZ + b.getModZ(), Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic))
){
if(Config.BlueExtendRegion.inRegion(block.getRelative(b)) && Config.RedExetendRegion.inRegion(block.getRelative(b))) {
e.setCancelled(true);
return;
}

Datei anzeigen

@ -30,10 +30,16 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class PrepareJoin implements Listener {
public class PrepareSchem implements Listener {
public PrepareJoin() {
new StateDependentListener(ArenaMode.Prepare, FightState.All, this);
public PrepareSchem() {
new StateDependentListener(ArenaMode.Prepare, FightState.Setup, this){
@Override
public void disable() {
super.disable();
//TODO
}
};
}
@EventHandler

Datei anzeigen

@ -26,6 +26,7 @@ import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.record.RecordSystem;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent;
import de.steamwar.fightsystem.states.StateDependentListener;
import org.bukkit.*;
import org.bukkit.entity.EntityType;
@ -53,19 +54,21 @@ public class Recording implements Listener {
private static final Random random = new Random();
public Recording() {
new StateDependentListener(Config.recording(), FightState.All, this){
new StateDependentListener(Config.recording(), FightState.All, this);
new StateDependent(Config.recording(), FightState.Ingame){
@Override
public void stateChange(FightState state) {
if(state == FightState.PRE_RUNNING) {
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> {
setKitItems(Fight.getBlueTeam());
setKitItems(Fight.getRedTeam());
}, 1);
}else if(state == FightState.SPECTATE){
despawnTeam(Fight.getRedTeam());
despawnTeam(Fight.getBlueTeam());
despawnTNT();
}
public void enable() {
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> {
setKitItems(Fight.getBlueTeam());
setKitItems(Fight.getRedTeam());
}, 1);
}
@Override
public void disable() {
despawnTeam(Fight.getRedTeam());
despawnTeam(Fight.getBlueTeam());
despawnTNT();
}
};
}

Datei anzeigen

@ -0,0 +1,50 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
public class SetupQuit implements Listener {
public SetupQuit(){
new StateDependentListener(ArenaMode.All, FightState.Setup, this);
}
@EventHandler(priority = EventPriority.HIGH)
public void handlePlayerQuit(PlayerQuitEvent event) {
event.setQuitMessage(null);
Player player = event.getPlayer();
FightTeam team = Fight.getPlayerTeam(player);
if(team == null)
return;
team.removePlayer(player);
}
}

Datei anzeigen

@ -0,0 +1,43 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
public class Shutdown implements Listener {
public Shutdown(){
new StateDependentListener(ArenaMode.AntiEvent, FightState.All, this);
}
@EventHandler(priority = EventPriority.HIGH)
public void handlePlayerQuit(PlayerQuitEvent event) {
//Shutdown server if nobody online and its not an event server
if(Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(event.getPlayer())))
Bukkit.shutdown();
}
}

Datei anzeigen

@ -0,0 +1,73 @@
package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import java.util.logging.Level;
public class TeamArea implements Listener {
private static final String DENY_TEAM = "§cDu darfst nicht zu den Teams";
private static final String DENY_ENTERN = "§cDu darfst nicht entern";
public TeamArea() {
new StateDependentListener(ArenaMode.AntiTest, FightState.All, this);
}
@EventHandler
public void teamAreas(PlayerMoveEvent event) {
Player player = event.getPlayer();
if(player == FightSystem.getEventLeiter())
return;
Location to = event.getTo();
assert to != null;
FightTeam team = Fight.getPlayerTeam(player);
if(Config.BlueExtendRegion.playerInRegion(to)){
if(team == null)
reset(event, DENY_TEAM);
else if(team == Fight.getRedTeam() && (player.getGameMode() == GameMode.SPECTATOR || !team.canPlayerEntern(player)))
reset(event, DENY_ENTERN);
else
return; // Is allowed in area
checkInInnerArea(event.getPlayer(), to, Fight.getBlueTeam());
}else if(Config.RedExetendRegion.playerInRegion(to)){
if(team == null)
reset(event, DENY_TEAM);
else if(team == Fight.getBlueTeam() && (player.getGameMode() == GameMode.SPECTATOR || !team.canPlayerEntern(player)))
reset(event, DENY_ENTERN);
else
return; // Is allowed in area
checkInInnerArea(event.getPlayer(), to, Fight.getRedTeam());
}else if(team != null && player.getGameMode() != GameMode.SPECTATOR && !team.canPlayerEntern(player))
reset(event, DENY_ENTERN);
}
private void checkInInnerArea(Player player, Location to, FightTeam team){
if(team.getSchemRegion().playerInRegion(to) && Config.BorderFromSchematic >= 5){ // Preventing false positives due to small extension
player.kickPlayer(null);
Bukkit.getLogger().log(Level.SEVERE, player.getName() + " ist in einen Teambereich eingedrungen.");
}
}
private void reset(PlayerMoveEvent event, String message){
Player player = event.getPlayer();
player.teleport(event.getFrom());
BasicListener.toActionbar(player, TextComponent.fromLegacyText(message));
}
}

Datei anzeigen

@ -41,7 +41,7 @@ public class TestJoin implements Listener {
Player player = event.getPlayer();
FightTeam fightTeam = Fight.getPlayerTeam(player);
if (fightTeam == null && (!Fight.getRedTeam().hasTeamLeader() || !Fight.getBlueTeam().hasTeamLeader())) {
if (fightTeam == null && (Fight.getRedTeam().isLeaderless() || Fight.getBlueTeam().isLeaderless())) {
player.sendMessage(FightSystem.PREFIX + "§7Werde zum Teamleader mit §8/§eleader");
}

Datei anzeigen

@ -64,12 +64,9 @@ public enum FightState {
for(Map.Entry<IStateDependent, Boolean> feature : stateDependentFeatures.entrySet()){
//Enable feature if should be enabled and currently disabled
if(feature.getKey().enabled().contains(fightState)){
if(!feature.getValue()){
feature.getKey().enable();
feature.setValue(true);
}
feature.getKey().stateChange(fightState);
if(feature.getKey().enabled().contains(fightState) && !feature.getValue()){
feature.getKey().enable();
feature.setValue(true);
}
//Disable feature if should be disabled and currently enabled

Datei anzeigen

@ -37,9 +37,4 @@ public interface IStateDependent {
* Disables the state dependent object
*/
void disable();
/**
* On state change when enabled
*/
default void stateChange(FightState state){}
}

Datei anzeigen

@ -41,7 +41,7 @@ public class FightStatistics {
private FightStatistics(){}
private static Timestamp starttime = Timestamp.from(Instant.now());
private static int K = 20;
private static final int K = 20;
public static void start(){
starttime = Timestamp.from(Instant.now());
@ -49,10 +49,14 @@ public class FightStatistics {
public static void saveStats(FightTeam winner, String windescription){
String gameMode = Config.SchematicType.toDB();
if(!Fight.getBlueTeam().hasTeamLeader() || !Fight.getRedTeam().hasTeamLeader())
return;
SteamwarUser blueLeader = SteamwarUser.get(Fight.getBlueTeam().getLeader().getPlayer().getUniqueId());
SteamwarUser redLeader = SteamwarUser.get(Fight.getRedTeam().getLeader().getPlayer().getUniqueId());
int blueLeader = 0;
int redLeader = 0;
if(Fight.getBlueTeam().getLeader() != null)
blueLeader = SteamwarUser.get(Fight.getBlueTeam().getLeader().getPlayer().getUniqueId()).getId();
if(Fight.getRedTeam().getLeader() != null)
redLeader = SteamwarUser.get(Fight.getRedTeam().getLeader().getPlayer().getUniqueId()).getId();
int win = 0;
double blueResult;
if(winner == Fight.getBlueTeam()) {
@ -65,7 +69,8 @@ public class FightStatistics {
blueResult = 0.5;
}
Integer blueSchem, redSchem;
Integer blueSchem;
Integer redSchem;
try{
blueSchem = Schematic.getSchemFromDB(Fight.getBlueTeam().getSchematic()).getSchemID();
}catch(SecurityException e){
@ -85,7 +90,7 @@ public class FightStatistics {
try {
int fightId = create(gameMode, Bukkit.getWorlds().get(0).getName(), starttime, remainingTime,
blueLeader.getId(), redLeader.getId(), blueSchem, redSchem, win, windescription);
blueLeader, redLeader, blueSchem, redSchem, win, windescription);
for (FightPlayer fp : Fight.getBlueTeam().getPlayers())
savePlayerStats(fp, fightId);
@ -96,16 +101,16 @@ public class FightStatistics {
}
if(Config.Ranked){
int blueElo = Elo.getElo(blueLeader.getId(), gameMode);
int redElo = Elo.getElo(redLeader.getId(), gameMode);
int blueElo = Elo.getElo(blueLeader, gameMode);
int redElo = Elo.getElo(redLeader, gameMode);
double redWinExpectation = 1 / (1 + Math.pow(10, (blueElo - redElo) / 400f));
double blueWinExpectation = 1 / (1 + Math.pow(10, (redElo - blueElo) / 400f));
int newBlueElo = (int) Math.round(blueElo + K * (blueResult - blueWinExpectation));
int newRedElo = (int) Math.round(redElo + K * (1 - blueResult - redWinExpectation));
Elo.setElo(blueLeader.getId(), gameMode, newBlueElo);
Elo.setElo(redLeader.getId(), gameMode, newRedElo);
Bukkit.broadcastMessage(FightSystem.PREFIX + "§7ELO von " + Fight.getBlueTeam().getPrefix() + blueLeader.getUserName() + "§8: §7" + blueElo + "§8»§e" + newBlueElo);
Bukkit.broadcastMessage(FightSystem.PREFIX + "§7ELO von " + Fight.getRedTeam().getPrefix() + redLeader.getUserName() + "§8: §7" + redElo + "§8»§e" + newRedElo);
Elo.setElo(blueLeader, gameMode, newBlueElo);
Elo.setElo(redLeader, gameMode, newRedElo);
Bukkit.broadcastMessage(FightSystem.PREFIX + "§7ELO von " + Fight.getBlueTeam().getPrefix() + Fight.getBlueTeam().getLeader().getPlayer().getName() + "§8: §7" + blueElo + "§8»§e" + newBlueElo);
Bukkit.broadcastMessage(FightSystem.PREFIX + "§7ELO von " + Fight.getRedTeam().getPrefix() + Fight.getRedTeam().getLeader().getPlayer().getName() + "§8: §7" + redElo + "§8»§e" + newRedElo);
}
}

Datei anzeigen

@ -1,55 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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.fightsystem.utils;
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;
}
}

Datei anzeigen

@ -232,10 +232,10 @@ public class TechHider implements IStateDependent {
if(DISABLED)
return Collections.emptyList();
List<ChunkPos> chunksToReload = new ArrayList<>();
for(int x = ITechHider.arenaMinX; x <= ITechHider.arenaMaxX; x++)
for(int z = ITechHider.arenaMinZ; z <= ITechHider.arenaMaxZ; z++)
if(!bypass(p, x, z))
chunksToReload.add(new ChunkPos(x, z));
Config.ArenaRegion.forEachChunk((x, z) -> {
if(!bypass(p, x, z))
chunksToReload.add(new ChunkPos(x, z));
});
return chunksToReload;
}

Datei anzeigen

@ -24,7 +24,6 @@ import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.utils.Region;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
@ -74,7 +73,7 @@ public class WinconditionPercentSystem extends Wincondition implements Listener,
}
private void check(EntityExplodeEvent event) {
if(!Region.isInRange(event.getEntity().getLocation(), team.getCornerX(), team.getCornerY(), team.getCornerZ(), Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ, Config.BorderFromSchematic)){
if(!team.getExtendRegion().inRegion(event.getEntity().getLocation())){
return;
}