SteamWar/FightSystem
Archiviert
13
1

Merge pull request 'Various quality of life improvements' (#295) from qol into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #295
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Lixfel 2021-10-26 10:38:30 +02:00
Commit 221f5930c9
15 geänderte Dateien mit 187 neuen und 102 gelöschten Zeilen

Datei anzeigen

@ -84,17 +84,20 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper
}
@Override
public Material onBreak(Material type) {
public ItemStack onBreak(Block block) {
Material type = block.getType();
switch(type){
case REDSTONE_WIRE:
return Material.REDSTONE;
type = Material.REDSTONE;
break;
case PISTON_HEAD:
return Material.PISTON;
type = Material.PISTON;
break;
case ICE:
return Material.AIR;
default:
return type;
type = Material.AIR;
break;
}
return new ItemStack(type);
}
@Override

Datei anzeigen

@ -63,17 +63,8 @@ public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper
}
@Override
public Material onBreak(Material type) {
switch(type){
case REDSTONE_WIRE:
return Material.REDSTONE;
case PISTON_EXTENSION:
return Material.PISTON_BASE;
case ICE:
return Material.AIR;
default:
return type;
}
public ItemStack onBreak(Block block) {
return block.getDrops().stream().findAny().orElse(new ItemStack(Material.AIR));
}
@Override

Datei anzeigen

@ -49,6 +49,7 @@ public class FightSystem extends JavaPlugin {
private static Player eventLeiter;
private Message message;
private FightTeam lastWinner;
@Override
public void onLoad() {
@ -71,6 +72,7 @@ public class FightSystem extends JavaPlugin {
new InFightDamage();
new InFightInventory();
new DenyWorldInteraction();
new DenyInventoryMovement();
new EventJoin();
new Recording();
//new ResourcePack();
@ -81,6 +83,7 @@ public class FightSystem extends JavaPlugin {
new TestJoin();
new NormalJoin();
new RankedJoin();
new RunningWorldInteraction();
new PersonalKitCreator();
new ArrowStopper();
new ArrowPickup();
@ -186,6 +189,7 @@ public class FightSystem extends JavaPlugin {
}
public static void setSpectateState(FightTeam winFightTeam, String winreason, String subtitle, Object... params) {
plugin.lastWinner = winFightTeam;
FightUI.printWin(winFightTeam, subtitle, params);
FightState.setFightState(FightState.SPECTATE);
@ -233,6 +237,10 @@ public class FightSystem extends JavaPlugin {
return plugin.message;
}
public static FightTeam getLastWinner() {
return plugin.lastWinner;
}
public static void shutdown() {
//Staggered kick to prevent lobby overloading
if(Bukkit.getOnlinePlayers().isEmpty()){

Datei anzeigen

@ -193,6 +193,8 @@ BAR_RUNNING1={1} {3} {5} {0} {6} {4} {2}
BAR_RUNNING2={1} {3} {5} {7} {0} {6} {8} {4} {2}
BAR_RUNNING3={1} {3} {5} {7} {9} {0} {6} {8} {10} {4} {2}
BAR_SPECTATE={1} §7Kampf vorbei {0} {2}
BAR_TIE={1} §7Unentschieden {0} {2}
BAR_WIN={1} §7Sieg {3} {0} {2}
BAR_POINTS={0} §8Punkte
BAR_PERCENT={0}§8%
BAR_CANNONS={0} §8Kanonen

Datei anzeigen

@ -61,6 +61,7 @@ public class FightPlayer {
if(enternCountdown != null){
enternCountdown.disable();
}
enternCountdown = null;
}
public Player getPlayer() {

Datei anzeigen

@ -66,6 +66,7 @@ public class FightTeam {
private final Region schemRegion;
private final Region extendRegion;
@SuppressWarnings("deprecation")
public FightTeam(String name, String prefix, Location spawn, Region schemRegion, Region extendRegion, boolean rotate, boolean blue, UUID designatedLeader) {
this.spawn = spawn;
this.schemRegion = schemRegion;
@ -87,7 +88,6 @@ public class FightTeam {
assert team != null;
WorldOfColorWrapper.impl.setTeamColor(team, color);
BountifulWrapper.impl.setNametagVisibility(team);
//noinspection deprecation
team.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OTHER_TEAMS);
team.setAllowFriendlyFire(false);
}
@ -167,10 +167,10 @@ public class FightTeam {
if(leaderBackup != null){
playerSet.remove(leaderBackup.getPlayer());
addMember(leaderBackup.getPlayer());
addMember(leaderBackup.getPlayer(), true);
}
playerSet.forEach(this::addMember);
playerSet.forEach(p -> addMember(p, true));
if(ArenaMode.VariableTeams.contains(Config.mode) && isLeaderless()){
for(Player player : Bukkit.getOnlinePlayers()){
@ -195,6 +195,10 @@ public class FightTeam {
}
public void addMember(Player player) {
addMember(player, false);
}
public void addMember(Player player, boolean silent) {
final List<TechHider.ChunkPos> chunksToReload = TechHider.prepareChunkReload(player, false);
FightPlayer fightPlayer = new FightPlayer(player, this);
players.put(player, fightPlayer);
@ -214,8 +218,8 @@ public class FightTeam {
TechHider.reloadChunks(player, chunksToReload, false);
if(isLeaderless())
setLeader(fightPlayer);
else
setLeader(fightPlayer, silent);
else if(!silent)
FightUI.addSubtitle("UI_PLAYER_JOINS", prefix, player.getName());
}
@ -257,13 +261,13 @@ public class FightTeam {
private void removeLeader() {
this.leader = null;
if(!players.isEmpty()) {
setLeader(players.values().iterator().next());
setLeader(players.values().iterator().next(), false);
}else if(FightState.getFightState() != FightState.PRE_LEADER_SETUP && !ArenaMode.RankedEvent.contains(Config.mode)){
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), FightSystem::setPreLeaderState, 1);
}
}
private void setLeader(FightPlayer leader) {
private void setLeader(FightPlayer leader, boolean silent) {
PersonalKitCreator.closeIfInKitCreator(leader.getPlayer());
this.leader = leader;
@ -271,7 +275,8 @@ public class FightTeam {
if(ready)
setReady(false);
FightUI.addSubtitle("UI_LEADER_JOINS", prefix, leader.getPlayer().getName());
if(!silent)
FightUI.addSubtitle("UI_LEADER_JOINS", prefix, leader.getPlayer().getName());
Optional<Integer> maxRank = Schematic.getSchemsOfType(leader.getPlayer().getUniqueId(), Config.SchematicType).stream().map(Schematic::getRank).max(Integer::compare);
if(Config.RanksEnabled)

Datei anzeigen

@ -0,0 +1,51 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2021 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.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.utils.BountifulWrapper;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
public class DenyInventoryMovement implements Listener {
public DenyInventoryMovement() {
new StateDependentListener(ArenaMode.AntiTest, FightState.AntiIngame, this);
Listener listener = BountifulWrapper.impl.newDenyHandSwapListener();
new StateDependentListener(ArenaMode.AntiTest, FightState.AntiIngame, listener);
}
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
if(!PersonalKitCreator.inKitCreator(event.getWhoClicked()))
event.setCancelled(true);
}
@EventHandler
public void onInventoryDrag(InventoryDragEvent event) {
if(!PersonalKitCreator.inKitCreator(event.getWhoClicked()))
event.setCancelled(true);
}
}

Datei anzeigen

@ -23,7 +23,6 @@ import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.utils.BountifulWrapper;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -32,8 +31,6 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.player.PlayerKickEvent;
public class DenyWorldInteraction implements Listener {
@ -41,10 +38,6 @@ public class DenyWorldInteraction implements Listener {
public DenyWorldInteraction() {
new StateDependentListener(ArenaMode.Test, FightState.PreRunning, this);
new StateDependentListener(ArenaMode.AntiTest, FightState.AntiRunning, this);
Listener listener = BountifulWrapper.impl.newDenyHandSwapListener();
new StateDependentListener(ArenaMode.Test, FightState.PreRunning, listener);
new StateDependentListener(ArenaMode.AntiTest, FightState.AntiRunning, listener);
}
@EventHandler
@ -72,18 +65,6 @@ public class DenyWorldInteraction implements Listener {
e.setCancelled(true);
}
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
if(!PersonalKitCreator.inKitCreator(event.getWhoClicked()))
event.setCancelled(true);
}
@EventHandler
public void onInventoryDrag(InventoryDragEvent event) {
if(!PersonalKitCreator.inKitCreator(event.getWhoClicked()))
event.setCancelled(true);
}
@EventHandler
public void handleProjectileLaunch(ProjectileLaunchEvent event) {
event.setCancelled(true);

Datei anzeigen

@ -20,19 +20,12 @@
package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.utils.FlatteningWrapper;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryType;
@ -42,7 +35,7 @@ import org.bukkit.inventory.ItemStack;
public class InFightInventory implements Listener {
public InFightInventory() {
new StateDependentListener(ArenaMode.AntiReplay, FightState.Running, this);
new StateDependentListener(ArenaMode.AntiReplay, FightState.Ingame, this);
}
@EventHandler
@ -79,44 +72,6 @@ public class InFightInventory implements Listener {
}
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
Inventory inventory = event.getPlayer().getInventory();
Material type = FlatteningWrapper.impl.onBreak(event.getBlock().getType());
ItemStack itemStack;
for (int i = 0; i <= 35; i++) { //35 is the last normal inventory slot
itemStack = inventory.getItem(i);
if (itemStack != null && itemStack.getType().equals(type) && itemStack.getAmount() != itemStack.getMaxStackSize()) {
itemStack.setType(type);
itemStack.setAmount(itemStack.getAmount() + 1);
inventory.setItem(i, itemStack);
event.getPlayer().updateInventory();
return;
}
}
for (int i = 0; i <= 35; i++) { //35 is the last normal inventory slot
itemStack = inventory.getItem(i);
if (itemStack == null || itemStack.getType().equals(Material.AIR)) {
itemStack = new ItemStack(type, 1);
inventory.setItem(i, itemStack);
event.getPlayer().updateInventory();
return;
}
}
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent e) {
FightPlayer fp = Fight.getFightPlayer(e.getPlayer());
if(fp != null && !fp.getKit().isTnt() && e.getBlockPlaced().getType() == Material.TNT){
FightSystem.getMessage().sendPrefixless("NO_TNT_PLACE", e.getPlayer(), ChatMessageType.ACTION_BAR);
e.setCancelled(true);
}
}
@EventHandler
public void onBlockDispense(BlockDispenseEvent e) {
if(e.getItem().getType() == Material.TNT)

Datei anzeigen

@ -0,0 +1,78 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2021 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.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.utils.FlatteningWrapper;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Material;
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.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
public class RunningWorldInteraction implements Listener {
public RunningWorldInteraction() {
new StateDependentListener(ArenaMode.AntiReplay, FightState.Running, this);
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
Inventory inventory = event.getPlayer().getInventory();
ItemStack stack = FlatteningWrapper.impl.onBreak(event.getBlock());
for (int i = 0; i <= 35; i++) { //35 is the last normal inventory slot
ItemStack itemStack = inventory.getItem(i);
if (itemStack != null && itemStack.isSimilar(stack) && itemStack.getAmount() != itemStack.getMaxStackSize()) {
itemStack.setAmount(itemStack.getAmount() + 1);
inventory.setItem(i, itemStack);
event.getPlayer().updateInventory();
return;
}
}
for (int i = 0; i <= 35; i++) { //35 is the last normal inventory slot
ItemStack itemStack = inventory.getItem(i);
if (itemStack == null || itemStack.getType().equals(Material.AIR)) {
inventory.setItem(i, stack);
event.getPlayer().updateInventory();
return;
}
}
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent e) {
FightPlayer fp = Fight.getFightPlayer(e.getPlayer());
if(fp != null && !fp.getKit().isTnt() && e.getBlockPlaced().getType() == Material.TNT){
FightSystem.getMessage().sendPrefixless("NO_TNT_PLACE", e.getPlayer(), ChatMessageType.ACTION_BAR);
e.setCancelled(true);
}
}
}

Datei anzeigen

@ -38,13 +38,18 @@ public class FileSource extends PacketSource {
return;
}
InputStream input = de.steamwar.sql.Fight.getReplay(Config.ReplayID);
de.steamwar.sql.Fight.getReplay(Config.ReplayID, input -> {
try {
Files.copy(
input,
FileRecorder.getFile().toPath(),
StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new SecurityException("Could not start replay", e);
}
});
try {
Files.copy(
input,
FileRecorder.getFile().toPath(),
StandardCopyOption.REPLACE_EXISTING);
input.close();
new FileSource(FileRecorder.getFile());
} catch (IOException e) {
throw new SecurityException("Could not start replay", e);

Datei anzeigen

@ -44,6 +44,7 @@ public enum FightState {
public static final Set<FightState> Schem = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(PRE_LEADER_SETUP, PRE_SCHEM_SETUP)));
public static final Set<FightState> Recording = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(PRE_LEADER_SETUP, PRE_SCHEM_SETUP, SPECTATE)));
public static final Set<FightState> AntiRunning = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(RUNNING)));
public static final Set<FightState> AntiIngame = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(PRE_RUNNING, RUNNING)));
public static final Set<FightState> AntiSpectate = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(SPECTATE)));
private static final Map<IStateDependent, Boolean> stateDependentFeatures = new HashMap<>();

Datei anzeigen

@ -33,7 +33,7 @@ import de.steamwar.sql.Schematic;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit;
import java.nio.file.Files;
import java.io.FileInputStream;
import java.sql.Timestamp;
import java.time.Instant;
import java.util.logging.Level;
@ -97,9 +97,9 @@ public class FightStatistics {
for (FightPlayer fp : Fight.getRedTeam().getPlayers())
savePlayerStats(fp, fightId);
setReplay(fightId, Files.readAllBytes(FileRecorder.getFile().toPath()));
setReplay(fightId, new FileInputStream(FileRecorder.getFile()));
if(ArenaMode.Event.contains(Config.mode)){
if(ArenaMode.Event.contains(Config.mode)) {
FightSystem.getEventFight().setFight(fightId);
}
}catch(Exception e){

Datei anzeigen

@ -105,7 +105,12 @@ public class FightUI {
break;
case SPECTATE:
default:
generator = (l, r, lP, rP, lW, rW) -> new Message("BAR_SPECTATE", time, l.getColoredName(), r.getColoredName());
generator = (l, r, lP, rP, lW, rW) -> {
if(FightSystem.getLastWinner() == null)
return new Message("BAR_TIE", time, l.getColoredName(), r.getColoredName());
else
return new Message("BAR_WIN", time, l.getColoredName(), r.getColoredName(), FightSystem.getLastWinner().getColoredName());
};
break;
}

Datei anzeigen

@ -21,7 +21,6 @@ package de.steamwar.fightsystem.utils;
import de.steamwar.fightsystem.VersionDependent;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
@ -43,7 +42,7 @@ public class FlatteningWrapper {
boolean containsBlockMeta(ItemMeta meta);
boolean hasAttributeModifier(ItemStack stack);
Material onBreak(Material type);
ItemStack onBreak(Block type);
boolean doRecord(BlockPhysicsEvent e);