SteamWar/MissileWars
Archiviert
13
0

Add Support Item softcoded

Dieser Commit ist enthalten in:
jojo 2020-10-31 17:59:41 +01:00
Ursprung adc1c9242b
Commit e8d3974b81
16 geänderte Dateien mit 145 neuen und 348 gelöschten Zeilen

Datei anzeigen

@ -71,11 +71,7 @@ public class MissileWars extends JavaPlugin {
FightScoreboard.init(); FightScoreboard.init();
Missile.init(); Missile.init();
new Arrows(); Item.init();
new Fireball();
new Shield();
new Mine();
new LandingPad();
StateDependent.setupState(fightState); StateDependent.setupState(fightState);
} }

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 Arrows extends SpecialItem {
private final ItemStack item = createItem(Material.ARROW, "§ePfeil", 3);
@Override
public ItemStack getItem() {
return item;
}
@Override
public boolean handleUse(Player p) {
return false;
}
}

Datei anzeigen

@ -1,40 +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 ExplodingArrows extends SpecialItem {
private final ItemStack item = createItem(Material.SPECTRAL_ARROW, "§eExplodierender Pfeil", 1);
@Override
public ItemStack getItem() {
return item;
}
@Override
public boolean handleUse(Player p) {
return false;
}
}

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

@ -0,0 +1,83 @@
/*
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 Item extends SpecialItem {
private ScriptedItem scriptedItem;
public Item(File item) {
try {
JsonObject jsonObject = new JsonParser().parse(new FileReader(item)).getAsJsonObject();
scriptedItem = new ScriptedItem(jsonObject);
} catch (JsonSyntaxException e) {
throw new SecurityException("Item JSON error");
} catch (IOException e) {
throw new SecurityException("Corrupt Item");
}
}
@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;
new Item(itemFile);
}
}
}

Datei anzeigen

@ -1,79 +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 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 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 {
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;
{
try {
clipboard = Objects.requireNonNull(ClipboardFormats.findByFile(landingPad)).getReader(new FileInputStream(landingPad)).read();
} catch (IOException e) {
throw new SecurityException("Could not load landingPad", e);
}
offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()).add(clipboard.getDimensions().divide(2));
}
@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);
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1);
Operations.completeBlindly(new ClipboardHolder(clipboard).createPaste(editSession).ignoreAirBlocks(true).to(paste).build());
editSession.flushSession();
return true;
}
}

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 Mine extends SpecialItem {
private final ItemStack item = createItem(Material.EGG, "§eMine", 1);
@Override
public ItemStack getItem() {
return item;
}
@Override
public boolean handleUse(Player p) {
return false;
}
}

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,8 +20,12 @@
package de.steamwar.misslewars.items; package de.steamwar.misslewars.items;
import de.steamwar.misslewars.Config; import de.steamwar.misslewars.Config;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; 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.ItemFlag;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
@ -41,12 +45,16 @@ public abstract class SpecialItem {
if (this.isMissile()) { if (this.isMissile()) {
missileItems.add(this); missileItems.add(this);
} else { } else {
materialName = getItem().getType().name().toLowerCase();
supportItems.add(this); supportItems.add(this);
} }
} }
private String materialName = "";
public abstract ItemStack getItem(); public abstract ItemStack getItem();
public abstract boolean handleUse(Player p); public abstract boolean handleUse(Player p);
public void handleThrow(Entity e) {}
public void handleHit(Entity e, Location l) {}
public boolean isMissile() { public boolean isMissile() {
return false; return false;
} }
@ -77,6 +85,31 @@ public abstract class SpecialItem {
return false; return false;
} }
public static void handleThrow(ProjectileLaunchEvent e) {
String name = e.getEntity().getClass().getName().toLowerCase();
for (SpecialItem specialItem : supportItems) {
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(specialItem.materialName)) {
specialItem.handleHit(e.getEntity(), location);
}
}
}
public static ItemStack getRandomItem() { public static ItemStack getRandomItem() {
if (random.nextDouble() > Config.MissileChance) { if (random.nextDouble() > Config.MissileChance) {
return supportItems.get(random.nextInt(supportItems.size())).getItem(); return supportItems.get(random.nextInt(supportItems.size())).getItem();

Datei anzeigen

@ -38,6 +38,7 @@ import org.bukkit.entity.Egg;
import org.bukkit.entity.Snowball; import org.bukkit.entity.Snowball;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -86,10 +87,10 @@ public class ItemListener extends BasicListener {
if (item == null) if (item == null)
return; 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; return;
if(SpecialItem.handleUse(item, e.getPlayer())){ if (SpecialItem.handleUse(item, e.getPlayer())){
item.setAmount(item.getAmount()-1); item.setAmount(item.getAmount()-1);
e.getPlayer().updateInventory(); e.getPlayer().updateInventory();
e.setCancelled(true); e.setCancelled(true);
@ -98,50 +99,12 @@ public class ItemListener extends BasicListener {
@EventHandler @EventHandler
public void onThrow(ProjectileLaunchEvent e) { public void onThrow(ProjectileLaunchEvent e) {
if (e.getEntity() instanceof Snowball) { SpecialItem.handleThrow(e);
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);
}
} }
private boolean validSpawn(Location location) { @EventHandler
int bz = MissileWars.getBlueTeam().getPortalZ(); public void onHit(ProjectileHitEvent e) {
int rz = MissileWars.getRedTeam().getPortalZ(); SpecialItem.handleHit(e);
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;
} }
} }

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.misslewars.scripts; package de.steamwar.misslewars.scripts;
import org.bukkit.Location;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
public interface RunnableScript { public interface RunnableScript {
@ -27,10 +28,12 @@ public interface RunnableScript {
public final ScriptedItem.EventType eventType; public final ScriptedItem.EventType eventType;
public final Entity entity; public final Entity entity;
public final Location location;
public RunnableScriptEvent(ScriptedItem.EventType eventType, Entity entity) { public RunnableScriptEvent(ScriptedItem.EventType eventType, Entity entity, Location location) {
this.eventType = eventType; this.eventType = eventType;
this.entity = entity; this.entity = entity;
this.location = location;
} }
} }

Datei anzeigen

@ -21,15 +21,13 @@ package de.steamwar.misslewars.scripts;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ScriptedItem { public class ScriptedItem {
@ -94,9 +92,14 @@ public class ScriptedItem {
return itemStack; return itemStack;
} }
public void execute(EventType eventType, Entity entity) { public boolean execute(EventType eventType, Entity entity, Location location) {
if (!scriptMap.containsKey(eventType)) return; if (!scriptMap.containsKey(eventType)) return false;
scriptMap.get(eventType).execute(new RunnableScript.RunnableScriptEvent(eventType, entity)); scriptMap.get(eventType).execute(new RunnableScript.RunnableScriptEvent(eventType, entity, location));
return true;
}
public ItemStack getItemStack() {
return itemStack;
} }
} }

Datei anzeigen

@ -39,7 +39,7 @@ public class FilterScript implements RunnableScript {
switch (filter.getAsJsonPrimitive("filter").getAsString().toLowerCase()) { switch (filter.getAsJsonPrimitive("filter").getAsString().toLowerCase()) {
case "nearportal": case "nearportal":
this.filter = runnableScriptEvent -> { this.filter = runnableScriptEvent -> {
Location location = runnableScriptEvent.entity.getLocation(); Location location = runnableScriptEvent.location;
int bz = MissileWars.getBlueTeam().getPortalZ(); int bz = MissileWars.getBlueTeam().getPortalZ();
int rz = MissileWars.getRedTeam().getPortalZ(); int rz = MissileWars.getRedTeam().getPortalZ();

Datei anzeigen

@ -50,7 +50,7 @@ public class LaunchScript implements RunnableScript {
setGlowing(fireball, launch); setGlowing(fireball, launch);
setGravity(fireball, launch); setGravity(fireball, launch);
fireball.setDirection(player.getLocation().getDirection()); fireball.setDirection(runnableScriptEvent.location.getDirection());
}; };
break; break;
case "arrow": case "arrow":

Datei anzeigen

@ -85,7 +85,7 @@ public class PasteScript implements RunnableScript {
@Override @Override
public boolean execute(RunnableScriptEvent runnableScriptEvent) { public boolean execute(RunnableScriptEvent runnableScriptEvent) {
Location location = runnableScriptEvent.entity.getLocation(); Location location = runnableScriptEvent.location;
BlockVector3 paste = BlockVector3.at(location.getX() + xOffset, location.getY() + yOffset, location.getZ() + zOffset); BlockVector3 paste = BlockVector3.at(location.getX() + xOffset, location.getY() + yOffset, location.getZ() + zOffset);
if (centered) { if (centered) {
paste = paste.subtract(centeredOffset); paste = paste.subtract(centeredOffset);

Datei anzeigen

@ -21,7 +21,6 @@ package de.steamwar.misslewars.scripts.implemented;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import de.steamwar.misslewars.scripts.RunnableScript; import de.steamwar.misslewars.scripts.RunnableScript;
import org.bukkit.entity.Entity;
import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.TNTPrimed;
import static de.steamwar.misslewars.scripts.utils.EntityUtils.*; import static de.steamwar.misslewars.scripts.utils.EntityUtils.*;
@ -30,7 +29,7 @@ public class SummonScript implements RunnableScript {
private interface Summon { private interface Summon {
void summon(Entity entity); void summon(RunnableScriptEvent event);
} }
@ -39,8 +38,8 @@ public class SummonScript implements RunnableScript {
public SummonScript(JsonObject summon) { public SummonScript(JsonObject summon) {
switch (summon.getAsJsonPrimitive("entity").getAsString().toLowerCase()) { switch (summon.getAsJsonPrimitive("entity").getAsString().toLowerCase()) {
case "tntprimed": case "tntprimed":
this.summon = entity -> { this.summon = runnableScriptEvent -> {
TNTPrimed tnt = entity.getWorld().spawn(entity.getLocation(), TNTPrimed.class); TNTPrimed tnt = runnableScriptEvent.entity.getWorld().spawn(runnableScriptEvent.location, TNTPrimed.class);
setYield(tnt, summon); setYield(tnt, summon);
setIncendiary(tnt, summon); setIncendiary(tnt, summon);
@ -55,7 +54,7 @@ public class SummonScript implements RunnableScript {
@Override @Override
public boolean execute(RunnableScriptEvent runnableScriptEvent) { public boolean execute(RunnableScriptEvent runnableScriptEvent) {
if (summon == null) return false; if (summon == null) return false;
summon.summon(runnableScriptEvent.entity); summon.summon(runnableScriptEvent);
return true; return true;
} }