This commit is contained in:
YuTian 2024-08-11 14:12:18 +08:00
parent 832e93a2ef
commit 4bd35b9292
27 changed files with 404 additions and 351 deletions

View File

@ -1,11 +1,11 @@
package com.yaohun.enderdragonwars; package com.yaohun.enderdragonwars;
import com.yaohun.enderdragonwars.listener.RepairGiftGui;
import com.yaohun.enderdragonwars.effect.types.*; import com.yaohun.enderdragonwars.effect.types.*;
import com.yaohun.enderdragonwars.game.Game; import com.yaohun.enderdragonwars.game.Game;
import com.yaohun.enderdragonwars.listener.GameListener; import com.yaohun.enderdragonwars.listener.GameListener;
import com.yaohun.enderdragonwars.listener.LiveListener; import com.yaohun.enderdragonwars.listener.LiveListener;
import com.yaohun.enderdragonwars.listener.PlayerListener; import com.yaohun.enderdragonwars.listener.PlayerListener;
import com.yaohun.enderdragonwars.listener.RepairGiftGui;
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.Bukkit;
@ -35,7 +35,7 @@ public class Main extends JavaPlugin {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String Command, String[] args) { public boolean onCommand(CommandSender sender, Command command, String Command, String[] args) {
if(args.length == 1 && args[0].equalsIgnoreCase("start")){ if (args.length == 1 && args[0].equalsIgnoreCase("start")) {
Player player = (Player) sender; Player player = (Player) sender;
game.startGame(player); game.startGame(player);
return true; return true;

View File

@ -27,10 +27,22 @@ public class DirectionPoint extends Point {
this.pitch = pitch; this.pitch = pitch;
} }
public static DirectionPoint of(Location location) {
return new DirectionPoint(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
}
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"));
}
public float getPitch() { public float getPitch() {
return pitch; return pitch;
} }
public void setPitch(float pitch) {
this.pitch = pitch;
}
public float getYaw() { public float getYaw() {
return yaw; return yaw;
} }
@ -39,19 +51,11 @@ public class DirectionPoint extends Point {
this.yaw = yaw; this.yaw = yaw;
} }
public void setPitch(float pitch) {
this.pitch = pitch;
}
@Override @Override
public Location toLocation(World world) { public Location toLocation(World world) {
return new Location(world, getX(), getY(), getZ(), yaw, pitch); 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 @Override
public String toString() { public String toString() {
return "DirectionPoint{" + return "DirectionPoint{" +
@ -77,8 +81,4 @@ public class DirectionPoint extends Point {
return Objects.hash(super.hashCode(), yaw, pitch); 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"));
}
} }

View File

@ -24,6 +24,14 @@ public class Point {
this.z = z; this.z = z;
} }
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"));
}
public int getBlockX() { public int getBlockX() {
return (int) Math.floor(x); return (int) Math.floor(x);
} }
@ -40,22 +48,22 @@ public class Point {
return x; return x;
} }
public double getY() {
return y;
}
public double getZ() {
return z;
}
public void setX(double x) { public void setX(double x) {
this.x = x; this.x = x;
} }
public double getY() {
return y;
}
public void setY(double y) { public void setY(double y) {
this.y = y; this.y = y;
} }
public double getZ() {
return z;
}
public void setZ(double z) { public void setZ(double z) {
this.z = z; this.z = z;
} }
@ -68,14 +76,6 @@ public class Point {
return new Location(world, x, y, z, 0, 0); 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 @Override
public String toString() { public String toString() {
return "Point{" + return "Point{" +

View File

@ -17,6 +17,13 @@ public class Region {
this.max = max; this.max = 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 World getWorld() { public World getWorld() {
return world; return world;
} }
@ -29,13 +36,6 @@ public class Region {
return max; 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) { public boolean isInRegion(Location location) {
if (!location.getWorld().getName().equalsIgnoreCase(world.getName())) { if (!location.getWorld().getName().equalsIgnoreCase(world.getName())) {
return false; return false;

View File

@ -23,6 +23,7 @@ public class AddMaxHealthEffect extends GiftEffect {
Player player = game.getPlayer(); Player player = game.getPlayer();
new BukkitRunnable() { new BukkitRunnable() {
private int count = 0; private int count = 0;
@Override @Override
public void run() { public void run() {
if (count >= 50) { if (count >= 50) {

View File

@ -34,9 +34,10 @@ public class BlackHoleEffect extends GiftEffect {
Location location = game.getPlayer().getLocation().add(0, 2, 0); Location location = game.getPlayer().getLocation().add(0, 2, 0);
new BukkitRunnable() { new BukkitRunnable() {
private int i = 0; private int i = 0;
@Override @Override
public void run() { public void run() {
if (i >= seconds*2) { if (i >= seconds * 2) {
stop = true; stop = true;
fallingBlocks.forEach(fallingBlock -> fallingBlock.setGravity(true)); fallingBlocks.forEach(fallingBlock -> fallingBlock.setGravity(true));
location.getWorld().createExplosion(location, 3.0F, false, false); location.getWorld().createExplosion(location, 3.0F, false, false);
@ -57,6 +58,7 @@ public class BlackHoleEffect extends GiftEffect {
}.runTaskTimer(Main.plugin, 0L, 10L); }.runTaskTimer(Main.plugin, 0L, 10L);
new BukkitRunnable() { new BukkitRunnable() {
private Set<UUID> uuids = new HashSet<>(); private Set<UUID> uuids = new HashSet<>();
@Override @Override
public void run() { public void run() {
if (stop) { if (stop) {
@ -103,6 +105,7 @@ public class BlackHoleEffect extends GiftEffect {
}.runTaskTimer(Main.plugin, 0L, 5L); }.runTaskTimer(Main.plugin, 0L, 5L);
new BukkitRunnable() { new BukkitRunnable() {
private Set<UUID> uuids = new HashSet<>(); private Set<UUID> uuids = new HashSet<>();
@Override @Override
public void run() { public void run() {
if (stop) { if (stop) {

View File

@ -34,10 +34,46 @@ public class BomBomEffect extends GiftEffect {
private static final ItemStack ITEM_6; private static final ItemStack ITEM_6;
private static final ItemStack ITEM_7; private static final ItemStack ITEM_7;
private List<FallingBlock> fallingBlocks = new ArrayList<>(); static {
private BossBar bossBar; ITEM_1 = new ItemStack(Material.TNT);
ITEM_2 = new ItemStack(Material.LEATHER_CHESTPLATE);
ITEM_3 = new ItemStack(Material.LEATHER_LEGGINGS);
ITEM_4 = new ItemStack(Material.LEATHER_BOOTS);
ITEM_5 = new ItemStack(Material.LEATHER_CHESTPLATE);
ITEM_6 = new ItemStack(Material.LEATHER_LEGGINGS);
ITEM_7 = new ItemStack(Material.LEATHER_BOOTS);
Color color1 = Color.fromRGB(214, 41, 0);
Color color2 = Color.fromRGB(255, 133, 102);
ItemMeta itemMeta2 = ITEM_2.getItemMeta();
ColorableArmorMeta colorableArmorMeta2 = (ColorableArmorMeta) itemMeta2;
colorableArmorMeta2.setColor(color1);
ITEM_2.setItemMeta(colorableArmorMeta2);
ItemMeta itemMeta3 = ITEM_3.getItemMeta();
ColorableArmorMeta colorableArmorMeta3 = (ColorableArmorMeta) itemMeta3;
colorableArmorMeta3.setColor(color1);
ITEM_3.setItemMeta(colorableArmorMeta3);
ItemMeta itemMeta4 = ITEM_4.getItemMeta();
ColorableArmorMeta colorableArmorMeta4 = (ColorableArmorMeta) itemMeta4;
colorableArmorMeta4.setColor(color1);
ITEM_4.setItemMeta(colorableArmorMeta4);
ItemMeta itemMeta5 = ITEM_5.getItemMeta();
ColorableArmorMeta colorableArmorMeta5 = (ColorableArmorMeta) itemMeta5;
colorableArmorMeta5.setColor(color2);
ITEM_5.setItemMeta(colorableArmorMeta5);
ItemMeta itemMeta6 = ITEM_6.getItemMeta();
ColorableArmorMeta colorableArmorMeta6 = (ColorableArmorMeta) itemMeta6;
colorableArmorMeta6.setColor(color2);
ITEM_6.setItemMeta(colorableArmorMeta6);
ItemMeta itemMeta7 = ITEM_7.getItemMeta();
ColorableArmorMeta colorableArmorMeta7 = (ColorableArmorMeta) itemMeta7;
colorableArmorMeta7.setColor(color2);
ITEM_7.setItemMeta(colorableArmorMeta7);
}
protected boolean stop = false; protected boolean stop = false;
private List<FallingBlock> fallingBlocks = new ArrayList<>();
private BossBar bossBar;
public BomBomEffect(String audience) { public BomBomEffect(String audience) {
super(audience); super(audience);
@ -49,7 +85,7 @@ public class BomBomEffect extends GiftEffect {
World world = game.getWorld(); World world = game.getWorld();
Player player = game.getPlayer(); Player player = game.getPlayer();
bossBar.addPlayer(player); 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);
armorStand1.setBasePlate(false); armorStand1.setBasePlate(false);
@ -68,6 +104,7 @@ public class BomBomEffect extends GiftEffect {
}); });
new BukkitRunnable() { new BukkitRunnable() {
private int count = 0; private int count = 0;
@Override @Override
public void run() { public void run() {
Location loc = armorStand.getLocation().clone().add(0, 8, 0); Location loc = armorStand.getLocation().clone().add(0, 8, 0);
@ -78,7 +115,7 @@ public class BomBomEffect extends GiftEffect {
} }
Random random = new Random(); Random random = new Random();
for (int i = 0; i < 500; i++) { for (int i = 0; i < 500; i++) {
FallingBlock fallingBlock = (FallingBlock) world.spawnEntity(loc, 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);
@ -95,7 +132,7 @@ public class BomBomEffect extends GiftEffect {
} }
Random random = new Random(); Random random = new Random();
for (int i = 0; i < 35; i++) { for (int i = 0; i < 35; i++) {
FallingBlock fallingBlock = (FallingBlock) world.spawnEntity(loc, 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);
@ -107,7 +144,7 @@ public class BomBomEffect extends GiftEffect {
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++) { for (int i = 0; i < 15; i++) {
TNTPrimed tntPrimed = (TNTPrimed) world.spawnEntity(loc, EntityType.TNT, CreatureSpawnEvent.SpawnReason.CUSTOM, (tntEntity)->{ TNTPrimed tntPrimed = (TNTPrimed) world.spawnEntity(loc, EntityType.TNT, CreatureSpawnEvent.SpawnReason.CUSTOM, (tntEntity) -> {
TNTPrimed tntPrimed1 = (TNTPrimed) tntEntity; TNTPrimed tntPrimed1 = (TNTPrimed) tntEntity;
tntPrimed1.setFuseTicks(80); tntPrimed1.setFuseTicks(80);
tntPrimed1.setYield(4); tntPrimed1.setYield(4);
@ -119,6 +156,7 @@ public class BomBomEffect extends GiftEffect {
}.runTaskTimer(Main.plugin, 0L, 15L); }.runTaskTimer(Main.plugin, 0L, 15L);
new BukkitRunnable() { new BukkitRunnable() {
private int count = 0; private int count = 0;
@Override @Override
public void run() { public void run() {
if (stop) { if (stop) {
@ -126,16 +164,17 @@ public class BomBomEffect extends GiftEffect {
return; return;
} }
boolean flag = count % 2 == 0; boolean flag = count % 2 == 0;
armorStand.customName(Component.text(flag? "§4§l毁天灭地" : "§c§l毁天灭地")); armorStand.customName(Component.text(flag ? "§4§l毁天灭地" : "§c§l毁天灭地"));
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毁天灭地"); bossBar.setTitle(flag ? "§4§l毁天灭地" : "§c§l毁天灭地");
count++; count++;
} }
}.runTaskTimer(Main.plugin, 0L, 5L); }.runTaskTimer(Main.plugin, 0L, 5L);
new BukkitRunnable() { new BukkitRunnable() {
private int count = 0; private int count = 0;
@Override @Override
public void run() { public void run() {
if (stop) { if (stop) {
@ -175,41 +214,4 @@ public class BomBomEffect extends GiftEffect {
}.runTaskTimer(Main.plugin, 0L, 1L); }.runTaskTimer(Main.plugin, 0L, 1L);
} }
static {
ITEM_1 = new ItemStack(Material.TNT);
ITEM_2 = new ItemStack(Material.LEATHER_CHESTPLATE);
ITEM_3 = new ItemStack(Material.LEATHER_LEGGINGS);
ITEM_4 = new ItemStack(Material.LEATHER_BOOTS);
ITEM_5 = new ItemStack(Material.LEATHER_CHESTPLATE);
ITEM_6 = new ItemStack(Material.LEATHER_LEGGINGS);
ITEM_7 = new ItemStack(Material.LEATHER_BOOTS);
Color color1 = Color.fromRGB(214, 41, 0);
Color color2 = Color.fromRGB(255, 133, 102);
ItemMeta itemMeta2 = ITEM_2.getItemMeta();
ColorableArmorMeta colorableArmorMeta2 = (ColorableArmorMeta) itemMeta2;
colorableArmorMeta2.setColor(color1);
ITEM_2.setItemMeta(colorableArmorMeta2);
ItemMeta itemMeta3 = ITEM_3.getItemMeta();
ColorableArmorMeta colorableArmorMeta3 = (ColorableArmorMeta) itemMeta3;
colorableArmorMeta3.setColor(color1);
ITEM_3.setItemMeta(colorableArmorMeta3);
ItemMeta itemMeta4 = ITEM_4.getItemMeta();
ColorableArmorMeta colorableArmorMeta4 = (ColorableArmorMeta) itemMeta4;
colorableArmorMeta4.setColor(color1);
ITEM_4.setItemMeta(colorableArmorMeta4);
ItemMeta itemMeta5 = ITEM_5.getItemMeta();
ColorableArmorMeta colorableArmorMeta5 = (ColorableArmorMeta) itemMeta5;
colorableArmorMeta5.setColor(color2);
ITEM_5.setItemMeta(colorableArmorMeta5);
ItemMeta itemMeta6 = ITEM_6.getItemMeta();
ColorableArmorMeta colorableArmorMeta6 = (ColorableArmorMeta) itemMeta6;
colorableArmorMeta6.setColor(color2);
ITEM_6.setItemMeta(colorableArmorMeta6);
ItemMeta itemMeta7 = ITEM_7.getItemMeta();
ColorableArmorMeta colorableArmorMeta7 = (ColorableArmorMeta) itemMeta7;
colorableArmorMeta7.setColor(color2);
ITEM_7.setItemMeta(colorableArmorMeta7);
}
} }

View File

@ -33,6 +33,7 @@ public class ClearInventoryEffect extends GiftEffect {
new BukkitRunnable() { new BukkitRunnable() {
private int totalCount = Math.max(15, getUseableItemCount(player).size()); private int totalCount = Math.max(15, getUseableItemCount(player).size());
private int count = 0; private int count = 0;
@Override @Override
public void run() { public void run() {
if (count > totalCount) { if (count > totalCount) {
@ -44,7 +45,7 @@ public class ClearInventoryEffect extends GiftEffect {
cancel(); cancel();
return; return;
} }
Allay allay = (Allay) world.spawnEntity(player.getLocation().add(0, 1, 0), EntityType.ALLAY, CreatureSpawnEvent.SpawnReason.CUSTOM, (entity)->{ Allay allay = (Allay) world.spawnEntity(player.getLocation().add(0, 1, 0), EntityType.ALLAY, CreatureSpawnEvent.SpawnReason.CUSTOM, (entity) -> {
Allay allay1 = (Allay) entity; Allay allay1 = (Allay) entity;
Vector vector = player.getEyeLocation().getDirection(); Vector vector = player.getEyeLocation().getDirection();
vector.normalize(); vector.normalize();

View File

@ -17,6 +17,7 @@ public class FiveLightningEffect extends GiftEffect {
Player player = game.getPlayer(); Player player = game.getPlayer();
new BukkitRunnable() { new BukkitRunnable() {
private int count = 0; private int count = 0;
@Override @Override
public void run() { public void run() {
if (count > 5) { if (count > 5) {

View File

@ -4,11 +4,7 @@ import com.yaohun.enderdragonwars.effect.GiftEffect;
import com.yaohun.enderdragonwars.game.Game; import com.yaohun.enderdragonwars.game.Game;
import com.yaohun.enderdragonwars.util.ItemStackBuilder; import com.yaohun.enderdragonwars.util.ItemStackBuilder;
import com.yaohun.enderdragonwars.util.RandomUtil; import com.yaohun.enderdragonwars.util.RandomUtil;
import net.kyori.adventure.text.Component; import org.bukkit.*;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
@ -22,13 +18,56 @@ public class LuckyBlockEffect extends GiftEffect {
private static List<ItemStack> itemStacks = new ArrayList<>(); private static List<ItemStack> itemStacks = new ArrayList<>();
public LuckyBlockEffect(String audience) { static {
super(audience); itemStacks.add(new ItemStackBuilder(Material.ENDER_PEARL).setAmount(16).build());
itemStacks.add(new ItemStackBuilder(Material.ENDER_EYE).setAmount(16).build());
itemStacks.add(new ItemStackBuilder(Material.DIAMOND_BLOCK).setAmount(16).build());
itemStacks.add(new ItemStackBuilder(Material.DIAMOND).setAmount(64).build());
itemStacks.add(new ItemStackBuilder(Material.GOLDEN_APPLE).setAmount(16).build());
itemStacks.add(new ItemStackBuilder(Material.ENCHANTED_GOLDEN_APPLE).setAmount(4).build());
itemStacks.add(new ItemStackBuilder(Material.CARROT).setAmount(64).build());
itemStacks.add(new ItemStackBuilder(Material.GOLDEN_CARROT).setAmount(64).build());
itemStacks.add(new ItemStackBuilder(Material.BAKED_POTATO).setAmount(64).build());
itemStacks.add(new ItemStackBuilder(Material.COOKED_BEEF).setAmount(64).build());
itemStacks.add(new ItemStackBuilder(Material.COOKED_CHICKEN).setAmount(64).build());
itemStacks.add(new ItemStackBuilder(Material.COOKED_COD).setAmount(64).build());
itemStacks.add(new ItemStackBuilder(Material.COOKED_MUTTON).setAmount(64).build());
itemStacks.add(new ItemStackBuilder(Material.COOKED_SALMON).setAmount(64).build());
itemStacks.add(new ItemStackBuilder(Material.COOKED_PORKCHOP).setAmount(64).build());
Tag.LOGS.getValues().forEach(material -> itemStacks.add(new ItemStackBuilder(material).setAmount(64).build()));
Tag.ITEMS_AXES.getValues().forEach(material -> itemStacks.add(new ItemStackBuilder(material).build()));
Tag.ITEMS_PICKAXES.getValues().forEach(material -> itemStacks.add(new ItemStackBuilder(material).build()));
Tag.ITEMS_SHOVELS.getValues().forEach(material -> itemStacks.add(new ItemStackBuilder(material).build()));
itemStacks.add(new ItemStackBuilder(Material.DIAMOND_HELMET).build());
itemStacks.add(new ItemStackBuilder(Material.DIAMOND_CHESTPLATE).build());
itemStacks.add(new ItemStackBuilder(Material.DIAMOND_LEGGINGS).build());
itemStacks.add(new ItemStackBuilder(Material.DIAMOND_BOOTS).build());
itemStacks.add(new ItemStackBuilder(Material.DIAMOND_SWORD).build());
itemStacks.add(new ItemStackBuilder(Material.DIAMOND_HELMET).addEnchant(Enchantment.PROTECTION, 1).build());
itemStacks.add(new ItemStackBuilder(Material.DIAMOND_CHESTPLATE).addEnchant(Enchantment.PROTECTION, 1).build());
itemStacks.add(new ItemStackBuilder(Material.DIAMOND_LEGGINGS).addEnchant(Enchantment.PROTECTION, 1).build());
itemStacks.add(new ItemStackBuilder(Material.DIAMOND_BOOTS).addEnchant(Enchantment.PROTECTION, 1).build());
itemStacks.add(new ItemStackBuilder(Material.DIAMOND_SWORD).addEnchant(Enchantment.SHARPNESS, 1).build());
itemStacks.add(new ItemStackBuilder(Material.NETHERITE_HELMET).build());
itemStacks.add(new ItemStackBuilder(Material.NETHERITE_CHESTPLATE).build());
itemStacks.add(new ItemStackBuilder(Material.NETHERITE_LEGGINGS).build());
itemStacks.add(new ItemStackBuilder(Material.NETHERITE_BOOTS).build());
itemStacks.add(new ItemStackBuilder(Material.NETHERITE_SWORD).build());
itemStacks.add(new ItemStackBuilder(Material.NETHERITE_HELMET).addEnchant(Enchantment.PROTECTION, 1).build());
itemStacks.add(new ItemStackBuilder(Material.NETHERITE_CHESTPLATE).addEnchant(Enchantment.PROTECTION, 1).build());
itemStacks.add(new ItemStackBuilder(Material.NETHERITE_LEGGINGS).addEnchant(Enchantment.PROTECTION, 1).build());
itemStacks.add(new ItemStackBuilder(Material.NETHERITE_BOOTS).addEnchant(Enchantment.PROTECTION, 1).build());
itemStacks.add(new ItemStackBuilder(Material.NETHERITE_SWORD).addEnchant(Enchantment.SHARPNESS, 1).build());
} }
@Override public LuckyBlockEffect(String audience) {
public void apply(Game game) { super(audience);
game.getPlayer().getInventory().addItem(new ItemStackBuilder(Material.SPONGE).setDisplayName("§6§l幸运方块").build());
} }
public static void openLuckyBlock(Player player, Block block) { public static void openLuckyBlock(Player player, Block block) {
@ -45,11 +84,9 @@ public class LuckyBlockEffect extends GiftEffect {
item.setGlowing(true); item.setGlowing(true);
} }
static { @Override
itemStacks.add(new ItemStackBuilder(Material.IRON_SWORD).addEnchant(Enchantment.SHARPNESS, 3).build()); public void apply(Game game) {
itemStacks.add(new ItemStackBuilder(Material.IRON_SWORD).addEnchant(Enchantment.SHARPNESS, 3).setDisplayName("§6§l幸运铁剑").build()); game.getPlayer().getInventory().addItem(new ItemStackBuilder(Material.SPONGE).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());
} }
} }

View File

@ -1,15 +1,12 @@
package com.yaohun.enderdragonwars.effect.types; package com.yaohun.enderdragonwars.effect.types;
import com.sk89q.worldedit.world.entity.EntityType;
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.manager.GiftEffectManager; import com.yaohun.enderdragonwars.manager.GiftEffectManager;
import net.kyori.adventure.sound.Sound;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
@ -50,18 +47,19 @@ public class RandomBox extends GiftEffect {
String eventName = stringList.get(random.nextInt(stringList.size())); String eventName = stringList.get(random.nextInt(stringList.size()));
BukkitTask task = new BukkitRunnable() { BukkitTask task = new BukkitRunnable() {
private int i = 0; private int i = 0;
@Override @Override
public void run() { public void run() {
if (i >= 12) { if (i >= 12) {
player.sendTitle("§6随机盲盒","§9整蛊效果: §e"+eventName); player.sendTitle("§6随机盲盒", "§9整蛊效果: §e" + eventName);
player.playSound(player.getLocation(),Sound.BLOCK_COMPARATOR_CLICK,1,1); player.playSound(player.getLocation(), Sound.BLOCK_COMPARATOR_CLICK, 1, 1);
GiftEffectManager.addGiftEffect(getAudience(),eventName); GiftEffectManager.addGiftEffect(getAudience(), eventName);
Bukkit.broadcastMessage("§c[消息]§a随机盲盒抽中了 §e"+eventName); Bukkit.broadcastMessage("§c[消息]§a随机盲盒抽中了 §e" + eventName);
cancel(); cancel();
return; return;
} }
player.sendTitle("§6随机盲盒","§9整蛊效果: §e"+stringList.get(random.nextInt(stringList.size()))); player.sendTitle("§6随机盲盒", "§9整蛊效果: §e" + stringList.get(random.nextInt(stringList.size())));
player.playSound(player.getLocation(),Sound.BLOCK_COMPARATOR_CLICK,1,1); player.playSound(player.getLocation(), Sound.BLOCK_COMPARATOR_CLICK, 1, 1);
i++; i++;
} }
}.runTaskTimer(Main.plugin, 0L, 5L); }.runTaskTimer(Main.plugin, 0L, 5L);

View File

@ -1,5 +1,6 @@
package com.yaohun.enderdragonwars.effect.types; package com.yaohun.enderdragonwars.effect.types;
import com.yaohun.enderdragonwars.Main;
import com.yaohun.enderdragonwars.data.Region; import com.yaohun.enderdragonwars.data.Region;
import com.yaohun.enderdragonwars.effect.GiftEffect; import com.yaohun.enderdragonwars.effect.GiftEffect;
import com.yaohun.enderdragonwars.game.Game; import com.yaohun.enderdragonwars.game.Game;
@ -30,6 +31,7 @@ public class SpawnEnderPortalEffect extends GiftEffect {
int platformWidth = 3; int platformWidth = 3;
int platformLength = 7; int platformLength = 7;
int levelAmount = 15; int levelAmount = 15;
Main.game.takeLiveTime(60 * 6);
World world = game.getWorld(); World world = game.getWorld();
Player player = game.getPlayer(); Player player = game.getPlayer();
Location location = player.getLocation(); Location location = player.getLocation();

View File

@ -4,7 +4,6 @@ import com.yaohun.enderdragonwars.effect.GiftEffect;
import com.yaohun.enderdragonwars.game.Game; import com.yaohun.enderdragonwars.game.Game;
import com.yaohun.enderdragonwars.util.RandomUtil; import com.yaohun.enderdragonwars.util.RandomUtil;
import org.bukkit.entity.Creeper; import org.bukkit.entity.Creeper;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Zombie; import org.bukkit.entity.Zombie;
@ -19,13 +18,13 @@ public class SummonMobs extends GiftEffect {
@Override @Override
public void apply(Game game) { public void apply(Game game) {
Player player = game.getPlayer(); Player player = game.getPlayer();
for (int i = 0; i < 5;i++){ for (int i = 0; i < 5; i++) {
Zombie zombie = (Zombie) player.getWorld().spawnEntity(player.getLocation(), EntityType.ZOMBIE); Zombie zombie = (Zombie) player.getWorld().spawnEntity(player.getLocation(), EntityType.ZOMBIE);
zombie.setVelocity(new Vector(RandomUtil.getRandomDouble(-1,1,1),RandomUtil.getRandomDouble(-1,1,1),RandomUtil.getRandomDouble(-1,1,1))); zombie.setVelocity(new Vector(RandomUtil.getRandomDouble(-1, 1, 1), RandomUtil.getRandomDouble(-1, 1, 1), RandomUtil.getRandomDouble(-1, 1, 1)));
} }
for (int i = 0; i < 5;i++){ for (int i = 0; i < 5; i++) {
Creeper creeper = (Creeper) player.getWorld().spawnEntity(player.getLocation(), EntityType.CREEPER); Creeper creeper = (Creeper) player.getWorld().spawnEntity(player.getLocation(), EntityType.CREEPER);
creeper.setVelocity(new Vector(RandomUtil.getRandomDouble(-1,1,1),RandomUtil.getRandomDouble(-1,1,1),RandomUtil.getRandomDouble(-1,1,1))); creeper.setVelocity(new Vector(RandomUtil.getRandomDouble(-1, 1, 1), RandomUtil.getRandomDouble(-1, 1, 1), RandomUtil.getRandomDouble(-1, 1, 1)));
} }
} }

View File

@ -17,11 +17,13 @@ public class ToHeavenEffect extends GiftEffect {
public void apply(Game game) { public void apply(Game game) {
Player player = game.getPlayer(); Player player = game.getPlayer();
double radius = 1.5D; double radius = 1.5D;
Main.game.takeLiveTime(60);
new BukkitRunnable() { new BukkitRunnable() {
private int count = 0; private int count = 0;
private double angle = 0; private double angle = 0;
private double speed = 1.25; private double speed = 1.25;
private int skyTnt = 0; private int skyTnt = 0;
@Override @Override
public void run() { public void run() {
if (count >= 200) { if (count >= 200) {

View File

@ -1,19 +1,16 @@
package com.yaohun.enderdragonwars.effect.types; package com.yaohun.enderdragonwars.effect.types;
import com.sk89q.worldedit.world.entity.EntityType;
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.RandomUtil; import org.bukkit.Effect;
import net.kyori.adventure.sound.Sound;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Creeper; import org.bukkit.Sound;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.Zombie;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
public class WuHuJump extends GiftEffect { public class WuHuJump extends GiftEffect {
@ -28,18 +25,21 @@ public class WuHuJump extends GiftEffect {
player.playEffect(player.getLocation(), Effect.MOBSPAWNER_FLAMES, 10); player.playEffect(player.getLocation(), Effect.MOBSPAWNER_FLAMES, 10);
player.playSound(player.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 1.0F, 1.0F); player.playSound(player.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 1.0F, 1.0F);
BukkitTask task = new BukkitRunnable() { BukkitTask task = new BukkitRunnable() {
private int i= 0; private int i = 0;
@Override @Override
public void run() { public void run() {
if(i >= 4){cancel();} if (i >= 4) {
cancel();
}
Location location = player.getLocation(); Location location = player.getLocation();
TNTPrimed tntPrimed = (TNTPrimed) location.getWorld().spawnEntity(location.clone().add(0,-0.5,0), EntityType.PRIMED_TNT); TNTPrimed tntPrimed = (TNTPrimed) location.getWorld().spawnEntity(location.clone().add(0, -0.5, 0), EntityType.TNT);
tntPrimed.setFuseTicks(5); tntPrimed.setFuseTicks(5);
tntPrimed.setYield(0.0F); tntPrimed.setYield(0.0F);
location.getWorld().playSound(location, Sound.ENTITY_CREEPER_PRIMED, 1.0f, 1.0f); location.getWorld().playSound(location, Sound.ENTITY_CREEPER_PRIMED, 1.0f, 1.0f);
i++; i++;
} }
}.runTaskTimer(Main.plugin, 2L,1L); }.runTaskTimer(Main.plugin, 2L, 1L);
game.addTasks(task); game.addTasks(task);
} }

View File

@ -26,7 +26,9 @@ public class Game {
private boolean startd; private boolean startd;
private long liveTime; private long liveTime;
private List<BukkitTask> tasks = new ArrayList<>(); private List<BukkitTask> tasks = new ArrayList<>();
public Game(){ private int tragetCueI = 0;
public Game() {
bossBar1 = Bukkit.createBossBar("下播时间", BarColor.WHITE, BarStyle.SEGMENTED_20); bossBar1 = Bukkit.createBossBar("下播时间", BarColor.WHITE, BarStyle.SEGMENTED_20);
bossBar2 = Bukkit.createBossBar("挑战目标", BarColor.WHITE, BarStyle.SOLID); bossBar2 = Bukkit.createBossBar("挑战目标", BarColor.WHITE, BarStyle.SOLID);
} }
@ -36,7 +38,7 @@ public class Game {
targetCueBossBar(); targetCueBossBar();
// 获取最大时间 // 获取最大时间
long maxLiveTime = 1000 * 60 * 60 * 6; long maxLiveTime = 1000 * 60 * 60 * 6;
double d = (double) getLiveTime() / (double)maxLiveTime; double d = (double) getLiveTime() / (double) maxLiveTime;
d = Math.max(0, Math.min(d, 1)); d = Math.max(0, Math.min(d, 1));
long liveTimeInSeconds = getLiveTime() / 1000; long liveTimeInSeconds = getLiveTime() / 1000;
long hours = liveTimeInSeconds / 3600; long hours = liveTimeInSeconds / 3600;
@ -51,14 +53,13 @@ public class Game {
} else { } else {
bossBar1.setTitle("§a§l恭喜您完成挑战下播吧"); bossBar1.setTitle("§a§l恭喜您完成挑战下播吧");
} }
BossBarUtil.setBarProgress(bossBar1,d); BossBarUtil.setBarProgress(bossBar1, d);
BossBarUtil.setBarColor(bossBar1,d); BossBarUtil.setBarColor(bossBar1, d);
} }
private int tragetCueI = 0; public void targetCueBossBar() {
public void targetCueBossBar(){
tragetCueI--; tragetCueI--;
if(tragetCueI <= 0) { if (tragetCueI <= 0) {
bossBar2.addPlayer(player); bossBar2.addPlayer(player);
List<String> stringList = new ArrayList<>(); List<String> stringList = new ArrayList<>();
stringList.add("§c§l击败末影龙 §b§l减播1小时"); stringList.add("§c§l击败末影龙 §b§l减播1小时");
@ -68,8 +69,8 @@ public class Game {
bossBar2.setTitle(titleShow); bossBar2.setTitle(titleShow);
BossBarUtil.setBarColor(bossBar2); BossBarUtil.setBarColor(bossBar2);
tragetCueI = 20; tragetCueI = 20;
}else{ } else {
if(tragetCueI == 16) { if (tragetCueI == 16) {
if (bossBar2.getPlayers().contains(player)) { if (bossBar2.getPlayers().contains(player)) {
bossBar2.removePlayer(player); bossBar2.removePlayer(player);
} }
@ -78,7 +79,9 @@ public class Game {
} }
public void startGame(Player player) { public void startGame(Player player) {
if(startd){return;} if (startd) {
return;
}
this.player = player; this.player = player;
this.startd = true; this.startd = true;
this.world = player.getWorld(); this.world = player.getWorld();
@ -101,14 +104,15 @@ public class Game {
public World getWorld() { public World getWorld() {
return world; return world;
} }
public void updataPlayerData(Player player){
public void updataPlayerData(Player player) {
player.setFoodLevel(20); player.setFoodLevel(20);
player.setGameMode(GameMode.SURVIVAL); player.setGameMode(GameMode.SURVIVAL);
bossBar1.addPlayer(player); bossBar1.addPlayer(player);
bossBar2.addPlayer(player); bossBar2.addPlayer(player);
} }
public void removePlayerDataBossBar(){ public void removePlayerDataBossBar() {
bossBar1.removeAll(); bossBar1.removeAll();
bossBar2.removeAll(); bossBar2.removeAll();
bossBar1 = Bukkit.createBossBar("下播时间", BarColor.WHITE, BarStyle.SEGMENTED_20); bossBar1 = Bukkit.createBossBar("下播时间", BarColor.WHITE, BarStyle.SEGMENTED_20);
@ -119,29 +123,31 @@ public class Game {
return startd; return startd;
} }
public void addTasks(BukkitTask task){ public void addTasks(BukkitTask task) {
this.tasks.add(task); this.tasks.add(task);
} }
public long getLiveTime() { public long getLiveTime() {
return liveTime; return liveTime;
} }
public void setLiveTime(long liveTime) { public void setLiveTime(long liveTime) {
this.liveTime = liveTime; this.liveTime = liveTime;
} }
public void takeLiveTime(long minutes){ public void takeLiveTime(long minutes) {
long minutesTime = 1000 * 60 * minutes; long minutesTime = 1000 * 60 * minutes;
long newTime = getLiveTime() - minutesTime; long newTime = getLiveTime() - minutesTime;
if(newTime < 0){ if (newTime < 0) {
newTime = 0; newTime = 0;
} }
setLiveTime(newTime); setLiveTime(newTime);
} }
public void addLiveTime(long minutes){ public void addLiveTime(long minutes) {
long minutesTime = 1000 * 60 * minutes; long minutesTime = 1000 * 60 * minutes;
long newTime = getLiveTime() + minutesTime; long newTime = getLiveTime() + minutesTime;
if(newTime < 0){ if (newTime < 0) {
newTime = 0; newTime = 0;
} }
setLiveTime(newTime); setLiveTime(newTime);

View File

@ -15,7 +15,7 @@ import org.bukkit.scheduler.BukkitRunnable;
public class GameListener implements Listener { public class GameListener implements Listener {
@EventHandler @EventHandler
public void onPing(ServerListPingEvent e){ public void onPing(ServerListPingEvent e) {
e.setMotd("§a整蛊模式: §6生存挑战 §a当前版本: §6常规版 §b运行中"); e.setMotd("§a整蛊模式: §6生存挑战 §a当前版本: §6常规版 §b运行中");
} }
@ -34,22 +34,22 @@ public class GameListener implements Listener {
} }
@EventHandler @EventHandler
public void onQuit(PlayerQuitEvent e){ public void onQuit(PlayerQuitEvent e) {
Player p = e.getPlayer(); Player p = e.getPlayer();
Main.game.removePlayerDataBossBar(); Main.game.removePlayerDataBossBar();
} }
@EventHandler @EventHandler
public void onKick(PlayerKickEvent e){ public void onKick(PlayerKickEvent e) {
Player p = e.getPlayer(); Player p = e.getPlayer();
Main.game.removePlayerDataBossBar( ); Main.game.removePlayerDataBossBar();
} }
@EventHandler @EventHandler
public void onPick(PlayerDropItemEvent e){ public void onPick(PlayerDropItemEvent e) {
Player p = e.getPlayer(); Player p = e.getPlayer();
if (Main.game.isStartd()) { if (Main.game.isStartd()) {
if(p.isSneaking()){ if (p.isSneaking()) {
e.setCancelled(true); e.setCancelled(true);
RepairGiftGui.OpenGui(p); RepairGiftGui.OpenGui(p);
} }
@ -65,19 +65,20 @@ public class GameListener implements Listener {
Player p = e.getEntity(); Player p = e.getEntity();
new BukkitRunnable() { new BukkitRunnable() {
private int i = 0; private int i = 0;
public void run() { public void run() {
if (i == 1) { if (i == 1) {
p.spigot().respawn(); p.spigot().respawn();
} }
// 增加游戏时间5分钟 // 增加游戏时间5分钟
if(i == 3) { if (i == 3) {
Main.game.addLiveTime(5); Main.game.addLiveTime(5);
p.sendTitle("§4你嘎了", "§e加播5分钟"); p.sendTitle("§4你嘎了", "§e加播5分钟");
cancel(); cancel();
} }
i++; i++;
} }
}.runTaskTimer(Main.plugin,0L, 2L); }.runTaskTimer(Main.plugin, 0L, 2L);
} }
} }

View File

@ -1,9 +1,7 @@
package com.yaohun.enderdragonwars.listener; package com.yaohun.enderdragonwars.listener;
import com.yaohun.enderdragonwars.effect.types.LuckyBlockEffect; import com.yaohun.enderdragonwars.effect.types.LuckyBlockEffect;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.IronGolem; import org.bukkit.entity.IronGolem;
@ -13,7 +11,6 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.PlayerInventory;

View File

@ -2,7 +2,6 @@ package com.yaohun.enderdragonwars.listener;
import com.yaohun.enderdragonwars.Main; import com.yaohun.enderdragonwars.Main;
import com.yaohun.enderdragonwars.data.GiftData; import com.yaohun.enderdragonwars.data.GiftData;
import com.yaohun.enderdragonwars.liveevent.GiftEventHandler;
import com.yaohun.enderdragonwars.manager.GiftEffectManager; import com.yaohun.enderdragonwars.manager.GiftEffectManager;
import com.yaohun.enderdragonwars.util.GameUtil; import com.yaohun.enderdragonwars.util.GameUtil;
import com.yaohun.enderdragonwars.util.RandomUtil; import com.yaohun.enderdragonwars.util.RandomUtil;
@ -27,66 +26,9 @@ public class RepairGiftGui implements Listener {
public static String invTitle = "我的世界整蛊 - 礼物触发管理"; public static String invTitle = "我的世界整蛊 - 礼物触发管理";
@EventHandler public static void OpenGui(Player p) {
public void onClick(InventoryClickEvent e){ Inventory inv = Bukkit.createInventory(null, 27, invTitle);
int rawSlot = e.getRawSlot(); HashMap<String, ItemStack> hashMap = new HashMap<>();
Player zhubo = (Player) e.getWhoClicked();
Inventory inv = e.getInventory();
if(e.getView().getTitle().equalsIgnoreCase(invTitle)){
if(rawSlot >= 0) {
e.setCancelled(true);
zhubo.closeInventory();
ItemStack stack = e.getCurrentItem();
if (stack != null && stack.getType() != Material.AIR) {
NBTItem nbti = new NBTItem(stack);
if (nbti.hasKey("giftName")) {
String giftName = nbti.getString("giftName");
String userName = "抖音"+ RandomUtil.getRandomInt(1,100);
int amount = 1;
if (e.getClick() == ClickType.RIGHT) {
amount = 10;
} else if (e.getClick() == ClickType.SHIFT_LEFT) {
amount = 66;
}else if (e.getClick() == ClickType.SHIFT_RIGHT) {
amount = 188;
}
if(Main.gameManager.getGiftData(giftName) == null){
zhubo.sendTitle("§r", "§c未设置效果",10, 30, 10);
return;
}
GiftData giftData = Main.gameManager.getGiftData(giftName);
String hide_userName = GameUtil.hideName(userName);
String eventName = giftData.getEvent();
String eventName_Show = eventName;
if(amount >= 2) {
String title = "§c" + eventName_Show + " x" + amount;
String subtitle = "§9" + hide_userName;
zhubo.sendTitle(title, subtitle,0, 30, 10);
}else{
String title = "§c" + eventName_Show;
String subtitle = "§9" + hide_userName;
zhubo.sendTitle(title, subtitle,0, 30, 10);
}
if (amount <= 1) {
giftData.playSoundEvent();
GiftEffectManager.addGiftEffect(hide_userName, eventName);
} else {
for (int i = 0; i < amount; i++) {
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
giftData.playSoundEvent();
GiftEffectManager.addGiftEffect(hide_userName, eventName);
}, (long) i * 5);
}
}
}
}
}
}
}
public static void OpenGui(Player p){
Inventory inv = Bukkit.createInventory(null,27,invTitle);
HashMap<String,ItemStack> hashMap = new HashMap<>();
hashMap.put("ONE礼挑一", stackGift("ONE礼挑一", 1)); hashMap.put("ONE礼挑一", stackGift("ONE礼挑一", 1));
hashMap.put("Thuglife", stackGift("Thuglife", 2)); hashMap.put("Thuglife", stackGift("Thuglife", 2));
hashMap.put("爱的纸鹤", stackGift("爱的纸鹤", 3)); hashMap.put("爱的纸鹤", stackGift("爱的纸鹤", 3));
@ -145,17 +87,17 @@ public class RepairGiftGui implements Listener {
hashMap.put("蝶 · 比翼鸟", stackGift("蝶 · 比翼鸟", 56)); hashMap.put("蝶 · 比翼鸟", stackGift("蝶 · 比翼鸟", 56));
hashMap.put("永生花", stackGift("永生花", 57)); hashMap.put("永生花", stackGift("永生花", 57));
Map<String, GiftData> giftData = Main.gameManager.getGiftDataMap(); Map<String, GiftData> giftData = Main.gameManager.getGiftDataMap();
for (String giftName : giftData.keySet()){ for (String giftName : giftData.keySet()) {
if(hashMap.get(giftName) != null){ if (hashMap.get(giftName) != null) {
inv.addItem(hashMap.get(giftName)); inv.addItem(hashMap.get(giftName));
}else{ } else {
inv.addItem(stackGift(giftName,-1)); inv.addItem(stackGift(giftName, -1));
} }
} }
p.openInventory(inv); p.openInventory(inv);
} }
public static ItemStack stackGift(String name,int model_id) { public static ItemStack stackGift(String name, int model_id) {
ItemStack item = new ItemStack(Material.PAPER); ItemStack item = new ItemStack(Material.PAPER);
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§d§l★ §e礼物: " + name); meta.setDisplayName("§d§l★ §e礼物: " + name);
@ -172,15 +114,72 @@ public class RepairGiftGui implements Listener {
lore.add("§b§l★ §6SHIFT+左键 §7召唤66次"); lore.add("§b§l★ §6SHIFT+左键 §7召唤66次");
lore.add("§b§l★ §6SHIFT+右键 §7召唤188次"); lore.add("§b§l★ §6SHIFT+右键 §7召唤188次");
meta.setLore(lore); meta.setLore(lore);
if (model_id >= 1){ if (model_id >= 1) {
meta.setCustomModelData(model_id); meta.setCustomModelData(model_id);
}else{ } else {
item.setType(Material.DIAMOND); item.setType(Material.DIAMOND);
} }
item.setItemMeta(meta); item.setItemMeta(meta);
NBTItem nbti = new NBTItem(item); NBTItem nbti = new NBTItem(item);
nbti.setString("giftName",name); nbti.setString("giftName", name);
item = nbti.getItem(); item = nbti.getItem();
return item; return item;
} }
@EventHandler
public void onClick(InventoryClickEvent e) {
int rawSlot = e.getRawSlot();
Player zhubo = (Player) e.getWhoClicked();
Inventory inv = e.getInventory();
if (e.getView().getTitle().equalsIgnoreCase(invTitle)) {
if (rawSlot >= 0) {
e.setCancelled(true);
zhubo.closeInventory();
ItemStack stack = e.getCurrentItem();
if (stack != null && stack.getType() != Material.AIR) {
NBTItem nbti = new NBTItem(stack);
if (nbti.hasKey("giftName")) {
String giftName = nbti.getString("giftName");
String userName = "抖音" + RandomUtil.getRandomInt(1, 100);
int amount = 1;
if (e.getClick() == ClickType.RIGHT) {
amount = 10;
} else if (e.getClick() == ClickType.SHIFT_LEFT) {
amount = 66;
} else if (e.getClick() == ClickType.SHIFT_RIGHT) {
amount = 188;
}
if (Main.gameManager.getGiftData(giftName) == null) {
zhubo.sendTitle("§r", "§c未设置效果", 10, 30, 10);
return;
}
GiftData giftData = Main.gameManager.getGiftData(giftName);
String hide_userName = GameUtil.hideName(userName);
String eventName = giftData.getEvent();
String eventName_Show = eventName;
if (amount >= 2) {
String title = "§c" + eventName_Show + " x" + amount;
String subtitle = "§9" + hide_userName;
zhubo.sendTitle(title, subtitle, 0, 30, 10);
} else {
String title = "§c" + eventName_Show;
String subtitle = "§9" + hide_userName;
zhubo.sendTitle(title, subtitle, 0, 30, 10);
}
if (amount <= 1) {
giftData.playSoundEvent();
GiftEffectManager.addGiftEffect(hide_userName, eventName);
} else {
for (int i = 0; i < amount; i++) {
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
giftData.playSoundEvent();
GiftEffectManager.addGiftEffect(hide_userName, eventName);
}, (long) i * 5);
}
}
}
}
}
}
}
} }

View File

@ -26,14 +26,14 @@ public class GameManager {
FileConfiguration yml = YamlConfiguration.loadConfiguration(file); FileConfiguration yml = YamlConfiguration.loadConfiguration(file);
Bukkit.getConsoleSender().sendMessage("[日志 - 末影龙挑战] 事件注册:"); Bukkit.getConsoleSender().sendMessage("[日志 - 末影龙挑战] 事件注册:");
this.dianzanNeed = 100; this.dianzanNeed = 100;
if(yml.getInt("点赞整蛊.点赞次数") >= 1){ if (yml.getInt("点赞整蛊.点赞次数") >= 1) {
this.dianzanNeed = yml.getInt("点赞整蛊.点赞次数"); this.dianzanNeed = yml.getInt("点赞整蛊.点赞次数");
} }
this.eventName = "怪物来袭"; this.eventName = "怪物来袭";
if(yml.getString("点赞整蛊.效果") != null){ if (yml.getString("点赞整蛊.效果") != null) {
this.eventName = yml.getString("点赞整蛊.效果"); this.eventName = yml.getString("点赞整蛊.效果");
} }
Bukkit.getConsoleSender().sendMessage("事件: "+this.getDianzan_event()+" 条件: 点赞x"+this.getDianzan_need()); Bukkit.getConsoleSender().sendMessage("事件: " + this.getDianzan_event() + " 条件: 点赞x" + this.getDianzan_need());
ConfigurationSection section = yml.getConfigurationSection("礼物设置"); ConfigurationSection section = yml.getConfigurationSection("礼物设置");
if (section == null) { if (section == null) {
System.out.println("[错误 - 游戏] 礼物设置错误,请检查文件."); System.out.println("[错误 - 游戏] 礼物设置错误,请检查文件.");
@ -62,13 +62,16 @@ public class GameManager {
public String getDianzan_event() { public String getDianzan_event() {
return this.eventName; return this.eventName;
} }
public int getDianzan_amount() { public int getDianzan_amount() {
return dianzan; return dianzan;
} }
public void addDianzan_amount(int add_amount){
setDianzan_amount(getDianzan_amount()+add_amount);
}
public void setDianzan_amount(int dianzan_amount) { public void setDianzan_amount(int dianzan_amount) {
this.dianzan = dianzan_amount; this.dianzan = dianzan_amount;
} }
public void addDianzan_amount(int add_amount) {
setDianzan_amount(getDianzan_amount() + add_amount);
}
} }

View File

@ -8,8 +8,8 @@ import java.util.List;
public class BossBarUtil { public class BossBarUtil {
public static void setBarColor(BossBar bossBar){ public static void setBarColor(BossBar bossBar) {
double random = RandomUtil.getRandomDouble(0,1,1); double random = RandomUtil.getRandomDouble(0, 1, 1);
if (random >= 0 && random <= 0.2) { if (random >= 0 && random <= 0.2) {
bossBar.setColor(BarColor.RED); bossBar.setColor(BarColor.RED);
} else if (random <= 0.4) { } else if (random <= 0.4) {
@ -23,7 +23,7 @@ public class BossBarUtil {
} }
} }
public static void setBarColor(BossBar bossBar,double percent){ public static void setBarColor(BossBar bossBar, double percent) {
if (percent >= 0 && percent <= 0.3333) { if (percent >= 0 && percent <= 0.3333) {
bossBar.setColor(BarColor.RED); bossBar.setColor(BarColor.RED);
} else if (percent <= 0.6666) { } else if (percent <= 0.6666) {
@ -32,7 +32,8 @@ public class BossBarUtil {
bossBar.setColor(BarColor.GREEN); bossBar.setColor(BarColor.GREEN);
} }
} }
public static void setBarProgress(BossBar bossBar,double percent){
public static void setBarProgress(BossBar bossBar, double percent) {
if (percent <= 0) { if (percent <= 0) {
percent = 0; percent = 0;
} else if (percent >= 1) { } else if (percent >= 1) {
@ -41,13 +42,13 @@ public class BossBarUtil {
bossBar.setProgress(percent); bossBar.setProgress(percent);
} }
public static void addBossBar(Player player, List<BossBar> bossBarList){ public static void addBossBar(Player player, List<BossBar> bossBarList) {
for (BossBar bossBar : bossBarList) { for (BossBar bossBar : bossBarList) {
bossBar.addPlayer(player); bossBar.addPlayer(player);
} }
} }
public static void removeBossBar(Player player,List<BossBar> bossBarList){ public static void removeBossBar(Player player, List<BossBar> bossBarList) {
for (BossBar bossBar : bossBarList) { for (BossBar bossBar : bossBarList) {
bossBar.removePlayer(player); bossBar.removePlayer(player);
} }

View File

@ -11,11 +11,11 @@ import org.bukkit.block.data.type.EndPortalFrame;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.Arrays;
import java.util.List; import java.util.List;
public class BuildSpawner { public class BuildSpawner {
protected ISpawnModeHander spawnModeHander;
private World world; private World world;
private Direction initialDirection; private Direction initialDirection;
private int originX; private int originX;
@ -29,16 +29,12 @@ public class BuildSpawner {
private int platformLength; private int platformLength;
private int levelAmount; private int levelAmount;
private SpawnMode spawnMode; private SpawnMode spawnMode;
private int nowX; private int nowX;
private int nowY; private int nowY;
private int nowZ; private int nowZ;
private Direction nowDirection; private Direction nowDirection;
private List<Material> materials; 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) { 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.world = world;
this.initialDirection = initialDirection; this.initialDirection = initialDirection;
@ -176,6 +172,22 @@ public class BuildSpawner {
nowDirection = nowDirection.getRightDirection(); nowDirection = nowDirection.getRightDirection();
} }
public Region getEffectiveRegion(World world) {
return spawnModeHander.getEffectiveRegion(world);
}
public int getHeight() {
return spawnModeHander.getHeight();
}
public void setInitialDirection(Direction initialDirection) {
this.initialDirection = initialDirection;
}
public Material getRandomMaterial() {
return materials.get(RandomUtil.getRandomInt(0, materials.size() - 1));
}
private enum TransformType { private enum TransformType {
PLATFORM, PLATFORM,
LADDER LADDER
@ -226,14 +238,6 @@ public class BuildSpawner {
} }
public Region getEffectiveRegion(World world) {
return spawnModeHander.getEffectiveRegion(world);
}
public int getHeight() {
return spawnModeHander.getHeight();
}
public enum SpawnMode { public enum SpawnMode {
MODE_1, MODE_1,
@ -241,11 +245,20 @@ public class BuildSpawner {
} }
private interface ISpawnModeHander {
void spawn();
Region getEffectiveRegion(World world);
int getHeight();
}
private class SpawnModeHandler_1 implements ISpawnModeHander { private class SpawnModeHandler_1 implements ISpawnModeHander {
@Override @Override
public void spawn() { public void spawn() {
new BukkitRunnable() { new BukkitRunnable() {
private int count = 0; private int count = 0;
@Override @Override
public void run() { public void run() {
if (count >= levelAmount) { if (count >= levelAmount) {
@ -329,6 +342,7 @@ public class BuildSpawner {
public void spawn() { public void spawn() {
new BukkitRunnable() { new BukkitRunnable() {
private int count = 0; private int count = 0;
@Override @Override
public void run() { public void run() {
if (count >= levelAmount) { if (count >= levelAmount) {
@ -377,7 +391,7 @@ public class BuildSpawner {
minZ += (platformLength * chunkLength) * initialDirection.getPlatformVector().getBlockZ(); minZ += (platformLength * chunkLength) * initialDirection.getPlatformVector().getBlockZ();
minZ += (ladderAmount * chunkLength) * initialDirection.getLadderVector().getBlockZ(); minZ += (ladderAmount * chunkLength) * initialDirection.getLadderVector().getBlockZ();
minZ += (platformWidth * chunkWight) * initialDirection.getRightDirection().getPlatformVector().getBlockZ(); minZ += (platformWidth * chunkWight) * initialDirection.getRightDirection().getPlatformVector().getBlockZ();
int maxX = originX + ladderAmount * ladderLength * chunkLength * initialDirection.getLadderVector().getBlockX() + (platformWidth * chunkWight) * initialDirection.getPlatformVector().getBlockX()+ 1; int maxX = originX + ladderAmount * ladderLength * chunkLength * initialDirection.getLadderVector().getBlockX() + (platformWidth * chunkWight) * initialDirection.getPlatformVector().getBlockX() + 1;
int maxZ = originZ; int maxZ = originZ;
int maxY = originY + levelAmount * 5 + 1; int maxY = originY + levelAmount * 5 + 1;
return new Region(world, new Point(minX, originY, minZ), new Point(maxX, maxY, maxZ)); return new Region(world, new Point(minX, originY, minZ), new Point(maxX, maxY, maxZ));
@ -388,7 +402,7 @@ public class BuildSpawner {
minX += (ladderAmount * chunkLength) * initialDirection.getLadderVector().getBlockX(); minX += (ladderAmount * chunkLength) * initialDirection.getLadderVector().getBlockX();
minX += (platformWidth * chunkWight) * initialDirection.getRightDirection().getPlatformVector().getBlockX(); minX += (platformWidth * chunkWight) * initialDirection.getRightDirection().getPlatformVector().getBlockX();
int maxX = originX; int maxX = originX;
int maxZ = originZ + ladderAmount * ladderLength * chunkLength * initialDirection.getLadderVector().getBlockZ() + (platformWidth * chunkWight) * initialDirection.getPlatformVector().getBlockZ()+ 1; int maxZ = originZ + ladderAmount * ladderLength * chunkLength * initialDirection.getLadderVector().getBlockZ() + (platformWidth * chunkWight) * initialDirection.getPlatformVector().getBlockZ() + 1;
int maxY = originY + levelAmount * 5 + 1; int maxY = originY + levelAmount * 5 + 1;
return new Region(world, new Point(minX, originY, minZ), new Point(maxX, maxY, maxZ)); return new Region(world, new Point(minX, originY, minZ), new Point(maxX, maxY, maxZ));
} }
@ -443,20 +457,4 @@ public class BuildSpawner {
} }
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));
}
} }

View File

@ -6,7 +6,7 @@ import org.bukkit.util.Vector;
public class EntityUtil { public class EntityUtil {
public static void shoot(Entity entity, double p_37266_, double p_37267_, double p_37268_, float p_37269_, float p_37270_) { public static void shoot(Entity entity, double p_37266_, double p_37267_, double p_37268_, float p_37269_, float p_37270_) {
Vector vec3 = new Vector(p_37266_, p_37267_, p_37268_).normalize().add(new Vector(RandomUtil.triangle(0.0D, 0.0172275D * (double)p_37270_), RandomUtil.triangle(0.0D, 0.0172275D * (double)p_37270_), RandomUtil.triangle(0.0D, 0.0172275D * (double)p_37270_))).multiply(p_37269_); Vector vec3 = new Vector(p_37266_, p_37267_, p_37268_).normalize().add(new Vector(RandomUtil.triangle(0.0D, 0.0172275D * (double) p_37270_), RandomUtil.triangle(0.0D, 0.0172275D * (double) p_37270_), RandomUtil.triangle(0.0D, 0.0172275D * (double) p_37270_))).multiply(p_37269_);
entity.setVelocity(vec3); entity.setVelocity(vec3);
} }

View File

@ -25,7 +25,8 @@ public class GameUtil {
} }
} }
} }
public static boolean specialGiftEffectTriggers(Player player,String eventName,String show_userName,int amount) {
public static boolean specialGiftEffectTriggers(Player player, String eventName, String show_userName, int amount) {
if (eventName.contains("盲盒")) { if (eventName.contains("盲盒")) {
if (eventName.contains("#")) { if (eventName.contains("#")) {
String s1 = "love"; String s1 = "love";

View File

@ -1,6 +1,8 @@
package com.yaohun.enderdragonwars.util; package com.yaohun.enderdragonwars.util;
import org.bukkit.*; import org.bukkit.ChatColor;
import org.bukkit.FireworkEffect;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier; import org.bukkit.attribute.AttributeModifier;
import org.bukkit.block.banner.Pattern; import org.bukkit.block.banner.Pattern;
@ -11,7 +13,6 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.FireworkMeta; import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@ -75,6 +76,29 @@ public class ItemStackBuilder {
this.fireworkEffects = new ArrayList<>(); this.fireworkEffects = new ArrayList<>();
} }
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;
}
public ItemStack build() { public ItemStack build() {
ItemStack item = new ItemStack(type, amount); ItemStack item = new ItemStack(type, amount);
item.setType(type); item.setType(type);
@ -115,26 +139,66 @@ public class ItemStackBuilder {
return amount; return amount;
} }
public ItemStackBuilder setAmount(int amount) {
this.amount = amount;
return this;
}
public Material getType() { public Material getType() {
return type; return type;
} }
public ItemStackBuilder setType(Material type) {
this.type = type;
return this;
}
public List<String> getLore() { public List<String> getLore() {
return lore; return lore;
} }
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 int getCustomModelData() { public int getCustomModelData() {
return customModelData; return customModelData;
} }
public ItemStackBuilder setCustomModelData(int customModelData) {
this.customModelData = customModelData;
return this;
}
public Map<Enchantment, Integer> getEnchants() { public Map<Enchantment, Integer> getEnchants() {
return enchants; return enchants;
} }
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 Set<ItemFlag> getItemFlags() { public Set<ItemFlag> getItemFlags() {
return itemFlags; return itemFlags;
} }
public ItemStackBuilder setItemFlags(Set<ItemFlag> itemFlags) {
this.itemFlags = itemFlags;
return this;
}
public List<PotionEffect> getPotionEffects() { public List<PotionEffect> getPotionEffects() {
return potionEffects; return potionEffects;
} }
@ -151,30 +215,15 @@ public class ItemStackBuilder {
return displayName; return displayName;
} }
public ItemStackBuilder setDisplayName(String name) {
this.displayName = name;
return this;
}
public short getData() { public short getData() {
return data; 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) { public ItemStackBuilder setData(int data) {
if (data > 255) { if (data > 255) {
data = 255; data = 255;
@ -188,26 +237,16 @@ public class ItemStackBuilder {
return this; return this;
} }
public ItemStackBuilder setItemStack(ItemStack item) {
this.itemStack = item;
return this;
}
public ItemStackBuilder setItemMeta(ItemMeta meta) { public ItemStackBuilder setItemMeta(ItemMeta meta) {
this.meta = meta; this.meta = meta;
return this; 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) { public ItemStackBuilder addLore(String lore) {
this.lore.add(lore); this.lore.add(lore);
return this; return this;
@ -255,21 +294,6 @@ public class ItemStackBuilder {
return this; 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) { public ItemStackBuilder addItemFlags(ItemFlag[] itemFlags) {
this.itemFlags.addAll(Arrays.asList(itemFlags)); this.itemFlags.addAll(Arrays.asList(itemFlags));
return this; return this;
@ -313,29 +337,6 @@ public class ItemStackBuilder {
return map; 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 { private void setField(Object instance, String name, Object value) throws ReflectiveOperationException {
Field field = instance.getClass().getDeclaredField(name); Field field = instance.getClass().getDeclaredField(name);
field.setAccessible(true); field.setAccessible(true);

View File

@ -20,13 +20,13 @@ public class WEUtil {
if (!path.exists()) { if (!path.exists()) {
path.mkdirs(); path.mkdirs();
} }
File schematicFile = new File(path,fileName+".schem"); File schematicFile = new File(path, fileName + ".schem");
if (!schematicFile.exists()) { if (!schematicFile.exists()) {
Main.plugin.saveResource("schematics/"+fileName+".schem", false); Main.plugin.saveResource("schematics/" + fileName + ".schem", false);
} }
World world = location.getWorld(); World world = location.getWorld();
EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(world)); EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(world));
Bukkit.getScheduler().runTaskAsynchronously (Main.plugin, () -> { Bukkit.getScheduler().runTaskAsynchronously(Main.plugin, () -> {
try { try {
Clipboard clipboard = ClipboardFormats.findByFile(schematicFile).load(schematicFile); Clipboard clipboard = ClipboardFormats.findByFile(schematicFile).load(schematicFile);
clipboard.paste(BukkitAdapter.adapt(world), BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ())); clipboard.paste(BukkitAdapter.adapt(world), BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ()));