SteamWar/BauSystem2.0
Archiviert
12
0
Dieser Commit ist enthalten in:
yoyosource 2021-05-03 16:58:01 +02:00
Ursprung b0eb0dfae3
Commit a252544fbb
7 geänderte Dateien mit 82 neuen und 23 gelöschten Zeilen

Datei anzeigen

@ -23,6 +23,7 @@ import de.steamwar.bausystem.config.ColorConfig;
import de.steamwar.bausystem.linkage.LinkageUtils;
import de.steamwar.bausystem.region.loader.PrototypeLoader;
import de.steamwar.bausystem.region.loader.RegionLoader;
import de.steamwar.bausystem.region.loader.Updater;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.event.Listener;
@ -31,6 +32,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.logging.Level;
public class BauSystem extends JavaPlugin implements Listener {
@ -47,8 +49,17 @@ public class BauSystem extends JavaPlugin implements Listener {
instance = this;
SWUtils.setBausystem(instance);
PrototypeLoader.load();
RegionLoader.load();
try {
PrototypeLoader.load();
RegionLoader.load();
} catch (SecurityException e) {
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
Bukkit.shutdown();
return;
}
new Updater(PrototypeLoader.file, PrototypeLoader::load);
new Updater(RegionLoader.file, RegionLoader::load);
LinkageUtils.link();
}

Datei anzeigen

@ -19,8 +19,6 @@
package de.steamwar.bausystem.region;
import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.flags.flagvalues.TNTMode;
import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType;
import lombok.Getter;

Datei anzeigen

@ -54,8 +54,6 @@ public class Prototype {
private final int copyPointOffsetZ;
public Prototype(String name, YAPIONObject yapionObject) {
PROTOTYPE_MAP.put(name, this);
this.name = name;
displayName = yapionObject.getPlainValueOrDefault("displayName", name);
@ -82,6 +80,11 @@ public class Prototype {
} else {
build = null;
}
if (PROTOTYPE_MAP.containsKey(name)) {
Region.getRegion(PROTOTYPE_MAP.remove(name)).forEach(region -> region.setPrototype(this));
}
PROTOTYPE_MAP.put(name, this);
}
@Getter

Datei anzeigen

@ -39,23 +39,30 @@ import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import static de.steamwar.bausystem.region.RegionUtils.paste;
@Getter
public class Region {
private static final List<Region> REGION_LIST = new ArrayList<>();
private static final Map<String, Region> REGION_MAP = new HashMap<>();
public static Region getRegion(Location location) {
return REGION_LIST.stream()
return REGION_MAP.values().stream()
.filter(r -> r.inRegion(location, r.minPoint, r.maxPoint))
.findFirst()
.orElse(GlobalRegion.instance);
}
public static Set<Region> getRegion(Prototype prototype) {
return REGION_MAP.values().stream()
.filter(r -> r.getPrototype() == prototype)
.collect(Collectors.toSet());
}
public static void setGlobal(Flag flagType, Flag.Value<?> value) {
REGION_LIST.forEach(region -> region.set(flagType, value));
REGION_MAP.values().forEach(region -> region.set(flagType, value));
}
YAPIONObject regionData;
@ -99,7 +106,7 @@ public class Region {
this.name = name;
this.regionData = regionData;
if (prototype != null) {
REGION_LIST.add(this);
REGION_MAP.put(name, this);
}
linkedRegionName = regionConfig.getPlainValueOrDefault("optionsLinkedWith", null);
@ -240,7 +247,7 @@ public class Region {
}
return;
}
for (Region region : REGION_LIST) {
for (Region region : REGION_MAP.values()) {
if (region.name.equals(linkedRegionName)) {
linkedRegion = region;
if (regionConsumer.test(linkedRegion)) {

Datei anzeigen

@ -22,8 +22,6 @@ package de.steamwar.bausystem.region.loader;
import de.steamwar.bausystem.region.Prototype;
import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit;
import yapion.hierarchy.output.StringOutput;
import yapion.hierarchy.output.SystemOutput;
import yapion.hierarchy.types.YAPIONObject;
import yapion.parser.YAPIONParser;
@ -31,20 +29,18 @@ import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.logging.Level;
@UtilityClass
public class PrototypeLoader {
public static final File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "prototypes.yapion");
public void load() {
File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "prototypes.yapion");
YAPIONObject yapionObject = null;
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file))) {
yapionObject = YAPIONParser.parse(bufferedInputStream);
} catch (IOException e) {
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
Bukkit.shutdown();
return;
throw new SecurityException(e.getMessage(), e);
}
yapionObject.forEach((key, yapionAnyType) -> {

Datei anzeigen

@ -33,12 +33,12 @@ import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.logging.Level;
@UtilityClass
public class RegionLoader {
private YAPIONObject optionsYapionObject;
public static final File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions.yapion");
public void save() {
try {
@ -49,14 +49,11 @@ public class RegionLoader {
}
public void load() {
File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions.yapion");
YAPIONObject yapionObject = null;
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file))) {
yapionObject = YAPIONParser.parse(bufferedInputStream);
} catch (IOException e) {
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
Bukkit.shutdown();
return;
throw new SecurityException(e.getMessage(), e);
}
File optionsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "options.yapion");

Datei anzeigen

@ -0,0 +1,47 @@
/*
* 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.region.loader;
import de.steamwar.bausystem.BauSystem;
import org.bukkit.Bukkit;
import java.io.File;
import java.util.logging.Level;
public class Updater {
private long lastUpdate;
public Updater(File file, Runnable updaterCode) {
this.lastUpdate = file.lastModified();
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
if (file.lastModified() > lastUpdate + 10) {
try {
updaterCode.run();
lastUpdate = file.lastModified();
Bukkit.getLogger().log(Level.INFO, "Update complete of " + file.getAbsolutePath());
} catch (Exception e) {
Bukkit.getLogger().log(Level.INFO, "Error while loading file " + file.getAbsolutePath() + " for config: " + e.getMessage(), e);
}
}
}, 20, 20);
}
}