diff --git a/pom.xml b/pom.xml
index 226acf5..d6ed03e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -53,5 +53,12 @@
system
${main.basedir}/lib/WorldEdit-1.15.jar
+
+ steamwar
+ SpigotCore
+ 1.0
+ system
+ ${main.basedir}/lib/SpigotCore.jar
+
\ No newline at end of file
diff --git a/src/de/steamwar/misslewars/Config.java b/src/de/steamwar/misslewars/Config.java
index 4e4ed04..b56c7cc 100644
--- a/src/de/steamwar/misslewars/Config.java
+++ b/src/de/steamwar/misslewars/Config.java
@@ -26,6 +26,7 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
+import java.util.UUID;
import java.util.logging.Level;
public class Config {
@@ -50,6 +51,9 @@ public class Config {
public static final double MissileChance;
+ public static final UUID BlueLeader;
+ public static final UUID RedLeader;
+
static {
File configfile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "config.yml");
if (!configfile.exists()) {
@@ -83,5 +87,21 @@ public class Config {
assert blue != null;
BluePortalZ = blue.getInt("PortalZ");
BlueSpawn = new Location(Bukkit.getWorlds().get(0), blue.getDouble("SpawnX"), blue.getDouble("SpawnY"), blue.getDouble("SpawnZ"), (float)blue.getDouble("SpawnYaw"), (float)blue.getDouble("SpawnPitch"));
+
+ String blueLeader = System.getProperty("blueLeader", null);
+ String redLeader = System.getProperty("redLeader", null);
+ if(blueLeader != null)
+ BlueLeader = UUID.fromString(blueLeader);
+ else
+ BlueLeader = null;
+ if(redLeader != null)
+ RedLeader = UUID.fromString(redLeader);
+ else
+ RedLeader = null;
}
+
+ public static boolean isChallenge() {
+ return BlueLeader != null && RedLeader != null;
+ }
+
}
diff --git a/src/de/steamwar/misslewars/MWTeam.java b/src/de/steamwar/misslewars/MWTeam.java
index 72ba713..310dac4 100644
--- a/src/de/steamwar/misslewars/MWTeam.java
+++ b/src/de/steamwar/misslewars/MWTeam.java
@@ -31,8 +31,10 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Team;
+import java.util.HashSet;
import java.util.LinkedList;
import java.util.Objects;
+import java.util.Set;
public class MWTeam {
private static final ItemStack bow = new ItemStack(Material.BOW);
@@ -53,7 +55,8 @@ public class MWTeam {
private final Location spawn;
private final int portalZ;
- private LinkedList players = new LinkedList<>();
+ private final LinkedList players = new LinkedList<>();
+ private final Set openInvitations = new HashSet<>();
MWTeam(ChatColor color, Location spawn, String teamName, int portalZ) {
this.teamName = teamName;
@@ -95,7 +98,7 @@ public class MWTeam {
}
public void teamScoreboard(Objective objective) {
- players.forEach(p -> objective.getScore(getPrefix() + p.getName()).setScore(1));
+ players.forEach(p -> objective.getScore(getColorCode() + p.getName()).setScore(1));
}
public int size() {
@@ -129,6 +132,17 @@ public class MWTeam {
if (players.isEmpty() && MissileWars.getFightState() == FightState.FIGHTING)
MissileWars.end(WinReasons.NO_ENEMY, enemy());
}
+
+ public void invitePlayer(Player p) {
+ if (enemy().openInvitations.contains(p)) return;
+
+ openInvitations.add(p);
+ }
+
+ public void acceptInvite(Player p) {
+ removeInvitations(p);
+ join(p);
+ }
private MWTeam enemy() {
if (this == MissileWars.getRedTeam())
@@ -137,16 +151,25 @@ public class MWTeam {
return MissileWars.getRedTeam();
}
- public String getPrefix(){
+ public String getColorCode(){
return "§" + color.getChar();
}
- public boolean hasPlayer (Player p) {
+ public boolean hasPlayer(Player p) {
return players.contains(p);
}
+ public boolean hasInvite(Player p) {
+ return openInvitations.contains(p);
+ }
+
public String getColoredName() {
return color.toString() + teamName;
}
+ public static void removeInvitations(Player p) {
+ MissileWars.getRedTeam().openInvitations.remove(p);
+ MissileWars.getBlueTeam().openInvitations.remove(p);
+ }
+
}
diff --git a/src/de/steamwar/misslewars/MissileWars.java b/src/de/steamwar/misslewars/MissileWars.java
index 29e3ec8..b5571b6 100644
--- a/src/de/steamwar/misslewars/MissileWars.java
+++ b/src/de/steamwar/misslewars/MissileWars.java
@@ -19,6 +19,8 @@
package de.steamwar.misslewars;
+import de.steamwar.misslewars.commands.CommandAcceptDecline;
+import de.steamwar.misslewars.commands.CommandInvite;
import de.steamwar.misslewars.commands.CommandSpectate;
import de.steamwar.misslewars.countdowns.EndCountdown;
import de.steamwar.misslewars.countdowns.ItemCountdown;
@@ -63,6 +65,14 @@ public class MissileWars extends JavaPlugin {
new ChatListener();
getCommand("spectate").setExecutor(new CommandSpectate());
+ // Invitation Commands
+ CommandInvite commandInvite = new CommandInvite();
+ getCommand("invite").setExecutor(commandInvite);
+ getCommand("invite").setTabCompleter(commandInvite);
+
+ getCommand("accept").setExecutor(new CommandAcceptDecline());
+ getCommand("decline").setExecutor(new CommandAcceptDecline());
+
new WaitingCountdown();
new ItemCountdown();
new EndCountdown();
@@ -70,11 +80,7 @@ public class MissileWars extends JavaPlugin {
FightScoreboard.init();
Missile.init();
- new Arrows();
- new Fireball();
- new Shield();
- new Mine();
- new LandingPad();
+ CustomItem.init();
StateDependent.setupState(fightState);
}
@@ -140,6 +146,14 @@ public class MissileWars extends JavaPlugin {
return null;
}
+ public static MWTeam getInvitation(Player p) {
+ if(blueTeam.hasInvite(p))
+ return blueTeam;
+ if(redTeam.hasInvite(p))
+ return redTeam;
+ return null;
+ }
+
public static void join(Player p) {
if (MissileWars.getRedTeam().size() < MissileWars.getBlueTeam().size()) {
MissileWars.getRedTeam().join(p);
diff --git a/src/de/steamwar/misslewars/commands/CommandAcceptDecline.java b/src/de/steamwar/misslewars/commands/CommandAcceptDecline.java
new file mode 100644
index 0000000..cc8def7
--- /dev/null
+++ b/src/de/steamwar/misslewars/commands/CommandAcceptDecline.java
@@ -0,0 +1,57 @@
+/*
+ *
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2020 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ * /
+ */
+
+package de.steamwar.misslewars.commands;
+
+import de.steamwar.misslewars.Config;
+import de.steamwar.misslewars.MWTeam;
+import de.steamwar.misslewars.MissileWars;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class CommandAcceptDecline implements CommandExecutor {
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ if (!(sender instanceof Player)) return false;
+ Player player = (Player) sender;
+ if (!Config.isChallenge()) {
+ player.sendMessage("§cDieser Command ist deaktiviert.");
+ return false;
+ }
+
+ MWTeam teamInvitation = MissileWars.getInvitation(player);
+ if (teamInvitation == null) {
+ player.sendMessage("§cDu wurdest nicht eingeladen.");
+ return false;
+ }
+
+ if (command.getName().equalsIgnoreCase("accept")) {
+ teamInvitation.acceptInvite(player);
+ } else {
+ MWTeam.removeInvitations(player);
+ }
+ return false;
+ }
+
+}
diff --git a/src/de/steamwar/misslewars/commands/CommandInvite.java b/src/de/steamwar/misslewars/commands/CommandInvite.java
new file mode 100644
index 0000000..0e01215
--- /dev/null
+++ b/src/de/steamwar/misslewars/commands/CommandInvite.java
@@ -0,0 +1,93 @@
+/*
+ *
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2020 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ * /
+ */
+
+package de.steamwar.misslewars.commands;
+
+import de.steamwar.misslewars.Config;
+import de.steamwar.misslewars.MWTeam;
+import de.steamwar.misslewars.MissileWars;
+import org.bukkit.Bukkit;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.TabCompleter;
+import org.bukkit.entity.Player;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class CommandInvite implements CommandExecutor, TabCompleter {
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ if (!(sender instanceof Player)) return false;
+ Player player = (Player) sender;
+ if (!Config.isChallenge()) {
+ player.sendMessage("§cDieser Command ist deaktiviert.");
+ return false;
+ }
+
+ MWTeam team = MissileWars.getTeam(player);
+ if (!Config.RedLeader.equals(player.getUniqueId()) && !Config.BlueLeader.equals(player.getUniqueId()) || team == null) {
+ player.sendMessage("§cDu kannst keine Spieler einladen.");
+ return false;
+ }
+
+ if (args.length != 1) {
+ player.sendMessage("§c/invite ");
+ return false;
+ }
+
+ Player invitedPlayer = Bukkit.getPlayer(args[0]);
+ if (invitedPlayer == null) {
+ player.sendMessage("§cDieser Spieler ist nicht online.");
+ return false;
+ }
+ if (MissileWars.getTeam(invitedPlayer) != null) {
+ player.sendMessage("§cDieser Spieler ist bereits in einem Team.");
+ return false;
+ }
+ if (MissileWars.getInvitation(invitedPlayer) != null) {
+ player.sendMessage("§cDieser Spieler wurde bereits eingeladen.");
+ return false;
+ }
+
+ team.invitePlayer(invitedPlayer);
+ invitedPlayer.sendMessage("§7Du wurdest von §6" + player.getName() + "§7 in das Team §6" + MissileWars.getTeam(player).getColoredName() + "§7 eingeladen.");
+ invitedPlayer.sendMessage("§8/§6accept §8- §7Zum akzeptieren.");
+ invitedPlayer.sendMessage("§8/§6decline §8- §7Zum ablehnen.");
+ return false;
+ }
+
+ @Override
+ public List onTabComplete(CommandSender sender, Command command, String label, String[] args) {
+ if (args.length != 1) return new ArrayList<>();
+ return Bukkit.getOnlinePlayers()
+ .stream()
+ .filter(p -> MissileWars.getTeam(p) != null)
+ .filter(p -> MissileWars.getInvitation(p) != null)
+ .map(Player::getName)
+ .filter(s -> s.startsWith(args[0]))
+ .collect(Collectors.toList());
+ }
+
+}
diff --git a/src/de/steamwar/misslewars/commands/CommandSpectate.java b/src/de/steamwar/misslewars/commands/CommandSpectate.java
index 6efa06f..4a8c1f2 100644
--- a/src/de/steamwar/misslewars/commands/CommandSpectate.java
+++ b/src/de/steamwar/misslewars/commands/CommandSpectate.java
@@ -19,6 +19,7 @@
package de.steamwar.misslewars.commands;
+import de.steamwar.misslewars.Config;
import de.steamwar.misslewars.MWTeam;
import de.steamwar.misslewars.MissileWars;
import org.bukkit.GameMode;
@@ -31,8 +32,12 @@ public class CommandSpectate implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if(!(sender instanceof Player)) return false;
+ if (!(sender instanceof Player)) return false;
Player player = (Player) sender;
+ if (Config.isChallenge()) {
+ player.sendMessage("§cDieser Command ist deaktiviert.");
+ return false;
+ }
MWTeam mwTeam = MissileWars.getTeam(player);
if (mwTeam == null) return false;
@@ -42,6 +47,8 @@ public class CommandSpectate implements CommandExecutor {
}
MissileWars.leave(player);
player.setGameMode(GameMode.SPECTATOR);
+ player.getInventory().clear();
+ player.updateInventory();
return true;
}
diff --git a/src/de/steamwar/misslewars/countdowns/ItemCountdown.java b/src/de/steamwar/misslewars/countdowns/ItemCountdown.java
index f5050ee..e656667 100644
--- a/src/de/steamwar/misslewars/countdowns/ItemCountdown.java
+++ b/src/de/steamwar/misslewars/countdowns/ItemCountdown.java
@@ -29,18 +29,16 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitTask;
import java.util.EnumSet;
-import java.util.Random;
public class ItemCountdown extends StateDependent {
private BukkitTask task;
- private Random random = new Random();
public ItemCountdown() {
super(EnumSet.of(FightState.FIGHTING));
}
- private void run(){
+ private void run() {
int itemCount = Math.max(MissileWars.getBlueTeam().size(), MissileWars.getRedTeam().size());
for (int i = 0; i < itemCount; i++) {
diff --git a/src/de/steamwar/misslewars/items/CustomItem.java b/src/de/steamwar/misslewars/items/CustomItem.java
new file mode 100644
index 0000000..cfcebda
--- /dev/null
+++ b/src/de/steamwar/misslewars/items/CustomItem.java
@@ -0,0 +1,84 @@
+/*
+ This file is a part of the SteamWar software.
+
+ Copyright (C) 2020 SteamWar.de-Serverteam
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+*/
+
+package de.steamwar.misslewars.items;
+
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonSyntaxException;
+import de.steamwar.misslewars.MissileWars;
+import de.steamwar.misslewars.scripts.ScriptedItem;
+import org.bukkit.Location;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Objects;
+
+public class CustomItem extends SpecialItem {
+
+ private ScriptedItem scriptedItem;
+
+ public CustomItem(ScriptedItem scriptedItem) {
+ this.scriptedItem = scriptedItem;
+ }
+
+ @Override
+ public ItemStack getItem() {
+ return scriptedItem.getItemStack();
+ }
+
+ @Override
+ public boolean handleUse(Player p) {
+ return scriptedItem.execute(ScriptedItem.EventType.onClick, p, p.getLocation());
+ }
+
+ @Override
+ public void handleThrow(Entity e) {
+ scriptedItem.execute(ScriptedItem.EventType.onThrow, e, e.getLocation());
+ }
+
+ @Override
+ public void handleHit(Entity e, Location l) {
+ scriptedItem.execute(ScriptedItem.EventType.onHit, e, l);
+ }
+
+ public static void init() {
+ File itemsFolder = new File(MissileWars.getPlugin().getDataFolder(), "items");
+ if (!itemsFolder.exists() || !itemsFolder.canRead() || !itemsFolder.isDirectory()) throw new SecurityException("Items could not be loaded");
+ for (File itemFile : Objects.requireNonNull(itemsFolder.listFiles())) {
+ if (!itemFile.canRead() || !itemFile.isFile()) continue;
+ try {
+ JsonObject jsonObject = new JsonParser().parse(new FileReader(itemFile)).getAsJsonObject();
+ new CustomItem(new ScriptedItem(jsonObject));
+ } catch (JsonSyntaxException | IOException e) {
+ e.printStackTrace();
+ throw new SecurityException("Item JSON error", e);
+ }
+ }
+ }
+
+ public ScriptedItem getScriptedItem() {
+ return scriptedItem;
+ }
+
+}
diff --git a/src/de/steamwar/misslewars/items/Fireball.java b/src/de/steamwar/misslewars/items/Fireball.java
deleted file mode 100644
index 2fb7d75..0000000
--- a/src/de/steamwar/misslewars/items/Fireball.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- This file is a part of the SteamWar software.
-
- Copyright (C) 2020 SteamWar.de-Serverteam
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see .
-*/
-
-package de.steamwar.misslewars.items;
-
-import org.bukkit.Material;
-import org.bukkit.Sound;
-import org.bukkit.entity.Player;
-import org.bukkit.inventory.ItemStack;
-
-public class Fireball extends SpecialItem {
-
- private final ItemStack item = createItem(Material.FIRE_CHARGE, "§eFeuerball", 1);
-
- @Override
- public ItemStack getItem() {
- return item;
- }
-
- @Override
- public boolean handleUse(Player p) {
- org.bukkit.entity.Fireball fb = p.launchProjectile(org.bukkit.entity.Fireball.class);
- fb.setVelocity(fb.getVelocity().multiply(2));
- fb.setDirection(p.getLocation().getDirection());
- p.playSound(p.getLocation(), Sound.ITEM_FIRECHARGE_USE, 100, 1);
- fb.setIsIncendiary(true);
- fb.setBounce(false);
- fb.setYield(3f);
- return true;
- }
-}
diff --git a/src/de/steamwar/misslewars/items/Missile.java b/src/de/steamwar/misslewars/items/Missile.java
index 09ecb5a..b97d18b 100644
--- a/src/de/steamwar/misslewars/items/Missile.java
+++ b/src/de/steamwar/misslewars/items/Missile.java
@@ -96,9 +96,7 @@ public class Missile extends SpecialItem {
if (index > size) index = size;
StringBuilder st = new StringBuilder();
st.append("§8[§e");
- if (index > 0) {
- st.append(repeat(index));
- }
+ if (index > 0) st.append(repeat(index));
st.append("§7");
st.append(repeat(size - index));
st.append("§8]");
@@ -108,9 +106,7 @@ public class Missile extends SpecialItem {
private String repeat(int count) {
if (count == 0) return "";
StringBuilder st = new StringBuilder();
- for (int i = 0; i < count; i++) {
- st.append("=");
- }
+ for (int i = 0; i < count; i++) st.append("=");
return st.toString();
}
@@ -128,13 +124,9 @@ public class Missile extends SpecialItem {
AffineTransform aT = new AffineTransform();
double yaw = (p.getLocation().getYaw() + 360f) % 360;
- if (yaw > 45 && yaw <= 135) {
- aT = aT.rotateY(270);
- } else if (yaw > 135 && yaw <= 225) {
- aT = aT.rotateY(180);
- } else if (yaw > 225 && yaw <= 315) {
- aT = aT.rotateY(90);
- }
+ if (yaw > 45 && yaw <= 135) aT = aT.rotateY(270);
+ else if (yaw > 135 && yaw <= 225) aT = aT.rotateY(180);
+ else if (yaw > 225 && yaw <= 315) aT = aT.rotateY(90);
v = v.subtract(dimensions.getX()/2, dimensions.getY() + 2, -2).subtract(offset);
v = aT.apply(v.toVector3()).toBlockPoint();
@@ -155,9 +147,7 @@ public class Missile extends SpecialItem {
public static void init() {
File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "missiles");
- if (!missileFolder.exists() || !missileFolder.canRead() || !missileFolder.isDirectory()) {
- throw new SecurityException("Missiles could not be loaded");
- }
+ if (!missileFolder.exists() || !missileFolder.canRead() || !missileFolder.isDirectory()) throw new SecurityException("Missiles could not be loaded");
for (File missileFile : Objects.requireNonNull(missileFolder.listFiles())) {
if (!missileFile.canRead() || !missileFile.isFile()) continue;
new Missile(missileFile);
diff --git a/src/de/steamwar/misslewars/items/Shield.java b/src/de/steamwar/misslewars/items/Shield.java
deleted file mode 100644
index b954660..0000000
--- a/src/de/steamwar/misslewars/items/Shield.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- This file is a part of the SteamWar software.
-
- Copyright (C) 2020 SteamWar.de-Serverteam
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see .
-*/
-
-package de.steamwar.misslewars.items;
-
-import org.bukkit.Material;
-import org.bukkit.entity.Player;
-import org.bukkit.inventory.ItemStack;
-
-public class Shield extends SpecialItem {
-
- private final ItemStack item = createItem(Material.SNOWBALL, "§aSchild", 1);
-
- @Override
- public ItemStack getItem() {
- return item;
- }
-
- @Override
- public boolean handleUse(Player p) {
- return false;
- }
-}
diff --git a/src/de/steamwar/misslewars/items/SpecialItem.java b/src/de/steamwar/misslewars/items/SpecialItem.java
index c4e2eaf..f776115 100644
--- a/src/de/steamwar/misslewars/items/SpecialItem.java
+++ b/src/de/steamwar/misslewars/items/SpecialItem.java
@@ -20,9 +20,12 @@
package de.steamwar.misslewars.items;
import de.steamwar.misslewars.Config;
+import org.bukkit.Location;
import org.bukkit.Material;
-import org.bukkit.enchantments.Enchantment;
+import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
+import org.bukkit.event.entity.ProjectileHitEvent;
+import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@@ -39,15 +42,15 @@ public abstract class SpecialItem {
private static List missileItems = new ArrayList<>();
SpecialItem() {
- if (this.isMissile()) {
- missileItems.add(this);
- } else {
- supportItems.add(this);
- }
+ if (this.isMissile()) missileItems.add(this);
+ else supportItems.add(this);
}
+ private String materialName = null;
public abstract ItemStack getItem();
public abstract boolean handleUse(Player p);
+ public void handleThrow(Entity e) {}
+ public void handleHit(Entity e, Location l) {}
public boolean isMissile() {
return false;
}
@@ -72,18 +75,39 @@ public abstract class SpecialItem {
}
private static boolean handleUse(ItemStack item, Player player, List items) {
- for (SpecialItem specialItem : items) {
+ for (SpecialItem specialItem : items)
if (item.isSimilar(specialItem.getItem())) return specialItem.handleUse(player);
- }
return false;
}
- public static ItemStack getRandomItem() {
- if (random.nextDouble() > Config.MissileChance) {
- return supportItems.get(random.nextInt(supportItems.size())).getItem();
- } else {
- return missileItems.get(random.nextInt(missileItems.size())).getItem();
+ public static void handleThrow(ProjectileLaunchEvent e) {
+ String name = e.getEntity().getClass().getName().toLowerCase();
+ for (SpecialItem specialItem : supportItems) {
+ if (specialItem.materialName == null)
+ specialItem.materialName = specialItem.getItem().getType().name().toLowerCase();
+ if (name.contains(specialItem.materialName))
+ specialItem.handleThrow(e.getEntity());
}
}
+ public static void handleHit(ProjectileHitEvent e) {
+ String name = e.getEntity().getClass().getName().toLowerCase();
+
+ Location location = null;
+ if (e.getHitEntity() != null) location = e.getHitEntity().getLocation();
+ else if (e.getHitBlock() != null) location = e.getHitBlock().getLocation();
+ if (location == null) return;
+
+ for (SpecialItem specialItem : supportItems) {
+ if (name.contains(((CustomItem) specialItem).getScriptedItem().getEntityName())) {
+ specialItem.handleHit(e.getEntity(), location);
+ }
+ }
+ }
+
+ public static ItemStack getRandomItem() {
+ if (random.nextDouble() > Config.MissileChance) return supportItems.get(random.nextInt(supportItems.size())).getItem();
+ else return missileItems.get(random.nextInt(missileItems.size())).getItem();
+ }
+
}
diff --git a/src/de/steamwar/misslewars/listener/ConnectionListener.java b/src/de/steamwar/misslewars/listener/ConnectionListener.java
index 7c556ed..549393f 100644
--- a/src/de/steamwar/misslewars/listener/ConnectionListener.java
+++ b/src/de/steamwar/misslewars/listener/ConnectionListener.java
@@ -20,6 +20,7 @@
package de.steamwar.misslewars.listener;
import de.steamwar.misslewars.FightState;
+import de.steamwar.misslewars.MWTeam;
import de.steamwar.misslewars.MissileWars;
import org.bukkit.GameMode;
import org.bukkit.event.EventHandler;
@@ -42,6 +43,7 @@ public class ConnectionListener extends BasicListener{
@EventHandler
public void onLeave(PlayerQuitEvent e) {
+ MWTeam.removeInvitations(e.getPlayer());
MissileWars.leave(e.getPlayer());
}
diff --git a/src/de/steamwar/misslewars/listener/DeathListener.java b/src/de/steamwar/misslewars/listener/DeathListener.java
index 4c12226..c82f2f2 100644
--- a/src/de/steamwar/misslewars/listener/DeathListener.java
+++ b/src/de/steamwar/misslewars/listener/DeathListener.java
@@ -28,11 +28,14 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
+import org.bukkit.util.Vector;
import java.util.EnumSet;
public class DeathListener extends BasicListener {
+ private static final Vector ZERO = new Vector(0, 0, 0);
+
public DeathListener() {
super(EnumSet.allOf(FightState.class));
}
@@ -52,6 +55,7 @@ public class DeathListener extends BasicListener {
return;
e.setRespawnLocation(team.getSpawn());
+ e.getPlayer().setVelocity(ZERO);
new SpawnPlatformCreator(p);
}
}
diff --git a/src/de/steamwar/misslewars/listener/ItemListener.java b/src/de/steamwar/misslewars/listener/ItemListener.java
index 14e6ec6..6d78e12 100644
--- a/src/de/steamwar/misslewars/listener/ItemListener.java
+++ b/src/de/steamwar/misslewars/listener/ItemListener.java
@@ -19,64 +19,19 @@
package de.steamwar.misslewars.listener;
-import com.sk89q.worldedit.EditSession;
-import com.sk89q.worldedit.WorldEdit;
-import com.sk89q.worldedit.bukkit.BukkitWorld;
-import com.sk89q.worldedit.extent.clipboard.Clipboard;
-import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
-import com.sk89q.worldedit.function.operation.Operations;
-import com.sk89q.worldedit.math.BlockVector3;
-import com.sk89q.worldedit.session.ClipboardHolder;
-import com.sk89q.worldedit.world.World;
-import de.steamwar.misslewars.Config;
import de.steamwar.misslewars.FightState;
-import de.steamwar.misslewars.MissileWars;
-import de.steamwar.misslewars.items.Missile;
import de.steamwar.misslewars.items.SpecialItem;
-import org.bukkit.Bukkit;
-import org.bukkit.Location;
-import org.bukkit.entity.Egg;
-import org.bukkit.entity.Snowball;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
+import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
import java.util.EnumSet;
-import java.util.Objects;
public class ItemListener extends BasicListener {
- private static final File shield = new File(MissileWars.getPlugin().getDataFolder(), "shield.schem");
- private static final File mine = new File(MissileWars.getPlugin().getDataFolder(), "mine.schem");
- private static final World world = new BukkitWorld(Bukkit.getWorlds().get(0));
- private static final Clipboard clipboardShield;
- private static final BlockVector3 offsetShield;
-
- private static final Clipboard clipboardMine;
- private static final BlockVector3 offsetMine;
-
- static {
- try {
- clipboardShield = Objects.requireNonNull(ClipboardFormats.findByFile(shield)).getReader(new FileInputStream(shield)).read();
- } catch (IOException e) {
- throw new SecurityException("Could not load shield", e);
- }
-
- try {
- clipboardMine = Objects.requireNonNull(ClipboardFormats.findByFile(mine)).getReader(new FileInputStream(mine)).read();
- } catch (IOException e) {
- throw new SecurityException("Could not load mine", e);
- }
-
- offsetShield = clipboardShield.getRegion().getMinimumPoint().subtract(clipboardShield.getOrigin()).add(clipboardShield.getDimensions().divide(2));
- offsetMine = clipboardMine.getRegion().getMinimumPoint().subtract(clipboardMine.getOrigin()).add(clipboardMine.getDimensions().divide(2));
- }
-
public ItemListener() {
super(EnumSet.of(FightState.FIGHTING));
}
@@ -87,10 +42,10 @@ public class ItemListener extends BasicListener {
if (item == null)
return;
- if(e.getAction() != Action.RIGHT_CLICK_BLOCK && e.getAction() != Action.RIGHT_CLICK_AIR)
+ if (e.getAction() != Action.RIGHT_CLICK_BLOCK && e.getAction() != Action.RIGHT_CLICK_AIR)
return;
- if(SpecialItem.handleUse(item, e.getPlayer())){
+ if (SpecialItem.handleUse(item, e.getPlayer())){
item.setAmount(item.getAmount()-1);
e.getPlayer().updateInventory();
e.setCancelled(true);
@@ -99,50 +54,12 @@ public class ItemListener extends BasicListener {
@EventHandler
public void onThrow(ProjectileLaunchEvent e) {
- if (e.getEntity() instanceof Snowball) {
- Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), () -> {
- Location l = e.getEntity().getLocation();
- if (!validSpawn(l)) return;
- BlockVector3 paste = BlockVector3.at(l.getX(), l.getY(), l.getZ()).subtract(offsetShield);
-
- EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1);
- Operations.completeBlindly(new ClipboardHolder(clipboardShield).createPaste(editSession).ignoreAirBlocks(true).to(paste).build());
- editSession.flushSession();
- }, Config.ShieldFlyTime);
- }
- if (e.getEntity() instanceof Egg) {
- Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), () -> {
- Location l = e.getEntity().getLocation();
- if (!validSpawn(l)) return;
- BlockVector3 paste = BlockVector3.at(l.getX(), l.getY(), l.getZ()).subtract(offsetMine);
-
- EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1);
- Operations.completeBlindly(new ClipboardHolder(clipboardMine).createPaste(editSession).ignoreAirBlocks(true).to(paste).build());
- editSession.flushSession();
- }, Config.ShieldFlyTime);
- }
+ SpecialItem.handleThrow(e);
}
- private boolean validSpawn(Location location) {
- int bz = MissileWars.getBlueTeam().getPortalZ();
- int rz = MissileWars.getRedTeam().getPortalZ();
-
- int offset = sign(bz - rz) * 5;
-
- int blockZ = location.getBlockZ();
- if (offset > 0) {
- if (blockZ > bz - offset) return false;
- if (blockZ < rz + offset) return false;
- } else {
- if (blockZ < bz - offset) return false;
- if (blockZ > rz + offset) return false;
- }
- return true;
- }
-
- private int sign(int i) {
- if (i < 0) return -1;
- return i > 0 ? 1 : 0;
+ @EventHandler
+ public void onHit(ProjectileHitEvent e) {
+ SpecialItem.handleHit(e);
}
}
diff --git a/src/de/steamwar/misslewars/listener/JoinListener.java b/src/de/steamwar/misslewars/listener/JoinListener.java
index 83a9bd7..7469e5a 100644
--- a/src/de/steamwar/misslewars/listener/JoinListener.java
+++ b/src/de/steamwar/misslewars/listener/JoinListener.java
@@ -19,6 +19,7 @@
package de.steamwar.misslewars.listener;
+import de.steamwar.misslewars.Config;
import de.steamwar.misslewars.FightState;
import de.steamwar.misslewars.MissileWars;
import org.bukkit.event.EventHandler;
@@ -35,8 +36,9 @@ public class JoinListener extends BasicListener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onJoin(PlayerJoinEvent e){
- MissileWars.join(e.getPlayer());
e.setJoinMessage("§a» " + e.getPlayer().getDisplayName());
+ if (Config.isChallenge()) return;
+ MissileWars.join(e.getPlayer());
}
}
diff --git a/src/de/steamwar/misslewars/items/Arrows.java b/src/de/steamwar/misslewars/scripts/RunnableScript.java
similarity index 55%
rename from src/de/steamwar/misslewars/items/Arrows.java
rename to src/de/steamwar/misslewars/scripts/RunnableScript.java
index 38668f3..5328bc3 100644
--- a/src/de/steamwar/misslewars/items/Arrows.java
+++ b/src/de/steamwar/misslewars/scripts/RunnableScript.java
@@ -1,6 +1,6 @@
-/*
+/*
This file is a part of the SteamWar software.
-
+
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
@@ -17,23 +17,19 @@
along with this program. If not, see .
*/
-package de.steamwar.misslewars.items;
+package de.steamwar.misslewars.scripts;
-import org.bukkit.Material;
-import org.bukkit.entity.Player;
-import org.bukkit.inventory.ItemStack;
+import java.util.function.UnaryOperator;
-public class Arrows extends SpecialItem {
+public interface RunnableScript {
+ boolean execute(RunnableScriptEvent runnableScriptEvent);
- private final ItemStack item = createItem(Material.ARROW, "§ePfeile", 3);
+ interface ScriptFunction {
+ boolean execute(RunnableScriptEvent runnableScriptEvent, double... doubles);
+ }
- @Override
- public ItemStack getItem() {
- return item;
- }
-
- @Override
- public boolean handleUse(Player p) {
- return false;
- }
+ default boolean defaultExecution(ScriptFunction scriptFunction, boolean nullReturn, UnaryOperator returnValue, RunnableScriptEvent runnableScriptEvent, double... doubles) {
+ if (scriptFunction == null) return nullReturn;
+ return returnValue.apply(scriptFunction.execute(runnableScriptEvent, doubles));
+ }
}
diff --git a/src/de/steamwar/misslewars/scripts/RunnableScriptEvent.java b/src/de/steamwar/misslewars/scripts/RunnableScriptEvent.java
new file mode 100644
index 0000000..8459f55
--- /dev/null
+++ b/src/de/steamwar/misslewars/scripts/RunnableScriptEvent.java
@@ -0,0 +1,82 @@
+/*
+ This file is a part of the SteamWar software.
+
+ Copyright (C) 2020 SteamWar.de-Serverteam
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+*/
+
+package de.steamwar.misslewars.scripts;
+
+import org.bukkit.Location;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Player;
+
+public class RunnableScriptEvent {
+
+ public enum LocationType {
+ STATIC,
+ DYNAMIC,
+ DEFAULT,
+ CUSTOM
+ }
+
+ public final ScriptedItem.EventType eventType;
+ public final Entity entity;
+ private final Location location;
+ private Location customLocation;
+ private LocationType locationType = LocationType.DEFAULT;
+ Script.ScriptExecutor scriptExecutor = null;
+
+ public RunnableScriptEvent(ScriptedItem.EventType eventType, Entity entity, Location location) {
+ this.eventType = eventType;
+ this.entity = entity;
+ this.location = location;
+ }
+
+ public Location getLocation() {
+ // Custom location
+ if (locationType == LocationType.CUSTOM && customLocation != null) return customLocation;
+
+ // Static initial Location
+ if (locationType == LocationType.STATIC) return location;
+
+ // Dynamic Location if entity is not null
+ if (locationType == LocationType.DYNAMIC) return entity != null ? entity.getLocation() : location;
+
+ // Default Location is static if EventType is onClick otherwise dynamic
+ if (eventType == ScriptedItem.EventType.onClick) return location;
+ if (entity != null) return entity.getLocation();
+ return location;
+ }
+
+ public void setLocationType(LocationType locationType) {
+ if (locationType == null) return;
+ this.locationType = locationType;
+ }
+
+ public void setCustomLocation(double x, double y, double z, float pitch, float yaw) {
+ this.customLocation = new Location(location.getWorld(), x, y, z, yaw, pitch);
+ }
+
+ public Player getPlayer() {
+ return (Player) entity;
+ }
+
+ public void resumeScriptExecution() {
+ if (scriptExecutor == null) return;
+ scriptExecutor.resume();
+ }
+
+}
diff --git a/src/de/steamwar/misslewars/scripts/Script.java b/src/de/steamwar/misslewars/scripts/Script.java
new file mode 100644
index 0000000..0b8ac11
--- /dev/null
+++ b/src/de/steamwar/misslewars/scripts/Script.java
@@ -0,0 +1,92 @@
+/*
+ This file is a part of the SteamWar software.
+
+ Copyright (C) 2020 SteamWar.de-Serverteam
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+*/
+
+package de.steamwar.misslewars.scripts;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+import de.steamwar.misslewars.scripts.implemented.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Script {
+
+ private List runnableScriptList = new ArrayList<>();
+
+ class ScriptExecutor {
+
+ private int index = 0;
+ private final RunnableScriptEvent runnableScriptEvent;
+
+ public ScriptExecutor(RunnableScriptEvent runnableScriptEvent) {
+ this.runnableScriptEvent = runnableScriptEvent;
+ runnableScriptEvent.scriptExecutor = this;
+ resume();
+ }
+
+ void resume() {
+ while (index < runnableScriptList.size()) {
+ if (!runnableScriptList.get(index++).execute(runnableScriptEvent)) return;
+ }
+ }
+
+ }
+
+ public void execute(RunnableScriptEvent runnableScriptEvent) {
+ new ScriptExecutor(runnableScriptEvent);
+ }
+
+ public static Script parseScript(JsonArray jsonArray) {
+ Script script = new Script();
+ jsonArray.forEach(jsonElement -> {
+ RunnableScript runnableScript = parseScriptSnippet((JsonObject) jsonElement);
+ if (runnableScript == null) return;
+ script.runnableScriptList.add(runnableScript);
+ });
+ return script;
+ }
+
+ private static RunnableScript parseScriptSnippet(JsonObject jsonObject) {
+ if (!jsonObject.has("type")) return null;
+ switch (jsonObject.getAsJsonPrimitive("type").getAsString().toLowerCase()) {
+ case "delay":
+ return new DelayScript(jsonObject);
+ case "filter":
+ return new FilterScript(jsonObject);
+ case "remove":
+ return new RemoveScript(jsonObject);
+ case "launch":
+ return new LaunchScript(jsonObject);
+ case "location":
+ return new LocationScript(jsonObject);
+ case "paste":
+ return new PasteScript(jsonObject);
+ case "potion":
+ return new PotionScript(jsonObject);
+ case "sound":
+ return new SoundScript(jsonObject);
+ case "summon":
+ return new SummonScript(jsonObject);
+ default:
+ return null;
+ }
+ }
+
+}
diff --git a/src/de/steamwar/misslewars/scripts/ScriptedItem.java b/src/de/steamwar/misslewars/scripts/ScriptedItem.java
new file mode 100644
index 0000000..8f6aa75
--- /dev/null
+++ b/src/de/steamwar/misslewars/scripts/ScriptedItem.java
@@ -0,0 +1,101 @@
+/*
+ This file is a part of the SteamWar software.
+
+ Copyright (C) 2020 SteamWar.de-Serverteam
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+*/
+
+package de.steamwar.misslewars.scripts;
+
+import com.google.gson.JsonObject;
+import de.steamwar.misslewars.scripts.utils.JsonUtils;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.entity.Entity;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static de.steamwar.misslewars.scripts.utils.JsonUtils.getString;
+
+public class ScriptedItem {
+
+ // "type": Material name (STRING)
+ // "name": Item name (STRING)
+ // "lore": Lore array (OPTIONAL STRING.ARRAY)
+ // "amount": Item amount (OPTIONAL [default 1] INT)
+ // "EVENT.": Event (OPTIONAL JSONobject.ARRAY)
+ // - onClick
+ // - onHit
+ // - onThrow
+
+ public enum EventType {
+ onHit,
+ onThrow,
+ onClick
+ }
+
+ private Map scriptMap = new HashMap<>();
+ private String entityName = "";
+
+ private ItemStack itemStack;
+
+ public ScriptedItem(JsonObject jsonObject) {
+ itemStack = createItemStack(jsonObject);
+
+ getString(jsonObject, "entityName", string -> entityName = string);
+
+ for (EventType eventType : EventType.values()) {
+ String eventString = "EVENT." + eventType.name();
+ if (!jsonObject.has(eventString) || !jsonObject.get(eventString).isJsonArray()) continue;
+ scriptMap.put(eventType, Script.parseScript(jsonObject.getAsJsonArray(eventString)));
+ }
+ }
+
+ private static ItemStack createItemStack(JsonObject jsonObject) {
+ ItemStack itemStack = new ItemStack(Material.valueOf(getString(jsonObject, "type", "")), JsonUtils.getInt(jsonObject, "amount", 1));
+ ItemMeta itemMeta = itemStack.getItemMeta();
+ if (itemMeta == null) return itemStack;
+ getString(jsonObject, "name", itemMeta::setDisplayName);
+
+ if (jsonObject.has("lore")) {
+ List lore = new ArrayList<>();
+ jsonObject.getAsJsonArray("lore").forEach(jsonElement -> lore.add(jsonElement.getAsString()));
+ itemMeta.setLore(lore);
+ }
+
+ itemStack.setItemMeta(itemMeta);
+ return itemStack;
+ }
+
+ public boolean execute(EventType eventType, Entity entity, Location location) {
+ if (!scriptMap.containsKey(eventType)) return false;
+ scriptMap.get(eventType).execute(new RunnableScriptEvent(eventType, entity, location));
+ return true;
+ }
+
+ public ItemStack getItemStack() {
+ return itemStack;
+ }
+
+ public String getEntityName() {
+ return entityName;
+ }
+
+}
diff --git a/src/de/steamwar/misslewars/scripts/implemented/DelayScript.java b/src/de/steamwar/misslewars/scripts/implemented/DelayScript.java
new file mode 100644
index 0000000..f77b985
--- /dev/null
+++ b/src/de/steamwar/misslewars/scripts/implemented/DelayScript.java
@@ -0,0 +1,62 @@
+/*
+ This file is a part of the SteamWar software.
+
+ Copyright (C) 2020 SteamWar.de-Serverteam
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+*/
+
+package de.steamwar.misslewars.scripts.implemented;
+
+import com.google.gson.JsonObject;
+import com.google.gson.JsonPrimitive;
+import de.steamwar.misslewars.Config;
+import de.steamwar.misslewars.MissileWars;
+import de.steamwar.misslewars.scripts.RunnableScript;
+import de.steamwar.misslewars.scripts.RunnableScriptEvent;
+import org.bukkit.Bukkit;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class DelayScript implements RunnableScript {
+
+ private static final Map delayMap = new HashMap<>();
+
+ static {
+ delayMap.put("config.mineflytime", Config.ShieldFlyTime);
+ delayMap.put("config.shieldflytime", Config.ShieldFlyTime);
+ delayMap.put("config.endtime", Config.EndTime);
+ delayMap.put("config.waitingtime", Config.WaitingTime);
+ delayMap.put("config.itemtime", Config.ItemTime);
+ delayMap.put("config.platformtime", Config.PlatformTime);
+
+ delayMap.put("config.tick", 1);
+ }
+
+ private int delayTime = 0;
+
+ public DelayScript(JsonObject delay) {
+ JsonPrimitive jsonPrimitive = delay.getAsJsonPrimitive("time");
+ if (jsonPrimitive.isString()) delayTime = delayMap.getOrDefault(jsonPrimitive.getAsString().toLowerCase(), 0);
+ else if (jsonPrimitive.isNumber()) delayTime = jsonPrimitive.getAsInt();
+ }
+
+ @Override
+ public boolean execute(RunnableScriptEvent runnableScriptEvent) {
+ Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), runnableScriptEvent::resumeScriptExecution, delayTime);
+ return false;
+ }
+
+}
diff --git a/src/de/steamwar/misslewars/scripts/implemented/FilterScript.java b/src/de/steamwar/misslewars/scripts/implemented/FilterScript.java
new file mode 100644
index 0000000..4cf250c
--- /dev/null
+++ b/src/de/steamwar/misslewars/scripts/implemented/FilterScript.java
@@ -0,0 +1,68 @@
+/*
+ This file is a part of the SteamWar software.
+
+ Copyright (C) 2020 SteamWar.de-Serverteam
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+*/
+
+package de.steamwar.misslewars.scripts.implemented;
+
+import com.google.gson.JsonObject;
+import de.steamwar.misslewars.MissileWars;
+import de.steamwar.misslewars.scripts.RunnableScript;
+import de.steamwar.misslewars.scripts.RunnableScriptEvent;
+import org.bukkit.Location;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static de.steamwar.misslewars.scripts.utils.JsonUtils.getBoolean;
+import static de.steamwar.misslewars.scripts.utils.JsonUtils.getString;
+
+public class FilterScript implements RunnableScript {
+
+ private static final Map filterMap = new HashMap<>();
+
+ static {
+ filterMap.put("nearportal", (runnableScriptEvent, doubles) -> {
+ Location location = runnableScriptEvent.getLocation();
+ int bz = MissileWars.getBlueTeam().getPortalZ();
+ int rz = MissileWars.getRedTeam().getPortalZ();
+ int offset = (int) Math.signum(bz - rz) * 5;
+
+ int blockZ = location.getBlockZ();
+ if (offset > 0) return (blockZ > bz - offset) || (blockZ < rz + offset);
+ else return (blockZ < bz - offset) || (blockZ > rz + offset);
+ });
+ filterMap.put("nearspawn", (runnableScriptEvent, doubles) -> {
+ Location location = runnableScriptEvent.getLocation();
+ return MissileWars.getBlueTeam().getSpawn().distance(location) < 3 || MissileWars.getRedTeam().getSpawn().distance(location) < 3;
+ });
+ }
+
+ private boolean inverted;
+ private ScriptFunction filter;
+
+ public FilterScript(JsonObject filter) {
+ this.filter = filterMap.getOrDefault(getString(filter, "filter", "").toLowerCase(), null);
+ inverted = getBoolean(filter, "invert", false);
+ }
+
+ @Override
+ public boolean execute(RunnableScriptEvent runnableScriptEvent) {
+ return defaultExecution(filter, true, b -> b ^ inverted, runnableScriptEvent);
+ }
+
+}
diff --git a/src/de/steamwar/misslewars/scripts/implemented/LaunchScript.java b/src/de/steamwar/misslewars/scripts/implemented/LaunchScript.java
new file mode 100644
index 0000000..83b44ed
--- /dev/null
+++ b/src/de/steamwar/misslewars/scripts/implemented/LaunchScript.java
@@ -0,0 +1,51 @@
+/*
+ This file is a part of the SteamWar software.
+
+ Copyright (C) 2020 SteamWar.de-Serverteam
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+*/
+
+package de.steamwar.misslewars.scripts.implemented;
+
+import com.google.gson.JsonObject;
+import de.steamwar.misslewars.scripts.RunnableScript;
+import de.steamwar.misslewars.scripts.RunnableScriptEvent;
+import de.steamwar.misslewars.scripts.ScriptedItem;
+import de.steamwar.misslewars.scripts.utils.EntityUtils;
+import de.steamwar.misslewars.scripts.utils.EntityUtils.ScriptShortcut;
+import org.bukkit.entity.Projectile;
+
+public class LaunchScript implements RunnableScript {
+
+ private ScriptFunction launch = null;
+
+ public LaunchScript(JsonObject launch) {
+ ScriptShortcut scriptShortcut = EntityUtils.getEntity(launch.getAsJsonPrimitive("entity").getAsString(), EntityUtils.EntityType.Projectile);
+ if (scriptShortcut == null) return;
+
+ this.launch = (runnableScriptEvent, doubles) -> {
+ Projectile projectile = runnableScriptEvent.getPlayer().launchProjectile(scriptShortcut.entityClass);
+ scriptShortcut.consumer.accept(launch, projectile, runnableScriptEvent);
+ return false;
+ };
+ }
+
+ @Override
+ public boolean execute(RunnableScriptEvent runnableScriptEvent) {
+ if (runnableScriptEvent.eventType != ScriptedItem.EventType.onClick) return true;
+ return defaultExecution(launch, false, b -> true, runnableScriptEvent);
+ }
+
+}
diff --git a/src/de/steamwar/misslewars/scripts/implemented/LocationScript.java b/src/de/steamwar/misslewars/scripts/implemented/LocationScript.java
new file mode 100644
index 0000000..1fb272e
--- /dev/null
+++ b/src/de/steamwar/misslewars/scripts/implemented/LocationScript.java
@@ -0,0 +1,89 @@
+/*
+ This file is a part of the SteamWar software.
+
+ Copyright (C) 2020 SteamWar.de-Serverteam
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+*/
+
+package de.steamwar.misslewars.scripts.implemented;
+
+import com.google.gson.JsonObject;
+import de.steamwar.misslewars.scripts.RunnableScript;
+import de.steamwar.misslewars.scripts.RunnableScriptEvent;
+import de.steamwar.misslewars.scripts.RunnableScriptEvent.LocationType;
+import org.bukkit.Location;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static de.steamwar.misslewars.scripts.utils.JsonUtils.getDouble;
+import static de.steamwar.misslewars.scripts.utils.JsonUtils.getString;
+
+public class LocationScript implements RunnableScript {
+
+ private static final Map locationTypeMap = new HashMap<>();
+ private static final Map locationMap = new HashMap<>();
+
+ static {
+ locationTypeMap.put("static", LocationType.STATIC);
+ locationTypeMap.put("dynamic", LocationType.DYNAMIC);
+ locationTypeMap.put("custom", LocationType.CUSTOM);
+ locationTypeMap.put("default", LocationType.DEFAULT);
+
+ locationMap.put("offsetentity", (runnableScriptEvent, doubles) -> {
+ if (runnableScriptEvent.entity == null) return false;
+ Location location1 = runnableScriptEvent.entity.getLocation();
+ runnableScriptEvent.setCustomLocation(location1.getX() + doubles[0], location1.getY() + doubles[1], location1.getZ() + doubles[2], 0, 0);
+ return false;
+ });
+ locationMap.put("offsetlocation", (runnableScriptEvent, doubles) -> {
+ Location location1 = runnableScriptEvent.getLocation();
+ runnableScriptEvent.setCustomLocation(location1.getX() + doubles[0], location1.getY() + doubles[1], location1.getZ() + doubles[2], 0, 0);
+ return false;
+ });
+ ScriptFunction absoluteLocation = (runnableScriptEvent, doubles) -> {
+ runnableScriptEvent.setCustomLocation(doubles[0], doubles[1], doubles[2], 0, 0);
+ return false;
+ };
+ locationMap.put("absolute", absoluteLocation);
+ locationMap.put("fix", absoluteLocation);
+ locationMap.put("fixed", absoluteLocation);
+ }
+
+ private LocationType locationType = null;
+ private ScriptFunction locationExecutor = null;
+
+ private double x, y, z = 0;
+
+ public LocationScript(JsonObject location) {
+ if (location.has("location")) {
+ JsonObject jsonObject = location.getAsJsonObject("location");
+ getDouble(jsonObject, "x", value -> x = value);
+ getDouble(jsonObject, "y", value -> y = value);
+ getDouble(jsonObject, "z", value -> z = value);
+ locationExecutor = locationMap.getOrDefault(getString(jsonObject, "type", "").toLowerCase(), null);
+ locationType = LocationType.CUSTOM;
+ } else if (location.has("locationType")) {
+ locationType = locationTypeMap.getOrDefault(getString(location, "locationType", "").toLowerCase(), LocationType.DEFAULT);
+ }
+ }
+
+ @Override
+ public boolean execute(RunnableScriptEvent runnableScriptEvent) {
+ runnableScriptEvent.setLocationType(locationType);
+ return defaultExecution(locationExecutor, true, b -> true, runnableScriptEvent, x, y, z);
+ }
+
+}
diff --git a/src/de/steamwar/misslewars/items/LandingPad.java b/src/de/steamwar/misslewars/scripts/implemented/PasteScript.java
similarity index 50%
rename from src/de/steamwar/misslewars/items/LandingPad.java
rename to src/de/steamwar/misslewars/scripts/implemented/PasteScript.java
index db7e781..db1b2cb 100644
--- a/src/de/steamwar/misslewars/items/LandingPad.java
+++ b/src/de/steamwar/misslewars/scripts/implemented/PasteScript.java
@@ -17,8 +17,10 @@
along with this program. If not, see .
*/
-package de.steamwar.misslewars.items;
+package de.steamwar.misslewars.scripts.implemented;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitWorld;
@@ -29,51 +31,62 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.world.World;
import de.steamwar.misslewars.MissileWars;
+import de.steamwar.misslewars.scripts.RunnableScript;
+import de.steamwar.misslewars.scripts.RunnableScriptEvent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
-import org.bukkit.Material;
-import org.bukkit.entity.Player;
-import org.bukkit.inventory.ItemStack;
-import org.bukkit.potion.PotionEffect;
-import org.bukkit.potion.PotionEffectType;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Objects;
-public class LandingPad extends SpecialItem {
+import static de.steamwar.misslewars.scripts.utils.JsonUtils.getBoolean;
+
+public class PasteScript implements RunnableScript {
- private final ItemStack item = createItem(Material.SLIME_BALL, "§aLanding Pad", 1);
private static final World world = new BukkitWorld(Bukkit.getWorlds().get(0));
- private static final File landingPad = new File(MissileWars.getPlugin().getDataFolder(), "landingPad.schem");
+
private final Clipboard clipboard;
- private final BlockVector3 offset;
+ private final BlockVector3 centeredOffset;
- {
+ private boolean centered, ignoreAir;
+ private int xOffset, yOffset, zOffset = 0;
+
+ public PasteScript(JsonObject paste) {
+ String schemFileName = paste.getAsJsonPrimitive("schem").getAsString();
+ if (!schemFileName.endsWith(".schem")) schemFileName += ".schem";
+
+ File schemFile = new File(MissileWars.getPlugin().getDataFolder(), schemFileName);
try {
- clipboard = Objects.requireNonNull(ClipboardFormats.findByFile(landingPad)).getReader(new FileInputStream(landingPad)).read();
+ clipboard = Objects.requireNonNull(ClipboardFormats.findByFile(schemFile)).getReader(new FileInputStream(schemFile)).read();
} catch (IOException e) {
- throw new SecurityException("Could not load landingPad", e);
+ throw new SecurityException("Could not load " + schemFileName, e);
}
+ centeredOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()).add(clipboard.getDimensions().divide(2));
- offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()).add(clipboard.getDimensions().divide(2));
+ centered = getBoolean(paste, "centered", false);
+ ignoreAir = getBoolean(paste, "ignoreAir", false);
+ if (paste.has("offset"))
+ return;
+ JsonArray jsonArray = paste.getAsJsonArray("offset");
+ if (jsonArray.size() == 3)
+ return;
+ xOffset = jsonArray.get(0).getAsInt();
+ yOffset = jsonArray.get(1).getAsInt();
+ zOffset = jsonArray.get(2).getAsInt();
}
@Override
- public ItemStack getItem() {
- return item;
- }
-
- @Override
- public boolean handleUse(Player p) {
- p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 2, 1, false, false, false));
- Location l = p.getLocation();
- BlockVector3 paste = BlockVector3.at(l.getX(), l.getY() - 5, l.getZ()).subtract(offset);
+ public boolean execute(RunnableScriptEvent runnableScriptEvent) {
+ Location location = runnableScriptEvent.getLocation();
+ BlockVector3 paste = BlockVector3.at(location.getX() + xOffset, location.getY() + yOffset, location.getZ() + zOffset);
+ if (centered) paste = paste.subtract(centeredOffset);
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1);
- Operations.completeBlindly(new ClipboardHolder(clipboard).createPaste(editSession).ignoreAirBlocks(true).to(paste).build());
+ Operations.completeBlindly(new ClipboardHolder(clipboard).createPaste(editSession).ignoreAirBlocks(ignoreAir).to(paste).build());
editSession.flushSession();
return true;
}
+
}
diff --git a/src/de/steamwar/misslewars/scripts/implemented/PotionScript.java b/src/de/steamwar/misslewars/scripts/implemented/PotionScript.java
new file mode 100644
index 0000000..34777dc
--- /dev/null
+++ b/src/de/steamwar/misslewars/scripts/implemented/PotionScript.java
@@ -0,0 +1,56 @@
+/*
+ This file is a part of the SteamWar software.
+
+ Copyright (C) 2020 SteamWar.de-Serverteam
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+*/
+
+package de.steamwar.misslewars.scripts.implemented;
+
+import com.google.gson.JsonObject;
+import de.steamwar.misslewars.scripts.RunnableScript;
+import de.steamwar.misslewars.scripts.RunnableScriptEvent;
+import de.steamwar.misslewars.scripts.ScriptedItem;
+import org.bukkit.potion.PotionEffect;
+import org.bukkit.potion.PotionEffectType;
+
+import static de.steamwar.misslewars.scripts.utils.JsonUtils.getBoolean;
+import static de.steamwar.misslewars.scripts.utils.JsonUtils.getInt;
+
+public class PotionScript implements RunnableScript {
+
+ private PotionEffect potionEffect = null;
+
+ public PotionScript(JsonObject potion) {
+ int duration = getInt(potion, "duration", 1);
+ int amplifier = getInt(potion, "amplifier", 1);
+ boolean ambient = getBoolean(potion, "ambient", true);
+ boolean particles = getBoolean(potion, "particles", true);
+ boolean icon = getBoolean(potion, "icon", true);
+
+ PotionEffectType potionEffectType = PotionEffectType.getByName(potion.getAsJsonPrimitive("potion").getAsString());
+ if (potionEffectType == null) return;
+ potionEffect = new PotionEffect(potionEffectType, duration, amplifier, ambient, particles, icon);
+ }
+
+ @Override
+ public boolean execute(RunnableScriptEvent runnableScriptEvent) {
+ if (potionEffect == null) return false;
+ if (runnableScriptEvent.eventType != ScriptedItem.EventType.onClick) return true;
+ runnableScriptEvent.getPlayer().addPotionEffect(potionEffect);
+ return true;
+ }
+
+}
diff --git a/src/de/steamwar/misslewars/items/Mine.java b/src/de/steamwar/misslewars/scripts/implemented/RemoveScript.java
similarity index 62%
rename from src/de/steamwar/misslewars/items/Mine.java
rename to src/de/steamwar/misslewars/scripts/implemented/RemoveScript.java
index f87d9a1..ede587e 100644
--- a/src/de/steamwar/misslewars/items/Mine.java
+++ b/src/de/steamwar/misslewars/scripts/implemented/RemoveScript.java
@@ -17,23 +17,22 @@
along with this program. If not, see .
*/
-package de.steamwar.misslewars.items;
+package de.steamwar.misslewars.scripts.implemented;
-import org.bukkit.Material;
+import com.google.gson.JsonObject;
+import de.steamwar.misslewars.scripts.RunnableScript;
+import de.steamwar.misslewars.scripts.RunnableScriptEvent;
import org.bukkit.entity.Player;
-import org.bukkit.inventory.ItemStack;
-public class Mine extends SpecialItem {
+public class RemoveScript implements RunnableScript {
- private final ItemStack item = createItem(Material.EGG, "§eMine", 1);
+ public RemoveScript(JsonObject jsonObject) {}
@Override
- public ItemStack getItem() {
- return item;
+ public boolean execute(RunnableScriptEvent runnableScriptEvent) {
+ if (runnableScriptEvent.entity instanceof Player) return true;
+ runnableScriptEvent.entity.remove();
+ return true;
}
- @Override
- public boolean handleUse(Player p) {
- return false;
- }
}
diff --git a/src/de/steamwar/misslewars/scripts/implemented/SoundScript.java b/src/de/steamwar/misslewars/scripts/implemented/SoundScript.java
new file mode 100644
index 0000000..32e40bb
--- /dev/null
+++ b/src/de/steamwar/misslewars/scripts/implemented/SoundScript.java
@@ -0,0 +1,51 @@
+/*
+ This file is a part of the SteamWar software.
+
+ Copyright (C) 2020 SteamWar.de-Serverteam
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+*/
+
+package de.steamwar.misslewars.scripts.implemented;
+
+import com.google.gson.JsonObject;
+import de.steamwar.misslewars.scripts.RunnableScript;
+import de.steamwar.misslewars.scripts.RunnableScriptEvent;
+import de.steamwar.misslewars.scripts.ScriptedItem;
+import org.bukkit.Sound;
+
+import static de.steamwar.misslewars.scripts.utils.JsonUtils.getFloat;
+import static de.steamwar.misslewars.scripts.utils.JsonUtils.getString;
+
+public class SoundScript implements RunnableScript {
+
+ private Sound sound;
+ private float volume;
+ private float pitch;
+
+ public SoundScript(JsonObject sound) {
+ getString(sound, "sound", value -> this.sound = Sound.valueOf(value));
+ volume = getFloat(sound, "volume", 100);
+ pitch = getFloat(sound, "pitch", 1);
+ }
+
+ @Override
+ public boolean execute(RunnableScriptEvent runnableScriptEvent) {
+ if (sound == null) return false;
+ if (runnableScriptEvent.eventType != ScriptedItem.EventType.onClick) return true;
+ runnableScriptEvent.getPlayer().playSound(runnableScriptEvent.getPlayer().getLocation(), sound, volume, pitch);
+ return true;
+ }
+
+}
diff --git a/src/de/steamwar/misslewars/scripts/implemented/SummonScript.java b/src/de/steamwar/misslewars/scripts/implemented/SummonScript.java
new file mode 100644
index 0000000..a85ea3a
--- /dev/null
+++ b/src/de/steamwar/misslewars/scripts/implemented/SummonScript.java
@@ -0,0 +1,49 @@
+/*
+ This file is a part of the SteamWar software.
+
+ Copyright (C) 2020 SteamWar.de-Serverteam
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+*/
+
+package de.steamwar.misslewars.scripts.implemented;
+
+import com.google.gson.JsonObject;
+import de.steamwar.misslewars.scripts.RunnableScript;
+import de.steamwar.misslewars.scripts.RunnableScriptEvent;
+import de.steamwar.misslewars.scripts.utils.EntityUtils;
+import de.steamwar.misslewars.scripts.utils.EntityUtils.ScriptShortcut;
+import org.bukkit.entity.Entity;
+
+public class SummonScript implements RunnableScript {
+
+ private ScriptFunction summon = null;
+
+ public SummonScript(JsonObject summon) {
+ ScriptShortcut scriptShortcut = EntityUtils.getEntity(summon.getAsJsonPrimitive("entity").getAsString(), EntityUtils.EntityType.Normal);
+ if (scriptShortcut == null) return;
+
+ this.summon = (runnableScriptEvent, doubles) -> {
+ Entity entity = runnableScriptEvent.entity.getWorld().spawn(runnableScriptEvent.getLocation(), scriptShortcut.entityClass);
+ scriptShortcut.consumer.accept(summon, entity, runnableScriptEvent);
+ return false;
+ };
+ }
+
+ @Override
+ public boolean execute(RunnableScriptEvent runnableScriptEvent) {
+ return defaultExecution(summon, false, b -> true, runnableScriptEvent);
+ }
+
+}
diff --git a/src/de/steamwar/misslewars/scripts/utils/EntityUtils.java b/src/de/steamwar/misslewars/scripts/utils/EntityUtils.java
new file mode 100644
index 0000000..823751e
--- /dev/null
+++ b/src/de/steamwar/misslewars/scripts/utils/EntityUtils.java
@@ -0,0 +1,99 @@
+/*
+ This file is a part of the SteamWar software.
+
+ Copyright (C) 2020 SteamWar.de-Serverteam
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+*/
+
+package de.steamwar.misslewars.scripts.utils;
+
+import com.google.gson.JsonObject;
+import de.steamwar.misslewars.scripts.RunnableScriptEvent;
+import org.bukkit.entity.*;
+
+import static de.steamwar.misslewars.scripts.utils.JsonUtils.*;
+
+public class EntityUtils {
+
+ private EntityUtils() {
+ throw new IllegalStateException("Utility class");
+ }
+
+ public static void setEntityOptions(Entity entity, JsonObject jsonObject) {
+ getDouble(jsonObject, "velocity", aDouble -> entity.setVelocity(entity.getVelocity().multiply(aDouble)));
+ getBoolean(jsonObject, "glowing", entity::setGlowing);
+ getBoolean(jsonObject, "gravity", entity::setGravity);
+ }
+
+ public static void setProjectileOptions(Projectile projectile, JsonObject jsonObject) {
+ getBoolean(jsonObject, "bounce", projectile::setBounce);
+ setEntityOptions(projectile, jsonObject);
+ }
+
+ public static void setExplosiveOptions(Explosive explosive, JsonObject jsonObject) {
+ getFloat(jsonObject, "yield", explosive::setYield);
+ getBoolean(jsonObject, "incendiary", explosive::setIsIncendiary);
+ setEntityOptions(explosive, jsonObject);
+ }
+
+ public static void setFireballOptions(Fireball fireball, JsonObject jsonObject) {
+ setProjectileOptions(fireball, jsonObject);
+ setExplosiveOptions(fireball, jsonObject);
+ }
+
+ public static void setTNTPrimedOptions(TNTPrimed tntPrimed, JsonObject jsonObject) {
+ getInt(jsonObject, "fuse", tntPrimed::setFuseTicks);
+ setExplosiveOptions(tntPrimed, jsonObject);
+ }
+
+ public enum EntityType {
+ Projectile,
+ Normal
+ }
+
+ public static ScriptShortcut getEntity(String name, EntityType entityType) {
+ switch (name.toLowerCase()) {
+ case "tntprimed":
+ if (entityType != EntityType.Normal) return null;
+ return new ScriptShortcut<>(TNTPrimed.class, (jsonObject, entity, runnableScriptEvent) -> setTNTPrimedOptions(entity, jsonObject));
+
+ case "fireball":
+ return new ScriptShortcut<>(Fireball.class, (jsonObject, entity, runnableScriptEvent) -> {
+ setFireballOptions(entity, jsonObject);
+ entity.setDirection(runnableScriptEvent.getLocation().getDirection());
+ });
+ case "arrow":
+ return new ScriptShortcut<>(Arrow.class, (jsonObject, entity, runnableScriptEvent) -> setProjectileOptions(entity, jsonObject));
+ }
+ return null;
+ }
+
+ public static class ScriptShortcut {
+
+ public Class entityClass;
+ public TriConsumer consumer;
+
+ public ScriptShortcut(Class entityClass, TriConsumer consumer) {
+ this.entityClass = entityClass;
+ this.consumer = consumer;
+ }
+
+ }
+
+ public interface TriConsumer {
+ void accept(T t, R r, K k);
+ }
+
+}
diff --git a/src/de/steamwar/misslewars/scripts/utils/JsonUtils.java b/src/de/steamwar/misslewars/scripts/utils/JsonUtils.java
new file mode 100644
index 0000000..f0a703a
--- /dev/null
+++ b/src/de/steamwar/misslewars/scripts/utils/JsonUtils.java
@@ -0,0 +1,51 @@
+package de.steamwar.misslewars.scripts.utils;
+
+import com.google.gson.JsonObject;
+
+import java.util.function.Consumer;
+import java.util.function.DoubleConsumer;
+import java.util.function.IntConsumer;
+
+public class JsonUtils {
+
+ private JsonUtils() {
+ throw new IllegalStateException("Utility class");
+ }
+
+ public static boolean getBoolean(JsonObject jsonObject, String key, boolean defaultValue) {
+ return jsonObject.has(key) ? jsonObject.getAsJsonPrimitive(key).getAsBoolean() : defaultValue;
+ }
+
+ public static int getInt(JsonObject jsonObject, String key, int defaultValue) {
+ return jsonObject.has(key) ? jsonObject.getAsJsonPrimitive(key).getAsInt() : defaultValue;
+ }
+
+ public static float getFloat(JsonObject jsonObject, String key, float defaultValue) {
+ return jsonObject.has(key) ? jsonObject.getAsJsonPrimitive(key).getAsFloat() : defaultValue;
+ }
+
+ public static String getString(JsonObject jsonObject, String key, String defaultValue) {
+ return jsonObject.has(key) ? jsonObject.getAsJsonPrimitive(key).getAsString() : defaultValue;
+ }
+
+ public static void getBoolean(JsonObject jsonObject, String key, Consumer booleanConsumer) {
+ if (jsonObject.has(key)) booleanConsumer.accept(jsonObject.getAsJsonPrimitive(key).getAsBoolean());
+ }
+
+ public static void getInt(JsonObject jsonObject, String key, IntConsumer booleanConsumer) {
+ if (jsonObject.has(key)) booleanConsumer.accept(jsonObject.getAsJsonPrimitive(key).getAsInt());
+ }
+
+ public static void getDouble(JsonObject jsonObject, String key, DoubleConsumer booleanConsumer) {
+ if (jsonObject.has(key)) booleanConsumer.accept(jsonObject.getAsJsonPrimitive(key).getAsDouble());
+ }
+
+ public static void getFloat(JsonObject jsonObject, String key, Consumer booleanConsumer) {
+ if (jsonObject.has(key)) booleanConsumer.accept(jsonObject.getAsJsonPrimitive(key).getAsFloat());
+ }
+
+ public static void getString(JsonObject jsonObject, String key, Consumer booleanConsumer) {
+ if (jsonObject.has(key)) booleanConsumer.accept(jsonObject.getAsJsonPrimitive(key).getAsString());
+ }
+
+}
diff --git a/src/plugin.yml b/src/plugin.yml
index 452b135..b05dc54 100644
--- a/src/plugin.yml
+++ b/src/plugin.yml
@@ -11,4 +11,7 @@ depend:
- WorldEdit
- SpigotCore
commands:
- spectate:
\ No newline at end of file
+ spectate:
+ invite:
+ accept:
+ decline:
\ No newline at end of file