Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to cloud framework #1080

Merged
merged 6 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>cloud.commandframework</groupId>
<artifactId>cloud-annotations</artifactId>
<version>1.7.1</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
Expand All @@ -47,7 +61,8 @@
<include>tc.oc.pgm:*:*</include>
<include>org.jdom:jdom2:*</include>
<include>net.kyori:*:*</include>
<include>app.ashcon.intake:intake-*:*</include>
<include>cloud.commandframework:cloud-*:*</include>
<include>me.lucko:commodore:*</include>
<include>fr.mrmicky:*:*</include>
<include>org.eclipse.jgit:org.eclipse.jgit:*</include>
<include>org.slf4j:slf4j-api:*</include>
Expand All @@ -65,8 +80,12 @@
</filters>
<relocations combine.children="append">
<relocation>
<pattern>app.ashcon.intake</pattern>
<shadedPattern>tc.oc.pgm.lib.app.ashcon.intake</shadedPattern>
<pattern>cloud.commandframework</pattern>
<shadedPattern>tc.oc.pgm.lib.cloud.commandframework</shadedPattern>
</relocation>
<relocation>
<pattern>me.lucko</pattern>
<shadedPattern>tc.oc.pgm.lib.me.lucko</shadedPattern>
</relocation>
<relocation>
<pattern>fr.mrmicky</pattern>
Expand Down
17 changes: 6 additions & 11 deletions core/src/main/java/tc/oc/pgm/PGMPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,12 @@
import tc.oc.pgm.api.module.Module;
import tc.oc.pgm.api.module.exception.ModuleLoadException;
import tc.oc.pgm.api.player.VanishManager;
import tc.oc.pgm.command.graph.CommandExecutor;
import tc.oc.pgm.command.graph.CommandGraph;
import tc.oc.pgm.community.command.CommunityCommandGraph;
import tc.oc.pgm.command.util.CommandGraph;
import tc.oc.pgm.community.features.VanishManagerImpl;
import tc.oc.pgm.db.CacheDatastore;
import tc.oc.pgm.db.SQLDatastore;
import tc.oc.pgm.listeners.AntiGriefListener;
import tc.oc.pgm.listeners.BlockTransformListener;
import tc.oc.pgm.listeners.ChatDispatcher;
import tc.oc.pgm.listeners.FormattingListener;
import tc.oc.pgm.listeners.MatchAnnouncer;
import tc.oc.pgm.listeners.MotdListener;
Expand Down Expand Up @@ -338,13 +335,11 @@ public InventoryManager getInventoryManager() {
}

private void registerCommands() {
final CommandGraph graph =
config.isCommunityMode() ? new CommunityCommandGraph() : new CommandGraph();

graph.register(vanishManager);
graph.register(ChatDispatcher.get());

new CommandExecutor(this, graph).register();
try {
new CommandGraph(this);
} catch (Exception e) {
getLogger().log(Level.SEVERE, "Exception registering commands", e);
Electroid marked this conversation as resolved.
Show resolved Hide resolved
}
}

private void registerEvents(Object listener) {
Expand Down
21 changes: 21 additions & 0 deletions core/src/main/java/tc/oc/pgm/api/integration/Integration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package tc.oc.pgm.api.integration;

import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
import tc.oc.pgm.api.PGM;

public interface Integration {

public static boolean isFriend(Player a, Player b) {
Electroid marked this conversation as resolved.
Show resolved Hide resolved
return false;
}

@Nullable
public static String getNick(Player player) {
return null;
}

public static boolean isVanished(Player player) {
return PGM.get().getVanishManager().isVanished(player.getUniqueId());
}
}
18 changes: 8 additions & 10 deletions core/src/main/java/tc/oc/pgm/api/map/MapInfo.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package tc.oc.pgm.api.map;

import java.text.Normalizer;
import java.time.LocalDate;
import java.util.Collection;
import net.kyori.adventure.text.Component;
Expand Down Expand Up @@ -38,10 +37,17 @@ public interface MapInfo extends Comparable<MapInfo>, Cloneable {
/**
* Get a unique, human-readable name for the map.
*
* @return A name, alphanumeric with spaces are allowed.
* @return A name, alphanumeric with spaces allowed.
*/
String getName();

/**
* Get the maps' name, but normalized to standard english characters and lower case.
*
* @return The map's name, lowercase with spaces allowed.
*/
String getNormalizedName();

/**
* Gets a styled map name.
*
Expand Down Expand Up @@ -161,12 +167,4 @@ default String getStyledNameLegacy(MapNameStyle style, @Nullable CommandSender s
default int compareTo(MapInfo o) {
return getId().compareTo(o.getId());
}

static String normalizeName(@Nullable String idOrName) {
return idOrName == null
? ""
: Normalizer.normalize(idOrName, Normalizer.Form.NFD)
.replaceAll("[^A-Za-z0-9]", "")
.toLowerCase();
}
}
8 changes: 8 additions & 0 deletions core/src/main/java/tc/oc/pgm/api/map/MapLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Iterator;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Stream;
import org.jetbrains.annotations.Nullable;
import tc.oc.pgm.api.map.includes.MapIncludeProcessor;

Expand All @@ -17,6 +18,13 @@ public interface MapLibrary {
@Nullable
MapInfo getMap(String idOrName);

/**
* Get all {@link MapInfo}s matching the query.
*
* @return A stream of {@link MapInfo}s.
*/
Stream<MapInfo> getMaps(String query);

/**
* Get all {@link MapInfo}s, without any duplicate ids or names.
*
Expand Down
7 changes: 2 additions & 5 deletions core/src/main/java/tc/oc/pgm/api/region/Region.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.Random;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
Expand All @@ -21,6 +18,7 @@
import tc.oc.pgm.api.filter.query.LocationQuery;
import tc.oc.pgm.filters.matcher.TypedFilter;
import tc.oc.pgm.regions.Bounds;
import tc.oc.pgm.util.StreamUtils;
import tc.oc.pgm.util.block.BlockVectors;
import tc.oc.pgm.util.chunk.ChunkVector;
import tc.oc.pgm.util.event.PlayerCoarseMoveEvent;
Expand Down Expand Up @@ -142,8 +140,7 @@ default Iterable<BlockVector> getBlockVectors() {
}

default Stream<BlockVector> getBlockPositions() {
return StreamSupport.stream(
Spliterators.spliterator(getBlockVectorIterator(), 0, Spliterator.ORDERED), false);
return StreamUtils.of(getBlockVectorIterator());
Pablete1234 marked this conversation as resolved.
Show resolved Hide resolved
}

default Iterable<Block> getBlocks(World world) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/tc/oc/pgm/api/setting/SettingKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public List<String> getAliases() {
/**
* Get a list of the possible {@link SettingValue}s.
*
* @return A array of {@link SettingValue}s, sorted by defined order.
* @return An array of {@link SettingValue}s, sorted by defined order.
*/
public SettingValue[] getPossibleValues() {
return values;
Expand Down
21 changes: 1 addition & 20 deletions core/src/main/java/tc/oc/pgm/api/setting/SettingValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

import static tc.oc.pgm.util.Assert.assertNotNull;

import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.bukkit.DyeColor;
import org.jetbrains.annotations.Nullable;
import tc.oc.pgm.util.StringUtils;

/**
* Values of a particular {@link SettingKey}, a toggleable setting.
Expand Down Expand Up @@ -83,7 +78,7 @@ public String getName() {
/**
* Get {@link DyeColor} related to this setting value .
*
* @see {@link SettingMenu} for usage.
* @see tc.oc.pgm.settings.SettingsMenu for usage.
* @return {@link DyeColor} for this setting value.
*/
public DyeColor getColor() {
Expand All @@ -94,18 +89,4 @@ public DyeColor getColor() {
public String toString() {
return getName();
}

public static SettingValue search(SettingKey key, @Nullable String query) {
final SettingValue value =
StringUtils.bestFuzzyMatch(
query,
Stream.of(SettingValue.values())
.filter(entry -> entry.getKey().equals(key))
.collect(Collectors.toMap(SettingValue::getName, Function.identity())),
0.6);
if (value == null) {
return key.getDefaultValue();
}
return value;
}
}
5 changes: 3 additions & 2 deletions core/src/main/java/tc/oc/pgm/classes/ClassMatchModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static tc.oc.pgm.util.Assert.assertNotNull;
import static tc.oc.pgm.util.Assert.assertTrue;
import static tc.oc.pgm.util.text.TextException.exception;

import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
Expand Down Expand Up @@ -158,15 +159,15 @@ public boolean getCanChangeClass(UUID userId) {
* @param userId player to set the class
* @param cls class to set
* @return old class or default if none selected
* @throws IllegalStateException if the player may not change classes
* @throws tc.oc.pgm.util.text.TextException if the player may not change classes
*/
public PlayerClass setPlayerClass(UUID userId, PlayerClass cls) {
assertNotNull(userId, "player id");
assertNotNull(cls, "player class");
assertTrue(this.classes.containsValue(cls), "class is not valid for this match");

if (!this.getCanChangeClass(userId)) {
throw new IllegalStateException("cannot change sticky class");
throw exception("match.class.sticky");
}

PlayerClass oldClass = this.selectedClasses.put(userId, cls);
Expand Down
23 changes: 11 additions & 12 deletions core/src/main/java/tc/oc/pgm/command/AdminCommand.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
package tc.oc.pgm.command;

import app.ashcon.intake.Command;
import app.ashcon.intake.parametric.annotation.Switch;
import cloud.commandframework.annotations.CommandDescription;
import cloud.commandframework.annotations.CommandMethod;
import cloud.commandframework.annotations.CommandPermission;
import cloud.commandframework.annotations.Flag;
import tc.oc.pgm.api.PGM;
import tc.oc.pgm.api.Permissions;
import tc.oc.pgm.api.map.MapLibrary;

public final class AdminCommand {

@Command(
aliases = {"pgm"},
desc = "Reload the config",
perms = Permissions.RELOAD)
@CommandMethod("pgm")
@CommandDescription("Reload the config")
@CommandPermission(Permissions.RELOAD)
public void pgm() {
PGM.get().reloadConfig();
}

@Command(
aliases = {"loadnewmaps", "findnewmaps", "newmaps"},
desc = "Load new maps",
flags = "f",
perms = Permissions.RELOAD)
public void loadNewMaps(MapLibrary library, @Switch('f') boolean force) {
@CommandMethod("loadnewmaps|findnewmaps|newmaps")
@CommandDescription("Reload the config")
@CommandPermission(Permissions.RELOAD)
public void loadNewMaps(MapLibrary library, @Flag(value = "force", aliases = "f") boolean force) {
library.loadNewMaps(force);
}
}
11 changes: 6 additions & 5 deletions core/src/main/java/tc/oc/pgm/command/CancelCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import static net.kyori.adventure.text.Component.translatable;

import app.ashcon.intake.Command;
import cloud.commandframework.annotations.CommandDescription;
import cloud.commandframework.annotations.CommandMethod;
import cloud.commandframework.annotations.CommandPermission;
import net.kyori.adventure.text.format.NamedTextColor;
import tc.oc.pgm.api.Permissions;
import tc.oc.pgm.api.match.Match;
Expand All @@ -15,10 +17,9 @@

public final class CancelCommand {

@Command(
aliases = {"cancel", "cancelrestart", "cr"},
desc = "Cancels all countdowns",
perms = Permissions.STOP)
@CommandMethod("cancel|cancelrestart|cr")
@CommandDescription("Cancels all countdowns")
@CommandPermission(Permissions.STOP)
public void cancel(Audience audience, Match match) {
if (RestartManager.isQueued()) {
match.callEvent(new CancelRestartEvent());
Expand Down
Loading