SteamWar/MissileWars
Archiviert
13
0

Merge pull request 'Update2.0' (#22) from Update2.0 into master

Reviewed-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
YoyoNow 2020-12-20 13:52:31 +01:00
Commit d754275a1c
33 geänderte Dateien mit 1290 neuen und 272 gelöschten Zeilen

Datei anzeigen

@ -53,5 +53,12 @@
<scope>system</scope>
<systemPath>${main.basedir}/lib/WorldEdit-1.15.jar</systemPath>
</dependency>
<dependency>
<groupId>steamwar</groupId>
<artifactId>SpigotCore</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${main.basedir}/lib/SpigotCore.jar</systemPath>
</dependency>
</dependencies>
</project>

Datei anzeigen

@ -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;
}
}

Datei anzeigen

@ -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<Player> players = new LinkedList<>();
private final LinkedList<Player> players = new LinkedList<>();
private final Set<Player> 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);
}
}

Datei anzeigen

@ -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);

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
* /
*/
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;
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
* /
*/
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 <PLAYER>");
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<String> 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());
}
}

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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++) {

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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;
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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;
}
}

Datei anzeigen

@ -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);

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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;
}
}

Datei anzeigen

@ -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<SpecialItem> 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<SpecialItem> 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();
}
}

Datei anzeigen

@ -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());
}

Datei anzeigen

@ -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);
}
}

Datei anzeigen

@ -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);
}
}

Datei anzeigen

@ -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());
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<Boolean> returnValue, RunnableScriptEvent runnableScriptEvent, double... doubles) {
if (scriptFunction == null) return nullReturn;
return returnValue.apply(scriptFunction.execute(runnableScriptEvent, doubles));
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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();
}
}

Datei anzeigen

@ -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;
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<RunnableScript> 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;
}
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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.<eventName>": Event (OPTIONAL JSONobject.ARRAY)
// - onClick
// - onHit
// - onThrow
public enum EventType {
onHit,
onThrow,
onClick
}
private Map<EventType, Script> 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<String> 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;
}
}

Datei anzeigen

@ -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;
}
}

Datei anzeigen

@ -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);
}
}

Datei anzeigen

@ -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);
}
}

Datei anzeigen

@ -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);
}
}

Datei anzeigen

@ -17,8 +17,10 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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;
}
}

Datei anzeigen

@ -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;
}
}

Datei anzeigen

@ -17,23 +17,22 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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;
}
}

Datei anzeigen

@ -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;
}
}

Datei anzeigen

@ -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);
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<T> {
public Class<T> entityClass;
public TriConsumer<JsonObject, T, RunnableScriptEvent> consumer;
public ScriptShortcut(Class<T> entityClass, TriConsumer<JsonObject, T, RunnableScriptEvent> consumer) {
this.entityClass = entityClass;
this.consumer = consumer;
}
}
public interface TriConsumer<T, R, K> {
void accept(T t, R r, K k);
}
}

Datei anzeigen

@ -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<Boolean> 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<Float> booleanConsumer) {
if (jsonObject.has(key)) booleanConsumer.accept(jsonObject.getAsJsonPrimitive(key).getAsFloat());
}
public static void getString(JsonObject jsonObject, String key, Consumer<String> booleanConsumer) {
if (jsonObject.has(key)) booleanConsumer.accept(jsonObject.getAsJsonPrimitive(key).getAsString());
}
}

Datei anzeigen

@ -11,4 +11,7 @@ depend:
- WorldEdit
- SpigotCore
commands:
spectate:
spectate:
invite:
accept:
decline: