diff --git a/src/main/java/com/gmail/goosius/siegewar/SiegeWar.java b/src/main/java/com/gmail/goosius/siegewar/SiegeWar.java index bb1541e33..065017df6 100644 --- a/src/main/java/com/gmail/goosius/siegewar/SiegeWar.java +++ b/src/main/java/com/gmail/goosius/siegewar/SiegeWar.java @@ -34,6 +34,7 @@ import com.gmail.goosius.siegewar.listeners.SiegeWarStatusScreenListener; import com.gmail.goosius.siegewar.listeners.SiegeWarTownEventListener; import com.gmail.goosius.siegewar.listeners.SiegeWarTownyEventListener; +import com.gmail.goosius.siegewar.listeners.SiegeWarLoreListener; import java.io.File; import java.nio.file.Files; @@ -174,6 +175,7 @@ private boolean registerListeners() { pm.registerEvents(new SiegeWarPlotEventListener(this), this); pm.registerEvents(new SiegeWarStatusScreenListener(), this); pm.registerEvents(new SiegeWarSelfListener(), this); + pm.registerEvents(new SiegeWarLoreListener(), this); if (getServer().getPluginManager().isPluginEnabled("TownyChat")) { info("SiegeWar found TownyChat plugin, enabling TownyChat integration."); pm.registerEvents(new SiegeWarTownyChatEventListener(), this); diff --git a/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarLoreListener.java b/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarLoreListener.java new file mode 100644 index 000000000..ba2d11597 --- /dev/null +++ b/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarLoreListener.java @@ -0,0 +1,130 @@ +package com.gmail.goosius.siegewar.listeners; + +import com.gmail.goosius.siegewar.events.PreSiegeCampEvent; +import com.gmail.goosius.siegewar.events.SiegeEndEvent; +import com.gmail.goosius.siegewar.events.SiegeWarStartEvent; +import com.gmail.goosius.siegewar.settings.SiegeWarSettings; +import com.gmail.goosius.siegewar.utils.SiegeWarLoreUtil; +import com.palmergames.bukkit.towny.event.actions.TownyBuildEvent; +import com.palmergames.bukkit.towny.object.Translation; +import org.bukkit.Material; +import org.bukkit.Tag; +import org.bukkit.block.BlockState; +import org.bukkit.entity.Item; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockDropItemEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.inventory.PrepareItemCraftEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.ItemStack; +import org.bukkit.persistence.PersistentDataHolder; + +import java.util.Arrays; + +/** + * + * @author lexiccn + * + */ +public class SiegeWarLoreListener implements Listener { + + @EventHandler(priority = EventPriority.MONITOR) + public void onSiegeStart(SiegeWarStartEvent event) { + if (!SiegeWarSettings.isSiegeLoreEnabled()) return; + + //Set name, type, attacker, defender, start time + SiegeWarLoreUtil.applySiegeStartLoreToBannerState(event.getSiege()); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onSiegeEnd(SiegeEndEvent event) { + if (!SiegeWarSettings.isSiegeLoreEnabled()) return; + + //Set outcome, winner, points, end time + SiegeWarLoreUtil.applySiegeEndLoreToBannerState(event.getSiege()); + } + + @EventHandler + public void onInteractBanner(PlayerInteractEvent event) { + if (!SiegeWarSettings.isSiegeLoreEnabled()) return; + if (event.getHand() != EquipmentSlot.HAND) return; + + PersistentDataHolder holder; + + if (event.getClickedBlock() != null && event.getAction() == Action.RIGHT_CLICK_BLOCK) { + if (!SiegeWarLoreUtil.isLoreItem(event.getClickedBlock().getState(), "siege_banner")) return; + holder = (PersistentDataHolder) event.getClickedBlock().getState(); + } else if (event.getItem() != null && event.getAction() == Action.RIGHT_CLICK_AIR) { + if (!SiegeWarLoreUtil.isLoreItem(event.getItem(), "siege_banner")) return; + holder = event.getItem().getItemMeta(); + } else return; + + SiegeWarLoreUtil.sendBannerChat(holder, event.getPlayer()); + } + + @EventHandler + public void onPrepareCraft(PrepareItemCraftEvent event) { + if (!SiegeWarSettings.isSiegeLoreEnabled()) return; + + ItemStack resultItem = event.getInventory().getResult(); + if (resultItem == null) return; + if (resultItem.getType() != Material.SHIELD) return; + + ItemStack bannerItem = Arrays.stream(event.getInventory().getMatrix()) + .filter(itemStack -> SiegeWarLoreUtil.isLoreItem(itemStack, "siege_banner")) + .findFirst().orElse(null); + if (bannerItem == null) return; + + SiegeWarLoreUtil.setShieldStackFromHolder(resultItem, bannerItem.getItemMeta()); + } + + @EventHandler(ignoreCancelled = true) + public void onTryStartSiege(PreSiegeCampEvent event) { + if (!SiegeWarSettings.isSiegeLoreEnabled()) return; + if (!SiegeWarLoreUtil.isLoreItem(event.getFlag().getState(), "siege_banner")) return; + + event.setCancelled(true); + event.setCancellationMsg(Translation.of("siege_lore_error_banner_cannot_be_used")); + } + + /** + * Copies lore data from a "siege_banner" ItemMeta PDC to a banner BlockState PDC + * This is necessary as Spigot/Minecraft do not copy PDC or Lore from items to blocks (and back) + * LOW priority to run and use ItemInHand methods before {@link com.gmail.goosius.siegewar.listeners.SiegeWarActionListener#onBlockBuild(TownyBuildEvent)} + */ + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) + public void onPlaceBlock(BlockPlaceEvent event) { + if (!SiegeWarSettings.isSiegeLoreEnabled()) return; + + ItemStack stack = event.getItemInHand(); + if (!SiegeWarLoreUtil.isLoreItem(stack, "siege_banner")) return; + + BlockState state = event.getBlock().getState(); + if (!(state instanceof PersistentDataHolder) || !Tag.BANNERS.isTagged(state.getType())) return; + + SiegeWarLoreUtil.copyPersistentLoreDataToHolder(stack.getItemMeta(), (PersistentDataHolder) state); + + state.update(); + } + + @EventHandler(ignoreCancelled = true) + public void onDropBanner(BlockDropItemEvent event) { + if (!SiegeWarSettings.isSiegeLoreEnabled()) return; + + if (event.getItems().isEmpty()) return; + + BlockState state = event.getBlockState(); + if (!SiegeWarLoreUtil.isLoreItem(state, "siege_banner")) return; + + Item item = event.getItems().get(0); + ItemStack stack = item.getItemStack(); + + SiegeWarLoreUtil.setBannerStackFromHolder(stack, (PersistentDataHolder) state); + + item.setItemStack(stack); + } +} diff --git a/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java b/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java index 584cf0a9b..0181a939c 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java @@ -1161,7 +1161,26 @@ public enum ConfigNodes { "# If this value is true, then the Battle Commander feature is enabled.", "# When a battle sessions starts, then for each siege, one player from each side may be designated as the Battle Commander.", "# To qualify as a battle commander, a player must be an official participant with general or king rank, and be online and in the Siege-Zone.", - "# If one side has a battle commander, then any member can run /sw spawn to spawn on the commander."); + "# If one side has a battle commander, then any member can run /sw spawn to spawn on the commander."), + SIEGE_LORE( + "siege_lore", + "", + "", + "", + "############################################################", + "# +------------------------------------------------------+ #", + "# | SIEGE LORE | #", + "# +------------------------------------------------------+ #", + "############################################################", + ""), + SIEGE_LORE_ENABLED( + "siege_lore.enabled", + "true", + "", + "# If this value is true, then the Siege Lore feature is enabled.", + "# When a banner is broken after a siege has ended, it will drop with a name and lore set to display info about the siege.", + "# Banners dropped from this feature can be placed and broken without losing lore, but can not be used to begin a new siege.", + "# Shields can be crafted from the lore banners and will inherit the lore and name from the banner."); private final String Root; private final String Default; private String[] comments; diff --git a/src/main/java/com/gmail/goosius/siegewar/settings/SiegeWarSettings.java b/src/main/java/com/gmail/goosius/siegewar/settings/SiegeWarSettings.java index 96d903af8..f51e7e44c 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/SiegeWarSettings.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/SiegeWarSettings.java @@ -620,6 +620,10 @@ public static boolean isBattleCommandersEnabled() { return Settings.getBoolean(ConfigNodes.BATTLE_COMMANDERS_ENABLED); } + public static boolean isSiegeLoreEnabled() { + return Settings.getBoolean(ConfigNodes.SIEGE_LORE_ENABLED); + } + public static String getDynmapLayerName() { return Settings.getString(ConfigNodes.WAR_SIEGE_DYNMAP_LAYER_NAME); } diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarLoreUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarLoreUtil.java new file mode 100644 index 000000000..b7ebf6888 --- /dev/null +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarLoreUtil.java @@ -0,0 +1,399 @@ +package com.gmail.goosius.siegewar.utils; + +import com.gmail.goosius.siegewar.Messaging; +import com.gmail.goosius.siegewar.SiegeWar; +import com.gmail.goosius.siegewar.enums.SiegeSide; +import com.gmail.goosius.siegewar.objects.Siege; +import com.palmergames.bukkit.towny.object.Translation; +import org.bukkit.NamespacedKey; +import org.bukkit.block.BlockState; +import org.bukkit.command.CommandSender; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.persistence.PersistentDataContainer; +import org.bukkit.persistence.PersistentDataHolder; +import org.bukkit.persistence.PersistentDataType; + +import javax.annotation.Nullable; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +public class SiegeWarLoreUtil { + private static final String SIEGE_BANNER = "siege_banner"; + private static final String SIEGE_SHIELD = "siege_shield"; + + private static final NamespacedKey LORE_ITEM = new NamespacedKey(SiegeWar.getSiegeWar(), "siege_lore_item"); + private static final NamespacedKey TYPE = new NamespacedKey(SiegeWar.getSiegeWar(), "siege_lore_type"); + private static final NamespacedKey TOWN = new NamespacedKey(SiegeWar.getSiegeWar(), "siege_lore_town"); + private static final NamespacedKey ATTACKER = new NamespacedKey(SiegeWar.getSiegeWar(), "siege_lore_attacker"); + private static final NamespacedKey DEFENDER = new NamespacedKey(SiegeWar.getSiegeWar(), "siege_lore_defender"); + private static final NamespacedKey ATTACKER_POINTS = new NamespacedKey(SiegeWar.getSiegeWar(), "siege_lore_attacker_points"); + private static final NamespacedKey DEFENDER_POINTS = new NamespacedKey(SiegeWar.getSiegeWar(), "siege_lore_defender_points"); + private static final NamespacedKey WINNER = new NamespacedKey(SiegeWar.getSiegeWar(), "siege_lore_winner"); + private static final NamespacedKey STATUS = new NamespacedKey(SiegeWar.getSiegeWar(), "siege_lore_status"); + private static final NamespacedKey START = new NamespacedKey(SiegeWar.getSiegeWar(), "siege_lore_start"); + private static final NamespacedKey END = new NamespacedKey(SiegeWar.getSiegeWar(), "siege_lore_end"); + + + public static boolean isLoreItem(BlockState state) { + if (state == null) return false; + if (!(state instanceof PersistentDataHolder)) return false; + PersistentDataHolder holder = (PersistentDataHolder) state; + return holder.getPersistentDataContainer().has(LORE_ITEM, PersistentDataType.STRING); + } + + public static boolean isLoreItem(BlockState state, String id) { + if (id == null) return false; + if (!isLoreItem(state)) return false; + PersistentDataHolder holder = (PersistentDataHolder) state; + String compare = holder.getPersistentDataContainer().get(LORE_ITEM, PersistentDataType.STRING); + return compare.equals(id); + } + + public static boolean isLoreItem(ItemStack itemStack) { + if (itemStack == null) return false; + if (!itemStack.hasItemMeta()) return false; + return itemStack.getItemMeta().getPersistentDataContainer().has(LORE_ITEM, PersistentDataType.STRING); + } + + public static boolean isLoreItem(ItemStack itemStack, String id) { + if (id == null) return false; + if (!isLoreItem(itemStack)) return false; + String compare = itemStack.getItemMeta().getPersistentDataContainer().get(LORE_ITEM, PersistentDataType.STRING); + return compare.equals(id); + } + + private static String colorAttacker(String string) { + return Translation.of("siege_lore_color_attacker", string); + } + + private static String colorDefender(String string) { + return Translation.of("siege_lore_color_defender", string); + } + + private static String colorNeutral(String string) { + return Translation.of("siege_lore_color_neutral", string); + } + + private static String colorKey(String string) { + return Translation.of("siege_lore_color_key", string); + } + + private static String colorValue(String string) { + return Translation.of("siege_lore_color_value", string); + } + + + @Nullable + private static String getSiegeType(PersistentDataContainer container) { + return container.get(TYPE, PersistentDataType.STRING); + } + + @Nullable + private static String getSiegeTown(PersistentDataContainer container) { + return container.get(TOWN, PersistentDataType.STRING); + } + + @Nullable + private static String getSiegeAttacker(PersistentDataContainer container) { + return container.get(ATTACKER, PersistentDataType.STRING); + } + + @Nullable + private static String getSiegeDefender(PersistentDataContainer container) { + return container.get(DEFENDER, PersistentDataType.STRING); + } + + @Nullable + private static Integer getSiegeAttackerPoints(PersistentDataContainer container) { + return container.get(ATTACKER_POINTS, PersistentDataType.INTEGER); + } + + @Nullable + private static Integer getSiegeDefenderPoints(PersistentDataContainer container) { + return container.get(DEFENDER_POINTS, PersistentDataType.INTEGER); + } + + @Nullable + private static String getSiegeWinningSide(PersistentDataContainer container) { + return container.get(WINNER, PersistentDataType.STRING); + } + + @Nullable + private static String getSiegeStatus(PersistentDataContainer container) { + return container.get(STATUS, PersistentDataType.STRING); + } + + @Nullable + private static Long getSiegeStart(PersistentDataContainer container) { + return container.get(START, PersistentDataType.LONG); + } + + @Nullable + private static Long getSiegeEnd(PersistentDataContainer container) { + return container.get(END, PersistentDataType.LONG); + } + + + private static String getFormattedUnknown() { + return colorNeutral(Translation.of("siege_lore_unknown")); + } + + private static String getFormattedType(PersistentDataContainer container) { + String type = getSiegeType(container); + if (type == null) return getFormattedUnknown(); + + return colorValue(Translation.of("siege_lore_type", type)); + } + + private static String getFormattedTown(PersistentDataContainer container) { + String town = getSiegeTown(container); + if (town == null) return getFormattedUnknown(); + + return colorDefender(town); + } + + private static String getFormattedAttacker(PersistentDataContainer container) { + String attacker = getSiegeAttacker(container); + if (attacker == null) return getFormattedUnknown(); + + return colorAttacker(attacker); + } + + private static String getFormattedDefender(PersistentDataContainer container) { + String defender = getSiegeDefender(container); + if (defender == null) return getFormattedUnknown(); + + return colorDefender(defender); + } + + private static String getFormattedAttackerPoints(PersistentDataContainer container) { + Integer points = getSiegeAttackerPoints(container); + if (points == null) return getFormattedUnknown(); + + return colorValue(String.valueOf(points)); + } + + private static String getFormattedDefenderPoints(PersistentDataContainer container) { + Integer points = getSiegeDefenderPoints(container); + if (points == null) return getFormattedUnknown(); + + return colorValue(String.valueOf(points)); + } + + private static String getFormattedWinner(PersistentDataContainer container) { + String winning_side = getSiegeWinningSide(container); + if (winning_side == null) return getFormattedUnknown(); + + switch (winning_side) { + case "ATTACKERS": + return getFormattedAttacker(container); + case "DEFENDERS": + return getFormattedDefender(container); + case "NOBODY": + return colorValue(SiegeSide.NOBODY.name()); + default: + throw new RuntimeException("Unknown winning SiegeSide in SiegeWar lore item."); + } + } + + private static String getFormattedOpposition(PersistentDataContainer container) { + String winning_side = getSiegeWinningSide(container); + if (winning_side == null) return getFormattedUnknown(); + + switch (winning_side) { + case "ATTACKERS": + return getFormattedDefender(container); + case "DEFENDERS": + return getFormattedAttacker(container); + case "NOBODY": + return colorValue(SiegeSide.NOBODY.name()); + default: + throw new RuntimeException("Unknown winning SiegeSide in SiegeWar lore item."); + } + } + + private static String getFormattedStatus(PersistentDataContainer container) { + String status = getSiegeStatus(container); + if (status == null) return getFormattedUnknown(); + + return colorValue(status); + } + + private static String getFormattedStart(PersistentDataContainer container) { + Long time = getSiegeStart(container); + if (time == null) return getFormattedUnknown(); + + return colorValue(new SimpleDateFormat(Translation.of("siege_lore_format_date")).format(time)); + + } + + private static String getFormattedEnd(PersistentDataContainer container) { + Long time = getSiegeEnd(container); + if (time == null) return getFormattedUnknown(); + + return colorValue(new SimpleDateFormat(Translation.of("siege_lore_format_date")).format(time)); + } + + public static void sendBannerChat(PersistentDataHolder holder, CommandSender target) { + PersistentDataContainer data = holder.getPersistentDataContainer(); + + Locale locale = Translation.getLocale(target); + + String winner = getSiegeWinningSide(data); + if (winner == null) winner = "NOBODY"; + + String chat = colorKey(Translation.of("siege_lore_banner_chat_1", locale, getFormattedType(data))) + + colorKey(Translation.of("siege_lore_banner_chat_2", locale, getFormattedTown(data))) + + colorKey(Translation.of("siege_lore_banner_chat_3", locale, getFormattedWinner(data))) + + colorKey(Translation.of("siege_lore_banner_chat_4_" + winner, locale, getFormattedOpposition(data))) + + colorKey(Translation.of("siege_lore_banner_chat_5_" + winner, locale, getFormattedEnd(data))); + + Messaging.sendMsg(target, chat); + } + + public static void setShieldStackFromHolder(ItemStack stack, PersistentDataHolder holder) { + if (stack == null || holder == null) return; + if (!stack.hasItemMeta()) return; + + ItemMeta meta = stack.getItemMeta(); + + copyPersistentLoreDataToHolder(holder, meta); + + meta.getPersistentDataContainer().set(LORE_ITEM, PersistentDataType.STRING, SIEGE_SHIELD); + + String name = Translation.of("siege_lore_format_two_values", + getFormattedTown(holder.getPersistentDataContainer()), + colorNeutral(Translation.of("siege_lore_shield_name"))); + + meta.setDisplayName(name); + + setBannerLore(meta, holder.getPersistentDataContainer()); + + stack.setItemMeta(meta); + } + + public static void setBannerStackFromHolder(ItemStack stack, PersistentDataHolder holder) { + if (stack == null || holder == null) return; + if (!stack.hasItemMeta()) return; + + ItemMeta meta = stack.getItemMeta(); + + copyPersistentLoreDataToHolder(holder, meta); + + meta.getPersistentDataContainer().set(LORE_ITEM, PersistentDataType.STRING, SIEGE_BANNER); + + String name = Translation.of("siege_lore_format_two_values", + getFormattedTown(holder.getPersistentDataContainer()), + colorNeutral(Translation.of("siege_lore_banner_name"))); + + meta.setDisplayName(name); + + setBannerLore(meta, holder.getPersistentDataContainer()); + + stack.setItemMeta(meta); + } + + private static void setBannerLore(ItemMeta meta, PersistentDataContainer data) { + List lore = new ArrayList<>(); + + lore.add(getFormattedType(data)); + + String attacker_line = Translation.of("siege_lore_format_key_value", + colorKey(Translation.of("siege_lore_attacker")), + Translation.of("siege_lore_format_two_values", + getFormattedAttacker(data), + colorValue(Translation.of("siege_lore_format_secondary_value", getFormattedAttackerPoints(data))))); + lore.add(attacker_line); + + String defender_line = Translation.of("siege_lore_format_key_value", + colorKey(Translation.of("siege_lore_defender")), + Translation.of("siege_lore_format_two_values", + getFormattedDefender(data), + colorValue(Translation.of("siege_lore_format_secondary_value", getFormattedDefenderPoints(data))))); + lore.add(defender_line); + + String winner_line = Translation.of("siege_lore_format_key_value", + colorKey(Translation.of("siege_lore_winner")), + Translation.of("siege_lore_format_two_values", + getFormattedWinner(data), + colorValue(Translation.of("siege_lore_format_secondary_value", getFormattedStatus(data))))); + lore.add(winner_line); + + String start_line = Translation.of("siege_lore_format_key_value", + colorKey(Translation.of("siege_lore_start")), + colorValue(getFormattedStart(data))); + lore.add(start_line); + + String end_line = Translation.of("siege_lore_format_key_value", + colorKey(Translation.of("siege_lore_end")), + colorValue(getFormattedEnd(data))); + lore.add(end_line); + + + meta.setLore(lore); + } + + public static void copyPersistentLoreDataToHolder(PersistentDataHolder fromHolder, PersistentDataHolder toHolder) { + PersistentDataContainer from = fromHolder.getPersistentDataContainer(); + PersistentDataContainer to = toHolder.getPersistentDataContainer(); + + if (!from.has(LORE_ITEM, PersistentDataType.STRING)) return; + to.set(LORE_ITEM, PersistentDataType.STRING, from.get(LORE_ITEM, PersistentDataType.STRING)); + if (from.has(TYPE, PersistentDataType.STRING)) + to.set(TYPE, PersistentDataType.STRING, from.get(TYPE, PersistentDataType.STRING)); + if (from.has(TOWN, PersistentDataType.STRING)) + to.set(TOWN, PersistentDataType.STRING, from.get(TOWN, PersistentDataType.STRING)); + if (from.has(ATTACKER, PersistentDataType.STRING)) + to.set(ATTACKER, PersistentDataType.STRING, from.get(ATTACKER, PersistentDataType.STRING)); + if (from.has(DEFENDER, PersistentDataType.STRING)) + to.set(DEFENDER, PersistentDataType.STRING, from.get(DEFENDER, PersistentDataType.STRING)); + if (from.has(ATTACKER_POINTS, PersistentDataType.INTEGER)) + to.set(ATTACKER_POINTS, PersistentDataType.INTEGER, from.get(ATTACKER_POINTS, PersistentDataType.INTEGER)); + if (from.has(DEFENDER_POINTS, PersistentDataType.INTEGER)) + to.set(DEFENDER_POINTS, PersistentDataType.INTEGER, from.get(DEFENDER_POINTS, PersistentDataType.INTEGER)); + if (from.has(WINNER, PersistentDataType.STRING)) + to.set(WINNER, PersistentDataType.STRING, from.get(WINNER, PersistentDataType.STRING)); + if (from.has(STATUS, PersistentDataType.STRING)) + to.set(STATUS, PersistentDataType.STRING, from.get(STATUS, PersistentDataType.STRING)); + if (from.has(START, PersistentDataType.LONG)) + to.set(START, PersistentDataType.LONG, from.get(START, PersistentDataType.LONG)); + if (from.has(END, PersistentDataType.LONG)) + to.set(END, PersistentDataType.LONG, from.get(END, PersistentDataType.LONG)); + } + + public static void applySiegeStartLoreToBannerState(Siege siege) { + BlockState blockState = siege.getFlagBlock().getState(); + if (!(blockState instanceof PersistentDataHolder)) return; + + PersistentDataHolder holder = (PersistentDataHolder) blockState; + PersistentDataContainer container = holder.getPersistentDataContainer(); + + container.set(LORE_ITEM, PersistentDataType.STRING, "siege_banner"); + container.set(TYPE, PersistentDataType.STRING, siege.getSiegeType().getName()); + container.set(TOWN, PersistentDataType.STRING, siege.getDefender().getName()); + container.set(ATTACKER, PersistentDataType.STRING, siege.getAttackingNationIfPossibleElseTown().getFormattedName()); + container.set(DEFENDER, PersistentDataType.STRING, siege.getDefendingNationIfPossibleElseTown().getFormattedName()); + container.set(START, PersistentDataType.LONG, System.currentTimeMillis()); + + blockState.update(); + } + + public static void applySiegeEndLoreToBannerState(Siege siege) { + BlockState blockState = siege.getFlagBlock().getState(); + if (!isLoreItem(blockState, "siege_banner")) return; + + PersistentDataHolder holder = (PersistentDataHolder) blockState; + PersistentDataContainer container = holder.getPersistentDataContainer(); + + container.set(WINNER, PersistentDataType.STRING, siege.getSiegeWinner().name()); + container.set(STATUS, PersistentDataType.STRING, siege.getStatus().getName()); + container.set(ATTACKER_POINTS, PersistentDataType.INTEGER, siege.getAttackerBattlePoints()); + container.set(DEFENDER_POINTS, PersistentDataType.INTEGER, siege.getDefenderBattlePoints()); + container.set(END, PersistentDataType.LONG, System.currentTimeMillis()); + + blockState.update(); + } +} diff --git a/src/main/resources/lang/en-US.yml b/src/main/resources/lang/en-US.yml index 378112f48..3a4b023fa 100644 --- a/src/main/resources/lang/en-US.yml +++ b/src/main/resources/lang/en-US.yml @@ -659,3 +659,40 @@ msg_err_cannot_spawn_outpost_during_battle_session: "&cYou cannot spawn to an ou #Added in 2.8.0 msg_swa_remove_siege: '&bSiege of %s removed via admin commands.' msg_swa_battle: 'Battle' + +# Siege Lore + +siege_lore_color_attacker: '&c%s' +siege_lore_color_defender: '&3%s' +siege_lore_color_neutral: '&e%s' +siege_lore_color_key: '&6%s' +siege_lore_color_value: '&e%s' + +siege_lore_format_date: 'dd/MM/yyyy HH:mm' +siege_lore_format_key_value: '%s: %s' +siege_lore_format_two_values: '%s %s' +siege_lore_format_secondary_value: '(%s)' + +siege_lore_error_banner_cannot_be_used: 'Lore banners from previous sieges cannot be used to start new sieges.' + +siege_lore_unknown: 'Unknown' +siege_lore_type: '%s Siege' +siege_lore_attacker: 'Attacker' +siege_lore_defender: 'Defender' +siege_lore_winner: 'Victor' +siege_lore_start: 'Started' +siege_lore_end: 'Ended' + +siege_lore_banner_name: 'Siege Banner' + +siege_lore_banner_chat_1: 'This banner began the %s' +siege_lore_banner_chat_2: ' of %s' +siege_lore_banner_chat_3: ', which ended in Victory for %s' +siege_lore_banner_chat_4_ATTACKERS: ', who overcame the defence of %s' +siege_lore_banner_chat_5_ATTACKERS: ' to take control of the town on %s' +siege_lore_banner_chat_4_DEFENDERS: ', who overcame the attack from %s' +siege_lore_banner_chat_5_DEFENDERS: ' to defend their town on %s' +siege_lore_banner_chat_4_NOBODY: ', fighting against %s' +siege_lore_banner_chat_5_NOBODY: ' in a battle for the town on %s' + +siege_lore_shield_name: 'Siege Shield' \ No newline at end of file