Add Updater
Dieser Commit ist enthalten in:
Ursprung
b0eb0dfae3
Commit
a252544fbb
@ -23,6 +23,7 @@ import de.steamwar.bausystem.config.ColorConfig;
|
|||||||
import de.steamwar.bausystem.linkage.LinkageUtils;
|
import de.steamwar.bausystem.linkage.LinkageUtils;
|
||||||
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 lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -31,6 +32,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
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.logging.Level;
|
||||||
|
|
||||||
public class BauSystem extends JavaPlugin implements Listener {
|
public class BauSystem extends JavaPlugin implements Listener {
|
||||||
|
|
||||||
@ -47,8 +49,17 @@ public class BauSystem extends JavaPlugin implements Listener {
|
|||||||
instance = this;
|
instance = this;
|
||||||
SWUtils.setBausystem(instance);
|
SWUtils.setBausystem(instance);
|
||||||
|
|
||||||
|
try {
|
||||||
PrototypeLoader.load();
|
PrototypeLoader.load();
|
||||||
RegionLoader.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();
|
LinkageUtils.link();
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,6 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.region;
|
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.RegionExtensionType;
|
||||||
import de.steamwar.bausystem.region.utils.RegionType;
|
import de.steamwar.bausystem.region.utils.RegionType;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
@ -54,8 +54,6 @@ public class Prototype {
|
|||||||
private final int copyPointOffsetZ;
|
private final int copyPointOffsetZ;
|
||||||
|
|
||||||
public Prototype(String name, YAPIONObject yapionObject) {
|
public Prototype(String name, YAPIONObject yapionObject) {
|
||||||
PROTOTYPE_MAP.put(name, this);
|
|
||||||
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
displayName = yapionObject.getPlainValueOrDefault("displayName", name);
|
displayName = yapionObject.getPlainValueOrDefault("displayName", name);
|
||||||
|
|
||||||
@ -82,6 +80,11 @@ public class Prototype {
|
|||||||
} else {
|
} else {
|
||||||
build = null;
|
build = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (PROTOTYPE_MAP.containsKey(name)) {
|
||||||
|
Region.getRegion(PROTOTYPE_MAP.remove(name)).forEach(region -> region.setPrototype(this));
|
||||||
|
}
|
||||||
|
PROTOTYPE_MAP.put(name, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
@ -39,23 +39,30 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static de.steamwar.bausystem.region.RegionUtils.paste;
|
import static de.steamwar.bausystem.region.RegionUtils.paste;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class Region {
|
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) {
|
public static Region getRegion(Location location) {
|
||||||
return REGION_LIST.stream()
|
return REGION_MAP.values().stream()
|
||||||
.filter(r -> r.inRegion(location, r.minPoint, r.maxPoint))
|
.filter(r -> r.inRegion(location, r.minPoint, r.maxPoint))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(GlobalRegion.instance);
|
.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) {
|
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;
|
YAPIONObject regionData;
|
||||||
@ -99,7 +106,7 @@ public class Region {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
this.regionData = regionData;
|
this.regionData = regionData;
|
||||||
if (prototype != null) {
|
if (prototype != null) {
|
||||||
REGION_LIST.add(this);
|
REGION_MAP.put(name, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
linkedRegionName = regionConfig.getPlainValueOrDefault("optionsLinkedWith", null);
|
linkedRegionName = regionConfig.getPlainValueOrDefault("optionsLinkedWith", null);
|
||||||
@ -240,7 +247,7 @@ public class Region {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (Region region : REGION_LIST) {
|
for (Region region : REGION_MAP.values()) {
|
||||||
if (region.name.equals(linkedRegionName)) {
|
if (region.name.equals(linkedRegionName)) {
|
||||||
linkedRegion = region;
|
linkedRegion = region;
|
||||||
if (regionConsumer.test(linkedRegion)) {
|
if (regionConsumer.test(linkedRegion)) {
|
||||||
|
@ -22,8 +22,6 @@ package de.steamwar.bausystem.region.loader;
|
|||||||
import de.steamwar.bausystem.region.Prototype;
|
import de.steamwar.bausystem.region.Prototype;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import yapion.hierarchy.output.StringOutput;
|
|
||||||
import yapion.hierarchy.output.SystemOutput;
|
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
import yapion.parser.YAPIONParser;
|
import yapion.parser.YAPIONParser;
|
||||||
|
|
||||||
@ -31,20 +29,18 @@ import java.io.BufferedInputStream;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class PrototypeLoader {
|
public class PrototypeLoader {
|
||||||
|
|
||||||
|
public static final File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "prototypes.yapion");
|
||||||
|
|
||||||
public void load() {
|
public void load() {
|
||||||
File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "prototypes.yapion");
|
|
||||||
YAPIONObject yapionObject = null;
|
YAPIONObject yapionObject = null;
|
||||||
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file))) {
|
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file))) {
|
||||||
yapionObject = YAPIONParser.parse(bufferedInputStream);
|
yapionObject = YAPIONParser.parse(bufferedInputStream);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
|
throw new SecurityException(e.getMessage(), e);
|
||||||
Bukkit.shutdown();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
yapionObject.forEach((key, yapionAnyType) -> {
|
yapionObject.forEach((key, yapionAnyType) -> {
|
||||||
|
@ -33,12 +33,12 @@ import java.io.BufferedInputStream;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class RegionLoader {
|
public class RegionLoader {
|
||||||
|
|
||||||
private YAPIONObject optionsYapionObject;
|
private YAPIONObject optionsYapionObject;
|
||||||
|
public static final File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions.yapion");
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
try {
|
try {
|
||||||
@ -49,14 +49,11 @@ public class RegionLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void load() {
|
public void load() {
|
||||||
File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions.yapion");
|
|
||||||
YAPIONObject yapionObject = null;
|
YAPIONObject yapionObject = null;
|
||||||
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file))) {
|
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file))) {
|
||||||
yapionObject = YAPIONParser.parse(bufferedInputStream);
|
yapionObject = YAPIONParser.parse(bufferedInputStream);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
|
throw new SecurityException(e.getMessage(), e);
|
||||||
Bukkit.shutdown();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
File optionsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "options.yapion");
|
File optionsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "options.yapion");
|
||||||
|
47
BauSystem_Main/src/de/steamwar/bausystem/region/loader/Updater.java
Normale Datei
47
BauSystem_Main/src/de/steamwar/bausystem/region/loader/Updater.java
Normale Datei
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren