Skip to content

Commit

Permalink
Add basic command.
Browse files Browse the repository at this point in the history
  • Loading branch information
lewmilburn committed Jun 26, 2024
1 parent 667b139 commit 05e84a5
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/main/java/net/lewmc/jailhouse/Jailhouse.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.lewmc.jailhouse;

import net.lewmc.jailhouse.commands.JailhouseCommand;
import net.lewmc.jailhouse.utils.LogUtil;
import net.lewmc.jailhouse.utils.UpdateUtil;
import org.bstats.bukkit.Metrics;
Expand Down Expand Up @@ -43,6 +44,8 @@ public void onEnable() {
update.VersionCheck();
update.UpdateConfig();

this.loadCommands();

this.log.info("Startup completed.");
}

Expand All @@ -51,6 +54,14 @@ public void onEnable() {
*/
private void initFileSystem() {
saveDefaultConfig();
saveResource("bans.yml", false);
}

/**
* Loads commands.
*/
public void loadCommands() {
this.getCommand("jailhouse").setExecutor(new JailhouseCommand(this));
}

@Override
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/net/lewmc/jailhouse/commands/JailhouseCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package net.lewmc.jailhouse.commands;

import net.lewmc.jailhouse.Jailhouse;
import net.lewmc.jailhouse.utils.MessageUtil;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;

public class JailhouseCommand implements CommandExecutor {
private final Jailhouse plugin;

/**
* Constructor for the JailhouseCommand class.
* @param plugin References to the main plugin class.
*/
public JailhouseCommand(Jailhouse plugin) {
this.plugin = plugin;
}

/**
* /jailhouse command handler.
* @param commandSender Information about who sent the command - player or console.
* @param command Information about what command was sent.
* @param s Command label - not used here.
* @param args The command's arguments.
* @return boolean true/false - was the command accepted and processed or not?
*/
@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {

MessageUtil message = new MessageUtil(commandSender, this.plugin);

if (command.getName().equalsIgnoreCase("jailhouse")) {
message.PrivateMessage("Running Jailhouse version " + plugin.getDescription().getVersion());
message.PrivateMessage("Created by LewMC.");

return true;
}

return true;
}
}
42 changes: 42 additions & 0 deletions src/main/java/net/lewmc/jailhouse/utils/MessageUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package net.lewmc.jailhouse.utils;

import net.lewmc.jailhouse.Jailhouse;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;

/**
* Jailhouse's Messaging Utility
*/
public class MessageUtil {

private final CommandSender cs;
private final Jailhouse plugin;

/**
* Constructor for the MessageUtil class
*
* @param cs CommandSender - the user who sent the command.
* @param plugin Reference to the main Essence class.
*/
public MessageUtil(CommandSender cs, Jailhouse plugin) {
this.cs = cs;
this.plugin = plugin;
}

/**
* Send a message to the user.
* @param message String - The message taken from the language file.
*/
public void PrivateMessage(String message) {
this.cs.sendMessage(ChatColor.GOLD + "[Jailhouse] " + ChatColor.YELLOW + message);
}

/**
* Send a message to a specific user.
* @param cs CommandSender - Who to send the message to.
* @param message String - The message taken from the language file.
*/
public void SendTo(CommandSender cs, String message) {
cs.sendMessage(ChatColor.GOLD + "[Jailhouse] " + ChatColor.YELLOW + message);
}
}
1 change: 1 addition & 0 deletions src/main/resources/bans.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bans:
6 changes: 5 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ author: LewMC
description: Jailhouse is a free and easy to use Minecraft banning system.
website: https://lewmc.net/plugin/jailhouse
load: POSTWORLD
folia-supported: true
folia-supported: true
commands:
jailhouse:
description: Main command.
aliases: ['jail', 'jh']

0 comments on commit 05e84a5

Please sign in to comment.