mirror of
https://github.com/CivMC/Civ.git
synced 2026-07-18 00:20:44 +00:00
Added me.Josvth.RandomSpawn.Handlers package and removed annoying
"RandomSpawn" prefix.
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package me.Josvth.RandomSpawn.Handlers;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.Josvth.RandomSpawn.RandomSpawn;
|
||||
import me.Josvth.RandomSpawn.RandomSpawnCommandExecutor;
|
||||
import me.Josvth.RandomSpawn.Commands.*;
|
||||
|
||||
public class CommandHandler implements CommandExecutor{
|
||||
|
||||
RandomSpawn plugin;
|
||||
|
||||
HashMap<String,RandomSpawnCommandExecutor> commands = new HashMap<String,RandomSpawnCommandExecutor>();
|
||||
|
||||
public CommandHandler(RandomSpawn instance) {
|
||||
plugin = instance;
|
||||
|
||||
plugin.getCommand("randomspawn").setExecutor(this);
|
||||
plugin.getCommand("rs").setExecutor(this);
|
||||
|
||||
registerCommands(new RandomSpawnCommandExecutor[]{
|
||||
new RandomSpawnBedsCommand(), new RandomSpawnDisableCommand(), new RandomSpawnEnableCommand(), new RandomSpawnFirstJoinCommand(), new RandomSpawnHelpCommand(), new RandomSpawnInfoCommand(), new RandomSpawnKeepSpawnsCommand(), new RandomSpawnReloadCommand(), new RandomSpawnSetAreaCommand(), new RandomSpawnSetFirstSpawnCommand(), new RandomSpawnTpFirstSpawnCommand(), new RandomSpawnUnsetFirstSpawnCommand()
|
||||
});
|
||||
}
|
||||
|
||||
private void registerCommands(RandomSpawnCommandExecutor[] executors) {
|
||||
|
||||
for(RandomSpawnCommandExecutor executor : executors){
|
||||
executor.setPlugin(plugin);
|
||||
commands.put(executor.getName(), executor);
|
||||
if (executor.getAliases() != null){
|
||||
for(String alias : executor.getAliases()){
|
||||
commands.put(alias, executor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
|
||||
if (args.length == 0 || !commands.containsKey(args[0])) return false;
|
||||
|
||||
RandomSpawnCommandExecutor commandExecutor = commands.get(args[0]);
|
||||
|
||||
if (!(sender instanceof Player)){
|
||||
sender.sendMessage("This command can only be used in game!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!sender.hasPermission(commandExecutor.getPermission())){
|
||||
sender.sendMessage("You don't have the permission to use this command!");
|
||||
}
|
||||
|
||||
if (commandExecutor.onCommand(sender, Arrays.asList(args).subList(1, args.length)) == false){
|
||||
sender.sendMessage(commandExecutor.getUsage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package me.Josvth.RandomSpawn.Handlers;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
import me.Josvth.RandomSpawn.RandomSpawn;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public class YamlHandler{
|
||||
|
||||
RandomSpawn plugin;
|
||||
|
||||
File configFile;
|
||||
File worldsFile;
|
||||
File spawnLocationsFile;
|
||||
|
||||
public FileConfiguration config;
|
||||
public FileConfiguration worlds;
|
||||
public FileConfiguration spawnLocations;
|
||||
|
||||
public YamlHandler(RandomSpawn instance) {
|
||||
this.plugin = instance;
|
||||
setupYamls();
|
||||
loadYamls();
|
||||
}
|
||||
|
||||
public void setupYamls(){
|
||||
configFile = new File(this.plugin.getDataFolder(), "config.yml");
|
||||
worldsFile = new File(this.plugin.getDataFolder(), "worlds.yml");
|
||||
spawnLocationsFile = new File(this.plugin.getDataFolder(), "spawnLocations.yml");
|
||||
|
||||
if (!(configFile.exists())){this.plugin.saveResource("config.yml", false);} // loads default config's on first run
|
||||
if (!(worldsFile.exists())){this.plugin.saveResource("worlds.yml", false);}
|
||||
if (!(spawnLocationsFile.exists())){this.plugin.saveResource("spawnLocations.yml", false);}
|
||||
|
||||
config = new YamlConfiguration();
|
||||
worlds = new YamlConfiguration();
|
||||
spawnLocations = new YamlConfiguration();
|
||||
}
|
||||
|
||||
public void loadYamls() {
|
||||
loadConfig();
|
||||
loadWorlds();
|
||||
loadSpawnLocations();
|
||||
}
|
||||
|
||||
public void loadConfig(){
|
||||
try {
|
||||
config.load(configFile);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void loadWorlds(){
|
||||
try {
|
||||
worlds.load(worldsFile);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void loadSpawnLocations(){
|
||||
try {
|
||||
spawnLocations.load(spawnLocationsFile);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveYamls() {
|
||||
saveConfig();
|
||||
saveWorlds();
|
||||
saveSpawnLocations();
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
try {
|
||||
config.save(configFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveWorlds() {
|
||||
try {
|
||||
worlds.save(worldsFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveSpawnLocations() {
|
||||
try {
|
||||
spawnLocations.save(spawnLocationsFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user