SteamWar/FightSystem
Archiviert
13
1

AI API
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2023-08-29 13:45:46 +02:00
Ursprung d7b63841a1
Commit 1cc247f6dd
12 geänderte Dateien mit 252 neuen und 110 gelöschten Zeilen

Datei anzeigen

@ -32,7 +32,10 @@ import de.steamwar.fightsystem.fight.FightWorld;
import de.steamwar.fightsystem.fight.HotbarKit; import de.steamwar.fightsystem.fight.HotbarKit;
import de.steamwar.fightsystem.listener.Shutdown; import de.steamwar.fightsystem.listener.Shutdown;
import de.steamwar.fightsystem.listener.*; import de.steamwar.fightsystem.listener.*;
import de.steamwar.fightsystem.record.*; import de.steamwar.fightsystem.record.FileRecorder;
import de.steamwar.fightsystem.record.FileSource;
import de.steamwar.fightsystem.record.GlobalRecorder;
import de.steamwar.fightsystem.record.LiveRecorder;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.OneShotStateDependent; import de.steamwar.fightsystem.states.OneShotStateDependent;
import de.steamwar.fightsystem.utils.*; import de.steamwar.fightsystem.utils.*;
@ -106,7 +109,7 @@ public class FightSystem extends JavaPlugin {
techHider = new TechHiderWrapper(); techHider = new TechHiderWrapper();
new FightWorld(); new FightWorld();
new FightUI(); new FightUI();
//new FightStatistics(); new FightStatistics();
new BungeeFightInfo(); new BungeeFightInfo();
new WinconditionAllDead(); new WinconditionAllDead();
@ -164,8 +167,6 @@ public class FightSystem extends JavaPlugin {
}else if(Config.mode == ArenaMode.PREPARE) { }else if(Config.mode == ArenaMode.PREPARE) {
Fight.getUnrotated().setSchem(SchematicNode.getSchematicNode(Config.PrepareSchemID)); Fight.getUnrotated().setSchem(SchematicNode.getSchematicNode(Config.PrepareSchemID));
} }
new LixfelAI(Fight.getBlueTeam());
} }
@Override @Override

Datei anzeigen

@ -19,29 +19,46 @@
package de.steamwar.fightsystem.ai; package de.steamwar.fightsystem.ai;
import com.comphenix.tinyprotocol.Reflection; import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config; 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.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.listener.Chat;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.OneShotStateDependent;
import de.steamwar.fightsystem.utils.Region;
import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Note;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Openable;
import org.bukkit.block.data.Powerable;
import org.bukkit.block.data.type.NoteBlock;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Villager;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.HashMap; import java.util.*;
import java.util.Map; import java.util.logging.Level;
import java.util.UUID;
public abstract class AI { public abstract class AI {
private static final Map<UUID, AI> ais = new HashMap<>(); private static final Map<UUID, AI> ais = new HashMap<>();
static {
new OneShotStateDependent(ArenaMode.All, FightState.Spectate, () -> {
ais.values().forEach(AI::stop);
ais.clear();
});
}
public static AI getAI(UUID uuid) { public static AI getAI(UUID uuid) {
return ais.get(uuid); return ais.get(uuid);
} }
@ -49,20 +66,18 @@ public abstract class AI {
private final FightTeam team; private final FightTeam team;
private final LivingEntity entity; private final LivingEntity entity;
private final BukkitTask task; private final BukkitTask task;
private int cooldown; private final Queue<Action> queue = new ArrayDeque<>();
private static final Reflection.MethodInvoker getHandle = Reflection.getMethod("{obc}.entity.CraftEntity", "getHandle");
private static final Reflection.FieldAccessor<UUID> entityUUID = Reflection.getField("{nms.world.entity}.Entity", UUID.class, 0);
protected AI(FightTeam team, SteamwarUser user) { protected AI(FightTeam team, SteamwarUser user) {
this.team = team; this.team = team;
entity = Config.world.spawn(Config.SpecSpawn, Villager.class, entity -> entityUUID.set(getHandle.invoke(entity), user.getUUID())); entity = (LivingEntity) Config.world.spawnEntity(Config.SpecSpawn, EntityType.VILLAGER);
entity.setCustomName(user.getUserName()); entity.setCustomName(user.getUserName());
entity.setAI(false); entity.setAI(false);
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::run, 1, 1); task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::run, 1, 1);
ais.put(user.getUUID(), this); ais.put(entity.getUniqueId(), this);
team.addMember(entity); team.addMember(entity, user);
} }
public abstract SchematicNode chooseSchematic(); public abstract SchematicNode chooseSchematic();
@ -73,8 +88,11 @@ public abstract class AI {
protected abstract void plan(); protected abstract void plan();
public void cleanup() { public void stop() {
ais.remove(entity.getUniqueId()); if(!entity.isDead())
entity.remove();
if(!task.isCancelled())
task.cancel(); task.cancel();
} }
@ -92,36 +110,151 @@ public abstract class AI {
team.setReady(true); team.setReady(true);
} }
protected void chat(String message) {
FightSystem.getPlugin().getLogger().log(Level.INFO, entity.getName() + "» " + message);
Chat.broadcastChat("PARTICIPANT_CHAT", team.getColoredName(), entity.getName(), message);
}
protected Vector getPosition() {
Location location = entity.getLocation();
Region extend = team.getExtendRegion();
if(Fight.getUnrotated() == team)
return new Vector(
location.getX() - extend.getMinX(),
location.getY() - extend.getMinY(),
location.getZ() - extend.getMinZ()
);
else
return new Vector(
extend.getMaxX() - location.getX(),
location.getY() - extend.getMinY(),
extend.getMaxZ() - location.getZ()
);
}
protected Material getBlock(Vector pos) { protected Material getBlock(Vector pos) {
//TODO position translation queue.add(new Action(1));
cooldown++; return translate(pos, true).getBlock().getType();
return pos.toLocation(Config.world).getBlock().getType(); }
protected boolean isPowered(Vector pos) {
queue.add(new Action(1));
return translate(pos, true).getBlock().isBlockPowered();
} }
protected void setTNT(Vector pos) { protected void setTNT(Vector pos) {
//TODO position translation queue.add(new Action(1) {
//TODO Check position @Override
//TODO Check AIR is there public void run() {
cooldown++; Location location = translate(pos, true);
pos.toLocation(Config.world).getBlock().setType(Material.TNT); if(interactionDistanceViolation(location))
return;
Block block = location.getBlock();
if(block.getType() == Material.AIR)
block.setType(Material.TNT);
}
});
}
protected void interact(Vector pos) {
queue.add(new Action(1) {
@Override
public void run() {
Location location = translate(pos, true);
if(interactionDistanceViolation(location))
return;
interact(location.getBlock());
}
});
} }
protected void move(Vector pos) { protected void move(Vector pos) {
//TODO position translation queue.add(new Action(2) {
//TODO Check position @Override
//TODO falling check public void run() {
//TODO pathfinding if(!entity.isOnGround())
cooldown += 5; return;
entity.teleport(pos.toLocation(Config.world));
Location location = entity.getLocation();
Location target = translate(pos, false);
if(Math.abs(location.getX() - target.getX()) > 1 || Math.abs(location.getY() - target.getY()) > 1 || Math.abs(location.getZ() - target.getZ()) > 1)
return;
entity.teleport(target);
}
});
}
private boolean interactionDistanceViolation(Location location) {
return location.distance(entity.getEyeLocation()) > 5;
}
private void interact(Block block) {
BlockData data = block.getBlockData(); //TODO only 1.14+ compatible at the moment
if (data instanceof NoteBlock) {
NoteBlock noteBlock = (NoteBlock) data;
Note note = noteBlock.getNote();
noteBlock.setNote(note.isSharped() ? note.flattened() : note.sharped());
} else if (data instanceof Openable) {
Openable openable = (Openable) data;
openable.setOpen(!openable.isOpen());
} else if (data instanceof Powerable) {
Material type = block.getType();
Powerable powerable = (Powerable) data;
boolean isPowered = powerable.isPowered();
if(type.name().endsWith("BUTTON")) {
if(isPowered)
return;
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> {
if(!block.getType().name().endsWith("BUTTON"))
return;
powerable.setPowered(false);
block.setBlockData(powerable);
}, type.name().endsWith("STONE_BUTTON") ? 20 : 30);
}
powerable.setPowered(!isPowered);
}
block.setBlockData(data);
} }
private void run() { private void run() {
if(cooldown > 0) if(queue.isEmpty())
cooldown--;
if(cooldown > 0)
return;
plan(); plan();
if(!queue.isEmpty() && --queue.peek().delay == 0)
queue.poll().run();
}
private Location translate(Vector pos, boolean blockPos) {
Region extend = team.getExtendRegion();
if(Fight.getUnrotated() == team)
return new Location(
Config.world,
pos.getX() + extend.getMinX(),
pos.getY() + extend.getMinY(),
pos.getZ() + extend.getMinZ()
);
else
return new Location(
Config.world,
extend.getMaxX() - pos.getX() - (blockPos ? 1 : 0),
pos.getY() + extend.getMinY(),
extend.getMaxZ() - pos.getZ() - (blockPos ? 1 : 0)
);
}
private static class Action {
private int delay;
public Action(int delay) {
this.delay = delay;
}
public void run() {}
} }
} }

Datei anzeigen

@ -88,7 +88,7 @@ public class Fight {
} }
public static FightTeam getUnrotated() { public static FightTeam getUnrotated() {
return Config.BlueRotate ? Fight.getRedTeam() : Fight.getBlueTeam(); return Config.blueNegZ() ? Fight.getBlueTeam() : Fight.getRedTeam();
} }
public static void playSound(Sound sound, float volume, float pitch) { public static void playSound(Sound sound, float volume, float pitch) {

Datei anzeigen

@ -28,12 +28,11 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.UUID;
import java.util.function.Consumer; import java.util.function.Consumer;
public class FightPlayer { public class FightPlayer {
private final UUID uuid; private final int id;
private LivingEntity entity; private LivingEntity entity;
private final FightTeam team; private final FightTeam team;
private boolean isOut; private boolean isOut;
@ -41,14 +40,14 @@ public class FightPlayer {
private int kills; private int kills;
private EnternCountdown enternCountdown = null; private EnternCountdown enternCountdown = null;
FightPlayer(LivingEntity player, FightTeam team) { FightPlayer(LivingEntity entity, SteamwarUser user, FightTeam team) {
this.uuid = player.getUniqueId(); this.id = user.getId();
this.entity = player; this.entity = entity;
this.team = team; this.team = team;
this.isOut = false; this.isOut = false;
kit = Kit.getKitByName(Config.MemberDefault); kit = Kit.getKitByName(Config.MemberDefault);
if(Config.PersonalKits){ if(Config.PersonalKits){
PersonalKit personalKit = PersonalKit.getKitInUse(SteamwarUser.get(uuid).getId(), Config.SchematicType.toDB()); PersonalKit personalKit = PersonalKit.getKitInUse(user.getId(), Config.SchematicType.toDB());
if(personalKit != null){ if(personalKit != null){
kit = new Kit(personalKit); kit = new Kit(personalKit);
} }
@ -63,7 +62,7 @@ public class FightPlayer {
public void setOut() { public void setOut() {
isOut = true; isOut = true;
stopEnternCountdown(); stopEnternCountdown();
ifAI(AI::cleanup); ifAI(AI::stop);
} }
public void startEnternCountdown() { public void startEnternCountdown() {
@ -79,15 +78,19 @@ public class FightPlayer {
} }
public LivingEntity getEntity() { public LivingEntity getEntity() {
Player bukkit = Bukkit.getPlayer(uuid); LivingEntity bukkit = (LivingEntity) Bukkit.getEntity(entity.getUniqueId());
if(bukkit != null) if(bukkit != null)
entity = bukkit; entity = bukkit;
return entity; return entity;
} }
public SteamwarUser getUser() {
return SteamwarUser.get(id);
}
public void ifAI(Consumer<AI> function) { public void ifAI(Consumer<AI> function) {
if(!(entity instanceof Player)) if(!(entity instanceof Player))
function.accept(AI.getAI(uuid)); function.accept(AI.getAI(entity.getUniqueId()));
} }
public void ifPlayer(Consumer<Player> function) { public void ifPlayer(Consumer<Player> function) {

Datei anzeigen

@ -203,21 +203,21 @@ public class FightTeam {
Set<UUID> playerSet = new HashSet<>(players.keySet()); Set<UUID> playerSet = new HashSet<>(players.keySet());
for(UUID uuid : playerSet){ for(UUID uuid : playerSet){
LivingEntity player = (LivingEntity) Bukkit.getEntity(uuid); Player player = Bukkit.getPlayer(uuid);
if(player == null) if(player == null)
removePlayer(players.get(uuid).getEntity()); removePlayer(players.get(uuid).getEntity());
} }
FightPlayer leaderBackup = leader; FightPlayer leaderBackup = leader;
playerSet.removeIf(uuid -> Bukkit.getEntity(uuid) == null); playerSet.removeIf(uuid -> Bukkit.getPlayer(uuid) == null);
players.clear(); players.clear();
leader = null; leader = null;
if(leaderBackup != null){ if(leaderBackup != null){
playerSet.remove(leaderBackup.getEntity().getUniqueId()); playerSet.remove(leaderBackup.getEntity().getUniqueId());
addMember(leaderBackup.getEntity(), true); addMember(leaderBackup.getEntity(), leaderBackup.getUser(), true);
} }
playerSet.forEach(uuid -> addMember((LivingEntity) Bukkit.getEntity(uuid), true)); playerSet.forEach(uuid -> addMember(Bukkit.getPlayer(uuid), SteamwarUser.get(uuid), true));
if(ArenaMode.VariableTeams.contains(Config.mode) && isLeaderless()){ if(ArenaMode.VariableTeams.contains(Config.mode) && isLeaderless()){
List<Player> onlinePlayers = new ArrayList<>(Bukkit.getOnlinePlayers()); List<Player> onlinePlayers = new ArrayList<>(Bukkit.getOnlinePlayers());
@ -251,72 +251,76 @@ public class FightTeam {
}); });
} }
public void addMember(LivingEntity player) { public void addMember(Player player) {
addMember(player, false); addMember(player, SteamwarUser.get(player.getUniqueId()), false);
} }
private void addMember(LivingEntity player, boolean silent) { public void addMember(LivingEntity entity, SteamwarUser user) {
final List<ProtocolUtils.ChunkPos> chunksToReload = FightSystem.getTechHider().prepareChunkReload(player, false); addMember(entity, user, false);
FightPlayer fightPlayer = getFightPlayer(player) != null ? getFightPlayer(player) : new FightPlayer(player, this); }
public void addMember(LivingEntity entity, SteamwarUser user, boolean silent) {
final List<ProtocolUtils.ChunkPos> chunksToReload = FightSystem.getTechHider().prepareChunkReload(entity, false);
FightPlayer fightPlayer = getFightPlayer(entity) != null ? getFightPlayer(entity) : new FightPlayer(entity, user, this);
fightPlayer.revive(); fightPlayer.revive();
players.put(player.getUniqueId(), fightPlayer); players.put(entity.getUniqueId(), fightPlayer);
Permanent.getSpectatorTeam().removeEntry(player.getName()); Permanent.getSpectatorTeam().removeEntry(entity.getName());
team.addEntry(player.getName()); team.addEntry(entity.getName());
player.setHealth(20); entity.setHealth(20);
player.teleport(spawn); entity.teleport(spawn);
fightPlayer.ifPlayer(p -> { fightPlayer.ifPlayer(player -> {
BountifulWrapper.impl.setAttackSpeed(p); BountifulWrapper.impl.setAttackSpeed(player);
p.setFoodLevel(20); player.setFoodLevel(20);
p.getInventory().clear(); player.getInventory().clear();
if(FightState.Spectate.contains(FightState.getFightState())) { if(FightState.Spectate.contains(FightState.getFightState())) {
Fight.setPlayerGamemode(p, GameMode.SPECTATOR); Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
} else { } else {
Fight.setPlayerGamemode(p, GameMode.SURVIVAL); Fight.setPlayerGamemode(player, GameMode.SURVIVAL);
(FightState.ingame() ? fightPlayer.getKit() : memberKit).loadToPlayer(p); (FightState.ingame() ? fightPlayer.getKit() : memberKit).loadToPlayer(player);
} }
}); });
if(FightState.Running.contains(FightState.getFightState())) if(FightState.Running.contains(FightState.getFightState()))
fightPlayer.startEnternCountdown(); fightPlayer.startEnternCountdown();
GlobalRecorder.getInstance().playerJoins(player); GlobalRecorder.getInstance().playerJoins(entity, user);
fightPlayer.ifPlayer(p -> FightSystem.getTechHider().reloadChunks(p, chunksToReload, false)); fightPlayer.ifPlayer(player -> FightSystem.getTechHider().reloadChunks(player, chunksToReload, false));
if(isLeaderless()) if(isLeaderless())
setLeader(fightPlayer, silent); setLeader(fightPlayer, silent);
else if(!silent) else if(!silent)
FightUI.addSubtitle("UI_PLAYER_JOINS", prefix, player.getName()); FightUI.addSubtitle("UI_PLAYER_JOINS", prefix, entity.getName());
} }
public void removePlayer(LivingEntity player) { public void removePlayer(LivingEntity entity) {
FightPlayer fightPlayer = getFightPlayer(player); FightPlayer fightPlayer = getFightPlayer(entity);
fightPlayer.ifPlayer(PersonalKitCreator::closeIfInKitCreator); fightPlayer.ifPlayer(PersonalKitCreator::closeIfInKitCreator);
List<ProtocolUtils.ChunkPos> chunksToReload = FightSystem.getTechHider().prepareChunkReload(player, true); List<ProtocolUtils.ChunkPos> chunksToReload = FightSystem.getTechHider().prepareChunkReload(entity, true);
players.remove(player.getUniqueId()); players.remove(entity.getUniqueId());
team.removeEntry(player.getName()); team.removeEntry(entity.getName());
Permanent.getSpectatorTeam().addEntry(player.getName()); Permanent.getSpectatorTeam().addEntry(entity.getName());
FightUI.addSubtitle("UI_PLAYER_LEAVES", prefix, player.getName()); FightUI.addSubtitle("UI_PLAYER_LEAVES", prefix, entity.getName());
if(fightPlayer.equals(leader)) if(fightPlayer.equals(leader))
removeLeader(); removeLeader();
GlobalRecorder.getInstance().entityDespawns(player); GlobalRecorder.getInstance().entityDespawns(entity);
player.teleport(Config.SpecSpawn); entity.teleport(Config.SpecSpawn);
fightPlayer.ifPlayer(p -> { fightPlayer.ifPlayer(player -> {
Fight.setPlayerGamemode(p, GameMode.SPECTATOR); Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
p.getInventory().clear(); player.getInventory().clear();
if(p.isOnline()){ if(player.isOnline()){
FightSystem.getTechHider().reloadChunks(p, chunksToReload, true); FightSystem.getTechHider().reloadChunks(player, chunksToReload, true);
if(ArenaMode.VariableTeams.contains(Config.mode)) if(ArenaMode.VariableTeams.contains(Config.mode))
HotbarKit.SPECTATOR_KIT.loadToPlayer(p); HotbarKit.SPECTATOR_KIT.loadToPlayer(player);
} }
}); });
} }
@ -353,7 +357,7 @@ public class FightTeam {
if(!silent) if(!silent)
FightUI.addSubtitle("UI_LEADER_JOINS", prefix, leader.getEntity().getName()); FightUI.addSubtitle("UI_LEADER_JOINS", prefix, leader.getEntity().getName());
Optional<Integer> maxRank = SchematicNode.getAllAccessibleSchematicsOfType(SteamwarUser.get(leader.getEntity().getUniqueId()).getId(), Config.SchematicType.toDB()).stream().map(SchematicNode::getRank).max(Integer::compare); Optional<Integer> maxRank = SchematicNode.getAllAccessibleSchematicsOfType(leader.getUser().getId(), Config.SchematicType.toDB()).stream().map(SchematicNode::getRank).max(Integer::compare);
if(Config.RanksEnabled) if(Config.RanksEnabled)
schemRank = maxRank.orElse(1); schemRank = maxRank.orElse(1);
else else
@ -373,7 +377,7 @@ public class FightTeam {
FightState.setFightState(FightState.PRE_SCHEM_SETUP); FightState.setFightState(FightState.PRE_SCHEM_SETUP);
} }
leader.ifAI(ai -> setSchem(ai.chooseSchematic())); leader.ifAI(ai -> pasteSchem(ai.chooseSchematic()));
} }
public Collection<FightPlayer> getPlayers() { public Collection<FightPlayer> getPlayers() {

Datei anzeigen

@ -63,6 +63,7 @@ public class JoinRequest {
this.player = player; this.player = player;
this.team = team; this.team = team;
this.waitOnApproval = new HashSet<>(FightState.ingame() ? Fight.teams() : Collections.singleton(team)); this.waitOnApproval = new HashSet<>(FightState.ingame() ? Fight.teams() : Collections.singleton(team));
Set<FightTeam> alreadyAccepted = new HashSet<>();
activeRequests.put(player, this); activeRequests.put(player, this);
for(FightTeam t : waitOnApproval) { for(FightTeam t : waitOnApproval) {
@ -76,11 +77,12 @@ public class JoinRequest {
leader.ifPlayer(leaderPlayer -> FightSystem.getMessage().sendPrefixless("JOIN_REQUEST_NOTIFICATION", leaderPlayer, "REQUESTS", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/requests"), player.getName(), team.getColoredName())); leader.ifPlayer(leaderPlayer -> FightSystem.getMessage().sendPrefixless("JOIN_REQUEST_NOTIFICATION", leaderPlayer, "REQUESTS", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/requests"), player.getName(), team.getColoredName()));
leader.ifAI(ai -> { leader.ifAI(ai -> {
if(ai.acceptJoinRequest(player, team)) if(ai.acceptJoinRequest(player, team))
accept(t); alreadyAccepted.add(t);
}); });
} }
FightSystem.getMessage().sendPrefixless("JOIN_REQUEST_CONFIRMATION", player, ChatMessageType.ACTION_BAR); FightSystem.getMessage().sendPrefixless("JOIN_REQUEST_CONFIRMATION", player, ChatMessageType.ACTION_BAR);
alreadyAccepted.forEach(this::accept);
} }
public boolean required(FightTeam decider) { public boolean required(FightTeam decider) {

Datei anzeigen

@ -23,14 +23,15 @@ import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config; 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.FightPlayer;
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 de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.states.StateDependentTask; import de.steamwar.fightsystem.states.StateDependentTask;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -69,10 +70,12 @@ public class ArenaBorder implements Listener {
} }
private void damage() { private void damage() {
for(Player player : Bukkit.getServer().getOnlinePlayers()) { Fight.teams().forEach(team -> {
FightTeam team = Fight.getPlayerTeam(player); for(FightPlayer fp : team.getPlayers()) {
if(team != null && player.getLocation().getY() <= Config.PlayerRegion.getMinY()) LivingEntity entity = fp.getEntity();
player.damage(1); if(fp.isLiving() && entity.getLocation().getY() <= Config.PlayerRegion.getMinY())
} entity.damage(1);
}
});
} }
} }

Datei anzeigen

@ -63,7 +63,7 @@ public class Chat implements Listener {
event.setCancelled(true); event.setCancelled(true);
} }
private void broadcastChat(String message, Object... params) { public static void broadcastChat(String message, Object... params) {
GlobalRecorder.getInstance().chat(message, params); GlobalRecorder.getInstance().chat(message, params);
FightSystem.getMessage().chat(message, params); FightSystem.getMessage().chat(message, params);
} }

Datei anzeigen

@ -32,7 +32,6 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -57,7 +56,7 @@ public class IngameDeath implements Listener {
} }
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void handlePlayerDeath(PlayerDeathEvent event) { public void handlePlayerDeath(EntityDeathEvent event) {
onPlayerEnd(event.getEntity(), FightPlayer::setOut); onPlayerEnd(event.getEntity(), FightPlayer::setOut);
} }

Datei anzeigen

@ -69,7 +69,7 @@ public interface Recorder {
if(FightState.AntiSpectate.contains(FightState.getFightState())){ if(FightState.AntiSpectate.contains(FightState.getFightState())){
for(FightPlayer player : team.getPlayers()){ for(FightPlayer player : team.getPlayers()){
if(player.isLiving()){ if(player.isLiving()){
playerJoins(player.getEntity()); playerJoins(player.getEntity(), player.getUser());
} }
} }
} }
@ -149,9 +149,7 @@ public interface Recorder {
* 0x08: Message following * 0x08: Message following
* */ * */
default void playerJoins(LivingEntity p){ default void playerJoins(LivingEntity p, SteamwarUser user){
SteamwarUser user = SteamwarUser.get(p.getUniqueId());
write(0x00, p.getEntityId(), user.getId()); write(0x00, p.getEntityId(), user.getId());
entityMoves(p); entityMoves(p);
} }

Datei anzeigen

@ -52,12 +52,12 @@ public class BungeeFightInfo {
Fight.getRedTeam().getColoredName(), Fight.getRedTeam().getColoredName(),
FightState.getFightState().name(), FightState.getFightState().name(),
StateDependentCountdown.getMainCountdown() != null ? StateDependentCountdown.getMainCountdown().getTimeLeft() : 0, StateDependentCountdown.getMainCountdown() != null ? StateDependentCountdown.getMainCountdown().getTimeLeft() : 0,
Fight.getBlueTeam().getLeader() != null ? SteamwarUser.get(Fight.getBlueTeam().getLeader().getEntity().getUniqueId()).getId() : 0, Fight.getBlueTeam().getLeader() != null ? Fight.getBlueTeam().getLeader().getUser().getId() : 0,
Fight.getRedTeam().getLeader() != null ? SteamwarUser.get(Fight.getRedTeam().getLeader().getEntity().getUniqueId()).getId() : 0, Fight.getRedTeam().getLeader() != null ? Fight.getRedTeam().getLeader().getUser().getId() : 0,
Fight.getBlueTeam().getSchematic(), Fight.getBlueTeam().getSchematic(),
Fight.getRedTeam().getSchematic(), Fight.getRedTeam().getSchematic(),
Fight.getBlueTeam().getPlayers().stream().map(p -> SteamwarUser.get(p.getEntity().getUniqueId()).getId()).collect(Collectors.toList()), Fight.getBlueTeam().getPlayers().stream().map(p -> p.getUser().getId()).collect(Collectors.toList()),
Fight.getRedTeam().getPlayers().stream().map(p -> SteamwarUser.get(p.getEntity().getUniqueId()).getId()).collect(Collectors.toList()), Fight.getRedTeam().getPlayers().stream().map(p -> p.getUser().getId()).collect(Collectors.toList()),
Bukkit.getOnlinePlayers().stream().filter(p -> Fight.getPlayerTeam(p) == null).map(p -> SteamwarUser.get(p.getUniqueId()).getId()).collect(Collectors.toList()) Bukkit.getOnlinePlayers().stream().filter(p -> Fight.getPlayerTeam(p) == null).map(p -> SteamwarUser.get(p.getUniqueId()).getId()).collect(Collectors.toList())
)); ));
} }

Datei anzeigen

@ -136,7 +136,7 @@ public class FightStatistics {
} }
if (!Bukkit.getOnlinePlayers().isEmpty() && !unranked) { if (!Bukkit.getOnlinePlayers().isEmpty() && !unranked) {
NetworkSender.send(new FightEndsPacket((byte) win, blueSchem == null ? 0 : blueSchem, redSchem == null ? 0 : redSchem, Fight.getBlueTeam().getPlayers().stream().map(FightPlayer::getEntity).map(p -> SteamwarUser.get(p.getUniqueId())).map(SteamwarUser::getId).collect(Collectors.toList()), Fight.getRedTeam().getPlayers().stream().map(FightPlayer::getEntity).map(p -> SteamwarUser.get(p.getUniqueId())).map(SteamwarUser::getId).collect(Collectors.toList()), gameMode, (int)(endTime.getEpochSecond() - starttime.toInstant().getEpochSecond()))); NetworkSender.send(new FightEndsPacket((byte) win, blueSchem == null ? 0 : blueSchem, redSchem == null ? 0 : redSchem, Fight.getBlueTeam().getPlayers().stream().map(FightPlayer::getUser).map(SteamwarUser::getId).collect(Collectors.toList()), Fight.getRedTeam().getPlayers().stream().map(FightPlayer::getUser).map(SteamwarUser::getId).collect(Collectors.toList()), gameMode, (int)(endTime.getEpochSecond() - starttime.toInstant().getEpochSecond())));
} }
unranked = false; unranked = false;
@ -144,14 +144,13 @@ public class FightStatistics {
private int getLeader(FightTeam team) { private int getLeader(FightTeam team) {
if (team.getLeader() != null) if (team.getLeader() != null)
return SteamwarUser.get(team.getLeader().getEntity().getUniqueId()).getId(); return team.getLeader().getUser().getId();
else if (team.getDesignatedLeader() != null) else if (team.getDesignatedLeader() != null)
return SteamwarUser.get(team.getDesignatedLeader()).getId(); return SteamwarUser.get(team.getDesignatedLeader()).getId();
return 0; return 0;
} }
private void savePlayerStats(FightPlayer fp, int fightId) { private void savePlayerStats(FightPlayer fp, int fightId) {
SteamwarUser user = SteamwarUser.get(fp.getEntity().getUniqueId()); de.steamwar.sql.FightPlayer.create(fightId, fp.getUser().getId(), fp.getTeam().isBlue(), fp.getKit().getName(), fp.getKills(), !fp.isLiving());
de.steamwar.sql.FightPlayer.create(fightId, user.getId(), fp.getTeam().isBlue(), fp.getKit().getName(), fp.getKills(), !fp.isLiving());
} }
} }