Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/net/tfminecraft/simplefactions/enums/SFGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public enum SFGUI {
TREATY_VIEW,
INSTALLATIONS_VIEW,
INSTALLATION_DETAIL_VIEW,
SUPPLY_HUB_VIEW,
HOSTED_SUPPLY_HUB_VIEW,
PLAYER_LEDGER_VIEW,
COMPANY_VIEW,
COMPANY_SLOTS_VIEW,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ private static double reachableTrade(Guild guild, Installation installation) {
}

/** Hub changes move trade power, so the map and incomes are brought up to date at once. */
private static void recalculateTrade() {
public static void recalculateTrade() {
if (FactionManager.getMap() != null && FactionManager.factions != null) {
for (Faction faction : FactionManager.factions) {
if (faction != null && faction.getRGB() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import net.tfminecraft.simplefactions.managers.inventory.GovernmentView;
import net.tfminecraft.simplefactions.managers.inventory.GuildView;
import net.tfminecraft.simplefactions.managers.inventory.InstallationView;
import net.tfminecraft.simplefactions.managers.inventory.SupplyHubView;
import net.tfminecraft.simplefactions.managers.inventory.InventoryUpdater;
import net.tfminecraft.simplefactions.managers.inventory.LawView;
import net.tfminecraft.simplefactions.managers.inventory.LoanPayment;
Expand Down Expand Up @@ -213,6 +214,7 @@ public void factionView(Player player, Faction f) {

//Guilds
public GuildView guildView = new GuildView(this);
public SupplyHubView supplyHubView = new SupplyHubView(this);
public PlayerLedgerView playerLedgerView = new PlayerLedgerView(this);
public void guildList(Player player) {
guildView.guildList(player);
Expand Down Expand Up @@ -757,6 +759,14 @@ public void confirmView(Player player, Faction f, String key, String data) {
player.openInventory(i);
}

public void confirmSupplyHub(Player player, Faction faction, String data) {
confirming.put(player, faction);
Inventory inventory = SimpleFactions.plugin.getServer().createInventory(null, 27, "§7Confirm Action");
inventory.setItem(11, createButton("confirm", "supply_hub_action", data));
inventory.setItem(15, createButton("cancel", "supply_hub_action", data));
player.openInventory(inventory);
}

// Keep the existing legacy text representation, formatting, and exact-string comparisons.
@SuppressWarnings("deprecation")
public void openQueueCancelConfirm(Player player, Faction f, String payload, String title) {
Expand Down Expand Up @@ -1086,6 +1096,16 @@ public void clickButton(InventoryClickEvent e) {
guildList(p);
}
break;
case SUPPLY_HUB_VIEW:
if (g != null) {
guildView(p, g);
}
break;
case HOSTED_SUPPLY_HUB_VIEW:
if (f != null) {
installationView.installationDetailView(p, f, h.getSecondaryId());
}
break;
case MILITARY_VIEW:
factionView(p, f);
break;
Expand Down Expand Up @@ -1276,6 +1296,9 @@ public void clickButton(InventoryClickEvent e) {
} else if(h.getType() == SFGUI.INSTALLATIONS_VIEW
|| h.getType() == SFGUI.INSTALLATION_DETAIL_VIEW) {
installationView.click(e, inv, p);
} else if (h.getType() == SFGUI.SUPPLY_HUB_VIEW
|| h.getType() == SFGUI.HOSTED_SUPPLY_HUB_VIEW) {
supplyHubView.click(e, inv, p);
} else if(h.getType() == SFGUI.GOVERNMENT_VIEW
|| h.getType() == SFGUI.PROPOSAL_VIEW
|| h.getType() == SFGUI.PROPOSALS
Expand Down Expand Up @@ -1356,9 +1379,21 @@ public void clickButton(InventoryClickEvent e) {
}
if(!confirming.containsKey(p)) return;
ItemStack item = e.getCurrentItem();
if (item == null || !item.hasItemMeta()) {
return;
}
ItemMeta m = item.getItemMeta();
NamespacedKey key = new NamespacedKey(SimpleFactions.plugin, "queue_cancel");
NamespacedKey key = new NamespacedKey(SimpleFactions.plugin, "supply_hub_action");
String data = m.getPersistentDataContainer().get(key, PersistentDataType.STRING);
if (data != null) {
boolean accepted = item.getType().equals(Material.GREEN_CONCRETE);
supplyHubView.confirm(p, data, accepted);
confirming.remove(p);
p.playSound(p, accepted ? Sound.ENTITY_PLAYER_LEVELUP : Sound.BLOCK_NOTE_BLOCK_BIT, 1f, 1f);
return;
}
key = new NamespacedKey(SimpleFactions.plugin, "queue_cancel");
data = m.getPersistentDataContainer().get(key, PersistentDataType.STRING);
if (data != null) {
var parsed = QueueCancelPayload.parse(data);
if (parsed.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ public class GuildCreator {

FactionRanker r = new FactionRanker();

@SuppressWarnings("deprecation")
public ItemStack createSupplyHubsItem() {
ItemStack item = new ItemStack(Material.CHEST);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(StringFormatter.formatHex("#b5835a§lSupply Hubs"));
meta.setLore(List.of("§7View your guild's supply hubs"));
item.setItemMeta(meta);
return item;
}

// Keep the existing legacy text representation, formatting, and exact-string comparisons.
@SuppressWarnings("deprecation")
public ItemStack createListItem(Player p, Guild guild) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ public void guildView(Player player, Guild guild, Inventory i) {
}
i.setItem(13, creator.createMenuItem(player, guild, MenuItemType.TRADE_BREAKDOWN));
i.setItem(14, creator.createLedgerItem(player, guild));
// Slots 20 to 24 are the branch upgrade buttons, so this sits past Loans.
i.setItem(26, creator.createSupplyHubsItem());
if (!guild.isBase()) {
i.setItem(17, creator.createDividendItem(player, guild));
}
Expand Down Expand Up @@ -251,6 +253,14 @@ public void upgradeView(Player player, Guild guild, Inventory i) {
public void click(InventoryClickEvent e, Inventory inventory, Player p) {
if(!(inventory.getHolder() instanceof SFInventoryHolder)) return;
SFInventoryHolder h = (SFInventoryHolder) inventory.getHolder();
if (h.getType() == SFGUI.GUILD_VIEW && e.getSlot() == 26) {
e.setCancelled(true);
Guild guild = FactionManager.getGuildByString(h.getId());
if (guild != null && guild.isMember(p)) {
inv.supplyHubView.guildView(p, guild);
}
return;
}
if (e.getView().getTitle().equalsIgnoreCase("§7Guild List")) {
e.setCancelled(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@
import net.tfminecraft.tlibs.utils.TimeFormatter;

public class InstallationCreator {

@SuppressWarnings("deprecation")
public ItemStack createSupplyHubsButton() {
ItemStack item = new ItemStack(Material.CHEST, 1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§eSupply Hubs");
meta.setLore(List.of("§7View guild hubs hosted here"));
item.setItemMeta(meta);
return item;
}
// Keep the existing legacy text representation, formatting, and exact-string comparisons.
@SuppressWarnings("deprecation")
public ItemStack createSummary(Faction f) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void installationDetailView(Player player, Faction f, String installation
List<PlayerVehicleRecord> berthed =
SimpleFactions.getVehicleRegistry().getByInstallation(f.getId(), installation.getId());
berthed.sort(Comparator.comparing(PlayerVehicleRecord::getVehicleTypeId));
for (int index = 0; index < berthed.size() && index < 43; index++) {
for (int index = 0; index < berthed.size() && index < 42; index++) {
PlayerVehicleRecord record = berthed.get(index);
Optional<Location> location =
VehicleFramework.getVehicleManager()
Expand Down Expand Up @@ -158,15 +158,27 @@ public void installationDetailView(Player player, Faction f, String installation
inventory.setItem(13, new ItemStack(Material.AIR, 1));
}

if (!isPending && installation != null) {
int hubSlot = supplyHubSlot(
InstallationConfigLoader.getHubSlots(installation.getKind(), installation.getLevel()));
if (hubSlot >= 0) {
inventory.setItem(hubSlot, creator.createSupplyHubsButton());
}
}

inventory.setItem(53, inv.createBackButton(SFGUI.INSTALLATION_DETAIL_VIEW));
if (open) player.openInventory(inventory);
}

static int berthedVehicleSlot(int index) {
if (index < 0 || index >= 43) {
if (index < 0 || index >= 42) {
return -1;
}
return index + (index >= 11 ? 1 : 0) + (index >= 12 ? 1 : 0);
return index + (index >= 11 ? 1 : 0) + (index >= 12 ? 1 : 0) + (index >= 13 ? 1 : 0);
}

static int supplyHubSlot(int hubSlots) {
return hubSlots > 0 ? 15 : -1;
}

public void click(InventoryClickEvent event, Inventory inventory, Player player) {
Expand Down Expand Up @@ -207,6 +219,14 @@ public void click(InventoryClickEvent event, Inventory inventory, Player player)

if (holder.getType() == SFGUI.INSTALLATION_DETAIL_VIEW) {
int slot = event.getSlot();
if (slot == 15) {
Installation installation = f.getInstallationHandler().getById(holder.getSecondaryId());
if (installation != null && InstallationConfigLoader.getHubSlots(
installation.getKind(), installation.getLevel()) > 0) {
inv.supplyHubView.hostedView(player, f, installation);
}
return;
}
if (slot == 13) {
ItemStack upgradeItem = event.getCurrentItem();
if (upgradeItem == null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package net.tfminecraft.simplefactions.managers.inventory;

import java.util.ArrayList;
import java.util.List;

import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import net.tfminecraft.simplefactions.guild.hub.SupplyHubService.HubStanding;
import net.tfminecraft.simplefactions.utils.Formatter;

public class SupplyHubCreator {
public static List<String> guildHubLore(
String installationName,
String kind,
String factionName,
double upkeep,
HubStanding standing,
List<String> connections,
double tradePower,
double production) {
List<String> lore = new ArrayList<>();
lore.add("§7Installation: §e" + installationName + " §8(" + kind + ")");
lore.add("§7Owned by: §e" + factionName);
lore.add("§7Daily upkeep: §e" + Formatter.formatDouble(upkeep) + "d");
lore.add(net.tfminecraft.simplefactions.guild.hub.SupplyHubService.statusText(standing));
if (connections != null) {
lore.addAll(connections);
}
lore.add("§7Trade power here: §e" + Formatter.formatDouble(tradePower));
lore.add("§7Production here: §e" + Formatter.formatDouble(production));
return lore;
}

public static List<String> hostHubLore(String guildName, String factionName, HubStanding standing) {
List<String> lore = new ArrayList<>();
lore.add("§7Guild: §e" + guildName);
lore.add("§7Faction: §e" + factionName);
lore.add(net.tfminecraft.simplefactions.guild.hub.SupplyHubService.statusText(standing));
return lore;
}

public static ItemStack item(Material material, String name, List<String> lore) {
ItemStack item = new ItemStack(material);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(lore);
item.setItemMeta(meta);
return item;
}
}
Loading
Loading