Got some problem that is really enoying

Discussion in 'Plugin Development' started by TheUpdater, Jun 14, 2013.

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

    TheUpdater

    Code:java
    1. @EventHandler
    2. public void Submachine(PlayerInteractEvent e) {
    3. final Player p = e.getPlayer();
    4. if (e.getAction() == Action.RIGHT_CLICK_AIR) {
    5. if (MyArrayListsListener.Red.contains(p.getName())
    6. || MyArrayListsListener.Blue.contains(p.getName())) {
    7. if (p.getItemInHand().getType() == Material.ARROW) {
    8. if (sub == false) {
    9. if (p.getInventory().contains(Material.GHAST_TEAR)) {
    10. Arrow a = p.launchProjectile(Arrow.class);
    11. a.setVelocity(a.getVelocity().multiply(4));
    12. a.getLocation().getWorld().playEffect(a.getLocation(),Effect.SMOKE,a.getLocation().getDirection().hashCode(), 10);
    13. a.getLocation().getWorld().playEffect(a.getLocation(),Effect.SMOKE,a.getLocation().getDirection().hashCode(), 10);
    14. p.getWorld().playSound(p.getLocation(),Sound.ITEM_BREAK, 5, 0);
    15. p.setVelocity(p.getLocation().getDirection().multiply(-0.02));
    16. p.updateInventory();
    17. su++;
    18. if (su == 10) {
    19. sub = true;
    20. p.sendRawMessage("Reloading...");
    21. new BukkitRunnable() {
    22. public void run() {
    23. p.sendRawMessage("Reloaded");
    24. p.getWorld().playSound(p.getLocation(),Sound.CLICK, 5, 10);
    25. p.getInventory().removeItem(new ItemStack(Material.GHAST_TEAR));
    26. sub = false;
    27. su = -10;
    28. cancel();
    29. }
    30. }.runTaskTimer(plugin, 80, 80);
    31. }
    32. } else {
    33. e.setCancelled(true);
    34. p.sendMessage(ChatColor.RED + "You Need More Ammo");
    35. p.getWorld().playSound(p.getLocation(),
    36. Sound.CLICK, 5, 10);
    37. }
    38. }
    39. }
    40. }
    41. }
    42. }

    that is my gun

    so if Red joins game whit sub
    and blue join whit sub
    and red shoots all 10 bullets
    then blue cant shoot until red has reloaded
    same whit if blue shoots all bullets
    red need to wait until blue has reloaded how do i make so when red is reloading blue can still shot and reload and same thing whit red they are buggy as fuck, when use sniper its 1 bullet
    so if red shoots it blue cant, if blue shoots it red cant

    PLZ HELP!

    same if they are in same team
     
  2. Offline

    chasechocolate

    If you want to make reloading player-specific, then make a HashMap<String, Boolean> where you can save the player's name and whether or not they are reloading.
     
  3. Offline

    TheUpdater

    all players gonna be able to reload and shoot when other players reload and shoot
     
  4. Offline

    Quidam

    You need to make a HashMap, as chasechocolate said. Check the HashMap instead of checking the Event user, because the code there applies to every player.
     
  5. Offline

    TheUpdater

    well i never done hashmaps

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  6. google is your friend.
     
    bennie3211 likes this.
  7. Offline

    Alex5657

    Here is a quick explanation:

    A hash map is like an array list, but it stores the values by keys that you specify. You initialize a hash map like this:

    Code:java
    1. HashMap<*object type used for key*,*values that will be stored*> *name* = new HashMap<*object type used for key*,*values that will be stored*>();


    To put values into it you use the put(K key,V value) method, where K is the object that will be used as a key and V the value itself.

    This allows you to store values by, for example, String. So if I do this:
    Code:java
    1. HashMap<String,Boolean> map = new HashMap<String,Boolean>();


    I can put a value into the map like so:
    Code:java
    1. map.put("Notch",true)

    And get the boolean value like so:
    Code:java
    1. map.get("Notch")

    Note: if the key does not exist the method will return null
     
    bennie3211 likes this.
  8. Offline

    bennie3211


    Nice and short tutorial, so a hashmap is a 2d arraylist :p I thought it just was a list like arrayList :p
     
Thread Status:
Not open for further replies.

Share This Page