From 2c0ec1354000afad06246d5581f126e3cc16d1f3 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 22 Aug 2022 20:25:40 +0200 Subject: [PATCH] Add CooldownScript --- .../steamwar/misslewars/scripts/Script.java | 2 ++ .../scripts/implemented/CooldownScript.java | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/de/steamwar/misslewars/scripts/implemented/CooldownScript.java diff --git a/src/de/steamwar/misslewars/scripts/Script.java b/src/de/steamwar/misslewars/scripts/Script.java index e43fbd0..98777cc 100644 --- a/src/de/steamwar/misslewars/scripts/Script.java +++ b/src/de/steamwar/misslewars/scripts/Script.java @@ -85,6 +85,8 @@ public class Script { return new SummonScript(jsonObject); case "slowmo": return new SlowMoScript(jsonObject); + case "cooldown": + return new CooldownScript(jsonObject); default: return null; } diff --git a/src/de/steamwar/misslewars/scripts/implemented/CooldownScript.java b/src/de/steamwar/misslewars/scripts/implemented/CooldownScript.java new file mode 100644 index 0000000..0932f33 --- /dev/null +++ b/src/de/steamwar/misslewars/scripts/implemented/CooldownScript.java @@ -0,0 +1,24 @@ +package de.steamwar.misslewars.scripts.implemented; + +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; +import de.steamwar.misslewars.scripts.RunnableScript; +import de.steamwar.misslewars.scripts.RunnableScriptEvent; +import org.bukkit.Material; + +public class CooldownScript implements RunnableScript { + + private int cooldown = 0; + + public CooldownScript(JsonObject object) { + JsonPrimitive primitive = object.getAsJsonPrimitive("cooldown"); + if(primitive.isNumber()) cooldown = primitive.getAsInt(); + } + + @Override + public boolean execute(RunnableScriptEvent runnableScriptEvent) { + if (runnableScriptEvent.getPlayer().getInventory().getItemInMainHand().getType() != Material.AIR) runnableScriptEvent.getPlayer().setCooldown(runnableScriptEvent.getPlayer().getInventory().getItemInMainHand().getType(), cooldown); + if (runnableScriptEvent.getPlayer().getInventory().getItemInOffHand().getType() != Material.AIR) runnableScriptEvent.getPlayer().setCooldown(runnableScriptEvent.getPlayer().getInventory().getItemInOffHand().getType(), cooldown); + return true; + } +}