Skip to content

Commit

Permalink
2.0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorfromhell committed Aug 1, 2024
1 parent 0237f0d commit 11c7b6a
Show file tree
Hide file tree
Showing 15 changed files with 307 additions and 7 deletions.
18 changes: 17 additions & 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.11</version>
<version>2.0.12</version>

<name>PhantomWorlds</name>
<description>The Robust World Manager for Minecraft Servers</description>
Expand Down Expand Up @@ -38,6 +38,10 @@
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<id>devmart-other</id>
<url>https://nexuslite.gcnt.net/repos/other/</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -53,6 +57,12 @@
<version>2.11.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.tcoded</groupId>
<artifactId>FoliaLib</artifactId>
<version>0.3.4</version>
<scope>compile</scope>
</dependency>
<!-- <dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
Expand Down Expand Up @@ -143,6 +153,10 @@
<pattern>dev.dejvokep.boostedyaml</pattern>
<shadedPattern>${phantom.relocation}.yaml</shadedPattern>
</relocation>
<relocation>
<pattern>com.tcoded.folialib</pattern>
<shadedPattern>${phantom.relocation}.folia</shadedPattern>
</relocation>
</relocations>
<minimizeJar>true</minimizeJar>
</configuration>
Expand All @@ -163,6 +177,8 @@
<include>dev.rollczi:*</include>
<include>panda.std:*</include>
<include>org.panda-lang:*</include>
<include>com.tcoded:*</include>
<include>com.tcoded.folialib:*</include>
</includes>
</artifactSet>
</configuration>
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.lokka30.phantomworlds;

import com.tcoded.folialib.FoliaLib;
import dev.rollczi.litecommands.LiteCommands;
import dev.rollczi.litecommands.argument.ArgumentKey;
import dev.rollczi.litecommands.bukkit.LiteBukkitFactory;
Expand All @@ -10,6 +11,7 @@
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.handler.PWInvalidUsageHandler;
import me.lokka30.phantomworlds.commands.params.AliasWorldParameter;
import me.lokka30.phantomworlds.commands.params.GamemodeParameter;
import me.lokka30.phantomworlds.commands.params.PortalParameter;
Expand Down Expand Up @@ -73,6 +75,7 @@ public class PhantomWorlds extends JavaPlugin {
private static VersionCompatibility compatibility;

protected LiteCommands<?> command;
protected FoliaLib folia;

private BukkitTask backupService = null;

Expand Down Expand Up @@ -137,7 +140,6 @@ public void onEnable() {
} else {
getServer().getPluginManager().registerEvents(new PluginEnableListener(), this);
}

createTabs.addAll(generateCreateSuggestions());

QuickTimer timer = new QuickTimer(TimeUnit.MILLISECONDS);
Expand Down Expand Up @@ -255,6 +257,7 @@ void registerCommands() {
.settings(settings -> settings
.nativePermissions(false)
)
.invalidUsage(new PWInvalidUsageHandler())
.argument(GameMode.class, new GamemodeParameter())
.argument(PortalType.class, new PortalParameter())
.argument(String.class, ArgumentKey.of("world-setting"), new SettingParameter())
Expand Down Expand Up @@ -386,4 +389,8 @@ private ArrayList<String> addTrueFalseValues(String option) {

return list;
}

public FoliaLib folia() {
return folia;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import dev.rollczi.litecommands.annotations.permission.Permission;
import me.lokka30.phantomworlds.commands.sub.BackupCommand;
import me.lokka30.phantomworlds.commands.sub.CompatibilityCommand;
import me.lokka30.phantomworlds.commands.sub.CopyCommand;
import me.lokka30.phantomworlds.commands.sub.CreateCommand;
import me.lokka30.phantomworlds.commands.sub.DebugCommand;
import me.lokka30.phantomworlds.commands.sub.DeleteCommand;
Expand Down Expand Up @@ -75,6 +76,13 @@ public void create(@Context CommandSender commandSender, @Arg("world name") fina
CreateCommand.onCommand(commandSender, name, environment, settings);
}

@Execute(name = "copy")
@Permission("phantomworlds.command.phantomworlds.copy")
@Description("command.phantomworlds.help.copy")
public void copy(@Context CommandSender commandSender, @Arg("world name") final String newWorld, @OptionalArg("world folder") final WorldFolder world) {
CopyCommand.onCommand(commandSender, newWorld, world);
}

@Execute(name = "compatibility")
@Permission("phantomworlds.command.phantomworlds.compatibility")
@Description("command.phantomworlds.help.compatibility")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import dev.rollczi.litecommands.invalidusage.InvalidUsageHandler;
import dev.rollczi.litecommands.invocation.Invocation;
import dev.rollczi.litecommands.schematic.Schematic;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;

/**
Expand All @@ -37,5 +38,18 @@ public void handle(Invocation<CommandSender> invocation, InvalidUsage<CommandSen
final CommandSender sender = invocation.sender();
final Schematic schematic = result.getSchematic();

if (schematic.isOnlyFirst()) {
sender.sendMessage(color("&cInvalid usage of command! &7(" + schematic.first() + ")"));
return;
}

sender.sendMessage(color("&cInvalid usage of command!"));
for (String scheme : schematic.all()) {
sender.sendMessage(color("&8 - &7" + scheme));
}
}

private String color(final String message) {
return ChatColor.translateAlternateColorCodes('&', message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@
public class AliasWorldParameter extends ArgumentResolver<CommandSender, World> {
@Override
protected ParseResult<World> parse(Invocation<CommandSender> invocation, Argument<World> context, String argument) {
return ParseResult.success(PhantomWorlds.worldManager().findWorld(argument));

final World world = PhantomWorlds.worldManager().findWorld(argument);
if(world == null) {
return ParseResult.failure("Invalid world name");
}

return ParseResult.success(world);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public class PotionEffectParameter extends ArgumentResolver<CommandSender, Strin

@Override
protected ParseResult<String> parse(Invocation<CommandSender> invocation, Argument<String> context, String argument) {
if(argument.isEmpty()) {
return ParseResult.failure("Invalid effect argument.");
}

return ParseResult.success(argument);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
public class SettingParameter extends ArgumentResolver<CommandSender, String> {
@Override
protected ParseResult<String> parse(Invocation<CommandSender> invocation, Argument<String> context, String argument) {
if(argument.isEmpty()) {
return ParseResult.failure("Invalid effect argument.");
}
return ParseResult.success(argument);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public SuggestionResult suggest(Invocation<CommandSender> invocation, Argument<W
final File directory = Bukkit.getWorldContainer();

if(directory.exists()) {
for(File file : directory.listFiles()) {
for(final File file : directory.listFiles()) {
final File levelDat = new File(file, "level.dat");
if(file.isDirectory() && levelDat.exists()) {
folders.add(file.getName());
Expand Down
106 changes: 106 additions & 0 deletions src/main/java/me/lokka30/phantomworlds/commands/sub/CopyCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package me.lokka30.phantomworlds.commands.sub;
/*
* 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.microlib.messaging.MultiMessage;
import me.lokka30.phantomworlds.PhantomWorlds;
import me.lokka30.phantomworlds.commands.utils.WorldFolder;
import me.lokka30.phantomworlds.misc.WorldCopyResponse;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;

import java.util.Arrays;

import static me.lokka30.phantomworlds.misc.WorldCopyResponse.INVALID;
import static me.lokka30.phantomworlds.misc.WorldCopyResponse.COPIED;

/**
* LoadCommand
*
* @author creatorfromhell
* @since 2.0.5.0
*/
public class CopyCommand {

public static void onCommand(final CommandSender sender, final String newWorld, final WorldFolder world) {

if(world == null || world.getFolder() == null || newWorld.isEmpty()) {
(new MultiMessage(
PhantomWorlds.instance().messages.getConfig()
.getStringList("command.phantomworlds.usages.copy"), Arrays.asList(
new MultiMessage.Placeholder("prefix",
PhantomWorlds.instance().messages.getConfig().getString("common.prefix", "&b&lPhantomWorlds: &7"),
true),
new MultiMessage.Placeholder("label", "pw", false)
))).send(sender);
return;
}

if(Bukkit.getWorld(newWorld) != null) {
(new MultiMessage(
PhantomWorlds.instance().messages.getConfig()
.getStringList("command.phantomworlds.subcommands.create.already-loaded"),
Arrays.asList(
new MultiMessage.Placeholder("prefix", PhantomWorlds.instance().messages.getConfig()
.getString("common.prefix", "&b&lPhantomWorlds: &7"), true),
new MultiMessage.Placeholder("world", newWorld, false),
new MultiMessage.Placeholder("label", "pw", false)
))).send(sender);
return;
}

final WorldCopyResponse response = PhantomWorlds.worldManager().copyWorld(world.getFolder(), newWorld);

if(response == INVALID) {
(new MultiMessage(
PhantomWorlds.instance().messages.getConfig()
.getStringList("command.phantomworlds.subcommands.copy.failure-copying"),
Arrays.asList(
new MultiMessage.Placeholder("prefix", PhantomWorlds.instance().messages.getConfig()
.getString("common.prefix", "&b&lPhantomWorlds: &7"), true),
new MultiMessage.Placeholder("world", world.getFolder(), false),
new MultiMessage.Placeholder("label", "pw", false)
))).send(sender);
return;
}

if(response != COPIED) {

(new MultiMessage(
PhantomWorlds.instance().messages.getConfig()
.getStringList("command.phantomworlds.subcommands.copy.failure-loading"),
Arrays.asList(
new MultiMessage.Placeholder("prefix", PhantomWorlds.instance().messages.getConfig()
.getString("common.prefix", "&b&lPhantomWorlds: &7"), true),
new MultiMessage.Placeholder("world", world.getFolder(), false),
new MultiMessage.Placeholder("label", "pw", false)
))).send(sender);
return;
}

(new MultiMessage(
PhantomWorlds.instance().messages.getConfig().getStringList(
"command.phantomworlds.subcommands.copy.success"),
Arrays.asList(
new MultiMessage.Placeholder("prefix", PhantomWorlds.instance().messages.getConfig()
.getString("common.prefix", "&b&lPhantomWorlds: &7"), true),
new MultiMessage.Placeholder("world", world.getFolder(), false),
new MultiMessage.Placeholder("new_world", newWorld, false)
))).send(sender);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void alertIncorrectVersion(final PWFile pwFile) {
public enum PWFile {
SETTINGS(3),
ADVANCED_SETTINGS(1),
MESSAGES(10),
MESSAGES(11),
DATA(2);

public final int latestFileVersion; // If == -1: 'do not migrate me!'
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/me/lokka30/phantomworlds/managers/WorldManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import me.lokka30.microlib.messaging.MultiMessage;
import me.lokka30.phantomworlds.PhantomWorlds;
import me.lokka30.phantomworlds.misc.Utils;
import me.lokka30.phantomworlds.misc.WorldCopyResponse;
import me.lokka30.phantomworlds.misc.WorldLoadResponse;
import me.lokka30.phantomworlds.world.PhantomWorld;
import org.bukkit.Bukkit;
Expand All @@ -14,6 +15,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Locale;
Expand Down Expand Up @@ -117,6 +119,35 @@ public WorldLoadResponse loadWorld(final String worldName) {
return WorldLoadResponse.LOADED;
}

public WorldCopyResponse copyWorld(final String worldName, final String newWorldName) {
final World world = Bukkit.getWorld(worldName);
if(world == null) {
return WorldCopyResponse.INVALID;
}

final File worldFolder = new File(Bukkit.getWorldContainer(), worldName);
final File newWorldFolder = new File(Bukkit.getWorldContainer(), newWorldName);

try {

if(!Utils.copyFolder(worldFolder.toPath(), newWorldFolder.toPath())) {
return WorldCopyResponse.INVALID;
}
final PhantomWorld pworld = new PhantomWorld(
newWorldName, world.getEnvironment(), world.canGenerateStructures(), null,
null, PhantomWorlds.compatibility().hardcore(world), world.getSeed(), world.getWorldType(), world.getAllowMonsters(),
world.getAllowAnimals(), world.getKeepSpawnInMemory(), world.getPVP(), world.getDifficulty(), GameMode.SURVIVAL
);
pworld.save();
loadWorld(newWorldName);

} catch(Exception ignore) {
return WorldCopyResponse.INVALID;
}

return WorldCopyResponse.COPIED;
}

/**
* This creates a PhantomWorld object by scanning the data file by the specified name. Developers
* are expected to make sure the specified world exists prior to retrieving it.
Expand Down
Loading

0 comments on commit 11c7b6a

Please sign in to comment.