Skip to content

Commit

Permalink
v1.0.8 (#20)
Browse files Browse the repository at this point in the history
- refactored SchematicManager

- renamed NullIsland to EmptyIsland & refactored IslandSetup
- got rid of the unnecessary map in GamePlayer class

- cleanup

- added items to island setup

- added items to regular games

- version bump

- made the items configurable

- moved over the config.conf, and data.db to their own folders

- complete migration to Lamp command framework

- package refactor

* javadocs improvement

- The player now immediately gets teleported to the island setup when the island has been created to make the process much simpler and faster
- Added additional debug messages, and made the messages more precise

- improved codebase practices
- locked behind some left out debugging messages

- changed `/sb select`, to `/sb modify` as it's more accurate
- changed `speedbridge.island.island.select` to `speedbridge.island.modify`
  • Loading branch information
Tofpu authored Apr 1, 2022
1 parent 7839885 commit 4e6863c
Show file tree
Hide file tree
Showing 137 changed files with 2,625 additions and 1,412 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ __Features__
__Dependencies__
- WorldEdit (Required)
- PlaceholderAPI (Optional)

__Thanks to__
- [GitBook](https://gitbook.com)
- [JProfiler](https://www.ej-technologies.com/products/jprofiler/overview.html)

For providing us with an open-source licence! <3
21 changes: 15 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ plugins {
}

group = "io.tofpu.speedbridge2"
version = "1.0.7"
version = "1.0.8"

tasks {
compileJava {
options.encoding = "UTF-8"
options.compilerArgs.plusAssign("-parameters")
sourceCompatibility = "11"
}

named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
Expand All @@ -26,6 +28,8 @@ tasks {
relocate("org.bstats", "io.tofpu.speedbridge2.lib.bstats")
relocate("com.github.benmanes.caffeine", "io.tofpu.speedbridge2.lib.caffeine")
relocate("org.apache.commons", "io.tofpu.speedbridge2.lib.commons")
relocate("org.yaml.snakeyaml", "io.tofpu.speedbridge2.lib.snakeyml")
relocate("revxrsal", "io.tofpu.speedbridge2.lib.lamp")
}

exclude("META-INF/**")
Expand All @@ -47,13 +51,15 @@ publishing {
}

repositories {
mavenCentral()
mavenLocal()
mavenCentral()

maven("https://jitpack.io")
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
maven("https://maven.enginehub.org/repo/")
maven("https://oss.sonatype.org/content/groups/public/")
maven("https://repo.codemc.org/repository/maven-public/")
maven("https://libraries.minecraft.net")
}

dependencies {
Expand All @@ -63,17 +69,18 @@ dependencies {

compileOnly("com.sk89q:worldedit:6.0.0-SNAPSHOT")

implementation("cloud.commandframework:cloud-bukkit:1.6.2")
implementation("cloud.commandframework:cloud-annotations:1.6.1")
implementation("com.github.Revxrsal.Lamp:common:b3af8b94a0")
implementation("com.github.Revxrsal.Lamp:bukkit:b3af8b94a0")

implementation("net.kyori:adventure-api:4.10.1")
implementation("net.kyori:adventure-platform-bukkit:4.0.1")
implementation("net.kyori:adventure-text-minimessage:4.10.1")

implementation("com.github.tofpu:DynamicClass:fdc123593b") {
implementation("com.github.tofpu:DynamicClass:1.1") {
exclude("com.google.guava", "guava")
}

implementation("org.spongepowered:configurate-yaml:4.1.2")
implementation("org.spongepowered:configurate-hocon:4.1.2")
implementation("commons-lang:commons-lang:2.6")
implementation("commons-io:commons-io:2.11.0")
Expand All @@ -85,9 +92,11 @@ dependencies {
implementation("com.github.ben-manes.caffeine:caffeine:3.0.5")

implementation("com.github.cryptomorin:XSeries:8.6.1")
implementation("com.github.tofpu.MultiWorldEdit:multiworldedit-api:f9ad4ce832") {
implementation("com.github.tofpu.MultiWorldEdit:multiworldedit-api:0eb85d6cbd") {
exclude("de.schlichtherle", "truezip")
exclude("rhino", "js")
exclude("com.sk89q", "worldedit")
}

implementation("com.github.tofpu:umbrella:1ce46ae04a")
}
49 changes: 29 additions & 20 deletions src/main/java/io/tofpu/speedbridge2/SpeedBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@
import io.tofpu.multiworldedit.MultiWorldEditAPI;
import io.tofpu.speedbridge2.command.CommandManager;
import io.tofpu.speedbridge2.command.subcommand.HelpCommandGenerator;
import io.tofpu.speedbridge2.domain.common.Message;
import io.tofpu.speedbridge2.domain.common.PluginExecutor;
import io.tofpu.speedbridge2.domain.common.config.manager.ConfigurationManager;
import io.tofpu.speedbridge2.domain.common.database.DatabaseManager;
import io.tofpu.speedbridge2.domain.common.util.BridgeUtil;
import io.tofpu.speedbridge2.domain.common.util.UpdateChecker;
import io.tofpu.speedbridge2.domain.extra.blockmenu.BlockMenuManager;
import io.tofpu.speedbridge2.domain.extra.leaderboard.Leaderboard;
import io.tofpu.speedbridge2.domain.island.IslandService;
import io.tofpu.speedbridge2.domain.island.object.IslandBoard;
import io.tofpu.speedbridge2.domain.island.schematic.SchematicManager;
import io.tofpu.speedbridge2.domain.island.setup.IslandSetupManager;
import io.tofpu.speedbridge2.domain.player.PlayerService;
import io.tofpu.speedbridge2.support.placeholderapi.PluginExpansion;
import io.tofpu.speedbridge2.support.placeholderapi.expansion.ExpansionHandler;
import io.tofpu.speedbridge2.model.common.Message;
import io.tofpu.speedbridge2.model.common.PluginExecutor;
import io.tofpu.speedbridge2.model.common.config.manager.ConfigurationManager;
import io.tofpu.speedbridge2.model.common.database.DatabaseManager;
import io.tofpu.speedbridge2.model.common.util.BridgeUtil;
import io.tofpu.speedbridge2.model.common.util.UpdateChecker;
import io.tofpu.speedbridge2.model.blockmenu.BlockMenuManager;
import io.tofpu.speedbridge2.model.leaderboard.Leaderboard;
import io.tofpu.speedbridge2.model.island.IslandService;
import io.tofpu.speedbridge2.model.island.object.IslandBoard;
import io.tofpu.speedbridge2.model.island.schematic.SchematicManager;
import io.tofpu.speedbridge2.model.island.setup.IslandSetupManager;
import io.tofpu.speedbridge2.model.player.PlayerService;
import io.tofpu.speedbridge2.model.support.placeholderapi.PluginExpansion;
import io.tofpu.speedbridge2.model.support.placeholderapi.expansion.ExpansionHandler;
import io.tofpu.umbrella.UmbrellaAPI;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
Expand All @@ -37,17 +38,20 @@ public SpeedBridge(final JavaPlugin javaPlugin) {

public void load() {
// reset the world, in-case it does exist
SchematicManager.INSTANCE.resetWorld();
SchematicManager.resetWorld();
}

public void enable() {
adventure = BukkitAudiences.create(javaPlugin);

new UmbrellaAPI(javaPlugin)
.enable();

new Metrics(javaPlugin, 14597);

MultiWorldEditAPI.load(javaPlugin);

log("Loading the `config.yml`...");
log("Loading the `config.conf` & 'items.yml'...");
ConfigurationManager.INSTANCE.load(javaPlugin);

try {
Expand All @@ -66,7 +70,7 @@ public void enable() {
}

log("Loading the `speedbridge2` world...");
SchematicManager.INSTANCE.load();
SchematicManager.load();

IslandSetupManager.INSTANCE.load();

Expand Down Expand Up @@ -137,8 +141,13 @@ public void shutdown() {
PlayerService.INSTANCE.shutdown();

log("Unloading the `speedbridge2` world...");
SchematicManager.INSTANCE.unloadWorld();
SchematicManager.INSTANCE.resetWorld();
SchematicManager.unloadWorld();
SchematicManager.resetWorld();

final UmbrellaAPI umbrellaAPI = UmbrellaAPI.getInstance();
if (umbrellaAPI != null) {
umbrellaAPI.disable();
}

log("Complete.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.tofpu.speedbridge2.command;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public abstract class AbstractLampRegistry<K, V> {
private final Map<K, V> parserMap = new HashMap<>();

public void register(final K key, final V value) {
this.parserMap.put(key, value);
}

public Collection<V> values() {
return Collections.unmodifiableCollection(parserMap.values());
}
}
163 changes: 107 additions & 56 deletions src/main/java/io/tofpu/speedbridge2/command/CommandManager.java
Original file line number Diff line number Diff line change
@@ -1,82 +1,133 @@
package io.tofpu.speedbridge2.command;

import cloud.commandframework.CommandTree;
import cloud.commandframework.annotations.AnnotationParser;
import cloud.commandframework.arguments.parser.ParserParameters;
import cloud.commandframework.arguments.parser.StandardParameters;
import cloud.commandframework.bukkit.BukkitCommandManager;
import cloud.commandframework.execution.CommandExecutionCoordinator;
import cloud.commandframework.meta.CommandMeta;
import io.tofpu.speedbridge2.command.parser.GameIslandParser;
import io.tofpu.speedbridge2.command.parser.IslandParser;
import io.tofpu.dynamicclass.DynamicClass;
import io.tofpu.speedbridge2.command.condition.AbstractCommandConditionWrapper;
import io.tofpu.speedbridge2.command.condition.LampConditionRegistry;
import io.tofpu.speedbridge2.command.context.AbstractLampContext;
import io.tofpu.speedbridge2.command.context.LampContextRegistry;
import io.tofpu.speedbridge2.command.parser.AbstractLampParser;
import io.tofpu.speedbridge2.command.parser.LampParseRegistry;
import io.tofpu.speedbridge2.command.subcommand.CommandCompletion;
import io.tofpu.speedbridge2.command.subcommand.SpeedBridgeCommand;
import io.tofpu.speedbridge2.domain.island.object.Island;
import io.tofpu.speedbridge2.domain.island.object.extra.GameIsland;
import io.tofpu.speedbridge2.domain.player.PlayerService;
import io.tofpu.speedbridge2.domain.player.object.BridgePlayer;
import io.tofpu.speedbridge2.domain.player.object.extra.CommonBridgePlayer;
import io.tofpu.speedbridge2.domain.player.object.extra.DummyBridgePlayer;
import io.tofpu.speedbridge2.domain.player.object.extra.SenderBridgePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import io.tofpu.speedbridge2.model.common.util.BridgeUtil;
import io.tofpu.speedbridge2.model.island.object.Island;
import io.tofpu.speedbridge2.model.player.PlayerService;
import io.tofpu.speedbridge2.model.player.object.BridgePlayer;
import io.tofpu.speedbridge2.model.player.object.extra.CommonBridgePlayer;
import io.tofpu.speedbridge2.model.player.object.extra.DummyBridgePlayer;
import io.tofpu.speedbridge2.model.player.object.extra.SenderBridgePlayer;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import revxrsal.commands.bukkit.BukkitCommandActor;
import revxrsal.commands.bukkit.BukkitCommandHandler;
import revxrsal.commands.command.CommandActor;
import revxrsal.commands.command.ExecutableCommand;
import revxrsal.commands.process.SenderResolver;

import java.util.Objects;
import java.util.UUID;
import java.util.function.Function;

public final class CommandManager {
private static BukkitCommandManager<CommonBridgePlayer> manager;
private static BukkitCommandHandler commandHandler;

public static void load(final @NotNull Plugin plugin) {
final Function<CommandTree<CommonBridgePlayer>, CommandExecutionCoordinator<CommonBridgePlayer>> executionCoordinatorFunction = CommandExecutionCoordinator.SimpleCoordinator
.simpleCoordinator();
commandHandler = BukkitCommandHandler.create(plugin);

final Function<CommandSender, CommonBridgePlayer> bridgePlayerFunction = sender -> {
if (sender instanceof ConsoleCommandSender) {
return new SenderBridgePlayer(sender);
commandHandler.registerResponseHandler(String.class, (response, actor, command) -> {
if (response.isEmpty()) {
return;
}
final Player player = (Player) sender;
final UUID uniqueId = player.getUniqueId();
final BridgePlayer bridgePlayer = PlayerService.INSTANCE.get(uniqueId);
actor.reply(BridgeUtil.miniMessageToLegacy(response));
});

// if the bridge player is null, return a dummy instance
if (bridgePlayer == null) {
return DummyBridgePlayer.of(uniqueId);
commandHandler.registerSenderResolver(new SenderResolver() {
@Override
public boolean isCustomType(final Class<?> type) {
return CommonBridgePlayer.class.isAssignableFrom(type);
}

return bridgePlayer;
};
@Override
public @NotNull Object getSender(
@NotNull final Class<?> customSenderType,
@NotNull final CommandActor actor,
@NotNull final ExecutableCommand command) {
final BukkitCommandActor commandActor = (BukkitCommandActor) actor;

final Function<CommonBridgePlayer, CommandSender> senderToBridgePlayerFunction = CommonBridgePlayer::getPlayer;
if (commandActor.isConsole()) {
return new SenderBridgePlayer(commandActor.requireConsole());
}

try {
manager = new BukkitCommandManager<>(plugin, executionCoordinatorFunction, bridgePlayerFunction, senderToBridgePlayerFunction);
} catch (Exception exception) {
exception.printStackTrace();
final UUID uniqueId = commandActor.requirePlayer().getUniqueId();
final BridgePlayer bridgePlayer = PlayerService.INSTANCE.get(uniqueId);
return Objects.requireNonNullElseGet(bridgePlayer, () -> DummyBridgePlayer.of(uniqueId));
}
});


commandHandler.setHelpWriter((command, actor) -> String.format(
"<white>- <yellow>/%s " + "%s - %s", command.getPath()
.toRealString(), command.getUsage(), command.getDescription()));

constructTabCompleter();
constructContext();
constructParsers();
constructCommandConditions();

commandHandler.register(new SpeedBridgeCommand());
}

private static void constructTabCompleter() {
BridgeUtil.debug("Constructing tab completer...");

commandHandler.getAutoCompleter()
.registerParameterSuggestions(Island.class, CommandCompletion::islands);
}

private static void constructContext() {
final AbstractLampRegistry<?, AbstractLampContext<?>> registry =
DynamicClass.getInstance(LampContextRegistry.class);
if (registry == null) {
return;
}

BridgeUtil.debug("Constructing contexts...");

for (final AbstractLampContext<?> parser : registry.values()) {
parser.register(commandHandler);

BridgeUtil.debug("Registered context: " + parser.getClass()
.getName());
}
}

final Function<ParserParameters, CommandMeta> commandMetaFunction = p -> CommandMeta
.simple()
// This will allow you to decorate commands with descriptions
.with(CommandMeta.DESCRIPTION, p.get(StandardParameters.DESCRIPTION, "No description"))
.build();
private static void constructParsers() {
final AbstractLampRegistry<?, AbstractLampParser<?>> lampParseRegistry = DynamicClass.getInstance(LampParseRegistry.class);
if (lampParseRegistry == null) {
return;
}

final AnnotationParser<CommonBridgePlayer> annotationParser = new AnnotationParser<>(
/* Manager */ manager,
/* Command sender type */ CommonBridgePlayer.class,
/* Mapper for command meta instances */ commandMetaFunction);
BridgeUtil.debug("Constructing parsers...");

annotationParser.getParameterInjectorRegistry()
.registerInjector(Island.class, (context, annotationAccessor) -> {
return new IslandParser<>().parse(context, annotationAccessor);
});
for (final AbstractLampParser<?> parser : lampParseRegistry.values()) {
parser.register(commandHandler);

annotationParser.getParameterInjectorRegistry()
.registerInjector(GameIsland.class, (context, annotationAccessor) -> new GameIslandParser<CommonBridgePlayer>()
.parse(context, annotationAccessor));
BridgeUtil.debug("Registered parser: " + parser.getClass()
.getName());
}
}

private static void constructCommandConditions() {
final AbstractLampRegistry<?, AbstractCommandConditionWrapper> registry = DynamicClass.getInstance(LampConditionRegistry.class);
if (registry == null) {
return;
}

annotationParser.parse(new SpeedBridgeCommand());
BridgeUtil.debug("Constructing command conditions...");

for (final AbstractCommandConditionWrapper condition : registry.values()) {
condition.register(commandHandler);
BridgeUtil.debug("Registered command condition: " + condition.getClass()
.getName());
}
}
}
Loading

0 comments on commit 4e6863c

Please sign in to comment.