SteamWar/BauSystem
Archiviert
13
0

Add TraceGUI #161

Manuell gemergt
YoyoNow hat 6 Commits von TraceGui nach master 2021-01-27 10:06:31 +01:00 zusammengeführt
16 geänderte Dateien mit 458 neuen und 221 gelöschten Zeilen
Nur Änderungen aus Commit 96be3d5259 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -36,7 +36,7 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Objects; import java.util.Objects;
public class Region_12 { class Region_12 {
private Region_12(){} private Region_12(){}
static void paste(File file, int x, int y, int z, boolean rotate){ static void paste(File file, int x, int y, int z, boolean rotate){

Datei anzeigen

@ -43,7 +43,7 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Objects; import java.util.Objects;
public class Region_15 { class Region_15 {
private Region_15(){} private Region_15(){}
static void paste(File file, int x, int y, int z, boolean rotate){ static void paste(File file, int x, int y, int z, boolean rotate){

Datei anzeigen

@ -29,7 +29,6 @@ import org.bukkit.Bukkit;
import org.bukkit.GameRule; import org.bukkit.GameRule;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -43,18 +42,13 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
public class BauSystem extends JavaPlugin implements Listener { public class BauSystem extends JavaPlugin implements Listener {
private static BauSystem plugin; private static BauSystem plugin;
private static UUID owner; private static UUID owner;
private static List<ArenaSection> sections;
public static final String PREFIX = "§eBauSystem§8» §7"; public static final String PREFIX = "§eBauSystem§8» §7";
public static final String SECTION_PATH = "/home/minecraft/backbone/server/UserBau/";
private BukkitTask autoShutdown; private BukkitTask autoShutdown;
@ -62,23 +56,10 @@ public class BauSystem extends JavaPlugin implements Listener {
public void onEnable() { public void onEnable() {
plugin = this; plugin = this;
String worldName = Bukkit.getWorlds().get(0).getName();
try { try {
owner = UUID.fromString(worldName); owner = UUID.fromString(Bukkit.getWorlds().get(0).getName());
sections = ArenaSection.loadFromFile(new File(Bukkit.getWorldContainer().getPath() + '/' + getOwner().toString() + "/sections.yml"));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
try {
owner = null; owner = null;
sections = ArenaSection.loadFromFile(new File(Bukkit.getWorldContainer().getPath() + '/' + worldName + "/sections.yml"));
} catch (IOException | InvalidConfigurationException ex) {
getLogger().log(Level.SEVERE, "owner is no UUID / failed to load sections.yml", e);
Bukkit.shutdown();
return;
}
} catch (InvalidConfigurationException | IOException e) {
getLogger().log(Level.SEVERE, "Failed to load sections.yml", e);
Bukkit.shutdown();
return;
} }
try { try {
@ -101,6 +82,7 @@ public class BauSystem extends JavaPlugin implements Listener {
getCommand("reset").setExecutor(new CommandReset()); getCommand("reset").setExecutor(new CommandReset());
getCommand("speed").setExecutor(new CommandSpeed()); getCommand("speed").setExecutor(new CommandSpeed());
getCommand("tnt").setExecutor(new CommandTNT()); getCommand("tnt").setExecutor(new CommandTNT());
getCommand("tnt").setTabCompleter(new CommandTNTTabComplete());
getCommand("fire").setExecutor(new CommandFire()); getCommand("fire").setExecutor(new CommandFire());
getCommand("freeze").setExecutor(new CommandFreeze()); getCommand("freeze").setExecutor(new CommandFreeze());
getCommand("testblock").setExecutor(new CommandTestblock()); getCommand("testblock").setExecutor(new CommandTestblock());
@ -143,10 +125,6 @@ public class BauSystem extends JavaPlugin implements Listener {
return owner; return owner;
} }
public static List<ArenaSection> getSections() {
return sections;
}
public static int getOwnerID() { public static int getOwnerID() {
return SteamwarUser.get(getOwner()).getId(); return SteamwarUser.get(getOwner()).getId();
} }

Datei anzeigen

@ -34,7 +34,7 @@ public class CommandInfo implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName()); sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName());
sender.sendMessage(BauSystem.PREFIX + "TNT-Schaden: " + (CommandTNT.getInstance().isOn() ? "§aAUS" : "§cAN")); sender.sendMessage(BauSystem.PREFIX + "TNT-Schaden: " + CommandTNT.getTntMode().getName());
sender.sendMessage(BauSystem.PREFIX + "Feuerschaden: " + (CommandFire.getInstance().isOn() ? "§aAUS" : "§cAN")); sender.sendMessage(BauSystem.PREFIX + "Feuerschaden: " + (CommandFire.getInstance().isOn() ? "§aAUS" : "§cAN"));
sender.sendMessage(BauSystem.PREFIX + "Eingefroren: " + (CommandFreeze.getInstance().isOn() ? "§aJA" : "§cNEIN")); sender.sendMessage(BauSystem.PREFIX + "Eingefroren: " + (CommandFreeze.getInstance().isOn() ? "§aJA" : "§cNEIN"));

Datei anzeigen

@ -21,13 +21,17 @@ package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.world.ArenaSection; import de.steamwar.bausystem.world.Region;
import de.steamwar.bausystem.world.Welt; import de.steamwar.bausystem.world.Welt;
import de.steamwar.sql.Schematic;
import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.logging.Level;
public class CommandProtect implements CommandExecutor { public class CommandProtect implements CommandExecutor {
@Override @Override
@ -41,10 +45,23 @@ public class CommandProtect implements CommandExecutor {
return false; return false;
} }
for(ArenaSection section : BauSystem.getSections()){ for(Region region : Region.getRegions()){
if(section.inRegion(player.getLocation()) && section.hasProtection()){ if(region.inRegion(player.getLocation()) && region.hasProtection()){
section.protect(); try {
Schematic schem = null;
if(args.length > 0){
schem = Schematic.getSchemFromDB(args[0], player.getUniqueId());
if(schem == null){
player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden");
return false;
}
}
region.protect(schem);
player.sendMessage(BauSystem.PREFIX + "§7Boden geschützt"); player.sendMessage(BauSystem.PREFIX + "§7Boden geschützt");
}catch(Exception e){
player.sendMessage(BauSystem.PREFIX + "§cFehler beim Schützen der Region");
Bukkit.getLogger().log(Level.WARNING, "Failed protect", e);
}
return false; return false;
} }
} }

Datei anzeigen

@ -21,7 +21,7 @@ package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.world.ArenaSection; import de.steamwar.bausystem.world.Region;
import de.steamwar.bausystem.world.Welt; import de.steamwar.bausystem.world.Welt;
import de.steamwar.sql.Schematic; import de.steamwar.sql.Schematic;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -45,8 +45,8 @@ public class CommandReset implements CommandExecutor {
return false; return false;
} }
for(ArenaSection section : BauSystem.getSections()){ for(Region region : Region.getRegions()){
if(section.inRegion(player.getLocation())){ if(region.inRegion(player.getLocation())){
try { try {
if(args.length > 0){ if(args.length > 0){
Schematic schem = Schematic.getSchemFromDB(args[0], player.getUniqueId()); Schematic schem = Schematic.getSchemFromDB(args[0], player.getUniqueId());
@ -54,9 +54,9 @@ public class CommandReset implements CommandExecutor {
player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden"); player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden");
return false; return false;
} }
section.reset(schem); region.reset(schem);
}else{ }else{
section.fastreset(); region.fastreset();
} }
player.sendMessage(BauSystem.PREFIX + "§7Region zurückgesetzt"); player.sendMessage(BauSystem.PREFIX + "§7Region zurückgesetzt");
}catch(Exception e){ }catch(Exception e){

Datei anzeigen

@ -19,34 +19,148 @@
package de.steamwar.bausystem.commands; package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.world.Region;
import de.steamwar.bausystem.world.Welt;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
public class CommandTNT extends ToggleCommand { public class CommandTNT implements CommandExecutor, Listener {
private static TNTMode tntMode = Region.buildAreaEnabled() ? TNTMode.ONLY_TB : TNTMode.OFF;
public static TNTMode getTntMode() {
return tntMode;
}
public enum TNTMode {
ON("§aan"),
ONLY_TB("§7nur §eTestblock"),
OFF("§caus");
private String name;
TNTMode(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
public CommandTNT() { public CommandTNT() {
super(true); Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin());
} }
public static ToggleCommand getInstance(){ private String getNoPermMessage() {
return getInstance(CommandTNT.class);
}
@Override
String getNoPermMessage() {
return "§cDu darfst hier nicht TNT-Schaden (de-)aktivieren"; return "§cDu darfst hier nicht TNT-Schaden (de-)aktivieren";
} }
@Override
String getEnableMessage(){ private String getEnableMessage() {
return "§cTNT-Schaden deaktiviert";
}
@Override
String getDisableMessage(){
return "§aTNT-Schaden aktiviert"; return "§aTNT-Schaden aktiviert";
} }
private String getDisableMessage() {
return "§cTNT-Schaden deaktiviert";
}
private String getTestblockEnableMessage() {
return "§aTNT-Schaden am Testblock aktiviert";
}
private String getDamageMessage() {
return "§cEine Explosion hätte Blöcke im Baubereich zerstört";
}
@Override
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
if (!(sender instanceof Player)) return false;
Player player = (Player) sender;
if (Welt.noPermission(player, Permission.world)) {
player.sendMessage(BauSystem.PREFIX + getNoPermMessage());
return false;
}
if (args.length != 0) {
switch (args[0].toLowerCase()) {
case "an":
case "on":
tntMode = TNTMode.ON;
sendToActionBar(getEnableMessage());
return false;
case "aus":
case "off":
tntMode = TNTMode.OFF;
sendToActionBar(getDisableMessage());
return false;
case "testblock":
case "tb":
if (!Region.buildAreaEnabled()) break;
tntMode = TNTMode.ONLY_TB;
sendToActionBar(getTestblockEnableMessage());
return false;
default:
break;
}
}
switch (tntMode) {
case ON:
case ONLY_TB:
tntMode = TNTMode.OFF;
sendToActionBar(getDisableMessage());
break;
case OFF:
if (Region.buildAreaEnabled()) {
tntMode = TNTMode.ONLY_TB;
sendToActionBar(getTestblockEnableMessage());
} else {
tntMode = TNTMode.ON;
sendToActionBar(getEnableMessage());
}
break;
}
return false;
}
@EventHandler @EventHandler
public void onExplode(EntityExplodeEvent e) { public void onExplode(EntityExplodeEvent event) {
e.blockList().clear(); switch (tntMode) {
case ON:
break;
case OFF:
event.blockList().clear();
break;
case ONLY_TB:
boolean blocksDestroyed = event.blockList().removeIf(block -> {
for (Region region : Region.getRegions()) {
if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) {
return true;
} }
} }
return false;
});
if (blocksDestroyed) {
sendToActionBar(getDamageMessage());
}
break;
}
}
private void sendToActionBar(String message) {
Bukkit.getOnlinePlayers().forEach(p -> p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message)));
}
}

Datei anzeigen

@ -0,0 +1,67 @@
/*
*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2020 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.commands;
import de.steamwar.bausystem.world.Region;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class CommandTNTTabComplete implements TabCompleter {
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) return new ArrayList<>();
return tntTabComplete(args);
}
private List<String> tntTabComplete(String[] args) {
List<String> tabComplete = new ArrayList<>();
tabComplete.add("an");
tabComplete.add("on");
tabComplete.add("aus");
tabComplete.add("off");
if (Region.buildAreaEnabled()) {
tabComplete.add("testblock");
tabComplete.add("tb");
}
if (args.length >= 2) {
return new ArrayList<>();
}
return manageList(tabComplete, args, 0);
}
private List<String> manageList(List<String> strings, String[] args, int index) {
for (int i = strings.size() - 1; i >= 0; i--) {
if (!strings.get(i).startsWith(args[index])) {
strings.remove(i);
}
}
return strings;
}
}

Datei anzeigen

@ -35,11 +35,16 @@ import org.bukkit.scheduler.BukkitTask;
public class CommandTPSLimiter implements CommandExecutor { public class CommandTPSLimiter implements CommandExecutor {
private static final World WORLD = Bukkit.getWorlds().get(0);
private static double currentTPSLimit = 20; private static double currentTPSLimit = 20;
private static World world = Bukkit.getWorlds().get(0);
private long lastTime = System.nanoTime(); private long lastTime = System.nanoTime();
private long currentTime = System.nanoTime(); private long currentTime = System.nanoTime();
private double delay = 0;
private int loops = 0;
private long sleepDelay = 0;
private BukkitTask tpsLimiter = null; private BukkitTask tpsLimiter = null;
private boolean permissionCheck(Player player) { private boolean permissionCheck(Player player) {
@ -95,6 +100,10 @@ public class CommandTPSLimiter implements CommandExecutor {
} }
private void tpsLimiter() { private void tpsLimiter() {
delay = 20 / currentTPSLimit;
loops = (int)Math.ceil(delay);
sleepDelay = (long) (50 * delay) / loops;
if (currentTPSLimit == 20) { if (currentTPSLimit == 20) {
if (tpsLimiter == null) return; if (tpsLimiter == null) return;
tpsLimiter.cancel(); tpsLimiter.cancel();
@ -102,10 +111,11 @@ public class CommandTPSLimiter implements CommandExecutor {
} else { } else {
if (tpsLimiter != null) return; if (tpsLimiter != null) return;
tpsLimiter = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { tpsLimiter = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> {
VersionedRunnable.call(new VersionedRunnable(() -> TPSLimit_12.createTickCache(world), 8), VersionedRunnable.call(new VersionedRunnable(() -> TPSLimit_12.createTickCache(WORLD), 8),
new VersionedRunnable(() -> TPSLimit_15.createTickCache(world), 14)); new VersionedRunnable(() -> TPSLimit_15.createTickCache(WORLD), 14));
for (int i = 0; i < (20 / currentTPSLimit); i++) {
sleepUntilNextTick(); for (int i = 0; i < loops; i++) {
sleepUntilNextTick(sleepDelay);
VersionedRunnable.call(new VersionedRunnable(TPSLimit_12::sendTickPackets, 8), VersionedRunnable.call(new VersionedRunnable(TPSLimit_12::sendTickPackets, 8),
new VersionedRunnable(TPSLimit_15::sendTickPackets, 14)); new VersionedRunnable(TPSLimit_15::sendTickPackets, 14));
} }
@ -113,16 +123,12 @@ public class CommandTPSLimiter implements CommandExecutor {
} }
} }
private void sleepUntilNextTick() { private void sleepUntilNextTick(long neededDelta) {
lastTime = currentTime; lastTime = currentTime;
currentTime = System.nanoTime(); currentTime = System.nanoTime();
long timeDelta = (currentTime - lastTime) / 1000000; long timeDelta = (currentTime - lastTime) / 1000000;
long neededDelta = 50; if (neededDelta - timeDelta < 0) return;
if (neededDelta - timeDelta < 0) {
return;
}
try { try {
Thread.sleep(neededDelta - timeDelta); Thread.sleep(neededDelta - timeDelta);

Datei anzeigen

@ -21,16 +21,16 @@ package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.world.ArenaSection; import de.steamwar.bausystem.world.Region;
import de.steamwar.bausystem.world.Welt; import de.steamwar.bausystem.world.Welt;
import de.steamwar.sql.NoClipboardException;
import de.steamwar.sql.Schematic; import de.steamwar.sql.Schematic;
import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.io.IOException; import java.util.logging.Level;
public class CommandTestblock implements CommandExecutor { public class CommandTestblock implements CommandExecutor {
@ -45,24 +45,23 @@ public class CommandTestblock implements CommandExecutor {
return false; return false;
} }
for(ArenaSection section : BauSystem.getSections()){ for(Region region : Region.getRegions()){
if(section.inRegion(player.getLocation())){ if(region.inRegion(player.getLocation()) && region.hasTestblock()){
try {
Schematic schem = null;
if(args.length > 0){ if(args.length > 0){
Schematic schem = Schematic.getSchemFromDB(args[0], player.getUniqueId()); schem = Schematic.getSchemFromDB(args[0], player.getUniqueId());
if(schem == null){ if(schem == null){
player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden"); player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden");
return false; return false;
} }
try {
section.getTestblock().reset(schem);
} catch (IOException | NoClipboardException e) {
player.sendMessage(BauSystem.PREFIX + "§cFehler beim Laden der Schematic");
throw new SecurityException("Failed to load Testblock Schematic", e);
}
}else{
section.getTestblock().reset();
} }
region.resetTestblock(schem);
player.sendMessage(BauSystem.PREFIX + "§7Testblock zurückgesetzt"); player.sendMessage(BauSystem.PREFIX + "§7Testblock zurückgesetzt");
}catch(Exception e){
player.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen des Testblocks");
Bukkit.getLogger().log(Level.WARNING, "Failed testblock", e);
}
return false; return false;
} }
} }

Datei anzeigen

@ -47,13 +47,13 @@ public class Advanced extends Basic {
if (!showModeParameter.isWater() && position.isExploded() && checkWater(position.getLocation())) { if (!showModeParameter.isWater() && position.isExploded() && checkWater(position.getLocation())) {
for(TNTPosition pos : position.getRecord().getPositions()){ for(TNTPosition pos : position.getRecord().getPositions()){
applyOnPosition(pos, updatePointPosition -> applyOnPosition(pos, updatePointPosition ->
updateEntityMap.computeIfPresent(updatePointPosition, (p, point) -> point.hide(player, false) ? null : point)); updateEntityMap.computeIfPresent(new RoundedTNTPosition(updatePointPosition), (p, point) -> point.hide(player, false) ? null : point));
} }
return; return;
} }
applyOnPosition(position, updatePointPosition -> applyOnPosition(position, updatePointPosition ->
updateEntityMap.computeIfAbsent(updatePointPosition, pos -> createEntity(position.getLocation(), false)) updateEntityMap.computeIfAbsent(new RoundedTNTPosition(updatePointPosition), pos -> createEntity(updatePointPosition, false))
.display(player, position.isExploded())); .display(player, position.isExploded()));
} }
@ -64,13 +64,13 @@ public class Advanced extends Basic {
updateEntityMap.clear(); updateEntityMap.clear();
} }
private void applyOnPosition(TNTPosition position, Consumer<RoundedTNTPosition> function){ private void applyOnPosition(TNTPosition position, Consumer<Vector> function){
if (position.getPreviousLocation() == null) return; if (position.getPreviousLocation() == null) return;
if (showModeParameter.isInterpolate_Y()) { if (showModeParameter.isInterpolate_Y()) {
Vector updatePointY = position.getPreviousLocation().clone().setY(position.getLocation().getY()); Vector updatePointY = position.getPreviousLocation().clone().setY(position.getLocation().getY());
if(!position.getLocation().equals(updatePointY)) if(!position.getLocation().equals(updatePointY))
function.accept(new RoundedTNTPosition(updatePointY)); function.accept(updatePointY);
} }
if (showModeParameter.isInterpolate_XZ()){ if (showModeParameter.isInterpolate_XZ()){
@ -79,7 +79,7 @@ public class Advanced extends Basic {
? position.getLocation().clone().setZ(position.getPreviousLocation().getZ()) ? position.getLocation().clone().setZ(position.getPreviousLocation().getZ())
: position.getLocation().clone().setX(position.getPreviousLocation().getX()); : position.getLocation().clone().setX(position.getPreviousLocation().getX());
if(!position.getLocation().equals(updatePointXZ)) if(!position.getLocation().equals(updatePointXZ))
function.accept(new RoundedTNTPosition(updatePointXZ)); function.accept(updatePointXZ);
} }
} }
} }

Datei anzeigen

@ -1,65 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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.world;
import de.steamwar.bausystem.BauSystem;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class ArenaSection extends Region {
private final Region testblock;
private final String protectSchematic;
private ArenaSection(ConfigurationSection config) {
super(config);
testblock = new Region(Objects.requireNonNull(config.getConfigurationSection("testblock")));
protectSchematic = config.getString("protection");
}
public Region getTestblock(){
return testblock;
}
public static List<ArenaSection> loadFromFile(File file) throws IOException, InvalidConfigurationException {
YamlConfiguration config = new YamlConfiguration();
config.load(file);
List<ArenaSection> list = new ArrayList<>();
for(String section : config.getKeys(false))
list.add(new ArenaSection(config.getConfigurationSection(section)));
return list;
}
public boolean hasProtection(){
return !protectSchematic.equals("");
}
public void protect(){
File file = new File(BauSystem.SECTION_PATH + protectSchematic);
paste(file, minX + sizeX/2, testblock.minY-1, minZ + sizeZ/2, rotate);
}
}

Datei anzeigen

@ -61,7 +61,7 @@ public class BauScoreboard implements Listener {
strings.add("§1"); strings.add("§1");
strings.add("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())); strings.add("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()));
strings.add("§2"); strings.add("§2");
strings.add("§eTNT§8: " + (!CommandTNT.getInstance().isOn() ? "§aan" : "§caus")); strings.add("§eTNT§8: " + CommandTNT.getTntMode().getName());
strings.add("§eFreeze§8: " + (CommandFreeze.getInstance().isOn() ? "§aan" : "§caus")); strings.add("§eFreeze§8: " + (CommandFreeze.getInstance().isOn() ? "§aan" : "§caus"));
strings.add("§eTrace§8: " + RecordStateMachine.getRecordStatus().getName()); strings.add("§eTrace§8: " + RecordStateMachine.getRecordStatus().getName());
strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus")); strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus"));

Datei anzeigen

@ -20,88 +20,224 @@
package de.steamwar.bausystem.world; package de.steamwar.bausystem.world;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.core.Core; import de.steamwar.core.Core;
import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.NoClipboardException;
import de.steamwar.sql.Schematic; import de.steamwar.sql.Schematic;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.*;
import java.util.logging.Level;
public class Region { public class Region {
final int sizeX;
private final int sizeY;
final int sizeZ;
final int minX; private static final List<Region> regions = new ArrayList<>();
final int minY; private static boolean buildArea = false;
final int minZ;
private final String schematic; public static boolean buildAreaEnabled() {
final boolean rotate; return buildArea;
}
Region(ConfigurationSection config){ static{
sizeX = config.getInt("sizeX"); YamlConfiguration config = new YamlConfiguration();
sizeY = config.getInt("sizeY"); try {
sizeZ = config.getInt("sizeZ"); config.load(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "sections.yml"));
} catch (InvalidConfigurationException | IOException e) {
Bukkit.getLogger().log(Level.SEVERE, "Failed to load sections.yml", e);
}
ConfigurationSection prototypes = config.getConfigurationSection("prototypes");
assert prototypes != null;
for(String prototype : prototypes.getKeys(false)){
new Prototype(Objects.requireNonNull(prototypes.getConfigurationSection(prototype)));
}
ConfigurationSection regions = config.getConfigurationSection("regions");
assert regions != null;
for(String region : regions.getKeys(false)){
new Region(Objects.requireNonNull(regions.getConfigurationSection(region)));
}
}
public static List<Region> getRegions(){
return regions;
}
private final int minX;
private final int minY;
private final int minZ;
private final Prototype prototype;
private Region(ConfigurationSection config){
minX = config.getInt("minX"); minX = config.getInt("minX");
minY = config.getInt("minY"); minY = config.getInt("minY");
minZ = config.getInt("minZ"); minZ = config.getInt("minZ");
schematic = config.getString("schematic"); prototype = Prototype.prototypes.get(config.getString("prototype"));
rotate = config.getBoolean("rotate"); regions.add(this);
} }
public boolean inRegion(Location l){ public boolean inRegion(Location l){
return inRange(l.getX(), minX, sizeX) && inRange(l.getY(), minY, sizeY) && inRange(l.getZ(), minZ, sizeZ); return prototype.inRegion(this, l);
} }
private boolean inRange(double l, int min, int size){ public boolean hasBuildRegion() {
return min <= l && l <= min + size; return prototype.buildArea != null;
}
public boolean inBuildRegion(Location l) {
return prototype.buildArea.inRegion(this, l);
} }
public void fastreset(){ public void fastreset(){
File file = new File(BauSystem.SECTION_PATH + schematic); prototype.fastreset(this);
fastpaste(file, minX + sizeX/2, minY, minZ + sizeZ/2, rotate);
}
public void reset(){
File file = new File(BauSystem.SECTION_PATH + schematic);
paste(file, minX + sizeX/2, minY, minZ + sizeZ/2, rotate);
} }
public void reset(Schematic schem) throws IOException, NoClipboardException { public void reset(Schematic schem) throws IOException, NoClipboardException {
paste(schem.load(), minX + sizeX/2, minY, minZ + sizeZ/2, rotate); prototype.reset(this, schem);
} }
static void paste(File file, int x, int y, int z, boolean rotate){ public boolean hasTestblock() {
return prototype.hasTestblock();
}
public void resetTestblock(Schematic schem) throws IOException, NoClipboardException{
prototype.resetTestblock(this, schem);
}
public boolean hasProtection(){
return prototype.hasProtection();
}
public void protect(Schematic schem) throws IOException, NoClipboardException {
prototype.protect(this, schem);
}
public static class Prototype{
private static final Map<String, Prototype> prototypes = new HashMap<>();
private final int sizeX;
private final int sizeY;
private final int sizeZ;
private final int offsetX;
private final int offsetY;
private final int offsetZ;
private final String schematic;
private final boolean rotate;
private final Prototype testblock; //nullable
private final Prototype buildArea; //nullable
private final String protectSchematic; //nullable
private Prototype(ConfigurationSection config){
sizeX = config.getInt("sizeX");
sizeY = config.getInt("sizeY");
sizeZ = config.getInt("sizeZ");
schematic = config.getString("schematic");
offsetX = config.getInt("offsetX", 0);
offsetY = config.getInt("offsetY", 0);
offsetZ = config.getInt("offsetZ", 0);
rotate = config.getBoolean("rotate", false);
ConfigurationSection testblockSection = config.getConfigurationSection("testblock");
testblock = testblockSection != null ? new Prototype(testblockSection) : null;
ConfigurationSection buildAreaSection = config.getConfigurationSection("buildArea");
buildArea = buildAreaSection != null ? new Prototype(buildAreaSection) : null;
if (buildArea != null) {
Region.buildArea = true;
}
protectSchematic = config.getString("protection", null);
if(!config.getName().equals("testblock") && !config.getName().equals("buildArea"))
prototypes.put(config.getName(), this);
}
public boolean inRegion(Region region, Location l){
return inRange(l.getX(), region.minX + offsetX, sizeX) &&
inRange(l.getY(), region.minY + offsetY, sizeY) &&
inRange(l.getZ(), region.minZ + offsetZ, sizeZ);
}
public void fastreset(Region region){
File file = new File(schematic);
int x = region.minX + offsetX + sizeX/2;
int y = region.minY + offsetY;
int z = region.minZ + offsetZ + sizeZ/2;
switch(Core.getVersion()){ switch(Core.getVersion()){
case 15: case 12:
Region_15.paste(file, x, y, z, rotate);
break;
default:
Region_12.paste(file, x, y, z, rotate); Region_12.paste(file, x, y, z, rotate);
} break;
}
private static void fastpaste(File file, int x, int y, int z, boolean rotate){
switch(Core.getVersion()){
case 15: case 15:
default:
Region_15.fastpaste(file, x, y, z, rotate); Region_15.fastpaste(file, x, y, z, rotate);
break; }
default: }
public void reset(Region region, Schematic schem) throws IOException, NoClipboardException {
int x = region.minX + offsetX + sizeX / 2;
int y = region.minY + offsetY;
int z = region.minZ + offsetZ + sizeZ / 2;
if(schem == null)
paste(new File(schematic), x, y, z, rotate);
else
paste(schem.load(), x, y, z, rotate);
}
public boolean hasProtection() {
return protectSchematic != null;
}
public void protect(Region region, Schematic schem) throws IOException, NoClipboardException {
int x = region.minX + offsetX + sizeX / 2;
int y = region.minY + testblock.offsetY - 1;
int z = region.minZ + offsetZ + sizeZ / 2;
if(schem == null)
paste(new File(protectSchematic), x, y, z, rotate);
else
paste(schem.load(), x, y, z, rotate);
}
public boolean hasTestblock() {
return testblock != null;
}
public void resetTestblock(Region region, Schematic schem) throws IOException, NoClipboardException {
testblock.reset(region, schem);
}
private static boolean inRange(double l, int min, int size){
return min <= l && l <= min + size;
}
private static void paste(File file, int x, int y, int z, boolean rotate){ //Type of protect
switch(Core.getVersion()){
case 12:
Region_12.paste(file, x, y, z, rotate); Region_12.paste(file, x, y, z, rotate);
break;
case 15:
default:
Region_15.paste(file, x, y, z, rotate);
} }
} }
private static void paste(Clipboard clipboard, int x, int y, int z, boolean rotate){ private static void paste(Clipboard clipboard, int x, int y, int z, boolean rotate){
switch(Core.getVersion()){ switch(Core.getVersion()){
case 15: case 12:
Region_15.paste(clipboard, x, y, z, rotate);
break;
default:
Region_12.paste(clipboard, x, y, z, rotate); Region_12.paste(clipboard, x, y, z, rotate);
break;
case 15:
default:
Region_15.paste(clipboard, x, y, z, rotate);
}
} }
} }
} }

Datei anzeigen

@ -23,23 +23,15 @@ package de.steamwar.bausystem.world;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.Permission;
import de.steamwar.core.Core; import de.steamwar.core.Core;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
import java.util.logging.Level;
public class RegionListener implements Listener { public class RegionListener implements Listener {
@ -53,13 +45,7 @@ public class RegionListener implements Listener {
if (Welt.noPermission(p, Permission.worldedit)){ if (Welt.noPermission(p, Permission.worldedit)){
p.sendMessage(BauSystem.PREFIX + "§cDu darfst hier kein WorldEdit benutzen"); p.sendMessage(BauSystem.PREFIX + "§cDu darfst hier kein WorldEdit benutzen");
e.setCancelled(true); e.setCancelled(true);
return;
} }
/*if(!CommandFreeze.getInstance().isOn() && !Bukkit.getPluginManager().isPluginEnabled("FastAsyncWorldEdit")){
CommandFreeze.getInstance().toggle();
Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), CommandFreeze.getInstance()::toggle, 3);
}*/
} }
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
@ -112,5 +98,4 @@ public class RegionListener implements Listener {
event.setLine(i, line); event.setLine(i, line);
} }
} }
} }

Datei anzeigen

@ -55,7 +55,7 @@ public class ScriptListener implements Listener {
if(item == null || isNoBook(item) || item.getItemMeta() == null) if(item == null || isNoBook(item) || item.getItemMeta() == null)
return; return;
if (CommandScript.BOOK.getItemMeta() != null && item.getItemMeta().getDisplayName().equals(CommandScript.BOOK.getItemMeta().getDisplayName())) { if (CommandScript.BOOK.getItemMeta() != null && item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().equals(CommandScript.BOOK.getItemMeta().getDisplayName())) {
return; return;
} }
@ -284,7 +284,7 @@ public class ScriptListener implements Listener {
case "trace": case "trace":
return RecordStateMachine.getRecordStatus().isTracing() ? 1 : 0; return RecordStateMachine.getRecordStatus().isTracing() ? 1 : 0;
case "tnt": case "tnt":
return CommandTNT.getInstance().isOn() ? 1 : 0; return CommandTNT.getTntMode() == CommandTNT.TNTMode.OFF ? 0 : 1;
case "freeze": case "freeze":
return CommandFreeze.getInstance().isOn() ? 1 : 0; return CommandFreeze.getInstance().isOn() ? 1 : 0;
case "fire": case "fire":