Search in sources :

Example 1 with ISoliniaGod

use of com.solinia.solinia.Interfaces.ISoliniaGod in project solinia3-core by mixxit.

the class CommandEditGod method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player) && !(sender instanceof CommandSender))
        return false;
    if (sender instanceof Player) {
        Player player = (Player) sender;
        if (!sender.isOp() && !sender.hasPermission("solinia.editgod")) {
            player.sendMessage("This is an operator only command");
            return false;
        }
    }
    if (args.length == 0) {
        return false;
    }
    int godid = Integer.parseInt(args[0]);
    if (args.length == 1) {
        try {
            ISoliniaGod solgod = StateManager.getInstance().getConfigurationManager().getGod(godid);
            if (solgod != null) {
                solgod.sendGodSettingsToSender(sender);
            } else {
                sender.sendMessage("ID doesnt exist");
            }
            return true;
        } catch (CoreStateInitException e) {
            sender.sendMessage(e.getMessage());
        }
    }
    if (args.length < 3) {
        sender.sendMessage("Insufficient arguments: godid setting value");
        return false;
    }
    String setting = args[1];
    String value = args[2];
    // a string
    if (args.length > 3 && setting.toLowerCase().contains("description")) {
        value = "";
        int current = 0;
        for (String entry : args) {
            current++;
            if (current <= 2)
                continue;
            value = value + entry + " ";
        }
        value = value.trim();
    }
    if (godid < 1) {
        sender.sendMessage("Invalid god id");
        return false;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getGod(godid) == null) {
            sender.sendMessage("Cannot locate god id: " + godid);
            return false;
        }
        StateManager.getInstance().getConfigurationManager().editGod(godid, setting, value);
        sender.sendMessage("Updating setting on god");
    } catch (InvalidGodSettingException ne) {
        sender.sendMessage("Invalid god setting: " + ne.getMessage());
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : ISoliniaGod(com.solinia.solinia.Interfaces.ISoliniaGod) Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) InvalidGodSettingException(com.solinia.solinia.Exceptions.InvalidGodSettingException) CommandSender(org.bukkit.command.CommandSender)

Example 2 with ISoliniaGod

use of com.solinia.solinia.Interfaces.ISoliniaGod in project solinia3-core by mixxit.

the class SoliniaGodFactory method CreateGod.

public static ISoliniaGod CreateGod(String name) throws CoreStateInitException {
    SoliniaGod entry = new SoliniaGod();
    entry.setId(StateManager.getInstance().getConfigurationManager().getNextGodId());
    entry.setName(name);
    return StateManager.getInstance().getConfigurationManager().addGod(entry);
}
Also used : SoliniaGod(com.solinia.solinia.Models.SoliniaGod) ISoliniaGod(com.solinia.solinia.Interfaces.ISoliniaGod)

Example 3 with ISoliniaGod

use of com.solinia.solinia.Interfaces.ISoliniaGod in project solinia3-core by mixxit.

the class ChatUtils method sendGodInfo.

public static void sendGodInfo(CommandSender sender) throws CoreStateInitException {
    for (ISoliniaGod entry : StateManager.getInstance().getConfigurationManager().getGods()) {
        TextComponent tc = new TextComponent();
        tc.setText(ChatColor.RED + "~ GOD: " + ChatColor.GOLD + entry.getName().toUpperCase() + ChatColor.GRAY + " [" + entry.getId() + "] - " + ChatColor.RESET);
        TextComponent tc2 = new TextComponent();
        tc2.setText("Hover for more details");
        String details = ChatColor.GOLD + entry.getName() + ChatColor.RESET + System.lineSeparator() + "Recommended Alignment: " + ChatColor.GOLD + entry.getAlignment() + ChatColor.RESET + System.lineSeparator() + entry.getDescription();
        tc2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(details).create()));
        tc.addExtra(tc2);
        sender.spigot().sendMessage(tc);
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) ISoliniaGod(com.solinia.solinia.Interfaces.ISoliniaGod) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 4 with ISoliniaGod

use of com.solinia.solinia.Interfaces.ISoliniaGod in project solinia3-core by mixxit.

the class CommandCreateGod method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player) && !(sender instanceof CommandSender))
        return false;
    try {
        if (!sender.isOp() && !sender.hasPermission("solinia.creategod")) {
            sender.sendMessage("You do not have permission to access this command");
            return false;
        }
        if (args.length < 1) {
            sender.sendMessage("Insufficient arguments: name");
            return false;
        }
        // args
        // defaultnpcid
        // spawngroupname
        String godname = args[0];
        if (godname.equals("")) {
            sender.sendMessage("Blank name not allowed when creating god");
            return false;
        }
        godname = godname.replace(" ", "_").toUpperCase();
        if (StateManager.getInstance().getConfigurationManager().getGod(godname) != null) {
            sender.sendMessage("God already exists");
            return true;
        }
        ISoliniaGod god = SoliniaGodFactory.CreateGod(godname);
        sender.sendMessage("Created god: " + god.getId());
        return true;
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : ISoliniaGod(com.solinia.solinia.Interfaces.ISoliniaGod) Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) CommandSender(org.bukkit.command.CommandSender)

Example 5 with ISoliniaGod

use of com.solinia.solinia.Interfaces.ISoliniaGod in project solinia3-core by mixxit.

the class JsonGodRepository method reload.

@Override
public void reload() {
    List<ISoliniaGod> file = new ArrayList<ISoliniaGod>();
    try {
        Gson gson = new Gson();
        BufferedReader br = new BufferedReader(new FileReader(filePath));
        file = gson.fromJson(br, new TypeToken<List<SoliniaGod>>() {
        }.getType());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    Gods.clear();
    for (ISoliniaGod i : file) {
        Gods.put(i.getId(), i);
    }
    System.out.println("Reloaded " + Gods.size() + " Gods");
}
Also used : ISoliniaGod(com.solinia.solinia.Interfaces.ISoliniaGod) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) FileReader(java.io.FileReader) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ISoliniaGod (com.solinia.solinia.Interfaces.ISoliniaGod)6 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)3 CommandSender (org.bukkit.command.CommandSender)3 Player (org.bukkit.entity.Player)3 ArrayList (java.util.ArrayList)2 Gson (com.google.gson.Gson)1 InvalidGodSettingException (com.solinia.solinia.Exceptions.InvalidGodSettingException)1 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)1 SoliniaGod (com.solinia.solinia.Models.SoliniaGod)1 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 List (java.util.List)1 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)1 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)1 TextComponent (net.md_5.bungee.api.chat.TextComponent)1 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)1