Fixed WarBanner Persistence Error with Placement

This commit is contained in:
BuildTools 2019-09-14 09:22:38 -05:00
parent 0530b67b77
commit 2439e5258f

@ -332,19 +332,17 @@ public class FactionsBlockListener implements Listener {
if (P.p.mc17) { if (P.p.mc17) {
return; return;
} }
if (e.getItemInHand().getType().name().contains("BANNER")) {
if (e.getItemInHand().getType() == XMaterial.BLACK_BANNER.parseMaterial()) {
ItemStack bannerInHand = e.getItemInHand(); ItemStack bannerInHand = e.getItemInHand();
FPlayer fme = FPlayers.getInstance().getByPlayer(e.getPlayer()); FPlayer fme = FPlayers.getInstance().getByPlayer(e.getPlayer());
ItemStack warBanner = fme.getFaction().getBanner(); ItemStack warBanner = fme.getFaction().getBanner();
if (warBanner != null) { if (warBanner == null) {
return;
}
ItemMeta warmeta = warBanner.getItemMeta(); ItemMeta warmeta = warBanner.getItemMeta();
warmeta.setDisplayName(P.p.color(P.p.getConfig().getString("fbanners.Item.Name"))); warmeta.setDisplayName(P.p.color(P.p.getConfig().getString("fbanners.Item.Name")));
warmeta.setLore(P.p.colorList(P.p.getConfig().getStringList("fbanners.Item.Lore"))); warmeta.setLore(P.p.colorList(P.p.getConfig().getStringList("fbanners.Item.Lore")));
warBanner.setItemMeta(warmeta); warBanner.setItemMeta(warmeta);
} else {
warBanner = P.p.createItem(XMaterial.BLACK_BANNER.parseMaterial(), 1, (short) 1, P.p.getConfig().getString("fbanners.Item.Name"), P.p.getConfig().getStringList("fbanners.Item.Lore"));
}
if (warBanner.isSimilar(bannerInHand)) { if (warBanner.isSimilar(bannerInHand)) {
if (fme.getFaction().isWilderness()) { if (fme.getFaction().isWilderness()) {
fme.msg(TL.WARBANNER_NOFACTION); fme.msg(TL.WARBANNER_NOFACTION);
@ -352,65 +350,65 @@ public class FactionsBlockListener implements Listener {
return; return;
} }
int bannerTime = P.p.getConfig().getInt("fbanners.Banner-Time") * 20; int bannerTime = P.p.getConfig().getInt("fbanners.Banner-Time") * 20;
Location placedLoc = e.getBlockPlaced().getLocation(); Location placedLoc = e.getBlockPlaced().getLocation();
FLocation fplacedLoc = new FLocation(placedLoc); FLocation fplacedLoc = new FLocation(placedLoc);
if ((Board.getInstance().getFactionAt(fplacedLoc).isWarZone() && P.p.getConfig().getBoolean("fbanners.Placeable.Warzone")) if ((Board.getInstance().getFactionAt(fplacedLoc).isWarZone() && P.p.getConfig().getBoolean("fbanners.Placeable.Warzone")) || (fme.getFaction().getRelationTo(Board.getInstance().getFactionAt(fplacedLoc)) == Relation.ENEMY && P.p.getConfig().getBoolean("fbanners.Placeable.Enemy"))) {
|| (fme.getFaction().getRelationTo(Board.getInstance().getFactionAt(fplacedLoc)) == Relation.ENEMY) && P.p.getConfig().getBoolean("fbanners.Placeable.Enemy")) {
if (bannerCooldownMap.containsKey(fme.getTag())) { if (bannerCooldownMap.containsKey(fme.getTag())) {
fme.msg(TL.WARBANNER_COOLDOWN); fme.msg(TL.WARBANNER_COOLDOWN);
e.setCancelled(true); e.setCancelled(true);
return; return;
} }
for (FPlayer fplayer : fme.getFaction().getFPlayers()) { for (FPlayer fplayer : fme.getFaction().getFPlayers()) {
// if (fplayer == fme) { continue; } //Idk if I wanna not send the title to the player if (XMaterial.isVersionOrHigher(XMaterial.MinecraftVersion.VERSION_1_9)) {
fplayer.getPlayer().sendTitle(P.p.color(fme.getTag() + " Placed A WarBanner!"), P.p.color("&7use &c/f tpbanner&7 to tp to the banner!"), 10, 70, 20); fplayer.getPlayer().sendTitle(P.p.color(fme.getTag() + " Placed A WarBanner!"), P.p.color("&7use &c/f tpbanner&7 to tp to the banner!"), 10, 70, 20);
} else {
fplayer.getPlayer().sendTitle(P.p.color(fme.getTag() + " Placed A WarBanner!"), P.p.color("&7use &c/f tpbanner&7 to tp to the banner!"));
}
} }
bannerCooldownMap.put(fme.getTag(), true); bannerCooldownMap.put(fme.getTag(), true);
bannerLocations.put(fme.getTag(), e.getBlockPlaced().getLocation()); FactionsBlockListener.bannerLocations.put(fme.getTag(), e.getBlockPlaced().getLocation());
int bannerCooldown = P.p.getConfig().getInt("fbanners.Banner-Place-Cooldown"); int bannerCooldown = P.p.getConfig().getInt("fbanners.Banner-Place-Cooldown");
ArmorStand as = (ArmorStand) e.getBlockPlaced().getLocation().add(0.5, 1, 0.5).getWorld().spawnEntity(e.getBlockPlaced().getLocation().add(0.5, 1, 0.5), EntityType.ARMOR_STAND); //Spawn the ArmorStand ArmorStand as = (ArmorStand) e.getBlockPlaced().getLocation().add(0.5, 1.0, 0.5).getWorld().spawnEntity(e.getBlockPlaced().getLocation().add(0.5, 1.0, 0.5), EntityType.ARMOR_STAND);
as.setVisible(false); //Makes the ArmorStand invisible as.setVisible(false);
as.setGravity(false); //Make sure it doesn't fall as.setGravity(false);
as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it as.setCanPickupItems(false);
as.setCustomName(P.p.color(P.p.getConfig().getString("fbanners.BannerHolo").replace("{Faction}", fme.getTag()))); //Set this to the text you want as.setCustomName(P.p.color(P.p.getConfig().getString("fbanners.BannerHolo").replace("{Faction}", fme.getTag())));
as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not as.setCustomNameVisible(true);
String tag = fme.getTag(); String tag = fme.getTag();
Bukkit.getScheduler().scheduleSyncDelayedTask(P.p, () -> bannerCooldownMap.remove(tag), Long.parseLong(bannerCooldown + "")); Bukkit.getScheduler().scheduleSyncDelayedTask(P.p, () -> bannerCooldownMap.remove(tag), Long.parseLong(bannerCooldown + ""));
Block banner = e.getBlockPlaced(); Block banner = e.getBlockPlaced();
Material bannerType = banner.getType(); Material bannerType = banner.getType();
Faction bannerFaction = fme.getFaction(); Faction bannerFaction = fme.getFaction();
banner.getWorld().strikeLightningEffect(banner.getLocation()); banner.getWorld().strikeLightningEffect(banner.getLocation());
// e.getPlayer().getWorld().playSound(e.getPlayer().getLocation(), Sound.ENTITY_LIGHTNING_IMPACT,2.0F,0.5F);
int radius = P.p.getConfig().getInt("fbanners.Banner-Effect-Radius"); int radius = P.p.getConfig().getInt("fbanners.Banner-Effect-Radius");
List<String> effects = P.p.getConfig().getStringList("fbanners.Effects"); List<String> effects = P.p.getConfig().getStringList("fbanners.Effects");
int affectorTask = Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, () -> { int affectorTask = Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, () -> {
for (Entity e1 : banner.getLocation().getWorld().getNearbyEntities(banner.getLocation(), radius, 255, radius)) { for (Entity e1 : banner.getLocation().getWorld().getNearbyEntities(banner.getLocation(), (double) radius, 255.0, (double) radius)) {
if (e1 instanceof Player) { if (e1 instanceof Player) {
Player player = (Player) e1; Player player = (Player) e1;
FPlayer fplayer = FPlayers.getInstance().getByPlayer(player); FPlayer fplayer = FPlayers.getInstance().getByPlayer(player);
if (fplayer.getFaction() == bannerFaction) { if (fplayer.getFaction() != bannerFaction) {
continue;
}
for (String effect : effects) { for (String effect : effects) {
String[] components = effect.split(":"); String[] components = effect.split(":");
player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(components[0]), 100, Integer.parseInt(components[1]))); player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(components[0]), 100, Integer.parseInt(components[1])));
} }
ParticleEffect.LAVA.display(1, 1, 1, 1, 10, banner.getLocation(), 16); ParticleEffect.LAVA.display(1.0f, 1.0f, 1.0f, 1.0f, 10, banner.getLocation(), 16.0);
ParticleEffect.FLAME.display(1, 1, 1, 1, 10, banner.getLocation(), 16); ParticleEffect.FLAME.display(1.0f, 1.0f, 1.0f, 1.0f, 10, banner.getLocation(), 16.0);
if (banner.getType() == bannerType) {
if (banner.getType() != bannerType) { continue;
}
banner.setType(bannerType); banner.setType(bannerType);
} }
} }
}
}
}, 0L, 20L); }, 0L, 20L);
Bukkit.getScheduler().scheduleSyncDelayedTask(P.p, () -> { Bukkit.getScheduler().scheduleSyncDelayedTask(P.p, () -> {
banner.setType(Material.AIR); banner.setType(Material.AIR);
as.remove(); as.remove();
banner.getWorld().strikeLightningEffect(banner.getLocation()); banner.getWorld().strikeLightningEffect(banner.getLocation());
Bukkit.getScheduler().cancelTask(affectorTask); Bukkit.getScheduler().cancelTask(affectorTask);
bannerLocations.remove(bannerFaction.getTag()); FactionsBlockListener.bannerLocations.remove(bannerFaction.getTag());
}, Long.parseLong(bannerTime + "")); }, Long.parseLong(bannerTime + ""));
} else { } else {
fme.msg(TL.WARBANNER_INVALIDLOC); fme.msg(TL.WARBANNER_INVALIDLOC);