Skip to content

Commit a771652

Browse files
authored
Merge pull request #3291 from Multiverse/5.2
5.2
2 parents 156ec79 + e89b4f1 commit a771652

32 files changed

+840
-84
lines changed

build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ repositories {
2727
configure(apiDependencies) {
2828
serverApiVersion = '1.19.4-R0.1-SNAPSHOT'
2929
mockBukkitServerApiVersion = '1.21'
30-
mockBukkitVersion = '4.31.1'
30+
mockBukkitVersion = '4.72.2'
3131
}
3232

3333
dependencies {
@@ -48,9 +48,9 @@ dependencies {
4848
}
4949

5050
// Utils
51-
shadowed 'io.vavr:vavr:0.10.4'
52-
shadowed 'org.glassfish.hk2:hk2-locator:3.0.3'
53-
shadowed('org.glassfish.hk2:hk2-inhabitant-generator:3.0.3') {
51+
shadowed 'io.vavr:vavr:0.10.7'
52+
shadowed 'org.glassfish.hk2:hk2-locator:3.1.1'
53+
shadowed('org.glassfish.hk2:hk2-inhabitant-generator:3.1.1') {
5454
exclude group: 'org.apache.maven', module: 'maven-core'
5555
}
5656
shadowed('com.dumptruckman.minecraft:Logging:1.1.1') {
@@ -60,8 +60,8 @@ dependencies {
6060
shadowed('org.bstats:bstats-bukkit:3.1.0') {
6161
exclude group: 'org.bukkit', module: 'bukkit'
6262
}
63-
shadowed 'net.minidev:json-smart:2.4.9'
64-
shadowed 'org.jetbrains:annotations:22.0.0'
63+
shadowed 'net.minidev:json-smart:2.5.2'
64+
shadowed 'org.jetbrains:annotations:26.0.2'
6565
shadowed 'io.papermc:paperlib:1.0.8'
6666

6767
// Tests

src/main/java/org/mvplugins/multiverse/core/commands/ImportCommand.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ void onImportCommand(
6868
.biome(parsedFlags.flagValue(flags.biome, ""))
6969
.environment(environment)
7070
.generator(parsedFlags.flagValue(flags.generator, String.class))
71-
.useSpawnAdjust(!parsedFlags.hasFlag(flags.noAdjustSpawn)))
71+
.useSpawnAdjust(!parsedFlags.hasFlag(flags.noAdjustSpawn))
72+
.doFolderCheck(!parsedFlags.hasFlag(flags.skipFolderCheck)))
7273
.onSuccess(newWorld -> {
7374
Logging.fine("World import success: " + newWorld);
7475
issuer.sendInfo(MVCorei18n.IMPORT_SUCCESS, Replace.WORLD.with(newWorld.getName()));
@@ -105,6 +106,10 @@ private Flags(@NotNull CommandFlagsManager flagsManager, @NotNull GeneratorProvi
105106
private final CommandValueFlag<String> biome = flag(CommandValueFlag.builder("--biome", String.class)
106107
.addAlias("-b")
107108
.build());
109+
110+
private final CommandFlag skipFolderCheck = flag(CommandFlag.builder("--skip-folder-check")
111+
.addAlias("-f")
112+
.build());
108113
}
109114

110115
@Service

src/main/java/org/mvplugins/multiverse/core/commands/RemoveCommand.java

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import org.mvplugins.multiverse.core.command.LegacyAliasCommand;
1616
import org.mvplugins.multiverse.core.command.MVCommandIssuer;
1717
import org.mvplugins.multiverse.core.command.MVCommandManager;
18+
import org.mvplugins.multiverse.core.command.flag.CommandFlag;
19+
import org.mvplugins.multiverse.core.command.flag.CommandFlagsManager;
1820
import org.mvplugins.multiverse.core.command.flag.ParsedCommandFlags;
1921
import org.mvplugins.multiverse.core.command.flags.RemovePlayerFlags;
2022
import org.mvplugins.multiverse.core.locale.MVCorei18n;
@@ -23,19 +25,20 @@
2325
import org.mvplugins.multiverse.core.world.MultiverseWorld;
2426
import org.mvplugins.multiverse.core.world.WorldManager;
2527
import org.mvplugins.multiverse.core.world.helpers.PlayerWorldTeleporter;
28+
import org.mvplugins.multiverse.core.world.options.RemoveWorldOptions;
2629

2730
@Service
2831
class RemoveCommand extends CoreCommand {
2932

3033
private final WorldManager worldManager;
3134
private final PlayerWorldTeleporter playerWorldTeleporter;
32-
private final RemovePlayerFlags flags;
35+
private final Flags flags;
3336

3437
@Inject
3538
RemoveCommand(
3639
@NotNull WorldManager worldManager,
3740
@NotNull PlayerWorldTeleporter playerWorldTeleporter,
38-
@NotNull RemovePlayerFlags flags
41+
@NotNull Flags flags
3942
) {
4043
this.worldManager = worldManager;
4144
this.playerWorldTeleporter = playerWorldTeleporter;
@@ -44,7 +47,7 @@ class RemoveCommand extends CoreCommand {
4447

4548
@Subcommand("remove")
4649
@CommandPermission("multiverse.core.remove")
47-
@CommandCompletion("@mvworlds:scope=both @flags:groupName=" + RemovePlayerFlags.NAME)
50+
@CommandCompletion("@mvworlds:scope=both @flags:groupName=" + Flags.NAME)
4851
@Syntax("<world>")
4952
@Description("{@@mv-core.remove.description}")
5053
void onRemoveCommand(
@@ -64,12 +67,14 @@ void onRemoveCommand(
6467
? worldManager.getLoadedWorld(world).map(playerWorldTeleporter::removeFromWorld).getOrElse(AsyncAttemptsAggregate::emptySuccess)
6568
: AsyncAttemptsAggregate.emptySuccess();
6669

67-
future.onSuccess(() -> doWorldRemoving(issuer, world))
70+
future.onSuccess(() -> doWorldRemoving(issuer, world, parsedFlags))
6871
.onFailure(() -> issuer.sendError("Failed to teleport one or more players out of the world!"));
6972
}
7073

71-
private void doWorldRemoving(MVCommandIssuer issuer, MultiverseWorld world) {
72-
worldManager.removeWorld(world)
74+
private void doWorldRemoving(MVCommandIssuer issuer, MultiverseWorld world, ParsedCommandFlags parsedFlags) {
75+
worldManager.removeWorld(RemoveWorldOptions.world(world)
76+
.saveBukkitWorld(!parsedFlags.hasFlag(flags.noSave))
77+
.unloadBukkitWorld(!parsedFlags.hasFlag(flags.noUnloadBukkitWorld)))
7378
.onSuccess(removedWorldName -> {
7479
Logging.fine("World remove success: " + removedWorldName);
7580
issuer.sendInfo(MVCorei18n.REMOVE_SUCCESS, Replace.WORLD.with(removedWorldName));
@@ -79,13 +84,32 @@ private void doWorldRemoving(MVCommandIssuer issuer, MultiverseWorld world) {
7984
});
8085
}
8186

87+
@Service
88+
private static final class Flags extends RemovePlayerFlags {
89+
90+
private static final String NAME = "mvremove";
91+
92+
@Inject
93+
private Flags(@NotNull CommandFlagsManager flagsManager) {
94+
super(NAME, flagsManager);
95+
}
96+
97+
private final CommandFlag noUnloadBukkitWorld = flag(CommandFlag.builder("--no-unload-bukkit-world")
98+
.addAlias("-b")
99+
.build());
100+
101+
private final CommandFlag noSave = flag(CommandFlag.builder("--no-save")
102+
.addAlias("-n")
103+
.build());
104+
}
105+
82106
@Service
83107
private static final class LegacyAlias extends RemoveCommand implements LegacyAliasCommand {
84108
@Inject
85109
LegacyAlias(
86110
@NotNull WorldManager worldManager,
87111
@NotNull PlayerWorldTeleporter playerWorldTeleporter,
88-
RemovePlayerFlags flags
112+
@NotNull Flags flags
89113
) {
90114
super(worldManager, playerWorldTeleporter, flags);
91115
}

src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private void handleSingleTeleport(MVCommandIssuer issuer, LoadedMultiverseWorld
108108
safetyTeleporter.to(mvWorld.getSpawnLocation())
109109
.by(issuer)
110110
.checkSafety(checkSafety)
111-
.teleport(entity)
111+
.teleportSingle(entity)
112112
.onSuccess(() -> issuer.sendInfo(MVCorei18n.SPAWN_SUCCESS,
113113
Replace.PLAYER.with(entity.equals(issuer.getPlayer())
114114
? Message.of(MVCorei18n.GENERIC_YOU)
@@ -119,7 +119,7 @@ private void handleSingleTeleport(MVCommandIssuer issuer, LoadedMultiverseWorld
119119
? Message.of(MVCorei18n.GENERIC_YOU)
120120
: Message.of(entity.getName())),
121121
Replace.WORLD.with(mvWorld.getName()),
122-
Replace.REASON.with(failure.getFailureMessage())));
122+
Replace.REASON.with(failure.getFirst().getFailureMessage())));
123123
}
124124

125125
private void handleMultiTeleport(MVCommandIssuer issuer, LoadedMultiverseWorld mvWorld,

src/main/java/org/mvplugins/multiverse/core/config/CoreConfigNodes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ private <N extends Node> N node(N node) {
518518
.build());
519519

520520
final ConfigNode<Boolean> debugPermissions = node(ConfigNode.builder("misc.debug-permissions", Boolean.class)
521+
.comment("")
521522
.comment("Sets whether console will log every permission check done by all multiverse plugins.")
522523
.comment("This will only work if the above 'global-debug' is set to 1 or more.")
523524
.defaultValue(false)

src/main/java/org/mvplugins/multiverse/core/display/filters/RegexContentFilter.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,12 @@ public boolean checkMatch(String value) {
6969
if (!hasValidRegex()) {
7070
return false;
7171
}
72-
String text = ChatTextFormatter.removeColor(String.valueOf(value)).toLowerCase();
72+
String text = ChatTextFormatter.removeColor(String.valueOf(value));
73+
if (text == null) {
74+
return false;
75+
}
7376
try {
74-
return regexPattern.matcher(text).find();
77+
return regexPattern.matcher(text.toLowerCase()).find();
7578
} catch (PatternSyntaxException ignored) {
7679
Logging.warning("Error parsing regex '%s' for input '%s'", regexString, text);
7780
return false;

src/main/java/org/mvplugins/multiverse/core/listeners/MVChatListener.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ void asyncPlayerChat(AsyncPlayerChatEvent event) {
8888
String prefixChatFormat = config.getPrefixChatFormat();
8989
prefixChatFormat = prefixChatFormat.replace("%world%", worldName).replace("%chat%", chat);
9090
prefixChatFormat = ChatTextFormatter.colorize(prefixChatFormat);
91-
92-
event.setFormat(prefixChatFormat);
91+
if (prefixChatFormat != null) {
92+
event.setFormat(prefixChatFormat);
93+
}
9394
}
9495

9596
private String getWorldName(Player player) {

src/main/java/org/mvplugins/multiverse/core/listeners/MVPlayerListener.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.mvplugins.multiverse.core.economy.MVEconomist;
4242
import org.mvplugins.multiverse.core.event.MVRespawnEvent;
4343
import org.mvplugins.multiverse.core.locale.PluginLocales;
44+
import org.mvplugins.multiverse.core.permissions.CorePermissionsChecker;
4445
import org.mvplugins.multiverse.core.teleportation.BlockSafety;
4546
import org.mvplugins.multiverse.core.teleportation.TeleportQueue;
4647
import org.mvplugins.multiverse.core.utils.result.ResultChain;
@@ -70,6 +71,7 @@ final class MVPlayerListener implements CoreListener {
7071
private final DestinationsProvider destinationsProvider;
7172
private final EnforcementHandler enforcementHandler;
7273
private final DimensionFinder dimensionFinder;
74+
private final CorePermissionsChecker corePermissionsChecker;
7375

7476
private final Map<String, String> playerWorld = new ConcurrentHashMap<>();
7577

@@ -86,7 +88,8 @@ final class MVPlayerListener implements CoreListener {
8688
Provider<MVCommandManager> commandManagerProvider,
8789
DestinationsProvider destinationsProvider,
8890
EnforcementHandler enforcementHandler,
89-
DimensionFinder dimensionFinder) {
91+
DimensionFinder dimensionFinder,
92+
CorePermissionsChecker corePermissionsChecker) {
9093
this.plugin = plugin;
9194
this.config = config;
9295
this.worldManagerProvider = worldManagerProvider;
@@ -99,6 +102,7 @@ final class MVPlayerListener implements CoreListener {
99102
this.destinationsProvider = destinationsProvider;
100103
this.enforcementHandler = enforcementHandler;
101104
this.dimensionFinder = dimensionFinder;
105+
this.corePermissionsChecker = corePermissionsChecker;
102106
}
103107

104108
private WorldManager getWorldManager() {
@@ -244,6 +248,10 @@ private void handleJoinLocation(PlayerSpawnLocationEvent event) {
244248
Logging.warning("Joindestination is enabled but no destination has been specified in config!");
245249
return;
246250
}
251+
if (corePermissionsChecker.hasJoinLocationBypassPermission(event.getPlayer())) {
252+
Logging.finer("Player %s has bypass permission for JoinDestination", event.getPlayer().getName());
253+
return;
254+
}
247255
Logging.finer("JoinDestination is " + config.getJoinDestination());
248256
destinationsProvider.parseDestination(config.getJoinDestination())
249257
.map(destination -> destination.getLocation(event.getPlayer())

src/main/java/org/mvplugins/multiverse/core/locale/MVCorei18n.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,13 @@ public enum MVCorei18n implements MessageKeyProvider {
308308
IMPORTWORLD_WORLDEXISTUNLOADED,
309309
IMPORTWORLD_WORLDEXISTLOADED,
310310
IMPORTWORLD_WORLDFOLDERINVALID,
311+
IMPORTWORLD_BUKKITENVIRONMENTMISMATCH,
311312

312313
LOADWORLD_WORLDALREADYLOADING,
313314
LOADWORLD_WORLDNONEXISTENT,
314315
LOADWORLD_WORLDEXISTFOLDER,
315316
LOADWORLD_WORLDEXISTLOADED,
317+
LOADWORLD_BUKKITENVIRONMENTMISMATCH,
316318

317319
REMOVEWORLD_WORLDNONEXISTENT,
318320

src/main/java/org/mvplugins/multiverse/core/permissions/CorePermissions.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.dumptruckman.minecraft.util.Logging;
44
import io.vavr.control.Try;
5+
import jakarta.annotation.PostConstruct;
56
import jakarta.inject.Inject;
67
import org.bukkit.permissions.Permission;
78
import org.bukkit.permissions.PermissionDefault;
@@ -15,6 +16,11 @@
1516

1617
@Service
1718
public final class CorePermissions {
19+
/**
20+
* Permission to bypass the join location.
21+
*/
22+
static final String JOINLOCATION_BYPASS = "mv.bypass.joinlocation";
23+
1824
/**
1925
* Permission to access a world.
2026
*/
@@ -52,6 +58,12 @@ public final class CorePermissions {
5258
this.pluginManager = pluginManager;
5359
}
5460

61+
@PostConstruct
62+
void registerBasePermissions() {
63+
pluginManager.addPermission(new Permission(JOINLOCATION_BYPASS, PermissionDefault.FALSE));
64+
Logging.fine("Successfully registered base permissions");
65+
}
66+
5567
public Try<Void> addWorldPermissions(@NotNull MultiverseWorld world) {
5668
return Try.run(() -> {
5769
pluginManager.addPermission(new Permission(

0 commit comments

Comments
 (0)