SteamWar/FightSystem
Archiviert
13
1
Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2021-08-23 07:30:50 +02:00
Ursprung 74565853bb
Commit 7d1c34d31e
10 geänderte Dateien mit 56 neuen und 90 gelöschten Zeilen

Datei anzeigen

@ -49,7 +49,7 @@ public enum ArenaMode {
public static final Set<ArenaMode> AntiPrepare = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(PREPARE))); 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, REPLAY))); public static final Set<ArenaMode> VariableTeams = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(RANKED, EVENT, REPLAY)));
public static final Set<ArenaMode> RankedEvent = Collections.unmodifiableSet(EnumSet.of(RANKED, EVENT, REPLAY)); public static final Set<ArenaMode> RankedEvent = Collections.unmodifiableSet(EnumSet.of(RANKED, EVENT, REPLAY));
public static final Set<ArenaMode> Restartable = Collections.unmodifiableSet(EnumSet.of(NORMAL, RANKED)); public static final Set<ArenaMode> Restartable = Collections.unmodifiableSet(EnumSet.of(NORMAL, RANKED, REPLAY));
public static final Set<ArenaMode> SoloLeader = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK, PREPARE)); public static final Set<ArenaMode> SoloLeader = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK, PREPARE));
public static final Set<ArenaMode> NotOnBau = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK, PREPARE, REPLAY))); public static final Set<ArenaMode> NotOnBau = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK, PREPARE, REPLAY)));
} }

Datei anzeigen

@ -30,7 +30,7 @@ import org.bukkit.entity.Player;
public class RemoveCommand implements CommandExecutor { public class RemoveCommand implements CommandExecutor {
public RemoveCommand() { public RemoveCommand() {
new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "die", this); new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "remove", this);
} }
@Override @Override

Datei anzeigen

@ -60,7 +60,7 @@ public class FightSchematic extends StateDependent {
private int schematic = 0; private int schematic = 0;
public FightSchematic(FightTeam team, boolean rotate) { public FightSchematic(FightTeam team, boolean rotate) {
super(ArenaMode.AntiReplay, FightState.PostSchemSetup); super(ArenaMode.All, FightState.PostSchemSetup);
this.team = team; this.team = team;
this.region = team.getSchemRegion(); this.region = team.getSchemRegion();
this.rotate = rotate; this.rotate = rotate;

Datei anzeigen

@ -170,7 +170,7 @@ public class FightTeam implements IFightTeam{
playerSet.forEach(this::addMember); playerSet.forEach(this::addMember);
if(isLeaderless()){ if(ArenaMode.VariableTeams.contains(Config.mode) && isLeaderless()){
for(Player player : Bukkit.getOnlinePlayers()){ for(Player player : Bukkit.getOnlinePlayers()){
if(Fight.getPlayerTeam(player) == null && canbeLeader(player)){ if(Fight.getPlayerTeam(player) == null && canbeLeader(player)){
addMember(player); addMember(player);

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.fightsystem.listener; package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.states.StateDependentListener;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -36,7 +37,10 @@ public class Shutdown implements Listener {
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void handlePlayerQuit(PlayerQuitEvent event) { public void handlePlayerQuit(PlayerQuitEvent event) {
//Shutdown server if nobody online and its not an event server if(Config.replayserver())
return;
//Shutdown server if nobody online
if(Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(event.getPlayer()))) if(Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(event.getPlayer())))
Bukkit.shutdown(); Bukkit.shutdown();
} }

Datei anzeigen

@ -38,6 +38,7 @@ public class FileRecorder extends StateDependent implements Recorder {
public FileRecorder(){ public FileRecorder(){
super(ArenaMode.AntiReplay, FightState.Recording); super(ArenaMode.AntiReplay, FightState.Recording);
register();
} }
@Override @Override

Datei anzeigen

@ -20,12 +20,10 @@
package de.steamwar.fightsystem.record; package de.steamwar.fightsystem.record;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.Config;
import org.bukkit.Bukkit;
import java.io.*; import java.io.*;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.util.logging.Level;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
public class FileSource extends PacketSource { public class FileSource extends PacketSource {
@ -56,7 +54,6 @@ public class FileSource extends PacketSource {
try{ try{
return inputStream.available() == 0; return inputStream.available() == 0;
}catch (IOException e){ }catch (IOException e){
Bukkit.getLogger().log(Level.WARNING, "On close test exception", e);
return true; return true;
} }
} }

Datei anzeigen

@ -101,7 +101,7 @@ public class PacketProcessor {
int entityId = source.rInt(); int entityId = source.rInt();
int userId = source.rInt(); int userId = source.rInt();
execSync(() -> new REntity(entityId, userId)); execSync(() -> new REntity(entityId, userId));
} }
private void entityMoves() throws IOException { private void entityMoves() throws IOException {
@ -289,13 +289,13 @@ public class PacketProcessor {
private void endReplay(){ private void endReplay(){
REntity.dieAll(); REntity.dieAll();
freezer.disable(); freezer.disable();
replaying = false;
if(Config.replayserver() || ArenaMode.AntiReplay.contains(Config.mode)) { if(Config.replayserver() || ArenaMode.AntiReplay.contains(Config.mode)) {
FightSystem.setSpectateState(null, "Replay ends"); FightSystem.setSpectateState(null, "Replay ends");
}else{ }else{
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cReplay beendet"); Bukkit.broadcastMessage(FightSystem.PREFIX + "§cReplay beendet");
new EventSpectateCountdown().enable(); new EventSpectateCountdown().enable();
} }
replaying = false;
} }
private void bow() throws IOException { private void bow() throws IOException {
@ -421,7 +421,7 @@ public class PacketProcessor {
} catch (EOFException e) { } catch (EOFException e) {
Bukkit.getLogger().log(Level.INFO, "The FightServer is offline"); Bukkit.getLogger().log(Level.INFO, "The FightServer is offline");
source.close(); source.close();
} catch(IOException e){ } catch(IOException e) {
Bukkit.getLogger().log(Level.WARNING, "Could not recieve packet", e); Bukkit.getLogger().log(Level.WARNING, "Could not recieve packet", e);
source.close(); source.close();
} }

Datei anzeigen

@ -24,6 +24,7 @@ import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.wrappers.*; import com.comphenix.protocol.wrappers.*;
import com.mojang.authlib.GameProfile;
import de.steamwar.core.Core; import de.steamwar.core.Core;
import de.steamwar.core.VersionedCallable; import de.steamwar.core.VersionedCallable;
import de.steamwar.fightsystem.listener.FightScoreboard; import de.steamwar.fightsystem.listener.FightScoreboard;
@ -55,14 +56,7 @@ public class REntity {
if(entity.fireTick > 0) { if(entity.fireTick > 0) {
entity.fireTick--; entity.fireTick--;
if(entity.fireTick == 0) { if(entity.fireTick == 0) {
/*DataWatcher dataWatcher = new DataWatcher(null); ProtocolLibrary.getProtocolManager().broadcastServerPacket(entity.getDataWatcherPacket(0, (byte)0));
DataWatcherObject<Byte> dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a);
dataWatcher.register(dataWatcherObject, (byte) 0);
dataWatcher.markDirty(dataWatcherObject);
entity.sendDataWatcher(dataWatcher);*/
WrappedDataWatcher watcher = new WrappedDataWatcher();
watcher.setObject(0, (byte) 0, true);
ProtocolLibrary.getProtocolManager().broadcastServerPacket(entity.getDataWatcherPacket(watcher));
} }
} }
}); });
@ -82,28 +76,14 @@ public class REntity {
} }
//ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getTeleportPacket()); Sollte nicht nötig sein? //ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getTeleportPacket()); Sollte nicht nötig sein?
if(entity.fireTick != 0) { if(entity.fireTick != 0) {
WrappedDataWatcher watcher = new WrappedDataWatcher(); ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(0, (byte) 1));
watcher.setObject(0, (byte) 1, true);
/*ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(watcher));
DataWatcher dataWatcher = new DataWatcher(null);
DataWatcherObject<Byte> dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a);
dataWatcher.register(dataWatcherObject, (byte) 1);
dataWatcher.markDirty(dataWatcherObject);
entity.sendDataWatcher(dataWatcher);*/
} }
if(entity.sneaks) { if(entity.sneaks) {
WrappedDataWatcher watcher = new WrappedDataWatcher();
if(Core.getVersion() > 12){ if(Core.getVersion() > 12){
watcher.setObject(6, getPose(true), true); ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(6, getPose(true)));
}else{ }else{
watcher.setObject(0, (byte) 2, true); ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(0, (byte) 2));
} }
ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(watcher));
/*DataWatcher dataWatcher = new DataWatcher(null);
DataWatcherObject<EntityPose> dataWatcherObject = new DataWatcherObject<>(6, DataWatcherRegistry.s);
dataWatcher.register(dataWatcherObject, EntityPose.CROUCHING);
dataWatcher.markDirty(dataWatcherObject);
entity.sendDataWatcher(dataWatcher);*/
} }
} }
}catch(InvocationTargetException e){ }catch(InvocationTargetException e){
@ -153,7 +133,7 @@ public class REntity {
SteamwarUser user = SteamwarUser.get(userId); SteamwarUser user = SteamwarUser.get(userId);
this.uuid = user.getUUID(); this.uuid = user.getUUID();
this.playerInfoData = new PlayerInfoData(WrappedGameProfile.fromOfflinePlayer(Bukkit.getOfflinePlayer(uuid)), 0, EnumWrappers.NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(user.getUserName())); this.playerInfoData = new PlayerInfoData(WrappedGameProfile.fromHandle(new GameProfile(uuid, user.getUserName())), 0, EnumWrappers.NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(user.getUserName()));
entities.put(internalId, this); entities.put(internalId, this);
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getPlayerInfoPacket()); ProtocolLibrary.getProtocolManager().broadcastServerPacket(getPlayerInfoPacket());
@ -211,18 +191,11 @@ public class REntity {
public void sneak(boolean sneaking) { public void sneak(boolean sneaking) {
sneaks = sneaking; sneaks = sneaking;
/*DataWatcher dataWatcher = new DataWatcher(null);
DataWatcherObject<EntityPose> dataWatcherObject = new DataWatcherObject<>(6, DataWatcherRegistry.s);
dataWatcher.register(dataWatcherObject, sneaking?EntityPose.CROUCHING:EntityPose.STANDING);
dataWatcher.markDirty(dataWatcherObject);*/
WrappedDataWatcher watcher = new WrappedDataWatcher();
if(Core.getVersion() > 12){ if(Core.getVersion() > 12){
watcher.setObject(6, getPose(sneaking), true); ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(6, getPose(sneaking)));
}else{ }else{
watcher.setObject(0, sneaking ? (byte) 2 : (byte) 0, true); ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(0, sneaking ? (byte) 2 : (byte) 0));
} }
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(watcher));
} }
public void setOnFire(boolean perma) { public void setOnFire(boolean perma) {
@ -232,36 +205,21 @@ public class REntity {
fireTick = -1; fireTick = -1;
} }
/*DataWatcher dataWatcher = new DataWatcher(null); ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(0, (byte) 1));
DataWatcherObject<Byte> dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a);
dataWatcher.register(dataWatcherObject, (byte) 1);
dataWatcher.markDirty(dataWatcherObject);*/
WrappedDataWatcher watcher = new WrappedDataWatcher();
watcher.setObject(0, (byte) 1, true);
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(watcher));
} }
public void setBowDrawn(boolean drawn, boolean offHand) { public void setBowDrawn(boolean drawn, boolean offHand) {
/*DataWatcher dataWatcher = new DataWatcher(null);
DataWatcherObject<Byte> dataWatcherObject = new DataWatcherObject<>(7, DataWatcherRegistry.a);
dataWatcher.register(dataWatcherObject, (byte) ((drawn ? 1 : 0) + (offHand ? 2 : 0)));
dataWatcher.markDirty(dataWatcherObject);
*/
WrappedDataWatcher watcher = new WrappedDataWatcher();
if(Core.getVersion() > 8){ if(Core.getVersion() > 8){
watcher.setObject(Core.getVersion() > 12 ? 7 : 6, (byte) ((drawn ? 1 : 0) + (offHand ? 2 : 0)), true); ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(Core.getVersion() > 12 ? 7 : 6, (byte) ((drawn ? 1 : 0) + (offHand ? 2 : 0))));
}else{ }else{
watcher.setObject(0, (byte)0x10, true); ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(0, (byte)0x10));
} }
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(watcher));
} }
public void setItem(String item, boolean enchanted, String slot) { public void setItem(String item, boolean enchanted, String slot) {
ItemStack stack = new ItemStack(Material.valueOf(item.replace("minecraft:", "").toUpperCase()), 1); ItemStack stack = new ItemStack(Material.valueOf(item.replace("minecraft:", "").toUpperCase()), 1);
if(enchanted) if(enchanted)
stack.addEnchantment(Enchantment.DURABILITY, 1); stack.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
itemSlots.put(slot, stack); itemSlots.put(slot, stack);
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getEquipmentPacket(slot, stack)); ProtocolLibrary.getProtocolManager().broadcastServerPacket(getEquipmentPacket(slot, stack));
@ -310,10 +268,12 @@ public class REntity {
bytes.write(1, pitch); bytes.write(1, pitch);
} }
private PacketContainer getDataWatcherPacket(WrappedDataWatcher dataWatcher) { private PacketContainer getDataWatcherPacket(int index, Object value) {
PacketContainer metadataPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_METADATA); PacketContainer metadataPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_METADATA);
metadataPacket.getIntegers().write(0, entityId); metadataPacket.getIntegers().write(0, entityId);
metadataPacket.getDataWatcherModifier().write(0, dataWatcher); WrappedWatchableObject watchable = new WrappedWatchableObject(new WrappedDataWatcher.WrappedDataWatcherObject(index, WrappedDataWatcher.Registry.get(value.getClass())), value);
watchable.setDirtyState(true);
metadataPacket.getWatchableCollectionModifier().write(0, Collections.singletonList(watchable));
return metadataPacket; return metadataPacket;
} }
@ -327,7 +287,7 @@ public class REntity {
private PacketContainer getHeadRotationPacket(){ private PacketContainer getHeadRotationPacket(){
PacketContainer headRotation = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_HEAD_ROTATION); PacketContainer headRotation = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_HEAD_ROTATION);
headRotation.getIntegers().write(0, entityId); headRotation.getIntegers().write(0, entityId);
headRotation.getBytes().write(1, headYaw); headRotation.getBytes().write(0, headYaw);
return headRotation; return headRotation;
} }
@ -366,7 +326,7 @@ public class REntity {
PacketContainer equipmentPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_EQUIPMENT); PacketContainer equipmentPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_EQUIPMENT);
StructureModifier<Integer> ints = equipmentPacket.getIntegers(); StructureModifier<Integer> ints = equipmentPacket.getIntegers();
ints.write(0, entityId); ints.write(0, entityId);
if(Core.getVersion() > 8){ if(Core.getVersion() == 8){
switch(slot){ switch(slot){
case "MAINHAND": case "MAINHAND":
case "OFFHAND": case "OFFHAND":

Datei anzeigen

@ -122,7 +122,7 @@ public interface Recorder {
default void entityMoves(Entity e){ default void entityMoves(Entity e){
Location location = e.getLocation(); Location location = e.getLocation();
write(0x01, e.getEntityId(), location.getX(), location.getY(), location.getZ(), location.getPitch(), location.getYaw(), (int)(VersionedCallable.call( write(0x01, e.getEntityId(), location.getX(), location.getY(), location.getZ(), location.getPitch(), location.getYaw(), (byte)(VersionedCallable.call(
new VersionedCallable<>(() -> FightWorld_8.headRotation(e), 8), new VersionedCallable<>(() -> FightWorld_8.headRotation(e), 8),
new VersionedCallable<>(() -> FightWorld_9.headRotation(e), 9), new VersionedCallable<>(() -> FightWorld_9.headRotation(e), 9),
new VersionedCallable<>(() -> FightWorld_10.headRotation(e), 10), new VersionedCallable<>(() -> FightWorld_10.headRotation(e), 10),
@ -141,7 +141,7 @@ public interface Recorder {
} }
default void entityAnimation(Entity e, int animation){ default void entityAnimation(Entity e, int animation){
write(0x04, e.getEntityId(), animation); write(0x04, e.getEntityId(), (byte)animation);
} }
default void tntSpawn(Entity e){ default void tntSpawn(Entity e){
@ -194,10 +194,10 @@ public interface Recorder {
int shortZ = block.getZ() - Config.ArenaRegion.getMinZ(); int shortZ = block.getZ() - Config.ArenaRegion.getMinZ();
if((short)blockState == blockState && shortX > 0 && shortX < 256 && shortZ > 0 && shortZ < 256){ if((short)blockState == blockState && shortX > 0 && shortX < 256 && shortZ > 0 && shortZ < 256){
//Short block packet //Short block packet
write(0x33, shortX, block.getY(), shortZ, (short)blockState); write(0x33, (byte)shortX, (byte)block.getY(), (byte)shortZ, (short)blockState);
}else{ }else{
//Block packet //Block packet
write(0x30, block.getX(), block.getY(), block.getZ(), blockState); write(0x30, block.getX(), (byte)block.getY(), block.getZ(), blockState);
} }
} }
@ -252,24 +252,28 @@ public interface Recorder {
default void write(int id, Object... objects){ default void write(int id, Object... objects){
DataOutputStream stream = getStream(); DataOutputStream stream = getStream();
try { try {
stream.writeByte(id); synchronized (stream) {
for(Object o : objects){ stream.writeByte(id);
if(o instanceof Byte) for(Object o : objects){
stream.writeByte((Byte)o); if(o instanceof Boolean)
else if(o instanceof Short) stream.writeBoolean((Boolean)o);
stream.writeShort((Short)o); else if(o instanceof Byte)
else if(o instanceof Integer) stream.writeByte((Byte)o);
stream.writeInt((Integer)o); else if(o instanceof Short)
else if(o instanceof Float) stream.writeShort((Short)o);
stream.writeFloat((Float)o); else if(o instanceof Integer)
else if(o instanceof Double) stream.writeInt((Integer)o);
stream.writeDouble((Double)o); else if(o instanceof Float)
else if(o instanceof String) stream.writeFloat((Float)o);
stream.writeUTF((String)o); else if(o instanceof Double)
else stream.writeDouble((Double)o);
throw new SecurityException("Undefined write for: " + o.getClass().getName()); else if(o instanceof String)
stream.writeUTF((String)o);
else
throw new SecurityException("Undefined write for: " + o.getClass().getName());
}
stream.flush();
} }
stream.flush();
} catch (IOException e) { } catch (IOException e) {
Bukkit.getLogger().log(Level.SEVERE, "Could not write", e); Bukkit.getLogger().log(Level.SEVERE, "Could not write", e);
try { try {