Search in sources :

Example 1 with ISoliniaSpawnGroup

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

the class JsonSpawnGroupRepository method reload.

@Override
public void reload() {
    List<ISoliniaSpawnGroup> file = new ArrayList<ISoliniaSpawnGroup>();
    try {
        GsonBuilder gsonbuilder = new GsonBuilder();
        gsonbuilder.registerTypeAdapterFactory(new ISoliniaSpawnGroupTypeAdapterFactory(SoliniaSpawnGroup.class));
        Gson gson = gsonbuilder.create();
        BufferedReader br = new BufferedReader(new FileReader(filePath));
        file = gson.fromJson(br, new TypeToken<List<SoliniaSpawnGroup>>() {
        }.getType());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    spawngroups.clear();
    for (ISoliniaSpawnGroup i : file) {
        spawngroups.put(i.getId(), i);
    }
    System.out.println("Reloaded " + spawngroups.size() + " spawngroups");
}
Also used : ISoliniaSpawnGroupTypeAdapterFactory(com.solinia.solinia.Factories.ISoliniaSpawnGroupTypeAdapterFactory) GsonBuilder(com.google.gson.GsonBuilder) SoliniaSpawnGroup(com.solinia.solinia.Models.SoliniaSpawnGroup) ISoliniaSpawnGroup(com.solinia.solinia.Interfaces.ISoliniaSpawnGroup) ISoliniaSpawnGroup(com.solinia.solinia.Interfaces.ISoliniaSpawnGroup) 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)

Example 2 with ISoliniaSpawnGroup

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

the class ConfigurationManager method editSpawnGroup.

@Override
public void editSpawnGroup(int spawngroupid, String setting, String value) throws NumberFormatException, InvalidSpawnGroupSettingException, CoreStateInitException, IOException {
    ISoliniaSpawnGroup spawnGroup = getSpawnGroup(spawngroupid);
    spawnGroup.editSetting(setting, value);
    SoliniaSpawnGroupUpdatedEvent soliniaevent = new SoliniaSpawnGroupUpdatedEvent(getSpawnGroup(spawnGroup.getId()));
    Bukkit.getPluginManager().callEvent(soliniaevent);
}
Also used : ISoliniaSpawnGroup(com.solinia.solinia.Interfaces.ISoliniaSpawnGroup) SoliniaSpawnGroupUpdatedEvent(com.solinia.solinia.Events.SoliniaSpawnGroupUpdatedEvent)

Example 3 with ISoliniaSpawnGroup

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

the class SoliniaNPC method disableAllSpawners.

@Override
public void disableAllSpawners(boolean parseBoolean) {
    try {
        for (ISoliniaSpawnGroup group : StateManager.getInstance().getConfigurationManager().getSpawnGroups()) {
            if (group.getNpcid() == this.getId()) {
                System.out.println("Set Spawner Disabled Status: " + group.getId() + ":" + group.getName() + " - " + parseBoolean);
                group.setDisabled(parseBoolean);
                StateManager.getInstance().getEntityManager().getNPCEntityProvider().removeSpawnGroup(group);
            }
        }
    } catch (CoreStateInitException e) {
    }
}
Also used : CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaSpawnGroup(com.solinia.solinia.Interfaces.ISoliniaSpawnGroup)

Example 4 with ISoliniaSpawnGroup

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

the class CommandEditSpawngroup 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 (!player.isOp() && !player.hasPermission("solinia.editspawngroup")) {
            player.sendMessage("You do not have permission to access this command");
            return false;
        }
    }
    if (args.length == 0) {
        return false;
    }
    int spawngroupid = Integer.parseInt(args[0]);
    if (args.length == 1) {
        try {
            ISoliniaSpawnGroup spawngroup = StateManager.getInstance().getConfigurationManager().getSpawnGroup(spawngroupid);
            if (spawngroup != null) {
                spawngroup.sendSpawnGroupSettingsToSender(sender);
            } else {
                sender.sendMessage("SPAWNGROUP ID doesnt exist");
            }
            return true;
        } catch (CoreStateInitException e) {
            sender.sendMessage(e.getMessage());
        }
    }
    if (args.length < 3) {
        sender.sendMessage("Insufficient arguments: spawngroupid setting value");
        return false;
    }
    String setting = args[1];
    String value = args[2];
    // for 'text' based spawngroup settings like trigger texts etc, get the whole thing as a string
    if (args.length > 3 && setting.toLowerCase().contains("text")) {
        value = "";
        int current = 0;
        for (String entry : args) {
            current++;
            if (current <= 2)
                continue;
            value = value + entry + " ";
        }
        value = value.trim();
    }
    if (spawngroupid < 1) {
        sender.sendMessage("Invalid spawngroupid");
        return false;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getSpawnGroup(spawngroupid) == null) {
            sender.sendMessage("Cannot locate spawngroupid: " + spawngroupid);
            return false;
        }
        if (StateManager.getInstance().getConfigurationManager().getSpawnGroup(spawngroupid).isOperatorCreated() && !sender.isOp()) {
            sender.sendMessage("This spawngroup was op created and you are not an op. Only ops can edit spawngroup npcs");
            return false;
        }
        try {
            StateManager.getInstance().getConfigurationManager().editSpawnGroup(spawngroupid, setting, value);
            sender.sendMessage("Updating setting on spawngroup");
        } catch (java.io.IOException e) {
            sender.sendMessage("Failed to update SpawnGroup");
        }
    } catch (InvalidSpawnGroupSettingException ne) {
        sender.sendMessage("Invalid SpawnGroup setting " + ne.getMessage());
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) InvalidSpawnGroupSettingException(com.solinia.solinia.Exceptions.InvalidSpawnGroupSettingException) ISoliniaSpawnGroup(com.solinia.solinia.Interfaces.ISoliniaSpawnGroup) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Aggregations

ISoliniaSpawnGroup (com.solinia.solinia.Interfaces.ISoliniaSpawnGroup)4 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 SoliniaSpawnGroupUpdatedEvent (com.solinia.solinia.Events.SoliniaSpawnGroupUpdatedEvent)1 InvalidSpawnGroupSettingException (com.solinia.solinia.Exceptions.InvalidSpawnGroupSettingException)1 ISoliniaSpawnGroupTypeAdapterFactory (com.solinia.solinia.Factories.ISoliniaSpawnGroupTypeAdapterFactory)1 SoliniaSpawnGroup (com.solinia.solinia.Models.SoliniaSpawnGroup)1 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CommandSender (org.bukkit.command.CommandSender)1 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)1 Player (org.bukkit.entity.Player)1