/src/com/mciseries/iAnimalProtect/handlers/Close.java

https://bitbucket.org/iseries/ianimalprotect · Java · 53 lines · 48 code · 5 blank · 0 comment · 14 complexity · c7a97bebb869dd104b8295da76ecd96b MD5 · raw file

  1. package com.mciseries.iAnimalProtect.handlers;
  2. import java.io.File;
  3. import java.io.IOException;
  4. import java.util.logging.Logger;
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.command.Command;
  7. import org.bukkit.command.CommandSender;
  8. import org.bukkit.configuration.file.FileConfiguration;
  9. import org.bukkit.entity.Player;
  10. import com.mciseries.iAnimalProtect.files.Messages;
  11. import com.worldcretornica.plotme.Plot;
  12. import com.worldcretornica.plotme.PlotManager;
  13. public class Close {
  14. Messages msg = new Messages();
  15. File file = new File("plugins/iAnimalProtect/config.yml");
  16. Logger log = Logger.getLogger("Minecraft");
  17. public Close(FileConfiguration conf, CommandSender cs, Command c, String[] a) {
  18. Player s = Bukkit.getPlayer(cs.getName());
  19. if(a.length < 1) {
  20. s.sendMessage(msg.getError("NotEnoughArgs", false));
  21. }
  22. else if(a.length > 1) {
  23. s.sendMessage(msg.getError("TooManyArgs", false));
  24. }
  25. else {
  26. String id = PlotManager.getPlotId(s.getLocation());
  27. Plot p = PlotManager.getPlotById(s, id);
  28. if(id.equalsIgnoreCase("")) {
  29. s.sendMessage(msg.getError("NoPlot", false));
  30. }
  31. else if(PlotManager.isPlotAvailable(id, s) || (!p.owner.equalsIgnoreCase(s.getName()) && !s.hasPermission("ap.admin"))) {
  32. s.sendMessage(msg.getError("NotYourPlot", false));
  33. }
  34. else if(p.owner.equalsIgnoreCase(s.getName()) || s.hasPermission("ap.admin")) {
  35. if(conf.getConfigurationSection("Plots." + s.getWorld().getName() + "." + id).getKeys(false).size() == 1)
  36. conf.set("Plots." + s.getWorld().getName() + "." + id, null);
  37. else
  38. conf.set("Plots." + s.getWorld().getName() + "." + id + ".Open", null);
  39. try {
  40. conf.save(file);
  41. } catch (IOException e) {
  42. log.warning("(iAP) Couldn't save config.yml! " + e.toString());
  43. }
  44. s.sendMessage(msg.getSuccess("ClosedPlot", "<?>", "?"));
  45. }
  46. }
  47. }
  48. }