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;
}
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;
}
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");
}
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();
}
}
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;
}
Aggregations