Solved How to make a zoomed in effect i.e for a gun?

Discussion in 'Plugin Development' started by mrsamcraft, Dec 28, 2013.

Thread Status:
Not open for further replies.
  1. Hello,

    I'm making some guns for my plugin and Iv done all the code for shooting and custom item. Just stumped on how to make a zoomin (scope) I thought about adding a slow postion effect on
    Code:java
    1. Action.RIGHT_CLICK_AIR
    . But I'm not sure if that would work?

    Thanks!
    ~ Sam
    All the best for 2014!
     
  2. Offline

    Gater12

    mrsamcraft Yes you can give them the slowness effect. You can add them to an ArrayList, so when they right click again, if they are in the list, remove the potion effect.
     
    mrsamcraft likes this.
  3. Gater12
    Ahh okay thanks! Ill post my code after and let you look to make sure its fine! :')
    All the best for 2014!

    Gater12

    Sorry for asking this, But i'm kind new to java but I'm stumped on the ArrayList, I have been watching some tut on YouTube about ArrayList but i'm confused.. sorry.

    Heres my code for the zoom in event.
    Code:java
    1. @EventHandler
    2. public void PlayerInteract(PlayerInteractEvent event) {
    3. Player p = event.getPlayer();
    4. if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
    5. if(p.getItemInHand().getType() != Material.IRON_BARDING){
    6. return;
    7. }
    8. if(p.getItemInHand().getItemMeta().getDisplayName() != null){
    9. if(p.getItemInHand().getItemMeta().getDisplayName().contains("Snowball Gun")){
    10. if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
    11. event.getPlayer().sendMessage(ChatColor.AQUA + "Zoomed In!");
    12. p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 200, 4));
    13.  
    14. }
    15. }
    16. }
    17.  
    18. }
    19. }
    20. }
    21.  


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

    Gater12

    mrsamcraft
    My explanation of storing a player's name in an ArrayList:
    Code:java
    1. /* Create a new ArrayList */
    2. ArrayList<String> sampleList = new ArrayList<String>();

    This will create an ArrayList that'll store Strings
    Code:java
    1. /* Add a player's name */
    2. sampleList.add(player.getName());

    It will store the player's name in the list
    Code:java
    1. if(sampleList.contains(player.getName())){
    2. /* Code */
    3. }

    This will test if a player's name is in the ArrayList
    Code:java
    1. /* Remove a player's name from an ArrayList */
    2. sampleList.remove(player.getName());

    *Remember to check beforehand before removing because if the player ain't in the list Java is goin to complain.
    Lastly in the event you want to get how much thinsg are stored in an ArrayList:
    Code:java
    1. sampleList.size();

    That'll return an int.
     
    mrsamcraft likes this.
  5. @Gater12

    Thanks! This will help me! This is better than a lot of them videos, thanks!
     
Thread Status:
Not open for further replies.

Share This Page