h31ix

Untitled

Mar 26th, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.01 KB | None | 0 0
  1. package net.h31ix.travelpadfactions;
  2.  
  3. import com.massivecraft.factions.FPlayer;
  4. import com.massivecraft.factions.Faction;
  5. import com.massivecraft.factions.Factions;
  6. import java.io.IOException;
  7. import java.util.logging.Level;
  8. import java.util.logging.Logger;
  9. import net.h31ix.travelpad.LangManager;
  10. import net.h31ix.travelpad.api.Configuration;
  11. import net.h31ix.travelpad.api.Pad;
  12. import net.h31ix.travelpad.api.TravelPadManager;
  13. import net.h31ix.travelpad.event.TravelPadTeleportEvent;
  14. import org.bukkit.ChatColor;
  15. import org.bukkit.command.Command;
  16. import org.bukkit.command.CommandSender;
  17. import org.bukkit.configuration.file.FileConfiguration;
  18. import org.bukkit.entity.Player;
  19. import org.bukkit.event.EventHandler;
  20. import org.bukkit.event.Listener;
  21. import org.bukkit.plugin.java.JavaPlugin;
  22.  
  23. public class Travelpadfactions extends JavaPlugin implements Listener {
  24. TravelPadManager manager;
  25. Factions factions;
  26. LangManager l;
  27. FileConfiguration config;
  28. Configuration tpconfig;
  29. public void onDisable() {
  30. }
  31.  
  32. public void onEnable() {
  33. getCommand("tpfaction").setExecutor(this);
  34. getServer().getPluginManager().registerEvents(this, this);
  35. manager = new TravelPadManager(getServer().getPluginManager().getPlugin("TravelPad"));
  36. tpconfig = manager.config;
  37. config = tpconfig.pads;
  38. l = manager.l;
  39. factions = (Factions)this.getServer().getPluginManager().getPlugin("Factions");
  40. }
  41.  
  42. @Override
  43. public boolean onCommand(CommandSender cs, Command cmd, String alias, String[] args) {
  44. if (!(cs instanceof Player))
  45. {
  46. System.out.println(l.command_deny_console());
  47. }
  48. else
  49. {
  50. Player player = (Player)cs;
  51. if (player.hasPermission("travelpad.faction"))
  52. {
  53. if (args.length == 2)
  54. {
  55. Pad pad = manager.getPad(args[0]);
  56. if (pad != null)
  57. {
  58. if (pad.getOwner().equalsIgnoreCase(player.getName()))
  59. {
  60. if (args[1].equalsIgnoreCase("remove"))
  61. {
  62. if(config.getString("Factions."+pad.getName()) != null)
  63. {
  64. config.set("Factions."+pad.getName(), null);
  65. try {
  66. config.save(tpconfig.padsFile);
  67. } catch (IOException ex) {
  68. Logger.getLogger(Travelpadfactions.class.getName()).log(Level.SEVERE, null, ex);
  69. }
  70. player.sendMessage(ChatColor.GREEN+"Faction protected removed from "+ChatColor.WHITE+pad.getName());
  71. }
  72. else
  73. {
  74. player.sendMessage(ChatColor.RED+"That pad is not protected by a faction!");
  75. }
  76. }
  77. else
  78. {
  79. Faction faction = factions.get(args[1]);
  80. if (faction != null)
  81. {
  82. boolean perm = false;
  83. for (FPlayer fplayer : faction.getFPlayers())
  84. {
  85. if (fplayer.getName().equalsIgnoreCase(player.getName()))
  86. {
  87. perm = true;
  88. }
  89. }
  90. if (perm)
  91. {
  92. config.set("Factions."+pad.getName(), faction.getTag());
  93. try {
  94. config.save(tpconfig.padsFile);
  95. } catch (IOException ex) {
  96. Logger.getLogger(Travelpadfactions.class.getName()).log(Level.SEVERE, null, ex);
  97. }
  98. player.sendMessage(ChatColor.GREEN+"TravelPad "+ChatColor.WHITE+pad.getName()+ChatColor.GREEN+" is now limited to the faction: "+ChatColor.WHITE+faction.getTag());
  99. }
  100. else
  101. {
  102. player.sendMessage(ChatColor.RED+"You are not a member of that faction!");
  103. }
  104. }
  105. else
  106. {
  107. player.sendMessage(ChatColor.RED+"Faction not found!");
  108. }
  109. }
  110. }
  111. else
  112. {
  113. player.sendMessage(ChatColor.RED+"That is not your pad!");
  114. }
  115. }
  116. else
  117. {
  118. player.sendMessage(ChatColor.RED+"Pad not found!");
  119. }
  120. }
  121. else
  122. {
  123. player.sendMessage(ChatColor.RED+"Usage: /tpfactions [padname] [factionname/remove]");
  124. }
  125. }
  126. else
  127. {
  128. player.sendMessage(ChatColor.RED+"Insufficient Permissions.");
  129. }
  130. }
  131. return true;
  132. }
  133.  
  134. public boolean isProtected(Pad pad)
  135. {
  136. if (config.getString("Factions."+pad.getName()) != null)
  137. {
  138. return true;
  139. }
  140. else
  141. {
  142. return false;
  143. }
  144. }
  145.  
  146. @EventHandler
  147. public void onTeleport(TravelPadTeleportEvent event) {
  148. Pad pad = event.getTo();
  149. Player player = event.getPlayer();
  150. if (!isProtected(pad))
  151. {
  152. Faction faction = factions.getByTag(config.getString("Factions."+pad.getName()));
  153. if (faction != null)
  154. {
  155. boolean perm = false;
  156. for (FPlayer fplayer : faction.getFPlayers())
  157. {
  158. if (fplayer.getName().equalsIgnoreCase(player.getName()))
  159. {
  160. perm = true;
  161. }
  162. }
  163. if (!perm)
  164. {
  165. event.setCancelled(true);
  166. player.sendMessage(ChatColor.RED+"You are not in the "+ChatColor.WHITE+faction.getTag()+ChatColor.RED+" faction!");
  167. }
  168. }
  169. }
  170. }
  171. }
Add Comment
Please, Sign In to add comment