Tracer-entity #147
37
BauSystem_Main/src/de/steamwar/bausystem/tracernew/DataHolder.java
Normale Datei
37
BauSystem_Main/src/de/steamwar/bausystem/tracernew/DataHolder.java
Normale Datei
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package de.steamwar.bausystem.tracernew;
|
||||
|
||||
public class TraceHolder {
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package de.steamwar.bausystem.tracernew.data;
|
||||
|
||||
public class TNTTrace {
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package de.steamwar.bausystem.tracernew.recorder;
|
||||
|
||||
public class RecordManager {
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren