SteamWar/FightSystem
Archiviert
13
1

Merge pull request 'Make arena leaveable' (#334) from arenaLeaveable into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #334
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Lixfel 2022-03-04 16:32:48 +01:00
Commit aa836e77f5
18 geänderte Dateien mit 186 neuen und 79 gelöschten Zeilen

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.fightsystem.utils;
import com.comphenix.tinyprotocol.Reflection;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.listener.Recording;
import de.steamwar.fightsystem.record.GlobalRecorder;
@ -76,7 +77,8 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper {
return new Listener() {
@EventHandler
public void onArrowPickup(PlayerPickupArrowEvent e){
e.setCancelled(true);
if(Fight.fighting(e.getPlayer()))
e.setCancelled(true);
}
};
}
@ -86,7 +88,8 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper {
return new Listener() {
@EventHandler
public void onSwapItems(PlayerSwapHandItemsEvent event) {
event.setCancelled(true);
if(Fight.fighting(event.getPlayer()))
event.setCancelled(true);
}
};
}

Datei anzeigen

@ -43,6 +43,8 @@ Arena:
GroundWalkable: true # defaults to true if missing
# Disable snow and ice melting
DisableSnowMelt: false # defaults to false if missing
# Allow leaving the arena area as spectator
Leaveable: false # defaults to false if missing
Schematic:
# The size of the schematics

Datei anzeigen

@ -70,6 +70,7 @@ public class Config {
public static final int WaterDepth;
public static final boolean GroundWalkable;
public static final boolean DisableSnowMelt;
public static final boolean ArenaLeaveable;
//schematic parameter
public static final boolean RanksEnabled;
@ -166,6 +167,7 @@ public class Config {
PreperationArea = config.getInt("Arena.BorderFromSchematic", 12);
GroundWalkable = config.getBoolean("Arena.GroundWalkable", true);
DisableSnowMelt = config.getBoolean("Arena.DisableSnowMelt", false);
ArenaLeaveable = config.getBoolean("Arena.Leaveable", false);
int schemsizeX = config.getInt("Schematic.Size.x");
int schemsizeY = config.getInt("Schematic.Size.y");

Datei anzeigen

@ -75,6 +75,10 @@ public class Fight {
return null;
}
public static boolean fighting(Player player) {
return getPlayerTeam(player) != null;
}
public static FightTeam getRedTeam() {
return redTeam;
}

Datei anzeigen

@ -43,6 +43,9 @@ public class ArenaBorder implements Listener {
@EventHandler
public void arenaBorder(PlayerMoveEvent event){
Player player = event.getPlayer();
if(Config.ArenaLeaveable && !Fight.fighting(player))
return;
Location to = event.getTo();
assert to != null;

Datei anzeigen

@ -87,10 +87,11 @@ public class ArrowStopper {
}
private boolean invalidEntity(Arrow entity) {
Location location = entity.getLocation();
boolean teamFrom = entity.getVelocity().getZ() > 0;
boolean overMid = entity.getLocation().getZ() > Config.SpecSpawn.getZ();
boolean overMid = location.getZ() > Config.SpecSpawn.getZ();
boolean otherSide = teamFrom == overMid;
return otherSide ||
return otherSide || !Config.ArenaRegion.inRegion(location) ||
WorldOfColorWrapper.impl.isInBlock(entity) ||
entity.getVelocity().equals(NULL_VECTOR);
}

Datei anzeigen

@ -1,31 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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.fight.Fight;
import org.bukkit.entity.Player;
public class BasicListener {
private BasicListener(){}
public static boolean notFighting(Player p){
return Fight.getFightPlayer(p) == null;
}
}

Datei anzeigen

@ -1,6 +1,5 @@
package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
@ -17,7 +16,7 @@ public class BlockFadeListener implements Listener {
@EventHandler
public void onBlockFade(BlockFadeEvent event) {
if (event.getBlock().getType() == Material.SNOW_BLOCK || event.getBlock().getType() == Material.SNOW || event.getBlock().getType() == Material.ICE) {
if (Config.ArenaRegion.inRegion(event.getBlock()) && (event.getBlock().getType() == Material.SNOW_BLOCK || event.getBlock().getType() == Material.SNOW || event.getBlock().getType() == Material.ICE)) {
event.setCancelled(true);
}
}

Datei anzeigen

@ -20,7 +20,9 @@
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;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import net.md_5.bungee.api.ChatMessageType;
@ -43,20 +45,25 @@ public class DenyWorldInteraction implements Listener {
@EventHandler
public void handleBlockBreak(BlockBreakEvent event) {
Player player = event.getPlayer();
event.setCancelled(true);
FightSystem.getMessage().sendPrefixless("NO_BLOCK_BREAK", player, ChatMessageType.ACTION_BAR);
if(Fight.fighting(player)) {
event.setCancelled(true);
FightSystem.getMessage().sendPrefixless("NO_BLOCK_BREAK", player, ChatMessageType.ACTION_BAR);
}
}
@EventHandler
public void handleBlockPlace(BlockPlaceEvent event) {
Player player = event.getPlayer();
event.setCancelled(true);
FightSystem.getMessage().sendPrefixless("NO_BLOCK_PLACE", player, ChatMessageType.ACTION_BAR);
if(Fight.fighting(player)) {
event.setCancelled(true);
FightSystem.getMessage().sendPrefixless("NO_BLOCK_PLACE", player, ChatMessageType.ACTION_BAR);
}
}
@EventHandler
public void handleEntityExplode(EntityExplodeEvent event) {
event.setCancelled(true);
if(Config.ArenaRegion.inRegion(event.getLocation()))
event.setCancelled(true);
}
@EventHandler
@ -67,10 +74,12 @@ public class DenyWorldInteraction implements Listener {
@EventHandler
public void handleProjectileLaunch(ProjectileLaunchEvent event) {
event.setCancelled(true);
if(event.getEntity().getShooter() instanceof Player){
if(event.getEntity().getShooter() instanceof Player) {
Player player = (Player) event.getEntity().getShooter();
FightSystem.getMessage().sendPrefixless("NO_BOW_USAGE", player, ChatMessageType.ACTION_BAR);
if(Fight.fighting(player)) {
event.setCancelled(true);
FightSystem.getMessage().sendPrefixless("NO_BOW_USAGE", player, ChatMessageType.ACTION_BAR);
}
}
}
}

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import org.bukkit.event.EventHandler;
@ -35,11 +36,13 @@ public class EntityDamage implements Listener {
@EventHandler
public void handleEntityDamage(EntityDamageEvent event) {
event.setCancelled(true);
if(Config.ArenaRegion.inRegion(event.getEntity().getLocation()))
event.setCancelled(true);
}
@EventHandler
public void handleEntityDamageByEntity(EntityDamageByEntityEvent event) {
event.setCancelled(true);
if(Config.ArenaRegion.inRegion(event.getEntity().getLocation()))
event.setCancelled(true);
}
}

Datei anzeigen

@ -30,7 +30,6 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import java.util.Objects;
@ -40,15 +39,6 @@ public class InFightDamage implements Listener {
new StateDependentListener(ArenaMode.AntiReplay, FightState.Running, this);
}
@EventHandler
public void handleEntityDamage(EntityDamageEvent event) {
if(!(event.getEntity() instanceof Player))
return;
if(BasicListener.notFighting((Player)event.getEntity()))
event.setCancelled(true);
}
@EventHandler
public void handleEntityDamageByEntity(EntityDamageByEntityEvent event) {
if(!(event.getEntity() instanceof Player))
@ -56,6 +46,9 @@ public class InFightDamage implements Listener {
return;
Player player = ((Player) event.getEntity());
if(!Fight.fighting(player))
return;
Player damager;
if(event.getDamager() instanceof Player) {
@ -72,7 +65,7 @@ public class InFightDamage implements Listener {
return;
}
if(BasicListener.notFighting(damager)){
if(!Fight.fighting(damager)){
event.setCancelled(true);
//Damager is not fighting
return;

Datei anzeigen

@ -20,9 +20,12 @@
package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockDispenseEvent;
@ -44,6 +47,9 @@ public class InFightInventory implements Listener {
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
if(!Fight.fighting((Player) event.getWhoClicked()))
return;
InventoryType top = event.getView().getTopInventory().getType();
if(top == InventoryType.CRAFTING)
return;
@ -54,6 +60,9 @@ public class InFightInventory implements Listener {
@EventHandler
public void onInventoryDrag(InventoryDragEvent event) {
if(!Fight.fighting((Player) event.getWhoClicked()))
return;
if (event.getInventory().getType() != InventoryType.PLAYER) {
int inventorySize = event.getInventory().getSize();
@ -68,7 +77,7 @@ public class InFightInventory implements Listener {
@EventHandler
public void onBlockDispense(BlockDispenseEvent e) {
if(e.getItem().getType() == Material.TNT)
if(Config.ArenaRegion.inRegion(e.getBlock()) && e.getItem().getType() == Material.TNT)
e.setCancelled(true);
}
}

Datei anzeigen

@ -0,0 +1,87 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2022 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.Config;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.spigotmc.event.player.PlayerSpawnLocationEvent;
import java.util.HashMap;
import java.util.Map;
public class LeaveableArena implements Listener {
private final Map<Player, GameMode> spectatorsInArena = new HashMap<>();
public LeaveableArena() {
new StateDependentListener(Config.ArenaLeaveable, FightState.All, this);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onJoin(PlayerSpawnLocationEvent event) {
Player player = event.getPlayer();
if(Fight.fighting(player))
return;
if(Config.ArenaRegion.inRegion(event.getSpawnLocation())) {
markInArena(player);
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onRespawn(PlayerRespawnEvent event) {
Player player = event.getPlayer();
if(Config.ArenaRegion.inRegion(event.getRespawnLocation())) {
markInArena(player);
} else {
spectatorsInArena.remove(player);
}
}
@EventHandler
public void arenaBorder(PlayerMoveEvent event){
Player player = event.getPlayer();
if(Fight.fighting(player))
return;
boolean inArena = Config.ArenaRegion.inRegion(event.getTo());
boolean spectator = spectatorsInArena.containsKey(player);
if(inArena && !spectator) {
markInArena(player);
} else if(!inArena && spectator) {
player.setGameMode(spectatorsInArena.remove(player));
}
}
private void markInArena(Player player) {
spectatorsInArena.put(player, player.getGameMode());
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
}
}

Datei anzeigen

@ -52,10 +52,12 @@ public class Permanent implements Listener {
@EventHandler
public void handlePlayerRespawn(PlayerRespawnEvent event){
Player player = event.getPlayer();
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
if(Fight.fighting(player)) {
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
FightTeam team = Fight.getPlayerTeam(player);
event.setRespawnLocation(team == null ? Config.SpecSpawn : team.getSpawn());
FightTeam team = Fight.getPlayerTeam(player);
event.setRespawnLocation(team == null ? Config.SpecSpawn : team.getSpawn());
}
}
@EventHandler
@ -72,9 +74,8 @@ public class Permanent implements Listener {
event.setJoinMessage(null);
Player player = event.getPlayer();
FightTeam fightTeam = Fight.getPlayerTeam(player);
if (fightTeam == null) {
if (!Config.ArenaLeaveable && !Fight.fighting(player)) {
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
player.teleport(Config.SpecSpawn);
}
@ -84,56 +85,66 @@ public class Permanent implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void handlePlayerDeath(PlayerDeathEvent event) {
event.setDeathMessage(null);
if(Fight.fighting(event.getEntity()))
event.setDeathMessage(null);
}
@EventHandler(priority = EventPriority.MONITOR)
public void handlePlayerLeave(PlayerQuitEvent event) {
event.setQuitMessage(null);
if(Fight.fighting(event.getPlayer()))
event.setQuitMessage(null);
}
@EventHandler
public void handleFoodLevelChange(FoodLevelChangeEvent event) {
event.setCancelled(true);
if(Fight.fighting((Player) event.getEntity()))
event.setCancelled(true);
}
@EventHandler
public void onWeatherChange(WeatherChangeEvent event){
public void onWeatherChange(WeatherChangeEvent event) {
event.setCancelled(true);
}
@EventHandler
public void onSpawnerSpawn(SpawnerSpawnEvent e){
e.setCancelled(true);
if(Config.ArenaRegion.inRegion(e.getSpawner().getBlock()))
e.setCancelled(true);
}
@EventHandler
public void onSleep(PlayerBedEnterEvent e) {
e.setCancelled(true);
if(Fight.fighting(e.getPlayer()))
e.setCancelled(true);
}
@EventHandler
public void onCrafting(CraftItemEvent e){
e.setCancelled(true);
if(Fight.fighting((Player) e.getWhoClicked()))
e.setCancelled(true);
}
@EventHandler
public void onFurnace(FurnaceSmeltEvent e){
e.setCancelled(true);
if(Config.ArenaRegion.inRegion(e.getBlock()))
e.setCancelled(true);
}
@EventHandler
public void onDropPickup(InventoryPickupItemEvent e){
e.setCancelled(true);
if(Config.ArenaRegion.inRegion(e.getItem().getLocation()))
e.setCancelled(true);
}
@EventHandler
public void onDropping(PlayerDropItemEvent e){
e.setCancelled(true);
if(Fight.fighting(e.getPlayer()))
e.setCancelled(true);
}
@EventHandler
public void onWorldLoad(WorldLoadEvent e) {
e.getWorld().setAutoSave(false);
if(!Config.ArenaLeaveable)
e.getWorld().setAutoSave(false);
}
}

Datei anzeigen

@ -43,6 +43,9 @@ public class PistonListener implements Listener {
@EventHandler
public void handlePistonExtend(BlockPistonExtendEvent e){
if(!Config.ArenaRegion.inRegion(e.getBlock()))
return;
BlockFace face = e.getDirection();
for(Block block : e.getBlocks()){
Block target = block.getRelative(face);
@ -55,6 +58,9 @@ public class PistonListener implements Listener {
@EventHandler
public void handlePistonRetract(BlockPistonRetractEvent e){
if(!Config.ArenaRegion.inRegion(e.getBlock()))
return;
for(Block block : e.getBlocks()){
if(!Config.BlueExtendRegion.inRegion(block) && !Config.RedExtendRegion.inRegion(block)) {
e.setCancelled(true);

Datei anzeigen

@ -120,7 +120,7 @@ public class Recording implements Listener {
private static final Reflection.FieldAccessor<?> blockDigType = Reflection.getField(blockDigPacket, playerDigType, 0);
private static final Object releaseUseItem = playerDigType.getEnumConstants()[5];
private Object blockDig(Player p, Object packet) {
if(blockDigType.get(packet) == releaseUseItem)
if(!isNotSent(p) && blockDigType.get(packet) == releaseUseItem)
GlobalRecorder.getInstance().bowSpan(p, false, false);
return packet;
}
@ -128,7 +128,7 @@ public class Recording implements Listener {
public static final Class<?> blockPlacePacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockPlace");
private Object blockPlace(Player p, Object packet) {
boolean mainHand = BountifulWrapper.impl.mainHand(packet);
if(BountifulWrapper.impl.bowInHand(mainHand, p))
if(!isNotSent(p) && BountifulWrapper.impl.bowInHand(mainHand, p))
GlobalRecorder.getInstance().bowSpan(p, true, !mainHand);
return packet;
}
@ -143,6 +143,9 @@ public class Recording implements Listener {
@EventHandler
public void onPlayerDeath(PlayerDeathEvent e) {
if(isNotSent(e.getEntity()))
return;
GlobalRecorder.getInstance().entityDespawns(e.getEntity());
}
@ -157,7 +160,7 @@ public class Recording implements Listener {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockPhysics(BlockPhysicsEvent e){
if(FlatteningWrapper.impl.doRecord(e))
GlobalRecorder.getInstance().blockChange(e.getBlock());
GlobalRecorder.getInstance().blockChange(e.getBlock()); //TODO ?
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)

Datei anzeigen

@ -43,6 +43,9 @@ public class RunningWorldInteraction implements Listener {
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
if(!Fight.fighting(event.getPlayer()))
return;
Inventory inventory = event.getPlayer().getInventory();
ItemStack stack = FlatteningWrapper.impl.onBreak(event.getBlock());

Datei anzeigen

@ -36,7 +36,7 @@ public class Shutdown implements Listener {
@EventHandler
public void handlePlayerQuit(PlayerQuitEvent event) {
if(Config.replayserver())
if(Config.replayserver() || Config.ArenaLeaveable)
return;
//Shutdown server if nobody online