Advertisement
copots

FacIdence ez src

Jul 31st, 2015
280
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.ceoepts.facidence;
  2.  
  3. import java.util.Iterator;
  4.  
  5. import net.md_5.bungee.api.ChatColor;
  6.  
  7. import org.bukkit.Location;
  8. import org.bukkit.event.EventHandler;
  9. import org.bukkit.event.Listener;
  10. import org.bukkit.plugin.PluginManager;
  11. import org.bukkit.plugin.java.JavaPlugin;
  12.  
  13. import com.bekvon.bukkit.residence.Residence;
  14. import com.bekvon.bukkit.residence.event.ResidenceCreationEvent;
  15. import com.bekvon.bukkit.residence.protection.ClaimedResidence;
  16. import com.bekvon.bukkit.residence.protection.CuboidArea;
  17. import com.bekvon.bukkit.residence.protection.ResidenceManager;
  18. import com.massivecraft.factions.FLocation;
  19. import com.massivecraft.factions.Faction;
  20. import com.massivecraft.factions.Factions;
  21. import com.massivecraft.factions.event.LandClaimEvent;
  22.  
  23. public class Main extends JavaPlugin implements Listener{
  24.  
  25. Residence residence;
  26. Factions factions;
  27. String noResidenceMessage = "&4You cant create a residence inside a faction!";
  28. String noFactionMessage = "&4You cant claim factionland inside a residence!";
  29. boolean NoResInFac;
  30. boolean NoFacInRes;
  31.  
  32. public void onEnable(){
  33. PluginManager pm = this.getServer().getPluginManager();
  34. pm.registerEvents(this, this);
  35. residence = (Residence) JavaPlugin.getPlugin(Residence.class);
  36. factions = (Factions) Factions.getInstance();
  37. //Config
  38. this.saveDefaultConfig();
  39.  
  40. noResidenceMessage = this.getConfig().getString("ResidenceWarning");
  41. noFactionMessage = this.getConfig().getString("FactionsWarning");
  42.  
  43. NoResInFac = this.getConfig().getBoolean("ResidenceInFactionRestriction");
  44. NoFacInRes = this.getConfig().getBoolean("FactionInResidenceRestriction");
  45.  
  46. }
  47.  
  48. @EventHandler
  49. public void residenceCreationEvent(ResidenceCreationEvent e){
  50. if(NoResInFac){
  51. CuboidArea area1 = e.getPhysicalArea();
  52. for(Faction f : factions.getAllFactions()){
  53. Iterator<FLocation> claims = f.getAllClaims().iterator();
  54. while(claims.hasNext()){
  55. CuboidArea area2 = flocationToArea(claims.next());
  56. if(area1.checkCollision(area2)){
  57. e.setCancelled(true);
  58. e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', noResidenceMessage));
  59. return;
  60. }
  61. }
  62. }
  63. }
  64. }
  65.  
  66. @EventHandler
  67. public void factionsCreationEvent(LandClaimEvent e){
  68. if(NoFacInRes){
  69. for(String r : Residence.getResidenceManager().getResidenceList()){
  70. ResidenceManager rm = Residence.getResidenceManager();
  71. ClaimedResidence res = rm.getByName(r);
  72. CuboidArea area1 = res.getAreaArray()[0];
  73. CuboidArea area2 = flocationToArea(e.getLocation());
  74. if(area1.checkCollision(area2)){
  75. e.setCancelled(true);
  76. e.getfPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', noFactionMessage));
  77. return;
  78. }
  79. }
  80. }
  81. }
  82.  
  83. public CuboidArea flocationToArea(FLocation f){
  84. int x = FLocation.chunkToBlock((int) f.getX());
  85. int z = FLocation.chunkToBlock((int) f.getZ());
  86. int x2 = FLocation.chunkToBlock((int) f.getX())+15;
  87. int z2 = FLocation.chunkToBlock((int) f.getZ())+15;
  88. CuboidArea area2 = new CuboidArea(new Location(f.getWorld(), x, 0, z), new Location(f.getWorld(), x2, f.getWorld().getMaxHeight(), z2));
  89. return area2;
  90. }
  91.  
  92. }
Advertisement
RAW Paste Data Copied
Advertisement