Skip to content

Commit

Permalink
New Command Lib, Set Commands, Copyright header updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorfromhell committed Feb 18, 2024
1 parent 736a95b commit c1567fc
Show file tree
Hide file tree
Showing 47 changed files with 1,428 additions and 1,048 deletions.
43 changes: 30 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>litecommands-repo</id>
<url>https://repo.panda-lang.org/releases</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -58,21 +62,21 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.carleslc.Simple-YAML</groupId>
<artifactId>Simple-Yaml</artifactId>
<version>1.8.4</version>
<groupId>dev.dejvokep</groupId>
<artifactId>boosted-yaml</artifactId>
<version>1.3.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.Revxrsal.Lamp</groupId>
<artifactId>bukkit</artifactId>
<version>3.1.8</version>
<groupId>dev.rollczi</groupId>
<artifactId>litecommands-core</artifactId>
<version>3.3.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.Revxrsal.Lamp</groupId>
<artifactId>common</artifactId>
<version>3.1.8</version>
<groupId>dev.rollczi</groupId>
<artifactId>litecommands-bukkit</artifactId>
<version>3.3.4</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -108,8 +112,19 @@
<shadedPattern>${phantom.relocation}.lamp</shadedPattern>
</relocation>
<relocation>
<pattern>me.carleslc</pattern>
<pattern>org.yaml</pattern>
<pattern>dev.rollczi</pattern>
<shadedPattern>${phantom.relocation}.lc</shadedPattern>
</relocation>
<relocation>
<pattern>panda.std</pattern>
<shadedPattern>${phantom.relocation}.panda</shadedPattern>
</relocation>
<relocation>
<pattern>org.panda-lang</pattern>
<shadedPattern>${phantom.relocation}.panda</shadedPattern>
</relocation>
<relocation>
<pattern>dev.dejvokep.boostedyaml</pattern>
<shadedPattern>${phantom.relocation}.yaml</shadedPattern>
</relocation>
</relocations>
Expand All @@ -125,11 +140,13 @@
<createDependencyReducedPom>false</createDependencyReducedPom>
<artifactSet>
<includes>
<include>org.yaml:*</include>
<include>me.carleslc.Simple-YAML:*</include>
<pattern>dev.dejvokep.boostedyaml:*</pattern>
<include>org.bstats:*</include>
<include>com.github.lokka30:MicroLib</include>
<include>com.github.Revxrsal.Lamp:*</include>
<include>dev.rollczi:*</include>
<include>panda.std:*</include>
<include>org.panda-lang:*</include>
</includes>
</artifactSet>
</configuration>
Expand Down
107 changes: 77 additions & 30 deletions src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package me.lokka30.phantomworlds;

import dev.rollczi.litecommands.LiteCommands;
import dev.rollczi.litecommands.bukkit.LiteBukkitFactory;
import me.lokka30.microlib.files.YamlConfigFile;
import me.lokka30.microlib.maths.QuickTimer;
import me.lokka30.microlib.other.UpdateChecker;
import me.lokka30.phantomworlds.commands.phantomworlds.PWCommand;
import me.lokka30.phantomworlds.commands.phantomworlds.parameters.resolvers.AliasWorldResolver;
import me.lokka30.phantomworlds.commands.phantomworlds.parameters.resolvers.WorldFolderResolver;
import me.lokka30.phantomworlds.commands.phantomworlds.parameters.suggestion.AliasWorldSuggestion;
import me.lokka30.phantomworlds.commands.phantomworlds.parameters.suggestion.WorldFolderSuggestion;
import me.lokka30.phantomworlds.commands.phantomworlds.utils.WorldFolder;
import me.lokka30.phantomworlds.commandsredux.PWCommand;
import me.lokka30.phantomworlds.commandsredux.params.AliasWorldParameter;
import me.lokka30.phantomworlds.commandsredux.params.GamemodeParameter;
import me.lokka30.phantomworlds.commandsredux.params.PortalParameter;
import me.lokka30.phantomworlds.commandsredux.params.PotionEffectParameter;
import me.lokka30.phantomworlds.commandsredux.params.SettingParameter;
import me.lokka30.phantomworlds.commandsredux.params.WorldFolderParameter;
import me.lokka30.phantomworlds.commandsredux.utils.WorldFolder;
import me.lokka30.phantomworlds.listeners.player.PlayerChangeWorldListener;
import me.lokka30.phantomworlds.listeners.player.PlayerDeathListener;
import me.lokka30.phantomworlds.listeners.player.PlayerJoinListener;
Expand All @@ -21,13 +25,16 @@
import me.lokka30.phantomworlds.misc.UpdateCheckerResult;
import me.lokka30.phantomworlds.scheduler.BackupScheduler;
import org.bstats.bukkit.Metrics;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.PortalType;
import org.bukkit.World;
import org.bukkit.WorldType;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitTask;
import revxrsal.commands.bukkit.BukkitCommandHandler;

import java.io.File;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;
Expand All @@ -41,6 +48,8 @@
*/
public class PhantomWorlds extends JavaPlugin {

public static final List<String> createTabs = new ArrayList<>();

/*
*TODO:
* - Translate backslash character in world names as a space so world names with a space can be used in the plugin
Expand All @@ -51,9 +60,10 @@ public class PhantomWorlds extends JavaPlugin {
* - log in console (LogLevel:INFO) when a command is prevented due to a target player seemingly being vanished to the command sender.
*/


private static PhantomWorlds instance;

protected BukkitCommandHandler command;
protected LiteCommands<?> command;

private BukkitTask backupService = null;

Expand Down Expand Up @@ -112,6 +122,8 @@ public void onEnable() {

instance = this;

createTabs.addAll(generateCreateSuggestions());

QuickTimer timer = new QuickTimer(TimeUnit.MILLISECONDS);
checkCompatibility();
loadFiles();
Expand Down Expand Up @@ -214,28 +226,15 @@ public void loadWorlds() {
*/
void registerCommands() {
getLogger().info("Registering commands...");
//Utils.registerCommand(new PhantomWorldsCommand(), "phantomworlds");

this.command = BukkitCommandHandler.create(this);

//Set our command help writer
for(final String key : messages.getConfig().getConfigurationSection("command.phantomworlds.help").getKeys(false)) {
COMMAND_HELP.add(ChatColor.translateAlternateColorCodes('&', messages.getConfig().getString("command.phantomworlds.help." + key, "Missing help message. Key: " + key)));
}

//Override the help writer because it dupes commands for some reason.
command.setHelpWriter((command, actor) ->"");

//Register Resolvers
this.command.registerValueResolver(WorldFolder.class, new WorldFolderResolver());
this.command.registerValueResolver(World.class, new AliasWorldResolver());

//Register Suggestors
this.command.getAutoCompleter().registerParameterSuggestions(WorldFolder.class, new WorldFolderSuggestion());
this.command.getAutoCompleter().registerParameterSuggestions(World.class, new AliasWorldSuggestion());

this.command.register(new PWCommand());
this.command.registerBrigadier();
this.command = LiteBukkitFactory.builder()
.commands(new PWCommand())
.argument(GameMode.class, new GamemodeParameter())
.argument(PortalType.class, new PortalParameter())
.argument(List.class, new PotionEffectParameter())
.argument(List.class, new SettingParameter())
.argument(World.class, new AliasWorldParameter())
.argument(WorldFolder.class, new WorldFolderParameter()).build();
}

/**
Expand Down Expand Up @@ -309,4 +308,52 @@ public static Logger logger() {
public static WorldManager worldManager() {
return instance.worldManager;
}

private ArrayList<String> generateCreateSuggestions() {
final ArrayList<String> suggestions = new ArrayList<>();

suggestions.addAll(addTrueFalseValues("generatestructures"));
suggestions.addAll(addTrueFalseValues("genstructures"));
suggestions.addAll(addTrueFalseValues("structures"));
suggestions.addAll(addTrueFalseValues("spawnmobs"));
suggestions.addAll(addTrueFalseValues("mobs"));
suggestions.addAll(addTrueFalseValues("spawnanimals"));
suggestions.addAll(addTrueFalseValues("animals"));
suggestions.addAll(addTrueFalseValues("keepspawninmemory"));
suggestions.addAll(addTrueFalseValues("spawninmemory"));
suggestions.addAll(addTrueFalseValues("hardcore"));
suggestions.addAll(addTrueFalseValues("allowpvp"));
suggestions.addAll(addTrueFalseValues("pvp"));
suggestions.addAll(addTrueFalseValues("difficulty"));
suggestions.addAll(addTrueFalseValues("diff"));

suggestions.add("generator:");
suggestions.add("gen:");

suggestions.add("generatorsettings:");
suggestions.add("gensettings:");

suggestions.add("gamemode:ADVENTURE");
suggestions.add("gamemode:CREATIVE");
suggestions.add("gamemode:HARDCORE");
suggestions.add("gamemode:SURVIVAL");

suggestions.add("seed:");

for(WorldType worldType : WorldType.values()) {
suggestions.add("type:" + worldType.toString());
}

return suggestions;
}

private ArrayList<String> addTrueFalseValues(String option) {
final ArrayList<String> list = new ArrayList<>();
option = option + ":";

list.add(option + "true");
list.add(option + "false");

return list;
}
}
26 changes: 0 additions & 26 deletions src/main/java/me/lokka30/phantomworlds/commands/Subcommand.java

This file was deleted.

Loading

0 comments on commit c1567fc

Please sign in to comment.