Zoom ability

Discussion in 'Plugin Development' started by XgXXSnipz, Sep 26, 2014.

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

    XgXXSnipz

    Code:java
    1. @EventHandler
    2. public void onZoom(PlayerInteractEvent e) {
    3. final Player p = e.getPlayer();
    4. if (e.getAction() == Action.LEFT_CLICK_AIR && zoom.containsKey(p)) {
    5.  
    6. zoom.remove(p);
    7. p.removePotionEffect(PotionEffectType.SLOW);
    8. p.playSound(p.getLocation(), Sound.CLICK, 3, 1);
    9. return;
    10. }
    11.  
    12. if (p.getItemInHand().getType() == Material.DIAMOND_HOE) {
    13. p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 100000, 4));
    14. zoom.put(p, p);
    15.  
    16. p.playSound(p.getLocation(), Sound.CLICK, 4, 2);
    17.  
    18. }
    19. }


    So I made a gun plugin and when I left click I can zoom in, and it partially works the zoom works but when I shoot it puts me back in zoom mode? can you help??


    Gun code:
    Code:java
    1. public void onInteract(PlayerInteractEvent e) {
    2. final Player p = e.getPlayer();
    3. if (e.getAction() == Action.RIGHT_CLICK_AIR) {
    4. if (p.getItemInHand().getType() == Material.DIAMOND_HOE) {
    5. p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 5, 2));
    6.  
    7. p.playSound(p.getEyeLocation(), Sound.EXPLODE, 0.6F, 2.0F);
    8. p.getWorld().playEffect(p.getEyeLocation().add(p.getLocation().getDirection()), Effect.SMOKE, 4);
    9. p.teleport(p.getLocation().add(new Vector(0, 1, -3)));
    10.  
     
  2. Offline

    Jimfutsu

    In your first class, you have the interact event and the zoom.contains event together, this means if the movement isn't equal to left click air, then you will get the slowme
     
  3. Offline

    Totom3

    XgXXSnipz Not sure about the error but why are you using a HashMap for the zoomed players ? You could just use a Set, like HashSet, and most importantly do not store the Player object, store their name or their UUID.
     
  4. Offline

    xepisolonxx

    XgXXSnipz A cheap way of doing this is by giving them slowness because it the potion effect is high enough it cause rhe players screen to zoom in
     
  5. Offline

    XgXXSnipz

  6. Offline

    CraftCreeper6

    XgXXSnipz
    Set the players walkSpeed to -1
    Let them shoot, change walkSpeed to 1.2
     
  7. Offline

    XgXXSnipz

  8. Offline

    CraftCreeper6

  9. Offline

    XgXXSnipz

  10. Offline

    CraftCreeper6

    XgXXSnipz
    That way, you don't see the potion effects :)
     
  11. Offline

    XgXXSnipz

Thread Status:
Not open for further replies.

Share This Page