SteamWar/FightSystem
Archiviert
13
1

Finishing setup split (untested)

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2020-01-11 15:44:40 +01:00
Ursprung 126a9b3ab4
Commit 049c51f2a9
28 geänderte Dateien mit 465 neuen und 344 gelöschten Zeilen

Datei anzeigen

@ -20,7 +20,10 @@ import org.bukkit.GameMode;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.util.*; import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
public class FightSystem extends JavaPlugin { public class FightSystem extends JavaPlugin {
@ -30,6 +33,7 @@ public class FightSystem extends JavaPlugin {
private static FightState fightState = FightState.PRE_LEADER_SETUP; private static FightState fightState = FightState.PRE_LEADER_SETUP;
private static Map<StateDependent, Boolean> stateDependentFeatures = new HashMap<>(); private static Map<StateDependent, Boolean> stateDependentFeatures = new HashMap<>();
private static int fightTime = 0; private static int fightTime = 0;
private static Countdown mainCountdown;
@Override @Override
public void onLoad() { public void onLoad() {
@ -41,6 +45,8 @@ public class FightSystem extends JavaPlugin {
public void onEnable() { public void onEnable() {
Fight.init(); Fight.init();
KitManager.loadAllKits(); KitManager.loadAllKits();
TechHider.init();
FightScoreboard.init();
new EntityDamageListener(); new EntityDamageListener();
new EntityExplodeListener(); new EntityExplodeListener();
@ -52,62 +58,10 @@ public class FightSystem extends JavaPlugin {
new PlayerStateListener(); new PlayerStateListener();
new ProjectileLaunchListener(); new ProjectileLaunchListener();
new InFightDamageListener(); new InFightDamageListener();
new FreezeWorldStateListener();
if(!Config.test()){ new EventJoinListener();
new FreezeWorldStateListener(); new TestListener();
TechHider.init(); new NormalJoinListener();
}
FightScoreboard.init();
getCommand("leave").setExecutor(new LeaveCommand());
getCommand("kit").setExecutor(new KitCommand());
getCommand("remove").setExecutor(new RemoveCommand());
getCommand("accept").setExecutor(new AcceptCommand());
getCommand("decline").setExecutor(new DeclineCommand());
getCommand("invite").setExecutor(new InviteCommand());
getCommand("ready").setExecutor(new ReadyCommand());
getCommand("ak").setExecutor(new AkCommand());
getCommand("leader").setExecutor(new LeaderCommand());
getCommand("lockschem").setExecutor(new LockschemCommand());
if(Config.event()) {
new EventJoinListener();
getCommand("invite").setExecutor(new EventDummyCommand());
getCommand("ready").setExecutor(new EventDummyCommand());
getCommand("ak").setExecutor(new EventDummyCommand());
getCommand("leader").setExecutor(new EventDummyCommand());
new EventStartCountdown();
}else if(Config.test()){
new TestListener();
Bukkit.getScheduler().runTaskLater(this, Fight.getBlueTeam()::pasteDummy, 0);
Bukkit.getScheduler().runTaskLater(this, Fight.getRedTeam()::pasteDummy, 0);
new NoPlayersOnlineCountdown();
}else{
new NormalJoinListener();
new NoPlayersOnlineCountdown();
}
}
public static void setPreRunningState() {
if(fightState != FightState.PRE_LEADER_SETUP) //TODO
return;
setFightState(FightState.PRE_RUNNING);
Countdown.cancelAllTimers();
loadKits(Fight.getBlueTeam());
loadKits(Fight.getRedTeam());
setAllPlayersGM(GameMode.SURVIVAL);
Bukkit.broadcastMessage(PREFIX + "§aDer Kampf beginnt!");
new PreRunningCountdown();
Fight.replaceSync();
new WinconditionAllDead(); new WinconditionAllDead();
new WinconditionCaptainDead(); new WinconditionCaptainDead();
@ -116,35 +70,117 @@ public class FightSystem extends JavaPlugin {
new WinconditionPercentSystem(); new WinconditionPercentSystem();
new WinconditionRelativePercent(); new WinconditionRelativePercent();
new WinconditionPoints(); new WinconditionPoints();
new WinconditionTimeout();
new WinconditionHeartRatioTimeout();
new WinconditionTechKO();
if(Config.event()){ Objects.requireNonNull(getCommand("leave")).setExecutor(new LeaveCommand());
new EventTeamOffWincondition(); Objects.requireNonNull(getCommand("kit")).setExecutor(new KitCommand());
Objects.requireNonNull(getCommand("remove")).setExecutor(new RemoveCommand());
Objects.requireNonNull(getCommand("accept")).setExecutor(new AcceptCommand());
Objects.requireNonNull(getCommand("decline")).setExecutor(new DeclineCommand());
Objects.requireNonNull(getCommand("invite")).setExecutor(new InviteCommand());
Objects.requireNonNull(getCommand("ready")).setExecutor(new ReadyCommand());
Objects.requireNonNull(getCommand("ak")).setExecutor(new AkCommand());
Objects.requireNonNull(getCommand("leader")).setExecutor(new LeaderCommand());
Objects.requireNonNull(getCommand("lockschem")).setExecutor(new LockschemCommand());
mainCountdown = new NoPlayersOnlineCountdown();
if(Config.event()) {
Objects.requireNonNull(getCommand("invite")).setExecutor(new EventDummyCommand());
Objects.requireNonNull(getCommand("ready")).setExecutor(new EventDummyCommand());
Objects.requireNonNull(getCommand("ak")).setExecutor(new EventDummyCommand());
Objects.requireNonNull(getCommand("leader")).setExecutor(new EventDummyCommand());
setPreSchemState();
}else if(Config.test()){
Bukkit.getScheduler().runTaskLater(this, Fight.getBlueTeam()::pasteDummy, 0);
Bukkit.getScheduler().runTaskLater(this, Fight.getRedTeam()::pasteDummy, 0);
setPreSchemState();
setPostSchemState();
} }
} }
public static void setPreSchemState() {
if(fightState != FightState.PRE_LEADER_SETUP)
throw new SecurityException(fightState.name());
setFightState(FightState.PRE_SCHEM_SETUP);
mainCountdown = new SetupOverCountdown();
}
public static void setPostSchemState() {
if(fightState != FightState.PRE_SCHEM_SETUP)
throw new SecurityException(fightState.name());
setFightState(FightState.POST_SCHEM_SETUP);
if(!Config.test()){
TechHider.start();
Fight.getBlueTeam().pasteSchematic();
Fight.getRedTeam().pasteSchematic();
}
if(Config.event())
mainCountdown = new EventStartCountdown();
else if(Config.test())
mainCountdown = null;
else
mainCountdown = new SetupOverCountdown();
}
public static void setPreRunningState() {
if(fightState != FightState.POST_SCHEM_SETUP)
throw new SecurityException(fightState.name());
setFightState(FightState.PRE_RUNNING);
loadKits(Fight.getBlueTeam());
loadKits(Fight.getRedTeam());
setAllPlayersGM(GameMode.SURVIVAL);
Bukkit.broadcastMessage(PREFIX + "§aDer Kampf beginnt!");
mainCountdown = new PreRunningCountdown();
Fight.replaceSync();
if(Config.event())
new EventTeamOffWincondition();
}
public static void setRunningState() { public static void setRunningState() {
if(fightState != FightState.PRE_RUNNING) if(fightState != FightState.PRE_RUNNING)
return; throw new SecurityException(fightState.name());
setFightState(FightState.RUNNING); setFightState(FightState.RUNNING);
Countdown.cancelAllTimers();
setAllPlayersGM(GameMode.SURVIVAL); setAllPlayersGM(GameMode.SURVIVAL);
new WinconditionTimeout(); if(Config.Entern)
new WinconditionHeartRatioTimeout(); new EnternCountdown();
new WinconditionEntern();
new WinconditionTechKO();
WaterRemover.init(); 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<Pair<Integer, Integer>> chunksBlue = TechHider.prepareChunkReload(Fight.getBlueTeam().getPlayers().iterator().next().getPlayer());
final List<Pair<Integer, Integer>> 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) { public static void setSpectateState(FightTeam winFightTeam) {
if(fightState != FightState.RUNNING && fightState != FightState.PRE_RUNNING) if(!fightState.ingame())
return; throw new SecurityException(fightState.name());
setFightState(FightState.SPECTATE); setFightState(FightState.SPECTATE);
Countdown.cancelAllTimers();
setAllPlayersGM(GameMode.SPECTATOR); setAllPlayersGM(GameMode.SPECTATOR);
Fight.getBlueTeam().teleportToSpawn(); Fight.getBlueTeam().teleportToSpawn();
@ -176,18 +212,6 @@ public class FightSystem extends JavaPlugin {
FightSystem.fightTime = fightTime; FightSystem.fightTime = fightTime;
} }
public static void setEntern(boolean entern) {
final List<Pair<Integer, Integer>> chunksBlue = TechHider.prepareChunkReload(Fight.getBlueTeam().getPlayers().iterator().next().getPlayer());
final List<Pair<Integer, Integer>> chunksRed = TechHider.prepareChunkReload(Fight.getRedTeam().getPlayers().iterator().next().getPlayer());
IFightSystem.setEntern(entern);
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 setEventLeiter(Player el){ public static void setEventLeiter(Player el){
IFightSystem.setEventLeiter(el); IFightSystem.setEventLeiter(el);
} }
@ -216,16 +240,17 @@ public class FightSystem extends JavaPlugin {
return fightTime; return fightTime;
} }
public static boolean isEntern() {
return IFightSystem.isEntern();
}
public static void shutdown(String reason){ public static void shutdown(String reason){
IFightSystem.shutdown(reason); IFightSystem.shutdown(reason);
} }
public static void registerStateDependent(StateDependent stateDependent){ public static void registerStateDependent(StateDependent stateDependent){
stateDependentFeatures.put(stateDependent, false); if(stateDependent.enabled().isEmpty())
return;
boolean enabled = stateDependent.enabled().contains(fightState);
stateDependentFeatures.put(stateDependent, enabled);
if(enabled)
stateDependent.enable();
} }
private static void loadKits(FightTeam team){ private static void loadKits(FightTeam team){
@ -250,6 +275,8 @@ public class FightSystem extends JavaPlugin {
private static void setFightState(FightState state){ private static void setFightState(FightState state){
fightState = state; fightState = state;
if(mainCountdown != null)
mainCountdown.disable();
postStateChange(); postStateChange();
} }

Datei anzeigen

@ -66,7 +66,7 @@ public class AkCommand implements CommandExecutor {
return false; return false;
} }
KitManager.saveInventory(args[1], player); KitManager.saveInventory(args[1], player);
} else if(args[0].equalsIgnoreCase("schemlist") && FightSystem.getFightState() == FightState.SETUP) { } else if(args[0].equalsIgnoreCase("schemlist") && FightSystem.getFightState() == FightState.PRE_SCHEM_SETUP) {
try { try {
FightTeam fightTeam = Fight.getPlayerTeam(player); FightTeam fightTeam = Fight.getPlayerTeam(player);
if(fightTeam != null && fightTeam.getFightPlayer(player).isLeader()) { if(fightTeam != null && fightTeam.getFightPlayer(player).isLeader()) {

Datei anzeigen

@ -3,7 +3,6 @@ package de.steamwar.fightsystem.commands;
import de.steamwar.fightsystem.FightSystem; 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.states.FightState;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.kit.Kit; import de.steamwar.fightsystem.kit.Kit;
import de.steamwar.fightsystem.kit.KitManager; import de.steamwar.fightsystem.kit.KitManager;
@ -18,7 +17,7 @@ public class Commands {
} }
static boolean checkSetup(Player p){ static boolean checkSetup(Player p){
if(FightSystem.getFightState() != FightState.SETUP){ if(FightSystem.getFightState().setup()){
p.sendMessage(FightSystem.PREFIX + "§cDer Kampf hat bereits begonnen!"); p.sendMessage(FightSystem.PREFIX + "§cDer Kampf hat bereits begonnen!");
return true; return true;
} }

Datei anzeigen

@ -9,17 +9,12 @@ import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitTask;
import java.util.ArrayList;
import java.util.logging.Level;
public abstract class Countdown { public abstract class Countdown {
private static final ArrayList<Countdown> countdowns = new ArrayList<>();
private int time; private int time;
private final int taskID; private final BukkitTask task;
private final Sound sound; private final Sound sound;
private final boolean level; private final boolean level;
@ -30,10 +25,8 @@ public abstract class Countdown {
this.time = time; this.time = time;
this.sound = getSound(sound); this.sound = getSound(sound);
this.level = level; this.level = level;
countdowns.add(this);
BukkitScheduler bukkitScheduler = Bukkit.getServer().getScheduler(); task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::count, 0, 20);
this.taskID = bukkitScheduler.scheduleSyncRepeatingTask(FightSystem.getPlugin(), this::count, 0, 20);
} }
public static Sound getSound(SWSound sound){ public static Sound getSound(SWSound sound){
@ -56,16 +49,8 @@ public abstract class Countdown {
} }
} }
public static void cancelAllTimers() { public void disable() {
while (!countdowns.isEmpty()) { task.cancel();
countdowns.get(0).cancelTimer();
}
}
public static void cancelTimerType(Class<? extends Countdown> type) {
for(int i = countdowns.size() - 1; i >= 0; i--)
if(type.isInstance(countdowns.get(i)))
countdowns.get(i).cancelTimer();
} }
private void broadcast(String message){ private void broadcast(String message){
@ -95,7 +80,7 @@ public abstract class Countdown {
if(this.sound != null) if(this.sound != null)
Fight.playSound(this.sound, 100.0F, 2.0F); Fight.playSound(this.sound, 100.0F, 2.0F);
cancelTimer(); disable();
countdownFinished(); countdownFinished();
break; break;
default: default:
@ -108,15 +93,6 @@ public abstract class Countdown {
} }
void onTime(int time){ void onTime(int time){
//Unused //Implemented in some countdowns
}
public void cancelTimer() {
try {
Bukkit.getScheduler().cancelTask(this.taskID);
} catch (AssertionError ex) {
FightSystem.getPlugin().getLogger().log(Level.SEVERE, "Could not cancel timer", ex);
}
countdowns.remove(this);
} }
} }

Datei anzeigen

@ -17,7 +17,7 @@ public class EnternCountdown extends Countdown {
@Override @Override
public void countdownFinished() { public void countdownFinished() {
FightSystem.setEntern(true); FightSystem.setEntern();
Bukkit.broadcastMessage(FightSystem.PREFIX + "§aEntern ist nun erlaubt!"); Bukkit.broadcastMessage(FightSystem.PREFIX + "§aEntern ist nun erlaubt!");
} }
} }

Datei anzeigen

@ -3,10 +3,10 @@ package de.steamwar.fightsystem.fight;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import de.steamwar.core.Core; import de.steamwar.core.Core;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.IFightSystem; 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.utils.ColorConverter; import de.steamwar.fightsystem.utils.ColorConverter;
import de.steamwar.fightsystem.utils.FightScoreboard; import de.steamwar.fightsystem.utils.FightScoreboard;
import de.steamwar.fightsystem.utils.ItemBuilder; import de.steamwar.fightsystem.utils.ItemBuilder;
@ -28,10 +28,7 @@ import org.bukkit.scoreboard.NameTagVisibility;
import org.bukkit.scoreboard.Team; import org.bukkit.scoreboard.Team;
import java.io.IOException; import java.io.IOException;
import java.util.HashSet; import java.util.*;
import java.util.List;
import java.util.Set;
import java.util.UUID;
public class FightTeam implements IFightTeam{ public class FightTeam implements IFightTeam{
@ -83,28 +80,6 @@ public class FightTeam implements IFightTeam{
team.setAllowFriendlyFire(false); team.setAllowFriendlyFire(false);
} }
private void setTeamColor(Team team, ChatColor color){
switch(Core.getVersion()){
case 15:
FightTeam_15.setTeamColor(team, color);
break;
case 14:
FightTeam_14.setTeamColor(team, color);
break;
case 10:
FightTeam_10.setTeamColor(team, color);
break;
case 9:
FightTeam_9.setTeamColor(team, color);
break;
case 8:
FightTeam_8.setTeamColor(team, color);
break;
default:
FightTeam_12.setTeamColor(team, color);
}
}
public final int getCornerX() { public final int getCornerX() {
return cornerX; return cornerX;
} }
@ -183,24 +158,14 @@ public class FightTeam implements IFightTeam{
public void removePlayer(Player player) { public void removePlayer(Player player) {
FightPlayer fightPlayer = getFightPlayer(player); FightPlayer fightPlayer = getFightPlayer(player);
if(fightPlayer == null)
return;
final List<Pair<Integer, Integer>> chunksToReload = TechHider.prepareChunkReload(player); final List<Pair<Integer, Integer>> chunksToReload = TechHider.prepareChunkReload(player);
players.remove(fightPlayer); players.remove(fightPlayer);
team.removeEntry(player.getName()); team.removeEntry(player.getName());
fightPlayer.getPlayer().getInventory().clear(); fightPlayer.getPlayer().getInventory().clear();
if(fightPlayer.equals(leader) && FightSystem.getFightState() == FightState.SETUP){
this.leader = null; if(fightPlayer.equals(leader) && FightSystem.getFightState().setup())
if(!players.isEmpty()) { setLeader(null);
setLeader(players.iterator().next());
Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §e" + leader.getPlayer().getName() + " §aist nun Leader von Team " + getColoredName() + "§a!");
}else if(!Config.event()){
FightSystem.shutdown(FightSystem.PREFIX + "§cTeam " + getColoredName() + " §chat keine Spieler mehr.\n Arena schließt...");
}else{
setLeader(null);
}
}
player.setGameMode(GameMode.SPECTATOR); player.setGameMode(GameMode.SPECTATOR);
player.teleport(Config.SpecSpawn); player.teleport(Config.SpecSpawn);
@ -222,8 +187,15 @@ public class FightTeam implements IFightTeam{
public void setLeader(FightPlayer leader) { public void setLeader(FightPlayer leader) {
this.leader = leader; this.leader = leader;
if (leader == null) if (leader == null){
if(!players.isEmpty()) {
setLeader(players.iterator().next());
Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §e" + this.leader.getPlayer().getName() + " §aist nun Leader von Team " + getColoredName() + "§a!");
}else if(!Config.event()){
FightSystem.shutdown(FightSystem.PREFIX + "§cTeam " + getColoredName() + " §chat keine Spieler mehr.\n Arena schließt...");
}
return; return;
}
leader.setKit(KitManager.getKitByName(Config.LeaderDefault)); leader.setKit(KitManager.getKitByName(Config.LeaderDefault));
Inventory inventory = leader.getPlayer().getInventory(); Inventory inventory = leader.getPlayer().getInventory();
@ -231,12 +203,15 @@ public class FightTeam implements IFightTeam{
inventory.setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§eKit wählen").build()); inventory.setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§eKit wählen").build());
else else
inventory.setItem(1, new ItemBuilder(Material.AIR).build()); inventory.setItem(1, new ItemBuilder(Material.AIR).build());
if(!Config.event()){ if(!Config.event()){
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());
inventory.setItem(4, new ItemBuilder(SWItem.getDye(10), (short) 10).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§cNicht bereit").build()); inventory.setItem(4, new ItemBuilder(SWItem.getDye(10), (short) 10).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§cNicht bereit").build());
} }
inventory.setItem(0, new ItemBuilder(SWItem.getMaterial("CAULDRON_ITEM")).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§e" + Config.GameName + " wählen").build());
if(!Config.test() && FightSystem.getFightState() != FightState.POST_SCHEM_SETUP)
inventory.setItem(0, new ItemBuilder(SWItem.getMaterial("CAULDRON_ITEM")).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§e" + Config.GameName + " wählen").build());
} }
public Set<FightPlayer> getPlayers() { public Set<FightPlayer> getPlayers() {
@ -247,28 +222,35 @@ public class FightTeam implements IFightTeam{
return ready; return ready;
} }
private void pasteSchematic(){ public void pasteSchematic(){
FreezeWorld freezer = new FreezeWorld(); FreezeWorld freezer = new FreezeWorld();
DyeColor c = ColorConverter.chat2dye(color);
EditSession e; EditSession e;
try { try {
switch(Core.getVersion()){ switch(Core.getVersion()){
case 15: case 15:
e = FightTeam_15.pasteSchematic(schematic, pasteX, pasteY, pasteZ, rotate); e = FightTeam_15.pasteSchematic(schematic, pasteX, pasteY, pasteZ, rotate);
FightTeam_15.replaceTeamColor(e, c, cornerX, cornerY, cornerZ);
break; break;
case 14: case 14:
e = FightTeam_14.pasteSchematic(schematic, pasteX, pasteY, pasteZ, rotate); e = FightTeam_14.pasteSchematic(schematic, pasteX, pasteY, pasteZ, rotate);
FightTeam_14.replaceTeamColor(e, c, cornerX, cornerY, cornerZ);
break; break;
case 10: case 10:
e = FightTeam_10.pasteSchematic(schematic, pasteX, pasteY, pasteZ, rotate); e = FightTeam_10.pasteSchematic(schematic, pasteX, pasteY, pasteZ, rotate);
FightTeam_10.replaceTeamColor(e, c, cornerX, cornerY, cornerZ);
break; break;
case 9: case 9:
e = FightTeam_9.pasteSchematic(schematic, pasteX, pasteY, pasteZ, rotate); e = FightTeam_9.pasteSchematic(schematic, pasteX, pasteY, pasteZ, rotate);
FightTeam_9.replaceTeamColor(e, c, cornerX, cornerY, cornerZ);
break; break;
case 8: case 8:
e = FightTeam_8.pasteSchematic(schematic, pasteX, pasteY, pasteZ, rotate); e = FightTeam_8.pasteSchematic(schematic, pasteX, pasteY, pasteZ, rotate);
FightTeam_8.replaceTeamColor(e, c, cornerX, cornerY, cornerZ);
break; break;
default: default:
e = FightTeam_12.pasteSchematic(schematic, pasteX, pasteY, pasteZ, rotate); e = FightTeam_12.pasteSchematic(schematic, pasteX, pasteY, pasteZ, rotate);
FightTeam_12.replaceTeamColor(e, c, cornerX, cornerY, cornerZ);
} }
} catch (Schematic.WrongVersionException ex) { } catch (Schematic.WrongVersionException ex) {
broadcast(FightSystem.PREFIX + "§cDie gewählte Schematic kann nicht in dieser Version geladen werden"); broadcast(FightSystem.PREFIX + "§cDie gewählte Schematic kann nicht in dieser Version geladen werden");
@ -278,41 +260,16 @@ public class FightTeam implements IFightTeam{
broadcast(FightSystem.PREFIX + "§cFehler beim Pasten der Schematic"); broadcast(FightSystem.PREFIX + "§cFehler beim Pasten der Schematic");
throw new SecurityException("Error pasting arena in schematic", ex); throw new SecurityException("Error pasting arena in schematic", ex);
} }
replaceTeamColor(e);
HandlerList.unregisterAll(freezer); HandlerList.unregisterAll(freezer);
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), this::teleportToSpawn,40); Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), this::teleportToSpawn,40);
} }
private void replaceTeamColor(EditSession e){
DyeColor c = ColorConverter.chat2dye(color);
switch(Core.getVersion()){
case 15:
FightTeam_15.replaceTeamColor(e, c, cornerX, cornerY, cornerZ);
break;
case 14:
FightTeam_14.replaceTeamColor(e, c, cornerX, cornerY, cornerZ);
break;
case 10:
FightTeam_10.replaceTeamColor(e, c, cornerX, cornerY, cornerZ);
break;
case 9:
FightTeam_9.replaceTeamColor(e, c, cornerX, cornerY, cornerZ);
break;
case 8:
FightTeam_8.replaceTeamColor(e, c, cornerX, cornerY, cornerZ);
break;
default:
FightTeam_12.replaceTeamColor(e, c, cornerX, cornerY, cornerZ);
}
}
public void pasteDummy(){ public void pasteDummy(){
List<Schematic> publics = Schematic.getSchemsOfType(0, Config.SchematicType); List<Schematic> publics = Schematic.getSchemsOfType(0, Config.SchematicType);
if(publics.isEmpty()) if(publics.isEmpty())
return; return;
schematic = publics.get(0); schematic = publics.get(new Random().nextInt(publics.size()));
pasteSchematic(); pasteSchematic();
} }
@ -326,9 +283,7 @@ public class FightTeam implements IFightTeam{
if(Config.test()) if(Config.test())
pasteSchematic(); pasteSchematic();
else if(Fight.getOpposite(this).hasSchematic()){ else if(Fight.getOpposite(this).hasSchematic()){
TechHider.start(); FightSystem.setPostSchemState();
pasteSchematic();
Fight.getOpposite(this).pasteSchematic();
} }
} }
@ -348,35 +303,14 @@ public class FightTeam implements IFightTeam{
if(ready) { if(ready) {
l.getInventory().setItem(4, new ItemBuilder(SWItem.getDye(8), (short) 8).removeAllAttributs().addEnchantment(Enchantment.DURABILITY,1 ).setDisplayName("§aBereit").build()); l.getInventory().setItem(4, new ItemBuilder(SWItem.getDye(8), (short) 8).removeAllAttributs().addEnchantment(Enchantment.DURABILITY,1 ).setDisplayName("§aBereit").build());
broadcast(FightSystem.PREFIX + "§aEuer Team ist nun bereit!"); broadcast(FightSystem.PREFIX + "§aEuer Team ist nun bereit!");
if(Fight.getOpposite(this).isReady() || Config.test()) { if(Fight.getOpposite(this).isReady() || Config.test())
FightSystem.setPreRunningState(); FightSystem.setPreRunningState();
}
} else { } else {
l.getInventory().setItem(4, new ItemBuilder(SWItem.getDye(10), (short) 10).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§cNicht bereit").build()); l.getInventory().setItem(4, new ItemBuilder(SWItem.getDye(10), (short) 10).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§cNicht bereit").build());
broadcast(FightSystem.PREFIX + "§cEuer Team ist nicht mehr bereit!"); broadcast(FightSystem.PREFIX + "§cEuer Team ist nicht mehr bereit!");
} }
} }
void replaceSync(boolean replace, Material target, Material replacement) {
if(!replace)
return;
World world = Bukkit.getWorlds().get(0);
Location minPoint = new Location(world, cornerX, cornerY, cornerZ);
Location maxPoint = new Location(world, (cornerX + Config.SchemsizeX), (cornerY + Config.SchemsizeY), (cornerZ + Config.SchemsizeZ));
for(int x = minPoint.getBlockX(); x <= maxPoint.getBlockX(); x++) {
for(int z = minPoint.getBlockZ(); z <= maxPoint.getBlockZ(); z++) {
for(int y = minPoint.getBlockY(); y <= maxPoint.getBlockY(); y++) {
Block block = world.getBlockAt(x, y, z);
if(block.getType() == target)
block.setType(replacement);
}
}
}
}
public Set<Player> getInvited() { public Set<Player> getInvited() {
return invited; return invited;
} }
@ -416,6 +350,48 @@ public class FightTeam implements IFightTeam{
return currentHearts / maximumHearts; return currentHearts / maximumHearts;
} }
void replaceSync(boolean replace, Material target, Material replacement) {
if(!replace)
return;
World world = Bukkit.getWorlds().get(0);
Location minPoint = new Location(world, cornerX, cornerY, cornerZ);
Location maxPoint = new Location(world, (cornerX + Config.SchemsizeX), (cornerY + Config.SchemsizeY), (cornerZ + Config.SchemsizeZ));
for(int x = minPoint.getBlockX(); x <= maxPoint.getBlockX(); x++) {
for(int z = minPoint.getBlockZ(); z <= maxPoint.getBlockZ(); z++) {
for(int y = minPoint.getBlockY(); y <= maxPoint.getBlockY(); y++) {
Block block = world.getBlockAt(x, y, z);
if(block.getType() == target)
block.setType(replacement);
}
}
}
}
private void setTeamColor(Team team, ChatColor color){
switch(Core.getVersion()){
case 15:
FightTeam_15.setTeamColor(team, color);
break;
case 14:
FightTeam_14.setTeamColor(team, color);
break;
case 10:
FightTeam_10.setTeamColor(team, color);
break;
case 9:
FightTeam_9.setTeamColor(team, color);
break;
case 8:
FightTeam_8.setTeamColor(team, color);
break;
default:
FightTeam_12.setTeamColor(team, color);
}
}
private static class FreezeWorld implements Listener { private static class FreezeWorld implements Listener {
private FreezeWorld(){ private FreezeWorld(){
Bukkit.getPluginManager().registerEvents(this, IFightSystem.getPlugin()); Bukkit.getPluginManager().registerEvents(this, IFightSystem.getPlugin());

Datei anzeigen

@ -17,7 +17,7 @@ import java.util.EnumSet;
public class EventJoinListener extends BasicListener { public class EventJoinListener extends BasicListener {
public EventJoinListener() { public EventJoinListener() {
super(EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP)); super(Config.event() ? EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP) : EnumSet.noneOf(FightState.class));
} }
@EventHandler @EventHandler

Datei anzeigen

@ -1,5 +1,6 @@
package de.steamwar.fightsystem.listener; package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -17,7 +18,7 @@ import java.util.EnumSet;
public class FreezeWorldStateListener extends BasicListener { public class FreezeWorldStateListener extends BasicListener {
public FreezeWorldStateListener() { public FreezeWorldStateListener() {
super(EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP, FightState.PRE_RUNNING, FightState.SPECTATE)); super(Config.test() ? EnumSet.noneOf(FightState.class) : EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP, FightState.PRE_RUNNING, FightState.SPECTATE));
} }
@EventHandler @EventHandler

Datei anzeigen

@ -1,8 +1,7 @@
package de.steamwar.fightsystem.listener; package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.countdown.Countdown; import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.countdown.NoPlayersOnlineCountdown; import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.SetupOverCountdown;
import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
@ -15,7 +14,7 @@ import java.util.EnumSet;
public class NormalJoinListener extends BasicListener { public class NormalJoinListener extends BasicListener {
public NormalJoinListener() { public NormalJoinListener() {
super(EnumSet.of(FightState.PRE_LEADER_SETUP)); super(Config.event() || Config.test() ? EnumSet.noneOf(FightState.class) : EnumSet.of(FightState.PRE_LEADER_SETUP));
} }
@EventHandler @EventHandler
@ -33,8 +32,7 @@ public class NormalJoinListener extends BasicListener {
if(Fight.getRedTeam().hasTeamLeader() && Fight.getBlueTeam().hasTeamLeader() if(Fight.getRedTeam().hasTeamLeader() && Fight.getBlueTeam().hasTeamLeader()
&& (Fight.getRedTeam().getLeader().getPlayer() == player || Fight.getBlueTeam().getLeader().getPlayer() == player)) { && (Fight.getRedTeam().getLeader().getPlayer() == player || Fight.getBlueTeam().getLeader().getPlayer() == player)) {
Countdown.cancelTimerType(NoPlayersOnlineCountdown.class); FightSystem.setPreSchemState();
new SetupOverCountdown();
} }
} }
} }

Datei anzeigen

@ -1,10 +1,10 @@
package de.steamwar.fightsystem.listener; package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.utils.Region; import de.steamwar.fightsystem.utils.Region;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -13,12 +13,18 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import java.util.EnumSet;
public class PlayerMoveListener extends BasicListener { public class PlayerMoveListener extends BasicListener {
private static final String DENY_ARENA = "§cDu darfst die Arena nicht verlassen"; private static final String DENY_ARENA = "§cDu darfst die Arena nicht verlassen";
private static final String DENY_TEAM = "§cDu darfst nicht zu den Teams"; private static final String DENY_TEAM = "§cDu darfst nicht zu den Teams";
private static final String DENY_ENTERN = "§cDu darfst nicht entern"; private static final String DENY_ENTERN = "§cDu darfst nicht entern";
public PlayerMoveListener() {
super(EnumSet.allOf(FightState.class));
}
@EventHandler @EventHandler
public void teamAreas(PlayerMoveEvent event) { public void teamAreas(PlayerMoveEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
@ -28,6 +34,7 @@ public class PlayerMoveListener extends BasicListener {
Location to = event.getTo(); Location to = event.getTo();
FightTeam fightTeam = Fight.getPlayerTeam(player); FightTeam fightTeam = Fight.getPlayerTeam(player);
assert to != null;
boolean inArenaY = to.getY() + 1.8 <= Config.upperArenaBorder; boolean inArenaY = to.getY() + 1.8 <= Config.upperArenaBorder;
boolean inBlueArea = inArenaY && Region.isIn2DRange(to, Config.TeamBlueCornerX, Config.TeamBlueCornerZ, Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic); boolean inBlueArea = inArenaY && Region.isIn2DRange(to, Config.TeamBlueCornerX, Config.TeamBlueCornerZ, Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic);
@ -37,7 +44,7 @@ public class PlayerMoveListener extends BasicListener {
if(fightTeam == null) if(fightTeam == null)
reset(event, DENY_TEAM); reset(event, DENY_TEAM);
}else if(fightTeam != null && ( }else if(fightTeam != null && (
!FightSystem.isEntern() || player.getGameMode() == GameMode.SPECTATOR)){ FightSystem.getFightState() != FightState.ENTERN || player.getGameMode() == GameMode.SPECTATOR)){
reset(event, DENY_ENTERN); reset(event, DENY_ENTERN);
} }
} }
@ -48,6 +55,7 @@ public class PlayerMoveListener extends BasicListener {
Location to = event.getTo(); Location to = event.getTo();
//Check in Arena //Check in Arena
assert to != null;
if(!Region.isIn2DRegion(to, Config.ArenaMinX, Config.ArenaMinZ, Config.ArenaMaxX, Config.ArenaMaxZ)){ if(!Region.isIn2DRegion(to, Config.ArenaMinX, Config.ArenaMinZ, Config.ArenaMaxX, Config.ArenaMaxZ)){
reset(event, DENY_ARENA); reset(event, DENY_ARENA);
return; return;

Datei anzeigen

@ -1,7 +1,7 @@
package de.steamwar.fightsystem.listener; package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.Countdown;
import de.steamwar.fightsystem.countdown.NoPlayersOnlineCountdown; import de.steamwar.fightsystem.countdown.NoPlayersOnlineCountdown;
import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
@ -15,8 +15,12 @@ import java.util.EnumSet;
public class TestListener extends BasicListener { public class TestListener extends BasicListener {
private NoPlayersOnlineCountdown countdown;
public TestListener() { public TestListener() {
super(EnumSet.allOf(FightState.class)); super(Config.test() ? EnumSet.allOf(FightState.class) : EnumSet.noneOf(FightState.class));
if(Config.test())
countdown = new NoPlayersOnlineCountdown();
} }
@EventHandler @EventHandler
@ -28,7 +32,10 @@ public class TestListener extends BasicListener {
player.sendMessage(FightSystem.PREFIX + "§7Werde zum Teamleader mit §8/§eleader"); player.sendMessage(FightSystem.PREFIX + "§7Werde zum Teamleader mit §8/§eleader");
} }
Countdown.cancelTimerType(NoPlayersOnlineCountdown.class); if(countdown != null){
countdown.disable();
countdown = null;
}
PermissionAttachment attachment = player.addAttachment(FightSystem.getPlugin()); PermissionAttachment attachment = player.addAttachment(FightSystem.getPlugin());
attachment.setPermission("fawe.permpack.basic", true); attachment.setPermission("fawe.permpack.basic", true);

Datei anzeigen

@ -1,8 +1,8 @@
package de.steamwar.fightsystem.states; package de.steamwar.fightsystem.states;
public enum FightState { public enum FightState {
PRE_LEADER_SETUP(true, true, false, false), //Can be skipped PRE_LEADER_SETUP(true, true, false, false),
PRE_SCHEM_SETUP(true, true, false, false), //Can be skipped PRE_SCHEM_SETUP(true, true, false, false),
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),

Datei anzeigen

@ -71,7 +71,7 @@ public class FightScoreboard {
objective.getScore("§7Zeit: §a" + fightTime + "s").setScore(3); objective.getScore("§7Zeit: §a" + fightTime + "s").setScore(3);
} }
if (Config.Entern) if (Config.Entern)
objective.getScore("§7Entern: " + (FightSystem.isEntern() ? "§aja" : "§cnein")).setScore(2); 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

@ -1,17 +1,31 @@
package de.steamwar.fightsystem.winconditions; package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
public class EventTeamOffWincondition { import java.util.EnumSet;
public class EventTeamOffWincondition extends Wincondition {
public EventTeamOffWincondition(){ public EventTeamOffWincondition(){
super(Config.event(), EnumSet.of(FightState.PRE_RUNNING));
}
@Override
public void enable() {
teamOff(Fight.getBlueTeam()); teamOff(Fight.getBlueTeam());
teamOff(Fight.getRedTeam()); teamOff(Fight.getRedTeam());
} }
@Override
public void disable() {
//Team off is a on time trigger
}
private void teamOff(FightTeam team){ private void teamOff(FightTeam team){
if(team.allPlayersOut()){ if(team.allPlayersOut()){
Bukkit.broadcastMessage(FightSystem.PREFIX + "§6Das Team " + team.getColoredName() + " §6ist Offline!"); Bukkit.broadcastMessage(FightSystem.PREFIX + "§6Das Team " + team.getColoredName() + " §6ist Offline!");

Datei anzeigen

@ -1,15 +1,33 @@
package de.steamwar.fightsystem.winconditions; package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.states.FightState;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
abstract class ListenerWincondition implements Listener { import java.util.Set;
void init(boolean condition){ abstract class ListenerWincondition extends Wincondition implements Listener {
if(!condition)
return;
ListenerWincondition(boolean condition, Set<FightState> enabled){
//If the condition is not met, never enable
super(condition, enabled);
}
/**
* Enables the state dependent object
*/
@Override
public void enable(){
Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin()); Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin());
} }
/**
* Disables the state dependent object
*/
@Override
public void disable(){
HandlerList.unregisterAll(this);
}
} }

Datei anzeigen

@ -1,17 +1,19 @@
package de.steamwar.fightsystem.winconditions; package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.EnumSet;
abstract class PlayerWincondition extends ListenerWincondition { abstract class PlayerWincondition extends ListenerWincondition {
boolean isTarget(Player player){ PlayerWincondition(boolean condition) {
if(FightSystem.getFightState() != FightState.PRE_RUNNING && FightSystem.getFightState() != FightState.RUNNING) super(condition, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING, FightState.ENTERN));
return false; }
boolean isTarget(Player player){
FightTeam fightTeam = Fight.getPlayerTeam(player); FightTeam fightTeam = Fight.getPlayerTeam(player);
if(fightTeam == null) if(fightTeam == null)
return false; return false;

Datei anzeigen

@ -0,0 +1,23 @@
package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent;
import java.util.Set;
abstract class Wincondition implements StateDependent {
private final Set<FightState> enabled;
Wincondition(boolean condition, Set<FightState> enabled){
this.enabled = enabled;
if(condition)
FightSystem.registerStateDependent(this);
}
@Override
public Set<FightState> enabled(){
return enabled;
}
}

Datei anzeigen

@ -13,7 +13,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
public class WinconditionAllDead extends PlayerWincondition { public class WinconditionAllDead extends PlayerWincondition {
public WinconditionAllDead(){ public WinconditionAllDead(){
init(Config.AllDead); super(Config.AllDead);
} }
@EventHandler @EventHandler

Datei anzeigen

@ -13,7 +13,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
public class WinconditionCaptainDead extends PlayerWincondition { public class WinconditionCaptainDead extends PlayerWincondition {
public WinconditionCaptainDead(){ public WinconditionCaptainDead(){
init(Config.CaptainDead); super(Config.CaptainDead);
} }
@EventHandler @EventHandler

Datei anzeigen

@ -1,13 +0,0 @@
package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.countdown.EnternCountdown;
import de.steamwar.fightsystem.Config;
public class WinconditionEntern {
public WinconditionEntern() {
if(!Config.Entern)
return;
new EnternCountdown();
}
}

Datei anzeigen

@ -4,14 +4,21 @@ import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.TimeOverCountdown; import de.steamwar.fightsystem.countdown.TimeOverCountdown;
import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.states.FightState;
public class WinconditionHeartRatioTimeout { import java.util.EnumSet;
public class WinconditionHeartRatioTimeout extends Wincondition {
private TimeOverCountdown countdown;
public WinconditionHeartRatioTimeout() { public WinconditionHeartRatioTimeout() {
if(!Config.HeartRatioTimeout) super(Config.HeartRatioTimeout, EnumSet.of(FightState.RUNNING, FightState.ENTERN));
return; }
new TimeOverCountdown(() -> { @Override
public void enable() {
countdown = new TimeOverCountdown(() -> {
double blueHeartRatio = Fight.getBlueTeam().getHeartRatio(); double blueHeartRatio = Fight.getBlueTeam().getHeartRatio();
double redHeartRatio = Fight.getRedTeam().getHeartRatio(); double redHeartRatio = Fight.getRedTeam().getHeartRatio();
@ -23,4 +30,9 @@ public class WinconditionHeartRatioTimeout {
FightSystem.setSpectateState(null); FightSystem.setSpectateState(null);
}); });
} }
@Override
public void disable(){
countdown.disable();
}
} }

Datei anzeigen

@ -1,14 +1,16 @@
package de.steamwar.fightsystem.winconditions; package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.utils.Region; import de.steamwar.fightsystem.utils.Region;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import java.util.EnumSet;
public class WinconditionPercentSystem extends ListenerWincondition { public class WinconditionPercentSystem extends ListenerWincondition {
private static double bluePercent = 0D; private static double bluePercent = 0D;
@ -17,12 +19,10 @@ public class WinconditionPercentSystem extends ListenerWincondition {
private static int blueDestroyedBlocks; private static int blueDestroyedBlocks;
private static int redDestroyedBlocks; private static int redDestroyedBlocks;
private static int schematicSize; private static final int schematicSize = Math.abs(Config.SchemsizeX * Config.SchemsizeY * Config.SchemsizeZ);
public WinconditionPercentSystem() { public WinconditionPercentSystem() {
init(Config.PercentSystem); super(Config.PercentSystem, EnumSet.of(FightState.RUNNING, FightState.ENTERN));
schematicSize = Math.abs(Config.SchemsizeX * Config.SchemsizeY * Config.SchemsizeZ);
} }
@EventHandler @EventHandler

Datei anzeigen

@ -5,6 +5,7 @@ import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.TimeOverCountdown; import de.steamwar.fightsystem.countdown.TimeOverCountdown;
import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -15,15 +16,38 @@ public class WinconditionPoints extends PlayerWincondition {
private static TeamPoints blue; private static TeamPoints blue;
private static TeamPoints red; private static TeamPoints red;
private TimeOverCountdown countdown;
public WinconditionPoints(){ public WinconditionPoints(){
if(!Config.Points) super(Config.Points);
return; }
init(true); public static TeamPoints getRed(){
return red;
}
public static TeamPoints getBlue(){
return blue;
}
@Override
public void enable() {
super.enable();
blue = new TeamPoints(Fight.getRedTeam(), WinconditionRelativePercent.getBlue(), WinconditionRelativePercent.getRed()); blue = new TeamPoints(Fight.getRedTeam(), WinconditionRelativePercent.getBlue(), WinconditionRelativePercent.getRed());
red = new TeamPoints(Fight.getBlueTeam(), WinconditionRelativePercent.getRed(), WinconditionRelativePercent.getBlue()); red = new TeamPoints(Fight.getBlueTeam(), WinconditionRelativePercent.getRed(), WinconditionRelativePercent.getBlue());
new TimeOverCountdown(this::fightEnds); }
@Override
public void disable() {
super.disable();
countdown.disable();
}
@Override
public void stateChange(FightState state){
if(state == FightState.RUNNING){
countdown = new TimeOverCountdown(this::fightEnds);
}
} }
@EventHandler @EventHandler
@ -54,14 +78,6 @@ public class WinconditionPoints extends PlayerWincondition {
} }
public static TeamPoints getRed(){
return red;
}
public static TeamPoints getBlue(){
return blue;
}
private void fightEnds(){ private void fightEnds(){
if(red.getPoints() > blue.getPoints()) if(red.getPoints() > blue.getPoints())
FightSystem.setSpectateState(blue.enemy); FightSystem.setSpectateState(blue.enemy);
@ -78,7 +94,7 @@ public class WinconditionPoints extends PlayerWincondition {
return red; return red;
} }
public static class TeamPoints extends PlayerWincondition { public static class TeamPoints {
private final FightTeam enemy; private final FightTeam enemy;
private final WinconditionRelativePercent.TeamPercent enemyPercent; private final WinconditionRelativePercent.TeamPercent enemyPercent;
private final double factor; private final double factor;
@ -89,13 +105,12 @@ public class WinconditionPoints extends PlayerWincondition {
TeamPoints(FightTeam enemy, WinconditionRelativePercent.TeamPercent ownPercent, WinconditionRelativePercent.TeamPercent enemyPercent){ TeamPoints(FightTeam enemy, WinconditionRelativePercent.TeamPercent ownPercent, WinconditionRelativePercent.TeamPercent enemyPercent){
this.enemy = enemy; this.enemy = enemy;
this.enemyPercent = enemyPercent; this.enemyPercent = enemyPercent;
init(true);
points = 0; points = 0;
if(enemyPercent.getBlockCount() < ownPercent.getBlockCount()) if(enemyPercent.getBlockCount() < ownPercent.getBlockCount())
this.factor = 10000; //Original mit 20 (20% = 0.2 ergeben 2000 Punkte this.factor = 10000; //Original mit 20 (20% = 0.2 ergeben 2000 Punkte
else{ else{
double f = 10000 * ownPercent.getBlockCount() / enemyPercent.getBlockCount(); double f = 10000.0 * ownPercent.getBlockCount() / enemyPercent.getBlockCount();
if(f > 10000) if(f > 10000)
f = 10000; f = 10000;

Datei anzeigen

@ -4,23 +4,25 @@ import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.scheduler.BukkitTask;
public class WinconditionPumpkinTechKO { import java.util.EnumSet;
public class WinconditionPumpkinTechKO extends Wincondition {
private static int teamRedPumpkins = -1; private static int teamRedPumpkins = -1;
private static int teamBluePumpkins = -1; private static int teamBluePumpkins = -1;
private static final World WORLD = Bukkit.getWorlds().get(0); private static final World WORLD = Bukkit.getWorlds().get(0);
private static final Material PUMPKIN_LANTERN = SWItem.getMaterial("JACK_O_LANTERN"); private static final Material PUMPKIN_LANTERN = SWItem.getMaterial("JACK_O_LANTERN");
private BukkitTask task;
public WinconditionPumpkinTechKO(){ public WinconditionPumpkinTechKO(){
if(!Config.PumpkinTechKO) super(Config.PumpkinTechKO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING, FightState.ENTERN));
return;
Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), WinconditionPumpkinTechKO::recursiveCheck, 0, 200);
} }
public static int getTeamBluePumpkins() { public static int getTeamBluePumpkins() {
@ -30,6 +32,16 @@ public class WinconditionPumpkinTechKO {
return teamRedPumpkins; return teamRedPumpkins;
} }
@Override
public void enable() {
task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), WinconditionPumpkinTechKO::recursiveCheck, 0, 200);
}
@Override
public void disable() {
task.cancel();
}
private static void recursiveCheck(){ private static void recursiveCheck(){
teamRedPumpkins = getPumpkins(Config.TeamRedCornerX, teamRedPumpkins = getPumpkins(Config.TeamRedCornerX,
Config.TeamRedCornerY, Config.TeamRedCornerY,

Datei anzeigen

@ -4,15 +4,18 @@ import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.scheduler.BukkitTask;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
public class WinconditionRelativePercent{ public class WinconditionRelativePercent extends Wincondition{
private static final Set<Material> ignoredBlocks; private static final Set<Material> ignoredBlocks;
private static TeamPercent blue; private static TeamPercent blue;
@ -26,11 +29,7 @@ public class WinconditionRelativePercent{
} }
public WinconditionRelativePercent(){ public WinconditionRelativePercent(){
if(!Config.RelativePercent && !Config.Points) super(Config.RelativePercent || Config.Points, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING));
return;
blue = new TeamPercent(Fight.getBlueTeam());
red = new TeamPercent(Fight.getRedTeam());
} }
public static TeamPercent getBlue(){ public static TeamPercent getBlue(){
@ -41,19 +40,32 @@ public class WinconditionRelativePercent{
return red; return red;
} }
@Override
public void enable() {
blue = new TeamPercent(Fight.getBlueTeam());
red = new TeamPercent(Fight.getRedTeam());
}
@Override
public void disable() {
blue.task.cancel();
red.task.cancel();
}
public static class TeamPercent { public static class TeamPercent {
private static final World world = Bukkit.getWorlds().get(0); private static final World world = Bukkit.getWorlds().get(0);
private final FightTeam team; private final FightTeam team;
private final int blockCount; private final int blockCount;
private final BukkitTask task;
private int currentBlocks; private int currentBlocks;
TeamPercent(FightTeam team){ private TeamPercent(FightTeam team){
this.team = team; this.team = team;
this.blockCount = currentBlocks(); this.blockCount = currentBlocks();
this.currentBlocks = blockCount; this.currentBlocks = blockCount;
Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), () -> { task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), () -> {
currentBlocks = currentBlocks(); currentBlocks = currentBlocks();
checkPercentDefeat(); checkPercentDefeat();
}, 400, 400); }, 400, 400);
@ -73,7 +85,7 @@ public class WinconditionRelativePercent{
} }
private int currentBlocks(){ private int currentBlocks(){
if(FightSystem.isEntern()) if(FightSystem.getFightState() == FightState.ENTERN || FightSystem.getFightState() == FightState.SPECTATE)
return currentBlocks; return currentBlocks;
int blocks = 0; int blocks = 0;

Datei anzeigen

@ -1,46 +1,61 @@
package de.steamwar.fightsystem.winconditions; package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.TechKOCountdown; import de.steamwar.fightsystem.countdown.TechKOCountdown;
import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.states.FightState;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.scheduler.BukkitTask;
import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class WinconditionTechKO implements Listener { public class WinconditionTechKO extends ListenerWincondition {
private static final int TECH_KO_TIME_IN_S = 90; private static final int TECH_KO_TIME_IN_S = 90;
private static final int TECH_KO_HALF_TIME = TECH_KO_TIME_IN_S*10; private static final int TECH_KO_HALF_TIME = TECH_KO_TIME_IN_S*10;
public static final int TECH_KO_COUNTDOWN_TIME = TECH_KO_HALF_TIME/20; public static final int TECH_KO_COUNTDOWN_TIME = TECH_KO_HALF_TIME/20;
private World world; private World world = Bukkit.getWorlds().get(0);
private Map<Integer, Boolean> map = new HashMap<>(400); private Map<Integer, Boolean> map = new HashMap<>(400);
private double toggle; private double toggle = Config.SpecSpawn.getZ();
private int smallerZtime; private int smallerZtime = TECH_KO_HALF_TIME;
private int biggerZtime; private int biggerZtime = TECH_KO_HALF_TIME;
private TechKOCountdown smallerZcountdown = null; private TechKOCountdown smallerZcountdown = null;
private TechKOCountdown biggerZcountdown = null; private TechKOCountdown biggerZcountdown = null;
private BukkitTask task;
//Works only for z-Axis fight direction for performance reasons /**
* Works only for z-Axis fight direction for performance reasons
*/
public WinconditionTechKO(){ public WinconditionTechKO(){
if(!Config.TechKO) super(Config.TechKO, EnumSet.of(FightState.RUNNING, FightState.SPECTATE));
return; }
world = Bukkit.getWorlds().get(0); @Override
toggle = Config.SpecSpawn.getZ(); public void enable() {
smallerZtime=TECH_KO_HALF_TIME; super.enable();
biggerZtime=TECH_KO_HALF_TIME; task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), this::run, 1, 1);
}
Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), this::run, 1, 1); @Override
Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin()); public void disable() {
super.disable();
smallerZcountdown.disable();
biggerZcountdown.disable();
task.cancel();
}
@EventHandler
public void onEntityDead(EntityExplodeEvent event){
map.remove(event.getEntity().getEntityId());
} }
private void run(){ private void run(){
@ -57,14 +72,14 @@ public class WinconditionTechKO implements Listener {
} }
if(smallerZtime == TECH_KO_HALF_TIME && smallerZcountdown != null){ if(smallerZtime == TECH_KO_HALF_TIME && smallerZcountdown != null){
smallerZcountdown.cancelTimer(); smallerZcountdown.disable();
smallerZcountdown = null; smallerZcountdown = null;
}else if(smallerZtime == 0){ }else if(smallerZtime == 0){
smallerZcountdown = new TechKOCountdown(smallerTeam()); smallerZcountdown = new TechKOCountdown(smallerTeam());
} }
if(biggerZtime == TECH_KO_HALF_TIME && biggerZcountdown != null){ if(biggerZtime == TECH_KO_HALF_TIME && biggerZcountdown != null){
biggerZcountdown.cancelTimer(); biggerZcountdown.disable();
biggerZcountdown = null; biggerZcountdown = null;
}else if(biggerZtime == 0){ }else if(biggerZtime == 0){
biggerZcountdown = new TechKOCountdown(biggerTeam()); biggerZcountdown = new TechKOCountdown(biggerTeam());
@ -87,9 +102,4 @@ public class WinconditionTechKO implements Listener {
else else
return Fight.getRedTeam(); return Fight.getRedTeam();
} }
@EventHandler
public void onEntityDead(EntityExplodeEvent event){
map.remove(event.getEntity().getEntityId());
}
} }

Datei anzeigen

@ -1,14 +1,27 @@
package de.steamwar.fightsystem.winconditions; package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.TimeOverCountdown; import de.steamwar.fightsystem.countdown.TimeOverCountdown;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.states.FightState;
import java.util.EnumSet;
public class WinconditionTimeout extends Wincondition {
private TimeOverCountdown countdown;
public class WinconditionTimeout {
public WinconditionTimeout() { public WinconditionTimeout() {
if(!Config.Timeout) super(Config.Timeout, EnumSet.of(FightState.RUNNING, FightState.ENTERN));
return; }
new TimeOverCountdown(() -> FightSystem.setSpectateState(null)); @Override
public void enable() {
countdown = new TimeOverCountdown(() -> FightSystem.setSpectateState(null));
}
@Override
public void disable() {
countdown.disable();
} }
} }

Datei anzeigen

@ -10,21 +10,34 @@ import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.scheduler.BukkitTask;
import java.util.EnumSet;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
public class WinconditionWaterTechKO { public class WinconditionWaterTechKO extends Wincondition {
private static final Set<Location> teamRedWater = new HashSet<>(); private static final Set<Location> teamRedWater = new HashSet<>();
private static final Set<Location> teamBlueWater = new HashSet<>(); private static final Set<Location> teamBlueWater = new HashSet<>();
private static final World WORLD = Bukkit.getWorlds().get(0); private static final World WORLD = Bukkit.getWorlds().get(0);
public WinconditionWaterTechKO() { private BukkitTask task;
if(!Config.WaterTechKO)
return;
Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), this::addWater, 200, 200); public WinconditionWaterTechKO() {
super(Config.WaterTechKO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING, FightState.SPECTATE));
}
public static int getTeamBlueWater() {
return teamBlueWater.size();
}
public static int getTeamRedWater() {
return teamRedWater.size();
}
@Override
public void enable() {
checkForWater(teamRedWater, checkForWater(teamRedWater,
Config.TeamRedCornerX, Config.TeamRedCornerX,
Config.TeamRedCornerY, Config.TeamRedCornerY,
@ -39,6 +52,19 @@ public class WinconditionWaterTechKO {
Config.TeamBlueCornerX + Config.SchemsizeX, Config.TeamBlueCornerX + Config.SchemsizeX,
Config.TeamBlueCornerY + Config.SchemsizeY, Config.TeamBlueCornerY + Config.SchemsizeY,
Config.TeamBlueCornerZ + Config.SchemsizeZ); Config.TeamBlueCornerZ + Config.SchemsizeZ);
task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), this::addWater, 200, 200);
}
@Override
public void disable() {
task.cancel();
}
private void checkEmpty(FightTeam team, Set<Location> teamWater){
if(teamWater.isEmpty()){
Bukkit.broadcastMessage(FightSystem.PREFIX + "§eDas Team " + team.getColoredName() + " §eist Tech K.O.!");
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team)));
}
} }
private void addWater() { private void addWater() {
@ -77,19 +103,4 @@ public class WinconditionWaterTechKO {
} }
} }
} }
private static void checkEmpty(FightTeam team, Set<Location> teamWater){
if(teamWater.isEmpty()){
Bukkit.broadcastMessage(FightSystem.PREFIX + "§eDas Team " + team.getColoredName() + " §eist Tech K.O.!");
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team)));
}
}
public static int getTeamBlueWater() {
return teamBlueWater.size();
}
public static int getTeamRedWater() {
return teamRedWater.size();
}
} }