Merge pull request 'AI API' (#396) from villager-ai into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Reviewed-on: #396 Reviewed-by: Chaoscaot <chaoscaot@zohomail.eu>
Dieser Commit ist enthalten in:
Commit
58d1f69e1c
@ -21,6 +21,7 @@ package de.steamwar.fightsystem;
|
||||
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.fightsystem.ai.LixfelAI;
|
||||
import de.steamwar.fightsystem.commands.*;
|
||||
import de.steamwar.fightsystem.countdown.*;
|
||||
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.listener.Shutdown;
|
||||
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.OneShotStateDependent;
|
||||
import de.steamwar.fightsystem.utils.*;
|
||||
|
260
FightSystem_Core/src/de/steamwar/fightsystem/ai/AI.java
Normale Datei
260
FightSystem_Core/src/de/steamwar/fightsystem/ai/AI.java
Normale Datei
@ -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() {}
|
||||
}
|
||||
}
|
46
FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelAI.java
Normale Datei
46
FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelAI.java
Normale Datei
@ -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);
|
||||
}
|
||||
}
|
@ -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<UUID> inv = new SWListInv<>(p, msg.parse("REMOVE_TITLE", p), players, (ClickType click, UUID player) -> {
|
||||
Commands.kick(p, SteamwarUser.get(player).getUserName());
|
||||
p.closeInventory();
|
||||
|
@ -51,7 +51,7 @@ public class InfoCommand implements CommandExecutor {
|
||||
FightSystem.getMessage().send("INFO_RANKED", player, !FightStatistics.isUnranked());
|
||||
for(FightTeam team : Fight.teams()) {
|
||||
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) {
|
||||
SchematicNode schematic = SchematicNode.getSchematicNode(team.getSchematic());
|
||||
|
@ -57,18 +57,20 @@ 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);
|
||||
FightSystem.getMessage().sendPrefixless("ENTERN_ALLOWED", fightPlayer.getEntity(), ChatMessageType.ACTION_BAR);
|
||||
fightPlayer.ifPlayer(player -> FightSystem.getTechHider().reloadChunks(player, chunkPos, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareFinish() {
|
||||
chunkPos = FightSystem.getTechHider().prepareChunkReload(fightPlayer.getPlayer(), false);
|
||||
chunkPos = FightSystem.getTechHider().prepareChunkReload(fightPlayer.getEntity(), false);
|
||||
}
|
||||
|
||||
@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.ifPlayer(player -> {
|
||||
player.playSound(player.getLocation(), sound, 100.0f, 1.0f);
|
||||
sendCountdownMessage(player, message, time / divisor, appendix);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
@ -87,7 +88,7 @@ public class Fight {
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -20,32 +20,34 @@
|
||||
package de.steamwar.fightsystem.fight;
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.ai.AI;
|
||||
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 final int id;
|
||||
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) {
|
||||
this.uuid = player.getUniqueId();
|
||||
this.player = player;
|
||||
FightPlayer(LivingEntity entity, SteamwarUser user, FightTeam team) {
|
||||
this.id = user.getId();
|
||||
this.entity = entity;
|
||||
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(user.getId(), Config.SchematicType.toDB());
|
||||
if(personalKit != null){
|
||||
kit = new Kit(personalKit);
|
||||
}
|
||||
@ -60,6 +62,7 @@ public class FightPlayer {
|
||||
public void setOut() {
|
||||
isOut = true;
|
||||
stopEnternCountdown();
|
||||
ifAI(AI::stop);
|
||||
}
|
||||
|
||||
public void startEnternCountdown() {
|
||||
@ -74,11 +77,25 @@ public class FightPlayer {
|
||||
enternCountdown = null;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
Player bukkit = Bukkit.getPlayer(uuid);
|
||||
public LivingEntity getEntity() {
|
||||
LivingEntity bukkit = (LivingEntity) Bukkit.getEntity(entity.getUniqueId());
|
||||
if(bukkit != null)
|
||||
player = bukkit;
|
||||
return player;
|
||||
entity = bukkit;
|
||||
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() {
|
||||
@ -87,7 +104,7 @@ public class FightPlayer {
|
||||
|
||||
public boolean isLeader() {
|
||||
FightPlayer leader = team.getLeader();
|
||||
return leader != null && leader.getPlayer() == player;
|
||||
return leader != null && leader.getEntity() == entity;
|
||||
}
|
||||
|
||||
public Kit getKit() {
|
||||
|
@ -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.ifPlayer(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.getEntity().teleport(spawn));
|
||||
}
|
||||
|
||||
public FightPlayer getFightPlayer(Player player) {
|
||||
public FightPlayer getFightPlayer(LivingEntity player) {
|
||||
return players.get(player.getUniqueId());
|
||||
}
|
||||
|
||||
@ -180,17 +181,17 @@ 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);
|
||||
return leader.getEntity().equals(player);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
@ -204,7 +205,7 @@ public class FightTeam {
|
||||
for(UUID uuid : playerSet){
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if(player == null)
|
||||
removePlayer(players.get(uuid).getPlayer());
|
||||
removePlayer(players.get(uuid).getEntity());
|
||||
}
|
||||
FightPlayer leaderBackup = leader;
|
||||
playerSet.removeIf(uuid -> Bukkit.getPlayer(uuid) == null);
|
||||
@ -212,11 +213,11 @@ public class FightTeam {
|
||||
leader = null;
|
||||
|
||||
if(leaderBackup != null){
|
||||
playerSet.remove(leaderBackup.getPlayer().getUniqueId());
|
||||
addMember(leaderBackup.getPlayer(), true);
|
||||
playerSet.remove(leaderBackup.getEntity().getUniqueId());
|
||||
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()){
|
||||
List<Player> onlinePlayers = new ArrayList<>(Bukkit.getOnlinePlayers());
|
||||
@ -251,66 +252,77 @@ public class FightTeam {
|
||||
}
|
||||
|
||||
public void addMember(Player player) {
|
||||
addMember(player, false);
|
||||
addMember(player, SteamwarUser.get(player.getUniqueId()), false);
|
||||
}
|
||||
|
||||
private void addMember(Player player, boolean silent) {
|
||||
final List<ProtocolUtils.ChunkPos> chunksToReload = FightSystem.getTechHider().prepareChunkReload(player, false);
|
||||
FightPlayer fightPlayer = getFightPlayer(player) != null ? getFightPlayer(player) : new FightPlayer(player, this);
|
||||
public void addMember(LivingEntity entity, SteamwarUser user) {
|
||||
addMember(entity, user, false);
|
||||
}
|
||||
|
||||
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(player.getUniqueId(), fightPlayer);
|
||||
Permanent.getSpectatorTeam().removeEntry(player.getName());
|
||||
team.addEntry(player.getName());
|
||||
players.put(entity.getUniqueId(), fightPlayer);
|
||||
Permanent.getSpectatorTeam().removeEntry(entity.getName());
|
||||
team.addEntry(entity.getName());
|
||||
|
||||
player.setHealth(20);
|
||||
player.setFoodLevel(20);
|
||||
player.getInventory().clear();
|
||||
BountifulWrapper.impl.setAttackSpeed(player);
|
||||
player.teleport(spawn);
|
||||
entity.setHealth(20);
|
||||
entity.teleport(spawn);
|
||||
|
||||
fightPlayer.ifPlayer(player -> {
|
||||
BountifulWrapper.impl.setAttackSpeed(player);
|
||||
player.setFoodLevel(20);
|
||||
player.getInventory().clear();
|
||||
|
||||
if(FightState.Spectate.contains(FightState.getFightState())) {
|
||||
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
|
||||
} else {
|
||||
Fight.setPlayerGamemode(player, GameMode.SURVIVAL);
|
||||
(FightState.ingame() ? fightPlayer.getKit() : memberKit).loadToPlayer(player);
|
||||
}
|
||||
});
|
||||
|
||||
if(FightState.Spectate.contains(FightState.getFightState())) {
|
||||
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
|
||||
} else {
|
||||
Fight.setPlayerGamemode(player, GameMode.SURVIVAL);
|
||||
(FightState.ingame() ? fightPlayer.getKit() : memberKit).loadToPlayer(player);
|
||||
}
|
||||
if(FightState.Running.contains(FightState.getFightState()))
|
||||
fightPlayer.startEnternCountdown();
|
||||
|
||||
GlobalRecorder.getInstance().playerJoins(player);
|
||||
FightSystem.getTechHider().reloadChunks(player, chunksToReload, false);
|
||||
GlobalRecorder.getInstance().playerJoins(entity, user);
|
||||
fightPlayer.ifPlayer(player -> FightSystem.getTechHider().reloadChunks(player, chunksToReload, false));
|
||||
|
||||
if(isLeaderless())
|
||||
setLeader(fightPlayer, 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) {
|
||||
FightPlayer fightPlayer = getFightPlayer(player);
|
||||
public void removePlayer(LivingEntity entity) {
|
||||
FightPlayer fightPlayer = getFightPlayer(entity);
|
||||
|
||||
PersonalKitCreator.closeIfInKitCreator(player);
|
||||
List<ProtocolUtils.ChunkPos> chunksToReload = FightSystem.getTechHider().prepareChunkReload(player, true);
|
||||
players.remove(player.getUniqueId());
|
||||
team.removeEntry(player.getName());
|
||||
Permanent.getSpectatorTeam().addEntry(player.getName());
|
||||
fightPlayer.ifPlayer(PersonalKitCreator::closeIfInKitCreator);
|
||||
List<ProtocolUtils.ChunkPos> chunksToReload = FightSystem.getTechHider().prepareChunkReload(entity, true);
|
||||
players.remove(entity.getUniqueId());
|
||||
team.removeEntry(entity.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))
|
||||
removeLeader();
|
||||
|
||||
GlobalRecorder.getInstance().entityDespawns(player);
|
||||
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
|
||||
player.teleport(Config.SpecSpawn);
|
||||
player.getInventory().clear();
|
||||
GlobalRecorder.getInstance().entityDespawns(entity);
|
||||
entity.teleport(Config.SpecSpawn);
|
||||
|
||||
if(player.isOnline()){
|
||||
FightSystem.getTechHider().reloadChunks(player, chunksToReload, true);
|
||||
fightPlayer.ifPlayer(player -> {
|
||||
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
|
||||
player.getInventory().clear();
|
||||
|
||||
if(ArenaMode.VariableTeams.contains(Config.mode))
|
||||
HotbarKit.SPECTATOR_KIT.loadToPlayer(player);
|
||||
}
|
||||
if(player.isOnline()){
|
||||
FightSystem.getTechHider().reloadChunks(player, chunksToReload, true);
|
||||
|
||||
if(ArenaMode.VariableTeams.contains(Config.mode))
|
||||
HotbarKit.SPECTATOR_KIT.loadToPlayer(player);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isLeaderless() {
|
||||
@ -335,7 +347,7 @@ public class FightTeam {
|
||||
}
|
||||
|
||||
private void setLeader(FightPlayer leader, boolean silent) {
|
||||
PersonalKitCreator.closeIfInKitCreator(leader.getPlayer());
|
||||
leader.ifPlayer(PersonalKitCreator::closeIfInKitCreator);
|
||||
|
||||
this.leader = leader;
|
||||
designatedLeader = null;
|
||||
@ -343,9 +355,9 @@ public class FightTeam {
|
||||
setReady(false);
|
||||
|
||||
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)
|
||||
schemRank = maxRank.orElse(1);
|
||||
else
|
||||
@ -354,15 +366,18 @@ 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.ifPlayer(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);
|
||||
}
|
||||
|
||||
leader.ifAI(ai -> pasteSchem(ai.chooseSchematic()));
|
||||
}
|
||||
|
||||
public Collection<FightPlayer> getPlayers() {
|
||||
@ -405,7 +420,7 @@ public class FightTeam {
|
||||
}
|
||||
|
||||
public void setReady(boolean ready) {
|
||||
Player l = leader.getPlayer();
|
||||
LivingEntity l = leader.getEntity();
|
||||
|
||||
if(!schematic.hasSchematic()){
|
||||
FightSystem.getMessage().sendPrefixless("SCHEMATIC_REQUIRED", l, ChatMessageType.ACTION_BAR);
|
||||
@ -415,12 +430,12 @@ public class FightTeam {
|
||||
this.ready = ready;
|
||||
if(ready) {
|
||||
broadcast("TEAM_READY");
|
||||
readyKit.loadToPlayer(l);
|
||||
leader.ifPlayer(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.ifPlayer(notReadyKit::loadToPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
@ -459,7 +474,7 @@ public class FightTeam {
|
||||
}
|
||||
|
||||
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(){
|
||||
@ -493,17 +508,18 @@ public class FightTeam {
|
||||
@Override
|
||||
public void enable() {
|
||||
for(FightPlayer fightPlayer : players.values()) {
|
||||
Player player = fightPlayer.getPlayer();
|
||||
PersonalKitCreator.closeIfInKitCreator(player);
|
||||
fightPlayer.ifPlayer(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.ifPlayer(p -> p.getInventory().clear()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -516,14 +532,14 @@ public class FightTeam {
|
||||
@Override
|
||||
public void enable() {
|
||||
players.values().forEach(fightPlayer -> {
|
||||
Fight.setPlayerGamemode(fightPlayer.getPlayer(), GameMode.SPECTATOR);
|
||||
fightPlayer.getPlayer().teleport(FightTeam.this.spawn);
|
||||
fightPlayer.ifPlayer(player -> Fight.setPlayerGamemode(player, GameMode.SPECTATOR));
|
||||
fightPlayer.getEntity().teleport(FightTeam.this.spawn);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,20 +63,26 @@ public class JoinRequest {
|
||||
this.player = player;
|
||||
this.team = 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) {
|
||||
FightPlayer leader = t.getLeader();
|
||||
if(leader == null)
|
||||
continue;
|
||||
|
||||
Player leaderPlayer = leader.getPlayer();
|
||||
if(leaderPlayer == null)
|
||||
if(leader.getEntity() == null)
|
||||
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);
|
||||
alreadyAccepted.forEach(this::accept);
|
||||
}
|
||||
|
||||
public boolean required(FightTeam decider) {
|
||||
|
@ -23,14 +23,15 @@ 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.FightPlayer;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentListener;
|
||||
import de.steamwar.fightsystem.states.StateDependentTask;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -69,10 +70,12 @@ public class ArenaBorder implements Listener {
|
||||
}
|
||||
|
||||
private void damage() {
|
||||
for(Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
FightTeam team = Fight.getPlayerTeam(player);
|
||||
if(team != null && player.getLocation().getY() <= Config.PlayerRegion.getMinY())
|
||||
player.damage(1);
|
||||
}
|
||||
Fight.teams().forEach(team -> {
|
||||
for(FightPlayer fp : team.getPlayers()) {
|
||||
LivingEntity entity = fp.getEntity();
|
||||
if(fp.isLiving() && entity.getLocation().getY() <= Config.PlayerRegion.getMinY())
|
||||
entity.damage(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ public class Chat implements Listener {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
private void broadcastChat(String message, Object... params) {
|
||||
public static void broadcastChat(String message, Object... params) {
|
||||
GlobalRecorder.getInstance().chat(message, params);
|
||||
FightSystem.getMessage().chat(message, params);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -26,11 +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.PlayerDeathEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
@ -42,20 +43,20 @@ 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());
|
||||
FightUI.addSubtitle("UI_PLAYER_DEATH", fightPlayer.getTeam().getPrefix(), fightPlayer.getEntity().getName());
|
||||
Fight.playSound(SWSound.ENTITY_WITHER_DEATH.getSound(), 100.0F, 1.0F);
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
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)
|
||||
public void handlePlayerDeath(PlayerDeathEvent event) {
|
||||
public void handlePlayerDeath(EntityDeathEvent event) {
|
||||
onPlayerEnd(event.getEntity(), FightPlayer::setOut);
|
||||
}
|
||||
|
||||
@ -64,8 +65,11 @@ public class IngameDeath implements Listener {
|
||||
onPlayerEnd(event.getPlayer(), FightPlayer::setOut);
|
||||
}
|
||||
|
||||
private void onPlayerEnd(Player player, Consumer<FightPlayer> withLivingPlayer) {
|
||||
FightPlayer fightPlayer = Fight.getFightPlayer(player);
|
||||
private void onPlayerEnd(Entity player, Consumer<FightPlayer> withLivingPlayer) {
|
||||
if(!(player instanceof LivingEntity))
|
||||
return;
|
||||
|
||||
FightPlayer fightPlayer = Fight.getFightPlayer((LivingEntity) player);
|
||||
if(fightPlayer == null || !fightPlayer.isLiving())
|
||||
return;
|
||||
|
||||
|
@ -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,19 +284,20 @@ 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.ifPlayer(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");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void despawnTeam(FightTeam team){
|
||||
for(FightPlayer player : team.getPlayers()){
|
||||
if(player.isLiving())
|
||||
GlobalRecorder.getInstance().entityDespawns(player.getPlayer());
|
||||
GlobalRecorder.getInstance().entityDespawns(player.getEntity());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
@ -68,7 +69,7 @@ public interface Recorder {
|
||||
if(FightState.AntiSpectate.contains(FightState.getFightState())){
|
||||
for(FightPlayer player : team.getPlayers()){
|
||||
if(player.isLiving()){
|
||||
playerJoins(player.getPlayer());
|
||||
playerJoins(player.getEntity(), player.getUser());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -148,9 +149,7 @@ public interface Recorder {
|
||||
* 0x08: Message following
|
||||
* */
|
||||
|
||||
default void playerJoins(Player p){
|
||||
SteamwarUser user = SteamwarUser.get(p.getUniqueId());
|
||||
|
||||
default void playerJoins(LivingEntity p, SteamwarUser user){
|
||||
write(0x00, p.getEntityId(), user.getId());
|
||||
entityMoves(p);
|
||||
}
|
||||
|
@ -52,12 +52,12 @@ public class BungeeFightInfo {
|
||||
Fight.getRedTeam().getColoredName(),
|
||||
FightState.getFightState().name(),
|
||||
StateDependentCountdown.getMainCountdown() != null ? StateDependentCountdown.getMainCountdown().getTimeLeft() : 0,
|
||||
Fight.getBlueTeam().getLeader() != null ? SteamwarUser.get(Fight.getBlueTeam().getLeader().getPlayer().getUniqueId()).getId() : 0,
|
||||
Fight.getRedTeam().getLeader() != null ? SteamwarUser.get(Fight.getRedTeam().getLeader().getPlayer().getUniqueId()).getId() : 0,
|
||||
Fight.getBlueTeam().getLeader() != null ? Fight.getBlueTeam().getLeader().getUser().getId() : 0,
|
||||
Fight.getRedTeam().getLeader() != null ? Fight.getRedTeam().getLeader().getUser().getId() : 0,
|
||||
Fight.getBlueTeam().getSchematic(),
|
||||
Fight.getRedTeam().getSchematic(),
|
||||
Fight.getBlueTeam().getPlayers().stream().map(p -> SteamwarUser.get(p.getPlayer().getUniqueId()).getId()).collect(Collectors.toList()),
|
||||
Fight.getRedTeam().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 -> 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())
|
||||
));
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ public class FightStatistics {
|
||||
}
|
||||
|
||||
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;
|
||||
@ -144,14 +144,13 @@ public class FightStatistics {
|
||||
|
||||
private int getLeader(FightTeam team) {
|
||||
if (team.getLeader() != null)
|
||||
return SteamwarUser.get(team.getLeader().getPlayer().getUniqueId()).getId();
|
||||
return team.getLeader().getUser().getId();
|
||||
else if (team.getDesignatedLeader() != null)
|
||||
return SteamwarUser.get(team.getDesignatedLeader()).getId();
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void savePlayerStats(FightPlayer fp, int fightId) {
|
||||
SteamwarUser user = SteamwarUser.get(fp.getPlayer().getUniqueId());
|
||||
de.steamwar.sql.FightPlayer.create(fightId, user.getId(), fp.getTeam().isBlue(), fp.getKit().getName(), fp.getKills(), !fp.isLiving());
|
||||
de.steamwar.sql.FightPlayer.create(fightId, fp.getUser().getId(), fp.getTeam().isBlue(), fp.getKit().getName(), fp.getKills(), !fp.isLiving());
|
||||
}
|
||||
}
|
||||
|
@ -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<ProtocolUtils.ChunkPos> prepareChunkReload(Player p, boolean hide) {
|
||||
if(!ENABLED)
|
||||
public List<ProtocolUtils.ChunkPos> prepareChunkReload(LivingEntity p, boolean hide) {
|
||||
if(!ENABLED || !(p instanceof Player))
|
||||
return Collections.emptyList();
|
||||
|
||||
List<ProtocolUtils.ChunkPos> 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;
|
||||
|
@ -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<PrintableWincondition> getPrintableWinconditions(){
|
||||
|
@ -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,13 +47,13 @@ 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;
|
||||
|
||||
for(FightPlayer fp : team.getPlayers()) {
|
||||
if(fp.isLiving() && fp.getPlayer() != player)
|
||||
if(fp.isLiving() && fp.getEntity() != player)
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -54,9 +54,9 @@ public class WinconditionAmongUs extends Wincondition implements Listener {
|
||||
FightPlayer imposter = fightPlayerList.get(random.nextInt(fightPlayerList.size()));
|
||||
for (FightPlayer fightPlayer : fightPlayerList) {
|
||||
if (fightPlayer == imposter) {
|
||||
FightSystem.getMessage().send("AMONG_US_IMPOSTER_MESSAGE", fightPlayer.getPlayer());
|
||||
FightSystem.getMessage().send("AMONG_US_IMPOSTER_MESSAGE", fightPlayer.getEntity());
|
||||
} else {
|
||||
FightSystem.getMessage().send("AMONG_US_IMPOSTER_AMONG_MESSAGE", fightPlayer.getPlayer());
|
||||
FightSystem.getMessage().send("AMONG_US_IMPOSTER_AMONG_MESSAGE", fightPlayer.getEntity());
|
||||
}
|
||||
}
|
||||
return imposter;
|
||||
|
@ -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,13 +47,13 @@ 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)) {
|
||||
win(Fight.getOpposite(team), "WIN_LEADER_DEAD", team.getPrefix() + team.getLeader().getPlayer().getName());
|
||||
if(team.isPlayerLeader((LivingEntity) player)) {
|
||||
win(Fight.getOpposite(team), "WIN_LEADER_DEAD", team.getPrefix() + team.getLeader().getEntity().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren