SteamWar/FightSystem
Archiviert
13
1

The big refactoring #238

Manuell gemergt
Lixfel hat 16 Commits von refactoring nach master 2021-03-31 20:08:07 +02:00 zusammengeführt
125 geänderte Dateien mit 4491 neuen und 3615 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,47 @@
/*
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.fight;
import de.steamwar.core.events.ChunkListener;
import net.minecraft.server.v1_10_R1.Chunk;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
import org.bukkit.entity.Player;
class FightWorld_10 {
private FightWorld_10(){}
static void resetChunk(World world, World backup, int x, int z){
net.minecraft.server.v1_10_R1.World w = ((CraftWorld) world).getHandle();
Chunk chunk = w.getChunkAt(x, z);
Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z);
System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length);
System.arraycopy(backupChunk.heightMap, 0, chunk.heightMap, 0, chunk.heightMap.length);
w.tileEntityListTick.removeAll(chunk.tileEntities.values());
w.tileEntityList.removeAll(chunk.tileEntities.values());
chunk.tileEntities.clear();
chunk.tileEntities.putAll(backupChunk.tileEntities);
for(Player p : Bukkit.getOnlinePlayers()){
ChunkListener.sendChunk(p, x, z);
}
}
}

Datei anzeigen

@ -25,9 +25,9 @@ import org.bukkit.inventory.ItemStack;
import java.util.HashSet;
import java.util.Set;
class PersonalKitCreator_10 {
public class PersonalKitCreator_10 {
static boolean hasItems(ItemStack stack){
public static boolean hasItems(ItemStack stack){
Set<String> keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c());
keys.remove("Enchantments");
keys.remove("Damage");

Datei anzeigen

@ -24,7 +24,7 @@ import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.regions.CuboidRegion;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.utils.Region;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.Material;
@ -54,10 +54,9 @@ class FightTeam_12 {
@SuppressWarnings("deprecation")
static void replaceTeamColor(EditSession e, DyeColor c, int cornerX, int cornerY, int cornerZ){
FightTeam_8.replaceTeamColor(e, c, cornerX, cornerY, cornerZ);
Vector corner = new Vector(cornerX, cornerY, cornerZ);
CuboidRegion region = new CuboidRegion(corner, corner.add(Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ));
static void replaceTeamColor(EditSession e, DyeColor c, Region r){
FightTeam_8.replaceTeamColor(e, c, r);
CuboidRegion region = new CuboidRegion(new Vector(r.getMinX(), r.getMinY(), r.getMinZ()), new Vector(r.getMaxX(), r.getMaxY(), r.getMaxZ()));
try {
e.replaceBlocks(region, CONCRETE_SET, new BaseBlock(CONCRETE.getId(), c.getWoolData()));
e.replaceBlocks(region, CONCRETE_POWDER_SET, new BaseBlock(CONCRETE_POWDER.getId(), c.getWoolData()));

Datei anzeigen

@ -0,0 +1,47 @@
/*
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.fight;
import de.steamwar.core.events.ChunkListener;
import net.minecraft.server.v1_12_R1.Chunk;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
import org.bukkit.entity.Player;
class FightWorld_12 {
private FightWorld_12(){}
static void resetChunk(World world, World backup, int x, int z){
net.minecraft.server.v1_12_R1.World w = ((CraftWorld) world).getHandle();
Chunk chunk = w.getChunkAt(x, z);
Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z);
System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length);
System.arraycopy(backupChunk.heightMap, 0, chunk.heightMap, 0, chunk.heightMap.length);
w.tileEntityListTick.removeAll(chunk.tileEntities.values());
w.tileEntityList.removeAll(chunk.tileEntities.values());
chunk.tileEntities.clear();
chunk.tileEntities.putAll(backupChunk.tileEntities);
for(Player p : Bukkit.getOnlinePlayers()){
ChunkListener.sendChunk(p, x, z);
}
}
}

Datei anzeigen

@ -25,9 +25,9 @@ import org.bukkit.inventory.ItemStack;
import java.util.HashSet;
import java.util.Set;
class PersonalKitCreator_12 {
public class PersonalKitCreator_12 {
static boolean hasItems(ItemStack stack){
public static boolean hasItems(ItemStack stack){
Set<String> keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c());
keys.remove("Enchantments");
keys.remove("Damage");

Datei anzeigen

@ -20,7 +20,6 @@
package de.steamwar.fightsystem.utils;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
@ -35,6 +34,7 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import static de.steamwar.fightsystem.utils.ITechHider.bypass;
@ -42,14 +42,8 @@ import static de.steamwar.fightsystem.utils.ITechHider.bypass;
class TechHider_12 {
private TechHider_12(){}
private static final short obfuscateShift4 = (short)(Config.ObfuscateWith << 4);
static void start(){
chunkHider();
}
private static void chunkHider(){
ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) {
static PacketAdapter chunkHider(Set<Integer> hiddenBlockIds, int obfuscateWith){
return new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) {
@Override
public void onPacketSending(PacketEvent e) {
PacketContainer packet = e.getPacket();
@ -96,8 +90,8 @@ class TechHider_12 {
int entry = ITechHider.readVarInt(data, i);
i += ITechHider.readVarIntLength(data, i);
if(Config.HiddenBlocks.contains(entry >> 4)){
entry = obfuscateShift4;
if(hiddenBlockIds.contains(entry)){
entry = obfuscateWith;
changed = true;
}
buffer.writeBytes(ITechHider.writeVarInt(entry));
@ -123,6 +117,6 @@ class TechHider_12 {
byteArray.write(0, data);
}
}
}).start(ITechHider.threadMultiplier * 4);
};
}
}

Datei anzeigen

@ -22,8 +22,13 @@ package de.steamwar.fightsystem.fight;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.transform.AffineTransform;
@ -33,19 +38,23 @@ import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockTypes;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.utils.Region;
import de.steamwar.sql.NoClipboardException;
import de.steamwar.sql.Schematic;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.scoreboard.Team;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Collections;
import java.util.Objects;
import java.util.Set;
class FightTeam_14 {
public class FightTeam_14 {
private FightTeam_14(){}
private static final Set<BaseBlock> WOOL_SET = Collections.singleton(Objects.requireNonNull(BlockTypes.PINK_WOOL).getDefaultState().toBaseBlock());
@ -61,10 +70,8 @@ class FightTeam_14 {
team.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM);
}
static void replaceTeamColor(EditSession e, DyeColor c, int cornerX, int cornerY, int cornerZ){
BlockVector3 corner3 = BlockVector3.at(cornerX, cornerY, cornerZ);
BlockVector3 schemsize3 = BlockVector3.at(Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ);
CuboidRegion region = new CuboidRegion(corner3, corner3.add(schemsize3));
static void replaceTeamColor(EditSession e, DyeColor c, Region r){
CuboidRegion region = new CuboidRegion(BlockVector3.at(r.getMinX(), r.getMinY(), r.getMinZ()), BlockVector3.at(r.getMaxX(), r.getMaxY(), r.getMaxZ()));
try {
e.replaceBlocks(region, WOOL_SET, Objects.requireNonNull(BlockTypes.get(c.name().toLowerCase() + "_wool")).getDefaultState().toBaseBlock());
e.replaceBlocks(region, CARPET_SET, Objects.requireNonNull(BlockTypes.get(c.name().toLowerCase() + "_carpet")).getDefaultState().toBaseBlock());
@ -79,9 +86,8 @@ class FightTeam_14 {
e.flushSession();
}
static EditSession pasteSchematic(Schematic schematic, int pX, int pY, int pZ, boolean rotate) throws Schematic.WrongVersionException, IOException, NoClipboardException {
BlockVector3 paste = BlockVector3.at(pX, pY, pZ);
Clipboard clipboard = schematic.load();
static EditSession pasteSchematic(Clipboard clipboard, Region region, boolean rotate) throws Schematic.WrongVersionException, IOException, NoClipboardException {
BlockVector3 paste = BlockVector3.at(region.centerX(), region.getMinY(), region.centerZ());
World w = new BukkitWorld(Bukkit.getWorlds().get(0));
BlockVector3 dimensions = clipboard.getDimensions();
@ -95,7 +101,7 @@ class FightTeam_14 {
v = paste.subtract(dimensions.getX()/2, 0, dimensions.getZ()/2).subtract(offset);
}
if(Config.AlignWater){
if(Config.WaterDepth != 0){
BlockVector3 it = clipboard.getMinimumPoint();
int depth = 0;
while(!clipboard.getBlock(it).getBlockType().getMaterial().isAir()){
@ -112,4 +118,35 @@ class FightTeam_14 {
e.flushSession();
return e;
}
public static boolean checkPistonMoving(Block block){
return block.getType() == Material.MOVING_PISTON;
}
public static void saveSchem(Schematic schem, Region region) {
World w = new BukkitWorld(Bukkit.getWorlds().get(0));
BlockVector3 min = BlockVector3.at(region.getMinX(), region.getMinY(), region.getMinZ());
CuboidRegion cuboidRegion = new CuboidRegion(w, min, BlockVector3.at(region.getMaxX(), region.getMaxY(), region.getMaxZ()));
BlockArrayClipboard clipboard = new BlockArrayClipboard(cuboidRegion);
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1);
ForwardExtentCopy forwardExtentCopy = new ForwardExtentCopy(editSession, cuboidRegion, clipboard, min);
forwardExtentCopy.setCopyingEntities(false);
try{
Operations.complete(forwardExtentCopy);
}catch(WorldEditException e){
throw new IllegalStateException(e);
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
ClipboardWriter writer = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(outputStream);
writer.write(clipboard);
writer.close();
} catch (IOException e) {
throw new IllegalStateException(e);
}
schem.saveFromBytes(outputStream.toByteArray(), true);
}
}

Datei anzeigen

@ -0,0 +1,48 @@
/*
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.fight;
import de.steamwar.core.events.ChunkListener;
import net.minecraft.server.v1_14_R1.Chunk;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
import org.bukkit.entity.Player;
class FightWorld_14 {
private FightWorld_14(){}
static void resetChunk(World world, World backup, int x, int z){
net.minecraft.server.v1_14_R1.World w = ((CraftWorld) world).getHandle();
Chunk chunk = w.getChunkAt(x, z);
Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z);
System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length);
w.tileEntityListTick.removeAll(chunk.tileEntities.values());
w.tileEntityList.removeAll(chunk.tileEntities.values());
chunk.tileEntities.clear();
chunk.tileEntities.putAll(backupChunk.tileEntities);
chunk.heightMap.clear();
chunk.heightMap.putAll(backupChunk.heightMap);
for(Player p : Bukkit.getOnlinePlayers()){
ChunkListener.sendChunk(p, x, z);
}
}
}

Datei anzeigen

@ -26,14 +26,14 @@ import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
class PersonalKitCreator_14 {
public class PersonalKitCreator_14 {
private PersonalKitCreator_14(){}
static boolean hasAttributeModifier(ItemStack stack){
public static boolean hasAttributeModifier(ItemStack stack){
return stack.hasItemMeta() && Objects.requireNonNull(stack.getItemMeta()).hasAttributeModifiers();
}
static boolean hasItems(ItemStack stack){
public static boolean hasItems(ItemStack stack){
Set<String> keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().getKeys());
keys.remove("Enchantments");
keys.remove("Damage");

Datei anzeigen

@ -17,7 +17,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.utils;
package de.steamwar.fightsystem.listener;
import org.bukkit.Material;
import org.bukkit.block.Block;

Datei anzeigen

@ -20,7 +20,6 @@
package de.steamwar.fightsystem.utils;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
@ -31,21 +30,49 @@ import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.IFightSystem;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.UnpooledByteBufAllocator;
import net.minecraft.server.v1_14_R1.*;
import org.bukkit.entity.Player;
import java.nio.ByteBuffer;
import java.nio.LongBuffer;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static de.steamwar.fightsystem.utils.ITechHider.bypass;
public class TechHider_14 {
private TechHider_14(){}
static void start(){
chunkHider();
static Set<Integer> getHiddenBlockIds() {
Set<Integer> hiddenBlockIds = new HashSet<>();
for(String tag : Config.HiddenBlocks){
for(IBlockData data : IRegistry.BLOCK.get(new MinecraftKey(tag)).getStates().a()){
hiddenBlockIds.add(Block.getCombinedId(data));
}
}
static void chunkHider(){
ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) {
if(Config.HiddenBlocks.contains("water")){
Fluid water = FluidTypes.WATER.a(false);
for(IBlockData data : Block.REGISTRY_ID){
if(data.p() == water){
hiddenBlockIds.add(Block.getCombinedId(data));
}
}
}
return hiddenBlockIds;
}
static int getObfuscateWith() {
return Block.getCombinedId(IRegistry.BLOCK.get(new MinecraftKey(Config.ObfuscateWith)).getBlockData());
}
static PacketAdapter chunkHider(Set<Integer> hiddenBlockIds, int obfuscateWith){
/*
* Bevor editing this function read and understand: https://wiki.vg/Chunk_Format
* */
return new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) {
@Override
public void onPacketSending(PacketEvent e) {
PacketContainer packet = e.getPacket();
@ -57,16 +84,9 @@ public class TechHider_14 {
if(bypass(p, chunkX, chunkZ))
return;
PacketContainer cached = ITechHider.packetCache.get(packet);
if(cached != null){
e.setPacket(cached);
return;
}
cached = packet.deepClone();
ITechHider.packetCache.put(packet, cached);
e.setPacket(cached);
StructureModifier<List<NbtBase<?>>> list = cached.getListNbtModifier();
packet = packet.shallowClone();
e.setPacket(packet);
StructureModifier<List<NbtBase<?>>> list = packet.getListNbtModifier();
List<NbtBase<?>> nmsTags = list.read(0);
boolean changed = false;
for(int i = nmsTags.size() - 1; i >= 0; i--){
@ -83,30 +103,25 @@ public class TechHider_14 {
}
changed = false;
StructureModifier<byte[]> byteArray = cached.getByteArrays();
StructureModifier<byte[]> byteArray = packet.getByteArrays();
int primaryBitMask = ints.read(2);
int numChunkSections = 0;
while(primaryBitMask != 0){
numChunkSections += primaryBitMask & 1;
primaryBitMask >>= 1;
}
byte [] data = byteArray.read(0);
byte[] data = byteArray.read(0);
ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100);
int i = 0;
while(numChunkSections > 0){
int chunkY = 0;
while(primaryBitMask != 0){
while((primaryBitMask & 1) == 0){
primaryBitMask >>= 1;
chunkY++;
}
buffer.writeBytes(data, i, 2); // Block count
i += 2;
byte bitsPerBlock = data[i++];
buffer.writeByte(bitsPerBlock);
if(bitsPerBlock < 4)
bitsPerBlock = 4;
else if(bitsPerBlock > 8){
bitsPerBlock = 14;
buffer.writeByte(data[++i]);
}
if(bitsPerBlock != 14){
if(bitsPerBlock < 9){
int paletteLength = ITechHider.readVarInt(data, i);
int paletteLengthLength = ITechHider.readVarIntLength(data, i);
buffer.writeBytes(data, i, paletteLengthLength);
@ -115,30 +130,48 @@ public class TechHider_14 {
int blockId = ITechHider.readVarInt(data, i);
int actPaletteLength = ITechHider.readVarIntLength(data, i);
if(Config.HiddenBlocks.contains(blockId)){
byte[] a = ITechHider.writeVarInt(Config.ObfuscateWith);
buffer.writeBytes(a);
if(hiddenBlockIds.contains(blockId)){
buffer.writeBytes(ITechHider.writeVarInt(obfuscateWith));
changed = true;
}else{
buffer.writeBytes(data, i, actPaletteLength);
}
i += actPaletteLength;
}
//We modify only the chunk palette for performance reasons
int dataArrayLength = ITechHider.readVarInt(data, i);
int dataArrayLengthLength = ITechHider.readVarIntLength(data, i);
buffer.writeBytes(data, i, dataArrayLength * 8 + dataArrayLengthLength);
i += dataArrayLengthLength;
i += dataArrayLength * 8;
}else{
//Full Chunk/no palette, so the chunk has to be crawled through
int dataArrayLength = ITechHider.readVarInt(data, i);
int dataArrayLengthLength = ITechHider.readVarIntLength(data, i);
buffer.writeBytes(data, i, dataArrayLength*8 + dataArrayLengthLength);
buffer.writeBytes(data, i, dataArrayLengthLength);
i += dataArrayLengthLength;
ByteBuffer source = ByteBuffer.wrap(data, i, dataArrayLength * 8);
VariableValueArray values = new VariableValueArray(bitsPerBlock, dataArrayLength, source.asLongBuffer());
for(int pos = 0; pos < 4096; pos++){
if(hiddenBlockIds.contains(values.get(pos))){
changed = true;
values.set(pos, obfuscateWith);
}
}
for(long l : values.backing)
buffer.writeLong(l);
i += dataArrayLength * 8;
}
numChunkSections--;
primaryBitMask >>= 1;
chunkY++;
}
buffer.writeBytes(data, i, data.length - i);
buffer.writeBytes(data, i, data.length - i); // MC appends a 0 byte at the end if there is a full chunk, idk why
if(changed){
data = new byte[buffer.readableBytes()];
@ -146,6 +179,48 @@ public class TechHider_14 {
byteArray.write(0, data);
}
}
}).start(ITechHider.threadMultiplier * 4);
};
}
private static final class VariableValueArray {
private final long[] backing;
private final int bitsPerValue;
private final long valueMask;
public VariableValueArray(int bitsPerEntry, int dataArrayLength, LongBuffer buffer) {
this.bitsPerValue = bitsPerEntry;
this.backing = new long[dataArrayLength];
buffer.get(backing);
this.valueMask = (1L << this.bitsPerValue) - 1;
}
public int get(int index) {
index *= bitsPerValue;
int i0 = index >> 6;
int i1 = index & 0x3f;
long value = backing[i0] >>> i1;
// The value is divided over two long values
if (i1 + bitsPerValue > 64) {
value |= backing[++i0] << 64 - i1;
}
return (int) (value & valueMask);
}
public void set(int index, int value) {
index *= bitsPerValue;
int i0 = index >> 6;
int i1 = index & 0x3f;
backing[i0] = this.backing[i0] & ~(this.valueMask << i1) | (value & valueMask) << i1;
int i2 = i1 + bitsPerValue;
// The value is divided over two long values
if (i2 > 64) {
i0++;
backing[i0] = backing[i0] & -(1L << i2 - 64) | value >> 64 - i1;
}
}
}
}

Datei anzeigen

@ -0,0 +1,48 @@
/*
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.fight;
import de.steamwar.core.events.ChunkListener;
import net.minecraft.server.v1_15_R1.Chunk;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
import org.bukkit.entity.Player;
class FightWorld_15 {
private FightWorld_15(){}
static void resetChunk(World world, World backup, int x, int z){
net.minecraft.server.v1_15_R1.World w = ((CraftWorld) world).getHandle();
Chunk chunk = w.getChunkAt(x, z);
Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z);
System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length);
w.tileEntityListTick.removeAll(chunk.tileEntities.values());
w.tileEntityList.removeAll(chunk.tileEntities.values());
chunk.tileEntities.clear();
chunk.tileEntities.putAll(backupChunk.tileEntities);
chunk.heightMap.clear();
chunk.heightMap.putAll(backupChunk.heightMap);
for(Player p : Bukkit.getOnlinePlayers()){
ChunkListener.sendChunk(p, x, z);
}
}
}

Datei anzeigen

@ -25,9 +25,9 @@ import org.bukkit.inventory.ItemStack;
import java.util.HashSet;
import java.util.Set;
class PersonalKitCreator_15 {
public class PersonalKitCreator_15 {
static boolean hasItems(ItemStack stack){
public static boolean hasItems(ItemStack stack){
Set<String> keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().getKeys());
keys.remove("Enchantments");
keys.remove("Damage");

Datei anzeigen

@ -19,187 +19,36 @@
package de.steamwar.fightsystem.utils;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.wrappers.nbt.NbtBase;
import com.comphenix.protocol.wrappers.nbt.NbtCompound;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.IFightSystem;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.UnpooledByteBufAllocator;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_15_R1.*;
import java.nio.ByteBuffer;
import java.nio.LongBuffer;
import java.util.List;
import java.util.HashSet;
import java.util.Set;
import static de.steamwar.fightsystem.utils.ITechHider.bypass;
public class TechHider_15 {
class TechHider_15 {
private TechHider_15(){}
static void start(){
chunkHider();
}
static void chunkHider(){
/*
* Bevor editing this function read and understand: https://wiki.vg/Chunk_Format
* */
ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) {
@Override
public void onPacketSending(PacketEvent e) {
PacketContainer packet = e.getPacket();
StructureModifier<Integer> ints = packet.getIntegers();
int chunkX = ints.read(0);
int chunkZ = ints.read(1);
Player p = e.getPlayer();
if(bypass(p, chunkX, chunkZ))
return;
packet = packet.shallowClone();
e.setPacket(packet);
StructureModifier<List<NbtBase<?>>> list = packet.getListNbtModifier();
List<NbtBase<?>> nmsTags = list.read(0);
boolean changed = false;
for(int i = nmsTags.size() - 1; i >= 0; i--){
NbtBase<?> nbtBase = nmsTags.get(i);
assert nbtBase instanceof NbtCompound;
NbtCompound nbt = (NbtCompound) nbtBase;
if(Config.HiddenBlockEntities.contains(nbt.getString("id"))){
nmsTags.remove(i);
changed = true;
}
}
if(changed){
list.write(0, nmsTags);
}
changed = false;
StructureModifier<byte[]> byteArray = packet.getByteArrays();
int primaryBitMask = ints.read(2);
byte[] data = byteArray.read(0);
ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100);
int i = 0;
int chunkY = 0;
while(primaryBitMask != 0){
while((primaryBitMask & 1) == 0){
primaryBitMask >>= 1;
chunkY++;
}
buffer.writeBytes(data, i, 2); // Block count
i += 2;
byte bitsPerBlock = data[i++];
buffer.writeByte(bitsPerBlock);
if(bitsPerBlock < 9){
int paletteLength = ITechHider.readVarInt(data, i);
int paletteLengthLength = ITechHider.readVarIntLength(data, i);
buffer.writeBytes(data, i, paletteLengthLength);
i += paletteLengthLength;
for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){
int blockId = ITechHider.readVarInt(data, i);
int actPaletteLength = ITechHider.readVarIntLength(data, i);
if(Config.HiddenBlocks.contains(blockId)){
byte[] a = ITechHider.writeVarInt(Config.ObfuscateWith);
buffer.writeBytes(a);
changed = true;
}else{
buffer.writeBytes(data, i, actPaletteLength);
}
i += actPaletteLength;
}
//We modify only the chunk palette for performance reasons
int dataArrayLength = ITechHider.readVarInt(data, i);
int dataArrayLengthLength = ITechHider.readVarIntLength(data, i);
buffer.writeBytes(data, i, dataArrayLength * 8 + dataArrayLengthLength);
i += dataArrayLengthLength;
i += dataArrayLength * 8;
}else{
//Full Chunk/no palette, so the chunk has to be crawled through
int dataArrayLength = ITechHider.readVarInt(data, i);
int dataArrayLengthLength = ITechHider.readVarIntLength(data, i);
buffer.writeBytes(data, i, dataArrayLengthLength);
i += dataArrayLengthLength;
ByteBuffer source = ByteBuffer.wrap(data, i, dataArrayLength * 8);
VariableValueArray values = new VariableValueArray(bitsPerBlock, dataArrayLength, source.asLongBuffer());
for(int pos = 0; pos < 4096; pos++){
if(Config.HiddenBlocks.contains(values.get(pos))){
changed = true;
values.set(pos, Config.ObfuscateWith);
static Set<Integer> getHiddenBlockIds() {
Set<Integer> hiddenBlockIds = new HashSet<>();
for(String tag : Config.HiddenBlocks){
for(IBlockData data : IRegistry.BLOCK.get(new MinecraftKey(tag)).getStates().a()){
hiddenBlockIds.add(Block.getCombinedId(data));
}
}
for(long l : values.backing)
buffer.writeLong(l);
i += dataArrayLength * 8;
}
primaryBitMask >>= 1;
chunkY++;
}
buffer.writeBytes(data, i, data.length - i); // MC appends a 0 byte at the end if there is a full chunk, idk why
if(changed){
data = new byte[buffer.readableBytes()];
buffer.readBytes(data);
byteArray.write(0, data);
if(Config.HiddenBlocks.contains("water")){
Fluid water = FluidTypes.WATER.a(false);
for(IBlockData data : Block.REGISTRY_ID){
if(data.getFluid() == water){
hiddenBlockIds.add(Block.getCombinedId(data));
}
}
}).start(ITechHider.threadMultiplier * 4);
}
private static final class VariableValueArray {
private final long[] backing;
private final int bitsPerValue;
private final long valueMask;
public VariableValueArray(int bitsPerEntry, int dataArrayLength, LongBuffer buffer) {
this.bitsPerValue = bitsPerEntry;
this.backing = new long[dataArrayLength];
buffer.get(backing);
this.valueMask = (1L << this.bitsPerValue) - 1;
return hiddenBlockIds;
}
public int get(int index) {
index *= bitsPerValue;
int i0 = index >> 6;
int i1 = index & 0x3f;
long value = backing[i0] >>> i1;
// The value is divided over two long values
if (i1 + bitsPerValue > 64) {
value |= backing[++i0] << 64 - i1;
}
return (int) (value & valueMask);
}
public void set(int index, int value) {
index *= bitsPerValue;
int i0 = index >> 6;
int i1 = index & 0x3f;
backing[i0] = this.backing[i0] & ~(this.valueMask << i1) | (value & valueMask) << i1;
int i2 = i1 + bitsPerValue;
// The value is divided over two long values
if (i2 > 64) {
i0++;
backing[i0] = backing[i0] & -(1L << i2 - 64) | value >> 64 - i1;
}
}
static int getObfuscateWith() {
return Block.getCombinedId(IRegistry.BLOCK.get(new MinecraftKey(Config.ObfuscateWith)).getBlockData());
}
}

Datei anzeigen

@ -19,32 +19,36 @@
package de.steamwar.fightsystem.fight;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.world.World;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.utils.Region;
import de.steamwar.sql.NoClipboardException;
import de.steamwar.sql.Schematic;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.scoreboard.Team;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Collections;
import java.util.Set;
class FightTeam_8 {
public class FightTeam_8 {
private FightTeam_8(){}
@SuppressWarnings("deprecation")
@ -72,9 +76,8 @@ class FightTeam_8 {
}
@SuppressWarnings("deprecation")
static void replaceTeamColor(EditSession e, DyeColor c, int cornerX, int cornerY, int cornerZ){
Vector corner = new Vector(cornerX, cornerY, cornerZ);
CuboidRegion region = new CuboidRegion(corner, corner.add(Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ));
static void replaceTeamColor(EditSession e, DyeColor c, Region r){
CuboidRegion region = new CuboidRegion(new Vector(r.getMinX(), r.getMinY(), r.getMinZ()), new Vector(r.getMaxX(), r.getMaxY(), r.getMaxZ()));
try {
e.replaceBlocks(region, WOOL_SET, new BaseBlock(WOOL.getId(), c.getWoolData()));
e.replaceBlocks(region, CLAY_SET, new BaseBlock(CLAY.getId(), c.getWoolData()));
@ -87,12 +90,10 @@ class FightTeam_8 {
e.flushQueue();
}
static EditSession pasteSchematic(Schematic schematic, int pasteX, int pasteY, int pasteZ, boolean rotate) throws Schematic.WrongVersionException, IOException, NoClipboardException {
Clipboard clipboard = schematic.load();
static EditSession pasteSchematic(Clipboard clipboard, Region paste, boolean rotate) throws Schematic.WrongVersionException, IOException, NoClipboardException {
World w = new BukkitWorld(Bukkit.getWorlds().get(0));
Vector dimensions = clipboard.getDimensions();
Vector v = new Vector(pasteX, pasteY, pasteZ);
Vector v = new Vector(paste.centerX(), paste.getMinY(), paste.centerZ());
Vector offset = clipboard.getMinimumPoint().subtract(clipboard.getOrigin());
AffineTransform aT = new AffineTransform();
if(rotate){
@ -102,7 +103,7 @@ class FightTeam_8 {
v = v.subtract(dimensions.getX()/2 - dimensions.getX()%2, 0, dimensions.getZ()/2 - dimensions.getZ()%2).subtract(offset);
}
if(Config.AlignWater){
if(Config.WaterDepth != 0){
Vector it = clipboard.getMinimumPoint();
int depth = 0;
while(!clipboard.getBlock(it).isAir()){
@ -119,4 +120,35 @@ class FightTeam_8 {
e.flushQueue();
return e;
}
public static boolean checkPistonMoving(Block block){
return block.getType() == Material.PISTON_MOVING_PIECE;
}
public static void saveSchem(Schematic schem, Region region) {
World w = new BukkitWorld(Bukkit.getWorlds().get(0));
Vector min = new Vector(region.getMinX(), region.getMinY(), region.getMinZ());
CuboidRegion cuboidRegion = new CuboidRegion(w, min, new Vector(region.getMaxX(), region.getMaxY(), region.getMaxZ()));
BlockArrayClipboard clipboard = new BlockArrayClipboard(cuboidRegion);
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1);
ForwardExtentCopy forwardExtentCopy = new ForwardExtentCopy(editSession, cuboidRegion, clipboard, min);
forwardExtentCopy.setCopyingEntities(false);
try{
Operations.complete(forwardExtentCopy);
}catch(WorldEditException e){
throw new IllegalStateException(e);
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
ClipboardWriter writer = ClipboardFormat.SCHEMATIC.getWriter(outputStream);
writer.write(clipboard, w.getWorldData());
writer.close();
} catch (IOException e) {
throw new IllegalStateException(e);
}
schem.saveFromBytes(outputStream.toByteArray(), false);
}
}

Datei anzeigen

@ -0,0 +1,47 @@
/*
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.fight;
import de.steamwar.core.events.ChunkListener;
import net.minecraft.server.v1_8_R3.Chunk;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.entity.Player;
class FightWorld_8 {
private FightWorld_8(){}
static void resetChunk(World world, World backup, int x, int z){
net.minecraft.server.v1_8_R3.World w = ((CraftWorld) world).getHandle();
Chunk chunk = w.getChunkAt(x, z);
Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z);
System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length);
System.arraycopy(backupChunk.heightMap, 0, chunk.heightMap, 0, chunk.heightMap.length);
w.h.removeAll(chunk.tileEntities.values());
w.tileEntityList.removeAll(chunk.tileEntities.values());
chunk.tileEntities.clear();
chunk.tileEntities.putAll(backupChunk.tileEntities);
for(Player p : Bukkit.getOnlinePlayers()){
ChunkListener.sendChunk(p, x, z);
}
}
}

Datei anzeigen

@ -25,9 +25,9 @@ import org.bukkit.inventory.ItemStack;
import java.util.HashSet;
import java.util.Set;
class PersonalKitCreator_8 {
public class PersonalKitCreator_8 {
static boolean hasItems(ItemStack stack){
public static boolean hasItems(ItemStack stack){
Set<String> keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c());
keys.remove("Enchantments");
keys.remove("Damage");

Datei anzeigen

@ -17,7 +17,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.utils;
package de.steamwar.fightsystem.listener;
import org.bukkit.Material;
import org.bukkit.block.Block;

Datei anzeigen

@ -0,0 +1,42 @@
/*
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.utils;
import de.steamwar.fightsystem.Config;
import org.bukkit.Material;
import java.util.HashSet;
import java.util.Set;
class TechHider_8 {
private TechHider_8(){}
static Set<Integer> getHiddenBlockIds() {
Set<Integer> hiddenBlockIds = new HashSet<>();
for(String tag : Config.HiddenBlocks){
hiddenBlockIds.add(Material.matchMaterial(tag).getId() << 4);
}
return hiddenBlockIds;
}
static int getObfuscateWith() {
return Material.matchMaterial(Config.ObfuscateWith).getId() << 4;
}
}

Datei anzeigen

@ -0,0 +1,47 @@
/*
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.fight;
import de.steamwar.core.events.ChunkListener;
import net.minecraft.server.v1_9_R2.Chunk;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_9_R2.CraftWorld;
import org.bukkit.entity.Player;
class FightWorld_9 {
private FightWorld_9(){}
static void resetChunk(World world, World backup, int x, int z){
net.minecraft.server.v1_9_R2.World w = ((CraftWorld) world).getHandle();
Chunk chunk = w.getChunkAt(x, z);
Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z);
System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length);
System.arraycopy(backupChunk.heightMap, 0, chunk.heightMap, 0, chunk.heightMap.length);
w.tileEntityListTick.removeAll(chunk.tileEntities.values());
w.tileEntityList.removeAll(chunk.tileEntities.values());
chunk.tileEntities.clear();
chunk.tileEntities.putAll(backupChunk.tileEntities);
for(Player p : Bukkit.getOnlinePlayers()){
ChunkListener.sendChunk(p, x, z);
}
}
}

Datei anzeigen

@ -25,9 +25,9 @@ import org.bukkit.inventory.ItemStack;
import java.util.HashSet;
import java.util.Set;
class PersonalKitCreator_9 {
public class PersonalKitCreator_9 {
static boolean hasItems(ItemStack stack){
public static boolean hasItems(ItemStack stack){
Set<String> keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c());
keys.remove("Enchantments");
keys.remove("Damage");

Datei anzeigen

@ -0,0 +1,49 @@
/*
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;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
public enum ArenaMode {
NORMAL,
RANKED,
EVENT,
TEST,
CHECK,
PREPARE;
public static final Set<ArenaMode> All = Collections.unmodifiableSet(EnumSet.allOf(ArenaMode.class));
public static final Set<ArenaMode> Normal = Collections.unmodifiableSet(EnumSet.of(NORMAL));
public static final Set<ArenaMode> Check = Collections.unmodifiableSet(EnumSet.of(CHECK));
public static final Set<ArenaMode> Event = Collections.unmodifiableSet(EnumSet.of(EVENT));
public static final Set<ArenaMode> Test = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK));
public static final Set<ArenaMode> Ranked = Collections.unmodifiableSet(EnumSet.of(RANKED));
public static final Set<ArenaMode> Prepare = Collections.unmodifiableSet(EnumSet.of(PREPARE));
public static final Set<ArenaMode> AntiTest = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK)));
public static final Set<ArenaMode> AntiEvent = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(EVENT)));
public static final Set<ArenaMode> AntiPrepare = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(PREPARE)));
public static final Set<ArenaMode> VariableTeams = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(RANKED, EVENT)));
public static final Set<ArenaMode> RankedEvent = Collections.unmodifiableSet(EnumSet.of(RANKED, EVENT));
public static final Set<ArenaMode> Restartable = Collections.unmodifiableSet(EnumSet.of(NORMAL, RANKED));
}

Datei anzeigen

@ -19,13 +19,14 @@
package de.steamwar.fightsystem;
import de.steamwar.fightsystem.utils.Region;
import de.steamwar.fightsystem.winconditions.Winconditions;
import de.steamwar.sql.Event;
import de.steamwar.sql.EventFight;
import de.steamwar.sql.Team;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.util.Vector;
@ -33,6 +34,7 @@ import org.bukkit.util.Vector;
import java.io.File;
import java.util.*;
import java.util.logging.Level;
import java.util.stream.Collectors;
public class Config {
@ -49,36 +51,22 @@ public class Config {
public static final List<Integer> EnterStages;
//arena parameter
public static final int SchemsizeX;
public static final int SchemsizeY;
public static final int SchemsizeZ;
public static final int TeamBlueCornerX;
public static final int TeamBlueCornerY;
public static final int TeamBlueCornerZ;
private static final int TeamBluePasteX;
private static final int TeamBluePasteZ;
public static final Region BluePasteRegion;
public static final Region RedPasteRegion;
public static final Region BlueExtendRegion;
public static final Region RedExtendRegion;
public static final Region ArenaRegion;
public static final Location TeamBlueSpawn;
public static final int TeamRedCornerX;
public static final int TeamRedCornerY;
public static final int TeamRedCornerZ;
private static final int TeamRedPasteX;
private static final int TeamRedPasteZ;
public static final Location TeamRedSpawn;
private static final int TeamBluetoReddistanceX;
private static final int TeamBluetoReddistanceY;
public static final int TeamBluetoReddistanceZ;
public static final Location SpecSpawn;
public static final int underArenaBorder;
public static final int BorderFromSchematic;
public static final int upperArenaBorder;
public static final boolean AlignWater;
private static final int BlueToRedX;
private static final int BlueToRedY;
public static final int BlueToRedZ;
public static final int PreperationArea;
public static final int WaterDepth;
private static final int Schem2BorderX;
private static final int Schem2BorderZ;
public static final int ArenaMinX;
public static final int ArenaMinZ;
public static final int ArenaMaxX;
public static final int ArenaMaxZ;
public static final boolean GroundWalkable;
//schematic parameter
@ -86,10 +74,10 @@ public class Config {
public static final boolean OnlyPublicSchematics;
public static final boolean IgnorePublicOnly;
public static final de.steamwar.sql.SchematicType SchematicType;
public static final boolean TeamRedRotate;
public static final boolean TeamBlueRotate;
public static final boolean ReplaceObsidian;
public static final boolean ReplaceBedrock;
public static final boolean RedRotate;
public static final boolean BlueRotate;
public static final boolean PasteAligned;
public static final boolean ReplaceObsidianBedrock;
public static final boolean ReplaceWithBlockupdates;
//team parameter
@ -104,16 +92,7 @@ public class Config {
public static final boolean Ranked;
//Active win conditions
public static final boolean Timeout;
public static final boolean HeartRatioTimeout;
public static final boolean AllDead;
public static final boolean CaptainDead;
public static final boolean PercentSystem;
public static final boolean RelativePercent;
public static final boolean Points;
public static final boolean TechKO;
public static final boolean WaterTechKO;
public static final boolean PumpkinTechKO;
public static final Set<Winconditions> ActiveWinconditions;
//win condition parameters
public static final int TimeoutTime;
@ -129,11 +108,9 @@ public class Config {
//tech hider parameter
public static final boolean TechhiderActive;
public static final Set<Integer> HiddenBlocks;
public static final Set<String> HiddenBlockTags;
public static final Set<String> HiddenBlocks;
public static final Set<String> HiddenBlockEntities;
public static final int ObfuscateWith;
public static final String ObfuscateWithTag;
public static final String ObfuscateWith;
//event parameter
private static final int EventKampfID;
@ -145,6 +122,9 @@ public class Config {
//check parameter
public static final int CheckSchemID;
public static final int PrepareSchemID;
public static final ArenaMode mode;
//live recorder parameter
public static final String spectateIP = "127.0.0.1";
@ -154,14 +134,14 @@ public class Config {
if(!new File(IFightSystem.getPlugin().getDataFolder(), System.getProperty("config", "config.yml")).exists()) {
IFightSystem.getPlugin().saveDefaultConfig();
Bukkit.getLogger().log(Level.SEVERE, "Arenaconfig fehlt!");
IFightSystem.shutdown(null);
Bukkit.shutdown();
}
FileConfiguration config = IFightSystem.getPlugin().getConfig();
File worldConfigFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), config.getString("Arenaconfig", "config.yml"));
if(!worldConfigFile.exists()) {
Bukkit.getLogger().log(Level.SEVERE, "Weltconfig fehlt!");
IFightSystem.shutdown(null);
Bukkit.shutdown();
}
FileConfiguration worldconfig = YamlConfiguration.loadConfiguration(worldConfigFile);
@ -171,47 +151,38 @@ public class Config {
PreFightDuration = config.getInt("Times.PreFightDuration");
SpectatorDuration = config.getInt("Times.SpectatorDuration");
int schemsizeX = worldconfig.getInt("Arena.Schemsize.x");
int schemsizeY = worldconfig.getInt("Arena.Schemsize.y");
int schemsizeZ = worldconfig.getInt("Arena.Schemsize.z");
int teamBlueCornerX = worldconfig.getInt("Arena.TeamBlueCorner.x");
int teamBlueCornerY = worldconfig.getInt("Arena.TeamBlueCorner.y");
int teamBlueCornerZ = worldconfig.getInt("Arena.TeamBlueCorner.z");
TeamBluetoReddistanceX = worldconfig.getInt("Arena.TeamBluetoReddistance.x");
TeamBluetoReddistanceY = worldconfig.getInt("Arena.TeamBluetoReddistance.y");
TeamBluetoReddistanceZ = worldconfig.getInt("Arena.TeamBluetoReddistance.z");
Schem2BorderX = worldconfig.getInt("Arena.Schem2Border.x");
Schem2BorderZ = worldconfig.getInt("Arena.Schem2Border.z");
underArenaBorder = worldconfig.getInt("Arena.underArenaBorder");
BorderFromSchematic = worldconfig.getInt("Arena.BorderFromSchematic");
AlignWater = worldconfig.getBoolean("Arena.AlignWater");
WaterDepth = worldconfig.getInt("Arena.WaterDepth");
int underBorder = worldconfig.getInt("UnderBorder");
int blueCornerX = worldconfig.getInt("BlueCorner.x");
int blueCornerY = worldconfig.getInt("BlueCorner.y");
int blueCornerZ = worldconfig.getInt("BlueCorner.z");
BlueToRedX = worldconfig.getInt("BlueToRed.x");
BlueToRedY = worldconfig.getInt("BlueToRed.y");
BlueToRedZ = worldconfig.getInt("BlueToRed.z");
double teamBlueSpawnOffsetX = worldconfig.getDouble("SpawnOffset.x");
double teamBlueSpawnOffsetY = worldconfig.getDouble("SpawnOffset.y");
double teamBlueSpawnOffsetZ = worldconfig.getDouble("SpawnOffset.z");
WaterDepth = config.getInt("Arena.WaterDepth");
int schemsizeX = config.getInt("Arena.Schemsize.x");
int schemsizeY = config.getInt("Arena.Schemsize.y");
int schemsizeZ = config.getInt("Arena.Schemsize.z");
int schem2BorderX = config.getInt("Arena.Schem2Border.x");
int schem2BorderZ = config.getInt("Arena.Schem2Border.z");
PreperationArea = config.getInt("Arena.BorderFromSchematic");
GroundWalkable = config.getBoolean("Arena.GroundWalkable");
double teamBlueSpawnOffsetX = worldconfig.getDouble("Arena.SpawnOffset.x");
double teamBlueSpawnOffsetY = worldconfig.getDouble("Arena.SpawnOffset.y");
double teamBlueSpawnOffsetZ = worldconfig.getDouble("Arena.SpawnOffset.z");
RanksEnabled = config.getBoolean("Schematic.RanksEnabled");
SchematicType = de.steamwar.sql.SchematicType.fromDB(config.getString("Schematic.SchematicType"));
IgnorePublicOnly = config.getBoolean("Schematic.IgnorePublicOnly");
boolean rotate = config.getBoolean("Schematic.Rotate");
ReplaceObsidian = config.getBoolean("Schematic.ReplaceObsidian");
ReplaceBedrock = config.getBoolean("Schematic.ReplaceBedrock");
PasteAligned = config.getBoolean("Schematic.PasteAligned");
ReplaceObsidianBedrock = config.getBoolean("Schematic.ReplaceObsidianBedrock");
ReplaceWithBlockupdates = config.getBoolean("Schematic.ReplaceWithBlockupdates");
GameName = config.getString("Output.GameName");
TeamChatDetection = config.getString("Output.TeamChatDetection");
Timeout = config.getBoolean("WinConditions.Timeout");
HeartRatioTimeout = config.getBoolean("WinConditions.HeartRatioTimeout");
AllDead = config.getBoolean("WinConditions.AllDead");
CaptainDead = config.getBoolean("WinConditions.CaptainDead");
PercentSystem = config.getBoolean("WinConditions.PercentSystem");
RelativePercent = config.getBoolean("WinConditions.RelativePercent");
Points = config.getBoolean("WinConditions.Points");
TechKO = config.getBoolean("WinConditions.TechKO");
WaterTechKO = config.getBoolean("WinConditions.WaterTechKO");
PumpkinTechKO = config.getBoolean("WinConditions.PumpkinTechKO");
ActiveWinconditions = Collections.unmodifiableSet(config.getStringList("WinConditions").stream().map(Winconditions::valueOf).collect(Collectors.toSet()));
TimeoutTime = config.getInt("WinConditionParams.TimeoutTime");
PercentWin = config.getDouble("WinConditionParams.PercentWin");
@ -223,113 +194,90 @@ public class Config {
MemberDefault = config.getString("Kits.MemberDefault");
LeaderDefault = config.getString("Kits.LeaderDefault");
PersonalKits = config.getBoolean("Kits.PersonalKits");
ForbiddenItems = config.getStringList("Kits.ForbiddenItems");
ForbiddenItems = Collections.unmodifiableList(config.getStringList("Kits.ForbiddenItems"));
ConfigurationSection techhiderConfig = config.getConfigurationSection("Techhider.HiddenBlocks");
Set<Integer> blocks = new HashSet<>();
Set<String> blockTags = new HashSet<>();
for(String key : techhiderConfig.getKeys(false)){
blockTags.add(key);
if(techhiderConfig.isInt(key))
blocks.add(techhiderConfig.getInt(key));
else{
List<Integer> minmax = techhiderConfig.getIntegerList(key); // Entry 0: Minimum, Entry 1: Maximum
for(int i = minmax.get(0); i <= minmax.get(1); i++)
blocks.add(i);
}
}
HiddenBlocks = Collections.unmodifiableSet(blocks);
HiddenBlockTags = Collections.unmodifiableSet(blockTags);
HiddenBlocks = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlocks")));
HiddenBlockEntities = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlockEntities")));
ObfuscateWith = config.getInt("Techhider.ObfuscateWith");
ObfuscateWithTag = config.getString("Techhider.ObfuscateWithTag");
ObfuscateWith = config.getString("Techhider.ObfuscateWith");
TechhiderActive = config.getBoolean("Techhider.Active");
if(schemsizeX < 0){
SchemsizeX = -schemsizeX;
TeamBlueCornerX = teamBlueCornerX - SchemsizeX;
}else{
SchemsizeX = schemsizeX;
TeamBlueCornerX = teamBlueCornerX;
schemsizeX = -schemsizeX;
blueCornerX = blueCornerX - schemsizeX;
}
if(schemsizeY < 0){
SchemsizeY = -schemsizeY;
TeamBlueCornerY = teamBlueCornerY - SchemsizeY;
}else{
SchemsizeY = schemsizeY;
TeamBlueCornerY = teamBlueCornerY;
schemsizeY = -schemsizeY;
blueCornerY = blueCornerY - schemsizeY;
}
if(schemsizeZ < 0){
SchemsizeZ = -schemsizeZ;
TeamBlueCornerZ = teamBlueCornerZ - SchemsizeZ;
}else{
SchemsizeZ = schemsizeZ;
TeamBlueCornerZ = teamBlueCornerZ;
schemsizeZ = -schemsizeZ;
blueCornerZ = blueCornerZ - schemsizeZ;
}
upperArenaBorder = TeamBlueCornerY + SchemsizeY + BorderFromSchematic;
TeamRedCornerX = TeamBluetoReddistanceX + TeamBlueCornerX;
TeamRedCornerY = TeamBluetoReddistanceY + TeamBlueCornerY;
TeamRedCornerZ = TeamBluetoReddistanceZ + TeamBlueCornerZ;
int teamRedCornerX = BlueToRedX + blueCornerX;
int teamRedCornerY = BlueToRedY + blueCornerY;
int teamRedCornerZ = BlueToRedZ + blueCornerZ;
TeamBluePasteX = TeamBlueCornerX + SchemsizeX / 2;
TeamBluePasteZ = TeamBlueCornerZ + SchemsizeZ / 2;
TeamRedPasteX = TeamBluePasteX + TeamBluetoReddistanceX;
TeamRedPasteZ = TeamBluePasteZ + TeamBluetoReddistanceZ;
int teamBluePasteX = blueCornerX + schemsizeX / 2;
int teamBluePasteZ = blueCornerZ + schemsizeZ / 2;
int teamRedPasteX = teamBluePasteX + BlueToRedX;
int teamRedPasteZ = teamBluePasteZ + BlueToRedZ;
World world = Bukkit.getWorlds().get(0);
TeamBlueSpawn = new Location(world,
TeamBluePasteX + 0.5 + teamBlueSpawnOffsetX,
TeamBlueCornerY + 0.5 + teamBlueSpawnOffsetY,
TeamBluePasteZ + 0.5 + teamBlueSpawnOffsetZ);
teamBluePasteX + 0.5 + teamBlueSpawnOffsetX,
blueCornerY + 0.5 + teamBlueSpawnOffsetY,
teamBluePasteZ + 0.5 + teamBlueSpawnOffsetZ);
TeamRedSpawn = new Location(world,
TeamRedPasteX + 0.5 - teamBlueSpawnOffsetX,
TeamRedCornerY + 0.5 + teamBlueSpawnOffsetY,
TeamRedPasteZ + 0.5 - teamBlueSpawnOffsetZ);
teamRedPasteX + 0.5 - teamBlueSpawnOffsetX,
teamRedCornerY + 0.5 + teamBlueSpawnOffsetY,
teamRedPasteZ + 0.5 - teamBlueSpawnOffsetZ);
SpecSpawn = new Location(world,
teamBluePasteX + BlueToRedX /2.0,
blueCornerY + BlueToRedY /2.0 + schemsizeY/2.0,
teamBluePasteZ + BlueToRedZ /2.0);
Vector v1 = TeamBlueSpawn.toVector().subtract(TeamRedSpawn.toVector());
double pitch = Math.toDegrees(v1.angle(v1.clone().setY(0)));
double yaw = Math.toDegrees(v1.clone().setY(0).angle(new Vector(0, 0, 1)));
double pitchInverted = pitch * -1;
double yawInverted = yaw + 180;
TeamBlueSpawn.setYaw((float) yawInverted);
TeamBlueSpawn.setYaw((float) yaw + 180);
TeamBlueSpawn.setPitch((float) pitch);
TeamRedSpawn.setYaw((float) yaw);
TeamRedSpawn.setPitch((float) pitchInverted);
TeamRedSpawn.setPitch((float) pitch * -1);
SpecSpawn = new Location(world,
TeamBluePasteX + TeamBluetoReddistanceX/2.0,
TeamBlueCornerY + TeamBluetoReddistanceY/2.0 + SchemsizeY/2.0,
TeamBluePasteZ + TeamBluetoReddistanceZ/2.0);
boolean teamRedRotate;
boolean teamBlueRotate;
if(TeamBluetoReddistanceX > 0){
ArenaMinX = TeamBlueCornerX - Schem2BorderX;
ArenaMaxX = TeamRedCornerX + SchemsizeX + Schem2BorderX;
int arenaMinX;
int arenaMaxX;
int arenaMinZ;
int arenaMaxZ;
if(BlueToRedX > 0){
arenaMinX = blueCornerX - schem2BorderX;
arenaMaxX = teamRedCornerX + schemsizeX + schem2BorderX;
teamRedRotate = true;
teamBlueRotate = false;
}else{
ArenaMinX = TeamRedCornerX - Schem2BorderX;
ArenaMaxX = TeamBlueCornerX + SchemsizeX + Schem2BorderX;
arenaMinX = teamRedCornerX - schem2BorderX;
arenaMaxX = blueCornerX + schemsizeX + schem2BorderX;
teamRedRotate = false;
teamBlueRotate = true;
}
if(TeamBluetoReddistanceZ > 0){
ArenaMinZ = TeamBlueCornerZ - Schem2BorderZ;
ArenaMaxZ = TeamRedCornerZ + SchemsizeZ + Schem2BorderZ;
if(BlueToRedZ > 0){
arenaMinZ = blueCornerZ - schem2BorderZ;
arenaMaxZ = teamRedCornerZ + schemsizeZ + schem2BorderZ;
teamRedRotate = true;
teamBlueRotate = false;
}else{
ArenaMinZ = TeamRedCornerZ - Schem2BorderZ;
ArenaMaxZ = TeamBlueCornerZ + SchemsizeZ + Schem2BorderZ;
if(TeamBluetoReddistanceZ != 0){
arenaMinZ = teamRedCornerZ - schem2BorderZ;
arenaMaxZ = blueCornerZ + schemsizeZ + schem2BorderZ;
if(BlueToRedZ != 0){
teamRedRotate = false;
teamBlueRotate = true;
}
@ -338,15 +286,24 @@ public class Config {
teamRedRotate = false;
teamBlueRotate = false;
}
TeamRedRotate = teamRedRotate;
TeamBlueRotate = teamBlueRotate;
RedRotate = teamRedRotate;
BlueRotate = teamBlueRotate;
int arenaYSize = blueCornerY - underBorder + schemsizeY + PreperationArea;
RedPasteRegion = new Region(teamRedCornerX, teamRedCornerY, teamRedCornerZ, schemsizeX, schemsizeY, schemsizeZ);
BluePasteRegion = new Region(blueCornerX, blueCornerY, blueCornerZ, schemsizeX, schemsizeY, schemsizeZ);
RedExtendRegion = new Region(teamRedCornerX, underBorder, teamRedCornerZ, schemsizeX, arenaYSize, schemsizeZ, PreperationArea, PreperationArea);
BlueExtendRegion = new Region(blueCornerX, underBorder, blueCornerZ, schemsizeX, arenaYSize, schemsizeZ, PreperationArea, PreperationArea);
ArenaRegion = new Region(arenaMinX, underBorder, arenaMinZ, arenaMaxX - arenaMinX, arenaYSize, arenaMaxZ - arenaMinZ);
EventKampfID = Integer.parseInt(System.getProperty("fightID", "0"));
if(event()){
if(EventKampfID >= 1){
EventFight eventFight = EventFight.get(EventKampfID);
if(eventFight == null){
Bukkit.getLogger().log(Level.SEVERE, "Failed to load EventFight");
IFightSystem.shutdown(null);
Bukkit.shutdown();
}
assert eventFight != null;
@ -355,7 +312,7 @@ public class Config {
if(team1 == null || team2 == null){
Bukkit.getLogger().log(Level.SEVERE, "Failed to load Team");
IFightSystem.shutdown(null);
Bukkit.shutdown();
}
assert team1 != null;
@ -405,19 +362,28 @@ public class Config {
RedLeader = null;
CheckSchemID = Integer.parseInt(System.getProperty("checkSchemID", "0"));
PrepareSchemID = Integer.parseInt(System.getProperty("prepareSchemID", "0"));
Ranked = Boolean.parseBoolean(System.getProperty("ranked", "false"));
if(Ranked){
mode = ArenaMode.RANKED;
}else if(CheckSchemID != 0){
mode = ArenaMode.CHECK;
}else if(PrepareSchemID != 0){
mode = ArenaMode.PREPARE;
}else if(EventKampfID >= 1){
mode = ArenaMode.EVENT;
}else if(EventKampfID == -1){
mode = ArenaMode.TEST;
}else{
mode = ArenaMode.NORMAL;
}
}
public static boolean event(){
return EventKampfID >= 1;
}
public static boolean test(){
return EventKampfID == -1;
}
public static boolean check(){
return CheckSchemID != 0;
return ArenaMode.Test.contains(mode);
}
public static boolean recording(){
return event();
return mode == ArenaMode.EVENT;
}
}

Datei anzeigen

@ -20,7 +20,6 @@
package de.steamwar.fightsystem;
import de.steamwar.sql.EventFight;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
@ -50,21 +49,4 @@ public class IFightSystem {
public static Player getEventLeiter(){
return eventLeiter;
}
public static void shutdown(String reason){
if(reason != null)
Bukkit.broadcastMessage(reason);
//Staggered kick to prevent lobby overloading
kickNext();
}
private static void kickNext(){
if(Bukkit.getOnlinePlayers().isEmpty()){
Bukkit.shutdown();
return;
}
Bukkit.getOnlinePlayers().iterator().next().kickPlayer(null);
Bukkit.getScheduler().runTaskLater(plugin, IFightSystem::kickNext, 10);
}
}

Datei anzeigen

@ -19,92 +19,34 @@
package de.steamwar.fightsystem.utils;
import com.comphenix.protocol.events.PacketContainer;
import com.google.common.primitives.Bytes;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.IFightSystem;
import de.steamwar.fightsystem.fight.IFight;
import de.steamwar.fightsystem.fight.IFightTeam;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ITechHider {
private ITechHider (){}
static final Map<PacketContainer, PacketContainer> packetCache = new HashMap<>();
static final Material obfuscateMaterial;
static final int threadMultiplier;
static final int arenaMinX;
static final int arenaMaxX;
static final int arenaMinZ;
static final int arenaMaxZ;
private static final int blueMinX;
private static final int blueMaxX;
private static final int blueMinZ;
private static final int blueMaxZ;
private static final int redMinX;
private static final int redMaxX;
private static final int redMinZ;
private static final int redMaxZ;
static{
int areaExtension = Config.EnterStages.isEmpty() ? Config.BorderFromSchematic : 0;
blueMinX = ITechHider.posToChunk(Config.TeamBlueCornerX - areaExtension);
blueMaxX = ITechHider.posToChunk(Config.TeamBlueCornerX + Config.SchemsizeX + areaExtension) + 1;
blueMinZ = ITechHider.posToChunk(Config.TeamBlueCornerZ - areaExtension);
blueMaxZ = ITechHider.posToChunk(Config.TeamBlueCornerZ + Config.SchemsizeZ + areaExtension) + 1;
redMinX = ITechHider.posToChunk(Config.TeamRedCornerX - areaExtension);
redMaxX = ITechHider.posToChunk(Config.TeamRedCornerX + Config.SchemsizeX + areaExtension) + 1;
redMinZ = ITechHider.posToChunk(Config.TeamRedCornerZ - areaExtension);
redMaxZ = ITechHider.posToChunk(Config.TeamRedCornerZ + Config.SchemsizeZ + areaExtension) + 1;
arenaMinX = ITechHider.posToChunk(Config.ArenaMinX);
arenaMaxX = ITechHider.posToChunk(Config.ArenaMaxX) + 1;
arenaMinZ = ITechHider.posToChunk(Config.ArenaMinZ);
arenaMaxZ = ITechHider.posToChunk(Config.ArenaMaxZ) + 1;
obfuscateMaterial = Material.getMaterial(Config.ObfuscateWithTag);
Bukkit.getScheduler().runTaskTimer(IFightSystem.getPlugin(), packetCache::clear, 1, 1);
if(Config.event())
threadMultiplier = 4;
else
threadMultiplier = 1;
}
static boolean bypass(Player p, int chunkX, int chunkZ){
if(p == IFightSystem.getEventLeiter())
return true;
IFightTeam ft = IFight.getPlayerTeam(p);
if(ft == null){
//Außerhalb der Arena
return arenaMinX > chunkX ||
chunkX > arenaMaxX ||
arenaMinZ > chunkZ ||
chunkZ > arenaMaxZ;
return Config.ArenaRegion.chunkOutside(chunkX, chunkZ);
}else if(ft.isBlue()){
return ft.canPlayerEntern(p) ||
redMinX > chunkX ||
chunkX > redMaxX ||
redMinZ > chunkZ ||
chunkZ > redMaxZ;
return ft.canPlayerEntern(p) || Config.RedExtendRegion.chunkOutside(chunkX, chunkZ);
}else{
return ft.canPlayerEntern(p) ||
blueMinX > chunkX ||
chunkX > blueMaxX ||
blueMinZ > chunkZ ||
chunkZ > blueMaxZ;
return ft.canPlayerEntern(p) || Config.BlueExtendRegion.chunkOutside(chunkX, chunkZ);
}
}
static int posToChunk(int c){
public static int posToChunk(int c){
int chunk = c / 16;
if(c<0)
chunk--;

Datei anzeigen

@ -0,0 +1,153 @@
/*
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.utils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import java.util.function.ObjIntConsumer;
import java.util.logging.Level;
public class Region {
private final int minX;
private final int minY;
private final int minZ;
private final int maxX;
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 extendZ) {
this(minX - extendX, minY, minZ - extendZ,
sizeX + extendX * 2, sizeY, sizeZ + extendZ * 2);
}
public Region(int minX, int minY, int minZ, int sizeX, int sizeY, int sizeZ) {
Bukkit.getLogger().log(Level.INFO, minX + " " + minY + " " + minZ + " " + sizeX + " " + sizeY + " " + 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 double posToChunk(int pos){
return pos / 16.0;
}
private int getMinChunkX(){
return (int) Math.floor(posToChunk(minX));
}
private int getMaxChunkX(){
return (int) Math.ceil(posToChunk(maxX));
}
private int getMinChunkZ(){
return (int) Math.floor(posToChunk(minZ));
}
private int getMaxChunkZ(){
return (int) Math.ceil(posToChunk(maxZ));
}
public boolean chunkOutside(int cX, int cZ) {
return getMinChunkX() > cX || cX > getMaxChunkX() ||
getMinChunkZ() > cZ || cZ > getMaxChunkZ();
}
public void forEachChunk(ObjIntConsumer<Integer> executor) {
for(int x = getMinChunkX(); x <= getMaxChunkX(); x++)
for(int z = getMinChunkZ(); z <= getMaxChunkZ(); z++)
executor.accept(x, z);
}
public void forEach(TriConsumer<Integer, Integer, Integer> executor) {
for(int x = minX; x < maxX; x++) {
for(int y = minY; y < maxY; y++) {
for (int z = minZ; z <= maxZ; z++) {
executor.accept(x, y, z);
}
}
}
}
public int volume(){
return (maxX - minX) * (maxY - minY) * (maxZ - minZ);
}
public int centerX() {
return (maxX - minX) / 2 + minX;
}
public int centerZ() {
return (maxZ - minZ) / 2 + minZ;
}
public boolean in2dRegion(Location location){
return minX <= location.getX() && location.getX() < maxX && minZ <= location.getZ() && location.getZ() <= maxZ;
}
public boolean inRegion(Location location){
return in2dRegion(location) && minY < location.getY() && location.getY() < maxY;
}
public boolean playerInRegion(Location location){
return in2dRegion(location) && minY <= location.getY() && location.getY() + 1.8 < maxY;
}
public boolean in2dRegion(Block block){
return minX <= block.getX() && block.getX() < maxX && minZ <= block.getZ() && block.getZ() <= maxZ;
}
public boolean inRegion(Block block){
return in2dRegion(block) && minY <= block.getY() && block.getY() < maxY;
}
public interface TriConsumer<T, V, U>{
void accept(T x, V y, U z);
}
}

Datei anzeigen

@ -0,0 +1,34 @@
/*
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.winconditions;
public enum Winconditions {
TIMEOUT,
HEART_RATIO_TIMEOUT,
PERCENT_TIMEOUT,
ALL_DEAD,
CAPTAIN_DEAD,
PERCENT_SYSTEM,
RELATIVE_PERCENT,
POINTS,
TIME_TECH_KO,
WATER_TECH_KO,
PUMPKIN_TECH_KO
}

Datei anzeigen

@ -1,90 +1,150 @@
Times:
NoPlayersOnlineDuration: 300
# Time in seconds the server stops after starting if nobody joins
NoPlayersOnlineDuration: 30
# Time in seconds the team leaders have to choose their schematic
PreSchemPasteDuration: 120
# Time in seconds for preparing
SetupDuration: 300
# Time in seconds the final countdown is long
PreFightDuration: 30
# Time in seconds to spectate the arena after the fight
SpectatorDuration: 30
Arena:
# The amount of blocks the schematics should be pasted under the surface
WaterDepth: 0
# The size of the schematics
Schemsize:
x: 0
y: 0
z: 0
# The outer border of the arena, measured in blocks around the schematic areas
Schem2Border:
x: 0
z: 0
# The size of the team areas are expanded around the schematics
BorderFromSchematic: 0
# If ground walkable, teams can walk below the lower arena border during setup
GroundWalkable: true
Schematic:
OnlyPublicSchematics: false
# If the rank system for the schematics should be enabled
RanksEnabled: false
# The schematic type that can be chosen in this arena
SchematicType: normal
# If the schematics should be rotated during pasting
Rotate: true
ReplaceObsidian: false
ReplaceBedrock: false
# If only public schematics are allowed
OnlyPublicSchematics: false
# If the public only force should be completly disabled
IgnorePublicOnly: false
# If obsidian and bedrock should be replaced during PRE_RUNNING
ReplaceObsidianBedrock: false
# If the replacement should happen with blockupdates
ReplaceWithBlockupdates: false
Output:
# Name of the "Red" team
TeamRedName: Rot
# Color prefix of the "Red" team
TeamRedPrefix: '§c'
# Name of the "Blue" team
TeamBlueName: Blau
# Color of the "Blue" team
TeamBluePrefix: '§3'
GameName: War*
# The name of the gamemode presented to the players
GameName: NoGear
# The prefix used for team chats
TeamChatDetection: +
# The list of active winconditions
WinConditions:
Timeout: true
AllDead: true
CaptainDead: false
PercentSystem: false
RelativePercent: false
Points: false
Entern: false
TechKO: false
WaterTechKO: false
HeartRatioTimeout: false
PumpkinTechKO: false
- TIMEOUT
# - HEART_RATIO_TIMEOUT
# - PERCENT_TIMEOUT
- ALL_DEAD
# - CAPTAIN_DEAD
# - PERCENT_SYSTEM
# - RELATIVE_PERCENT
# - POINTS
- WATER_TECH_KO
# - TIME_TECH_KO
# - PUMPKIN_TECH_KO
WinConditionParams:
# The time of any of the timeout winconditions in seconds
TimeoutTime: 1200
EnterPhaseBegin: 600
# The percentage when any of the percent winconditions limits or triggers a win
PercentWin: 5.0
# Blocks ignored by the percent winconditions
IgnoredBlocks:
- AIR
- WATER
- TNT
- OBSIDIAN
Kits:
# The kit file for this configuration
File: kits.yml
# The default kit for team members
MemberDefault: default
# The default kit for team leaders
LeaderDefault: default
# If the personal kit system is active
PersonalKits: false
# Items that are not allowed in the personal kit
ForbiddenItems: []
# A list of integers containing the waiting time of this enter stage in the fight
EnterStages: []
Techhider:
ObfuscateWith: 121
ObfuscateWithTag: ENDER_STONE
# if the techhider is active
Active: true
# Which block the techhider replaces to.
ObfuscateWith: end_stone
# A list of all hidden blocks. "water" results in the hiding of all waterlogged blocks as well.
HiddenBlocks:
BEDROCK: 7
WATER: 8
STATIONARY_WATER: 9
NOTE_BLOCK: 25
DETECTOR_RAIL: 28
PISTON_BASE: 33
PISTON_EXTENSION: 34
PISTON_STICKY_BASE: 29
POWERED_RAIL: 27
TNT: 46
OBSIDIAN: 49
CHEST: 54
REDSTONE_WIRE: 55
STONE_PLATE: 70
IRON_DOOR_BLOCK: 71
WOOD_PLATE: 72
REDSTONE_TORCH_OFF: 75
REDSTONE_TORCH_ON: 76
STONE_BUTTON: 77
DIODE_BLOCK_OFF: 93
DIODE_BLOCK_ON: 94
BREWING_STAND: 117
TRIPWIRE_HOOK: 131
TRIPWIRE: 132
WOOD_BUTTON: 143
TRAPPED_CHEST: 146
GOLD_PLATE: 147
IRON_PLATE: 148
REDSTONE_COMPARATOR_OFF: 149
REDSTONE_COMPARATOR_ON: 150
REDSTONE_BLOCK: 152
HOPPER: 154
ACTIVATOR_RAIL: 157
DROPPER: 158
SLIME_BLOCK: 165
IRON_TRAPDOOR: 167
OBSERVER: 218
LEVER: 69
- water
- note_block
- powered_rail
- detector_rail
- piston
- piston_head
- sticky_piston
- tnt
- chest
- trapped_chest
- redstone_wire
- stone_pressure_plate
- iron_door
- oak_pressure_plate
- spruce_pressure_plate
- birch_pressure_plate
- jungle_pressure_plate
- acacia_pressure_plate
- dark_oak_pressure_plate
- redstone_torch
- redstone_wall_torch
- repeater
- brewing_stand
- tripwire_hook
- tripwire
- heavy_weighted_pressure_plate
- light_weighted_pressure_plate
- comparator
- redstone_block
- hopper
- activator_rail
- dropper
- slime_block
- observer
- honey_block
- lever
# The block entities that are hidden (contents of blocks)
HiddenBlockEntites:
- minecraft:sign
- minecraft:dispenser
@ -98,22 +158,22 @@ Techhider:
- minecraft:jukebox
- minecraft:comparator
# Muss in config.yml des Weltordners gesetzt werden
Arena:
Schemsize:
x: 0
y: 0
z: 0
TeamBlueCorner:
x: 0
y: 0
z: 0
TeamBluetoReddistance:
x: 0
y: 0
z: 0
Schem2Border:
x: 0
z: 0
underArenaBorder: 0
BorderFromSchematic: 0
# The following configuration must be in the Worldforlder/config.yml
#
# # The lower arena border under which players get damage
# UnderBorder:
# # The lowest corner in all axis of the blue team schematic area
# BlueCorner:
# x: 0
# y: 0
# z: 0
# # The offset between the lowest corner of the blue area and the lowest corner of the red area
# BlueToRed:
# x: 0
# y: 0
# z: 0
# # The offset the teams spawn relative to the center of their area
# SpawnOffset:
# x: 0
# y: 0
# z: 0

Datei anzeigen

@ -24,26 +24,24 @@ import de.steamwar.core.Core;
import de.steamwar.fightsystem.commands.*;
import de.steamwar.fightsystem.countdown.*;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.kit.KitManager;
import de.steamwar.fightsystem.fight.FightWorld;
import de.steamwar.fightsystem.listener.Shutdown;
import de.steamwar.fightsystem.listener.*;
import de.steamwar.fightsystem.record.RecordSystem;
import de.steamwar.fightsystem.record.Recorder;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent;
import de.steamwar.fightsystem.utils.*;
import de.steamwar.fightsystem.states.OneShotStateDependent;
import de.steamwar.fightsystem.utils.EnterHandler;
import de.steamwar.fightsystem.utils.FightStatistics;
import de.steamwar.fightsystem.utils.TechHider;
import de.steamwar.fightsystem.winconditions.*;
import de.steamwar.sql.EventFight;
import de.steamwar.sql.Schematic;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Level;
public class FightSystem extends JavaPlugin {
@ -51,60 +49,47 @@ public class FightSystem extends JavaPlugin {
public static final String PREFIX = "§eArena§8» ";
private static FightSystem plugin;
private static FightState fightState = FightState.PRE_LEADER_SETUP;
private static Map<StateDependent, Boolean> stateDependentFeatures = new HashMap<>();
private static int fightTime = 0;
private static Countdown mainCountdown;
@Override
public void onLoad() {
setPlugin(this);
plugin = this;
IFightSystem.init(this);
}
@Override
public void onEnable() {
Fight.init();
KitManager.loadAllKits();
TechHider.init();
FightScoreboard.init();
RecordSystem.init();
try {
CommandRemover.removeAll("gamemode");
CommandInjector.injectCommand(new GamemodeCommand());
} catch (Exception e) {
getLogger().log(Level.SEVERE, "Failed to replace commands", e);
Bukkit.shutdown();
return;
}
new EntityDamageListener();
new EntityExplodeListener();
new FoodLevelChangeListener();
new EntityDamage();
new WaterRemover();
new Permanent();
new PistonListener();
new PlayerChatListener();
new HotbarGUIListener();
new PlayerMoveListener();
new PlayerStateListener();
new ProjectileLaunchListener();
new InFightDamageListener();
new InFightInventoryListener();
new FreezeWorldStateListener();
new EventJoinListener();
new EventRecordListener();
new CheckListener();
new TestListener();
new NormalJoinListener();
new RankedJoinListener();
new GameplayListener();
new Chat();
new HotbarGUI();
new ArenaBorder();
new TeamArea();
new IngameDeath();
new InFightDamage();
new InFightInventory();
new DenyWorldInteraction();
new EventJoin();
new Recording();
new Check();
new Shutdown();
new SetupQuit();
new PrepareSchem();
new TestJoin();
new NormalJoin();
new RankedJoin();
new PersonalKitCreator();
new ScoreboardListener();
new FightScoreboard();
new ArrowStopper();
if(Core.getVersion() > 8)
new VersionDependentListener();
new ArrowPickup();
new EnterHandler();
new TechHider();
new FightWorld();
new WinconditionAllDead();
new WinconditionCaptainDead();
@ -115,41 +100,49 @@ public class FightSystem extends JavaPlugin {
new WinconditionPoints();
new WinconditionTimeout();
new WinconditionHeartRatioTimeout();
new WinconditionTechKO();
new WinconditionTimeTechKO();
new EventTeamOffWincondition();
new RankedPlayerLeftWincondition();
new WinconditionPercentTimeout();
Objects.requireNonNull(getCommand("leave")).setExecutor(new LeaveCommand());
Objects.requireNonNull(getCommand("kit")).setExecutor(new KitCommand());
Objects.requireNonNull(getCommand("remove")).setExecutor(new RemoveCommand());
Objects.requireNonNull(getCommand("accept")).setExecutor(new AcceptCommand());
Objects.requireNonNull(getCommand("decline")).setExecutor(new DeclineCommand());
Objects.requireNonNull(getCommand("invite")).setExecutor(new InviteCommand());
Objects.requireNonNull(getCommand("ready")).setExecutor(new ReadyCommand());
Objects.requireNonNull(getCommand("ak")).setExecutor(new AkCommand());
Objects.requireNonNull(getCommand("leader")).setExecutor(new LeaderCommand());
Objects.requireNonNull(getCommand("lockschem")).setExecutor(new LockschemCommand());
new NoPlayersOnlineCountdown();
new PreSchemCountdown();
new PostSchemCountdown();
new PreRunningCountdown();
new SpectateOverCountdown();
new EventSpectateCountdown();
mainCountdown = new NoPlayersOnlineCountdown();
fightTime = Config.TimeoutTime;
new LeaveCommand();
new KitCommand();
new RemoveCommand();
new AcceptCommand();
new DeclineCommand();
new InviteCommand();
new ReadyCommand();
new AkCommand();
new LeaderCommand();
new LockschemCommand();
new StateCommand();
new SkipCommand();
if(Config.event() || Config.Ranked) {
Objects.requireNonNull(getCommand("invite")).setExecutor(new EventDummyCommand());
Objects.requireNonNull(getCommand("ready")).setExecutor(new EventDummyCommand());
Objects.requireNonNull(getCommand("ak")).setExecutor(new EventDummyCommand());
Objects.requireNonNull(getCommand("leader")).setExecutor(new EventDummyCommand());
new OneShotStateDependent(ArenaMode.All, FightState.PreRunning, () -> Bukkit.broadcastMessage(PREFIX + "§aDer Kampf beginnt!"));
new OneShotStateDependent(ArenaMode.All, FightState.Running, () -> Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!"));
new OneShotStateDependent(ArenaMode.AntiTest, FightState.Running, FightStatistics::start);
setPreSchemState();
}else if(Config.test()){
if(Config.check()){
Bukkit.getScheduler().runTaskLater(this, () -> Fight.getBlueTeam().setSchematic(Schematic.getSchemFromDB(Config.CheckSchemID)), 0);
}else{
Bukkit.getScheduler().runTaskLater(this, Fight.getBlueTeam()::pasteDummy, 0);
}
Bukkit.getScheduler().runTaskLater(this, Fight.getRedTeam()::pasteDummy, 0);
setPreSchemState();
setPostSchemState();
try {
CommandRemover.removeAll("gamemode");
CommandInjector.injectCommand(new GamemodeCommand());
} catch (Exception e) {
getLogger().log(Level.SEVERE, "Failed to replace commands", e);
}
if(Config.mode == ArenaMode.EVENT) {
setPreSchemState();
}else if(Config.mode == ArenaMode.CHECK){
Fight.getBlueTeam().setSchem(Schematic.getSchemFromDB(Config.CheckSchemID));
}else if(Config.mode == ArenaMode.PREPARE) {
Fight.getBlueTeam().setSchem(Schematic.getSchemFromDB(Config.PrepareSchemID));
}
}
@Override
@ -157,71 +150,31 @@ public class FightSystem extends JavaPlugin {
Recorder.closeAll();
}
public static void setPreSchemState() {
if(fightState != FightState.PRE_LEADER_SETUP)
throw new SecurityException(fightState.name());
setFightState(FightState.PRE_SCHEM_SETUP);
public static void setPreLeaderState() {
FightState.setFightState(FightState.PRE_LEADER_SETUP);
Fight.calcAvailibleSchemTypes();
mainCountdown = new PreSchemPasteCountdown();
Fight.getBlueTeam().reset();
Fight.getRedTeam().reset();
}
public static void setPreSchemState() {
FightState.setFightState(FightState.PRE_SCHEM_SETUP);
}
public static void setPostSchemState() {
if(fightState != FightState.PRE_SCHEM_SETUP)
throw new SecurityException(fightState.name());
setFightState(FightState.POST_SCHEM_SETUP);
TechHider.start();
if(!Config.test()){
Fight.getBlueTeam().pasteSchematic();
Fight.getRedTeam().pasteSchematic();
}
if(Config.test())
mainCountdown = null;
else
mainCountdown = new SetupOverCountdown();
FightState.setFightState(FightState.POST_SCHEM_SETUP);
}
public static void setPreRunningState() {
if(fightState != FightState.POST_SCHEM_SETUP)
throw new SecurityException(fightState.name());
setFightState(FightState.PRE_RUNNING);
Fight.getBlueTeam().loadKits();
Fight.getRedTeam().loadKits();
setAllPlayersGM(GameMode.SURVIVAL);
Bukkit.broadcastMessage(PREFIX + "§aDer Kampf beginnt!");
mainCountdown = new PreRunningCountdown();
Fight.replaceSync();
if(Config.event())
new EventTeamOffWincondition();
FightState.setFightState(FightState.PRE_RUNNING);
}
public static void setRunningState() {
if(fightState != FightState.PRE_RUNNING)
throw new SecurityException(fightState.name());
setFightState(FightState.RUNNING);
setAllPlayersGM(GameMode.SURVIVAL);
FightStatistics.start();
Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!");
FightState.setFightState(FightState.RUNNING);
}
public static void setSpectateState(FightTeam winFightTeam, String windescription) {
if(fightState == FightState.SPECTATE)
return;
setFightState(FightState.SPECTATE);
setAllPlayersGM(GameMode.SPECTATOR);
Fight.getBlueTeam().teleportToSpawn();
Fight.getRedTeam().teleportToSpawn();
Bukkit.getOnlinePlayers().forEach(player -> player.getInventory().clear());
Bukkit.broadcastMessage(" ");
FightState.setFightState(FightState.SPECTATE);
if(winFightTeam != null) {
Bukkit.broadcastMessage(PREFIX + "§aDas Team " + winFightTeam.getColoredName() + " §ahat gewonnen!");
@ -229,7 +182,7 @@ public class FightSystem extends JavaPlugin {
Bukkit.broadcastMessage(PREFIX + "§aKein Team hat gewonnen!");
}
if(Config.event()) {
if(Config.mode == ArenaMode.EVENT) {
if (winFightTeam == null)
getEventFight().setErgebnis(0);
else if (winFightTeam.isBlue())
@ -239,15 +192,10 @@ public class FightSystem extends JavaPlugin {
}
if(!Config.test()){
new SpectateOverCountdown();
FightStatistics.saveStats(winFightTeam, windescription);
}
}
public static void setFightTime(int fightTime) {
FightSystem.fightTime = fightTime;
}
public static void setEventLeiter(Player el){
IFightSystem.setEventLeiter(el);
}
@ -260,70 +208,24 @@ public class FightSystem extends JavaPlugin {
return IFightSystem.getEventFight();
}
private static void setPlugin(FightSystem pl){
plugin = pl;
}
public static FightSystem getPlugin() {
return plugin;
}
public static FightState getFightState() {
return fightState;
}
public static int getFightTime() {
return fightTime;
}
public static void shutdown(String reason){
IFightSystem.shutdown(reason);
if(reason != null)
Bukkit.broadcastMessage(reason);
//Staggered kick to prevent lobby overloading
kickNext();
}
public static void registerStateDependent(StateDependent stateDependent){
if(stateDependent.enabled().isEmpty())
private static void kickNext(){
if(Bukkit.getOnlinePlayers().isEmpty()){
Bukkit.shutdown();
return;
boolean enabled = stateDependent.enabled().contains(fightState);
stateDependentFeatures.put(stateDependent, enabled);
if(enabled)
stateDependent.enable();
}
private static void setAllPlayersGM(GameMode gm) {
for(FightPlayer fightPlayer: Fight.getBlueTeam().getPlayers()){
Fight.setPlayerGamemode(fightPlayer.getPlayer(), gm);
}
for(FightPlayer fightPlayer: Fight.getRedTeam().getPlayers()){
Fight.setPlayerGamemode(fightPlayer.getPlayer(), gm);
}
}
private static void setFightState(FightState state){
fightState = state;
if(mainCountdown != null){
mainCountdown.disable();
mainCountdown = null;
}
postStateChange();
}
private static void postStateChange(){
for(Map.Entry<StateDependent, Boolean> feature : stateDependentFeatures.entrySet()){
//Enable feature if should be enabled and currently disabled
if(feature.getKey().enabled().contains(fightState)){
if(!feature.getValue()){
feature.getKey().enable();
feature.setValue(true);
}
feature.getKey().stateChange(fightState);
}
//Disable feature if should be disabled and currently enabled
if(!feature.getKey().enabled().contains(fightState) && feature.getValue()){
feature.getKey().disable();
feature.setValue(false);
}
}
Bukkit.getOnlinePlayers().iterator().next().kickPlayer(null);
Bukkit.getScheduler().runTaskLater(plugin, FightSystem::kickNext, 10);
}
}

Datei anzeigen

@ -19,12 +19,20 @@
package de.steamwar.fightsystem.commands;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class AcceptCommand implements CommandExecutor {
public AcceptCommand() {
new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "accept", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) {

Datei anzeigen

@ -19,211 +19,36 @@
package de.steamwar.fightsystem.commands;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.fight.Kit;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.kit.KitManager;
import de.steamwar.fightsystem.Config;
import de.steamwar.sql.Schematic;
import de.steamwar.sql.SchematicType;
import de.steamwar.fightsystem.states.StateDependentCommand;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.UserGroup;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class AkCommand implements CommandExecutor {
private static final String SCHEMLIST_COMMAND = "/ak schemlist ";
private static final int FILES_PER_PAGE = 15;
public AkCommand() {
new StateDependentCommand(ArenaMode.Test, FightState.All, "ak", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) {
return false;
}
Player player = (Player) sender;
switch(args.length){
case 1:
if(args[0].equalsIgnoreCase("schem") || args[0].equalsIgnoreCase("schemlist")){
//TEXT COMPONENTS
TextComponent publicList = new TextComponent("PUBLIC");
publicList.setColor(ChatColor.YELLOW);
publicList.setBold(true);
publicList.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§ePublic Liste...").create()));
publicList.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ak schemlist public"));
TextComponent privateList = new TextComponent("PRIVATE");
privateList.setColor(ChatColor.YELLOW);
privateList.setBold(true);
privateList.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§ePrivate Liste...").create()));
privateList.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ak schemlist 0"));
//TEXT COMPONENTS
player.spigot().sendMessage(publicList);
player.spigot().sendMessage(privateList);
}else
Commands.sendHelp(player);
break;
case 2:
if(args[0].equalsIgnoreCase("addkit")){
if(SteamwarUser.get(player.getUniqueId()).getUserGroup() != UserGroup.Developer){
Commands.sendHelp(player);
return false;
}
KitManager.saveInventory(args[1], player);
} else if(args[0].equalsIgnoreCase("schemlist") && FightSystem.getFightState() == FightState.PRE_SCHEM_SETUP) {
try {
FightTeam fightTeam = Fight.getPlayerTeam(player);
if(fightTeam != null && fightTeam.getFightPlayer(player).isLeader()) {
if(args[1].equalsIgnoreCase("public")) {
sendPlayerSchematicList(true, 0, player, Config.SchematicType);
Kit.createKit(args[0], player);
return false;
} else {
int page;
page = Integer.parseInt(args[1]);
sendPlayerSchematicList(false, page, player, Config.SchematicType);
}
}
} catch (NumberFormatException ex) {
player.sendMessage(FightSystem.PREFIX + "§cDu musst eine Seitenzahl angeben!");
return false;
}
} else
Commands.sendHelp(player);
break;
case 3:
if(args[0].equalsIgnoreCase("schem")) {
FightTeam fightTeam = Fight.getPlayerTeam(player);
if(fightTeam == null) {
player.sendMessage(FightSystem.PREFIX + "§cDu bist in keinem Team!");
return false;
}else if(fightTeam.hasSchematic()) {
player.sendMessage(FightSystem.PREFIX + "§cDie Schematic ist bereits gewählt!");
return false;
}
Schematic schem;
if(args[2].equalsIgnoreCase("public")) {
schem = Schematic.getSchemFromDB(args[1], SteamwarUser.get(0).getUUID());
} else if(args[2].equalsIgnoreCase("private")) {
schem = Schematic.getSchemFromDB(args[1], player.getUniqueId());
} else
return false;
if(schem == null) {
schem = Schematic.getSchemFromDB(args[1], 0);
if(schem == null){
player.sendMessage(FightSystem.PREFIX + "§cDiese Schematic gibt es nicht!");
return false;
}
}
if(schem.getSchemType() != Config.SchematicType) {
player.sendMessage(FightSystem.PREFIX + "§cDiese Schematic ist kein " + Config.GameName);
return false;
}
fightTeam.setSchematic(schem);
}else
Commands.sendHelp(player);
break;
default:
Commands.sendHelp(player);
}
return false;
}
private void sendPlayerSchematicList(boolean publicSchematics, int currentPage, Player player, SchematicType schematicType) {
List<Schematic> preSchematicList;
List<Schematic> schematicList = new ArrayList<>();
if(publicSchematics) {
preSchematicList = Schematic.getSchemsAccessibleByUser(0);
} else {
preSchematicList = Schematic.getSchemsAccessibleByUser(player.getUniqueId());
}
for(Schematic s : preSchematicList) {
if(s.getSchemType() == schematicType)
schematicList.add(s);
}
if(schematicList.isEmpty()) {
player.sendMessage(FightSystem.PREFIX + "§cDu hast noch keine Schematic(s)!");
return;
}
int pages;
double doublePages = (double) schematicList.size() / (double) FILES_PER_PAGE;
int intPages = schematicList.size() / FILES_PER_PAGE;
if(schematicList.size() <= FILES_PER_PAGE) {
pages = 1;
} else if(doublePages > intPages) {
pages = (intPages + 1);
} else
pages = intPages;
if(currentPage >= pages) return;
player.sendMessage("§5======§8[§dSeite " + (currentPage + 1) + " §7/ §d" + pages + " §7| §d" + schematicList.size() + " Schematic(s)§8]§5======");
for(int i = currentPage * FILES_PER_PAGE; i < (currentPage * FILES_PER_PAGE) + FILES_PER_PAGE; i++) {
if(schematicList.size() <= i) break;
Schematic schem = schematicList.get(i);
TextComponent schematics = new TextComponent("§b" + schem.getSchemName());
schematics.setBold(true);
schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Schematic benutzen...").create()));
schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ak schem " + schem.getSchemName() + (publicSchematics ? " public" : " private")));
player.spigot().sendMessage(schematics);
}
if(pages <= 1) return;
if(currentPage == 0) {
TextComponent nextPage = new TextComponent("Nächste Seite >>");
nextPage.setColor(ChatColor.RED);
nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§6Nächste Seite...").create()));
nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, SCHEMLIST_COMMAND + "1"));
player.spigot().sendMessage(nextPage);
} else if((currentPage + 1) == pages) {
TextComponent beforePage = new TextComponent("<< Vorherige Seite");
beforePage.setColor(ChatColor.RED);
beforePage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§6Vorherige Seite...").create()));
beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, SCHEMLIST_COMMAND + (currentPage - 1)));
player.spigot().sendMessage(beforePage);
} else {
TextComponent beforePage = new TextComponent("<< Seite ");
beforePage.setColor(ChatColor.RED);
beforePage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§6Vorherige Seite...").create()));
beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, SCHEMLIST_COMMAND + (currentPage - 1)));
TextComponent nextPage = new TextComponent(">>");
nextPage.setColor(ChatColor.RED);
nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§6Nächste Seite...").create()));
nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, SCHEMLIST_COMMAND + (currentPage + 1)));
beforePage.addExtra(nextPage);
player.spigot().sendMessage(beforePage);
}
}
}

Datei anzeigen

@ -19,12 +19,15 @@
package de.steamwar.fightsystem.commands;
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.kit.Kit;
import de.steamwar.fightsystem.kit.KitManager;
import de.steamwar.fightsystem.fight.Kit;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.sql.PersonalKit;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -36,7 +39,7 @@ public class Commands {
}
static boolean checkSetup(Player p){
if(!FightSystem.getFightState().setup()){
if(!FightState.setup()){
p.sendMessage(FightSystem.PREFIX + "§cDer Kampf hat bereits begonnen!");
return true;
}
@ -85,9 +88,6 @@ public class Commands {
}
static void toggleReady(Player p){
if(checkSetup(p))
return;
FightTeam fightTeam = checkGetTeam(p);
if(fightTeam == null || checkGetLeader(p) == null)
return;
@ -95,6 +95,14 @@ public class Commands {
fightTeam.setReady(!fightTeam.isReady());
}
static void toggleSkip(Player p){
FightTeam fightTeam = checkGetTeam(p);
if(fightTeam == null || checkGetLeader(p) == null)
return;
fightTeam.skip();
}
static void acceptInvitation(Player p){
if(checkSetup(p))
return;
@ -103,9 +111,8 @@ public class Commands {
if(team == null)
return;
FightPlayer leader = team.getLeader();
p.sendMessage(FightSystem.PREFIX + "§aDu bist Team " + team.getColoredName() + " §abeigetreten!");
leader.sendMessage(FightSystem.PREFIX + "§aDer Spieler §e" + p.getName() + " §aist deinem Team beigetreten!");
team.broadcast(FightSystem.PREFIX + "§aDer Spieler §e" + p.getName() + " §aist dem Team beigetreten!");
team.addMember(p);
}
@ -117,9 +124,8 @@ public class Commands {
if(team == null)
return;
FightPlayer leader = team.getLeader();
p.sendMessage(FightSystem.PREFIX + "§aDu hast die Einladung von " + team.getColoredName() + " §aabgelehnt!");
leader.sendMessage(FightSystem.PREFIX + "§cDer Spieler §e" + p.getName() + " §chat deine Einladung abgelehnt!");
team.broadcast(FightSystem.PREFIX + "§cDer Spieler §e" + p.getName() + " §chat die Einladung abgelehnt!");
team.getInvited().remove(p);
}
@ -201,14 +207,23 @@ public class Commands {
if(fightPlayer == null)
return;
Kit k = KitManager.getKitByName(kitName);
Kit k = null;
if(Config.PersonalKits){
PersonalKit kit = PersonalKit.get(SteamwarUser.get(p.getUniqueId()).getId(), Config.SchematicType.toDB(), kitName);
if(kit != null){
kit.setInUse();
k = new Kit(kit);
}
}else{
k = Kit.getKitByName(kitName);
}
if(k == null){
p.sendMessage(FightSystem.PREFIX + "§cDieses Kit gibt es nicht!");
return;
}
if((fightPlayer.isLeader() && !k.isLeaderAllowed()) ||
(!fightPlayer.isLeader() && !k.isMemberAllowed())){
if(!k.canUseKit(fightPlayer.isLeader())){
p.sendMessage(FightSystem.PREFIX + "§cDu darfst dieses Kit nicht verwenden!");
return;
}
@ -227,7 +242,6 @@ public class Commands {
p.sendMessage("§8/§eleader §8- §7Werde der Leader eines Teams");
}else{
if(fightPlayer.isLeader()){
p.sendMessage("§8/§eak schem §8<§eSchematic§8> - §7Setze deine Schematic");
p.sendMessage("§8/§eready §8- §7Setzt das eigene Team auf bereit");
p.sendMessage("§8/§einvite §8<§eSpieler§8> - §7Lade einen Spieler in dein Team ein");
p.sendMessage("§8/§eremove §8<§eSpieler§8> - §7Wirft einen Spieler aus dem Team");

Datei anzeigen

@ -19,12 +19,20 @@
package de.steamwar.fightsystem.commands;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class DeclineCommand implements CommandExecutor {
public DeclineCommand() {
new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "decline", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) {

Datei anzeigen

@ -24,13 +24,14 @@ 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.kit.Kit;
import de.steamwar.fightsystem.kit.KitManager;
import de.steamwar.fightsystem.fight.Kit;
import de.steamwar.fightsystem.listener.PersonalKitCreator;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv;
import de.steamwar.sql.PersonalKit;
import de.steamwar.sql.Schematic;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit;
@ -66,6 +67,20 @@ public class GUI {
inv.open();
}
public static void state(Player p){
SWInventory inv = new SWInventory(p, 9, "Kampfstatus");
inv.setItem(0, Material.GLASS, "§7PRE_LEADER_SETUP", (ClickType click) -> FightSystem.setPreLeaderState());
inv.setItem(1, Material.GLASS, "§7PRE_SCHEM_SETUP", (ClickType click) -> FightSystem.setPreSchemState());
inv.setItem(2, Material.GLASS, "§7POST_SCHEM_SETUP", (ClickType click) -> FightSystem.setPostSchemState());
inv.setItem(3, Material.GLASS, "§ePRE_RUNNING", (ClickType click) -> FightSystem.setPreRunningState());
inv.setItem(4, Material.GLASS, "§eRUNNING", (ClickType click) -> FightSystem.setRunningState());
inv.setItem(5, Material.GLASS, "§7SPECTATE Blue", (ClickType click) -> FightSystem.setSpectateState(Fight.getBlueTeam(), "operator"));
inv.setItem(6, Material.GLASS, "§7SPECTATE Red", (ClickType click) -> FightSystem.setSpectateState(Fight.getRedTeam(), "operator"));
inv.setItem(7, Material.GLASS, "§7SPECTATE Tie", (ClickType click) -> FightSystem.setSpectateState(null, "operator"));
inv.setCallback(-999, (ClickType click) -> p.closeInventory());
inv.open();
}
public static void chooseInvitation(Player p){
List<SWListInv.SWListEntry<UUID>> players = SWListInv.createPlayerList(p.getUniqueId());
players.removeIf(swItemUUIDPair -> Fight.getFightPlayer(Bukkit.getPlayer(swItemUUIDPair.getObject())) != null);
@ -91,30 +106,59 @@ public class GUI {
inv.open();
}
public static void kitSelection(Player p){
public static void kitSelection(Player p, String query){
FightPlayer fightPlayer = Fight.getFightPlayer(p);
if(fightPlayer == null)
return;
List<SWListInv.SWListEntry<Kit>> entries = new ArrayList<>();
if(Config.PersonalKits){
PersonalKitCreator.openKitSelector(p, "");
List<PersonalKit> kits = PersonalKit.get(SteamwarUser.get(p.getUniqueId()).getId(), Config.SchematicType.toDB());
kits.forEach(kit -> entries.add(new SWListInv.SWListEntry<>(new SWItem(Material.LEATHER_CHESTPLATE, "§e" + kit.getName(), new ArrayList<>(), kit.isInUse(), clickType -> {}), new Kit(kit))));
}else{
List<Kit> kitList = Kit.getAvailableKits(fightPlayer.isLeader());
for(Kit k : kitList){
entries.add(new SWListInv.SWListEntry<>(new SWItem(Material.LEATHER_CHESTPLATE, k.getName(), null, k.leaderExclusive(), null), k));
}
}
entries.removeIf(entry -> !entry.getObject().getName().toLowerCase().contains(query.toLowerCase()));
SWListInv<Kit> inv = new SWListInv<>(p, "Kitauswahl", false, entries, (clickType, kit) -> kit.preview(p));
inv.setCallback(-999, (ClickType click) -> p.closeInventory());
if(entries.isEmpty()) {
inv.setItem(22, new SWItem(Material.BARRIER, "§cKeine Kits gefunden"));
}
if(Config.PersonalKits){
inv.setItem(48, Material.NETHER_STAR, "§eNeues Kit", clickType -> {
SWAnvilInv anvilInv = new SWAnvilInv(p, "Kitname eingeben");
anvilInv.setItem(Material.LEATHER_CHESTPLATE);
anvilInv.setCallback(s -> {
SteamwarUser user = SteamwarUser.get(p.getUniqueId());
if(PersonalKit.nameInUse(user.getId(), Config.SchematicType.toDB(), s)) {
p.sendMessage(FightSystem.PREFIX + "§cDieser Kitname wird bereits genutzt!");
p.closeInventory();
return;
}
List<SWListInv.SWListEntry<Kit>> iconList = new ArrayList<>();
List<Kit> kitList = KitManager.getKits(fightPlayer.isLeader());
for(Kit k : kitList){
iconList.add(new SWListInv.SWListEntry<>(new SWItem(Material.LEATHER_CHESTPLATE, k.getName(), null, !k.isMemberAllowed(), null), k));
Kit prototype = Kit.getAvailableKits(Fight.getFightPlayer(p).isLeader()).get(0);
PersonalKit kit = PersonalKit.create(user.getId(), Config.SchematicType.toDB(), s, prototype.getInventory(), prototype.getArmor());
PersonalKitCreator.openKitCreator(p, kit);
});
anvilInv.open();
});
}
SWListInv<Kit> inv = new SWListInv<>(p, "Kitauswahl", iconList, (ClickType click, Kit k) -> k.preview(p));
inv.setCallback(-999, (ClickType click) -> p.closeInventory());
inv.setItem(50, Material.NAME_TAG, "§eSuchen", clickType -> {
SWAnvilInv anvilInv = new SWAnvilInv(p, "§eNach Kit suchen");
anvilInv.setItem(Material.PAPER);
anvilInv.setCallback(s -> kitSelection(p, s));
anvilInv.open();
});
inv.open();
}
public static void preSchemDialog(Player p){
if(!Config.test() && FightSystem.getFightState() != FightState.PRE_SCHEM_SETUP){
if(!Config.test() && FightState.getFightState() != FightState.PRE_SCHEM_SETUP){
p.sendMessage(FightSystem.PREFIX + "§cDu kannst ohne Gegner keine Schematic wählen");
return;
}
@ -153,8 +197,8 @@ public class GUI {
FightTeam fightTeam = Fight.getPlayerTeam(p);
if(fightTeam == null)
return;
if(Config.test() || FightSystem.getFightState() != FightState.POST_SCHEM_SETUP)
fightTeam.setSchematic(s);
if(Config.test() || FightState.getFightState() != FightState.POST_SCHEM_SETUP)
fightTeam.pasteSchem(s);
p.closeInventory();
});
inv.setCallback(-999, (ClickType click) -> p.closeInventory());

Datei anzeigen

@ -19,12 +19,20 @@
package de.steamwar.fightsystem.commands;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class InviteCommand implements CommandExecutor {
public InviteCommand() {
new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "invite", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) {

Datei anzeigen

@ -19,12 +19,20 @@
package de.steamwar.fightsystem.commands;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class KitCommand implements CommandExecutor {
public KitCommand() {
new StateDependentCommand(ArenaMode.All, FightState.Setup, "kit", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) {
@ -33,7 +41,7 @@ public class KitCommand implements CommandExecutor {
Player player = (Player) sender;
if(args.length != 1)
GUI.kitSelection(player);
GUI.kitSelection(player, "");
else{
Commands.kit(player, args[0]);
}

Datei anzeigen

@ -19,29 +19,34 @@
package de.steamwar.fightsystem.commands;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class LeaderCommand implements CommandExecutor {
public LeaderCommand() {
new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "leader", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player))
return false;
Player player = (Player) sender;
if(Commands.checkSetup(player))
return false;
if(args.length == 0){
if(Fight.getFightPlayer(player) == null){
if(!Fight.getBlueTeam().hasTeamLeader())
Fight.getBlueTeam().setLeader(Fight.getBlueTeam().addMember(player));
else if(!Fight.getRedTeam().hasTeamLeader())
Fight.getRedTeam().setLeader(Fight.getRedTeam().addMember(player));
if(Fight.getBlueTeam().isLeaderless())
Fight.getBlueTeam().addMember(player);
else if(Fight.getRedTeam().isLeaderless())
Fight.getRedTeam().addMember(player);
else
player.sendMessage(FightSystem.PREFIX + "§cEs sind bereits 2 Teamleader vorhanden");
}else

Datei anzeigen

@ -19,12 +19,20 @@
package de.steamwar.fightsystem.commands;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class LeaveCommand implements CommandExecutor {
public LeaveCommand() {
new StateDependentCommand(ArenaMode.All, FightState.Setup, "leave", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) {

Datei anzeigen

@ -19,9 +19,12 @@
package de.steamwar.fightsystem.commands;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCommand;
import de.steamwar.sql.Schematic;
import de.steamwar.sql.SchematicType;
import de.steamwar.sql.SteamwarUser;
@ -32,6 +35,11 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class LockschemCommand implements CommandExecutor {
public LockschemCommand() {
new StateDependentCommand(ArenaMode.All, FightState.All, "lockschem", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player))
@ -62,6 +70,7 @@ public class LockschemCommand implements CommandExecutor {
}
Schematic.getSchemFromDB(fightTeam.getSchematic()).setSchemType(SchematicType.Normal);
player.sendMessage(FightSystem.PREFIX + "Schematic von " + fightTeam.getColoredName() + " §cgesperrt!");
fightTeam.broadcast(FightSystem.PREFIX + "§cDie Schematic wurde von " + player.getName() + " gesperrt!");
return false;
}

Datei anzeigen

@ -19,12 +19,20 @@
package de.steamwar.fightsystem.commands;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class ReadyCommand implements CommandExecutor {
public ReadyCommand() {
new StateDependentCommand(ArenaMode.AntiPrepare, FightState.PostSchemSetup, "ready", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) {

Datei anzeigen

@ -19,12 +19,20 @@
package de.steamwar.fightsystem.commands;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class RemoveCommand implements CommandExecutor {
public RemoveCommand() {
new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "remove", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) {

Datei anzeigen

@ -0,0 +1,46 @@
/*
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.commands;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class SkipCommand implements CommandExecutor {
public SkipCommand() {
new StateDependentCommand(ArenaMode.AntiPrepare, FightState.Running, "skip", this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) {
return false;
}
Player player = (Player) sender;
Commands.toggleSkip(player);
return false;
}
}

Datei anzeigen

@ -19,15 +19,27 @@
package de.steamwar.fightsystem.commands;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class StateCommand implements CommandExecutor {
public StateCommand() {
new StateDependentCommand(ArenaMode.Test, FightState.All, "state", this);
}
public class EventDummyCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
sender.sendMessage(FightSystem.PREFIX + "§cWährend des Events ist der Befehl nicht verfügbar.");
if(!(sender instanceof Player)) {
return false;
}
GUI.state((Player) sender);
return false;
}
}

Datei anzeigen

@ -20,7 +20,6 @@
package de.steamwar.fightsystem.countdown;
import de.steamwar.core.Core;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.listener.BasicListener;
@ -32,22 +31,28 @@ import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
import java.util.ArrayList;
import java.util.List;
public abstract class Countdown {
private int time;
private final BukkitTask task;
private static final List<Countdown> currentCountdowns = new ArrayList<>();
private final int totalTime;
private final Sound sound;
private final boolean level;
abstract String countdownCounting();
abstract void countdownFinished();
protected int time;
private BukkitTask task = null;
Countdown(int time, SWSound sound, boolean level) {
public abstract String countdownCounting();
public abstract void countdownFinished();
public Countdown(int time, SWSound sound, boolean level) {
this.totalTime = time;
this.time = time;
this.sound = getSound(sound);
this.level = level;
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::count, 0, 20);
}
public static Sound getSound(SWSound sound){
@ -68,19 +73,52 @@ public abstract class Countdown {
}
}
public void enable() {
time = totalTime;
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::count, 20, 20);
currentCountdowns.add(this);
}
public void disable() {
if(task != null){
task.cancel();
currentCountdowns.remove(this);
task = null;
}
}
public static void skip(){
if(currentCountdowns.isEmpty())
return;
int smallestTime = currentCountdowns.get(0).time;
for(Countdown countdown : currentCountdowns){
if(countdown.time < smallestTime)
smallestTime = countdown.time;
}
smallestTime--;
for(Countdown countdown : currentCountdowns){
countdown.time -= smallestTime;
}
Bukkit.broadcastMessage(FightSystem.PREFIX + "§aBeide Teams waren damit einverstanden, zum nächsten Event zu beschleunigen!");
}
private void broadcast(String message){
if(Config.recording())
RecordSystem.actionBar(message);
BaseComponent[] msg = TextComponent.fromLegacyText(message);
for(Player p : Bukkit.getOnlinePlayers())
BasicListener.toActionbar(p, msg);
}
public int getTimeLeft(){
return time;
}
void count(){
time--;
switch (time) {
case 900: case 600: case 300: case 180: case 120:
broadcast("§rNoch §a" + time / 60 + " §rMinuten " + countdownCounting());
@ -106,14 +144,8 @@ public abstract class Countdown {
break;
default:
}
if(this.level)
Fight.setLevel(time);
time--;
onTime(time);
}
void onTime(int time){
//Implemented in some countdowns
Bukkit.getServer().getOnlinePlayers().forEach(player -> player.setLevel(time));
}
}

Datei anzeigen

@ -35,8 +35,9 @@ public class EnternCountdown extends Countdown {
private List<TechHider.ChunkPos> chunkPos;
public EnternCountdown(FightPlayer fp) {
super(fp.getKit().getEnterStage(), SWSound.BLOCK_NOTE_PLING, false);
super(Config.EnterStages.get(fp.getKit().getEnterStage()), SWSound.BLOCK_NOTE_PLING, false);
fightPlayer = fp;
enable();
}
@Override
@ -52,13 +53,9 @@ public class EnternCountdown extends Countdown {
@Override
void count(){
if(!fightPlayer.isLiving()){
disable();
return;
}
time--;
Player player = fightPlayer.getPlayer();
int time = FightSystem.getFightTime() - Config.EnterStages.get(fightPlayer.getKit().getEnterStage());
switch (time) {
case 900: case 600: case 300: case 180: case 120:
BasicListener.toActionbar(player, TextComponent.fromLegacyText("§rNoch §a" + time / 60 + " §rMinuten " + countdownCounting()));

Datei anzeigen

@ -17,36 +17,28 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.winconditions;
package de.steamwar.fightsystem.countdown;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.states.FightState;
import org.bukkit.Bukkit;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import de.steamwar.fightsystem.states.StateDependentCountdown;
import java.util.Set;
public class EventSpectateCountdown extends Countdown {
abstract class ListenerWincondition extends Wincondition implements Listener {
ListenerWincondition(boolean condition, Set<FightState> enabled){
//If the condition is not met, never enable
super(condition, enabled);
public EventSpectateCountdown() {
super(Config.SpectatorDuration, SWSound.BLOCK_NOTE_PLING, false);
new StateDependentCountdown(ArenaMode.Event, FightState.Spectate, this);
}
/**
* Enables the state dependent object
*/
@Override
public void enable(){
Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin());
public String countdownCounting() {
return "bis der Server gestoppt wird!";
}
/**
* Disables the state dependent object
*/
@Override
public void disable(){
HandlerList.unregisterAll(this);
public void countdownFinished() {
FightSystem.shutdown(null);
}
}

Datei anzeigen

@ -19,13 +19,29 @@
package de.steamwar.fightsystem.countdown;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCountdown;
import de.steamwar.fightsystem.states.StateDependentListener;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class NoPlayersOnlineCountdown extends Countdown {
public class NoPlayersOnlineCountdown extends Countdown implements Listener {
public NoPlayersOnlineCountdown() {
super(Config.NoPlayerOnlineDuration, null, false);
new StateDependentListener(ArenaMode.All, FightState.PreLeaderSetup, this);
new StateDependentCountdown(ArenaMode.All, FightState.PreLeaderSetup, this){
@Override
public void enable() {
if(Bukkit.getOnlinePlayers().isEmpty())
super.enable();
}
};
}
@Override
@ -33,6 +49,11 @@ public class NoPlayersOnlineCountdown extends Countdown {
return "bis der Server gestoppt wird!";
}
@EventHandler
public void handlePlayerJoin(PlayerJoinEvent event) {
disable();
}
@Override
public void countdownFinished() {
Bukkit.getServer().shutdown();

Datei anzeigen

@ -19,17 +19,21 @@
package de.steamwar.fightsystem.countdown;
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.StateDependentCountdown;
public class SetupOverCountdown extends Countdown {
public class PostSchemCountdown extends Countdown {
public SetupOverCountdown() {
public PostSchemCountdown() {
super(Config.SetupDuration, null, false);
new StateDependentCountdown(ArenaMode.AntiTest, FightState.PostSchemSetup, this);
}
@Override
String countdownCounting() {
public String countdownCounting() {
return "bis die Kits verteilt werden!";
}

Datei anzeigen

@ -19,13 +19,17 @@
package de.steamwar.fightsystem.countdown;
import de.steamwar.fightsystem.FightSystem;
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.StateDependentCountdown;
public class PreRunningCountdown extends Countdown {
public PreRunningCountdown() {
super(Config.PreFightDuration, SWSound.BLOCK_NOTE_PLING, true);
new StateDependentCountdown(ArenaMode.All, FightState.PreRunning, this);
}
@Override

Datei anzeigen

@ -19,31 +19,26 @@
package de.steamwar.fightsystem.countdown;
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.states.FightState;
import de.steamwar.fightsystem.states.StateDependentCountdown;
public class PreSchemPasteCountdown extends Countdown {
public class PreSchemCountdown extends Countdown {
public PreSchemPasteCountdown() {
public PreSchemCountdown() {
super(Config.PreSchemPasteDuration, SWSound.BLOCK_NOTE_PLING, false);
new StateDependentCountdown(ArenaMode.All, FightState.PreSchemSetup, this);
}
@Override
String countdownCounting() {
public String countdownCounting() {
return "bis eine Public-Schematic gewählt wird!";
}
@Override
void countdownFinished() {
checkTeam(Fight.getBlueTeam());
checkTeam(Fight.getRedTeam());
public void countdownFinished() {
FightSystem.setPostSchemState();
}
private void checkTeam(FightTeam team){
if(!team.hasSchematic())
team.pasteDummy();
}
}

Datei anzeigen

@ -19,22 +19,26 @@
package de.steamwar.fightsystem.countdown;
import de.steamwar.fightsystem.FightSystem;
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.StateDependentCountdown;
public class SpectateOverCountdown extends Countdown {
public SpectateOverCountdown() {
super(Config.SpectatorDuration, SWSound.BLOCK_NOTE_PLING, false);
new StateDependentCountdown(ArenaMode.Restartable, FightState.Spectate, this);
}
@Override
public String countdownCounting() {
return "bis der Server gestoppt wird!";
return "bis die Arena zurückgesetzt wird!";
}
@Override
public void countdownFinished() {
FightSystem.shutdown(null);
FightSystem.setPreLeaderState();
}
}

Datei anzeigen

@ -1,46 +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.countdown;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import org.bukkit.Bukkit;
public class TechKOCountdown extends Countdown {
private final FightTeam team;
public TechKOCountdown(FightTeam team, int countdownTime) {
super(countdownTime, SWSound.BLOCK_NOTE_PLING, false);
this.team = team;
}
@Override
final String countdownCounting() {
return "bis " + team.getColoredName() + " §feinen Schuss abgegeben haben muss!";
}
@Override
void countdownFinished() {
Bukkit.broadcastMessage(FightSystem.PREFIX + team.getColoredName() + "§7 ist §eTech K§8.§eO§8.!");
FightSystem.setSpectateState(Fight.getOpposite(team), "TechKO");
}
}

Datei anzeigen

@ -42,9 +42,4 @@ public class TimeOverCountdown extends Countdown {
Bukkit.broadcastMessage(FightSystem.PREFIX +"§aZeit abgelaufen!");
timeOver.run();
}
@Override
void onTime(int time) {
FightSystem.setFightTime(time);
}
}

Datei anzeigen

@ -26,6 +26,7 @@ import com.comphenix.protocol.wrappers.EnumWrappers;
import com.comphenix.protocol.wrappers.PlayerInfoData;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.record.RecordSystem;
import de.steamwar.fightsystem.FightSystem;
@ -41,9 +42,8 @@ import java.util.logging.Level;
public class Fight {
private Fight(){}
public static final FightTeam redTeam = new FightTeam(Config.TeamRedName, Config.TeamRedColor, Config.TeamRedSpawn, Config.TeamRedCornerX, Config.TeamRedCornerY, Config.TeamRedCornerZ, Config.TeamRedRotate, false, Config.RedLeader);
public static final FightTeam blueTeam = new FightTeam(Config.TeamBlueName, Config.TeamBlueColor, Config.TeamBlueSpawn, Config.TeamBlueCornerX, Config.TeamBlueCornerY, Config.TeamBlueCornerZ, Config.TeamBlueRotate, true, Config.BlueLeader);
private static int schemRank;
private static final FightTeam redTeam = new FightTeam(Config.TeamRedName, Config.TeamRedColor, Config.TeamRedSpawn, Config.RedPasteRegion, Config.RedExtendRegion, Config.RedRotate, false, Config.RedLeader);
private static final FightTeam blueTeam = new FightTeam(Config.TeamBlueName, Config.TeamBlueColor, Config.TeamBlueSpawn, Config.BluePasteRegion, Config.BlueExtendRegion, Config.BlueRotate, true, Config.BlueLeader);
public static void init(){
IFight.init(redTeam, blueTeam);
@ -58,14 +58,12 @@ public class Fight {
}
public static FightTeam getOpposite(FightTeam fightTeam) {
if(fightTeam == null){
throw new IllegalArgumentException();
}
if(fightTeam == redTeam)
return blueTeam;
else
else if(fightTeam == blueTeam)
return redTeam;
throw new IllegalArgumentException();
}
public static FightTeam getInvitedTeam(Player player){
@ -93,16 +91,11 @@ public class Fight {
}
public static void playSound(Sound sound, float volume, float pitch) {
if(Config.recording())
RecordSystem.soundAtPlayer(sound.name(), volume, pitch);
//volume: max. 100, pitch: max. 2
Bukkit.getServer().getOnlinePlayers().forEach(player -> player.playSound(player.getLocation(), sound, volume, pitch));
}
public static void setLevel(int level) {
Bukkit.getServer().getOnlinePlayers().forEach(player -> player.setLevel(level));
}
public static FightTeam getTeamByName(String name) {
if(redTeam.getName().equalsIgnoreCase(name))
return redTeam;
@ -111,14 +104,6 @@ public class Fight {
return null;
}
public static void replaceSync() {
Fight.getRedTeam().replaceSync(Config.ReplaceObsidian, Material.OBSIDIAN, Material.TNT);
Fight.getBlueTeam().replaceSync(Config.ReplaceObsidian, Material.OBSIDIAN, Material.TNT);
Fight.getRedTeam().replaceSync(Config.ReplaceBedrock, Material.BEDROCK, Material.SLIME_BLOCK);
Fight.getBlueTeam().replaceSync(Config.ReplaceBedrock, Material.BEDROCK, Material.SLIME_BLOCK);
}
public static void setPlayerGamemode(Player player, GameMode gameMode) {
player.setGameMode(gameMode);
@ -159,33 +144,26 @@ public class Fight {
public static int getMaxRank(){
/* MaxRank of 0 is Pubonly*/
return schemRank;
}
public static void calcAvailibleSchemTypes() {
if(Config.OnlyPublicSchematics){
schemRank = 0;
return;
return 0;
}
if(Config.IgnorePublicOnly || Config.event() || Config.Ranked){
schemRank = 1000;
return;
if(Config.IgnorePublicOnly || ArenaMode.RankedEvent.contains(Config.mode)){
return 1000;
}
if(redTeam.getLeader() == null || redTeam.getLeader().getPlayer() == null ||
blueTeam.getLeader() == null || blueTeam.getLeader().getPlayer() == null){
schemRank = 1000;
return;
if(redTeam.getLeader() == null || blueTeam.getLeader() == null){
return 1000;
}
if(Config.RanksEnabled)
schemRank = Math.min(schemRank(redTeam.getLeader()), schemRank(blueTeam.getLeader()));
return Math.min(schemRank(redTeam.getLeader()), schemRank(blueTeam.getLeader()));
else if(Schematic.getSchemsOfType(redTeam.getLeader().getPlayer().getUniqueId(), Config.SchematicType).isEmpty() ||
Schematic.getSchemsOfType(blueTeam.getLeader().getPlayer().getUniqueId(), Config.SchematicType).isEmpty())
schemRank = 0;
return 0;
else
schemRank = 1;
return 1;
}
private static int schemRank(FightPlayer fightPlayer){

Datei anzeigen

@ -19,10 +19,10 @@
package de.steamwar.fightsystem.fight;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.kit.KitManager;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.kit.Kit;
import de.steamwar.fightsystem.countdown.EnternCountdown;
import de.steamwar.sql.PersonalKit;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.entity.Player;
public class FightPlayer {
@ -32,9 +32,9 @@ public class FightPlayer {
private boolean isOut;
private Kit kit;
private int kills;
private EnternCountdown enternCountdown = null;
public void sendMessage(String message) {
if (this.player != null && this.player.isOnline())
this.player.sendMessage(message);
}
@ -42,12 +42,29 @@ public class FightPlayer {
this.player = player;
this.team = team;
this.isOut = false;
kit = KitManager.getKitByName(Config.MemberDefault);
kit = Kit.getKitByName(Config.MemberDefault);
if(Config.PersonalKits){
PersonalKit personalKit = PersonalKit.getKitInUse(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB());
if(personalKit != null){
kit = new Kit(personalKit);
}
}
kills = 0;
}
public void setOut() {
isOut = true;
stopEnternCountdown();
}
public void setEnternCountdown(EnternCountdown countdown){
enternCountdown = countdown;
}
public void stopEnternCountdown(){
if(enternCountdown != null){
enternCountdown.disable();
}
}
public Player getPlayer() {
@ -84,8 +101,8 @@ public class FightPlayer {
}
public boolean canEntern(){
if(Config.EnterStages.size() <= kit.getEnterStage() || kit.getEnterStage() < 0)
if(enternCountdown == null)
return false;
return Config.EnterStages.get(kit.getEnterStage()) >= FightSystem.getFightTime();
return enternCountdown.getTimeLeft() == 0;
}
}

Datei anzeigen

@ -0,0 +1,218 @@
/*
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.fight;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.core.VersionedRunnable;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.IFightSystem;
import de.steamwar.fightsystem.record.RecordSystem;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent;
import de.steamwar.fightsystem.utils.ColorConverter;
import de.steamwar.fightsystem.utils.Region;
import de.steamwar.sql.NoClipboardException;
import de.steamwar.sql.Schematic;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.*;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import java.io.IOException;
import java.util.List;
import java.util.Random;
import java.util.logging.Level;
public class FightSchematic extends StateDependent {
private final FightTeam team;
private final Region region;
private final boolean rotate;
private Clipboard clipboard = null;
private int schematic = 0;
public FightSchematic(FightTeam team, boolean rotate) {
super(ArenaMode.All, FightState.PostSchemSetup);
this.team = team;
this.region = team.getSchemRegion();
this.rotate = rotate;
register();
}
public boolean hasSchematic(){
return clipboard != null;
}
public int getId(){
return schematic;
}
public void setSchematic(Schematic schem) {
schematic = schem.getSchemID();
try {
clipboard = schem.load();
} catch (IOException e) {
team.broadcast(FightSystem.PREFIX + "§cKonnte die Schematic nicht laden!");
Bukkit.getLogger().log(Level.SEVERE, "Couldn't load Schematic " + schem.getSchemName(), e);
}
}
public void reset(){
schematic = 0;
clipboard = null;
}
@Override
public void enable() {
if(FightState.getFightState() == FightState.SPECTATE)
return;
if(clipboard == null){
List<Schematic> publics = Schematic.getSchemsOfType(0, Config.SchematicType);
if(publics.isEmpty())
return;
setSchematic(publics.get(new Random().nextInt(publics.size())));
}
if(!ArenaMode.Test.contains(Config.mode)){
FightPlayer leader = team.getLeader();
if(leader != null)
leader.getPlayer().getInventory().clear(0);
}
if(team.isBlue())
RecordSystem.blueSchem(schematic);
else
RecordSystem.redSchem(schematic);
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::paste);
}
private void paste(){
FreezeWorld freezer = new FreezeWorld();
DyeColor c = ColorConverter.chat2dye(team.getColor());
try {
VersionedRunnable.call(new VersionedRunnable(() -> {
try {
EditSession e = FightTeam_8.pasteSchematic(clipboard, region, rotate);
FightTeam_8.replaceTeamColor(e, c, region);
} catch (Schematic.WrongVersionException | IOException | NoClipboardException ex) {
throw new SecurityException("Error pasting arena in schematic", ex);
}
}, 8), new VersionedRunnable(() -> {
try {
EditSession e = FightTeam_8.pasteSchematic(clipboard, region, rotate);
FightTeam_12.replaceTeamColor(e, c, region);
} catch (Schematic.WrongVersionException | IOException | NoClipboardException ex) {
throw new SecurityException("Error pasting arena in schematic", ex);
}
}, 12), new VersionedRunnable(() -> {
try {
EditSession e = FightTeam_14.pasteSchematic(clipboard, region, rotate);
FightTeam_14.replaceTeamColor(e, c, region);
} catch (Schematic.WrongVersionException | IOException | NoClipboardException ex) {
throw new SecurityException("Error pasting arena in schematic", ex);
}
}, 14));
} catch (SecurityException securityException) {
team.broadcast(FightSystem.PREFIX + "§cFehler beim Pasten der Schematic");
throw securityException;
}
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> HandlerList.unregisterAll(freezer), 3);
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), team::teleportToSpawn, 40);
}
@Override
public void disable() {
if(!Config.ReplaceObsidianBedrock)
return;
FreezeWorld freezer = null;
if(!Config.ReplaceWithBlockupdates)
freezer = new FreezeWorld();
replaceSync(Material.OBSIDIAN, Material.TNT);
replaceSync(Material.BEDROCK, Material.SLIME_BLOCK);
if(!Config.ReplaceWithBlockupdates)
HandlerList.unregisterAll(freezer);
}
private void replaceSync(Material target, Material replacement){
World world = Bukkit.getWorlds().get(0);
region.forEach((x, y, z) -> {
Block block = world.getBlockAt(x, y, z);
if(block.getType() == target)
block.setType(replacement);
});
}
private static class FreezeWorld implements Listener {
private FreezeWorld(){
Bukkit.getPluginManager().registerEvents(this, IFightSystem.getPlugin());
}
@EventHandler
public void onBlockPhysicsEvent(BlockPhysicsEvent e){
e.setCancelled(true);
}
@EventHandler
public void onPistonExtend(BlockPistonExtendEvent e){
e.setCancelled(true);
}
@EventHandler
public void onPistonRetract(BlockPistonRetractEvent e){
e.setCancelled(true);
}
@EventHandler
public void onBlockGrow(BlockGrowEvent e){
e.setCancelled(true);
}
@EventHandler
public void onRedstoneEvent(BlockRedstoneEvent e){
e.setNewCurrent(e.getOldCurrent());
}
@EventHandler
public void onBlockDispense(BlockDispenseEvent e){
e.setCancelled(true);
}
@EventHandler
public void onInventoryMoveEvent(InventoryMoveItemEvent e){
e.setCancelled(true);
}
}
}

Datei anzeigen

@ -19,82 +19,70 @@
package de.steamwar.fightsystem.fight;
import com.sk89q.worldedit.EditSession;
import de.steamwar.comms.packets.TablistNamePacket;
import de.steamwar.core.VersionedRunnable;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.IFightSystem;
import de.steamwar.fightsystem.kit.KitManager;
import de.steamwar.fightsystem.countdown.Countdown;
import de.steamwar.fightsystem.listener.BasicListener;
import de.steamwar.fightsystem.listener.PersonalKitCreator;
import de.steamwar.fightsystem.record.RecordSystem;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.utils.ColorConverter;
import de.steamwar.fightsystem.utils.FightScoreboard;
import de.steamwar.fightsystem.listener.FightScoreboard;
import de.steamwar.fightsystem.states.StateDependent;
import de.steamwar.fightsystem.utils.ItemBuilder;
import de.steamwar.fightsystem.utils.Region;
import de.steamwar.fightsystem.utils.TechHider;
import de.steamwar.fightsystem.winconditions.RankedPlayerLeftWincondition;
import de.steamwar.inventory.SWItem;
import de.steamwar.sql.NoClipboardException;
import de.steamwar.sql.PersonalKit;
import de.steamwar.sql.Schematic;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.*;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.scoreboard.NameTagVisibility;
import org.bukkit.scoreboard.Team;
import java.io.IOException;
import java.util.*;
public class FightTeam implements IFightTeam{
private UUID designatedLeader;
private FightPlayer leader;
private final UUID designatedLeader;
private final Map<Player, FightPlayer> players = new HashMap<>();
private boolean ready;
private final Set<Player> invited = new HashSet<>();
private final String name;
private final String prefix;
private final ChatColor color;
private int schematic = 0;
private final FightSchematic schematic;
private final Team team;
private final boolean blue;
private final Location spawn;
private final int pasteX;
private final int pasteY;
private final int pasteZ;
private final int cornerX;
private final int cornerY;
private final int cornerZ;
private final boolean rotate;
private boolean ready;
private boolean skip;
public FightTeam(String name, String prefix, Location spawn, int cornerX, int cornerY, int cornerZ, boolean rotate, boolean blue, UUID designatedLeader) {
private final Location spawn;
private final Region schemRegion;
private final Region extendRegion;
public FightTeam(String name, String prefix, Location spawn, Region schemRegion, Region extendRegion, boolean rotate, boolean blue, UUID designatedLeader) {
this.spawn = spawn;
this.pasteX = cornerX + Config.SchemsizeX/2;
this.pasteY = cornerY;
this.pasteZ = cornerZ + Config.SchemsizeZ/2;
this.schemRegion = schemRegion;
this.extendRegion = extendRegion;
this.name = name;
this.prefix = prefix;
this.ready = false;
this.rotate = rotate;
this.cornerX = cornerX;
this.cornerY = cornerY;
this.cornerZ = cornerZ;
this.skip = false;
this.blue = blue;
this.designatedLeader = designatedLeader;
color = ChatColor.getByChar(ChatColor.getLastColors(prefix).replace("§", ""));
this.color = ChatColor.getByChar(ChatColor.getLastColors(prefix).replace("§", ""));
this.schematic = new FightSchematic(this, rotate);
new KitLoader();
new SpectateHandler();
if(FightScoreboard.getScoreboard().getTeam(name) == null)
team = FightScoreboard.getScoreboard().registerNewTeam(name);
else
@ -106,20 +94,16 @@ public class FightTeam implements IFightTeam{
team.setAllowFriendlyFire(false);
}
public final int getCornerX() {
return cornerX;
public Region getSchemRegion() {
return schemRegion;
}
public final int getCornerY() {
return cornerY;
}
public final int getCornerZ() {
return cornerZ;
public Region getExtendRegion() {
return extendRegion;
}
public boolean canbeLeader(Player p){
return !hasTeamLeader() && (designatedLeader == null || designatedLeader.equals(p.getUniqueId()));
return isLeaderless() && (designatedLeader == null || designatedLeader.equals(p.getUniqueId()));
}
public void teleportToSpawn(){
@ -155,11 +139,44 @@ public class FightTeam implements IFightTeam{
return false;
}
public void reset(){
skip = false;
ready = false;
schematic.reset();
invited.clear();
Set<Player> playerSet = new HashSet<>(players.keySet());
for(Player player : playerSet){
if(!Bukkit.getOnlinePlayers().contains(player))
removePlayer(player);
}
FightPlayer leaderBackup = leader;
playerSet.removeIf(player -> !Bukkit.getOnlinePlayers().contains(player));
players.clear();
leader = null;
if(leaderBackup != null){
playerSet.remove(leaderBackup.getPlayer());
addMember(leaderBackup.getPlayer());
}
playerSet.forEach(this::addMember);
if(isLeaderless()){
for(Player player : Bukkit.getOnlinePlayers()){
if(Fight.getPlayerTeam(player) == null && canbeLeader(player)){
addMember(player);
break;
}
}
}
}
public void broadcast(String message) {
players.forEach((player, fp) -> player.sendMessage(message));
}
public FightPlayer addMember(Player player) {
public void addMember(Player player) {
final List<TechHider.ChunkPos> chunksToReload = TechHider.prepareChunkReload(player);
FightPlayer fightPlayer = new FightPlayer(player, this);
players.put(player, fightPlayer);
@ -167,40 +184,47 @@ public class FightTeam implements IFightTeam{
team.addEntry(player.getName());
Fight.setPlayerGamemode(player, GameMode.SURVIVAL);
player.setHealth(20);
player.setFoodLevel(20);
player.getInventory().clear();
BasicListener.setAttackSpeed(player);
player.teleport(spawn);
if(KitManager.getKits(false).size() > 1 || Config.PersonalKits)
if(Kit.getAvailableKits(false).size() > 1 || Config.PersonalKits)
player.getInventory().setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§eKit wählen").build());
player.getInventory().setItem(7, new ItemBuilder(Material.BEACON).removeAllAttributs().setDisplayName("§eRespawn").build());
if(!Config.test())
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), prefix + player.getName()).send(player), 5);
if(Config.recording())
RecordSystem.playerJoins(player);
TechHider.reloadChunks(player, chunksToReload);
return fightPlayer;
if(isLeaderless())
setLeader(fightPlayer);
}
public void removePlayer(Player player) {
FightPlayer fightPlayer = getFightPlayer(player);
final List<TechHider.ChunkPos> chunksToReload = TechHider.prepareChunkReload(player);
List<TechHider.ChunkPos> chunksToReload = TechHider.prepareChunkReload(player);
players.remove(player);
team.removeEntry(player.getName());
fightPlayer.getPlayer().getInventory().clear();
if(fightPlayer.equals(leader) && FightSystem.getFightState().setup())
if(fightPlayer.equals(leader))
setLeader(null);
RecordSystem.entityDespawns(player);
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
player.teleport(Config.SpecSpawn);
if(!Config.test())
player.getInventory().clear();
if(player.isOnline()){
if(!ArenaMode.Test.contains(Config.mode))
new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7" + player.getName()).send(player);
if(Config.recording())
RecordSystem.entityDespawns(player);
TechHider.reloadChunks(player, chunksToReload);
}
}
public boolean hasTeamLeader() {
return leader != null;
public boolean isLeaderless() {
return leader == null;
}
@Override
@ -212,43 +236,48 @@ public class FightTeam implements IFightTeam{
return leader;
}
public void setLeader(FightPlayer leader) {
if (leader == null){
private void setLeader(FightPlayer leader) {
if (leader == null) {
this.leader = null;
if(!players.isEmpty()) {
setLeader(players.values().iterator().next());
Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §e" + this.leader.getPlayer().getName() + " §aist nun Leader von Team " + getColoredName() + "§a!");
}else if(Config.Ranked){
RankedPlayerLeftWincondition.leaderQuit(this);
}else if(!Config.event()){
FightSystem.shutdown(FightSystem.PREFIX + "§cTeam " + getColoredName() + " §chat keine Spieler mehr.\n Arena schließt...");
}else if(FightState.getFightState() != FightState.PRE_LEADER_SETUP && !ArenaMode.RankedEvent.contains(Config.mode)){
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), FightSystem::setPreLeaderState, 1);
}
return;
}
if (!PersonalKitCreator.notInKitCreator(leader.getPlayer()))
leader.getPlayer().closeInventory();
PersonalKitCreator.closeIfInKitCreator(leader.getPlayer());
this.leader = leader;
designatedLeader = null;
if(ready)
setReady(false);
leader.setKit(KitManager.getKitByName(Config.LeaderDefault));
if(!Config.PersonalKits)
leader.setKit(Kit.getKitByName(Config.LeaderDefault));
Inventory inventory = leader.getPlayer().getInventory();
if (KitManager.getKits(true).size() > 1)
if (Kit.getAvailableKits(true).size() > 1)
inventory.setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§eKit wählen").build());
else if(Config.PersonalKits)
inventory.setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§eKit bearbeiten").build());
else
inventory.setItem(1, new ItemBuilder(Material.AIR).build());
if(!Config.event() && !Config.Ranked){
if(!ArenaMode.RankedEvent.contains(Config.mode)){
inventory.setItem(2, new ItemBuilder(Material.PAPER).removeAllAttributs().setDisplayName("§eSpieler einladen").build());
inventory.setItem(3, new ItemBuilder(SWItem.getMaterial("FIREWORK_CHARGE")).removeAllAttributs().setDisplayName("§cSpieler rauswerfen").build());
}
inventory.setItem(4, new ItemBuilder(SWItem.getDye(10), (short) 10).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§cNicht bereit").build());
if(Config.test() || FightSystem.getFightState() != FightState.POST_SCHEM_SETUP)
if(Config.test() || FightState.getFightState() != FightState.POST_SCHEM_SETUP)
inventory.setItem(0, new ItemBuilder(SWItem.getMaterial("CAULDRON_ITEM")).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§e" + Config.GameName + " wählen").build());
if(FightState.getFightState() == FightState.PRE_LEADER_SETUP && !Fight.getOpposite(this).isLeaderless()){
FightSystem.setPreSchemState();
}
}
public Collection<FightPlayer> getPlayers() {
@ -259,89 +288,29 @@ public class FightTeam implements IFightTeam{
return ready;
}
public void pasteSchematic(){
if(Config.recording()){
if(blue)
RecordSystem.blueSchem(schematic);
else
RecordSystem.redSchem(schematic);
}
FreezeWorld freezer = new FreezeWorld();
DyeColor c = ColorConverter.chat2dye(color);
Schematic schem;
try{
schem = Schematic.getSchemFromDB(this.schematic);
}catch(SecurityException e){
pasteDummy();
return;
}
try {
VersionedRunnable.call(new VersionedRunnable(() -> {
try {
EditSession e = FightTeam_8.pasteSchematic(schem, pasteX, pasteY, pasteZ, rotate);
FightTeam_8.replaceTeamColor(e, c, cornerX, cornerY, cornerZ);
} catch (Schematic.WrongVersionException | IOException | NoClipboardException ex) {
throw new SecurityException("Error pasting arena in schematic", ex);
}
}, 8), new VersionedRunnable(() -> {
try {
EditSession e = FightTeam_8.pasteSchematic(schem, pasteX, pasteY, pasteZ, rotate);
FightTeam_12.replaceTeamColor(e, c, cornerX, cornerY, cornerZ);
} catch (Schematic.WrongVersionException | IOException | NoClipboardException ex) {
throw new SecurityException("Error pasting arena in schematic", ex);
}
}, 12), new VersionedRunnable(() -> {
try {
EditSession e = FightTeam_14.pasteSchematic(schem, pasteX, pasteY, pasteZ, rotate);
FightTeam_14.replaceTeamColor(e, c, cornerX, cornerY, cornerZ);
} catch (Schematic.WrongVersionException | IOException | NoClipboardException ex) {
throw new SecurityException("Error pasting arena in schematic", ex);
}
}, 14));
} catch (SecurityException securityException) {
broadcast(FightSystem.PREFIX + "§cFehler beim Pasten der Schematic");
throw securityException;
}
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> HandlerList.unregisterAll(freezer), 3);
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), this::teleportToSpawn,40);
}
public void pasteDummy(){
List<Schematic> publics = Schematic.getSchemsOfType(0, Config.SchematicType);
if(publics.isEmpty())
return;
schematic = publics.get(new Random().nextInt(publics.size())).getSchemID();
pasteSchematic();
if(!Config.test() && leader != null)
leader.getPlayer().getInventory().clear(0);
}
public void setSchematic(Schematic schematic){
this.schematic = schematic.getSchemID();
broadcast(FightSystem.PREFIX + "§7Das §e" + Config.GameName + " " + schematic.getSchemName() + " §7wird für den Kampf verwendet!");
if(!Config.test())
leader.getPlayer().getInventory().clear(0);
public void pasteSchem(Schematic schematic){
setSchem(schematic);
if(Config.test())
pasteSchematic();
this.schematic.enable();
else if(Fight.getOpposite(this).hasSchematic()){
FightSystem.setPostSchemState();
}
}
public void setSchem(Schematic schematic){
this.schematic.setSchematic(schematic);
broadcast(FightSystem.PREFIX + "§7Das §e" + Config.GameName + " " + schematic.getSchemName() + " §7wird für den Kampf verwendet!");
}
public boolean hasSchematic(){
return schematic != 0;
return schematic.hasSchematic();
}
public void setReady(boolean ready) {
Player l = leader.getPlayer();
if(schematic == 0){
if(!schematic.hasSchematic()){
l.sendMessage(FightSystem.PREFIX + "§cZuerst muss eine Schematic gewählt sein!");
return;
}
@ -358,6 +327,18 @@ public class FightTeam implements IFightTeam{
}
}
public void skip(){
this.skip = !skip;
if(skip){
broadcast(FightSystem.PREFIX + "§aEuer Team ist nun bereit, zum nächsten Event zu beschleunigen!");
if(Fight.getOpposite(this).skip || Config.test()){
Countdown.skip();
}
}else{
broadcast(FightSystem.PREFIX + "§cEuer Team ist nicht mehr bereit, zum nächsten Event zu beschleunigen!");
}
}
public Set<Player> getInvited() {
return invited;
}
@ -375,7 +356,7 @@ public class FightTeam implements IFightTeam{
}
public int getSchematic() {
return schematic;
return schematic.getId();
}
public Location getSpawn() {
@ -397,51 +378,6 @@ public class FightTeam implements IFightTeam{
return currentHearts / maximumHearts;
}
public void loadKits(){
for(FightPlayer fightPlayer : players.values()) {
if(fightPlayer.getPlayer() == null)
continue;
fightPlayer.getPlayer().getInventory().clear();
PersonalKit personalKit = null;
if(Config.PersonalKits)
personalKit = PersonalKit.getKitInUse(SteamwarUser.get(fightPlayer.getPlayer().getUniqueId()).getId(), Config.SchematicType.toDB());
if(personalKit != null){
PlayerInventory inventory = fightPlayer.getPlayer().getInventory();
inventory.setContents(personalKit.getInventory());
inventory.setArmorContents(personalKit.getArmor());
}else if(fightPlayer.getKit() != null)
fightPlayer.getKit().loadToPlayer(fightPlayer.getPlayer());
}
}
void replaceSync(boolean replace, Material target, Material replacement) {
if(!replace)
return;
World world = Bukkit.getWorlds().get(0);
Location minPoint = new Location(world, cornerX, cornerY, cornerZ);
Location maxPoint = new Location(world, (cornerX + Config.SchemsizeX), (cornerY + Config.SchemsizeY), (cornerZ + Config.SchemsizeZ));
FreezeWorld freezer = null;
if(!Config.ReplaceWithBlockupdates)
freezer = new FreezeWorld();
for(int x = minPoint.getBlockX(); x <= maxPoint.getBlockX(); x++) {
for(int z = minPoint.getBlockZ(); z <= maxPoint.getBlockZ(); z++) {
for(int y = minPoint.getBlockY(); y <= maxPoint.getBlockY(); y++) {
Block block = world.getBlockAt(x, y, z);
if(block.getType() == target)
block.setType(replacement);
}
}
}
if(!Config.ReplaceWithBlockupdates)
HandlerList.unregisterAll(freezer);
}
private void setTeamColor(Team team, ChatColor color){
VersionedRunnable.call(new VersionedRunnable(() -> FightTeam_8.setTeamColor(team, color), 8),
new VersionedRunnable(() -> FightTeam_9.setTeamColor(team, color), 9),
@ -449,44 +385,48 @@ public class FightTeam implements IFightTeam{
new VersionedRunnable(() -> FightTeam_14.setTeamColor(team, color), 14));
}
private static class FreezeWorld implements Listener {
private FreezeWorld(){
Bukkit.getPluginManager().registerEvents(this, IFightSystem.getPlugin());
public ChatColor getColor() {
return color;
}
@EventHandler
public void onBlockPhysicsEvent(BlockPhysicsEvent e){
e.setCancelled(true);
private class KitLoader extends StateDependent {
private KitLoader() {
super(ArenaMode.All, FightState.Ingame);
register();
}
@EventHandler
public void onPistonExtend(BlockPistonExtendEvent e){
e.setCancelled(true);
@Override
public void enable() {
for(FightPlayer fightPlayer : players.values()) {
Player player = fightPlayer.getPlayer();
PersonalKitCreator.closeIfInKitCreator(player);
player.getInventory().clear();
Fight.setPlayerGamemode(player, GameMode.SURVIVAL);
fightPlayer.getKit().loadToPlayer(player);
}
}
@EventHandler
public void onPistonRetract(BlockPistonRetractEvent e){
e.setCancelled(true);
@Override
public void disable() {
players.values().forEach(fightPlayer -> fightPlayer.getPlayer().getInventory().clear());
}
}
@EventHandler
public void onBlockGrow(BlockGrowEvent e){
e.setCancelled(true);
private class SpectateHandler extends StateDependent {
private SpectateHandler() {
super(ArenaMode.All, FightState.Spectate);
register();
}
@EventHandler
public void onRedstoneEvent(BlockRedstoneEvent e){
e.setNewCurrent(e.getOldCurrent());
@Override
public void enable() {
players.values().forEach(fightPlayer -> Fight.setPlayerGamemode(fightPlayer.getPlayer(), GameMode.SPECTATOR));
}
@EventHandler
public void onBlockDispense(BlockDispenseEvent e){
e.setCancelled(true);
}
@EventHandler
public void onInventoryMoveEvent(InventoryMoveItemEvent e){
e.setCancelled(true);
@Override
public void disable() {
players.values().forEach(fightPlayer -> Fight.setPlayerGamemode(fightPlayer.getPlayer(), GameMode.SURVIVAL));
}
}
}

Datei anzeigen

@ -0,0 +1,62 @@
/*
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.fight;
import de.steamwar.core.VersionedRunnable;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator;
public class FightWorld extends StateDependent {
private final World world = Bukkit.getWorlds().get(0);
public FightWorld() {
super(ArenaMode.Restartable, FightState.Schem);
register();
}
@Override
public void enable() {
//unused
}
@Override
public void disable() {
World backup = new WorldCreator(world.getName() + "/backup").createWorld();
assert backup != null;
Config.ArenaRegion.forEachChunk((x, z) -> resetChunk(backup, x, z));
Bukkit.unloadWorld(backup, false);
}
private void resetChunk(World backup, int x, int z){
VersionedRunnable.call(
new VersionedRunnable(() -> FightWorld_8.resetChunk(world, backup, x, z), 8),
new VersionedRunnable(() -> FightWorld_9.resetChunk(world, backup, x, z), 9),
new VersionedRunnable(() -> FightWorld_10.resetChunk(world, backup, x, z), 10),
new VersionedRunnable(() -> FightWorld_12.resetChunk(world, backup, x, z), 12),
new VersionedRunnable(() -> FightWorld_14.resetChunk(world, backup, x, z), 14),
new VersionedRunnable(() -> FightWorld_15.resetChunk(world, backup, x, z), 15));
}
}

Datei anzeigen

@ -0,0 +1,349 @@
/*
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.fight;
import de.steamwar.core.Core;
import de.steamwar.core.VersionedCallable;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.commands.Commands;
import de.steamwar.fightsystem.commands.GUI;
import de.steamwar.fightsystem.listener.*;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import de.steamwar.sql.PersonalKit;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BlockDataMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.logging.Level;
public class Kit {
private static final File kits = new File(FightSystem.getPlugin().getDataFolder(), Config.KitFile);
private static final ArrayList<Kit> loadedKits = new ArrayList<>();
static {
if(!kits.exists()) {
Bukkit.getLogger().log(Level.SEVERE, "Kitconfig fehlend!");
}
FileConfiguration kitData = YamlConfiguration.loadConfiguration(kits);
ConfigurationSection kitSection = kitData.getConfigurationSection("Kits");
for(String key : Objects.requireNonNull(kitSection).getKeys(false)) {
loadedKits.add(new Kit(Objects.requireNonNull(kitSection.getConfigurationSection(key))));
}
}
private final String name;
private final ItemStack[] inventory;
private final ItemStack[] armor;
private final Collection<PotionEffect> effects;
private final int enterStage;
private final boolean tnt;
private final boolean leaderAllowed;
private final boolean memberAllowed;
public Kit(String name, Player player) {
this.name = name;
this.inventory = player.getInventory().getContents();
this.armor = player.getInventory().getArmorContents();
this.effects = player.getActivePotionEffects();
this.leaderAllowed = true;
this.memberAllowed = true;
this.enterStage = 0;
this.tnt = true;
}
public Kit(ConfigurationSection kit){
name = kit.getName();
inventory = Objects.requireNonNull(kit.getList("Items")).toArray(new ItemStack[0]);
if(kit.isList("Armor"))
armor = Objects.requireNonNull(kit.getList("Armor")).toArray(new ItemStack[0]);
else
armor = null;
leaderAllowed = kit.getBoolean("LeaderAllowed");
memberAllowed = kit.getBoolean("MemberAllowed");
if(kit.isList("Effects"))
effects = (List<PotionEffect>) kit.getList("Effects");
else
effects = null;
enterStage = kit.getInt("EnterStage", 0);
tnt = kit.getBoolean("TNT", true);
}
public Kit(PersonalKit kit){
this.name = kit.getName();
this.inventory = kit.getInventory();
this.armor = kit.getArmor();
this.effects = Collections.emptyList();
this.leaderAllowed = true;
this.memberAllowed = true;
this.enterStage = 0;
this.tnt = true;
}
public static Kit getKitByName(String kitName) {
for(Kit kit : loadedKits) {
if(kit.getName().equalsIgnoreCase(kitName))
return kit;
}
return null;
}
public static List<Kit> getAvailableKits(boolean leader){
List<Kit> kits = new ArrayList<>();
for (Kit k : loadedKits) {
if (k.canUseKit(leader)){
kits.add(k);
}
}
return kits;
}
public String getName() {
return name;
}
public boolean canUseKit(boolean leader){
if (leader) {
return leaderAllowed;
} else {
return memberAllowed;
}
}
public boolean leaderExclusive() {
return !memberAllowed;
}
public ItemStack[] getInventory() {
return inventory;
}
public ItemStack[] getArmor() {
return armor;
}
/* Is this kit allowed to set/handle tnt? */
public boolean isTnt(){
return tnt;
}
/* In which stage is entern allowed? */
public int getEnterStage() {
return enterStage;
}
public void toPersonalKit(PersonalKit kit) {
kit.setContainer(inventory, armor);
}
public void removeBadItems(){
Kit normal = Kit.getKitByName(Config.MemberDefault);
assert normal != null;
for(int i = 0; i < inventory.length; i++){
if(isBadItem(inventory[i]))
inventory[i] = null;
}
}
public static boolean isBadItem(ItemStack stack){
if(stack == null)
return false;
//Check for forbidden item
if(Config.ForbiddenItems.contains(stack.getType().name()))
return true;
//Check for attribute modifiers
if(Core.getVersion() >= 14 && PersonalKitCreator_14.hasAttributeModifier(stack)){
return true;
}
if(stack.hasItemMeta()){
ItemMeta meta = stack.getItemMeta();
if(meta instanceof BlockDataMeta && ((BlockDataMeta)meta).hasBlockData())
return true; //Blocks always upwards slabs etc.
if(VersionedCallable.call(new VersionedCallable<>(() -> PersonalKitCreator_8.hasItems(stack), 8),
new VersionedCallable<>(() -> PersonalKitCreator_9.hasItems(stack), 9),
new VersionedCallable<>(() -> PersonalKitCreator_10.hasItems(stack), 10),
new VersionedCallable<>(() -> PersonalKitCreator_12.hasItems(stack), 12),
new VersionedCallable<>(() -> PersonalKitCreator_14.hasItems(stack), 14),
new VersionedCallable<>(() -> PersonalKitCreator_15.hasItems(stack), 15)))
return true; //Blocks prefilled inventories
}
Kit normal = Kit.getKitByName(Config.MemberDefault);
assert normal != null;
return !normal.isEnchantmentInKit(stack) && !stack.getEnchantments().isEmpty();
}
private boolean isEnchantmentInKit(ItemStack stack){
for(ItemStack is : inventory){
if(similar(stack, is))
return true;
}
if(armor != null){
for(ItemStack is : armor){
if(similar(stack, is))
return true;
}
}
return false;
}
private boolean similar(ItemStack stack, ItemStack stack2){
if(stack == null || stack2 == null)
return false;
if(stack.getType() != stack2.getType())
return false;
if(stack.hasItemMeta() != stack2.hasItemMeta())
return false;
if(stack.getItemMeta() == null || stack2.getItemMeta() == null)
return true;
//Enchantment Map comparison used for default similarity check does not work
Map<Enchantment, Integer> en = stack.getItemMeta().getEnchants();
Map<Enchantment, Integer> en2 = new HashMap<>(stack.getItemMeta().getEnchants());
for(Map.Entry<Enchantment, Integer> e : en.entrySet()){
if(!en2.remove(e.getKey(), e.getValue()))
return false;
}
return en2.isEmpty();
}
public void loadToPlayer(Player player) {
player.getInventory().setContents(inventory);
if(armor != null)
player.getInventory().setArmorContents(armor);
player.updateInventory();
if(effects != null)
player.addPotionEffects(effects);
}
/**
* Opens a kit preview with the options to go back to kit selection or to select the kit.
*/
public void preview(Player player){
SWInventory inv = new SWInventory(player, 54, name);
//36 = Inventargröße
for(int i = 0; i < 36; i++){
if(inventory[i] == null)
continue;
SWItem item = new SWItem();
item.setItemStack(inventory[i]);
inv.setItem(i, item);
}
if(armor != null){
for(int i = 0; i < 4; i++){
if(armor[i] == null)
continue;
SWItem item = new SWItem();
item.setItemStack(armor[i]);
inv.setItem(36 + i, item);
}
}
if(effects != null){
Iterator<PotionEffect> it = effects.iterator();
int pos = 44;
while(it.hasNext()){
PotionEffect effect = it.next();
SWItem item = new SWItem(SWItem.getMaterial("POTION"), effect.getType().getName());
inv.setItem(pos, item);
pos--;
}
}
inv.setCallback(-999, click -> player.closeInventory());
if(Config.PersonalKits){
inv.setItem(49, SWItem.getMaterial("WOOD_AXE"), "§7Kit bearbeiten", clickType -> PersonalKitCreator.openKitCreator(player, PersonalKit.get(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB(), name)));
inv.setItem(53, Material.BARRIER, "§cKit löschen", clickType -> {
player.closeInventory();
SWInventory conf = new SWInventory(player, 9, "Kit wirklich löchen?");
conf.setItem(8, SWItem.getDye(1), "§cAbbrechen", click -> player.closeInventory());
conf.setItem(0, SWItem.getDye(10), "§aLöschen", click -> {
player.closeInventory();
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
PersonalKit kit = PersonalKit.get(user.getId(), Config.SchematicType.toDB(), name);
if(kit.isInUse()) {
List<PersonalKit> kits = PersonalKit.get(user.getId(), Config.SchematicType.toDB());
if(!kits.isEmpty()){
PersonalKit kit1 = kits.get(0);
kit1.setInUse();
FightPlayer fightPlayer = Fight.getFightPlayer(player);
assert fightPlayer != null;
fightPlayer.setKit(new Kit(kit1));
}
}
kit.delete();
});
conf.open();
});
}
inv.setItem(45, SWItem.getDye(10), (byte)10, "§aKit wählen", click -> {
Commands.kit(player, name);
player.closeInventory();
});
inv.setItem(53, SWItem.getDye(1), (byte)1, "§cZurück", click -> GUI.kitSelection(player, ""));
inv.open();
}
public static void createKit(String kitName, Player player){
loadedKits.add(new Kit(kitName, player));
YamlConfiguration yamlConfiguration = new YamlConfiguration();
for(Kit k : loadedKits){
ConfigurationSection section = yamlConfiguration.createSection("Kits." + k.getName());
section.set("Items", k.inventory);
if(k.armor != null)
section.set("Armor", k.armor);
section.set("LeaderAllowed", k.leaderAllowed);
section.set("MemberAllowed", k.memberAllowed);
section.set("Effects", k.effects);
section.set("EnterStage", k.enterStage);
section.set("TNT", k.tnt);
}
try {
yamlConfiguration.save(kits);
}catch(IOException e){
throw new SecurityException("Failed to save kits.data", e);
}
}
}

Datei anzeigen

@ -1,207 +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.kit;
import de.steamwar.fightsystem.commands.Commands;
import de.steamwar.fightsystem.commands.GUI;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import java.util.*;
public class Kit {
private final String name;
private final boolean leaderAllowed;
private final boolean memberAllowed;
private final ItemStack[] inventory;
private final ItemStack[] armor;
private final Collection<PotionEffect> effects;
private final int enterStage;
private final boolean tnt;
Kit(String name, Player player) {
this.name = name;
this.leaderAllowed = true;
this.memberAllowed = true;
this.inventory = player.getInventory().getContents();
this.armor = player.getInventory().getArmorContents();
this.effects = player.getActivePotionEffects();
this.enterStage = 0;
this.tnt = true;
}
Kit(ConfigurationSection kit){
name = kit.getName();
inventory = Objects.requireNonNull(kit.getList("Items")).toArray(new ItemStack[0]);
if(kit.isList("Armor"))
armor = Objects.requireNonNull(kit.getList("Armor")).toArray(new ItemStack[0]);
else
armor = null;
leaderAllowed = kit.getBoolean("LeaderAllowed");
memberAllowed = kit.getBoolean("MemberAllowed");
if(kit.isList("Effects"))
effects = (Collection<PotionEffect>) kit.getList("Effects");
else
effects = null;
enterStage = kit.getInt("EnterStage", 0);
tnt = kit.getBoolean("TNT", true);
}
public String getName() {
return name;
}
public boolean isLeaderAllowed() {
return leaderAllowed;
}
public boolean isMemberAllowed() {
return memberAllowed;
}
public ItemStack[] getInventory() {
return inventory;
}
public ItemStack[] getArmor() {
return armor;
}
/* Is this kit allowed to set/handle tnt? */
public boolean isTnt(){
return tnt;
}
/* In which stage is entern allowed? */
public int getEnterStage() {
return enterStage;
}
public boolean isEnchantmentInKit(ItemStack stack){
for(ItemStack is : inventory){
if(similar(stack, is))
return true;
}
if(armor != null){
for(ItemStack is : armor){
if(similar(stack, is))
return true;
}
}
return false;
}
private boolean similar(ItemStack stack, ItemStack stack2){
if(stack == null || stack2 == null)
return false;
if(stack.getType() != stack2.getType())
return false;
if(stack.hasItemMeta() != stack2.hasItemMeta())
return false;
if(stack.getItemMeta() == null || stack2.getItemMeta() == null)
return true;
//Enchantment Map comparison used for default similarity check does not work
Map<Enchantment, Integer> en = stack.getItemMeta().getEnchants();
Map<Enchantment, Integer> en2 = new HashMap<>(stack.getItemMeta().getEnchants());
for(Map.Entry<Enchantment, Integer> e : en.entrySet()){
if(!en2.remove(e.getKey(), e.getValue()))
return false;
}
return en2.isEmpty();
}
public void loadToPlayer(Player player) {
player.getInventory().setContents(inventory);
if(armor != null)
player.getInventory().setArmorContents(armor);
player.updateInventory();
if(effects != null)
player.addPotionEffects(effects);
}
void saveKit(ConfigurationSection section){
section.set("Items", inventory);
if(armor != null)
section.set("Armor", armor);
section.set("LeaderAllowed", leaderAllowed);
section.set("MemberAllowed", memberAllowed);
section.set("Effects", effects);
section.set("EnterStage", enterStage);
section.set("TNT", tnt);
}
/**
* Opens a kit preview with the options to go back to kit selection or to select the kit.
* @param player
*/
public void preview(Player player){
SWInventory inv = new SWInventory(player, 54, name);
preview(inv, inventory, armor, effects);
inv.setCallback(-999, (click) -> player.closeInventory());
inv.setItem(45, SWItem.getDye(10), (byte)10, "§aKit wählen", (click) -> {
Commands.kit(player, name);
player.closeInventory();
});
inv.setItem(53, SWItem.getDye(1), (byte)1, "§cZurück", (click) -> GUI.kitSelection(player));
inv.open();
}
public static void preview(SWInventory inv, ItemStack[] inventory, ItemStack[] armor, Collection<PotionEffect> effects) {
//36 = Inventargröße
for(int i = 0; i < 36; i++){
if(inventory[i] == null)
continue;
SWItem item = new SWItem();
item.setItemStack(inventory[i]);
inv.setItem(i, item);
}
if(armor != null){
for(int i = 0; i < 4; i++){
if(armor[i] == null)
continue;
SWItem item = new SWItem();
item.setItemStack(armor[i]);
inv.setItem(36 + i, item);
}
}
if(effects != null){
Iterator<PotionEffect> it = effects.iterator();
int pos = 44;
while(it.hasNext()){
PotionEffect effect = it.next();
SWItem item = new SWItem(SWItem.getMaterial("POTION"), effect.getType().getName());
inv.setItem(pos, item);
pos--;
}
}
}
}

Datei anzeigen

@ -1,97 +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.kit;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
public class KitManager {
private KitManager(){}
private static final File kits = new File(FightSystem.getPlugin().getDataFolder(), Config.KitFile);
private static final FileConfiguration kitData = YamlConfiguration.loadConfiguration(kits);
private static final ArrayList<Kit> loadedKits = new ArrayList<>();
public static void saveInventory(String kitName, Player player){
loadedKits.add(new Kit(kitName, player));
saveAllKits();
}
public static Kit getKitByName(String kitName) {
for(Kit kit : loadedKits) {
if(kit.getName().equalsIgnoreCase(kitName))
return kit;
}
return null;
}
public static List<Kit> getKits(boolean leader){
List<Kit> kits = new ArrayList<>();
if(leader){
for (Kit k : loadedKits)
if (k.isLeaderAllowed())
kits.add(k);
}else{
for (Kit k : loadedKits)
if (k.isMemberAllowed())
kits.add(k);
}
return kits;
}
public static void loadAllKits() {
if(!kits.exists()) {
saveAllKits();
Bukkit.getLogger().log(Level.SEVERE, "kit config fehlend!");
FightSystem.shutdown(null);
return;
}
if(kitData.getConfigurationSection("Kits") != null) {
for(String key : kitData.getConfigurationSection("Kits").getKeys(false)) {
loadedKits.add(new Kit(kitData.getConfigurationSection("Kits." + key)));
}
}
}
private static void saveAllKits(){
YamlConfiguration yamlConfiguration = new YamlConfiguration();
for(Kit k : loadedKits)
k.saveKit(yamlConfiguration.createSection("Kits." + k.getName()));
try {
yamlConfiguration.save(kits);
}catch(IOException e){
throw new SecurityException("Failed to save kits.data", e);
}
}
}

Datei anzeigen

@ -0,0 +1,72 @@
/*
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.ArenaMode;
import de.steamwar.fightsystem.Config;
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 net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
public class ArenaBorder implements Listener {
public ArenaBorder() {
new StateDependentListener(ArenaMode.All, FightState.All, this);
}
@EventHandler
public void arenaBorder(PlayerMoveEvent event){
Player player = event.getPlayer();
Location to = event.getTo();
assert to != null;
if(!Config.ArenaRegion.in2dRegion(to)){
reset(event);
return;
}
FightTeam team = Fight.getPlayerTeam(player);
if(team == null || player.getGameMode() == GameMode.SPECTATOR)
return;
if(to.getY() <= Config.ArenaRegion.getMinY()) {
if(FightState.infight())
player.damage(2);
else if(!Config.GroundWalkable)
player.teleport(team.getSpawn());
}else if(to.getY() + 1.8 > Config.ArenaRegion.getMaxY()){
reset(event);
}
}
private void reset(PlayerMoveEvent event){
Player player = event.getPlayer();
player.teleport(event.getFrom());
BasicListener.toActionbar(player, TextComponent.fromLegacyText("§cDu darfst die Arena nicht verlassen"));
}
}

Datei anzeigen

@ -19,22 +19,16 @@
package de.steamwar.fightsystem.listener;
import de.steamwar.core.Core;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.utils.WaterRemover;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityExplodeEvent;
import de.steamwar.fightsystem.states.StateDependentListener;
import java.util.EnumSet;
public class ArrowPickup {
public class EntityExplodeListener extends BasicListener {
public EntityExplodeListener() {
super(EnumSet.of(FightState.RUNNING));
public ArrowPickup() {
if(Core.getVersion() > 8){
new StateDependentListener(ArenaMode.All, FightState.All, new PickupArrowListener_9());
}
@EventHandler
public void handleEntityExplode(EntityExplodeEvent event) {
event.setYield(0); //No drops (additionally to world config)
WaterRemover.add(event.blockList());
}
}

Datei anzeigen

@ -20,27 +20,27 @@
package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.states.StateDependentTask;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
import java.util.EnumSet;
public class ArrowStopper implements Listener {
public class ArrowStopper extends BasicListener {
private BukkitTask task;
private static final Vector NULL_VECTOR = new Vector(0, 0, 0);
private static final BlockFace[] BLOCK_FACES = {BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH};
public ArrowStopper() {
super(Config.TechhiderActive ? EnumSet.of(FightState.RUNNING) : EnumSet.noneOf(FightState.class));
new StateDependentListener(Config.TechhiderActive, FightState.Running, this);
new StateDependentTask(Config.TechhiderActive, FightState.Running, this::run, 1, 1);
}
private void run() {
@ -62,18 +62,6 @@ public class ArrowStopper extends BasicListener {
}
}
@Override
public void enable() {
super.enable();
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::run, 1, 1);
}
@Override
public void disable() {
super.disable();
task.cancel();
}
private boolean checkBlocks(Block start, Block end) {
Block cursor = start;
@ -97,7 +85,7 @@ public class ArrowStopper extends BasicListener {
}
private boolean checkBlock(Block block) {
return Config.HiddenBlockTags.contains(block.getType().name());
return Config.HiddenBlocks.contains(block.getType().name());
}
private boolean invalidEntity(Arrow entity) {

Datei anzeigen

@ -20,28 +20,14 @@
package de.steamwar.fightsystem.listener;
import de.steamwar.core.VersionedRunnable;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent;
import net.md_5.bungee.api.chat.BaseComponent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import java.util.Set;
public class BasicListener {
private BasicListener(){}
public abstract class BasicListener implements Listener, StateDependent {
private final Set<FightState> enabled;
BasicListener(Set<FightState> enabled){
this.enabled = enabled;
FightSystem.registerStateDependent(this);
}
boolean notFighting(Player p){
public static boolean notFighting(Player p){
return Fight.getFightPlayer(p) == null;
}
@ -55,22 +41,7 @@ public abstract class BasicListener implements Listener, StateDependent {
new VersionedRunnable(() -> BasicListener_9.toChat(player, components), 9));
}
void setAttackSpeed(Player player){
public static void setAttackSpeed(Player player){
VersionedRunnable.call(new VersionedRunnable(() -> BasicListener_9.setAttackSpeed(player), 9));
}
@Override
public void enable(){
Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin());
}
@Override
public void disable(){
HandlerList.unregisterAll(this);
}
@Override
public Set<FightState> enabled() {
return enabled;
}
}

Datei anzeigen

@ -19,25 +19,26 @@
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.fight.FightTeam;
import de.steamwar.fightsystem.record.RecordSystem;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import java.util.EnumSet;
public class Chat implements Listener {
public class PlayerChatListener extends BasicListener {
public PlayerChatListener(){
super(EnumSet.allOf(FightState.class));
public Chat(){
new StateDependentListener(ArenaMode.All, FightState.All, this);
}
@EventHandler
@ -63,10 +64,9 @@ public class PlayerChatListener extends BasicListener {
}
private void broadcastChat(String message) {
if (Config.recording())
RecordSystem.chat(message);
BaseComponent[] msg = TextComponent.fromLegacyText(message);
for(Player p : Bukkit.getOnlinePlayers())
toChat(p, msg);
BasicListener.toChat(p, msg);
}
}

Datei anzeigen

@ -19,24 +19,26 @@
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 de.steamwar.sql.Schematic;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.UserGroup;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import java.util.EnumSet;
import java.util.logging.Level;
public class CheckListener extends BasicListener {
public class Check implements Listener {
public CheckListener() {
super(Config.check() ? EnumSet.allOf(FightState.class) : EnumSet.noneOf(FightState.class));
public Check() {
new StateDependentListener(ArenaMode.Check, FightState.All, this);
}
@EventHandler
@ -66,7 +68,7 @@ public class CheckListener extends BasicListener {
Bukkit.getLogger().log(Level.SEVERE, player.getName() + " tried to use a copy command!");
}
private static boolean allowedToCheck(SteamwarUser user) {
private boolean allowedToCheck(SteamwarUser user) {
return user.getUserGroup() == UserGroup.Supporter ||
user.getUserGroup() == UserGroup.Developer ||
user.getUserGroup() == UserGroup.Moderator ||

Datei anzeigen

@ -19,40 +19,40 @@
package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import net.md_5.bungee.api.chat.TextComponent;
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.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerKickEvent;
import java.util.EnumSet;
public class DenyWorldInteraction implements Listener {
public class FreezeWorldStateListener extends BasicListener {
public FreezeWorldStateListener() {
super(Config.test() ? EnumSet.of(FightState.PRE_RUNNING) : EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP, FightState.PRE_RUNNING, FightState.SPECTATE));
public DenyWorldInteraction() {
new StateDependentListener(ArenaMode.Test, FightState.PreRunning, this);
new StateDependentListener(ArenaMode.AntiTest, FightState.AntiRunning, this);
}
@EventHandler
public void handleBlockBreak(BlockBreakEvent event) {
Player player = event.getPlayer();
event.setCancelled(true);
toActionbar(player, TextComponent.fromLegacyText("§cDu darfst derzeit keine Blöcke abbauen!"));
BasicListener.toActionbar(player, TextComponent.fromLegacyText("§cDu darfst derzeit keine Blöcke abbauen!"));
}
@EventHandler
public void handleBlockPlace(BlockPlaceEvent event) {
Player player = event.getPlayer();
event.setCancelled(true);
toActionbar(player, TextComponent.fromLegacyText("§cDu darfst derzeit keine Blöcke setzen!"));
BasicListener.toActionbar(player, TextComponent.fromLegacyText("§cDu darfst derzeit keine Blöcke setzen!"));
}
@EventHandler
@ -60,18 +60,18 @@ public class FreezeWorldStateListener extends BasicListener {
event.setCancelled(true);
}
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
if(PersonalKitCreator.notInKitCreator(event.getWhoClicked()))
event.setCancelled(true);
}
@EventHandler
public void handlePlayerKickEvent(PlayerKickEvent e){
if(e.getReason().contains("Flying is not enabled"))
e.setCancelled(true);
}
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
if(PersonalKitCreator.notInKitCreator(event.getWhoClicked()))
event.setCancelled(true);
}
@EventHandler
public void onInventoryDrag(InventoryDragEvent event) {
if(PersonalKitCreator.notInKitCreator(event.getWhoClicked()))
@ -79,12 +79,11 @@ public class FreezeWorldStateListener extends BasicListener {
}
@EventHandler
public void onDropPickup(InventoryPickupItemEvent e){
e.setCancelled(true);
public void handleProjectileLaunch(ProjectileLaunchEvent event) {
event.setCancelled(true);
if(event.getEntity().getShooter() instanceof Player){
Player player = (Player) event.getEntity().getShooter();
BasicListener.toActionbar(player, TextComponent.fromLegacyText("§cDu darfst den Bogen erst nach Kampfbeginn nutzen!"));
}
@EventHandler
public void onDropping(PlayerDropItemEvent e){
e.setCancelled(true);
}
}

Datei anzeigen

@ -19,17 +19,18 @@
package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
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.EnumSet;
public class EntityDamage implements Listener {
public class EntityDamageListener extends BasicListener {
public EntityDamageListener() {
super(EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP, FightState.PRE_RUNNING, FightState.SPECTATE));
public EntityDamage() {
new StateDependentListener(ArenaMode.All, FightState.AntiRunning, this);
}
@EventHandler

Datei anzeigen

@ -19,25 +19,25 @@
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.fight.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.sql.SteamwarUser;
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.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.EnumSet;
public class EventJoin implements Listener {
public class EventJoinListener extends BasicListener {
public EventJoinListener() {
super(Config.event() ? EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP) : EnumSet.noneOf(FightState.class));
public EventJoin() {
new StateDependentListener(ArenaMode.Event, FightState.All, this);
}
@EventHandler
@ -60,6 +60,7 @@ public class EventJoinListener extends BasicListener {
Player player = event.getPlayer();
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
if(FightState.Setup.contains(FightState.getFightState())){
FightTeam team = null;
if(user.getTeam() == Config.EventTeamBlueID)
team = Fight.getBlueTeam();
@ -79,11 +80,10 @@ public class EventJoinListener extends BasicListener {
}
if(team != null && team.getPlayers().size() < Config.MaximumTeamMembers){
FightPlayer fp = team.addMember(player);
if(!team.hasTeamLeader())
team.setLeader(fp);
team.addMember(player);
return;
}
}
if(user.getId() == FightSystem.getEventFight().getKampfleiter()){
FightSystem.setEventLeiter(player);

Datei anzeigen

@ -0,0 +1,142 @@
/*
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.core.TPSWatcher;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.countdown.Countdown;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.record.RecordSystem;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.states.StateDependentTask;
import de.steamwar.fightsystem.winconditions.PrintableWincondition;
import de.steamwar.fightsystem.winconditions.Wincondition;
import de.steamwar.scoreboard.SWScoreboard;
import de.steamwar.scoreboard.ScoreboardCallback;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scoreboard.Scoreboard;
import java.util.*;
public class FightScoreboard implements Listener {
private static final Set<FightState> fullScoreboard = EnumSet.of(FightState.RUNNING, FightState.SPECTATE);
private int index = 0;
private String title = "";
private final HashMap<String, Integer> scores = new HashMap<>();
public static Scoreboard getScoreboard() {
return Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard();
}
public FightScoreboard(){
new StateDependentListener(ArenaMode.All, FightState.All, this);
new StateDependentTask(ArenaMode.All, FightState.All, this::nextIndexDisplay, 0, 200);
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
SWScoreboard.createScoreboard(event.getPlayer(), new ScoreboardCallback() {
@Override
public HashMap<String, Integer> getData() {
return scores;
}
@Override
public String getTitle() {
return title;
}
});
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
SWScoreboard.removeScoreboard(event.getPlayer());
}
private void teamScoreboard(FightTeam fightTeam){
setTitle(fightTeam.getColoredName());
fightTeam.getPlayers().forEach(fp -> {
if(fp.isLiving())
addScore(fightTeam.getPrefix() + fp.getPlayer().getName(), (int) Math.ceil(fp.getPlayer().getHealth()));
});
}
private void generalScoreboard(){
setTitle("§eKampf");
List<String> scoreList = new ArrayList<>();
Countdown timeOverCountdown = Wincondition.getTimeOverCountdown();
if(timeOverCountdown != null){
int fightTime = timeOverCountdown.getTimeLeft();
if (fightTime >= 60)
scoreList.add("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s");
else
scoreList.add("§7Zeit: §a" + fightTime + "s");
}
scoreList.add("§7TPS: §e" + TPSWatcher.getTPS());
if(fullScoreboard.contains(FightState.getFightState())){
for(PrintableWincondition wincondition : Wincondition.getPrintableWinconditions()){
scoreList.add(wincondition.getDisplay(Fight.getRedTeam()));
scoreList.add(wincondition.getDisplay(Fight.getBlueTeam()));
}
}
int value = scoreList.size();
for(String score : scoreList){
addScore(score, value--);
}
}
private void nextIndexDisplay() {
index++;
if(index > 2)
index = 0;
FightTeam team = null;
if(index == 1)
team = Fight.getRedTeam();
if(index == 2)
team = Fight.getBlueTeam();
scores.clear();
if(team != null)
teamScoreboard(team);
else
generalScoreboard();
}
private void setTitle(String t) {
title = t;
RecordSystem.scoreboardTitle(t);
}
private void addScore(String string, int i) {
scores.put(string, i);
RecordSystem.scoreboardData(string, i);
}
}

Datei anzeigen

@ -19,22 +19,23 @@
package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.commands.GUI;
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.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.EnumSet;
public class HotbarGUI implements Listener {
public class HotbarGUIListener extends BasicListener {
public HotbarGUIListener() {
super(EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP));
public HotbarGUI() {
new StateDependentListener(ArenaMode.All, FightState.Setup, this);
}
@EventHandler
@ -78,7 +79,7 @@ public class HotbarGUIListener extends BasicListener {
break;
case "§eKit bearbeiten":
case "§eKit wählen":
GUI.kitSelection(player);
GUI.kitSelection(player, "");
break;
case "§eRespawn":
player.teleport(fightTeam.getSpawn());

Datei anzeigen

@ -19,22 +19,24 @@
package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.entity.Arrow;
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.EnumSet;
import java.util.Objects;
public class InFightDamageListener extends BasicListener {
public class InFightDamage implements Listener {
public InFightDamageListener() {
super(EnumSet.of(FightState.RUNNING));
public InFightDamage() {
new StateDependentListener(ArenaMode.All, FightState.Running, this);
}
@EventHandler
@ -42,7 +44,7 @@ public class InFightDamageListener extends BasicListener {
if(!(event.getEntity() instanceof Player))
return;
if(notFighting((Player)event.getEntity()))
if(BasicListener.notFighting((Player)event.getEntity()))
event.setCancelled(true);
}
@ -69,7 +71,7 @@ public class InFightDamageListener extends BasicListener {
return;
}
if(notFighting(damager)){
if(BasicListener.notFighting(damager)){
event.setCancelled(true);
//Damager is not fighting
return;
@ -81,7 +83,7 @@ public class InFightDamageListener extends BasicListener {
event.getDamager().setFireTicks(0);
player.setFireTicks(0);
}
toActionbar(damager, TextComponent.fromLegacyText("§cDu darfst deinen Teamkollegen keinen Schaden zufügen!"));
BasicListener.toActionbar(damager, TextComponent.fromLegacyText("§cDu darfst deinen Teamkollegen keinen Schaden zufügen!"));
}
if(player.getHealth() - event.getFinalDamage() <= 0){

Datei anzeigen

@ -19,28 +19,27 @@
package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode;
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 net.md_5.bungee.api.chat.TextComponent;
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.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.EnumSet;
public class InFightInventory implements Listener {
public class InFightInventoryListener extends BasicListener {
public InFightInventoryListener() {
super(EnumSet.of(FightState.RUNNING));
public InFightInventory() {
new StateDependentListener(ArenaMode.All, FightState.Running, this);
}
@EventHandler
@ -77,16 +76,6 @@ public class InFightInventoryListener extends BasicListener {
}
}
@EventHandler
public void onDropPickup(InventoryPickupItemEvent e){
e.setCancelled(true);
}
@EventHandler
public void onDropping(PlayerDropItemEvent e){
e.setCancelled(true);
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
Inventory inventory = event.getPlayer().getInventory();

Datei anzeigen

@ -0,0 +1,77 @@
/*
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.ArenaMode;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.Countdown;
import de.steamwar.fightsystem.countdown.SWSound;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.record.RecordSystem;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
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.player.PlayerQuitEvent;
public class IngameDeath implements Listener {
public IngameDeath() {
new StateDependentListener(ArenaMode.All, FightState.Ingame, this);
}
@EventHandler(priority = EventPriority.HIGH)
public void handlePlayerDeath(PlayerDeathEvent event) {
event.setDeathMessage(null);
Player player = event.getEntity();
FightTeam team = Fight.getPlayerTeam(player);
if(team == null)
return;
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler " + team.getPrefix() + player.getName() + " §cist gestorben!");
Fight.playSound(Countdown.getSound(SWSound.ENTITY_WITHER_DEATH), 100.0F, 1.0F);
team.getFightPlayer(player).setOut();
}
@EventHandler(priority = EventPriority.HIGH)
public void handlePlayerQuit(PlayerQuitEvent event) {
event.setQuitMessage(null);
Player player = event.getPlayer();
FightTeam team = Fight.getPlayerTeam(player);
if(team == null)
return;
FightPlayer fightPlayer = team.getFightPlayer(player);
if(fightPlayer.isLiving()) {
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler " + team.getPrefix() + player.getName() + " §chat den Kampf verlassen!");
team.getFightPlayer(player).setOut();
RecordSystem.entityDespawns(player);
}
}
}

Datei anzeigen

@ -19,20 +19,21 @@
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.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import java.util.EnumSet;
public class NormalJoin implements Listener {
public class RankedJoinListener extends BasicListener {
public RankedJoinListener() {
super(!Config.event() && Config.Ranked ? EnumSet.of(FightState.PRE_SCHEM_SETUP) : EnumSet.noneOf(FightState.class));
public NormalJoin() {
new StateDependentListener(ArenaMode.Normal, FightState.PreLeaderSetup, this);
}
@EventHandler
@ -42,9 +43,9 @@ public class RankedJoinListener extends BasicListener {
if (fightTeam == null) {
if(!player.getUniqueId().equals(Config.RedLeader) && Fight.getBlueTeam().canbeLeader(player)) {
Fight.getBlueTeam().setLeader(Fight.getBlueTeam().addMember(player));
Fight.getBlueTeam().addMember(player);
}else if(Fight.getRedTeam().canbeLeader(player)) {
Fight.getRedTeam().setLeader(Fight.getRedTeam().addMember(player));
Fight.getRedTeam().addMember(player);
}
}
}

Datei anzeigen

@ -0,0 +1,130 @@
/*
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.comms.packets.TablistNamePacket;
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.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.sql.SteamwarUser;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
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.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.SpawnerSpawnEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.FurnaceSmeltEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.player.*;
import org.bukkit.event.weather.WeatherChangeEvent;
import org.bukkit.event.world.WorldLoadEvent;
public class Permanent implements Listener {
public Permanent() {
new StateDependentListener(ArenaMode.All, FightState.All, this);
}
@EventHandler
public void handlePlayerRespawn(PlayerRespawnEvent event){
Player player = event.getPlayer();
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
FightTeam team = Fight.getPlayerTeam(player);
event.setRespawnLocation(team == null ? Config.SpecSpawn : team.getSpawn());
}
@EventHandler
public void onTpGM3(PlayerTeleportEvent e) {
if (e.getCause() == PlayerTeleportEvent.TeleportCause.SPECTATE) {
e.setCancelled(true);
BasicListener.toActionbar(e.getPlayer(), TextComponent.fromLegacyText("§cDu darfst diese Teleportfunktion nicht benutzen!"));
e.getPlayer().kickPlayer("§cDu darfst diese Teleportfunktion nicht benutzen!");
}
}
@EventHandler(priority = EventPriority.HIGH)
public void handlePlayerJoin(PlayerJoinEvent event) {
event.setJoinMessage(null);
Player player = event.getPlayer();
FightTeam fightTeam = Fight.getPlayerTeam(player);
if (fightTeam == null) {
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
player.teleport(Config.SpecSpawn);
if(!ArenaMode.Test.contains(Config.mode))
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7" + player.getName()).send(player), 5);
}
}
@EventHandler
public void handleFoodLevelChange(FoodLevelChangeEvent event) {
event.setCancelled(true);
}
@EventHandler
public void onWeatherChange(WeatherChangeEvent event){
event.setCancelled(true);
}
@EventHandler
public void onSpawnerSpawn(SpawnerSpawnEvent e){
e.setCancelled(true);
}
@EventHandler
public void onSleep(PlayerBedEnterEvent e) {
e.setCancelled(true);
}
@EventHandler
public void onCrafting(CraftItemEvent e){
e.setCancelled(true);
}
@EventHandler
public void onFurnace(FurnaceSmeltEvent e){
e.setCancelled(true);
}
@EventHandler
public void onDropPickup(InventoryPickupItemEvent e){
e.setCancelled(true);
}
@EventHandler
public void onDropping(PlayerDropItemEvent e){
e.setCancelled(true);
}
@EventHandler
public void onWorldLoad(WorldLoadEvent e) {
e.getWorld().setAutoSave(false);
}
}

Datei anzeigen

@ -19,143 +19,58 @@
package de.steamwar.fightsystem.listener;
import de.steamwar.core.Core;
import de.steamwar.core.VersionedCallable;
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.kit.Kit;
import de.steamwar.fightsystem.kit.KitManager;
import de.steamwar.fightsystem.fight.Kit;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.sql.PersonalKit;
import de.steamwar.sql.SteamwarUser;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.BlockDataMeta;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.*;
import java.util.logging.Level;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
public class PersonalKitCreator extends BasicListener {
public class PersonalKitCreator implements Listener {
private static final Map<HumanEntity, InventoryBackup> openKitCreators = new HashMap<>();
private static final EnumSet<FightState> enabled = Config.PersonalKits ? EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP) : EnumSet.noneOf(FightState.class);
public PersonalKitCreator(){
super(enabled);
}
public static void openKitSelector(Player player, String qry) {
List<PersonalKit> kits = PersonalKit.get(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB());
kits.removeIf(kit -> !kit.getName().toLowerCase().contains(qry.toLowerCase()));
List<SWListInv.SWListEntry<PersonalKit>> entries = new ArrayList<>(kits.size());
kits.forEach(kit -> entries.add(new SWListInv.SWListEntry<>(new SWItem(Material.LEATHER_CHESTPLATE, "§e" + kit.getName(), new ArrayList<>(), kit.isInUse(), clickType -> {}), kit)));
SWListInv<PersonalKit> inv = new SWListInv<>(player, "§eKit wählen", false, entries, (clickType, kit) -> preview(player, kit));
if(entries.isEmpty())
inv.setItem(22, new SWItem(Material.BARRIER, "§cKeine Kits gefunden"));
inv.setItem(48, Material.NETHER_STAR, "§eNeues Kit", clickType -> {
SWAnvilInv anvilInv = new SWAnvilInv(player, "Kitname eingeben");
anvilInv.setItem(Material.LEATHER_CHESTPLATE);
anvilInv.setCallback(s -> {
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
if(PersonalKit.nameInUse(user.getId(), Config.SchematicType.toDB(), s)) {
player.sendMessage(FightSystem.PREFIX + "§cDieser Kitname wird bereits genutzt!");
player.closeInventory();
return;
}
Kit prototype = KitManager.getKits(Fight.getFightPlayer(player).isLeader()).get(0);
PersonalKit kit = PersonalKit.create(user.getId(), Config.SchematicType.toDB(), s, prototype.getInventory(), prototype.getArmor());
openKitCreator(player, kit);
});
anvilInv.open();
});
inv.setItem(50, Material.NAME_TAG, "§eSuchen", clickType -> {
SWAnvilInv anvilInv = new SWAnvilInv(player, "§eNach Kit suchen");
anvilInv.setItem(Material.PAPER);
anvilInv.setCallback(s -> openKitSelector(player, s));
anvilInv.open();
});
inv.open();
}
public static void preview(Player player, PersonalKit kit){
SWInventory inv = new SWInventory(player, 54, kit.getName());
Kit.preview(inv, kit.getInventory(), kit.getArmor(), null);
inv.setItem(45, Material.LEATHER_CHESTPLATE, "§aKit benutzen", clickType -> useKit(player, kit));
inv.setItem(49, SWItem.getMaterial("WOOD_AXE"), "§7Kit bearbeiten", clickType -> openKitCreator(player, kit));
inv.setItem(53, Material.BARRIER, "§cKit löschen", clickType -> {
player.closeInventory();
SWInventory conf = new SWInventory(player, 9, "Kit wirklich löchen?");
conf.setItem(8, SWItem.getDye(1), "§cAbbrechen", click -> player.closeInventory());
conf.setItem(0, SWItem.getDye(10), "§aLöschen", click -> {
player.closeInventory();
if(kit.isInUse()) {
useKit(player, PersonalKit.get(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB()).get(0));
}
kit.delete();
});
conf.open();
});
inv.open();
}
private static void useKit(Player player, PersonalKit kit) {
kit.setInUse();
player.closeInventory();
new StateDependentListener(Config.PersonalKits, FightState.Setup, this);
}
public static void openKitCreator(Player player, PersonalKit kit){
if(!enabled.contains(FightSystem.getFightState()))
return;
player.closeInventory();
new InventoryBackup(player, kit);
FightPlayer fightPlayer = Fight.getFightPlayer(player);
assert fightPlayer != null;
if(kit == null){
fightPlayer.getKit().loadToPlayer(player);
}else{
player.getInventory().setContents(kit.getInventory());
player.getInventory().setArmorContents(kit.getArmor());
}
player.updateInventory();
new Kit(kit).loadToPlayer(player);
player.setGameMode(GameMode.CREATIVE);
toActionbar(player, TextComponent.fromLegacyText("§eInventar zum Anpassen des Kits öffnen§8!"));
BasicListener.toActionbar(player, TextComponent.fromLegacyText("§eInventar zum Anpassen des Kits öffnen§8!"));
}
public static boolean notInKitCreator(HumanEntity player){
return !openKitCreators.containsKey(player);
}
@Override
public void disable(){
while(!openKitCreators.isEmpty()){
openKitCreators.values().iterator().next().close();
}
super.disable();
public static void closeIfInKitCreator(HumanEntity player){
InventoryBackup backup = openKitCreators.get(player);
if(backup == null)
return;
backup.close();
}
@EventHandler
@ -165,10 +80,23 @@ public class PersonalKitCreator extends BasicListener {
Player player = (Player) e.getWhoClicked();
//Deny bad items
if(isBadItem(e.getCursor(), player))
if(Kit.isBadItem(e.getCursor()))
e.setCancelled(true);
checkForClear(e, player);
/* Should the inventory reset? */
if(e.getAction() != InventoryAction.PLACE_ALL)
return;
ItemStack[] items = e.getWhoClicked().getInventory().getContents();
for(int i = 0; i < items.length; i++){
ItemStack stack = items[i];
if(stack != null && i != e.getSlot())
return;
}
FightPlayer fightPlayer = Fight.getFightPlayer(player);
assert fightPlayer != null;
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> fightPlayer.getKit().loadToPlayer(player), 1);
}
@EventHandler
@ -198,97 +126,28 @@ public class PersonalKitCreator extends BasicListener {
backup.close();
}
private void checkForClear(InventoryClickEvent e, Player player){
if(e.getAction() != InventoryAction.PLACE_ALL)
return;
ItemStack[] items = e.getWhoClicked().getInventory().getContents();
for(int i = 0; i < items.length; i++){
ItemStack stack = items[i];
if(stack != null && i != e.getSlot())
return;
}
FightPlayer fightPlayer = Fight.getFightPlayer(player);
assert fightPlayer != null;
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> fightPlayer.getKit().loadToPlayer(player), 1);
}
private static boolean isBadItem(ItemStack stack, Player player){
if(stack == null)
return false;
//Check for forbidden item
if(Config.ForbiddenItems.contains(stack.getType().name()))
return true;
//Check for attribute modifiers
if(Core.getVersion() >= 14 && PersonalKitCreator_14.hasAttributeModifier(stack)){
Bukkit.getLogger().log(Level.SEVERE, "Spieler " + player.getName() + " hat versucht ein Item mit einem Attribute-Modifier zu bekommen.");
return true;
}
if(stack.hasItemMeta()){
ItemMeta meta = stack.getItemMeta();
if(meta instanceof BlockDataMeta && ((BlockDataMeta)meta).hasBlockData())
return true; //Blocks always upwards slabs etc.
if(hasItems(stack))
return true; //Blocks prefilled inventories
}
Kit normal = KitManager.getKitByName(Config.MemberDefault);
assert normal != null;
return !normal.isEnchantmentInKit(stack) && !stack.getEnchantments().isEmpty();
}
private static boolean hasItems(ItemStack stack){
return VersionedCallable.call(new VersionedCallable<>(() -> PersonalKitCreator_8.hasItems(stack), 8),
new VersionedCallable<>(() -> PersonalKitCreator_9.hasItems(stack), 9),
new VersionedCallable<>(() -> PersonalKitCreator_10.hasItems(stack), 10),
new VersionedCallable<>(() -> PersonalKitCreator_12.hasItems(stack), 12),
new VersionedCallable<>(() -> PersonalKitCreator_14.hasItems(stack), 14),
new VersionedCallable<>(() -> PersonalKitCreator_15.hasItems(stack), 15));
}
private static class InventoryBackup{
private final Player player;
private final ItemStack[] contents;
private final ItemStack[] armor;
private final PersonalKit kit;
private final Kit backup;
private InventoryBackup(Player player, PersonalKit kit){
openKitCreators.put(player, this);
this.player = player;
this.contents = player.getInventory().getContents();
this.armor = player.getInventory().getArmorContents();
this.backup = new Kit("backup", player);
this.kit = kit;
}
private void loadBackup(){
PlayerInventory inventory = player.getInventory();
inventory.setContents(contents);
inventory.setArmorContents(armor);
player.updateInventory();
}
private void close(){
openKitCreators.remove(player);
kit.setContainer(removeBadItems(player.getInventory().getContents()), removeBadItems(player.getInventory().getArmorContents()));
loadBackup();
Kit kit1 = new Kit(kit.getName(), player);
kit1.removeBadItems();
kit1.toPersonalKit(kit);
backup.loadToPlayer(player);
player.setGameMode(GameMode.SURVIVAL);
useKit(player, kit);
}
private ItemStack[] removeBadItems(ItemStack[] inventory){
Kit normal = KitManager.getKitByName(Config.MemberDefault);
assert normal != null;
for(int i = 0; i < inventory.length; i++){
if(isBadItem(inventory[i], player))
inventory[i] = null;
}
return inventory;
kit.setInUse();
player.closeInventory();
Objects.requireNonNull(Fight.getFightPlayer(player)).setKit(new Kit(kit));
}
}
}

Datei anzeigen

@ -21,33 +21,27 @@ package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.utils.Region;
import de.steamwar.fightsystem.states.StateDependentListener;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import java.util.EnumSet;
public class PistonListener extends BasicListener {
public class PistonListener implements Listener {
public PistonListener() {
//Wenn Entern aktiv ist, sollen Raketen etc. entern können
super(Config.EnterStages.isEmpty()
? EnumSet.allOf(FightState.class)
: EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP));
new StateDependentListener(Config.EnterStages.isEmpty(), FightState.All, this);
new StateDependentListener(!Config.EnterStages.isEmpty(), FightState.Setup, this);
}
@EventHandler
public void handlePistonExtend(BlockPistonExtendEvent e){
BlockFace b = e.getDirection();
BlockFace b = e.getDirection().getOppositeFace();
for(Block block : e.getBlocks()){
if(
block.getY() > Config.upperArenaBorder ||
(!Region.isIn2DRange(block.getLocation(), Config.TeamBlueCornerX + b.getModX(), Config.TeamBlueCornerZ + b.getModZ(), Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic) &&
!Region.isIn2DRange(block.getLocation(), Config.TeamRedCornerX + b.getModX(), Config.TeamRedCornerZ + b.getModZ(), Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic))
){
if(Config.BlueExtendRegion.inRegion(block.getRelative(b)) && Config.RedExtendRegion.inRegion(block.getRelative(b))){
e.setCancelled(true);
return;
}
@ -56,13 +50,9 @@ public class PistonListener extends BasicListener {
@EventHandler
public void handlePistonRetract(BlockPistonRetractEvent e){
BlockFace b = e.getDirection();
BlockFace b = e.getDirection().getOppositeFace();
for(Block block : e.getBlocks()){
if(
block.getY() > Config.upperArenaBorder ||
(!Region.isIn2DRange(block.getLocation(), Config.TeamBlueCornerX + b.getModX(), Config.TeamBlueCornerZ + b.getModZ(), Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic) &&
!Region.isIn2DRange(block.getLocation(), Config.TeamRedCornerX + b.getModX(), Config.TeamRedCornerZ + b.getModZ(), Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic))
){
if(Config.BlueExtendRegion.inRegion(block.getRelative(b)) && Config.RedExtendRegion.inRegion(block.getRelative(b))) {
e.setCancelled(true);
return;
}

Datei anzeigen

@ -1,125 +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.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.utils.Region;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerMoveEvent;
import java.util.EnumSet;
import java.util.logging.Level;
public class PlayerMoveListener extends BasicListener {
private static final String DENY_ARENA = "§cDu darfst die Arena nicht verlassen";
private static final String DENY_TEAM = "§cDu darfst nicht zu den Teams";
private static final String DENY_ENTERN = "§cDu darfst nicht entern";
public PlayerMoveListener() {
super(EnumSet.allOf(FightState.class));
}
@EventHandler
public void teamAreas(PlayerMoveEvent event) {
Player player = event.getPlayer();
if(player == FightSystem.getEventLeiter() || Config.test())
return;
Location to = event.getTo();
FightTeam fightTeam = Fight.getPlayerTeam(player);
assert to != null;
boolean inArenaY = to.getY() + 1.8 <= Config.upperArenaBorder;
boolean inBlueArea = inArenaY && Region.isIn2DRange(to, Config.TeamBlueCornerX, Config.TeamBlueCornerZ, Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic);
boolean inRedArea = inArenaY && Region.isIn2DRange(to, Config.TeamRedCornerX, Config.TeamRedCornerZ, Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic);
if(inBlueArea){
if(fightTeam == null)
reset(event, DENY_TEAM);
else if(fightTeam == Fight.getRedTeam() && (player.getGameMode() == GameMode.SPECTATOR || !fightTeam.canPlayerEntern(player)))
reset(event, DENY_ENTERN);
else
return; // Is allowed in area
checkInInnerArea(event.getPlayer(), to, Config.TeamBlueCornerX, Config.TeamBlueCornerZ);
}else if(inRedArea){
if(fightTeam == null)
reset(event, DENY_TEAM);
else if(fightTeam == Fight.getBlueTeam() && (player.getGameMode() == GameMode.SPECTATOR || !fightTeam.canPlayerEntern(player)))
reset(event, DENY_ENTERN);
else
return; // Is allowed in area
checkInInnerArea(event.getPlayer(), to, Config.TeamRedCornerX, Config.TeamRedCornerZ);
}else if(fightTeam != null && player.getGameMode() != GameMode.SPECTATOR && !fightTeam.canPlayerEntern(player))
reset(event, DENY_ENTERN);
}
private void checkInInnerArea(Player player, Location to, int teamCornerX, int teamCornerZ){
boolean inArenaY = to.getY() + 1.8 <= Config.TeamBlueCornerY + Config.SchemsizeY;
boolean inArea = inArenaY && Region.isIn2DRange(to, teamCornerX, teamCornerZ, Config.SchemsizeX, Config.SchemsizeZ, 0);
if(inArea && Config.BorderFromSchematic >= 5){ // Preventing false positives due to small extension
player.kickPlayer(null);
Bukkit.getLogger().log(Level.SEVERE, player.getName() + " ist in einen Teambereich eingedrungen.");
}
}
@EventHandler
public void arenaBorder(PlayerMoveEvent event){
Player player = event.getPlayer();
Location to = event.getTo();
//Check in Arena
assert to != null;
if(!Region.isIn2DRegion(to, Config.ArenaMinX, Config.ArenaMinZ, Config.ArenaMaxX, Config.ArenaMaxZ)){
reset(event, DENY_ARENA);
return;
}
FightTeam team = Fight.getPlayerTeam(player);
boolean inArenaY = to.getY() + 1.8 <= Config.upperArenaBorder;
if(to.getY() <= Config.underArenaBorder) {
if(player.getGameMode() == GameMode.SPECTATOR || team == null)
reset(event, DENY_ARENA);
else if(FightSystem.getFightState().infight())
player.damage(2);
else if(!Config.GroundWalkable)
player.teleport(team.getSpawn());
}else if(team != null && !inArenaY){
reset(event, DENY_ARENA);
}
}
private void reset(PlayerMoveEvent event, String message){
Player player = event.getPlayer();
player.teleport(event.getFrom());
toActionbar(player, TextComponent.fromLegacyText(message));
}
}

Datei anzeigen

@ -1,146 +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.comms.packets.TablistNamePacket;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.Countdown;
import de.steamwar.fightsystem.countdown.SWSound;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.record.RecordSystem;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.sql.SteamwarUser;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import java.util.EnumSet;
public class PlayerStateListener extends BasicListener{
public PlayerStateListener() {
super(EnumSet.allOf(FightState.class));
}
@EventHandler(priority = EventPriority.HIGH)
public void handlePlayerJoin(PlayerJoinEvent event) {
event.setJoinMessage(null);
Player player = event.getPlayer();
player.setHealth(20);
player.setFoodLevel(20);
setAttackSpeed(player);
FightTeam fightTeam = Fight.getPlayerTeam(player);
if (fightTeam == null) {
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
player.teleport(Config.SpecSpawn);
if(!Config.test())
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7" + player.getName()).send(player), 5);
} else {
player.teleport(fightTeam.getSpawn());
if(FightSystem.getFightState().setup())
Fight.setPlayerGamemode(player, GameMode.SURVIVAL);
else
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void handlePlayerDeath(PlayerDeathEvent event) {
Player player = event.getEntity().getPlayer();
FightTeam fightTeam = Fight.getPlayerTeam(player);
if(fightTeam == null)
return;
assert player != null;
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler " + fightTeam.getPrefix() + player.getName() + " §cist gestorben!");
event.setDeathMessage(null);
fightTeam.getFightPlayer(player).setOut();
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
player.teleport(fightTeam.getSpawn());
Fight.playSound(Countdown.getSound(SWSound.ENTITY_WITHER_DEATH), 100.0F, 1.0F);
if(Config.recording())
RecordSystem.entityDespawns(player);
}
@EventHandler(priority = EventPriority.HIGH)
public void handlePlayerQuit(PlayerQuitEvent event) {
event.setQuitMessage(null);
Player player = event.getPlayer();
FightTeam fightTeam = Fight.getPlayerTeam(player);
if(fightTeam == null)
return;
FightState fightState = FightSystem.getFightState();
if(fightState.setup()){
fightTeam.removePlayer(player);
if(Config.recording())
RecordSystem.entityDespawns(player);
}else if(fightState.ingame()){
FightPlayer fightPlayer = fightTeam.getFightPlayer(player);
if(fightPlayer.isLiving()) {
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler " + fightTeam.getPrefix() + player.getName() + " §chat den Kampf verlassen!");
fightTeam.getFightPlayer(player).setOut();
if(Config.recording())
RecordSystem.entityDespawns(player);
}
}
//Shutdown server if nobody online and its not an event server
if(!Config.event() && (Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(player))))
FightSystem.shutdown(null);
}
@EventHandler
public void handlePlayerRespawn(PlayerRespawnEvent event) {
Player player = event.getPlayer();
FightTeam team = Fight.getPlayerTeam(player);
if(team == null)
event.setRespawnLocation(Config.SpecSpawn);
else
event.setRespawnLocation(team.getSpawn());
}
@EventHandler
public void onTpGM3(PlayerTeleportEvent e) {
if (e.getCause() == PlayerTeleportEvent.TeleportCause.SPECTATE) {
e.setCancelled(true);
toActionbar(e.getPlayer(), TextComponent.fromLegacyText("§cDu darfst diese Teleportfunktion nicht benutzen!"));
e.getPlayer().kickPlayer("§cDu darfst diese Teleportfunktion nicht benutzen!");
}
}
}

Datei anzeigen

@ -0,0 +1,102 @@
/*
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.core.VersionedCallable;
import de.steamwar.core.VersionedRunnable;
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.fight.FightTeam_14;
import de.steamwar.fightsystem.fight.FightTeam_8;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.utils.Region;
import de.steamwar.sql.Schematic;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class PrepareSchem implements Listener {
public PrepareSchem() {
new StateDependentListener(ArenaMode.Prepare, FightState.Setup, this){
@Override
public void disable() {
super.disable();
Region region = Fight.getBlueTeam().getExtendRegion();
World world = Bukkit.getWorlds().get(0);
Schematic schem;
try{
schem = Schematic.getSchemFromDB(Config.PrepareSchemID);
}catch(SecurityException e){
FightSystem.shutdown(FightSystem.PREFIX + "§cAnscheinend wurde die auszufahrende Schematic gelöscht, Einsenden wird abgebrochen.");
return;
}
try{
region.forEach((x, y, z) -> {
if(VersionedCallable.call(
new VersionedCallable<>(() -> FightTeam_8.checkPistonMoving(world.getBlockAt(x, y, z)), 8),
new VersionedCallable<>(() -> FightTeam_14.checkPistonMoving(world.getBlockAt(x, y, z)), 14))){
FightSystem.shutdown(FightSystem.PREFIX + "§cIm Teambereich wurden sich noch bewegende Pistons gefunden, Einsenden wird abgebrochen.");
throw new IllegalStateException();
}
});
}catch (IllegalStateException e){
return;
}
try{
VersionedRunnable.call(
new VersionedRunnable(() -> FightTeam_8.saveSchem(schem, region), 8),
new VersionedRunnable(() -> FightTeam_14.saveSchem(schem, region), 14));
}catch(IllegalStateException e){
FightSystem.shutdown(FightSystem.PREFIX + "§cDie Schematic konnte nicht gespeichert werden, Einsenden wird abgebrochen.");
return;
}
schem.setSchemType(Config.SchematicType.checkType());
FightSystem.shutdown(FightSystem.PREFIX + "§aDie Schematic wird nun zeitnah von einem Teammitglied überprüft");
}
};
}
@EventHandler
public void handlePlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
FightTeam team = Fight.getPlayerTeam(player);
if (team == null) {
Fight.getBlueTeam().addMember(player);
}
if(FightState.getFightState() == FightState.PRE_LEADER_SETUP) {
FightSystem.setPreSchemState();
FightSystem.setPostSchemState();
}
}
}

Datei anzeigen

@ -1,44 +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.states.FightState;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import java.util.EnumSet;
public class ProjectileLaunchListener extends BasicListener {
public ProjectileLaunchListener() {
super(EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP, FightState.PRE_RUNNING, FightState.SPECTATE));
}
@EventHandler
public void handleProjectileLaunch(ProjectileLaunchEvent event) {
event.setCancelled(true);
if(event.getEntity().getShooter() instanceof Player){
Player player = (Player) event.getEntity().getShooter();
toActionbar(player, TextComponent.fromLegacyText("§cDu darfst den Bogen erst nach Fightbeginn nutzen!"));
}
}
}

Datei anzeigen

@ -19,21 +19,21 @@
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.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import java.util.EnumSet;
public class RankedJoin implements Listener {
public class NormalJoinListener extends BasicListener {
public NormalJoinListener() {
super(Config.event() || Config.test() || Config.Ranked ? EnumSet.noneOf(FightState.class) : EnumSet.of(FightState.PRE_LEADER_SETUP));
public RankedJoin() {
new StateDependentListener(ArenaMode.Ranked, FightState.PreLeaderSetup, this);
}
@EventHandler
@ -43,15 +43,10 @@ public class NormalJoinListener extends BasicListener {
if (fightTeam == null) {
if(!player.getUniqueId().equals(Config.RedLeader) && Fight.getBlueTeam().canbeLeader(player)) {
Fight.getBlueTeam().setLeader(Fight.getBlueTeam().addMember(player));
Fight.getBlueTeam().addMember(player);
}else if(Fight.getRedTeam().canbeLeader(player)) {
Fight.getRedTeam().setLeader(Fight.getRedTeam().addMember(player));
Fight.getRedTeam().addMember(player);
}
}
if(Fight.getRedTeam().hasTeamLeader() && Fight.getBlueTeam().hasTeamLeader()
&& (Fight.getRedTeam().getLeader().getPlayer() == player || Fight.getBlueTeam().getLeader().getPlayer() == player)) {
FightSystem.setPreSchemState();
}
}
}

Datei anzeigen

@ -26,12 +26,15 @@ import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.record.RecordSystem;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent;
import de.steamwar.fightsystem.states.StateDependentListener;
import org.bukkit.*;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
@ -43,16 +46,31 @@ import org.bukkit.event.player.*;
import org.bukkit.event.server.BroadcastMessageEvent;
import org.bukkit.inventory.ItemStack;
import java.util.EnumSet;
import java.util.Random;
public class EventRecordListener extends BasicListener {
public class Recording implements Listener {
private static final int AIR = 0;
private static final Random random = new Random();
public EventRecordListener() {
super(Config.recording() ? EnumSet.allOf(FightState.class) : EnumSet.noneOf(FightState.class));
public Recording() {
new StateDependentListener(Config.recording(), FightState.All, this);
new StateDependent(Config.recording(), FightState.Ingame){
@Override
public void enable() {
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> {
setKitItems(Fight.getBlueTeam());
setKitItems(Fight.getRedTeam());
}, 1);
}
@Override
public void disable() {
despawnTeam(Fight.getRedTeam());
despawnTeam(Fight.getBlueTeam());
despawnTNT();
}
}.register();
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@ -170,22 +188,8 @@ public class EventRecordListener extends BasicListener {
}
}
@Override
public void stateChange(FightState state) {
if(state == FightState.PRE_RUNNING) {
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> {
setKitItems(Fight.getBlueTeam());
setKitItems(Fight.getRedTeam());
}, 1);
}else if(state == FightState.SPECTATE){
despawnTeam(Fight.getRedTeam());
despawnTeam(Fight.getBlueTeam());
despawnTNT();
}
}
private void setKitItems(FightTeam team){
if(FightSystem.getFightState() != FightState.PRE_RUNNING)
if(FightState.getFightState() != FightState.PRE_RUNNING)
return;
for(FightPlayer fp : team.getPlayers()){
@ -222,6 +226,6 @@ public class EventRecordListener extends BasicListener {
private boolean isNotSent(Player p){
FightPlayer fp = Fight.getFightPlayer(p);
return fp == null || !fp.isLiving() || FightSystem.getFightState() == FightState.SPECTATE;
return fp == null || !fp.isLiving() || FightState.getFightState() == FightState.SPECTATE;
}
}

Datei anzeigen

@ -0,0 +1,35 @@
package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
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.PlayerResourcePackStatusEvent;
public class ResourcePack implements Listener {
public ResourcePack(){
new StateDependentListener(ArenaMode.Event, FightState.All, this);
}
@EventHandler
public void handlePlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
player.setResourcePack("https://steamwar.de/antixray.zip");
}
@EventHandler
public void onResourcepack(PlayerResourcePackStatusEvent e){
if(e.getStatus() == PlayerResourcePackStatusEvent.Status.ACCEPTED || e.getStatus() == PlayerResourcePackStatusEvent.Status.SUCCESSFULLY_LOADED)
return;
Player player = e.getPlayer();
player.sendMessage(FightSystem.PREFIX + "§cAuf Eventserver kann nur mit dem SteamWar-Resourcepack beigetreten werden");
player.sendMessage(FightSystem.PREFIX + "§cDa du abgelehnt hast, musst du nun in der Serverliste erstmal wieder Ressourcenpakete von SteamWar aktivieren.");
player.kickPlayer(null);
}
}

Datei anzeigen

@ -1,26 +0,0 @@
package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.utils.FightScoreboard;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.EnumSet;
public class ScoreboardListener extends BasicListener {
public ScoreboardListener() {
super(EnumSet.allOf(FightState.class));
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
FightScoreboard.showScoreboard(event.getPlayer());
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
FightScoreboard.removeScoreboard(event.getPlayer());
}
}

Datei anzeigen

@ -19,32 +19,31 @@
package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode;
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.event.EventHandler;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.SpawnerSpawnEvent;
import org.bukkit.event.weather.WeatherChangeEvent;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.EnumSet;
public class SetupQuit implements Listener {
public class FoodLevelChangeListener extends BasicListener {
public FoodLevelChangeListener() {
super(EnumSet.allOf(FightState.class));
public SetupQuit(){
new StateDependentListener(ArenaMode.All, FightState.Setup, this);
}
@EventHandler
public void handleFoodLevelChange(FoodLevelChangeEvent event) {
event.setCancelled(true);
}
public void handlePlayerQuit(PlayerQuitEvent event) {
event.setQuitMessage(null);
@EventHandler
public void onWeatherChange(WeatherChangeEvent event){
event.setCancelled(true);
}
Player player = event.getPlayer();
FightTeam team = Fight.getPlayerTeam(player);
if(team == null)
return;
@EventHandler
public void onSpawnerSpawn(SpawnerSpawnEvent e){
e.setCancelled(true);
team.removePlayer(player);
}
}

Datei anzeigen

@ -19,32 +19,25 @@
package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.FurnaceSmeltEvent;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.EnumSet;
public class Shutdown implements Listener {
public class GameplayListener extends BasicListener{
public GameplayListener() {
super(EnumSet.allOf(FightState.class));
public Shutdown(){
new StateDependentListener(ArenaMode.AntiEvent, FightState.All, this);
}
@EventHandler
public void onSleep(PlayerBedEnterEvent e) {
e.setCancelled(true);
}
@EventHandler
public void onCrafting(CraftItemEvent e){
e.setCancelled(true);
}
@EventHandler
public void onFurnace(FurnaceSmeltEvent e){
e.setCancelled(true);
@EventHandler(priority = EventPriority.HIGH)
public void handlePlayerQuit(PlayerQuitEvent event) {
//Shutdown server if nobody online and its not an event server
if(Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(event.getPlayer())))
Bukkit.shutdown();
}
}

Datei anzeigen

@ -0,0 +1,92 @@
/*
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.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.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import java.util.logging.Level;
public class TeamArea implements Listener {
private static final String DENY_TEAM = "§cDu darfst nicht zu den Teams";
private static final String DENY_ENTERN = "§cDu darfst nicht entern";
public TeamArea() {
new StateDependentListener(ArenaMode.AntiTest, FightState.All, this);
}
@EventHandler
public void teamAreas(PlayerMoveEvent event) {
Player player = event.getPlayer();
if(player == FightSystem.getEventLeiter())
return;
Location to = event.getTo();
assert to != null;
FightTeam team = Fight.getPlayerTeam(player);
if(Config.BlueExtendRegion.playerInRegion(to)){
if(team == null)
reset(event, DENY_TEAM);
else if(team == Fight.getRedTeam() && (player.getGameMode() == GameMode.SPECTATOR || !team.canPlayerEntern(player)))
reset(event, DENY_ENTERN);
else
return; // Is allowed in area
checkInInnerArea(event.getPlayer(), to, Fight.getBlueTeam());
}else if(Config.RedExtendRegion.playerInRegion(to)){
if(team == null)
reset(event, DENY_TEAM);
else if(team == Fight.getBlueTeam() && (player.getGameMode() == GameMode.SPECTATOR || !team.canPlayerEntern(player)))
reset(event, DENY_ENTERN);
else
return; // Is allowed in area
checkInInnerArea(event.getPlayer(), to, Fight.getRedTeam());
}else if(team != null && player.getGameMode() != GameMode.SPECTATOR && !team.canPlayerEntern(player))
reset(event, DENY_ENTERN);
}
private void checkInInnerArea(Player player, Location to, FightTeam team){
if(team.getSchemRegion().playerInRegion(to) && Config.PreperationArea >= 5){ // Preventing false positives due to small extension
player.kickPlayer(null);
Bukkit.getLogger().log(Level.SEVERE, player.getName() + " ist in einen Teambereich eingedrungen.");
}
}
private void reset(PlayerMoveEvent event, String message){
Player player = event.getPlayer();
player.teleport(event.getFrom());
BasicListener.toActionbar(player, TextComponent.fromLegacyText(message));
}
}

Datei anzeigen

@ -0,0 +1,55 @@
/*
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.ArenaMode;
import de.steamwar.fightsystem.FightSystem;
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.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class TestJoin implements Listener {
public TestJoin() {
new StateDependentListener(ArenaMode.Test, FightState.All, this);
}
@EventHandler
public void handlePlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
FightTeam fightTeam = Fight.getPlayerTeam(player);
if (fightTeam == null && (Fight.getRedTeam().isLeaderless() || Fight.getBlueTeam().isLeaderless())) {
player.sendMessage(FightSystem.PREFIX + "§7Werde zum Teamleader mit §8/§eleader");
}
player.setOp(true);
if(FightState.getFightState() == FightState.PRE_LEADER_SETUP){
FightSystem.setPreSchemState();
FightSystem.setPostSchemState();
}
}
}

Datei anzeigen

@ -1,193 +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.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.NoPlayersOnlineCountdown;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import java.util.EnumSet;
public class TestListener extends BasicListener {
private NoPlayersOnlineCountdown countdown;
public TestListener() {
super(Config.test() ? EnumSet.allOf(FightState.class) : EnumSet.noneOf(FightState.class));
if(Config.test())
countdown = new NoPlayersOnlineCountdown();
}
@EventHandler
public void handlePlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
FightTeam fightTeam = Fight.getPlayerTeam(player);
if (fightTeam == null && (!Fight.getRedTeam().hasTeamLeader() || !Fight.getBlueTeam().hasTeamLeader())) {
player.sendMessage(FightSystem.PREFIX + "§7Werde zum Teamleader mit §8/§eleader");
}
if(countdown != null){
countdown.disable();
countdown = null;
}
player.setOp(true);
/*PermissionAttachment attachment = player.addAttachment(FightSystem.getPlugin());
attachment.setPermission("fawe.permpack.basic", true);
attachment.setPermission("minecraft.command.gamemode", true);
attachment.setPermission("minecraft.command.tp", true);
attachment.setPermission("worldedit.navigation.jumpto.tool", true);
attachment.setPermission("worldedit.navigation.thru.tool", true);
attachment.setPermission("worldedit.navigation.jumpto.tool", true);
attachment.setPermission("worldedit.navigation.thru.tool", true);
attachment.setPermission("worldedit.biome.info", true);
attachment.setPermission("worldedit.biome.set", true);
attachment.setPermission("worldedit.biome.list", true);
attachment.setPermission("worldedit.chunkinfo", true);
attachment.setPermission("worldedit.listchunks", true);
attachment.setPermission("worldedit.clipboard.cut", true);
attachment.setPermission("worldedit.clipboard.paste", true);
attachment.setPermission("worldedit.schematic.formats", true);
attachment.setPermission("worldedit.schematic.load", true);
attachment.setPermission("worldedit.schematic.list", true);
attachment.setPermission("worldedit.schematic.save", true);
attachment.setPermission("worldedit.clipboard.clear", true);
attachment.setPermission("worldedit.clipboard.copy", true);
attachment.setPermission("worldedit.clipboard.lazycopy", true);
attachment.setPermission("worldedit.clipboard.place", true);
attachment.setPermission("worldedit.clipboard.download", true);
attachment.setPermission("worldedit.clipboard.flip", true);
attachment.setPermission("worldedit.clipboard.rotate", true);
attachment.setPermission("worldedit.help", true);
attachment.setPermission("worldedit.global-mask", true);
attachment.setPermission("worldedit.global-transform", true);
attachment.setPermission("worldedit.generation.cylinder", true);
attachment.setPermission("worldedit.generation.sphere", true);
attachment.setPermission("worldedit.generation.forest", true);
attachment.setPermission("worldedit.generation.pumpkins", true);
attachment.setPermission("worldedit.generation.pyramid", true);
attachment.setPermission("worldedit.generation.shape", true);
attachment.setPermission("worldedit.biome.set", true);
attachment.setPermission("worldedit.history.undo", true);
attachment.setPermission("worldedit.history.redo", true);
attachment.setPermission("worldedit.history.rollback", true);
attachment.setPermission("worldedit.navigation.unstuck", true);
attachment.setPermission("worldedit.navigation.ascend", true);
attachment.setPermission("worldedit.navigation.descend", true);
attachment.setPermission("worldedit.navigation.ceiling", true);
attachment.setPermission("worldedit.navigation.thru.command", true);
attachment.setPermission("worldedit.navigation.jumpto.command", true);
attachment.setPermission("worldedit.navigation.up", true);
attachment.setPermission("worldedit.region.hollow", true);
attachment.setPermission("worldedit.region.line", true);
attachment.setPermission("worldedit.region.curve", true);
attachment.setPermission("worldedit.region.overlay", true);
attachment.setPermission("worldedit.region.center", true);
attachment.setPermission("worldedit.region.naturalize", true);
attachment.setPermission("worldedit.region.walls", true);
attachment.setPermission("worldedit.region.faces", true);
attachment.setPermission("worldedit.region.smooth", true);
attachment.setPermission("worldedit.region.move", true);
attachment.setPermission("worldedit.region.forest", true);
attachment.setPermission("worldedit.region.replace", true);
attachment.setPermission("worldedit.region.stack", true);
attachment.setPermission("worldedit.region.set", true);
attachment.setPermission("worldedit.selection.pos", true);
attachment.setPermission("worldedit.selection.chunk", true);
attachment.setPermission("worldedit.selection.hpos", true);
attachment.setPermission("worldedit.wand", true);
attachment.setPermission("worldedit.wand.toggle", true);
attachment.setPermission("worldedit.selection.contract", true);
attachment.setPermission("worldedit.selection.outset", true);
attachment.setPermission("worldedit.selection.inset", true);
attachment.setPermission("worldedit.analysis.distr", true);
attachment.setPermission("worldedit.analysis.count", true);
attachment.setPermission("worldedit.selection.size", true);
attachment.setPermission("worldedit.selection.expand", true);
attachment.setPermission("worldedit.selection.shift", true);
attachment.setPermission("worldedit.snapshots.list", true);
attachment.setPermission("worldedit.superpickaxe", true);
attachment.setPermission("worldedit.superpickaxe.area", true);
attachment.setPermission("worldedit.superpickaxe.recursive", true);
attachment.setPermission("worldedit.brush.blendball", true);
attachment.setPermission("worldedit.brush.erode", true);
attachment.setPermission("worldedit.brush.pull", true);
attachment.setPermission("worldedit.brush.circle", true);
attachment.setPermission("worldedit.brush.recursive", true);
attachment.setPermission("worldedit.brush.line", true);
attachment.setPermission("worldedit.brush.spline", true);
attachment.setPermission("worldedit.brush.surfacespline", true);
attachment.setPermission("worldedit.brush.shatter", true);
attachment.setPermission("worldedit.brush.stencil", true);
attachment.setPermission("worldedit.brush.height", true);
attachment.setPermission("worldedit.brush.layer", true);
attachment.setPermission("worldedit.brush.populateschematic", true);
attachment.setPermission("worldedit.brush.scatter", true);
attachment.setPermission("worldedit.brush.splatter", true);
attachment.setPermission("worldedit.brush.scattercommand", true);
attachment.setPermission("worldedit.brush.copy", true);
attachment.setPermission("worldedit.brush.command", true);
attachment.setPermission("worldedit.brush.apply", true);
attachment.setPermission("worldedit.brush.sphere", true);
attachment.setPermission("worldedit.brush.cylinder", true);
attachment.setPermission("worldedit.brush.clipboard", true);
attachment.setPermission("worldedit.brush.smooth", true);
attachment.setPermission("worldedit.brush.ex", true);
attachment.setPermission("worldedit.brush.gravity", true);
attachment.setPermission("worldedit.brush.options.range", true);
attachment.setPermission("worldedit.brush.options.material", true);
attachment.setPermission("worldedit.brush.options.size", true);
attachment.setPermission("worldedit.brush.options.mask", true);
attachment.setPermission("worldedit.brush.options.smask", true);
attachment.setPermission("worldedit.brush.options.transform", true);
attachment.setPermission("worldedit.brush.options.scroll", true);
attachment.setPermission("worldedit.brush.options.visualize", true);
attachment.setPermission("worldedit.tool.deltree", true);
attachment.setPermission("worldedit.tool.farwand", true);
attachment.setPermission("worldedit.tool.lrbuild", true);
attachment.setPermission("worldedit.tool.info", true);
attachment.setPermission("worldedit.tool.tree", true);
attachment.setPermission("worldedit.tool.replacer", true);
attachment.setPermission("worldedit.tool.data-cycler", true);
attachment.setPermission("worldedit.tool.flood-fill", true);
attachment.setPermission("worldedit.tool.inspect", true);
attachment.setPermission("worldedit.fill.recursive", true);
attachment.setPermission("worldedit.drain", true);
attachment.setPermission("worldedit.fixlava", true);
attachment.setPermission("worldedit.fixwater", true);
attachment.setPermission("worldedit.removeabove", true);
attachment.setPermission("worldedit.removebelow", true);
attachment.setPermission("worldedit.removenear", true);
attachment.setPermission("worldedit.replacenear", true);
attachment.setPermission("worldedit.snow", true);
attachment.setPermission("worldedit.thaw", true);
attachment.setPermission("worldedit.green", true);
attachment.setPermission("worldedit.extinguish", true);
attachment.setPermission("worldedit.calc", true);
attachment.setPermission("worldedit.fill", true);*/
}
}

Datei anzeigen

@ -1,55 +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.core.Core;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.states.FightState;
import org.bukkit.Bukkit;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import java.util.*;
public class VersionDependentListener extends BasicListener {
private static final List<Listener> listeners = new ArrayList<>();
static {
if(Core.getVersion() > 8)
listeners.add(new PickupArrowListener_9());
}
public VersionDependentListener() {
super(EnumSet.allOf(FightState.class));
}
@Override
public void enable() {
for(Listener listener : listeners)
Bukkit.getPluginManager().registerEvents(listener, FightSystem.getPlugin());
}
@Override
public void disable() {
for(Listener listener : listeners)
HandlerList.unregisterAll(listener);
}
}

Datei anzeigen

@ -17,22 +17,32 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.utils;
package de.steamwar.fightsystem.listener;
import de.steamwar.core.VersionedCallable;
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.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
import java.util.List;
public class WaterRemover implements Listener {
public class WaterRemover {
private WaterRemover(){}
private static final int MIN_Y = Config.BluePasteRegion.getMinY() + Config.WaterDepth;
private static final int MIN_Y = Config.AlignWater ? Config.TeamBlueCornerY + Config.WaterDepth : Config.TeamBlueCornerY;
public WaterRemover() {
new StateDependentListener(ArenaMode.All, FightState.Running, this);
}
public static void add(List<Block> l) {
for(Block b : l){
@EventHandler
public void handleEntityExplode(EntityExplodeEvent event) {
event.setYield(0); //No drops (additionally to world config)
for(Block b : event.blockList()){
//b cannot be water or air due to current explosion
checkBlock(b.getRelative(BlockFace.UP));
@ -43,8 +53,11 @@ public class WaterRemover {
}
}
private static void checkBlock(Block b) {
if(!removeWater(b))
private void checkBlock(Block b) {
//checks for water and removes it, if present
if(!VersionedCallable.call(
new VersionedCallable<>(() -> WaterRemover_8.removeWater(b), 8),
new VersionedCallable<>(() -> WaterRemover_14.removeWater(b), 14)))
return;
if(b.getY() < MIN_Y)
@ -58,13 +71,8 @@ public class WaterRemover {
}
public static boolean isWater(Block block){
return VersionedCallable.call(new VersionedCallable<>(() -> WaterRemover_8.isWater(block), 8),
return VersionedCallable.call(
new VersionedCallable<>(() -> WaterRemover_8.isWater(block), 8),
new VersionedCallable<>(() -> WaterRemover_14.isWater(block), 14));
}
public static boolean removeWater(Block block){
//checks for water and removes it, if present
return VersionedCallable.call(new VersionedCallable<>(() -> WaterRemover_8.removeWater(block), 8),
new VersionedCallable<>(() -> WaterRemover_14.removeWater(block), 14));
}
}

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.fightsystem.record;
import de.steamwar.core.VersionedCallable;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.states.FightState;
@ -48,7 +49,7 @@ public class RecordSystem {
if (Config.SpectateSystem)
new SpectateConnection();
new FileRecorder();
if(Config.event())
if(Config.mode == ArenaMode.EVENT)
teamIds(Config.EventTeamBlueID, Config.EventTeamRedID);
}
@ -167,8 +168,8 @@ public class RecordSystem {
public static synchronized void blockChange(Block block){
int blockState = blockToId(block);
int shortX = block.getX() - Config.ArenaMinX;
int shortZ = block.getZ() - Config.ArenaMinZ;
int shortX = block.getX() - Config.ArenaRegion.getMinX();
int shortZ = block.getZ() - Config.ArenaRegion.getMinZ();
if((short)blockState == blockState && shortX > 0 && shortX < 256 && shortZ > 0 && shortZ < 256){
//Short block packet
Recorder.rByte(0x33);
@ -274,7 +275,7 @@ public class RecordSystem {
private static void checkWorldState(){
tick();
if(FightSystem.getFightState() == FightState.SPECTATE)
if(FightState.getFightState() == FightState.SPECTATE)
return;
for(TNTPrimed tnt : WORLD.getEntitiesByClass(TNTPrimed.class)){

Datei anzeigen

@ -19,39 +19,73 @@
package de.steamwar.fightsystem.states;
import java.util.*;
public enum FightState {
PRE_LEADER_SETUP(true, true, false, false),
PRE_SCHEM_SETUP(true, true, false, false),
POST_SCHEM_SETUP(true, true, false, false),
PRE_RUNNING(false, false, true, false),
RUNNING(false, false, true, true),
SPECTATE(false, true, false, false);
PRE_LEADER_SETUP,
PRE_SCHEM_SETUP,
POST_SCHEM_SETUP,
PRE_RUNNING,
RUNNING,
SPECTATE;
private final boolean setup; //PRE_LEADER_SETUP, PRE_SCHEM_SETUP, POST_SCHEM_SETUP
private final boolean outgame; //PRE_LEADER_SETUP, PRE_SCHEM_SETUP, POST_SCHEM_SETUP, SPECTATE
private final boolean ingame; //PRE_RUNNING, RUNNING
private final boolean infight; //RUNNING
public static final Set<FightState> All = Collections.unmodifiableSet(EnumSet.allOf(FightState.class));
FightState(boolean setup, boolean outgame, boolean ingame, boolean infight){
this.setup = setup;
this.outgame = outgame;
this.ingame = ingame;
this.infight = infight;
public static final Set<FightState> PreLeaderSetup = Collections.unmodifiableSet(EnumSet.of(PRE_LEADER_SETUP));
public static final Set<FightState> PreSchemSetup = Collections.unmodifiableSet(EnumSet.of(PRE_SCHEM_SETUP));
public static final Set<FightState> PostSchemSetup = Collections.unmodifiableSet(EnumSet.of(POST_SCHEM_SETUP));
public static final Set<FightState> PreRunning = Collections.unmodifiableSet(EnumSet.of(PRE_RUNNING));
public static final Set<FightState> Running = Collections.unmodifiableSet(EnumSet.of(RUNNING));
public static final Set<FightState> Spectate = Collections.unmodifiableSet(EnumSet.of(SPECTATE));
public static final Set<FightState> Setup = Collections.unmodifiableSet(EnumSet.of(PRE_LEADER_SETUP, PRE_SCHEM_SETUP, POST_SCHEM_SETUP));
public static final Set<FightState> Ingame = Collections.unmodifiableSet(EnumSet.of(PRE_RUNNING, RUNNING));
public static final Set<FightState> Schem = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(PRE_LEADER_SETUP, PRE_SCHEM_SETUP)));
public static final Set<FightState> AntiRunning = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(RUNNING)));
private static final Map<IStateDependent, Boolean> stateDependentFeatures = new HashMap<>();
private static FightState fightState = PRE_LEADER_SETUP;
public static FightState getFightState() {
return fightState;
}
public boolean setup(){
return setup;
public static void registerStateDependent(IStateDependent stateDependent){
if(stateDependent.enabled().isEmpty())
return;
boolean enabled = stateDependent.enabled().contains(fightState);
stateDependentFeatures.put(stateDependent, enabled);
if(enabled)
stateDependent.enable();
}
public boolean outgame(){
return outgame;
public static void setFightState(FightState state){
fightState = state;
for(Map.Entry<IStateDependent, Boolean> feature : stateDependentFeatures.entrySet()){
//Enable feature if should be enabled and currently disabled
if(feature.getKey().enabled().contains(fightState) && !feature.getValue()){
feature.getKey().enable();
feature.setValue(true);
}
public boolean ingame(){
return ingame;
//Disable feature if should be disabled and currently enabled
if(!feature.getKey().enabled().contains(fightState) && feature.getValue()){
feature.getKey().disable();
feature.setValue(false);
}
}
}
public boolean infight(){
return infight;
public static boolean setup(){
return Setup.contains(fightState);
}
public static boolean ingame(){
return Ingame.contains(fightState);
}
public static boolean infight(){
return fightState == RUNNING;
}
}

Datei anzeigen

@ -0,0 +1,40 @@
/*
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.states;
import java.util.Set;
public interface IStateDependent {
/**
* @return returns a set containing
*/
Set<FightState> enabled();
/**
* Enables the state dependent object
*/
void enable();
/**
* Disables the state dependent object
*/
void disable();
}

Datei anzeigen

@ -0,0 +1,45 @@
/*
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.states;
import de.steamwar.fightsystem.ArenaMode;
import java.util.Set;
public class OneShotStateDependent extends StateDependent{
private final Runnable runnable;
public OneShotStateDependent(Set<ArenaMode> mode, Set<FightState> states, Runnable runnable) {
super(mode, states);
this.runnable = runnable;
register();
}
@Override
public void enable() {
runnable.run();
}
@Override
public void disable() {
//Do nothing, oneshot
}
}

Datei anzeigen

@ -19,27 +19,37 @@
package de.steamwar.fightsystem.states;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.winconditions.Winconditions;
import java.util.Set;
public interface StateDependent {
public abstract class StateDependent implements IStateDependent {
/**
* @return returns a set containing
*/
Set<FightState> enabled();
private final Set<FightState> enabled;
private final boolean register;
/**
* Enables the state dependent object
*/
void enable();
protected StateDependent(Winconditions wincondition, Set<FightState> states){
this(Config.ActiveWinconditions.contains(wincondition), states);
}
/**
* Disables the state dependent object
*/
void disable();
protected StateDependent(Set<ArenaMode> mode, Set<FightState> states){
this(mode.contains(Config.mode), states);
}
/**
* On state change when enabled
*/
default void stateChange(FightState state){}
protected StateDependent(boolean enabled, Set<FightState> states){
this.enabled = states;
this.register = enabled;
}
public void register(){
if(register)
FightState.registerStateDependent(this);
}
@Override
public Set<FightState> enabled() {
return enabled;
}
}

Datei anzeigen

@ -0,0 +1,57 @@
/*
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.states;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.FightSystem;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.PluginCommand;
import java.util.Set;
public class StateDependentCommand extends StateDependent {
private static final CommandExecutor unavailable = (sender, cmd, s, strings) -> {
sender.sendMessage(FightSystem.PREFIX + "§cDieser Befehl ist zu diesem Kampfzeitpunkt nicht verfügbar.");
return false;
};
private final PluginCommand command;
private final CommandExecutor executor;
public StateDependentCommand(Set<ArenaMode> mode, Set<FightState> states, String name, CommandExecutor executor) {
super(mode, states);
this.executor = executor;
this.command = FightSystem.getPlugin().getCommand(name);
assert command != null;
disable();
register();
}
@Override
public void enable() {
command.setExecutor(executor);
}
@Override
public void disable() {
command.setExecutor(unavailable);
}
}

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden Mehr anzeigen