Skip to content

Commit

Permalink
Merge pull request #1249 from Lildirt/attack_cooldown
Browse files Browse the repository at this point in the history
Added pattack_cooldown().
  • Loading branch information
PseudoKnight committed Oct 27, 2020
2 parents f5ecef5 + 1b3af52 commit 612736e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/laytonsmith/abstraction/MCHumanEntity.java
Expand Up @@ -42,4 +42,6 @@ public interface MCHumanEntity extends MCInventoryHolder, MCLivingEntity, MCAnim

void setCooldown(MCMaterial material, int ticks);
//boolean setWindowProperty(MCInventoryView.Property prop, int value);

float getAttackCooldown();
}
Expand Up @@ -93,6 +93,11 @@ public void setCooldown(MCMaterial material, int ticks) {
he.setCooldown((Material) material.getHandle(), ticks);
}

@Override
public float getAttackCooldown() {
return he.getAttackCooldown();
}

@Override
public MCInventoryView openInventory(MCInventory inventory) {
return new BukkitMCInventoryView(he.openInventory((Inventory) inventory.getHandle()));
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/com/laytonsmith/core/functions/PlayerManagement.java
Expand Up @@ -7,6 +7,7 @@
import com.laytonsmith.abstraction.MCCommandSender;
import com.laytonsmith.abstraction.MCConsoleCommandSender;
import com.laytonsmith.abstraction.MCEntity;
import com.laytonsmith.abstraction.MCHumanEntity;
import com.laytonsmith.abstraction.MCItemStack;
import com.laytonsmith.abstraction.MCLocation;
import com.laytonsmith.abstraction.MCOfflinePlayer;
Expand Down Expand Up @@ -5560,6 +5561,58 @@ public MSVersion since() {

}

@api(environments = {CommandHelperEnvironment.class})
public static class pattack_cooldown extends AbstractFunction {

@Override
public Class<? extends CREThrowable>[] thrown() {
return new Class[] { CREPlayerOfflineException.class, CRELengthException.class };
}

@Override
public boolean isRestricted() {
return true;
}

@Override
public Boolean runAsync() {
return false;
}

@Override
public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException {
MCHumanEntity he;
if(args.length == 0) {
he = env.getEnv(CommandHelperEnvironment.class).GetPlayer();
} else {
he = Static.GetPlayer(args[0], t);
}
return new CDouble(he.getAttackCooldown(), t);
}

@Override
public String getName() {
return "pattack_cooldown";
}

@Override
public Integer[] numArgs() {
return new Integer[]{0, 1};
}

@Override
public String docs() {
return "double {[player]} Gets the charge value of the player's attack cooldown. This is a "
+ " double with range 0.0-1.0 inclusive. 1.0 is fully charged, while 0.0 is no charge.";
}

@Override
public MSVersion since() {
return MSVersion.V3_3_4;
}

}

@api(environments = {CommandHelperEnvironment.class})
public static class get_plist_header extends AbstractFunction {

Expand Down

0 comments on commit 612736e

Please sign in to comment.