Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.h31ix.travelpadfactions;
- import com.massivecraft.factions.FPlayer;
- import com.massivecraft.factions.Faction;
- import com.massivecraft.factions.Factions;
- import java.io.IOException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import net.h31ix.travelpad.LangManager;
- import net.h31ix.travelpad.api.Configuration;
- import net.h31ix.travelpad.api.Pad;
- import net.h31ix.travelpad.api.TravelPadManager;
- import net.h31ix.travelpad.event.TravelPadTeleportEvent;
- import org.bukkit.ChatColor;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Travelpadfactions extends JavaPlugin implements Listener {
- TravelPadManager manager;
- Factions factions;
- LangManager l;
- FileConfiguration config;
- Configuration tpconfig;
- public void onDisable() {
- }
- public void onEnable() {
- getCommand("tpfaction").setExecutor(this);
- getServer().getPluginManager().registerEvents(this, this);
- manager = new TravelPadManager(getServer().getPluginManager().getPlugin("TravelPad"));
- tpconfig = manager.config;
- config = tpconfig.pads;
- l = manager.l;
- factions = (Factions)this.getServer().getPluginManager().getPlugin("Factions");
- }
- @Override
- public boolean onCommand(CommandSender cs, Command cmd, String alias, String[] args) {
- if (!(cs instanceof Player))
- {
- System.out.println(l.command_deny_console());
- }
- else
- {
- Player player = (Player)cs;
- if (player.hasPermission("travelpad.faction"))
- {
- if (args.length == 2)
- {
- Pad pad = manager.getPad(args[0]);
- if (pad != null)
- {
- if (pad.getOwner().equalsIgnoreCase(player.getName()))
- {
- if (args[1].equalsIgnoreCase("remove"))
- {
- if(config.getString("Factions."+pad.getName()) != null)
- {
- config.set("Factions."+pad.getName(), null);
- try {
- config.save(tpconfig.padsFile);
- } catch (IOException ex) {
- Logger.getLogger(Travelpadfactions.class.getName()).log(Level.SEVERE, null, ex);
- }
- player.sendMessage(ChatColor.GREEN+"Faction protected removed from "+ChatColor.WHITE+pad.getName());
- }
- else
- {
- player.sendMessage(ChatColor.RED+"That pad is not protected by a faction!");
- }
- }
- else
- {
- Faction faction = factions.get(args[1]);
- if (faction != null)
- {
- boolean perm = false;
- for (FPlayer fplayer : faction.getFPlayers())
- {
- if (fplayer.getName().equalsIgnoreCase(player.getName()))
- {
- perm = true;
- }
- }
- if (perm)
- {
- config.set("Factions."+pad.getName(), faction.getTag());
- try {
- config.save(tpconfig.padsFile);
- } catch (IOException ex) {
- Logger.getLogger(Travelpadfactions.class.getName()).log(Level.SEVERE, null, ex);
- }
- player.sendMessage(ChatColor.GREEN+"TravelPad "+ChatColor.WHITE+pad.getName()+ChatColor.GREEN+" is now limited to the faction: "+ChatColor.WHITE+faction.getTag());
- }
- else
- {
- player.sendMessage(ChatColor.RED+"You are not a member of that faction!");
- }
- }
- else
- {
- player.sendMessage(ChatColor.RED+"Faction not found!");
- }
- }
- }
- else
- {
- player.sendMessage(ChatColor.RED+"That is not your pad!");
- }
- }
- else
- {
- player.sendMessage(ChatColor.RED+"Pad not found!");
- }
- }
- else
- {
- player.sendMessage(ChatColor.RED+"Usage: /tpfactions [padname] [factionname/remove]");
- }
- }
- else
- {
- player.sendMessage(ChatColor.RED+"Insufficient Permissions.");
- }
- }
- return true;
- }
- public boolean isProtected(Pad pad)
- {
- if (config.getString("Factions."+pad.getName()) != null)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- @EventHandler
- public void onTeleport(TravelPadTeleportEvent event) {
- Pad pad = event.getTo();
- Player player = event.getPlayer();
- if (!isProtected(pad))
- {
- Faction faction = factions.getByTag(config.getString("Factions."+pad.getName()));
- if (faction != null)
- {
- boolean perm = false;
- for (FPlayer fplayer : faction.getFPlayers())
- {
- if (fplayer.getName().equalsIgnoreCase(player.getName()))
- {
- perm = true;
- }
- }
- if (!perm)
- {
- event.setCancelled(true);
- player.sendMessage(ChatColor.RED+"You are not in the "+ChatColor.WHITE+faction.getTag()+ChatColor.RED+" faction!");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment