Skip to content

Commit

Permalink
Refactor commands directory, add compatibility classes for older vers…
Browse files Browse the repository at this point in the history
…ions.
  • Loading branch information
creatorfromhell committed Mar 1, 2024
1 parent 3ab0ecc commit 35fbeb8
Show file tree
Hide file tree
Showing 38 changed files with 248 additions and 105 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.lokka30</groupId>
<artifactId>PhantomWorlds</artifactId>
<version>2.0.7</version>
<version>2.0.8</version>

<name>PhantomWorlds</name>
<description>The Robust World Manager for Minecraft Servers</description>
Expand Down
34 changes: 26 additions & 8 deletions src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
import me.lokka30.microlib.files.YamlConfigFile;
import me.lokka30.microlib.maths.QuickTimer;
import me.lokka30.microlib.other.UpdateChecker;
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.comatibility.VersionCompatibility;
import me.lokka30.phantomworlds.comatibility.impl.OneSeventeenCompatibility;
import me.lokka30.phantomworlds.comatibility.impl.OneTwentyCompatibility;
import me.lokka30.phantomworlds.commands.PWCommand;
import me.lokka30.phantomworlds.commands.params.AliasWorldParameter;
import me.lokka30.phantomworlds.commands.params.GamemodeParameter;
import me.lokka30.phantomworlds.commands.params.PortalParameter;
import me.lokka30.phantomworlds.commands.params.PotionEffectParameter;
import me.lokka30.phantomworlds.commands.params.SettingParameter;
import me.lokka30.phantomworlds.commands.params.WorldFolderParameter;
import me.lokka30.phantomworlds.commands.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 @@ -24,8 +27,10 @@
import me.lokka30.phantomworlds.managers.WorldManager;
import me.lokka30.phantomworlds.misc.CompatibilityChecker;
import me.lokka30.phantomworlds.misc.UpdateCheckerResult;
import me.lokka30.phantomworlds.misc.Utils;
import me.lokka30.phantomworlds.scheduler.BackupScheduler;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.PortalType;
import org.bukkit.World;
Expand Down Expand Up @@ -63,6 +68,8 @@ public class PhantomWorlds extends JavaPlugin {

private static PhantomWorlds instance;

private static VersionCompatibility compatibility;

protected LiteCommands<?> command;

private BukkitTask backupService = null;
Expand Down Expand Up @@ -125,6 +132,13 @@ public void onEnable() {
createTabs.addAll(generateCreateSuggestions());

QuickTimer timer = new QuickTimer(TimeUnit.MILLISECONDS);

final String bukkitVersion = Bukkit.getServer().getBukkitVersion();
if(Utils.isOneSeventeen(bukkitVersion)) {
compatibility = new OneSeventeenCompatibility();
} else {
compatibility = new OneTwentyCompatibility();
}
checkCompatibility();
loadFiles();

Expand Down Expand Up @@ -312,6 +326,10 @@ public static WorldManager worldManager() {
return instance.worldManager;
}

public static VersionCompatibility compatibility() {
return compatibility;
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package me.lokka30.phantomworlds.comatibility;
/*
* Phantom Worlds
* Copyright (C) 2023 - 2024 Daniel "creatorfromhell" Vidmar
*
* 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 <http://www.gnu.org/licenses/>.
*/

import org.bukkit.NamespacedKey;
import org.bukkit.potion.PotionEffectType;

import java.util.ArrayList;
import java.util.List;

/**
* VersionCompatibility
*
* @author creatorfromhell
* @since 2.0.5.0
*/
public interface VersionCompatibility {

/**
* Used to return a list of potion effects suggestions for our /pw set effects command.
* @return The list containing the potion effects that exist.
*/
default List<String> potionEffectSuggestions() {

final List<String> effects = new ArrayList<>();

for(PotionEffectType value : PotionEffectType.values()) {

if(value == null) { //for some reason there is a null value here
continue;
}
effects.add(value.getKey() + ",duration,amplifier");
effects.add(value.getKey() + ",-1,1");
}
return effects;
}

/**
* Used to find an {@link PotionEffectType effect type} based on a string.
* @param effectType The effect type.
* @return The effect type if found, otherwise null
*/
default PotionEffectType findType(final String effectType) {
return PotionEffectType.getByKey(NamespacedKey.fromString(effectType));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package me.lokka30.phantomworlds.comatibility.impl;
/*
* Phantom Worlds
* Copyright (C) 2023 - 2024 Daniel "creatorfromhell" Vidmar
*
* 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 <http://www.gnu.org/licenses/>.
*/

import me.lokka30.phantomworlds.comatibility.VersionCompatibility;
import org.bukkit.potion.PotionEffectType;

import java.util.ArrayList;
import java.util.List;

/**
* OneSixteenCompatibility
*
* @author creatorfromhell
* @since 2.0.5.0
*/
public class OneSeventeenCompatibility implements VersionCompatibility {

/**
* Used to return a list of potion effects suggestions for our /pw set effects command.
*
* @return The list containing the potion effects that exist.
*/
@Override
public List<String> potionEffectSuggestions() {

final List<String> effects = new ArrayList<>();

for(PotionEffectType value : PotionEffectType.values()) {

if(value == null) { //for some reason there is a null value here
continue;
}

effects.add(value.getName() + ",duration,amplifier");
effects.add(value.getName() + ",-1,1");
}
return effects;
}

/**
* Used to find an {@link PotionEffectType effect type} based on a string.
*
* @param effectType The effect type.
*
* @return The effect type if found, otherwise null
*/
@Override
public PotionEffectType findType(String effectType) {
return PotionEffectType.getByName(effectType);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package me.lokka30.phantomworlds.comatibility.impl;
/*
* Phantom Worlds
* Copyright (C) 2023 - 2024 Daniel "creatorfromhell" Vidmar
*
* 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 <http://www.gnu.org/licenses/>.
*/

import me.lokka30.phantomworlds.comatibility.VersionCompatibility;

/**
* OneTwentyCompatibility
*
* @author creatorfromhell
* @since 2.0.5.0
*/
public class OneTwentyCompatibility implements VersionCompatibility {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.lokka30.phantomworlds.commandsredux;
package me.lokka30.phantomworlds.commands;
/*
* Phantom Worlds
* Copyright (C) 2023 - 2024 Daniel "creatorfromhell" Vidmar
Expand All @@ -24,25 +24,25 @@
import dev.rollczi.litecommands.annotations.execute.Execute;
import dev.rollczi.litecommands.annotations.optional.OptionalArg;
import dev.rollczi.litecommands.annotations.permission.Permission;
import me.lokka30.phantomworlds.commandsredux.sub.BackupCommand;
import me.lokka30.phantomworlds.commandsredux.sub.CompatibilityCommand;
import me.lokka30.phantomworlds.commandsredux.sub.CreateCommand;
import me.lokka30.phantomworlds.commandsredux.sub.DebugCommand;
import me.lokka30.phantomworlds.commandsredux.sub.DeleteCommand;
import me.lokka30.phantomworlds.commandsredux.sub.ImportCommand;
import me.lokka30.phantomworlds.commandsredux.sub.InfoCommand;
import me.lokka30.phantomworlds.commandsredux.sub.ListCommand;
import me.lokka30.phantomworlds.commandsredux.sub.LoadCommand;
import me.lokka30.phantomworlds.commandsredux.sub.ReloadCommand;
import me.lokka30.phantomworlds.commandsredux.sub.SetSpawnCommand;
import me.lokka30.phantomworlds.commandsredux.sub.SpawnCommand;
import me.lokka30.phantomworlds.commandsredux.sub.TeleportCommand;
import me.lokka30.phantomworlds.commandsredux.sub.UnloadCommand;
import me.lokka30.phantomworlds.commandsredux.sub.set.SetEffectsCommand;
import me.lokka30.phantomworlds.commandsredux.sub.set.SetGamemodeCommand;
import me.lokka30.phantomworlds.commandsredux.sub.set.SetPortalCommand;
import me.lokka30.phantomworlds.commandsredux.sub.set.SetWhitelistCommand;
import me.lokka30.phantomworlds.commandsredux.utils.WorldFolder;
import me.lokka30.phantomworlds.commands.sub.BackupCommand;
import me.lokka30.phantomworlds.commands.sub.CompatibilityCommand;
import me.lokka30.phantomworlds.commands.sub.CreateCommand;
import me.lokka30.phantomworlds.commands.sub.DebugCommand;
import me.lokka30.phantomworlds.commands.sub.DeleteCommand;
import me.lokka30.phantomworlds.commands.sub.ImportCommand;
import me.lokka30.phantomworlds.commands.sub.InfoCommand;
import me.lokka30.phantomworlds.commands.sub.ListCommand;
import me.lokka30.phantomworlds.commands.sub.LoadCommand;
import me.lokka30.phantomworlds.commands.sub.ReloadCommand;
import me.lokka30.phantomworlds.commands.sub.SetSpawnCommand;
import me.lokka30.phantomworlds.commands.sub.SpawnCommand;
import me.lokka30.phantomworlds.commands.sub.TeleportCommand;
import me.lokka30.phantomworlds.commands.sub.UnloadCommand;
import me.lokka30.phantomworlds.commands.sub.set.SetEffectsCommand;
import me.lokka30.phantomworlds.commands.sub.set.SetGamemodeCommand;
import me.lokka30.phantomworlds.commands.sub.set.SetPortalCommand;
import me.lokka30.phantomworlds.commands.sub.set.SetWhitelistCommand;
import me.lokka30.phantomworlds.commands.utils.WorldFolder;
import org.bukkit.GameMode;
import org.bukkit.PortalType;
import org.bukkit.World;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.lokka30.phantomworlds.commandsredux.handler;
package me.lokka30.phantomworlds.commands.handler;
/*
* Phantom Worlds
* Copyright (C) 2023 - 2024 Daniel "creatorfromhell" Vidmar
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.lokka30.phantomworlds.commandsredux.params;
package me.lokka30.phantomworlds.commands.params;
/*
* Phantom Worlds
* Copyright (C) 2023 - 2024 Daniel "creatorfromhell" Vidmar
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.lokka30.phantomworlds.commandsredux.params;
package me.lokka30.phantomworlds.commands.params;
/*
* Phantom Worlds
* Copyright (C) 2023 - 2024 Daniel "creatorfromhell" Vidmar
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.lokka30.phantomworlds.commandsredux.params;
package me.lokka30.phantomworlds.commands.params;
/*
* Phantom Worlds
* Copyright (C) 2023 - 2024 Daniel "creatorfromhell" Vidmar
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.lokka30.phantomworlds.commandsredux.params;
package me.lokka30.phantomworlds.commands.params;
/*
* Phantom Worlds
* Copyright (C) 2023 - 2024 Daniel "creatorfromhell" Vidmar
Expand All @@ -23,6 +23,7 @@
import dev.rollczi.litecommands.invocation.Invocation;
import dev.rollczi.litecommands.suggestion.SuggestionContext;
import dev.rollczi.litecommands.suggestion.SuggestionResult;
import me.lokka30.phantomworlds.PhantomWorlds;
import org.bukkit.command.CommandSender;
import org.bukkit.potion.PotionEffectType;

Expand All @@ -40,10 +41,10 @@ public class PotionEffectParameter extends ArgumentResolver<CommandSender, Strin
private static final List<String> POTION_EFFECTS = new ArrayList<>();

static {
for(PotionEffectType value : PotionEffectType.values()) {
POTION_EFFECTS.add(value.getKey() + ",duration,amplifier");
POTION_EFFECTS.add(value.getKey() + ",-1,1");
}

System.out.println("Null Check: " + (PhantomWorlds.compatibility() == null));

POTION_EFFECTS.addAll(PhantomWorlds.compatibility().potionEffectSuggestions());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.lokka30.phantomworlds.commandsredux.params;
package me.lokka30.phantomworlds.commands.params;
/*
* Phantom Worlds
* Copyright (C) 2023 Daniel "creatorfromhell" Vidmar
* Copyright (C) 2023 - 2024 Daniel "creatorfromhell" Vidmar
*
* 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.lokka30.phantomworlds.commandsredux.params;
package me.lokka30.phantomworlds.commands.params;
/*
* Phantom Worlds
* Copyright (C) 2023 - 2024 Daniel "creatorfromhell" Vidmar
Expand All @@ -23,7 +23,7 @@
import dev.rollczi.litecommands.invocation.Invocation;
import dev.rollczi.litecommands.suggestion.SuggestionContext;
import dev.rollczi.litecommands.suggestion.SuggestionResult;
import me.lokka30.phantomworlds.commandsredux.utils.WorldFolder;
import me.lokka30.phantomworlds.commands.utils.WorldFolder;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.lokka30.phantomworlds.commandsredux.sub;
package me.lokka30.phantomworlds.commands.sub;

/*
* Phantom Worlds
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.lokka30.phantomworlds.commandsredux.sub;
package me.lokka30.phantomworlds.commands.sub;
/*
* Phantom Worlds
* Copyright (C) 2023 - 2024 Daniel "creatorfromhell" Vidmar
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.lokka30.phantomworlds.commandsredux.sub;
package me.lokka30.phantomworlds.commands.sub;
/*
* Phantom Worlds
* Copyright (C) 2023 - 2024 Daniel "creatorfromhell" Vidmar
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.lokka30.phantomworlds.commandsredux.sub;
package me.lokka30.phantomworlds.commands.sub;
/*
* Phantom Worlds
* Copyright (C) 2023 - 2024 Daniel "creatorfromhell" Vidmar
Expand Down
Loading

0 comments on commit 35fbeb8

Please sign in to comment.