Skip to content

Commit

Permalink
Updating commands
Browse files Browse the repository at this point in the history
  • Loading branch information
alkanife committed Jul 25, 2023
1 parent cea5ab6 commit a63e0a9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 27 deletions.
2 changes: 1 addition & 1 deletion mcdevtools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>fr.alkanife</groupId>
<artifactId>mcdevtools</artifactId>
<version>1.0.1</version>
<version>1.1.0</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand Down
21 changes: 6 additions & 15 deletions mcdevtools/src/main/java/fr/alkanife/mcdevtools/EchoCommands.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
package fr.alkanife.mcdevtools;

import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.GreedyStringArgument;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Bukkit;

import java.util.Objects;

public class EchoCommands {

public void register() {
new CommandAPICommand("echo")
.withAliases("e")
.withArguments(new GreedyStringArgument("text"))
.executes((commandSender, objects) -> {
if (!commandSender.isOp())
return;

Bukkit.broadcast(Component.text(((String) objects.args()[0]).replaceAll("&", "§")));
}).register();

new CommandAPICommand("echominimessage")
.withAliases("em")
.withFullDescription("Broadcast input")
.withPermission(CommandPermission.OP)
.withArguments(new GreedyStringArgument("minimessage"))
.executes((commandSender, objects) -> {
if (!commandSender.isOp())
return;

Bukkit.broadcast(MiniMessage.miniMessage().deserialize((String) objects.args()[0]));
Bukkit.broadcast(MiniMessage.miniMessage().deserialize((String) Objects.requireNonNull(objects.get(0))));
}).register();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.alkanife.mcdevtools;

import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.GreedyStringArgument;
import dev.jorel.commandapi.arguments.PlayerArgument;
import net.kyori.adventure.text.Component;
Expand All @@ -20,7 +21,9 @@ public class LoreCommand {

public void register() {
new CommandAPICommand("lore")
.withArguments(new PlayerArgument("player"), new GreedyStringArgument("text"))
.withFullDescription("Set a lore to a player's item")
.withPermission(CommandPermission.OP)
.withArguments(new PlayerArgument("player"), new GreedyStringArgument("minimessages"))
.executes((commandSender, objects) -> {
if (!commandSender.isOp())
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void onEnable() {

new EchoCommands().register();
new LoreCommand().register();
new RenameCommand().register();
new RenameCommands().register();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package fr.alkanife.mcdevtools;

import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.GreedyStringArgument;
import dev.jorel.commandapi.arguments.PlayerArgument;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.StyleBuilderApplicable;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.minimessage.MiniMessage;
Expand All @@ -14,17 +13,17 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

public class RenameCommand {
import java.util.Objects;

public class RenameCommands {

public void register() {
new CommandAPICommand("renameitem")
.withAliases("ri")
.withFullDescription("Rename a player's item")
.withPermission(CommandPermission.OP)
.withArguments(new PlayerArgument("player"), new GreedyStringArgument("text"))
.executes((commandSender, objects) -> {
if (!commandSender.isOp())
return;

Player player = (Player) objects.args()[0];
Player player = (Player) Objects.requireNonNull(objects.get(0));

ItemStack itemStack = player.getInventory().getItemInMainHand();

Expand All @@ -35,7 +34,7 @@ public void register() {

Component component = Component.text("")
.color(TextColor.color(255, 255, 255)).decoration(TextDecoration.ITALIC, false)
.append(MiniMessage.miniMessage().deserialize((String) objects.args()[1]));
.append(MiniMessage.miniMessage().deserialize((String) Objects.requireNonNull(objects.get(1))));
itemMeta.displayName(component);
itemStack.setItemMeta(itemMeta);
}).register();
Expand Down

0 comments on commit a63e0a9

Please sign in to comment.