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

https://bitbucket.org/iseries/ianimalprotect · Java · 51 lines · 46 code · 5 blank · 0 comment · 12 complexity · cdf58c66142decf7cfe81371df53dd98 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 Add {
  14. Messages msg = new Messages();
  15. File file = new File("plugins/iAnimalProtect/config.yml");
  16. Logger log = Logger.getLogger("Minecraft");
  17. public Add(FileConfiguration conf, CommandSender cs, Command c, String[] a) {
  18. Player s = Bukkit.getPlayer(cs.getName());
  19. if(a.length < 2) {
  20. s.sendMessage(msg.getError("NotEnoughArgs", false));
  21. }
  22. else if(a.length > 2) {
  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. conf.set("Plots." + s.getWorld().getName() + "." + id + "." + a[1], true);
  36. try {
  37. conf.save(file);
  38. } catch (IOException e) {
  39. log.warning("(iAP) Couldn't save config.yml! " + e.toString());
  40. }
  41. String name = a[1];
  42. s.sendMessage(msg.getSuccess("AddedPlayer", "<player>", name));
  43. }
  44. }
  45. }
  46. }