SteamWar/FightSystem
Archiviert
13
1

Merge pull request 'Team Event API, Fancy Borders' (#413) from fancyBorder into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #413
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Lixfel 2024-01-24 12:05:03 +01:00
Commit 0db80a56a6
22 geänderte Dateien mit 531 neuen und 246 gelöschten Zeilen

Datei anzeigen

@ -108,4 +108,9 @@ public class FlatteningWrapper14 implements FlatteningWrapper {
public boolean isCrouching(Player player) {
return player.getPose() == Pose.SWIMMING;
}
@Override
public void sendBlockChange(Player player, Block block, Material type) {
player.sendBlockChange(block.getLocation(), type.createBlockData());
}
}

Datei anzeigen

@ -83,4 +83,10 @@ public class FlatteningWrapper8 implements FlatteningWrapper {
public boolean isCrouching(Player player) {
return false;
}
@Override
@SuppressWarnings("deprecation")
public void sendBlockChange(Player player, Block block, Material type) {
player.sendBlockChange(block.getLocation(), type, (byte)0);
}
}

Datei anzeigen

@ -47,6 +47,9 @@ dependencies {
compileOnly 'io.netty:netty-all:4.1.68.Final'
compileOnly 'com.mojang:authlib:1.5.25'
compileOnly 'org.projectlombok:lombok:1.18.30'
annotationProcessor 'org.projectlombok:lombok:1.18.30'
compileOnly swdep("WorldEdit-1.15")
compileOnly swdep("SpigotCore")
}

Datei anzeigen

@ -309,13 +309,13 @@ public class Config {
RedRotate = teamRedRotate;
BlueRotate = teamBlueRotate;
RedPasteRegion = new Region(teamRedCornerX, teamRedCornerY, teamRedCornerZ, schemsizeX, schemsizeY, schemsizeZ);
BluePasteRegion = new Region(blueCornerX, blueCornerY, blueCornerZ, schemsizeX, schemsizeY, schemsizeZ);
RedPasteRegion = Region.fromSize(teamRedCornerX, teamRedCornerY, teamRedCornerZ, schemsizeX, schemsizeY, schemsizeZ);
BluePasteRegion = Region.fromSize(blueCornerX, blueCornerY, blueCornerZ, schemsizeX, schemsizeY, schemsizeZ);
RedExtendRegion = new Region(teamRedCornerX, teamRedCornerY, teamRedCornerZ, schemsizeX, schemsizeY, schemsizeZ, PreperationArea, PreperationArea, PreperationArea);
BlueExtendRegion = new Region(blueCornerX, blueCornerY, blueCornerZ, schemsizeX, schemsizeY, schemsizeZ, PreperationArea, PreperationArea, PreperationArea);
ArenaRegion = new Region(arenaMinX, blueCornerY, arenaMinZ, arenaMaxX - arenaMinX, schemsizeY, arenaMaxZ - arenaMinZ, 0, PreperationArea, 0);
PlayerRegion = new Region(arenaMinX, underBorder, arenaMinZ, arenaMaxX - arenaMinX, world.getMaxHeight() - underBorder, arenaMaxZ - arenaMinZ);
RedExtendRegion = Region.withExtension(teamRedCornerX, teamRedCornerY, teamRedCornerZ, schemsizeX, schemsizeY, schemsizeZ, PreperationArea, PreperationArea, PreperationArea);
BlueExtendRegion = Region.withExtension(blueCornerX, blueCornerY, blueCornerZ, schemsizeX, schemsizeY, schemsizeZ, PreperationArea, PreperationArea, PreperationArea);
ArenaRegion = Region.withExtension(arenaMinX, blueCornerY, arenaMinZ, arenaMaxX - arenaMinX, schemsizeY, arenaMaxZ - arenaMinZ, 0, PreperationArea, 0);
PlayerRegion = new Region(arenaMinX, underBorder, arenaMinZ, arenaMaxX, world.getMaxHeight(), arenaMaxZ);
EventKampfID = Integer.parseInt(System.getProperty("fightID", "0"));
if(EventKampfID >= 1){

Datei anzeigen

@ -81,7 +81,6 @@ public class FightSystem extends JavaPlugin {
});
new Chat();
new ArenaBorder();
new TeamArea();
new IngameDeath();
new InFightDamage();
new InFightInventory();

Datei anzeigen

@ -21,11 +21,13 @@ package de.steamwar.fightsystem.countdown;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.events.BoardingEvent;
import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.utils.Message;
import de.steamwar.fightsystem.utils.SWSound;
import de.steamwar.techhider.ProtocolUtils;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Bukkit;
import java.util.List;
@ -55,6 +57,7 @@ public class EnternCountdown extends Countdown {
@Override
public void countdownFinished() {
Bukkit.getPluginManager().callEvent(new BoardingEvent(fightPlayer));
FightSystem.getMessage().sendPrefixless("ENTERN_ALLOWED", fightPlayer.getEntity(), ChatMessageType.ACTION_BAR);
fightPlayer.ifPlayer(player -> {
FightSystem.getHullHider().updatePlayer(player);

Datei anzeigen

@ -0,0 +1,40 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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.events;
import de.steamwar.fightsystem.fight.FightPlayer;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
@Getter
@AllArgsConstructor
public class BoardingEvent extends Event {
@Getter
private static final HandlerList handlerList = new HandlerList();
private final FightPlayer fightPlayer;
@Override
public HandlerList getHandlers() {
return handlerList;
}
}

Datei anzeigen

@ -0,0 +1,40 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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.events;
import de.steamwar.fightsystem.fight.FightPlayer;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
@Getter
@AllArgsConstructor
public class TeamDeathEvent extends Event {
@Getter
private static final HandlerList handlerList = new HandlerList();
private final FightPlayer fightPlayer;
@Override
public HandlerList getHandlers() {
return handlerList;
}
}

Datei anzeigen

@ -0,0 +1,40 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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.events;
import de.steamwar.fightsystem.fight.FightPlayer;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
@Getter
@AllArgsConstructor
public class TeamLeaveEvent extends Event {
@Getter
private static final HandlerList handlerList = new HandlerList();
private final FightPlayer fightPlayer;
@Override
public HandlerList getHandlers() {
return handlerList;
}
}

Datei anzeigen

@ -0,0 +1,40 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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.events;
import de.steamwar.fightsystem.fight.FightPlayer;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
@Getter
@AllArgsConstructor
public class TeamSpawnEvent extends Event {
@Getter
private static final HandlerList handlerList = new HandlerList();
private final FightPlayer fightPlayer;
@Override
public HandlerList getHandlers() {
return handlerList;
}
}

Datei anzeigen

@ -23,6 +23,7 @@ import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.ai.AI;
import de.steamwar.fightsystem.countdown.Countdown;
import de.steamwar.fightsystem.countdown.EnternCountdown;
import de.steamwar.fightsystem.events.TeamDeathEvent;
import de.steamwar.sql.PersonalKit;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit;
@ -62,6 +63,7 @@ public class FightPlayer {
public void setOut() {
isOut = true;
Bukkit.getPluginManager().callEvent(new TeamDeathEvent(this));
stopEnternCountdown();
ifAI(AI::stop);
}

Datei anzeigen

@ -25,10 +25,12 @@ import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.commands.GUI;
import de.steamwar.fightsystem.countdown.Countdown;
import de.steamwar.fightsystem.events.TeamLeaveEvent;
import de.steamwar.fightsystem.events.TeamSpawnEvent;
import de.steamwar.fightsystem.listener.FightScoreboard;
import de.steamwar.fightsystem.listener.Permanent;
import de.steamwar.fightsystem.listener.PersonalKitCreator;
import de.steamwar.fightsystem.record.GlobalRecorder;
import de.steamwar.fightsystem.listener.TeamArea;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.OneShotStateDependent;
import de.steamwar.fightsystem.states.StateDependent;
@ -39,6 +41,7 @@ import de.steamwar.inventory.SWItem;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.techhider.ProtocolUtils;
import lombok.Getter;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.*;
import org.bukkit.enchantments.Enchantment;
@ -89,24 +92,35 @@ public class FightTeam {
readyKit.setItem(4, "TEAM_READY", new ItemBuilder(SWItem.getDye(8), (short) 8).removeAllAttributes().addEnchantment(Enchantment.DURABILITY,1 ).build(), player -> Objects.requireNonNull(Fight.getPlayerTeam(player)).setReady(false));
}
@Getter
private UUID designatedLeader;
@Getter
private FightPlayer leader;
@Getter
private boolean publicsOnly;
private final Map<UUID, FightPlayer> players = new HashMap<>();
@Getter
private String name;
@Getter
private String prefix;
@Getter
private ChatColor color;
private final FightSchematic schematic;
private final Team team;
@Getter
private final boolean blue;
@Getter
private boolean ready;
private boolean skip;
@Getter
private final Location spawn;
@Getter
private final Region schemRegion;
@Getter
private final Region extendRegion;
@SuppressWarnings("deprecation")
@ -123,6 +137,7 @@ public class FightTeam {
this.schematic = new FightSchematic(this, rotate);
new KitLoader();
new SpectateHandler();
new TeamArea(this);
team = FightScoreboard.getBukkitTeam(name);
WorldOfColorWrapper.impl.setTeamColor(team, color);
@ -146,26 +161,10 @@ public class FightTeam {
this.color = ChatColor.getByChar(ChatColor.getLastColors(prefix).replace("§", ""));
}
public UUID getDesignatedLeader(){
return designatedLeader;
}
public Region getSchemRegion() {
return schemRegion;
}
public Region getExtendRegion() {
return extendRegion;
}
public boolean canbeLeader(Player p){
return isLeaderless() && (designatedLeader == null || designatedLeader.equals(p.getUniqueId()));
}
public boolean isPublicsOnly() {
return publicsOnly;
}
public void teleportToSpawn(){
players.forEach((player, fp) -> fp.getEntity().teleport(spawn));
}
@ -265,6 +264,8 @@ public class FightTeam {
FightPlayer fightPlayer = getFightPlayer(entity) != null ? getFightPlayer(entity) : new FightPlayer(entity, user, this);
fightPlayer.revive();
players.put(entity.getUniqueId(), fightPlayer);
Bukkit.getPluginManager().callEvent(new TeamSpawnEvent(fightPlayer));
Permanent.getSpectatorTeam().removeEntry(entity.getName());
team.addEntry(entity.getName());
@ -288,7 +289,6 @@ public class FightTeam {
if(FightState.Running.contains(FightState.getFightState()))
fightPlayer.startEnternCountdown(Wincondition.getTimeOverCountdown());
GlobalRecorder.getInstance().playerJoins(entity, user);
fightPlayer.ifPlayer(player -> FightSystem.getTechHider().reloadChunks(player, chunksToReload, false));
if(isLeaderless())
@ -299,6 +299,7 @@ public class FightTeam {
public void removePlayer(LivingEntity entity) {
FightPlayer fightPlayer = getFightPlayer(entity);
Bukkit.getPluginManager().callEvent(new TeamLeaveEvent(fightPlayer));
fightPlayer.ifPlayer(PersonalKitCreator::closeIfInKitCreator);
List<ProtocolUtils.ChunkPos> chunksToReload = FightSystem.getTechHider().prepareChunkReload(entity, true);
@ -311,7 +312,6 @@ public class FightTeam {
if(fightPlayer.equals(leader))
removeLeader();
GlobalRecorder.getInstance().entityDespawns(entity);
entity.teleport(Config.SpecSpawn);
fightPlayer.ifPlayer(player -> {
@ -332,14 +332,6 @@ public class FightTeam {
return leader == null;
}
public boolean isBlue(){
return blue;
}
public FightPlayer getLeader() {
return leader;
}
private void removeLeader() {
this.leader = null;
if(!players.isEmpty()) {
@ -383,10 +375,6 @@ public class FightTeam {
return players.values();
}
public boolean isReady() {
return ready;
}
public void pasteSchem() {
testPasteAction();
}
@ -457,26 +445,14 @@ public class FightTeam {
}
}
public String getName() {
return name;
}
public String getColoredName() {
return prefix + name;
}
public String getPrefix() {
return prefix;
}
public int getSchematic() {
return schematic.getId();
}
public Location getSpawn() {
return spawn;
}
public double getCurrentHearts() {
return players.values().stream().filter(FightPlayer::isLiving).mapToDouble(fp -> fp.getEntity().getHealth()).sum();
}
@ -494,10 +470,6 @@ public class FightTeam {
return (int) players.values().stream().filter(FightPlayer::isLiving).count();
}
public ChatColor getColor() {
return color;
}
@Override
public String toString() {
return name;

Datei anzeigen

@ -21,52 +21,72 @@ package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.events.TeamDeathEvent;
import de.steamwar.fightsystem.events.TeamLeaveEvent;
import de.steamwar.fightsystem.events.TeamSpawnEvent;
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.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;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class ArenaBorder implements Listener {
private final Border spectatorBorder = new Border(Config.PlayerRegion, true, 5, "NO_ARENA_LEAVING");
private final Border playerBorder = new Border(Config.PlayerRegion.to2d(), true, 5, "NO_ARENA_LEAVING");
public ArenaBorder() {
new StateDependentListener(ArenaMode.All, FightState.All, this);
new StateDependentTask(ArenaMode.All, FightState.Running, this::damage, 2, 2);
new StateDependentListener(!Config.GroundWalkable, FightState.AntiIngame, new Listener() {
@EventHandler
public void onMove(PlayerMoveEvent e) {
Player player = e.getPlayer();
if(e.getTo().getY() <= Config.PlayerRegion.getMinY() && playerBorder.contains(player))
player.teleport(Fight.getPlayerTeam(player).getSpawn());
}
});
}
@EventHandler
public void arenaBorder(PlayerMoveEvent event){
Player player = event.getPlayer();
FightTeam team = Fight.getPlayerTeam(player);
if(Config.ArenaLeaveable && team == null)
return;
Location to = event.getTo();
assert to != null;
if(Config.PlayerRegion.inRegion(to))
return;
if(to.getY() <= Config.PlayerRegion.getMinY() && player.getGameMode() != GameMode.SPECTATOR && team != null) {
if(!Config.GroundWalkable && !FightState.infight())
player.teleport(team.getSpawn());
return;
public void onPlayerJoin(PlayerJoinEvent e) {
addToSpectator(e.getPlayer());
}
player.teleport(event.getFrom());
FightSystem.getMessage().sendPrefixless("NO_ARENA_LEAVING", player, ChatMessageType.ACTION_BAR);
@EventHandler
public void onTeamJoin(TeamSpawnEvent e) {
e.getFightPlayer().ifPlayer(player -> {
spectatorBorder.removePlayer(player);
playerBorder.addPlayer(player);
});
}
@EventHandler
public void onTeamDeath(TeamDeathEvent e) {
e.getFightPlayer().ifPlayer(player -> {
playerBorder.removePlayer(player);
addToSpectator(player);
});
}
@EventHandler
public void onTeamLeave(TeamLeaveEvent e) {
e.getFightPlayer().ifPlayer(player -> {
playerBorder.removePlayer(player);
addToSpectator(player);
});
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent e) {
spectatorBorder.removePlayer(e.getPlayer());
}
private void damage() {
@ -78,4 +98,11 @@ public class ArenaBorder implements Listener {
}
});
}
private void addToSpectator(Player player) {
if(Config.ArenaLeaveable || !player.isOnline() || playerBorder.contains(player))
return;
spectatorBorder.addPlayer(player);
}
}

Datei anzeigen

@ -0,0 +1,131 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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.listener;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentTask;
import de.steamwar.fightsystem.utils.FlatteningWrapper;
import de.steamwar.fightsystem.utils.Region;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class Border {
private final Map<Player, Set<Block>> ghostBarriers = new HashMap<>();
private final Map<Player, Location> lastLocation = new HashMap<>();
private final boolean contain;
private final String resetMessage;
private final Region region;
private final int ghostRange;
private final int ghostSize;
public Border(Region region, boolean contain, int ghostRange, String resetMessage) {
this.contain = contain;
this.resetMessage = resetMessage;
this.region = region;
this.ghostRange = ghostRange;
this.ghostSize = 2*ghostRange + 1;
new StateDependentTask(ArenaMode.All, FightState.All, this::run, 1, 1);
}
public void addPlayer(Player player) {
ghostBarriers.computeIfAbsent(player, uuid -> new HashSet<>());
lastLocation.put(player, player.getLocation());
}
public boolean contains(Player player) {
return ghostBarriers.containsKey(player);
}
public void removePlayer(Player player) {
lastLocation.remove(player);
Set<Block> blocks = ghostBarriers.remove(player);
if(blocks == null || !player.isOnline())
return;
for(Block block : blocks)
sendChange(player, block, Material.AIR);
}
private void run() {
for(Map.Entry<Player, Set<Block>> entry : ghostBarriers.entrySet()) {
Player player = entry.getKey();
Location location = player.getLocation();
if(region.playerInRegion(location) != contain) {
player.teleport(lastLocation.get(player));
FightSystem.getMessage().sendPrefixless(resetMessage, player, ChatMessageType.ACTION_BAR);
return;
}
Set<Block> ghostBlocks = entry.getValue();
Region ghostRegion = Region.fromSize(location.getBlockX() - ghostRange, location.getBlockY() - ghostRange, location.getBlockZ() - ghostRange, ghostSize, ghostSize, ghostSize);
ghostBlocks.removeIf(block -> {
if(!ghostRegion.inRegion(block)) {
sendChange(player, block, Material.AIR);
return true;
}
return false;
});
if(contain) {
borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX()-1, region.getMinY(), region.getMinZ(), 1, region.getSizeY(), region.getSizeZ()).intersection(ghostRegion));
borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMinY()-1, region.getMinZ(), region.getSizeX(), 1, region.getSizeZ()).intersection(ghostRegion));
borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMinY(), region.getMinZ()-1, region.getSizeX(), region.getSizeY(), 1).intersection(ghostRegion));
borderIteration(player, ghostBlocks, Region.fromSize(region.getMaxX(), region.getMinY(), region.getMinZ(), 1, region.getSizeY(), region.getSizeZ()).intersection(ghostRegion));
borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMaxY(), region.getMinZ(), region.getSizeX(), 1, region.getSizeZ()).intersection(ghostRegion));
borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMinY(), region.getMaxZ(), region.getSizeX(), region.getSizeY(), 1).intersection(ghostRegion));
} else {
borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMinY(), region.getMinZ(), 1, region.getSizeY(), region.getSizeZ()).intersection(ghostRegion));
borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMinY(), region.getMinZ(), region.getSizeX(), 1, region.getSizeZ()).intersection(ghostRegion));
borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMinY(), region.getMinZ(), region.getSizeX(), region.getSizeY(), 1).intersection(ghostRegion));
borderIteration(player, ghostBlocks, Region.fromSize(region.getMaxX()-1, region.getMinY(), region.getMinZ(), 1, region.getSizeY(), region.getSizeZ()).intersection(ghostRegion));
borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMaxY()-1, region.getMinZ(), region.getSizeX(), 1, region.getSizeZ()).intersection(ghostRegion));
borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMinY(), region.getMaxZ()-1, region.getSizeX(), region.getSizeY(), 1).intersection(ghostRegion));
}
lastLocation.put(entry.getKey(), location);
}
}
private void borderIteration(Player player, Set<Block> ghostBlocks, Region border) {
border.forEach((x, y, z) -> {
Block block = Config.world.getBlockAt(x, y, z);
if(ghostBlocks.add(block))
sendChange(player, block, Material.BARRIER);
});
}
private void sendChange(Player player, Block block, Material type) {
if(block.getType() == Material.AIR)
FlatteningWrapper.impl.sendBlockChange(player, block, type);
}
}

Datei anzeigen

@ -37,8 +37,10 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
@ -217,4 +219,25 @@ public class Permanent implements Listener {
if(e.getItem().getType() == Material.TNT || FlatteningWrapper.impl.isFacingWater(block))
e.setCancelled(true);
}
@EventHandler
public void blockPlace(BlockPlaceEvent event) {
Player player = event.getPlayer();
Block block = event.getBlock();
if(Fight.teams().stream().anyMatch(team -> team.getExtendRegion().inRegion(block)))
return;
event.setCancelled(true);
FightSystem.getMessage().sendPrefixless("NO_BLOCK_PLACE", player, ChatMessageType.ACTION_BAR);
}
@EventHandler
public void blockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
if(Config.BlueExtendRegion.getMinY() <= block.getY())
return;
event.setCancelled(true);
FightSystem.getMessage().sendPrefixless("NO_BLOCK_BREAK", event.getPlayer(), ChatMessageType.ACTION_BAR);
}
}

Datei anzeigen

@ -23,6 +23,9 @@ import com.comphenix.tinyprotocol.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.events.TeamDeathEvent;
import de.steamwar.fightsystem.events.TeamLeaveEvent;
import de.steamwar.fightsystem.events.TeamSpawnEvent;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam;
@ -142,6 +145,11 @@ public class Recording implements Listener {
return packet;
}
@EventHandler
public void onPlayerSpawn(TeamSpawnEvent e) {
GlobalRecorder.getInstance().playerJoins(e.getFightPlayer().getEntity(), e.getFightPlayer().getUser());
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerMove(PlayerMoveEvent e){
if(isNotSent(e.getPlayer()))
@ -151,19 +159,13 @@ public class Recording implements Listener {
}
@EventHandler
public void onPlayerDeath(PlayerDeathEvent e) {
if(isNotSent(e.getEntity()))
return;
GlobalRecorder.getInstance().entityDespawns(e.getEntity());
public void onPlayerDeath(TeamDeathEvent e) {
GlobalRecorder.getInstance().entityDespawns(e.getFightPlayer().getEntity());
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent e){
if(isNotSent(e.getPlayer()))
return;
GlobalRecorder.getInstance().entityDespawns(e.getPlayer());
public void onPlayerLeave(TeamLeaveEvent e) {
GlobalRecorder.getInstance().entityDespawns(e.getFightPlayer().getEntity());
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)

Datei anzeigen

@ -21,98 +21,98 @@ package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.events.BoardingEvent;
import de.steamwar.fightsystem.events.TeamDeathEvent;
import de.steamwar.fightsystem.events.TeamSpawnEvent;
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.OneShotStateDependent;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.utils.Region;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.block.Block;
import de.steamwar.fightsystem.states.StateDependentTask;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
public class TeamArea implements Listener {
private static final Set<Player> realSpectator = new HashSet<>();
private final FightTeam team;
private final Border spectatorBorder;
private final Border bordingBorder;
private final Set<Player> realSpectator = new HashSet<>();
public TeamArea(FightTeam team) {
this.team = team;
this.spectatorBorder = new Border(team.getExtendRegion(), false, 5, "NO_TEAMAREA");
this.bordingBorder = new Border(team.getExtendRegion().to2d(), true, 1, "NO_ENTERN");
public TeamArea() {
new StateDependentListener(ArenaMode.AntiTest, FightState.All, this);
new StateDependentTask(ArenaMode.AntiTest, FightState.TeamFix, this::realSpectatorCheck, 1, 1);
new OneShotStateDependent(ArenaMode.AntiTest, FightState.Spectate, () -> Fight.teams().forEach(t -> t.getPlayers().forEach(this::teamSpectator)));
}
@EventHandler
public void teamAreas(PlayerMoveEvent event) {
Player player = event.getPlayer();
if(Config.isReferee(player))
return;
public void playerJoin(PlayerJoinEvent e) {
Player player = e.getPlayer();
if(Fight.getPlayerTeam(player) != team && !Config.isReferee(player))
spectatorBorder.addPlayer(player);
}
FightTeam team = Fight.getPlayerTeam(player);
Fight.teams().forEach(t -> checkInTeamRegion(event, t, player, team));
@EventHandler
public void teamJoin(TeamSpawnEvent e) {
FightPlayer fightPlayer = e.getFightPlayer();
if(fightPlayer.getTeam() == team) {
fightPlayer.ifPlayer(player -> {
spectatorBorder.removePlayer(player);
bordingBorder.addPlayer(player);
});
}
}
@EventHandler
public void boarding(BoardingEvent e) {
FightPlayer fightPlayer = e.getFightPlayer();
if(fightPlayer.getTeam() == team) {
fightPlayer.ifPlayer(bordingBorder::removePlayer);
} else {
fightPlayer.ifPlayer(spectatorBorder::removePlayer);
}
}
@EventHandler
public void teamDeath(TeamDeathEvent e) {
teamSpectator(e.getFightPlayer());
}
private void teamSpectator(FightPlayer fightPlayer) {
if(fightPlayer.getTeam() == team) {
fightPlayer.ifPlayer(bordingBorder::removePlayer);
} else {
fightPlayer.ifPlayer(spectatorBorder::addPlayer);
}
}
@EventHandler
public void playerQuit(PlayerQuitEvent e) {
realSpectator.remove(e.getPlayer());
Player player = e.getPlayer();
spectatorBorder.removePlayer(player);
bordingBorder.removePlayer(player);
realSpectator.remove(player);
}
@EventHandler
public void blockPlace(BlockPlaceEvent event) {
Player player = event.getPlayer();
Block block = event.getBlock();
if(Config.BlueExtendRegion.inRegion(block) || Config.RedExtendRegion.inRegion(block))
return;
private void realSpectatorCheck() {
for(FightPlayer fightPlayer : team.getPlayers()) {
if(fightPlayer.isLiving())
continue;
event.setCancelled(true);
FightSystem.getMessage().sendPrefixless("NO_BLOCK_PLACE", player, ChatMessageType.ACTION_BAR);
}
@EventHandler
public void blockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
if(Config.BlueExtendRegion.getMinY() <= block.getY())
return;
event.setCancelled(true);
FightSystem.getMessage().sendPrefixless("NO_BLOCK_BREAK", event.getPlayer(), ChatMessageType.ACTION_BAR);
}
private void checkInTeamRegion(PlayerMoveEvent event, FightTeam team, Player player, FightTeam playerTeam) {
boolean spectator = player.getGameMode() == GameMode.SPECTATOR;
if(!spectator && playerTeam != null && playerTeam.canPlayerEntern(player))
return; // Player can entern
Region region = team.getExtendRegion();
boolean inRegion = region.in2dRegion(event.getTo());
if(team == playerTeam) {
if(spectator) {
realSpectator(inRegion, player);
} else if (!playerTeam.canPlayerEntern(player) && !inRegion) {
reset(event, "NO_ENTERN"); // Leaving prior to entern
}
return; // Always allowed in own region
}
if(region.playerInRegion(event.getTo())) {
reset(event, "NO_TEAMAREA"); // Not allowed in region
if(team.getSchemRegion().playerInRegion(event.getTo()) && Config.PreperationArea >= 5){ // Preventing false positives due to small extension
player.kickPlayer(null);
Bukkit.getLogger().log(Level.INFO, player.getName() + " has entered a team area");
}
}
}
private void realSpectator(boolean inRegion, Player player) {
fightPlayer.ifPlayer(player -> {
boolean inRegion = team.getExtendRegion().playerInRegion(player.getLocation());
if(inRegion && !realSpectator.contains(player)) {
Fight.pseudoSpectator(player, false);
realSpectator.add(player);
@ -120,11 +120,7 @@ public class TeamArea implements Listener {
Fight.pseudoSpectator(player, true);
realSpectator.remove(player);
}
});
}
private void reset(PlayerMoveEvent event, String message){
Player player = event.getPlayer();
player.teleport(event.getFrom());
FightSystem.getMessage().sendPrefixless(message, player, ChatMessageType.ACTION_BAR);
}
}

Datei anzeigen

@ -22,6 +22,7 @@ package de.steamwar.fightsystem.utils;
import de.steamwar.core.VersionDependent;
import de.steamwar.fightsystem.FightSystem;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
@ -49,4 +50,5 @@ public interface FlatteningWrapper {
boolean isFacingWater(Block dispenser);
boolean isCrouching(Player player);
void sendBlockChange(Player player, Block block, Material type);
}

Datei anzeigen

@ -20,13 +20,26 @@
package de.steamwar.fightsystem.utils;
import de.steamwar.techhider.ProtocolUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.bukkit.Location;
import org.bukkit.block.Block;
import java.util.function.ObjIntConsumer;
@Getter
@AllArgsConstructor
public class Region {
public static Region withExtension(int minX, int minY, int minZ, int sizeX, int sizeY, int sizeZ, int extendX, int extendY, int extendZ) {
return Region.fromSize(minX - extendX, minY - extendY, minZ - extendZ,
sizeX + extendX * 2, sizeY + extendY * 2, sizeZ + extendZ * 2);
}
public static Region fromSize(int minX, int minY, int minZ, int sizeX, int sizeY, int sizeZ) {
return new Region(minX, minY, minZ, minX+sizeX, minY+sizeY, minZ+sizeZ);
}
private final int minX;
private final int minY;
private final int minZ;
@ -34,44 +47,6 @@ public class Region {
private final int maxY;
private final int maxZ;
public Region(int minX, int minY, int minZ, int sizeX, int sizeY, int sizeZ, int extendX, int extendY, int extendZ) {
this(minX - extendX, minY - extendY, minZ - extendZ,
sizeX + extendX * 2, sizeY + extendY * 2, sizeZ + extendZ * 2);
}
public Region(int minX, int minY, int minZ, int sizeX, int sizeY, int sizeZ) {
this.minX = minX;
this.minY = minY;
this.minZ = minZ;
this.maxX = minX + sizeX;
this.maxY = minY + sizeY;
this.maxZ = minZ + sizeZ;
}
public int getMinX() {
return minX;
}
public int getMinY() {
return minY;
}
public int getMinZ() {
return minZ;
}
public int getMaxX() {
return maxX;
}
public int getMaxY() {
return maxY;
}
public int getMaxZ() {
return maxZ;
}
public int getSizeX() {
return maxX - minX;
}
@ -161,6 +136,18 @@ public class Region {
return in2dRegion(x, z) && minY <= y && y < maxY;
}
public Region intersection(Region other) {
int x = Math.max(minX, other.minX);
int y = Math.max(minY, other.minY);
int z = Math.max(minZ, other.minZ);
return new Region(x, y, z, Math.min(maxX, other.maxX), Math.min(maxY, other.maxY), Math.min(maxZ, other.maxZ));
}
public Region to2d() {
return new Region(minX, Integer.MIN_VALUE/2, minZ, maxX, Integer.MAX_VALUE/2, maxZ);
}
public interface TriConsumer<T, V, U>{
void accept(T x, V y, U z);
}

Datei anzeigen

@ -19,16 +19,13 @@
package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.events.TeamDeathEvent;
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 org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class WinconditionAllDead extends Wincondition implements Listener {
@ -38,25 +35,12 @@ public class WinconditionAllDead extends Wincondition implements Listener {
}
@EventHandler
public void handlePlayerDeath(EntityDeathEvent event) {
handleDeath(event.getEntity());
}
public void handlePlayerDeath(TeamDeathEvent event) {
FightTeam team = event.getFightPlayer().getTeam();
@EventHandler
public void handlePlayerQuit(PlayerQuitEvent event) {
handleDeath(event.getPlayer());
}
private void handleDeath(Entity player){
FightTeam team = isTarget(player);
if(team == null)
if(team.getAlivePlayers() > 0)
return;
for(FightPlayer fp : team.getPlayers()) {
if(fp.isLiving() && fp.getEntity() != player)
return;
}
win(Fight.getOpposite(team), "WIN_ALL_DEAD", team.getPrefix());
}
}

Datei anzeigen

@ -19,16 +19,14 @@
package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.events.TeamDeathEvent;
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 org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class WinconditionCaptainDead extends Wincondition implements Listener {
@ -38,22 +36,12 @@ public class WinconditionCaptainDead extends Wincondition implements Listener {
}
@EventHandler
public void handlePlayerDeath(EntityDeathEvent event) {
handleDeath(event.getEntity());
}
@EventHandler
public void handlePlayerQuit(PlayerQuitEvent event) {
handleDeath(event.getPlayer());
}
private void handleDeath(Entity player){
FightTeam team = isTarget(player);
if(team == null)
public void handlePlayerDeath(TeamDeathEvent event) {
FightPlayer leader = event.getFightPlayer();
if(!leader.isLeader())
return;
if(team.isPlayerLeader((LivingEntity) player)) {
win(Fight.getOpposite(team), "WIN_LEADER_DEAD", team.getPrefix() + team.getLeader().getEntity().getName());
}
FightTeam team = leader.getTeam();
win(Fight.getOpposite(team), "WIN_LEADER_DEAD", team.getPrefix() + leader.getEntity().getName());
}
}

Datei anzeigen

@ -46,11 +46,6 @@ mainClassName = ''
allprojects {
repositories {
mavenCentral()
jcenter()
maven {
url = uri("https://repo.codemc.io/repository/maven-snapshots/")
}
maven {
url = uri('https://hub.spigotmc.org/nexus/content/repositories/snapshots/')