-
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.
* Fixed formatting for default prefix issue * Added generic "FireCommand" class * Added commands: /dps /dps reload and /dps forceupdate * Make createMarkerSets and update public methods * Added a tabcompleter for the commands
- Loading branch information
1 parent
5ca5656
commit c7785e4
Showing
8 changed files
with
212 additions
and
5 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
28 changes: 28 additions & 0 deletions
28
src/main/java/com/firecontroller1847/dynmapps/FireCommand.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,28 @@ | ||
package com.firecontroller1847.dynmapps; | ||
|
||
import org.bukkit.command.CommandExecutor; | ||
|
||
/** | ||
* An abstract command that has an instance of the plugin readily available. | ||
*/ | ||
public abstract class FireCommand implements CommandExecutor { | ||
|
||
// Variables | ||
protected FirePlugin plugin; | ||
|
||
// Constructor | ||
public FireCommand(FirePlugin plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
// Getters | ||
public FirePlugin getPlugin() { | ||
return plugin; | ||
} | ||
|
||
// Setters | ||
public void setPlugin(FirePlugin plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/firecontroller1847/dynmapps/command/CommandDynmapPS.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,34 @@ | ||
package com.firecontroller1847.dynmapps.command; | ||
|
||
import com.firecontroller1847.dynmapps.DynmapPS; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
|
||
public class CommandDynmapPS implements CommandExecutor { | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
// Get plugin instance | ||
DynmapPS plugin = (DynmapPS) DynmapPS.getInstance(); | ||
|
||
// Handle-Sub-Commands | ||
if (args.length > 0) { | ||
// Reload | ||
if (args[0].equalsIgnoreCase("reload")) { | ||
return DynmapPS.runCommand(new CommandReload(plugin), "dynmapps.command.reload", sender, command, label, args); | ||
} | ||
|
||
// ForceUpdate | ||
if (args[0].equalsIgnoreCase("forceupdate")) { | ||
return DynmapPS.runCommand(new CommandForceUpdate(plugin), "dynmapps.command.forceupdate", sender, command, label, args); | ||
} | ||
} | ||
|
||
// If it's not the command or any sub command, return false | ||
sender.sendMessage("/" + label + " reload"); | ||
sender.sendMessage("/" + label + " forceupdate"); | ||
return true; | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/firecontroller1847/dynmapps/command/CommandForceUpdate.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,27 @@ | ||
package com.firecontroller1847.dynmapps.command; | ||
|
||
import com.firecontroller1847.dynmapps.DynmapPS; | ||
import com.firecontroller1847.dynmapps.FireCommand; | ||
import com.firecontroller1847.dynmapps.FirePlugin; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
|
||
public class CommandForceUpdate extends FireCommand { | ||
|
||
public CommandForceUpdate(FirePlugin plugin) { | ||
super(plugin); | ||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
(new Thread(() -> { | ||
sender.sendMessage(plugin.getTranslation("forceupdate.wait")); | ||
((DynmapPS) plugin).update(); | ||
sender.sendMessage(plugin.getTranslation("forceupdate.complete")); | ||
})).start(); | ||
|
||
// The command always works | ||
return true; | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/firecontroller1847/dynmapps/command/CommandReload.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,26 @@ | ||
package com.firecontroller1847.dynmapps.command; | ||
|
||
import com.firecontroller1847.dynmapps.FireCommand; | ||
import com.firecontroller1847.dynmapps.FirePlugin; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
|
||
public class CommandReload extends FireCommand { | ||
|
||
public CommandReload(FirePlugin plugin) { | ||
super(plugin); | ||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
// Reload Plugin | ||
plugin.reload(); | ||
|
||
// Send message | ||
sender.sendMessage(plugin.getTranslation("config.reloaded")); | ||
|
||
// The command always works | ||
return true; | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/firecontroller1847/dynmapps/tabcompleter/TabCompleterDynmapPS.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,42 @@ | ||
package com.firecontroller1847.dynmapps.tabcompleter; | ||
|
||
import com.firecontroller1847.dynmapps.DynmapPS; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.command.TabCompleter; | ||
import org.bukkit.util.StringUtil; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class TabCompleterDynmapPS implements TabCompleter { | ||
|
||
// Define Primary Arguments | ||
public static final String[][] FIRST_ARGS = { | ||
{ "reload", "dynmapps.command.reload" }, | ||
{ "forceupdate", "dynmapps.command.forceupdate" } | ||
}; | ||
|
||
@Override | ||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) { | ||
// Completions | ||
ArrayList<String> completions = new ArrayList(); | ||
|
||
// First-Level Arguments | ||
if (args.length == 1) { | ||
ArrayList<String> originals = new ArrayList<>(); | ||
for (String[] argument : FIRST_ARGS) { | ||
if (DynmapPS.hasPermission(sender, argument[1])) { | ||
originals.add(argument[0]); | ||
} | ||
} | ||
StringUtil.copyPartialMatches(args[0], originals, completions); | ||
} | ||
|
||
// Sort Completions & Return | ||
Collections.sort(completions); | ||
return completions; | ||
} | ||
|
||
} |
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