SteamWar/BauSystem
Archiviert
13
0

Initial TNT-Tracer

Dieser Commit ist enthalten in:
jojo 2020-11-19 13:00:12 +01:00
Ursprung 80ac2de1c9
Commit dc79b80cc0
6 geänderte Dateien mit 128 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,37 @@
package de.steamwar.bausystem.tracernew;
import de.steamwar.bausystem.tracernew.data.RecordStatus;
import org.bukkit.Bukkit;
import org.bukkit.World;
public class DataHolder {
public static final World world = Bukkit.getWorlds().get(0);
public static RecordStatus status = RecordStatus.IDLE;
public static boolean isRecording() {
return status == RecordStatus.RECORD || status == RecordStatus.RECORD_AUTO;
}
public static boolean isRecordingAuto() {
return status == RecordStatus.RECORD_AUTO;
}
public static boolean isRecordingNotAuto() {
return status == RecordStatus.RECORD;
}
public static boolean isIdle() {
return status == RecordStatus.IDLE || status == RecordStatus.IDLE_AUTO;
}
public static boolean isIdleAuto() {
return status == RecordStatus.IDLE_AUTO;
}
public static boolean isIdleNotAuto() {
return status == RecordStatus.IDLE;
}
}

Datei anzeigen

@ -0,0 +1,4 @@
package de.steamwar.bausystem.tracernew;
public class TraceHolder {
}

Datei anzeigen

@ -0,0 +1,26 @@
package de.steamwar.bausystem.tracernew.data;
public enum RecordStatus {
RECORD("§aan", true),
RECORD_AUTO("§aan", true),
IDLE("§caus", false),
IDLE_AUTO("§eauto", false);
String name;
boolean tracing;
RecordStatus(String value, boolean tracing) {
this.name = value;
this.tracing = tracing;
}
public String getName() {
return name;
}
public boolean isTracing() {
return tracing;
}
}

Datei anzeigen

@ -0,0 +1,4 @@
package de.steamwar.bausystem.tracernew.data;
public class TNTTrace {
}

Datei anzeigen

@ -0,0 +1,4 @@
package de.steamwar.bausystem.tracernew.recorder;
public class RecordManager {
}

Datei anzeigen

@ -0,0 +1,53 @@
package de.steamwar.bausystem.tracernew.recorder;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.tracer.TraceListener;
import de.steamwar.bausystem.tracernew.DataHolder;
import org.bukkit.Bukkit;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.scheduler.BukkitTask;
import java.util.stream.Stream;
import static de.steamwar.bausystem.tracer.recorder.RecordManager.stopAuto;
public class TNTRecorder {
private static BukkitTask task = null;
public static long recordStart = System.currentTimeMillis();
public static long lastExplosion = System.currentTimeMillis();
static void update() {
if (task == null) return;
if (!DataHolder.isRecordingAuto()) return;
lastExplosion = System.currentTimeMillis();
}
static void startRecording() {
if (task != null) return;
recordStart = System.currentTimeMillis();
lastExplosion = System.currentTimeMillis();
task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), TNTRecorder::run, 1, 1);
run();
}
static void stopRecording() {
if (task == null) return;
task.cancel();
task = null;
}
private static void run() {
DataHolder.world.getEntitiesByClass(TNTPrimed.class).stream()
Stream<TNTPrimed> tntPrimedStream = DataHolder.world.getEntities()
.stream()
.filter(e -> e instanceof TNTPrimed)
.map(e -> (TNTPrimed)e);
TraceListener.onTick(tntPrimedStream);
if (DataHolder.isRecordingAuto() && System.currentTimeMillis() - lastExplosion > 4500) {
stopAuto();
}
}
}