-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3033 from Multiverse/ben/mv5/list-value-node
Implement ListValueNode and modify actions
- Loading branch information
Showing
17 changed files
with
755 additions
and
95 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
src/main/java/org/mvplugins/multiverse/core/commands/ModifyCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package org.mvplugins.multiverse.core.commands; | ||
|
||
import co.aikar.commands.annotation.CommandAlias; | ||
import co.aikar.commands.annotation.CommandCompletion; | ||
import co.aikar.commands.annotation.CommandPermission; | ||
import co.aikar.commands.annotation.Description; | ||
import co.aikar.commands.annotation.Flags; | ||
import co.aikar.commands.annotation.Optional; | ||
import co.aikar.commands.annotation.Subcommand; | ||
import co.aikar.commands.annotation.Syntax; | ||
import com.dumptruckman.minecraft.util.Logging; | ||
import jakarta.inject.Inject; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jvnet.hk2.annotations.Service; | ||
|
||
import org.mvplugins.multiverse.core.commandtools.MVCommandIssuer; | ||
import org.mvplugins.multiverse.core.commandtools.MVCommandManager; | ||
import org.mvplugins.multiverse.core.commandtools.MultiverseCommand; | ||
import org.mvplugins.multiverse.core.configuration.handle.PropertyModifyAction; | ||
import org.mvplugins.multiverse.core.configuration.handle.StringPropertyHandle; | ||
import org.mvplugins.multiverse.core.world.MultiverseWorld; | ||
import org.mvplugins.multiverse.core.world.WorldManager; | ||
|
||
@Service | ||
@CommandAlias("mv") | ||
class ModifyCommand extends MultiverseCommand { | ||
|
||
private final WorldManager worldManager; | ||
|
||
@Inject | ||
ModifyCommand(@NotNull MVCommandManager commandManager, WorldManager worldManager) { | ||
super(commandManager); | ||
this.worldManager = worldManager; | ||
} | ||
|
||
@Subcommand("modify") | ||
@CommandPermission("multiverse.core.modify") | ||
@CommandCompletion("@mvworlds:scope=both @propsmodifyaction @mvworldpropsname @mvworldpropsvalue") | ||
@Syntax("[world] <set|add|remove|reset> <property> <value>") | ||
@Description("") | ||
void onModifyCommand( | ||
MVCommandIssuer issuer, | ||
|
||
@Flags("resolve=issuerAware") | ||
@Syntax("[world]") | ||
@Description("") | ||
MultiverseWorld world, | ||
|
||
@Syntax("<set|add|remove|reset>") | ||
@Description("") | ||
PropertyModifyAction action, | ||
|
||
@Syntax("<property>") | ||
@Description("") | ||
String propertyName, | ||
|
||
@Optional | ||
@Syntax("[value]") | ||
@Description("") | ||
String propertyValue) { | ||
StringPropertyHandle worldPropertyHandle = world.getStringPropertyHandle(); | ||
worldPropertyHandle.modifyProperty(propertyName, propertyValue, action).onSuccess(ignore -> { | ||
issuer.sendMessage("Property %s set to %s for world %s.".formatted( | ||
propertyName, | ||
worldPropertyHandle.getProperty(propertyName).getOrNull(), | ||
world.getName())); | ||
worldManager.saveWorldsConfig(); | ||
}).onFailure(exception -> { | ||
issuer.sendMessage("Failed to %s property %s to %s for world %s.".formatted( | ||
action.name().toLowerCase(), | ||
propertyName, | ||
propertyValue, | ||
world.getName())); | ||
issuer.sendMessage(exception.getMessage()); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/org/mvplugins/multiverse/core/configuration/handle/PropertyModifyAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.mvplugins.multiverse.core.configuration.handle; | ||
|
||
/** | ||
* The type of modification to a config. | ||
*/ | ||
public enum PropertyModifyAction { | ||
SET, | ||
ADD, | ||
REMOVE, | ||
RESET | ||
} |
Oops, something went wrong.