This repository has been archived by the owner on Oct 20, 2020. It is now read-only.
-
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.
- Loading branch information
BuildTools
committed
Apr 23, 2018
0 parents
commit 3cd78c7
Showing
12 changed files
with
844 additions
and
0 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,56 @@ | ||
package com.arch.guicommands; | ||
|
||
import org.bukkit.ChatColor; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
public class CommandListener implements CommandExecutor { | ||
|
||
private GUICommands plugin; | ||
|
||
public CommandListener(GUICommands plugin){ | ||
this.plugin = plugin; | ||
} | ||
|
||
// This method is called, when somebody uses our command | ||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
|
||
//test if there are any arguments | ||
//if there are none, just give back the version | ||
if (/*args.length == 0*/true){ | ||
sender.sendMessage(plugin.prefix + ChatColor.GREEN + "Version " + plugin.getDescription().getVersion()); | ||
return true; | ||
} | ||
|
||
Player player = null; | ||
Boolean isPlayer = false; | ||
if (sender instanceof Player){ | ||
player = (Player) sender; | ||
isPlayer = true; | ||
} | ||
|
||
//test if we are reloading | ||
if (args[0].equalsIgnoreCase("reload")){ | ||
//trying to reload | ||
//test for permissions | ||
if (isPlayer){ | ||
if (!player.hasPermission("guicommands.reload")){ | ||
sender.sendMessage(plugin.prefix + ChatColor.RED + "You don't have permission to use that command."); | ||
return true; | ||
} | ||
} | ||
|
||
plugin.ConfigLoad(); | ||
|
||
sender.sendMessage(plugin.prefix + ChatColor.GREEN + "Reloaded"); | ||
} | ||
else{ | ||
sender.sendMessage(plugin.prefix + ChatColor.RESET + "That is an unknown command."); | ||
|
||
} | ||
return true; | ||
} | ||
} |
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.arch.guicommands; | ||
|
||
import com.arch.guicommands.Menu.Argument; | ||
|
||
public class CommandMemory { | ||
|
||
public String uuid; | ||
public Argument[] args; | ||
} |
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,100 @@ | ||
package com.arch.guicommands; | ||
|
||
import com.arch.guicommands.Menu.Argument; | ||
import com.arch.guicommands.Menu.Item; | ||
import com.arch.guicommands.Menu.Menu; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
|
||
import java.util.*; | ||
|
||
public class Config { | ||
private GUICommands plugin; | ||
private boolean debug;//whether to debug verbose | ||
//private boolean bungeemode;//whether or not server is using bungeecord | ||
|
||
public Config(GUICommands plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
public void loadConfig() { | ||
FileConfiguration localConfigFile = plugin.getConfig();//load up config file | ||
|
||
|
||
debug = localConfigFile.getBoolean("debug");//get debug value and hope to the lord all-mighty that they have chosen false | ||
if (debug) { | ||
plugin.console.log("Debug Mode is on. Goodluck!"); | ||
} | ||
/*bungeemode = localConfigFile.getBoolean("bungeemode");//assign bungeemode. Used to see if we need to communicate to bungee for anything like player list | ||
if (bungeemode) { | ||
plugin.console.log("Bungeemode was set to true. Opening Channels."); | ||
}*/ | ||
|
||
//get menus | ||
Set<String> keys = localConfigFile.getConfigurationSection("menus").getKeys(false); | ||
for (String key : keys) { | ||
if (loadGUI(localConfigFile, key)) { | ||
plugin.console.log("Loaded Menu: " + ChatColor.GREEN + key); | ||
} else { | ||
plugin.console.log(ChatColor.DARK_RED + "Failed to load menu: " + ChatColor.GRAY + key); | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
/* Load GUI Menu into list */ | ||
private boolean loadGUI(FileConfiguration localConfigFile, String key) { | ||
Menu tempMenu = new Menu();//object to add to menuList | ||
|
||
//set path | ||
String configPath = "menus." + key + "."; | ||
|
||
tempMenu.setMenuName(key);//sets a menu name | ||
|
||
//set prefix | ||
tempMenu.setPrefix(localConfigFile.getString(configPath + "prefix")); | ||
|
||
//set permission | ||
tempMenu.setPermission(localConfigFile.getString(configPath + "permission")); | ||
|
||
//set usage for usage warning | ||
tempMenu.setUsage(localConfigFile.getString(configPath + "usage")); | ||
|
||
//set rows in GUI | ||
tempMenu.setRows(localConfigFile.getInt(configPath + "rows")); | ||
|
||
//set arguments | ||
List<Argument> argsList = new ArrayList<Argument>(); | ||
String argPath = configPath + "arguments.";//yml path for args | ||
//get the section of all the args that are for this menu | ||
Set<String> args = localConfigFile | ||
.getConfigurationSection(configPath + "arguments") | ||
.getKeys(false); | ||
//for each argument found in config, put the details into an array | ||
for (String arg : args) { | ||
Argument tempArg = new Argument(); | ||
tempArg.setArgNum(Integer.parseInt(arg.substring(arg.length() - 1))); | ||
tempArg.setName(localConfigFile.getString(argPath + arg + ".name")); | ||
argsList.add(tempArg); | ||
} | ||
tempMenu.setArguments(argsList);//add arguments for menu to the menu object | ||
|
||
|
||
//set Items | ||
List<Item> itemList = new ArrayList<Item>(); | ||
String itemsPath = configPath + "Items"; | ||
Set<String> menuItems = localConfigFile | ||
.getConfigurationSection(itemsPath) | ||
.getKeys(false); | ||
for (String item : menuItems) { | ||
Item tempItem = new Item(); | ||
tempItem.formatItem(localConfigFile, itemsPath + "." + item); | ||
itemList.add(tempItem); | ||
} | ||
tempMenu.setItems(itemList); | ||
|
||
plugin.menuList.add(tempMenu);//add menu to list | ||
return true;//nothing has gone wrong, so return true | ||
} | ||
} |
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,114 @@ | ||
package com.arch.guicommands; | ||
|
||
|
||
import com.arch.guicommands.Menu.Item; | ||
import com.arch.guicommands.Menu.Menu; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.command.ConsoleCommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.PluginLogger; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Main class for GUICommands Plugin | ||
*/ | ||
public class GUICommands extends JavaPlugin { | ||
Config config;//config file | ||
Logger console;//logging object | ||
List<Menu> menuList;//list of menus | ||
List<CommandMemory> cmdMemoryList;//list of args and commands to store | ||
|
||
final String prefix = ChatColor.GOLD + "[GUICommands]"; | ||
|
||
/*Fired when the server loads up*/ | ||
@Override | ||
public void onEnable() { | ||
//initialise logger | ||
console = new Logger(this); | ||
menuList = new ArrayList<Menu>(); | ||
cmdMemoryList = new ArrayList<CommandMemory>(); | ||
|
||
if (!ConfigLoad()) { | ||
//config did not load correctly | ||
console.log("Config was not able to be loaded."); | ||
getServer().getPluginManager().disablePlugin(this); | ||
return; | ||
} | ||
/**/ | ||
|
||
/*register Listener */ | ||
getServer().getPluginManager().registerEvents(new GUICommandsListener(this), this); | ||
|
||
/*Register command */ | ||
this.getCommand("guicommands").setExecutor(new CommandListener(this)); | ||
} | ||
|
||
/*Fired when the server stops and disables plugins*/ | ||
@Override | ||
public void onDisable() { | ||
/* */ | ||
} | ||
|
||
/*Loads Config */ | ||
public boolean ConfigLoad() { | ||
//create config file if not already created | ||
this.saveDefaultConfig(); | ||
|
||
//load config | ||
config = new Config(this); | ||
config.loadConfig(); | ||
return true; | ||
} | ||
|
||
/* Finds the menu that we should be using */ | ||
protected Menu findMenuByCommand(String[] cmdArray) { | ||
|
||
//var to hold whether or not the menu matches | ||
boolean menuMatches; | ||
|
||
//go through each menu to find the right command | ||
for (Menu m : menuList) { | ||
String[] tempMArray = m.getUsage().split(" "); | ||
|
||
//reset menuMatches | ||
menuMatches = true; | ||
|
||
//test if the first command is the same | ||
if (tempMArray[0].toLowerCase().equals(cmdArray[0].toLowerCase())) { | ||
//this could be the one, boiseses (Yes, I am a nerd, i am sorry.) | ||
|
||
//test if the commands both have the same amount of arguments | ||
if (tempMArray.length == cmdArray.length) { | ||
//GETTING CLOSER | ||
//last test is to make sure that we have the same non-arg params in the same order | ||
for (int i = 0; i < cmdArray.length; i++) { | ||
//if the tempMArray param starts with "$", it is an argument and will not match | ||
if (tempMArray[i].charAt(0) != '$') { | ||
//not an arg, test if they are the same | ||
if (!tempMArray[i].equalsIgnoreCase(cmdArray[i])){ | ||
//not the same | ||
menuMatches = false; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
//if menuMatches is still true, after this, we ahve found out menu | ||
if (menuMatches){ | ||
return m; | ||
} | ||
} | ||
|
||
} | ||
} | ||
return null; | ||
} | ||
|
||
public void MessagePlayer(Menu m, Player p, String msg) { | ||
p.sendMessage(m.getPrefix() + ChatColor.RESET + msg); | ||
} | ||
} |
Oops, something went wrong.