-
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.
Refactored for modern Bukkit (1.13+)
Removed old large font
- Loading branch information
Showing
20 changed files
with
1,039 additions
and
546 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.DS_Store | ||
.classpath | ||
.project | ||
.settings/ | ||
.vscode/ | ||
target/ | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.allocinit.bukkit; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.bukkit.ChatColor; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
public class CommandPlugin extends JavaPlugin implements CommandExecutor { | ||
private String cmdName; | ||
private Map<String, SubCommand<?>> commands = new HashMap<>(); | ||
|
||
public CommandPlugin(String cmdName) { | ||
this.cmdName = cmdName; | ||
} | ||
|
||
public void onEnable() { | ||
try { | ||
this.saveDefaultConfig(); | ||
} catch (Exception e) { | ||
} | ||
|
||
this.getCommand(cmdName).setExecutor(this); | ||
} | ||
|
||
protected void registerSubCommand(SubCommand<?> cmd) { | ||
commands.put(cmd.getCommandName(), cmd); | ||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
try { | ||
if (args.length == 0) | ||
throw new UsageException(); | ||
|
||
SubCommand<?> cmd = commands.get(args[0]); | ||
|
||
if (cmd == null) | ||
throw new UsageException(); | ||
|
||
cmd.doCommand(sender, Arrays.copyOfRange(args, 1, args.length)); | ||
} catch (UsageException e) { | ||
this.writeUsage(sender); | ||
} catch (PermissionDeniedException e) { | ||
sender.sendMessage(ChatColor.RED + "Permission Denied"); | ||
} catch (ErrorException e) { | ||
sender.sendMessage(ChatColor.RED + e.getMessage()); | ||
} catch (Exception e) { | ||
sender.sendMessage("Uncaught exception: " + e.getMessage()); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public void writeUsage(CommandSender player) { | ||
player.sendMessage("[" + ChatColor.GOLD + cmdName + ChatColor.WHITE + " usage]"); | ||
for (SubCommand<?> cmd : commands.values()) | ||
cmd.writeUsage(player); | ||
} | ||
} |
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,9 @@ | ||
package com.allocinit.bukkit; | ||
|
||
public class ErrorException extends RuntimeException { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public ErrorException(String string) { | ||
super(string); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/allocinit/bukkit/PermissionDeniedException.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,5 @@ | ||
package com.allocinit.bukkit; | ||
|
||
public class PermissionDeniedException extends RuntimeException { | ||
private static final long serialVersionUID = 1L; | ||
} |
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,29 @@ | ||
package com.allocinit.bukkit; | ||
|
||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
public abstract class SubCommand<T extends CommandPlugin> { | ||
protected T plugin; | ||
private String cmd; | ||
|
||
public SubCommand(T plugin, String cmd) { | ||
this.plugin = plugin; | ||
this.cmd = cmd; | ||
} | ||
|
||
public String getCommandName() { | ||
return this.cmd; | ||
} | ||
|
||
public abstract void doCommand(CommandSender sender, String[] args) throws Exception; | ||
|
||
public abstract void writeUsage(CommandSender player); | ||
|
||
protected void checkPerm(CommandSender sender, String perm) { | ||
if (sender instanceof Player) { | ||
if (!((Player) sender).hasPermission(perm)) | ||
throw new PermissionDeniedException(); | ||
} | ||
} | ||
} |
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,5 @@ | ||
package com.allocinit.bukkit; | ||
|
||
public class UsageException extends RuntimeException { | ||
private static final long serialVersionUID = 1L; | ||
} |
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
Oops, something went wrong.