diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java
index ff07546..ccca371 100644
--- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java
+++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java
@@ -105,7 +105,7 @@ public class FightSystem extends JavaPlugin {
techHider = new TechHiderWrapper();
new FightWorld();
new FightUI();
- new FightStatistics();
+ //new FightStatistics();
new BungeeFightInfo();
new WinconditionAllDead();
diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIPlayer.java b/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIPlayer.java
new file mode 100644
index 0000000..1730174
--- /dev/null
+++ b/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIPlayer.java
@@ -0,0 +1,45 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2023 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.fightsystem.ai;
+
+import com.comphenix.tinyprotocol.Reflection;
+import de.steamwar.fightsystem.Config;
+import de.steamwar.sql.SteamwarUser;
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.entity.Villager;
+
+import java.util.UUID;
+
+public class AIPlayer {
+ private static final Reflection.MethodInvoker getHandle = Reflection.getMethod("{obc}.entity.CraftEntity", "getHandle");
+ private static final Reflection.FieldAccessor entityUUID = Reflection.getField("{nms.world.entity}.Entity", UUID.class, 0);
+
+ private final LivingEntity player;
+
+ public AIPlayer(SteamwarUser user) {
+ player = Config.world.spawn(Config.SpecSpawn, Villager.class, entity -> entityUUID.set(getHandle.invoke(entity), user.getUUID()));
+ player.setCustomName(user.getUserName());
+ player.setAI(false);
+ }
+
+ public LivingEntity getEntity() {
+ return player;
+ }
+}
diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java
index cb63550..3dd7779 100644
--- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java
+++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java
@@ -33,6 +33,7 @@ import de.steamwar.sql.SteamwarUser;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Bukkit;
import org.bukkit.Material;
+import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
@@ -101,7 +102,7 @@ public class GUI {
FightTeam team = Fight.getPlayerTeam(p);
if(team == null)
return;
- players.removeIf(swItemUUIDPair -> !team.equals(Fight.getPlayerTeam(Bukkit.getPlayer(swItemUUIDPair.getObject()))));
+ players.removeIf(swItemUUIDPair -> !team.equals(Fight.getPlayerTeam((LivingEntity) Bukkit.getEntity(swItemUUIDPair.getObject()))));
SWListInv inv = new SWListInv<>(p, msg.parse("REMOVE_TITLE", p), players, (ClickType click, UUID player) -> {
Commands.kick(p, SteamwarUser.get(player).getUserName());
p.closeInventory();
diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java
index c5c19b5..a98e9b6 100644
--- a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java
+++ b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java
@@ -58,7 +58,7 @@ public class EnternCountdown extends Countdown {
@Override
public void countdownFinished() {
FightSystem.getMessage().sendPrefixless("ENTERN_ALLOWED", fightPlayer.getPlayer(), ChatMessageType.ACTION_BAR);
- FightSystem.getTechHider().reloadChunks(fightPlayer.getPlayer(), chunkPos, false);
+ fightPlayer.withPlayer(player -> FightSystem.getTechHider().reloadChunks(player, chunkPos, false));
}
@Override
@@ -68,7 +68,9 @@ public class EnternCountdown extends Countdown {
@Override
protected void broadcast(String message, int divisor) {
- fightPlayer.getPlayer().playSound(fightPlayer.getPlayer().getLocation(), sound, 100.0f, 1.0f);
- sendCountdownMessage(fightPlayer.getPlayer(), message, time / divisor, appendix);
+ fightPlayer.withPlayer(player -> {
+ player.playSound(player.getLocation(), sound, 100.0f, 1.0f);
+ sendCountdownMessage(player, message, time / divisor, appendix);
+ });
}
}
diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java
index 6f465e8..380f39e 100644
--- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java
+++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java
@@ -29,6 +29,7 @@ import de.steamwar.fightsystem.record.GlobalRecorder;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Sound;
+import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import java.util.Collection;
@@ -45,7 +46,7 @@ public class Fight {
teams.add(blueTeam);
}
- public static FightTeam getPlayerTeam(Player player) {
+ public static FightTeam getPlayerTeam(LivingEntity player) {
if(redTeam.isPlayerInTeam(player))
return redTeam;
if(blueTeam.isPlayerInTeam(player))
@@ -62,7 +63,7 @@ public class Fight {
throw new IllegalArgumentException();
}
- public static FightPlayer getFightPlayer(Player player) {
+ public static FightPlayer getFightPlayer(LivingEntity player) {
if(redTeam.isPlayerInTeam(player))
return redTeam.getFightPlayer(player);
if(blueTeam.isPlayerInTeam(player))
@@ -70,7 +71,7 @@ public class Fight {
return null;
}
- public static boolean fighting(Player player) {
+ public static boolean fighting(LivingEntity player) {
return getPlayerTeam(player) != null;
}
diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java
index ed2e6d5..4f34137 100644
--- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java
+++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java
@@ -24,28 +24,30 @@ import de.steamwar.fightsystem.countdown.EnternCountdown;
import de.steamwar.sql.PersonalKit;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit;
+import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import java.util.UUID;
+import java.util.function.Consumer;
public class FightPlayer {
private final UUID uuid;
- private Player player;
+ private LivingEntity entity;
private final FightTeam team;
private boolean isOut;
private Kit kit;
private int kills;
private EnternCountdown enternCountdown = null;
- FightPlayer(Player player, FightTeam team) {
+ FightPlayer(LivingEntity player, FightTeam team) {
this.uuid = player.getUniqueId();
- this.player = player;
+ this.entity = player;
this.team = team;
this.isOut = false;
kit = Kit.getKitByName(Config.MemberDefault);
if(Config.PersonalKits){
- PersonalKit personalKit = PersonalKit.getKitInUse(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB());
+ PersonalKit personalKit = PersonalKit.getKitInUse(SteamwarUser.get(uuid).getId(), Config.SchematicType.toDB());
if(personalKit != null){
kit = new Kit(personalKit);
}
@@ -74,11 +76,16 @@ public class FightPlayer {
enternCountdown = null;
}
- public Player getPlayer() {
+ public LivingEntity getPlayer() {
Player bukkit = Bukkit.getPlayer(uuid);
if(bukkit != null)
- player = bukkit;
- return player;
+ entity = bukkit;
+ return entity;
+ }
+
+ public void withPlayer(Consumer function) {
+ if(entity instanceof Player)
+ function.accept((Player) entity);
}
public boolean isLiving() {
@@ -87,7 +94,7 @@ public class FightPlayer {
public boolean isLeader() {
FightPlayer leader = team.getLeader();
- return leader != null && leader.getPlayer() == player;
+ return leader != null && leader.getPlayer() == entity;
}
public Kit getKit() {
diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java
index dbd812c..f67a0a1 100644
--- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java
+++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java
@@ -41,6 +41,7 @@ import de.steamwar.techhider.ProtocolUtils;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.*;
import org.bukkit.enchantments.Enchantment;
+import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.NameTagVisibility;
import org.bukkit.scoreboard.Team;
@@ -134,7 +135,7 @@ public class FightTeam {
new OneShotStateDependent(Config.replayserver(), FightState.PreLeaderSetup, () -> Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::reset));
new OneShotStateDependent(ArenaMode.All, FightState.PostSchemSetup, () -> {
if(leader != null)
- notReadyKit.loadToPlayer(leader.getPlayer());
+ leader.withPlayer(notReadyKit::loadToPlayer);
});
}
@@ -165,10 +166,10 @@ public class FightTeam {
}
public void teleportToSpawn(){
- players.forEach((player, fp) -> Objects.requireNonNull(Bukkit.getPlayer(player)).teleport(spawn));
+ players.forEach((player, fp) -> fp.getPlayer().teleport(spawn));
}
- public FightPlayer getFightPlayer(Player player) {
+ public FightPlayer getFightPlayer(LivingEntity player) {
return players.get(player.getUniqueId());
}
@@ -180,15 +181,15 @@ public class FightTeam {
return true;
}
- public boolean isPlayerInTeam(Player player) {
+ public boolean isPlayerInTeam(LivingEntity player) {
return players.containsKey(player.getUniqueId());
}
- public boolean canPlayerEntern(Player player) {
+ public boolean canPlayerEntern(LivingEntity player) {
return getFightPlayer(player).canEntern();
}
- public boolean isPlayerLeader(Player player) {
+ public boolean isPlayerLeader(LivingEntity player) {
if(leader != null)
return leader.getPlayer().equals(player);
else
@@ -202,12 +203,12 @@ public class FightTeam {
Set playerSet = new HashSet<>(players.keySet());
for(UUID uuid : playerSet){
- Player player = Bukkit.getPlayer(uuid);
+ LivingEntity player = (LivingEntity) Bukkit.getEntity(uuid);
if(player == null)
removePlayer(players.get(uuid).getPlayer());
}
FightPlayer leaderBackup = leader;
- playerSet.removeIf(uuid -> Bukkit.getPlayer(uuid) == null);
+ playerSet.removeIf(uuid -> Bukkit.getEntity(uuid) == null);
players.clear();
leader = null;
@@ -216,7 +217,7 @@ public class FightTeam {
addMember(leaderBackup.getPlayer(), true);
}
- playerSet.forEach(uuid -> addMember(Bukkit.getPlayer(uuid), true));
+ playerSet.forEach(uuid -> addMember((LivingEntity) Bukkit.getEntity(uuid), true));
if(ArenaMode.VariableTeams.contains(Config.mode) && isLeaderless()){
List onlinePlayers = new ArrayList<>(Bukkit.getOnlinePlayers());
@@ -250,11 +251,11 @@ public class FightTeam {
});
}
- public void addMember(Player player) {
+ public void addMember(LivingEntity player) {
addMember(player, false);
}
- private void addMember(Player player, boolean silent) {
+ private void addMember(LivingEntity player, boolean silent) {
final List chunksToReload = FightSystem.getTechHider().prepareChunkReload(player, false);
FightPlayer fightPlayer = getFightPlayer(player) != null ? getFightPlayer(player) : new FightPlayer(player, this);
fightPlayer.revive();
@@ -263,22 +264,26 @@ public class FightTeam {
team.addEntry(player.getName());
player.setHealth(20);
- player.setFoodLevel(20);
- player.getInventory().clear();
- BountifulWrapper.impl.setAttackSpeed(player);
player.teleport(spawn);
- if(FightState.Spectate.contains(FightState.getFightState())) {
- Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
- } else {
- Fight.setPlayerGamemode(player, GameMode.SURVIVAL);
- (FightState.ingame() ? fightPlayer.getKit() : memberKit).loadToPlayer(player);
- }
+ fightPlayer.withPlayer(p -> {
+ BountifulWrapper.impl.setAttackSpeed(p);
+ p.setFoodLevel(20);
+ p.getInventory().clear();
+
+ if(FightState.Spectate.contains(FightState.getFightState())) {
+ Fight.setPlayerGamemode(p, GameMode.SPECTATOR);
+ } else {
+ Fight.setPlayerGamemode(p, GameMode.SURVIVAL);
+ (FightState.ingame() ? fightPlayer.getKit() : memberKit).loadToPlayer(p);
+ }
+ });
+
if(FightState.Running.contains(FightState.getFightState()))
fightPlayer.startEnternCountdown();
GlobalRecorder.getInstance().playerJoins(player);
- FightSystem.getTechHider().reloadChunks(player, chunksToReload, false);
+ fightPlayer.withPlayer(p -> FightSystem.getTechHider().reloadChunks(p, chunksToReload, false));
if(isLeaderless())
setLeader(fightPlayer, silent);
@@ -286,10 +291,10 @@ public class FightTeam {
FightUI.addSubtitle("UI_PLAYER_JOINS", prefix, player.getName());
}
- public void removePlayer(Player player) {
+ public void removePlayer(LivingEntity player) {
FightPlayer fightPlayer = getFightPlayer(player);
- PersonalKitCreator.closeIfInKitCreator(player);
+ fightPlayer.withPlayer(PersonalKitCreator::closeIfInKitCreator);
List chunksToReload = FightSystem.getTechHider().prepareChunkReload(player, true);
players.remove(player.getUniqueId());
team.removeEntry(player.getName());
@@ -301,16 +306,19 @@ public class FightTeam {
removeLeader();
GlobalRecorder.getInstance().entityDespawns(player);
- Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
player.teleport(Config.SpecSpawn);
- player.getInventory().clear();
- if(player.isOnline()){
- FightSystem.getTechHider().reloadChunks(player, chunksToReload, true);
+ fightPlayer.withPlayer(p -> {
+ Fight.setPlayerGamemode(p, GameMode.SPECTATOR);
+ p.getInventory().clear();
- if(ArenaMode.VariableTeams.contains(Config.mode))
- HotbarKit.SPECTATOR_KIT.loadToPlayer(player);
- }
+ if(p.isOnline()){
+ FightSystem.getTechHider().reloadChunks(p, chunksToReload, true);
+
+ if(ArenaMode.VariableTeams.contains(Config.mode))
+ HotbarKit.SPECTATOR_KIT.loadToPlayer(p);
+ }
+ });
}
public boolean isLeaderless() {
@@ -335,7 +343,7 @@ public class FightTeam {
}
private void setLeader(FightPlayer leader, boolean silent) {
- PersonalKitCreator.closeIfInKitCreator(leader.getPlayer());
+ leader.withPlayer(PersonalKitCreator::closeIfInKitCreator);
this.leader = leader;
designatedLeader = null;
@@ -354,11 +362,12 @@ public class FightTeam {
if(!Config.PersonalKits)
leader.setKit(Kit.getKitByName(Config.LeaderDefault));
- Player player = leader.getPlayer();
- if(FightState.getFightState() != FightState.POST_SCHEM_SETUP)
- chooseSchemKit.loadToPlayer(player);
- else
- notReadyKit.loadToPlayer(player);
+ leader.withPlayer(player -> {
+ if(FightState.getFightState() != FightState.POST_SCHEM_SETUP)
+ chooseSchemKit.loadToPlayer(player);
+ else
+ notReadyKit.loadToPlayer(player);
+ });
if(FightState.getFightState() == FightState.PRE_LEADER_SETUP && !Fight.getOpposite(this).isLeaderless()){
FightState.setFightState(FightState.PRE_SCHEM_SETUP);
@@ -405,7 +414,7 @@ public class FightTeam {
}
public void setReady(boolean ready) {
- Player l = leader.getPlayer();
+ LivingEntity l = leader.getPlayer();
if(!schematic.hasSchematic()){
FightSystem.getMessage().sendPrefixless("SCHEMATIC_REQUIRED", l, ChatMessageType.ACTION_BAR);
@@ -415,12 +424,12 @@ public class FightTeam {
this.ready = ready;
if(ready) {
broadcast("TEAM_READY");
- readyKit.loadToPlayer(l);
+ leader.withPlayer(readyKit::loadToPlayer);
if(Fight.getOpposite(this).isReady() || ArenaMode.SoloLeader.contains(Config.mode))
FightState.setFightState(FightState.PRE_RUNNING);
} else {
broadcast("TEAM_NOT_READY");
- notReadyKit.loadToPlayer(l);
+ leader.withPlayer(notReadyKit::loadToPlayer);
}
}
@@ -493,17 +502,18 @@ public class FightTeam {
@Override
public void enable() {
for(FightPlayer fightPlayer : players.values()) {
- Player player = fightPlayer.getPlayer();
- PersonalKitCreator.closeIfInKitCreator(player);
+ fightPlayer.withPlayer(player -> {
+ PersonalKitCreator.closeIfInKitCreator(player);
- player.closeInventory();
- fightPlayer.getKit().loadToPlayer(player);
+ player.closeInventory();
+ fightPlayer.getKit().loadToPlayer(player);
+ });
}
}
@Override
public void disable() {
- players.values().forEach(fightPlayer -> fightPlayer.getPlayer().getInventory().clear());
+ players.values().forEach(fightPlayer -> fightPlayer.withPlayer(p -> p.getInventory().clear()));
}
}
@@ -516,14 +526,14 @@ public class FightTeam {
@Override
public void enable() {
players.values().forEach(fightPlayer -> {
- Fight.setPlayerGamemode(fightPlayer.getPlayer(), GameMode.SPECTATOR);
+ fightPlayer.withPlayer(player -> Fight.setPlayerGamemode(player, GameMode.SPECTATOR));
fightPlayer.getPlayer().teleport(FightTeam.this.spawn);
});
}
@Override
public void disable() {
- players.values().forEach(fightPlayer -> Fight.setPlayerGamemode(fightPlayer.getPlayer(), GameMode.SURVIVAL));
+ players.values().forEach(fightPlayer -> fightPlayer.withPlayer(player -> Fight.setPlayerGamemode(player, GameMode.SURVIVAL)));
}
}
}
diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java
index 13ab67a..4b44d40 100644
--- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java
+++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java
@@ -68,11 +68,10 @@ public class JoinRequest {
if(leader == null)
continue;
- Player leaderPlayer = leader.getPlayer();
- if(leaderPlayer == null)
+ if(leader.getPlayer() == null)
continue;
- FightSystem.getMessage().sendPrefixless("JOIN_REQUEST_NOTIFICATION", leaderPlayer, "REQUESTS", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/requests"), player.getName(), team.getColoredName());
+ leader.withPlayer(leaderPlayer -> FightSystem.getMessage().sendPrefixless("JOIN_REQUEST_NOTIFICATION", leaderPlayer, "REQUESTS", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/requests"), player.getName(), team.getColoredName()));
}
activeRequests.put(player, this);
diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/InFightDamage.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/InFightDamage.java
index 9be2167..7194fdd 100644
--- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/InFightDamage.java
+++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/InFightDamage.java
@@ -19,7 +19,6 @@
package de.steamwar.fightsystem.listener;
-import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
@@ -28,7 +27,7 @@ import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.winconditions.Winconditions;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.entity.Arrow;
-import org.bukkit.entity.Player;
+import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@@ -43,25 +42,25 @@ public class InFightDamage implements Listener {
@EventHandler
public void handleEntityDamageByEntity(EntityDamageByEntityEvent event) {
- if(!(event.getEntity() instanceof Player))
+ if(!(event.getEntity() instanceof LivingEntity))
//Target is not a player
return;
- Player player = ((Player) event.getEntity());
+ LivingEntity player = ((LivingEntity) event.getEntity());
if(!Fight.fighting(player))
return;
- Player damager;
+ LivingEntity damager;
- if(event.getDamager() instanceof Player) {
- damager = ((Player) event.getDamager()).getPlayer();
+ if(event.getDamager() instanceof LivingEntity) {
+ damager = (LivingEntity) event.getDamager();
}else if(event.getDamager() instanceof Arrow) {
Arrow damagerArrow = (Arrow) event.getDamager();
- if(!(damagerArrow.getShooter() instanceof Player))
+ if(!(damagerArrow.getShooter() instanceof LivingEntity))
//Shooter is not a player
return;
- damager = (Player) damagerArrow.getShooter();
+ damager = (LivingEntity) damagerArrow.getShooter();
}else{
//Damager is not a player
return;
diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/IngameDeath.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/IngameDeath.java
index 75d80cf..1058968 100644
--- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/IngameDeath.java
+++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/IngameDeath.java
@@ -26,10 +26,12 @@ import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.utils.FightUI;
import de.steamwar.fightsystem.utils.SWSound;
-import org.bukkit.entity.Player;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
+import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent;
@@ -42,7 +44,7 @@ public class IngameDeath implements Listener {
}
@EventHandler
- public void broadcastDeath(PlayerDeathEvent event) {
+ public void broadcastDeath(EntityDeathEvent event) {
onPlayerEnd(event.getEntity(), fightPlayer -> {
FightUI.addSubtitle("UI_PLAYER_DEATH", fightPlayer.getTeam().getPrefix(), fightPlayer.getPlayer().getName());
Fight.playSound(SWSound.ENTITY_WITHER_DEATH.getSound(), 100.0F, 1.0F);
@@ -64,8 +66,11 @@ public class IngameDeath implements Listener {
onPlayerEnd(event.getPlayer(), FightPlayer::setOut);
}
- private void onPlayerEnd(Player player, Consumer withLivingPlayer) {
- FightPlayer fightPlayer = Fight.getFightPlayer(player);
+ private void onPlayerEnd(Entity player, Consumer withLivingPlayer) {
+ if(!(player instanceof LivingEntity))
+ return;
+
+ FightPlayer fightPlayer = Fight.getFightPlayer((LivingEntity) player);
if(fightPlayer == null || !fightPlayer.isLiving())
return;
diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/NormalJoin.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/NormalJoin.java
index 371ae75..931f0b7 100644
--- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/NormalJoin.java
+++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/NormalJoin.java
@@ -20,10 +20,14 @@
package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode;
+import de.steamwar.fightsystem.FightSystem;
+import de.steamwar.fightsystem.ai.AIPlayer;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
+import de.steamwar.sql.SteamwarUser;
+import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@@ -43,7 +47,15 @@ public class NormalJoin implements Listener {
FightTeam team = Fight.teams().stream().filter(t -> player.getUniqueId().equals(t.getDesignatedLeader())).findAny( // Player is designated leader of a team
).orElse(Fight.teams().stream().filter(t -> t.canbeLeader(player)).findAny().orElse(null)); // Else search empty team
- if(team != null)
+ if(team != null) {
team.addMember(player);
+ FightTeam aiTeam = Fight.getOpposite(team);
+ AIPlayer aiPlayer = new AIPlayer(SteamwarUser.get(0));
+ aiTeam.addMember(aiPlayer.getEntity());
+ Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> {
+ FightState.setFightState(FightState.POST_SCHEM_SETUP);
+ aiTeam.setReady(true);
+ }, 1);
+ }
}
}
diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java
index ca3c654..1a6aaec 100644
--- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java
+++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java
@@ -31,7 +31,10 @@ import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.states.StateDependentTask;
-import de.steamwar.fightsystem.utils.*;
+import de.steamwar.fightsystem.utils.BountifulWrapper;
+import de.steamwar.fightsystem.utils.CraftbukkitWrapper;
+import de.steamwar.fightsystem.utils.FlatteningWrapper;
+import de.steamwar.fightsystem.utils.SWSound;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -281,12 +284,13 @@ public class Recording implements Listener {
if(!fp.isLiving())
continue;
- Player player = fp.getPlayer();
- BountifulWrapper.impl.recordHandItems(player);
- GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getHelmet()), "HEAD");
- GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getChestplate()), "CHEST");
- GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getLeggings()), "LEGS");
- GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getBoots()), "FEET");
+ fp.withPlayer(player -> {
+ BountifulWrapper.impl.recordHandItems(player);
+ GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getHelmet()), "HEAD");
+ GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getChestplate()), "CHEST");
+ GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getLeggings()), "LEGS");
+ GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getBoots()), "FEET");
+ });
}
}
diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java
index 2b5f3c7..969cd52 100644
--- a/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java
+++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java
@@ -36,6 +36,7 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
+import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
@@ -148,7 +149,7 @@ public interface Recorder {
* 0x08: Message following
* */
- default void playerJoins(Player p){
+ default void playerJoins(LivingEntity p){
SteamwarUser user = SteamwarUser.get(p.getUniqueId());
write(0x00, p.getEntityId(), user.getId());
diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java
index 284c174..5b443da 100644
--- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java
+++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java
@@ -30,6 +30,7 @@ import de.steamwar.techhider.ProtocolUtils;
import de.steamwar.techhider.TechHider;
import org.bukkit.Bukkit;
import org.bukkit.Material;
+import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import java.util.ArrayList;
@@ -58,13 +59,13 @@ public class TechHiderWrapper extends StateDependent {
techHider.disable();
}
- public List prepareChunkReload(Player p, boolean hide) {
- if(!ENABLED)
+ public List prepareChunkReload(LivingEntity p, boolean hide) {
+ if(!ENABLED || !(p instanceof Player))
return Collections.emptyList();
List chunksToReload = new ArrayList<>();
Config.ArenaRegion.forEachChunk((x, z) -> {
- if(bypass(p, x, z) == hide)
+ if(bypass((Player) p, x, z) == hide)
chunksToReload.add(new ProtocolUtils.ChunkPos(x, z));
});
return chunksToReload;
diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Wincondition.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Wincondition.java
index a01d660..8e6e283 100644
--- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Wincondition.java
+++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Wincondition.java
@@ -24,7 +24,8 @@ import de.steamwar.fightsystem.countdown.Countdown;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.StateDependentCountdown;
-import org.bukkit.entity.Player;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.LivingEntity;
import java.util.ArrayList;
import java.util.List;
@@ -53,8 +54,11 @@ public abstract class Wincondition {
FightSystem.setSpectateState(team, windescription, subtitle, params);
}
- protected FightTeam isTarget(Player player){
- return Fight.getPlayerTeam(player);
+ protected FightTeam isTarget(Entity player){
+ if(!(player instanceof LivingEntity))
+ return null;
+
+ return Fight.getPlayerTeam((LivingEntity) player);
}
public static List getPrintableWinconditions(){
diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java
index 882b9ad..1ab835c 100644
--- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java
+++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java
@@ -24,10 +24,10 @@ import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
-import org.bukkit.entity.Player;
+import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
-import org.bukkit.event.entity.PlayerDeathEvent;
+import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class WinconditionAllDead extends Wincondition implements Listener {
@@ -38,8 +38,8 @@ public class WinconditionAllDead extends Wincondition implements Listener {
}
@EventHandler
- public void handlePlayerDeath(PlayerDeathEvent event) {
- handleDeath(event.getEntity().getPlayer());
+ public void handlePlayerDeath(EntityDeathEvent event) {
+ handleDeath(event.getEntity());
}
@EventHandler
@@ -47,7 +47,7 @@ public class WinconditionAllDead extends Wincondition implements Listener {
handleDeath(event.getPlayer());
}
- private void handleDeath(Player player){
+ private void handleDeath(Entity player){
FightTeam team = isTarget(player);
if(team == null)
return;
diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java
index 6bbaf0e..fef7ff6 100644
--- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java
+++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java
@@ -23,10 +23,11 @@ import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
-import org.bukkit.entity.Player;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
-import org.bukkit.event.entity.PlayerDeathEvent;
+import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class WinconditionCaptainDead extends Wincondition implements Listener {
@@ -37,8 +38,8 @@ public class WinconditionCaptainDead extends Wincondition implements Listener {
}
@EventHandler
- public void handlePlayerDeath(PlayerDeathEvent event) {
- handleDeath(event.getEntity().getPlayer());
+ public void handlePlayerDeath(EntityDeathEvent event) {
+ handleDeath(event.getEntity());
}
@EventHandler
@@ -46,12 +47,12 @@ public class WinconditionCaptainDead extends Wincondition implements Listener {
handleDeath(event.getPlayer());
}
- private void handleDeath(Player player){
+ private void handleDeath(Entity player){
FightTeam team = isTarget(player);
if(team == null)
return;
- if(team.isPlayerLeader(player)) {
+ if(team.isPlayerLeader((LivingEntity) player)) {
win(Fight.getOpposite(team), "WIN_LEADER_DEAD", team.getPrefix() + team.getLeader().getPlayer().getName());
}
}