-
Notifications
You must be signed in to change notification settings - Fork 0
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 #23 from TheNextLvl-net/reload
Add /command reload and /command save
- Loading branch information
Showing
14 changed files
with
325 additions
and
1 deletion.
There are no files selected for viewing
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
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
38 changes: 38 additions & 0 deletions
38
paper/src/main/java/net/thenextlvl/commander/paper/command/ReloadCommand.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,38 @@ | ||
package net.thenextlvl.commander.paper.command; | ||
|
||
import com.mojang.brigadier.Command; | ||
import com.mojang.brigadier.builder.ArgumentBuilder; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import io.papermc.paper.command.brigadier.CommandSourceStack; | ||
import io.papermc.paper.command.brigadier.Commands; | ||
import lombok.RequiredArgsConstructor; | ||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; | ||
import net.thenextlvl.commander.paper.CommanderPlugin; | ||
import org.bukkit.entity.Player; | ||
|
||
@RequiredArgsConstructor | ||
@SuppressWarnings("UnstableApiUsage") | ||
class ReloadCommand { | ||
private final CommanderPlugin plugin; | ||
|
||
public ArgumentBuilder<CommandSourceStack, ?> create() { | ||
return Commands.literal("reload").executes(this::reload); | ||
} | ||
|
||
private int reload(CommandContext<CommandSourceStack> context) { | ||
var sender = context.getSource().getSender(); | ||
try { | ||
var commands = plugin.commandRegistry().reload(sender); | ||
var permissions = plugin.permissionOverride().reload(sender); | ||
var success = commands || permissions; | ||
if (success && sender instanceof Player player) player.updateCommands(); | ||
var message = success ? "command.reload.success" : "nothing.changed"; | ||
plugin.bundle().sendMessage(sender, message); | ||
return success ? Command.SINGLE_SUCCESS : 0; | ||
} catch (Exception e) { | ||
plugin.bundle().sendMessage(sender, "command.reload.failed", | ||
Placeholder.parsed("error", e.getMessage())); | ||
return 0; | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
paper/src/main/java/net/thenextlvl/commander/paper/command/SaveCommand.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,28 @@ | ||
package net.thenextlvl.commander.paper.command; | ||
|
||
import com.mojang.brigadier.Command; | ||
import com.mojang.brigadier.builder.ArgumentBuilder; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import io.papermc.paper.command.brigadier.CommandSourceStack; | ||
import io.papermc.paper.command.brigadier.Commands; | ||
import lombok.RequiredArgsConstructor; | ||
import net.thenextlvl.commander.paper.CommanderPlugin; | ||
|
||
@RequiredArgsConstructor | ||
@SuppressWarnings("UnstableApiUsage") | ||
class SaveCommand { | ||
private final CommanderPlugin plugin; | ||
|
||
public ArgumentBuilder<CommandSourceStack, ?> create() { | ||
return Commands.literal("save").executes(this::save); | ||
} | ||
|
||
private int save(CommandContext<CommandSourceStack> context) { | ||
var sender = context.getSource().getSender(); | ||
plugin.commandRegistry().getHiddenFile().save(); | ||
plugin.commandRegistry().getUnregisteredFile().save(); | ||
plugin.permissionOverride().getOverridesFile().save(); | ||
plugin.bundle().sendMessage(sender, "command.saved"); | ||
return Command.SINGLE_SUCCESS; | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
velocity/src/main/java/net/thenextlvl/commander/velocity/command/ReloadCommand.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,35 @@ | ||
package net.thenextlvl.commander.velocity.command; | ||
|
||
import com.mojang.brigadier.Command; | ||
import com.mojang.brigadier.builder.ArgumentBuilder; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import com.velocitypowered.api.command.BrigadierCommand; | ||
import com.velocitypowered.api.command.CommandSource; | ||
import lombok.RequiredArgsConstructor; | ||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; | ||
import net.thenextlvl.commander.velocity.CommanderPlugin; | ||
|
||
@RequiredArgsConstructor | ||
class ReloadCommand { | ||
private final CommanderPlugin plugin; | ||
|
||
public ArgumentBuilder<CommandSource, ?> create() { | ||
return BrigadierCommand.literalArgumentBuilder("reload").executes(this::reload); | ||
} | ||
|
||
private int reload(CommandContext<CommandSource> context) { | ||
var sender = context.getSource(); | ||
try { | ||
var commands = plugin.commandRegistry().reload(sender); | ||
var permissions = plugin.permissionOverride().reload(sender); | ||
var success = commands || permissions; | ||
var message = success ? "command.reload.success" : "nothing.changed"; | ||
plugin.bundle().sendMessage(sender, message); | ||
return success ? Command.SINGLE_SUCCESS : 0; | ||
} catch (Exception e) { | ||
plugin.bundle().sendMessage(sender, "command.reload.failed", | ||
Placeholder.parsed("error", e.getMessage())); | ||
return 0; | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
velocity/src/main/java/net/thenextlvl/commander/velocity/command/SaveCommand.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,27 @@ | ||
package net.thenextlvl.commander.velocity.command; | ||
|
||
import com.mojang.brigadier.Command; | ||
import com.mojang.brigadier.builder.ArgumentBuilder; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import com.velocitypowered.api.command.BrigadierCommand; | ||
import com.velocitypowered.api.command.CommandSource; | ||
import lombok.RequiredArgsConstructor; | ||
import net.thenextlvl.commander.velocity.CommanderPlugin; | ||
|
||
@RequiredArgsConstructor | ||
class SaveCommand { | ||
private final CommanderPlugin plugin; | ||
|
||
public ArgumentBuilder<CommandSource, ?> create() { | ||
return BrigadierCommand.literalArgumentBuilder("save").executes(this::save); | ||
} | ||
|
||
private int save(CommandContext<CommandSource> context) { | ||
var sender = context.getSource(); | ||
plugin.commandRegistry().getHiddenFile().save(); | ||
plugin.commandRegistry().getUnregisteredFile().save(); | ||
plugin.permissionOverride().getOverridesFile().save(); | ||
plugin.bundle().sendMessage(sender, "command.saved"); | ||
return Command.SINGLE_SUCCESS; | ||
} | ||
} |
Oops, something went wrong.