1.0
This commit is contained in:
parent
83e3d5f289
commit
4d184bb239
10
pom.xml
10
pom.xml
|
@ -22,6 +22,10 @@
|
||||||
<id>sonatype</id>
|
<id>sonatype</id>
|
||||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>public-rpg</id>
|
||||||
|
<url>https://repo.aurora-pixels.com/repository/public-rpg/</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -31,6 +35,12 @@
|
||||||
<version>1.20.6-R0.1-SNAPSHOT</version>
|
<version>1.20.6-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.sk89q</groupId>
|
||||||
|
<artifactId>fastasyncworldedit</artifactId>
|
||||||
|
<version>2.11.1</version>
|
||||||
|
<classifier>857</classifier>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -0,0 +1,84 @@
|
||||||
|
package com.yaohun.enderdragonwars.data;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class DirectionPoint extends Point {
|
||||||
|
|
||||||
|
private float yaw;
|
||||||
|
private float pitch;
|
||||||
|
|
||||||
|
public DirectionPoint(int x, int y, int z, float yaw, float pitch) {
|
||||||
|
super(x, y, z);
|
||||||
|
this.yaw = yaw;
|
||||||
|
this.pitch = pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DirectionPoint(double x, double y, double z) {
|
||||||
|
this(x, y, z, 0f, 0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DirectionPoint(double x, double y, double z, float yaw, float pitch) {
|
||||||
|
super(x, y, z);
|
||||||
|
this.yaw = yaw;
|
||||||
|
this.pitch = pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getPitch() {
|
||||||
|
return pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getYaw() {
|
||||||
|
return yaw;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setYaw(float yaw) {
|
||||||
|
this.yaw = yaw;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPitch(float pitch) {
|
||||||
|
this.pitch = pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location toLocation(World world) {
|
||||||
|
return new Location(world, getX(), getY(), getZ(), yaw, pitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DirectionPoint of(Location location) {
|
||||||
|
return new DirectionPoint(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "DirectionPoint{" +
|
||||||
|
"x=" + getX() +
|
||||||
|
", y=" + getY() +
|
||||||
|
", z=" + getZ() +
|
||||||
|
", yaw=" + yaw +
|
||||||
|
", pitch=" + pitch +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
if (!super.equals(o)) return false;
|
||||||
|
DirectionPoint that = (DirectionPoint) o;
|
||||||
|
return super.equals(o) && Float.compare(that.yaw, yaw) == 0 && Float.compare(that.pitch, pitch) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(super.hashCode(), yaw, pitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DirectionPoint deserialize(ConfigurationSection section) {
|
||||||
|
return new DirectionPoint(section.getDouble("x"), section.getDouble("y"), section.getDouble("z"), (float) section.getDouble("yaw"), (float) section.getDouble("pitch"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
101
src/main/java/com/yaohun/enderdragonWars/data/Point.java
Normal file
101
src/main/java/com/yaohun/enderdragonWars/data/Point.java
Normal file
|
@ -0,0 +1,101 @@
|
||||||
|
package com.yaohun.enderdragonwars.data;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class Point {
|
||||||
|
|
||||||
|
private double x;
|
||||||
|
private double y;
|
||||||
|
private double z;
|
||||||
|
|
||||||
|
public Point(int x, int y, int z) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point(double x, double y, double z) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBlockX() {
|
||||||
|
return (int) Math.floor(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBlockY() {
|
||||||
|
return (int) Math.floor(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBlockZ() {
|
||||||
|
return (int) Math.floor(z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getY() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getZ() {
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setX(double x) {
|
||||||
|
this.x = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setY(double y) {
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setZ(double z) {
|
||||||
|
this.z = z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point clone() {
|
||||||
|
return new Point(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location toLocation(World world) {
|
||||||
|
return new Location(world, x, y, z, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Point of(Location location) {
|
||||||
|
return new Point(location.getX(), location.getY(), location.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Point deserialize(ConfigurationSection section) {
|
||||||
|
return new Point(section.getDouble("x"), section.getDouble("y"), section.getDouble("z"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Point{" +
|
||||||
|
"x=" + x +
|
||||||
|
", y=" + y +
|
||||||
|
", z=" + z +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Point point = (Point) o;
|
||||||
|
return Double.compare(point.x, x) == 0 && Double.compare(point.y, y) == 0 && Double.compare(point.z, z) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
51
src/main/java/com/yaohun/enderdragonWars/data/Region.java
Normal file
51
src/main/java/com/yaohun/enderdragonWars/data/Region.java
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
package com.yaohun.enderdragonwars.data;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
|
public class Region {
|
||||||
|
|
||||||
|
private World world;
|
||||||
|
private Point min;
|
||||||
|
private Point max;
|
||||||
|
|
||||||
|
public Region(World world, Point min, Point max) {
|
||||||
|
this.world = world;
|
||||||
|
this.min = min;
|
||||||
|
this.max = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
public World getWorld() {
|
||||||
|
return world;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point getMin() {
|
||||||
|
return min;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point getMax() {
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Region deserialize(ConfigurationSection section) {
|
||||||
|
World world1 = Bukkit.getWorld(section.getString("world"));
|
||||||
|
Point point1 = Point.deserialize(section.getConfigurationSection("min"));
|
||||||
|
Point point2 = Point.deserialize(section.getConfigurationSection("max"));
|
||||||
|
return new Region(world1, point1, point2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInRegion(Location location) {
|
||||||
|
if (!location.getWorld().getName().equalsIgnoreCase(world.getName())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return (location.getBlockX() >= this.min.getX()
|
||||||
|
&& location.getBlockX() <= this.max.getX()
|
||||||
|
&& location.getBlockY() >= this.min.getY()
|
||||||
|
&& location.getBlockY() <= this.max.getY()
|
||||||
|
&& location.getBlockZ() >= this.min.getZ()
|
||||||
|
&& location.getBlockZ() <= this.max.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package com.yaohun.enderdragonwars.effect.types;
|
||||||
|
|
||||||
|
import com.yaohun.enderdragonwars.Main;
|
||||||
|
import com.yaohun.enderdragonwars.effect.GiftEffect;
|
||||||
|
import com.yaohun.enderdragonwars.game.Game;
|
||||||
|
import org.bukkit.Particle;
|
||||||
|
import org.bukkit.attribute.Attribute;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class AddMaxHealthEffect extends GiftEffect {
|
||||||
|
|
||||||
|
public static UUID uuid = UUID.randomUUID();
|
||||||
|
|
||||||
|
public AddMaxHealthEffect(String audience) {
|
||||||
|
super(audience);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(Game game) {
|
||||||
|
Player player = game.getPlayer();
|
||||||
|
new BukkitRunnable() {
|
||||||
|
private int count = 0;
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (count >= 10) {
|
||||||
|
cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
player.spawnParticle(Particle.HEART, player.getLocation().add(0, 0.5, 0), 1, 0.25, 0.25, 0.25, 0.1);
|
||||||
|
if (player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue() < 120) {
|
||||||
|
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue() + 2);
|
||||||
|
player.setHealth(Math.min(player.getHealth() + 2, player.getMaxHealth()));
|
||||||
|
}
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}.runTaskTimer(Main.plugin, 0L, 1L);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getQueueTime() {
|
||||||
|
return 55;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,169 @@
|
||||||
|
package com.yaohun.enderdragonwars.effect.types;
|
||||||
|
|
||||||
|
import com.yaohun.enderdragonwars.Main;
|
||||||
|
import com.yaohun.enderdragonwars.effect.GiftEffect;
|
||||||
|
import com.yaohun.enderdragonwars.game.Game;
|
||||||
|
import com.yaohun.enderdragonwars.util.RandomUtil;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Particle;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.FallingBlock;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class BlackHoleEffect extends GiftEffect {
|
||||||
|
|
||||||
|
private static int seconds = 15;
|
||||||
|
private boolean stop = false;
|
||||||
|
|
||||||
|
public BlackHoleEffect(String audience) {
|
||||||
|
super(audience);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(Game game) {
|
||||||
|
List<FallingBlock> fallingBlocks = new ArrayList<>();
|
||||||
|
Location location = game.getPlayer().getLocation().add(0, 2, 0);
|
||||||
|
new BukkitRunnable() {
|
||||||
|
private int i = 0;
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (i >= seconds*2) {
|
||||||
|
stop = true;
|
||||||
|
fallingBlocks.forEach(fallingBlock -> fallingBlock.setGravity(true));
|
||||||
|
location.getWorld().createExplosion(location, 3.0F, false, false);
|
||||||
|
cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Set<Block> blocks = getRandomUpBlocks(location, 6, 10);
|
||||||
|
for (Block block : blocks) {
|
||||||
|
FallingBlock fallingBlock = location.getWorld().spawnFallingBlock(block.getLocation().add(0.5, 0, 0.5), block.getBlockData());
|
||||||
|
fallingBlock.setDropItem(false);
|
||||||
|
fallingBlock.setHurtEntities(false);
|
||||||
|
fallingBlock.setGravity(false);
|
||||||
|
block.setType(Material.AIR);
|
||||||
|
fallingBlocks.add(fallingBlock);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}.runTaskTimer(Main.plugin, 0L, 10L);
|
||||||
|
new BukkitRunnable() {
|
||||||
|
private Set<UUID> uuids = new HashSet<>();
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (stop) {
|
||||||
|
cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
double r = 16;
|
||||||
|
for (Entity entity : location.getWorld().getNearbyEntities(location, r, r, r)) {
|
||||||
|
if (entity instanceof FallingBlock) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Location location1 = entity.getLocation();
|
||||||
|
Vector vector = location.toVector().subtract(location1.toVector());
|
||||||
|
vector.normalize();
|
||||||
|
vector.multiply(0.25);
|
||||||
|
entity.setVelocity(vector);
|
||||||
|
if (entity instanceof LivingEntity livingEntity) {
|
||||||
|
livingEntity.damage(1);
|
||||||
|
}
|
||||||
|
if (entity instanceof Player player) {
|
||||||
|
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20 * 3, 0, true, true, true));
|
||||||
|
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOWNESS, 20 * 3, 0, true, true, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Iterator<FallingBlock> iterator = fallingBlocks.iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
FallingBlock fallingBlock = iterator.next();
|
||||||
|
org.bukkit.util.Vector vector = fallingBlock.getLocation().toVector();
|
||||||
|
org.bukkit.util.Vector vector1 = location.toVector();
|
||||||
|
Vector vector2 = vector1.subtract(vector);
|
||||||
|
vector2.normalize();
|
||||||
|
vector2.multiply(0.65);
|
||||||
|
fallingBlock.setVelocity(vector2);
|
||||||
|
if (!uuids.contains(fallingBlock.getUniqueId())) {
|
||||||
|
if (RandomUtil.random(0.5)) {
|
||||||
|
uuids.add(fallingBlock.getUniqueId());
|
||||||
|
} else {
|
||||||
|
fallingBlock.remove();
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskTimer(Main.plugin, 0L, 5L);
|
||||||
|
new BukkitRunnable() {
|
||||||
|
private Set<UUID> uuids = new HashSet<>();
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (stop) {
|
||||||
|
cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
location.getWorld().spawnParticle(Particle.CLOUD, location, 10, 1.5, 1.5, 1.5, 0.01);
|
||||||
|
location.getWorld().spawnParticle(Particle.INFESTED, location, 10, 1.5, 1.5, 1.5, 0.01);
|
||||||
|
location.getWorld().spawnParticle(Particle.LARGE_SMOKE, location, 10, 1.5, 1.5, 1.5, 0.01);
|
||||||
|
location.getWorld().spawnParticle(Particle.SQUID_INK, location, 10, 1.5, 1.5, 1.5, 0.01);
|
||||||
|
Iterator<FallingBlock> iterator = fallingBlocks.iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
FallingBlock fallingBlock = iterator.next();
|
||||||
|
org.bukkit.util.Vector vector = fallingBlock.getLocation().toVector();
|
||||||
|
org.bukkit.util.Vector vector1 = location.toVector();
|
||||||
|
Vector vector2 = vector1.subtract(vector);
|
||||||
|
vector2.normalize();
|
||||||
|
vector2.multiply(0.65);
|
||||||
|
fallingBlock.setVelocity(vector2);
|
||||||
|
if (!uuids.contains(fallingBlock.getUniqueId())) {
|
||||||
|
if (RandomUtil.random(0.5)) {
|
||||||
|
uuids.add(fallingBlock.getUniqueId());
|
||||||
|
} else {
|
||||||
|
fallingBlock.remove();
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskTimer(Main.plugin, 0L, 1L);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Set<Block> getRandomUpBlocks(Location location, int size, int amount) {
|
||||||
|
List<Block> blocks = new ArrayList<>();
|
||||||
|
int minX = location.getBlockX() - size;
|
||||||
|
int minY = location.getBlockY() - size * 2;
|
||||||
|
int minZ = location.getBlockZ() - size;
|
||||||
|
int maxX = location.getBlockX() + size;
|
||||||
|
int maxY = location.getBlockY() + size;
|
||||||
|
int maxZ = location.getBlockZ() + size;
|
||||||
|
for (int x = minX; x <= maxX; x++) {
|
||||||
|
for (int z = minZ; z <= maxZ; z++) {
|
||||||
|
for (int y = maxY; y >= minY; y--) {
|
||||||
|
Block block = location.getWorld().getBlockAt(x, y, z);
|
||||||
|
if (!block.getType().equals(Material.AIR)) {
|
||||||
|
blocks.add(block);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Set<Block> blocks1 = new HashSet<>();
|
||||||
|
if (blocks.isEmpty()) {
|
||||||
|
return blocks1;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < amount; i++) {
|
||||||
|
int k = RandomUtil.getRandomInt(0, blocks.size() - 1);
|
||||||
|
Block block = blocks.remove(k);
|
||||||
|
blocks1.add(block);
|
||||||
|
}
|
||||||
|
return blocks1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,23 +1,24 @@
|
||||||
package com.yaohun.enderdragonwars.effectevent;
|
package com.yaohun.enderdragonwars.effect.types;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
import com.yaohun.enderdragonwars.Main;
|
import com.yaohun.enderdragonwars.Main;
|
||||||
import com.yaohun.enderdragonwars.effect.GiftEffect;
|
import com.yaohun.enderdragonwars.effect.GiftEffect;
|
||||||
import com.yaohun.enderdragonwars.game.Game;
|
import com.yaohun.enderdragonwars.game.Game;
|
||||||
import com.yaohun.enderdragonwars.util.EntityUtil;
|
import com.yaohun.enderdragonwars.util.EntityUtil;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
|
import org.bukkit.attribute.Attribute;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.ArmorStand;
|
import org.bukkit.boss.BarColor;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.boss.BarStyle;
|
||||||
import org.bukkit.entity.FallingBlock;
|
import org.bukkit.boss.BossBar;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.*;
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ColorableArmorMeta;
|
import org.bukkit.inventory.meta.ColorableArmorMeta;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -36,6 +37,7 @@ public class BomBomEffect extends GiftEffect {
|
||||||
private static final ItemStack ITEM_7;
|
private static final ItemStack ITEM_7;
|
||||||
|
|
||||||
private List<FallingBlock> fallingBlocks = new ArrayList<>();
|
private List<FallingBlock> fallingBlocks = new ArrayList<>();
|
||||||
|
private BossBar bossBar;
|
||||||
|
|
||||||
protected boolean stop = false;
|
protected boolean stop = false;
|
||||||
|
|
||||||
|
@ -45,8 +47,10 @@ public class BomBomEffect extends GiftEffect {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(Game game) {
|
public void apply(Game game) {
|
||||||
|
bossBar = Bukkit.createBossBar("§4§l毁天灭地", BarColor.RED, BarStyle.SOLID);
|
||||||
World world = game.getWorld();
|
World world = game.getWorld();
|
||||||
Player player = game.getPlayer();
|
Player player = game.getPlayer();
|
||||||
|
bossBar.addPlayer(player);
|
||||||
ArmorStand armorStand = (ArmorStand) world.spawnEntity(player.getLocation(), EntityType.ARMOR_STAND, CreatureSpawnEvent.SpawnReason.CUSTOM, (entity)->{
|
ArmorStand armorStand = (ArmorStand) world.spawnEntity(player.getLocation(), EntityType.ARMOR_STAND, CreatureSpawnEvent.SpawnReason.CUSTOM, (entity)->{
|
||||||
ArmorStand armorStand1 = (ArmorStand) entity;
|
ArmorStand armorStand1 = (ArmorStand) entity;
|
||||||
armorStand1.setArms(true);
|
armorStand1.setArms(true);
|
||||||
|
@ -62,23 +66,38 @@ public class BomBomEffect extends GiftEffect {
|
||||||
armorStand1.getEquipment().setItem(EquipmentSlot.CHEST, ITEM_2);
|
armorStand1.getEquipment().setItem(EquipmentSlot.CHEST, ITEM_2);
|
||||||
armorStand1.getEquipment().setItem(EquipmentSlot.LEGS, ITEM_3);
|
armorStand1.getEquipment().setItem(EquipmentSlot.LEGS, ITEM_3);
|
||||||
armorStand1.getEquipment().setItem(EquipmentSlot.FEET, ITEM_4);
|
armorStand1.getEquipment().setItem(EquipmentSlot.FEET, ITEM_4);
|
||||||
|
armorStand1.getAttribute(Attribute.GENERIC_SCALE).setBaseValue(6.0);
|
||||||
});
|
});
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
private int count = 0;
|
private int count = 0;
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (count >= 10) {
|
Location loc = armorStand.getLocation().clone().add(0, 8, 0);
|
||||||
|
if (count > 30) {
|
||||||
armorStand.remove();
|
armorStand.remove();
|
||||||
for (int i =0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
armorStand.getWorld().createExplosion(armorStand.getLocation(), 5f, true, true);
|
armorStand.getWorld().createExplosion(armorStand.getLocation(), 5f, true, true);
|
||||||
}
|
}
|
||||||
|
Random random = new Random();
|
||||||
|
for (int i = 0; i < 500; i++) {
|
||||||
|
FallingBlock fallingBlock = (FallingBlock) world.spawnEntity(loc, EntityType.FALLING_BLOCK, CreatureSpawnEvent.SpawnReason.CUSTOM, (fallingBlockEntity)->{
|
||||||
|
FallingBlock fallingBlock1 = (FallingBlock) fallingBlockEntity;
|
||||||
|
fallingBlock1.setBlockData(Bukkit.createBlockData(Material.MAGMA_BLOCK));
|
||||||
|
fallingBlock1.setDropItem(false);
|
||||||
|
fallingBlock1.setCancelDrop(true);
|
||||||
|
});
|
||||||
|
fallingBlocks.add(fallingBlock);
|
||||||
|
EntityUtil.shoot(fallingBlock, (Math.random() * 1.8D - 1.5D) * 0.1f, 0.2f + Math.random() * 0.1f, (Math.random() * 1.8D - 1.5D) * 0.1f, 3f + random.nextFloat() * 1.5f, 0f);
|
||||||
|
player.getWorld().playSound(fallingBlock.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1f, 1f);
|
||||||
|
}
|
||||||
|
bossBar.removeAll();
|
||||||
stop = true;
|
stop = true;
|
||||||
cancel();
|
cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
for (int i = 0; i < 30; i++) {
|
for (int i = 0; i < 35; i++) {
|
||||||
FallingBlock fallingBlock = (FallingBlock) world.spawnEntity(armorStand.getLocation(), EntityType.FALLING_BLOCK, CreatureSpawnEvent.SpawnReason.CUSTOM, (fallingBlockEntity)->{
|
FallingBlock fallingBlock = (FallingBlock) world.spawnEntity(loc, EntityType.FALLING_BLOCK, CreatureSpawnEvent.SpawnReason.CUSTOM, (fallingBlockEntity)->{
|
||||||
FallingBlock fallingBlock1 = (FallingBlock) fallingBlockEntity;
|
FallingBlock fallingBlock1 = (FallingBlock) fallingBlockEntity;
|
||||||
fallingBlock1.setBlockData(Bukkit.createBlockData(Material.MAGMA_BLOCK));
|
fallingBlock1.setBlockData(Bukkit.createBlockData(Material.MAGMA_BLOCK));
|
||||||
fallingBlock1.setDropItem(false);
|
fallingBlock1.setDropItem(false);
|
||||||
|
@ -89,6 +108,14 @@ public class BomBomEffect extends GiftEffect {
|
||||||
EntityUtil.shoot(fallingBlock, (Math.random() * 2.5D - 1.5D) * 0.1f, 0.4f + Math.random() * 0.15f, (Math.random() * 2.5D - 1.5D) * 0.1f, 3f + random.nextFloat() * 1.5f, 0f);
|
EntityUtil.shoot(fallingBlock, (Math.random() * 2.5D - 1.5D) * 0.1f, 0.4f + Math.random() * 0.15f, (Math.random() * 2.5D - 1.5D) * 0.1f, 3f + random.nextFloat() * 1.5f, 0f);
|
||||||
player.getWorld().playSound(fallingBlock.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1f, 1f);
|
player.getWorld().playSound(fallingBlock.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1f, 1f);
|
||||||
}
|
}
|
||||||
|
for (int i = 0; i < 15; i++) {
|
||||||
|
TNTPrimed tntPrimed = (TNTPrimed) world.spawnEntity(loc, EntityType.TNT, CreatureSpawnEvent.SpawnReason.CUSTOM, (tntEntity)->{
|
||||||
|
TNTPrimed tntPrimed1 = (TNTPrimed) tntEntity;
|
||||||
|
tntPrimed1.setFuseTicks(80);
|
||||||
|
tntPrimed1.setYield(4);
|
||||||
|
});
|
||||||
|
EntityUtil.shoot(tntPrimed, (Math.random() * 2D - 1.5D) * 0.08f, 0.1f + Math.random() * 0.025f, (Math.random() * 2D - 1.5D) * 0.08f, 3f + random.nextFloat() * 1.5f, 0f);
|
||||||
|
}
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}.runTaskTimer(Main.plugin, 0L, 15L);
|
}.runTaskTimer(Main.plugin, 0L, 15L);
|
||||||
|
@ -105,6 +132,7 @@ public class BomBomEffect extends GiftEffect {
|
||||||
armorStand.getEquipment().setItem(EquipmentSlot.CHEST, flag ? ITEM_2 : ITEM_5);
|
armorStand.getEquipment().setItem(EquipmentSlot.CHEST, flag ? ITEM_2 : ITEM_5);
|
||||||
armorStand.getEquipment().setItem(EquipmentSlot.LEGS, flag ? ITEM_3 : ITEM_6);
|
armorStand.getEquipment().setItem(EquipmentSlot.LEGS, flag ? ITEM_3 : ITEM_6);
|
||||||
armorStand.getEquipment().setItem(EquipmentSlot.FEET, flag ? ITEM_4 : ITEM_7);
|
armorStand.getEquipment().setItem(EquipmentSlot.FEET, flag ? ITEM_4 : ITEM_7);
|
||||||
|
bossBar.setTitle(flag? "§4§l毁天灭地" : "§c§l毁天灭地");
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}.runTaskTimer(Main.plugin, 0L, 5L);
|
}.runTaskTimer(Main.plugin, 0L, 5L);
|
||||||
|
@ -125,7 +153,6 @@ public class BomBomEffect extends GiftEffect {
|
||||||
}
|
}
|
||||||
}.runTaskTimer(Main.plugin, 0L, 2L);
|
}.runTaskTimer(Main.plugin, 0L, 2L);
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
private int count = 0;
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (fallingBlocks.isEmpty()) {
|
if (fallingBlocks.isEmpty()) {
|
||||||
|
@ -135,18 +162,19 @@ public class BomBomEffect extends GiftEffect {
|
||||||
Iterator<FallingBlock> iterator = fallingBlocks.iterator();
|
Iterator<FallingBlock> iterator = fallingBlocks.iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
FallingBlock fallingBlock = iterator.next();
|
FallingBlock fallingBlock = iterator.next();
|
||||||
Location location = fallingBlock.getLocation().add(0, -2, 0);
|
Location location = fallingBlock.getLocation();
|
||||||
Block block = location.getBlock();
|
if (fallingBlock.isOnGround() || fallingBlock.isDead()) {
|
||||||
if (block.getType() != Material.AIR) {
|
|
||||||
location.getWorld().createExplosion(location, 5f, true, true);
|
location.getWorld().createExplosion(location, 5f, true, true);
|
||||||
|
armorStand.getWorld().spawnParticle(Particle.LAVA, fallingBlock.getLocation(), 35, 1.5, 1.5, 1.5, 0.05);
|
||||||
|
armorStand.getWorld().spawnParticle(Particle.FLAME, fallingBlock.getLocation(), 35, 1.5, 1.5, 1.5, 0.01);
|
||||||
location.add(0, 1, 0).getBlock().setType(Material.LAVA);
|
location.add(0, 1, 0).getBlock().setType(Material.LAVA);
|
||||||
fallingBlock.remove();
|
fallingBlock.remove();
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
count++;
|
|
||||||
}
|
}
|
||||||
}.runTaskTimer(Main.plugin, 0L, 2L);
|
}.runTaskTimer(Main.plugin, 0L, 1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
|
@ -0,0 +1,91 @@
|
||||||
|
package com.yaohun.enderdragonwars.effect.types;
|
||||||
|
|
||||||
|
import com.yaohun.enderdragonwars.Main;
|
||||||
|
import com.yaohun.enderdragonwars.effect.GiftEffect;
|
||||||
|
import com.yaohun.enderdragonwars.game.Game;
|
||||||
|
import com.yaohun.enderdragonwars.util.RandomUtil;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Particle;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Allay;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ClearInventoryEffect extends GiftEffect {
|
||||||
|
|
||||||
|
public ClearInventoryEffect(String audience) {
|
||||||
|
super(audience);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(Game game) {
|
||||||
|
World world = game.getWorld();
|
||||||
|
Player player = game.getPlayer();
|
||||||
|
List<Allay> allays = new ArrayList<>();
|
||||||
|
new BukkitRunnable() {
|
||||||
|
private int totalCount = Math.max(15, getUseableItemCount(player).size());
|
||||||
|
private int count = 0;
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (count > totalCount) {
|
||||||
|
for (Allay allay : allays) {
|
||||||
|
allay.getWorld().spawnParticle(Particle.WAX_OFF, allay.getLocation(), 30, 0.5, 0.5, 0.5, 0.1);
|
||||||
|
allay.remove();
|
||||||
|
}
|
||||||
|
player.getInventory().clear();
|
||||||
|
cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Allay allay = (Allay) world.spawnEntity(player.getLocation().add(0, 1, 0), EntityType.ALLAY, CreatureSpawnEvent.SpawnReason.CUSTOM, (entity)->{
|
||||||
|
Allay allay1 = (Allay) entity;
|
||||||
|
Vector vector = player.getEyeLocation().getDirection();
|
||||||
|
vector.normalize();
|
||||||
|
vector.multiply(0.5);
|
||||||
|
allay1.setVelocity(vector);
|
||||||
|
allay1.setGlowing(true);
|
||||||
|
allay1.setCollidable(false);
|
||||||
|
allay1.setInvulnerable(true);
|
||||||
|
ItemStack item = takeRandomItem(player);
|
||||||
|
if (item == null) {
|
||||||
|
item = new ItemStack(Material.DIAMOND);
|
||||||
|
}
|
||||||
|
allay1.getEquipment().setItemInMainHand(item);
|
||||||
|
});
|
||||||
|
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_PICKUP, 1, 1);
|
||||||
|
allays.add(allay);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}.runTaskTimer(Main.plugin, 10L, 4L);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Integer> getUseableItemCount(Player player) {
|
||||||
|
List<Integer> useableSlots = new ArrayList<>();
|
||||||
|
for (int i = 0; i < 36; i++) {
|
||||||
|
ItemStack item = player.getInventory().getItem(i);
|
||||||
|
if (item != null && item.getType() != Material.AIR) {
|
||||||
|
useableSlots.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return useableSlots;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack takeRandomItem(Player player) {
|
||||||
|
List<Integer> useableSlots = getUseableItemCount(player);
|
||||||
|
if (useableSlots.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
int i = RandomUtil.getRandomInt(0, useableSlots.size() - 1);
|
||||||
|
ItemStack item = player.getInventory().getItem(useableSlots.get(i));
|
||||||
|
player.getInventory().setItem(useableSlots.get(i), null);
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.yaohun.enderdragonwars.effect.types;
|
||||||
|
|
||||||
|
import com.yaohun.enderdragonwars.Main;
|
||||||
|
import com.yaohun.enderdragonwars.effect.GiftEffect;
|
||||||
|
import com.yaohun.enderdragonwars.game.Game;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
public class FiveLightningEffect extends GiftEffect {
|
||||||
|
|
||||||
|
public FiveLightningEffect(String audience) {
|
||||||
|
super(audience);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(Game game) {
|
||||||
|
Player player = game.getPlayer();
|
||||||
|
new BukkitRunnable() {
|
||||||
|
private int count = 0;
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (count > 5) {
|
||||||
|
cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
player.getWorld().strikeLightning(player.getLocation());
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}.runTaskTimer(Main.plugin, 0, 10L);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.yaohun.enderdragonwars.effect.types;
|
||||||
|
|
||||||
|
import com.yaohun.enderdragonwars.effect.GiftEffect;
|
||||||
|
import com.yaohun.enderdragonwars.game.Game;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class GiveTotemEffect extends GiftEffect {
|
||||||
|
|
||||||
|
public GiveTotemEffect(String audience) {
|
||||||
|
super(audience);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(Game game) {
|
||||||
|
Player player = game.getPlayer();
|
||||||
|
player.getInventory().addItem(new ItemStack(Material.TOTEM_OF_UNDYING));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
package com.yaohun.enderdragonwars.effect.types;
|
||||||
|
|
||||||
|
import com.yaohun.enderdragonwars.effect.GiftEffect;
|
||||||
|
import com.yaohun.enderdragonwars.game.Game;
|
||||||
|
import com.yaohun.enderdragonwars.util.RandomUtil;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Blaze;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.MagmaCube;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
|
public class LavaPoolEffect extends GiftEffect {
|
||||||
|
|
||||||
|
public LavaPoolEffect(String audience) {
|
||||||
|
super(audience);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(Game game) {
|
||||||
|
Player player = game.getPlayer();
|
||||||
|
Location location = player.getLocation();
|
||||||
|
|
||||||
|
int size = 20;
|
||||||
|
|
||||||
|
int minX = location.getBlockX() - size / 2;
|
||||||
|
int minY = location.getBlockY() - 3;
|
||||||
|
int minZ = location.getBlockZ() - size / 2;
|
||||||
|
int maxX = location.getBlockX() + size / 2;
|
||||||
|
int maxY = location.getBlockY();
|
||||||
|
int maxZ = location.getBlockZ() + size / 2;
|
||||||
|
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
Location location1 = getRandomLocation(location.add(0, 3, 0), size - 3, 3, size - 3);
|
||||||
|
Blaze blaze = (Blaze) location1.getWorld().spawnEntity(location1, EntityType.BLAZE);
|
||||||
|
blaze.setTarget(player);
|
||||||
|
blaze.customName(Component.text("§4§l烈焰人"));
|
||||||
|
blaze.setCustomNameVisible(true);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
Location location1 = getRandomLocation(location, size - 3, 0, size - 3);
|
||||||
|
MagmaCube magmaCube = (MagmaCube) location1.getWorld().spawnEntity(location1, EntityType.MAGMA_CUBE);
|
||||||
|
magmaCube.setTarget(player);
|
||||||
|
magmaCube.customName(Component.text("§4§l岩浆怪"));
|
||||||
|
magmaCube.setCustomNameVisible(true);
|
||||||
|
}
|
||||||
|
player.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 20 * 60, 1, true, true, true));
|
||||||
|
|
||||||
|
for (int x = minX; x <= maxX; x++) {
|
||||||
|
for (int y = minY; y <= maxY; y++) {
|
||||||
|
for (int z = minZ; z <= maxZ; z++) {
|
||||||
|
Block block = location.getWorld().getBlockAt(x, y, z);
|
||||||
|
block.setType(Material.LAVA);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private Location getRandomLocation(Location location, double xRange, double yRange, double zRange) {
|
||||||
|
return new Location(location.getWorld(),
|
||||||
|
RandomUtil.getRandomDouble(location.getX() - xRange, location.getX() + xRange, 1),
|
||||||
|
RandomUtil.getRandomDouble(location.getY() - yRange, location.getY() + yRange, 1),
|
||||||
|
RandomUtil.getRandomDouble(location.getZ() - zRange, location.getZ() + zRange, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
package com.yaohun.enderdragonwars.effect.types;
|
||||||
|
|
||||||
|
import com.yaohun.enderdragonwars.effect.GiftEffect;
|
||||||
|
import com.yaohun.enderdragonwars.game.Game;
|
||||||
|
import com.yaohun.enderdragonwars.util.ItemStackBuilder;
|
||||||
|
import com.yaohun.enderdragonwars.util.RandomUtil;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Particle;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.entity.Item;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class LuckyBlockEffect extends GiftEffect {
|
||||||
|
|
||||||
|
private static List<ItemStack> itemStacks = new ArrayList<>();
|
||||||
|
|
||||||
|
public LuckyBlockEffect(String audience) {
|
||||||
|
super(audience);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(Game game) {
|
||||||
|
game.getPlayer().getInventory().addItem(new ItemStackBuilder(Material.SPONGE).setDisplayName("§6§l幸运方块").build());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void openLuckyBlock(Player player, Block block) {
|
||||||
|
Location location = block.getLocation().add(0.5, 0.5, 0.5);
|
||||||
|
location.getWorld().spawnParticle(Particle.FIREWORK, location, 35, 0.55, 0.55, 0.55, 0.05);
|
||||||
|
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1);
|
||||||
|
ItemStack itemStack = itemStacks.get(RandomUtil.getRandomInt(0, itemStacks.size() - 1));
|
||||||
|
Item item = location.getWorld().dropItemNaturally(location, itemStack);
|
||||||
|
item.setOwner(player.getUniqueId());
|
||||||
|
if (itemStack.getItemMeta().hasDisplayName()) {
|
||||||
|
item.customName(itemStack.getItemMeta().displayName());
|
||||||
|
item.setCustomNameVisible(true);
|
||||||
|
}
|
||||||
|
item.setGlowing(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
itemStacks.add(new ItemStackBuilder(Material.IRON_SWORD).addEnchant(Enchantment.SHARPNESS, 3).build());
|
||||||
|
itemStacks.add(new ItemStackBuilder(Material.IRON_SWORD).addEnchant(Enchantment.SHARPNESS, 3).setDisplayName("§6§l幸运铁剑").build());
|
||||||
|
itemStacks.add(new ItemStackBuilder(Material.GOLDEN_SWORD).addEnchant(Enchantment.SHARPNESS, 5).addEnchant(Enchantment.FIRE_ASPECT, 2).setDisplayName("§6§l幸运金剑").build());
|
||||||
|
itemStacks.add(new ItemStackBuilder(Material.DIAMOND_CHESTPLATE).addEnchant(Enchantment.PROTECTION, 3).setDisplayName("§6§l幸运钻石胸甲").build());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.yaohun.enderdragonwars.effect.types;
|
||||||
|
|
||||||
|
import com.yaohun.enderdragonwars.effect.GiftEffect;
|
||||||
|
import com.yaohun.enderdragonwars.game.Game;
|
||||||
|
import org.bukkit.attribute.Attribute;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class PlayerBigEffect extends GiftEffect {
|
||||||
|
|
||||||
|
public PlayerBigEffect(String audience) {
|
||||||
|
super(audience);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(Game game) {
|
||||||
|
Player player = game.getPlayer();
|
||||||
|
if (player.getAttribute(Attribute.GENERIC_SCALE).getBaseValue() >= 20) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
player.getAttribute(Attribute.GENERIC_SCALE).setBaseValue(player.getAttribute(Attribute.GENERIC_SCALE).getBaseValue() + 0.5);
|
||||||
|
player.getAttribute(Attribute.PLAYER_BLOCK_INTERACTION_RANGE).setBaseValue(player.getAttribute(Attribute.PLAYER_BLOCK_INTERACTION_RANGE).getBaseValue() + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.yaohun.enderdragonwars.effect.types;
|
||||||
|
|
||||||
|
import com.yaohun.enderdragonwars.effect.GiftEffect;
|
||||||
|
import com.yaohun.enderdragonwars.game.Game;
|
||||||
|
import org.bukkit.attribute.Attribute;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class PlayerResetEffect extends GiftEffect {
|
||||||
|
|
||||||
|
public PlayerResetEffect(String audience) {
|
||||||
|
super(audience);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(Game game) {
|
||||||
|
Player player = game.getPlayer();
|
||||||
|
player.getAttribute(Attribute.GENERIC_SCALE).setBaseValue(1);
|
||||||
|
player.getAttribute(Attribute.PLAYER_BLOCK_INTERACTION_RANGE).setBaseValue(4.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.yaohun.enderdragonwars.effect.types;
|
||||||
|
|
||||||
|
import com.yaohun.enderdragonwars.effect.GiftEffect;
|
||||||
|
import com.yaohun.enderdragonwars.game.Game;
|
||||||
|
import org.bukkit.attribute.Attribute;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class PlayerSmallEffect extends GiftEffect {
|
||||||
|
|
||||||
|
public PlayerSmallEffect(String audience) {
|
||||||
|
super(audience);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(Game game) {
|
||||||
|
Player player = game.getPlayer();
|
||||||
|
if (player.getAttribute(Attribute.GENERIC_SCALE).getBaseValue() <= 0.1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
player.getAttribute(Attribute.GENERIC_SCALE).setBaseValue(player.getAttribute(Attribute.GENERIC_SCALE).getBaseValue() - 0.5);
|
||||||
|
player.getAttribute(Attribute.PLAYER_BLOCK_INTERACTION_RANGE).setBaseValue(player.getAttribute(Attribute.PLAYER_BLOCK_INTERACTION_RANGE).getBaseValue() - 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.yaohun.enderdragonwars.effect.types;
|
||||||
|
|
||||||
|
import com.yaohun.enderdragonwars.effect.GiftEffect;
|
||||||
|
import com.yaohun.enderdragonwars.game.Game;
|
||||||
|
import com.yaohun.enderdragonwars.util.WEUtil;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class SpawnBuildEffect extends GiftEffect {
|
||||||
|
|
||||||
|
public SpawnBuildEffect(String audience) {
|
||||||
|
super(audience);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(Game game) {
|
||||||
|
Player player = game.getPlayer();
|
||||||
|
WEUtil.loadSchematics(player.getLocation(), "anquanwu");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package com.yaohun.enderdragonwars.effect.types;
|
||||||
|
|
||||||
|
import com.yaohun.enderdragonwars.data.Region;
|
||||||
|
import com.yaohun.enderdragonwars.effect.GiftEffect;
|
||||||
|
import com.yaohun.enderdragonwars.game.Game;
|
||||||
|
import com.yaohun.enderdragonwars.util.BuildSpawner;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SpawnEnderPortalEffect extends GiftEffect {
|
||||||
|
|
||||||
|
private static final List<Material> MATERIAL_LIST = Arrays.asList(Material.WHITE_WOOL, Material.BLACK_WOOL, Material.BROWN_WOOL, Material.BLUE_WOOL, Material.GREEN_WOOL, Material.RED_WOOL, Material.YELLOW_WOOL, Material.PURPLE_WOOL, Material.ORANGE_WOOL, Material.PINK_WOOL, Material.LIGHT_BLUE_WOOL, Material.LIME_WOOL);
|
||||||
|
|
||||||
|
|
||||||
|
public SpawnEnderPortalEffect(String audience) {
|
||||||
|
super(audience);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(Game game) {
|
||||||
|
int chunkWight = 2;
|
||||||
|
int chunkLength = 2;
|
||||||
|
int ladderLength = 3;
|
||||||
|
int ladderAmount = 5;
|
||||||
|
int platformWidth = 3;
|
||||||
|
int platformLength = 7;
|
||||||
|
int levelAmount = 15;
|
||||||
|
World world = game.getWorld();
|
||||||
|
Player player = game.getPlayer();
|
||||||
|
Location location = player.getLocation();
|
||||||
|
BuildSpawner buildSpawner = new BuildSpawner(world, BuildSpawner.Direction.NORTH, location.getBlockX(), location.getBlockY() - 1, location.getBlockZ(), chunkWight, chunkLength, ladderLength, ladderAmount, platformWidth, platformLength, levelAmount, BuildSpawner.SpawnMode.MODE_2, MATERIAL_LIST);
|
||||||
|
Region region = buildSpawner.getEffectiveRegion(world);
|
||||||
|
for (int x = region.getMin().getBlockX(); x <= region.getMax().getBlockX(); x++) {
|
||||||
|
for (int y = region.getMin().getBlockY(); y <= region.getMax().getBlockY(); y++) {
|
||||||
|
for (int z = region.getMin().getBlockZ(); z <= region.getMax().getBlockZ(); z++) {
|
||||||
|
if (world.getBlockAt(x, y, z).getType() != Material.AIR) {
|
||||||
|
world.getBlockAt(x, y, z).setType(Material.AIR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buildSpawner.spawn();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.yaohun.enderdragonwars.effect.types;
|
||||||
|
|
||||||
|
import com.yaohun.enderdragonwars.effect.GiftEffect;
|
||||||
|
import com.yaohun.enderdragonwars.game.Game;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class SummonIronGolem extends GiftEffect {
|
||||||
|
|
||||||
|
public SummonIronGolem(String audience) {
|
||||||
|
super(audience);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(Game game) {
|
||||||
|
Player player = game.getPlayer();
|
||||||
|
player.getWorld().spawnEntity(player.getLocation(), EntityType.IRON_GOLEM);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.yaohun.enderdragonwars.effect.types;
|
||||||
|
|
||||||
|
import com.yaohun.enderdragonwars.effect.GiftEffect;
|
||||||
|
import com.yaohun.enderdragonwars.game.Game;
|
||||||
|
import org.bukkit.Particle;
|
||||||
|
import org.bukkit.attribute.Attribute;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class TakeMaxHealthEffect extends GiftEffect {
|
||||||
|
|
||||||
|
public TakeMaxHealthEffect(String audience) {
|
||||||
|
super(audience);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(Game game) {
|
||||||
|
Player player = game.getPlayer();
|
||||||
|
player.spawnParticle(Particle.SMOKE, player.getLocation().add(0, 1, 0), 30, 0.25, 0.25, 0.25, 0.05);
|
||||||
|
if (player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue() <= 20) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue() - 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
package com.yaohun.enderdragonwars.effect.types;
|
||||||
|
|
||||||
|
import com.yaohun.enderdragonwars.Main;
|
||||||
|
import com.yaohun.enderdragonwars.effect.GiftEffect;
|
||||||
|
import com.yaohun.enderdragonwars.game.Game;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
public class ToHeavenEffect extends GiftEffect {
|
||||||
|
|
||||||
|
public ToHeavenEffect(String audience) {
|
||||||
|
super(audience);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(Game game) {
|
||||||
|
Player player = game.getPlayer();
|
||||||
|
double radius = 1.5D;
|
||||||
|
new BukkitRunnable() {
|
||||||
|
private int count = 0;
|
||||||
|
private double angle = 0;
|
||||||
|
private double speed = 1.25;
|
||||||
|
private int skyTnt = 0;
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (count >= 200) {
|
||||||
|
cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
double radius = 1.5;
|
||||||
|
double angleStep = Math.PI / 4;
|
||||||
|
double angle = skyTnt * angleStep;
|
||||||
|
Vector vector = new Vector(radius * Math.cos(angle), 0.5, radius * Math.sin(angle));
|
||||||
|
player.setVelocity(vector);
|
||||||
|
skyTnt++;
|
||||||
|
if (skyTnt >= 8) {
|
||||||
|
skyTnt = 0;
|
||||||
|
}
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}.runTaskTimer(Main.plugin, 0L, 1L);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,11 +1,11 @@
|
||||||
package com.yaohun.enderdragonwars.effectevent;
|
package com.yaohun.enderdragonwars.effect.types;
|
||||||
|
|
||||||
import com.yaohun.enderdragonwars.effect.GiftEffect;
|
import com.yaohun.enderdragonwars.effect.GiftEffect;
|
||||||
import com.yaohun.enderdragonwars.game.Game;
|
import com.yaohun.enderdragonwars.game.Game;
|
||||||
|
|
||||||
public class ClearInvEffect extends GiftEffect {
|
public class WorldDestroyEffect extends GiftEffect {
|
||||||
|
|
||||||
public ClearInvEffect(String audience) {
|
public WorldDestroyEffect(String audience) {
|
||||||
super(audience);
|
super(audience);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
package com.yaohun.enderdragonWars.effectevent;
|
|
||||||
|
|
||||||
import com.yaohun.enderdragonWars.effect.GiftEffect;
|
|
||||||
import com.yaohun.enderdragonWars.game.Game;
|
|
||||||
|
|
||||||
public class ClearInvEffect extends GiftEffect {
|
|
||||||
|
|
||||||
public ClearInvEffect(String audience) {
|
|
||||||
super(audience);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void apply(Game game) {
|
|
||||||
/*
|
|
||||||
* 获取玩家背包中所有物品然后从头上像喷泉一样到处散落
|
|
||||||
* 给这些掉落的物品添加一个nbt antipick: true
|
|
||||||
* */
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
package com.yaohun.enderdragonwars.listener;
|
||||||
|
|
||||||
|
import com.yaohun.enderdragonwars.effect.types.LuckyBlockEffect;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Particle;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.IronGolem;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class PlayerListener implements Listener {
|
||||||
|
|
||||||
|
private static Map<Player, ItemStack> totem = new HashMap<>();
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onEntityDamage(EntityDamageEvent event) {
|
||||||
|
if (event.getEntity() instanceof Player player) {
|
||||||
|
PlayerInventory inventory = player.getInventory();
|
||||||
|
Material item = Material.TOTEM_OF_UNDYING;
|
||||||
|
ItemStack mainhand = inventory.getItemInMainHand();
|
||||||
|
ItemStack offhand = inventory.getItemInOffHand();
|
||||||
|
if (player.getHealth() - event.getFinalDamage() <= 0.0d && inventory.contains(item)) {
|
||||||
|
if (mainhand != null && mainhand.getType() == item) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ((offhand == null || offhand.getType() != item)) {
|
||||||
|
this.totem.put(player, inventory.getItemInOffHand());
|
||||||
|
ItemStack[] contents = inventory.getContents();
|
||||||
|
int length = contents.length;
|
||||||
|
int i = 0;
|
||||||
|
while (true) {
|
||||||
|
if (i >= length) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ItemStack totem = contents[i];
|
||||||
|
if (totem != null && totem.getType().equals(item)) {
|
||||||
|
totem.setAmount(totem.getAmount() - 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
inventory.setItemInOffHand(new ItemStack(Material.TOTEM_OF_UNDYING));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerBreakBlock(BlockBreakEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
Block block = event.getBlock();
|
||||||
|
if (block.getType() == Material.SPONGE) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
block.setType(Material.AIR);
|
||||||
|
LuckyBlockEffect.openLuckyBlock(player, block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
Entity entity = event.getRightClicked();
|
||||||
|
if (entity instanceof IronGolem) {
|
||||||
|
entity.addPassenger(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -2,8 +2,8 @@ package com.yaohun.enderdragonwars.manager;
|
||||||
|
|
||||||
import com.yaohun.enderdragonwars.effect.GiftEffect;
|
import com.yaohun.enderdragonwars.effect.GiftEffect;
|
||||||
import com.yaohun.enderdragonwars.effect.GiftQueue;
|
import com.yaohun.enderdragonwars.effect.GiftQueue;
|
||||||
import com.yaohun.enderdragonwars.effectevent.BomBomEffect;
|
import com.yaohun.enderdragonwars.effect.types.BomBomEffect;
|
||||||
import com.yaohun.enderdragonwars.effectevent.ClearInvEffect;
|
import com.yaohun.enderdragonwars.effect.types.ClearInventoryEffect;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -41,7 +41,7 @@ public class GiftEffectManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerAll() {
|
public static void registerAll() {
|
||||||
registerGiftEffect("清理背包", ClearInvEffect::new);
|
registerGiftEffect("清理背包", ClearInventoryEffect::new);
|
||||||
registerGiftEffect("火山喷发", BomBomEffect::new);
|
registerGiftEffect("火山喷发", BomBomEffect::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
462
src/main/java/com/yaohun/enderdragonWars/util/BuildSpawner.java
Normal file
462
src/main/java/com/yaohun/enderdragonWars/util/BuildSpawner.java
Normal file
|
@ -0,0 +1,462 @@
|
||||||
|
package com.yaohun.enderdragonwars.util;
|
||||||
|
|
||||||
|
import com.yaohun.enderdragonwars.Main;
|
||||||
|
import com.yaohun.enderdragonwars.data.Point;
|
||||||
|
import com.yaohun.enderdragonwars.data.Region;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.data.type.EndPortalFrame;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class BuildSpawner {
|
||||||
|
|
||||||
|
private World world;
|
||||||
|
private Direction initialDirection;
|
||||||
|
private int originX;
|
||||||
|
private int originY;
|
||||||
|
private int originZ;
|
||||||
|
private int chunkWight;
|
||||||
|
private int chunkLength;
|
||||||
|
private int ladderLength;
|
||||||
|
private int ladderAmount;
|
||||||
|
private int platformWidth;
|
||||||
|
private int platformLength;
|
||||||
|
private int levelAmount;
|
||||||
|
private SpawnMode spawnMode;
|
||||||
|
|
||||||
|
private int nowX;
|
||||||
|
private int nowY;
|
||||||
|
private int nowZ;
|
||||||
|
private Direction nowDirection;
|
||||||
|
|
||||||
|
private List<Material> materials;
|
||||||
|
|
||||||
|
protected ISpawnModeHander spawnModeHander;
|
||||||
|
|
||||||
|
public BuildSpawner(World world, Direction initialDirection, int originX, int originY, int originZ, int chunkWight, int chunkLength, int ladderLength, int ladderAmount, int platformWidth, int platformLength, int levelAmount, SpawnMode spawnMode, List<Material> materials) {
|
||||||
|
this.world = world;
|
||||||
|
this.initialDirection = initialDirection;
|
||||||
|
this.originX = originX;
|
||||||
|
this.originY = originY;
|
||||||
|
this.originZ = originZ;
|
||||||
|
this.chunkWight = chunkWight;
|
||||||
|
this.chunkLength = chunkLength;
|
||||||
|
this.ladderLength = ladderLength;
|
||||||
|
this.ladderAmount = ladderAmount;
|
||||||
|
this.platformWidth = platformWidth;
|
||||||
|
this.platformLength = platformLength;
|
||||||
|
this.levelAmount = levelAmount;
|
||||||
|
this.spawnMode = spawnMode;
|
||||||
|
this.materials = materials;
|
||||||
|
|
||||||
|
nowX = originX;
|
||||||
|
nowY = originY;
|
||||||
|
nowZ = originZ;
|
||||||
|
nowDirection = initialDirection;
|
||||||
|
if (spawnMode == SpawnMode.MODE_1) {
|
||||||
|
spawnModeHander = new SpawnModeHandler_1();
|
||||||
|
} else if (spawnMode == SpawnMode.MODE_2) {
|
||||||
|
spawnModeHander = new SpawnModeHandler_2();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void spawn() {
|
||||||
|
nowX = originX;
|
||||||
|
nowY = originY;
|
||||||
|
nowZ = originZ;
|
||||||
|
nowDirection = initialDirection;
|
||||||
|
if (spawnModeHander != null) {
|
||||||
|
spawnModeHander.spawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void spawnPlatform(int x, int y, int z, Direction direction) {
|
||||||
|
if (direction == Direction.EAST || direction == Direction.WEST) {
|
||||||
|
for (int i = 0; i < platformLength; i++) {
|
||||||
|
for (int j = 0; j < platformWidth; j++) {
|
||||||
|
int x1 = x + (i * chunkWight) * direction.getPlatformVector().getBlockX();
|
||||||
|
int z1 = z + (j * chunkLength) * direction.getPlatformVector().getBlockZ();
|
||||||
|
spawnPlatformChunk(x1, y, z1, direction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (direction == Direction.NORTH || direction == Direction.SOUTH) {
|
||||||
|
for (int i = 0; i < platformLength; i++) {
|
||||||
|
for (int j = 0; j < platformWidth; j++) {
|
||||||
|
int x1 = x + (j * chunkLength) * direction.getPlatformVector().getBlockX();
|
||||||
|
int z1 = z + (i * chunkWight) * direction.getPlatformVector().getBlockZ();
|
||||||
|
spawnPlatformChunk(x1, y, z1, direction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void spawnLadder(int x, int y, int z, Direction direction) {
|
||||||
|
for (int i = 0; i < ladderAmount; i++) {
|
||||||
|
for (int j = 0; j < ladderLength; j++) {
|
||||||
|
int x1 = getLadderX(i, j, x, z, direction);
|
||||||
|
int z1 = getLadderZ(i, j, x, z, direction);
|
||||||
|
spawnLadderChunk(x1, y + i + 1, z1, direction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getLadderX(int i, int j, int x, int z, Direction direction) {
|
||||||
|
switch (direction) {
|
||||||
|
case EAST:
|
||||||
|
case WEST:
|
||||||
|
return x + (i * chunkWight) * direction.getLadderVector().getBlockX();
|
||||||
|
case SOUTH:
|
||||||
|
case NORTH:
|
||||||
|
return x + (j * chunkLength) * direction.getLadderVector().getBlockX();
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getLadderZ(int i, int j, int x, int z, Direction direction) {
|
||||||
|
switch (direction) {
|
||||||
|
case EAST:
|
||||||
|
case WEST:
|
||||||
|
return z + (j * chunkLength) * direction.getLadderVector().getBlockZ();
|
||||||
|
case SOUTH:
|
||||||
|
case NORTH:
|
||||||
|
return z + (i * chunkWight) * direction.getLadderVector().getBlockZ();
|
||||||
|
}
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void spawnPlatformChunk(int x, int y, int z, Direction direction) {
|
||||||
|
Material material = getRandomMaterial();
|
||||||
|
if (direction == Direction.EAST || direction == Direction.WEST) {
|
||||||
|
for (int i = 0; i < chunkWight; i++) {
|
||||||
|
for (int j = 0; j < chunkLength; j++) {
|
||||||
|
int x1 = x + i * direction.getPlatformVector().getBlockX();
|
||||||
|
int z1 = z + j * direction.getPlatformVector().getBlockZ();
|
||||||
|
world.getBlockAt(x1, y, z1).setType(material);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (direction == Direction.NORTH || direction == Direction.SOUTH) {
|
||||||
|
for (int i = 0; i < chunkWight; i++) {
|
||||||
|
for (int j = 0; j < chunkLength; j++) {
|
||||||
|
int x1 = x + j * direction.getPlatformVector().getBlockX();
|
||||||
|
int z1 = z + i * direction.getPlatformVector().getBlockZ();
|
||||||
|
world.getBlockAt(x1, y, z1).setType(material);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void spawnLadderChunk(int x, int y, int z, Direction direction) {
|
||||||
|
Material material = getRandomMaterial();
|
||||||
|
if (direction == Direction.EAST || direction == Direction.WEST) {
|
||||||
|
for (int i = 0; i < chunkWight; i++) {
|
||||||
|
for (int j = 0; j < chunkLength; j++) {
|
||||||
|
int x1 = x + i * direction.getLadderVector().getBlockX();
|
||||||
|
int z1 = z + j * direction.getLadderVector().getBlockZ();
|
||||||
|
world.getBlockAt(x1, y, z1).setType(material);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (direction == Direction.NORTH || direction == Direction.SOUTH) {
|
||||||
|
for (int i = 0; i < chunkLength; i++) {
|
||||||
|
for (int j = 0; j < chunkWight; j++) {
|
||||||
|
int x1 = x + i * direction.getLadderVector().getBlockX();
|
||||||
|
int z1 = z + j * direction.getLadderVector().getBlockZ();
|
||||||
|
world.getBlockAt(x1, y, z1).setType(material);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void transformDirection() {
|
||||||
|
nowDirection = nowDirection.getRightDirection();
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum TransformType {
|
||||||
|
PLATFORM,
|
||||||
|
LADDER
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Direction {
|
||||||
|
|
||||||
|
NORTH(new Vector(1.0, 1.0, -1.0), new Vector(-1.0, 1.0, -1.0), new Vector(1.0, 1.0, -1.0)),
|
||||||
|
EAST(new Vector(1.0, 1.0, 1.0), new Vector(1.0, 1.0, -1.0), new Vector(1.0, 1.0, 1.0)),
|
||||||
|
SOUTH(new Vector(-1.0, 1.0, 1.0), new Vector(1.0, 1.0, 1.0), new Vector(-1.0, 1.0, 1.0)),
|
||||||
|
WEST(new Vector(-1.0, 1.0, -1.0), new Vector(-1.0, 1.0, 1.0), new Vector(-1.0, 1.0, -1.0));
|
||||||
|
|
||||||
|
private final Vector vector;
|
||||||
|
private final Vector platformVector;
|
||||||
|
private final Vector ladderVector;
|
||||||
|
|
||||||
|
Direction(Vector vector, Vector platformVector, Vector ladderVector) {
|
||||||
|
this.vector = vector;
|
||||||
|
this.platformVector = platformVector;
|
||||||
|
this.ladderVector = ladderVector;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector getVector() {
|
||||||
|
return vector;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector getPlatformVector() {
|
||||||
|
return platformVector;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector getLadderVector() {
|
||||||
|
return ladderVector;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Direction getRightDirection() {
|
||||||
|
switch (this) {
|
||||||
|
case NORTH:
|
||||||
|
return EAST;
|
||||||
|
case EAST:
|
||||||
|
return SOUTH;
|
||||||
|
case SOUTH:
|
||||||
|
return WEST;
|
||||||
|
case WEST:
|
||||||
|
return NORTH;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Region getEffectiveRegion(World world) {
|
||||||
|
return spawnModeHander.getEffectiveRegion(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHeight() {
|
||||||
|
return spawnModeHander.getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum SpawnMode {
|
||||||
|
|
||||||
|
MODE_1,
|
||||||
|
MODE_2
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class SpawnModeHandler_1 implements ISpawnModeHander {
|
||||||
|
@Override
|
||||||
|
public void spawn() {
|
||||||
|
new BukkitRunnable() {
|
||||||
|
private int count = 0;
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (count >= levelAmount) {
|
||||||
|
spawnPlatform(nowX, nowY, nowZ, nowDirection);
|
||||||
|
cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
spawnPlatform(nowX, nowY, nowZ, nowDirection);
|
||||||
|
transformXYZ(TransformType.PLATFORM, nowDirection);
|
||||||
|
transformDirection();
|
||||||
|
spawnLadder(nowX, nowY, nowZ, nowDirection);
|
||||||
|
transformXYZ(TransformType.LADDER, nowDirection);
|
||||||
|
transformDirection();
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}.runTaskTimer(Main.plugin, 0L, 3L);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Region getEffectiveRegion(World world) {
|
||||||
|
if (initialDirection == Direction.NORTH || initialDirection == Direction.SOUTH) {
|
||||||
|
int minX = originX + (platformWidth * chunkWight) * initialDirection.getPlatformVector().getBlockX();
|
||||||
|
int minY = originY;
|
||||||
|
int minZ = originZ;
|
||||||
|
int maxX = originX + ladderAmount * ladderLength * chunkLength * initialDirection.getLadderVector().getBlockX() + (platformWidth * chunkWight) * initialDirection.getPlatformVector().getBlockX() + 1;
|
||||||
|
int maxY = originY + levelAmount * 5 + 1;
|
||||||
|
int maxZ = originZ + (platformLength * chunkLength) * initialDirection.getPlatformVector().getBlockZ() + 1;
|
||||||
|
return new Region(world, new Point(minX, minY, minZ), new Point(maxX, maxY, maxZ));
|
||||||
|
} else if (initialDirection == Direction.EAST || initialDirection == Direction.WEST) {
|
||||||
|
int minX = originX;
|
||||||
|
int minY = originY;
|
||||||
|
int minZ = originZ + (platformWidth * chunkWight) * initialDirection.getPlatformVector().getBlockZ();
|
||||||
|
int maxX = originX + (platformLength * chunkLength) * initialDirection.getPlatformVector().getBlockX() + 1;
|
||||||
|
int maxY = originY + levelAmount * 5 + 1;
|
||||||
|
int maxZ = originZ + ladderAmount * ladderLength * chunkLength * initialDirection.getLadderVector().getBlockX() + (platformWidth * chunkWight) * initialDirection.getPlatformVector().getBlockZ() + 1;
|
||||||
|
return new Region(world, new Point(minX, minY, minZ), new Point(maxX, maxY, maxZ));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getHeight() {
|
||||||
|
return levelAmount * 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void transformXYZ(TransformType transformType, Direction direction) {
|
||||||
|
if (transformType == TransformType.PLATFORM) {
|
||||||
|
if (direction == Direction.EAST || direction == Direction.WEST) {
|
||||||
|
nowX += (platformLength * chunkWight - 1) * direction.getPlatformVector().getX();
|
||||||
|
} else if (direction == Direction.NORTH || direction == Direction.SOUTH) {
|
||||||
|
nowZ += (platformLength * chunkWight - 1) * direction.getPlatformVector().getZ();
|
||||||
|
}
|
||||||
|
switch (nowDirection) {
|
||||||
|
case EAST:
|
||||||
|
nowZ += 1;
|
||||||
|
break;
|
||||||
|
case SOUTH:
|
||||||
|
nowX -= 1;
|
||||||
|
break;
|
||||||
|
case WEST:
|
||||||
|
nowZ -= 1;
|
||||||
|
break;
|
||||||
|
case NORTH:
|
||||||
|
nowX += 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (transformType == TransformType.LADDER) {
|
||||||
|
nowY += ladderAmount;
|
||||||
|
if (direction == Direction.EAST || direction == Direction.WEST) {
|
||||||
|
nowX += (ladderAmount * chunkWight) * direction.getLadderVector().getBlockX();
|
||||||
|
} else if (direction == Direction.NORTH || direction == Direction.SOUTH) {
|
||||||
|
nowZ += (ladderAmount * chunkWight) * direction.getLadderVector().getBlockZ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class SpawnModeHandler_2 implements ISpawnModeHander {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void spawn() {
|
||||||
|
new BukkitRunnable() {
|
||||||
|
private int count = 0;
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (count >= levelAmount) {
|
||||||
|
spawnPlatform(nowX, nowY, nowZ, nowDirection);
|
||||||
|
Region region = getEffectiveRegion(world);
|
||||||
|
int centerX = (region.getMax().getBlockX() - region.getMin().getBlockX() + 1) / 2;
|
||||||
|
int centerZ = (region.getMax().getBlockZ() - region.getMin().getBlockZ() + 1) / 2;
|
||||||
|
Point blockCenterPoint = new Point(region.getMin().getBlockX() + centerZ, region.getMax().getBlockY() - 3, region.getMin().getBlockZ() + centerZ);
|
||||||
|
Block block = world.getBlockAt(blockCenterPoint.getBlockX(), blockCenterPoint.getBlockY(), blockCenterPoint.getBlockZ());
|
||||||
|
for (int i = -6; i <= 6; i++) {
|
||||||
|
for (int j = -6; j <= 6; j++) {
|
||||||
|
if (Math.abs(i) == 6 && Math.abs(j) == 6) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Block block1 = world.getBlockAt(blockCenterPoint.getBlockX() + i, blockCenterPoint.getBlockY(), blockCenterPoint.getBlockZ() + j);
|
||||||
|
if (Math.abs(i) <= 5 && Math.abs(j) <= 5) {
|
||||||
|
block1.setType(Material.END_PORTAL);
|
||||||
|
} else {
|
||||||
|
block1.setType(Material.END_PORTAL_FRAME);
|
||||||
|
EndPortalFrame endPortalFrame = (EndPortalFrame) block1.getBlockData();
|
||||||
|
endPortalFrame.setEye(true);
|
||||||
|
block1.setBlockData(endPortalFrame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
block.getWorld().strikeLightning(block.getLocation().add(0.5, 0, 0.5));
|
||||||
|
block.getWorld().getPlayers().forEach(player -> player.playSound(player.getLocation(), Sound.BLOCK_END_PORTAL_SPAWN, 1.0f, 1.0f));
|
||||||
|
cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
spawnPlatform(nowX, nowY, nowZ, nowDirection);
|
||||||
|
transformXYZ(TransformType.PLATFORM, nowDirection, 0);
|
||||||
|
spawnLadder(nowX, nowY, nowZ, nowDirection);
|
||||||
|
transformXYZ(TransformType.LADDER, nowDirection, 0);
|
||||||
|
transformDirection();
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}.runTaskTimer(Main.plugin, 0L, 3L);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Region getEffectiveRegion(World world) {
|
||||||
|
if (initialDirection == Direction.NORTH || initialDirection == Direction.SOUTH) {
|
||||||
|
int minX = originX + (platformWidth * chunkWight) * initialDirection.getPlatformVector().getBlockX();
|
||||||
|
int minZ = originZ;
|
||||||
|
minZ += (platformLength * chunkLength) * initialDirection.getPlatformVector().getBlockZ();
|
||||||
|
minZ += (ladderAmount * chunkLength) * initialDirection.getLadderVector().getBlockZ();
|
||||||
|
minZ += (platformWidth * chunkWight) * initialDirection.getRightDirection().getPlatformVector().getBlockZ();
|
||||||
|
int maxX = originX + ladderAmount * ladderLength * chunkLength * initialDirection.getLadderVector().getBlockX() + (platformWidth * chunkWight) * initialDirection.getPlatformVector().getBlockX()+ 1;
|
||||||
|
int maxZ = originZ;
|
||||||
|
int maxY = originY + levelAmount * 5 + 1;
|
||||||
|
return new Region(world, new Point(minX, originY, minZ), new Point(maxX, maxY, maxZ));
|
||||||
|
} else if (initialDirection == Direction.EAST || initialDirection == Direction.WEST) {
|
||||||
|
int minX = originX;
|
||||||
|
int minZ = originZ + (platformWidth * chunkWight) * initialDirection.getPlatformVector().getBlockZ();
|
||||||
|
minX += (platformLength * chunkLength) * initialDirection.getPlatformVector().getBlockX();
|
||||||
|
minX += (ladderAmount * chunkLength) * initialDirection.getLadderVector().getBlockX();
|
||||||
|
minX += (platformWidth * chunkWight) * initialDirection.getRightDirection().getPlatformVector().getBlockX();
|
||||||
|
int maxX = originX;
|
||||||
|
int maxZ = originZ + ladderAmount * ladderLength * chunkLength * initialDirection.getLadderVector().getBlockZ() + (platformWidth * chunkWight) * initialDirection.getPlatformVector().getBlockZ()+ 1;
|
||||||
|
int maxY = originY + levelAmount * 5 + 1;
|
||||||
|
return new Region(world, new Point(minX, originY, minZ), new Point(maxX, maxY, maxZ));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getHeight() {
|
||||||
|
return levelAmount * 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void transformXYZ(TransformType transformType, Direction direction, int type) {
|
||||||
|
if (transformType == TransformType.PLATFORM) {
|
||||||
|
if (type == 0) {
|
||||||
|
if (direction == Direction.EAST || direction == Direction.WEST) {
|
||||||
|
nowX += (platformLength * chunkWight) * direction.getPlatformVector().getX();
|
||||||
|
nowZ += (platformWidth * chunkLength - 1) * direction.getPlatformVector().getZ();
|
||||||
|
} else if (direction == Direction.NORTH || direction == Direction.SOUTH) {
|
||||||
|
nowX += (platformWidth * chunkLength - 1) * direction.getPlatformVector().getX();
|
||||||
|
nowZ += (platformLength * chunkWight) * direction.getPlatformVector().getZ();
|
||||||
|
}
|
||||||
|
} else if (type == 1) {
|
||||||
|
if (direction == Direction.EAST || direction == Direction.WEST) {
|
||||||
|
nowX += (platformLength * chunkWight - 1) * direction.getPlatformVector().getX();
|
||||||
|
} else if (direction == Direction.NORTH || direction == Direction.SOUTH) {
|
||||||
|
nowZ += (platformLength * chunkWight - 1) * direction.getPlatformVector().getZ();
|
||||||
|
}
|
||||||
|
switch (nowDirection) {
|
||||||
|
case EAST:
|
||||||
|
nowZ += 1;
|
||||||
|
break;
|
||||||
|
case SOUTH:
|
||||||
|
nowX -= 1;
|
||||||
|
break;
|
||||||
|
case WEST:
|
||||||
|
nowZ -= 1;
|
||||||
|
break;
|
||||||
|
case NORTH:
|
||||||
|
nowX += 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (transformType == TransformType.LADDER) {
|
||||||
|
nowY += ladderAmount;
|
||||||
|
if (direction == Direction.EAST || direction == Direction.WEST) {
|
||||||
|
nowX += (ladderAmount * chunkWight) * direction.getLadderVector().getBlockX();
|
||||||
|
} else if (direction == Direction.NORTH || direction == Direction.SOUTH) {
|
||||||
|
nowZ += (ladderAmount * chunkWight) * direction.getLadderVector().getBlockZ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInitialDirection(Direction initialDirection) {
|
||||||
|
this.initialDirection = initialDirection;
|
||||||
|
}
|
||||||
|
|
||||||
|
private interface ISpawnModeHander {
|
||||||
|
void spawn();
|
||||||
|
|
||||||
|
Region getEffectiveRegion(World world);
|
||||||
|
|
||||||
|
int getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Material getRandomMaterial() {
|
||||||
|
return materials.get(RandomUtil.getRandomInt(0, materials.size() - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,345 @@
|
||||||
|
package com.yaohun.enderdragonwars.util;
|
||||||
|
|
||||||
|
import org.bukkit.*;
|
||||||
|
import org.bukkit.attribute.Attribute;
|
||||||
|
import org.bukkit.attribute.AttributeModifier;
|
||||||
|
import org.bukkit.block.banner.Pattern;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
|
import org.bukkit.inventory.ItemFlag;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||||
|
import org.bukkit.inventory.meta.FireworkMeta;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.inventory.meta.SkullMeta;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class ItemStackBuilder {
|
||||||
|
|
||||||
|
private ItemStack itemStack;
|
||||||
|
|
||||||
|
private Material type;
|
||||||
|
|
||||||
|
private int amount;
|
||||||
|
|
||||||
|
private short data;
|
||||||
|
|
||||||
|
private ItemMeta meta;
|
||||||
|
|
||||||
|
private String displayName;
|
||||||
|
|
||||||
|
private int customModelData;
|
||||||
|
|
||||||
|
private List<String> lore;
|
||||||
|
|
||||||
|
private Map<Enchantment, Integer> enchants;
|
||||||
|
|
||||||
|
private Set<ItemFlag> itemFlags;
|
||||||
|
|
||||||
|
private List<PotionEffect> potionEffects;
|
||||||
|
private List<Pattern> patterns;
|
||||||
|
private List<FireworkEffect> fireworkEffects;
|
||||||
|
|
||||||
|
public ItemStackBuilder(Material material) {
|
||||||
|
this.itemStack = new ItemStack(material);
|
||||||
|
this.type = material;
|
||||||
|
this.amount = 1;
|
||||||
|
this.data = 0;
|
||||||
|
this.meta = this.itemStack.getItemMeta();
|
||||||
|
this.displayName = this.meta.getDisplayName();
|
||||||
|
this.customModelData = this.meta.hasCustomModelData() ? this.meta.getCustomModelData() : -1;
|
||||||
|
this.lore = new ArrayList<>();
|
||||||
|
this.enchants = new HashMap<>();
|
||||||
|
this.itemFlags = new HashSet<>();
|
||||||
|
this.potionEffects = new ArrayList<>();
|
||||||
|
this.patterns = new ArrayList<>();
|
||||||
|
this.fireworkEffects = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder(ItemStack item) {
|
||||||
|
this.itemStack = item.clone();
|
||||||
|
this.type = item.getType();
|
||||||
|
this.amount = item.getAmount();
|
||||||
|
this.data = item.getDurability();
|
||||||
|
this.meta = item.getItemMeta();
|
||||||
|
this.displayName = this.meta.getDisplayName();
|
||||||
|
this.customModelData = this.meta.hasCustomModelData() ? this.meta.getCustomModelData() : -1;
|
||||||
|
this.lore = this.meta.getLore() == null ? new ArrayList<>() : meta.getLore();
|
||||||
|
this.enchants = this.meta.getEnchants();
|
||||||
|
this.itemFlags = this.meta.getItemFlags();
|
||||||
|
this.potionEffects = new ArrayList<>();
|
||||||
|
this.patterns = new ArrayList<>();
|
||||||
|
this.fireworkEffects = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack build() {
|
||||||
|
ItemStack item = new ItemStack(type, amount);
|
||||||
|
item.setType(type);
|
||||||
|
item.setAmount(amount);
|
||||||
|
if (enchants != null) {
|
||||||
|
item.addUnsafeEnchantments(enchants);
|
||||||
|
}
|
||||||
|
ItemMeta itemMeta = item.getItemMeta();
|
||||||
|
if (displayName != null) {
|
||||||
|
itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', displayName));
|
||||||
|
}
|
||||||
|
if (lore != null) {
|
||||||
|
List<String> l = new ArrayList<>();
|
||||||
|
lore.forEach((s) -> {
|
||||||
|
l.add(ChatColor.translateAlternateColorCodes('&', s));
|
||||||
|
});
|
||||||
|
itemMeta.setLore(l);
|
||||||
|
}
|
||||||
|
if (this.customModelData != -1) {
|
||||||
|
itemMeta.setCustomModelData(customModelData);
|
||||||
|
}
|
||||||
|
if (itemFlags != null) {
|
||||||
|
for (ItemFlag flag : itemFlags) {
|
||||||
|
itemMeta.addItemFlags(flag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fireworkEffects != null && fireworkEffects.size() > 0 && (type.equals(Material.FIREWORK_STAR) || type.equals(Material.FIREWORK_ROCKET))) {
|
||||||
|
FireworkMeta fireworkMeta = (FireworkMeta) itemMeta;
|
||||||
|
for (FireworkEffect effect : fireworkEffects) {
|
||||||
|
fireworkMeta.addEffect(effect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
item.setItemMeta(itemMeta);
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAmount() {
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Material getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getLore() {
|
||||||
|
return lore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCustomModelData() {
|
||||||
|
return customModelData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<Enchantment, Integer> getEnchants() {
|
||||||
|
return enchants;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<ItemFlag> getItemFlags() {
|
||||||
|
return itemFlags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PotionEffect> getPotionEffects() {
|
||||||
|
return potionEffects;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<FireworkEffect> getFireworkEffects() {
|
||||||
|
return fireworkEffects;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Pattern> getPatterns() {
|
||||||
|
return patterns;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDisplayName() {
|
||||||
|
return displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public short getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder setItemStack(ItemStack item) {
|
||||||
|
this.itemStack = item;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder setType(Material type) {
|
||||||
|
this.type = type;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder setCustomModelData(int customModelData) {
|
||||||
|
this.customModelData = customModelData;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder setAmount(int amount) {
|
||||||
|
this.amount = amount;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder setData(int data) {
|
||||||
|
if (data > 255) {
|
||||||
|
data = 255;
|
||||||
|
}
|
||||||
|
this.data = (short) data;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder setData(short data) {
|
||||||
|
this.data = data;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder setItemMeta(ItemMeta meta) {
|
||||||
|
this.meta = meta;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder setDisplayName(String name) {
|
||||||
|
this.displayName = name;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder setLore(List<String> loreList) {
|
||||||
|
this.lore = loreList;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder setLore(String... lores) {
|
||||||
|
this.lore = new ArrayList<>(Arrays.asList(lores));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder addLore(String lore) {
|
||||||
|
this.lore.add(lore);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder addLore(String... lores) {
|
||||||
|
this.lore.addAll(Arrays.asList(lores));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder addLore(List<String> lores) {
|
||||||
|
for (String lore : lores) {
|
||||||
|
this.lore.add(lore);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder addAttributeModifier(Attribute attribute, AttributeModifier attributeModifier) {
|
||||||
|
this.meta.addAttributeModifier(attribute, attributeModifier);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder removeAttributeModifier(Attribute attribute) {
|
||||||
|
this.meta.removeAttributeModifier(attribute);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder removeAttributeModifier(EquipmentSlot equipmentSlot) {
|
||||||
|
this.meta.removeAttributeModifier(equipmentSlot);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder removeAttributeModifier(Attribute attribute, AttributeModifier attributeModifier) {
|
||||||
|
this.meta.removeAttributeModifier(attribute, attributeModifier);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder addEnchant(Enchantment ench, int level) {
|
||||||
|
this.enchants.put(ench, level);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder removeEnchant(Enchantment ench) {
|
||||||
|
this.enchants.remove(ench);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder setEnchants(Map<Enchantment, Integer> enchants) {
|
||||||
|
this.enchants = enchants;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder setEnchants(List<String> enchants) {
|
||||||
|
this.enchants = getEnchantsFromList(enchants);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder setItemFlags(Set<ItemFlag> itemFlags) {
|
||||||
|
this.itemFlags = itemFlags;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder addItemFlags(ItemFlag[] itemFlags) {
|
||||||
|
this.itemFlags.addAll(Arrays.asList(itemFlags));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder addItemFlags(ItemFlag itemFlag) {
|
||||||
|
this.itemFlags.add(itemFlag);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder addPotionEffect(PotionEffect potionEffect) {
|
||||||
|
this.potionEffects.add(potionEffect);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder addPattern(Pattern pattern) {
|
||||||
|
this.patterns.add(pattern);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStackBuilder addFireworkEffect(FireworkEffect fireworkEffect) {
|
||||||
|
this.fireworkEffects.add(fireworkEffect);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Map<Enchantment, Integer> getEnchantsFromList(List<String> enchants) {
|
||||||
|
Map<Enchantment, Integer> map = new HashMap<>();
|
||||||
|
if (enchants == null) {
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
for (String s : enchants) {
|
||||||
|
if (s.contains(":")) {
|
||||||
|
String[] part = s.split(":");
|
||||||
|
Enchantment en = Enchantment.getByName(part[0]);
|
||||||
|
if (en == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
map.put(en, Integer.parseInt(part[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static ItemStack setEnchants(ItemStack stack, List<String> enchants) {
|
||||||
|
if (enchants == null) {
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
for (String s : enchants) {
|
||||||
|
if (s.contains(":")) {
|
||||||
|
String[] part = s.split(":");
|
||||||
|
Enchantment en = Enchantment.getByName(part[0]);
|
||||||
|
if (en == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (stack.getType() != Material.ENCHANTED_BOOK) {
|
||||||
|
stack.addUnsafeEnchantment(en, Integer.parseInt(part[1]));
|
||||||
|
} else {
|
||||||
|
EnchantmentStorageMeta esm = (EnchantmentStorageMeta) stack.getItemMeta();
|
||||||
|
esm.addStoredEnchant(en, Integer.parseInt(part[1]), true);
|
||||||
|
stack.setItemMeta((ItemMeta) esm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setField(Object instance, String name, Object value) throws ReflectiveOperationException {
|
||||||
|
Field field = instance.getClass().getDeclaredField(name);
|
||||||
|
field.setAccessible(true);
|
||||||
|
field.set(instance, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
44
src/main/java/com/yaohun/enderdragonWars/util/WEUtil.java
Normal file
44
src/main/java/com/yaohun/enderdragonWars/util/WEUtil.java
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
package com.yaohun.enderdragonwars.util;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||||
|
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
|
||||||
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
import com.yaohun.enderdragonwars.Main;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class WEUtil {
|
||||||
|
|
||||||
|
public static void loadSchematics(Location location, String fileName) {
|
||||||
|
File path = new File(Main.plugin.getDataFolder(), "schematics");
|
||||||
|
if (!path.exists()) {
|
||||||
|
path.mkdirs();
|
||||||
|
}
|
||||||
|
File schematicFile = new File(path,fileName+".schem");
|
||||||
|
if (!schematicFile.exists()) {
|
||||||
|
Main.plugin.saveResource("schematics/"+fileName+".schem", false);
|
||||||
|
}
|
||||||
|
World world = location.getWorld();
|
||||||
|
EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(world));
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously (Main.plugin, () -> {
|
||||||
|
try {
|
||||||
|
Clipboard clipboard = ClipboardFormats.findByFile(schematicFile).load(schematicFile);
|
||||||
|
clipboard.paste(BukkitAdapter.adapt(world), BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
|
||||||
|
clipboard.flush();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
editSession.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,9 +1,11 @@
|
||||||
package com.yaohun.enderdragonwars;
|
package com.yaohun.enderdragonwars;
|
||||||
|
|
||||||
import com.yaohun.enderdragonwars.effectevent.BomBomEffect;
|
import com.yaohun.enderdragonwars.effect.types.*;
|
||||||
import com.yaohun.enderdragonwars.game.Game;
|
import com.yaohun.enderdragonwars.game.Game;
|
||||||
|
import com.yaohun.enderdragonwars.listener.PlayerListener;
|
||||||
import com.yaohun.enderdragonwars.manager.GameManager;
|
import com.yaohun.enderdragonwars.manager.GameManager;
|
||||||
import com.yaohun.enderdragonwars.manager.GiftEffectManager;
|
import com.yaohun.enderdragonwars.manager.GiftEffectManager;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -22,6 +24,8 @@ public class Main extends JavaPlugin {
|
||||||
GiftEffectManager.registerAll();
|
GiftEffectManager.registerAll();
|
||||||
gameManager = new GameManager();
|
gameManager = new GameManager();
|
||||||
game = new Game();
|
game = new Game();
|
||||||
|
|
||||||
|
Bukkit.getPluginManager().registerEvents(new PlayerListener(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -32,6 +36,32 @@ public class Main extends JavaPlugin {
|
||||||
game.startGame(player);
|
game.startGame(player);
|
||||||
if (subCommand.equalsIgnoreCase("1")) {
|
if (subCommand.equalsIgnoreCase("1")) {
|
||||||
new BomBomEffect(player.getName()).apply(game);
|
new BomBomEffect(player.getName()).apply(game);
|
||||||
|
} else if (subCommand.equalsIgnoreCase("2")) {
|
||||||
|
new ClearInventoryEffect(player.getName()).apply(game);
|
||||||
|
} else if (subCommand.equalsIgnoreCase("3")) {
|
||||||
|
new FiveLightningEffect(player.getName()).apply(game);
|
||||||
|
} else if (subCommand.equalsIgnoreCase("4")) {
|
||||||
|
new BlackHoleEffect(player.getName()).apply(game);
|
||||||
|
} else if (subCommand.equalsIgnoreCase("5")) {
|
||||||
|
new LavaPoolEffect(player.getName()).apply(game);
|
||||||
|
} else if (subCommand.equalsIgnoreCase("6")) {
|
||||||
|
new AddMaxHealthEffect(player.getName()).apply(game);
|
||||||
|
} else if (subCommand.equalsIgnoreCase("7")) {
|
||||||
|
new TakeMaxHealthEffect(player.getName()).apply(game);
|
||||||
|
} else if (subCommand.equalsIgnoreCase("8")) {
|
||||||
|
new SpawnEnderPortalEffect(player.getName()).apply(game);
|
||||||
|
} else if (subCommand.equalsIgnoreCase("9")) {
|
||||||
|
new PlayerBigEffect(player.getName()).apply(game);
|
||||||
|
} else if (subCommand.equalsIgnoreCase("10")) {
|
||||||
|
new PlayerSmallEffect(player.getName()).apply(game);
|
||||||
|
} else if (subCommand.equalsIgnoreCase("11")) {
|
||||||
|
new PlayerResetEffect(player.getName()).apply(game);
|
||||||
|
} else if (subCommand.equalsIgnoreCase("12")) {
|
||||||
|
new SpawnBuildEffect(player.getName()).apply(game);
|
||||||
|
} else if (subCommand.equalsIgnoreCase("13")) {
|
||||||
|
new ToHeavenEffect(player.getName()).apply(game);
|
||||||
|
} else if (subCommand.equalsIgnoreCase("14")) {
|
||||||
|
new LuckyBlockEffect(player.getName()).apply(game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
BIN
src/main/resources/schematics/anquanwu.schem
Normal file
BIN
src/main/resources/schematics/anquanwu.schem
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user