Add FightSystem module

This commit is contained in:
2024-08-05 11:43:04 +02:00
parent 1c7ab28a77
commit 89a8c9f11c
176 changed files with 16893 additions and 1 deletions
@@ -0,0 +1,61 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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/>.
*/
plugins {
id("java")
id("base")
}
group = "de.steamwar"
version = ""
tasks.compileJava {
options.encoding = "UTF-8"
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
sourceSets {
main {
java {
srcDirs("src/")
}
resources {
srcDirs("src/")
exclude("**/*.java", "**/*.kt")
}
}
}
dependencies {
compileOnly("org.projectlombok:lombok:1.18.32")
annotationProcessor("org.projectlombok:lombok:1.18.32")
compileOnly(project(":SpigotCore"))
compileOnly("de.steamwar:worldedit:1.15")
compileOnly("org.spigotmc:spigot-api:1.19-R0.1-SNAPSHOT")
compileOnly("it.unimi.dsi:fastutil:8.5.6")
compileOnly("io.netty:netty-all:4.1.68.Final")
compileOnly("com.mojang:authlib:1.5.25")
}
+180
View File
@@ -0,0 +1,180 @@
Server:
# Base server folder
Folder: ""
# Server java archive
ServerJar: ""
# Available arenas
Maps: []
# Names to address the game mode in the chat interface
ChatNames: []
# If the game mode should be marked as a historic game mode
Historic: false # defaults to false if missing
# If ranked matches should be available for the game mode
Ranked: false # defaults to false if missing
# The questions that have to be answered to accept the schematic
CheckQuestions: [] # Disables check schem type if missing
# The available schematic ranks
Ranks: [] # Disables ranks for this schematic type if missing
Times:
# Time in seconds the server stops after starting if nobody joins
NoPlayersOnlineDuration: 300 # defaults to 300 if missing
# Time in seconds the team leaders have to choose their schematic
PreSchemPasteDuration: 120 # defaults to 120 if missing
# Time in seconds for preparing
SetupDuration: 300 # defaults to 300 if missing
# Time in seconds the final countdown is long
PreFightDuration: 30 # defaults to 30 if missing
# Time in seconds to spectate the arena after the fight
SpectatorDuration: 30 # defaults to 30 if missing
Arena:
# The amount of blocks the schematics should be pasted under the surface
WaterDepth: 0 # defaults to 0 if missing
# The outer border of the arena, measured in blocks around the schematic areas
Schem2Border:
x: 24 # defaults to 24 if missing
z: 24 # defaults to 24 if missing
# The offset the teams spawn relative to the center of their area
SpawnOffset:
x: 0 # defaults to 0 if missing
y: 0 # defaults to Schematic.Size.y if missing
z: 0 # defaults to 0 if missing
# The size of the team areas are expanded around the schematics
BorderFromSchematic: 12 # defaults to 12 if missing
# If ground walkable, teams can walk below the lower arena border during setup
GroundWalkable: true # defaults to true if missing
# Disable snow and ice melting
DisableSnowMelt: false # defaults to false if missing
# Allow leaving the arena area as spectator
Leaveable: false # defaults to false if missing
# Allow missiles to fly to the enemy and not stop at the schem border.
AllowMissiles: false # defaults to true if EnterStages are present otherwise 'false'
Schematic:
# The size of the schematics
Size:
x: 0
y: 0
z: 0
# The schematic type that can be chosen in this arena
Type: Normal # defaults to Normal if missing
# The schematic types that are also allowed to be chosen in this arena
SubTypes: [] # defaults to empty List
# Shortcut of the schematic type
Shortcut: "" # defaults to "" if missing
# Spigot (1.8) material for GUIs
Material: STONE_BUTTON # defaults to STONE_BUTTON if missing
# Manual check of schematic necessary
ManualCheck: true # defaults to true if missing
# If the schematics should be rotated during pasting
Rotate: true # defaults to true if missing
# If the schematics should be pasted aligned to the borders instead of centered
PasteAligned: false # defaults to false if missing
# If only public schematics are allowed
OnlyPublicSchematics: false # defaults to false if missing
# If the public only force should be completely disabled
IgnorePublicOnly: false # defaults to false if missing
# If obsidian and bedrock should be replaced during PRE_RUNNING
ReplaceObsidianBedrock: false # defaults to false if missing
# If the replacement should happen with block updates
ReplaceWithBlockupdates: false # defaults to false if missing
# If the schematic perparation arena mode is time limited
UnlimitedPrepare: false # defaults to false if missing
# Maximal amount of blocks allowed in the schematic
MaxBlocks: 0 # defaults to 0 (ignored) if missing
# Maximal amount of items per dispenser
MaxDispenserItems: 128 # defaults to 128 if missing
# List of limited material (combinations)
# List contains tags Amount (integer) and Materials (List of material names in Spigot 1.12 AND Spigot 1.15 format)
Limited:
- Materials: []
Amount: 0
# The name of the game mode presented to the players
GameName: WarGear # defaults to WarGear if missing
# The prefix used for team chats
TeamChatPrefix: + # defaults to + if missing
Blue:
Name: Blau # defaults to Blue if missing
Prefix: '§3' # defaults to '§3' if missing
Red:
Name: Rot # defaults to Red if missing
Prefix: '§c' # defaults to '§c' if missing
# The list of active win conditions
WinConditions: # defaults to none if missing
- TIMEOUT
# - HEART_RATIO_TIMEOUT
# - PERCENT_TIMEOUT
- ALL_DEAD
# - CAPTAIN_DEAD
# - PERCENT_SYSTEM
# - POINTS
# - POINTS_AIRSHIP
# - WATER_TECH_KO
# - TIME_TECH_KO
# - PUMPKIN_TECH_KO
# - HELLS_BELLS
# - METEOR
# - PERSISTENT_DAMAGE
# - TNT_DISTRIBUTION
WinConditionParams:
# The time of any of the timeout win conditions in seconds
TimeoutTime: 1200 # defaults to 1200 if missing
# The percentage when any of the percent win conditions limits or triggers a win
PercentWin: 7.0 # defaults to 7.0 if missing
# Does the percentage still change after the start of the enter phase
PercentEntern: true # defaults to true if missing
# Is Blocks a whitelist (true) or blacklist (false)
BlocksWhitelist: false # defaults to false if missing
# Special Blocks (Valid spigot material values) used by the percent win conditions
Blocks: [] # defaults to none if missing
Kits:
# The kit file for this configuration
File: kits.yml # defaults to kits.yml if missing
# The default kit for team members
MemberDefault: default # defaults to default if missing
# The default kit for team leaders
LeaderDefault: default # defaults to default if missing
# If the personal kit system is active
PersonalKits: false # defaults to false if missing
# Items (Valid spigot material values) that are not allowed in the personal kit
ForbiddenItems: [] # defaults to none if missing
# A list of integers containing the waiting time of this enter stage in the fight
EnterStages: [] # defaults to no enter stages (empty list) if missing
Techhider:
# The tech hider blocks/materials have to be valid lowercase minecraft material names
# Activates the tech hider
Active: false # defaults to false if missing
# Which block the tech hider replaces to.
ObfuscateWith: end_stone # defaults to end_stone if missing
# A list of all hidden blocks. "water" results in the hiding of all waterlogged blocks as well.
HiddenBlocks: [] # defaults to none if missing
# The block entity contents that are hidden (here with minecraft:nametag)
HiddenBlockEntites: [] # defaults to none if missing
# The following configuration must be in the world folder/config.yml
#
# # The lower arena border under which players get damage
# UnderBorder: 0 # defaults to BlueCorner.y if missing
# # The lowest corner in all axis of the blue team schematic area
# BlueCorner:
# x: 0
# y: 0
# z: 0
# # The offset between the lowest corner of the blue area and the lowest corner of the red area
# BlueToRed:
# x: 0 # defaults to 0 if missing
# y: 0 # defaults to 0 if missing
# z: 0 # defaults to Schematic.Size.z + 50 if missing
@@ -0,0 +1,56 @@
/*
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.fightsystem;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
public enum ArenaMode {
NORMAL,
EVENT,
TEST,
CHECK,
PREPARE,
REPLAY;
public static final Set<ArenaMode> All = Collections.unmodifiableSet(EnumSet.allOf(ArenaMode.class));
public static final Set<ArenaMode> Normal = Collections.unmodifiableSet(EnumSet.of(NORMAL));
public static final Set<ArenaMode> Check = Collections.unmodifiableSet(EnumSet.of(CHECK));
public static final Set<ArenaMode> Event = Collections.unmodifiableSet(EnumSet.of(EVENT));
public static final Set<ArenaMode> Test = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK));
public static final Set<ArenaMode> Prepare = Collections.unmodifiableSet(EnumSet.of(PREPARE));
public static final Set<ArenaMode> Replay = Collections.unmodifiableSet(EnumSet.of(REPLAY, TEST));
public static final Set<ArenaMode> AntiReplay = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(REPLAY)));
public static final Set<ArenaMode> AntiTest = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK)));
public static final Set<ArenaMode> AntiEvent = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(EVENT)));
public static final Set<ArenaMode> AntiTestCheckPrepare = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK, PREPARE)));
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(EVENT, REPLAY, CHECK)));
public static final Set<ArenaMode> ManualTeams = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(EVENT, REPLAY)));
public static final Set<ArenaMode> RankedEvent = Collections.unmodifiableSet(EnumSet.of(EVENT, REPLAY));
public static final Set<ArenaMode> Restartable = Collections.unmodifiableSet(EnumSet.of(NORMAL, TEST));
public static final Set<ArenaMode> NotRestartable = Collections.unmodifiableSet(EnumSet.of(EVENT, REPLAY));
public static final Set<ArenaMode> SoloLeader = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK, PREPARE));
public static final Set<ArenaMode> NotOnBau = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK, PREPARE, REPLAY)));
public static final Set<ArenaMode> SeriousFight = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK, REPLAY)));
}
@@ -0,0 +1,415 @@
/*
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.fightsystem;
import de.steamwar.fightsystem.utils.Region;
import de.steamwar.fightsystem.winconditions.Winconditions;
import de.steamwar.sql.*;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import java.io.File;
import java.util.*;
import java.util.logging.Level;
import java.util.stream.Collectors;
public class Config {
private Config(){}
public static final World world = Bukkit.getWorlds().get(0);
//Fight sequence
public static final int NoPlayerOnlineDuration;
public static final int PreSchemPasteDuration;
public static final int SetupDuration;
public static final int PreFightDuration;
public static final int SpectatorDuration;
// entern parameter
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 RedExtendRegion;
public static final Region ArenaRegion;
public static final Region PlayerRegion;
public static final Location TeamBlueSpawn;
public static final Location TeamRedSpawn;
public static final Location SpecSpawn;
public static final int BlueToRedX;
private static final int BlueToRedY;
public static final int BlueToRedZ;
public static final int PreperationArea;
public static final int WaterDepth;
public static final boolean GroundWalkable;
public static final boolean DisableSnowMelt;
public static final boolean ArenaLeaveable;
public static final boolean AllowMissiles;
//schematic parameter
public static final boolean RanksEnabled;
public static final boolean OnlyPublicSchematics;
public static final boolean IgnorePublicOnly;
public static final de.steamwar.sql.SchematicType SchematicType;
public static final List<de.steamwar.sql.SchematicType> SubTypes;
public static final boolean RedRotate;
public static final boolean BlueRotate;
public static final boolean PasteAligned;
public static final boolean ReplaceObsidianBedrock;
public static final boolean ReplaceWithBlockupdates;
public static final boolean UnlimitedPrepare;
//team parameter
public static final String TeamRedName;
public static final String TeamBlueName;
public static final String TeamRedColor;
public static final String TeamBlueColor;
public static final String GameName;
public static final String TeamChatDetection;
public static final UUID BlueLeader;
public static final UUID RedLeader;
//Active win conditions
public static final Set<Winconditions> ActiveWinconditions;
//win condition parameters
public static final int TimeoutTime;
public static final double PercentWin;
public static final boolean PercentEntern;
public static final boolean PercentBlocksWhitelist;
public static final Set<Material> PercentBlocks;
//default kits
public static final String MemberDefault;
public static final String LeaderDefault;
public static final boolean PersonalKits;
public static final Set<Material> ForbiddenItems;
public static final String KitFile;
//tech hider parameter
public static final boolean TechhiderActive;
public static final Set<Material> HiddenBlocks;
public static final Set<String> HiddenBlockEntities;
public static final Material ObfuscateWith;
//event parameter
public static final EventFight EventKampf;
private static final Set<Integer> Referees;
public static final int EventTeamBlueID;
public static final int EventTeamRedID;
public static final boolean BothTeamsPublic;
public static final int MaximumTeamMembers;
public static final boolean LiveReplay;
//check parameter
public static final int CheckSchemID;
public static final int PrepareSchemID;
public static final ArenaMode mode;
//replay system parameter
public static final String spectateIP = "127.0.0.1";
public static final int SpectatePort;
public static final int ReplayID;
static{
CheckSchemID = Integer.parseInt(System.getProperty("checkSchemID", "0"));
PrepareSchemID = Integer.parseInt(System.getProperty("prepareSchemID", "0"));
ReplayID = Integer.parseInt(System.getProperty("replay", "0"));
String configFile = System.getProperty("config", "config.yml");
if(!new File(FightSystem.getPlugin().getDataFolder(), configFile).exists()) {
FightSystem.getPlugin().saveDefaultConfig();
Bukkit.getLogger().log(Level.SEVERE, "Arenaconfig fehlt!");
Bukkit.shutdown();
}
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(FightSystem.getPlugin().getDataFolder(), configFile));
File worldConfigFile = new File(world.getWorldFolder(), "config.yml");
if(!worldConfigFile.exists()) {
Bukkit.getLogger().log(Level.SEVERE, "Weltconfig fehlt!");
Bukkit.shutdown();
}
FileConfiguration worldconfig = YamlConfiguration.loadConfiguration(worldConfigFile);
NoPlayerOnlineDuration = config.getInt("Times.NoPlayersOnlineDuration", 300);
PreSchemPasteDuration = config.getInt("Times.PreSchemPasteDuration", 120);
SetupDuration = config.getInt("Times.SetupDuration", 300);
PreFightDuration = config.getInt("Times.PreFightDuration", 30);
SpectatorDuration = config.getInt("Times.SpectatorDuration", 30);
int blueCornerX = worldconfig.getInt("BlueCorner.x");
int blueCornerY = worldconfig.getInt("BlueCorner.y");
int blueCornerZ = worldconfig.getInt("BlueCorner.z");
int underBorder = worldconfig.getInt("UnderBorder", blueCornerY);
WaterDepth = config.getInt("Arena.WaterDepth", 0);
int schem2BorderX = config.getInt("Arena.Schem2Border.x", 24);
int schem2BorderZ = config.getInt("Arena.Schem2Border.z", 24);
PreperationArea = config.getInt("Arena.BorderFromSchematic", 12);
GroundWalkable = config.getBoolean("Arena.GroundWalkable", true);
DisableSnowMelt = config.getBoolean("Arena.DisableSnowMelt", false);
ArenaLeaveable = config.getBoolean("Arena.Leaveable", false);
int schemsizeX = config.getInt("Schematic.Size.x");
int schemsizeY = config.getInt("Schematic.Size.y");
int schemsizeZ = config.getInt("Schematic.Size.z");
RanksEnabled = !config.getStringList("Ranks").isEmpty();
SchematicType = de.steamwar.sql.SchematicType.fromDB(Objects.requireNonNull(config.getString("Schematic.Type", "normal")));
SubTypes = config.getStringList("Schematic.SubTypes").stream().map(de.steamwar.sql.SchematicType::fromDB).collect(Collectors.toList());
IgnorePublicOnly = config.getBoolean("Schematic.IgnorePublicOnly", false);
boolean rotate = config.getBoolean("Schematic.Rotate", true);
PasteAligned = config.getBoolean("Schematic.PasteAligned", false);
ReplaceObsidianBedrock = config.getBoolean("Schematic.ReplaceObsidianBedrock", false);
ReplaceWithBlockupdates = config.getBoolean("Schematic.ReplaceWithBlockupdates", false);
UnlimitedPrepare = config.getBoolean("Schematic.UnlimitedPrepare", false);
GameName = config.getString("GameName", "WarGear");
TeamChatDetection = config.getString("TeamChatPrefix", "+");
ActiveWinconditions = Collections.unmodifiableSet(config.getStringList("WinConditions").stream().map(Winconditions::valueOf).collect(Collectors.toSet()));
TimeoutTime = config.getInt("WinConditionParams.TimeoutTime", 1200);
PercentWin = config.getDouble("WinConditionParams.PercentWin", 7.0);
PercentEntern = config.getBoolean("WinConditionParams.PercentEntern", true);
PercentBlocksWhitelist = config.getBoolean("WinConditionParams.BlocksWhitelist", false);
PercentBlocks = Collections.unmodifiableSet(config.getStringList("WinConditionParams.Blocks").stream().map(Material::valueOf).collect(Collectors.toSet()));
EnterStages = Collections.unmodifiableList(config.getIntegerList("EnterStages"));
AllowMissiles = config.getBoolean("Arena.AllowMissiles", !EnterStages.isEmpty());
KitFile = config.getString("Kits.File", "kits.yml");
MemberDefault = config.getString("Kits.MemberDefault", "default");
LeaderDefault = config.getString("Kits.LeaderDefault", "default");
PersonalKits = config.getBoolean("Kits.PersonalKits", false);
ForbiddenItems = Collections.unmodifiableSet(config.getStringList("Kits.ForbiddenItems").stream().map(Material::valueOf).collect(Collectors.toSet()));
TechhiderActive = config.getBoolean("Techhider.Active", false);
ObfuscateWith = Material.getMaterial(config.getString("Techhider.ObfuscateWith", "end_stone").toUpperCase());
HiddenBlocks = config.getStringList("Techhider.HiddenBlocks").stream().map(String::toUpperCase).map(Material::getMaterial).collect(Collectors.toSet());
HiddenBlockEntities = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlockEntities")));
if(schemsizeX < 0){
schemsizeX = -schemsizeX;
blueCornerX = blueCornerX - schemsizeX;
}
if(schemsizeY < 0){
schemsizeY = -schemsizeY;
blueCornerY = blueCornerY - schemsizeY;
}
if(schemsizeZ < 0){
schemsizeZ = -schemsizeZ;
blueCornerZ = blueCornerZ - schemsizeZ;
}
BlueToRedX = worldconfig.getInt("BlueToRed.x", 0);
BlueToRedY = worldconfig.getInt("BlueToRed.y", 0);
BlueToRedZ = worldconfig.getInt("BlueToRed.z", schemsizeZ + 50);
double teamBlueSpawnOffsetX = config.getDouble("Arena.SpawnOffset.x", 0);
double teamBlueSpawnOffsetY = config.getDouble("Arena.SpawnOffset.y", schemsizeY);
double teamBlueSpawnOffsetZ = config.getDouble("Arena.SpawnOffset.z", 0);
int teamRedCornerX = BlueToRedX + blueCornerX;
int teamRedCornerY = BlueToRedY + blueCornerY;
int teamRedCornerZ = BlueToRedZ + blueCornerZ;
int teamBluePasteX = blueCornerX + schemsizeX / 2;
int teamBluePasteZ = blueCornerZ + schemsizeZ / 2;
int teamRedPasteX = teamBluePasteX + BlueToRedX;
int teamRedPasteZ = teamBluePasteZ + BlueToRedZ;
TeamBlueSpawn = new Location(world,
teamBluePasteX + 0.5 + teamBlueSpawnOffsetX,
blueCornerY + 0.5 + teamBlueSpawnOffsetY,
teamBluePasteZ + 0.5 + teamBlueSpawnOffsetZ);
TeamRedSpawn = new Location(world,
teamRedPasteX + 0.5 - teamBlueSpawnOffsetX,
teamRedCornerY + 0.5 + teamBlueSpawnOffsetY,
teamRedPasteZ + 0.5 - teamBlueSpawnOffsetZ);
SpecSpawn = new Location(world,
teamBluePasteX + BlueToRedX /2.0,
blueCornerY + BlueToRedY /2.0 + schemsizeY/2.0,
teamBluePasteZ + BlueToRedZ /2.0);
Vector v1 = TeamBlueSpawn.toVector().subtract(TeamRedSpawn.toVector());
double pitch = Math.toDegrees(v1.angle(v1.clone().setY(0)));
double yaw = Math.toDegrees(v1.clone().setY(0).angle(new Vector(0, 0, 1)));
TeamBlueSpawn.setYaw((float) yaw + 180);
TeamBlueSpawn.setPitch((float) pitch);
TeamRedSpawn.setYaw((float) yaw);
TeamRedSpawn.setPitch((float) pitch * -1);
boolean teamRedRotate;
boolean teamBlueRotate;
int arenaMinX;
int arenaMaxX;
int arenaMinZ;
int arenaMaxZ;
if(BlueToRedX > 0){
arenaMinX = blueCornerX - schem2BorderX;
arenaMaxX = teamRedCornerX + schemsizeX + schem2BorderX;
teamRedRotate = true;
teamBlueRotate = false;
}else{
arenaMinX = teamRedCornerX - schem2BorderX;
arenaMaxX = blueCornerX + schemsizeX + schem2BorderX;
teamRedRotate = false;
teamBlueRotate = true;
}
if(BlueToRedZ > 0){
arenaMinZ = blueCornerZ - schem2BorderZ;
arenaMaxZ = teamRedCornerZ + schemsizeZ + schem2BorderZ;
teamRedRotate = true;
teamBlueRotate = false;
}else{
arenaMinZ = teamRedCornerZ - schem2BorderZ;
arenaMaxZ = blueCornerZ + schemsizeZ + schem2BorderZ;
if(BlueToRedZ != 0){
teamRedRotate = false;
teamBlueRotate = true;
}
}
if(!rotate){
teamRedRotate = false;
teamBlueRotate = false;
}
RedRotate = teamRedRotate;
BlueRotate = teamBlueRotate;
RedPasteRegion = Region.fromSize(teamRedCornerX, teamRedCornerY, teamRedCornerZ, schemsizeX, schemsizeY, schemsizeZ);
BluePasteRegion = Region.fromSize(blueCornerX, blueCornerY, blueCornerZ, schemsizeX, schemsizeY, schemsizeZ);
RedExtendRegion = Region.withExtension(teamRedCornerX, teamRedCornerY, teamRedCornerZ, schemsizeX, schemsizeY, schemsizeZ, PreperationArea, PreperationArea, PreperationArea);
BlueExtendRegion = Region.withExtension(blueCornerX, blueCornerY, blueCornerZ, schemsizeX, schemsizeY, schemsizeZ, PreperationArea, PreperationArea, PreperationArea);
ArenaRegion = Region.withExtension(arenaMinX, blueCornerY, arenaMinZ, arenaMaxX - arenaMinX, schemsizeY, arenaMaxZ - arenaMinZ, 0, PreperationArea, 0);
PlayerRegion = new Region(arenaMinX, underBorder, arenaMinZ, arenaMaxX, world.getMaxHeight(), arenaMaxZ);
int eventKampfID = Integer.parseInt(System.getProperty("fightID", "0"));
if(eventKampfID >= 1){
EventKampf = EventFight.get(eventKampfID);
if(EventKampf == null){
Bukkit.getLogger().log(Level.SEVERE, "Failed to load EventFight");
Bukkit.shutdown();
}
assert EventKampf != null;
Team team1 = Team.get(EventKampf.getTeamBlue());
Team team2 = Team.get(EventKampf.getTeamRed());
if(team1 == null || team2 == null){
Bukkit.getLogger().log(Level.SEVERE, "Failed to load Team");
Bukkit.shutdown();
}
assert team1 != null;
assert team2 != null;
TeamBlueName = team1.getTeamKuerzel();
TeamRedName = team2.getTeamKuerzel();
TeamBlueColor = "§" + team1.getTeamColor();
TeamRedColor = "§" + team2.getTeamColor();
EventTeamBlueID = team1.getTeamId();
EventTeamRedID = team2.getTeamId();
BothTeamsPublic = EventTeamRedID == 0 && EventTeamBlueID == 0;
SpectatePort = EventKampf.getSpectatePort();
LiveReplay = SpectatePort != 0;
Referees = Referee.get(Config.EventKampf.getEventID());
Event event = Event.get(EventKampf.getEventID());
if(BothTeamsPublic) {
OnlyPublicSchematics = true;
MaximumTeamMembers = Integer.MAX_VALUE;
}else{
OnlyPublicSchematics = event.publicSchemsOnly();
MaximumTeamMembers = event.getMaximumTeamMembers();
}
}else{
//No event
TeamRedColor = config.getString("Red.Prefix", "§c");
TeamBlueColor = config.getString("Blue.Prefix", "§3");
TeamRedName = config.getString("Red.Name", "Rot");
TeamBlueName = config.getString("Blue.Name", "Blau");
OnlyPublicSchematics = config.getBoolean("Schematic.OnlyPublicSchematics", false);
EventTeamBlueID = 0;
EventTeamRedID = 0;
EventKampf = null;
BothTeamsPublic = true;
Referees = Collections.emptySet();
MaximumTeamMembers = Integer.MAX_VALUE;
LiveReplay = false;
SpectatePort = -ReplayID;
}
String blueLeader = System.getProperty("blueLeader", null);
String redLeader = System.getProperty("redLeader", null);
if(blueLeader != null)
BlueLeader = UUID.fromString(blueLeader);
else
BlueLeader = null;
if(redLeader != null)
RedLeader = UUID.fromString(redLeader);
else
RedLeader = null;
if(CheckSchemID != 0){
mode = ArenaMode.CHECK;
}else if(PrepareSchemID != 0){
mode = ArenaMode.PREPARE;
}else if(eventKampfID >= 1){
mode = ArenaMode.EVENT;
}else if(eventKampfID == -1){
mode = ArenaMode.TEST;
}else if(ReplayID != 0){
mode = ArenaMode.REPLAY;
}else{
mode = ArenaMode.NORMAL;
}
}
public static boolean test(){
return ArenaMode.Test.contains(mode);
}
public static boolean replayserver(){
return ReplayID < 0;
}
public static boolean blueNegZ(){
return BlueToRedZ > 0;
}
public static boolean isReferee(Player player) {
return Referees.contains(SteamwarUser.get(player.getUniqueId()).getId());
}
}
@@ -0,0 +1,230 @@
/*
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;
import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.core.Core;
import de.steamwar.fightsystem.commands.*;
import de.steamwar.fightsystem.countdown.*;
import de.steamwar.fightsystem.event.HellsBells;
import de.steamwar.fightsystem.event.Meteor;
import de.steamwar.fightsystem.event.PersistentDamage;
import de.steamwar.fightsystem.event.TNTDistributor;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.fight.FightWorld;
import de.steamwar.fightsystem.fight.HotbarKit;
import de.steamwar.fightsystem.listener.Shutdown;
import de.steamwar.fightsystem.listener.*;
import de.steamwar.fightsystem.record.FileRecorder;
import de.steamwar.fightsystem.record.FileSource;
import de.steamwar.fightsystem.record.GlobalRecorder;
import de.steamwar.fightsystem.record.LiveRecorder;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.OneShotStateDependent;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.utils.*;
import de.steamwar.fightsystem.winconditions.*;
import de.steamwar.message.Message;
import de.steamwar.sql.SchematicNode;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
public class FightSystem extends JavaPlugin {
@Getter
private static FightSystem plugin;
private Message message;
private FightTeam lastWinner;
private String lastWinreason;
private TechHiderWrapper techHider;
private HullHider hullHider;
@Override
public void onLoad() {
plugin = this;
}
@Override
public void onEnable() {
if(Core.getInstance() == null) {
Core.setInstance(this);
TinyProtocol.init();
}
message = new Message("de.steamwar.fightsystem.FightSystem", FightSystem.class.getClassLoader());
new EntityDamage();
new WaterRemover();
new Permanent();
new PistonListener(ArenaMode.AntiTestCheckPrepare, e -> e.setCancelled(true));
new PistonListener(ArenaMode.Test, e -> getMessage().broadcastActionbar("PISTON_PUSHED_OUTSIDE"));
new PistonListener(ArenaMode.Prepare, e -> {
getMessage().broadcast("PISTON_PUSHED_OUTSIDE");
shutdown();
});
new Chat();
new ArenaBorder();
new IngameDeath();
new InFightDamage();
new InFightInventory();
new DenyWorldInteraction();
new DenyInventoryMovement();
new EventJoin();
new Recording();
new Check();
new Shutdown();
new SetupQuit();
new PrepareSchem();
new TestJoin();
new NormalJoin();
new RunningWorldInteraction();
new PersonalKitCreator();
new ArrowStopper();
new StateDependentListener(ArenaMode.All, FightState.All, BountifulWrapper.impl.newDenyArrowPickupListener());
new BlockFadeListener();
new LeaveableArena();
new ClickAnalyzer();
new BlockPlaceCollision();
new HotbarKit.HotbarKitListener();
new JoinRequestListener();
new OneShotStateDependent(ArenaMode.All, FightState.PreSchemSetup, () -> Fight.playSound(SWSound.BLOCK_NOTE_PLING.getSound(), 100.0f, 2.0f));
new EnterHandler();
techHider = new TechHiderWrapper();
hullHider = new HullHider();
new FightWorld();
new FightUI();
new FightStatistics();
new BungeeFightInfo();
new WinconditionAllDead();
new WinconditionCaptainDead();
new WinconditionBlocks(Winconditions.WATER_TECH_KO, "WaterTechKO", "BAR_WATER", FlatteningWrapper.impl::isWater);
new WinconditionBlocks(Winconditions.PUMPKIN_TECH_KO, "PumpkinTechKO", "BAR_CANNONS", block -> block.getType() == WinconditionBlocks.PUMPKIN_LANTERN);
new WinconditionPercent(Winconditions.PERCENT_SYSTEM, "Percent");
new WinconditionPoints();
new WinconditionPointsAirShip();
new WinconditionTimeout();
new WinconditionTimeTechKO();
new EventTeamOffWincondition();
new WinconditionComparisonTimeout(Winconditions.HEART_RATIO_TIMEOUT, "HeartTimeout", "WIN_MORE_HEALTH", FightTeam::getHeartRatio);
new WinconditionComparisonTimeout(Winconditions.PERCENT_TIMEOUT, "PercentTimeout", "WIN_LESS_DAMAGE", team -> -Wincondition.getPercentWincondition().getPercent(team));
new HellsBells();
new Meteor();
new PersistentDamage();
new TNTDistributor();
new WinconditionAmongUs();
new NoPlayersOnlineCountdown();
new PreSchemCountdown();
new PostSchemCountdown();
new PreRunningCountdown();
new SpectateOverCountdown();
new EventSpectateCountdown();
new LeaveCommand();
new KitCommand();
new RemoveCommand();
new RequestsCommand();
new InfoCommand();
new WGCommand();
new TBCommand();
new GamemodeCommand();
new ReadyCommand();
new AkCommand();
new LeaderCommand();
new LockschemCommand();
new StateCommand();
new SkipCommand();
new TPSWarpCommand();
new UnrankCommand();
new WinCommand();
new LiveRecorder();
new FileRecorder();
FileSource.startReplay();
if(Config.mode == ArenaMode.EVENT) {
FightState.setFightState(FightState.PRE_SCHEM_SETUP);
}else if(Config.mode == ArenaMode.CHECK){
SchematicNode checkSchematicNode = SchematicNode.getSchematicNode(Config.CheckSchemID);
Fight.getBlueTeam().setSchem(checkSchematicNode);
if (checkSchematicNode.getName().endsWith("-prepared")) {
SchematicNode unpreparedSchematicNode = SchematicNode.getSchematicNode(checkSchematicNode.getOwner(), checkSchematicNode.getName().substring(0, checkSchematicNode.getName().length() - 9), checkSchematicNode.getParent());
if (unpreparedSchematicNode != null) {
Fight.getRedTeam().setSchem(unpreparedSchematicNode);
}
}
}else if(Config.mode == ArenaMode.PREPARE) {
Fight.getUnrotated().setSchem(SchematicNode.getSchematicNode(Config.PrepareSchemID));
}
}
@Override
public void onDisable() {
GlobalRecorder.getInstance().close();
ClickAnalyzer.close();
}
public static void setSpectateState(FightTeam winFightTeam, String winreason, String subtitle, Object... params) {
plugin.lastWinner = winFightTeam;
plugin.lastWinreason = winreason;
FightUI.printWin(winFightTeam, subtitle, params);
FightState.setFightState(FightState.SPECTATE);
}
public static Message getMessage() {
return plugin.message;
}
public static FightTeam getLastWinner() {
return plugin.lastWinner;
}
public static String getLastWinreason() {
return plugin.lastWinreason;
}
public static TechHiderWrapper getTechHider() {
return plugin.techHider;
}
public static HullHider getHullHider() {
return plugin.hullHider;
}
public static void shutdown() {
//Staggered kick to prevent lobby overloading
if(Bukkit.getOnlinePlayers().isEmpty()){
Bukkit.shutdown();
return;
}
Bukkit.getOnlinePlayers().iterator().next().kickPlayer(null);
Bukkit.getScheduler().runTaskLater(plugin, FightSystem::shutdown, 10);
}
}
@@ -0,0 +1,256 @@
#
# This file is a part of the SteamWar software.
#
# Copyright (C) 2022 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/>.
#
PREFIX=§eArena§8»
# Commands
NO_TEAM=§cYou are in no team
FIGHT_ALREADY_STARTED=§cThe fight already started
NOT_LEADER=§cYou aren't a leader
PLAYER_UNAVAILABLE=§cThe player is not in an arena
NOT_IN_TEAM=§e{0} §cis not in your team
KIT_UNAVAILABLE=§cThis kit does not exist
KIT_CHOSEN=§7Selected kit §e{0}
GAMEMODE_NOT_ALLOWED=§cChanging gamemode is not permitted
GAMEMODE_UNKNOWN=§cUnknown gamemode {0}
GAMEMODE_HELP=§8/§7gm §8[§egamemode§8]
LEADER_FULL=§cAll teams already have a leader
ALREADY_IN_TEAM=§cYou are already in a team
LOCKSCHEM_HELP=§8/§7lockschem §8[§eteam§8]
UNKNOWN_TEAM=§cThis team does not exist
LOCKSCHEM_LOCKED=§7Schematic locked
LOCKSCHEM_LOCKED_BY=§cThe schematic was locked by §e{0}
REMOVE_HELP=§8/§eremove §8[§eplayer§8]
NOT_FIGHTLEADER=§cYou are not the fight leader
WIN_HELP=§8/§7win §8[§eteam §8or §etie§8]
INFO_RANKED=§7Ranked§8: §e{0}
INFO_LEADER=§7Leader {0}§8: {1}
INFO_SCHEMATIC=§7Schematic {0}§8: §e{1} §7from {2}, Rank: {3}
TPSWARP_HELP=§8/§7tpswarp §8[§eticks per second§8]
TPSWARP_SET=§7TPS set to §e{0}
# GUI
STATE_TITLE=Fight state
STATE_PRE_LEADER_SETUP=§7Team leader waiting phase
STATE_PRE_SCHEM_SETUP=§7Schematic selection phase
STATE_POST_SCHEM_SETUP=§7Preparation phase
STATE_PRE_RUNNING=§eKit distribution
STATE_RUNNING=§eFighting phase
STATE_SPECTATE_WIN=§7Victory {0}
STATE_SPECTATE_TIE=§7Draw
REMOVE_TITLE=Kick player
KIT_SELECTION_TITLE=Kit selection
KIT_NO_KITS=§cNo kits found
KIT_CREATE=§eNew kit
KITNAME_TITLE=Input kit name
KITNAME_IN_USE=§cThis kit name is already in use
KIT_SEARCH=§eSearch
KITSEARCH_TITLE=Search for kit
SCHEM_NO_ENEMY=§cNo schematic selection without an opponent
SCHEM_TITLE={0} selection
SCHEM_PUBLIC=§ePublic {0}
SCHEM_UNCHECKED=§eUnchecked {0}
SCHEM_PRIVATE=§ePrivate {0}
SCHEM_NO_PRIVATE=§7No private {0} present
SCHEM_PRIVATE_FORBIDDEN=§7No private {0} allowed
# Countdowns
COUNTDOWN_MINUTES=§e{0} §7Minutes {1}
COUNTDOWN_SECONDS=§e{0} §7Seconds {1}
COUNTDOWN_SECOND=§eOne §7second {1}
ENTERN_COUNTDOWN=until boarding is allowed
ENTERN_ALLOWED=§eBoarding §7is now allowed
SHUTDOWN_COUNTDOWN=until the server is stopped
PRE_SCHEM_COUNTDOWN=until a public schematic is chosen
POST_SCHEM_COUNTDOWN=until the kits are distributed
PRE_RUNNING_COUNTDOWN=until the fight starts
RUNNING_COUNTDOWN=until the fight ends
SPECTATE_COUNTDOWN=until the arena is reset
# Fight
SCHEMATIC_UNLOADABLE=§cUnable to load schematic
SCHEMATIC_CHOSEN=§7{0} §e{1} §7chosen
SCHEMATIC_UNCHECKED=§7Team {0} §7has chosen an §eunchecked §7schematic§8!
TEAM_READY=§aTeam ready
TEAM_NOT_READY=§c§mTeam ready
SKIP_READY=§aSkipping to next event
SKIP_NOT_READY=§c§mSkipping to next event
TEAM_CHAT={0}{1}§8» {0}{2}
CHOOSE_KIT=§eChoose kit
RESPAWN=§eRespawn
REMOVE_PLAYERS=§cKick player
CHOOSE_SCHEMATIC=§eChoose {0}
SCHEMATIC_REQUIRED=§cChoose a schematic first
KIT_PREVIEW_EDIT=§7Edit kit
KIT_PREVIEW_CHOOSE=§aSelect kit
KIT_PREVIEW_BACK=§cBack
KIT_PREVIEW_DELETE=§cDelete kit
KIT_DELETION_CONFIRMATION=Are you sure you want to delete the kit?
KIT_DELETION_ABORT=§cCancel
KIT_DELETION_DELETE=§aDelete
# Listener
NO_ARENA_LEAVING=§cYou may not leave the arena
CHECK_JOIN_DENIED=§cThere is a schematic in review on this server!
CHECK_COMMAND_LOCKED=§cThis command is locked during review! Admin will be notified.
NO_BLOCK_BREAK=§cYou are currently not allowed to break blocks here
NO_BLOCK_PLACE=§cYou are currently not allowed to place blocks here
NO_BOW_USAGE=§cYou can only use your bow after the fight has started
NO_PARTICIPANT=§cYou are no fight participant
NO_FRIENDLY_FIRE=§cNo friendly fire allowed
NO_TNT_PLACE=§cYou are not allowed to place tnt
NO_TELEPORT=§cYou are not allowed to use this teleport function
OPEN_INVENTORY_TO_CUSTOMIZE=§eOpen inventory to customize your kit
NO_ENTERN=§cYou may not board
NO_TEAMAREA=§cYou are not allowed in the team area
TEST_BECOME_LEADER=§7Become a team leader with §8/§eleader
PREPARE_SCHEM_DELETED=§cApparently the schematic to be submitted was deleted. submission aborted.
PREPARE_SCHEM_EXISTS=§cThere is already a schematic with the suffix -prepared, please rename or delete it, submission aborted.
PREPARE_ACTIVE_PISTON=§cMoving pistons were found in the team area, submission aborted.
PREPARE_FAILED_SAVING=§cThe schematic could not be saved, submission aborted.
PREPARE_SENT_IN=§aA team member will review the schematic soon
PARTICIPANT_CHAT={0} {1}§8» §7{2}
FIGHTLEADER_CHAT=§e{0}§8» §e{1}
SPECTATOR_CHAT=§7{0}§8» §7{1}
PISTON_PUSHED_OUTSIDE=§cA piston pushed a block outside the allowed area!
# Replay
REPLAY_ENDS=§cReplay ended
OLD_STRING={0}
# States
COMMAND_CURRENTLY_UNAVAILABLE=§cThis command is unavailable at this time of the fight
# Utils
TPS_WARNING=§c{0} §7TPS
UI_PRE_RUNNING=§7Kits distributed
UI_RUNNING=§aFight started
UI_SKIP=§7Skipping to next event
UI_UNRANKED=§7Unranked match
UI_PLAYER_JOINS=§a§l» {0}{1}
UI_PLAYER_LEAVES=§c§l« {0}{1}
UI_LEADER_JOINS=§a§l» {0}Leader {1}
UI_PLAYER_DEATH={0}{1} §7died
UI_PLAYER_LEAVE={0}{1} §7left the fight
UI_WIN={0}Victory {1}
UI_DRAW=§7Draw
BAR_PRE_LEADER=§7Waiting for team leader
BAR_PRE_SCHEM={1} §7Schematic selection {0} {2}
BAR_PREPARE={1} {3} §7Preparation {0} {4} {2}
BAR_PRE_RUNNING={1} {3} §7Start of fight in {0} {4} {2}
BAR_RUNNING0={1} {3} {0} {4} {2}
BAR_RUNNING1={1} {3} {5} {0} {6} {4} {2}
BAR_RUNNING2={1} {3} {5} {7} {0} {6} {8} {4} {2}
BAR_RUNNING3={1} {3} {5} {7} {9} {0} {6} {8} {10} {4} {2}
BAR_TIE={1} §7Draw {0} {2}
BAR_WIN={1} §7Victory {3} {0} {2}
BAR_POINTS={0} §8Points
BAR_POINTS_OF={0}§8/§7{1} §8Points
BAR_PERCENT={0}§8%
BAR_CANNONS={0} §8Cannons
BAR_WATER={0} §8Water
# Winconditions
HELLS_BELLS_COUNTDOWN=until the bombs start dropping
HELLS_BELLS_START_1=§c!!Careful!! Bombers arriving in about a minute.
HELLS_BELLS_START_2=§cBombers approaching, arrival in about a minute.
HELLS_BELLS_START_3=§cBombers spotted on the radar, ETA: one minute.
HELLS_BELLS_START_4=§cUnknown flying object spotted, arriving in about a minute.
HELLS_BELLS_START_5=§cFlying object spotted. ETA: one minute.
HELLS_BELLS_START_6=§cWild bombers appeared, arrival in about a minute.
HELLS_BELLS_SWAP_1=§aThe bombs are starting to fall more quickly.
HELLS_BELLS_SWAP_2=§aMore bombers arriving.
HELLS_BELLS_SWAP_3=§aAdditional bombers sighted.
HELLS_BELLS_SWAP_4=§aThe bombardement is increasing.
METEOR_COUNTDOWN=until meteors start falling
METEOR_START_1=§cA meteor shower was detected
METEOR_START_2=§cShooting starts are 100% more likely to appear during this fight
METEOR_START_3=§cMeteors sighted, seek shelter immediately!
METEOR_START_4=§cThe end is near! The meteors will hit us in about a minute.
METEOR_START_5=§fNEWS §cThere will be multiple meteor showers this afternoon!
METEOR_START_6=§cAirships still flying are doomed to crash.
METEOR_SWAP_1=§aIt doesn't stop, the meteors appear to be increasing.
METEOR_SWAP_2=§aThis was only the beginning, the meteors are arriving faster and more powerful.
METEOR_SWAP_3=§aIt seems like it won't stop, the meteors are starting to arrive more quickly!
METEOR_SWAP_4=§aAnother shower has been detected, get to safety!
TECHKO_COUNTDOWN=must have fired a shot by {0}
WIN_FIGHTLEADER=§7Referee decision
WIN_PERCENT={0} §7is too badly damaged
WIN_OFFLINE_BOTH=§7Both teams offline
WIN_OFFLINE={0} §7offline
WIN_ALL_DEAD={0}All players neutralised
WIN_LEADER_DEAD={0} neutralised
WIN_TIME_OVER=§7Time is up!
WIN_MORE_HEALTH={0} with more remaining health
WIN_LESS_DAMAGE={0} §7less damaged
WIN_POINTS={0} has more points
WIN_POINTS_EQUAL=§7Equal points
WIN_TECHKO={0} §7is tech K.O.
WIN_IMPOSTER_DEAD={0} §7killed the imposter
WIN_CREWMATE_DEAD={0} §7killed all team mates
AMONG_US_IMPOSTER_MESSAGE = §4You are the Imposter§8! §7Kill all your team mates to win the game!
AMONG_US_IMPOSTER_AMONG_MESSAGE = §4There is an Imposter among us§8! §7Kill him to win the game!
# Invites
JOIN_REQUEST=§7Request join
JOIN_REQUEST_TITLE=Request join
JOIN_REQUEST_ALREADY=§cYou have already sent a join request
JOIN_REQUEST_TEAM=§7Join {0}
JOIN_REQUEST_CONFIRMATION=§7Join request submitted
JOIN_REQUEST_NOTIFICATION=§e{0} §7requests joining team {1}§8. §7Accept or decline using §8/§erequests
REQUESTS=§7Open join requests
REQUESTS_TITLE=Open join requests
REQUEST_DECLINED=§cJoin of {0} declined
REQUEST_YOUR_DECLINED=§cYour join request was declined
REQUESTS_LEFT_CLICK=§eLeft click §7to §eaccept§8!
REQUESTS_RIGHT_CLICK=§eRight click §7to §edecline§8!
NO_JOIN_REQUEST=§cThe player did not request joining
NO_CONFIRMATION=§cNo confirmation necessary
@@ -0,0 +1,236 @@
#
# This file is a part of the SteamWar software.
#
# Copyright (C) 2022 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/>.
#
# Commands
NO_TEAM=§cDu bist in keinem Team
FIGHT_ALREADY_STARTED=§cDer Kampf hat bereits begonnen
NOT_LEADER=§cDu bist kein Leader
PLAYER_UNAVAILABLE=§cDer Spieler ist nicht in der Arena
NOT_IN_TEAM=§e{0} §cist nicht in deinem Team
KIT_UNAVAILABLE=§cDieses Kit gibt es nicht
KIT_CHOSEN=§7Kit §e{0} §7gew§hlt
GAMEMODE_NOT_ALLOWED=§cSpielmodusänderung verboten
GAMEMODE_UNKNOWN=§cUnbekannter Spielmodus {0}
GAMEMODE_HELP=§8/§7gm §8[§eSpielmodus§8]
LEADER_FULL=§cAlle Teams haben bereits einen Leader
ALREADY_IN_TEAM=§cDu bist bereits in einem Team
LOCKSCHEM_HELP=§8/§7lockschem §8[§eTeam§8]
UNKNOWN_TEAM=§cDieses Team existiert nicht
LOCKSCHEM_LOCKED=§7Schematic gesperrt
LOCKSCHEM_LOCKED_BY=§cDie Schematic wurde von §e{0} §cgesperrt
REMOVE_HELP=§8/§eremove §8[§eSpieler§8]
NOT_FIGHTLEADER=§cDu bist nicht Kampfleiter
WIN_HELP=§8/§7win §8[§eTeam §8oder §etie§8]
TPSWARP_HELP=§8/§7tpswarp §8[§eTicks pro Sekunde§8]
TPSWARP_SET=§7TPS auf §e{0} §7gesetzt
# GUI
STATE_TITLE=Kampfstatus
STATE_PRE_LEADER_SETUP=§7Teamleaderwartephase
STATE_PRE_SCHEM_SETUP=§7Schemauswahlphase
STATE_POST_SCHEM_SETUP=§7Vorbereitungsphase
STATE_PRE_RUNNING=§eKitausgabe
STATE_RUNNING=§eKampfphase
STATE_SPECTATE_WIN=§7Sieg {0}
STATE_SPECTATE_TIE=§7Unentschieden
REMOVE_TITLE=Spieler rauswerfen
KIT_SELECTION_TITLE=Kitauswahl
KIT_NO_KITS=§cKeine Kits gefunden
KIT_CREATE=§eNeues Kit
KITNAME_TITLE=Kitname eingeben
KITNAME_IN_USE=§cDieser Kitname wird bereits genutzt
KIT_SEARCH=§eSuchen
KITSEARCH_TITLE=Nach Kit suchen
SCHEM_NO_ENEMY=§cKeine Schematicwahl ohne Gegner
SCHEM_TITLE={0}-Auswahl
SCHEM_PUBLIC=§eÖffentliches {0}
SCHEM_UNCHECKED=§eUngeprüftes {0}
SCHEM_PRIVATE=§ePrivates {0}
SCHEM_NO_PRIVATE=§7Kein privates {0} vorhanden
SCHEM_PRIVATE_FORBIDDEN=§7Kein privates {0} erlaubt
# Countdowns
COUNTDOWN_MINUTES=§e{0} §7Minuten {1}
COUNTDOWN_SECONDS=§e{0} §7Sekunden {1}
COUNTDOWN_SECOND=§eEine §7Sekunde {1}
ENTERN_COUNTDOWN=bis Entern erlaubt ist
ENTERN_ALLOWED=§eEntern §7ist nun erlaubt
SHUTDOWN_COUNTDOWN=bis der Server gestoppt wird
PRE_SCHEM_COUNTDOWN=bis eine Public-Schematic gewählt wird
POST_SCHEM_COUNTDOWN=bis die Kits verteilt werden
PRE_RUNNING_COUNTDOWN=bis die Arena freigegeben ist
RUNNING_COUNTDOWN=bis der Kampf vorbei ist
SPECTATE_COUNTDOWN=bis die Arena zurückgesetzt wird
# Fight
SCHEMATIC_UNLOADABLE=§cSchematic konnte nicht geladen werden
SCHEMATIC_CHOSEN=§7{0} §e{1} §7gewählt
SCHEMATIC_UNCHECKED=§7Team {0} §7hat eine §eungeprüfte §7Schematic gewählt§8!
TEAM_READY=§aTeam bereit
TEAM_NOT_READY=§c§mTeam bereit
SKIP_READY=§aBeschleunigung zum nächsten Event
SKIP_NOT_READY=§c§mBeschleunigung zum nächsten Event
CHOOSE_KIT=§eKit wählen
RESPAWN=§eRespawn
REMOVE_PLAYERS=§cSpieler rauswerfen
CHOOSE_SCHEMATIC=§e{0} wählen
SCHEMATIC_REQUIRED=§cZuerst muss eine Schematic gewählt sein
KIT_PREVIEW_EDIT=§7Kit bearbeiten
KIT_PREVIEW_CHOOSE=§aKit wählen
KIT_PREVIEW_BACK=§cZurück
KIT_PREVIEW_DELETE=§cKit löschen
KIT_DELETION_CONFIRMATION=Kit wirklich löschen?
KIT_DELETION_ABORT=§cAbbrechen
KIT_DELETION_DELETE=§aLöschen
# Listener
NO_ARENA_LEAVING=§cDu darfst die Arena nicht verlassen
CHECK_JOIN_DENIED=§cAuf diesem Server wird momentan eine Schematic geprüft!
CHECK_COMMAND_LOCKED=§cDieser Befehl ist beim Prüfen gesperrt! Admin wird benachrichtigt.
NO_BLOCK_BREAK=§cDu darfst hier derzeit keine Blöcke abbauen
NO_BLOCK_PLACE=§cDu darfst hier derzeit keine Blöcke setzen
NO_BOW_USAGE=§cDu darfst den Bogen erst nach Kampfbeginn nutzen
NO_PARTICIPANT=§cDu bist kein Kampfteilnehmer
NO_FRIENDLY_FIRE=§cDu darfst deinen Teamkollegen keinen Schaden zufügen
NO_TNT_PLACE=§cDu darfst kein TNT setzen
NO_TELEPORT=§cDu darfst diese Teleportfunktion nicht benutzen
OPEN_INVENTORY_TO_CUSTOMIZE=§eInventar zum Anpassen des Kits öffnen
NO_ENTERN=§cDu darfst nicht entern
NO_TEAMAREA=§cDu darfst nicht zu den Teams
TEST_BECOME_LEADER=§7Werde zum Teamleader mit §8/§eleader
PREPARE_SCHEM_DELETED=§cAnscheinend wurde die auszufahrende Schematic gelöscht, Einsenden wird abgebrochen.
PREPARE_SCHEM_EXISTS=§cEs existiert bereits eine Schem mit Namenszusatz -prepared, diese bitte umbenennen oder löschen, Einsenden wird abgebrochen.
PREPARE_ACTIVE_PISTON=§cIm Teambereich wurden sich noch bewegende Pistons gefunden, Einsenden wird abgebrochen.
PREPARE_FAILED_SAVING=§cDie Schematic konnte nicht gespeichert werden, Einsenden wird abgebrochen.
PREPARE_SENT_IN=§aDie Schematic wird nun zeitnah von einem Teammitglied überprüft
PISTON_PUSHED_OUTSIDE=§cEin Kolben hat einen Block aus dem erlaubten Bereich geschoben!
# Replay
REPLAY_ENDS=§cReplay beendet
# States
COMMAND_CURRENTLY_UNAVAILABLE=§cDieser Befehl ist zu diesem Kampfzeitpunkt nicht verfügbar
# Utils
UI_PRE_RUNNING=§7Kits verteilt
UI_RUNNING=§aArena freigegeben
UI_SKIP=§7Sprung zum nächsten Ereignis
UI_UNRANKED=§7Ungewerteter Kampf
UI_LEADER_JOINS=§a§l» {0}Leader {1}
UI_PLAYER_DEATH={0}{1} §7ist gestorben
UI_PLAYER_LEAVE={0}{1} §7hat den Kampf verlassen
UI_WIN={0}Sieg {1}
UI_DRAW=§7Unentschieden
BAR_PRE_LEADER=§7Warten auf Teamleader
BAR_PRE_SCHEM={1} §7Schemauswahl {0} {2}
BAR_PREPARE={1} {3} §7Vorbereitung {0} {4} {2}
BAR_PRE_RUNNING={1} {3} §7Kampfbeginn in {0} {4} {2}
BAR_TIE={1} §7Unentschieden {0} {2}
BAR_WIN={1} §7Sieg {3} {0} {2}
BAR_POINTS={0} §8Punkte
BAR_POINTS_OF={0}§8/§7{1} §8Punkte
BAR_PERCENT={0}§8%
BAR_CANNONS={0} §8Kanonen
BAR_WATER={0} §8Wasser
# Winconditions
HELLS_BELLS_COUNTDOWN=bis die Bomben fallen
HELLS_BELLS_START_1=§c!!Achtung!! Bomber im Anflug, noch ca. eine Minute bis zur Ankunft.
HELLS_BELLS_START_2=§cBomber im Anflug, ca. eine Minute bis zur Ankunft.
HELLS_BELLS_START_3=§cBomber auf dem Radar gesichtet, geschätzte Ankunftszeit: eine Minute.
HELLS_BELLS_START_4=§cUnbekanntes Flugobjekt gesichtet, trifft in ca. einer Minute ein.
HELLS_BELLS_START_5=§cFlugobjekt gesichtet. Ankunft in ca. einer Minute.
HELLS_BELLS_START_6=§cBomber erschienen, Ankunft ca. eine Minute.
HELLS_BELLS_SWAP_1=§aDie Bomben fallen nun schneller.
HELLS_BELLS_SWAP_2=§aMehr Bomber im Anflug.
HELLS_BELLS_SWAP_3=§aZusätzliche Bomber gesichtet.
HELLS_BELLS_SWAP_4=§aDas Bombardement scheint sich zu erhöhen.
METEOR_COUNTDOWN=bis es Meteore regnet
METEOR_START_1=§cEin Meteorschauer wurden am Himmel entdeckt
METEOR_START_2=§cSternschnuppen sind diesen Fight 100% wahrscheinlicher
METEOR_START_3=§cEs wurden Meteoriten am Himmel entdeckt, begeben sie sich umgehend in Sicherheit!
METEOR_START_4=§cDer Untergang steht nahe! Die Meteoriten werden uns in etwa einer Minute treffen.
METEOR_START_5=§fNEWS §cHeute Nachmittag wird es größere Meteoriten Schauer geben!
METEOR_START_6=§cNoch fliegende Airships sind dem Absturz geweiht.
METEOR_SWAP_1=§aEs hört nicht auf, die Meteoriten scheinen mehr zu werden.
METEOR_SWAP_2=§aDas war erst der Anfang, die Meteoriten kommen immer schneller und machen mehr Schaden.
METEOR_SWAP_3=§aEs scheint als würde es nicht aufhören, die Meteoriten kommen nur schneller!
METEOR_SWAP_4=§aEin weiterer Schauer ist entdeckt worden, begebt euch in Sicherheit!
TECHKO_COUNTDOWN=bis {0} §7einen Schuss abgegeben haben muss
WIN_FIGHTLEADER=§7Kampfleiterentscheidung
WIN_PERCENT={0} §7zu beschädigt
WIN_OFFLINE_BOTH=§7Beide Teams offline
WIN_OFFLINE={0} §7offline
WIN_ALL_DEAD={0}Alle Spieler kampfunfähig
WIN_LEADER_DEAD={0} kampfunfähig
WIN_TIME_OVER=§7Zeit abgelaufen
WIN_MORE_HEALTH={0} mit mehr verbleibenden Leben
WIN_LESS_DAMAGE={0} §7weniger beschädigt
WIN_POINTS={0} hat mehr Punkte
WIN_POINTS_EQUAL=§7Gleicher Punktestand
WIN_TECHKO={0} §7ist Tech K.O.
WIN_IMPOSTER_DEAD={0} §7 hat den Imposter getötet
WIN_CREWMATE_DEAD={0} §7 hat alle Kameraden getötet
AMONG_US_IMPOSTER_MESSAGE = §4Du bist ein Imposter§8! §7Du musst alle Kameraden töten, um zu gewinnen.
AMONG_US_IMPOSTER_AMONG_MESSAGE = §4Es ist ein Imposter unter uns§8! §7Tötet ihn, um das Spiel zu gewinnen!
# Invites
JOIN_REQUEST=§7Teambeitritt anfragen
JOIN_REQUEST_TITLE=Teambeitritt anfragen
JOIN_REQUEST_ALREADY=§cDu hast bereits ein Team um Beitritt angefragt
JOIN_REQUEST_TEAM={0} §7beitreten
JOIN_REQUEST_CONFIRMATION=§7Teambeitritt angefragt
JOIN_REQUEST_NOTIFICATION=§e{0} §7möchte Team {1} §7beitreten§8. §7Akzeptiere oder lehne ab mit §8/§erequests
REQUESTS=§7Offene Beitrittsanfragen
REQUESTS_TITLE=Offene Beitrittsanfragen
REQUEST_DECLINED=§cBeitritt von {0} abgelehnt
REQUEST_YOUR_DECLINED=§cDeine Betrittsanfrage wurde abgelehnt
REQUESTS_LEFT_CLICK=§eLinksklick §7um §eanzunehmen§8!
REQUESTS_RIGHT_CLICK=§eRechtsklick §7um §eabzulehnen§8!
NO_JOIN_REQUEST=§cDer Spieler hat noch keinen Beitritt angefragt
NO_CONFIRMATION=§cKeine Zustimmung nötig
@@ -0,0 +1,294 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 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.ai;
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.listener.Chat;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.OneShotStateDependent;
import de.steamwar.fightsystem.utils.Region;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Note;
import org.bukkit.block.Block;
import org.bukkit.block.Lectern;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Openable;
import org.bukkit.block.data.Powerable;
import org.bukkit.block.data.type.Comparator;
import org.bukkit.block.data.type.NoteBlock;
import org.bukkit.block.data.type.Repeater;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Villager;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
import java.util.*;
import java.util.logging.Level;
public abstract class AI {
private static final Map<UUID, AI> ais = new HashMap<>();
static {
new OneShotStateDependent(ArenaMode.All, FightState.Spectate, () -> {
ais.values().forEach(AI::stop);
ais.clear();
});
}
public static AI getAI(UUID uuid) {
return ais.get(uuid);
}
private final FightTeam team;
private final LivingEntity entity;
private final BukkitTask task;
private final Queue<Action> queue = new ArrayDeque<>();
protected AI(FightTeam team, SteamwarUser user) {
this.team = team;
entity = (LivingEntity) Config.world.spawnEntity(Config.SpecSpawn, EntityType.VILLAGER);
entity.setCustomName(user.getUserName());
((Villager)entity).setAware(false);
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::run, 1, 1);
ais.put(entity.getUniqueId(), this);
team.addMember(entity, user);
}
public abstract SchematicNode chooseSchematic();
public boolean acceptJoinRequest(Player player, FightTeam team) {
return true;
}
protected abstract void plan();
public void stop() {
if(!entity.isDead())
entity.remove();
if(!task.isCancelled())
task.cancel();
}
public LivingEntity getEntity() {
return entity;
}
protected void setReady() {
if(FightState.getFightState() != FightState.POST_SCHEM_SETUP)
return;
if(team.getLeader().getEntity() != entity)
return;
team.setReady(true);
}
protected void chat(String message) {
FightSystem.getPlugin().getLogger().log(Level.INFO, () -> entity.getName() + "» " + message);
Chat.broadcastChat("PARTICIPANT_CHAT", team.getColoredName(), entity.getName(), message);
}
protected Vector getPosition() {
Location location = entity.getLocation();
Region extend = team.getExtendRegion();
if(Fight.getUnrotated() == team)
return new Vector(
location.getX() - extend.getMinX(),
location.getY() - team.getSchemRegion().getMinY(),
location.getZ() - extend.getMinZ()
);
else
return new Vector(
extend.getMaxX() - location.getX(),
location.getY() - team.getSchemRegion().getMinY(),
extend.getMaxZ() - location.getZ()
);
}
protected Material getBlock(Vector pos) {
queue.add(new Action(1));
return translate(pos, true).getBlock().getType();
}
protected boolean isPowered(Vector pos) {
queue.add(new Action(1));
return translate(pos, true).getBlock().isBlockPowered();
}
protected void setTNT(Vector pos) {
queue.add(new Action(1) {
@Override
public void run() {
if(FightState.getFightState() != FightState.RUNNING)
return;
Location location = translate(pos, true);
if(interactionDistanceViolation(location))
return;
Block block = location.getBlock();
if(block.getType() == Material.AIR)
block.setType(Material.TNT);
}
});
}
protected void interact(Vector pos) {
queue.add(new Action(1) {
@Override
public void run() {
Location location = translate(pos, true);
if(interactionDistanceViolation(location))
return;
interact(location.getBlock());
}
});
}
protected void interact(Vector pos, int n) {
queue.add(new Action(1) {
@Override
public void run() {
Location location = translate(pos, true);
if (interactionDistanceViolation(location))
return;
Block block = location.getBlock();
BlockData data = block.getBlockData();
if (data instanceof Repeater) {
Repeater repeater = (Repeater) data;
repeater.setDelay(n);
} else if (data instanceof Lectern) {
Lectern lectern = (Lectern) data;
lectern.setPage(n);
}
block.setBlockData(data);
}
});
}
protected void move(Vector pos) {
queue.add(new Action(2) {
@Override
public void run() {
Location location = entity.getLocation();
Location target = translate(pos, false);
if(Math.abs(location.getX() - target.getX()) > 1 || Math.abs(location.getY() - target.getY()) > 1.2 || Math.abs(location.getZ() - target.getZ()) > 1) {
FightSystem.getPlugin().getLogger().log(Level.INFO, () -> entity.getName() + ": Overdistance movement " + location.toVector() + " " + target.toVector());
return;
}
if(!team.getFightPlayer(entity).canEntern() && !team.getExtendRegion().inRegion(target))
return;
entity.teleport(target, PlayerTeleportEvent.TeleportCause.COMMAND);
}
});
}
private boolean interactionDistanceViolation(Location location) {
return location.distance(entity.getEyeLocation()) > 5;
}
private void interact(Block block) {
BlockData data = block.getBlockData(); //TODO only 1.14+ compatible at the moment
if (data instanceof NoteBlock) {
NoteBlock noteBlock = (NoteBlock) data;
Note note = noteBlock.getNote();
noteBlock.setNote(note.isSharped() ? note.flattened() : note.sharped());
} else if (data instanceof Openable) {
Openable openable = (Openable) data;
openable.setOpen(!openable.isOpen());
} else if (data instanceof Comparator) {
Comparator comparator = (Comparator) data;
comparator.setMode(Comparator.Mode.values()[1 - comparator.getMode().ordinal()]);
} else if (data instanceof Powerable) {
Material type = block.getType();
Powerable powerable = (Powerable) data;
boolean isPowered = powerable.isPowered();
if(type.name().endsWith("BUTTON")) {
if(isPowered)
return;
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> {
if(!block.getType().name().endsWith("BUTTON"))
return;
powerable.setPowered(false);
block.setBlockData(powerable);
}, type.name().endsWith("STONE_BUTTON") ? 20 : 30);
}
powerable.setPowered(!isPowered);
}
block.setBlockData(data);
}
private void run() {
if(queue.isEmpty())
plan();
if(!queue.isEmpty() && --queue.peek().delay == 0)
queue.poll().run();
}
private Location translate(Vector pos, boolean blockPos) {
Region extend = team.getExtendRegion();
if(Fight.getUnrotated() == team)
return new Location(
Config.world,
pos.getX() + extend.getMinX(),
pos.getY() + team.getSchemRegion().getMinY(),
pos.getZ() + extend.getMinZ()
);
else
return new Location(
Config.world,
extend.getMaxX() - pos.getX() - (blockPos ? 1 : 0),
pos.getY() + team.getSchemRegion().getMinY(),
extend.getMaxZ() - pos.getZ() - (blockPos ? 1 : 0)
);
}
private static class Action {
private int delay;
public Action(int delay) {
this.delay = delay;
}
public void run() {}
}
}
@@ -0,0 +1,60 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 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.ai;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.util.Vector;
import java.util.List;
import java.util.Random;
public class LixfelAI extends AI {
private final Random random = new Random();
private LixfelPathplanner pathplanner;
public LixfelAI(FightTeam team, String user) {
super(team, SteamwarUser.get(user));
}
@Override
public SchematicNode chooseSchematic() {
List<SchematicNode> publics = SchematicNode.getAllSchematicsOfType(0, Config.SchematicType.toDB());
SchematicNode schem = publics.get(new Random().nextInt(publics.size()));
pathplanner = new LixfelPathplanner(schem);
return schem;
}
@Override
protected void plan() {
setReady();
Vector destination = pathplanner.getWalkable().get(random.nextInt(pathplanner.getWalkable().size()));
List<Vector> path = pathplanner.plan(getPosition(), destination);
if(!path.isEmpty())
chat("Path size: " + path.size());
for(Vector p : path) {
move(p);
}
}
}
@@ -0,0 +1,141 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 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.ai;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.block.BlockType;
import de.steamwar.fightsystem.Config;
import de.steamwar.sql.SchematicData;
import de.steamwar.sql.SchematicNode;
import org.bukkit.util.Vector;
import java.io.IOException;
import java.util.*;
public class LixfelPathplanner {
private static BlockType getBlockType(Clipboard clipboard, BlockVector3 vector) {
return clipboard.getBlock(vector).getBlockType();
}
private static boolean nonsolid(Clipboard clipboard, BlockVector3 vector) {
return !getBlockType(clipboard, vector).getMaterial().isSolid();
}
private static Vector toBukkit(BlockVector3 vector) {
return new Vector(vector.getX() + 0.5, vector.getY(), vector.getZ() + 0.5);
}
private final List<Vector> walkable = new ArrayList<>();
private final Map<Vector, Vector[]> neighbours = new HashMap<>();
public LixfelPathplanner(SchematicNode schem) {
try {
fillWalkable(new SchematicData(schem).load());
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
public List<Vector> getWalkable() {
return walkable;
}
private void fillWalkable(Clipboard clipboard) {
BlockVector3 min = clipboard.getRegion().getMinimumPoint().subtract(Config.PreperationArea, 0, Config.PreperationArea); //TODO assumes nonextended Schematic with maximal size
Region region = clipboard.getRegion();
clipboard.getRegion().forEach(vector -> {
BlockVector3 below = vector.subtract(0, 1, 0);
if(!region.contains(below))
return;
BlockType belowMaterial = getBlockType(clipboard, below);
BlockVector3 above = vector.add(0, 1, 0);
if(nonsolid(clipboard, vector)) {
if(
(belowMaterial.getMaterial().isSolid() || belowMaterial.getId().equals("minecraft:ladder")) &&
(!region.contains(above) || nonsolid(clipboard, above))
)
walkable.add(toBukkit(vector.subtract(min)));
} else {
if(!region.contains(above))
walkable.add(toBukkit(above.subtract(min)));
}
});
for(Vector vector : walkable) {
neighbours.put(vector, walkable.stream().filter(neighbour -> neighbouring(neighbour, vector)).filter(neighbour -> neighbour != vector).toArray(Vector[]::new));
}
}
public List<Vector> planToAnywhere(Vector start, Vector destination) {
Vector intermediate = walkable.stream().filter(vector -> neighbouring(vector, destination)).findAny().orElse(null);
if(intermediate == null)
return Collections.emptyList();
List<Vector> plan = plan(start, intermediate);
plan.add(destination);
return plan;
}
public List<Vector> plan(Vector start, Vector destination) {
if(neighbouring(start, destination))
return Collections.singletonList(destination);
Map<Vector, Vector> approach = new HashMap<>();
Set<Vector> checking = Collections.singleton(destination);
while(!checking.isEmpty()) {
Set<Vector> toCheck = new HashSet<>();
for(Vector current : checking) {
Vector firstStep = Arrays.stream(neighbours.get(current))
.filter(vector -> !approach.containsKey(vector))
.filter(next -> {
approach.put(next, current);
toCheck.add(next);
return neighbouring(next, start);
})
.findAny().orElse(null);
if(firstStep != null) {
List<Vector> path = new ArrayList<>();
path.add(firstStep);
while(path.get(path.size()-1) != destination) {
path.add(approach.get(path.get(path.size()-1)));
}
return path;
}
}
checking = toCheck;
}
return Collections.emptyList();
}
private boolean neighbouring(Vector a, Vector b) {
return Math.abs(a.getX() - b.getX()) <= 1 && Math.abs(a.getY() - b.getY()) <= 1 && Math.abs(a.getZ() - b.getZ()) <= 1;
}
}
@@ -0,0 +1,57 @@
/*
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.commands;
import de.steamwar.core.Core;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Kit;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCommand;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.UserPerm;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class AkCommand implements CommandExecutor {
public AkCommand() {
new StateDependentCommand(ArenaMode.Test, FightState.All, "ak", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) {
return false;
}
Player player = (Player) sender;
if(!player.isOp())
return false;
if(!SteamwarUser.get(player.getUniqueId()).hasPerm(UserPerm.ADMINISTRATION) && Core.getInstance() != FightSystem.getPlugin()){
return false;
}
Kit.createKit(args[0], player);
return false;
}
}
@@ -0,0 +1,170 @@
/*
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.commands;
import com.comphenix.tinyprotocol.Reflection;
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.fight.Kit;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.sql.PersonalKit;
import de.steamwar.sql.SteamwarUser;
import lombok.experimental.UtilityClass;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.SimpleCommandMap;
import org.bukkit.entity.Player;
@UtilityClass
public class Commands {
private static final Reflection.FieldAccessor<SimpleCommandMap> commandMap = Reflection.getField("{obc}.CraftServer", "commandMap", SimpleCommandMap.class);
public static void injectCommand(Command cmd) {
commandMap.get(Bukkit.getServer()).register("FightSystem", cmd);
}
private static void errNoTeam(Player p){
FightSystem.getMessage().sendPrefixless("NO_TEAM", p, ChatMessageType.ACTION_BAR);
}
static boolean checkSetup(Player p){
if(!FightState.setup()){
FightSystem.getMessage().sendPrefixless("FIGHT_ALREADY_STARTED", p, ChatMessageType.ACTION_BAR);
return true;
}
return false;
}
private static FightPlayer checkGetPlayer(Player p){
FightPlayer fightPlayer = Fight.getFightPlayer(p);
if(fightPlayer == null){
errNoTeam(p);
}
return fightPlayer;
}
public static FightPlayer checkGetLeader(Player p){
FightPlayer fightPlayer = checkGetPlayer(p);
if(fightPlayer != null && !fightPlayer.isLeader()){
FightSystem.getMessage().sendPrefixless("NOT_LEADER", p, ChatMessageType.ACTION_BAR);
fightPlayer = null;
}
return fightPlayer;
}
public static FightTeam checkGetTeam(Player p){
FightTeam fightTeam = Fight.getPlayerTeam(p);
if(fightTeam == null){
errNoTeam(p);
}
return fightTeam;
}
private static Player checkGetPlayer(Player p, String t){
Player target = Bukkit.getPlayer(t);
if(target == null) {
FightSystem.getMessage().sendPrefixless("PLAYER_UNAVAILABLE", p, ChatMessageType.ACTION_BAR);
}
return target;
}
static void toggleReady(Player p){
FightTeam fightTeam = checkGetTeam(p);
if(fightTeam == null || checkGetLeader(p) == null)
return;
fightTeam.setReady(!fightTeam.isReady());
}
static void toggleSkip(Player p){
FightTeam fightTeam = checkGetTeam(p);
if(fightTeam == null || checkGetLeader(p) == null)
return;
fightTeam.skip();
}
static void leaveTeam(Player p){
if(checkSetup(p))
return;
FightTeam fightTeam = checkGetTeam(p);
if(fightTeam == null)
return;
fightTeam.removePlayer(p);
}
static void kick(Player p, String kicked){
if(checkSetup(p))
return;
FightTeam fightTeam = checkGetTeam(p);
if(fightTeam == null)
return;
FightPlayer fightPlayer = checkGetLeader(p);
if(fightPlayer == null)
return;
Player target = checkGetPlayer(p, kicked);
if(target == null)
return;
if(!fightTeam.isPlayerInTeam(target)){
FightSystem.getMessage().sendPrefixless("NOT_IN_TEAM", p, ChatMessageType.ACTION_BAR, target.getName());
return;
}
fightTeam.removePlayer(target);
}
public static void kit(Player p, String kitName){
if(checkSetup(p))
return;
FightPlayer fightPlayer = checkGetPlayer(p);
if(fightPlayer == null)
return;
Kit k = null;
if(Config.PersonalKits){
PersonalKit kit = PersonalKit.get(SteamwarUser.get(p.getUniqueId()).getId(), Config.SchematicType.toDB(), kitName);
if(kit != null){
kit.setInUse();
k = new Kit(kit);
}
}else{
k = Kit.getKitByName(kitName);
}
if(k == null || !k.canUseKit(fightPlayer.isLeader())){
FightSystem.getMessage().sendPrefixless("KIT_UNAVAILABLE", p, ChatMessageType.ACTION_BAR);
return;
}
FightSystem.getMessage().sendPrefixless("KIT_CHOSEN", p, ChatMessageType.ACTION_BAR, kitName);
fightPlayer.setKit(k);
}
}
@@ -0,0 +1,224 @@
/*
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.commands;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.*;
import de.steamwar.fightsystem.listener.PersonalKitCreator;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.utils.ColorConverter;
import de.steamwar.inventory.*;
import de.steamwar.message.Message;
import de.steamwar.sql.PersonalKit;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SchematicType;
import de.steamwar.sql.SteamwarUser;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class GUI {
private GUI(){}
private static final Message msg = FightSystem.getMessage();
@SuppressWarnings("deprecation")
private static void addTeamRequest(Player p, SWInventory inv, int pos, FightTeam team) {
byte colorCode = ColorConverter.chat2dye(team.getColor()).getDyeData();
String name = team.getLeader() != null ? team.getLeader().getEntity().getName() : team.getName();
inv.setItem(pos, SWItem.getDye(colorCode), colorCode, msg.parse("JOIN_REQUEST_TEAM", p, team.getColor() + name), click -> {
p.closeInventory();
new JoinRequest(p, team);
});
}
public static void joinRequest(Player p) {
if(JoinRequest.get(p) != null) {
msg.sendPrefixless("JOIN_REQUEST_ALREADY", p, ChatMessageType.ACTION_BAR);
return;
}
SWInventory inv = new SWInventory(p, 9, msg.parse("JOIN_REQUEST_TITLE", p));
FightTeam team = Fight.getPlayerTeam(p);
if(team != Fight.getRedTeam())
addTeamRequest(p, inv, team == null ? 0 : 4, Fight.getBlueTeam());
if(team != Fight.getBlueTeam())
addTeamRequest(p, inv, team == null ? 8 : 4, Fight.getRedTeam());
inv.open();
}
public static void state(Player p){
SWInventory inv = new SWInventory(p, 9, msg.parse("STATE_TITLE", p));
int i = 0;
for(FightState state : FightState.values()) {
if(state == FightState.SPECTATE)
continue;
inv.setItem(i++, Material.GLASS, msg.parse("STATE_" + state.name(), p), click -> FightState.setFightState(state));
}
for(FightTeam team : Fight.teams()) {
inv.setItem(i++, Material.GLASS, msg.parse("STATE_SPECTATE_WIN", p, team.getColoredName()), click -> FightSystem.setSpectateState(team, "operator", "WIN_FIGHTLEADER"));
}
inv.setItem(i, Material.GLASS, msg.parse("STATE_SPECTATE_TIE", p), click -> FightSystem.setSpectateState(null, "operator", "WIN_FIGHTLEADER"));
inv.setCallback(-999, (ClickType click) -> p.closeInventory());
inv.open();
}
public static void chooseJoinRequests(Player p){
List<SWListInv.SWListEntry<Player>> players = JoinRequest.openRequests(p, Fight.getPlayerTeam(p));
SWListInv<Player> inv = new SWListInv<>(p, msg.parse("REQUESTS_TITLE", p), players, (ClickType click, Player player) -> {
p.closeInventory();
RequestsCommand.onJoinRequest(p, player, click.isLeftClick() ? JoinRequest::accept : JoinRequest::decline);
});
inv.setCallback(-999, (ClickType click) -> p.closeInventory());
inv.open();
}
public static void chooseRemove(Player p){
List<SWListInv.SWListEntry<UUID>> players = SWListInv.createPlayerList(p.getUniqueId());
FightTeam team = Fight.getPlayerTeam(p);
if(team == null)
return;
players.removeIf(swItemUUIDPair -> !team.equals(Fight.getPlayerTeam(Bukkit.getPlayer(swItemUUIDPair.getObject()))));
SWListInv<UUID> inv = new SWListInv<>(p, msg.parse("REMOVE_TITLE", p), players, (ClickType click, UUID player) -> {
Commands.kick(p, SteamwarUser.get(player).getUserName());
p.closeInventory();
});
inv.setCallback(-999, (ClickType click) -> p.closeInventory());
inv.open();
}
public static void kitSelection(Player p, String query){
FightPlayer fightPlayer = Fight.getFightPlayer(p);
if(fightPlayer == null)
return;
List<SWListInv.SWListEntry<Kit>> entries = new ArrayList<>();
if(Config.PersonalKits){
List<PersonalKit> kits = PersonalKit.get(SteamwarUser.get(p.getUniqueId()).getId(), Config.SchematicType.toDB());
kits.forEach(kit -> entries.add(new SWListInv.SWListEntry<>(new SWItem(Material.LEATHER_CHESTPLATE, "§e" + kit.getName(), new ArrayList<>(), kit.isInUse(), clickType -> {}), new Kit(kit))));
}else{
List<Kit> kitList = Kit.getAvailableKits(fightPlayer.isLeader());
for(Kit k : kitList){
entries.add(new SWListInv.SWListEntry<>(new SWItem(Material.LEATHER_CHESTPLATE, k.getName(), null, k.leaderExclusive(), null), k));
}
}
entries.removeIf(entry -> !entry.getObject().getName().toLowerCase().contains(query.toLowerCase()));
SWListInv<Kit> inv = new SWListInv<>(p, msg.parse("KIT_SELECTION_TITLE", p), false, entries, (clickType, kit) -> kit.preview(p));
inv.setCallback(-999, (ClickType click) -> p.closeInventory());
if(entries.isEmpty()) {
inv.setItem(22, new SWItem(Material.BARRIER, msg.parse("KIT_NO_KITS", p)));
}
if(Config.PersonalKits){
inv.setItem(48, Material.NETHER_STAR, msg.parse("KIT_CREATE", p), clickType -> {
SWAnvilInv anvilInv = new SWAnvilInv(p, msg.parse("KITNAME_TITLE", p));
anvilInv.setItem(Material.LEATHER_CHESTPLATE);
anvilInv.setCallback(s -> {
SteamwarUser user = SteamwarUser.get(p.getUniqueId());
if(PersonalKit.get(user.getId(), Config.SchematicType.toDB(), s) != null) {
msg.sendPrefixless("KITNAME_IN_USE", p, ChatMessageType.ACTION_BAR);
p.closeInventory();
return;
}
Kit prototype = Kit.getAvailableKits(Fight.getFightPlayer(p).isLeader()).get(0);
PersonalKit kit = PersonalKit.create(user.getId(), Config.SchematicType.toDB(), s, prototype.getInventory(), prototype.getArmor());
PersonalKitCreator.openKitCreator(p, kit);
});
anvilInv.open();
});
}
inv.setItem(50, Material.NAME_TAG, msg.parse("KIT_SEARCH", p), clickType -> {
SWAnvilInv anvilInv = new SWAnvilInv(p, msg.parse("KITSEARCH_TITLE", p));
anvilInv.setItem(Material.PAPER);
anvilInv.setCallback(s -> kitSelection(p, s));
anvilInv.open();
});
inv.open();
}
public static void preSchemDialog(Player p){
if(!Config.test() && FightState.getFightState() != FightState.PRE_SCHEM_SETUP){
msg.sendPrefixless("SCHEM_NO_ENEMY", p, ChatMessageType.ACTION_BAR);
return;
}
int invSize = (Config.SubTypes.size() + 1) * 9;
SWInventory inv = new SWInventory(p, invSize, msg.parse("SCHEM_TITLE", p, Config.GameName));
setupSchemTypeRow(p, inv, Config.SchematicType, 0);
for (int i = 0; i < Config.SubTypes.size(); i++) {
setupSchemTypeRow(p, inv, Config.SubTypes.get(i), i + 1);
}
inv.setCallback(-999, (ClickType click) -> p.closeInventory());
inv.open();
}
private static void setupSchemTypeRow(Player p, SWInventory inv, SchematicType type, int row) {
inv.setItem(row * 9 + 8, Material.REDSTONE, msg.parse("SCHEM_PUBLIC", p, type.name()), (ClickType click) -> {
p.closeInventory();
schemDialog(p, type, true, false);
});
if (Fight.publicOnly()) {
inv.setItem(row * 9, SWItem.getDye(8), (byte)8, msg.parse("SCHEM_PRIVATE_FORBIDDEN", p, type.name()), (ClickType click)->{});
return;
}
if (type.checkType() != null && type.checkType() != type && ArenaMode.AntiEvent.contains(Config.mode) && !SchematicNode.getAllAccessibleSchematicsOfType(SteamwarUser.get(p.getUniqueId()).getId(), type.checkType().toDB()).isEmpty()) {
inv.setItem(row * 9 + 4, Material.ANVIL, msg.parse("SCHEM_UNCHECKED", p, type.name()), (ClickType click) -> {
p.closeInventory();
schemDialog(p, type, false, true);
});
}
if (SchematicNode.getAllAccessibleSchematicsOfType(SteamwarUser.get(p.getUniqueId()).getId(), type.toDB()).isEmpty() && !Config.test()) {
inv.setItem(row * 9, SWItem.getDye(8), (byte)8, msg.parse("SCHEM_NO_PRIVATE", p, type.name()), (ClickType click)->{});
return;
}
inv.setItem(row * 9, SWItem.getMaterial("CAULDRON_ITEM"), msg.parse("SCHEM_PRIVATE", p, type.name()), (ClickType click) -> {
p.closeInventory();
schemDialog(p, type, false, false);
});
}
private static void schemDialog(Player p, SchematicType type, boolean publicSchems, boolean unchecked){
SchematicSelector selector = new SchematicSelector(p, Config.test() ? SchematicSelector.selectSchematic() : SchematicSelector.selectSchematicType(unchecked ? type.checkType() : type), node -> {
FightTeam fightTeam = Fight.getPlayerTeam(p);
if(fightTeam == null)
return;
if(Config.test() || FightState.getFightState() != FightState.POST_SCHEM_SETUP)
fightTeam.pasteSchem(node);
p.closeInventory();
});
selector.setPublicMode(publicSchems?SchematicSelector.PublicMode.PUBLIC_ONLY:SchematicSelector.PublicMode.PRIVATE_ONLY);
selector.open();
}
}
@@ -0,0 +1,107 @@
/*
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.commands;
import com.google.common.collect.ImmutableList;
import de.steamwar.core.CommandRemover;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.GameMode;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
public class GamemodeCommand extends BukkitCommand {
private static final List<String> GAMEMODE_NAMES = ImmutableList.of("adventure", "creative", "survival",
"spectator");
public GamemodeCommand() {
super("gamemode");
List<String> aliases = new ArrayList<>();
aliases.add("gm");
this.setAliases(aliases);
try {
CommandRemover.removeAll("gamemode");
} catch (Exception e) {
FightSystem.getPlugin().getLogger().log(Level.SEVERE, "Failed to replace commands", e);
}
Commands.injectCommand(this);
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!(sender instanceof Player)) {
return false;
}else if (args.length == 0) {
FightSystem.getMessage().sendPrefixless("GAMEMODE_HELP", sender);
return false;
}
Player p = (Player) sender;
if (!(Config.test() || Config.isReferee(p))) {
FightSystem.getMessage().sendPrefixless("GAMEMODE_NOT_ALLOWED", p, ChatMessageType.ACTION_BAR);
return false;
}
GameMode mode = createMode(args[0]);
if(mode == null){
FightSystem.getMessage().sendPrefixless("GAMEMODE_UNKNOWN", p, ChatMessageType.ACTION_BAR, args[0]);
return false;
}
p.setGameMode(mode);
return true;
}
@SuppressWarnings("deprecation")
private GameMode createMode(String modeArg){
try {
return GameMode.getByValue(Integer.parseInt(modeArg));
} catch (NumberFormatException ignored) {
if ((modeArg.equalsIgnoreCase("creative")) || (modeArg.equalsIgnoreCase("c")))
return GameMode.CREATIVE;
else if ((modeArg.equalsIgnoreCase("adventure")) || (modeArg.equalsIgnoreCase("a")))
return GameMode.ADVENTURE;
else if ((modeArg.equalsIgnoreCase("spectator")) || (modeArg.equalsIgnoreCase("sp")))
return GameMode.SPECTATOR;
else if ((modeArg.equalsIgnoreCase("survival")) || (modeArg.equalsIgnoreCase("s")))
return GameMode.SURVIVAL;
}
return null;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
if (args.length == 1)
return StringUtil.copyPartialMatches(args[0], GAMEMODE_NAMES, new ArrayList<>(GAMEMODE_NAMES.size()));
return ImmutableList.of();
}
}
@@ -0,0 +1,64 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 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.commands;
import de.steamwar.fightsystem.ArenaMode;
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.StateDependentCommand;
import de.steamwar.fightsystem.utils.FightStatistics;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.UserPerm;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class InfoCommand implements CommandExecutor {
public InfoCommand() {
new StateDependentCommand(ArenaMode.All, FightState.All, "fightinfo", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player))
return false;
Player player = (Player) sender;
if(!SteamwarUser.get(player.getUniqueId()).hasPerm(UserPerm.CHECK))
return false;
FightSystem.getMessage().send("INFO_RANKED", player, !FightStatistics.isUnranked());
for(FightTeam team : Fight.teams()) {
if(!team.isLeaderless())
FightSystem.getMessage().send("INFO_LEADER", player, team.getColoredName(), team.getLeader().getEntity().getName());
if(team.getSchematic() != 0) {
SchematicNode schematic = SchematicNode.getSchematicNode(team.getSchematic());
FightSystem.getMessage().send("INFO_SCHEMATIC", player, team.getColoredName(), schematic.getName(), SteamwarUser.get(schematic.getOwner()).getUserName(), schematic.getRank());
}
}
return false;
}
}
@@ -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.commands;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class KitCommand implements CommandExecutor {
public KitCommand() {
new StateDependentCommand(ArenaMode.AntiReplay, FightState.Setup, "kit", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) {
return false;
}
Player player = (Player) sender;
if(args.length != 1)
GUI.kitSelection(player, "");
else{
Commands.kit(player, args[0]);
}
return false;
}
}
@@ -0,0 +1,60 @@
/*
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.commands;
import de.steamwar.fightsystem.ArenaMode;
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.StateDependentCommand;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class LeaderCommand implements CommandExecutor {
public LeaderCommand() {
new StateDependentCommand(ArenaMode.ManualTeams, FightState.Setup, "leader", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player))
return false;
Player player = (Player) sender;
if(Fight.getFightPlayer(player) != null) {
FightSystem.getMessage().sendPrefixless("ALREADY_IN_TEAM", player, ChatMessageType.ACTION_BAR);
return false;
}
for(FightTeam team : Fight.teams()) {
if(team.canbeLeader(player)) {
team.addMember(player);
return false;
}
}
FightSystem.getMessage().sendPrefixless("LEADER_FULL", player, ChatMessageType.ACTION_BAR);
return false;
}
}
@@ -0,0 +1,46 @@
/*
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.commands;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class LeaveCommand implements CommandExecutor {
public LeaveCommand() {
new StateDependentCommand(ArenaMode.AntiReplay, FightState.Setup, "leave", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) {
return false;
}
Player player = (Player) sender;
Commands.leaveTeam(player);
return false;
}
}
@@ -0,0 +1,68 @@
/*
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.commands;
import de.steamwar.fightsystem.ArenaMode;
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.StateDependentCommand;
import de.steamwar.sql.*;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class LockschemCommand implements CommandExecutor {
public LockschemCommand() {
new StateDependentCommand(ArenaMode.All, FightState.Schem, "lockschem", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player))
return false;
Player player = (Player) sender;
if(!SteamwarUser.get(player.getUniqueId()).hasPerm(UserPerm.CHECK))
return false;
if(args.length != 1) {
FightSystem.getMessage().sendPrefixless("LOCKSCHEM_HELP", player);
return false;
}
String teamName = args[0];
FightTeam fightTeam = Fight.getTeamByName(teamName);
if(fightTeam == null) {
FightSystem.getMessage().sendPrefixless("UNKNOWN_TEAM", player, ChatMessageType.ACTION_BAR);
return false;
}
SchematicNode.getSchematicNode(fightTeam.getSchematic()).setSchemtype(SchematicType.Normal);
FightSystem.getMessage().sendPrefixless("LOCKSCHEM_LOCKED", player, ChatMessageType.ACTION_BAR);
fightTeam.broadcastSystem("LOCKSCHEM_LOCKED_BY", player.getName());
return false;
}
}
@@ -0,0 +1,46 @@
/*
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.commands;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class ReadyCommand implements CommandExecutor {
public ReadyCommand() {
new StateDependentCommand(ArenaMode.AntiPrepare, FightState.PostSchemSetup, "ready", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) {
return false;
}
Player player = (Player) sender;
Commands.toggleReady(player);
return false;
}
}
@@ -0,0 +1,52 @@
/*
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.commands;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class RemoveCommand implements CommandExecutor {
public RemoveCommand() {
new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "remove", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) {
return false;
}
Player player = (Player) sender;
if(args.length != 1){
FightSystem.getMessage().sendPrefixless("REMOVE_HELP", player);
return false;
}
Commands.kick(player, args[0]);
return false;
}
}
@@ -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.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.fight.JoinRequest;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.function.BiConsumer;
public class RequestsCommand implements CommandExecutor {
public RequestsCommand() {
new StateDependentCommand(ArenaMode.VariableTeams, FightState.AntiSpectate, "request", this);
new StateDependentCommand(ArenaMode.VariableTeams, FightState.AntiSpectate, "requests", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player))
return false;
Player player = (Player) sender;
FightPlayer fp = Fight.getFightPlayer(player);
if(fp == null || !(fp.isLeader() || fp.isLiving())) {
GUI.joinRequest(player);
return false;
}
if(Commands.checkGetLeader(player) == null)
return false;
GUI.chooseJoinRequests(player);
return false;
}
public static void onJoinRequest(Player player, Player target, BiConsumer<JoinRequest, FightTeam> handleJoinRequest) {
JoinRequest request = JoinRequest.get(target);
if(request == null) {
FightSystem.getMessage().send("NO_JOIN_REQUEST", player);
return;
}
FightTeam team = Fight.getPlayerTeam(player);
if(!request.required(team)) {
FightSystem.getMessage().send("NO_CONFIRMATION", player);
return;
}
handleJoinRequest.accept(request, team);
}
}
@@ -0,0 +1,53 @@
/*
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.commands;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.record.PacketProcessor;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class SkipCommand implements CommandExecutor {
public SkipCommand() {
new StateDependentCommand(ArenaMode.AntiPrepare, ArenaMode.Replay.contains(Config.mode) ? FightState.All : FightState.TeamFix, "skip", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) {
return false;
}
Player player = (Player) sender;
if(PacketProcessor.isReplaying() && player.getUniqueId().equals(Fight.getBlueTeam().getDesignatedLeader())) {
PacketProcessor.currentReplay().skipToSubtitle();
} else {
Commands.toggleSkip(player);
}
return false;
}
}
@@ -0,0 +1,45 @@
/*
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.commands;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class StateCommand implements CommandExecutor {
public StateCommand() {
new StateDependentCommand(ArenaMode.Test, FightState.All, "state", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) {
return false;
}
GUI.state((Player) sender);
return false;
}
}
@@ -0,0 +1,45 @@
/*
* 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.commands;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class TBCommand implements CommandExecutor {
public TBCommand() {
new StateDependentCommand(ArenaMode.Check, FightState.All, "resettb", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) {
return false;
}
Fight.getRedTeam().pasteSchem();
return false;
}
}
@@ -0,0 +1,52 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 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.commands;
import de.steamwar.core.TPSWarpUtils;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class TPSWarpCommand implements CommandExecutor {
public TPSWarpCommand() {
new StateDependentCommand(ArenaMode.Prepare, FightState.PostSchemSetup, "tpswarp", this);
new StateDependentCommand(ArenaMode.Prepare, FightState.PostSchemSetup, "tpslimit", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
double tps;
try {
tps = Double.parseDouble(args[0]);
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
FightSystem.getMessage().send("TPSWARP_HELP", sender);
return false;
}
TPSWarpUtils.warp(tps);
FightSystem.getMessage().broadcastActionbar("TPSWARP_SET", tps);
return false;
}
}
@@ -0,0 +1,49 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2022 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.commands;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCommand;
import de.steamwar.fightsystem.utils.FightStatistics;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class UnrankCommand implements CommandExecutor {
public UnrankCommand () {
new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "unrank", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player))
return false;
Player player = (Player) sender;
if(Commands.checkGetLeader(player) == null)
return false;
FightStatistics.unrank();
return false;
}
}
@@ -0,0 +1,45 @@
/*
* 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.commands;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class WGCommand implements CommandExecutor {
public WGCommand() {
new StateDependentCommand(ArenaMode.Check, FightState.All, "resetwg", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) {
return false;
}
Fight.getBlueTeam().pasteSchem();
return false;
}
}
@@ -0,0 +1,52 @@
package de.steamwar.fightsystem.commands;
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.StateDependentCommand;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class WinCommand implements CommandExecutor {
public WinCommand() {
new StateDependentCommand(ArenaMode.Event, FightState.Ingame, "win", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) {
return false;
}
Player p = (Player) sender;
if (!Config.isReferee(p)) {
FightSystem.getMessage().sendPrefixless("NOT_FIGHTLEADER", p, ChatMessageType.ACTION_BAR);
return false;
}
if(args.length == 0){
FightSystem.getMessage().sendPrefixless("WIN_HELP", p);
return false;
}
if(args[0].equalsIgnoreCase("tie")){
FightSystem.setSpectateState(null, "Referee", "WIN_FIGHTLEADER");
return false;
}
for(FightTeam team : Fight.teams()) {
if(args[0].equalsIgnoreCase(team.getName())){
FightSystem.setSpectateState(team, "Referee", "WIN_FIGHTLEADER");
return false;
}
}
return false;
}
}
@@ -0,0 +1,138 @@
/*
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.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.record.GlobalRecorder;
import de.steamwar.fightsystem.utils.FightUI;
import de.steamwar.fightsystem.utils.Message;
import de.steamwar.fightsystem.utils.SWSound;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
import java.util.ArrayList;
import java.util.List;
public abstract class Countdown {
private static final List<Countdown> currentCountdowns = new ArrayList<>();
protected final Message appendix;
private final int totalTime;
protected final Sound sound;
private final boolean level;
protected int time;
private BukkitTask task = null;
public abstract void countdownFinished();
protected Countdown(int time, Message appendix, SWSound sound, boolean level) {
this.totalTime = time;
this.time = time;
this.appendix = appendix;
this.sound = sound != null ? sound.getSound() : null;
this.level = level;
}
public void enable() {
time = totalTime;
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::count, 20, 20);
currentCountdowns.add(this);
show();
}
public void disable() {
if(task != null){
task.cancel();
currentCountdowns.remove(this);
task = null;
}
}
public static void skip(){
if(currentCountdowns.isEmpty())
return;
int smallestTime = currentCountdowns.get(0).time;
for(Countdown countdown : currentCountdowns){
if(countdown.time < smallestTime)
smallestTime = countdown.time;
}
for(Countdown countdown : new ArrayList<>(currentCountdowns)) {
countdown.time -= smallestTime;
countdown.show();
}
FightUI.addSubtitle("UI_SKIP");
}
public static void sendCountdownMessage(Player p, String message, int displaytime, Message appendix) {
FightSystem.getMessage().sendPrefixless(message, p, ChatMessageType.ACTION_BAR, displaytime, FightSystem.getMessage().parse(appendix.getMsg(), p, appendix.getParams()));
}
protected void broadcast(String message, int divisor){
if(this.sound != null && divisor == 1)
Fight.playSound(this.sound, 100.0F, 1.0F);
GlobalRecorder.getInstance().countdown(message, time / divisor, appendix);
Bukkit.getOnlinePlayers().forEach(p -> sendCountdownMessage(p, message, time / divisor, appendix));
}
public int getTimeLeft(){
return time;
}
private void count() {
time--;
show();
}
private void show(){
switch (time) {
case 900: case 600: case 300: case 180: case 120:
broadcast("COUNTDOWN_MINUTES", 60);
break;
case 60: case 30: case 20: case 15: case 10: case 5: case 4: case 3: case 2:
broadcast("COUNTDOWN_SECONDS", 1);
break;
case 1:
broadcast("COUNTDOWN_SECOND", 1);
break;
case 0:
if(this.sound != null)
Fight.playSound(this.sound, 100.0F, 2.0F);
disable();
countdownFinished();
break;
default:
}
if(this.level)
Bukkit.getServer().getOnlinePlayers().forEach(player -> player.setLevel(time));
}
}
@@ -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.countdown;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.events.BoardingEvent;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.utils.Message;
import de.steamwar.fightsystem.utils.Region;
import de.steamwar.fightsystem.utils.SWSound;
import de.steamwar.techhider.ProtocolUtils;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Bukkit;
import java.util.List;
public class EnternCountdown extends Countdown {
private static int calcTime(FightPlayer fp, Countdown countdown) {
int time = Config.EnterStages.get(fp.getKit().getEnterStage());
if(countdown != null) {
time -= Config.TimeoutTime - countdown.getTimeLeft();
if(time < 0)
time = 0;
}
return time;
}
private final FightPlayer fightPlayer;
private List<ProtocolUtils.ChunkPos> chunkPos;
public EnternCountdown(FightPlayer fp, Countdown countdown) {
super(calcTime(fp, countdown), new Message("ENTERN_COUNTDOWN"), SWSound.BLOCK_NOTE_PLING, false);
fightPlayer = fp;
enable();
}
@Override
public void countdownFinished() {
Bukkit.getPluginManager().callEvent(new BoardingEvent(fightPlayer));
FightSystem.getMessage().sendPrefixless("ENTERN_ALLOWED", fightPlayer.getEntity(), ChatMessageType.ACTION_BAR);
fightPlayer.ifPlayer(player -> {
FightSystem.getHullHider().updatePlayer(player);
FightSystem.getTechHider().reloadChunks(player, Fight.getOpposite(fightPlayer.getTeam()).getExtendRegion(), Region.EMPTY);
});
}
@Override
protected void broadcast(String message, int divisor) {
fightPlayer.ifPlayer(player -> {
player.playSound(player.getLocation(), sound, 100.0f, 1.0f);
sendCountdownMessage(player, message, time / divisor, appendix);
});
}
}
@@ -0,0 +1,41 @@
/*
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;
import de.steamwar.fightsystem.utils.Message;
import de.steamwar.fightsystem.utils.SWSound;
public class EventSpectateCountdown extends Countdown {
public EventSpectateCountdown() {
super(Config.SpectatorDuration, new Message("SHUTDOWN_COUNTDOWN"), SWSound.BLOCK_NOTE_PLING, false);
new StateDependentCountdown(ArenaMode.NotRestartable.contains(Config.mode) && !Config.replayserver(), FightState.Spectate, this);
}
@Override
public void countdownFinished() {
FightSystem.shutdown();
}
}
@@ -0,0 +1,42 @@
/*
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.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCountdown;
import de.steamwar.fightsystem.utils.Message;
import org.bukkit.Bukkit;
public class NoPlayersOnlineCountdown extends Countdown {
public NoPlayersOnlineCountdown() {
super(Config.NoPlayerOnlineDuration, new Message("SHUTDOWN_COUNTDOWN"), null, false);
if (!Config.ArenaLeaveable)
new StateDependentCountdown(ArenaMode.AntiReplay, FightState.PreLeaderSetup, this);
}
@Override
public void countdownFinished() {
Bukkit.getServer().shutdown();
}
}
@@ -0,0 +1,42 @@
/*
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.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCountdown;
import de.steamwar.fightsystem.utils.Message;
public class PostSchemCountdown extends Countdown {
public PostSchemCountdown() {
super(Config.SetupDuration, new Message("POST_SCHEM_COUNTDOWN"), null, false);
if(Config.mode == ArenaMode.PREPARE && Config.UnlimitedPrepare)
return;
new StateDependentCountdown(ArenaMode.SeriousFight, FightState.PostSchemSetup, this);
}
@Override
public void countdownFinished() {
FightState.setFightState(FightState.PRE_RUNNING);
}
}
@@ -0,0 +1,40 @@
/*
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.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCountdown;
import de.steamwar.fightsystem.utils.Message;
import de.steamwar.fightsystem.utils.SWSound;
public class PreRunningCountdown extends Countdown {
public PreRunningCountdown() {
super(Config.PreFightDuration, new Message("PRE_RUNNING_COUNTDOWN"), SWSound.BLOCK_NOTE_PLING, true);
new StateDependentCountdown(ArenaMode.AntiReplay, FightState.PreRunning, this);
}
@Override
public void countdownFinished() {
FightState.setFightState(FightState.RUNNING);
}
}
@@ -0,0 +1,40 @@
/*
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.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCountdown;
import de.steamwar.fightsystem.utils.Message;
import de.steamwar.fightsystem.utils.SWSound;
public class PreSchemCountdown extends Countdown {
public PreSchemCountdown() {
super(Config.PreSchemPasteDuration, new Message("PRE_SCHEM_COUNTDOWN"), SWSound.BLOCK_NOTE_PLING, false);
new StateDependentCountdown(ArenaMode.AntiReplay, FightState.PreSchemSetup, this);
}
@Override
public void countdownFinished() {
FightState.setFightState(FightState.POST_SCHEM_SETUP);
}
}
@@ -0,0 +1,40 @@
/*
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.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCountdown;
import de.steamwar.fightsystem.utils.Message;
import de.steamwar.fightsystem.utils.SWSound;
public class SpectateOverCountdown extends Countdown {
public SpectateOverCountdown() {
super(Config.test() ? 3600 : Config.SpectatorDuration, new Message("SPECTATE_COUNTDOWN"), SWSound.BLOCK_NOTE_PLING, false);
new StateDependentCountdown(ArenaMode.Restartable.contains(Config.mode) || Config.replayserver(), FightState.Spectate, this);
}
@Override
public void countdownFinished() {
FightState.setFightState(FightState.PRE_LEADER_SETUP);
}
}
@@ -0,0 +1,39 @@
/*
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.Config;
import de.steamwar.fightsystem.utils.Message;
import de.steamwar.fightsystem.utils.SWSound;
public class TimeOverCountdown extends Countdown {
private final Runnable timeOver;
public TimeOverCountdown(Runnable timeOver) {
super(Config.TimeoutTime, new Message("RUNNING_COUNTDOWN"), SWSound.BLOCK_NOTE_BASS, false);
this.timeOver = timeOver;
}
@Override
public void countdownFinished() {
timeOver.run();
}
}
@@ -0,0 +1,242 @@
/*
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.event;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.Countdown;
import de.steamwar.fightsystem.record.GlobalRecorder;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent;
import de.steamwar.fightsystem.utils.Message;
import de.steamwar.fightsystem.utils.SWSound;
import de.steamwar.fightsystem.winconditions.Winconditions;
import org.bukkit.Bukkit;
import org.bukkit.entity.EntityType;
import org.bukkit.scheduler.BukkitTask;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
public class HellsBells {
public static final Random random = new Random();
private final int xLength = Config.BlueExtendRegion.getSizeX();
private final int zLength = Config.BlueExtendRegion.getSizeZ();
private State current = State.PRE;
private int currentDrops = 0;
private HellsBellsCountdown currentCountdown;
private BukkitTask currentDropping;
private final List<String> startMessages = Arrays.asList("HELLS_BELLS_START_1", "HELLS_BELLS_START_2",
"HELLS_BELLS_START_3", "HELLS_BELLS_START_4", "HELLS_BELLS_START_5", "HELLS_BELLS_START_6");
private final List<String> stateSwapMessages = Arrays.asList("HELLS_BELLS_SWAP_1", "HELLS_BELLS_SWAP_2",
"HELLS_BELLS_SWAP_3", "HELLS_BELLS_SWAP_4");
public void startCountdown() {
if (current == HellsBells.State.PRE || current == HellsBells.State.FIRST) {
String startMessage = startMessages.get(random.nextInt(startMessages.size()));
GlobalRecorder.getInstance().system(startMessage);
FightSystem.getMessage().broadcast(startMessage);
current = current.getNext();
} else if (current != HellsBells.State.LAST && currentDrops >= current.SWITCH_AFTER) {
String stateSwapMessage = stateSwapMessages.get(random.nextInt(stateSwapMessages.size()));
GlobalRecorder.getInstance().system(stateSwapMessage);
FightSystem.getMessage().broadcast(stateSwapMessage);
currentDrops = 0;
current = current.getNext();
}
currentDrops++;
currentCountdown = new HellsBellsCountdown(current.MIN_TIME + random.nextInt(current.MAX_TIME - current.MIN_TIME));
currentCountdown.enable();
}
public void drop() {
Direction direction = Direction.getRandom();
AtomicInteger length = new AtomicInteger(20 + random.nextInt(direction.getLength(zLength, xLength) - 20));
int width = 5 + random.nextInt(5);
int xOffset = getStart(direction.getLength(xLength, zLength), direction.getLength(length.get(), width));
int zOffset = getStart(direction.getLength(zLength, xLength), direction.getLength(width, length.get()));
int yOffset = getHeightStart();
Point redStart;
Point blueStart;
if (direction.isNorthOrWest()) {
redStart = new Point(Config.RedExtendRegion.getMaxX() - xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedExtendRegion.getMaxZ() - zOffset);
blueStart = new Point(Config.BlueExtendRegion.getMinX() + xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BlueExtendRegion.getMinZ() + zOffset);
} else {
redStart = new Point(Config.RedExtendRegion.getMinX() + xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedExtendRegion.getMinZ() + zOffset);
blueStart = new Point(Config.BlueExtendRegion.getMaxX() - xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BlueExtendRegion.getMaxZ() - zOffset);
}
currentDropping = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), () -> {
for (int w = 0; w < width; w++) {
if (direction.isNorthOrWest()) {
Config.world.spawnEntity(redStart.addAndToLocation(Config.world, -1 * (direction.dx * length.get() + w * direction.other().dx), 0, -1 * (direction.dz * length.get() + w * direction.other().dz)), EntityType.PRIMED_TNT);
Config.world.spawnEntity(blueStart.addAndToLocation(Config.world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT);
} else {
Config.world.spawnEntity(redStart.addAndToLocation(Config.world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT);
Config.world.spawnEntity(blueStart.addAndToLocation(Config.world, -1 * (direction.dx * length.get() + w * direction.other().dx), 0, -1 * (direction.dz * length.get() + w * direction.other().dz)), EntityType.PRIMED_TNT);
}
}
if (length.addAndGet(-2) <= 0) {
currentDropping.cancel();
}
}, 0L, 4L);
}
private int getStart(int regionSize, int length) {
double randomNumber = (Math.max(Math.min(random.nextGaussian(), -2), 2) + 2) / 4;
Bukkit.getLogger().log(Level.INFO, "Calculated Start: " + (int) (randomNumber * (regionSize - length)));
return Math.max(Math.min((int) (randomNumber * (regionSize - length)), regionSize - length), 0);
}
private int getHeightStart() {
return 5 + random.nextInt(15);
}
public HellsBells() {
new StateDependent(Winconditions.HELLS_BELLS, FightState.Running) {
@Override
public void enable() {
current = State.PRE;
currentDrops = 0;
startCountdown();
}
@Override
public void disable() {
currentCountdown.disable();
}
}.register();
}
private class HellsBellsCountdown extends Countdown {
public HellsBellsCountdown(int time) {
super(time, new Message("HELLS_BELLS_COUNTDOWN"), SWSound.BLOCK_NOTE_BASS, true);
}
@Override
public void countdownFinished() {
drop();
startCountdown();
}
}
private enum State {
PRE(60, 80, 1),
FIRST(40, 60, 3),
SECOND(30, 40, 4),
THIRD(20, 30, 4),
FOURTH(10, 20, 5),
LAST(5, 10, 0);
State(int minTime, int maxTime, int switchAfter) {
this.MIN_TIME = minTime;
this.MAX_TIME = maxTime;
this.SWITCH_AFTER = switchAfter;
}
private final int MIN_TIME; //NOSONAR
private final int MAX_TIME; //NOSONAR
private final int SWITCH_AFTER; //NOSONAR
public State getNext() {
switch (this) {
case PRE:
return FIRST;
case FIRST:
return SECOND;
case SECOND:
return THIRD;
case THIRD:
return FOURTH;
case FOURTH:
case LAST:
return LAST;
default:
return PRE;
}
}
}
private enum Direction {
NORTH(0, 0, 1),
SOUTH(0, 0, -1),
EAST(1, 0, 0),
WEST(-1, 0, 0);
int dx;
int dy;
int dz;
Direction(int dx, int dy, int dz) {
this.dx = dx;
this.dy = dy;
this.dz = dz;
}
public static Direction getRandom() {
return Direction.values()[random.nextInt(Direction.values().length)];
}
Direction other() {
switch (this) {
case NORTH:
return EAST;
case SOUTH:
return WEST;
case EAST:
return NORTH;
case WEST:
return SOUTH;
default:
return this;
}
}
public int getLength(int length1, int length2) {
return isNorthOrSouth() ? length1 : length2;
}
public boolean isNorthOrSouth() {
return this == NORTH || this == SOUTH;
}
public boolean isNorthOrWest() {
return this == NORTH || this == WEST;
}
}
}
@@ -0,0 +1,216 @@
/*
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.event;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.Countdown;
import de.steamwar.fightsystem.record.GlobalRecorder;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.utils.Message;
import de.steamwar.fightsystem.utils.SWSound;
import de.steamwar.fightsystem.winconditions.Winconditions;
import org.bukkit.Bukkit;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.LargeFireball;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
public class Meteor implements Listener {
public static final Random random = new Random();
private final Vector vector = new Vector(0, -1, 0);
private final int xLength = Config.RedExtendRegion.getMaxX() - Config.RedExtendRegion.getMinX();
private final int zLength = Config.RedExtendRegion.getMaxZ() - Config.RedExtendRegion.getMinZ();
private Meteor.State current = Meteor.State.PRE;
private int currentDrops = 0;
private Meteor.MeteorCountdown currentCountdown;
private final AtomicInteger amount = new AtomicInteger(0);
private BukkitTask currentDropping;
private final List<String> startMessages = Arrays.asList("METEOR_START_1", "METEOR_START_2", "METEOR_START_3", "METEOR_START_4", "METEOR_START_5", "METEOR_START_6");
private final List<String> stateSwapMessages = Arrays.asList("METEOR_SWAP_1", "METEOR_SWAP_2", "METEOR_SWAP_3", "METEOR_SWAP_4");
public void startCountdown() {
if (current == Meteor.State.PRE || current == Meteor.State.FIRST) {
String startMessage = startMessages.get(random.nextInt(startMessages.size()));
GlobalRecorder.getInstance().system(startMessage);
FightSystem.getMessage().broadcast(startMessage);
current = current.getNext();
} else if (current != Meteor.State.LAST && currentDrops >= current.SWITCH_AFTER) {
String stateSwapMessage = stateSwapMessages.get(random.nextInt(stateSwapMessages.size()));
GlobalRecorder.getInstance().system(stateSwapMessage);
FightSystem.getMessage().broadcast(stateSwapMessage);
currentDrops = 0;
current = current.getNext();
}
currentDrops++;
currentCountdown = new Meteor.MeteorCountdown(current.MIN_TIME + random.nextInt(current.MAX_TIME - current.MIN_TIME));
currentCountdown.enable();
}
//@EventHandler
public void explode(ProjectileHitEvent event) {
if (event.getEntity() instanceof Fireball) {
TNTPrimed tnt = Config.world.spawn(event.getEntity().getLocation(), TNTPrimed.class);
tnt.setVelocity(new Vector(0, 0, 0));
tnt.setFuseTicks(0);
tnt.setYield(((Fireball) event.getEntity()).getYield());
event.getEntity().remove();
}
}
public void drop() {
int randomAmount = current.minAmount + random.nextInt(current.maxAmount - current.minAmount);
if (amount.get() > 0) {
amount.set(amount.get() + randomAmount);
return;
}
amount.set(randomAmount);
currentDropping = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), () -> {
int xOffset = getStart(xLength);
int zOffset = getStart(zLength);
int yOffset = getHeightStart();
Point redStart = new Point(Config.RedExtendRegion.getMinX() + xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedExtendRegion.getMaxZ() - zOffset);
Point blueStart = new Point(Config.BlueExtendRegion.getMinX() + xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BlueExtendRegion.getMinZ() + zOffset);
vector.setX(random.nextDouble() - 0.5);
vector.setZ(random.nextDouble() - 0.5);
LargeFireball fireballRed = Config.world.spawn(redStart.toLocation(Config.world), LargeFireball.class);
fireballRed.setDirection(vector);
fireballRed.setBounce(false);
fireballRed.setIsIncendiary(false);
fireballRed.setYield(current.explosionSize);
LargeFireball fireballBlue = Config.world.spawn(blueStart.toLocation(Config.world), LargeFireball.class);
vector.setZ(vector.getZ() * -1);
fireballBlue.setDirection(vector);
fireballBlue.setBounce(false);
fireballBlue.setIsIncendiary(false);
fireballBlue.setYield(current.explosionSize);
if (amount.decrementAndGet() <= 0) {
currentDropping.cancel();
}
}, 0L, 4L);
}
private int getStart(int regionSize) {
double randomNumber = (random.nextDouble() - random.nextDouble()) / 2 + 0.5;
Bukkit.getLogger().log(Level.INFO, "Calculated Start: " + (int) (randomNumber * (regionSize - 1)));
return Math.max(Math.min((int) (randomNumber * (regionSize - 1)), regionSize - 1), 0);
}
private int getHeightStart() {
return 5 + random.nextInt(15);
}
public Meteor() {
new StateDependentListener(Winconditions.METEOR, FightState.Running, this);
new StateDependent(Winconditions.METEOR, FightState.Running) {
@Override
public void enable() {
startCountdown();
}
@Override
public void disable() {
currentCountdown.disable();
}
}.register();
}
private class MeteorCountdown extends Countdown {
public MeteorCountdown(int time) {
super(time, new Message("METEOR_COUNTDOWN"), SWSound.BLOCK_NOTE_BASS, true);
}
@Override
public void countdownFinished() {
drop();
startCountdown();
}
}
private enum State {
PRE(60, 80, 1, 0, 0, 0),
FIRST(25, 35, 6, 2, 3, 6),
SECOND(20, 30, 7, 4, 4, 8),
THIRD(15, 25, 7, 4, 5, 10),
FOURTH(10, 20, 8, 6, 7, 14),
LAST(5, 10, 0, 6, 9, 18);
State(int minTime, int maxTime, int switchAfter, int explosionSize, int minAmount, int maxAmount) {
this.MIN_TIME = minTime;
this.MAX_TIME = maxTime;
this.SWITCH_AFTER = switchAfter;
this.explosionSize = explosionSize;
this.minAmount = minAmount;
this.maxAmount = maxAmount;
}
private final int MIN_TIME; //NOSONAR
private final int MAX_TIME; //NOSONAR
private final int SWITCH_AFTER; //NOSONAR
private final int explosionSize; //NOSONAR
private final int minAmount;
private final int maxAmount;
public Meteor.State getNext() {
switch (this) {
case PRE:
return FIRST;
case FIRST:
return SECOND;
case SECOND:
return THIRD;
case THIRD:
return FOURTH;
case FOURTH:
case LAST:
return LAST;
default:
return PRE;
}
}
}
}
@@ -0,0 +1,49 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 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.event;
import com.sk89q.worldedit.WorldEditException;
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.states.FightState;
import de.steamwar.fightsystem.states.OneShotStateDependent;
import de.steamwar.fightsystem.utils.WorldeditWrapper;
import de.steamwar.fightsystem.winconditions.Winconditions;
import de.steamwar.sql.SchematicNode;
import java.util.logging.Level;
public class PersistentDamage {
public PersistentDamage() {
if(!ArenaMode.SeriousFight.contains(Config.mode))
return;
new OneShotStateDependent(Winconditions.PERSISTENT_DAMAGE, FightState.Spectate, () -> Fight.teams().forEach(team -> {
try{
WorldeditWrapper.impl.saveSchem(SchematicNode.getSchematicNode(team.getSchematic()), team.getExtendRegion(), team.getSchemRegion().getMinY());
}catch(WorldEditException e){
FightSystem.getPlugin().getLogger().log(Level.SEVERE, "Could not persist schematic state", e);
}
}));
}
}
@@ -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.event;
import org.bukkit.Location;
import org.bukkit.World;
class Point {
private final int x;
private final int y;
private final int z;
public Point(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public Location toLocation(World world) {
return new Location(world, this.x, this.y, this.z); //NOSONAR
}
public Location addAndToLocation(World world, int x, int y, int z) {
return new Location(world, this.x + x, this.y + y, this.z + z); //NOSONAR
}
}
@@ -0,0 +1,39 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 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.event;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentTask;
import de.steamwar.fightsystem.winconditions.Winconditions;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
public class TNTDistributor {
public TNTDistributor() {
new StateDependentTask(Winconditions.TNT_DISTRIBUTION, FightState.Running, () -> Fight.teams().forEach(team -> team.getPlayers().forEach(fp -> {
if(!fp.isLiving())
return;
fp.ifPlayer(player -> player.getInventory().addItem(new ItemStack(Material.TNT, 20)));
})), 300, 300);
}
}
@@ -0,0 +1,40 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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.events;
import de.steamwar.fightsystem.fight.FightPlayer;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
@Getter
@AllArgsConstructor
public class BoardingEvent extends Event {
@Getter
private static final HandlerList handlerList = new HandlerList();
private final FightPlayer fightPlayer;
@Override
public HandlerList getHandlers() {
return handlerList;
}
}
@@ -0,0 +1,40 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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.events;
import de.steamwar.fightsystem.fight.FightPlayer;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
@Getter
@AllArgsConstructor
public class TeamDeathEvent extends Event {
@Getter
private static final HandlerList handlerList = new HandlerList();
private final FightPlayer fightPlayer;
@Override
public HandlerList getHandlers() {
return handlerList;
}
}
@@ -0,0 +1,40 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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.events;
import de.steamwar.fightsystem.fight.FightPlayer;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
@Getter
@AllArgsConstructor
public class TeamLeaveEvent extends Event {
@Getter
private static final HandlerList handlerList = new HandlerList();
private final FightPlayer fightPlayer;
@Override
public HandlerList getHandlers() {
return handlerList;
}
}
@@ -0,0 +1,40 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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.events;
import de.steamwar.fightsystem.fight.FightPlayer;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
@Getter
@AllArgsConstructor
public class TeamSpawnEvent extends Event {
@Getter
private static final HandlerList handlerList = new HandlerList();
private final FightPlayer fightPlayer;
@Override
public HandlerList getHandlers() {
return handlerList;
}
}
@@ -0,0 +1,153 @@
/*
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.fight;
import com.comphenix.tinyprotocol.TinyProtocol;
import com.mojang.authlib.GameProfile;
import de.steamwar.core.Core;
import de.steamwar.core.ProtocolWrapper;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.record.GlobalRecorder;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Sound;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import java.util.Collection;
import java.util.HashSet;
public class Fight {
private Fight(){}
@Getter
private static final FightTeam redTeam = new FightTeam(Config.TeamRedName, Config.TeamRedColor, Config.TeamRedSpawn, Config.RedPasteRegion, Config.RedExtendRegion, Config.RedRotate, false, Config.RedLeader);
@Getter
private static final FightTeam blueTeam = new FightTeam(Config.TeamBlueName, Config.TeamBlueColor, Config.TeamBlueSpawn, Config.BluePasteRegion, Config.BlueExtendRegion, Config.BlueRotate, true, Config.BlueLeader);
private static final Collection<FightTeam> teams = new HashSet<>();
static {
teams.add(redTeam);
teams.add(blueTeam);
}
public static FightTeam getPlayerTeam(LivingEntity player) {
if(redTeam.isPlayerInTeam(player))
return redTeam;
if(blueTeam.isPlayerInTeam(player))
return blueTeam;
return null;
}
public static FightTeam getOpposite(FightTeam fightTeam) {
if(fightTeam == redTeam)
return blueTeam;
else if(fightTeam == blueTeam)
return redTeam;
throw new IllegalArgumentException();
}
public static FightPlayer getFightPlayer(LivingEntity player) {
if(redTeam.isPlayerInTeam(player))
return redTeam.getFightPlayer(player);
if(blueTeam.isPlayerInTeam(player))
return blueTeam.getFightPlayer(player);
return null;
}
public static boolean fighting(LivingEntity player) {
return getPlayerTeam(player) != null;
}
public static Collection<FightTeam> teams() {
return teams;
}
public static FightTeam getUnrotated() {
return Config.blueNegZ() ? Fight.getBlueTeam() : Fight.getRedTeam();
}
public static void playSound(Sound sound, float volume, float pitch) {
GlobalRecorder.getInstance().soundAtPlayer(sound.name(), volume, pitch);
//volume: max. 100, pitch: max. 2
if(Core.getVersion() >= 18)
Bukkit.getServer().getOnlinePlayers().forEach(player -> player.playSound(player, sound, volume, pitch));
else
Bukkit.getServer().getOnlinePlayers().forEach(player -> player.playSound(player.getLocation(), sound, volume, pitch));
}
public static FightTeam getTeamByName(String name) {
if(redTeam.getName().equalsIgnoreCase(name))
return redTeam;
if(blueTeam.getName().equalsIgnoreCase(name))
return blueTeam;
return null;
}
@SuppressWarnings("deprecation")
public static void setPlayerGamemode(Player player, GameMode gameMode) {
player.setGameMode(gameMode);
if(gameMode == GameMode.SPECTATOR) {
for(Player currentPlayer : Bukkit.getServer().getOnlinePlayers()) {
if(currentPlayer.getUniqueId() != player.getUniqueId() && currentPlayer.getGameMode() == GameMode.SPECTATOR) {
currentPlayer.hidePlayer(player);
player.hidePlayer(currentPlayer);
}
}
if(Config.test() || Config.isReferee(player))
return;
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> {
if(!player.isOnline())
return;
pseudoSpectator(player, true);
}, 1);
}else if(gameMode == GameMode.SURVIVAL) {
for(Player currentPlayer : Bukkit.getServer().getOnlinePlayers()) {
if(currentPlayer.getUniqueId() != player.getUniqueId() && currentPlayer.getGameMode() == GameMode.SPECTATOR) {
currentPlayer.showPlayer(player);
player.showPlayer(currentPlayer);
}
}
}
}
public static void pseudoSpectator(Player player, boolean enable) {
TinyProtocol.instance.sendPacket(player, ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.GAMEMODE, new GameProfile(player.getUniqueId(), player.getName()), enable ? GameMode.CREATIVE : GameMode.SPECTATOR));
}
public static boolean publicOnly() {
if (Config.OnlyPublicSchematics) {
return true;
}
if (Config.IgnorePublicOnly || ArenaMode.RankedEvent.contains(Config.mode)) {
return false;
}
if (redTeam.getLeader() == null || blueTeam.getLeader() == null) {
return false;
}
return redTeam.isPublicsOnly() || blueTeam.isPublicsOnly();
}
}
@@ -0,0 +1,131 @@
/*
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.fight;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.ai.AI;
import de.steamwar.fightsystem.countdown.Countdown;
import de.steamwar.fightsystem.countdown.EnternCountdown;
import de.steamwar.fightsystem.events.TeamDeathEvent;
import de.steamwar.sql.PersonalKit;
import de.steamwar.sql.SteamwarUser;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import java.util.function.Consumer;
public class FightPlayer {
private final int id;
private LivingEntity entity;
@Getter
private final FightTeam team;
private boolean isOut;
@Setter
@Getter
private Kit kit;
@Getter
private int kills;
private EnternCountdown enternCountdown = null;
FightPlayer(LivingEntity entity, SteamwarUser user, FightTeam team) {
this.id = user.getId();
this.entity = entity;
this.team = team;
this.isOut = false;
kit = Kit.getKitByName(Config.MemberDefault);
if(Config.PersonalKits){
PersonalKit personalKit = PersonalKit.getKitInUse(user.getId(), Config.SchematicType.toDB());
if(personalKit != null){
kit = new Kit(personalKit);
}
}
kills = 0;
}
public void revive() {
isOut = false;
}
public void setOut() {
isOut = true;
Bukkit.getPluginManager().callEvent(new TeamDeathEvent(this));
stopEnternCountdown();
ifAI(AI::stop);
}
public void startEnternCountdown(Countdown countdown) {
if(Config.EnterStages.size() > kit.getEnterStage() && kit.getEnterStage() >= 0)
enternCountdown = new EnternCountdown(this, countdown);
}
public void stopEnternCountdown(){
if(enternCountdown != null){
enternCountdown.disable();
}
enternCountdown = null;
}
public LivingEntity getEntity() {
LivingEntity bukkit = Bukkit.getPlayer(entity.getUniqueId());
if(bukkit != null)
entity = bukkit;
return entity;
}
public SteamwarUser getUser() {
return SteamwarUser.get(id);
}
public void ifAI(Consumer<AI> function) {
if(entity instanceof Player)
return;
AI ai = AI.getAI(entity.getUniqueId());
if(ai != null)
function.accept(ai);
}
public void ifPlayer(Consumer<Player> function) {
if(entity instanceof Player)
function.accept((Player) entity);
}
public boolean isLiving() {
return !this.isOut;
}
public boolean isLeader() {
FightPlayer leader = team.getLeader();
return leader != null && leader.getEntity() == entity;
}
public void addKill(){
kills++;
}
public boolean canEntern(){
if(enternCountdown == null)
return false;
return enternCountdown.getTimeLeft() == 0;
}
}
@@ -0,0 +1,217 @@
/*
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.fight;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.math.transform.AffineTransform;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.record.GlobalRecorder;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent;
import de.steamwar.fightsystem.utils.ColorConverter;
import de.steamwar.fightsystem.utils.Region;
import de.steamwar.fightsystem.utils.WorldeditWrapper;
import de.steamwar.sql.SchematicData;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SchematicType;
import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.util.Vector;
import java.io.IOException;
import java.util.List;
import java.util.Random;
import java.util.logging.Level;
public class FightSchematic extends StateDependent {
private final FightTeam team;
private final Region region;
private final boolean rotate;
private Clipboard clipboard = null;
private int schematic = 0;
public FightSchematic(FightTeam team, boolean rotate) {
super(ArenaMode.All, FightState.PostSchemSetup);
this.team = team;
this.region = team.getSchemRegion();
this.rotate = rotate;
register();
}
public boolean hasSchematic() {
return clipboard != null;
}
public int getId(){
return schematic;
}
public void setSchematic(SchematicNode schem) {
schematic = schem.getId();
try {
clipboard = new SchematicData(schem).load();
if(schem.replaceColor())
replaceTeamColor(clipboard);
} catch (IOException e) {
team.broadcastSystem("SCHEMATIC_UNLOADABLE");
Bukkit.getLogger().log(Level.SEVERE, e, () -> "Couldn't load Schematic " + schem.getName());
}
}
public void setSchematic(int schemId, Clipboard clipboard) {
this.schematic = schemId;
this.clipboard = clipboard;
}
public void reset(){
schematic = 0;
clipboard = null;
}
@Override
public void enable() {
if(FightState.getFightState() == FightState.SPECTATE)
return;
if(clipboard == null){
List<SchematicNode> publics = SchematicNode.getAllSchematicsOfType(0, Config.SchematicType.toDB());
if(publics.isEmpty()) {
for (SchematicType type : Config.SubTypes) {
publics = SchematicNode.getAllSchematicsOfType(0, type.toDB());
if (!publics.isEmpty()) {
break;
}
}
if (publics.isEmpty()) {
return;
}
}
setSchematic(publics.get(new Random().nextInt(publics.size())));
}
if(ArenaMode.AntiReplay.contains(Config.mode)) {
if(team.isBlue())
GlobalRecorder.getInstance().blueSchem(schematic);
else
GlobalRecorder.getInstance().redSchem(schematic);
}
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::paste);
}
private void replaceTeamColor(Clipboard clipboard) {
try {
WorldeditWrapper.impl.replaceTeamColor(clipboard, ArenaMode.AntiPrepare.contains(Config.mode) ? ColorConverter.chat2dye(team.getColor()) : DyeColor.PINK);
} catch (WorldEditException e) {
Bukkit.getLogger().log(Level.SEVERE, "Could not recolor schematic", e);
}
}
private void paste(){
FreezeWorld freezer = new FreezeWorld();
Vector dims = WorldeditWrapper.impl.getDimensions(clipboard);
WorldeditWrapper.impl.pasteClipboard(
clipboard,
new Location(Config.world, region.centerX(), region.getMinY(), region.centerZ()),
new Vector(
Config.PasteAligned && Config.BlueToRedX != 0 ? region.getSizeX()/2.0 - dims.getBlockX() : -dims.getBlockX()/2.0,
Config.WaterDepth != 0 ? Config.WaterDepth - WorldeditWrapper.impl.getWaterDepth(clipboard) : 0,
Config.PasteAligned && Config.BlueToRedZ != 0 ? region.getSizeZ()/2.0 - dims.getBlockZ() : -dims.getBlockZ()/2.0
).add(new Vector(rotate ? 1 : 0, 0, rotate ? 1 : 0)),
new AffineTransform().rotateY(rotate ? 180 : 0)
);
FightSystem.getHullHider().initialize(team);
if(ArenaMode.Check.contains(Config.mode) && !team.isBlue())
replaceSync(Material.TNT, Material.OBSIDIAN);
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), freezer::disable, 3);
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), team::teleportToSpawn, 40);
}
@Override
public void disable() {
if(!Config.ReplaceObsidianBedrock || Config.mode == ArenaMode.PREPARE)
return;
FreezeWorld freezer = null;
if(!Config.ReplaceWithBlockupdates)
freezer = new FreezeWorld();
replaceSync(Material.OBSIDIAN, Material.TNT);
replaceSync(Material.BEDROCK, Material.SLIME_BLOCK);
if(!Config.ReplaceWithBlockupdates)
freezer.disable();
}
public void pasteTeamName(){
char[] chars = team.getName().toCharArray();
Clipboard[] characters = new Clipboard[chars.length];
int length = 0;
int[] offsets = new int[chars.length];
for(int i = 0; i < chars.length; i++){
Clipboard character;
try {
character = WorldeditWrapper.impl.loadChar(chars[i] == '/' ? "slash" : String.valueOf(chars[i]));
} catch (IOException e) {
Bukkit.getLogger().log(Level.WARNING, "Could not display character {} due to missing file!", chars[i]);
try {
character = WorldeditWrapper.impl.loadChar("");
}catch (IOException ex) {
throw new SecurityException("Could not load text", ex);
}
}
replaceTeamColor(character);
characters[i] = character;
offsets[i] = length;
length += WorldeditWrapper.impl.getDimensions(character).getBlockX() + 1; // 1 is the distance between characters
}
length -= 1;
AffineTransform aT = new AffineTransform().rotateY(((team == Fight.getRedTeam()) == (Config.BlueToRedZ > 0)) ? 180 : 0);
Location base = new Location(Config.world, region.centerX(), team.getExtendRegion().getMaxY(), region.centerZ());
for(int i = 0; i < characters.length; i++){
WorldeditWrapper.impl.pasteClipboard(characters[i], base, new Vector(offsets[i] - length/2, 0, -region.getSizeZ()/2), aT);
}
}
private void replaceSync(Material target, Material replacement){
region.forEach((x, y, z) -> {
Block block = Config.world.getBlockAt(x, y, z);
if(block.getType() == target)
block.setType(replacement);
});
}
}
@@ -0,0 +1,520 @@
/*
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.fight;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.commands.GUI;
import de.steamwar.fightsystem.countdown.Countdown;
import de.steamwar.fightsystem.events.TeamLeaveEvent;
import de.steamwar.fightsystem.events.TeamSpawnEvent;
import de.steamwar.fightsystem.listener.FightScoreboard;
import de.steamwar.fightsystem.listener.Permanent;
import de.steamwar.fightsystem.listener.PersonalKitCreator;
import de.steamwar.fightsystem.listener.TeamArea;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.OneShotStateDependent;
import de.steamwar.fightsystem.states.StateDependent;
import de.steamwar.fightsystem.utils.*;
import de.steamwar.fightsystem.winconditions.Wincondition;
import de.steamwar.fightsystem.winconditions.Winconditions;
import de.steamwar.inventory.SWItem;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser;
import lombok.Getter;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.*;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.NameTagVisibility;
import org.bukkit.scoreboard.Team;
import java.util.*;
import java.util.function.Consumer;
public class FightTeam {
private static void setKitButton(HotbarKit kit, boolean leader) {
if (Kit.getAvailableKits(leader).size() > 1 || Config.PersonalKits)
kit.setItem(1, "CHOOSE_KIT", new ItemBuilder(Material.LEATHER_CHESTPLATE).enchant().build(), player -> GUI.kitSelection(player, ""));
else
kit.setItem(1, null, null, null);
}
private static final HotbarKit memberKit = new HotbarKit();
static {
setKitButton(memberKit, false);
memberKit.setItem(7, "RESPAWN", new ItemBuilder(Material.BEACON).build(), player -> player.teleport(Objects.requireNonNull(Fight.getPlayerTeam(player)).getSpawn()));
}
private static final HotbarKit notReadyKit = new HotbarKit(memberKit);
static {
setKitButton(notReadyKit, true);
if(!ArenaMode.RankedEvent.contains(Config.mode)){
notReadyKit.setItem(2, "REQUESTS", new ItemBuilder(Material.PAPER).build(), GUI::chooseJoinRequests);
notReadyKit.setItem(3, "REMOVE_PLAYERS", new ItemBuilder(SWItem.getMaterial("FIREWORK_CHARGE")).build(), GUI::chooseRemove);
}
if(Config.test())
notReadyKit.setItem(5, "CHOOSE_SCHEMATIC", new ItemBuilder(SWItem.getMaterial("CAULDRON_ITEM")).enchant().build(), GUI::preSchemDialog);
notReadyKit.setItem(4, "TEAM_NOT_READY", new ItemBuilder(SWItem.getDye(10), (short) 10).enchant().build(), player -> Objects.requireNonNull(Fight.getPlayerTeam(player)).setReady(true));
}
private static final HotbarKit chooseSchemKit = new HotbarKit(notReadyKit);
static {
chooseSchemKit.setItem(4, "CHOOSE_SCHEMATIC", new ItemBuilder(SWItem.getMaterial("CAULDRON_ITEM")).enchant().build(), GUI::preSchemDialog);
}
private static final HotbarKit readyKit = new HotbarKit(memberKit);
static {
readyKit.setItem(1, null, null, null);
readyKit.setItem(4, "TEAM_READY", new ItemBuilder(SWItem.getDye(8), (short) 8).enchant().build(), player -> Objects.requireNonNull(Fight.getPlayerTeam(player)).setReady(false));
}
@Getter
private UUID designatedLeader;
@Getter
private FightPlayer leader;
@Getter
private boolean publicsOnly;
private final Map<UUID, FightPlayer> players = new HashMap<>();
@Getter
private String name;
@Getter
private String prefix;
@Getter
private ChatColor color;
private final FightSchematic schematic;
private final Team team;
@Getter
private final boolean blue;
@Getter
private boolean ready;
private boolean skip;
@Getter
private final Location spawn;
@Getter
private final Region schemRegion;
@Getter
private final Region extendRegion;
@SuppressWarnings("deprecation")
public FightTeam(String name, String prefix, Location spawn, Region schemRegion, Region extendRegion, boolean rotate, boolean blue, UUID designatedLeader) { //TODO: Static TeamConfig object
this.spawn = spawn;
this.schemRegion = schemRegion;
this.extendRegion = extendRegion;
this.publicsOnly = false;
this.ready = false;
this.skip = false;
this.blue = blue;
this.designatedLeader = designatedLeader;
setPrefixAndName(prefix, name);
this.schematic = new FightSchematic(this, rotate);
new KitLoader();
new SpectateHandler();
new TeamArea(this);
team = FightScoreboard.getBukkitTeam(name);
WorldOfColorWrapper.impl.setTeamColor(team, color);
BountifulWrapper.impl.setNametagVisibility(team);
team.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OTHER_TEAMS);
if (!Config.ActiveWinconditions.contains(Winconditions.AMONG_US)) {
team.setAllowFriendlyFire(false);
}
new OneShotStateDependent(ArenaMode.Restartable, FightState.PreLeaderSetup, () -> Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::reset));
new OneShotStateDependent(Config.replayserver(), FightState.PreLeaderSetup, () -> Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::reset));
new OneShotStateDependent(ArenaMode.All, FightState.PostSchemSetup, () -> {
if(leader != null)
leader.ifPlayer(notReadyKit::loadToPlayer);
});
}
public void setPrefixAndName(String prefix, String name){
this.name = name;
this.prefix = prefix;
this.color = ChatColor.getByChar(ChatColor.getLastColors(prefix).replace("§", ""));
}
public boolean canbeLeader(Player p){
return isLeaderless() && (designatedLeader == null || designatedLeader.equals(p.getUniqueId()));
}
public void teleportToSpawn(){
players.forEach((player, fp) -> fp.getEntity().teleport(spawn));
}
public FightPlayer getFightPlayer(LivingEntity player) {
return players.get(player.getUniqueId());
}
public boolean allPlayersOut() {
for(FightPlayer fightPlayer : players.values()) {
if(fightPlayer.isLiving())
return false;
}
return true;
}
public boolean isPlayerInTeam(LivingEntity player) {
return players.containsKey(player.getUniqueId());
}
public boolean canPlayerEntern(LivingEntity player) {
return getFightPlayer(player).canEntern();
}
public boolean isPlayerLeader(LivingEntity player) {
if(leader != null)
return leader.getEntity().equals(player);
else
return false;
}
public void reset() {
skip = false;
ready = false;
schematic.reset();
Set<UUID> playerSet = new HashSet<>(players.keySet());
playerSet.removeIf(uuid -> {
Player player = Bukkit.getPlayer(uuid);
if(player == null) {
removePlayer(players.get(uuid).getEntity());
return true;
}
return false;
});
FightPlayer leaderBackup = leader;
players.clear();
leader = null;
if(leaderBackup != null){
playerSet.remove(leaderBackup.getEntity().getUniqueId());
addMember(leaderBackup.getEntity(), leaderBackup.getUser(), true);
}
playerSet.forEach(uuid -> addMember(Bukkit.getPlayer(uuid), SteamwarUser.get(uuid), true));
if(ArenaMode.VariableTeams.contains(Config.mode) && isLeaderless()){
List<Player> onlinePlayers = new ArrayList<>(Bukkit.getOnlinePlayers());
Collections.shuffle(onlinePlayers);
for(Player player : onlinePlayers) {
if(Fight.getPlayerTeam(player) == null && canbeLeader(player)){
addMember(player);
break;
}
}
}
}
public void broadcast(String message, Object... params) {
broadcast(player -> FightSystem.getMessage().sendPrefixless(message, player, ChatMessageType.ACTION_BAR, params));
}
public void broadcastSystem(String message, Object... params) {
broadcast(player -> FightSystem.getMessage().send(message, player, params));
}
public void broadcastChat(Player sender, String message) {
broadcast(player -> FightSystem.getMessage().sendPrefixless("TEAM_CHAT", player, ChatMessageType.CHAT, prefix, sender.getName(), message));
}
private void broadcast(Consumer<Player> f) {
players.forEach((uuid, fightPlayer) -> {
Player player = Bukkit.getPlayer(uuid);
if(player != null)
f.accept(player);
});
}
public void addMember(Player player) {
addMember(player, SteamwarUser.get(player.getUniqueId()), false);
}
public void addMember(LivingEntity entity, SteamwarUser user) {
addMember(entity, user, false);
}
public void addMember(LivingEntity entity, SteamwarUser user, boolean silent) {
FightPlayer fightPlayer = getFightPlayer(entity) != null ? getFightPlayer(entity) : new FightPlayer(entity, user, this);
fightPlayer.revive();
players.put(entity.getUniqueId(), fightPlayer);
Bukkit.getPluginManager().callEvent(new TeamSpawnEvent(fightPlayer));
Permanent.getSpectatorTeam().removeEntry(entity.getName());
team.addEntry(entity.getName());
entity.setHealth(20);
entity.teleport(spawn);
fightPlayer.ifPlayer(player -> {
BountifulWrapper.impl.setAttackSpeed(player);
player.setFoodLevel(20);
player.getInventory().clear();
FightSystem.getHullHider().updatePlayer(player);
if(FightState.Spectate.contains(FightState.getFightState())) {
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
} else {
Fight.setPlayerGamemode(player, GameMode.SURVIVAL);
(FightState.ingame() ? fightPlayer.getKit() : memberKit).loadToPlayer(player);
}
});
if(FightState.Running.contains(FightState.getFightState()))
fightPlayer.startEnternCountdown(Wincondition.getTimeOverCountdown());
fightPlayer.ifPlayer(player -> FightSystem.getTechHider().reloadChunks(player, Config.ArenaRegion, fightPlayer.canEntern() ? Region.EMPTY : Fight.getOpposite(this).getExtendRegion()));
if(isLeaderless())
setLeader(fightPlayer, silent);
else if(!silent)
FightUI.addSubtitle("UI_PLAYER_JOINS", prefix, entity.getName());
}
public void removePlayer(LivingEntity entity) {
FightPlayer fightPlayer = getFightPlayer(entity);
Bukkit.getPluginManager().callEvent(new TeamLeaveEvent(fightPlayer));
fightPlayer.ifPlayer(PersonalKitCreator::closeIfInKitCreator);
players.remove(entity.getUniqueId());
team.removeEntry(entity.getName());
Permanent.getSpectatorTeam().addEntry(entity.getName());
FightUI.addSubtitle("UI_PLAYER_LEAVES", prefix, entity.getName());
if(fightPlayer.equals(leader))
removeLeader();
entity.teleport(Config.SpecSpawn);
fightPlayer.ifPlayer(player -> {
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
player.getInventory().clear();
if(player.isOnline()){
FightSystem.getHullHider().updatePlayer(player);
FightSystem.getTechHider().reloadChunks(player, Config.ArenaRegion, Fight.getOpposite(this).getExtendRegion());
if(ArenaMode.VariableTeams.contains(Config.mode))
HotbarKit.SPECTATOR_KIT.loadToPlayer(player);
}
});
}
public boolean isLeaderless() {
return leader == null;
}
private void removeLeader() {
this.leader = null;
if(!players.isEmpty()) {
setLeader(players.values().iterator().next(), false);
}else if(FightState.getFightState() != FightState.PRE_LEADER_SETUP && !ArenaMode.RankedEvent.contains(Config.mode)){
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> FightState.setFightState(FightState.PRE_LEADER_SETUP), 1);
}
}
private void setLeader(FightPlayer leader, boolean silent) {
leader.ifPlayer(PersonalKitCreator::closeIfInKitCreator);
this.leader = leader;
designatedLeader = null;
if(ready)
setReady(false);
if(!silent)
FightUI.addSubtitle("UI_LEADER_JOINS", prefix, leader.getEntity().getName());
publicsOnly = SchematicNode.getAllAccessibleSchematicsOfType(leader.getUser().getId(), Config.SchematicType.toDB()).isEmpty();
if(!Config.PersonalKits)
leader.setKit(Kit.getKitByName(Config.LeaderDefault));
leader.ifPlayer(player -> {
if(FightState.getFightState() != FightState.POST_SCHEM_SETUP)
chooseSchemKit.loadToPlayer(player);
else
notReadyKit.loadToPlayer(player);
});
if(FightState.getFightState() == FightState.PRE_LEADER_SETUP && !Fight.getOpposite(this).isLeaderless()){
FightState.setFightState(FightState.PRE_SCHEM_SETUP);
}
leader.ifAI(ai -> pasteSchem(ai.chooseSchematic()));
}
public Collection<FightPlayer> getPlayers() {
return players.values();
}
public void pasteSchem() {
testPasteAction();
}
public void pasteSchem(SchematicNode schematic){
if(schematic.getSchemtype().check()) {
FightStatistics.unrank();
FightSystem.getMessage().broadcast("SCHEMATIC_UNCHECKED", getColoredName());
}
setSchem(schematic);
testPasteAction();
}
public void pasteSchem(int schemId, Clipboard clipboard){
this.schematic.setSchematic(schemId, clipboard);
testPasteAction();
}
private void testPasteAction(){
if(Config.test())
this.schematic.enable();
else if(Fight.getOpposite(this).schematic.hasSchematic()){
FightState.setFightState(FightState.POST_SCHEM_SETUP);
}
}
public void pasteTeamName(){
schematic.pasteTeamName();
}
public void setSchem(SchematicNode schematic){
this.schematic.setSchematic(schematic);
broadcast("SCHEMATIC_CHOSEN", Config.GameName, schematic.getName());
}
public void setReady(boolean ready) {
LivingEntity l = leader.getEntity();
if(!schematic.hasSchematic()){
FightSystem.getMessage().sendPrefixless("SCHEMATIC_REQUIRED", l, ChatMessageType.ACTION_BAR);
return;
}
this.ready = ready;
if(ready) {
broadcast("TEAM_READY");
leader.ifPlayer(readyKit::loadToPlayer);
if(Fight.getOpposite(this).isReady() || ArenaMode.SoloLeader.contains(Config.mode))
FightState.setFightState(FightState.PRE_RUNNING);
} else {
broadcast("TEAM_NOT_READY");
leader.ifPlayer(notReadyKit::loadToPlayer);
}
}
public void skip(){
this.skip = !skip;
if(skip){
broadcast("SKIP_READY");
if(Fight.getOpposite(this).skip || Config.test()){
skip = false;
Fight.getOpposite(this).skip = false;
Countdown.skip();
}
}else{
broadcast("SKIP_NOT_READY");
}
}
public String getColoredName() {
return prefix + name;
}
public int getSchematic() {
return schematic.getId();
}
public double getCurrentHearts() {
return players.values().stream().filter(FightPlayer::isLiving).mapToDouble(fp -> fp.getEntity().getHealth()).sum();
}
public double getHeartRatio(){
int maximumHearts = players.size() * 20;
return maximumHearts != 0 ? getCurrentHearts() / maximumHearts : 0;
}
public int getPlayerCount() {
return players.size();
}
public int getAlivePlayers() {
return (int) players.values().stream().filter(FightPlayer::isLiving).count();
}
@Override
public String toString() {
return name;
}
private class KitLoader extends StateDependent {
private KitLoader() {
super(ArenaMode.AntiReplay, FightState.Ingame);
register();
}
@Override
public void enable() {
for(FightPlayer fightPlayer : players.values()) {
fightPlayer.ifPlayer(player -> {
PersonalKitCreator.closeIfInKitCreator(player);
player.closeInventory();
fightPlayer.getKit().loadToPlayer(player);
});
}
}
@Override
public void disable() {
players.values().forEach(fightPlayer -> fightPlayer.ifPlayer(p -> p.getInventory().clear()));
}
}
private class SpectateHandler extends StateDependent {
private SpectateHandler() {
super(ArenaMode.AntiReplay, FightState.Spectate);
register();
}
@Override
public void enable() {
players.values().forEach(fightPlayer -> {
fightPlayer.ifPlayer(player -> Fight.setPlayerGamemode(player, GameMode.SPECTATOR));
fightPlayer.getEntity().teleport(FightTeam.this.spawn);
});
}
@Override
public void disable() {
players.values().forEach(fightPlayer -> fightPlayer.ifPlayer(player -> Fight.setPlayerGamemode(player, GameMode.SURVIVAL)));
}
}
}
@@ -0,0 +1,88 @@
/*
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.fight;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.listener.Recording;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent;
import de.steamwar.fightsystem.utils.CraftbukkitWrapper;
import de.steamwar.fightsystem.utils.FlatteningWrapper;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class FightWorld extends StateDependent {
@Getter
private static final boolean PAPER = Bukkit.getVersion().contains("git-Paper");
public FightWorld() {
super(ArenaMode.Restartable.contains(Config.mode) || Config.replayserver(), FightState.Schem);
register();
}
@Override
public void enable() {
//unused
}
@Override
public void disable() {
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), FightWorld::resetWorld); //Delay to prevent raceconditions with techhider and hullhider
}
public static void forceLoad(){
Config.ArenaRegion.forEachChunk((cX, cZ) -> {
Config.world.loadChunk(cX, cZ);
FlatteningWrapper.impl.forceLoadChunk(Config.world, cX, cZ);
});
}
public static void resetWorld(){
List<Entity> entities = new ArrayList<>();
Recording.iterateOverEntities(Objects::nonNull, entity -> {
if(entity.getType() != EntityType.PLAYER && (!Config.ArenaLeaveable || Config.ArenaRegion.inRegion(entity.getLocation())))
entities.add(entity);
});
entities.forEach(Entity::remove);
entities.clear();
World backup = new WorldCreator(Config.world.getName() + "/backup").createWorld();
assert backup != null;
Config.ArenaRegion.forEachChunk((x, z) -> {
CraftbukkitWrapper.impl.resetChunk(Config.world, backup, x, z);
for(Player p : Bukkit.getOnlinePlayers()) {
de.steamwar.core.CraftbukkitWrapper.impl.sendChunk(p, x, z);
}
});
Bukkit.unloadWorld(backup, false);
}
}
@@ -0,0 +1,96 @@
/*
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.fight;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.utils.BountifulWrapper;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.*;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
public class FreezeWorld implements Listener {
private final Listener denyHandSwap = BountifulWrapper.impl.newDenyHandSwapListener();
public FreezeWorld(){
Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin());
Bukkit.getPluginManager().registerEvents(denyHandSwap, FightSystem.getPlugin());
}
public void disable(){
HandlerList.unregisterAll(this);
HandlerList.unregisterAll(denyHandSwap);
}
@EventHandler
public void onBlockPhysicsEvent(BlockPhysicsEvent e){
e.setCancelled(true);
}
@EventHandler
public void onPistonExtend(BlockPistonExtendEvent e){
e.setCancelled(true);
}
@EventHandler
public void onPistonRetract(BlockPistonRetractEvent e){
e.setCancelled(true);
}
@EventHandler
public void onBlockGrow(BlockGrowEvent e){
e.setCancelled(true);
}
@EventHandler
public void onRedstoneEvent(BlockRedstoneEvent e){
e.setNewCurrent(e.getOldCurrent());
}
@EventHandler
public void onBlockDispense(BlockDispenseEvent e){
e.setCancelled(true);
}
@EventHandler
public void onInventoryMoveEvent(InventoryMoveItemEvent e){
e.setCancelled(true);
}
@EventHandler
public void onBlockExplosion(BlockExplodeEvent e){
e.setCancelled(true);
}
@EventHandler
public void onBlockExplosion(ItemSpawnEvent e){
e.setCancelled(true);
}
@EventHandler(priority = EventPriority.LOW)
public void handlePlayerInteract(PlayerInteractEvent event) {
event.setCancelled(true);
}
}
@@ -0,0 +1,121 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2022 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.fight;
import de.steamwar.core.Core;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.commands.GUI;
import de.steamwar.fightsystem.listener.PersonalKitCreator;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.states.StateDependentTask;
import de.steamwar.fightsystem.utils.ItemBuilder;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect;
import java.util.Collection;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;
public class HotbarKit extends Kit {
public static final HotbarKit SPECTATOR_KIT = new HotbarKit();
static {
for(int i = 0; i < 9; i++)
SPECTATOR_KIT.setItem(i, "JOIN_REQUEST", new ItemBuilder(Material.PAPER).build(), GUI::joinRequest);
}
private static final int HOTBAR_SIZE = 9;
private final String[] nameTags;
private final Consumer<Player>[] onClicks;
protected HotbarKit(String name, ItemStack[] inventory, ItemStack[] armor, Collection<PotionEffect> effects, String[] nameTags, Consumer<Player>[] onClicks) {
super(name, inventory, armor, effects);
this.nameTags = nameTags;
this.onClicks = onClicks;
}
public HotbarKit() {
this(null, new ItemStack[HOTBAR_SIZE], null, null, new String[HOTBAR_SIZE], new Consumer[HOTBAR_SIZE]);
}
public HotbarKit(HotbarKit kit) {
this(kit.getName(), kit.getInventory().clone(), kit.getArmor() != null ? kit.getArmor().clone() : null, kit.getEffects(), kit.nameTags.clone(), kit.onClicks.clone());
}
public void setItem(int id, String nameTag, ItemStack stack, Consumer<Player> onClick) {
super.setItem(id, stack);
nameTags[id] = nameTag;
onClicks[id] = onClick;
}
@Override
public synchronized void loadToPlayer(Player player) {
for(int i = 0; i < HOTBAR_SIZE; i++) {
if(nameTags[i] != null) {
ItemMeta meta = Objects.requireNonNull(getInventory()[i].getItemMeta());
meta.setDisplayName(FightSystem.getMessage().parse(nameTags[i], player, Config.GameName));
getInventory()[i].setItemMeta(meta);
}
}
super.loadToPlayer(player);
}
public static class HotbarKitListener implements Listener {
private static final Set<Player> clicked = new HashSet<>();
public HotbarKitListener() {
new StateDependentListener(ArenaMode.AntiReplay, FightState.All, this);
new StateDependentTask(ArenaMode.AntiReplay, FightState.All, clicked::clear, 10, 10);
}
@EventHandler
public void handlePlayerInteract(PlayerInteractEvent event) {
if(event.getAction() == Action.PHYSICAL || (Core.getVersion() > 8 && event.getHand() != EquipmentSlot.HAND))
return;
Player player = event.getPlayer();
int slot = player.getInventory().getHeldItemSlot();
Kit activeKit = activeKits.get(player);
if(!(activeKit instanceof HotbarKit) || PersonalKitCreator.inKitCreator(player) || activeKit.getInventory()[slot] == null)
return;
event.setCancelled(true);
if(!clicked.add(player))
return;
((HotbarKit)activeKit).onClicks[slot].accept(player);
}
}
}
@@ -0,0 +1,110 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2022 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.fight;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.ClickEvent;
import org.bukkit.entity.Player;
import java.util.*;
import java.util.stream.Collectors;
public class JoinRequest {
private static final Map<Player, JoinRequest> activeRequests = new HashMap<>();
public static List<SWListInv.SWListEntry<Player>> openRequests(Player p, FightTeam team) {
return activeRequests.values().stream().filter(
request -> request.waitOnApproval.contains(team)
).map(request -> {
SWItem item = SWItem.getPlayerSkull(request.player);
item.setLore(Arrays.asList(
FightSystem.getMessage().parse("REQUESTS_LEFT_CLICK", p),
FightSystem.getMessage().parse("REQUESTS_RIGHT_CLICK", p)
));
return new SWListInv.SWListEntry<>(item, request.player);
}).collect(Collectors.toList());
}
public static void clearRequests() {
activeRequests.clear();
}
public static JoinRequest get(Player player) {
return activeRequests.get(player);
}
private final Player player;
private final FightTeam team;
private final Set<FightTeam> waitOnApproval;
public JoinRequest(Player player, FightTeam team) {
this.player = player;
this.team = team;
this.waitOnApproval = new HashSet<>(FightState.ingame() ? Fight.teams() : Collections.singleton(team));
Set<FightTeam> alreadyAccepted = new HashSet<>();
activeRequests.put(player, this);
for(FightTeam t : waitOnApproval) {
FightPlayer leader = t.getLeader();
if(leader == null)
continue;
if(leader.getEntity() == null)
continue;
leader.ifPlayer(leaderPlayer -> FightSystem.getMessage().sendPrefixless("JOIN_REQUEST_NOTIFICATION", leaderPlayer, "REQUESTS", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/requests"), player.getName(), team.getColoredName()));
leader.ifAI(ai -> {
if(ai.acceptJoinRequest(player, team))
alreadyAccepted.add(t);
});
}
FightSystem.getMessage().sendPrefixless("JOIN_REQUEST_CONFIRMATION", player, ChatMessageType.ACTION_BAR);
alreadyAccepted.forEach(this::accept);
}
public boolean required(FightTeam decider) {
return waitOnApproval.contains(decider);
}
public void accept(FightTeam acceptor) {
waitOnApproval.remove(acceptor);
if(waitOnApproval.isEmpty()) {
team.addMember(player);
activeRequests.remove(player);
}
}
public void decline(FightTeam declinor) {
FightSystem.getMessage().sendPrefixless("REQUEST_YOUR_DECLINED", player, ChatMessageType.ACTION_BAR);
waitOnApproval.forEach(t -> t.broadcast("REQUEST_DECLINED", player.getName()));
silentDecline();
}
public void silentDecline() {
activeRequests.remove(player);
}
}
@@ -0,0 +1,368 @@
/*
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.fight;
import com.comphenix.tinyprotocol.Reflection;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.commands.Commands;
import de.steamwar.fightsystem.commands.GUI;
import de.steamwar.fightsystem.listener.PersonalKitCreator;
import de.steamwar.fightsystem.utils.FlatteningWrapper;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import de.steamwar.sql.PersonalKit;
import de.steamwar.sql.SteamwarUser;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.logging.Level;
public class Kit {
private static final File kits = new File(FightSystem.getPlugin().getDataFolder(), Config.KitFile);
private static final ArrayList<Kit> loadedKits = new ArrayList<>();
protected static final Map<Player, Kit> activeKits = new HashMap<>();
public static Kit getActiveKit(Player player) {
return activeKits.get(player);
}
static {
if(!kits.exists()) {
Bukkit.getLogger().log(Level.SEVERE, "Kitconfig fehlend!" + kits.getAbsolutePath());
}
FileConfiguration kitData = YamlConfiguration.loadConfiguration(kits);
ConfigurationSection kitSection = kitData.getConfigurationSection("Kits");
for(String key : Objects.requireNonNull(kitSection).getKeys(false)) {
loadedKits.add(new Kit(Objects.requireNonNull(kitSection.getConfigurationSection(key))));
}
}
@Getter
private final String name;
@Getter
private final ItemStack[] inventory;
@Getter
private final ItemStack[] armor;
@Getter
private final Collection<PotionEffect> effects;
/* In which stage is entern allowed? */
@Getter
private final int enterStage;
/* Is this kit allowed to set/handle tnt? */
@Getter
private final boolean tnt;
private final boolean leaderAllowed;
private final boolean memberAllowed;
protected Kit(String name, ItemStack[] inventory, ItemStack[] armor, Collection<PotionEffect> effects) {
this.name = name;
this.inventory = inventory;
this.armor = armor;
this.effects = effects;
this.leaderAllowed = true;
this.memberAllowed = true;
this.enterStage = 0;
this.tnt = true;
}
protected Kit(Kit kit) {
this(kit.name, kit.inventory.clone(), kit.armor, kit.effects);
}
public Kit(String name, Player player) {
this(name, player.getInventory().getContents(), player.getInventory().getArmorContents(), player.getActivePotionEffects());
}
public Kit(PersonalKit kit){
this(kit.getName(), kit.getInventory(), kit.getArmor(), Collections.emptyList());
}
public Kit(ConfigurationSection kit){
name = kit.getName();
inventory = Objects.requireNonNull(kit.getList("Items")).toArray(new ItemStack[0]);
if(kit.isList("Armor"))
armor = Objects.requireNonNull(kit.getList("Armor")).toArray(new ItemStack[0]);
else
armor = null;
leaderAllowed = kit.getBoolean("LeaderAllowed");
memberAllowed = kit.getBoolean("MemberAllowed");
if(kit.isList("Effects"))
effects = (List<PotionEffect>) kit.getList("Effects");
else
effects = null;
enterStage = kit.getInt("EnterStage", 0);
tnt = kit.getBoolean("TNT", true);
}
protected void setItem(int id, ItemStack stack) {
inventory[id] = stack;
}
public static Kit getKitByName(String kitName) {
for(Kit kit : loadedKits) {
if(kit.getName().equalsIgnoreCase(kitName))
return kit;
}
return null;
}
public static List<Kit> getAvailableKits(boolean leader){
List<Kit> kits = new ArrayList<>();
for (Kit k : loadedKits) {
if (k.canUseKit(leader)){
kits.add(k);
}
}
return kits;
}
public boolean canUseKit(boolean leader){
if (leader) {
return leaderAllowed;
} else {
return memberAllowed;
}
}
public boolean leaderExclusive() {
return !memberAllowed;
}
public boolean contains(ItemStack stack) {
for(ItemStack i : inventory) {
if(similar(i, stack))
return true;
}
for(ItemStack i : armor) {
if(similar(i, stack))
return true;
}
return false;
}
public void toPersonalKit(PersonalKit kit) {
kit.setContainer(inventory, armor);
}
public void removeBadItems(){
Kit normal = Kit.getKitByName(Config.MemberDefault);
assert normal != null;
for(int i = 0; i < inventory.length; i++){
if(isBadItem(inventory[i]))
inventory[i] = null;
}
}
public static boolean isBadItem(ItemStack stack){
if(stack == null)
return false;
//Check for forbidden item
if(Config.ForbiddenItems.contains(stack.getType()))
return true;
//Check for attribute modifiers
if(FlatteningWrapper.impl.hasAttributeModifier(stack)){
return true;
}
if(stack.hasItemMeta()){
ItemMeta meta = stack.getItemMeta();
if(FlatteningWrapper.impl.containsBlockMeta(meta))
return true; //Blocks always upwards slabs etc.
if(hasItems(stack))
return true; //Blocks prefilled inventories
}
Kit normal = Kit.getKitByName(Config.MemberDefault);
assert normal != null;
return !normal.isEnchantmentInKit(stack) && !stack.getEnchantments().isEmpty();
}
private static final Class<?> itemStack = Reflection.getClass("{nms.world.item}.ItemStack");
private static final Reflection.MethodInvoker asNMSCopy = Reflection.getTypedMethod(Reflection.getClass("{obc}.inventory.CraftItemStack"), "asNMSCopy", itemStack, ItemStack.class);
private static final Class<?> nbtTagCompound = Reflection.getClass("{nms.nbt}.NBTTagCompound");
private static final Reflection.MethodInvoker getTag = Reflection.getTypedMethod(itemStack, null, nbtTagCompound);
private static final Reflection.MethodInvoker getKeys = Reflection.getTypedMethod(nbtTagCompound, null, Set.class);
public static boolean hasItems(ItemStack stack) {
Set<String> keys = new HashSet<>((Set<String>) getKeys.invoke(getTag.invoke(asNMSCopy.invoke(null, stack))));
keys.remove("Enchantments");
keys.remove("Damage");
return !keys.isEmpty();
}
private boolean isEnchantmentInKit(ItemStack stack){
for(ItemStack is : inventory){
if(similar(stack, is))
return true;
}
if(armor != null){
for(ItemStack is : armor){
if(similar(stack, is))
return true;
}
}
return false;
}
private boolean similar(ItemStack stack, ItemStack stack2){
if(stack == null || stack2 == null)
return false;
if(stack.getType() != stack2.getType())
return false;
if(stack.hasItemMeta() != stack2.hasItemMeta())
return false;
if(stack.getItemMeta() == null || stack2.getItemMeta() == null)
return true;
//Enchantment Map comparison used for default similarity check does not work
Map<Enchantment, Integer> en = stack.getItemMeta().getEnchants();
Map<Enchantment, Integer> en2 = new HashMap<>(stack.getItemMeta().getEnchants());
for(Map.Entry<Enchantment, Integer> e : en.entrySet()){
if(!en2.remove(e.getKey(), e.getValue()))
return false;
}
return en2.isEmpty();
}
public void loadToPlayer(Player player) {
activeKits.put(player, this);
player.getInventory().clear();
player.getInventory().setContents(inventory);
if(armor != null)
player.getInventory().setArmorContents(armor);
player.updateInventory();
if(effects != null)
player.addPotionEffects(effects);
}
/**
* Opens a kit preview with the options to go back to kit selection or to select the kit.
*/
public void preview(Player player){
SWInventory inv = new SWInventory(player, 54, name);
//36 = Inventargröße
for(int i = 0; i < 36; i++){
if(inventory[i] == null)
continue;
SWItem item = new SWItem();
item.setItemStack(inventory[i]);
inv.setItem(i, item);
}
if(armor != null){
for(int i = 0; i < 4; i++){
if(armor[i] == null)
continue;
SWItem item = new SWItem();
item.setItemStack(armor[i]);
inv.setItem(36 + i, item);
}
}
if(effects != null){
Iterator<PotionEffect> it = effects.iterator();
int pos = 44;
while(it.hasNext()){
PotionEffect effect = it.next();
SWItem item = new SWItem(SWItem.getMaterial("POTION"), effect.getType().getName());
inv.setItem(pos, item);
pos--;
}
}
inv.setCallback(-999, click -> player.closeInventory());
if(Config.PersonalKits){
inv.setItem(49, SWItem.getMaterial("WOOD_AXE"), FightSystem.getMessage().parse("KIT_PREVIEW_EDIT", player), clickType -> PersonalKitCreator.openKitCreator(player, PersonalKit.get(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB(), name)));
inv.setItem(53, Material.BARRIER, FightSystem.getMessage().parse("KIT_PREVIEW_DELETE", player), clickType -> {
player.closeInventory();
SWInventory conf = new SWInventory(player, 9, FightSystem.getMessage().parse("KIT_DELETION_CONFIRMATION", player));
conf.setItem(8, SWItem.getDye(1), FightSystem.getMessage().parse("KIT_DELETION_ABORT", player), click -> player.closeInventory());
conf.setItem(0, SWItem.getDye(10), FightSystem.getMessage().parse("KIT_DELETION_DELETE", player), click -> {
player.closeInventory();
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
PersonalKit kit = PersonalKit.get(user.getId(), Config.SchematicType.toDB(), name);
if(kit.isInUse()) {
List<PersonalKit> kits = PersonalKit.get(user.getId(), Config.SchematicType.toDB());
if(!kits.isEmpty()){
PersonalKit kit1 = kits.get(0);
kit1.setInUse();
FightPlayer fightPlayer = Fight.getFightPlayer(player);
assert fightPlayer != null;
fightPlayer.setKit(new Kit(kit1));
}
}
kit.delete();
});
conf.open();
});
}
inv.setItem(45, SWItem.getDye(10), (byte)10, FightSystem.getMessage().parse("KIT_PREVIEW_CHOOSE", player), click -> {
Commands.kit(player, name);
player.closeInventory();
});
inv.setItem(53, SWItem.getDye(1), (byte)1, FightSystem.getMessage().parse("KIT_PREVIEW_BACK", player), click -> GUI.kitSelection(player, ""));
inv.open();
}
public static void createKit(String kitName, Player player){
loadedKits.add(new Kit(kitName, player));
YamlConfiguration yamlConfiguration = new YamlConfiguration();
for(Kit k : loadedKits){
ConfigurationSection section = yamlConfiguration.createSection("Kits." + k.getName());
section.set("Items", k.inventory);
if(k.armor != null)
section.set("Armor", k.armor);
section.set("LeaderAllowed", k.leaderAllowed);
section.set("MemberAllowed", k.memberAllowed);
section.set("Effects", k.effects);
section.set("EnterStage", k.enterStage);
section.set("TNT", k.tnt);
}
try {
yamlConfiguration.save(kits);
}catch(IOException e){
throw new SecurityException("Failed to save kits.data", e);
}
}
}
@@ -0,0 +1,108 @@
/*
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.events.TeamDeathEvent;
import de.steamwar.fightsystem.events.TeamLeaveEvent;
import de.steamwar.fightsystem.events.TeamSpawnEvent;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.states.StateDependentTask;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class ArenaBorder implements Listener {
private final Border spectatorBorder = new Border(Config.PlayerRegion, true, 5, "NO_ARENA_LEAVING", "ArenaBorder.spectatorBorder");
private final Border playerBorder = new Border(Config.PlayerRegion.to2d(), true, 5, "NO_ARENA_LEAVING", "ArenaBorder.playerBorder");
public ArenaBorder() {
new StateDependentListener(ArenaMode.All, FightState.All, this);
new StateDependentTask(ArenaMode.All, FightState.Running, this::damage, 2, 2);
new StateDependentListener(!Config.GroundWalkable, FightState.AntiRunning, new Listener() {
@EventHandler
public void onMove(PlayerMoveEvent e) {
Player player = e.getPlayer();
if(e.getTo().getY() <= Config.PlayerRegion.getMinY() && playerBorder.contains(player))
player.teleport(Fight.getPlayerTeam(player).getSpawn());
}
});
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
addToSpectator(e.getPlayer());
}
@EventHandler
public void onTeamJoin(TeamSpawnEvent e) {
e.getFightPlayer().ifPlayer(player -> {
spectatorBorder.removePlayer(player);
playerBorder.addPlayer(player);
});
}
@EventHandler
public void onTeamDeath(TeamDeathEvent e) {
e.getFightPlayer().ifPlayer(player -> {
playerBorder.removePlayer(player);
addToSpectator(player);
});
}
@EventHandler
public void onTeamLeave(TeamLeaveEvent e) {
e.getFightPlayer().ifPlayer(player -> {
playerBorder.removePlayer(player);
addToSpectator(player);
});
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent e) {
spectatorBorder.removePlayer(e.getPlayer());
}
private void damage() {
Fight.teams().forEach(team -> {
for(FightPlayer fp : team.getPlayers()) {
LivingEntity entity = fp.getEntity();
if(fp.isLiving() && entity.getLocation().getY() <= Config.PlayerRegion.getMinY())
entity.damage(1);
}
});
}
private void addToSpectator(Player player) {
if(Config.ArenaLeaveable || !player.isOnline() || playerBorder.contains(player))
return;
spectatorBorder.addPlayer(player);
}
}
@@ -0,0 +1,100 @@
/*
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.fightsystem.listener;
import com.comphenix.tinyprotocol.Reflection;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentTask;
import de.steamwar.fightsystem.utils.WorldOfColorWrapper;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.Vector;
public class ArrowStopper {
private static final Vector NULL_VECTOR = new Vector(0, 0, 0);
private static final BlockFace[] BLOCK_FACES = {BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH};
public ArrowStopper() {
new StateDependentTask(Config.TechhiderActive, FightState.Running, this::run, 1, 1);
}
private static final Class<?> entityArrow = Reflection.getClass("{nms.world.entity.projectile}.EntityArrow");
private void run() {
Recording.iterateOverEntities(entityArrow::isInstance, entity -> {
Projectile arrow = (Projectile) entity;
if (invalidEntity(arrow))
return;
Location prevLocation = arrow.getLocation().toVector().subtract(arrow.getVelocity()).toLocation(arrow.getWorld());
if (arrow.getTicksLived() == 0){
ProjectileSource projSource = arrow.getShooter();
if(projSource instanceof Player)
prevLocation = ((Player) arrow.getShooter()).getEyeLocation();
else
return;
}
if (checkBlocks(arrow.getLocation().getBlock(), prevLocation.getBlock())) {
arrow.remove();
}
});
}
private boolean checkBlocks(Block start, Block end) {
Block cursor = start;
while (!cursor.getLocation().equals(end.getLocation())) {
BlockFace nearest = BlockFace.SELF;
double nearestDistance = cursor.getLocation().distance(end.getLocation());
for (BlockFace face : BLOCK_FACES) {
Block relative = cursor.getRelative(face);
double distance = relative.getLocation().distance(end.getLocation());
if(distance < nearestDistance) {
nearestDistance = distance;
nearest = face;
}
}
cursor = cursor.getRelative(nearest);
if(checkBlock(cursor))
return true;
}
return false;
}
private boolean checkBlock(Block block) {
return Config.HiddenBlocks.contains(block.getType());
}
private boolean invalidEntity(Projectile entity) {
Location location = entity.getLocation();
boolean teamFrom = entity.getVelocity().getZ() > 0;
boolean overMid = location.getZ() > Config.SpecSpawn.getZ();
boolean otherSide = teamFrom == overMid;
return otherSide || !Config.ArenaRegion.inRegion(location) ||
WorldOfColorWrapper.impl.isInBlock(entity) ||
entity.getVelocity().equals(NULL_VECTOR);
}
}
@@ -0,0 +1,24 @@
package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockFadeEvent;
public class BlockFadeListener implements Listener {
public BlockFadeListener() {
new StateDependentListener(Config.DisableSnowMelt, FightState.All, this);
}
@EventHandler
public void onBlockFade(BlockFadeEvent event) {
if (Config.ArenaRegion.inRegion(event.getBlock()) && (event.getBlock().getType() == Material.SNOW_BLOCK || event.getBlock().getType() == Material.SNOW || event.getBlock().getType() == Material.ICE)) {
event.setCancelled(true);
}
}
}
@@ -0,0 +1,61 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2023 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 de.steamwar.fightsystem.utils.FlatteningWrapper;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
public class BlockPlaceCollision implements Listener {
public BlockPlaceCollision() {
new StateDependentListener(ArenaMode.All, FightState.All, this);
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
Block block = event.getBlock();
if(!block.getType().isSolid())
return;
// Hitbox size: 0.6xz, 1.8y, 1.5y when sneaking
Player player = event.getPlayer();
Location min = player.getLocation().add(-0.3, 0, -0.3);
Location max = player.getLocation().add(0.3, FlatteningWrapper.impl.isCrouching(player) ? 0.6 : (player.isSneaking() ? 1.5 : 1.8), 0.3);
Location blockmin = block.getLocation();
Location blockmax = block.getLocation().add(1.0, 1.0, 1.0);
if(
max.getX() <= blockmin.getX() || min.getX() >= blockmax.getX() ||
max.getY() <= blockmin.getY() || min.getY() >= blockmax.getY() ||
max.getZ() <= blockmin.getZ() || min.getZ() >= blockmax.getZ()
)
return;
event.setCancelled(true);
}
}
@@ -0,0 +1,148 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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.states.FightState;
import de.steamwar.fightsystem.states.StateDependentTask;
import de.steamwar.fightsystem.utils.FlatteningWrapper;
import de.steamwar.fightsystem.utils.Region;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import java.util.*;
import java.util.logging.Level;
public class Border {
private final Map<UUID, Set<Block>> ghostBarriers = new HashMap<>();
private final Map<UUID, Location> lastLocation = new HashMap<>();
private final boolean contain;
private final String resetMessage;
private final String name;
private final Region region;
private final int ghostRange;
private final int ghostSize;
public Border(Region region, boolean contain, int ghostRange, String resetMessage, String name) {
this.contain = contain;
this.resetMessage = resetMessage;
this.name = name;
this.region = region;
this.ghostRange = ghostRange;
this.ghostSize = 2*ghostRange + 1;
new StateDependentTask(ArenaMode.All, FightState.All, this::run, 1, 1);
}
public void addPlayer(Player player) {
if(ghostBarriers.containsKey(player.getUniqueId()))
return;
ghostBarriers.put(player.getUniqueId(), new HashSet<>());
lastLocation.put(player.getUniqueId(), player.getLocation());
FightSystem.getPlugin().getLogger().log(Level.INFO, () -> player.getName() + " was added to border " + name);
}
public boolean contains(Player player) {
return ghostBarriers.containsKey(player.getUniqueId());
}
public void removePlayer(Player player) {
FightSystem.getPlugin().getLogger().log(Level.INFO, () -> player.getName() + " was removed from border " + name);
lastLocation.remove(player.getUniqueId());
Set<Block> blocks = ghostBarriers.remove(player.getUniqueId());
if(blocks == null || !player.isOnline())
return;
for(Block block : blocks)
sendChange(player, block, Material.AIR);
}
private void run() {
List<UUID> offline = new ArrayList<>();
for(Map.Entry<UUID, Set<Block>> entry : ghostBarriers.entrySet()) {
UUID uuid = entry.getKey();
Player player = Bukkit.getPlayer(uuid);
if(player == null) {
offline.add(uuid);
continue;
}
Location location = player.getLocation();
if(region.playerInRegion(location) != contain) {
player.teleport(lastLocation.get(uuid));
FightSystem.getMessage().sendPrefixless(resetMessage, player, ChatMessageType.ACTION_BAR);
return;
}
Set<Block> ghostBlocks = entry.getValue();
Region ghostRegion = Region.fromSize(location.getBlockX() - ghostRange, location.getBlockY() - ghostRange, location.getBlockZ() - ghostRange, ghostSize, ghostSize, ghostSize);
ghostBlocks.removeIf(block -> {
if(!ghostRegion.inRegion(block)) {
sendChange(player, block, Material.AIR);
return true;
}
return false;
});
if(contain) {
borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX()-1, region.getMinY(), region.getMinZ(), 1, region.getSizeY(), region.getSizeZ()).intersection(ghostRegion));
borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMinY()-1, region.getMinZ(), region.getSizeX(), 1, region.getSizeZ()).intersection(ghostRegion));
borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMinY(), region.getMinZ()-1, region.getSizeX(), region.getSizeY(), 1).intersection(ghostRegion));
borderIteration(player, ghostBlocks, Region.fromSize(region.getMaxX(), region.getMinY(), region.getMinZ(), 1, region.getSizeY(), region.getSizeZ()).intersection(ghostRegion));
borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMaxY(), region.getMinZ(), region.getSizeX(), 1, region.getSizeZ()).intersection(ghostRegion));
borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMinY(), region.getMaxZ(), region.getSizeX(), region.getSizeY(), 1).intersection(ghostRegion));
} else {
borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMinY(), region.getMinZ(), 1, region.getSizeY(), region.getSizeZ()).intersection(ghostRegion));
borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMinY(), region.getMinZ(), region.getSizeX(), 1, region.getSizeZ()).intersection(ghostRegion));
borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMinY(), region.getMinZ(), region.getSizeX(), region.getSizeY(), 1).intersection(ghostRegion));
borderIteration(player, ghostBlocks, Region.fromSize(region.getMaxX()-1, region.getMinY(), region.getMinZ(), 1, region.getSizeY(), region.getSizeZ()).intersection(ghostRegion));
borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMaxY()-1, region.getMinZ(), region.getSizeX(), 1, region.getSizeZ()).intersection(ghostRegion));
borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMinY(), region.getMaxZ()-1, region.getSizeX(), region.getSizeY(), 1).intersection(ghostRegion));
}
lastLocation.put(entry.getKey(), location);
}
offline.forEach(uuid -> FightSystem.getPlugin().getLogger().log(Level.INFO, () -> uuid + " was removed from border " + name));
offline.forEach(ghostBarriers::remove);
offline.forEach(lastLocation::remove);
}
private void borderIteration(Player player, Set<Block> ghostBlocks, Region border) {
border.forEach((x, y, z) -> {
Block block = Config.world.getBlockAt(x, y, z);
if(ghostBlocks.add(block))
sendChange(player, block, Material.BARRIER);
});
}
private void sendChange(Player player, Block block, Material type) {
if(block.getType() == Material.AIR)
FlatteningWrapper.impl.sendBlockChange(player, block, type);
}
}
@@ -0,0 +1,70 @@
/*
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.record.GlobalRecorder;
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.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import java.util.logging.Level;
public class Chat implements Listener {
public Chat(){
new StateDependentListener(ArenaMode.All, FightState.All, this);
}
@EventHandler
public void handlePlayerChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
String message = event.getMessage();
FightSystem.getPlugin().getLogger().log(Level.INFO, player.getName() + "» " + message);
FightTeam fightTeam = Fight.getPlayerTeam(player);
if(fightTeam != null) {
String teamName = fightTeam.getColoredName();
if(message.startsWith(Config.TeamChatDetection)) {
fightTeam.broadcastChat(player, message.substring(1));
} else {
broadcastChat("PARTICIPANT_CHAT", teamName, player.getName(), message);
}
}else if(Config.isReferee(player)){
broadcastChat("FIGHTLEADER_CHAT", player.getName(), message);
}else{
broadcastChat("SPECTATOR_CHAT", player.getName(), message);
}
event.setCancelled(true);
}
public static void broadcastChat(String message, Object... params) {
GlobalRecorder.getInstance().chat(message, params);
FightSystem.getMessage().chat(message, params);
}
}
@@ -0,0 +1,71 @@
/*
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.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.UserPerm;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import java.util.logging.Level;
public class Check implements Listener {
public Check() {
new StateDependentListener(ArenaMode.Check, FightState.All, this);
}
@EventHandler
public void onJoin(PlayerJoinEvent e){
Player player = e.getPlayer();
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
if(user.hasPerm(UserPerm.CHECK))
return;
SchematicNode schem = SchematicNode.getSchematicNode(Config.CheckSchemID);
if(user.getId() == schem.getOwner())
return;
FightSystem.getMessage().send("CHECK_JOIN_DENIED", player);
player.kickPlayer("");
}
@EventHandler
public void handlePlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
if(!event.getMessage().contains("copy") && !event.getMessage().contains("cut"))
return;
event.setCancelled(true);
FightSystem.getMessage().send("CHECK_COMMAND_LOCKED", player);
Bukkit.getLogger().log(Level.SEVERE, player.getName() + " tried to use a copy command!");
}
}
@@ -0,0 +1,59 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2022 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 com.comphenix.tinyprotocol.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.core.Core;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.utils.CraftbukkitWrapper;
import org.bukkit.entity.Player;
import java.io.*;
public class ClickAnalyzer {
private static final PrintStream output;
static {
try {
output = new PrintStream(new BufferedOutputStream(new FileOutputStream(new File(Config.world.getWorldFolder(), "clicks.csv"))));
} catch (FileNotFoundException e) {
throw new SecurityException(e);
}
}
public ClickAnalyzer() {
TinyProtocol.instance.addFilter(Recording.blockPlacePacket, this::onBlockPlace);
if(Core.getVersion() > 8)
TinyProtocol.instance.addFilter(Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem"), this::onBlockPlace);
}
public Object onBlockPlace(Player player, Object packet) {
synchronized(output) {
output.println(player.getName() + "," + System.nanoTime() + "," + CraftbukkitWrapper.impl.headRotation(player) + "," + player.getLocation().getPitch());
}
return packet;
}
public static void close() {
output.close();
}
}
@@ -0,0 +1,57 @@
/*
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.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.utils.BountifulWrapper;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
public class DenyInventoryMovement implements Listener {
public DenyInventoryMovement() {
new StateDependentListener(ArenaMode.AntiTest, FightState.AntiIngame, this);
Listener listener = BountifulWrapper.impl.newDenyHandSwapListener();
new StateDependentListener(ArenaMode.AntiTest, FightState.AntiIngame, listener);
}
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
if(!PersonalKitCreator.inKitCreator(event.getWhoClicked()))
event.setCancelled(true);
}
@EventHandler
public void onInventoryDrag(InventoryDragEvent event) {
if(!PersonalKitCreator.inKitCreator(event.getWhoClicked()))
event.setCancelled(true);
}
@EventHandler
public void onItemPickup(PlayerPickupItemEvent event) {
event.setCancelled(true);
}
}
@@ -0,0 +1,109 @@
/*
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.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerKickEvent;
public class DenyWorldInteraction implements Listener {
public DenyWorldInteraction() {
new StateDependentListener(ArenaMode.Test, FightState.PreRunning, this);
new StateDependentListener(ArenaMode.AntiTest, FightState.AntiRunning, this);
}
@EventHandler
public void handleBlockBreak(BlockBreakEvent event) {
Player player = event.getPlayer();
if(Fight.fighting(player)) {
event.setCancelled(true);
FightSystem.getMessage().sendPrefixless("NO_BLOCK_BREAK", player, ChatMessageType.ACTION_BAR);
}
}
@EventHandler
public void handleItemDrop(PlayerDropItemEvent event) {
Player player = event.getPlayer();
if(Fight.fighting(player)) {
event.setCancelled(true);
}
}
@EventHandler
public void handleHangingBreak(HangingBreakEvent event) {
if(Config.ArenaRegion.inRegion(event.getEntity().getLocation())) {
event.setCancelled(true);
}
}
@EventHandler
public void handleBlockPlace(BlockPlaceEvent event) {
Player player = event.getPlayer();
if(Fight.fighting(player)) {
event.setCancelled(true);
FightSystem.getMessage().sendPrefixless("NO_BLOCK_PLACE", player, ChatMessageType.ACTION_BAR);
}
}
@EventHandler
public void handleEntityExplode(EntityExplodeEvent event) {
if(!Config.ArenaLeaveable || Config.ArenaRegion.inRegion(event.getLocation()))
event.setCancelled(true);
}
@EventHandler
public void handleBlockBurn(BlockIgniteEvent event) {
if(!Config.ArenaLeaveable || Config.ArenaRegion.inRegion(event.getBlock()))
event.setCancelled(true);
}
@EventHandler
public void handlePlayerKickEvent(PlayerKickEvent e){
if(e.getReason().contains("Flying is not enabled"))
e.setCancelled(true);
}
@EventHandler
public void handleProjectileLaunch(ProjectileLaunchEvent event) {
if(event.getEntity().getShooter() instanceof Player) {
Player player = (Player) event.getEntity().getShooter();
if(Fight.fighting(player)) {
event.setCancelled(true);
FightSystem.getMessage().sendPrefixless("NO_BOW_USAGE", player, ChatMessageType.ACTION_BAR);
}
}
}
}
@@ -0,0 +1,48 @@
/*
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.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
public class EntityDamage implements Listener {
public EntityDamage() {
new StateDependentListener(ArenaMode.All, FightState.AntiRunning, this);
}
@EventHandler
public void handleEntityDamage(EntityDamageEvent event) {
if(Config.ArenaRegion.in2dRegion(event.getEntity().getLocation()))
event.setCancelled(true);
}
@EventHandler
public void handleEntityDamageByEntity(EntityDamageByEntityEvent event) {
if(Config.ArenaRegion.in2dRegion(event.getEntity().getLocation()))
event.setCancelled(true);
}
}
@@ -0,0 +1,93 @@
/*
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.sql.SteamwarUser;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
public class EventJoin implements Listener {
public EventJoin() {
new StateDependentListener(ArenaMode.Event, FightState.All, this);
}
@EventHandler
public void playerLogin(PlayerLoginEvent event) {
if(!Config.LiveReplay)
return;
Player player = event.getPlayer();
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
if(user.getTeam() == Config.EventTeamBlueID ||
user.getTeam() == Config.EventTeamRedID ||
Config.isReferee(player))
return;
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, FightSystem.getMessage().parse("NO_PARTICIPANT", player));
}
@EventHandler
public void handlePlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
if(Config.isReferee(player))
return;
if(FightState.Setup.contains(FightState.getFightState())){
FightTeam team = null;
if(user.getTeam() == Config.EventTeamBlueID)
team = Fight.getBlueTeam();
else if(user.getTeam() == Config.EventTeamRedID)
team = Fight.getRedTeam();
if(Config.BothTeamsPublic){
if(Fight.getRedTeam().getPlayers().size() < Fight.getBlueTeam().getPlayers().size())
team = Fight.getRedTeam();
else
team = Fight.getBlueTeam();
}else if(team == null){
if(Config.EventTeamRedID == 0)
team = Fight.getRedTeam();
else if(Config.EventTeamBlueID == 0)
team = Fight.getBlueTeam();
}
if(team != null && team.getPlayers().size() < Config.MaximumTeamMembers){
team.addMember(player);
return;
}
}
if(Config.LiveReplay)
player.kickPlayer(FightSystem.getMessage().parse("NO_PARTICIPANT", player));
}
}
@@ -0,0 +1,94 @@
/*
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 de.steamwar.scoreboard.SWScoreboard;
import de.steamwar.scoreboard.ScoreboardCallback;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import java.util.HashMap;
import java.util.Objects;
public class FightScoreboard implements Listener, ScoreboardCallback {
public static Team getBukkitTeam(String name) {
Scoreboard scoreboard = Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard();
Team team = scoreboard.getTeam(name);
if(team != null)
return team;
return scoreboard.registerNewTeam(name);
}
private static FightScoreboard scoreboard;
public static FightScoreboard getScoreboard(){
if(scoreboard == null)
scoreboard = new FightScoreboard();
return scoreboard;
}
private String title = "";
private final HashMap<String, Integer> scores = new HashMap<>();
private FightScoreboard(){
new StateDependentListener(ArenaMode.Replay, FightState.All, this);
Bukkit.getOnlinePlayers().forEach(player -> SWScoreboard.createScoreboard(player, this));
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
SWScoreboard.createScoreboard(event.getPlayer(), this);
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
SWScoreboard.removeScoreboard(event.getPlayer());
}
public void setTitle(String t) {
scores.clear();
title = t;
}
public void addScore(String string, int i) {
scores.put(string, i);
}
@Override
public String getTitle() {
return title;
}
@Override
public HashMap<String, Integer> getData() {
return scores;
}
}
@@ -0,0 +1,88 @@
/*
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.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.winconditions.Winconditions;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import java.util.Objects;
public class InFightDamage implements Listener {
public InFightDamage() {
new StateDependentListener(!Config.ActiveWinconditions.contains(Winconditions.AMONG_US), FightState.Running, this);
}
@EventHandler
public void handleEntityDamageByEntity(EntityDamageByEntityEvent event) {
if(!(event.getEntity() instanceof LivingEntity))
//Target is not a player
return;
LivingEntity player = ((LivingEntity) event.getEntity());
if(!Fight.fighting(player))
return;
LivingEntity damager;
if(event.getDamager() instanceof LivingEntity) {
damager = (LivingEntity) event.getDamager();
}else if(event.getDamager() instanceof Arrow) {
Arrow damagerArrow = (Arrow) event.getDamager();
if(!(damagerArrow.getShooter() instanceof LivingEntity))
//Shooter is not a player
return;
damager = (LivingEntity) damagerArrow.getShooter();
}else{
//Damager is not a player
return;
}
if(!Fight.fighting(damager)){
event.setCancelled(true);
//Damager is not fighting
return;
}
if(Fight.getPlayerTeam(player) == Fight.getPlayerTeam(damager)) {
event.setCancelled(true);
if(event.getDamager() instanceof Arrow){
event.getDamager().setFireTicks(0);
player.setFireTicks(0);
}
FightSystem.getMessage().sendPrefixless("NO_FRIENDLY_FIRE", damager, ChatMessageType.ACTION_BAR);
}
if(player.getHealth() - event.getFinalDamage() <= 0){
Objects.requireNonNull(Fight.getFightPlayer(damager)).addKill();
}
}
}
@@ -0,0 +1,75 @@
/*
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.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryType;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
public class InFightInventory implements Listener {
private static final Set<Material> allowed = Collections.unmodifiableSet(EnumSet.of(Material.TNT, Material.AIR));
public InFightInventory() {
new StateDependentListener(ArenaMode.AntiReplay, FightState.Ingame, this);
}
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
if(!Fight.fighting((Player) event.getWhoClicked()))
return;
InventoryType top = event.getView().getTopInventory().getType();
if(top == InventoryType.CRAFTING)
return;
if ((event.getCursor() != null && !allowed.contains(event.getCursor().getType())) || (event.getCurrentItem() != null && !allowed.contains(event.getCurrentItem().getType())))
event.setCancelled(true); // Deny if transferred item is not TNT
}
@EventHandler
public void onInventoryDrag(InventoryDragEvent event) {
if(!Fight.fighting((Player) event.getWhoClicked()))
return;
if (event.getInventory().getType() != InventoryType.PLAYER) {
int inventorySize = event.getInventory().getSize();
for (int i : event.getRawSlots()) {
if (i < inventorySize) {
event.setCancelled(true);
break;
}
}
}
}
}
@@ -0,0 +1,78 @@
/*
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.FightPlayer;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.utils.FightUI;
import de.steamwar.fightsystem.utils.SWSound;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.function.Consumer;
public class IngameDeath implements Listener {
public IngameDeath() {
new StateDependentListener(ArenaMode.AntiReplay, FightState.Ingame, this);
}
@EventHandler
public void broadcastDeath(EntityDeathEvent event) {
onPlayerEnd(event.getEntity(), fightPlayer -> {
FightUI.addSubtitle("UI_PLAYER_DEATH", fightPlayer.getTeam().getPrefix(), fightPlayer.getEntity().getName());
Fight.playSound(SWSound.ENTITY_WITHER_DEATH.getSound(), 100.0F, 1.0F);
});
}
@EventHandler
public void broadcastQuit(PlayerQuitEvent event) {
onPlayerEnd(event.getPlayer(), fightPlayer -> FightUI.addSubtitle("UI_PLAYER_LEAVE", fightPlayer.getTeam().getPrefix(), fightPlayer.getEntity().getName()));
}
@EventHandler(priority = EventPriority.MONITOR)
public void handlePlayerDeath(EntityDeathEvent event) {
onPlayerEnd(event.getEntity(), FightPlayer::setOut);
}
@EventHandler(priority = EventPriority.MONITOR)
public void handlePlayerQuit(PlayerQuitEvent event) {
onPlayerEnd(event.getPlayer(), FightPlayer::setOut);
}
private void onPlayerEnd(Entity player, Consumer<FightPlayer> withLivingPlayer) {
if(!(player instanceof LivingEntity))
return;
FightPlayer fightPlayer = Fight.getFightPlayer((LivingEntity) player);
if(fightPlayer == null || !fightPlayer.isLiving())
return;
withLivingPlayer.accept(fightPlayer);
}
}
@@ -0,0 +1,74 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2022 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.FightPlayer;
import de.steamwar.fightsystem.fight.HotbarKit;
import de.steamwar.fightsystem.fight.JoinRequest;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.OneShotStateDependent;
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.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
public class JoinRequestListener implements Listener {
public JoinRequestListener() {
new OneShotStateDependent(ArenaMode.VariableTeams, FightState.PreLeaderSetup, () -> Bukkit.getScheduler().runTask(FightSystem.getPlugin(), JoinRequest::clearRequests));
new OneShotStateDependent(ArenaMode.VariableTeams, FightState.PreRunning, () -> Bukkit.getScheduler().runTask(FightSystem.getPlugin(), JoinRequest::clearRequests));
new StateDependentListener(ArenaMode.VariableTeams, FightState.All, this);
}
@EventHandler(priority = EventPriority.HIGH)
public void onJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
FightPlayer fp = Fight.getFightPlayer(player);
if (!Config.ArenaLeaveable && (fp == null || !fp.isLiving())) {
HotbarKit.SPECTATOR_KIT.loadToPlayer(player);
}
}
@EventHandler
public void handlePlayerRespawn(PlayerRespawnEvent event) {
Player player = event.getPlayer();
if(Fight.fighting(player)) {
HotbarKit.SPECTATOR_KIT.loadToPlayer(player);
}
}
@EventHandler
public void onLeave(PlayerQuitEvent event) {
JoinRequest request = JoinRequest.get(event.getPlayer());
if(request != null)
request.silentDecline();
}
}
@@ -0,0 +1,89 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2022 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.Config;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
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.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.spigotmc.event.player.PlayerSpawnLocationEvent;
import java.util.HashMap;
import java.util.Map;
public class LeaveableArena implements Listener {
private final Map<Player, GameMode> spectatorsInArena = new HashMap<>();
public LeaveableArena() {
new StateDependentListener(Config.ArenaLeaveable, FightState.All, this);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onJoin(PlayerSpawnLocationEvent event) {
Player player = event.getPlayer();
if(Fight.fighting(player))
return;
if(Config.ArenaRegion.in2dRegion(event.getSpawnLocation())) {
markInArena(player);
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onRespawn(PlayerRespawnEvent event) {
Player player = event.getPlayer();
if(Config.ArenaRegion.in2dRegion(event.getRespawnLocation())) {
markInArena(player);
} else {
spectatorsInArena.remove(player);
}
}
@EventHandler
public void arenaBorder(PlayerMoveEvent event){
Player player = event.getPlayer();
if(Fight.fighting(player))
return;
boolean inArena = Config.ArenaRegion.in2dRegion(event.getTo());
boolean spectator = spectatorsInArena.containsKey(player);
if(inArena && !spectator) {
markInArena(player);
} else if(!inArena && spectator) {
GameMode mode = spectatorsInArena.remove(player);
if(mode != null)
player.setGameMode(mode);
}
}
private void markInArena(Player player) {
spectatorsInArena.put(player, player.getGameMode());
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
}
}
@@ -0,0 +1,49 @@
/*
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.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class NormalJoin implements Listener {
public NormalJoin() {
new StateDependentListener(ArenaMode.Normal, FightState.PreLeaderSetup, this);
}
@EventHandler
public void handlePlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
if (Fight.getPlayerTeam(player) != null)
return;
FightTeam team = Fight.teams().stream().filter(t -> player.getUniqueId().equals(t.getDesignatedLeader())).findAny( // Player is designated leader of a team
).orElse(Fight.teams().stream().filter(t -> t.canbeLeader(player)).findAny().orElse(null)); // Else search empty team
if(team != null)
team.addMember(player);
}
}
@@ -0,0 +1,243 @@
/*
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.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.utils.BountifulWrapper;
import de.steamwar.fightsystem.utils.FlatteningWrapper;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.entity.SpawnerSpawnEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.FurnaceSmeltEvent;
import org.bukkit.event.player.*;
import org.bukkit.event.weather.WeatherChangeEvent;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scoreboard.NameTagVisibility;
import org.bukkit.scoreboard.Team;
public class Permanent implements Listener {
private static final Team spectatorTeam = FightScoreboard.getBukkitTeam("Spectator");
static {
BountifulWrapper.impl.setNametagVisibility(spectatorTeam);
spectatorTeam.setNameTagVisibility(NameTagVisibility.NEVER);
}
public static Team getSpectatorTeam() {
return spectatorTeam;
}
public Permanent() {
new StateDependentListener(ArenaMode.All, FightState.All, this);
}
@EventHandler
public void handlePlayerRespawn(PlayerRespawnEvent event){
Player player = event.getPlayer();
if(Fight.fighting(player)) {
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);
FightSystem.getMessage().sendPrefixless("NO_TELEPORT", e.getPlayer(), ChatMessageType.ACTION_BAR);
e.getPlayer().kickPlayer(null);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void handlePlayerJoin(PlayerJoinEvent event) {
event.setJoinMessage(null);
Player player = event.getPlayer();
FightPlayer fp = Fight.getFightPlayer(player);
if (!Config.ArenaLeaveable && fp == null) {
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
spectatorTeam.addEntry(player.getName());
player.teleport(Config.SpecSpawn);
} else if(fp != null && !fp.isLiving()) {
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
player.teleport(fp.getTeam().getSpawn());
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void handlePlayerDeath(PlayerDeathEvent event) {
if(!Config.ArenaLeaveable || Fight.fighting(event.getEntity()))
event.setDeathMessage(null);
}
@EventHandler(priority = EventPriority.MONITOR)
public void handlePlayerLeave(PlayerQuitEvent event) {
if(!Config.ArenaLeaveable)
event.setQuitMessage(null);
}
@EventHandler
public void handleFoodLevelChange(FoodLevelChangeEvent event) {
if(Fight.fighting((Player) event.getEntity()))
event.setCancelled(true);
}
@EventHandler
public void onWeatherChange(WeatherChangeEvent event) {
event.setCancelled(true);
}
@EventHandler
public void onSpawnerSpawn(SpawnerSpawnEvent e){
if(Config.ArenaRegion.inRegion(e.getSpawner().getBlock()))
e.setCancelled(true);
}
@EventHandler
public void onSleep(PlayerBedEnterEvent e) {
if(Fight.fighting(e.getPlayer()))
e.setCancelled(true);
}
@EventHandler
public void onCrafting(CraftItemEvent e) {
if(Fight.fighting((Player) e.getWhoClicked()))
e.setCancelled(true);
}
@EventHandler
public void onFurnace(FurnaceSmeltEvent e){
if(Config.ArenaRegion.inRegion(e.getBlock()))
e.setCancelled(true);
}
@EventHandler
public void onDropPickup(PlayerPickupItemEvent e) {
if(!(Config.ArenaRegion.inRegion(e.getItem().getLocation())))
return;
Player player = e.getPlayer();
ItemStack stack = e.getItem().getItemStack();
if(Config.PersonalKits) {
if(Config.ForbiddenItems.contains(stack.getType())) {
e.setCancelled(true);
}
} else {
FightPlayer fp = Fight.getFightPlayer(player);
if(fp == null)
return;
if(!fp.getKit().contains(stack)) {
e.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onExplosion(EntityExplodeEvent e) {
e.blockList().removeIf(block -> {
if(block.getType() == Material.TNT) {
return false;
} else {
block.setType(Material.AIR);
return true;
}
});
}
@EventHandler
public void onWorldLoad(WorldLoadEvent e) {
if(!Config.ArenaLeaveable)
e.getWorld().setAutoSave(false);
}
@EventHandler
public void onBlockFromTo(BlockFromToEvent event) {
if(!event.getBlock().getType().equals(Material.DRAGON_EGG)) return;
for (FightTeam team : Fight.teams()) {
if(team.getExtendRegion().inRegion(event.getBlock())){
if(team.getExtendRegion().inRegion(event.getToBlock())) return;
}
}
event.setCancelled(true);
}
@EventHandler
public void onBlockDispense(BlockDispenseEvent e) {
Block block = e.getBlock();
if(!Config.ArenaRegion.inRegion(block))
return;
if(e.getItem().getType() == Material.TNT || FlatteningWrapper.impl.isFacingWater(block))
e.setCancelled(true);
}
@EventHandler
public void blockPlace(BlockPlaceEvent event) {
Player player = event.getPlayer();
Block block = event.getBlock();
if(Fight.teams().stream().anyMatch(team -> team.getExtendRegion().inRegion(block)))
return;
event.setCancelled(true);
FightSystem.getMessage().sendPrefixless("NO_BLOCK_PLACE", player, ChatMessageType.ACTION_BAR);
}
@EventHandler
public void blockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
if(Config.BlueExtendRegion.getMinY() <= block.getY())
return;
event.setCancelled(true);
FightSystem.getMessage().sendPrefixless("NO_BLOCK_BREAK", event.getPlayer(), ChatMessageType.ACTION_BAR);
}
}
@@ -0,0 +1,163 @@
/*
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.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.fight.Kit;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.sql.PersonalKit;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
public class PersonalKitCreator implements Listener {
private static final Map<HumanEntity, InventoryBackup> openKitCreators = new HashMap<>();
public PersonalKitCreator(){
new StateDependentListener(Config.PersonalKits, FightState.Setup, this);
}
public static void openKitCreator(Player player, PersonalKit kit){
player.closeInventory();
new InventoryBackup(player, kit);
new Kit(kit).loadToPlayer(player);
player.setGameMode(GameMode.CREATIVE);
FightSystem.getMessage().sendPrefixless("OPEN_INVENTORY_TO_CUSTOMIZE", player, ChatMessageType.ACTION_BAR);
}
public static boolean inKitCreator(HumanEntity player){
return openKitCreators.containsKey(player);
}
public static void closeIfInKitCreator(HumanEntity player){
InventoryBackup backup = openKitCreators.get(player);
if(backup == null)
return;
backup.close();
}
@EventHandler
public void onInventoryClick(InventoryClickEvent e){
if(!openKitCreators.containsKey(e.getWhoClicked()))
return;
Player player = (Player) e.getWhoClicked();
//Deny bad items
if(Kit.isBadItem(e.getCursor()))
e.setCancelled(true);
/* Should the inventory reset? */
if(e.getAction() != InventoryAction.PLACE_ALL)
return;
ItemStack[] items = e.getWhoClicked().getInventory().getContents();
for(int i = 0; i < items.length; i++){
ItemStack stack = items[i];
if(stack != null && i != e.getSlot())
return;
}
FightPlayer fightPlayer = Fight.getFightPlayer(player);
assert fightPlayer != null;
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> fightPlayer.getKit().loadToPlayer(player), 1);
}
@EventHandler
public void onMoveEvent(PlayerMoveEvent e){
InventoryBackup backup = openKitCreators.get(e.getPlayer());
if(backup == null)
return;
backup.close();
}
@EventHandler
public void onOpenEvent(InventoryOpenEvent e){
InventoryBackup backup = openKitCreators.get(e.getPlayer());
if(backup == null)
return;
backup.close();
}
@EventHandler
public void onInventoryClose(InventoryCloseEvent e) {
InventoryBackup backup = openKitCreators.get(e.getPlayer());
if(backup == null)
return;
backup.close();
}
@EventHandler
public void onPlayerExit(PlayerQuitEvent e){
InventoryBackup backup = openKitCreators.get(e.getPlayer());
if(backup == null)
return;
backup.close();
}
private static class InventoryBackup{
private final Player player;
private final PersonalKit kit;
private final Kit backup;
private InventoryBackup(Player player, PersonalKit kit){
openKitCreators.put(player, this);
this.player = player;
this.backup = Kit.getActiveKit(player);
this.kit = kit;
}
private void close(){
openKitCreators.remove(player);
Kit kit1 = new Kit(kit.getName(), player);
kit1.removeBadItems();
kit1.toPersonalKit(kit);
backup.loadToPlayer(player);
player.setGameMode(GameMode.SURVIVAL);
kit.setInUse();
player.closeInventory();
Objects.requireNonNull(Fight.getFightPlayer(player)).setKit(new Kit(kit));
}
}
}
@@ -0,0 +1,79 @@
/*
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.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.PistonMoveReaction;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPistonEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import java.util.Set;
import java.util.function.Consumer;
public class PistonListener implements Listener {
private final Consumer<BlockPistonEvent> leftAreaHandler;
public PistonListener(Set<ArenaMode> condition, Consumer<BlockPistonEvent> leftAreaHandler) {
this.leftAreaHandler = leftAreaHandler;
if(!condition.contains(Config.mode))
return;
//Wenn Entern aktiv ist, sollen Raketen etc. entern können
new StateDependentListener(!Config.AllowMissiles, FightState.All, this);
new StateDependentListener(Config.AllowMissiles, FightState.Setup, this);
}
@EventHandler
public void handlePistonExtend(BlockPistonExtendEvent e){
if(!Config.ArenaRegion.inRegion(e.getBlock()))
return;
BlockFace face = e.getDirection();
for(Block block : e.getBlocks()){
Block target = block.getRelative(face);
if(!Config.BlueExtendRegion.inRegion(target) && !Config.RedExtendRegion.inRegion(target) && block.getPistonMoveReaction() != PistonMoveReaction.BREAK) {
leftAreaHandler.accept(e);
return;
}
}
}
@EventHandler
public void handlePistonRetract(BlockPistonRetractEvent e){
if(!Config.ArenaRegion.inRegion(e.getBlock()))
return;
for(Block block : e.getBlocks()){
if(!Config.BlueExtendRegion.inRegion(block) && !Config.RedExtendRegion.inRegion(block)) {
leftAreaHandler.accept(e);
return;
}
}
}
}
@@ -0,0 +1,135 @@
/*
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 com.sk89q.worldedit.WorldEditException;
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.OneShotStateDependent;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.utils.FlatteningWrapper;
import de.steamwar.fightsystem.utils.Region;
import de.steamwar.fightsystem.utils.WorldeditWrapper;
import de.steamwar.sql.SchematicNode;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.util.Vector;
import java.util.HashSet;
import java.util.Set;
public class PrepareSchem implements Listener {
private final Set<Vector> stationaryMovingPistons = new HashSet<>();
public PrepareSchem() {
new OneShotStateDependent(ArenaMode.Prepare, FightState.PostSchemSetup, () -> Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> {
stationaryMovingPistons.clear();
Fight.getUnrotated().getSchemRegion().forEach((x, y, z) -> {
if(FlatteningWrapper.impl.checkPistonMoving(Config.world.getBlockAt(x, y, z)))
stationaryMovingPistons.add(new Vector(x, y, z));
});
}, 1));
new StateDependentListener(ArenaMode.Prepare, FightState.Setup, this){
@Override
public void disable() {
super.disable();
Region region = Fight.getUnrotated().getExtendRegion();
int minY = Fight.getUnrotated().getSchemRegion().getMinY();
SchematicNode schem;
try{
schem = SchematicNode.getSchematicNode(Config.PrepareSchemID);
}catch(SecurityException e){
FightSystem.getMessage().broadcast("PREPARE_SCHEM_DELETED");
Bukkit.shutdown();
return;
}
try{
region.forEach((x, y, z) -> {
if(FlatteningWrapper.impl.checkPistonMoving(Config.world.getBlockAt(x, y, z)) && !stationaryMovingPistons.contains(new Vector(x, y, z))){
FightSystem.getMessage().broadcast("PREPARE_ACTIVE_PISTON");
Bukkit.shutdown();
throw new IllegalStateException();
}
});
}catch (IllegalStateException e){
return;
}
if(schemExists(schem))
return;
schem = SchematicNode.createSchematicNode(schem.getOwner(), preparedName(schem), schem.getParent(), Config.SchematicType.checkType().toDB(), schem.getItem());
try{
WorldeditWrapper.impl.saveSchem(schem, region, minY);
}catch(WorldEditException e){
FightSystem.getMessage().broadcast("PREPARE_FAILED_SAVING");
Bukkit.shutdown();
schem.delete();
throw new SecurityException("Could not save schem", e);
}
FightSystem.getMessage().broadcast("PREPARE_SENT_IN");
Bukkit.shutdown();
}
};
}
@EventHandler
public void handlePlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
FightTeam team = Fight.getPlayerTeam(player);
if (team == null) {
Fight.getUnrotated().addMember(player);
}
if(FightState.getFightState() == FightState.PRE_LEADER_SETUP) {
FightState.setFightState(FightState.PRE_SCHEM_SETUP);
FightState.setFightState(FightState.POST_SCHEM_SETUP);
}
schemExists(SchematicNode.getSchematicNode(Config.PrepareSchemID));
}
private boolean schemExists(SchematicNode schem) {
if(SchematicNode.getSchematicNode(schem.getOwner(), preparedName(schem), schem.getParent()) != null) {
FightSystem.getMessage().broadcast("PREPARE_SCHEM_EXISTS");
Bukkit.shutdown();
return true;
}
return false;
}
private String preparedName(SchematicNode schem) {
return schem.getName() + "-prepared";
}
}
@@ -0,0 +1,309 @@
/*
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 com.comphenix.tinyprotocol.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.events.TeamDeathEvent;
import de.steamwar.fightsystem.events.TeamLeaveEvent;
import de.steamwar.fightsystem.events.TeamSpawnEvent;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.record.GlobalRecorder;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.states.StateDependentTask;
import de.steamwar.fightsystem.utils.BountifulWrapper;
import de.steamwar.fightsystem.utils.CraftbukkitWrapper;
import de.steamwar.fightsystem.utils.FlatteningWrapper;
import de.steamwar.fightsystem.utils.SWSound;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.entity.*;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.*;
import org.bukkit.inventory.ItemStack;
import java.util.Random;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Predicate;
public class Recording implements Listener {
private static final int AIR = 0;
private static final Random random = new Random();
public static ItemStack disarmNull(ItemStack stack){
if(stack == null)
return new ItemStack(Material.AIR);
return stack;
}
public static boolean isNotSent(Player p){
FightPlayer fp = Fight.getFightPlayer(p);
return fp == null || !fp.isLiving() || FightState.getFightState() == FightState.SPECTATE;
}
public static final Class<?> primedTnt = Reflection.getClass("{nms.world.entity.item}.EntityTNTPrimed");
private static final Reflection.MethodInvoker getBukkitEntity = Reflection.getTypedMethod(Reflection.getClass("{nms.world.entity}.Entity"), "getBukkitEntity", null);
public static void iterateOverEntities(Predicate<Object> filter, Consumer<Entity> consumer) {
CraftbukkitWrapper.impl.entityIterator().filter(filter).map(entity -> (Entity) getBukkitEntity.invoke(entity)).forEach(consumer);
}
public Recording() {
new StateDependentListener(ArenaMode.AntiReplay, FightState.All, this);
new StateDependentListener(ArenaMode.AntiReplay, FightState.All, BountifulWrapper.impl.newHandSwapRecorder());
new StateDependent(ArenaMode.AntiReplay, FightState.Ingame){
@Override
public void enable() {
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> Fight.teams().forEach(Recording.this::setKitItems), 1);
}
@Override
public void disable() {
Fight.teams().forEach(Recording.this::despawnTeam);
despawnTNT();
}
}.register();
new StateDependent(ArenaMode.AntiReplay, FightState.Ingame) {
private final BiFunction<Player, Object, Object> place = Recording.this::blockPlace;
private final BiFunction<Player, Object, Object> dig = Recording.this::blockDig;
@Override
public void enable() {
TinyProtocol.instance.addFilter(blockPlacePacket, place);
TinyProtocol.instance.addFilter(blockDigPacket, dig);
}
@Override
public void disable() {
TinyProtocol.instance.removeFilter(blockPlacePacket, place);
TinyProtocol.instance.removeFilter(blockDigPacket, dig);
}
}.register();
new StateDependentTask(ArenaMode.AntiReplay, FightState.All, () -> {
GlobalRecorder.getInstance().tick();
if(FightState.getFightState() == FightState.SPECTATE || !GlobalRecorder.getInstance().recording())
return;
iterateOverEntities(primedTnt::isInstance, this::trackEntity);
}, 1, 1);
}
private void trackEntity(Entity entity) {
GlobalRecorder.getInstance().entityMoves(entity);
GlobalRecorder.getInstance().entitySpeed(entity);
}
private static final Class<?> blockDigPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockDig");
private static final Class<?> playerDigType = blockDigPacket.getDeclaredClasses()[0];
private static final Reflection.FieldAccessor<?> blockDigType = Reflection.getField(blockDigPacket, playerDigType, 0);
private static final Object releaseUseItem = playerDigType.getEnumConstants()[5];
private Object blockDig(Player p, Object packet) {
if(!isNotSent(p) && blockDigType.get(packet) == releaseUseItem)
GlobalRecorder.getInstance().bowSpan(p, false, false);
return packet;
}
public static final Class<?> blockPlacePacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockPlace");
private Object blockPlace(Player p, Object packet) {
boolean mainHand = BountifulWrapper.impl.mainHand(packet);
if(!isNotSent(p) && BountifulWrapper.impl.bowInHand(mainHand, p))
GlobalRecorder.getInstance().bowSpan(p, true, !mainHand);
return packet;
}
@EventHandler
public void onPlayerSpawn(TeamSpawnEvent e) {
GlobalRecorder.getInstance().playerJoins(e.getFightPlayer().getEntity(), e.getFightPlayer().getUser());
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerMove(PlayerMoveEvent e){
if(isNotSent(e.getPlayer()))
return;
GlobalRecorder.getInstance().entityMoves(e.getPlayer());
}
@EventHandler
public void onPlayerDeath(TeamDeathEvent e) {
GlobalRecorder.getInstance().entityDespawns(e.getFightPlayer().getEntity());
}
@EventHandler
public void onPlayerLeave(TeamLeaveEvent e) {
GlobalRecorder.getInstance().entityDespawns(e.getFightPlayer().getEntity());
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockPhysics(BlockPhysicsEvent e){
if(FlatteningWrapper.impl.doRecord(e))
GlobalRecorder.getInstance().blockChange(e.getBlock());
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onSneak(PlayerToggleSneakEvent e){
if(isNotSent(e.getPlayer()))
return;
GlobalRecorder.getInstance().playerSneak(e.getPlayer(), e.isSneaking());
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onAnimation(PlayerAnimationEvent e){
if(isNotSent(e.getPlayer()))
return;
if(e.getAnimationType() == PlayerAnimationType.ARM_SWING)
GlobalRecorder.getInstance().entityAnimation(e.getPlayer(), AIR);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityDamage(EntityDamageEvent e) {
if(e.getEntityType() != EntityType.PLAYER)
return;
Player p = (Player) e.getEntity();
if(isNotSent(p))
return;
GlobalRecorder.getInstance().damageAnimation(p);
if(e.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK || e.getCause() == EntityDamageEvent.DamageCause.FIRE)
GlobalRecorder.getInstance().setOnFire(p, false);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityCombust(EntityCombustEvent e) {
if(e.getEntityType() != EntityType.PLAYER)
return;
Player p = (Player) e.getEntity();
if(isNotSent(p))
return;
GlobalRecorder.getInstance().setOnFire(p, false);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onTNTSpawn(EntitySpawnEvent e){
if(e.getEntityType() != EntityType.PRIMED_TNT)
return;
GlobalRecorder.getInstance().tntSpawn(e.getEntity());
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onExplosion(EntityExplodeEvent e){
if(e.getEntityType() != EntityType.PRIMED_TNT)
return;
Location loc = e.getLocation();
GlobalRecorder.getInstance().entityDespawns(e.getEntity());
GlobalRecorder.getInstance().particle(loc.getX(), loc.getY(), loc.getZ(), "EXPLOSION_HUGE");
GlobalRecorder.getInstance().sound(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), SWSound.ENTITY_GENERIC_EXPLODE, "BLOCKS", 4.0F, (1.0F + (random.nextFloat() - random.nextFloat()) * 0.2F) * 0.7F);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onItem(PlayerItemHeldEvent e){
if(isNotSent(e.getPlayer()))
return;
GlobalRecorder.getInstance().item(e.getPlayer(), disarmNull(e.getPlayer().getInventory().getItem(e.getNewSlot())), "MAINHAND");
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onProjectileSpawn(ProjectileLaunchEvent e){
if(e.getEntityType() == EntityType.FIREBALL)
GlobalRecorder.getInstance().fireballSpawn(e.getEntity());
else if(e.getEntityType() == EntityType.ARROW)
GlobalRecorder.getInstance().arrowSpawn(e.getEntity());
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent e){
Player player = (Player) e.getWhoClicked();
if(isNotSent(player))
return;
if(e.getSlotType() != InventoryType.SlotType.ARMOR)
return;
switch(e.getSlot()){
case 103:
GlobalRecorder.getInstance().item(player, disarmNull(e.getCurrentItem()), "HEAD");
break;
case 102:
GlobalRecorder.getInstance().item(player, disarmNull(e.getCurrentItem()), "CHEST");
break;
case 101:
GlobalRecorder.getInstance().item(player, disarmNull(e.getCurrentItem()), "LEGS");
break;
case 100:
default:
GlobalRecorder.getInstance().item(player, disarmNull(e.getCurrentItem()), "FEET");
}
}
private void setKitItems(FightTeam team){
if(FightState.getFightState() != FightState.PRE_RUNNING)
return;
for(FightPlayer fp : team.getPlayers()){
if(!fp.isLiving())
continue;
fp.ifPlayer(player -> {
BountifulWrapper.impl.recordHandItems(player);
GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getHelmet()), "HEAD");
GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getChestplate()), "CHEST");
GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getLeggings()), "LEGS");
GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getBoots()), "FEET");
});
}
}
private void despawnTeam(FightTeam team){
for(FightPlayer player : team.getPlayers()){
if(player.isLiving())
GlobalRecorder.getInstance().entityDespawns(player.getEntity());
}
}
private void despawnTNT(){
iterateOverEntities(primedTnt::isInstance, GlobalRecorder.getInstance()::entityDespawns);
}
}
@@ -0,0 +1,48 @@
/*
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.fightsystem.listener;
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.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
public class RunningWorldInteraction implements Listener {
public RunningWorldInteraction() {
new StateDependentListener(ArenaMode.AntiReplay, FightState.Running, this);
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent e) {
FightPlayer fp = Fight.getFightPlayer(e.getPlayer());
if(fp != null && !fp.getKit().isTnt() && e.getBlockPlaced().getType() == Material.TNT){
FightSystem.getMessage().sendPrefixless("NO_TNT_PLACE", e.getPlayer(), ChatMessageType.ACTION_BAR);
e.setCancelled(true);
}
}
}
@@ -0,0 +1,47 @@
/*
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.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
public class SetupQuit implements Listener {
public SetupQuit(){
new StateDependentListener(ArenaMode.AntiReplay, FightState.Setup, this);
}
@EventHandler
public void handlePlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
FightTeam team = Fight.getPlayerTeam(player);
if(team == null)
return;
team.removePlayer(player);
}
}
@@ -0,0 +1,46 @@
/*
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.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
public class Shutdown implements Listener {
public Shutdown(){
new StateDependentListener(ArenaMode.AntiEvent.contains(Config.mode) && !Config.replayserver(), FightState.All, this);
}
@EventHandler
public void handlePlayerQuit(PlayerQuitEvent event) {
if(Config.replayserver() || Config.ArenaLeaveable)
return;
//Shutdown server if nobody online
if(Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(event.getPlayer())))
Bukkit.shutdown();
}
}
@@ -0,0 +1,143 @@
/*
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.events.BoardingEvent;
import de.steamwar.fightsystem.events.TeamDeathEvent;
import de.steamwar.fightsystem.events.TeamLeaveEvent;
import de.steamwar.fightsystem.events.TeamSpawnEvent;
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.OneShotStateDependent;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.states.StateDependentTask;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.HashSet;
import java.util.Set;
public class TeamArea implements Listener {
private final FightTeam team;
private final Border spectatorBorder;
private final Border bordingBorder;
private final Set<Player> realSpectator = new HashSet<>();
public TeamArea(FightTeam team) {
this.team = team;
this.spectatorBorder = new Border(team.getExtendRegion(), false, 5, "NO_TEAMAREA", team.getName() + ".spectatorBorder");
this.bordingBorder = new Border(team.getExtendRegion().to2d(), true, 1, "NO_ENTERN", team.getName() + ".boardingBorder");
new StateDependentListener(ArenaMode.AntiTest, FightState.All, this);
new StateDependentTask(ArenaMode.AntiTest, FightState.TeamFix, this::realSpectatorCheck, 1, 1);
new OneShotStateDependent(ArenaMode.AntiTest, FightState.Spectate, () -> Fight.teams().forEach(t -> t.getPlayers().forEach(this::teamSpectator)));
}
@EventHandler
public void playerJoin(PlayerJoinEvent e) {
Player player = e.getPlayer();
if(Fight.getPlayerTeam(player) != team && !Config.isReferee(player))
spectatorBorder.addPlayer(player);
}
@EventHandler
public void teamJoin(TeamSpawnEvent e) {
FightPlayer fightPlayer = e.getFightPlayer();
if(fightPlayer.getTeam() == team) {
fightPlayer.ifPlayer(player -> {
spectatorBorder.removePlayer(player);
bordingBorder.addPlayer(player);
});
}
}
@EventHandler
public void teamLeave(TeamLeaveEvent e) {
FightPlayer fightPlayer = e.getFightPlayer();
fightPlayer.ifPlayer(spectatorBorder::addPlayer);
if(fightPlayer.getTeam() == team)
fightPlayer.ifPlayer(bordingBorder::removePlayer);
}
@EventHandler
public void boarding(BoardingEvent e) {
FightPlayer fightPlayer = e.getFightPlayer();
if(fightPlayer.getTeam() == team) {
fightPlayer.ifPlayer(bordingBorder::removePlayer);
} else {
fightPlayer.ifPlayer(spectatorBorder::removePlayer);
}
}
@EventHandler
public void teamDeath(TeamDeathEvent e) {
teamSpectator(e.getFightPlayer());
}
private void teamSpectator(FightPlayer fightPlayer) {
if(fightPlayer.getTeam() == team) {
fightPlayer.ifPlayer(bordingBorder::removePlayer);
} else {
fightPlayer.ifPlayer(spectatorBorder::addPlayer);
}
}
@EventHandler
public void playerQuit(PlayerQuitEvent e) {
Player player = e.getPlayer();
spectatorBorder.removePlayer(player);
bordingBorder.removePlayer(player);
realSpectator.remove(player);
}
private void realSpectatorCheck() {
for(FightPlayer fightPlayer : team.getPlayers()) {
if(fightPlayer.isLiving())
continue;
fightPlayer.ifPlayer(player -> {
boolean inRegion = team.getExtendRegion().playerInRegion(player.getLocation());
if(inRegion && !realSpectator.contains(player)) {
realSpectator.add(player);
//Later to prevent race condition with Fight.setSpecatator() during respawn
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> {
if(!player.isOnline())
return;
Fight.pseudoSpectator(player, false);
}, 2);
}else if(!inRegion && realSpectator.contains(player)) {
Fight.pseudoSpectator(player, true);
realSpectator.remove(player);
}
});
}
}
}
@@ -0,0 +1,64 @@
/*
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.sql.SteamwarUser;
import de.steamwar.sql.UserPerm;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class TestJoin implements Listener {
public TestJoin() {
new StateDependentListener(ArenaMode.Test, FightState.All, this);
}
@EventHandler
public void handlePlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
FightTeam fightTeam = Fight.getPlayerTeam(player);
if(Config.ReplayID != 0 && !SteamwarUser.get(player.getUniqueId()).hasPerm(UserPerm.MODERATION)) {
FightSystem.getMessage().send("CHECK_JOIN_DENIED", player);
player.kickPlayer("");
return;
}
if (fightTeam == null && Fight.teams().stream().anyMatch(team -> team.canbeLeader(player))) {
FightSystem.getMessage().send("TEST_BECOME_LEADER", player);
}
player.setOp(true);
if(FightState.getFightState() == FightState.PRE_LEADER_SETUP){
FightState.setFightState(FightState.PRE_SCHEM_SETUP);
FightState.setFightState(FightState.POST_SCHEM_SETUP);
}
}
}
@@ -0,0 +1,111 @@
/*
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 de.steamwar.fightsystem.utils.FlatteningWrapper;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import java.util.HashMap;
import java.util.Map;
public class WaterRemover implements Listener {
private static final int MIN_Y = Config.BluePasteRegion.getMinY() + Config.WaterDepth;
private final Map<Integer, FightTeam> tnt = new HashMap<>();
public WaterRemover() {
new StateDependentListener(ArenaMode.AntiReplay, FightState.Running, this){
@Override
public void enable() {
tnt.clear();
super.enable();
}
};
}
@EventHandler
public void handleEntitySpawn(EntitySpawnEvent event) {
if(event.getEntityType() != EntityType.PRIMED_TNT)
return;
Location location = event.getLocation();
Fight.teams().forEach(team -> {
if(team.getExtendRegion().inRegion(location))
tnt.put(event.getEntity().getEntityId(), team);
});
}
@EventHandler
public void handleEntityExplode(EntityExplodeEvent event) {
event.setYield(0); //No drops (additionally to world config)
FightTeam spawn = tnt.remove(event.getEntity().getEntityId());
if(spawn != null && !spawn.getExtendRegion().inRegion(event.getLocation())) {
Block b = event.getLocation().getBlock();
for(int y = -1; y <= 1; y++) {
for(int z = -1; z <= 1; z++) {
for(int x = -1; x <= 1; x++) {
checkBlock(b.getRelative(x, y, z));
}
}
}
}
event.blockList().forEach(this::checkNeighbours);
}
private void checkNeighbours(Block b) {
checkBlock(b.getRelative(BlockFace.UP));
checkBlock(b.getRelative(BlockFace.EAST));
checkBlock(b.getRelative(BlockFace.WEST));
checkBlock(b.getRelative(BlockFace.NORTH));
checkBlock(b.getRelative(BlockFace.SOUTH));
checkBlock(b.getRelative(BlockFace.DOWN));
}
private void checkBlock(Block b) {
//do not remove outside teamareas
if(!Config.BlueExtendRegion.inRegion(b) && !Config.RedExtendRegion.inRegion(b))
return;
//checks for water and removes it, if present
if(!FlatteningWrapper.impl.removeWater(b))
return;
if(b.getY() < MIN_Y)
return;
checkNeighbours(b);
}
}
@@ -0,0 +1,75 @@
/*
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.record;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent;
import lombok.Getter;
import java.io.*;
import java.util.zip.GZIPOutputStream;
public class FileRecorder extends StateDependent implements Recorder {
@Getter
private static final File file = new File(Config.world.getWorldFolder(), "recording.recording");
private DataOutputStream outputStream;
public FileRecorder(){
super(Config.ReplayID == 0, FightState.Recording);
register();
}
@Override
public DataOutputStream getStream() {
return outputStream;
}
@Override
public void enable() {
try{
outputStream = new DataOutputStream(new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(file), 4096)){
@Override
public synchronized void flush() {
//Don't flush explicitly (performance)
}
@Override
public void close() throws IOException {
try{
super.flush();
}catch(IOException e){
//do nothing
}
super.close();
}
});
}catch(IOException e){
throw new SecurityException("Could not open file", e);
}
Recorder.super.enable();
}
@Override
public void disable() {
Recorder.super.disable();
}
}
@@ -0,0 +1,69 @@
/*
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.record;
import de.steamwar.fightsystem.Config;
import de.steamwar.sql.Replay;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
public class FileSource extends PacketSource {
public static void startReplay() {
if(Config.replayserver()) {
try {
new LiveServer();
} catch (IOException e) {
throw new SecurityException("Could not start replayserver", e);
}
return;
}
if(Config.ReplayID > 0) {
try {
new FileSource(Replay.get(Config.ReplayID).getReplay());
} catch (IOException e) {
throw new SecurityException("Could not start replay", e);
}
}
}
public FileSource(File fightFile) throws IOException {
super(new GZIPInputStream(new FileInputStream(fightFile)));
new PacketProcessor(this);
}
@Override
boolean isClosed() {
try{
return available() == 0;
}catch (IOException e){
return true;
}
}
@Override
boolean async() {
return false;
}
}
@@ -0,0 +1,95 @@
/*
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.record;
import org.bukkit.Bukkit;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
public class GlobalRecorder extends OutputStream implements Recorder {
private static final GlobalRecorder recorder = new GlobalRecorder();
public static GlobalRecorder getInstance(){
return recorder;
}
private final List<Recorder> recorders = new ArrayList<>();
private final DataOutputStream outputStream = new DataOutputStream(this);
public void add(Recorder recorder){
recorders.add(recorder);
}
public void remove(Recorder recorder){
recorders.remove(recorder);
}
public boolean recording(){
return !recorders.isEmpty();
}
@Override
public DataOutputStream getStream() {
return outputStream;
}
@Override
public void write(int i) {
foreach(stream -> stream.write(i));
}
@Override
public void write(byte[] bytes, int i, int i1) {
foreach(stream -> stream.write(bytes, i, i1));
}
@Override
public void flush() {
foreach(OutputStream::flush);
}
@Override
public void close() {
foreach(OutputStream::close);
}
private void foreach(IOThrower thrower) {
for(int i = 0; i < recorders.size(); i++) {
Recorder stream = recorders.get(i);
try{
thrower.run(stream.getStream());
}catch (IOException e){
Bukkit.getLogger().log(Level.SEVERE, "Could not operate on OutputStream", e);
stream.disable();
i--; // Recorder was removed from recorders
}
}
}
interface IOThrower{
void run(OutputStream stream) throws IOException;
}
}
@@ -0,0 +1,70 @@
/*
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.record;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent;
import org.bukkit.Bukkit;
import java.io.*;
import java.net.Socket;
import java.util.logging.Level;
public class LiveRecorder extends StateDependent implements Recorder {
private DataOutputStream outputStream;
private Socket socket;
public LiveRecorder(){
super(Config.LiveReplay, FightState.AntiSpectate);
register();
}
@Override
public void enable() {
try {
socket = new Socket(Config.spectateIP, Config.SpectatePort);
socket.setSoTimeout(1); // Wait a maximum of 1ms on a blocking operation (flush)
socket.setSoLinger(true, 1); // Wait a maximum of 1ms on disable
socket.setTcpNoDelay(true); // Don't wait on ack
outputStream = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream(), 1024));
} catch (IOException e) {
Bukkit.getLogger().log(Level.WARNING, "Could not init connection to spectate server", e);
disable();
}
Recorder.super.enable();
}
@Override
public void disable() {
try {
socket.close();
} catch (IOException e) {
Bukkit.getLogger().log(Level.WARNING, "IOException on socket close", e);
}
Recorder.super.disable();
}
@Override
public DataOutputStream getStream() {
return outputStream;
}
}
@@ -0,0 +1,62 @@
/*
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.record;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import org.bukkit.Bukkit;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
public class LiveServer {
private final ServerSocket socket;
public LiveServer() throws IOException {
socket = new ServerSocket(Config.SpectatePort);
Bukkit.getScheduler().runTaskAsynchronously(FightSystem.getPlugin(), this::acceptConnections);
}
public void close(){
try {
socket.close();
} catch (IOException e) {
Bukkit.getLogger().log(Level.SEVERE, "Could not close socket", e);
}
}
private void acceptConnections(){
try {
while(!socket.isClosed()){
Socket s = socket.accept();
if(PacketProcessor.isReplaying()){
s.close();
}else{
new LiveSource(s);
}
}
} catch (IOException e) {
Bukkit.getLogger().log(Level.INFO, "Stopping accepting connections", e);
}
}
}
@@ -0,0 +1,56 @@
/*
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.record;
import org.bukkit.Bukkit;
import java.io.IOException;
import java.net.Socket;
import java.util.logging.Level;
public class LiveSource extends PacketSource {
private final Socket socket;
protected LiveSource(Socket socket) throws IOException {
super(socket.getInputStream());
this.socket = socket;
new PacketProcessor(this);
}
@Override
public void close() {
super.close();
try {
socket.close();
} catch (IOException e) {
Bukkit.getLogger().log(Level.SEVERE, "IOException on close", e);
}
}
@Override
boolean isClosed() {
return socket.isClosed();
}
@Override
boolean async() {
return true;
}
}
@@ -0,0 +1,715 @@
/*
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.record;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.core.Core;
import de.steamwar.entity.REntity;
import de.steamwar.entity.REntityServer;
import de.steamwar.entity.RPlayer;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.Countdown;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.fight.FightWorld;
import de.steamwar.fightsystem.fight.FreezeWorld;
import de.steamwar.fightsystem.listener.FightScoreboard;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.utils.*;
import de.steamwar.sql.SchematicData;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.Team;
import de.steamwar.techhider.BlockIds;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.scoreboard.NameTagVisibility;
import java.io.EOFException;
import java.io.FilterInputStream;
import java.io.IOException;
import java.util.*;
import java.util.logging.Level;
import java.util.stream.Collectors;
public class PacketProcessor implements Listener {
private static final org.bukkit.scoreboard.Team team = FightScoreboard.getBukkitTeam("Replay");
static {
BountifulWrapper.impl.setNametagVisibility(team);
team.setNameTagVisibility(NameTagVisibility.NEVER);
}
private static PacketProcessor currentProcessor = null;
public static PacketProcessor currentReplay() {
return currentProcessor;
}
public static boolean isReplaying(){
return currentProcessor != null;
}
private final PacketParser[] packetDecoder = new PacketParser[256];
private final PacketSource source;
private final BukkitTask task;
private final LinkedList<Runnable> syncList = new LinkedList<>();
private final Set<Integer> hiddenBlockIds = Config.HiddenBlocks.stream().flatMap(m -> BlockIds.impl.materialToAllIds(m).stream()).collect(Collectors.toSet());
private final int obfuscateWith = BlockIds.impl.materialToId(Config.ObfuscateWith);
private final FreezeWorld freezer = new FreezeWorld();
private final REntityServer entityServer = new REntityServer();
private final Map<Integer, REntity> entities = new HashMap<>();
private boolean rotateZ = false;
private int arenaMinX = Config.ArenaRegion.getMinX();
private int arenaMinY = Config.BluePasteRegion.getMinY();
private int arenaMinZ = Config.ArenaRegion.getMinZ();
private boolean skipToSubtitle = false;
private boolean tickFinished = false;
private final List<Integer> lastPackets = new LinkedList<>();
public PacketProcessor(PacketSource source) {
this.source = source;
currentProcessor = this;
packetDecoder[0x00] = this::playerJoins;
packetDecoder[0x01] = this::entityMoves;
packetDecoder[0x02] = this::entityDespawns;
packetDecoder[0x03] = this::entitySneak;
packetDecoder[0x04] = this::entityAnimation;
packetDecoder[0x05] = this::tntSpawn;
packetDecoder[0x06] = this::entityVelocity;
packetDecoder[0x07] = this::playerItem;
packetDecoder[0x08] = this::arrowSpawn;
packetDecoder[0x09] = this::fireballSpawn;
packetDecoder[0x0a] = this::bow;
packetDecoder[0x0b] = this::damage;
packetDecoder[0x0c] = this::fireTick;
packetDecoder[0x20] = this::oldArenaInfo;
packetDecoder[0x21] = this::arenaInfo;
packetDecoder[0x30] = this::byteWorldHeightBlock;
packetDecoder[0x31] = this::particle;
packetDecoder[0x32] = this::sound;
packetDecoder[0x33] = this::shortBlock;
packetDecoder[0x34] = this::soundAtPlayer;
packetDecoder[0x35] = this::shortRelativeBlock;
packetDecoder[0x36] = this::block;
packetDecoder[0xa0] = () -> send(ChatMessageType.CHAT);
packetDecoder[0xa1] = () -> send(ChatMessageType.ACTION_BAR);
packetDecoder[0xa2] = () -> send(ChatMessageType.SYSTEM);
packetDecoder[0xa3] = this::countdown;
packetDecoder[0xa4] = this::chat;
packetDecoder[0xa5] = this::system;
packetDecoder[0xb0] = () -> pasteSchem(Fight.getBlueTeam());
packetDecoder[0xb1] = () -> pasteSchem(Fight.getRedTeam());
packetDecoder[0xb2] = this::teams;
packetDecoder[0xb3] = () -> pasteEmbeddedSchem(Fight.getBlueTeam());
packetDecoder[0xb4] = () -> pasteEmbeddedSchem(Fight.getRedTeam());
packetDecoder[0xc0] = this::scoreboardTitle;
packetDecoder[0xc1] = this::scoreboardData;
packetDecoder[0xc2] = this::bossBar;
packetDecoder[0xc3] = this::subtitle;
packetDecoder[0xc4] = this::printWin;
packetDecoder[0xc5] = this::messageSubtitle;
packetDecoder[0xc6] = this::winMessage;
packetDecoder[0xc7] = this::bossBarMessage;
packetDecoder[0xef] = source::readUTF;
packetDecoder[0xff] = this::tick;
execSync(FightWorld::forceLoad);
if(source.async()) {
Bukkit.getScheduler().runTaskAsynchronously(FightSystem.getPlugin(), this::process);
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::runSync, 1, 1);
}else
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::process, 1, 1);
Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin());
for(Player player : Bukkit.getOnlinePlayers())
entityServer.addPlayer(player);
}
private void addREntity(int entityId, REntity entity) {
entities.put(entityId, entity);
FightSystem.getHullHider().updateREntity(entity);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerJoin(PlayerJoinEvent e) {
entityServer.addPlayer(e.getPlayer());
}
public void skipToSubtitle() {
skipToSubtitle = true;
}
private void winMessage() throws IOException {
byte team = source.readByte();
Message message = readMessage();
execSync(() -> {
FightTeam winner = null;
if(team == 0x01)
winner = Fight.getBlueTeam();
else if(team == 0x02)
winner = Fight.getRedTeam();
FightSystem.setSpectateState(winner, "Replay ends", message.getMsg(), message.getParams());
});
}
private void system() throws IOException {
Message message = readMessage();
FightSystem.getMessage().broadcast(message.getMsg(), message.getParams());
}
private void messageSubtitle() throws IOException {
Message message = readMessage();
FightUI.addSubtitle(message.getMsg(), message.getParams());
skipToSubtitle = false;
}
private void chat() throws IOException {
Message message = readMessage();
FightSystem.getMessage().chat(message.getMsg(), message.getParams());
}
private void runSync() {
synchronized (syncList) {
for(Runnable runnable : syncList) {
try{
runnable.run();
}catch (Exception e) {
Bukkit.getLogger().log(Level.WARNING, "Failed to execute packet LastPacket: " + Arrays.toString(lastPackets.toArray()), e);
}
}
syncList.clear();
}
}
private void execSync(Runnable runnable){
if (!source.async()) {
runnable.run();
return;
}
synchronized (syncList) {
syncList.add(runnable);
}
}
private void playerJoins() throws IOException {
int entityId = source.readInt();
int userId = source.readInt();
execSync(() -> {
SteamwarUser user = SteamwarUser.get(userId);
addREntity(entityId, new RPlayer(entityServer, user.getUUID(), user.getUserName(), Config.SpecSpawn));
team.addEntry(user.getUserName());
});
}
private void entityMoves() throws IOException {
int entityId = source.readInt();
double x = source.readDouble() - arenaMinX;
double locY = source.readDouble() - arenaMinY + Config.BluePasteRegion.getMinY();
double z = source.readDouble() - arenaMinZ;
if(rotateZ) {
x = Config.ArenaRegion.getSizeX() - x;
z = Config.ArenaRegion.getSizeZ() - z;
}
double locX = x + Config.ArenaRegion.getMinX();
double locZ = z + Config.ArenaRegion.getMinZ();
float pitch = source.readFloat();
float yaw = source.readFloat() + (rotateZ ? 180 : 0);
byte headYaw = (byte)((source.readByte() + (rotateZ ? 128 : 0)) % 256);
execSync(() -> {
REntity entity = entities.get(entityId);
if(entity != null) {
entity.move(locX, locY, locZ, pitch, yaw, headYaw);
FightSystem.getHullHider().updateREntity(entity);
}
});
}
private void entityDespawns() throws IOException {
int entityId = source.readInt();
execSync(() -> {
REntity entity = entities.remove(entityId);
if(entity != null) {
FightSystem.getHullHider().despawnREntity(entity);
entity.die();
}
});
}
private void entitySneak() throws IOException {
int entityId = source.readInt();
boolean sneaking = source.readBoolean();
execSync(() -> entities.get(entityId).setPose(sneaking ? de.steamwar.core.FlatteningWrapper.EntityPose.SNEAKING : de.steamwar.core.FlatteningWrapper.EntityPose.NORMAL));
}
private void entityAnimation() throws IOException {
int entityId = source.readInt();
byte animation = source.readByte();
execSync(() -> entities.get(entityId).showAnimation(animation));
}
private void tntSpawn() throws IOException {
int entityId = source.readInt();
execSync(() -> addREntity(entityId, new REntity(entityServer, EntityType.PRIMED_TNT, Config.SpecSpawn)));
}
private void entityVelocity() throws IOException {
int entityId = source.readInt();
double dX = rotateZ ? -source.readDouble() : source.readDouble();
double dY = source.readDouble();
double dZ = rotateZ ? -source.readDouble() : source.readDouble();
execSync(() -> {
REntity entity = entities.get(entityId);
if(entity != null)
entity.setVelocity(dX, dY, dZ);
});
}
private void playerItem() throws IOException {
int entityId = source.readInt();
String item = source.readUTF();
boolean enchanted = source.readBoolean();
String slotName = source.readUTF();
ItemStack stack = new ItemStack(Material.valueOf(item.replace("minecraft:", "").toUpperCase()), 1);
if(enchanted)
stack.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
Object slot;
switch(slotName){
case "HEAD":
slot = de.steamwar.core.ProtocolWrapper.itemSlots[5];
break;
case "CHEST":
slot = de.steamwar.core.ProtocolWrapper.itemSlots[4];
break;
case "LEGS":
slot = de.steamwar.core.ProtocolWrapper.itemSlots[3];
break;
case "FEET":
slot = de.steamwar.core.ProtocolWrapper.itemSlots[2];
break;
case "OFFHAND":
slot = de.steamwar.core.ProtocolWrapper.itemSlots[1];
break;
case "MAINHAND":
default:
slot = de.steamwar.core.ProtocolWrapper.itemSlots[0];
}
execSync(() -> entities.get(entityId).setItem(slot, stack));
}
private void arrowSpawn() throws IOException {
int entityId = source.readInt();
execSync(() -> addREntity(entityId, new REntity(entityServer, EntityType.ARROW, Config.SpecSpawn)));
}
private void fireballSpawn() throws IOException {
int entityId = source.readInt();
execSync(() -> addREntity(entityId, new REntity(entityServer, EntityType.FIREBALL, Config.SpecSpawn)));
}
private void send(ChatMessageType type) throws IOException {
String message = source.readUTF();
BaseComponent[] text = TextComponent.fromLegacyText(message);
Bukkit.getOnlinePlayers().forEach(p -> de.steamwar.core.BountifulWrapper.impl.sendMessage(p, type, text));
}
private void countdown() throws IOException {
String message = source.readUTF();
int displaytime = source.readInt();
Message appendix = readMessage();
Bukkit.getOnlinePlayers().forEach(p -> Countdown.sendCountdownMessage(p, message, displaytime, appendix));
}
private void oldArenaInfo() throws IOException {
rotateZ = source.readBoolean() != Config.blueNegZ();
arenaMinY = Byte.toUnsignedInt(source.readByte());
arenaMinX = source.readInt();
arenaMinZ = source.readInt();
}
private void arenaInfo() throws IOException {
rotateZ = source.readBoolean() != Config.blueNegZ();
arenaMinX = source.readInt();
arenaMinY = source.readInt();
arenaMinZ = source.readInt();
}
private void shortBlock() throws IOException {
int x = Byte.toUnsignedInt(source.readByte()) + Config.ArenaRegion.getMinX();
int y = Byte.toUnsignedInt(source.readByte());
int z = Byte.toUnsignedInt(source.readByte()) + Config.ArenaRegion.getMinZ();
int blockState = source.readShort();
setBlock(x, y, z, blockState);
}
private void shortRelativeBlock() throws IOException {
int x = Byte.toUnsignedInt(source.readByte());
int y = Byte.toUnsignedInt(source.readByte());
int z = Byte.toUnsignedInt(source.readByte());
int blockState = source.readShort();
if(rotateZ) {
x = Config.ArenaRegion.getSizeX() - x;
z = Config.ArenaRegion.getSizeZ() - z;
}
setBlock(x + Config.ArenaRegion.getMinX(), y + Config.BluePasteRegion.getMinY(), z + Config.ArenaRegion.getMinZ(), blockState);
}
private void byteWorldHeightBlock() throws IOException {
int x = source.readInt() - arenaMinX;
int y = Byte.toUnsignedInt(source.readByte()) - arenaMinY;
int z = source.readInt() - arenaMinZ;
int blockState = source.readInt();
if(rotateZ) {
x = Config.ArenaRegion.getSizeX() - x;
z = Config.ArenaRegion.getSizeZ() - z;
}
setBlock(x + Config.ArenaRegion.getMinX(), y + Config.BluePasteRegion.getMinY(), z + Config.ArenaRegion.getMinZ(), blockState);
}
private void block() throws IOException {
int x = source.readInt() - arenaMinX;
int y = source.readShort() - arenaMinY;
int z = source.readInt() - arenaMinZ;
int blockState = source.readInt();
if(rotateZ) {
x = Config.ArenaRegion.getSizeX() - x;
z = Config.ArenaRegion.getSizeZ() - z;
}
setBlock(x + Config.ArenaRegion.getMinX(), y + Config.BluePasteRegion.getMinY(), z + Config.ArenaRegion.getMinZ(), blockState);
}
private void setBlock(int x, int y, int z, int blockState){
if(!Config.ArenaRegion.in2dRegion(x, z))
return; //Outside of the arena
execSync(() -> {
BlockIdWrapper.impl.setBlock(Config.world, x, y, z, TechHiderWrapper.ENABLED && hiddenBlockIds.contains(blockState) ? obfuscateWith : blockState);
FightSystem.getHullHider().blockUpdate(Config.world.getBlockAt(x, y, z), BlockIdWrapper.impl.idToMaterial(blockState));
});
}
private void particle() throws IOException {
double x = source.readDouble() - arenaMinX;
double y = source.readDouble() - arenaMinY;
double z = source.readDouble() - arenaMinZ;
String particleName = source.readUTF();
if(rotateZ) {
x = Config.ArenaRegion.getSizeX() - x;
z = Config.ArenaRegion.getSizeZ() - z;
}
double finalX = x;
double finalZ = z;
execSync(() -> BountifulWrapper.impl.spawnParticle(Config.world, particleName, finalX + Config.ArenaRegion.getMinX(), y + Config.BluePasteRegion.getMinY(), finalZ + Config.ArenaRegion.getMinZ()));
}
private void sound() throws IOException {
int rawX = source.readInt() - arenaMinX;
int y = source.readInt() - arenaMinY + Config.BluePasteRegion.getMinY();
int rawZ = source.readInt() - arenaMinZ;
if(rotateZ) {
rawX = Config.ArenaRegion.getSizeX() - rawX;
rawZ = Config.ArenaRegion.getSizeZ() - rawZ;
}
int x = rawX + Config.ArenaRegion.getMinX();
int z = rawZ + Config.ArenaRegion.getMinZ();
String soundName = source.readUTF();
String soundCategory = source.readUTF();
float volume = source.readFloat();
float pitch = source.readFloat();
Sound sound = Sound.valueOf(soundName);
execSync(() -> WorldOfColorWrapper.impl.playSound(new Location(Config.world, x, y, z), sound, soundCategory, volume, pitch));
}
private void soundAtPlayer() throws IOException {
String soundName = source.readUTF();
float volume = source.readFloat();
float pitch = source.readFloat();
Sound sound = Sound.valueOf(soundName);
execSync(() -> Fight.playSound(sound, volume, pitch));
}
private void pasteSchem(FightTeam team) throws IOException {
int schemId = source.readInt();
if(schemId == 0)
return;
execSync(() -> team.pasteSchem(SchematicNode.getSchematicNode(schemId)));
}
private void pasteEmbeddedSchem(FightTeam team) throws IOException {
int schemId = source.readInt();
Clipboard clipboard = SchematicData.clipboardFromStream(new FilterInputStream(source) {
@Override
public void close() {
// FAWE 1.12 calls close...
}
}, Core.getVersion() > 12);
execSync(() -> team.pasteSchem(schemId, clipboard));
}
private void teams() throws IOException {
int blueId = source.readInt();
int redId = source.readInt();
execSync(() -> {
pasteForTeam(blueId, Fight.getBlueTeam());
pasteForTeam(redId, Fight.getRedTeam());
});
}
private void pasteForTeam(int teamId, FightTeam fightTeam){
Team team = Team.get(teamId);
fightTeam.setPrefixAndName("§" + team.getTeamColor(), team.getTeamKuerzel());
fightTeam.pasteTeamName();
}
private void scoreboardTitle() throws IOException {
String title = source.readUTF();
FightScoreboard.getScoreboard().setTitle(title);
}
private void scoreboardData() throws IOException {
String key = source.readUTF();
int value = source.readInt();
FightScoreboard.getScoreboard().addScore(key, value);
}
private void bossBar() throws IOException {
double leftBlueProgress = source.readDouble();
double leftRedProgress = source.readDouble();
String leftBlueText = source.readUTF();
String leftRedText = source.readUTF();
FightUI.getInstance().setBossbar(leftBlueProgress, leftRedProgress, leftBlueText, leftRedText);
}
private void bossBarMessage() throws IOException {
double leftBlueProgress = source.readDouble();
double leftRedProgress = source.readDouble();
Message leftBlueText = readMessage();
Message leftRedText = readMessage();
FightUI.getInstance().setBossbar(leftBlueProgress, leftRedProgress, leftBlueText, leftRedText);
}
private void subtitle() throws IOException {
String subtitle = source.readUTF();
FightUI.addSubtitle("OLD_STRING", subtitle);
skipToSubtitle = false;
}
private void printWin() throws IOException {
String title = source.readUTF();
String subtitle = source.readUTF();
Bukkit.getOnlinePlayers().forEach(p -> {
p.resetTitle();
WorldOfColorWrapper.impl.sendTitle(p, title, subtitle, 5, 40, 5);
});
}
private void endReplay() {
HandlerList.unregisterAll(this);
entityServer.close();
entities.values().forEach(FightSystem.getHullHider()::despawnREntity);
entities.clear();
freezer.disable();
if(!Config.replayserver()) {
FightSystem.getMessage().broadcast("REPLAY_ENDS");
}
if (FightSystem.getLastWinner() != null) {
FightUI.getInstance().setBossbar(0.5, 0.5,
new Message("BAR_WIN", FightSystem.getLastWinner().getColoredName(), Fight.getBlueTeam().getColoredName(), Fight.getRedTeam().getColoredName(), ""),
new Message("BAR_WIN", FightSystem.getLastWinner().getColoredName(), Fight.getRedTeam().getColoredName(), Fight.getBlueTeam().getColoredName(), ""));
} else {
FightUI.getInstance().setBossbar(0.5, 0.5,
new Message("BAR_TIE", "", Fight.getBlueTeam().getColoredName(), Fight.getRedTeam().getColoredName()),
new Message("BAR_TIE", "", Fight.getRedTeam().getColoredName(), Fight.getBlueTeam().getColoredName()));
}
FightState.setFightState(FightState.SPECTATE);
currentProcessor = null;
task.cancel();
}
private void bow() throws IOException {
int entityId = source.readInt();
boolean drawn = source.readBoolean();
boolean offHand = source.readBoolean();
execSync(() -> entities.get(entityId).setBowDrawn(drawn, offHand));
}
private void damage() throws IOException {
int entityId = source.readInt();
execSync(() -> entities.get(entityId).showDamage());
}
private void fireTick() throws IOException {
int entityId = source.readInt();
boolean perma = source.readBoolean();
execSync(() -> entities.get(entityId).setOnFire(perma));
}
private void tick(){
execSync(entityServer::tick);
if(!source.async() && !skipToSubtitle)
tickFinished = true;
}
private void process(){
tickFinished = false;
try{
while(!source.isClosed() && !tickFinished){
int packetType = Byte.toUnsignedInt(source.readByte());
lastPackets.add(packetType);
if (lastPackets.size() > 10)
lastPackets.remove(0);
PacketParser parser = packetDecoder[packetType];
if(parser != null){
parser.process();
}else{
Bukkit.getLogger().log(Level.SEVERE, "Unknown packet " + packetType + " recieved, closing. LastPacket: " + Arrays.toString(lastPackets.toArray()));
source.close();
}
}
} catch (EOFException e) {
Bukkit.getLogger().log(Level.INFO, "The FightServer is offline");
source.close();
} catch(Exception e) {
Bukkit.getLogger().log(Level.WARNING, "Could not recieve packet, LastPacket: " + Arrays.toString(lastPackets.toArray()), e);
source.close();
}
if(source.isClosed()){
execSync(() -> Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::endReplay));
}
}
private Message readMessage() throws IOException {
String msg = source.readUTF();
List<Object> params = new ArrayList<>();
while(true) {
int type = source.readUnsignedByte();
switch(type) {
case 0x00:
return new Message(msg, params.toArray());
case 0x01:
params.add(source.readBoolean());
break;
case 0x02:
params.add(source.readByte());
break;
case 0x03:
params.add(source.readShort());
break;
case 0x04:
params.add(source.readInt());
break;
case 0x05:
params.add(source.readFloat());
break;
case 0x06:
params.add(source.readDouble());
break;
case 0x07:
params.add(source.readUTF());
break;
case 0x08:
params.add(readMessage());
break;
default:
throw new IOException("Unknown message param type " + type);
}
}
}
private interface PacketParser{
void process() throws IOException;
}
}
@@ -0,0 +1,46 @@
/*
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.record;
import org.bukkit.Bukkit;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
public abstract class PacketSource extends DataInputStream {
protected PacketSource(InputStream inputStream){
super(inputStream);
}
@Override
public void close(){
try {
super.close();
} catch (IOException e) {
Bukkit.getLogger().log(Level.SEVERE, "IOException on disable", e);
}
}
abstract boolean isClosed();
abstract boolean async();
}
@@ -0,0 +1,382 @@
/*
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.record;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
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.utils.BlockIdWrapper;
import de.steamwar.fightsystem.utils.CraftbukkitWrapper;
import de.steamwar.fightsystem.utils.Message;
import de.steamwar.fightsystem.utils.SWSound;
import de.steamwar.sql.NodeData;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import java.io.*;
import java.util.logging.Level;
public interface Recorder {
DataOutputStream getStream();
default void enable() {
GlobalRecorder.getInstance().add(this);
if(ArenaMode.Event.contains(Config.mode)){
teamIds(Config.EventTeamBlueID, Config.EventTeamRedID);
}
arenaInfo();
Fight.teams().forEach(this::enableTeam);
}
default void enableTeam(FightTeam team){
if(FightState.Schem.contains(FightState.getFightState())){
if(team.isBlue())
blueSchem(team.getSchematic());
else
redSchem(team.getSchematic());
}
if(FightState.AntiSpectate.contains(FightState.getFightState())){
for(FightPlayer player : team.getPlayers()){
if(player.isLiving()){
playerJoins(player.getEntity(), player.getUser());
}
}
}
}
default void disable() {
GlobalRecorder.getInstance().remove(this);
try {
getStream().close();
} catch (IOException e) {
Bukkit.getLogger().log(Level.SEVERE, "Could not close OutputStream", e);
}
}
/*
* PlayerJoinPacket (0x00) + int EntityId + int SWUserId
* EntityMovePacket (0x01) + int EntityId + double x, y, z + float pitch, yaw + byte headyaw
* EntityDespawnsPacket (0x02) + int EntityId
* PlayerSneakPacket (0x03) + int EntityId + boolean sneaks
* EntityAnimationPacket (0x04) + int EntityId + byte animation
* TNTSpawnPacket (0x05) + int EntityId
* EntitySpeedPacket (0x06) + int EntityId + double dx, dy, dz
* PlayerItemPacket (0x07) + int EntityId + String item + boolean enchanted + String slot
* ArrowSpawnPacket (0x08) + int EntityId
* FireballSpawnPacket (0x09) + int EntityId
* BowSpanPacket (0x0a) + int EntityId + boolean start + hand
* PlayerDamagePacket (0x0b) + int EntityId
* SetOnFire (0x0c) + int EntityId + boolean perma
*
* DEPRECATED ArenaInfo (0x20) + bool blueNegZ + byte arenaY + int arenaMinX + int arenaMinZ
* ArenaInfo (0x21) + bool blueNegZ + int arenaMinX + int arenaMinY + int arenaMinZ
*
* DEPRECATED BlockPacket (0x30) + pos int, byte, int + int BlockState
* ParticlePacket (0x31) + double x, y, z + string particleType
* SoundPacket (0x32) + int x, y, z + string soundType + string soundCategory + float volume, pitch
* DEPRECATED ShortBlockPacket (0x33) + pos relative to ArenaMinX,ArenaMinZ byte, byte, byte + short BlockState
* SoundAtPlayerPacket (0x34) + string (soundType, soundCategory) + float volume, pitch
* ShortBlockPacket (0x35) + pos relative to ArenaMinX,BluePasteY,ArenaMinZ byte, byte, byte + short BlockState
* BlockPacket (0x36) + pos int, short, int + int BlockState
*
*
* DEPRECATED ChatPacket (0xa0) + String message
* DEPRECATED ActionBarPacket (0xa1) + String message
* DEPRECATED SystemPacket (0xa2) + String message
* CountdownPacket (0xa3) + String message, int displaytime, Message appendix
* ChatPacket (0xa4) + Message
* SystemPacket (0xa5) + Message
*
* BlueSchemPacket (0xb0) + int blueSchemId
* RedSchemPacket (0xb1) + int redSchemId
* TeamIDPacket (0xb2) + int blueTeamId, redTeamId
* BlueEmbeddedSchemPacket (0xb3) + int blueSchemId + gzipt NBT blob
* RedEmbeddedSchemPacket (0xb4) + int redSchemId + gzipt NBT blob
*
* DEPRECATED ScoreboardTitlePacket (0xc0) + String scoreboardTitle
* DEPRECATED ScoreboardDataPacket (0xc1) + String key + int value
* DEPRECATED BossBarPacket (0xc2) + double leftBlueProgress, leftRedProgress + String leftBlueText, leftRedText
* DEPRECATED SubtitlePacket (0xc3) + String subtitle
* DEPRECATED PrintWinPacket (0xc4) + String title, subtitle
* SubtitlePacket (0xc5) + Message
* WinPacket (0xc6) + byte team + Message subtitle
* BossBarPacket (0xc7) + double leftBlueProgress, leftRedProgress + Message leftBlueText, leftRedText
*
* CommentPacket (0xfe) + String comment
* TickPacket (0xff)
*
* Message-Format
* String message + byte prefixed Object-Params + byte 0x00
* 0x00: End of message
* 0x01: boolean following
* 0x02: byte following
* 0x03: short following
* 0x04: int following
* 0x05: float following
* 0x06: double following
* 0x07: String following
* 0x08: Message following
* */
default void playerJoins(LivingEntity p, SteamwarUser user){
write(0x00, p.getEntityId(), user.getId());
entityMoves(p);
}
default void entityMoves(Entity e){
Location location = e.getLocation();
write(0x01, e.getEntityId(), location.getX(), location.getY(), location.getZ(), location.getPitch(), location.getYaw(), (byte) (CraftbukkitWrapper.impl.headRotation(e) * 256 / 360));
}
default void entityDespawns(Entity e){
write(0x02, e.getEntityId());
}
default void playerSneak(Player p, boolean sneaks){
write(0x03, p.getEntityId(), sneaks);
}
default void entityAnimation(Entity e, int animation){
write(0x04, e.getEntityId(), (byte)animation);
}
default void tntSpawn(Entity e){
write(0x05, e.getEntityId());
entityMoves(e);
entitySpeed(e);
}
default void entitySpeed(Entity e){
Vector velocity = e.getVelocity();
write(0x06, e.getEntityId(), velocity.getX(), velocity.getY(), velocity.getZ());
}
default void item(Player p, ItemStack item, String slot){
write(0x07, p.getEntityId(), "minecraft:" + item.getType().name().toLowerCase(), !item.getEnchantments().isEmpty(), slot);
}
default void arrowSpawn(Entity e){
write(0x08, e.getEntityId());
entityMoves(e);
entitySpeed(e);
if(e.getFireTicks() > 0)
setOnFire(e, true);
}
default void fireballSpawn(Entity e){
write(0x09, e.getEntityId());
entityMoves(e);
entitySpeed(e);
}
default void bowSpan(Entity e, boolean start, boolean offHand) {
write(0x0a, e.getEntityId(), start, offHand);
}
default void damageAnimation(Player p) {
write(0x0b, p.getEntityId());
}
default void setOnFire(Entity e, boolean perma) {
write(0x0c, e.getEntityId(), perma);
}
default void arenaInfo(){
write(0x21, Config.blueNegZ(), Config.ArenaRegion.getMinX(), Config.BluePasteRegion.getMinY(), Config.ArenaRegion.getMinZ());
}
default void blockChange(Block block){
int blockState = BlockIdWrapper.impl.blockToId(block);
int shortX = block.getX() - Config.ArenaRegion.getMinX();
int shortY = block.getY() - Config.BluePasteRegion.getMinY();
int shortZ = block.getZ() - Config.ArenaRegion.getMinZ();
if((short)blockState == blockState && shortX >= 0 && shortX < 256 && shortY >= 0 && shortZ >= 0 && shortZ < 256){
//Short block packet
write(0x35, (byte)shortX, (byte)shortY, (byte)shortZ, (short)blockState);
}else{
//Block packet
write(0x36, block.getX(), (short)block.getY(), block.getZ(), blockState);
}
}
default void particle(double x, double y, double z, String particleType){
write(0x31, x, y, z, particleType);
}
default void sound(int x, int y, int z, SWSound soundType, String soundCategory, float volume, float pitch){
write(0x32, x, y, z, soundType.getSound().name(), soundCategory, volume, pitch);
}
default void soundAtPlayer(String soundType, float volume, float pitch){
write(0x34, soundType, volume, pitch);
}
default void countdown(String message, int displaytime, Message appendix) {
write(0xa3, message, displaytime, appendix);
}
default void chat(String msg, Object... params) {
write(0xa4, new Message(msg, params));
}
default void system(String msg, Object... params) {
write(0xa5, new Message(msg, params));
}
default void teamIds(int blueTeamId, int redTeamId) {
write(0xb2, blueTeamId, redTeamId);
}
default void blueSchem(int schemId) {
schem(0xb3, 0xb0, schemId);
}
default void redSchem(int schemId) {
schem(0xb4, 0xb1, schemId);
}
default void schem(int embedId, int noEmbedId, int schemId){
if(schemId == 0) {
write(noEmbedId, schemId);
return;
}
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
try{
copy(NodeData.get(SchematicNode.getSchematicNode(schemId)).schemData(), buffer);
}catch (EOFException e) {
Bukkit.getLogger().log(Level.INFO, "EOFException ignored");
} catch (IOException e) {
Bukkit.getLogger().log(Level.SEVERE, "Could not embed schematic", e);
disable();
return;
}
write(embedId, schemId, buffer.toByteArray());
}
static void copy(InputStream input, OutputStream output) throws IOException {
int bytes;
for(byte[] buffer = new byte[8192]; (bytes = input.read(buffer)) > 0;) {
output.write(buffer, 0, bytes);
}
}
default void bossBar(double leftBlueProgress, double leftRedProgress, Message leftBlueText, Message leftRedText) {
write(0xc7, leftBlueProgress, leftRedProgress, leftBlueText, leftRedText);
}
default void subtitle(Message subtitle) {
write(0xc5, subtitle);
}
default void winMessage(FightTeam team, String subtitle, Object... params) {
byte bTeam = 0x00;
if(team != null) {
bTeam = (byte) (team.isBlue() ? 0x01 : 0x02);
}
write(0xc6, bTeam, new Message(subtitle, params));
}
default void tick(){
write(0xff);
}
default void write(int id, Object... objects){
DataOutputStream stream = getStream();
synchronized (stream) {
try {
stream.writeByte(id);
for(Object o : objects) {
writeObject(stream, o);
}
stream.flush();
} catch (IOException e) {
Bukkit.getLogger().log(Level.SEVERE, "Could not write", e);
disable();
}
}
}
default void writeObject(DataOutputStream stream, Object o) throws IOException {
if(o instanceof Boolean)
stream.writeBoolean((Boolean)o);
else if(o instanceof Byte)
stream.writeByte((Byte)o);
else if(o instanceof Short)
stream.writeShort((Short)o);
else if(o instanceof Integer)
stream.writeInt((Integer)o);
else if(o instanceof Float)
stream.writeFloat((Float)o);
else if(o instanceof Double)
stream.writeDouble((Double)o);
else if(o instanceof String)
stream.writeUTF((String)o);
else if(o instanceof byte[])
stream.write((byte[])o);
else if(o instanceof Message)
writeMessage(stream, (Message) o);
else
throw new SecurityException("Undefined write for: " + o.getClass().getName());
}
default void writeMessage(DataOutputStream stream, Message message) throws IOException {
stream.writeUTF(message.getMsg());
for(Object o : message.getParams()) {
if(o instanceof Boolean)
stream.writeByte(0x01);
else if(o instanceof Byte)
stream.writeByte(0x02);
else if(o instanceof Short)
stream.writeByte(0x03);
else if(o instanceof Integer)
stream.writeByte(0x04);
else if(o instanceof Float)
stream.writeByte(0x05);
else if(o instanceof Double)
stream.writeByte(0x06);
else if(o instanceof String)
stream.writeByte(0x07);
else if(o instanceof Message)
stream.writeByte(0x08);
else
throw new SecurityException("Undefined message serialization for: " + o.getClass().getName());
writeObject(stream, o);
}
stream.writeByte(0x00);
}
}
@@ -0,0 +1,94 @@
/*
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.states;
import lombok.Getter;
import java.util.*;
public enum FightState {
PRE_LEADER_SETUP,
PRE_SCHEM_SETUP,
POST_SCHEM_SETUP,
PRE_RUNNING,
RUNNING,
SPECTATE;
public static final Set<FightState> All = Collections.unmodifiableSet(EnumSet.allOf(FightState.class));
public static final Set<FightState> PreLeaderSetup = Collections.unmodifiableSet(EnumSet.of(PRE_LEADER_SETUP));
public static final Set<FightState> PreSchemSetup = Collections.unmodifiableSet(EnumSet.of(PRE_SCHEM_SETUP));
public static final Set<FightState> PostSchemSetup = Collections.unmodifiableSet(EnumSet.of(POST_SCHEM_SETUP));
public static final Set<FightState> PreRunning = Collections.unmodifiableSet(EnumSet.of(PRE_RUNNING));
public static final Set<FightState> Running = Collections.unmodifiableSet(EnumSet.of(RUNNING));
public static final Set<FightState> Spectate = Collections.unmodifiableSet(EnumSet.of(SPECTATE));
public static final Set<FightState> Setup = Collections.unmodifiableSet(EnumSet.of(PRE_LEADER_SETUP, PRE_SCHEM_SETUP, POST_SCHEM_SETUP));
public static final Set<FightState> Ingame = Collections.unmodifiableSet(EnumSet.of(PRE_RUNNING, RUNNING));
public static final Set<FightState> TeamFix = Collections.unmodifiableSet(EnumSet.of(PRE_RUNNING, RUNNING, SPECTATE));
public static final Set<FightState> Schem = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(PRE_LEADER_SETUP, PRE_SCHEM_SETUP)));
public static final Set<FightState> Recording = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(PRE_LEADER_SETUP, PRE_SCHEM_SETUP, SPECTATE)));
public static final Set<FightState> AntiRunning = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(RUNNING)));
public static final Set<FightState> AntiIngame = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(PRE_RUNNING, RUNNING)));
public static final Set<FightState> AntiSpectate = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(SPECTATE)));
private static final Map<IStateDependent, Boolean> stateDependentFeatures = new HashMap<>();
@Getter
private static FightState fightState = PRE_LEADER_SETUP;
public static void registerStateDependent(IStateDependent stateDependent){
if(stateDependent.enabled().isEmpty())
return;
boolean enabled = stateDependent.enabled().contains(fightState);
stateDependentFeatures.put(stateDependent, enabled);
if(enabled)
stateDependent.enable();
}
public static void setFightState(FightState state){
fightState = state;
for(Map.Entry<IStateDependent, Boolean> feature : stateDependentFeatures.entrySet()){
//Enable feature if should be enabled and currently disabled
if(feature.getKey().enabled().contains(fightState) && !feature.getValue()){
feature.getKey().enable();
feature.setValue(true);
}
//Disable feature if should be disabled and currently enabled
if(!feature.getKey().enabled().contains(fightState) && feature.getValue()){
feature.getKey().disable();
feature.setValue(false);
}
}
}
public static boolean setup(){
return Setup.contains(fightState);
}
public static boolean ingame(){
return Ingame.contains(fightState);
}
public static boolean infight(){
return fightState == RUNNING;
}
}
@@ -0,0 +1,40 @@
/*
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.states;
import java.util.Set;
public interface IStateDependent {
/**
* @return returns a set containing
*/
Set<FightState> enabled();
/**
* Enables the state dependent object
*/
void enable();
/**
* Disables the state dependent object
*/
void disable();
}
@@ -0,0 +1,59 @@
/*
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.states;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.winconditions.Winconditions;
import java.util.Set;
public class OneShotStateDependent extends StateDependent{
private final Runnable runnable;
public OneShotStateDependent(Set<ArenaMode> mode, Set<FightState> states, Runnable runnable) {
super(mode, states);
this.runnable = runnable;
register();
}
public OneShotStateDependent(Winconditions wincondition, Set<FightState> states, Runnable runnable) {
super(Config.ActiveWinconditions.contains(wincondition), states);
this.runnable = runnable;
register();
}
public OneShotStateDependent(boolean active, Set<FightState> states, Runnable runnable) {
super(active, states);
this.runnable = runnable;
register();
}
@Override
public void enable() {
runnable.run();
}
@Override
public void disable() {
//Do nothing, oneshot
}
}
@@ -0,0 +1,55 @@
/*
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.states;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.winconditions.Winconditions;
import java.util.Set;
public abstract class StateDependent implements IStateDependent {
private final Set<FightState> enabled;
private final boolean register;
protected StateDependent(Winconditions wincondition, Set<FightState> states){
this(Config.ActiveWinconditions.contains(wincondition), states);
}
protected StateDependent(Set<ArenaMode> mode, Set<FightState> states){
this(mode.contains(Config.mode), states);
}
protected StateDependent(boolean enabled, Set<FightState> states){
this.enabled = states;
this.register = enabled;
}
public void register(){
if(register)
FightState.registerStateDependent(this);
}
@Override
public Set<FightState> enabled() {
return enabled;
}
}
@@ -0,0 +1,58 @@
/*
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.states;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.FightSystem;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.PluginCommand;
import java.util.Set;
public class StateDependentCommand extends StateDependent {
private static final CommandExecutor unavailable = (sender, cmd, s, strings) -> {
FightSystem.getMessage().sendPrefixless("COMMAND_CURRENTLY_UNAVAILABLE", sender, ChatMessageType.ACTION_BAR);
return false;
};
private final PluginCommand command;
private final CommandExecutor executor;
public StateDependentCommand(Set<ArenaMode> mode, Set<FightState> states, String name, CommandExecutor executor) {
super(mode, states);
this.executor = executor;
this.command = FightSystem.getPlugin().getCommand(name);
assert command != null;
disable();
register();
}
@Override
public void enable() {
command.setExecutor(executor);
}
@Override
public void disable() {
command.setExecutor(unavailable);
}
}

Some files were not shown because too many files have changed in this diff Show More