SteamWar/BauSystem
Archiviert
13
0

Merge branch 'bauconfigRefactoring'

Dieser Commit ist enthalten in:
Lixfel 2021-01-16 08:59:04 +01:00
Commit df63358d8f
9 geänderte Dateien mit 207 neuen und 187 gelöschten Zeilen

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 {
@ -143,10 +124,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

@ -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()) && region.hasProtection()){
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

@ -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.hasProtection()){
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

@ -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

@ -20,88 +20,195 @@
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;
final int minZ;
private final String schematic; static{
final boolean rotate; YamlConfiguration config = new YamlConfiguration();
try {
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);
}
Region(ConfigurationSection config){ ConfigurationSection prototypes = config.getConfigurationSection("prototypes");
sizeX = config.getInt("sizeX"); assert prototypes != null;
sizeY = config.getInt("sizeY"); for(String prototype : prototypes.getKeys(false)){
sizeZ = config.getInt("sizeZ"); 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){
return min <= l && l <= min + size;
} }
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 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 String SECTION_PATH = "/home/minecraft/backbone/server/UserBau/";
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 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;
protectSchematic = config.getString("protection", null);
if(!config.getName().equals("testblock"))
prototypes.put(config.getName(), this);
}
public boolean inRegion(Region region, Location l){
return inRange(l.getX(), region.minX + offsetX, sizeX + offsetX) &&
inRange(l.getY(), region.minY + offsetY, sizeY + offsetY) &&
inRange(l.getZ(), region.minZ + offsetZ, sizeZ + offsetZ);
}
public void fastreset(Region region){
File file = new File(SECTION_PATH + 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(SECTION_PATH + 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(SECTION_PATH + protectSchematic), x, y, z, rotate);
else
paste(schem.load(), x, y, z, rotate);
}
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);
} }
} }
} }