Search in sources :

Example 1 with SoliniaDisguise

use of com.solinia.solinia.Models.SoliniaDisguise in project solinia3-core by mixxit.

the class CommandEditDisguise 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.isOp() && !sender.hasPermission("solinia.editdisguise")) {
        sender.sendMessage("You do not have permission to access this command");
        return false;
    }
    if (args.length < 1) {
        sender.sendMessage("Insufficient arguments: disguiseid");
        return false;
    }
    if (args.length == 0) {
        return false;
    }
    int Disguiseid = Integer.parseInt(args[0]);
    if (args.length == 1) {
        try {
            SoliniaDisguise Disguise = StateManager.getInstance().getConfigurationManager().getDisguise(Disguiseid);
            if (Disguise != null) {
                Disguise.sendDisguiseSettingsToSender(sender);
            } else {
                sender.sendMessage("Disguise ID doesnt exist");
            }
            return true;
        } catch (CoreStateInitException e) {
            sender.sendMessage(e.getMessage());
        }
    }
    if (args.length < 3) {
        sender.sendMessage("Insufficient arguments: Disguiseid setting value");
        return false;
    }
    String setting = args[1];
    String value = args[2];
    if (Disguiseid < 1) {
        sender.sendMessage("Invalid Disguiseid");
        return false;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getDisguise(Disguiseid) == null) {
            sender.sendMessage("Cannot locate Disguise id: " + Disguiseid);
            return false;
        }
        StateManager.getInstance().getConfigurationManager().editDisguise(Disguiseid, setting, value);
        sender.sendMessage("Updating setting on Disguise");
    } catch (InvalidDisguiseSettingException ne) {
        sender.sendMessage("Invalid Disguise 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) CommandSender(org.bukkit.command.CommandSender) InvalidDisguiseSettingException(com.solinia.solinia.Exceptions.InvalidDisguiseSettingException) SoliniaDisguise(com.solinia.solinia.Models.SoliniaDisguise)

Example 2 with SoliniaDisguise

use of com.solinia.solinia.Models.SoliniaDisguise in project solinia3-core by mixxit.

the class SoliniaDisguiseFactory method Create.

public static SoliniaDisguise Create(String disguiseName, String disguiseType) throws CoreStateInitException, SoliniaDisguiseCreationException {
    if (StateManager.getInstance().getConfigurationManager().getDisguise(disguiseName.toUpperCase()) != null)
        throw new SoliniaDisguiseCreationException("Disguise already exists: " + StateManager.getInstance().getConfigurationManager().getDisguise(disguiseName.toUpperCase()).getDisguiseName());
    SoliniaDisguise d = new SoliniaDisguise();
    d.setId(StateManager.getInstance().getConfigurationManager().getNextDisguiseId());
    d.setDisguiseName(disguiseName.toUpperCase());
    d.setDisguiseType(disguiseType.toUpperCase());
    StateManager.getInstance().getConfigurationManager().addDisguise(d);
    return d;
}
Also used : SoliniaDisguiseCreationException(com.solinia.solinia.Exceptions.SoliniaDisguiseCreationException) SoliniaDisguise(com.solinia.solinia.Models.SoliniaDisguise)

Example 3 with SoliniaDisguise

use of com.solinia.solinia.Models.SoliniaDisguise in project solinia3-core by mixxit.

the class JsonDisguiseRepository method reload.

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

Example 4 with SoliniaDisguise

use of com.solinia.solinia.Models.SoliniaDisguise in project solinia3-core by mixxit.

the class JsonDisguiseRepository method commit.

@Override
public void commit() {
    // TODO Auto-generated method stub
    GsonBuilder gsonbuilder = new GsonBuilder();
    // gsonbuilder.setPrettyPrinting();
    Gson gson = gsonbuilder.create();
    String jsonOutput = gson.toJson(Disguises.values(), new TypeToken<List<SoliniaDisguise>>() {
    }.getType());
    try {
        File file = new File(filePath);
        if (!file.exists())
            file.createNewFile();
        FileOutputStream fileOut = new FileOutputStream(file);
        OutputStreamWriter outWriter = new OutputStreamWriter(fileOut);
        outWriter.append(jsonOutput);
        outWriter.close();
        fileOut.close();
        System.out.println("Commited " + Disguises.size() + " Disguises");
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) TypeToken(com.google.gson.reflect.TypeToken) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) SoliniaDisguise(com.solinia.solinia.Models.SoliniaDisguise) File(java.io.File)

Example 5 with SoliniaDisguise

use of com.solinia.solinia.Models.SoliniaDisguise in project solinia3-core by mixxit.

the class CommandCreateDisguise 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.isOp() && !sender.hasPermission("solinia.createdisguise")) {
        sender.sendMessage("You do not have permission to access this command");
        return false;
    }
    if (args.length < 2) {
        sender.sendMessage("Insufficient arguments: name disguisetype");
        return false;
    }
    String name = args[0].toUpperCase();
    String disguisetype = args[1].toUpperCase();
    if (name.equals("")) {
        sender.sendMessage("Name of disguise cannot be null");
        return false;
    }
    if (disguisetype.equals("")) {
        sender.sendMessage("Type of disguise cannot be null");
        return false;
    }
    try {
        SoliniaDisguise existing = StateManager.getInstance().getConfigurationManager().getDisguise(name);
        if (existing != null) {
            sender.sendMessage("A disguise already exists with this name");
            return false;
        }
        SoliniaDisguise disguise = SoliniaDisguiseFactory.Create(name, disguisetype);
        sender.sendMessage("Created Disguise: " + disguise.getId());
    } catch (CoreStateInitException | SoliniaDisguiseCreationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) SoliniaDisguiseCreationException(com.solinia.solinia.Exceptions.SoliniaDisguiseCreationException) CommandSender(org.bukkit.command.CommandSender) SoliniaDisguise(com.solinia.solinia.Models.SoliniaDisguise)

Aggregations

SoliniaDisguise (com.solinia.solinia.Models.SoliniaDisguise)6 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)3 CommandSender (org.bukkit.command.CommandSender)3 Player (org.bukkit.entity.Player)3 Gson (com.google.gson.Gson)2 SoliniaDisguiseCreationException (com.solinia.solinia.Exceptions.SoliniaDisguiseCreationException)2 FileNotFoundException (java.io.FileNotFoundException)2 GsonBuilder (com.google.gson.GsonBuilder)1 TypeToken (com.google.gson.reflect.TypeToken)1 InvalidDisguiseSettingException (com.solinia.solinia.Exceptions.InvalidDisguiseSettingException)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ClickEvent (net.md_5.bungee.api.chat.ClickEvent)1 TextComponent (net.md_5.bungee.api.chat.TextComponent)1