Integrate Wild Update quests and Citizens contacts
This commit is contained in:
parent
018d776874
commit
f46b26d956
2 changed files with 919 additions and 81 deletions
|
|
@ -93,12 +93,8 @@ public final class DuneNPC extends JavaPlugin implements Listener, CommandExecut
|
|||
}
|
||||
}
|
||||
private void spawnNavigator(Location location) {
|
||||
location.getWorld().spawn(location, Villager.class, villager -> {
|
||||
villager.setCustomName(ChatColor.LIGHT_PURPLE + "Vaerkring Navigator");
|
||||
villager.setCustomNameVisible(true); villager.setProfession(Villager.Profession.CLERIC);
|
||||
villager.setAI(false); villager.setInvulnerable(true); villager.setSilent(true); villager.setPersistent(true);
|
||||
villager.getPersistentDataContainer().set(guildKey, PersistentDataType.BYTE, (byte) 1);
|
||||
});
|
||||
if (!com.dunerealms.npc.CitizensBridge.ready() || com.dunerealms.npc.CitizensBridge.exists(this, location.getWorld(), guildKey, "1")) return;
|
||||
com.dunerealms.npc.CitizensBridge.spawnContact(this, location, ChatColor.LIGHT_PURPLE + "Vaerkring Navigator", guildKey, "1", true);
|
||||
}
|
||||
@EventHandler public void navigator(PlayerInteractEntityEvent event) {
|
||||
if (!event.getRightClicked().getPersistentDataContainer().has(guildKey, PersistentDataType.BYTE)) return;
|
||||
|
|
@ -115,7 +111,7 @@ public final class DuneNPC extends JavaPlugin implements Listener, CommandExecut
|
|||
if (!player.isOp()) { player.sendMessage(ChatColor.RED + "Operators only. Right-click an Arrakis Smuggler for missions."); return true; }
|
||||
if (args.length == 0 || args[0].equalsIgnoreCase("admin")) { openAdmin(player); return true; }
|
||||
if (args[0].equalsIgnoreCase("smuggler")) {
|
||||
if (!getConfig().getBoolean("smugglers.enabled", true)) { player.sendMessage("Smugglers are disabled in DuneNPC/config.yml."); return true; }
|
||||
if (getConfig().getBoolean("smugglers.fixed-contracts.enabled", false) || !getConfig().getBoolean("smugglers.enabled", true)) { player.sendMessage("Smugglers are disabled in DuneNPC/config.yml."); return true; }
|
||||
if (!player.getWorld().getName().equalsIgnoreCase("arrakis")) { player.sendMessage("Spawn smugglers on Arrakis."); return true; }
|
||||
smugglers.spawnAt(player.getLocation()); player.sendMessage("Arrakis Smuggler placed."); return true;
|
||||
}
|
||||
|
|
@ -168,7 +164,7 @@ public final class DuneNPC extends JavaPlugin implements Listener, CommandExecut
|
|||
@Override public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length == 1) return (sender.isOp() ? List.of("admin", "guildnpc", "smuggler", "status", "smuggle") : List.of("smuggle"))
|
||||
.stream().filter(item -> item.startsWith(args[0].toLowerCase(Locale.ROOT))).toList();
|
||||
if (args.length == 2 && args[0].equalsIgnoreCase("smuggle")) return List.of("status", "cancel").stream()
|
||||
if (args.length == 2 && args[0].equalsIgnoreCase("smuggle")) return List.of("status", "contract", "cancel").stream()
|
||||
.filter(item -> item.startsWith(args[1].toLowerCase(Locale.ROOT))).toList();
|
||||
return List.of();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,46 @@ final class Smugglers implements Listener {
|
|||
Bukkit.getScheduler().runTaskTimer(plugin, this::populate, 100L, 1200L);
|
||||
Bukkit.getScheduler().runTaskTimer(plugin, this::updateCamps, 1L, 20L);
|
||||
}
|
||||
private static final NamespacedKey QUEST_CONTACT = new NamespacedKey("dunerealms", "quest_character");
|
||||
private static final String ESMAR = "esmar_tuek", STABAN = "staban_tuek";
|
||||
|
||||
private boolean fixedContracts() {
|
||||
return plugin.getConfig().getBoolean("smugglers.fixed-contracts.enabled", false);
|
||||
}
|
||||
private boolean roamingEnabled() {
|
||||
return !fixedContracts() && plugin.getConfig().getBoolean("smugglers.enabled", true);
|
||||
}
|
||||
private String fixedRole(Entity entity) {
|
||||
if (!entity.getWorld().getName().equals("arrakis")) return null;
|
||||
String role = entity.getPersistentDataContainer().get(QUEST_CONTACT, PersistentDataType.STRING);
|
||||
if (!ESMAR.equals(role) && !STABAN.equals(role)) return null;
|
||||
var contact = com.dunerealms.npc.CitizensBridge.contact(entity.getWorld(), QUEST_CONTACT, role);
|
||||
return contact != null && contact.id().equals(com.dunerealms.npc.CitizensBridge.identity(entity)) ? role : null;
|
||||
}
|
||||
private boolean contractContact(Entity entity) {
|
||||
if (!fixedContracts()) return roamingEnabled() && tagged(entity);
|
||||
String role = fixedRole(entity);
|
||||
return ESMAR.equals(role) || STABAN.equals(role);
|
||||
}
|
||||
private LivingEntity fixedContact(World world, String role) {
|
||||
if (!world.getName().equals("arrakis")) return null;
|
||||
LivingEntity contact = null;
|
||||
for (LivingEntity candidate : world.getEntitiesByClass(LivingEntity.class)) {
|
||||
if (!candidate.isValid() || !role.equals(fixedRole(candidate))) continue;
|
||||
if (contact != null) return null;
|
||||
contact = candidate;
|
||||
}
|
||||
return contact;
|
||||
}
|
||||
private boolean fixedPairReady(Entity esmar) {
|
||||
if (!ESMAR.equals(fixedRole(esmar)) || fixedContact(esmar.getWorld(), ESMAR) != esmar) return false;
|
||||
var staban = com.dunerealms.npc.CitizensBridge.contact(esmar.getWorld(), QUEST_CONTACT, STABAN);
|
||||
if (staban == null || staban.id().equals(com.dunerealms.npc.CitizensBridge.identity(esmar))) return false;
|
||||
Location source = esmar.getLocation();
|
||||
Location destination = staban.location();
|
||||
return Math.hypot(source.getX() - destination.getX(), source.getZ() - destination.getZ()) >= 64;
|
||||
}
|
||||
|
||||
private Set<UUID> activeSources() {
|
||||
Set<UUID> ids = new HashSet<>();
|
||||
for (Contract contract : contracts.values()) ids.add(contract.source());
|
||||
|
|
@ -72,9 +112,9 @@ final class Smugglers implements Listener {
|
|||
}
|
||||
private void updateCamps() {
|
||||
expireContracts();
|
||||
Set<UUID> active = plugin.getConfig().getBoolean("smugglers.enabled", true) ? activeSources() : Set.of();
|
||||
Set<UUID> active = roamingEnabled() ? activeSources() : Set.of();
|
||||
camps.sync(active);
|
||||
if (!plugin.getConfig().getBoolean("smugglers.enabled", true)) return;
|
||||
if (!roamingEnabled()) return;
|
||||
World world = Bukkit.getWorld("arrakis");
|
||||
if (world == null) return;
|
||||
for (LivingEntity trader : world.getEntitiesByClass(LivingEntity.class)) if (tagged(trader)) {
|
||||
|
|
@ -110,7 +150,7 @@ final class Smugglers implements Listener {
|
|||
}
|
||||
int activeCount() { expireContracts(); return contracts.size(); }
|
||||
void spawnAt(Location location) {
|
||||
if (!plugin.getConfig().getBoolean("smugglers.enabled", true)) return;
|
||||
if (!roamingEnabled()) return;
|
||||
com.dunerealms.npc.CitizensBridge.spawnContact(plugin,location,"Arrakis Smuggler",traderKey);
|
||||
}
|
||||
private boolean tagged(Entity entity) {
|
||||
|
|
@ -129,7 +169,7 @@ final class Smugglers implements Listener {
|
|||
if(event.getEntity() instanceof WanderingTrader && event.getEntity().getWorld().getName().equalsIgnoreCase("arrakis")) event.setCancelled(true);
|
||||
}
|
||||
private void populate() {
|
||||
if (!plugin.getConfig().getBoolean("smugglers.enabled", true)) return;
|
||||
if (!roamingEnabled()) return;
|
||||
World world = Bukkit.getWorld("arrakis");
|
||||
if (world == null || world.getPlayers().isEmpty()) return;
|
||||
int count = 0;
|
||||
|
|
@ -173,16 +213,20 @@ final class Smugglers implements Listener {
|
|||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = false) public void interact(PlayerInteractEntityEvent event) {
|
||||
if (!tagged(event.getRightClicked())) return;
|
||||
Entity contact = event.getRightClicked();
|
||||
if (!contractContact(contact) || fixedContracts() && ESMAR.equals(fixedRole(contact))) return;
|
||||
event.setCancelled(true);
|
||||
if (!plugin.getConfig().getBoolean("smugglers.enabled", true)) return;
|
||||
if (event.getHand() != EquipmentSlot.HAND) return;
|
||||
Player player = event.getPlayer();
|
||||
if (sanctioned(player)) {
|
||||
player.sendMessage(ChatColor.GOLD + "Smuggler: 'The Emperor's seal is on your house. I won't risk my routes for an Imperial agent. Sell through your charter: /duneess sell pays +33% before the Trust levy.'");
|
||||
return;
|
||||
}
|
||||
open(player, event.getRightClicked());
|
||||
if(fixedContracts() && !contracts.containsKey(player.getUniqueId())){
|
||||
player.sendMessage("Start a delivery contract with Esmar Tuek first.");
|
||||
return;
|
||||
}
|
||||
open(player, contact);
|
||||
}
|
||||
private ItemStack icon(Material type, String title, String... lines) {
|
||||
ItemStack item = new ItemStack(type);
|
||||
|
|
@ -235,16 +279,19 @@ final class Smugglers implements Listener {
|
|||
if (!player.isOnline()) return;
|
||||
player.closeInventory();
|
||||
expireContracts();
|
||||
if (!plugin.getConfig().getBoolean("smugglers.enabled", true)) return;
|
||||
if (sanctioned(player)) { player.sendMessage(ChatColor.RED + "Imperial sanction: smuggling contracts are unavailable."); return; }
|
||||
Entity trader = com.dunerealms.npc.CitizensBridge.resolve(menu.trader);
|
||||
if (trader == null || !trader.isValid() || !tagged(trader)
|
||||
if (trader == null || !trader.isValid() || !contractContact(trader)
|
||||
|| !trader.getWorld().getName().equalsIgnoreCase("arrakis") || player.getWorld() != trader.getWorld()
|
||||
|| player.getLocation().distanceSquared(trader.getLocation()) > 64) {
|
||||
player.sendMessage(ChatColor.RED + "Return to the smuggler to trade."); return;
|
||||
}
|
||||
Contract active = contracts.get(player.getUniqueId());
|
||||
if (active == null && (slot == 11 || slot == 15)) {
|
||||
if(fixedContracts() && !fixedPairReady(trader)) {
|
||||
player.sendMessage("Both fixed delivery contacts must be available before starting a contract.");
|
||||
return;
|
||||
}
|
||||
contracts.put(player.getUniqueId(), offer(slot == 11 ? "spice" : "water", trader));
|
||||
if (!save()) { contracts.remove(player.getUniqueId()); player.sendMessage("Contract could not be saved. Try again."); return; }
|
||||
updateCamps();
|
||||
|
|
@ -253,7 +300,7 @@ final class Smugglers implements Listener {
|
|||
? "Smuggler: 'The melange must vanish from the Imperial ledger. My distant contact will pay for your silence.'"
|
||||
: "Smuggler: 'The hidden sietch has no water to spare. Reach my distant contact, and its people will remember.'"));
|
||||
player.sendMessage("Carry the cargo to another smuggler 64+ blocks from here. /dune smuggle status shows your contract.");
|
||||
player.sendMessage("You have 30 real minutes, including offline time. Your contact will wait at this lit camp until the contract ends.");
|
||||
player.sendMessage(fixedContracts()?"You have 30 real minutes. Deliver to Staban Tuek.":"You have 30 real minutes, including offline time. Your contact will wait at this lit camp until the contract ends.");
|
||||
} else if (active != null && slot == 22) {
|
||||
contracts.remove(player.getUniqueId());
|
||||
if (!save()) contracts.put(player.getUniqueId(), active);
|
||||
|
|
@ -316,8 +363,16 @@ final class Smugglers implements Listener {
|
|||
}
|
||||
void command(Player player, String[] args) {
|
||||
expireContracts();
|
||||
if(args.length>1&&args[1].equalsIgnoreCase("contract")){
|
||||
LivingEntity esmar=fixedContracts()?fixedContact(player.getWorld(),ESMAR):null;
|
||||
if(esmar==null||player.getLocation().distanceSquared(esmar.getLocation())>64){player.sendMessage("Meet Esmar Tuek on Arrakis to open fixed delivery contracts.");return;}
|
||||
if(sanctioned(player)){player.sendMessage("Imperial sanction: smuggling contracts are unavailable.");return;}
|
||||
if(!fixedPairReady(esmar)&&!contracts.containsKey(player.getUniqueId())){player.sendMessage("Both fixed contacts must be available first.");return;}
|
||||
open(player,esmar);
|
||||
return;
|
||||
}
|
||||
Contract contract = contracts.get(player.getUniqueId());
|
||||
if (contract == null) { player.sendMessage("No smuggling contract. Seek a roaming Arrakis Smuggler."); return; }
|
||||
if (contract == null) { player.sendMessage(fixedContracts()?"No smuggling contract. Meet Esmar Tuek on Arrakis.":"No smuggling contract. Seek a roaming Arrakis Smuggler."); return; }
|
||||
if (args.length > 1 && args[1].equalsIgnoreCase("cancel")) {
|
||||
contracts.remove(player.getUniqueId());
|
||||
if (!save()) contracts.put(player.getUniqueId(), contract);
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff