forked from SteamWar/SteamWar
Add MissileWars module
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package de.steamwar.misslewars.scripts.implemented;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import de.steamwar.misslewars.MissileWars;
|
||||
import de.steamwar.misslewars.scripts.RunnableScript;
|
||||
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
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) {
|
||||
Material mainHand = runnableScriptEvent.getPlayer().getInventory().getItemInMainHand().getType();
|
||||
Material offHand = runnableScriptEvent.getPlayer().getInventory().getItemInOffHand().getType();
|
||||
Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), () -> {
|
||||
if (mainHand != Material.AIR) runnableScriptEvent.getPlayer().setCooldown(mainHand, cooldown);
|
||||
if (offHand != Material.AIR) runnableScriptEvent.getPlayer().setCooldown(offHand, cooldown);
|
||||
}, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<String, Integer> 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<String, ScriptFunction> 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<Projectile> 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<String, LocationType> locationTypeMap = new HashMap<>();
|
||||
private static final Map<String, ScriptFunction> 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
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.MissileWars;
|
||||
import de.steamwar.misslewars.scripts.RunnableScript;
|
||||
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
import static de.steamwar.misslewars.scripts.utils.JsonUtils.getBoolean;
|
||||
|
||||
public class PasteScript implements RunnableScript {
|
||||
|
||||
private static final World world = new BukkitWorld(Bukkit.getWorlds().get(0));
|
||||
|
||||
private final Clipboard clipboard;
|
||||
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(schemFile)).getReader(new FileInputStream(schemFile)).read();
|
||||
} catch (IOException e) {
|
||||
throw new SecurityException("Could not load " + schemFileName, e);
|
||||
}
|
||||
centeredOffset = 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 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(ignoreAir).to(paste).build());
|
||||
editSession.flushSession();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
* /
|
||||
*/
|
||||
|
||||
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.entity.Player;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class RandomPlayerScript implements RunnableScript {
|
||||
|
||||
private Random random = new Random();
|
||||
|
||||
public RandomPlayerScript(JsonObject __) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
|
||||
int size = MissileWars.getBlueTeam().getPlayers().size() + MissileWars.getRedTeam().getPlayers().size();
|
||||
if (size == 0) return true;
|
||||
int index = random.nextInt(size);
|
||||
Player player;
|
||||
if (index >= MissileWars.getBlueTeam().getPlayers().size()) {
|
||||
player = MissileWars.getRedTeam().getPlayers().get(index - MissileWars.getBlueTeam().getPlayers().size());
|
||||
} else {
|
||||
player = MissileWars.getBlueTeam().getPlayers().get(index);
|
||||
}
|
||||
runnableScriptEvent.setLocationType(RunnableScriptEvent.LocationType.CUSTOM);
|
||||
runnableScriptEvent.setCustomLocation(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ(), player.getLocation().getPitch(), player.getLocation().getYaw());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.misslewars.scripts.implemented;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import de.steamwar.misslewars.scripts.RunnableScript;
|
||||
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class RemoveScript implements RunnableScript {
|
||||
|
||||
public RemoveScript(JsonObject jsonObject) {}
|
||||
|
||||
@Override
|
||||
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
|
||||
if (runnableScriptEvent.entity instanceof Player) return true;
|
||||
runnableScriptEvent.entity.remove();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
* /
|
||||
*/
|
||||
|
||||
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 de.steamwar.misslewars.slowmo.SlowMoRunner;
|
||||
|
||||
public class SlowMoScript implements RunnableScript {
|
||||
|
||||
private int slowMoTime = 0;
|
||||
|
||||
public SlowMoScript(JsonObject jsonObject) {
|
||||
JsonPrimitive jsonPrimitive = jsonObject.getAsJsonPrimitive("time");
|
||||
if (jsonPrimitive.isNumber()) slowMoTime = jsonPrimitive.getAsInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
|
||||
SlowMoRunner.addSlowMoTime(slowMoTime);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<Entity> 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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user