-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added initial command framework and updated the plugin.yml * plugin.yml + DDCommand + CommandManager + InfoCommand * Implemented most of hte logic of the commands + Toggle command * Toggle command functionality in DamageHandler event + Help command * Updated plugin.yml + Reload command + Reload command functionality * Fixed slight issue with info command * Fixed info command * Version Bump * Beautified the info command * Fixed the command registration * Polished, fixed and implemented all commands * Updated README.md
- Loading branch information
Showing
11 changed files
with
251 additions
and
6 deletions.
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
36 changes: 36 additions & 0 deletions
36
src/main/java/com/danlegt/damagedisplay/Commands/CommandManager.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,36 @@ | ||
package com.danlegt.damagedisplay.Commands; | ||
|
||
import com.danlegt.damagedisplay.DamageDisplay; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
|
||
import java.util.List; | ||
|
||
public class CommandManager implements CommandExecutor { | ||
|
||
public static List<DDCommand> registeredCommands = List.of( | ||
new InfoCommand(), | ||
new ToggleCommand(), | ||
new HelpCommand(), | ||
new ReloadCommand() | ||
); | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
if (args.length == 0) { | ||
sender.sendMessage(ChatColor.RED + "Usage: /dd <info|help|toggle|reload>"); | ||
return true; | ||
} | ||
|
||
for ( var cmd: registeredCommands ) { | ||
if ( cmd.getCommandLabel().equalsIgnoreCase(args[0]) ) { | ||
return cmd.handleCommand(sender, command, label, args); | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/danlegt/damagedisplay/Commands/DDCommand.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,14 @@ | ||
package com.danlegt.damagedisplay.Commands; | ||
|
||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
|
||
public interface DDCommand { | ||
|
||
public String getCommandLabel(); | ||
|
||
public boolean handleCommand(CommandSender sender, Command command, String label, String[] args); | ||
|
||
public String getDescription(); | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/danlegt/damagedisplay/Commands/HelpCommand.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,33 @@ | ||
package com.danlegt.damagedisplay.Commands; | ||
|
||
import org.bukkit.ChatColor; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
|
||
public class HelpCommand implements DDCommand { | ||
@Override | ||
public String getCommandLabel() { | ||
return "help"; | ||
} | ||
|
||
@Override | ||
public boolean handleCommand(CommandSender sender, Command command, String label, String[] args) { | ||
if ( !sender.hasPermission("damagedisplay.command.help") ) { | ||
sender.sendMessage(ChatColor.RED + "You do not have permission to use this command."); | ||
return true; | ||
} | ||
|
||
sender.sendMessage(ChatColor.GRAY + "===================="); | ||
CommandManager.registeredCommands.forEach( cmd -> { | ||
sender.sendMessage(ChatColor.GOLD + "/dd " + cmd.getCommandLabel() + ChatColor.GRAY + " - " + ChatColor.RESET + cmd.getDescription()); | ||
}); | ||
sender.sendMessage(ChatColor.GRAY + "===================="); | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Show the help screen with all the available commands"; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/com/danlegt/damagedisplay/Commands/InfoCommand.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,51 @@ | ||
package com.danlegt.damagedisplay.Commands; | ||
|
||
import com.danlegt.damagedisplay.DamageDisplay; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class InfoCommand implements DDCommand{ | ||
|
||
@Override | ||
public String getCommandLabel() { | ||
return "info"; | ||
} | ||
|
||
@Override | ||
public boolean handleCommand(CommandSender sender, Command command, String label, String[] args) { | ||
if ( !sender.hasPermission("damagedisplay.command.info") ) { | ||
sender.sendMessage(ChatColor.RED + "You do not have permission to use this command."); | ||
return true; | ||
} | ||
|
||
FileConfiguration config = DamageDisplay.me.getConfig(); | ||
sender.sendMessage(ChatColor.GREEN + "DamageDisplay (" + ChatColor.AQUA + DamageDisplay.me.getDescription().getVersion() + ChatColor.GREEN + ")"); | ||
for (String key : config.getKeys(true)) { | ||
var val = config.get(key); | ||
if ( val == null ) { | ||
val = ""; | ||
} | ||
|
||
if ( val instanceof Boolean v) { | ||
val = v ? "True" : "False"; | ||
} | ||
|
||
if ( val instanceof String || val instanceof Integer || val instanceof Float || val instanceof Double ) { | ||
sender.sendMessage(ChatColor.GOLD + key + ChatColor.GRAY + ": " + ChatColor.WHITE + config.get(key)); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Retrieve information about the plugin"; | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/danlegt/damagedisplay/Commands/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,31 @@ | ||
package com.danlegt.damagedisplay.Commands; | ||
|
||
import com.danlegt.damagedisplay.DamageDisplay; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
|
||
public class ReloadCommand implements DDCommand { | ||
@Override | ||
public String getCommandLabel() { | ||
return "reload"; | ||
} | ||
|
||
@Override | ||
public boolean handleCommand(CommandSender sender, Command command, String label, String[] args) { | ||
if ( !sender.hasPermission("damagedisplay.command.reload") ) { | ||
sender.sendMessage(ChatColor.RED + "You do not have permission to use this command."); | ||
return true; | ||
} | ||
|
||
sender.sendMessage(ChatColor.GREEN + "Configuration reloaded."); | ||
DamageDisplay.me.reloadConfig(); | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Reload the configuration from the config file into memory."; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/danlegt/damagedisplay/Commands/ToggleCommand.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,48 @@ | ||
package com.danlegt.damagedisplay.Commands; | ||
|
||
import com.danlegt.damagedisplay.DamageDisplay; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ToggleCommand implements DDCommand { | ||
|
||
public static List<Player> disabledPlayers = new ArrayList<>(); | ||
|
||
@Override | ||
public String getCommandLabel() { | ||
return "toggle"; | ||
} | ||
|
||
@Override | ||
public boolean handleCommand(CommandSender sender, Command command, String label, String[] args) { | ||
if ( !sender.hasPermission("damagedisplay.command.toggle") ) { | ||
sender.sendMessage(ChatColor.RED + "You do not have permission to use this command."); | ||
return true; | ||
} | ||
|
||
if ( !(sender instanceof Player player) ) { | ||
sender.sendMessage(ChatColor.RED + "Only players can use this command."); | ||
return true; | ||
} | ||
|
||
if ( ToggleCommand.disabledPlayers.contains(player) ) { | ||
sender.sendMessage("Action bar messages toggled " + ChatColor.GREEN + "ON"); | ||
ToggleCommand.disabledPlayers.remove(player); | ||
} else { | ||
sender.sendMessage("Action bar messages toggled " + ChatColor.RED + "OFF"); | ||
ToggleCommand.disabledPlayers.add(player); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Toggle the actionbar message you receive whenever dealing/taking damage"; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,24 @@ prefix: DamageDisplay | |
authors: [Daniel Legt <[email protected]>] | ||
description: "A simple and efficient plugin for displaying damage events" | ||
website: https://danlegt.com | ||
commands: | ||
dd: | ||
description: "Main command for DamageDisplay" | ||
usage: "/<command> <info|help|toggle|reload>" | ||
aliases: [damagedisplay] | ||
permissions: | ||
damagedisplay.enabled: | ||
default: true | ||
description: "Grants permission to view ActionBar messages to a user" | ||
damagedisplay.command.info: | ||
default: false | ||
description: "Grants permission to /damagedisplay info to show information about the plugin" | ||
description: "Grants permission to /dd info to show information about the plugin" | ||
damagedisplay.command.toggle: | ||
default: true | ||
description: "Grants permission to /dd toggle which enables or disables the ActionBar messages" | ||
damagedisplay.command.reload: | ||
default: false | ||
description: "Grants permission to /dd reload which will reload the configuration file, so you won't have to reload it" | ||
damagedisplay.command.help: | ||
default: false | ||
description: "Grants permission to /damagedisplay toggle which enables or disables the ActionBar messages" | ||
description: "Grants permission to /dd help" |