Solved KitPvP Plugin! Need Help!

Discussion in 'Plugin Development' started by zfarman7, Jul 12, 2014.

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

    zfarman7

    Hey guys, well I started coding a few days ago and created a working kitpvp plugin, this plugin had working kits and a kit selector gui.

    When I was testing my plugin I found something that should have not been happening. Everytime someone leaves the server and joins back they cannot select a kit. It keeps saying the message I added to stop people using kits in the same life.

    How is it possible to allow the player to select a kit after they have left and rejoined?

    EDIT: I have another problem aswell, how do I make it so when players join they get teleported to spawn and not to the spot they logged off? (Sorry I'm not that great of a coder)
    Thanks :)
     
  2. Offline

    TheMcScavenger

    Show your code.
     
  3. Offline

    xepisolonxx

    zfarman7 If you saved them to some sort of hashmap to check if they have a kit on quit,death,respawn etc events remove them from the list so that they are able to reselect a kit.
     
  4. Offline

    zfarman7

    Hmm xepisolonxx thanks for the idea, I'll try it out!

    xepisolonxx I failed with the hashmap, how would i save them to a hashmap? I only need to save the respawn data. But I have no clue how to do that. Can you please start me off?

    Thanks

    TheMcScavenger my code is here: http://pastebin.com/K9ChiKzT

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  5. Offline

    ResultStatic

    zfarman7 instead of having that looped code use
    for (int i = 0; i < numberofsoupneed; i++){
    player.getInventory().addItem(new ItemStack[] { new ItemStack(Material.MUSHROOM_SOUP) });
     
  6. Offline

    zfarman7

    ResultStatic I removed all looped code today, as I cleaned out the plugin. Right now its cleaner then before and no looped code.

    Okay so I went around testing stuff in kitpvp servers and plugins and they all have the same problem. How do i fix this?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  7. Offline

    EcMiner

    Most kitpvp servers do this on purpose, when someone leaves and then joins back their kit stays activated so they don't have to choose it again and can just keep on playing. I'm not sure how you clear their selected kit when they die, but you should try and do it the same way you do it when someone dies. I do get the feeling you don't use hashmaps to store players' kits, which, in my opinion, is not good at all. What you should do is when someone chooses a kit you put their name and their kit in a hashmap, then if they try and choose another kit check if they still exist in the hashmap, and when someone dies / leaves remove him from the hashmap.

    EDIT: I just saw the code, and if you don't wanna use a hashmap you can just keep using your arraylist (Not recommended) and remove him from the list when he leaves. I do recommend you just put all the methods you run in the playerdeathevent's in 1 PlayerDeathEvent instead of a lot of different ones.
     
  8. Offline

    zfarman7

    EcMiner thanks for the advise, hashmaps are a bit confusing for me but I'll try to do it that way because it is better also, I have cleaned out my coding a lot, I have separated my commands in different classes and using CommandExecutor, so all of this has just become a lot more complicated. With the Commands in onEnable(); do I put my hashmap in the main class? Also how would I store the players kit and player name because I have no clue.

    EcMiner Wait I think I have found a solution but I'm not sure, and I haven't tested this since I'm posting on my phone.
    If I put this code: this.kit.remove(e.getEntity().getName()); in my PlayerQuitEvent will it work? I think that this fill fix it because I have used it when player dies this resets the kit, so if I add this to PlayerQuitEvent I'm assuming it will reset when they quit?

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

    EcMiner

    Yes, but their inventory will stay, so you should probably clear their inventory as well
     
  10. Offline

    zfarman7

    EcMiner I have already added that later on I'm going to test this and if it doesn't work goin back to hashmaps.
     
Thread Status:
Not open for further replies.

Share This Page