From 67b4eb18b85ad195c76eed7206c19e6088d6020b Mon Sep 17 00:00:00 2001 From: Luca Date: Sun, 28 Nov 2021 14:56:55 +0100 Subject: [PATCH] e --- src/main/java/rip/tilly/bedwars/BedWars.java | 2 +- .../java/rip/tilly/bedwars/game/Game.java | 45 +++++++------ .../rip/tilly/bedwars/upgrades/AxeTier.java | 24 +++---- .../bedwars/villager/CustomVillager.java | 67 +++++++++++++++++++ .../bedwars/villager/VillagerCallable.java | 9 +++ 5 files changed, 115 insertions(+), 32 deletions(-) create mode 100644 src/main/java/rip/tilly/bedwars/villager/CustomVillager.java create mode 100644 src/main/java/rip/tilly/bedwars/villager/VillagerCallable.java diff --git a/src/main/java/rip/tilly/bedwars/BedWars.java b/src/main/java/rip/tilly/bedwars/BedWars.java index 71b3e7f..9970f67 100644 --- a/src/main/java/rip/tilly/bedwars/BedWars.java +++ b/src/main/java/rip/tilly/bedwars/BedWars.java @@ -23,12 +23,12 @@ import rip.tilly.bedwars.managers.hotbar.HotbarManager; import rip.tilly.bedwars.managers.mongo.MongoManager; import rip.tilly.bedwars.managers.party.PartyManager; import rip.tilly.bedwars.managers.queue.QueueManager; -import rip.tilly.bedwars.utils.menusystem.PlayerMenuUtil; import rip.tilly.bedwars.providers.placeholderapi.PlaceholderAPIProvider; import rip.tilly.bedwars.providers.scoreboard.ScoreboardProvider; import rip.tilly.bedwars.utils.CC; import rip.tilly.bedwars.utils.aether.Aether; import rip.tilly.bedwars.utils.config.file.Config; +import rip.tilly.bedwars.utils.menusystem.PlayerMenuUtil; import java.util.Arrays; import java.util.HashMap; diff --git a/src/main/java/rip/tilly/bedwars/game/Game.java b/src/main/java/rip/tilly/bedwars/game/Game.java index b22362c..3cbad9d 100644 --- a/src/main/java/rip/tilly/bedwars/game/Game.java +++ b/src/main/java/rip/tilly/bedwars/game/Game.java @@ -6,6 +6,7 @@ import lombok.Setter; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; +import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -21,6 +22,7 @@ import rip.tilly.bedwars.generators.GeneratorType; import rip.tilly.bedwars.utils.CC; import rip.tilly.bedwars.utils.CustomLocation; import rip.tilly.bedwars.utils.TimeUtils; +import rip.tilly.bedwars.villager.CustomVillager; import java.util.*; import java.util.stream.Collectors; @@ -312,25 +314,30 @@ public class Game { } public void spawnVillagers() { - Villager teamAShopVillager = this.copiedArena.getTeamAshop().toBukkitLocation().getWorld().spawn(this.copiedArena.getTeamAshop().toBukkitLocation(), Villager.class); - teamAShopVillager.setCustomName(CC.translate("&aItem Shop")); - teamAShopVillager.setCustomNameVisible(true); + CustomVillager villager = new CustomVillager(this.copiedArena.getA().toBukkitWorld()); + villager.register(); + villager.spawn(this.copiedArena.getTeamAshop().toBukkitLocation(), "&aItem Shop"); + this.addEntityToRemove(villager.getBukkitEntity()); - Villager teamBShopVillager = this.copiedArena.getTeamBshop().toBukkitLocation().getWorld().spawn(this.copiedArena.getTeamBshop().toBukkitLocation(), Villager.class); - teamBShopVillager.setCustomName(CC.translate("&aItem Shop")); - teamBShopVillager.setCustomNameVisible(true); - - Villager teamAUpgradesVillager = this.copiedArena.getTeamAupgrades().toBukkitLocation().getWorld().spawn(this.copiedArena.getTeamAupgrades().toBukkitLocation(), Villager.class); - teamAUpgradesVillager.setCustomName(CC.translate("&aUpgrades Shop")); - teamAUpgradesVillager.setCustomNameVisible(true); - - Villager teamBUpgradesVillager = this.copiedArena.getTeamBupgrades().toBukkitLocation().getWorld().spawn(this.copiedArena.getTeamBupgrades().toBukkitLocation(), Villager.class); - teamBUpgradesVillager.setCustomName(CC.translate("&aUpgrades Shop")); - teamBUpgradesVillager.setCustomNameVisible(true); - - this.addEntityToRemove(teamAShopVillager); - this.addEntityToRemove(teamBShopVillager); - this.addEntityToRemove(teamAUpgradesVillager); - this.addEntityToRemove(teamBUpgradesVillager); +// Villager teamAShopVillager = this.copiedArena.getTeamAshop().toBukkitLocation().getWorld().spawn(this.copiedArena.getTeamAshop().toBukkitLocation(), Villager.class); +// teamAShopVillager.setCustomName(CC.translate("&aItem Shop")); +// teamAShopVillager.setCustomNameVisible(true); +// +// Villager teamBShopVillager = this.copiedArena.getTeamBshop().toBukkitLocation().getWorld().spawn(this.copiedArena.getTeamBshop().toBukkitLocation(), Villager.class); +// teamBShopVillager.setCustomName(CC.translate("&aItem Shop")); +// teamBShopVillager.setCustomNameVisible(true); +// +// Villager teamAUpgradesVillager = this.copiedArena.getTeamAupgrades().toBukkitLocation().getWorld().spawn(this.copiedArena.getTeamAupgrades().toBukkitLocation(), Villager.class); +// teamAUpgradesVillager.setCustomName(CC.translate("&aUpgrades Shop")); +// teamAUpgradesVillager.setCustomNameVisible(true); +// +// Villager teamBUpgradesVillager = this.copiedArena.getTeamBupgrades().toBukkitLocation().getWorld().spawn(this.copiedArena.getTeamBupgrades().toBukkitLocation(), Villager.class); +// teamBUpgradesVillager.setCustomName(CC.translate("&aUpgrades Shop")); +// teamBUpgradesVillager.setCustomNameVisible(true); +// +// this.addEntityToRemove(teamAShopVillager); +// this.addEntityToRemove(teamBShopVillager); +// this.addEntityToRemove(teamAUpgradesVillager); +// this.addEntityToRemove(teamBUpgradesVillager); } } diff --git a/src/main/java/rip/tilly/bedwars/upgrades/AxeTier.java b/src/main/java/rip/tilly/bedwars/upgrades/AxeTier.java index 208e0a4..dea77eb 100644 --- a/src/main/java/rip/tilly/bedwars/upgrades/AxeTier.java +++ b/src/main/java/rip/tilly/bedwars/upgrades/AxeTier.java @@ -7,15 +7,15 @@ import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; import rip.tilly.bedwars.utils.ItemBuilder; -@Getter -@RequiredArgsConstructor -public enum AxeTier { - - NONE(0, Material.AIR, null, 0), - WOOD(10, Material.IRON_INGOT, new ItemBuilder(Material.WOOD_AXE).enchantment(Enchantment.DIG_SPEED, 1).name(), 1) - - private final int cost; - private final Material costType; - private final ItemStack item; - private final int level; -} +//@Getter +//@RequiredArgsConstructor +//public enum AxeTier { +// +// NONE(0, Material.AIR, null, 0), +// WOOD(10, Material.IRON_INGOT, new ItemBuilder(Material.WOOD_AXE).enchantment(Enchantment.DIG_SPEED, 1).name(), 1) +// +// private final int cost; +// private final Material costType; +// private final ItemStack item; +// private final int level; +//} diff --git a/src/main/java/rip/tilly/bedwars/villager/CustomVillager.java b/src/main/java/rip/tilly/bedwars/villager/CustomVillager.java new file mode 100644 index 0000000..449b014 --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/villager/CustomVillager.java @@ -0,0 +1,67 @@ +package rip.tilly.bedwars.villager; + +import net.minecraft.server.v1_8_R3.EntityTypes; +import net.minecraft.server.v1_8_R3.EntityVillager; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity; +import org.bukkit.event.entity.CreatureSpawnEvent; +import rip.tilly.bedwars.utils.CC; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Map; + +public class CustomVillager extends EntityVillager implements VillagerCallable { + + public CustomVillager(World world) { + super(((CraftWorld) world).getHandle()); + } + + @Override + public CustomVillager spawn(Location location, String name) { + CustomVillager customVillager = new CustomVillager(location.getWorld()); + customVillager.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + ((CraftLivingEntity) customVillager.getBukkitEntity()).setRemoveWhenFarAway(false); + customVillager.setHealth(customVillager.getMaxHealth()); + customVillager.setCustomName(CC.translate(name)); + customVillager.setCustomNameVisible(true); + customVillager.setInvisible(false); + ((CraftWorld) location.getWorld()).getHandle().addEntity(customVillager, CreatureSpawnEvent.SpawnReason.CUSTOM); + this.register(); + return customVillager; + } + + @Override + public void register() { + registerEntity("Villager", 120, EntityVillager.class); + } + + private void registerEntity(String string, int paramInt, Class villagerClass) { + try { + ArrayList arrayList = new ArrayList(); + byte b; + int i; + Field[] arrayOfField; + for (i = (arrayOfField = EntityTypes.class.getDeclaredFields()).length, b = 0; b < i; ) { + Field field = arrayOfField[b]; + if (field.getType().getSimpleName().equals(Map.class.getSimpleName())) { + field.setAccessible(true); + arrayList.add((Map)field.get(null)); + } + b++; + } + if (arrayList.get(2).containsKey(paramInt)) { + arrayList.get(0).remove(string); + arrayList.get(2).remove(paramInt); + } + Method method = EntityTypes.class.getDeclaredMethod("a", Class.class, String.class, int.class); + method.setAccessible(true); + method.invoke(null, villagerClass, string, paramInt); + } catch (Exception exception) { + exception.printStackTrace(); + } + } +} diff --git a/src/main/java/rip/tilly/bedwars/villager/VillagerCallable.java b/src/main/java/rip/tilly/bedwars/villager/VillagerCallable.java new file mode 100644 index 0000000..bafd515 --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/villager/VillagerCallable.java @@ -0,0 +1,9 @@ +package rip.tilly.bedwars.villager; + +import org.bukkit.Location; + +public interface VillagerCallable { + CustomVillager spawn(Location location, String name); + + void register(); +}