SteamWar/FightSystem
Archiviert
13
1

Merge pull request 'AI API' (#396) from villager-ai into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #396
Reviewed-by: Chaoscaot <chaoscaot@zohomail.eu>
Dieser Commit ist enthalten in:
Lixfel 2023-08-29 21:51:45 +02:00
Commit 58d1f69e1c
23 geänderte Dateien mit 529 neuen und 162 gelöschten Zeilen

Datei anzeigen

@ -21,6 +21,7 @@ package de.steamwar.fightsystem;
import com.comphenix.tinyprotocol.TinyProtocol; import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.core.Core; import de.steamwar.core.Core;
import de.steamwar.fightsystem.ai.LixfelAI;
import de.steamwar.fightsystem.commands.*; import de.steamwar.fightsystem.commands.*;
import de.steamwar.fightsystem.countdown.*; import de.steamwar.fightsystem.countdown.*;
import de.steamwar.fightsystem.event.HellsBells; import de.steamwar.fightsystem.event.HellsBells;
@ -31,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.*;

Datei anzeigen

@ -0,0 +1,260 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.ai;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.listener.Chat;
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.SteamwarUser;
import org.bukkit.Bukkit;
import org.bukkit.Location;
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.Player;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
import java.util.*;
import java.util.logging.Level;
public abstract class AI {
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) {
return ais.get(uuid);
}
private final FightTeam team;
private final LivingEntity entity;
private final BukkitTask task;
private final Queue<Action> queue = new ArrayDeque<>();
protected AI(FightTeam team, SteamwarUser user) {
this.team = team;
entity = (LivingEntity) Config.world.spawnEntity(Config.SpecSpawn, EntityType.VILLAGER);
entity.setCustomName(user.getUserName());
entity.setAI(false);
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::run, 1, 1);
ais.put(entity.getUniqueId(), this);
team.addMember(entity, user);
}
public abstract SchematicNode chooseSchematic();
public boolean acceptJoinRequest(Player player, FightTeam team) {
return true;
}
protected abstract void plan();
public void stop() {
if(!entity.isDead())
entity.remove();
if(!task.isCancelled())
task.cancel();
}
public LivingEntity getEntity() {
return entity;
}
protected void setReady() {
if(FightState.getFightState() != FightState.POST_SCHEM_SETUP)
return;
if(team.getLeader().getEntity() != entity)
return;
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) {
queue.add(new Action(1));
return translate(pos, true).getBlock().getType();
}
protected boolean isPowered(Vector pos) {
queue.add(new Action(1));
return translate(pos, true).getBlock().isBlockPowered();
}
protected void setTNT(Vector pos) {
queue.add(new Action(1) {
@Override
public void run() {
Location location = translate(pos, true);
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) {
queue.add(new Action(2) {
@Override
public void run() {
if(!entity.isOnGround())
return;
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() {
if(queue.isEmpty())
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

@ -0,0 +1,46 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.ai;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser;
import java.util.List;
import java.util.Random;
public class LixfelAI extends AI {
public LixfelAI(FightTeam team) {
super(team, SteamwarUser.get("public"));
}
@Override
public SchematicNode chooseSchematic() {
List<SchematicNode> publics = SchematicNode.getAllSchematicsOfType(0, Config.SchematicType.toDB());
return publics.get(new Random().nextInt(publics.size()));
}
@Override
protected void plan() {
setReady();
getEntity().setAI(true);
}
}

Datei anzeigen

@ -33,6 +33,7 @@ import de.steamwar.sql.SteamwarUser;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
@ -101,7 +102,7 @@ public class GUI {
FightTeam team = Fight.getPlayerTeam(p); FightTeam team = Fight.getPlayerTeam(p);
if(team == null) if(team == null)
return; 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<UUID> inv = new SWListInv<>(p, msg.parse("REMOVE_TITLE", p), players, (ClickType click, UUID player) -> { SWListInv<UUID> inv = new SWListInv<>(p, msg.parse("REMOVE_TITLE", p), players, (ClickType click, UUID player) -> {
Commands.kick(p, SteamwarUser.get(player).getUserName()); Commands.kick(p, SteamwarUser.get(player).getUserName());
p.closeInventory(); p.closeInventory();

Datei anzeigen

@ -51,7 +51,7 @@ public class InfoCommand implements CommandExecutor {
FightSystem.getMessage().send("INFO_RANKED", player, !FightStatistics.isUnranked()); FightSystem.getMessage().send("INFO_RANKED", player, !FightStatistics.isUnranked());
for(FightTeam team : Fight.teams()) { for(FightTeam team : Fight.teams()) {
if(!team.isLeaderless()) if(!team.isLeaderless())
FightSystem.getMessage().send("INFO_LEADER", player, team.getColoredName(), team.getLeader().getPlayer().getName()); FightSystem.getMessage().send("INFO_LEADER", player, team.getColoredName(), team.getLeader().getEntity().getName());
if(team.getSchematic() != 0) { if(team.getSchematic() != 0) {
SchematicNode schematic = SchematicNode.getSchematicNode(team.getSchematic()); SchematicNode schematic = SchematicNode.getSchematicNode(team.getSchematic());

Datei anzeigen

@ -57,18 +57,20 @@ public class EnternCountdown extends Countdown {
@Override @Override
public void countdownFinished() { public void countdownFinished() {
FightSystem.getMessage().sendPrefixless("ENTERN_ALLOWED", fightPlayer.getPlayer(), ChatMessageType.ACTION_BAR); FightSystem.getMessage().sendPrefixless("ENTERN_ALLOWED", fightPlayer.getEntity(), ChatMessageType.ACTION_BAR);
FightSystem.getTechHider().reloadChunks(fightPlayer.getPlayer(), chunkPos, false); fightPlayer.ifPlayer(player -> FightSystem.getTechHider().reloadChunks(player, chunkPos, false));
} }
@Override @Override
protected void prepareFinish() { protected void prepareFinish() {
chunkPos = FightSystem.getTechHider().prepareChunkReload(fightPlayer.getPlayer(), false); chunkPos = FightSystem.getTechHider().prepareChunkReload(fightPlayer.getEntity(), false);
} }
@Override @Override
protected void broadcast(String message, int divisor) { protected void broadcast(String message, int divisor) {
fightPlayer.getPlayer().playSound(fightPlayer.getPlayer().getLocation(), sound, 100.0f, 1.0f); fightPlayer.ifPlayer(player -> {
sendCountdownMessage(fightPlayer.getPlayer(), message, time / divisor, appendix); player.playSound(player.getLocation(), sound, 100.0f, 1.0f);
sendCountdownMessage(player, message, time / divisor, appendix);
});
} }
} }

Datei anzeigen

@ -29,6 +29,7 @@ import de.steamwar.fightsystem.record.GlobalRecorder;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Collection; import java.util.Collection;
@ -45,7 +46,7 @@ public class Fight {
teams.add(blueTeam); teams.add(blueTeam);
} }
public static FightTeam getPlayerTeam(Player player) { public static FightTeam getPlayerTeam(LivingEntity player) {
if(redTeam.isPlayerInTeam(player)) if(redTeam.isPlayerInTeam(player))
return redTeam; return redTeam;
if(blueTeam.isPlayerInTeam(player)) if(blueTeam.isPlayerInTeam(player))
@ -62,7 +63,7 @@ public class Fight {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
public static FightPlayer getFightPlayer(Player player) { public static FightPlayer getFightPlayer(LivingEntity player) {
if(redTeam.isPlayerInTeam(player)) if(redTeam.isPlayerInTeam(player))
return redTeam.getFightPlayer(player); return redTeam.getFightPlayer(player);
if(blueTeam.isPlayerInTeam(player)) if(blueTeam.isPlayerInTeam(player))
@ -70,7 +71,7 @@ public class Fight {
return null; return null;
} }
public static boolean fighting(Player player) { public static boolean fighting(LivingEntity player) {
return getPlayerTeam(player) != null; return getPlayerTeam(player) != null;
} }
@ -87,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

@ -20,32 +20,34 @@
package de.steamwar.fightsystem.fight; package de.steamwar.fightsystem.fight;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.ai.AI;
import de.steamwar.fightsystem.countdown.EnternCountdown; import de.steamwar.fightsystem.countdown.EnternCountdown;
import de.steamwar.sql.PersonalKit; import de.steamwar.sql.PersonalKit;
import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.UUID; import java.util.function.Consumer;
public class FightPlayer { public class FightPlayer {
private final UUID uuid; private final int id;
private Player player; private LivingEntity entity;
private final FightTeam team; private final FightTeam team;
private boolean isOut; private boolean isOut;
private Kit kit; private Kit kit;
private int kills; private int kills;
private EnternCountdown enternCountdown = null; private EnternCountdown enternCountdown = null;
FightPlayer(Player player, FightTeam team) { FightPlayer(LivingEntity entity, SteamwarUser user, FightTeam team) {
this.uuid = player.getUniqueId(); this.id = user.getId();
this.player = 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(player.getUniqueId()).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);
} }
@ -60,6 +62,7 @@ public class FightPlayer {
public void setOut() { public void setOut() {
isOut = true; isOut = true;
stopEnternCountdown(); stopEnternCountdown();
ifAI(AI::stop);
} }
public void startEnternCountdown() { public void startEnternCountdown() {
@ -74,11 +77,25 @@ public class FightPlayer {
enternCountdown = null; enternCountdown = null;
} }
public Player getPlayer() { public LivingEntity getEntity() {
Player bukkit = Bukkit.getPlayer(uuid); LivingEntity bukkit = (LivingEntity) Bukkit.getEntity(entity.getUniqueId());
if(bukkit != null) if(bukkit != null)
player = bukkit; entity = bukkit;
return player; return entity;
}
public SteamwarUser getUser() {
return SteamwarUser.get(id);
}
public void ifAI(Consumer<AI> function) {
if(!(entity instanceof Player))
function.accept(AI.getAI(entity.getUniqueId()));
}
public void ifPlayer(Consumer<Player> function) {
if(entity instanceof Player)
function.accept((Player) entity);
} }
public boolean isLiving() { public boolean isLiving() {
@ -87,7 +104,7 @@ public class FightPlayer {
public boolean isLeader() { public boolean isLeader() {
FightPlayer leader = team.getLeader(); FightPlayer leader = team.getLeader();
return leader != null && leader.getPlayer() == player; return leader != null && leader.getEntity() == entity;
} }
public Kit getKit() { public Kit getKit() {

Datei anzeigen

@ -41,6 +41,7 @@ import de.steamwar.techhider.ProtocolUtils;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scoreboard.NameTagVisibility; import org.bukkit.scoreboard.NameTagVisibility;
import org.bukkit.scoreboard.Team; 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(Config.replayserver(), FightState.PreLeaderSetup, () -> Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::reset));
new OneShotStateDependent(ArenaMode.All, FightState.PostSchemSetup, () -> { new OneShotStateDependent(ArenaMode.All, FightState.PostSchemSetup, () -> {
if(leader != null) if(leader != null)
notReadyKit.loadToPlayer(leader.getPlayer()); leader.ifPlayer(notReadyKit::loadToPlayer);
}); });
} }
@ -165,10 +166,10 @@ public class FightTeam {
} }
public void teleportToSpawn(){ public void teleportToSpawn(){
players.forEach((player, fp) -> Objects.requireNonNull(Bukkit.getPlayer(player)).teleport(spawn)); players.forEach((player, fp) -> fp.getEntity().teleport(spawn));
} }
public FightPlayer getFightPlayer(Player player) { public FightPlayer getFightPlayer(LivingEntity player) {
return players.get(player.getUniqueId()); return players.get(player.getUniqueId());
} }
@ -180,17 +181,17 @@ public class FightTeam {
return true; return true;
} }
public boolean isPlayerInTeam(Player player) { public boolean isPlayerInTeam(LivingEntity player) {
return players.containsKey(player.getUniqueId()); return players.containsKey(player.getUniqueId());
} }
public boolean canPlayerEntern(Player player) { public boolean canPlayerEntern(LivingEntity player) {
return getFightPlayer(player).canEntern(); return getFightPlayer(player).canEntern();
} }
public boolean isPlayerLeader(Player player) { public boolean isPlayerLeader(LivingEntity player) {
if(leader != null) if(leader != null)
return leader.getPlayer().equals(player); return leader.getEntity().equals(player);
else else
return false; return false;
} }
@ -204,7 +205,7 @@ public class FightTeam {
for(UUID uuid : playerSet){ for(UUID uuid : playerSet){
Player player = Bukkit.getPlayer(uuid); Player player = Bukkit.getPlayer(uuid);
if(player == null) if(player == null)
removePlayer(players.get(uuid).getPlayer()); removePlayer(players.get(uuid).getEntity());
} }
FightPlayer leaderBackup = leader; FightPlayer leaderBackup = leader;
playerSet.removeIf(uuid -> Bukkit.getPlayer(uuid) == null); playerSet.removeIf(uuid -> Bukkit.getPlayer(uuid) == null);
@ -212,11 +213,11 @@ public class FightTeam {
leader = null; leader = null;
if(leaderBackup != null){ if(leaderBackup != null){
playerSet.remove(leaderBackup.getPlayer().getUniqueId()); playerSet.remove(leaderBackup.getEntity().getUniqueId());
addMember(leaderBackup.getPlayer(), true); addMember(leaderBackup.getEntity(), leaderBackup.getUser(), true);
} }
playerSet.forEach(uuid -> addMember(Bukkit.getPlayer(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,22 +252,28 @@ public class FightTeam {
} }
public void addMember(Player player) { public void addMember(Player player) {
addMember(player, false); addMember(player, SteamwarUser.get(player.getUniqueId()), false);
} }
private void addMember(Player 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); }
fightPlayer.revive();
players.put(player.getUniqueId(), fightPlayer);
Permanent.getSpectatorTeam().removeEntry(player.getName());
team.addEntry(player.getName());
player.setHealth(20); 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();
players.put(entity.getUniqueId(), fightPlayer);
Permanent.getSpectatorTeam().removeEntry(entity.getName());
team.addEntry(entity.getName());
entity.setHealth(20);
entity.teleport(spawn);
fightPlayer.ifPlayer(player -> {
BountifulWrapper.impl.setAttackSpeed(player);
player.setFoodLevel(20); player.setFoodLevel(20);
player.getInventory().clear(); player.getInventory().clear();
BountifulWrapper.impl.setAttackSpeed(player);
player.teleport(spawn);
if(FightState.Spectate.contains(FightState.getFightState())) { if(FightState.Spectate.contains(FightState.getFightState())) {
Fight.setPlayerGamemode(player, GameMode.SPECTATOR); Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
@ -274,35 +281,39 @@ public class FightTeam {
Fight.setPlayerGamemode(player, GameMode.SURVIVAL); Fight.setPlayerGamemode(player, GameMode.SURVIVAL);
(FightState.ingame() ? fightPlayer.getKit() : memberKit).loadToPlayer(player); (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);
FightSystem.getTechHider().reloadChunks(player, 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(Player player) { public void removePlayer(LivingEntity entity) {
FightPlayer fightPlayer = getFightPlayer(player); FightPlayer fightPlayer = getFightPlayer(entity);
PersonalKitCreator.closeIfInKitCreator(player); 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);
entity.teleport(Config.SpecSpawn);
fightPlayer.ifPlayer(player -> {
Fight.setPlayerGamemode(player, GameMode.SPECTATOR); Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
player.teleport(Config.SpecSpawn);
player.getInventory().clear(); player.getInventory().clear();
if(player.isOnline()){ if(player.isOnline()){
@ -311,6 +322,7 @@ public class FightTeam {
if(ArenaMode.VariableTeams.contains(Config.mode)) if(ArenaMode.VariableTeams.contains(Config.mode))
HotbarKit.SPECTATOR_KIT.loadToPlayer(player); HotbarKit.SPECTATOR_KIT.loadToPlayer(player);
} }
});
} }
public boolean isLeaderless() { public boolean isLeaderless() {
@ -335,7 +347,7 @@ public class FightTeam {
} }
private void setLeader(FightPlayer leader, boolean silent) { private void setLeader(FightPlayer leader, boolean silent) {
PersonalKitCreator.closeIfInKitCreator(leader.getPlayer()); leader.ifPlayer(PersonalKitCreator::closeIfInKitCreator);
this.leader = leader; this.leader = leader;
designatedLeader = null; designatedLeader = null;
@ -343,9 +355,9 @@ public class FightTeam {
setReady(false); setReady(false);
if(!silent) if(!silent)
FightUI.addSubtitle("UI_LEADER_JOINS", prefix, leader.getPlayer().getName()); FightUI.addSubtitle("UI_LEADER_JOINS", prefix, leader.getEntity().getName());
Optional<Integer> maxRank = SchematicNode.getAllAccessibleSchematicsOfType(SteamwarUser.get(leader.getPlayer().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
@ -354,15 +366,18 @@ public class FightTeam {
if(!Config.PersonalKits) if(!Config.PersonalKits)
leader.setKit(Kit.getKitByName(Config.LeaderDefault)); leader.setKit(Kit.getKitByName(Config.LeaderDefault));
Player player = leader.getPlayer(); leader.ifPlayer(player -> {
if(FightState.getFightState() != FightState.POST_SCHEM_SETUP) if(FightState.getFightState() != FightState.POST_SCHEM_SETUP)
chooseSchemKit.loadToPlayer(player); chooseSchemKit.loadToPlayer(player);
else else
notReadyKit.loadToPlayer(player); notReadyKit.loadToPlayer(player);
});
if(FightState.getFightState() == FightState.PRE_LEADER_SETUP && !Fight.getOpposite(this).isLeaderless()){ if(FightState.getFightState() == FightState.PRE_LEADER_SETUP && !Fight.getOpposite(this).isLeaderless()){
FightState.setFightState(FightState.PRE_SCHEM_SETUP); FightState.setFightState(FightState.PRE_SCHEM_SETUP);
} }
leader.ifAI(ai -> pasteSchem(ai.chooseSchematic()));
} }
public Collection<FightPlayer> getPlayers() { public Collection<FightPlayer> getPlayers() {
@ -405,7 +420,7 @@ public class FightTeam {
} }
public void setReady(boolean ready) { public void setReady(boolean ready) {
Player l = leader.getPlayer(); LivingEntity l = leader.getEntity();
if(!schematic.hasSchematic()){ if(!schematic.hasSchematic()){
FightSystem.getMessage().sendPrefixless("SCHEMATIC_REQUIRED", l, ChatMessageType.ACTION_BAR); FightSystem.getMessage().sendPrefixless("SCHEMATIC_REQUIRED", l, ChatMessageType.ACTION_BAR);
@ -415,12 +430,12 @@ public class FightTeam {
this.ready = ready; this.ready = ready;
if(ready) { if(ready) {
broadcast("TEAM_READY"); broadcast("TEAM_READY");
readyKit.loadToPlayer(l); leader.ifPlayer(readyKit::loadToPlayer);
if(Fight.getOpposite(this).isReady() || ArenaMode.SoloLeader.contains(Config.mode)) if(Fight.getOpposite(this).isReady() || ArenaMode.SoloLeader.contains(Config.mode))
FightState.setFightState(FightState.PRE_RUNNING); FightState.setFightState(FightState.PRE_RUNNING);
} else { } else {
broadcast("TEAM_NOT_READY"); broadcast("TEAM_NOT_READY");
notReadyKit.loadToPlayer(l); leader.ifPlayer(notReadyKit::loadToPlayer);
} }
} }
@ -459,7 +474,7 @@ public class FightTeam {
} }
public double getCurrentHearts() { public double getCurrentHearts() {
return players.values().stream().filter(FightPlayer::isLiving).mapToDouble(fp -> fp.getPlayer().getHealth()).sum(); return players.values().stream().filter(FightPlayer::isLiving).mapToDouble(fp -> fp.getEntity().getHealth()).sum();
} }
public double getHeartRatio(){ public double getHeartRatio(){
@ -493,17 +508,18 @@ public class FightTeam {
@Override @Override
public void enable() { public void enable() {
for(FightPlayer fightPlayer : players.values()) { for(FightPlayer fightPlayer : players.values()) {
Player player = fightPlayer.getPlayer(); fightPlayer.ifPlayer(player -> {
PersonalKitCreator.closeIfInKitCreator(player); PersonalKitCreator.closeIfInKitCreator(player);
player.closeInventory(); player.closeInventory();
fightPlayer.getKit().loadToPlayer(player); fightPlayer.getKit().loadToPlayer(player);
});
} }
} }
@Override @Override
public void disable() { public void disable() {
players.values().forEach(fightPlayer -> fightPlayer.getPlayer().getInventory().clear()); players.values().forEach(fightPlayer -> fightPlayer.ifPlayer(p -> p.getInventory().clear()));
} }
} }
@ -516,14 +532,14 @@ public class FightTeam {
@Override @Override
public void enable() { public void enable() {
players.values().forEach(fightPlayer -> { players.values().forEach(fightPlayer -> {
Fight.setPlayerGamemode(fightPlayer.getPlayer(), GameMode.SPECTATOR); fightPlayer.ifPlayer(player -> Fight.setPlayerGamemode(player, GameMode.SPECTATOR));
fightPlayer.getPlayer().teleport(FightTeam.this.spawn); fightPlayer.getEntity().teleport(FightTeam.this.spawn);
}); });
} }
@Override @Override
public void disable() { public void disable() {
players.values().forEach(fightPlayer -> Fight.setPlayerGamemode(fightPlayer.getPlayer(), GameMode.SURVIVAL)); players.values().forEach(fightPlayer -> fightPlayer.ifPlayer(player -> Fight.setPlayerGamemode(player, GameMode.SURVIVAL)));
} }
} }
} }

Datei anzeigen

@ -63,20 +63,26 @@ 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);
for(FightTeam t : waitOnApproval) { for(FightTeam t : waitOnApproval) {
FightPlayer leader = t.getLeader(); FightPlayer leader = t.getLeader();
if(leader == null) if(leader == null)
continue; continue;
Player leaderPlayer = leader.getPlayer(); if(leader.getEntity() == null)
if(leaderPlayer == null)
continue; continue;
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 -> {
if(ai.acceptJoinRequest(player, team))
alreadyAccepted.add(t);
});
} }
activeRequests.put(player, this);
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

@ -19,7 +19,6 @@
package de.steamwar.fightsystem.listener; package de.steamwar.fightsystem.listener;
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;
@ -28,7 +27,7 @@ import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.winconditions.Winconditions; import de.steamwar.fightsystem.winconditions.Winconditions;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.entity.Arrow; import org.bukkit.entity.Arrow;
import org.bukkit.entity.Player; import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
@ -43,25 +42,25 @@ public class InFightDamage implements Listener {
@EventHandler @EventHandler
public void handleEntityDamageByEntity(EntityDamageByEntityEvent event) { public void handleEntityDamageByEntity(EntityDamageByEntityEvent event) {
if(!(event.getEntity() instanceof Player)) if(!(event.getEntity() instanceof LivingEntity))
//Target is not a player //Target is not a player
return; return;
Player player = ((Player) event.getEntity()); LivingEntity player = ((LivingEntity) event.getEntity());
if(!Fight.fighting(player)) if(!Fight.fighting(player))
return; return;
Player damager; LivingEntity damager;
if(event.getDamager() instanceof Player) { if(event.getDamager() instanceof LivingEntity) {
damager = ((Player) event.getDamager()).getPlayer(); damager = (LivingEntity) event.getDamager();
}else if(event.getDamager() instanceof Arrow) { }else if(event.getDamager() instanceof Arrow) {
Arrow damagerArrow = (Arrow) event.getDamager(); Arrow damagerArrow = (Arrow) event.getDamager();
if(!(damagerArrow.getShooter() instanceof Player)) if(!(damagerArrow.getShooter() instanceof LivingEntity))
//Shooter is not a player //Shooter is not a player
return; return;
damager = (Player) damagerArrow.getShooter(); damager = (LivingEntity) damagerArrow.getShooter();
}else{ }else{
//Damager is not a player //Damager is not a player
return; return;

Datei anzeigen

@ -26,11 +26,12 @@ import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.utils.FightUI; import de.steamwar.fightsystem.utils.FightUI;
import de.steamwar.fightsystem.utils.SWSound; 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.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.PlayerDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -42,20 +43,20 @@ public class IngameDeath implements Listener {
} }
@EventHandler @EventHandler
public void broadcastDeath(PlayerDeathEvent event) { public void broadcastDeath(EntityDeathEvent event) {
onPlayerEnd(event.getEntity(), fightPlayer -> { onPlayerEnd(event.getEntity(), fightPlayer -> {
FightUI.addSubtitle("UI_PLAYER_DEATH", fightPlayer.getTeam().getPrefix(), fightPlayer.getPlayer().getName()); FightUI.addSubtitle("UI_PLAYER_DEATH", fightPlayer.getTeam().getPrefix(), fightPlayer.getEntity().getName());
Fight.playSound(SWSound.ENTITY_WITHER_DEATH.getSound(), 100.0F, 1.0F); Fight.playSound(SWSound.ENTITY_WITHER_DEATH.getSound(), 100.0F, 1.0F);
}); });
} }
@EventHandler @EventHandler
public void broadcastQuit(PlayerQuitEvent event) { public void broadcastQuit(PlayerQuitEvent event) {
onPlayerEnd(event.getPlayer(), fightPlayer -> FightUI.addSubtitle("UI_PLAYER_LEAVE", fightPlayer.getTeam().getPrefix(), fightPlayer.getPlayer().getName())); onPlayerEnd(event.getPlayer(), fightPlayer -> FightUI.addSubtitle("UI_PLAYER_LEAVE", fightPlayer.getTeam().getPrefix(), fightPlayer.getEntity().getName()));
} }
@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);
} }
@ -64,8 +65,11 @@ public class IngameDeath implements Listener {
onPlayerEnd(event.getPlayer(), FightPlayer::setOut); onPlayerEnd(event.getPlayer(), FightPlayer::setOut);
} }
private void onPlayerEnd(Player player, Consumer<FightPlayer> withLivingPlayer) { private void onPlayerEnd(Entity player, Consumer<FightPlayer> withLivingPlayer) {
FightPlayer fightPlayer = Fight.getFightPlayer(player); if(!(player instanceof LivingEntity))
return;
FightPlayer fightPlayer = Fight.getFightPlayer((LivingEntity) player);
if(fightPlayer == null || !fightPlayer.isLiving()) if(fightPlayer == null || !fightPlayer.isLiving())
return; return;

Datei anzeigen

@ -31,7 +31,10 @@ import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.states.StateDependent;
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 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.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -281,19 +284,20 @@ public class Recording implements Listener {
if(!fp.isLiving()) if(!fp.isLiving())
continue; continue;
Player player = fp.getPlayer(); fp.ifPlayer(player -> {
BountifulWrapper.impl.recordHandItems(player); BountifulWrapper.impl.recordHandItems(player);
GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getHelmet()), "HEAD"); 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().getChestplate()), "CHEST");
GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getLeggings()), "LEGS"); GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getLeggings()), "LEGS");
GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getBoots()), "FEET"); GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getBoots()), "FEET");
});
} }
} }
private void despawnTeam(FightTeam team){ private void despawnTeam(FightTeam team){
for(FightPlayer player : team.getPlayers()){ for(FightPlayer player : team.getPlayers()){
if(player.isLiving()) if(player.isLiving())
GlobalRecorder.getInstance().entityDespawns(player.getPlayer()); GlobalRecorder.getInstance().entityDespawns(player.getEntity());
} }
} }

Datei anzeigen

@ -36,6 +36,7 @@ import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@ -68,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.getPlayer()); playerJoins(player.getEntity(), player.getUser());
} }
} }
} }
@ -148,9 +149,7 @@ public interface Recorder {
* 0x08: Message following * 0x08: Message following
* */ * */
default void playerJoins(Player 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().getPlayer().getUniqueId()).getId() : 0, Fight.getBlueTeam().getLeader() != null ? Fight.getBlueTeam().getLeader().getUser().getId() : 0,
Fight.getRedTeam().getLeader() != null ? SteamwarUser.get(Fight.getRedTeam().getLeader().getPlayer().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.getPlayer().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.getPlayer().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::getPlayer).map(p -> SteamwarUser.get(p.getUniqueId())).map(SteamwarUser::getId).collect(Collectors.toList()), Fight.getRedTeam().getPlayers().stream().map(FightPlayer::getPlayer).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().getPlayer().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.getPlayer().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());
} }
} }

Datei anzeigen

@ -30,6 +30,7 @@ import de.steamwar.techhider.ProtocolUtils;
import de.steamwar.techhider.TechHider; import de.steamwar.techhider.TechHider;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
@ -58,13 +59,13 @@ public class TechHiderWrapper extends StateDependent {
techHider.disable(); techHider.disable();
} }
public List<ProtocolUtils.ChunkPos> prepareChunkReload(Player p, boolean hide) { public List<ProtocolUtils.ChunkPos> prepareChunkReload(LivingEntity p, boolean hide) {
if(!ENABLED) if(!ENABLED || !(p instanceof Player))
return Collections.emptyList(); return Collections.emptyList();
List<ProtocolUtils.ChunkPos> chunksToReload = new ArrayList<>(); List<ProtocolUtils.ChunkPos> chunksToReload = new ArrayList<>();
Config.ArenaRegion.forEachChunk((x, z) -> { 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)); chunksToReload.add(new ProtocolUtils.ChunkPos(x, z));
}); });
return chunksToReload; return chunksToReload;

Datei anzeigen

@ -24,7 +24,8 @@ import de.steamwar.fightsystem.countdown.Countdown;
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.StateDependentCountdown; 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.ArrayList;
import java.util.List; import java.util.List;
@ -53,8 +54,11 @@ public abstract class Wincondition {
FightSystem.setSpectateState(team, windescription, subtitle, params); FightSystem.setSpectateState(team, windescription, subtitle, params);
} }
protected FightTeam isTarget(Player player){ protected FightTeam isTarget(Entity player){
return Fight.getPlayerTeam(player); if(!(player instanceof LivingEntity))
return null;
return Fight.getPlayerTeam((LivingEntity) player);
} }
public static List<PrintableWincondition> getPrintableWinconditions(){ public static List<PrintableWincondition> getPrintableWinconditions(){

Datei anzeigen

@ -24,10 +24,10 @@ 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 org.bukkit.entity.Player; import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
public class WinconditionAllDead extends Wincondition implements Listener { public class WinconditionAllDead extends Wincondition implements Listener {
@ -38,8 +38,8 @@ public class WinconditionAllDead extends Wincondition implements Listener {
} }
@EventHandler @EventHandler
public void handlePlayerDeath(PlayerDeathEvent event) { public void handlePlayerDeath(EntityDeathEvent event) {
handleDeath(event.getEntity().getPlayer()); handleDeath(event.getEntity());
} }
@EventHandler @EventHandler
@ -47,13 +47,13 @@ public class WinconditionAllDead extends Wincondition implements Listener {
handleDeath(event.getPlayer()); handleDeath(event.getPlayer());
} }
private void handleDeath(Player player){ private void handleDeath(Entity player){
FightTeam team = isTarget(player); FightTeam team = isTarget(player);
if(team == null) if(team == null)
return; return;
for(FightPlayer fp : team.getPlayers()) { for(FightPlayer fp : team.getPlayers()) {
if(fp.isLiving() && fp.getPlayer() != player) if(fp.isLiving() && fp.getEntity() != player)
return; return;
} }

Datei anzeigen

@ -54,9 +54,9 @@ public class WinconditionAmongUs extends Wincondition implements Listener {
FightPlayer imposter = fightPlayerList.get(random.nextInt(fightPlayerList.size())); FightPlayer imposter = fightPlayerList.get(random.nextInt(fightPlayerList.size()));
for (FightPlayer fightPlayer : fightPlayerList) { for (FightPlayer fightPlayer : fightPlayerList) {
if (fightPlayer == imposter) { if (fightPlayer == imposter) {
FightSystem.getMessage().send("AMONG_US_IMPOSTER_MESSAGE", fightPlayer.getPlayer()); FightSystem.getMessage().send("AMONG_US_IMPOSTER_MESSAGE", fightPlayer.getEntity());
} else { } else {
FightSystem.getMessage().send("AMONG_US_IMPOSTER_AMONG_MESSAGE", fightPlayer.getPlayer()); FightSystem.getMessage().send("AMONG_US_IMPOSTER_AMONG_MESSAGE", fightPlayer.getEntity());
} }
} }
return imposter; return imposter;

Datei anzeigen

@ -23,10 +23,11 @@ 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 de.steamwar.fightsystem.states.StateDependentListener; 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.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
public class WinconditionCaptainDead extends Wincondition implements Listener { public class WinconditionCaptainDead extends Wincondition implements Listener {
@ -37,8 +38,8 @@ public class WinconditionCaptainDead extends Wincondition implements Listener {
} }
@EventHandler @EventHandler
public void handlePlayerDeath(PlayerDeathEvent event) { public void handlePlayerDeath(EntityDeathEvent event) {
handleDeath(event.getEntity().getPlayer()); handleDeath(event.getEntity());
} }
@EventHandler @EventHandler
@ -46,13 +47,13 @@ public class WinconditionCaptainDead extends Wincondition implements Listener {
handleDeath(event.getPlayer()); handleDeath(event.getPlayer());
} }
private void handleDeath(Player player){ private void handleDeath(Entity player){
FightTeam team = isTarget(player); FightTeam team = isTarget(player);
if(team == null) if(team == null)
return; return;
if(team.isPlayerLeader(player)) { if(team.isPlayerLeader((LivingEntity) player)) {
win(Fight.getOpposite(team), "WIN_LEADER_DEAD", team.getPrefix() + team.getLeader().getPlayer().getName()); win(Fight.getOpposite(team), "WIN_LEADER_DEAD", team.getPrefix() + team.getLeader().getEntity().getName());
} }
} }
} }