1v1 System HELP

Discussion in 'Plugin Development' started by xCalib0r, May 31, 2014.

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

    xCalib0r

    So what I'm trying to accomplish is making a 1v1 system where just like in kitpvp.com , you have an item and when you right click someone , you request them to 1v1 you, and then when they right click you , you accept and you both go to the arena and everyone is invisible for you. I tried doing this with hashmaps and somewhat succeeded , but alot of things went wrong like null pointer exceptions. I also don't understand how I can make sure that players cant request people in fights and how I can get the winner. Alot I don't understand, can someone show me how I can make a 1v1 system?
     
  2. Offline

    es359

    Please post your code and your Stacktraces.
     
  3. Offline

    xCalib0r

    es359 I don't have my code anymore because It was disgusting and didn't work , I just can't figure out how to make the system.
     
  4. Offline

    es359

    We can't help you if we don't know whats wrong. It may have been wrong, but possibly not all of it?
     
  5. Offline

    xCalib0r

    es359 Well the thing is I don't understand how to even make it at all.
     
  6. Offline

    es359

    We're not going to spoon feed you... If you put some effort into your project, we will put some effort into helping you. So what is it you are trying to understand?
     
  7. Offline

    xCalib0r

    es359 See I get the part where I have to right click a victim and they have to right click me to accept, already done that, NOW, the other problem is how would I make it so AFTER you kill the player and YOU WON , how would I know which play won? Like so confused here, and another thing, when two people go in a fight, I want them not to see anyone else and other people can't request to 1v1 with them, alot of thing's I'm confused with here.
     
  8. Offline

    es359

    Sounds like a pretty complicated plugin, but not impossible. I have an idea about this, let me go look at something.
     
  9. Offline

    xCalib0r

    es359 like if you want an example go to kitpvp.com and do /1v1
     
    es359 likes this.
  10. Offline

    xCalib0r

  11. Offline

    scenariocreator

    For a system like this you need a couple of pieces.

    A event listening for if they right clicked on a player.
    (PlayerInteractEntityEvent is a good one)

    A event listening for player deaths.
    (PlayerDeathEvent is good for this one)

    Some sort of storage system to keep track of players that have tried to challenge a player
    (HashMaps are good for this sort of thing)

    Some basic clean up for hashmaps and the like.
    (Like logout events and timers to remove from hashmap after a while)

    Now for the storage system i would recommend making a new class to store the info about each player.

    Although you should try the rest before asking for more help if you need it, it makes for a good learning experience.
     
  12. Offline

    xCalib0r

    scenariocreator I tried exactly all of this, but alot of null pointer exceptions and problems like getting the winner happened.
     
  13. Offline

    scenariocreator

    As es359 said we will be glad to help you, but we are unable to do so unless you have some sort of code for us to help you fix.
     
  14. Offline

    Garris0n

    If you have problems, we will help you solve them. If you don't know what to do, learn Java/Bukkit and start with something simpler.
     
  15. Offline

    xCalib0r

    Garris0n so far I got this but everytime we right click eachother to accept it says "requesting with null cancelled, now requesting blablabla

    Code:
    @EventHandler
    public void onRightClicked(PlayerInteractEntityEvent e) {
     
    final Player p = e.getPlayer();
    final Player target = (Player) e.getRightClicked();
     
    if (p.getItemInHand().getType() == Material.DIAMOND_SWORD && p.getItemInHand().getItemMeta().getDisplayName().contains(ChatColor.AQUA + "" + ChatColor.BOLD + "Regular Match")) {
    if (target instanceof Player) {
    if (request.containsKey(dAPI.getInstance().getUUID(p))) {
    p.sendMessage(ChatColor.RED + "Request with " + request.get(p.getName()) + " cancelled. Now requesting to 1v1 with " + target.getName());
    request.put(dAPI.getInstance().getUUID(p), dAPI.getInstance().getUUID(target));
    target.sendMessage(ChatColor.GOLD + p.getName() + " just send you a request to 1v1. Right click him to accept.");
    } else {
    p.sendMessage(ChatColor.GOLD + "Requesting to 1v1 with " + target.getName());
    request.put(dAPI.getInstance().getUUID(p), dAPI.getInstance().getUUID(target));
    target.sendMessage(ChatColor.GOLD + p.getName() + " just send you a request to 1v1. Right click him to accept.");
    }
    if (request.get(dAPI.getInstance().getUUID(target)) == dAPI.getInstance().getUUID(p)) {
    request.remove(dAPI.getInstance().getUUID(p));
    request.remove(dAPI.getInstance().getUUID(target));
    teleportPlayers(p, target);
    pregame.add(dAPI.getInstance().getUUID(p));
    pregame.add(dAPI.getInstance().getUUID(target));
    }
    }
    }
     
    }
    
     
  16. Offline

    Onlineids

    You cast Player to target then later on do if(target instanceof Player)......
     
  17. Offline

    xCalib0r

    Onlineids so??? I get that, but I don't think that was causing the problem.
     
  18. Offline

    Onlineids

    If anyone on your entire server right clicks anything but a player it will break
     
  19. Offline

    xCalib0r

    Onlineids So how would I fix it? ANd I didn't experience this actually. My problem is when I right click one guy it says requesting, then the other guy right clicks him it says requesting again then if the other guy right clicks again it says request cancelling, it's REALLY buggy.
     
  20. Offline

    Onlineids

    Add the instanceof Player before you define the target
     
  21. Offline

    xCalib0r

    Onlineids Ok did it but that still didn't fix anything

    Code:
    final Player p = e.getPlayer();
     
    if (p.getItemInHand().getType() == Material.DIAMOND_SWORD && p.getItemInHand().getItemMeta().getDisplayName().contains(ChatColor.AQUA + "" + ChatColor.BOLD + "Regular Match")) {
    if (e.getRightClicked() instanceof Player) {
    final Player target = (Player) e.getRightClicked();
    if (request.containsKey(dAPI.getInstance().getUUID(p))) {
    p.sendMessage(ChatColor.RED + "Request with " + request.get(p.getName()) + " cancelled. Now requesting to 1v1 with " + target.getName());
    request.put(dAPI.getInstance().getUUID(p), dAPI.getInstance().getUUID(target));
    target.sendMessage(ChatColor.GOLD + p.getName() + " just send you a request to 1v1. Right click him to accept.");
    } else {
    p.sendMessage(ChatColor.GOLD + "Requesting to 1v1 with " + target.getName());
    request.put(dAPI.getInstance().getUUID(p), dAPI.getInstance().getUUID(target));
    target.sendMessage(ChatColor.GOLD + p.getName() + " just send you a request to 1v1. Right click him to accept.");
    }
    if (request.get(dAPI.getInstance().getUUID(target)) == dAPI.getInstance().getUUID(p)) {
    request.remove(dAPI.getInstance().getUUID(p));
    request.remove(dAPI.getInstance().getUUID(target));
    teleportPlayers(p, target);
    pregame.add(dAPI.getInstance().getUUID(p));
    pregame.add(dAPI.getInstance().getUUID(target));
    }
    }
    }
    
    Onlineids soo???

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

    Onlineids

    T
    This is returning null request.get(p.getName())
     
  23. Offline

    xCalib0r

    Onlineids how would I fix it though ? It looks like it's correct, and that's not the only problem, it never teleports the player but just keeps saying request cancelled. it has to do with this if (request.get(dAPI.getInstance().getUUID(target)) == dAPI.getInstance().getUUID(p)) {
     
  24. Offline

    Onlineids

    What is dAPI?
     
  25. Offline

    xCalib0r

    Onlineids It's just an easier method I made for getting the players UUID, this shouldn't be the problem , ignore it. I tried .getName() as well.
     
  26. Offline

    Onlineids

    Well I can't see anything wrong of the top of my head so you might want to post ALL of your code
     
  27. Offline

    xCalib0r

    Onlineids Will do, one more thing that is SO weird that I dont understand is when I'm checking if the player is in the 1v1 arena. See when they do /1v1 it fires the setup1v1player which adds their uUid to inarena , but then when I'm checking the part where they right click, it doesn't work even though I set it so ONLY if they aren't in inarena dont call it. heres everything

    Code:
    public class OneVersusOneArena implements Listener {
     
    public ArrayList<String> inarena = new ArrayList<String>();
    public ArrayList<String> pregame = new ArrayList<String>();
    public ArrayList<String> fighting = new ArrayList<String>();
    public HashMap<String, String> request = new HashMap<String, String>();
     
    private static OneVersusOneArena INSTANCE = new OneVersusOneArena();
     
    public void teleportPlayers(Player p1, Player p2) {
    Location p1Location = new Location(Bukkit.getWorld("world"), 185.54202, 64, -311.47342);
    p1Location.setYaw(89F);
    p1.teleport(p1Location);
    Location p2Location = new Location(Bukkit.getWorld("world"), 159.41695, 64, -311.47342);
    p1Location.setYaw(-90F);
    p1.teleport(p2Location);
    }
     
    public void setup1v1Player(Player p) {
    if (KitManager.getInstance().kitType.containsKey(dAPI.getInstance().getUUID(p))) {
    KitManager.getInstance().kitType.remove(dAPI.getInstance().getUUID(p));
    }
    dInventory.getInstance().sortoutPlayer(p);
    p.teleport(LocationManager.getInstance().get1v1Location());
    p.getInventory().setItem(0, dInventory.getInstance().RegularMatch1v1Sword());
    inarena.add(dAPI.getInstance().getUUID(p));
    }
     
    @EventHandler
    public void onRightClicked(PlayerInteractEntityEvent e) {
     
    final Player p = e.getPlayer();
     
    if (!inarena.contains(dAPI.getInstance().getUUID(p))) {
    return;
    }
     
    if (p.getItemInHand().getType() == Material.DIAMOND_SWORD && p.getItemInHand().getItemMeta().getDisplayName().contains(ChatColor.AQUA + "" + ChatColor.BOLD + "Regular Match")) {
    if (e.getRightClicked() instanceof Player) {
    final Player target = (Player) e.getRightClicked();
    if (request.containsKey(dAPI.getInstance().getUUID(p))) {
    p.sendMessage(ChatColor.RED + "Request with " + request.get(p.getName()) + " cancelled. Now requesting to 1v1 with " + target.getName());
    request.put(dAPI.getInstance().getUUID(p), dAPI.getInstance().getUUID(target));
    target.sendMessage(ChatColor.GOLD + p.getName() + " just send you a request to 1v1. Right click him to accept.");
    } else {
    p.sendMessage(ChatColor.GOLD + "Requesting to 1v1 with " + target.getName());
    request.put(dAPI.getInstance().getUUID(p), dAPI.getInstance().getUUID(target));
    target.sendMessage(ChatColor.GOLD + p.getName() + " just send you a request to 1v1. Right click him to accept.");
    }
    if (request.get(dAPI.getInstance().getUUID(target)) == dAPI.getInstance().getUUID(p)) {
    request.remove(dAPI.getInstance().getUUID(p));
    request.remove(dAPI.getInstance().getUUID(target));
    teleportPlayers(p, target);
    pregame.add(dAPI.getInstance().getUUID(p));
    pregame.add(dAPI.getInstance().getUUID(target));
    }
    }
    }
     
    }
     
    public static OneVersusOneArena getInstance() {
    return INSTANCE;
    }
    
    command
    Code:
    if (args.length == 0) {
    OneVersusOneArena.getInstance().setup1v1Player(p);
    return;
    }
    
     
  28. Offline

    Etched

    I see you found some of my wording for the code :p. I presume you saw my post: http://forums.bukkit.org/threads/1v1-system.271761/#post-2516883
     
  29. Offline

    xCalib0r

    Etched Ya I saw your post to see how I could even attempt this.

    the inarena arraylist that had problems I fixed, note to self , arraylists DONT LIKE instances. Weird.

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

    Etched

    As I did, its best to make a custom 1v1 class. It simplifies it quite a bit.
     
Thread Status:
Not open for further replies.

Share This Page