SteamWar/BauSystem
Archiviert
13
0

Tracer-entity #147

Manuell gemergt
YoyoNow hat 47 Commits von Tracer-entity nach master 2020-12-27 22:16:04 +01:00 zusammengeführt
4 geänderte Dateien mit 118 neuen und 7 gelöschten Zeilen
Nur Änderungen aus Commit d7e13f2be2 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -1,5 +1,6 @@
package de.steamwar.bausystem.tracernew; package de.steamwar.bausystem.tracernew;
import de.steamwar.bausystem.commands.CommandTPSLimiter;
import de.steamwar.bausystem.tracernew.data.RecordStatus; import de.steamwar.bausystem.tracernew.data.RecordStatus;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
@ -9,6 +10,13 @@ public class DataHolder {
public static final World world = Bukkit.getWorlds().get(0); public static final World world = Bukkit.getWorlds().get(0);
public static RecordStatus status = RecordStatus.IDLE; public static RecordStatus status = RecordStatus.IDLE;
public static long recordStart = System.currentTimeMillis();
public static long lastExplosion = System.currentTimeMillis();
public static boolean isAutoStop() {
if (!isRecordingAuto()) return false;
return System.currentTimeMillis() - lastExplosion > (20.0 / CommandTPSLimiter.getCurrentTPSLimit()) * 50 * 80;
}
public static boolean isRecording() { public static boolean isRecording() {
return status == RecordStatus.RECORD || status == RecordStatus.RECORD_AUTO; return status == RecordStatus.RECORD || status == RecordStatus.RECORD_AUTO;

Datei anzeigen

@ -0,0 +1,22 @@
package de.steamwar.bausystem.tracernew.recorder;
import de.steamwar.bausystem.tracernew.DataHolder;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
public class ExplodeListener implements Listener {
public void onEntityExplode(EntityExplodeEvent event) {
if (!(event.getEntity() instanceof TNTPrimed))
return;
if (DataHolder.isRecordingAuto())
RecordManager.stopAuto();
if (DataHolder.isIdleAuto())
RecordManager.updateAuto();
}
}

Datei anzeigen

@ -1,4 +1,87 @@
package de.steamwar.bausystem.tracernew.recorder; package de.steamwar.bausystem.tracernew.recorder;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.tracer.TraceManager;
import de.steamwar.bausystem.tracernew.DataHolder;
import de.steamwar.bausystem.tracernew.data.RecordStatus;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import static de.steamwar.bausystem.tracernew.recorder.TNTRecorder.*;
public class RecordManager { public class RecordManager {
public static void recordCommands(Player player, String[] args) {
switch (args[0].toLowerCase()) {
case "start":
start();
player.sendMessage(BauSystem.PREFIX + "§aAufnahme gestartet");
break;
case "stop":
stop();
player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer gestoppt");
break;
case "auto":
case "toggleauto":
toggleAuto();
if (DataHolder.isIdleNotAuto() || DataHolder.isRecordingNotAuto()) {
player.sendMessage(BauSystem.PREFIX + "§cAutomatischer TNT-Tracer deaktiviert");
} else {
player.sendMessage(BauSystem.PREFIX + "§aAutomatischer TNT-Tracer aktiviert");
}
break;
}
}
private static void toggleAuto() {
switch (DataHolder.status) {
case IDLE:
DataHolder.status = RecordStatus.IDLE_AUTO;
break;
case RECORD:
DataHolder.status = RecordStatus.RECORD_AUTO;
break;
case IDLE_AUTO:
DataHolder.status = RecordStatus.IDLE;
break;
case RECORD_AUTO:
DataHolder.status = RecordStatus.RECORD;
break;
default:
break;
}
}
public static void start() {
DataHolder.status = RecordStatus.RECORD;
TraceManager.startFrame();
startRecording();
}
public static void startAuto() {
DataHolder.status = RecordStatus.RECORD_AUTO;
Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§7Automatischer TNT-Tracer §8- §aAufnahme gestartet")));
TraceManager.startFrame();
startRecording();
}
public static void updateAuto() {
update();
}
public static void stop() {
DataHolder.status = RecordStatus.IDLE;
stopRecording();
TraceManager.stopFrame();
}
static void stopAuto() {
DataHolder.status = RecordStatus.IDLE_AUTO;
Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§7Automatischer TNT-Tracer §8- §aAufnahme gestoppt")));
stopRecording();
TraceManager.stopFrame();
}
} }

Datei anzeigen

@ -9,24 +9,22 @@ import org.bukkit.scheduler.BukkitTask;
import java.util.stream.Stream; import java.util.stream.Stream;
import static de.steamwar.bausystem.tracer.recorder.RecordManager.stopAuto; import static de.steamwar.bausystem.tracernew.recorder.RecordManager.stopAuto;
public class TNTRecorder { public class TNTRecorder {
private static BukkitTask task = null; private static BukkitTask task = null;
public static long recordStart = System.currentTimeMillis();
public static long lastExplosion = System.currentTimeMillis();
static void update() { static void update() {
if (task == null) return; if (task == null) return;
if (!DataHolder.isRecordingAuto()) return; if (!DataHolder.isRecordingAuto()) return;
lastExplosion = System.currentTimeMillis(); DataHolder.lastExplosion = System.currentTimeMillis();
} }
static void startRecording() { static void startRecording() {
if (task != null) return; if (task != null) return;
recordStart = System.currentTimeMillis(); DataHolder.recordStart = System.currentTimeMillis();
lastExplosion = System.currentTimeMillis(); DataHolder.lastExplosion = System.currentTimeMillis();
task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), TNTRecorder::run, 1, 1); task = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), TNTRecorder::run, 1, 1);
run(); run();
} }
@ -45,7 +43,7 @@ public class TNTRecorder {
.map(e -> (TNTPrimed)e); .map(e -> (TNTPrimed)e);
TraceListener.onTick(tntPrimedStream); TraceListener.onTick(tntPrimedStream);
if (DataHolder.isRecordingAuto() && System.currentTimeMillis() - lastExplosion > 4500) { if (DataHolder.isAutoStop()) {
stopAuto(); stopAuto();
} }
} }