[Factions, solved]Working with Factions

Discussion in 'Plugin Development' started by Jogy34, Nov 23, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Jogy34

    First of all I'm not all that familiar with essentials. I need to be able to get access to the essentials economy but have a few questions about doing that.
    1. I know how to check to see if a plugin is on the server but what do I have to check for with essentials?(Eg. Do I check to see if they just have the base essentials plugin on their server or is it in another part of Essentials?)
    2. how do I go about taking away money from people?
    I'm using Vault.

    I am making a plugin to add on to Factions but need to know a few things.
    1. How do I get all the clans that are on the server?
    2. how do I get the land that each clan has claimed?
    1. How do I turn a Player into an FPlayer?
    Go do down to my latest post for up to date problems if there are any left.
     
  2. Offline

    Lolmewn

    You could use Register.. ;)
    For the factions part: No clue.
     
  3. Offline

    Jogy34

  4. Offline

    Lolmewn

    Register is an API you can use, try the search function. It's really handy.
     
  5. Offline

    Jaker232

    Code:
    softdepend: [Essentials, Factions]
    
    In plugin.yml
     
  6. Offline

    desht

    Speaking as someone who's coded for both, I'd really suggest using Vault, not Register.

    Vault has the distinct advantage of having a developer who actually responds to posts, as well as being easier to code for, not having the huge compatibility issues that Register brought upon itself, and as an added bonus provides permission abstraction too.
     
  7. Offline

    Jogy34

    @MassiveCraft can you help me out with the Factions part?

    @desht Thanks I think vault should help.
     
  8. Offline

    Daniel Heppner

    I suggest supporting iConomy over Essentials Economy.
     
  9. Offline

    Jogy34

  10. Offline

    Jogy34

    @Olof Larsson @Brettflan Can one of you help me with the factions part. I need to cast a Player as an FPlayer however I can't do this directly. Can please you tell me how to indirectly do this ?
     
  11. Offline

    hatstand

    You'd be after this:
    Code:
    FPlayer.get(Player)
     
    Olof Larsson likes this.
  12. Offline

    Jogy34

    @hatstand there isn't a method like that.
     
  13. Offline

    hatstand

    Bleh. They changed it:
    Code:
    FPlayers.i.get(Player)
    That should be it.
     
  14. Offline

    Olof Larsson

    yeah. thank's :)
     
  15. Offline

    Jogy34

    @hatstand that works. Thanks.

    @Olof Larsson , @hatstand I'm making a war plugin that is an addon to Factions but I'm stuck as to why this won't work:
    Code:
      for(int i = 0; i < optedoutFactions.length; i++)
        {
          if(optedoutFactions[i].equals(null))
          {
            optedoutFactions[i] = (fplayer.getFaction());
            break;
          }
        }
    
    optedoutFactions[] - Is an array of Factions.
    fplayer - Is the player that is sending the command to opt out of the war.

    It keeps giving me this error:
    Code:
    12:02:06 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'wt'
    in plugin War Time v0.1
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:163)
            at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:364)
            at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:756)
            at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:721)
    
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:714)
            at net.minecraft.server.Packet3Chat.a(Packet3Chat.java:33)
            at net.minecraft.server.NetworkManager.b(NetworkManager.java:226)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:92)
            at net.minecraft.server.NetworkListenThread.a(SourceFile:108)
            at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:516)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:414)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:457)
    Caused by: java.lang.NullPointerException
            at me.Jogy34.WarTime.WarTime.onCommand(WarTime.java:171)
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
            ... 12 more
    
    @Olof Larsson , @hatstand never mind that I fixed it but now I have a different problem.
    when I do this:
    Code:
    	public static boolean noExplosion(FLocation loc)
    	{
    		for(int i = 0; i < optedOut.length; i++)
    		{
    			if(optedOut[i].doesLocationHaveOwnersSet(loc) == true)
    			{
    				return true;
    			}
    		}
    		return false;
    	}
    
    optedout[] - Is an array of Factions.

    It gives me this error when I try to use it:
    Code:
    20:03:54 [SEVERE] Could not pass event ENTITY_EXPLODE to War Time
    java.lang.NullPointerException
            at me.Jogy34.WarTime.ActivateWar.noExplosion(ActivateWar.java:92)
            at me.Jogy34.WarTime.EntityExplodeListener.onEntityExplode(EntityExplodeListener.java:39)
            at org.bukkit.plugin.java.JavaPluginLoader$66.execute(JavaPluginLoader.java:721)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:58)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:339)
            at net.minecraft.server.Explosion.a(Explosion.java:181)
            at net.minecraft.server.World.createExplosion(World.java:1522)
            at net.minecraft.server.WorldServer.createExplosion(WorldServer.java:215)
            at net.minecraft.server.EntityTNTPrimed.explode(EntityTNTPrimed.java:88)
    
            at net.minecraft.server.EntityTNTPrimed.w_(EntityTNTPrimed.java:66)
            at net.minecraft.server.World.entityJoinedWorld(World.java:1251)
            at net.minecraft.server.WorldServer.entityJoinedWorld(WorldServer.java:104)
            at net.minecraft.server.World.playerJoinedWorld(World.java:1233)
            at net.minecraft.server.World.tickEntities(World.java:1140)
            at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:507)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:414)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:457)
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 21, 2016
  16. Offline

    Jogy34

  17. Offline

    hatstand

    Firstly, just because I'm pedantic:
    Code:java
    1. public static boolean noExplosion(FLocation loc)
    2. {
    3. for(faction f : optedOut)
    4. {
    5. if(f.doesLocationHaveOwnersSet(loc))
    6. {
    7. return true;
    8. }
    9. }
    10. return false;
    11. }


    secondly, what happens on line 92, in that function? Whatever is happening in there is throwing an NPE - A good way of figuring out exactly what it is is to split everything onto multiple lines, like so:
    Code:java
    1. public static boolean noExplosion(FLocation loc)
    2. {
    3. for(
    4. faction f
    5. :
    6. optedOut)
    7. {
    8. if(
    9. f.doesLocationHaveOwnersSet(
    10. loc))
    11. {
    12. return true;
    13. }
    14. }
    15. return false;
    16. }

    So then when the error pops up, you have the exact location of what is throwing that exception.
     
  18. Offline

    Sleaker

    FPlayer isn't a player object, it's a representation of the data that a Player needs to have to work in factions. (That means you can't just cast it)

    To get an Fplayer object from a player you should be able to just

    FPlayer.i.get(player);
     
  19. Offline

    Jogy34

    @hatstand I did that and It said that
    Code:
    doesLocationHaveOwnersSet(
    
    Was the error

    @Olof Larsson , @Brettflan , @hatstand , @Sleaker , or anyone else who can help me. Anyone have any thoughts. This is my last problem before I can complete this plugin

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 21, 2016
  20. Offline

    Brettflan

    What is the actual error, and what version/build of Factions are you using?
     
  21. Offline

    Jogy34

    The error is posted above but I'll re-post it:
    Code:
    20:03:54 [SEVERE] Could not pass event ENTITY_EXPLODE to War Time
    java.lang.NullPointerException
            at me.Jogy34.WarTime.ActivateWar.noExplosion(ActivateWar.java:92)
            at me.Jogy34.WarTime.EntityExplodeListener.onEntityExplode(EntityExplodeListener.java:39)
            at org.bukkit.plugin.java.JavaPluginLoader$66.execute(JavaPluginLoader.java:721)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:58)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:339)
            at net.minecraft.server.Explosion.a(Explosion.java:181)
            at net.minecraft.server.World.createExplosion(World.java:1522)
            at net.minecraft.server.WorldServer.createExplosion(WorldServer.java:215)
            at net.minecraft.server.EntityTNTPrimed.explode(EntityTNTPrimed.java:88)
    
            at net.minecraft.server.EntityTNTPrimed.w_(EntityTNTPrimed.java:66)
            at net.minecraft.server.World.entityJoinedWorld(World.java:1251)
            at net.minecraft.server.WorldServer.entityJoinedWorld(WorldServer.java:104)
            at net.minecraft.server.World.playerJoinedWorld(World.java:1233)
            at net.minecraft.server.World.tickEntities(World.java:1140)
            at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:507)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:414)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:457)
    
    And I'm using the newest version of factions: 1.6.1
     
  22. Offline

    Jogy34

    @hatstand I see you are on. Do you have any thoughts on this?
     
  23. Offline

    Jogy34

  24. Offline

    Jogy34

  25. Can you post this method then please? :)
     
  26. Offline

    Jogy34

    Sure:
    Code:
    public static boolean noExplosion(FLocation loc)
    	{
    		for(Faction f : optedOut)
    		{
    			if(f.doesLocationHaveOwnersSet(loc))
    			{
    				return true;
    			}
    		}
    		return false;
    	}
     
  27. Oh never mind I meant the method doesLocationHaveOwnersSet but I realized that is a Faction method xD hmmm have you checked that loc is not null?
    EDIT: Actually I cannot find this method? Have you created the method doesLocationHaveOwnersSet yourself?
     
  28. Offline

    Jogy34

    1. I realized a big mistake on my part. In the class I only ever got the Faction Array at the beginning when I first initialized it (The Factions are put into the array from the main class) and I never checked if the faction was null so that is where the null pointer exception comes in.
    Here is my updated method:
    Code:
    public static boolean noExplosion(FLocation loc)
    	{
    		optedOut = WarTime.getOptedOut();//This gets the Factions array from the main class
    		for(Faction f : optedOut)
    		{
    			if((f != null))
    			{
    				if(f.doesLocationHaveOwnersSet(loc))
    				{
    					return true;
    				}
    			}
    		}
    		return false;
    	}
    
    This is how I am putting the factions into the array:
    Code:
    else if((args[0].equalsIgnoreCase("OptOut") || args[0].equalsIgnoreCase("Out")) && sender instanceof Player)
    {
    if(sender instanceof Player)
    {
    FPlayer fplayer = FPlayers.i.get((Player)sender);
    if((economy.getBalance(sender.getName()) >= (fplayer.getFaction().getLandRounded()) * cost)
    && fplayer.hasFaction() == true)
    {
    if(fplayer.getRole().isAtLeast(Role.MODERATOR) == true)
    {
    economy.withdrawPlayer(sender.getName(), (fplayer.getFaction().getLandRounded()) * cost);
    sender.sendMessage("You have payed " + ((fplayer.getFaction().getLandRounded()) * cost) + " To opt your Faction of the next war");
    for(int i = 0; i < optedoutFactions.length; i++)
    {
    if(optedoutFactions[i] == null)
    {
    optedoutFactions[i] = fplayer.getFaction();
    break;
    }
    }
    }else
    {
    sender.sendMessage("You must be atleast a moderator in your faction to do this");
    }
    }else
    {
    sender.sendMessage("You must have atleast " + (fplayer.getPower()) * cost + " in your bank
    in order to Opt Out");
    }
    }else{
    sender.sendMessage("You cannot do this from here");
    }
    }
    
    2.
    1. I know that the location isn't null
    2. exe dee

    3. @Olof Larsson , @hatstand , @Brettflan Am I doing this right?
     
  29. Offline

    Jogy34

  30. Your using i < optedoutFactions.length, however the first array length will be 0 and as i is initially 0 it will not add anything to the array it because i < optedoutFactions.length will be false. To confirm my theory try adding:
    Code:
    System.out.println("The array length is ----> "+optedout.length());
    before the for loop in the noExplosion method but after it gets the array so like this:
    Code:
    optedOut = WarTime.getOptedOut();
    System.out.println("The length of the array is ----> "+optedOut.length());
    for(Faction f : optedOut)
        {
    EDIT: forgot to say you then need to add a faction to the optedOut array (run whichever command it is) then do whatever triggers the noExplosion method. Once you have done this check your log file for "The length of the array is ---->" and if the number after is 0 then my theory is correct.
     
Thread Status:
Not open for further replies.

Share This Page