This commit is contained in:
Luca 2021-11-28 14:56:55 +01:00
parent 84066a8da8
commit 67b4eb18b8
5 changed files with 115 additions and 32 deletions

View File

@ -23,12 +23,12 @@ import rip.tilly.bedwars.managers.hotbar.HotbarManager;
import rip.tilly.bedwars.managers.mongo.MongoManager; import rip.tilly.bedwars.managers.mongo.MongoManager;
import rip.tilly.bedwars.managers.party.PartyManager; import rip.tilly.bedwars.managers.party.PartyManager;
import rip.tilly.bedwars.managers.queue.QueueManager; 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.placeholderapi.PlaceholderAPIProvider;
import rip.tilly.bedwars.providers.scoreboard.ScoreboardProvider; import rip.tilly.bedwars.providers.scoreboard.ScoreboardProvider;
import rip.tilly.bedwars.utils.CC; import rip.tilly.bedwars.utils.CC;
import rip.tilly.bedwars.utils.aether.Aether; import rip.tilly.bedwars.utils.aether.Aether;
import rip.tilly.bedwars.utils.config.file.Config; import rip.tilly.bedwars.utils.config.file.Config;
import rip.tilly.bedwars.utils.menusystem.PlayerMenuUtil;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;

View File

@ -6,6 +6,7 @@ import lombok.Setter;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; 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.CC;
import rip.tilly.bedwars.utils.CustomLocation; import rip.tilly.bedwars.utils.CustomLocation;
import rip.tilly.bedwars.utils.TimeUtils; import rip.tilly.bedwars.utils.TimeUtils;
import rip.tilly.bedwars.villager.CustomVillager;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -312,25 +314,30 @@ public class Game {
} }
public void spawnVillagers() { public void spawnVillagers() {
Villager teamAShopVillager = this.copiedArena.getTeamAshop().toBukkitLocation().getWorld().spawn(this.copiedArena.getTeamAshop().toBukkitLocation(), Villager.class); CustomVillager villager = new CustomVillager(this.copiedArena.getA().toBukkitWorld());
teamAShopVillager.setCustomName(CC.translate("&aItem Shop")); villager.register();
teamAShopVillager.setCustomNameVisible(true); 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); // Villager teamAShopVillager = this.copiedArena.getTeamAshop().toBukkitLocation().getWorld().spawn(this.copiedArena.getTeamAshop().toBukkitLocation(), Villager.class);
teamBShopVillager.setCustomName(CC.translate("&aItem Shop")); // teamAShopVillager.setCustomName(CC.translate("&aItem Shop"));
teamBShopVillager.setCustomNameVisible(true); // teamAShopVillager.setCustomNameVisible(true);
//
Villager teamAUpgradesVillager = this.copiedArena.getTeamAupgrades().toBukkitLocation().getWorld().spawn(this.copiedArena.getTeamAupgrades().toBukkitLocation(), Villager.class); // Villager teamBShopVillager = this.copiedArena.getTeamBshop().toBukkitLocation().getWorld().spawn(this.copiedArena.getTeamBshop().toBukkitLocation(), Villager.class);
teamAUpgradesVillager.setCustomName(CC.translate("&aUpgrades Shop")); // teamBShopVillager.setCustomName(CC.translate("&aItem Shop"));
teamAUpgradesVillager.setCustomNameVisible(true); // teamBShopVillager.setCustomNameVisible(true);
//
Villager teamBUpgradesVillager = this.copiedArena.getTeamBupgrades().toBukkitLocation().getWorld().spawn(this.copiedArena.getTeamBupgrades().toBukkitLocation(), Villager.class); // Villager teamAUpgradesVillager = this.copiedArena.getTeamAupgrades().toBukkitLocation().getWorld().spawn(this.copiedArena.getTeamAupgrades().toBukkitLocation(), Villager.class);
teamBUpgradesVillager.setCustomName(CC.translate("&aUpgrades Shop")); // teamAUpgradesVillager.setCustomName(CC.translate("&aUpgrades Shop"));
teamBUpgradesVillager.setCustomNameVisible(true); // teamAUpgradesVillager.setCustomNameVisible(true);
//
this.addEntityToRemove(teamAShopVillager); // Villager teamBUpgradesVillager = this.copiedArena.getTeamBupgrades().toBukkitLocation().getWorld().spawn(this.copiedArena.getTeamBupgrades().toBukkitLocation(), Villager.class);
this.addEntityToRemove(teamBShopVillager); // teamBUpgradesVillager.setCustomName(CC.translate("&aUpgrades Shop"));
this.addEntityToRemove(teamAUpgradesVillager); // teamBUpgradesVillager.setCustomNameVisible(true);
this.addEntityToRemove(teamBUpgradesVillager); //
// this.addEntityToRemove(teamAShopVillager);
// this.addEntityToRemove(teamBShopVillager);
// this.addEntityToRemove(teamAUpgradesVillager);
// this.addEntityToRemove(teamBUpgradesVillager);
} }
} }

View File

@ -7,15 +7,15 @@ import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import rip.tilly.bedwars.utils.ItemBuilder; import rip.tilly.bedwars.utils.ItemBuilder;
@Getter //@Getter
@RequiredArgsConstructor //@RequiredArgsConstructor
public enum AxeTier { //public enum AxeTier {
//
NONE(0, Material.AIR, null, 0), // NONE(0, Material.AIR, null, 0),
WOOD(10, Material.IRON_INGOT, new ItemBuilder(Material.WOOD_AXE).enchantment(Enchantment.DIG_SPEED, 1).name(), 1) // WOOD(10, Material.IRON_INGOT, new ItemBuilder(Material.WOOD_AXE).enchantment(Enchantment.DIG_SPEED, 1).name(), 1)
//
private final int cost; // private final int cost;
private final Material costType; // private final Material costType;
private final ItemStack item; // private final ItemStack item;
private final int level; // private final int level;
} //}

View File

@ -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<EntityVillager> villagerClass) {
try {
ArrayList<Map> 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();
}
}
}

View File

@ -0,0 +1,9 @@
package rip.tilly.bedwars.villager;
import org.bukkit.Location;
public interface VillagerCallable {
CustomVillager spawn(Location location, String name);
void register();
}