Factions Anti-Sethome [Bug]

Discussion in 'Spigot Plugin Development' started by DustinThePlugin, Apr 24, 2017.

  1. So I'm currently coding a plugin to make it hook into factions and essentials, The way it SHOULD work is when a player tries to sethome in a enemy or neutral factions claimed land it will say they can't. I have gotten that down, but I have no idea how to implement essentials sethome to tell it to continue what it was doing.

    Current Code:
    Code (Text):
    package com.plugin.afp;

    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;

    import com.massivecraft.factions.FPlayer;
    import com.massivecraft.factions.FPlayers;

    public class Main extends JavaPlugin implements Listener {
        Plugin main = plugin;
        private static Plugin plugin;
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
        public void onDisable() {

        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            Player p = (Player)sender;
            FPlayer fp = FPlayers.getInstance().getByPlayer((Player) sender);
            if (label.equalsIgnoreCase("sethome") || label.equalsIgnoreCase("esethome") || label.equalsIgnoreCase("createhome") || label.equalsIgnoreCase("ecreatehome")) {
                if (fp.isInEnemyTerritory() || fp.isInNeutralTerritory()) {
                    p.sendMessage(ChatColor.RED + "You cannot set your homes in this factions territory");
                    return true;
                } else if (fp.isInAllyTerritory() || fp.isInOwnTerritory() || fp.isAdminBypassing() || fp.isInOthersTerritory()) {
                    // Nothing, just let the player set his home.
            return false;
  2. Try not returning false if you want the command to function normally

    Sent from my iPhone using Tapatalk
    • Agree Agree x 1
  3. it worked with it returning false, but what happens is, the sethome functionality wont work
    • Winner Winner x 1
  4. Are you getting any console errors? Returning true should be used if the command executed, false should give the user a command not found. Check your console for errors whenever /sethome is used and see if there's errors being thrown when they're not in faction land

    Sent from my iPhone using Tapatalk
  5. Umm you need to listen to that command not make your own one. Use like the PlayerCommandpreprocesseventfrom there . Im positive that cancelling the event does cancel the command execution.
  6. Why do you have 2 plugin variables, and they are both null? I sure hope you don't call those anywhere....
  7. It works yes, returning true or false is used to indicate success or failure. Randomly returning true and false will not directly break something, but you're still using it the wrong way. I'd follow the advice of @dNiym.

    Also, I agree with @EvanTheSurfer here. You have multiple (why multiple? seriously, why?) which are both null at the start, which is fine, but the value is never set. Accessing these variables will cause NPE errors.

    simply do:
    Code (Text):
    plugin = this;
    and your plugin variable should be initialized.
  8. *cough* *cough* anyone noticed that he is working with onCommand like a listener.
    For onCommand you must Override the onCommand method from CommandExecutor. Plus it does not work because your are forcing your own command over the other command. You are registering your plugin for the command. Therefore only your code work, anything from the same command from the other plugin doesnt(unless u use /thatPluginName:sethome) . To do what u want to do you need to use the event PlayerCommandPreProcessEvent
  9. Sure, but he has other problems that he needs to understand before working with that.
  10. Will this be a standalone plugin? Would be interested in using it on my server so players cant sethome in enemy territory.