SteamWar/BauSystem2.0
Archiviert
12
0

Merge branch 'master' into lua
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
YoyoNow 2023-07-17 16:42:49 +02:00
Commit 445b85cfaa
50 geänderte Dateien mit 622 neuen und 784 gelöschten Zeilen

Datei anzeigen

@ -251,6 +251,18 @@ SCRIPT_MENU_GUI_ITEM_ADD_LORE = §7Click with a book to insert
SCRIPT_MENU_GUI_ENTER_NAME = §eEnter a name SCRIPT_MENU_GUI_ENTER_NAME = §eEnter a name
# Shield Printing # Shield Printing
SHIELD_PRINTING_HELP_START = §8/§eshieldprinting start §8- §7Starts the shield printing
SHIELD_PRINTING_HELP_COPY = §8/§eshieldprinting copy §8- §7Copies the shield configuration
SHIELD_PRINTING_HELP_APPLY = §8/§eshieldprinting apply §8- §7Applies the shield configuration
SHIELD_PRINTING_HELP_STOP = §8/§eshieldprinting stop §8- §7Stops the shield printing
SHIELD_PRINTING_HELP_STEP_1 = §81. §7Paste the schematic you want to use
SHIELD_PRINTING_HELP_STEP_2 = §82. §7Start the shield printing with §8/§eshieldprinting start
SHIELD_PRINTING_HELP_STEP_3 = §83. §7Wait until the shield printing is finished
SHIELD_PRINTING_HELP_STEP_4 = §84. §7Edit the shields if necessary
SHIELD_PRINTING_HELP_STEP_5 = §85. §7Copy the shields printing with §8/§eshieldprinting copy
SHIELD_PRINTING_HELP_STEP_6 = §86. §7Paste the original schematic
SHIELD_PRINTING_HELP_STEP_7 = §87. §7Apply the shield printing with §8/§eshieldprinting apply
SHIELD_PRINTING_NO_REGION = §cYou are not in a region. SHIELD_PRINTING_NO_REGION = §cYou are not in a region.
SHIELD_PRINTING_NOT_RUNNING = §cThe shield printing is not running. SHIELD_PRINTING_NOT_RUNNING = §cThe shield printing is not running.
SHIELD_PRINTING_DISALLOWED = §cYou are not allowed to use shield printing here. SHIELD_PRINTING_DISALLOWED = §cYou are not allowed to use shield printing here.
@ -416,25 +428,15 @@ KILLCHECKER_BOSSBAR = §e§l{0} §7(§e{1}%§7) §e§l{2}§7 cannons
BLOCK_COUNTER_HELP_TOGGLE = §8/§eblockcounter §8- §7Toggle on/off BLOCK_COUNTER_HELP_TOGGLE = §8/§eblockcounter §8- §7Toggle on/off
BLOCK_COUNTER_HELP_ENABLE = §8/§eblockcounter enable §8- §7Toggles BlockCounter on BLOCK_COUNTER_HELP_ENABLE = §8/§eblockcounter enable §8- §7Toggles BlockCounter on
BLOCK_COUNTER_HELP_DISABLE = §8/§eblockcounter disable §8- §7Toggles BlockCounter off BLOCK_COUNTER_HELP_DISABLE = §8/§eblockcounter disable §8- §7Toggles BlockCounter off
BLOCK_COUNTER_MESSAGE = §7Counter §8> §e{0} §7Blocks §e{1} §7TNT §e{2} §7Blocks/TNT §e{3} §7Blocks/tick BLOCK_COUNTER_MESSAGE = §7Damage §8> §e{0} §7Blocks §e{1} §7TNT §e{2} §7Blocks/TNT §e{3} §7Blocks/tick
BLOCK_COUNTER_MESSAGE_SECOND = §7Counter §8> §e{0} §7Blocks §e{1} §7TNT §e{2} §7Blocks/TNT §e{3} §7Blocks/s BLOCK_COUNTER_MESSAGE_SECOND = §7Damage §8> §e{0} §7Blocks §e{1} §7TNT §e{2} §7Blocks/TNT §e{3} §7Blocks/s
BLOCK_COUNTER_ENABLE = §7BlockCounter activated BLOCK_COUNTER_ENABLE = §7BlockCounter activated
BLOCK_COUNTER_DISABLE = §7BlockCounter deactivated BLOCK_COUNTER_DISABLE = §7BlockCounter deactivated
# DepthCounter # DepthCounter
DEPTH_COUNTER_COMMAND_ENABLE_HELP = §8/§edepthcounter enable §8- §7Activate the depth-counter DEPTH_COUNTER_MESSAGE = §7Depth §8> §7
DEPTH_COUNTER_COMMAND_DISABLE_HELP = §8/§edepthcounter disable §8- §7Deactivate the depth-counter DEPTH_COUNTER_COUNT = {0}{1}§8×{2}{3}§8×{4}{5}
DEPTH_COUNTER_COMMAND_INFO_HELP = §8/§edepthcounter info §8- §7Lists active counting modes DEPTH_COUNTER_HOVER = §7X§8ק7Y§8ק7Z
DEPTH_COUNTER_COMMAND_TOGGLE_HELP = §8/§edepthcounter toggle §8<§7CountMode§8> §8- §7Toggle counting modes
DEPTH_COUNTER_ENABLE_MESSAGE = §7You activated the depth-counter
DEPTH_COUNTER_DISABLE_MESSAGE = §7You deactivated the depth-counter
DEPTH_COUNTER_ACTIVE_MESSAGE = §7Active couting modes: §e{0}§8.
DEPTH_COUNTER_MESSAGE = §7Damage §8> §7{0}
DEPTH_COUNTER_HIGHLIGHT = §e
DEPTH_COUNTER_SEPARATOR = §7 §7
DEPTH_COUNTER_X = X: {0}
DEPTH_COUNTER_Y = Y: {0}
DEPTH_COUNTER_Z = Z: {0}
DEPTH_COUNTER_TNT = §7 TNT§8: §e{0} DEPTH_COUNTER_TNT = §7 TNT§8: §e{0}
# TPSLimit # TPSLimit
@ -478,7 +480,6 @@ TRACE_MESSAGE_ISOLATE = §aTNT-positions isolated
TRACE_MESSAGE_UNISOLATE = §cTNT-positions hidden TRACE_MESSAGE_UNISOLATE = §cTNT-positions hidden
TRACE_MESSAGE_CLICK_ISOLATE = §eClick to §aisolate§8/§cunisolate TRACE_MESSAGE_CLICK_ISOLATE = §eClick to §aisolate§8/§cunisolate
TRACE_MESSAGE_DISALLOWED = §cYou are not allowed to use the TNT-Tracer here TRACE_MESSAGE_DISALLOWED = §cYou are not allowed to use the TNT-Tracer here
TRACE_MESSAGE_NO_REGION = §cYou are not in a region
TRACE_COMMAND_HELP_START = §8/§etrace start §8- §7Starts recording of all TNT-positions TRACE_COMMAND_HELP_START = §8/§etrace start §8- §7Starts recording of all TNT-positions
TRACE_COMMAND_HELP_SINGLE = §8/§etrace single §8- §7Starts a single recording of all TNT-positions TRACE_COMMAND_HELP_SINGLE = §8/§etrace single §8- §7Starts a single recording of all TNT-positions

Datei anzeigen

@ -241,6 +241,18 @@ SCRIPT_MENU_GUI_ITEM_ADD_NAME = §eHinzufügen
SCRIPT_MENU_GUI_ITEM_ADD_LORE = §7Klicke mit einem Buch zum hinzufügen SCRIPT_MENU_GUI_ITEM_ADD_LORE = §7Klicke mit einem Buch zum hinzufügen
# Shield Printing # Shield Printing
SHIELD_PRINTING_HELP_START = §8/§eshieldprinting start §8- §7Starte das Schild drucken
SHIELD_PRINTING_HELP_COPY = §8/§eshieldprinting copy §8- §7Kopiert die Schilder
SHIELD_PRINTING_HELP_APPLY = §8/§eshieldprinting apply §8- §7Wendet die Schilder an
SHIELD_PRINTING_HELP_STOP = §8/§eshieldprinting stop §8- §7Stoppt das Schild drucken
SHIELD_PRINTING_HELP_STEP_1 = §81. §7Füge die Schematic in die Welt ein
SHIELD_PRINTING_HELP_STEP_2 = §82. §7Starte das Schild drucken mit §8/§eshieldprinting start
SHIELD_PRINTING_HELP_STEP_3 = §83. §7Warte bis alle Schilde ausgefahren sind
SHIELD_PRINTING_HELP_STEP_4 = §84. §7Editiere die Schilde wenn nötig
SHIELD_PRINTING_HELP_STEP_5 = §85. §7Kopiere das gedruckte mit §8/§eshieldprinting copy
SHIELD_PRINTING_HELP_STEP_6 = §86. §7Füge die originale Schematic wieder ein
SHIELD_PRINTING_HELP_STEP_7 = §87. §7Wende das gedruckte mit §8/§eshieldprinting apply§7 an
SHIELD_PRINTING_NO_REGION = §cDu bist in keiner Region. SHIELD_PRINTING_NO_REGION = §cDu bist in keiner Region.
SHIELD_PRINTING_NOT_RUNNING = §cShield printing ist nicht aktiv. SHIELD_PRINTING_NOT_RUNNING = §cShield printing ist nicht aktiv.
SHIELD_PRINTING_DISALLOWED = §cDu darfst Shield printing nicht benutzen. SHIELD_PRINTING_DISALLOWED = §cDu darfst Shield printing nicht benutzen.
@ -386,26 +398,13 @@ KILLCHECKER_BOSSBAR = §e§l{0} §7(§e{1}%§7) §e§l{2}§7 Kanonnen
BLOCK_COUNTER_HELP_TOGGLE = §8/§eblockcounter §8- §7Wechsel zwischen an und aus BLOCK_COUNTER_HELP_TOGGLE = §8/§eblockcounter §8- §7Wechsel zwischen an und aus
BLOCK_COUNTER_HELP_ENABLE = §8/§eblockcounter enable §8- §7Schalte den BlockCounter an BLOCK_COUNTER_HELP_ENABLE = §8/§eblockcounter enable §8- §7Schalte den BlockCounter an
BLOCK_COUNTER_HELP_DISABLE = §8/§eblockcounter disable §8- §7Schalte den BlockCounter aus BLOCK_COUNTER_HELP_DISABLE = §8/§eblockcounter disable §8- §7Schalte den BlockCounter aus
BLOCK_COUNTER_MESSAGE = §7Counter §8> §e{0} §7Blöcke §e{1} §7TNT §e{2} §7Blöcke/TNT §e{3} §7Blöcke/tick BLOCK_COUNTER_MESSAGE = §7Schaden §8> §e{0} §7Blöcke §e{1} §7TNT §e{2} §7Blöcke/TNT §e{3} §7Blöcke/tick
BLOCK_COUNTER_MESSAGE_SECOND = §7Counter §8> §e{0} §7Blöcke §e{1} §7TNT §e{2} §7Blöcke/TNT §e{3} §7Blöcke/s BLOCK_COUNTER_MESSAGE_SECOND = §7Schaden §8> §e{0} §7Blöcke §e{1} §7TNT §e{2} §7Blöcke/TNT §e{3} §7Blöcke/s
BLOCK_COUNTER_ENABLE = §7BlockCounter angemacht BLOCK_COUNTER_ENABLE = §7BlockCounter angemacht
BLOCK_COUNTER_DISABLE = §7BlockCounter ausgemacht BLOCK_COUNTER_DISABLE = §7BlockCounter ausgemacht
# DepthCounter # DepthCounter
DEPTH_COUNTER_COMMAND_ENABLE_HELP = §8/§edepthcounter enable §8- §7Aktiviere den Tiefenzähler DEPTH_COUNTER_MESSAGE = §7Tiefe §8> §7
DEPTH_COUNTER_COMMAND_DISABLE_HELP = §8/§edepthcounter disable §8- §7Deaktiviere den Tiefenzähler
DEPTH_COUNTER_COMMAND_INFO_HELP = §8/§edepthcounter info §8- §7Zähle aktive Zählmodi auf
DEPTH_COUNTER_COMMAND_TOGGLE_HELP = §8/§edepthcounter toggle §8<§7CountMode§8> §8- §7Stelle einzelne Zählmodi ein
DEPTH_COUNTER_ENABLE_MESSAGE = §7Du hast den Tiefenzähler aktiviert.
DEPTH_COUNTER_DISABLE_MESSAGE = §7Du hast den Tiefenzähler deaktiviert.
DEPTH_COUNTER_ACTIVE_MESSAGE = §7Aktive Zählmodi: §e{0}§8.
DEPTH_COUNTER_MESSAGE = §7Schaden §8> §7{0}
DEPTH_COUNTER_HIGHLIGHT = §e
DEPTH_COUNTER_SEPARATOR = §7 §7
DEPTH_COUNTER_X = X: {0}
DEPTH_COUNTER_Y = Y: {0}
DEPTH_COUNTER_Z = Z: {0}
DEPTH_COUNTER_TNT = §7TNT§8: §e{0}
# TPSLimit # TPSLimit
TICK_STEP_HELP = §8/§etick step §8<§7Ticks§8> §8- §7Spule n Ticks vor TICK_STEP_HELP = §8/§etick step §8<§7Ticks§8> §8- §7Spule n Ticks vor
@ -448,7 +447,6 @@ TRACE_MESSAGE_ISOLATE = §aTNT-Positionen isoliert
TRACE_MESSAGE_UNISOLATE = §cTNT-Positionen ausgeblendet TRACE_MESSAGE_UNISOLATE = §cTNT-Positionen ausgeblendet
TRACE_MESSAGE_CLICK_ISOLATE = §eKlicken zum §aisolieren§8/§causblenden TRACE_MESSAGE_CLICK_ISOLATE = §eKlicken zum §aisolieren§8/§causblenden
TRACE_MESSAGE_DISALLOWED = §cDu darfst hier nicht den TNT-Tracer nutzen TRACE_MESSAGE_DISALLOWED = §cDu darfst hier nicht den TNT-Tracer nutzen
TRACE_MESSAGE_NO_REGION = §cDu bist in keiner Region
TRACE_COMMAND_HELP_START = §8/§etrace start §8- §7Startet die Aufnahme aller TNT-Positionen TRACE_COMMAND_HELP_START = §8/§etrace start §8- §7Startet die Aufnahme aller TNT-Positionen
TRACE_COMMAND_HELP_SINGLE = §8/§etrace single §8- §7Startet eine einzelne Aufnahme aller TNT-Positionen TRACE_COMMAND_HELP_SINGLE = §8/§etrace single §8- §7Startet eine einzelne Aufnahme aller TNT-Positionen
@ -1017,7 +1015,7 @@ WARP_EXISTS=§7Ein Warp mit dem namen §e{0} §7existiert bereits
WARP_NAME_RESERVED=§7Du kannst nicht §c{0} §7als name für einen Warp nutzen WARP_NAME_RESERVED=§7Du kannst nicht §c{0} §7als name für einen Warp nutzen
WARP_CREATED=§7Der Warp §e{0} §7wurde erstellt WARP_CREATED=§7Der Warp §e{0} §7wurde erstellt
WARP_DELETE_HOVER=§e{0} §7löschen WARP_DELETE_HOVER=§e{0} §7löschen
WARP_DELETED=§e{0} §7wurde gelöcht WARP_DELETED=§e{0} §7wurde gelöscht
WARP_TELEPORT_HOVER=§7Zu §e{0} §7teleportieren WARP_TELEPORT_HOVER=§7Zu §e{0} §7teleportieren
WARP_MATERIAL_CHOOSE=Material auswählen WARP_MATERIAL_CHOOSE=Material auswählen
WARP_GUI_NAME=Warps WARP_GUI_NAME=Warps

Datei anzeigen

@ -21,6 +21,11 @@ package de.steamwar.bausystem;
import com.comphenix.tinyprotocol.TinyProtocol; import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.bausystem.configplayer.Config; import de.steamwar.bausystem.configplayer.Config;
import de.steamwar.bausystem.features.tpslimit.FreezeUtils;
import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils;
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
import de.steamwar.bausystem.features.tpslimit.TPSWarpUtils;
import de.steamwar.bausystem.features.world.RamUsage;
import de.steamwar.bausystem.region.loader.PrototypeLoader; import de.steamwar.bausystem.region.loader.PrototypeLoader;
import de.steamwar.bausystem.region.loader.RegionLoader; import de.steamwar.bausystem.region.loader.RegionLoader;
import de.steamwar.bausystem.region.loader.Updater; import de.steamwar.bausystem.region.loader.Updater;
@ -31,11 +36,16 @@ import lombok.Getter;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.logging.Level; import java.util.logging.Level;
public class BauSystem extends JavaPlugin implements Listener { public class BauSystem extends JavaPlugin implements Listener {
@ -73,6 +83,7 @@ public class BauSystem extends JavaPlugin implements Listener {
new Updater(RegionLoader.file, RegionLoader::load); new Updater(RegionLoader.file, RegionLoader::load);
LinkageUtils.link(); LinkageUtils.link();
RamUsage.init();
// This could disable any watchdog stuff. We need to investigate if this is a problem. // This could disable any watchdog stuff. We need to investigate if this is a problem.
/* /*
@ -121,4 +132,45 @@ public class BauSystem extends JavaPlugin implements Listener {
} }
})); }));
} }
public static BukkitTask runTaskLater(Plugin plugin, Runnable runnable, long delay) {
return new BukkitRunnable() {
private int counter = 1;
@Override
public void run() {
if (FreezeUtils.isFrozen()) return;
if (counter >= delay) {
runnable.run();
cancel();
return;
}
counter++;
}
}.runTaskTimer(plugin, 0, 1);
}
public static BukkitTask runTaskTimer(Plugin plugin, Runnable runnable, long delay, long period) {
return new BukkitRunnable() {
private int counter = 1;
private boolean first = true;
@Override
public void run() {
if (FreezeUtils.isFrozen()) return;
if (counter >= (first ? delay : period)) {
first = false;
runnable.run();
counter = 1;
return;
}
counter++;
}
}.runTaskTimer(plugin, 0, 1);
}
public static void runTaskTimer(Plugin plugin, Consumer<BukkitTask> consumer, long delay, long period) {
AtomicReference<BukkitTask> task = new AtomicReference<>();
task.set(runTaskTimer(plugin, () -> consumer.accept(task.get()), delay, period));
}
} }

Datei anzeigen

@ -88,7 +88,7 @@ public class AutostartListener implements Listener {
} else { } else {
BauSystem.MESSAGE.send("AUTOSTART_MESSAGE_START", player); BauSystem.MESSAGE.send("AUTOSTART_MESSAGE_START", player);
} }
regionStartTime.put(region, TPSUtils.currentTick.get()); regionStartTime.put(region, TPSUtils.currentRealTick.get());
} }
@EventHandler @EventHandler
@ -101,7 +101,7 @@ public class AutostartListener implements Listener {
if (!regionStartTime.containsKey(region)) return; if (!regionStartTime.containsKey(region)) return;
if (!region.hasType(RegionType.TESTBLOCK)) return; if (!region.hasType(RegionType.TESTBLOCK)) return;
if (!region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)) return; if (!region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)) return;
long tickDiff = TPSUtils.currentTick.get() - regionStartTime.remove(region); long tickDiff = TPSUtils.currentRealTick.get() - regionStartTime.remove(region);
RegionUtils.message(region, player -> { RegionUtils.message(region, player -> {
return BauSystem.MESSAGE.parse("AUTOSTART_MESSAGE_RESULT1", player, new SimpleDateFormat(BauSystem.MESSAGE.parse("AUTOSTART_MESSAGE_DATE_PATTERN", player)).format(new Date(tickDiff * 50))); return BauSystem.MESSAGE.parse("AUTOSTART_MESSAGE_RESULT1", player, new SimpleDateFormat(BauSystem.MESSAGE.parse("AUTOSTART_MESSAGE_DATE_PATTERN", player)).format(new Date(tickDiff * 50)));
}); });

Datei anzeigen

@ -0,0 +1,99 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.cannon;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.cannon.depth.Depth;
import de.steamwar.bausystem.features.cannon.depth.DepthManager;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.utils.RegionType;
import de.steamwar.linkage.Linked;
import org.bukkit.Bukkit;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Linked
public class CannonDetector implements Listener {
private Map<TNTPrimed, Vector> velocities = new HashMap<>();
@EventHandler
public void onEntityExplode(EntityExplodeEvent event) {
if (!(event.getEntity() instanceof TNTPrimed)) {
return;
}
TNTPrimed tnt = (TNTPrimed) event.getEntity();
DepthManager.update(tnt, event.blockList());
List<TNTPrimed> tnts = Bukkit.getWorlds().get(0).getEntitiesByClass(TNTPrimed.class)
.stream()
.filter(entity -> entity != tnt)
.filter(entity -> entity.getFuseTicks() > 1)
.filter(entity -> entity.getLocation().distance(event.getLocation()) <= 8)
.collect(Collectors.toList());
if (tnts.isEmpty()) {
return;
}
boolean isEmpty = velocities.isEmpty();
tnts.forEach(tntPrimed -> {
velocities.put(tntPrimed, tntPrimed.getVelocity().clone());
});
if (!isEmpty) {
return;
}
BauSystem.runTaskLater(BauSystem.getInstance(), () -> {
Map<CannonKey, List<TNTPrimed>> grouped = new HashMap<>();
velocities.forEach((tntPrimed, vector) -> {
grouped.computeIfAbsent(new CannonKey(round(tntPrimed.getLocation().toVector()), round(vector)), ignored -> new ArrayList<>()).add(tntPrimed);
});
grouped.forEach((cannonKey, tntPrimeds) -> {
if (tntPrimeds.size() <= 5) return;
Region region = Region.getRegion(tntPrimeds.get(0).getLocation());
if (region.isGlobal()) return;
if (!region.hasType(RegionType.TESTBLOCK)) return;
Depth depth = new Depth(region);
DepthManager.init(tntPrimeds, depth);
});
velocities.clear();
}, 1);
}
private Vector round(Vector vector) {
vector.multiply(10000);
vector.setX(Math.round(vector.getX()));
vector.setY(Math.round(vector.getY()));
vector.setZ(Math.round(vector.getZ()));
return vector;
}
}

Datei anzeigen

@ -0,0 +1,33 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.cannon;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.bukkit.util.Vector;
@AllArgsConstructor
@EqualsAndHashCode
@Getter
public final class CannonKey {
private Vector locationVector;
private Vector velocityVector;
}

Datei anzeigen

@ -0,0 +1,110 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.cannon.depth;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.RegionUtils;
import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class Depth {
private Region region;
private Vector minVector = null;
private Vector maxVector = null;
private int tntCount = 0;
public Depth(Region region) {
this.region = region;
}
public void update(List<Block> blocks) {
List<Block> blocksList = blocks.stream()
.filter(block -> region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION))
.collect(Collectors.toList());
if (blocksList.isEmpty()) return;
tntCount++;
for (Block block : blocksList) {
internalUpdate(block);
}
}
public void finish() {
if (maxVector == null || minVector == null) return;
Vector dimensions = maxVector.subtract(minVector);
dimensions.setX(Math.abs(dimensions.getX()));
dimensions.setY(Math.abs(dimensions.getY()));
dimensions.setZ(Math.abs(dimensions.getZ()));
RegionUtils.message(region, player -> {
player.spigot().sendMessage(getMessage(player, dimensions.getBlockX() + 1, dimensions.getBlockY() + 1, dimensions.getBlockZ() + 1, tntCount));
});
}
private void internalUpdate(Block block) {
if (minVector == null) {
minVector = block.getLocation().toVector();
}
minVector.setX(Math.min(minVector.getX(), block.getX()));
minVector.setY(Math.min(minVector.getY(), block.getY()));
minVector.setZ(Math.min(minVector.getZ(), block.getZ()));
if (maxVector == null) {
maxVector = block.getLocation().toVector();
}
maxVector.setX(Math.max(maxVector.getX(), block.getX()));
maxVector.setY(Math.max(maxVector.getY(), block.getY()));
maxVector.setZ(Math.max(maxVector.getZ(), block.getZ()));
}
private static BaseComponent[] getMessage(Player player, int x, int y, int z, int tntCount) {
final Set<Integer> dimensions = new HashSet<>();
dimensions.add(x);
dimensions.add(y);
dimensions.add(z);
int max = getMax(dimensions);
TextComponent headerComponent = new TextComponent(BauSystem.MESSAGE.parse("DEPTH_COUNTER_MESSAGE", player));
TextComponent depthComponent = new TextComponent(BauSystem.MESSAGE.parse("DEPTH_COUNTER_COUNT", player, x == max ? "§e" : "§7", x, y == max ? "§e" : "§7", y, z == max ? "§e" : "§7", z));
depthComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent(BauSystem.MESSAGE.parse("DEPTH_COUNTER_HOVER", player))}));
TextComponent tntComponent = new TextComponent(BauSystem.MESSAGE.parse("DEPTH_COUNTER_TNT", player, tntCount));
return new BaseComponent[]{headerComponent, depthComponent, tntComponent};
}
private static int getMax(Set<Integer> values) {
return values.stream().max(Integer::compare).orElse(0);
}
}

Datei anzeigen

@ -0,0 +1,48 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.cannon.depth;
import lombok.experimental.UtilityClass;
import org.bukkit.block.Block;
import org.bukkit.entity.TNTPrimed;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@UtilityClass
public class DepthManager {
private Map<TNTPrimed, Depth> depths = new HashMap<>();
public void init(List<TNTPrimed> list, Depth depth) {
for (TNTPrimed tnt : list) {
depths.putIfAbsent(tnt, depth);
}
}
public void update(TNTPrimed tnt, List<Block> blocks) {
Depth depth = depths.remove(tnt);
if (depth == null) return;
depth.update(blocks);
if (depths.containsValue(depth)) return;
depth.finish();
}
}

Datei anzeigen

@ -293,7 +293,7 @@ public class KillcheckerVisualizer {
private void updateBossBar(Player player) { private void updateBossBar(Player player) {
BauSystemBossbar bossbar = bossBarService.get(player, region, "killchecker"); BauSystemBossbar bossbar = bossBarService.get(player, region, "killchecker");
bossbar.setTitle(BauSystem.MESSAGE.parse("KILLCHECKER_BOSSBAR", player, kills, ((int) (percent * 1000) / 10.0), cannonCount)); bossbar.setTitle(BauSystem.MESSAGE.parse("KILLCHECKER_BOSSBAR", player, kills, ((int) (percent * 1000) / 10.0), cannonCount));
bossbar.setProgress(percent); bossbar.setProgress(Math.min(Math.max(percent, 0), 1));
if (percent >= 0.35) { if (percent >= 0.35) {
bossbar.setColor(BarColor.RED); bossbar.setColor(BarColor.RED);

Datei anzeigen

@ -71,7 +71,7 @@ public class Loader implements Listener {
if (currentElement >= elements.size()) { if (currentElement >= elements.size()) {
currentElement = 0; currentElement = 0;
if (totalDelay == 0) { if (totalDelay == 0) {
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), this::next, 1); BauSystem.runTaskLater(BauSystem.getInstance(), this::next, 1);
return; return;
} }
totalDelay = 0; totalDelay = 0;

Datei anzeigen

@ -46,7 +46,7 @@ public class LoaderRecorder implements Listener {
private Player player; private Player player;
private List<LoaderElement> loaderElementList; private List<LoaderElement> loaderElementList;
private long lastInteraction = TPSUtils.currentTick.get(); private long lastInteraction = TPSUtils.currentRealTick.get();
public LoaderRecorder(Player player, List<LoaderElement> loaderElementList) { public LoaderRecorder(Player player, List<LoaderElement> loaderElementList) {
this.player = player; this.player = player;
@ -63,15 +63,15 @@ public class LoaderRecorder implements Listener {
private void addWaitTime(boolean last) { private void addWaitTime(boolean last) {
if (loaderElementList.isEmpty()) { if (loaderElementList.isEmpty()) {
lastInteraction = TPSUtils.currentTick.get(); lastInteraction = TPSUtils.currentRealTick.get();
return; return;
} }
if (loaderElementList.get(loaderElementList.size() - 1) instanceof LoaderWait) { if (loaderElementList.get(loaderElementList.size() - 1) instanceof LoaderWait) {
return; return;
} }
long diff = TPSUtils.currentTick.get() - lastInteraction; long diff = TPSUtils.currentRealTick.get() - lastInteraction;
if (last && diff > 160) diff = 160; if (last && diff > 160) diff = 160;
lastInteraction = TPSUtils.currentTick.get(); lastInteraction = TPSUtils.currentRealTick.get();
loaderElementList.add(new LoaderWait(diff)); loaderElementList.add(new LoaderWait(diff));
} }
@ -165,10 +165,10 @@ public class LoaderRecorder implements Listener {
Long startTime = blockSet.remove(fromBlock.getLocation()); Long startTime = blockSet.remove(fromBlock.getLocation());
LoaderMovement loaderMovement = movementSet.remove(fromBlock.getLocation()); LoaderMovement loaderMovement = movementSet.remove(fromBlock.getLocation());
if (loaderMovement != null && startTime != null) { if (loaderMovement != null && startTime != null) {
loaderMovement.setInitialTicks(TPSUtils.currentTick.get() - startTime); loaderMovement.setInitialTicks(TPSUtils.currentRealTick.get() - startTime);
} }
blockSet.put(toBlock.getLocation(), TPSUtils.currentTick.get()); blockSet.put(toBlock.getLocation(), TPSUtils.currentRealTick.get());
addWaitTime(false); addWaitTime(false);
loaderMovement = null; loaderMovement = null;

Datei anzeigen

@ -52,11 +52,11 @@ public class LoaderLever extends LoaderInteractionElement<LoaderLever.LeverSetti
private SWItem menu(Player player, boolean noop, boolean interact, boolean power) { private SWItem menu(Player player, boolean noop, boolean interact, boolean power) {
SWItem swItem; SWItem swItem;
if (noop) { if (noop) {
swItem = new SWItem(Material.STRUCTURE_VOID, translateItemName("LOADER_LEVER", "LOADER_INTERACTION_NOOP", player)); swItem = new SWItem(Material.STRUCTURE_VOID, translateItemName("LOADER_BUTTON_SWITCH", "LOADER_INTERACTION_NOOP", player));
} else if (interact) { } else if (interact) {
swItem = new SWItem(Material.STICK, translateItemName("LOADER_LEVER", "LOADER_INTERACTION_INTERACT", player)); swItem = new SWItem(Material.STICK, translateItemName("LOADER_BUTTON_SWITCH", "LOADER_INTERACTION_INTERACT", player));
} else { } else {
swItem = new SWItem(Material.LEVER, translateItemName("LOADER_LEVER", power ? "LOADER_INTERACTION_ACTIVE" : "LOADER_INTERACTION_INACTIVE", player)); swItem = new SWItem(Material.LEVER, translateItemName("LOADER_BUTTON_SWITCH", power ? "LOADER_INTERACTION_ACTIVE" : "LOADER_INTERACTION_INACTIVE", player));
} }
swItem.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", player))); swItem.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", player)));
return swItem; return swItem;

Datei anzeigen

@ -112,7 +112,7 @@ public class LoaderMovement extends LoaderInteractionElement<LoaderMovement.Move
if (ticks >= 0) { if (ticks >= 0) {
boolean finalWaitFor = waitFor; boolean finalWaitFor = waitFor;
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { BauSystem.runTaskLater(BauSystem.getInstance(), () -> {
if (blockData instanceof AnaloguePowerable) { if (blockData instanceof AnaloguePowerable) {
AnaloguePowerable analoguePowerable = (AnaloguePowerable) blockData; AnaloguePowerable analoguePowerable = (AnaloguePowerable) blockData;
analoguePowerable.setPower(0); analoguePowerable.setPower(0);

Datei anzeigen

@ -49,7 +49,7 @@ public class LoaderTNT implements LoaderElement {
public void execute(Runnable nextAction) { public void execute(Runnable nextAction) {
Block block = location.getBlock(); Block block = location.getBlock();
if (block.getType() != Material.AIR && block.getType() != Material.WATER) { if (block.getType() != Material.AIR && block.getType() != Material.WATER) {
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> execute(nextAction), 1); BauSystem.runTaskLater(BauSystem.getInstance(), () -> execute(nextAction), 1);
return; return;
} }

Datei anzeigen

@ -87,7 +87,7 @@ public class LoaderTicks extends LoaderInteractionElement<LoaderTicks.TicksSetti
update(powerable); update(powerable);
boolean finalWaitFor = waitFor; boolean finalWaitFor = waitFor;
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { BauSystem.runTaskLater(BauSystem.getInstance(), () -> {
powerable.setPowered(false); powerable.setPowered(false);
location.getBlock().setBlockData(powerable, true); location.getBlock().setBlockData(powerable, true);
update(powerable); update(powerable);

Datei anzeigen

@ -58,7 +58,7 @@ public class LoaderWait implements LoaderElement, Listener {
nextAction.run(); nextAction.run();
return; return;
} }
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), nextAction, delay); BauSystem.runTaskLater(BauSystem.getInstance(), nextAction, delay);
} }
@Override @Override

Datei anzeigen

@ -65,9 +65,9 @@ public class Loadtimer implements Listener {
this.region = region; this.region = region;
this.stage = Stage.WAITING; this.stage = Stage.WAITING;
Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance()); Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance());
task = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { task = BauSystem.runTaskTimer(BauSystem.getInstance(), () -> {
if (stage == Stage.COUNTING) { if (stage == Stage.COUNTING) {
long timeSinceStart = TPSUtils.currentTick.get() - start; long timeSinceStart = TPSUtils.currentRealTick.get() - start;
long timeSinceHalf = timeSinceStart / 2; long timeSinceHalf = timeSinceStart / 2;
double timeSec = (timeSinceStart / 20d); double timeSec = (timeSinceStart / 20d);
String sec = new DecimalFormat("#.#").format(timeSec); String sec = new DecimalFormat("#.#").format(timeSec);
@ -119,7 +119,7 @@ public class Loadtimer implements Listener {
public void onTntPlace(BlockPlaceEvent event) { public void onTntPlace(BlockPlaceEvent event) {
if (stage == Stage.WAITING) { if (stage == Stage.WAITING) {
this.stage = Stage.COUNTING; this.stage = Stage.COUNTING;
this.start = TPSUtils.currentTick.get(); this.start = TPSUtils.currentRealTick.get();
} }
if (stage == Stage.COUNTING) { if (stage == Stage.COUNTING) {
@ -146,9 +146,9 @@ public class Loadtimer implements Listener {
public void onTntSpawn() { public void onTntSpawn() {
if ((stage == Stage.COUNTING || stage == Stage.ACTIVATED)) { if ((stage == Stage.COUNTING || stage == Stage.ACTIVATED)) {
stage = Stage.IGNITION; stage = Stage.IGNITION;
ignite = TPSUtils.currentTick.get(); ignite = TPSUtils.currentRealTick.get();
if (activate == -1) if (activate == -1)
activate = TPSUtils.currentTick.get(); activate = TPSUtils.currentRealTick.get();
if (finishOnActive) { if (finishOnActive) {
stage = Stage.END; stage = Stage.END;
print(); print();
@ -160,14 +160,14 @@ public class Loadtimer implements Listener {
public void onTntExplode(EntityExplodeEvent event) { public void onTntExplode(EntityExplodeEvent event) {
if (region.inRegion(event.getLocation(), RegionType.BUILD, RegionExtensionType.EXTENSION) && stage == Stage.IGNITION) { if (region.inRegion(event.getLocation(), RegionType.BUILD, RegionExtensionType.EXTENSION) && stage == Stage.IGNITION) {
stage = Stage.END; stage = Stage.END;
explode = TPSUtils.currentTick.get(); explode = TPSUtils.currentRealTick.get();
print(); print();
delete(); delete();
} }
} }
private void setActivate() { private void setActivate() {
activate = TPSUtils.currentTick.get(); activate = TPSUtils.currentRealTick.get();
stage = Stage.ACTIVATED; stage = Stage.ACTIVATED;
if (finishOnActive) { if (finishOnActive) {
print(); print();

Datei anzeigen

@ -89,18 +89,18 @@ public class RedstonetesterUtils {
tick = null; tick = null;
return; return;
} }
if (TPSUtils.currentTick.get() - lastTick > 100) { if (TPSUtils.currentRealTick.get() - lastTick > 100) {
tick = null; tick = null;
} }
if (loc1.equals(location)) { if (loc1.equals(location)) {
lastTick = TPSUtils.currentTick.get(); lastTick = TPSUtils.currentRealTick.get();
if (tick == null) { if (tick == null) {
tick = TPSUtils.currentTick.get(); tick = TPSUtils.currentRealTick.get();
} }
return; return;
} }
if (tick != null && loc2.equals(location)) { if (tick != null && loc2.equals(location)) {
BauSystem.MESSAGE.send("RT_RESULT", player, (TPSUtils.currentTick.get() - tick), ((TPSUtils.currentTick.get() - tick) / 2.0)); BauSystem.MESSAGE.send("RT_RESULT", player, (TPSUtils.currentRealTick.get() - tick), ((TPSUtils.currentRealTick.get() - tick) / 2.0));
} }
} }

Datei anzeigen

@ -100,7 +100,9 @@ public class FreezeListener implements Listener, ScoreboardElement {
@EventHandler @EventHandler
public void onInventoryMoveEvent(InventoryMoveItemEvent e) { public void onInventoryMoveEvent(InventoryMoveItemEvent e) {
if (Region.getRegion(e.getDestination().getLocation()).get(Flag.FREEZE) == FreezeMode.ACTIVE) { if (e.getDestination().getLocation() != null && Region.getRegion(e.getDestination().getLocation()).get(Flag.FREEZE) == FreezeMode.ACTIVE) {
e.setCancelled(true);
} else if (e.getSource().getLocation() != null && Region.getRegion(e.getSource().getLocation()).get(Flag.FREEZE) == FreezeMode.ACTIVE) {
e.setCancelled(true); e.setCancelled(true);
} }
} }

Datei anzeigen

@ -23,7 +23,6 @@ import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar; import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar;
import de.steamwar.bausystem.utils.bossbar.BossBarService; import de.steamwar.bausystem.utils.bossbar.BossBarService;
import de.steamwar.bausystem.utils.bossbar.RegionedBossbar;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -38,13 +37,9 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.EntityBlockFormEvent;
import org.bukkit.event.entity.EntityAirChangeEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
@ -57,7 +52,7 @@ public class ShieldPrinting implements Listener {
private static final World WORLD = Bukkit.getWorlds().get(0); private static final World WORLD = Bukkit.getWorlds().get(0);
static { static {
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { BauSystem.runTaskTimer(BauSystem.getInstance(), () -> {
ShieldPrintingCommand.SHIELD_PRINTING_MAP.values().forEach(shieldPrinting -> { ShieldPrintingCommand.SHIELD_PRINTING_MAP.values().forEach(shieldPrinting -> {
shieldPrinting.fallingBlocks.replaceAll((entity, location) -> { shieldPrinting.fallingBlocks.replaceAll((entity, location) -> {
if (entity.isDead()) return null; if (entity.isDead()) return null;

Datei anzeigen

@ -38,6 +38,17 @@ public class ShieldPrintingCommand extends SWCommand implements Listener {
public ShieldPrintingCommand() { public ShieldPrintingCommand() {
super("shieldprinting"); super("shieldprinting");
addDefaultHelpMessage("SHIELD_PRINTING_HELP_START");
addDefaultHelpMessage("SHIELD_PRINTING_HELP_COPY");
addDefaultHelpMessage("SHIELD_PRINTING_HELP_APPLY");
addDefaultHelpMessage("SHIELD_PRINTING_HELP_STOP");
addDefaultHelpMessage("SHIELD_PRINTING_HELP_STEP_1");
addDefaultHelpMessage("SHIELD_PRINTING_HELP_STEP_2");
addDefaultHelpMessage("SHIELD_PRINTING_HELP_STEP_3");
addDefaultHelpMessage("SHIELD_PRINTING_HELP_STEP_4");
addDefaultHelpMessage("SHIELD_PRINTING_HELP_STEP_5");
addDefaultHelpMessage("SHIELD_PRINTING_HELP_STEP_6");
addDefaultHelpMessage("SHIELD_PRINTING_HELP_STEP_7");
} }
static final Map<Region, ShieldPrinting> SHIELD_PRINTING_MAP = new HashMap<>(); static final Map<Region, ShieldPrinting> SHIELD_PRINTING_MAP = new HashMap<>();

Datei anzeigen

@ -245,7 +245,7 @@ public class TNTSimulator {
}); });
AtomicInteger currentTick = new AtomicInteger(0); AtomicInteger currentTick = new AtomicInteger(0);
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), bukkitTask -> { BauSystem.runTaskTimer(BauSystem.getInstance(), bukkitTask -> {
int tick = currentTick.get(); int tick = currentTick.get();
if (tick > maxTick.get()) bukkitTask.cancel(); if (tick > maxTick.get()) bukkitTask.cancel();
currentTick.incrementAndGet(); currentTick.incrementAndGet();

Datei anzeigen

@ -36,13 +36,13 @@ public interface LaufbauState {
default String eta(Player p, long start, int done, int total) { default String eta(Player p, long start, int done, int total) {
if (total == 0) return ""; if (total == 0) return "";
long elapsed = System.currentTimeMillis() - start; long elapsed = System.currentTimeMillis() - start;
long eta = (long) (elapsed / (done / (double) total) - elapsed); long eta = ((long) (elapsed / (done / (double) total) - elapsed)) * 1000000;
if (eta > 86399999999999L) { if (eta > 86399999999999L) {
return LocalTime.ofNanoOfDay(86399999999999L).format(DateTimeFormatter.ofPattern(BauSystem.MESSAGE.parse("TIME", p))); return LocalTime.ofNanoOfDay(86399999999999L).format(DateTimeFormatter.ofPattern(BauSystem.MESSAGE.parse("TIME", p)));
} }
if (eta < 0) { if (eta < 0) {
return LocalTime.ofNanoOfDay(0).format(DateTimeFormatter.ofPattern(BauSystem.MESSAGE.parse("TIME", p))); return LocalTime.ofNanoOfDay(0).format(DateTimeFormatter.ofPattern(BauSystem.MESSAGE.parse("TIME", p)));
} }
return LocalTime.ofNanoOfDay(eta * 1000000).format(DateTimeFormatter.ofPattern(BauSystem.MESSAGE.parse("TIME", p))); return LocalTime.ofNanoOfDay(eta).format(DateTimeFormatter.ofPattern(BauSystem.MESSAGE.parse("TIME", p)));
} }
} }

Datei anzeigen

@ -40,24 +40,26 @@ public class BlockCount {
private Region region; private Region region;
private int count = 0; private int count = 0;
private int tntCount = 0; private int tntCount = 0;
private final long tick = TPSUtils.currentTick.get(); private final long tick = TPSUtils.currentRealTick.get();
private long lastUpdate = TPSUtils.currentTick.get(); private long lastUpdate = TPSUtils.currentRealTick.get();
public BlockCount(Region region) { public BlockCount(Region region) {
this.region = region; this.region = region;
if (bukkitTask == null) { if (bukkitTask == null) {
bukkitTask = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { bukkitTask = BauSystem.runTaskTimer(BauSystem.getInstance(), () -> {
Set<Region> toRemove = new HashSet<>(); Set<Region> toRemove = new HashSet<>();
for (BlockCount blockCount : BlockCounter.blockCountMap.values()) { for (BlockCount blockCount : BlockCounter.blockCountMap.values()) {
if (TPSUtils.currentTick.get() - blockCount.lastUpdate < 60) { if (TPSUtils.currentRealTick.get() - blockCount.lastUpdate < 60) {
continue; continue;
} }
toRemove.add(blockCount.region); toRemove.add(blockCount.region);
if (count > 10) { if (count > 10) {
RegionUtils.message(blockCount.region, player -> BlockCounter.getMessage(player, blockCount.count, blockCount.tntCount, blockCount.tick, blockCount.lastUpdate)); RegionUtils.message(blockCount.region, player -> {
return BlockCounter.getMessage(player, blockCount.count, blockCount.tntCount, blockCount.tick, blockCount.lastUpdate);
});
} }
} }
toRemove.forEach(BlockCounter.blockCountMap::remove); toRemove.forEach(BlockCounter.blockCountMap::remove);
@ -72,6 +74,6 @@ public class BlockCount {
public void update(List<Block> blocks) { public void update(List<Block> blocks) {
count += blocks.size(); count += blocks.size();
tntCount++; tntCount++;
lastUpdate = TPSUtils.currentTick.get(); lastUpdate = TPSUtils.currentRealTick.get();
} }
} }

Datei anzeigen

@ -1,36 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.testblock.depthcounter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public enum CountMode {
X,
Y,
Z;
public static Set<CountMode> ALL() {
return new HashSet<>(Arrays.asList(values()));
}
}

Datei anzeigen

@ -1,131 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.testblock.depthcounter;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.RegionUtils;
import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class Depth {
private static BukkitTask bukkitTask = null;
private Region region;
private int tntCount = 1;
private Vector minVector = null;
private Vector maxVector = null;
private long lastUpdate = TPSUtils.currentTick.get();
public Depth(Region region, List<Block> blocks) {
if (blocks.isEmpty()) {
throw new SecurityException();
}
this.region = region;
blocks.forEach(block -> {
if (minVector == null) {
minVector = DepthCounter.blockVector(block.getLocation().toVector());
maxVector = DepthCounter.blockVector(block.getLocation().toVector());
} else {
internalUpdate(block);
}
});
if (bukkitTask == null) {
bukkitTask = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
Set<Depth> toRemove = new HashSet<>();
for (Set<Depth> value : DepthCounter.depthMap.values()) {
value.forEach(depth -> {
if (TPSUtils.currentTick.get() - depth.lastUpdate < 10) {
return;
}
Vector dimensions = depth.maxVector.subtract(depth.minVector);
dimensions.setX(Math.abs(dimensions.getX()));
dimensions.setY(Math.abs(dimensions.getY()));
dimensions.setZ(Math.abs(dimensions.getZ()));
if (depth.tntCount > 4 && dimensions.getX() != 0 && dimensions.getY() != 0 && dimensions.getZ() != 0) {
RegionUtils.message(depth.region, player -> DepthCounter.getMessage(player, dimensions.getBlockX() + 1, dimensions.getBlockY() + 1, dimensions.getBlockZ() + 1, depth.tntCount));
}
Set<Depth> depthSet = DepthCounter.depthMap.get(depth.region);
if (depthSet == null) {
return;
}
toRemove.add(depth);
});
}
toRemove.forEach(depth -> {
Set<Depth> depthSet = DepthCounter.depthMap.get(depth.region);
depthSet.remove(depth);
if (depthSet.isEmpty()) {
DepthCounter.depthMap.remove(depth.region);
}
});
if (DepthCounter.depthMap.isEmpty()) {
bukkitTask.cancel();
bukkitTask = null;
}
}, 2, 2);
}
}
public boolean update(List<Block> blocks) {
double totalBlastResistanceBroken = blocks.stream().filter(block -> {
Vector vector = DepthCounter.blockVector(block.getLocation().toVector());
return vector.getX() >= minVector.getX()
&& vector.getY() >= minVector.getY()
&& vector.getZ() >= minVector.getZ()
&& vector.getX() <= maxVector.getX()
&& vector.getY() <= maxVector.getY()
&& vector.getZ() <= maxVector.getZ();
}).filter(block -> block.getType().isBlock())
.mapToDouble(block -> block.getType().getBlastResistance())
.sum();
if (totalBlastResistanceBroken < 18) {
return false;
}
lastUpdate = TPSUtils.currentTick.get();
blocks.forEach(this::internalUpdate);
tntCount++;
return true;
}
private void internalUpdate(Block block) {
minVector.setX(Math.min(minVector.getX(), block.getX()));
minVector.setY(Math.min(minVector.getY(), block.getY()));
minVector.setZ(Math.min(minVector.getZ(), block.getZ()));
maxVector.setX(Math.max(maxVector.getX(), block.getX()));
maxVector.setY(Math.max(maxVector.getY(), block.getY()));
maxVector.setZ(Math.max(maxVector.getZ(), block.getZ()));
}
}

Datei anzeigen

@ -1,142 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.testblock.depthcounter;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.configplayer.Config;
import de.steamwar.bausystem.region.Region;
import lombok.experimental.UtilityClass;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import yapion.hierarchy.types.YAPIONObject;
import java.util.*;
import java.util.stream.Collectors;
@UtilityClass
public class DepthCounter {
public final Map<Region, Set<Depth>> depthMap = new HashMap<>();
private static final YAPIONObject DEFAULT = new YAPIONObject().add("X", "").add("Y", "").add("Z", "");
public void toggleMode(final Player p, final CountMode countMode) {
if (isActive(p, countMode)) {
removeMode(p, countMode);
} else {
addMode(p, countMode);
}
}
public boolean isActive(final Player p, final CountMode countMode) {
return Config.getInstance().get(p).getYAPIONObjectOrSetDefault("depth-counter", (YAPIONObject) DEFAULT.copy()).containsKey(countMode.name());
}
public void addMode(final Player p, final CountMode countMode) {
if (!isActive(p, countMode)) {
Config.getInstance().get(p).getObject("depth-counter").add(countMode.name(), "");
}
}
public void removeMode(final Player p, final CountMode countMode) {
if (isActive(p, countMode)) {
Config.getInstance().get(p).getObject("depth-counter").remove(countMode.name());
}
}
public void setModes(final Player p, final Set<CountMode> countModes) {
YAPIONObject yapionObject = new YAPIONObject();
countModes.forEach(countMode -> yapionObject.put(countMode.name(), ""));
Config.getInstance().get(p).put("depth-counter", yapionObject);
}
public void removePlayer(final Player p) {
Config.getInstance().get(p).put("depth-counter", new YAPIONObject());
}
public Vector blockVector(Vector vector) {
return new Vector(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
}
public Set<CountMode> getModes(Player p) {
Set<CountMode> countModes = new HashSet<>();
Config.getInstance().get(p).getYAPIONObjectOrSetDefault("depth-counter", (YAPIONObject) DEFAULT.copy()).forEach((s, yapionAnyType) -> {
countModes.add(CountMode.valueOf(s));
});
return countModes.stream().sorted().collect(Collectors.toCollection(LinkedHashSet::new));
}
public boolean hasModes(Player p) {
return !getModes(p).isEmpty();
}
public int getMax(int... values) {
return Arrays.stream(values).max().orElse(0);
}
public int getMax(Set<Integer> values) {
return values.stream().max(Integer::compare).orElse(0);
}
public String getMessage(Player player, int x, int y, int z, int tntCount) {
final boolean xActive = DepthCounter.isActive(player, CountMode.X);
final boolean yActive = DepthCounter.isActive(player, CountMode.Y);
final boolean zActive = DepthCounter.isActive(player, CountMode.Z);
if (!xActive && !yActive && !zActive) {
return null;
}
final Set<Integer> dimensions = new HashSet<>();
if (xActive) {
dimensions.add(x);
}
if (yActive) {
dimensions.add(y);
}
if (zActive) {
dimensions.add(z);
}
int max = getMax(dimensions);
StringBuilder st = new StringBuilder();
if (xActive) {
st.append(x == max ? BauSystem.MESSAGE.parse("DEPTH_COUNTER_HIGHLIGHT", player) : "")
.append(BauSystem.MESSAGE.parse("DEPTH_COUNTER_X", player, x))
.append(BauSystem.MESSAGE.parse("DEPTH_COUNTER_SEPARATOR", player));
}
if (yActive) {
st.append(y == max ? BauSystem.MESSAGE.parse("DEPTH_COUNTER_HIGHLIGHT", player) : "")
.append(BauSystem.MESSAGE.parse("DEPTH_COUNTER_Y", player, y))
.append(BauSystem.MESSAGE.parse("DEPTH_COUNTER_SEPARATOR", player));
}
if (zActive) {
st.append(z == max ? BauSystem.MESSAGE.parse("DEPTH_COUNTER_HIGHLIGHT", player) : "")
.append(BauSystem.MESSAGE.parse("DEPTH_COUNTER_Z", player, z))
.append(BauSystem.MESSAGE.parse("DEPTH_COUNTER_SEPARATOR", player));
}
st.append(BauSystem.MESSAGE.parse("DEPTH_COUNTER_TNT", player, tntCount));
return BauSystem.MESSAGE.parse("DEPTH_COUNTER_MESSAGE", player, st.toString());
}
}

Datei anzeigen

@ -1,57 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.testblock.depthcounter;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.command.SWCommand;
import de.steamwar.linkage.Linked;
import org.bukkit.entity.Player;
@Linked
public class DepthCounterCommand extends SWCommand {
public DepthCounterCommand() {
super("depthcounter", "depthcount", "dcounter", "dcount");
}
@Register(value = "toggle", description = "DEPTH_COUNTER_COMMAND_TOGGLE_HELP")
public void toggleCommand(Player p, CountMode countMode) {
DepthCounter.toggleMode(p, countMode);
BauSystem.MESSAGE.send("DEPTH_COUNTER_ACTIVE_MESSAGE", p, DepthCounter.getModes(p).toString());
}
@Register(value = "enable", description = "DEPTH_COUNTER_COMMAND_ENABLE_HELP")
public void enableCommand(Player p) {
DepthCounter.setModes(p, CountMode.ALL());
BauSystem.MESSAGE.send("DEPTH_COUNTER_ENABLE_MESSAGE", p);
BauSystem.MESSAGE.send("DEPTH_COUNTER_ACTIVE_MESSAGE", p, DepthCounter.getModes(p).toString());
}
@Register(value = "disable", description = "DEPTH_COUNTER_COMMAND_DISABLE_HELP")
public void disableCommand(Player p) {
DepthCounter.removePlayer(p);
BauSystem.MESSAGE.send("DEPTH_COUNTER_DISABLE_MESSAGE", p);
}
@Register(value = "info", description = "DEPTH_COUNTER_COMMAND_INFO_HELP")
public void infoCommand(Player p) {
BauSystem.MESSAGE.send("DEPTH_COUNTER_ACTIVE_MESSAGE", p, DepthCounter.getModes(p).toString());
}
}

Datei anzeigen

@ -1,57 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.testblock.depthcounter;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType;
import de.steamwar.linkage.Linked;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@Linked
public class DepthCounterListener implements Listener {
@EventHandler
public void onEntityExplode(EntityExplodeEvent event) {
Region region = Region.getRegion(event.getLocation());
List<Block> blockList = event.blockList();
blockList = blockList.stream().filter(block -> region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)).collect(Collectors.toList());
if (blockList.isEmpty()) {
return;
}
DepthCounter.depthMap.putIfAbsent(region, new HashSet<>());
Set<Depth> depthSet = DepthCounter.depthMap.get(region);
for (Depth depth : depthSet) {
if (depth.update(blockList)) {
return;
}
}
depthSet.add(new Depth(region, blockList));
}
}

Datei anzeigen

@ -31,20 +31,28 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
@Linked @Linked
public class TPSLimitCommand extends SWCommand implements Enable { public class TPSLimitCommand extends SWCommand implements Enable {
private final List<String> tabCompletions = new ArrayList<>(Arrays.asList("0,5", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20")); private final List<String> tabCompletions = new ArrayList<>();
static final int MAX_TPS = Integer.MAX_VALUE;
public TPSLimitCommand() { public TPSLimitCommand() {
super("tpslimit"); super("tpslimit");
tabCompletions.add("0,5");
for (int i = 0; i <= 20; i++) {
tabCompletions.add(i + "");
}
if (TPSWarpUtils.isWarpAllowed()) { if (TPSWarpUtils.isWarpAllowed()) {
for (int i = 20; i <= 60; i += 5) { for (int i = 20; i <= 60; i += 5) {
tabCompletions.add(i + ""); tabCompletions.add(i + "");
} }
for (int i = 60; i <= 240; i += 10) {
tabCompletions.add(i + "");
}
} }
if (FreezeUtils.freezeEnabled) { if (FreezeUtils.freezeEnabled) {
tabCompletions.add("0"); tabCompletions.add("0");
@ -79,7 +87,7 @@ public class TPSLimitCommand extends SWCommand implements Enable {
sendNewTPSLimitMessage(true); sendNewTPSLimitMessage(true);
return; return;
} }
if (tpsLimitDouble < 0.5 || tpsLimitDouble > (TPSWarpUtils.isWarpAllowed() ? 60 : 20)) { if (tpsLimitDouble < 0.5 || tpsLimitDouble > (TPSWarpUtils.isWarpAllowed() ? MAX_TPS : 20)) {
sendInvalidArgumentMessage(p); sendInvalidArgumentMessage(p);
return; return;
} }
@ -121,6 +129,6 @@ public class TPSLimitCommand extends SWCommand implements Enable {
} }
private void sendInvalidArgumentMessage(Player player) { private void sendInvalidArgumentMessage(Player player) {
BauSystem.MESSAGE.send("TPSLIMIT_INVALID", player, TPSWarpUtils.isWarpAllowed() ? 60 : 20, FreezeUtils.freezeEnabled ? BauSystem.MESSAGE.parse("TPSLIMIT_INVALID_FROZEN", player) : ""); BauSystem.MESSAGE.send("TPSLIMIT_INVALID", player, TPSWarpUtils.isWarpAllowed() ? MAX_TPS : 20, FreezeUtils.freezeEnabled ? BauSystem.MESSAGE.parse("TPSLIMIT_INVALID_FROZEN", player) : "");
} }
} }

Datei anzeigen

@ -32,6 +32,8 @@ import org.bukkit.scheduler.BukkitTask;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import static de.steamwar.bausystem.features.tpslimit.TPSLimitCommand.MAX_TPS;
@UtilityClass @UtilityClass
public class TPSLimitUtils { public class TPSLimitUtils {
@ -88,7 +90,7 @@ public class TPSLimitUtils {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static void setTPS(double d) { public static void setTPS(double d) {
if (d < 0.5) d = 0.5; if (d < 0.5) d = 0.5;
if (d > (TPSWarpUtils.isWarpAllowed() ? 60 : 20)) d = (TPSWarpUtils.isWarpAllowed() ? 60 : 20); if (d > (TPSWarpUtils.isWarpAllowed() ? MAX_TPS : 20)) d = (TPSWarpUtils.isWarpAllowed() ? MAX_TPS : 20);
currentTPSLimit = d; currentTPSLimit = d;
tpsLimiter(); tpsLimiter();
} }

Datei anzeigen

@ -31,7 +31,11 @@ public class TPSUtils {
private static long ticksSinceServerStart = 0; private static long ticksSinceServerStart = 0;
public static final Supplier<Long> currentTick = () -> ticksSinceServerStart; // This is intended as Supplier<Long> public static final Supplier<Long> currentTick = () -> ticksSinceServerStart; // This is intended as Supplier<Long>
private static long realTicksSinceServerStart = 0;
public static final Supplier<Long> currentRealTick = () -> realTicksSinceServerStart; // This is intended as Supplier<Long>
static { static {
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> ticksSinceServerStart++, 1, 1); Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> ticksSinceServerStart++, 1, 1);
BauSystem.runTaskTimer(BauSystem.getInstance(), () -> realTicksSinceServerStart++, 1, 1);
} }
} }

Datei anzeigen

@ -40,7 +40,8 @@ public class TPSWarpUtils {
public static void setTPS(double tps) { public static void setTPS(double tps) {
double d = 50 - (50 / (tps / 20.0)); double d = 50 - (50 / (tps / 20.0));
nanoDOffset = Math.max(0, Math.min((long) (d * 1000000), 375000000)); // nanoDOffset = Math.max(0, Math.min((long) (d * 1000000), 375000000));
nanoDOffset = Math.max(0, (long) (d * 1000000));
if (nanoDOffset == 0) { if (nanoDOffset == 0) {
if (bukkitTask == null) return; if (bukkitTask == null) return;
bukkitTask.cancel(); bukkitTask.cancel();

Datei anzeigen

@ -25,7 +25,6 @@ import de.steamwar.bausystem.features.tracer.gui.TraceGui;
import de.steamwar.bausystem.features.tracer.record.*; import de.steamwar.bausystem.features.tracer.record.*;
import de.steamwar.bausystem.features.tracer.show.Record; import de.steamwar.bausystem.features.tracer.show.Record;
import de.steamwar.bausystem.features.tracer.show.*; import de.steamwar.bausystem.features.tracer.show.*;
import de.steamwar.bausystem.features.tracer.show.EntityShowMode;
import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.shared.ShowMode; import de.steamwar.bausystem.shared.ShowMode;
import de.steamwar.command.PreviousArguments; import de.steamwar.command.PreviousArguments;
@ -262,11 +261,6 @@ public class TraceCommand extends SWCommand {
messageSender.send("TRACE_MESSAGE_DISALLOWED", player); messageSender.send("TRACE_MESSAGE_DISALLOWED", player);
return false; return false;
} }
Region region = Region.getRegion(player.getLocation());
if (region.isGlobal()) {
messageSender.send("TRACE_MESSAGE_NO_REGION", player);
return false;
}
return true; return true;
}; };
} }

Datei anzeigen

@ -21,12 +21,15 @@ package de.steamwar.bausystem.features.tracer;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.tracer.record.Recorder; import de.steamwar.bausystem.features.tracer.record.Recorder;
import de.steamwar.bausystem.features.tracer.show.Record;
import de.steamwar.bausystem.features.tracer.show.StoredRecords; import de.steamwar.bausystem.features.tracer.show.StoredRecords;
import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.bausystem.utils.ScoreboardElement;
import de.steamwar.linkage.Linked; import de.steamwar.linkage.Linked;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.List;
@Linked @Linked
public class TraceScoreboardElement implements ScoreboardElement { public class TraceScoreboardElement implements ScoreboardElement {
@ -45,9 +48,14 @@ public class TraceScoreboardElement implements ScoreboardElement {
String traceScore = Recorder.INSTANCE.get(region).scoreboard(p); String traceScore = Recorder.INSTANCE.get(region).scoreboard(p);
if (traceScore != null) { if (traceScore != null) {
return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + traceScore; return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + traceScore;
} else if (!(Recorder.INSTANCE.get(region) instanceof Recorder.NoopTraceRecorder) && !StoredRecords.getRecords(region).isEmpty()) {
return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + BauSystem.MESSAGE.parse("TRACE_HAS_TRACES", p);
} }
List<Record> records = StoredRecords.getRecords(region);
if (records.isEmpty()) {
return null; return null;
} }
if (records.stream().allMatch(record -> record.getTnt().isEmpty())) {
return null;
}
return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + BauSystem.MESSAGE.parse("TRACE_HAS_TRACES", p);
}
} }

Datei anzeigen

@ -46,10 +46,6 @@ public class TracerBauGuiItem extends BauGuiItem {
@Override @Override
public ItemStack getItem(Player player) { public ItemStack getItem(Player player) {
Region region = Region.getRegion(player.getLocation()); Region region = Region.getRegion(player.getLocation());
if (region.isGlobal()) {
return SWUtils.setCustomModelData(new SWItem(Material.OBSERVER, BauSystem.MESSAGE.parse("TRACE_GUI_ITEM_NAME", player), Collections.emptyList(), false, clickType -> {
}), 1).getItemStack();
}
return SWUtils.setCustomModelData(new SWItem(Material.OBSERVER, BauSystem.MESSAGE.parse("TRACE_GUI_ITEM_NAME", player), Arrays.asList(BauSystem.MESSAGE.parse("TRACE_GUI_ITEM_LORE", player, Recorder.INSTANCE.get(region).scoreboard(player))), false, clickType -> { return SWUtils.setCustomModelData(new SWItem(Material.OBSERVER, BauSystem.MESSAGE.parse("TRACE_GUI_ITEM_NAME", player), Arrays.asList(BauSystem.MESSAGE.parse("TRACE_GUI_ITEM_LORE", player, Recorder.INSTANCE.get(region).scoreboard(player))), false, clickType -> {
}), 1).getItemStack(); }), 1).getItemStack();
} }

Datei anzeigen

@ -32,7 +32,7 @@ import java.util.function.Supplier;
public abstract class AutoTraceRecorder implements TraceRecorder { public abstract class AutoTraceRecorder implements TraceRecorder {
protected boolean recording = false; protected boolean recording = false;
private long startTime = TPSUtils.currentTick.get(); private long startTime = TPSUtils.currentRealTick.get();
private long lastExplosion = 0; private long lastExplosion = 0;
private final Map<TNTPrimed, Record.TNTRecord> recordMap = new HashMap<>(); private final Map<TNTPrimed, Record.TNTRecord> recordMap = new HashMap<>();
@ -40,7 +40,7 @@ public abstract class AutoTraceRecorder implements TraceRecorder {
private Supplier<Record> recordSupplier; private Supplier<Record> recordSupplier;
private Record.TNTRecord getRecord(TNTPrimed tntPrimed) { private Record.TNTRecord getRecord(TNTPrimed tntPrimed) {
return recordMap.computeIfAbsent(tntPrimed, __ -> record.spawn(TPSUtils.currentTick.get() - startTime)); return recordMap.computeIfAbsent(tntPrimed, __ -> record.spawn(TPSUtils.currentRealTick.get() - startTime));
} }
protected abstract String getInactivityMessage(); protected abstract String getInactivityMessage();
@ -51,7 +51,7 @@ public abstract class AutoTraceRecorder implements TraceRecorder {
@Override @Override
public final String scoreboard(Player player) { public final String scoreboard(Player player) {
if (recording) { if (recording) {
return BauSystem.MESSAGE.parse("TRACE_RECORD", player) + " §8| §e" + (TPSUtils.currentTick.get() - startTime) + " §7" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE_TICKS", player); return BauSystem.MESSAGE.parse("TRACE_RECORD", player) + " §8| §e" + (TPSUtils.currentRealTick.get() - startTime) + " §7" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE_TICKS", player);
} else { } else {
return BauSystem.MESSAGE.parse(getInactivityMessage(), player); return BauSystem.MESSAGE.parse(getInactivityMessage(), player);
} }
@ -59,7 +59,7 @@ public abstract class AutoTraceRecorder implements TraceRecorder {
private void startRecording() { private void startRecording() {
lastExplosion = 0; lastExplosion = 0;
startTime = TPSUtils.currentTick.get(); startTime = TPSUtils.currentRealTick.get();
record = recordSupplier.get(); record = recordSupplier.get();
recording = true; recording = true;
} }
@ -130,6 +130,6 @@ public abstract class AutoTraceRecorder implements TraceRecorder {
@Override @Override
public long scriptTime() { public long scriptTime() {
return TPSUtils.currentTick.get() - startTime; return TPSUtils.currentRealTick.get() - startTime;
} }
} }

Datei anzeigen

@ -27,7 +27,6 @@ import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.bausystem.region.utils.RegionType;
import de.steamwar.linkage.Linked; import de.steamwar.linkage.Linked;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.TNTPrimed;
@ -37,7 +36,9 @@ import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.entity.EntitySpawnEvent;
import java.util.*; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Linked @Linked
@ -49,36 +50,6 @@ public class Recorder implements Listener {
INSTANCE = this; INSTANCE = this;
} }
public static class NoopTraceRecorder implements TraceRecorder {
@Override
public String scoreboard(Player player) {
return null;
}
@Override
public void spawn(TNTPrimed tntPrimed) {
}
@Override
public void tick(TNTPrimed tntPrimed) {
}
@Override
public void explode(TNTPrimed tntPrimed, boolean b) {
}
@Override
public String scriptState() {
return "OFF";
}
@Override
public long scriptTime() {
return 0;
}
}
private static final NoopTraceRecorder NOOP = new NoopTraceRecorder();
private static class DisabledTracerRecorder implements TraceRecorder { private static class DisabledTracerRecorder implements TraceRecorder {
@Override @Override
public String scoreboard(Player player) { public String scoreboard(Player player) {
@ -115,8 +86,6 @@ public class Recorder implements Listener {
instance = this; instance = this;
} }
private final World world = Bukkit.getWorlds().get(0);
private Map<Region, TraceRecorder> regionTraceRecorderMap = new HashMap<>(); private Map<Region, TraceRecorder> regionTraceRecorderMap = new HashMap<>();
private Map<TNTPrimed, Region> tntTraceRecorderMap = new HashMap<>(); private Map<TNTPrimed, Region> tntTraceRecorderMap = new HashMap<>();
@ -125,7 +94,7 @@ public class Recorder implements Listener {
} }
public TraceRecorder get(Region region) { public TraceRecorder get(Region region) {
return regionTraceRecorderMap.getOrDefault(region, region.isGlobal() ? NOOP : DISABLED); return regionTraceRecorderMap.getOrDefault(region, DISABLED);
} }
public void set(Region region, TraceRecorder traceRecorder) { public void set(Region region, TraceRecorder traceRecorder) {
@ -160,7 +129,7 @@ public class Recorder implements Listener {
} }
{ {
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { BauSystem.runTaskTimer(BauSystem.getInstance(), () -> {
tick(); tick();
tntTraceRecorderMap.keySet() tntTraceRecorderMap.keySet()
.stream() .stream()

Datei anzeigen

@ -31,13 +31,13 @@ import java.util.function.Supplier;
public class SimpleTraceRecorder implements TraceRecorder, ActiveTracer { public class SimpleTraceRecorder implements TraceRecorder, ActiveTracer {
private final long startTime = TPSUtils.currentTick.get(); private final long startTime = TPSUtils.currentRealTick.get();
private final Map<TNTPrimed, Record.TNTRecord> recordMap = new HashMap<>(); private final Map<TNTPrimed, Record.TNTRecord> recordMap = new HashMap<>();
private Record record; private Record record;
@Override @Override
public String scoreboard(Player player) { public String scoreboard(Player player) {
return BauSystem.MESSAGE.parse("TRACE_RECORD", player) + " §8| §e" + (TPSUtils.currentTick.get() - startTime) + " §7" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE_TICKS", player); return BauSystem.MESSAGE.parse("TRACE_RECORD", player) + " §8| §e" + (TPSUtils.currentRealTick.get() - startTime) + " §7" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE_TICKS", player);
} }
@Override @Override
@ -51,7 +51,7 @@ public class SimpleTraceRecorder implements TraceRecorder, ActiveTracer {
} }
private Record.TNTRecord getRecord(TNTPrimed tntPrimed) { private Record.TNTRecord getRecord(TNTPrimed tntPrimed) {
return recordMap.computeIfAbsent(tntPrimed, __ -> record.spawn(TPSUtils.currentTick.get() - startTime)); return recordMap.computeIfAbsent(tntPrimed, __ -> record.spawn(TPSUtils.currentRealTick.get() - startTime));
} }
@Override @Override
@ -79,6 +79,6 @@ public class SimpleTraceRecorder implements TraceRecorder, ActiveTracer {
@Override @Override
public long scriptTime() { public long scriptTime() {
return TPSUtils.currentTick.get() - startTime; return TPSUtils.currentRealTick.get() - startTime;
} }
} }

Datei anzeigen

@ -29,7 +29,6 @@ import de.steamwar.entity.REntityServer;
import de.steamwar.entity.RFallingBlockEntity; import de.steamwar.entity.RFallingBlockEntity;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@ -85,6 +84,10 @@ public class EntityShowMode implements ShowMode<TNTPosition> {
return; return;
} }
if (showModeParameter.isMicroMotion() && !position.getRecord().isHasMicroMotion()) {
return;
}
if (showModeParameter.isExplodeOnly()) { if (showModeParameter.isExplodeOnly()) {
if (position.isExploded()) { if (position.isExploded()) {
generatePositions(position, false, false); generatePositions(position, false, false);

Datei anzeigen

@ -48,7 +48,7 @@ public class Record {
} }
public TNTRecord spawn(long offset) { public TNTRecord spawn(long offset) {
TNTRecord record = new TNTRecord(offset, region); TNTRecord record = new TNTRecord(this, offset, region);
tnt.add(record); tnt.add(record);
return record; return record;
} }
@ -57,11 +57,29 @@ public class Record {
tnt.clear(); tnt.clear();
} }
private void checkMicroMotion() {
for (TNTRecord tntRecord : tnt) {
List<TNTPosition> positions = tntRecord.positions;
if (positions.isEmpty()) continue;
TNTPosition position = positions.get(positions.size() - 1);
Vector velocity = position.getVelocity();
if (velocity.getY() == 0 && (velocity.getX() != 0 || velocity.getZ() != 0) && (Math.abs(velocity.getX()) < 0.001 || Math.abs(velocity.getZ()) < 0.001)) {
if (!tntRecord.hasMicroMotion) {
positions.forEach(tntPosition -> TraceShowManager.show(region, tntPosition));
}
tntRecord.hasMicroMotion = true;
}
}
}
public static class TNTRecord { public static class TNTRecord {
@Getter @Getter
private final UUID id = UUID.randomUUID(); private final UUID id = UUID.randomUUID();
private Record record;
@Getter @Getter
private final long offset; private final long offset;
@ -75,7 +93,11 @@ public class Record {
@Setter @Setter
private boolean inBuildArea = false; private boolean inBuildArea = false;
public TNTRecord(long offset, Region region) { @Getter
private boolean hasMicroMotion = false;
public TNTRecord(Record record, long offset, Region region) {
this.record = record;
this.offset = offset; this.offset = offset;
this.region = region; this.region = region;
} }
@ -90,6 +112,7 @@ public class Record {
public void explode(TNTPrimed tntPrimed) { public void explode(TNTPrimed tntPrimed) {
add(tntPrimed, false, true); add(tntPrimed, false, true);
record.checkMicroMotion();
} }
private void add(TNTPrimed tntPrimed, boolean source, boolean exploded) { private void add(TNTPrimed tntPrimed, boolean source, boolean exploded) {

Datei anzeigen

@ -32,6 +32,7 @@ public class ShowModeParameter {
private boolean count = false; private boolean count = false;
private boolean buildDestroyOnly = false; private boolean buildDestroyOnly = false;
private boolean ticksSinceStart = false; private boolean ticksSinceStart = false;
private boolean microMotion = false;
public void enableWater() { public void enableWater() {
this.water = true; this.water = true;
@ -68,4 +69,8 @@ public class ShowModeParameter {
public void enableTicksSinceStart() { public void enableTicksSinceStart() {
this.ticksSinceStart = true; this.ticksSinceStart = true;
} }
public void enableMicroMotion() {
this.microMotion = true;
}
} }

Datei anzeigen

@ -41,7 +41,9 @@ public enum ShowModeParameterType {
TICKS(ShowModeParameter::enableTicks, Arrays.asList("-ticks", "-t"), "EXPLODE", "SOURCE", "COUNT", "TICKS_SINCE_START"), TICKS(ShowModeParameter::enableTicks, Arrays.asList("-ticks", "-t"), "EXPLODE", "SOURCE", "COUNT", "TICKS_SINCE_START"),
COUNT(ShowModeParameter::enableCount, Arrays.asList("-count", "-c"), "TICKS", "TICKS_SINCE_START"), COUNT(ShowModeParameter::enableCount, Arrays.asList("-count", "-c"), "TICKS", "TICKS_SINCE_START"),
BUILD_DESTROY_ONLY(ShowModeParameter::enableBuildDestroyOnly, Arrays.asList("-builddestroy", "-builddestoryonly"), "WATER"), BUILD_DESTROY_ONLY(ShowModeParameter::enableBuildDestroyOnly, Arrays.asList("-builddestroy", "-builddestoryonly"), "WATER"),
TICKS_SINCE_START(ShowModeParameter::enableTicksSinceStart, Arrays.asList("-tickssincestart", "-tss"), "TICKS", "COUNT"); TICKS_SINCE_START(ShowModeParameter::enableTicksSinceStart, Arrays.asList("-tickssincestart", "-tss"), "TICKS", "COUNT"),
MICROMOTION(ShowModeParameter::enableMicroMotion, Arrays.asList("-micromotion", "-micro", "-m")),
;
@Getter @Getter
private final Consumer<ShowModeParameter> showModeParameterConsumer; private final Consumer<ShowModeParameter> showModeParameterConsumer;

Datei anzeigen

@ -42,7 +42,7 @@ public class StoredRecords {
private static final Map<Region, List<Record>> records = new HashMap<>(); private static final Map<Region, List<Record>> records = new HashMap<>();
static { static {
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { BauSystem.runTaskTimer(BauSystem.getInstance(), () -> {
replayLoops.forEach((region, playerSupplierMap) -> { replayLoops.forEach((region, playerSupplierMap) -> {
playerSupplierMap.forEach((player, integerSupplier) -> { playerSupplierMap.forEach((player, integerSupplier) -> {
int tick = integerSupplier.get(); int tick = integerSupplier.get();

Datei anzeigen

@ -47,9 +47,6 @@ public class TraceShowManager implements Listener {
hide(player); hide(player);
Region region = Region.getRegion(player.getLocation()); Region region = Region.getRegion(player.getLocation());
if (region.isGlobal()) {
return;
}
Map<Player, ShowMode<TNTPosition>> regionalShowModes = showModes.computeIfAbsent(region, __ -> new HashMap<>()); Map<Player, ShowMode<TNTPosition>> regionalShowModes = showModes.computeIfAbsent(region, __ -> new HashMap<>());
regionalShowModes.put(player, traceShowMode); regionalShowModes.put(player, traceShowMode);
StoredRecords.show(region, player, traceShowMode); StoredRecords.show(region, player, traceShowMode);
@ -57,9 +54,6 @@ public class TraceShowManager implements Listener {
public static void hide(Player player) { public static void hide(Player player) {
Region region = Region.getRegion(player.getLocation()); Region region = Region.getRegion(player.getLocation());
if (region.isGlobal()) {
return;
}
Map<Player, ShowMode<TNTPosition>> regionalShowModes = showModes.get(region); Map<Player, ShowMode<TNTPosition>> regionalShowModes = showModes.get(region);
if (regionalShowModes == null) { if (regionalShowModes == null) {
return; return;

Datei anzeigen

@ -30,10 +30,18 @@ import org.bukkit.event.player.PlayerMoveEvent;
@Linked @Linked
public class AFKStopperListener implements Listener { public class AFKStopperListener implements Listener {
// CPU > 50%
// RAM > 60%
private int minutesAfk = 0; private int minutesAfk = 0;
public AFKStopperListener() { public AFKStopperListener() {
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
// System.out.println("CPU: " + load + " RAM: " + usage);
if (RamUsage.getLoad() < 50.0 && RamUsage.getUsage() < 0.6) {
minutesAfk = 0;
return;
}
switch (minutesAfk) { switch (minutesAfk) {
case 5: case 5:
if (Bukkit.getOnlinePlayers().isEmpty()) { if (Bukkit.getOnlinePlayers().isEmpty()) {
@ -54,6 +62,12 @@ public class AFKStopperListener implements Listener {
@EventHandler @EventHandler
public void onPlayerMove(PlayerMoveEvent event) { public void onPlayerMove(PlayerMoveEvent event) {
if (event.getTo() == null) return;
if (event.getFrom().getPitch() != event.getTo().getPitch()) {
minutesAfk = 0;
}
if (event.getFrom().getYaw() != event.getTo().getYaw()) {
minutesAfk = 0; minutesAfk = 0;
} }
} }
}

Datei anzeigen

@ -22,13 +22,48 @@ package de.steamwar.bausystem.features.world;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import java.io.*; import java.io.*;
import java.util.concurrent.locks.LockSupport;
@UtilityClass @UtilityClass
public class RamUsage { public class RamUsage {
private File meminfo = new File("/proc/meminfo"); private File meminfo = new File("/proc/meminfo");
private File stat = new File("/proc/stat");
private double usageSelf = 0D;
private double usage = 0D;
private double load = 0D;
public static void init() {
}
static {
Thread thread = new Thread(() -> {
while (true) {
long maxMemory = Runtime.getRuntime().maxMemory();
long totalMemory = Runtime.getRuntime().totalMemory();
long freeMemory = Runtime.getRuntime().freeMemory();
long usedMemory = totalMemory - freeMemory;
usageSelf = usedMemory / (double) totalMemory;
double usageSelfByMax = usedMemory / (double) maxMemory;
// System.out.println("Self: " + usageSelf + "/" + usageSelfByMax + /* " " + maxMemory + " " + totalMemory + " " + freeMemory + " " + usedMemory + */ " Ram: " + usage + " CPU: " + load);
usage = _getUsage();
load = _getLoad();
Thread.yield();
LockSupport.parkNanos(1000000000L);
}
});
thread.setDaemon(true);
thread.setName("RamUsage");
thread.start();
}
public static double getUsage() { public static double getUsage() {
return usage;
}
private static double _getUsage() {
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(meminfo)))) { try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(meminfo)))) {
String memTotal = bufferedReader.readLine().replaceAll(" +", " "); String memTotal = bufferedReader.readLine().replaceAll(" +", " ");
bufferedReader.readLine(); bufferedReader.readLine();
@ -43,20 +78,43 @@ public class RamUsage {
} }
public static double getLoad() { public static double getLoad() {
try { return load;
Process process = new ProcessBuilder("bash", "-c", "cat <(grep 'cpu ' /proc/stat) <(sleep 1 && grep 'cpu ' /proc/stat) | awk -v RS=\"\" '{printf \"%.2f\\n\", ($13-$2+$15-$4)*100/($13-$2+$15-$4+$16-$5)}'").start(); }
process.waitFor();
return Double.parseDouble(new BufferedReader(new InputStreamReader(process.getInputStream())).readLine()); private long lastCpuSecond = -1;
private long lastCpuForth = -1;
private long lastCpuFifth = -1;
private static double _getLoad() {
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(stat)))) {
String[] strings = bufferedReader.readLine().split(" ");
long cpuSecond = Long.parseLong(strings[2]);
long cpuForth = Long.parseLong(strings[4]);
long cpuFifth = Long.parseLong(strings[5]);
if (lastCpuSecond == -1) {
lastCpuSecond = cpuSecond;
lastCpuForth = cpuForth;
lastCpuFifth = cpuFifth;
return 0D;
}
long cpuSecondDiff = cpuSecond - lastCpuSecond;
long cpuForthDiff = cpuForth - lastCpuForth;
long cpuSixthDiff = cpuFifth - lastCpuFifth;
lastCpuSecond = cpuSecond;
lastCpuForth = cpuForth;
lastCpuFifth = cpuFifth;
return (cpuSecondDiff + cpuForthDiff) / (double) (cpuSecondDiff + cpuForthDiff + cpuSixthDiff);
} catch (IOException e) { } catch (IOException e) {
return 1D; return 1D;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return 1D;
} }
} }
private static long getNumber(String s) { private static long getNumber(String s) {
return Long.parseLong(s.split(" ")[1]); return Long.parseLong(s.split(" ")[1]);
} }
} }

Datei anzeigen

@ -33,6 +33,7 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.io.File; import java.io.File;
import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
@ -70,6 +71,16 @@ public class RegionUtils {
}); });
} }
public static void message(Region region, Consumer<Player> function) {
Bukkit.getOnlinePlayers()
.stream()
.filter(player -> region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL))
.filter(player -> !region.isGlobal() || Region.getRegion(player.getLocation()).isGlobal())
.forEach(player -> {
function.accept(player);
});
}
static EditSession paste(File file, Point pastePoint, PasteOptions pasteOptions) { static EditSession paste(File file, Point pastePoint, PasteOptions pasteOptions) {
return FlatteningWrapper.impl.paste(file, pastePoint, pasteOptions); return FlatteningWrapper.impl.paste(file, pastePoint, pasteOptions);
} }

Datei anzeigen

@ -16,10 +16,6 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import org.apache.tools.ant.taskdefs.condition.Os
plugins { plugins {
// Adding the base plugin fixes the following gradle warnings in IntelliJ: // Adding the base plugin fixes the following gradle warnings in IntelliJ:
// //
@ -32,43 +28,12 @@ plugins {
id 'application' id 'application'
id 'com.github.johnrengelman.shadow' version '5.0.0' id 'com.github.johnrengelman.shadow' version '5.0.0'
} id 'de.steamwar.gradle' version 'RELEASE'
ext.swdep = { s ->
if (file("${rootDir}/lib/${s}.jar").exists()) {
return files("${rootDir}/lib/${s}.jar")
} else {
if (s.contains("-")) {
return "de.steamwar:${s.toLowerCase().replace('-', ':')}"
} else {
return "de.steamwar:${s.toLowerCase()}:RELEASE"
}
}
} }
group 'de.steamwar' group 'de.steamwar'
version '' version ''
Properties steamwarProperties = new Properties()
if (file("steamwar.properties").exists()) {
steamwarProperties.load(file("steamwar.properties").newDataInputStream())
}
ext {
buildName = 'BauSystem2.0'
artifactName = 'bausystem2.0'
uberJarName = "${buildName}-all.jar"
jarName = "${artifactName}.jar"
libs = "${buildDir}/libs"
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
operatingSystem = "windows"
} else {
operatingSystem = "unix"
}
}
compileJava.options.encoding = 'UTF-8' compileJava.options.encoding = 'UTF-8'
compileJava.options.compilerArgs << '-parameter' compileJava.options.compilerArgs << '-parameter'
@ -96,14 +61,6 @@ allprojects {
maven { maven {
url = uri('https://libraries.minecraft.net') url = uri('https://libraries.minecraft.net')
} }
maven {
url = uri('https://steamwar.de/maven/')
credentials {
username = steamwarProperties.getProperty("maven.username")
password = steamwarProperties.getProperty("maven.password")
}
}
} }
} }
@ -117,151 +74,3 @@ dependencies {
} }
} }
} }
task buildProject {
description 'Build this project'
group "Steamwar"
dependsOn build
}
task finalizeProject {
description 'Finalize this project'
group "Steamwar"
doLast {
if ("${buildDir}" == null) {
return
}
delete fileTree("${libs}").matching {
exclude("${uberJarName}")
}
file(libs + "/" + uberJarName).renameTo(file(libs + "/" + jarName))
}
}
build.finalizedBy(finalizeProject)
if (steamwarProperties.containsKey("hostname")) {
String hostname = steamwarProperties.get("hostname")
String type = steamwarProperties.getOrDefault("type", "Bau19")
String world = steamwarProperties.getOrDefault("world", "")
String pluginFolder = steamwarProperties.getOrDefault("pluginFolder", "")
task uploadProject {
description 'Upload this project'
group "Steamwar"
doLast {
await(shell("scp ${libs}/${jarName} ${hostname}:${pluginFolder}"))
if (steamwarProperties.getOrDefault("directStart", "false") == "false" && !answer("Start ${server} server?")) {
return
}
serverStart(type, hostname, world, pluginFolder)
}
}
uploadProject.dependsOn(buildProject)
task startDevServer {
description 'Start the DevServer'
group "Steamwar"
doLast {
serverStart(server, "", hostname)
}
}
}
private def await(Process proc) {
def out = new StringBuilder()
def err = new StringBuilder()
proc.waitForProcessOutput(out, err)
return [out, err, proc.exitValue()]
}
private def shell(String command) {
if (operatingSystem == "unix") {
return ['bash', '-c', command].execute()
} else {
return ["cmd", "/c", command].execute()
}
}
private def serverStart(String type, String hostname, String worldName, String pluginFolder) {
def proc = shell("ssh -t ${hostname} \"./binarys/dev.py ${type} -w ${worldName} -p ${pluginFolder}\"")
Set<String> strings = new HashSet<>()
File file = new File("${projectDir}/ignoredlog");
if (file.exists()) {
new BufferedReader(new InputStreamReader(new FileInputStream(file))).readLines().forEach({ s ->
strings.add(s)
})
}
Thread outputThread = new Thread({
Reader reader = proc.getInputStream().newReader();
Writer writer = System.out.newWriter();
try {
while (proc.alive) {
String s = reader.readLine()
if (s == null) {
return
}
if (strings.stream().anyMatch({check -> s.contains(check)})) {
continue
}
writer.write(s + "\n")
writer.flush()
}
} catch (IOException e) {
// Ignored
}
})
outputThread.setName("${type} - OutputThread")
outputThread.start()
Writer writer
Thread inputThread = new Thread({
Reader reader = System.in.newReader()
writer = proc.getOutputStream().newWriter()
try {
while (proc.alive) {
String s = reader.readLine()
writer.write(s + "\n")
writer.flush()
}
} catch (IOException e) {
// Ignored
}
})
inputThread.setName("${type} - InputThread")
inputThread.start()
gradle.buildFinished { buildResult ->
if (!proc.alive) {
return
}
writer = proc.getOutputStream().newWriter()
writer.write("stop\n")
writer.flush()
awaitClose(proc, outputThread, inputThread)
}
awaitClose(proc, outputThread, inputThread)
};
private static def awaitClose(Process proc, Thread outputThread, Thread inputThread) {
while (proc.alive) {
Thread.sleep(10)
}
proc.closeStreams()
outputThread.interrupt()
inputThread.interrupt()
}
private def answer(String question) {
while (System.in.available() > 0) System.in.read()
println(question)
boolean valid = "Yy".contains(((char) System.in.read()).toString())
while (System.in.available() > 0) System.in.read()
return valid
}

Datei anzeigen

@ -17,6 +17,15 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
pluginManagement {
repositories {
gradlePluginPortal()
maven {
url 'https://steamwar.de/maven/'
}
}
}
rootProject.name = 'BauSystem2.0' rootProject.name = 'BauSystem2.0'
file('.').listFiles().each { file('.').listFiles().each {