Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
Update command descriptions and add 'Test' command
Browse files Browse the repository at this point in the history
This update modifies the wording on existing command descriptions to improve clarity. It also introduces a new 'Test' command. With adjustments to the CommandListener and Command.java files, this commit improves instance management and introduces exception handling. It also corrects the referenced logger name in Cherrycore.java.
  • Loading branch information
mathiasclari committed Jan 9, 2024
1 parent c95b698 commit 5b55ded
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/cherrycraft/cherrycore/CherryCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void onEnable() {
@Override
public void onDisable() {
// Plugin shutdown logic
logger.info("ReefCore has been disabled.");
logger.info("CherryCore has been disabled.");
}

void loadDatabase() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.cherrycraft.cherrycore.CherryCore;
import net.cherrycraft.cherrycore.command.commands.*;
import net.cherrycraft.cherrycore.languageSystem.command.LanguageCommand;
import net.cherrycraft.cherrycore.listener.CommandListener;
import net.cherrycraft.cherrycore.manager.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
Expand All @@ -44,24 +45,24 @@ public CommandManager(CherryCore plugin) {
registerCommand(new GamemodeSurvival("gms"));
registerCommand(new GamemodeAdventure("gma"));
registerCommand(new GamemodeSpectator("gmsp"));
registerCommand(new Test("test"));
}

private void registerCommand(Command command) {
PluginCommand pluginCommand = plugin.getCommand(command.getCommandName());
PluginCommand pluginCommand = plugin.getServer().getPluginCommand(command.getCommandName());
if (pluginCommand != null) {
pluginCommand.setExecutor(plugin.getCommandListener());

pluginCommand.setExecutor(new CommandListener(plugin));
commands.add(command);
((Plugin) plugin).getLogger().info("Command '" + command.getCommandName() + "' has been registered.");
} else {
plugin.getLogger().warning("Failed to register command: " + command.getCommandName());
}
}

public boolean runCommand(CommandSender sender, String label, String[] args) {
System.out.println("Attempting to run command: " + label);
public boolean runCommand(CommandSender sender, String commandname, String[] args) {
for (Command command : commands) {
System.out.println(command.getCommandName() + "=" + label);
if (command.getCommandName().equalsIgnoreCase(label)) {
if (command.getCommandName().equalsIgnoreCase(commandname)) {
String permission = command.getPermission();
if (permission != null && !sender.hasPermission("cherrycore." + permission)) {
sender.sendMessage("<red>" + command.getPermissionMessage());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* (c) 2024 CherryCraft. All rights reserved.
*
* This software is the confidential and proprietary information of CherryCraft
* ("Confidential Information"). You shall not disclose such Confidential Information
* and shall use it only in accordance with the terms of the license agreement you
* entered into with CherryCraft.
*
* UNAUTHORIZED COPYING, DISTRIBUTION, OR REPRODUCTION OF THIS SOFTWARE, IN WHOLE OR
* IN PART, IS STRICTLY PROHIBITED. UNLESS OTHERWISE EXPRESSLY AGREED UPON IN A
* WRITTEN AGREEMENT, CHERRYCRAFT PROVIDES THIS SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY
* KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
* NON-INFRINGEMENT.
*
* For inquiries, please contact CherryCraft at [email protected].
*/

package net.cherrycraft.cherrycore.command.commands;

import net.cherrycraft.cherrycore.manager.Command;
import org.bukkit.command.CommandSender;

public class Test extends Command {
public Test(String commandName) {
super("test");
}

@Override
public boolean execute(CommandSender sender, String[] args) {
System.out.println("Test execute");
return true;
}

@Override
public String getPermission() {
return null;
}

@Override
public String getPermissionMessage() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@
public class CommandListener implements CommandExecutor {

private final CherryCore plugin;
private final CommandManager commandManager;
private CommandManager commandManager;

public CommandListener(CherryCore plugin) {
this.plugin = plugin;
this.commandManager = plugin.getCommandManager();
}

@Override
public boolean onCommand(CommandSender sender, org.bukkit.command.Command command, String label, String[] args) {
return commandManager.runCommand(sender, label, args);
public boolean onCommand(CommandSender sender, org.bukkit.command.Command command, String commandname, String[] args) {
if (this.commandManager == null) {
this.commandManager = new CommandManager(this.plugin);
}
return commandManager.runCommand(sender, commandname, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ public Command(String commandName) {
this.commandName = commandName;
}

public abstract boolean execute(CommandSender sender, String[] args);
public boolean execute(CommandSender sender, String[] args) {
try {
return execute(sender, args);
} catch (Exception e) {

return false;
}
}

public String getCommandName() {
return commandName;
Expand Down
14 changes: 8 additions & 6 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ author: CherryCraft
description: CherryCore is a plugin that adds a lot of features to your server.
commands:
language:
description: Change your language
description: Changes the language
gm:
description: Change your gamemode
description: Changes the game mode
gmc:
description: Change your gamemode to creative
description: Changes the game mode to creative
gms:
description: Change your gamemode to survival
description: Changes the game mode to survival
gma:
description: Change your gamemode to adventure
description: Changes the game mode to adventure
gmsp:
description: Change your gamemode to spectator
description: Changes the game mode to spectator
test:
description: Test command

0 comments on commit 5b55ded

Please sign in to comment.