Adding reading fight from file
Dieser Commit ist enthalten in:
Ursprung
8956c5523e
Commit
63317896b6
@ -1,15 +1,32 @@
|
||||
package de.steamwar.spectatesystem;
|
||||
|
||||
import java.io.*;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class FightfileConnection extends PacketSource {
|
||||
|
||||
public FightfileConnection(File fightFile) throws IOException {
|
||||
super(new DataInputStream(new FileInputStream(fightFile)));
|
||||
super(new DataInputStream(new GZIPInputStream(new FileInputStream(fightFile))));
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isClosed() {
|
||||
try{
|
||||
return inputStream.available() == 0;
|
||||
}catch (IOException e){
|
||||
Bukkit.getLogger().log(Level.WARNING, "On close test exception", e);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean async() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -48,4 +48,9 @@ public class FightserverConnection extends PacketSource {
|
||||
public boolean isClosed() {
|
||||
return socket.isClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean async() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ import net.minecraft.server.v1_15_R1.Block;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
@ -49,10 +50,14 @@ class PacketProcessor {
|
||||
private final Map<Byte, Integer> packetCounter = new HashMap<>();
|
||||
|
||||
private final PacketSource source;
|
||||
private final BukkitTask task;
|
||||
|
||||
public PacketProcessor(PacketSource source){
|
||||
this.source = source;
|
||||
Bukkit.getScheduler().runTaskAsynchronously(SpectateSystem.get(), this::process);
|
||||
if(source.async())
|
||||
task = Bukkit.getScheduler().runTaskAsynchronously(SpectateSystem.get(), this::process);
|
||||
else
|
||||
task = Bukkit.getScheduler().runTaskTimer(SpectateSystem.get(), this::process, 1, 1);
|
||||
}
|
||||
|
||||
private void playerJoins() throws IOException{
|
||||
@ -259,9 +264,25 @@ class PacketProcessor {
|
||||
SpectateSystem.getScoreboard().addValue(key, value);
|
||||
}
|
||||
|
||||
private void endSpectating(){
|
||||
WorldLoader.reloadWorld();
|
||||
SpectateSystem.getScoreboard().setTitle("§eKein Kampf");
|
||||
|
||||
for(Map.Entry<Byte, Integer> entry : packetCounter.entrySet()){
|
||||
System.out.println(Integer.toHexString(entry.getKey()) + " " + entry.getValue());
|
||||
}
|
||||
System.out.println("Techhiderupdates: " + debug_block_ignored + ", Unneccesary: " + debug_block_unneccesary);
|
||||
|
||||
packetCounter.clear();
|
||||
debug_block_ignored = 0;
|
||||
debug_block_unneccesary = 0;
|
||||
}
|
||||
|
||||
private void process(){
|
||||
|
||||
try{
|
||||
while(!source.isClosed()){
|
||||
boolean tickFinished = false;
|
||||
while(!source.isClosed() && !tickFinished){
|
||||
byte packetType = source.rByte();
|
||||
packetCounter.compute(packetType, (key, value) -> value != null ? value + 1 : 1);
|
||||
switch(packetType){
|
||||
@ -340,6 +361,8 @@ class PacketProcessor {
|
||||
break;
|
||||
case (byte) 0xFF:
|
||||
//Tick
|
||||
if(!source.async())
|
||||
tickFinished = true;
|
||||
break;
|
||||
default:
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Unknown packet recieved, closing");
|
||||
@ -354,12 +377,10 @@ class PacketProcessor {
|
||||
source.close();
|
||||
}
|
||||
|
||||
WorldLoader.reloadWorld();
|
||||
SpectateSystem.getScoreboard().setTitle("§eKein Kampf");
|
||||
|
||||
for(Map.Entry<Byte, Integer> entry : packetCounter.entrySet()){
|
||||
System.out.println(Integer.toHexString(entry.getKey()) + " " + entry.getValue());
|
||||
if(source.isClosed()){
|
||||
endSpectating();
|
||||
if(!source.async())
|
||||
task.cancel();
|
||||
}
|
||||
System.out.println("Techhiderupdates: " + debug_block_ignored + ", Unneccesary: " + debug_block_unneccesary);
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ import java.util.logging.Level;
|
||||
|
||||
public abstract class PacketSource {
|
||||
|
||||
private final DataInputStream inputStream;
|
||||
protected final DataInputStream inputStream;
|
||||
|
||||
protected PacketSource(DataInputStream inputStream){
|
||||
this.inputStream = inputStream;
|
||||
@ -75,4 +75,5 @@ public abstract class PacketSource {
|
||||
}
|
||||
|
||||
abstract boolean isClosed();
|
||||
abstract boolean async();
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import de.steamwar.spectatesystem.listener.JoinListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@ -47,6 +48,15 @@ public class SpectateSystem extends JavaPlugin {
|
||||
} catch (IOException e) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Could not open ConnectionAcceptor", e);
|
||||
}
|
||||
|
||||
String fightFile = System.getProperty("fightFile");
|
||||
if(fightFile != null){
|
||||
try {
|
||||
new FightfileConnection(new File(fightFile));
|
||||
} catch (IOException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Could not start reading file", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -22,7 +22,6 @@ package de.steamwar.spectatesystem.util;
|
||||
import de.steamwar.spectatesystem.Config;
|
||||
import de.steamwar.spectatesystem.SpectateSystem;
|
||||
import de.steamwar.spectatesystem.elements.REntity;
|
||||
import net.minecraft.server.v1_15_R1.Block;
|
||||
import net.minecraft.server.v1_15_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_15_R1.IBlockData;
|
||||
import net.minecraft.server.v1_15_R1.WorldServer;
|
||||
@ -56,7 +55,7 @@ public class WorldLoader {
|
||||
for(int z = cZ; z < (cZ + 1) * 16; z++){
|
||||
BlockPosition blockPos = new BlockPosition(x, y, z);
|
||||
IBlockData backupBlock = backup.getType(blockPos);
|
||||
if(Block.REGISTRY_ID.getId(backupBlock) == Block.REGISTRY_ID.getId(cchunk.getType(blockPos)))
|
||||
if(backupBlock == cworld.getType(blockPos))
|
||||
continue;
|
||||
|
||||
changedBlocks++;
|
||||
|
@ -4,7 +4,7 @@ name: SpectateSystem
|
||||
version: "1.0"
|
||||
api-version: "1.13"
|
||||
main: de.steamwar.spectatesystem.SpectateSystem
|
||||
load: STARTUP
|
||||
load: POSTWORLD
|
||||
depends:
|
||||
- SpigotCore
|
||||
- WorldEdit
|
In neuem Issue referenzieren
Einen Benutzer sperren