forked from SteamWar/SteamWar
Format code
This commit is contained in:
@@ -37,24 +37,24 @@ import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MissileWars extends JavaPlugin {
|
||||
private static MissileWars plugin;
|
||||
private static MWTeam redTeam; //red has South side -> spawns missles towards north
|
||||
private static MWTeam blueTeam;
|
||||
private static FightState fightState;
|
||||
private static MissileWars plugin;
|
||||
private static MWTeam redTeam; //red has South side -> spawns missles towards north
|
||||
private static MWTeam blueTeam;
|
||||
private static FightState fightState;
|
||||
|
||||
/**
|
||||
* create teams, ect
|
||||
*/
|
||||
@Override
|
||||
public void onLoad() {
|
||||
plugin = this;
|
||||
fightState = FightState.WAITING;
|
||||
}
|
||||
/**
|
||||
* create teams, ect
|
||||
*/
|
||||
@Override
|
||||
public void onLoad() {
|
||||
plugin = this;
|
||||
fightState = FightState.WAITING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
redTeam = new MWTeam(Config.TeamRedColor, Config.RedSpawn, Config.TeamRedName, Config.RedPortalZ);
|
||||
blueTeam = new MWTeam(Config.TeamBlueColor, Config.BlueSpawn, Config.TeamBlueName, Config.BluePortalZ);
|
||||
@Override
|
||||
public void onEnable() {
|
||||
redTeam = new MWTeam(Config.TeamRedColor, Config.RedSpawn, Config.TeamRedName, Config.RedPortalZ);
|
||||
blueTeam = new MWTeam(Config.TeamBlueColor, Config.BlueSpawn, Config.TeamBlueName, Config.BluePortalZ);
|
||||
|
||||
SpigotLinker spigotLinker = new SpigotLinker(this, null) {
|
||||
@Override
|
||||
@@ -71,128 +71,117 @@ public class MissileWars extends JavaPlugin {
|
||||
}
|
||||
|
||||
Missile.init();
|
||||
CustomItem.init();
|
||||
CustomItem.init();
|
||||
|
||||
StateDependent.setupState(fightState);
|
||||
StateDependent.setupState(fightState);
|
||||
|
||||
Bukkit.getScheduler().runTaskTimer(this, new FightInfoPacketSender(), 20, 20);
|
||||
Bukkit.getScheduler().runTaskTimer(this, new FightInfoPacketSender(), 20, 20);
|
||||
|
||||
Bukkit.getWorlds().forEach(world -> {
|
||||
world.setGameRule(GameRule.KEEP_INVENTORY, true);
|
||||
world.setGameRule(GameRule.MOB_GRIEFING, true);
|
||||
world.setGameRule(GameRule.DO_TILE_DROPS, false);
|
||||
});
|
||||
Bukkit.getWorlds().forEach(world -> {
|
||||
world.setGameRule(GameRule.KEEP_INVENTORY, true);
|
||||
world.setGameRule(GameRule.MOB_GRIEFING, true);
|
||||
world.setGameRule(GameRule.DO_TILE_DROPS, false);
|
||||
});
|
||||
|
||||
// TODO: Enable Item Dropping, and the own team can pick them up! Add config value for that?
|
||||
}
|
||||
// TODO: Enable Item Dropping, and the own team can pick them up! Add config value for that?
|
||||
}
|
||||
|
||||
public static void waiting() {
|
||||
if (fightState == FightState.END) {
|
||||
fightState = FightState.WAITING;
|
||||
StateDependent.setupState(fightState);
|
||||
public static void waiting() {
|
||||
if (fightState == FightState.END) {
|
||||
fightState = FightState.WAITING;
|
||||
StateDependent.setupState(fightState);
|
||||
|
||||
SlowMoRunner.resetSlowMoTime();
|
||||
SlowMoRunner.resetSlowMoTime();
|
||||
|
||||
Set<UUID> uuidList = Bukkit.getOnlinePlayers().stream().map(Entity::getUniqueId).collect(Collectors.toSet());
|
||||
if (!uuidList.contains(Config.RedLeader) || !uuidList.contains(Config.BlueLeader)) {
|
||||
Config.RedLeader = null;
|
||||
Config.BlueLeader = null;
|
||||
}
|
||||
Set<UUID> uuidList = Bukkit.getOnlinePlayers().stream().map(Entity::getUniqueId).collect(Collectors.toSet());
|
||||
if (!uuidList.contains(Config.RedLeader) || !uuidList.contains(Config.BlueLeader)) {
|
||||
Config.RedLeader = null;
|
||||
Config.BlueLeader = null;
|
||||
}
|
||||
|
||||
redTeam.reset();
|
||||
blueTeam.reset();
|
||||
}
|
||||
}
|
||||
redTeam.reset();
|
||||
blueTeam.reset();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* call to change fightstate from WAITING to INGAME
|
||||
*/
|
||||
static void startRound() {
|
||||
if (fightState != FightState.WAITING) // anti dual-call
|
||||
return;
|
||||
fightState = FightState.FIGHTING;
|
||||
StateDependent.setupState(fightState);
|
||||
}
|
||||
/**
|
||||
* call to change fightstate from WAITING to INGAME
|
||||
*/
|
||||
static void startRound() {
|
||||
if (fightState != FightState.WAITING) // anti dual-call
|
||||
return;
|
||||
fightState = FightState.FIGHTING;
|
||||
StateDependent.setupState(fightState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fight beenden
|
||||
* @param reason Grund fürs ende
|
||||
* @param winner Gewinner (oder null)
|
||||
*/
|
||||
public static void end(WinReasons reason, MWTeam winner) {
|
||||
if (fightState == FightState.END) //verhindern dass es mehrfach gecallt wird
|
||||
return;
|
||||
fightState = FightState.END;
|
||||
StateDependent.setupState(fightState);
|
||||
/**
|
||||
* Fight beenden
|
||||
*
|
||||
* @param reason Grund fürs ende
|
||||
* @param winner Gewinner (oder null)
|
||||
*/
|
||||
public static void end(WinReasons reason, MWTeam winner) {
|
||||
if (fightState == FightState.END) //verhindern dass es mehrfach gecallt wird
|
||||
return;
|
||||
fightState = FightState.END;
|
||||
StateDependent.setupState(fightState);
|
||||
|
||||
for(Player player : Bukkit.getOnlinePlayers()) {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_ENDER_DRAGON_DEATH, 100f, 1f);
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
}
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_ENDER_DRAGON_DEATH, 100f, 1f);
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
}
|
||||
|
||||
byte ergebnis = winner == blueTeam ? (byte) 1 : (byte) 2;
|
||||
if (Config.isEvent()) {
|
||||
Config.EventKampf.setErgebnis(ergebnis);
|
||||
}
|
||||
if (Config.isEvent() || Config.isChallenge()) {
|
||||
FightEndsPacket packet = FightEndsPacket.builder()
|
||||
.gameMode("MissileWars")
|
||||
.duration((int)((System.currentTimeMillis() - FightScoreboard.getStartTime()) / 1000))
|
||||
.win(ergebnis)
|
||||
.bluePlayers(blueTeam.getPlayers().stream().map(Player::getUniqueId).map(SteamwarUser::get).map(SteamwarUser::getId).collect(Collectors.toList()))
|
||||
.redPlayers(redTeam.getPlayers().stream().map(Player::getUniqueId).map(SteamwarUser::get).map(SteamwarUser::getId).collect(Collectors.toList()))
|
||||
.blueSchem(-1)
|
||||
.redSchem(-1)
|
||||
.build();
|
||||
NetworkSender.send(packet);
|
||||
}
|
||||
byte ergebnis = winner == blueTeam ? (byte) 1 : (byte) 2;
|
||||
if (Config.isEvent()) {
|
||||
Config.EventKampf.setErgebnis(ergebnis);
|
||||
}
|
||||
if (Config.isEvent() || Config.isChallenge()) {
|
||||
FightEndsPacket packet = FightEndsPacket.builder().gameMode("MissileWars").duration((int) ((System.currentTimeMillis() - FightScoreboard.getStartTime()) / 1000)).win(ergebnis).bluePlayers(blueTeam.getPlayers().stream().map(Player::getUniqueId).map(SteamwarUser::get).map(SteamwarUser::getId).collect(Collectors.toList())).redPlayers(redTeam.getPlayers().stream().map(Player::getUniqueId).map(SteamwarUser::get).map(SteamwarUser::getId).collect(Collectors.toList())).blueSchem(-1).redSchem(-1).build();
|
||||
NetworkSender.send(packet);
|
||||
}
|
||||
|
||||
switch (reason) {
|
||||
case PORTAL_DESTROYED:
|
||||
Bukkit.getServer().broadcastMessage(winner.getColoredName() + ChatColor.RESET + " §7hat das gegnerische Portal zerstört");
|
||||
break;
|
||||
case NO_ENEMY:
|
||||
default:
|
||||
Bukkit.getServer().broadcastMessage("§7Team " + winner.getColoredName() + ChatColor.RESET + " §7hat aufgrund fehlenden Gegners gewonnen");
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch (reason) {
|
||||
case PORTAL_DESTROYED:
|
||||
Bukkit.getServer().broadcastMessage(winner.getColoredName() + ChatColor.RESET + " §7hat das gegnerische Portal zerstört");
|
||||
break;
|
||||
case NO_ENEMY:
|
||||
default:
|
||||
Bukkit.getServer().broadcastMessage("§7Team " + winner.getColoredName() + ChatColor.RESET + " §7hat aufgrund fehlenden Gegners gewonnen");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static MissileWars getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
public static MissileWars getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public static FightState getFightState() {
|
||||
return fightState;
|
||||
}
|
||||
public static FightState getFightState() {
|
||||
return fightState;
|
||||
}
|
||||
|
||||
public static MWTeam getRedTeam() {
|
||||
return redTeam;
|
||||
}
|
||||
public static MWTeam getRedTeam() {
|
||||
return redTeam;
|
||||
}
|
||||
|
||||
public static MWTeam getBlueTeam() {
|
||||
return blueTeam;
|
||||
}
|
||||
public static MWTeam getBlueTeam() {
|
||||
return blueTeam;
|
||||
}
|
||||
|
||||
public static MWTeam getTeam(Player p) {
|
||||
if(blueTeam.hasPlayer(p))
|
||||
return blueTeam;
|
||||
if(redTeam.hasPlayer(p))
|
||||
return redTeam;
|
||||
return null;
|
||||
}
|
||||
public static MWTeam getTeam(Player p) {
|
||||
if (blueTeam.hasPlayer(p)) return blueTeam;
|
||||
if (redTeam.hasPlayer(p)) return redTeam;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static MWTeam getInvitation(Player p) {
|
||||
if(blueTeam.hasInvite(p))
|
||||
return blueTeam;
|
||||
if(redTeam.hasInvite(p))
|
||||
return redTeam;
|
||||
return null;
|
||||
}
|
||||
public static MWTeam getInvitation(Player p) {
|
||||
if (blueTeam.hasInvite(p)) return blueTeam;
|
||||
if (redTeam.hasInvite(p)) return redTeam;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void leave(Player p) {
|
||||
MissileWars.getBlueTeam().leave(p);
|
||||
MissileWars.getRedTeam().leave(p);
|
||||
}
|
||||
public static void leave(Player p) {
|
||||
MissileWars.getBlueTeam().leave(p);
|
||||
MissileWars.getRedTeam().leave(p);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user