SteamWar/FightSystem
Archiviert
13
1

RecordSystem (Beta) #199

Manuell gemergt
Lixfel hat 40 Commits von recordSystem nach master 2020-11-01 20:11:45 +01:00 zusammengeführt
31 geänderte Dateien mit 307 neuen und 171 gelöschten Zeilen
Nur Änderungen aus Commit b73bc9ad5e werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -24,9 +24,10 @@ public class Config {
public static final int PreSchemPasteDuration; public static final int PreSchemPasteDuration;
public static final int SetupDuration; public static final int SetupDuration;
public static final int PreFightDuration; public static final int PreFightDuration;
public static final int EnterPhaseBegin;
public static final int SpectatorDuration; public static final int SpectatorDuration;
public static final boolean Entern;
// entern parameter
public static final List<Integer> EnterStages;
//arena parameter //arena parameter
public static final int SchemsizeX; public static final int SchemsizeX;
@ -81,6 +82,7 @@ public class Config {
public static final String TeamChatDetection; public static final String TeamChatDetection;
public static final UUID BlueLeader; public static final UUID BlueLeader;
public static final UUID RedLeader; public static final UUID RedLeader;
public static final boolean Ranked;
//Active win conditions //Active win conditions
public static final boolean Timeout; public static final boolean Timeout;
@ -183,16 +185,16 @@ public class Config {
PercentSystem = config.getBoolean("WinConditions.PercentSystem"); PercentSystem = config.getBoolean("WinConditions.PercentSystem");
RelativePercent = config.getBoolean("WinConditions.RelativePercent"); RelativePercent = config.getBoolean("WinConditions.RelativePercent");
Points = config.getBoolean("WinConditions.Points"); Points = config.getBoolean("WinConditions.Points");
Entern = config.getBoolean("WinConditions.Entern");
TechKO = config.getBoolean("WinConditions.TechKO"); TechKO = config.getBoolean("WinConditions.TechKO");
WaterTechKO = config.getBoolean("WinConditions.WaterTechKO"); WaterTechKO = config.getBoolean("WinConditions.WaterTechKO");
PumpkinTechKO = config.getBoolean("WinConditions.PumpkinTechKO"); PumpkinTechKO = config.getBoolean("WinConditions.PumpkinTechKO");
TimeoutTime = config.getInt("WinConditionParams.TimeoutTime"); TimeoutTime = config.getInt("WinConditionParams.TimeoutTime");
EnterPhaseBegin = config.getInt("WinConditionParams.EnterPhaseBegin");
PercentWin = config.getDouble("WinConditionParams.PercentWin"); PercentWin = config.getDouble("WinConditionParams.PercentWin");
IgnoredBlocks = Collections.unmodifiableList(config.getStringList("WinConditionParams.IgnoredBlocks")); IgnoredBlocks = Collections.unmodifiableList(config.getStringList("WinConditionParams.IgnoredBlocks"));
EnterStages = Collections.unmodifiableList(config.getIntegerList("EnterStages"));
MemberDefault = config.getString("Kits.MemberDefault"); MemberDefault = config.getString("Kits.MemberDefault");
LeaderDefault = config.getString("Kits.LeaderDefault"); LeaderDefault = config.getString("Kits.LeaderDefault");
PersonalKits = config.getBoolean("Kits.PersonalKits"); PersonalKits = config.getBoolean("Kits.PersonalKits");
@ -372,6 +374,7 @@ public class Config {
RedLeader = null; RedLeader = null;
CheckSchemID = Integer.parseInt(System.getProperty("checkSchemID", "0")); CheckSchemID = Integer.parseInt(System.getProperty("checkSchemID", "0"));
Ranked = Boolean.parseBoolean(System.getProperty("ranked", "false"));
} }
public static boolean event(){ public static boolean event(){

Datei anzeigen

@ -11,7 +11,6 @@ public class IFightSystem {
private static Plugin plugin; private static Plugin plugin;
private static String prefix; private static String prefix;
private static EventFight eventFight; private static EventFight eventFight;
private static boolean entern = false;
private static Player eventLeiter; private static Player eventLeiter;
public static void init(Plugin plugin, String prefix){ public static void init(Plugin plugin, String prefix){
@ -21,9 +20,6 @@ public class IFightSystem {
static void setEventFight(EventFight ef){ static void setEventFight(EventFight ef){
eventFight = ef; eventFight = ef;
} }
static void setEntern(boolean entern){
IFightSystem.entern = entern;
}
static void setEventLeiter(Player el){ static void setEventLeiter(Player el){
eventLeiter = el; eventLeiter = el;
} }
@ -37,9 +33,6 @@ public class IFightSystem {
public static EventFight getEventFight(){ public static EventFight getEventFight(){
return eventFight; return eventFight;
} }
public static boolean isEntern(){
return entern;
}
public static Player getEventLeiter(){ public static Player getEventLeiter(){
return eventLeiter; return eventLeiter;
} }

Datei anzeigen

@ -6,4 +6,5 @@ public interface IFightTeam {
boolean isBlue(); boolean isBlue();
boolean isPlayerInTeam(Player player); boolean isPlayerInTeam(Player player);
boolean canPlayerEntern(Player player);
} }

Datei anzeigen

@ -70,13 +70,13 @@ public class ITechHider {
arenaMinZ > chunkZ || arenaMinZ > chunkZ ||
chunkZ > arenaMaxZ; chunkZ > arenaMaxZ;
}else if(ft.isBlue()){ }else if(ft.isBlue()){
return IFightSystem.isEntern() || return ft.canPlayerEntern(p) ||
redMinX > chunkX || redMinX > chunkX ||
chunkX > redMaxX || chunkX > redMaxX ||
redMinZ > chunkZ || redMinZ > chunkZ ||
chunkZ > redMaxZ; chunkZ > redMaxZ;
}else{ }else{
return IFightSystem.isEntern() || return ft.canPlayerEntern(p) ||
blueMinX > chunkX || blueMinX > chunkX ||
chunkX > blueMaxX || chunkX > blueMaxX ||
blueMinZ > chunkZ || blueMinZ > chunkZ ||

Datei anzeigen

@ -22,7 +22,6 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.logging.Level; import java.util.logging.Level;
@ -76,9 +75,12 @@ public class FightSystem extends JavaPlugin {
new CheckListener(); new CheckListener();
new TestListener(); new TestListener();
new NormalJoinListener(); new NormalJoinListener();
new RankedJoinListener();
if(Core.getVersion() > 8) if(Core.getVersion() > 8)
new ExtendedInventoryListener(); new ExtendedInventoryListener();
new EnterHandler();
new WinconditionAllDead(); new WinconditionAllDead();
new WinconditionCaptainDead(); new WinconditionCaptainDead();
new WinconditionPumpkinTechKO(); new WinconditionPumpkinTechKO();
@ -103,7 +105,7 @@ public class FightSystem extends JavaPlugin {
mainCountdown = new NoPlayersOnlineCountdown(); mainCountdown = new NoPlayersOnlineCountdown();
if(Config.event()) { if(Config.event() || Config.Ranked) {
Objects.requireNonNull(getCommand("invite")).setExecutor(new EventDummyCommand()); Objects.requireNonNull(getCommand("invite")).setExecutor(new EventDummyCommand());
Objects.requireNonNull(getCommand("ready")).setExecutor(new EventDummyCommand()); Objects.requireNonNull(getCommand("ready")).setExecutor(new EventDummyCommand());
Objects.requireNonNull(getCommand("ak")).setExecutor(new EventDummyCommand()); Objects.requireNonNull(getCommand("ak")).setExecutor(new EventDummyCommand());
@ -175,33 +177,13 @@ public class FightSystem extends JavaPlugin {
setFightState(FightState.RUNNING); setFightState(FightState.RUNNING);
setAllPlayersGM(GameMode.SURVIVAL); setAllPlayersGM(GameMode.SURVIVAL);
if(Config.Entern)
mainCountdown = new EnternCountdown();
FightStatistics.start(); FightStatistics.start();
WaterRemover.init();
Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!"); Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!");
} }
public static void setEntern() {
if(fightState != FightState.RUNNING)
throw new SecurityException(fightState.name());
setFightState(FightState.ENTERN);
final List<ITechHider.ChunkPos> chunksBlue = TechHider.prepareChunkReload(Fight.getBlueTeam().getPlayers().iterator().next().getPlayer());
final List<ITechHider.ChunkPos> chunksRed = TechHider.prepareChunkReload(Fight.getRedTeam().getPlayers().iterator().next().getPlayer());
IFightSystem.setEntern(true);
for(FightPlayer player : Fight.getBlueTeam().getPlayers()){
TechHider.reloadChunks(player.getPlayer(), chunksBlue);
}
for(FightPlayer player : Fight.getRedTeam().getPlayers()){
TechHider.reloadChunks(player.getPlayer(), chunksRed);
}
}
public static void setSpectateState(FightTeam winFightTeam, String windescription) { public static void setSpectateState(FightTeam winFightTeam, String windescription) {
if(!fightState.ingame()) if(fightState == FightState.SPECTATE)
throw new SecurityException(fightState.name()); return;
setFightState(FightState.SPECTATE); setFightState(FightState.SPECTATE);
setAllPlayersGM(GameMode.SPECTATOR); setAllPlayersGM(GameMode.SPECTATOR);
@ -217,10 +199,10 @@ public class FightSystem extends JavaPlugin {
Bukkit.broadcastMessage(PREFIX + "§aKein Team hat gewonnen!"); Bukkit.broadcastMessage(PREFIX + "§aKein Team hat gewonnen!");
} }
if(Config.event()){ if(Config.event()) {
if(winFightTeam == null) if (winFightTeam == null)
getEventFight().setErgebnis(0); getEventFight().setErgebnis(0);
else if(winFightTeam.isBlue()) else if (winFightTeam.isBlue())
getEventFight().setErgebnis(1); getEventFight().setErgebnis(1);
else else
getEventFight().setErgebnis(2); getEventFight().setErgebnis(2);

Datei anzeigen

@ -59,7 +59,7 @@ public abstract class Countdown {
BasicListener.toActionbar(p, msg); BasicListener.toActionbar(p, msg);
} }
private void count(){ void count(){
switch (time) { switch (time) {
case 900: case 600: case 300: case 180: case 120: case 900: case 600: case 300: case 180: case 120:
broadcast("§rNoch §a" + time / 60 + " §rMinuten " + countdownCounting()); broadcast("§rNoch §a" + time / 60 + " §rMinuten " + countdownCounting());

Datei anzeigen

@ -1,13 +1,24 @@
package de.steamwar.fightsystem.countdown; package de.steamwar.fightsystem.countdown;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.Config;
import org.bukkit.Bukkit; import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.listener.BasicListener;
import de.steamwar.fightsystem.utils.ITechHider;
import de.steamwar.fightsystem.utils.TechHider;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.entity.Player;
import java.util.List;
public class EnternCountdown extends Countdown { public class EnternCountdown extends Countdown {
public EnternCountdown() { private final FightPlayer fightPlayer;
super(Config.EnterPhaseBegin, SWSound.BLOCK_NOTE_PLING, false); private List<ITechHider.ChunkPos> chunkPos;
public EnternCountdown(FightPlayer fp) {
super(fp.getKit().getEnterStage(), SWSound.BLOCK_NOTE_PLING, false);
fightPlayer = fp;
} }
@Override @Override
@ -17,7 +28,42 @@ public class EnternCountdown extends Countdown {
@Override @Override
public void countdownFinished() { public void countdownFinished() {
FightSystem.setEntern(); fightPlayer.getPlayer().sendMessage(FightSystem.PREFIX + "§aEntern ist nun erlaubt!");
Bukkit.broadcastMessage(FightSystem.PREFIX + "§aEntern ist nun erlaubt!"); TechHider.reloadChunks(fightPlayer.getPlayer(), chunkPos);
}
@Override
void count(){
if(!fightPlayer.isLiving()){
disable();
return;
}
Player player = fightPlayer.getPlayer();
int time = FightSystem.getFightTime() - Config.EnterStages.get(fightPlayer.getKit().getEnterStage());
switch (time) {
case 900: case 600: case 300: case 180: case 120:
BasicListener.toActionbar(player, TextComponent.fromLegacyText("§rNoch §a" + time / 60 + " §rMinuten " + countdownCounting()));
break;
case 60: case 30: case 20: case 15: case 10: case 5: case 4: case 3: case 2:
player.playSound(player.getLocation(), Countdown.getSound(SWSound.BLOCK_NOTE_PLING), 100.0F, 1.0F);
BasicListener.toActionbar(player, TextComponent.fromLegacyText("§rNoch §a" + time + " §rSekunden " + countdownCounting()));
break;
case 1:
player.playSound(player.getLocation(), Countdown.getSound(SWSound.BLOCK_NOTE_PLING), 100.0F, 1.0F);
BasicListener.toActionbar(player, TextComponent.fromLegacyText("§rNoch §a1 §rSekunde " + countdownCounting()));
chunkPos = TechHider.prepareChunkReload(player);
break;
case 0:
player.playSound(player.getLocation(), Countdown.getSound(SWSound.BLOCK_NOTE_PLING), 100.0F, 2.0F);
disable();
countdownFinished();
break;
default:
}
} }
} }

Datei anzeigen

@ -122,7 +122,7 @@ public class Fight {
return; return;
} }
if(Config.IgnorePublicOnly || Config.event()){ if(Config.IgnorePublicOnly || Config.event() || Config.Ranked){
schemRank = 1000; schemRank = 1000;
return; return;
} }

Datei anzeigen

@ -1,5 +1,6 @@
package de.steamwar.fightsystem.fight; package de.steamwar.fightsystem.fight;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.kit.KitManager; import de.steamwar.fightsystem.kit.KitManager;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.kit.Kit; import de.steamwar.fightsystem.kit.Kit;
@ -62,4 +63,10 @@ public class FightPlayer {
public void addKill(){ public void addKill(){
kills++; kills++;
} }
public boolean canEntern(){
if(Config.EnterStages.size() <= kit.getEnterStage() || kit.getEnterStage() < 0)
return false;
return Config.EnterStages.get(kit.getEnterStage()) >= FightSystem.getFightTime();
}
} }

Datei anzeigen

@ -8,6 +8,7 @@ import de.steamwar.fightsystem.IFightSystem;
import de.steamwar.fightsystem.kit.KitManager; import de.steamwar.fightsystem.kit.KitManager;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.utils.*; import de.steamwar.fightsystem.utils.*;
import de.steamwar.fightsystem.winconditions.RankedPlayerLeftWincondition;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.NoClipboardException;
import de.steamwar.sql.PersonalKit; import de.steamwar.sql.PersonalKit;
@ -127,6 +128,11 @@ public class FightTeam implements IFightTeam{
return false; return false;
} }
@Override
public boolean canPlayerEntern(Player player) {
return getFightPlayer(player).canEntern();
}
public boolean isPlayerLeader(Player player) { public boolean isPlayerLeader(Player player) {
if(leader != null) if(leader != null)
return leader.getPlayer().equals(player); return leader.getPlayer().equals(player);
@ -186,19 +192,20 @@ public class FightTeam implements IFightTeam{
} }
public void setLeader(FightPlayer leader) { public void setLeader(FightPlayer leader) {
this.leader = leader;
if(ready && leader != null)
setReady(false);
if (leader == null){ if (leader == null){
if(!players.isEmpty()) { if(!players.isEmpty()) {
setLeader(players.iterator().next()); setLeader(players.iterator().next());
Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §e" + this.leader.getPlayer().getName() + " §aist nun Leader von Team " + getColoredName() + "§a!"); Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §e" + this.leader.getPlayer().getName() + " §aist nun Leader von Team " + getColoredName() + "§a!");
}else if(Config.Ranked){
RankedPlayerLeftWincondition.leaderQuit(this);
}else if(!Config.event()){ }else if(!Config.event()){
FightSystem.shutdown(FightSystem.PREFIX + "§cTeam " + getColoredName() + " §chat keine Spieler mehr.\n Arena schließt..."); FightSystem.shutdown(FightSystem.PREFIX + "§cTeam " + getColoredName() + " §chat keine Spieler mehr.\n Arena schließt...");
} }
return; return;
} }
this.leader = leader;
if(ready)
setReady(false);
leader.setKit(KitManager.getKitByName(Config.LeaderDefault)); leader.setKit(KitManager.getKitByName(Config.LeaderDefault));
Inventory inventory = leader.getPlayer().getInventory(); Inventory inventory = leader.getPlayer().getInventory();
@ -209,7 +216,7 @@ public class FightTeam implements IFightTeam{
else else
inventory.setItem(1, new ItemBuilder(Material.AIR).build()); inventory.setItem(1, new ItemBuilder(Material.AIR).build());
if(!Config.event()){ if(!Config.event() && !Config.Ranked){
inventory.setItem(2, new ItemBuilder(Material.PAPER).removeAllAttributs().setDisplayName("§eSpieler einladen").build()); inventory.setItem(2, new ItemBuilder(Material.PAPER).removeAllAttributs().setDisplayName("§eSpieler einladen").build());
inventory.setItem(3, new ItemBuilder(SWItem.getMaterial("FIREWORK_CHARGE")).removeAllAttributs().setDisplayName("§cSpieler rauswerfen").build()); inventory.setItem(3, new ItemBuilder(SWItem.getMaterial("FIREWORK_CHARGE")).removeAllAttributs().setDisplayName("§cSpieler rauswerfen").build());
} }

Datei anzeigen

@ -21,6 +21,8 @@ public class Kit {
private final ItemStack[] inventory; private final ItemStack[] inventory;
private final ItemStack[] armor; private final ItemStack[] armor;
private final Collection<PotionEffect> effects; private final Collection<PotionEffect> effects;
private final int enterStage;
private final boolean tnt;
Kit(String name, Player player) { Kit(String name, Player player) {
this.name = name; this.name = name;
@ -29,13 +31,15 @@ public class Kit {
this.inventory = player.getInventory().getContents(); this.inventory = player.getInventory().getContents();
this.armor = player.getInventory().getArmorContents(); this.armor = player.getInventory().getArmorContents();
this.effects = player.getActivePotionEffects(); this.effects = player.getActivePotionEffects();
this.enterStage = 0;
this.tnt = true;
} }
Kit(ConfigurationSection kit){ Kit(ConfigurationSection kit){
name = kit.getName(); name = kit.getName();
inventory = Objects.requireNonNull(kit.getList("Items")).toArray(new ItemStack[1]); inventory = Objects.requireNonNull(kit.getList("Items")).toArray(new ItemStack[0]);
if(kit.isList("Armor")) if(kit.isList("Armor"))
armor = Objects.requireNonNull(kit.getList("Armor")).toArray(new ItemStack[1]); armor = Objects.requireNonNull(kit.getList("Armor")).toArray(new ItemStack[0]);
else else
armor = null; armor = null;
leaderAllowed = kit.getBoolean("LeaderAllowed"); leaderAllowed = kit.getBoolean("LeaderAllowed");
@ -44,6 +48,8 @@ public class Kit {
effects = (Collection<PotionEffect>) kit.getList("Effects"); effects = (Collection<PotionEffect>) kit.getList("Effects");
else else
effects = null; effects = null;
enterStage = kit.getInt("EnterStage", 0);
tnt = kit.getBoolean("TNT", true);
} }
public String getName() { public String getName() {
@ -58,6 +64,16 @@ public class Kit {
return memberAllowed; return memberAllowed;
} }
/* Is this kit allowed to set/handle tnt? */
public boolean isTnt(){
return tnt;
}
/* In which stage is entern allowed? */
public int getEnterStage() {
return enterStage;
}
public boolean isStackInKit(ItemStack stack){ public boolean isStackInKit(ItemStack stack){
for(ItemStack is : inventory){ for(ItemStack is : inventory){
if(stack.equals(is)) if(stack.equals(is))
@ -88,6 +104,8 @@ public class Kit {
section.set("LeaderAllowed", leaderAllowed); section.set("LeaderAllowed", leaderAllowed);
section.set("MemberAllowed", memberAllowed); section.set("MemberAllowed", memberAllowed);
section.set("Effects", effects); section.set("Effects", effects);
section.set("EnterStage", enterStage);
section.set("TNT", tnt);
} }
/** /**
@ -127,8 +145,7 @@ public class Kit {
} }
} }
inv.setCallback(-999, (click) -> GUI.kitSelection(player)); inv.setCallback(-999, (click) -> player.closeInventory());
inv.addCloseCallback((click) -> GUI.kitSelection(player));
inv.setItem(45, SWItem.getDye(10), (byte)10, "§aKit wählen", (click) -> { inv.setItem(45, SWItem.getDye(10), (byte)10, "§aKit wählen", (click) -> {
Commands.kit(player, name); Commands.kit(player, name);
player.closeInventory(); player.closeInventory();

Datei anzeigen

@ -15,8 +15,7 @@ import java.util.logging.Level;
public class KitManager { public class KitManager {
private KitManager(){} private KitManager(){}
private static final String KITS_PATH = "plugins/" + FightSystem.getPlugin().getName() + "/kits.data"; private static final File kits = new File(FightSystem.getPlugin().getDataFolder(), "kits.data");
private static final File kits = new File(KITS_PATH);
private static final FileConfiguration kitData = YamlConfiguration.loadConfiguration(kits); private static final FileConfiguration kitData = YamlConfiguration.loadConfiguration(kits);
private static final ArrayList<Kit> loadedKits = new ArrayList<>(); private static final ArrayList<Kit> loadedKits = new ArrayList<>();
@ -49,7 +48,7 @@ public class KitManager {
} }
public static void loadAllKits() { public static void loadAllKits() {
if(!new File(KITS_PATH).exists()) { if(!kits.exists()) {
saveAllKits(); saveAllKits();
Bukkit.getLogger().log(Level.INFO, "kits.data erstellt!"); Bukkit.getLogger().log(Level.INFO, "kits.data erstellt!");
FightSystem.shutdown(null); FightSystem.shutdown(null);

Datei anzeigen

@ -10,7 +10,7 @@ import java.util.EnumSet;
public class EntityExplodeListener extends BasicListener { public class EntityExplodeListener extends BasicListener {
public EntityExplodeListener() { public EntityExplodeListener() {
super(EnumSet.of(FightState.RUNNING, FightState.ENTERN)); super(EnumSet.of(FightState.RUNNING));
} }
@EventHandler @EventHandler

Datei anzeigen

@ -15,7 +15,7 @@ import java.util.Objects;
public class InFightDamageListener extends BasicListener { public class InFightDamageListener extends BasicListener {
public InFightDamageListener() { public InFightDamageListener() {
super(EnumSet.of(FightState.RUNNING, FightState.ENTERN)); super(EnumSet.of(FightState.RUNNING));
} }
@EventHandler @EventHandler
@ -44,8 +44,6 @@ public class InFightDamageListener extends BasicListener {
//Shooter is not a player //Shooter is not a player
return; return;
damagerArrow.setFireTicks(0);
player.setFireTicks(0);
damager = (Player) damagerArrow.getShooter(); damager = (Player) damagerArrow.getShooter();
}else{ }else{
//Damager is not a player //Damager is not a player
@ -60,6 +58,10 @@ public class InFightDamageListener extends BasicListener {
if(Fight.getPlayerTeam(player) == Fight.getPlayerTeam(damager)) { if(Fight.getPlayerTeam(player) == Fight.getPlayerTeam(damager)) {
event.setCancelled(true); event.setCancelled(true);
if(event.getDamager() instanceof Arrow){
event.getDamager().setFireTicks(0);
player.setFireTicks(0);
}
toActionbar(damager, TextComponent.fromLegacyText("§cDu darfst deinen Teamkollegen keinen Schaden zufügen!")); toActionbar(damager, TextComponent.fromLegacyText("§cDu darfst deinen Teamkollegen keinen Schaden zufügen!"));
} }

Datei anzeigen

@ -1,9 +1,13 @@
package de.steamwar.fightsystem.listener; package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent; import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent; import org.bukkit.event.inventory.InventoryPickupItemEvent;
@ -17,7 +21,7 @@ import java.util.EnumSet;
public class InFightInventoryListener extends BasicListener { public class InFightInventoryListener extends BasicListener {
public InFightInventoryListener() { public InFightInventoryListener() {
super(EnumSet.of(FightState.RUNNING, FightState.ENTERN)); super(EnumSet.of(FightState.RUNNING));
} }
@EventHandler @EventHandler
@ -93,4 +97,12 @@ public class InFightInventoryListener extends BasicListener {
} }
} }
@EventHandler
public void onBlockPlace(BlockPlaceEvent e) {
FightPlayer fp = Fight.getFightPlayer(e.getPlayer());
if(fp != null && !fp.getKit().isTnt() && e.getBlockPlaced().getType() == Material.TNT){
BasicListener.toActionbar(e.getPlayer(), TextComponent.fromLegacyText("§cDu darfst kein TNT setzen!"));
e.setCancelled(true);
}
}
} }

Datei anzeigen

@ -14,7 +14,7 @@ import java.util.EnumSet;
public class NormalJoinListener extends BasicListener { public class NormalJoinListener extends BasicListener {
public NormalJoinListener() { public NormalJoinListener() {
super(Config.event() || Config.test() ? EnumSet.noneOf(FightState.class) : EnumSet.of(FightState.PRE_LEADER_SETUP)); super(Config.event() || Config.test() || Config.Ranked ? EnumSet.noneOf(FightState.class) : EnumSet.of(FightState.PRE_LEADER_SETUP));
} }
@EventHandler @EventHandler

Datei anzeigen

@ -15,9 +15,9 @@ public class PistonListener extends BasicListener {
public PistonListener() { public PistonListener() {
//Wenn Entern aktiv ist, sollen Raketen etc. entern können //Wenn Entern aktiv ist, sollen Raketen etc. entern können
super(Config.Entern super(Config.EnterStages.isEmpty()
? EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP) ? EnumSet.allOf(FightState.class)
: EnumSet.allOf(FightState.class)); : EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP));
} }
@EventHandler @EventHandler

Datei anzeigen

@ -50,7 +50,7 @@ public class PlayerMoveListener extends BasicListener {
reset(event, DENY_TEAM); reset(event, DENY_TEAM);
else if(fightTeam == Fight.getBlueTeam() && player.getGameMode() == GameMode.SPECTATOR) else if(fightTeam == Fight.getBlueTeam() && player.getGameMode() == GameMode.SPECTATOR)
reset(event, DENY_ENTERN); reset(event, DENY_ENTERN);
}else if(fightTeam != null && FightSystem.getFightState() != FightState.ENTERN && player.getGameMode() != GameMode.SPECTATOR) }else if(fightTeam != null && player.getGameMode() != GameMode.SPECTATOR && !fightTeam.canPlayerEntern(player))
reset(event, DENY_ENTERN); reset(event, DENY_ENTERN);
} }

Datei anzeigen

@ -0,0 +1,32 @@
package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import java.util.EnumSet;
public class RankedJoinListener extends BasicListener {
public RankedJoinListener() {
super(!Config.event() && Config.Ranked ? EnumSet.of(FightState.PRE_SCHEM_SETUP) : EnumSet.noneOf(FightState.class));
}
@EventHandler
public void handlePlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
FightTeam fightTeam = Fight.getPlayerTeam(player);
if (fightTeam == null) {
if(!player.getUniqueId().equals(Config.RedLeader) && Fight.getBlueTeam().canbeLeader(player)) {
Fight.getBlueTeam().setLeader(Fight.getBlueTeam().addMember(player));
}else if(Fight.getRedTeam().canbeLeader(player)) {
Fight.getRedTeam().setLeader(Fight.getRedTeam().addMember(player));
}
}
}
}

Datei anzeigen

@ -6,13 +6,12 @@ public enum FightState {
POST_SCHEM_SETUP(true, true, false, false), POST_SCHEM_SETUP(true, true, false, false),
PRE_RUNNING(false, false, true, false), PRE_RUNNING(false, false, true, false),
RUNNING(false, false, true, true), RUNNING(false, false, true, true),
ENTERN(false, false, true, true), //Can be skipped
SPECTATE(false, true, false, false); SPECTATE(false, true, false, false);
private final boolean setup; //PRE_LEADER_SETUP, PRE_SCHEM_SETUP, POST_SCHEM_SETUP private final boolean setup; //PRE_LEADER_SETUP, PRE_SCHEM_SETUP, POST_SCHEM_SETUP
private final boolean outgame; //PRE_LEADER_SETUP, PRE_SCHEM_SETUP, POST_SCHEM_SETUP, SPECTATE private final boolean outgame; //PRE_LEADER_SETUP, PRE_SCHEM_SETUP, POST_SCHEM_SETUP, SPECTATE
private final boolean ingame; //PRE_RUNNING, RUNNING, ENTERN private final boolean ingame; //PRE_RUNNING, RUNNING
private final boolean infight; //RUNNING, ENTERN private final boolean infight; //RUNNING
FightState(boolean setup, boolean outgame, boolean ingame, boolean infight){ FightState(boolean setup, boolean outgame, boolean ingame, boolean infight){
this.setup = setup; this.setup = setup;

Datei anzeigen

@ -0,0 +1,49 @@
package de.steamwar.fightsystem.utils;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.EnternCountdown;
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.StateDependent;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
public class EnterHandler implements StateDependent {
private static final Set<FightState> enabled = EnumSet.of(FightState.RUNNING);
private static final Set<EnternCountdown> countdowns = new HashSet<>();
public EnterHandler(){
FightSystem.registerStateDependent(this);
}
@Override
public Set<FightState> enabled() {
return enabled;
}
private void registerTeam(FightTeam team){
for(FightPlayer fp : team.getPlayers()){
if(Config.EnterStages.size() > fp.getKit().getEnterStage() && fp.getKit().getEnterStage() >= 0)
countdowns.add(new EnternCountdown(fp));
}
}
@Override
public void enable() {
registerTeam(Fight.getBlueTeam());
registerTeam(Fight.getRedTeam());
}
@Override
public void disable() {
for(EnternCountdown countdown : countdowns){
countdown.disable();
}
countdowns.clear();
}
}

Datei anzeigen

@ -19,7 +19,7 @@ public class FightScoreboard {
private FightScoreboard(){} private FightScoreboard(){}
private static final Set<FightState> fullScoreboard = EnumSet.of(FightState.RUNNING, FightState.ENTERN, FightState.SPECTATE); private static final Set<FightState> fullScoreboard = EnumSet.of(FightState.RUNNING, FightState.SPECTATE);
private static final Scoreboard scoreboard = Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard(); private static final Scoreboard scoreboard = Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard();
private static final Objective objective; private static final Objective objective;
private static int index = 0; private static int index = 0;
@ -70,8 +70,6 @@ public class FightScoreboard {
else else
objective.getScore("§7Zeit: §a" + fightTime + "s").setScore(3); objective.getScore("§7Zeit: §a" + fightTime + "s").setScore(3);
} }
if (Config.Entern)
objective.getScore("§7Entern: " + (FightSystem.getFightState() == FightState.ENTERN ? "§aja" : "§cnein")).setScore(2);
if(fullScoreboard.contains(FightSystem.getFightState())){ if(fullScoreboard.contains(FightSystem.getFightState())){
if (Config.PercentSystem){ if (Config.PercentSystem){

Datei anzeigen

@ -5,6 +5,7 @@ import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.sql.Elo;
import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -17,20 +18,29 @@ public class FightStatistics {
private FightStatistics(){} private FightStatistics(){}
private static Timestamp starttime = Timestamp.from(Instant.now()); private static Timestamp starttime = Timestamp.from(Instant.now());
private static int K = 20;
public static void start(){ public static void start(){
starttime = Timestamp.from(Instant.now()); starttime = Timestamp.from(Instant.now());
} }
public static void saveStats(FightTeam winner, String windescription){ public static void saveStats(FightTeam winner, String windescription){
String gameMode = Config.SchematicType.toDB();
SteamwarUser blueLeader = SteamwarUser.get(Fight.getBlueTeam().getLeader().getPlayer().getUniqueId()); SteamwarUser blueLeader = SteamwarUser.get(Fight.getBlueTeam().getLeader().getPlayer().getUniqueId());
SteamwarUser redLeader = SteamwarUser.get(Fight.getRedTeam().getLeader().getPlayer().getUniqueId()); SteamwarUser redLeader = SteamwarUser.get(Fight.getRedTeam().getLeader().getPlayer().getUniqueId());
int win = 0; int win = 0;
if(winner == Fight.getBlueTeam()) double blueResult;
if(winner == Fight.getBlueTeam()) {
win = 1; win = 1;
else if(winner == Fight.getRedTeam()) blueResult = 1;
}else if(winner == Fight.getRedTeam()) {
win = 2; win = 2;
int fightId = create(Config.SchematicType.toDB(), Bukkit.getWorlds().get(0).getName(), starttime, Config.TimeoutTime - FightSystem.getFightTime(), blueResult = 0;
}else{
blueResult = 0.5;
}
if(Fight.getBlueTeam().getSchematic() != null && Fight.getRedTeam().getSchematic() != null){
int fightId = create(gameMode, Bukkit.getWorlds().get(0).getName(), starttime, Config.TimeoutTime - FightSystem.getFightTime(),
blueLeader.getId(), redLeader.getId(), Fight.getBlueTeam().getSchematic().getSchemID(), Fight.getRedTeam().getSchematic().getSchemID(), win, windescription); blueLeader.getId(), redLeader.getId(), Fight.getBlueTeam().getSchematic().getSchemID(), Fight.getRedTeam().getSchematic().getSchemID(), win, windescription);
for(FightPlayer fp : Fight.getBlueTeam().getPlayers()) for(FightPlayer fp : Fight.getBlueTeam().getPlayers())
@ -39,8 +49,22 @@ public class FightStatistics {
savePlayerStats(fp, fightId); savePlayerStats(fp, fightId);
} }
if(Config.Ranked && !Config.event()){
int blueElo = Elo.getElo(blueLeader.getId(), gameMode);
int redElo = Elo.getElo(redLeader.getId(), gameMode);
double redWinExpectation = 1 / (1 + Math.pow(10, (blueElo - redElo) / 400f));
double blueWinExpectation = 1 / (1 + Math.pow(10, (redElo - blueElo) / 400f));
int newBlueElo = (int) Math.round(blueElo + K * (blueResult - blueWinExpectation));
int newRedElo = (int) Math.round(redElo + K * (1 - blueResult - redWinExpectation));
Elo.setElo(blueLeader.getId(), gameMode, newBlueElo);
Elo.setElo(redLeader.getId(), gameMode, newRedElo);
Bukkit.broadcastMessage(FightSystem.PREFIX + "§7ELO von " + Fight.getBlueTeam().getPrefix() + blueLeader.getUserName() + "§8: §7" + blueElo + "§8»§e" + newBlueElo);
Bukkit.broadcastMessage(FightSystem.PREFIX + "§7ELO von " + Fight.getRedTeam().getPrefix() + redLeader.getUserName() + "§8: §7" + redElo + "§8»§e" + newRedElo);
}
}
private static void savePlayerStats(FightPlayer fp, int fightId){ private static void savePlayerStats(FightPlayer fp, int fightId){
SteamwarUser user = SteamwarUser.get(fp.getPlayer().getUniqueId()); SteamwarUser user = SteamwarUser.get(fp.getPlayer().getUniqueId());
de.steamwar.sql.FightPlayer.create(fightId, user.getId(), fp.getKit().getName(), fp.getKills(), !fp.isLiving()); de.steamwar.sql.FightPlayer.create(fightId, user.getId(), fp.getTeam().isBlue(), fp.getKit().getName(), fp.getKills(), !fp.isLiving());
} }
} }

Datei anzeigen

@ -1,106 +1,57 @@
package de.steamwar.fightsystem.utils; package de.steamwar.fightsystem.utils;
import de.steamwar.core.Core; import de.steamwar.core.Core;
import de.steamwar.fightsystem.FightSystem;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import java.util.*; import java.util.List;
public class WaterRemover { public class WaterRemover {
private WaterRemover(){} private WaterRemover(){}
private static final Map<Location, Integer> explodedBlocks = Collections.synchronizedMap(new HashMap<>());
private static Set<Block> waterList = new HashSet<>();
private static boolean isRunning = false;
private static int steps = 1;
public static void init() {
Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), () -> {
if(isRunning){
steps++;
return;
}
isRunning = true;
wateredCheck();
removeWater();
isRunning = false;
}, 0, 20);
}
public static void add(List<Block> l) { public static void add(List<Block> l) {
l.forEach((Block b) -> explodedBlocks.put(b.getLocation(), 0)); for(Block b : l){
} //b cannot be water or air due to current explosion
private static void wateredCheck() { int startX = b.getX();
int startY = b.getY();
int startZ = b.getZ();
try{ try{
Iterator<Map.Entry<Location, Integer>> it = explodedBlocks.entrySet().iterator(); checkBlock(b.getRelative(BlockFace.EAST), startX, startY, startZ);
while (it.hasNext()) { checkBlock(b.getRelative(BlockFace.WEST), startX, startY, startZ);
Map.Entry<Location, Integer> e = it.next(); checkBlock(b.getRelative(BlockFace.NORTH), startX, startY, startZ);
Block b = e.getKey().getBlock(); checkBlock(b.getRelative(BlockFace.SOUTH), startX, startY, startZ);
if (isWater(b)) checkBlock(b.getRelative(BlockFace.UP), startX, startY, startZ);
waterList.add(b); }catch(IsAnOcean e){
//ignore
if(b.getType() != Material.AIR){
it.remove();
continue;
} }
e.setValue(e.getValue() + steps);
if(e.getValue() > 15)
it.remove();
}
steps = 1;
}catch(ConcurrentModificationException e){
steps++;
} }
} }
private static void removeWater() { private static void checkBlock(Block b, int startX, int startY, int startZ) throws IsAnOcean {
List<Block> blocksToRemove = new LinkedList<>(); if(!isWater(b))
Iterator<Block> it = waterList.iterator();
while(it.hasNext()){
Block b = it.next();
blocksToRemove.addAll(getSourceBlocksOfWater(b));
if (!isWater(b))
it.remove();
}
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> blocksToRemove.forEach((Block b) -> b.setType(Material.AIR)));
}
private static Set<Block> getSourceBlocksOfWater(Block startBlock) {
Set<Block> water = new HashSet<>();
collectBlocks(startBlock, water, new HashSet<>());
return water;
}
private static void collectBlocks(Block anchor, Set<Block> collected, Set<Block> visitedBlocks) {
if(
!isWater(anchor) ||
visitedBlocks.contains(anchor)
)
return; return;
visitedBlocks.add(anchor); // If distance to original block is greater than 20
if (isWater(anchor)) if(Math.abs(startX - b.getX()) + Math.abs(startY - b.getY() + Math.abs(startZ - b.getZ())) >= 20)
collected.add(anchor); throw new IsAnOcean();
if(visitedBlocks.size() > 100) { b.setType(Material.AIR);
collected.clear(); try{
return; checkBlock(b.getRelative(BlockFace.EAST), startX, startY, startZ);
checkBlock(b.getRelative(BlockFace.WEST), startX, startY, startZ);
checkBlock(b.getRelative(BlockFace.NORTH), startX, startY, startZ);
checkBlock(b.getRelative(BlockFace.SOUTH), startX, startY, startZ);
checkBlock(b.getRelative(BlockFace.UP), startX, startY, startZ);
}catch(IsAnOcean e){
b.setType(Material.WATER);
throw e;
} }
collectBlocks(anchor.getRelative(BlockFace.UP), collected, visitedBlocks);
collectBlocks(anchor.getRelative(BlockFace.NORTH), collected, visitedBlocks);
collectBlocks(anchor.getRelative(BlockFace.EAST), collected, visitedBlocks);
collectBlocks(anchor.getRelative(BlockFace.SOUTH), collected, visitedBlocks);
collectBlocks(anchor.getRelative(BlockFace.WEST), collected, visitedBlocks);
} }
private static class IsAnOcean extends Throwable{}
public static boolean isWater(Block block){ public static boolean isWater(Block block){
switch(Core.getVersion()){ switch(Core.getVersion()){
case 15: case 15:

Datei anzeigen

@ -10,7 +10,7 @@ import java.util.EnumSet;
abstract class PlayerWincondition extends ListenerWincondition { abstract class PlayerWincondition extends ListenerWincondition {
PlayerWincondition(boolean condition) { PlayerWincondition(boolean condition) {
super(condition, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING, FightState.ENTERN)); super(condition, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING));
} }
boolean isTarget(Player player){ boolean isTarget(Player player){

Datei anzeigen

@ -0,0 +1,13 @@
package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
public class RankedPlayerLeftWincondition {
private RankedPlayerLeftWincondition(){}
public static void leaderQuit(FightTeam leaderlessTeam){
FightSystem.setSpectateState(Fight.getOpposite(leaderlessTeam), "LeaderQuit");
}
}

Datei anzeigen

@ -13,7 +13,7 @@ public class WinconditionHeartRatioTimeout extends Wincondition {
private TimeOverCountdown countdown; private TimeOverCountdown countdown;
public WinconditionHeartRatioTimeout() { public WinconditionHeartRatioTimeout() {
super(Config.HeartRatioTimeout, EnumSet.of(FightState.RUNNING, FightState.ENTERN)); super(Config.HeartRatioTimeout, EnumSet.of(FightState.RUNNING));
} }
@Override @Override

Datei anzeigen

@ -22,7 +22,7 @@ public class WinconditionPercentSystem extends ListenerWincondition {
private static final int schematicSize = Math.abs(Config.SchemsizeX * Config.SchemsizeY * Config.SchemsizeZ); private static final int schematicSize = Math.abs(Config.SchemsizeX * Config.SchemsizeY * Config.SchemsizeZ);
public WinconditionPercentSystem() { public WinconditionPercentSystem() {
super(Config.PercentSystem, EnumSet.of(FightState.RUNNING, FightState.ENTERN)); super(Config.PercentSystem, EnumSet.of(FightState.RUNNING));
} }
@EventHandler @EventHandler

Datei anzeigen

@ -22,7 +22,7 @@ public class WinconditionPumpkinTechKO extends Wincondition {
private BukkitTask task; private BukkitTask task;
public WinconditionPumpkinTechKO(){ public WinconditionPumpkinTechKO(){
super(Config.PumpkinTechKO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING, FightState.ENTERN)); super(Config.PumpkinTechKO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING));
} }
public static int getTeamBluePumpkins() { public static int getTeamBluePumpkins() {

Datei anzeigen

@ -89,7 +89,8 @@ public class WinconditionRelativePercent extends Wincondition{
} }
private int currentBlocks(){ private int currentBlocks(){
if(FightSystem.getFightState() == FightState.ENTERN || FightSystem.getFightState() == FightState.SPECTATE) // Entern active
if(!Config.EnterStages.isEmpty() && Config.EnterStages.get(0) <= FightSystem.getFightTime())
return currentBlocks; return currentBlocks;
int blocks = 0; int blocks = 0;

Datei anzeigen

@ -12,7 +12,7 @@ public class WinconditionTimeout extends Wincondition {
private TimeOverCountdown countdown; private TimeOverCountdown countdown;
public WinconditionTimeout() { public WinconditionTimeout() {
super(Config.Timeout, EnumSet.of(FightState.RUNNING, FightState.ENTERN)); super(Config.Timeout, EnumSet.of(FightState.RUNNING));
} }
@Override @Override