SteamWar/BauSystem2.0
Archiviert
12
0

Merge remote-tracking branch 'origin/master'

Dieser Commit ist enthalten in:
Chaoscaot 2021-04-18 13:58:10 +02:00
Commit 7790b13340
6 geänderte Dateien mit 170 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -24,6 +24,7 @@ import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.config.BauServer;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.bausystem.linkage.LinkedInstance;
import de.steamwar.command.SWCommand;
import de.steamwar.command.SWCommandUtils;
import de.steamwar.command.TypeMapper;
@ -36,6 +37,9 @@ import java.util.stream.Collectors;
@Linked(LinkageType.COMMAND)
public class BauCommand extends SWCommand {
@LinkedInstance(BauServer.class)
private BauServer bauServer;
public BauCommand() {
super("bau", "b", "gs");
}
@ -83,7 +87,7 @@ public class BauCommand extends SWCommand {
return;
}
BauweltMember target = BauweltMember.getBauMember(BauServer.getInstance().getOwnerID(), id.getId());
BauweltMember target = BauweltMember.getBauMember(bauServer.getOwnerID(), id.getId());
Permission.WORLDEDIT.toggle(p, target);
}
@ -92,7 +96,7 @@ public class BauCommand extends SWCommand {
return;
}
BauweltMember target = BauweltMember.getBauMember(BauServer.getInstance().getOwnerID(), id.getId());
BauweltMember target = BauweltMember.getBauMember(bauServer.getOwnerID(), id.getId());
Permission.WORLD.toggle(p, target);
}
@ -102,7 +106,7 @@ public class BauCommand extends SWCommand {
return true;
}
BauweltMember target = BauweltMember.getBauMember(BauServer.getInstance().getOwnerID(), id.getId());
BauweltMember target = BauweltMember.getBauMember(bauServer.getOwnerID(), id.getId());
if (target == null) {
p.sendMessage(BauSystem.PREFIX + "§cDer Spieler ist kein Mitglied deiner Welt!");
return true;
@ -112,7 +116,7 @@ public class BauCommand extends SWCommand {
private boolean permissionCheck(Player p) {
if (!BauServer.getInstance().getOwner().equals(p.getUniqueId())) {
if (!bauServer.getOwner().equals(p.getUniqueId())) {
p.sendMessage(BauSystem.PREFIX + "§cDies ist nicht deine Welt!");
return false;
} else {
@ -123,7 +127,7 @@ public class BauCommand extends SWCommand {
@ClassMapper(value = SteamwarUser.class, local = true)
private TypeMapper<SteamwarUser> steamwarUserTypeMapper() {
return SWCommandUtils.createMapper(s -> BauweltMember.getMembers(BauServer.getInstance().getOwnerID())
return SWCommandUtils.createMapper(s -> BauweltMember.getMembers(bauServer.getOwnerID())
.stream()
.map(m -> SteamwarUser.get(m.getMemberID()))
.filter(u -> u.getUserName().equals(s))

Datei anzeigen

@ -29,7 +29,7 @@ import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.command.SWCommand;
import org.bukkit.entity.Player;
@Linked(LinkageType.LISTENER)
@Linked(LinkageType.COMMAND)
public class SimulatorCommand extends SWCommand {
public SimulatorCommand() {

Datei anzeigen

@ -28,8 +28,6 @@ import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.command.SWCommand;
import de.steamwar.command.SWCommandUtils;
import de.steamwar.command.TypeMapper;
import lombok.AccessLevel;
import lombok.Getter;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
@ -43,14 +41,10 @@ import java.util.List;
@Linked(LinkageType.ENABLE_LINK)
public class TPSLimitCommand extends SWCommand implements Enable {
@Getter(AccessLevel.PACKAGE)
private static TPSLimitCommand instance = null;
private final List<String> tabCompletions = new ArrayList<>(Arrays.asList("0,5", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"));
public TPSLimitCommand() {
super("tpslimit");
instance = this;
if (TPSWarpUtils.isWarpAllowed()) {
for (int i = 20; i <= 60; i += 5) {
tabCompletions.add(i + "");

Datei anzeigen

@ -27,6 +27,7 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.logging.Level;
@ -35,10 +36,12 @@ import java.util.logging.Level;
public class LinkageUtils {
private Map<Class<?>, Object> objectMap = new HashMap<>();
private Set<Field> fieldsToLink = new HashSet<>();
public void link() {
internalLinkOrUnlink(false, Linked.class);
internalLinkOrUnlink(false, Linked.Linkages.class);
internalLinkFields();
}
public void unlink() {
@ -64,6 +67,23 @@ public class LinkageUtils {
}
}
private void internalLinkFields() {
for (Field field : fieldsToLink) {
LinkedInstance linkedInstance = field.getDeclaredAnnotation(LinkedInstance.class);
if (linkedInstance == null) {
continue;
}
Object object = objectMap.getOrDefault(linkedInstance.value(), null);
Object source = objectMap.getOrDefault(field.getDeclaringClass(), null);
try {
field.setAccessible(true);
field.set(source, object);
} catch (IllegalAccessException e) {
// Ignored
}
}
}
private void linkOrUnlink(Class<?> clazz, boolean unlink) {
Linked[] linkages = clazz.getDeclaredAnnotationsByType(Linked.class);
if (linkages.length == 0) {
@ -87,8 +107,27 @@ public class LinkageUtils {
}
linkageTypeList.sort(Comparator.comparingInt(LinkageType::getOrder));
Object object = objectMap.computeIfAbsent(clazz, LinkageUtils::constructInstance);
linkageTypeList.forEach(linkageType -> linkageType.getLinkageConsumer().accept(object));
if (unlink) {
Object object = objectMap.remove(clazz);
if (object == null) {
return;
}
linkageTypeList.forEach(linkageType -> linkageType.getLinkageConsumer().accept(object));
} else {
Object object = objectMap.computeIfAbsent(clazz, LinkageUtils::constructInstance);
linkageTypeList.forEach(linkageType -> linkageType.getLinkageConsumer().accept(object));
for (Field field : clazz.getDeclaredFields()) {
LinkedInstance linkedInstance = field.getDeclaredAnnotation(LinkedInstance.class);
if (linkedInstance == null) {
continue;
}
if (!field.getType().isAssignableFrom(linkedInstance.value())) {
continue;
}
fieldsToLink.add(field);
}
}
}
private Object constructInstance(Class<?> clazz) {

Datei anzeigen

@ -0,0 +1,31 @@
/*
* 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.linkage;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
public @interface LinkedInstance {
Class<?> value();
}

Datei anzeigen

@ -0,0 +1,88 @@
/*
* 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.utils;
import de.steamwar.bausystem.config.ColorConfig;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class ChatMessageBuilder {
private List<StringBuilder> messages = new ArrayList<>();
private String[] strings = new String[0];
public ChatMessageBuilder() {
messages.add(new StringBuilder());
}
public ChatMessageBuilder highlight(String s) {
messages.get(messages.size() - 1).append(ColorConfig.HIGHLIGHT).append(s);
return this;
}
public ChatMessageBuilder base(String s) {
messages.get(messages.size() - 1).append(ColorConfig.BASE).append(s);
return this;
}
public ChatMessageBuilder other(String s) {
messages.get(messages.size() - 1).append(ColorConfig.OTHER).append(s);
return this;
}
public ChatMessageBuilder enable(String s) {
messages.get(messages.size() - 1).append(ColorConfig.ENABLE).append(s);
return this;
}
public ChatMessageBuilder disable(String s) {
messages.get(messages.size() - 1).append(ColorConfig.DISABLE).append(s);
return this;
}
public ChatMessageBuilder error(String s) {
messages.get(messages.size() - 1).append(ColorConfig.ERROR).append(s);
return this;
}
public ChatMessageBuilder append(String s) {
messages.get(messages.size() - 1).append(s);
return this;
}
public ChatMessageBuilder newLine() {
messages.add(new StringBuilder());
return this;
}
public ChatMessageBuilder finish() {
strings = messages.stream().map(StringBuilder::toString).toArray(String[]::new);
return this;
}
public void send(Player player) {
for (String message : strings) {
player.sendMessage(message);
}
}
}