SteamWar/BauSystem2.0
Archiviert
12
0

Optimize some init stuff
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-08-26 20:45:43 +02:00
Ursprung 6830852c78
Commit 5758820679
2 geänderte Dateien mit 8 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -58,7 +58,6 @@ public class BauSystem extends JavaPlugin implements Listener {
@Override @Override
public void onEnable() { public void onEnable() {
SWScoreboard.class.getName();
world = Bukkit.getWorlds().get(0); world = Bukkit.getWorlds().get(0);
fixBauSystem(); fixBauSystem();
@ -149,6 +148,8 @@ public class BauSystem extends JavaPlugin implements Listener {
Bukkit.shutdown(); Bukkit.shutdown();
return; return;
} }
} else {
return;
} }
int number = -1; int number = -1;
try { try {

Datei anzeigen

@ -34,6 +34,7 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicLong;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -61,10 +62,13 @@ public class LinkageUtils {
} }
private void internalLinkOrUnlink(boolean unlink, Class<?> toLink) { private void internalLinkOrUnlink(boolean unlink, Class<?> toLink) {
AtomicLong totalTime = new AtomicLong();
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(BauSystem.class.getResourceAsStream("/de.steamwar.bausystem/" + toLink.getTypeName().replace("$", "."))))) { try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(BauSystem.class.getResourceAsStream("/de.steamwar.bausystem/" + toLink.getTypeName().replace("$", "."))))) {
bufferedReader.lines().forEach(s -> { bufferedReader.lines().forEach(s -> {
try { try {
long time = System.currentTimeMillis();
linkOrUnlink(Class.forName(s), unlink); linkOrUnlink(Class.forName(s), unlink);
totalTime.addAndGet(System.currentTimeMillis() - time);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
// ignored // ignored
} catch (Exception e) { } catch (Exception e) {
@ -76,6 +80,7 @@ public class LinkageUtils {
} catch (NullPointerException e) { } catch (NullPointerException e) {
// Ignored // Ignored
} }
BauSystem.getInstance().getLogger().info("Linkage took " + totalTime + "ms");
} }
private void internalLinkFields() { private void internalLinkFields() {
@ -101,12 +106,11 @@ public class LinkageUtils {
return; return;
} }
List<LinkageType> linkageTypeList = Arrays.stream(linkages).filter(Objects::nonNull).map(Linked::value).filter(linkageType -> linkageType.getLinkagePredicate().test(clazz)).filter(linkageType -> linkageType.isUnlink() == unlink).collect(Collectors.toList()); List<LinkageType> linkageTypeList = Arrays.stream(linkages).map(Linked::value).filter(linkageType -> linkageType.isUnlink() == unlink).filter(linkageType -> linkageType.getLinkagePredicate().test(clazz)).collect(Collectors.toList());
if (linkageTypeList.isEmpty()) { if (linkageTypeList.isEmpty()) {
return; return;
} }
linkageTypeList.sort(Comparator.comparingInt(LinkageType::getOrder));
if (unlink) { if (unlink) {
Object object = objectMap.remove(clazz); Object object = objectMap.remove(clazz);
if (object == null) { if (object == null) {