Merge branch 'master' into network

Dieser Commit ist enthalten in:
Chaoscaot 2022-05-01 22:46:02 +02:00
Commit 82a5679818
20 geänderte Dateien mit 475 neuen und 21 gelöschten Zeilen

Datei anzeigen

@ -1,3 +1,22 @@
/*
* 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.command; package de.steamwar.command;
@FunctionalInterface @FunctionalInterface

Datei anzeigen

@ -1,3 +1,22 @@
/*
* 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.command; package de.steamwar.command;
import java.lang.annotation.*; import java.lang.annotation.*;

Datei anzeigen

@ -1,6 +1,25 @@
/*
* 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.command; package de.steamwar.command;
import java.util.List; import java.util.Collection;
public interface AbstractTypeMapper<K, T> { public interface AbstractTypeMapper<K, T> {
/** /**
@ -8,5 +27,5 @@ public interface AbstractTypeMapper<K, T> {
*/ */
T map(K sender, String[] previousArguments, String s); T map(K sender, String[] previousArguments, String s);
List<String> tabCompletes(K sender, String[] previousArguments, String s); Collection<String> tabCompletes(K sender, String[] previousArguments, String s);
} }

Datei anzeigen

@ -1,3 +1,22 @@
/*
* 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.command; package de.steamwar.command;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@ -5,6 +24,7 @@ import lombok.Setter;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.List; import java.util.List;
class CommandPart<T> { class CommandPart<T> {
@ -133,12 +153,12 @@ class CommandPart<T> {
public void generateTabComplete(List<String> current, T sender, String[] args, int startIndex) { public void generateTabComplete(List<String> current, T sender, String[] args, int startIndex) {
if (varArgType != null) { if (varArgType != null) {
for (int i = startIndex; i < args.length - 1; i++) { for (int i = startIndex; i < args.length - 1; i++) {
CheckArgumentResult validArgument = checkArgument(null, sender, args, i); CheckArgumentResult validArgument = checkArgument(GuardCheckType.TAB_COMPLETE, sender, args, i);
if (!validArgument.success) { if (!validArgument.success) {
return; return;
} }
} }
List<String> strings = typeMapper.tabCompletes(sender, Arrays.copyOf(args, args.length - 1), args[args.length - 1]); Collection<String> strings = typeMapper.tabCompletes(sender, Arrays.copyOf(args, args.length - 1), args[args.length - 1]);
if (strings != null) { if (strings != null) {
current.addAll(strings); current.addAll(strings);
} }
@ -157,7 +177,7 @@ class CommandPart<T> {
return; return;
} }
List<String> strings = typeMapper.tabCompletes(sender, Arrays.copyOf(args, startIndex), args[startIndex]); Collection<String> strings = typeMapper.tabCompletes(sender, Arrays.copyOf(args, startIndex), args[startIndex]);
if (strings != null) { if (strings != null) {
current.addAll(strings); current.addAll(strings);
} }

Datei anzeigen

@ -1,3 +1,22 @@
/*
* 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.command; package de.steamwar.command;
import lombok.Getter; import lombok.Getter;
@ -9,7 +28,6 @@ import java.lang.reflect.Parameter;
import java.util.*; import java.util.*;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors;
@UtilityClass @UtilityClass
public class SWCommandUtils { public class SWCommandUtils {
@ -198,20 +216,19 @@ public class SWCommandUtils {
} }
public static AbstractTypeMapper<?, Enum<?>> createEnumMapper(Class<Enum<?>> enumClass) { public static AbstractTypeMapper<?, Enum<?>> createEnumMapper(Class<Enum<?>> enumClass) {
Enum<?>[] enums = enumClass.getEnumConstants(); Map<String, Enum<?>> enumMap = new HashMap<>();
List<String> strings = Arrays.stream(enums).map(Enum::name).map(String::toLowerCase).collect(Collectors.toList()); for (Enum<?> e : enumClass.getEnumConstants()) {
enumMap.put(e.name(), e);
}
return new AbstractTypeMapper<Object, Enum<?>>() { return new AbstractTypeMapper<Object, Enum<?>>() {
@Override @Override
public Enum<?> map(Object commandSender, String[] previousArguments, String s) { public Enum<?> map(Object commandSender, String[] previousArguments, String s) {
for (Enum<?> e : enums) { return enumMap.get(s);
if (e.name().equalsIgnoreCase(s)) return e;
}
return null;
} }
@Override @Override
public List<String> tabCompletes(Object commandSender, String[] previousArguments, String s) { public Collection<String> tabCompletes(Object commandSender, String[] previousArguments, String s) {
return strings; return enumMap.keySet();
} }
}; };
} }

Datei anzeigen

@ -1,10 +1,28 @@
/*
* 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.command; package de.steamwar.command;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Parameter; import java.lang.reflect.Parameter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function; import java.util.function.Function;

Datei anzeigen

@ -1,3 +1,22 @@
/*
* 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; package de.steamwar;
import de.steamwar.command.CommandFrameworkException; import de.steamwar.command.CommandFrameworkException;

Datei anzeigen

@ -1,3 +1,22 @@
/*
* 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.command; package de.steamwar.command;
import de.steamwar.command.dto.ExecutionIdentifier; import de.steamwar.command.dto.ExecutionIdentifier;

Datei anzeigen

@ -1,3 +1,22 @@
/*
* 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.command; package de.steamwar.command;
import de.steamwar.command.dto.ExecutionIdentifier; import de.steamwar.command.dto.ExecutionIdentifier;

Datei anzeigen

@ -0,0 +1,43 @@
/*
* 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.command;
import de.steamwar.command.dto.ExecutionIdentifier;
import de.steamwar.command.dto.TestGuardChecker;
import de.steamwar.command.dto.TestSWCommand;
public class GuardCommand extends TestSWCommand {
public GuardCommand() {
super("typemapper");
}
@Register
public void test(@Guard String sender) {
throw new ExecutionIdentifier("RunTypeMapper");
}
@ClassGuard(value = String.class, local = true)
public AbstractGuardChecker<String> getGuardChecker() {
return (TestGuardChecker) (s, guardCheckType, previousArguments, s2) -> {
throw new ExecutionIdentifier("GuardChecker " + guardCheckType);
};
}
}

Datei anzeigen

@ -0,0 +1,52 @@
/*
* 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.command;
import de.steamwar.command.dto.ExecutionIdentifier;
import org.junit.Test;
import static de.steamwar.AssertionUtils.assertCMDFramework;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
public class GuardCommandTest {
@Test
public void test() {
GuardCommand cmd = new GuardCommand();
try {
cmd.execute("test", "", new String[0]);
} catch (Exception e) {
assertCMDFramework(e, ExecutionIdentifier.class, "RunTypeMapper");
}
}
@Test
public void testTabComplete() {
GuardCommand cmd = new GuardCommand();
try {
cmd.tabComplete("test", "", new String[]{""});
} catch (Exception e) {
assertThat(e, is(instanceOf(ExecutionIdentifier.class)));
assertThat(e.getMessage(), is("GuardChecker TAB_COMPLETE"));
}
}
}

Datei anzeigen

@ -1,3 +1,22 @@
/*
* 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.command; package de.steamwar.command;
import de.steamwar.command.dto.ExecutionIdentifier; import de.steamwar.command.dto.ExecutionIdentifier;

Datei anzeigen

@ -1,3 +1,22 @@
/*
* 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.command; package de.steamwar.command;
import de.steamwar.command.dto.ExecutionIdentifier; import de.steamwar.command.dto.ExecutionIdentifier;

Datei anzeigen

@ -0,0 +1,40 @@
/*
* 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.command;
import de.steamwar.command.dto.ExecutionIdentifier;
import de.steamwar.command.dto.TestSWCommand;
public class TypeMapperCommand extends TestSWCommand {
public TypeMapperCommand() {
super("typemapper");
}
@Register
public void test(String sender, String s) {
throw new ExecutionIdentifier("RunTypeMapper with CustomMapper");
}
@ClassMapper(value = String.class, local = true)
public AbstractTypeMapper<String, String> getTypeMapper() {
return SWCommandUtils.createMapper("1", "2", "3", "4", "5");
}
}

Datei anzeigen

@ -0,0 +1,36 @@
/*
* 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.command;
import org.junit.Test;
import java.util.List;
import static de.steamwar.AssertionUtils.assertTabCompletes;
public class TypeMapperCommandTest {
@Test
public void testTabComplete() {
TypeMapperCommand cmd = new TypeMapperCommand();
List<String> strings = cmd.tabComplete("test", "", new String[]{""});
assertTabCompletes(strings, "1", "2", "3", "4", "5");
}
}

Datei anzeigen

@ -1,3 +1,22 @@
/*
* 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.command.dto; package de.steamwar.command.dto;
public class ExecutionIdentifier extends RuntimeException { public class ExecutionIdentifier extends RuntimeException {

Datei anzeigen

@ -1,3 +1,22 @@
/*
* 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.command.dto; package de.steamwar.command.dto;
import de.steamwar.command.AbstractGuardChecker; import de.steamwar.command.AbstractGuardChecker;

Datei anzeigen

@ -1,3 +1,22 @@
/*
* 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.command.dto; package de.steamwar.command.dto;
import de.steamwar.command.AbstractSWCommand; import de.steamwar.command.AbstractSWCommand;

Datei anzeigen

@ -1,6 +0,0 @@
package de.steamwar.command.dto;
import de.steamwar.command.AbstractTypeMapper;
public interface TestTypeChecker<T> extends AbstractTypeMapper<String, T> {
}

Datei anzeigen

@ -0,0 +1,25 @@
/*
* 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.command.dto;
import de.steamwar.command.AbstractTypeMapper;
public interface TestTypeMapper<T> extends AbstractTypeMapper<String, T> {
}