/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
- package com.mciseries.iAnimalProtect.handlers;
- import java.io.File;
- import java.io.IOException;
- import java.util.logging.Logger;
- import org.bukkit.Bukkit;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.entity.Player;
- import com.mciseries.iAnimalProtect.files.Messages;
- import com.worldcretornica.plotme.Plot;
- import com.worldcretornica.plotme.PlotManager;
- public class Add {
- Messages msg = new Messages();
- File file = new File("plugins/iAnimalProtect/config.yml");
- Logger log = Logger.getLogger("Minecraft");
- public Add(FileConfiguration conf, CommandSender cs, Command c, String[] a) {
- Player s = Bukkit.getPlayer(cs.getName());
- if(a.length < 2) {
- s.sendMessage(msg.getError("NotEnoughArgs", false));
- }
- else if(a.length > 2) {
- s.sendMessage(msg.getError("TooManyArgs", false));
- }
- else {
- String id = PlotManager.getPlotId(s.getLocation());
- Plot p = PlotManager.getPlotById(s, id);
- if(id.equalsIgnoreCase("")) {
- s.sendMessage(msg.getError("NoPlot", false));
- }
- else if(PlotManager.isPlotAvailable(id, s) || (!p.owner.equalsIgnoreCase(s.getName()) && !s.hasPermission("ap.admin"))) {
- s.sendMessage(msg.getError("NotYourPlot", false));
- }
- else if(p.owner.equalsIgnoreCase(s.getName()) || s.hasPermission("ap.admin")) {
- conf.set("Plots." + s.getWorld().getName() + "." + id + "." + a[1], true);
- try {
- conf.save(file);
- } catch (IOException e) {
- log.warning("(iAP) Couldn't save config.yml! " + e.toString());
- }
- String name = a[1];
- s.sendMessage(msg.getSuccess("AddedPlayer", "<player>", name));
- }
- }
- }
- }