A couple of questions :)

Discussion in 'Plugin Development' started by Brexima, Apr 12, 2013.

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

    Brexima

    mcoder
    Terradominik
    Malikk
    @others =P

    Code:
    @EventHandler
        public void onPlayerClick(PlayerInteractEvent event){
            Player oyuncu = event.getPlayer();
                if(event.getPlayer().getItemInHand().getTypeId() == 262 && (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK)){
                    oyuncu.shootArrow();
                } 
    }
    1- how can i add cooldown to this like 5 seconds ?
    2-how can i do, a player send message from chat with a function ?(not player.sendMessage and not bukkit broadcast message a player gonna send message to others with a function..)
    3-how can i change the speed of arrow ? this is my onlaunch function
    Code:
    @EventHandler
        public void onLaunch(ProjectileLaunchEvent event)
        {
          if (event.getEntity().getShooter() instanceof Player)
          {
              Entity oklok = event.getEntity();
              oklok.getVelocity().multiply(20); // i tried this but nothing happened =(
          }
        }
    4-
    Code:
    player.getWorld().playEffect(oyuncu.getLocation(), Effect.SMOKE, 0);
    this code is creating a smoke effect but its just appear 0.5 second, how can i increase that ?
     
  2. Offline

    xmarinusx

    1. Make a List which stores (the names of) players. In your OnClick event check if the player is on that list, if not add him to it and use a BukkitRunnable to remove him after 20*5 ticks.
    2. player.chat("message here");
    3. Use this to shoot an arror with higher speed: shooter.launchProjectile(Arrow.class).setVelocity(shooter.getLocation().getDirection().normalize().multiply(5));
    EDIT:
    shooter is a Player object.


    4. Not sure about this one, perhaps make a BukkitRunnable to make the smoke effect appear ever 0.5 seconds for a certain amount of time?
     
  3. Offline

    Brexima

    i did all of them thank u :)
     
  4. Offline

    kreashenz

    Brexima Just a wild question, as this is your post, and not mine, but would you be kind enough to post the code to question 1, because I have asked for that before, and I'm still waiting for a reply :)
     
  5. Offline

    Brexima

  6. Offline

    kreashenz

    Brexima Yeah, that's how to do it..I'm not good with BukkitRunnables, so can you please post the code?
    [EDIT] Ahhh my bad.. I meant question 1..
     
  7. Offline

    Brexima

  8. Offline

    kreashenz

    Brexima I don't really like using whole class files, I would just like an easier, simple way to do it..
     
  9. Offline

    Brexima

    kreashenz
    it's the easiest way i think, u just have to copy the first code to a class file, then use the second code.
     
  10. Offline

    xmarinusx

    I will write some code for you on how to do a cooldown, hold on.

    Here it is:
    Code:java
    1. public List<String> cooldown = new ArrayList<String>();
    2.  
    3. @EventHandler
    4. public void OnPlayerInteract(PlayerInteractEvent event){
    5. final Player player = event.getPlayer();
    6. if(!cooldown.contains(player.getName())){
    7. cooldown.add(player.getName());
    8. //Do what you would like to do.
    9. new BukkitRunnable(){
    10. @Override
    11. public void run(){
    12. cooldown.remove(player.getName());
    13. }
    14. }.runTaskLater(plugin, 5*20);
    15. }
    16. }


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

    kreashenz

    xmarinusx For this, how would I enable flight mode, and then disable it after 4 seconds? ( 4 seconds of fly, 1 minute of no fly. )
     
  12. Offline

    xmarinusx

    Code:java
    1. public List<String> cooldown = new ArrayList<String>();
    2.  
    3. @EventHandler
    4. public void OnPlayerInteract(PlayerInteractEvent event){
    5. final Player player = event.getPlayer();
    6. if(!cooldown.contains(player.getName())){
    7. cooldown.add(player.getName());
    8. player.setAllowFlight(true);
    9. new BukkitRunnable(){
    10. @Override
    11. public void run(){
    12. player.setAllowFlight(false);
    13. }
    14. }.runTaskLater(plugin, 4*20);
    15. new BukkitRunnable(){
    16. @Override
    17. public void run(){
    18. cooldown.remove(player.getName());
    19. }
    20. }.runTaskLater(plugin, 64*20);
    21. }
    22. }
     
  13. Offline

    kreashenz

    xmarinusx That was pretty close to what I had. Almost :) Thanks..

    xmarinusx When I use it AFTER a reload, it works 1 time, but sends the debugs in a weird way, then when I try again, nothing happens, it only sends "debug 1". Also, how would I disable fall damage for just 1 kit? ( this is a KitPvP plugin, just to be clear ).

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

    xmarinusx

    kreashenz
    Can you show me some code? A reload clears the list, just so you know that.

    To do the fall damage thing:
    Listing to EntityDamageEvent, if DamageCause equals DamageCause.FALL check if they have the kit selected and if so use event.setCancelled(true);

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

    kreashenz

    xmarinusx I know, that's why it only worked 1 time.
    Code:java
    1. @EventHandler
    2. public void onFeatherFly(PlayerInteractEvent event){
    3. final Player player = event.getPlayer();
    4. if(event.getAction() == Action.RIGHT_CLICK_AIR
    5. ||event.getAction() == Action.RIGHT_CLICK_BLOCK
    6. && player.getItemInHand().getType() == Material.FEATHER){
    7. player.sendMessage("debug 1");
    8. if(!cooldown.contains(player.getName())){
    9. player.sendMessage("debug 2");
    10. cooldown.add(player.getName());
    11. player.setAllowFlight(true);
    12. new BukkitRunnable(){
    13. @Override
    14. public void run(){
    15. player.sendMessage("debug 3");
    16. player.setAllowFlight(false);
    17. }
    18. }.runTaskLater(plugin, 4*20);
    19. new BukkitRunnable(){
    20. @Override
    21. public void run(){
    22. cooldown.remove(player.getName());
    23. player.sendMessage("debug 4");
    24. }
    25. }.runTaskLater(plugin, 64*20);
    26. player.sendMessage("debug 5");
    27. }
    28. }
    29. }

    Also, how would I check if the player has the kit? Create a custom method?

    Just a little stupid picture of the order of debug messages. Where all the 1's are, is where I spammed right click.[​IMG]

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

    macguy8

    xmarinusx
    For a simple cool down (without anything happening after the cooldown period, just removing from a list), if you have a lot of entries at once, it's better to use a HashMap<String, Long> as to not have too many tasks running at once
     
  17. Offline

    kreashenz

    macguy8 Example, or it doesn't happen (LOLOLOL)
     
  18. Offline

    xmarinusx

    And what would you put as long variable in there then?
     
  19. Offline

    Brexima

    xmarinusx
    do u know how can i check "is there xx item in player's inventory "(not in hand, in inventory)
     
  20. Offline

    kreashenz

    if(player.getInventory().contains(new ItemStack(Material.WHATEVER))){
     
  21. Offline

    Brexima

    it didnt work =(
     
  22. Offline

    xmarinusx

    Show us more code then.
     
  23. Offline

    Brexima

    Code:
    if(oyuncu.getInventory().contains(new ItemStack(Material.BONE))){
                        if(rs.containsKey(oyuncu) || rscarp.containsKey(oyuncu)){
                          ..
                             
                                ..
                                ..
                            ..
                                    ..
                                 
                                  ..
                              ..
                        }else{oyuncu.sendMessage(ChatColor.RED + "You don't remember the seal.");}
                    }else{oyuncu.sendMessage(ChatColor.RED + "You don't have chakra ball.");}
    its always giving you dont have chakra ball message
     
  24. Offline

    xmarinusx

    Have you changed the name of the bone?
     
  25. Offline

    Brexima

    xmarinusx
    interesting, i try it with arrow and bow item and it work but when i try it with carrot, apple, bone item it didnt work :confused:

    i understand now,
    if(player.getInventory().contains(new ItemStack(Material.WHATEVER)))
    this code just checking one item ( one in inventory of item ), if item is more than 1, this method not see it. how can i fix it ?

    xmarinusx
    im still searching a answer for up one =(
    if(player.getInventory().contains(new ItemStack(Material.WHATEVER))) this function see item if item is just one.. if item in slot is more than one function not see it

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

    xmarinusx

    new ItemStack(Material.WHATEVER), *amount to check*)
     
  27. Offline

    Brexima

    xmarinusx
    i want to check all of amounts.. am i must use for (1 to 64) ?
    and one more question

    Code:
    public void onLaunch(ProjectileLaunchEvent event)
        {
          if (event.getEntity().getShooter() instanceof Player)
          {
              //Player player = (Player)event.getEntity().getShooter();
              event.getEntity().getVelocity().multiply(20);
              Entity oklok = event.getEntity();
              entiti = oklok;
          }
        }
    im teleporting the players to arrow and im taking the arrow's entity with this code but when i try it with my friends, my friend shooting arrow and im teleporting to my friend's arrow =/ but i want my friend teleport his arrow and i teleport to my arrow so how can i do this entity connected to his shooter?
     
  28. Offline

    xmarinusx

    Try using Material.BONE, instead of new ItemStack(etc).
    arrow.getShooter()?
     
  29. Offline

    Brexima

    xmarinusx
    arrow.getShooter() working in single player, when we try it multiplayer x player shooting arrow and im teleporting to his arrow not mine arrow =/ so i mean how can i do that arrow launch personal

    xmarinusx
    and contains(Material.BONE) worked thanks :) now there is one last problem look up =P

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

    xmarinusx

    Brexima
    Can you show your hit event?
     
Thread Status:
Not open for further replies.

Share This Page