1.11 ender perl cooldown?

Discussion in 'Spigot Plugin Help' started by AndGK, Apr 30, 2017.

  1. I tried five plugins and none of them work on 1.11 ._. Anyone knows a plugin that would work at 1.11? :3
     
  2. What kind of cooldown do you mean? The animation after throwing a enderpearl?
     
    • Like Like x 2
  3. I have posted a resource update :) Thank you for the suggestion.
     
    • Like Like x 1
  4. Here's what I use for the cooldown for enderpearl. ATM I use it on my teleport compass but this section should help ya out a bit. I just copied it from my source, the item in hand is the item,, the 20*cooldownTime is the cooldown visual time, cooldownTime being milliseconds

    I use this in the player interact event. But hopefully you get what you need from this.

    Code (Text):

    EntityPlayer p = ((CraftPlayer)event.getPlayer()).getHandle();
    p.playerConnection.sendPacket(new PacketPlayOutSetCooldown(p.inventory.getItemInHand().getItem(), 20 * cooldownTime));
     
     
    • Informative Informative x 1
  5. Today I learned, thanks.
    I don't know whether I should change my plugin though. I don't want to use NMS unless it's absolutely necessary and your method wouldn't let me play annoying sounds when a player tries to throw an ender pearl while he is on cooldown.
     
  6. Actually it can. Just go further by having a check function for the cooldown timer. I store mine in a hashmap and from there I check if they are in the cooldown period. If so play the sound. So yes it would work all the same. I use mine in a similar manner by giving a player a message however instead that they have to wait.


    ill use mine as an example, please note these are snippets from different locations on the same class however

    Code (Text):

    // Top of class
    int cooldownTime = YourTimeinSeconds;

    // Put this before w/e event you want to cooldown
    if(cooldowns.containsKey(player.getName())) {
    long secondsLeft = ((cooldowns.get(player.getName())/1000)+cooldownTime) - (System.currentTimeMillis()/1000);
    if(secondsLeft>0) {
    // Still cooling down
    // Do what you want here, sound, message, etc
    return;
    }
    }

    // At end of event function such as an enderpearl throw
    cooldowns.put(player.getName(), System.currentTimeMillis());
    EntityPlayer p = ((CraftPlayer)event.getPlayer()).getHandle();
    p.playerConnection.sendPacket(new PacketPlayOutSetCooldown(p.inventory.getItemInHand().getItem(), 20 * cooldownTime));


     
     
  7. I made some tests before your first post in this thread and I have concluded that the PlayerInteractEvent is not called when a player right-clicks an item which is on cooldown.
     
  8. alright cause mine literally does all checks and balances and provides this when an items in cooldown

    player.sendMessage(ChatColor.DARK_PURPLE+"You are unable to harness the powers of ender for "+ChatColor.GOLD+ secondsLeft +ChatColor.DARK_PURPLE+" more seconds!");


    and works :p

    but if the intent is to not work when its in cooldown and got it then good. otherwise if I understand right. the events called regardless of cooldown. Just what happens in the event is handled by the code end of which was setup.

    although im using a compass, but it doesnt matter. its placement. player interact event should fire regardless. Just have to place the check I shown provided and place what you want in that check area.

    for example (this is the whole class for the event) (literal copy paste from my plugin)

    Code (Text):

    EnderCompassPlugin plugin;
    FileConfiguration config;
       
      /*
      * Class Imports
      */
       SafeLocation sl = new SafeLocation();
       KickBack kb = new KickBack();
       
       /*
      * HashMaps
      */
      public HashMap<String, Long> cooldowns = new HashMap<String, Long>();
       
        /*
      * Variables
      */
       boolean isFence = false;
       boolean result = false;
       boolean isLiquid = false;
       int cooldownTime;
       
       public PlayerInteract(EnderCompassPlugin plugin){
         this.plugin = plugin;
         this.config = plugin.getConfig();
         this.cooldownTime = config.getInt("Settings.CoolDownInSeconds");
       }

    @EventHandler(priority=EventPriority.HIGHEST)
       public void onPlayerInteract(PlayerInteractEvent event) throws InterruptedException{
         Player player = event.getPlayer();
         if (player == null) return;
       
         if (!player.hasPermission("ctp.jumpto")) return;
       
         Action action = event.getAction();
       
         if (action != Action.RIGHT_CLICK_AIR && action != Action.RIGHT_CLICK_BLOCK) return;
         // with compass in hand
         ItemStack item = event.getPlayer().getItemInHand();
         if (item == null || item.getType() != Material.COMPASS) return;
       
         /*
          * Custom Compass Event
          */
         CompassEvent ce = new CompassEvent(player);
         Bukkit.getServer().getPluginManager().callEvent(ce);
         if (ce.isCancelled()) {
           return;
         }

         // get block pointing at
         Block block = player.getTargetBlock(MaterialValues.IgnoredBlocks, 500);
       
         if(cooldowns.containsKey(player.getName())) {
      long secondsLeft = ((cooldowns.get(player.getName())/1000)+cooldownTime) - (System.currentTimeMillis()/1000);
      if(secondsLeft>0) {
      // Still cooling down
      //player.sendMessage(ChatColor.DARK_PURPLE+"You are unable to harness the powers of ender for "+ChatColor.GOLD+ secondsLeft +ChatColor.DARK_PURPLE+" more seconds!");
      return;
      }
      }
       
         if (block == null || block.getType() == Material.AIR){
           player.sendMessage(ChatColor.DARK_PURPLE+"The powers of Ender can not travel such a distance!");
           return;
         }
       
         if (Arrays.asList(MaterialValues.PUT_ON_TOP).contains(block.getType())){
           isFence = true;
         }

         // filter location - nothing above/below limit (and no 0 position - sky)
         Location dest = block.getLocation();
         int y = dest.getBlockY();
         if (y <= 0 || y > 256) return;
       
         // get to the topmost block
         while (block.getType() != Material.AIR) {
           block = block.getRelative(BlockFace.UP);
           if (block == null) return;
           dest = block.getLocation();
           if (dest.getBlockY() > 256) return;
         }
       
         // use player's direction of sight and correct for block offset
         Location src = player.getLocation();
         dest.setPitch(src.getPitch());
         dest.setYaw(src.getYaw());
         dest.setX(dest.getX()+0.5);
         dest.setZ(dest.getZ()+0.5);
         if (isFence){
           dest.setY(dest.getY());
           isFence = false;
         }
     
         // and finally teleport
         if (ce.isCancelled()) {
           return;
         }
       
         if (dest.getBlock().getRelative(BlockFace.DOWN).isLiquid()){
           isLiquid = true;
         }
         while (result == false) {
             if (dest.getBlock().getLocation().getBlockY() > 256){
               return;
             }

             if (!sl.isSafeLocation((dest))){
               dest.add(0, 1, 0);
           }else{
             if (isLiquid){
                 if (dest.getBlock().getRelative(BlockFace.DOWN).isLiquid()){
                   dest.subtract(0, 1, 0);
                 }
                 else{
                   result = true;
                 }
               }else{
                 result = true;
               }
           }
         }
       
         player.playSound(player.getLocation(), Sound.ENTITY_ENDERMEN_TELEPORT, 10, 1);
         player.playEffect(player.getLocation(), Effect.ENDER_SIGNAL, 2);
         player.teleport(dest);
       
         result = false;
         isLiquid = false;
         player.playEffect(player.getLocation(), Effect.ENDER_SIGNAL, 2);
       
         cooldowns.put(player.getName(), System.currentTimeMillis());
         EntityPlayer p = ((CraftPlayer)event.getPlayer()).getHandle();
         p.playerConnection.sendPacket(new PacketPlayOutSetCooldown(p.inventory.getItemInHand().getItem(), 20 * cooldownTime));
       
         kb.kickBack(player, config);

      }