When I use a Plugin to register a new Flag, the users can't have permissions to use commands of Residence (/res info per example), but if I take off the plugin, the users can use the commands of Residence.
import java.io.File;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import com.bekvon.bukkit.residence.Residence;
import com.bekvon.bukkit.residence.protection.ClaimedResidence;
import com.bekvon.bukkit.residence.protection.FlagPermissions;
import com.bekvon.bukkit.residence.protection.ResidenceManager;
public class SFlags extends JavaPlugin{
private ResidenceManager res;
private List<String> cmdban;
private File cplugin;
public void onEnable(){
Plugin p=getServer().getPluginManager().getPlugin("Residence");
if(p!=null){
if(!p.isEnabled())getServer().getPluginManager().enablePlugin(p);
}else{
Bukkit.getConsoleSender().sendMessage(ChatColor.AQUA+"[Soulflags] "+ChatColor.RED+"No se ha encontrado el residence. Plugin deshabilitado");
Bukkit.getPluginManager().disablePlugin(getPlugin(SFlags.class));
return;
}FlagPermissions.addResidenceOnlyFlag("cmd");
res=Residence.getResidenceManager();
try{
cplugin=getDataFolder();
if(!cplugin.exists())cplugin.mkdir();
File f=new File(cplugin+"/config.yml");
if(!f.exists())f.createNewFile();
FileConfiguration yml=new YamlConfiguration();
yml.load(f);
if(!yml.contains("ComandosBaneados")){
yml.set("ComandosBaneados",cmdban=Arrays.asList("/spawn","/tpa","/tpaccept","/tpahere"));
yml.save(f);
}else cmdban=yml.getStringList("ComandosBaneados");
}catch(Exception Ex){
Ex.printStackTrace();
}Bukkit.getPluginManager().registerEvents(new Listener(){
@SuppressWarnings("deprecation")
@EventHandler
public void alComando(PlayerCommandPreprocessEvent e){
Player j=e.getPlayer();
String m=e.getMessage().toLowerCase();
ClaimedResidence R=res.getByLoc(j.getLocation());
if(R!=null&&!R.getPermissions().playerHas(j,"cmd",true)){
for(String s:cmdban)if(m.startsWith(s)){
j.sendMessage(ChatColor.RED+"No estás autorizado para ejecutar aquí ese comando.");
e.setCancelled(true);
return;
}
}
}
},this);
}
}
Regards.
Sorry for my bad English.