Add native crossplay menus and organic Arrakis highlands
Recovered from the attached four-commit source patch (original tip 1686291). Includes native Java/Bedrock menus, minimal Essentials, organic highlands, finite Dense Spice, desert villages, Harkonnen fortress and three personal highland sietches. Original validation reports 50 passing tests on Java 21/Paper 1.21.8. Live Paper/Velocity/Bedrock/ViaVersion staging remains pending. Existing world, configuration and player data must be preserved.
This commit is contained in:
parent
c692949a78
commit
d988ea2983
3 changed files with 2005 additions and 138 deletions
|
|
@ -30,9 +30,10 @@ import java.sql.PreparedStatement;
|
|||
import java.util.*;
|
||||
|
||||
public final class DuneEss extends JavaPlugin implements CommandExecutor, TabCompleter, Listener {
|
||||
private static final List<String> PLANETS = List.of("arrakis", "giedi_prime", "kaitain", "caladan", "sigma_draconis_iv");
|
||||
private static final List<String> PLANETS = List.of("arrakis", "giedi_prime", "kaitain", "caladan", "sigma_draconis_iv", "spacing_guild");
|
||||
private DuneEconomy economy;
|
||||
private ExchangeMenu exchangeMenu;
|
||||
private EssentialsBasics basics;
|
||||
private String jdbcUrl = "", dbUser = "", dbPassword = "";
|
||||
private boolean networkEnabled;
|
||||
private String localPlanet;
|
||||
|
|
@ -87,10 +88,12 @@ public final class DuneEss extends JavaPlugin implements CommandExecutor, TabCom
|
|||
command.setExecutor(this);
|
||||
command.setTabCompleter(this);
|
||||
getServer().getPluginManager().registerEvents(this, this);
|
||||
basics=new EssentialsBasics(this);
|
||||
basics.register();
|
||||
exchangeMenu = new ExchangeMenu(this);
|
||||
exchangeMenu.register();
|
||||
for (Player player : Bukkit.getOnlinePlayers()) economy.createPlayerAccount(player);
|
||||
getLogger().info("DuneEss enabled as the Solaris Vault provider.");
|
||||
getLogger().info("DuneRealms Essentials enabled as the Solaris Vault provider.");
|
||||
}
|
||||
|
||||
@Override public void onDisable() {
|
||||
|
|
@ -150,6 +153,7 @@ public final class DuneEss extends JavaPlugin implements CommandExecutor, TabCom
|
|||
}
|
||||
|
||||
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(args.length==0 && sender instanceof Player player) { basics.menu(player); return true; }
|
||||
if (args.length == 0 || args[0].equalsIgnoreCase("help")) {
|
||||
int page = 1;
|
||||
if (args.length > 1 && args[1].equalsIgnoreCase("menu")) {
|
||||
|
|
@ -273,7 +277,17 @@ public final class DuneEss extends JavaPlugin implements CommandExecutor, TabCom
|
|||
nextMeta.getPersistentDataContainer().set(helpPageKey, PersistentDataType.INTEGER, index + 2);
|
||||
next.setItemMeta(nextMeta);
|
||||
menu.setItem(53, next);
|
||||
player.openInventory(menu);
|
||||
java.util.Map<Integer,Runnable> actions=new java.util.HashMap<>();
|
||||
actions.put(45,()->openHelpMenu(player,index));
|
||||
actions.put(53,()->openHelpMenu(player,index+2));
|
||||
actions.put(49,player::closeInventory);
|
||||
for(int slot:slots) {
|
||||
ItemStack entry=menu.getItem(slot);
|
||||
if(entry==null) continue;
|
||||
String command=entry.getItemMeta().getPersistentDataContainer().get(helpActionKey,PersistentDataType.STRING);
|
||||
if(command!=null) actions.put(slot,()->player.performCommand(command.substring(1)));
|
||||
}
|
||||
com.example.dunegui.NativeMenus.inventory(this,player,"Dune Field Guide · "+(index+1),menu,actions);
|
||||
}
|
||||
|
||||
private ItemStack helpItem(Material material, String name, List<String> lore) {
|
||||
|
|
@ -306,6 +320,33 @@ public final class DuneEss extends JavaPlugin implements CommandExecutor, TabCom
|
|||
economy.createPlayerAccount(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void spiceSeller(org.bukkit.event.player.PlayerInteractEntityEvent event) {
|
||||
if(!event.getRightClicked().getPersistentDataContainer().has(new NamespacedKey("dunerealms","spice-seller"),PersistentDataType.BYTE))return;
|
||||
event.setCancelled(true);
|
||||
if(event.getHand()!=org.bukkit.inventory.EquipmentSlot.HAND)return;
|
||||
Player player=event.getPlayer();
|
||||
Inventory menu=Bukkit.createInventory(null,9,"Spice Seller");
|
||||
int quantity=16;
|
||||
double price=java.math.BigDecimal.valueOf(Math.max(1,getConfig().getInt("currency.spice-price",15)))
|
||||
.multiply(new java.math.BigDecimal("1.35")).multiply(java.math.BigDecimal.valueOf(quantity)).doubleValue();
|
||||
ItemStack offer=new ItemStack(Material.ORANGE_DYE,quantity); ItemMeta meta=offer.getItemMeta();
|
||||
meta.setDisplayName("Buy 16 spice · "+economy.format(price));
|
||||
meta.setLore(List.of("35% above standard spice price", "Confirm purchase"));offer.setItemMeta(meta);menu.setItem(4,offer);
|
||||
Map<Integer,Runnable> actions=new HashMap<>();
|
||||
actions.put(4,()->{
|
||||
// Recheck proximity and capacity at confirmation; never charge for undeliverable goods.
|
||||
if(!event.getRightClicked().isValid() || !player.getWorld().equals(event.getRightClicked().getWorld())
|
||||
|| player.getLocation().distanceSquared(event.getRightClicked().getLocation())>64)return;
|
||||
ItemStack spice=new ItemStack(Material.ORANGE_DYE,quantity);ItemMeta sm=spice.getItemMeta();
|
||||
sm.setDisplayName(ChatColor.GOLD+"Melange Spice");sm.getPersistentDataContainer().set(spiceKey,PersistentDataType.STRING,"spice");spice.setItemMeta(sm);
|
||||
if(player.getInventory().firstEmpty()<0){player.sendMessage("Make an empty inventory slot first.");return;}
|
||||
if(!economy.withdrawPlayer(player,price).transactionSuccess()){player.sendMessage("Not enough Solaris, or economy unavailable.");return;}
|
||||
player.getInventory().addItem(spice);player.sendMessage(ChatColor.GOLD+"Bought 16 spice for "+economy.format(price)+".");
|
||||
});
|
||||
com.example.dunegui.NativeMenus.inventory(this,player,"Spice Seller · +35%",menu,actions);
|
||||
}
|
||||
|
||||
private void sellSpice(Player player) {
|
||||
int amount = 0;
|
||||
for (ItemStack item : player.getInventory().getStorageContents()) {
|
||||
|
|
@ -346,7 +387,9 @@ public final class DuneEss extends JavaPlugin implements CommandExecutor, TabCom
|
|||
item.setItemMeta(meta);
|
||||
inventory.setItem(i, item);
|
||||
}
|
||||
player.openInventory(inventory);
|
||||
java.util.Map<Integer,Runnable> actions=new java.util.HashMap<>();
|
||||
for(int i=0;i<PLANETS.size();i++) { String planet=PLANETS.get(i); actions.put(i,()->travel(player,planet)); }
|
||||
com.example.dunegui.NativeMenus.inventory(this,player,"Spacing Guild Travel",inventory,actions);
|
||||
}
|
||||
|
||||
@EventHandler public void onTravelMenuClick(InventoryClickEvent event) {
|
||||
|
|
|
|||
138
DuneEss/src/main/java/com/example/duneess/EssentialsBasics.java
Normal file
138
DuneEss/src/main/java/com/example/duneess/EssentialsBasics.java
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
package com.example.duneess;
|
||||
|
||||
import com.example.dunegui.NativeMenus;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.*;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
|
||||
/** Deliberately small essentials command surface; vanilla owns bed/anchor respawns. */
|
||||
final class EssentialsBasics implements CommandExecutor, TabCompleter, Listener {
|
||||
private final DuneEss plugin;
|
||||
private final File file;
|
||||
private YamlConfiguration homes;
|
||||
private final Map<UUID,Request> requests=new HashMap<>();
|
||||
private record Request(UUID sender,long expires) {}
|
||||
EssentialsBasics(DuneEss plugin) {
|
||||
this.plugin=plugin;
|
||||
file=new File(plugin.getDataFolder(),"homes.yml");
|
||||
homes=YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
void register() {
|
||||
for(String name:List.of("home","sethome","delhome","homes","tpa","tpaccept","tpdeny","spawn","server","essentials")) {
|
||||
PluginCommand command=Objects.requireNonNull(plugin.getCommand(name));
|
||||
command.setExecutor(this); command.setTabCompleter(this);
|
||||
}
|
||||
Bukkit.getPluginManager().registerEvents(this,plugin);
|
||||
}
|
||||
static String homeName(String[] args) {
|
||||
String name=args.length==0?"home":args[0].toLowerCase(Locale.ROOT);
|
||||
if(args.length>1 || !name.matches("[a-z0-9_-]{1,24}")) throw new IllegalArgumentException("Use a home name with 1–24 letters, numbers, underscores or hyphens.");
|
||||
return name;
|
||||
}
|
||||
private String key(Player p,String name) { return p.getUniqueId()+"."+name; }
|
||||
private Set<String> names(Player p) {
|
||||
var section=homes.getConfigurationSection(p.getUniqueId().toString());
|
||||
return section==null?Set.of():section.getKeys(false);
|
||||
}
|
||||
private void save() throws IOException {
|
||||
Path target=file.toPath(), temp=target.resolveSibling("homes.yml.tmp");
|
||||
Files.createDirectories(target.getParent());
|
||||
Files.writeString(temp,homes.saveToString());
|
||||
try { Files.move(temp,target,StandardCopyOption.ATOMIC_MOVE,StandardCopyOption.REPLACE_EXISTING); }
|
||||
catch(AtomicMoveNotSupportedException ex) { Files.move(temp,target,StandardCopyOption.REPLACE_EXISTING); }
|
||||
}
|
||||
private void teleport(Player p,Location location) {
|
||||
// Local essentials never bypass interplanetary permits, fares, or arrival rules.
|
||||
if(location==null || location.getWorld()==null) { p.sendMessage("That destination is unavailable on this server."); return; }
|
||||
if(!p.getWorld().equals(location.getWorld())) { p.sendMessage("Use /server to travel between worlds, then /home at your destination."); return; }
|
||||
if(!location.getWorld().getWorldBorder().isInside(location) || location.getY()<location.getWorld().getMinHeight() || location.getY()>=location.getWorld().getMaxHeight()) {
|
||||
p.sendMessage("That destination is outside the world's playable bounds."); return;
|
||||
}
|
||||
p.teleportAsync(location).thenAccept(success->{ if(!success) p.sendMessage("Teleportation failed. Try again."); });
|
||||
}
|
||||
void menu(Player p) {
|
||||
List<NativeMenus.Choice> choices=new ArrayList<>();
|
||||
choices.add(new NativeMenus.Choice("Set home","Save your current position as home.",()->p.performCommand("sethome")));
|
||||
choices.add(new NativeMenus.Choice("Homes","Choose a saved home on this backend.",()->homeMenu(p)));
|
||||
choices.add(new NativeMenus.Choice("Spawn","Return to this world's spawn.",()->p.performCommand("spawn")));
|
||||
choices.add(new NativeMenus.Choice("Guild servers","Travel using existing Solaris fares and permissions.",()->p.performCommand("duneess travel")));
|
||||
choices.add(new NativeMenus.Choice("Solaris","Show your balance.",()->p.performCommand("duneess balance")));
|
||||
choices.add(new NativeMenus.Choice("CHOAM Exchange","Buy, list and reclaim items.",()->p.performCommand("exchange")));
|
||||
choices.add(new NativeMenus.Choice("Help","Open the Dune Field Guide.",()->p.performCommand("duneess help menu")));
|
||||
NativeMenus.show(plugin,p,"DuneRealms Essentials","Solaris: "+plugin.economy().format(plugin.economy().getBalance(p)),choices);
|
||||
}
|
||||
private void homeMenu(Player p) {
|
||||
List<NativeMenus.Choice> choices=names(p).stream().sorted().map(name->new NativeMenus.Choice(name,"Teleport to this saved home.",()->p.performCommand("home "+name))).toList();
|
||||
if(choices.isEmpty()) p.sendMessage("You have no homes. Use /sethome [name].");
|
||||
else NativeMenus.show(plugin,p,"Your homes",choices);
|
||||
}
|
||||
@Override public boolean onCommand(CommandSender sender,Command command,String label,String[] args) {
|
||||
if(!(sender instanceof Player p)) { sender.sendMessage("Use this command in-game."); return true; }
|
||||
String action=command.getName();
|
||||
if(!p.hasPermission("duneess.basics")) { p.sendMessage("You do not have permission to use essentials."); return true; }
|
||||
try {
|
||||
switch(action) {
|
||||
case "essentials" -> menu(p);
|
||||
case "homes" -> homeMenu(p);
|
||||
case "sethome" -> {
|
||||
String name=homeName(args), path=key(p,name);
|
||||
if(!homes.contains(path) && names(p).size()>=Math.max(1,plugin.getConfig().getInt("essentials.max-homes",3))) throw new IllegalArgumentException("Your home limit has been reached.");
|
||||
homes.set(path,p.getLocation()); save(); p.sendMessage("Home saved: "+name);
|
||||
}
|
||||
case "home" -> teleport(p,homes.getLocation(key(p,homeName(args))));
|
||||
case "delhome" -> {
|
||||
String name=homeName(args),path=key(p,name);
|
||||
if(!homes.contains(path)) throw new IllegalArgumentException("That home does not exist.");
|
||||
homes.set(path,null); save(); p.sendMessage("Home removed: "+name);
|
||||
}
|
||||
case "spawn" -> teleport(p,p.getWorld().getSpawnLocation());
|
||||
case "server" -> plugin.onCommand(p,Objects.requireNonNull(plugin.getCommand("duneess")),"duneess",args.length==0?new String[]{"travel"}:new String[]{"travel",args[0]});
|
||||
case "tpa" -> {
|
||||
if(args.length!=1) throw new IllegalArgumentException("Usage: /tpa <online player>");
|
||||
Player target=Bukkit.getPlayerExact(args[0]);
|
||||
if(target==null || target.equals(p) || !p.canSee(target)) throw new IllegalArgumentException("Choose another online player on this server.");
|
||||
if(!target.getWorld().equals(p.getWorld())) throw new IllegalArgumentException("Use Guild travel to reach that player's world first.");
|
||||
requests.put(target.getUniqueId(),new Request(p.getUniqueId(),System.nanoTime()+60_000_000_000L));
|
||||
target.sendMessage(p.getName()+" requests to teleport to you. /tpaccept or /tpdeny (60 seconds).");
|
||||
p.sendMessage("Teleport request sent.");
|
||||
}
|
||||
case "tpaccept","tpdeny" -> {
|
||||
Request request=requests.remove(p.getUniqueId());
|
||||
if(request==null || request.expires()<System.nanoTime()) throw new IllegalArgumentException("No active teleport request.");
|
||||
Player requester=Bukkit.getPlayer(request.sender());
|
||||
if(requester==null || !requester.isOnline()) throw new IllegalArgumentException("That player is offline.");
|
||||
if(action.equals("tpaccept")) teleport(requester,p.getLocation());
|
||||
else requester.sendMessage("Your teleport request was declined.");
|
||||
}
|
||||
default -> { return false; }
|
||||
}
|
||||
} catch(IllegalArgumentException ex) { p.sendMessage(ex.getMessage()); }
|
||||
catch(IOException ex) {
|
||||
homes=YamlConfiguration.loadConfiguration(file);
|
||||
plugin.getLogger().warning("Could not persist homes: "+ex.getMessage());
|
||||
p.sendMessage("Could not save your homes. No change was committed.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override public List<String> onTabComplete(CommandSender sender,Command command,String alias,String[] args) {
|
||||
if(!(sender instanceof Player p) || args.length!=1) return List.of();
|
||||
Collection<String> values=switch(command.getName()) {
|
||||
case "home","delhome" -> names(p);
|
||||
case "tpa" -> Bukkit.getOnlinePlayers().stream().filter(p::canSee).map(Player::getName).toList();
|
||||
case "server" -> List.of("arrakis","giedi_prime","caladan","kaitain","sigma_draconis_iv","spacing_guild");
|
||||
default -> List.of();
|
||||
};
|
||||
return values.stream().filter(v->v.toLowerCase(Locale.ROOT).startsWith(args[0].toLowerCase(Locale.ROOT))).toList();
|
||||
}
|
||||
@EventHandler public void quit(PlayerQuitEvent event) {
|
||||
UUID id=event.getPlayer().getUniqueId();
|
||||
requests.remove(id); requests.values().removeIf(request->request.sender().equals(id));
|
||||
}
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@ import java.math.BigDecimal;
|
|||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
/** Standard inventory slots work on Java and through Geyser without custom client interfaces. */
|
||||
/** Native menus share the existing SQL-backed trading operations. */
|
||||
@SuppressWarnings("deprecation")
|
||||
final class ExchangeMenu implements Listener, CommandExecutor, TabCompleter {
|
||||
private static final List<String> CATEGORIES=List.of("ores","spice","building","equipment","farming","misc");
|
||||
|
|
@ -28,6 +28,7 @@ final class ExchangeMenu implements Listener, CommandExecutor, TabCompleter {
|
|||
final UUID owner;
|
||||
final Map<Integer,Runnable> actions=new HashMap<>();
|
||||
Inventory inventory;
|
||||
String title;
|
||||
Screen(UUID owner) { this.owner=owner; }
|
||||
@Override public Inventory getInventory() { return inventory; }
|
||||
}
|
||||
|
|
@ -72,6 +73,7 @@ final class ExchangeMenu implements Listener, CommandExecutor, TabCompleter {
|
|||
}
|
||||
private Screen screen(Player p,String title) {
|
||||
Screen s=new Screen(p.getUniqueId());
|
||||
s.title="CHOAM | "+title;
|
||||
s.inventory=Bukkit.createInventory(s,54,tint(p)+"CHOAM | "+title);
|
||||
Material glass=switch(faction(p)) {
|
||||
case "Atreides" -> Material.CYAN_STAINED_GLASS_PANE;
|
||||
|
|
@ -106,7 +108,7 @@ final class ExchangeMenu implements Listener, CommandExecutor, TabCompleter {
|
|||
});
|
||||
if(p.hasPermission("dune.admin")) button(s,42,Material.COMMAND_BLOCK,"Exchange Administration",()->admin(p));
|
||||
button(s,49,Material.BARRIER,"Close",p::closeInventory);
|
||||
p.openInventory(s.inventory);
|
||||
com.example.dunegui.NativeMenus.inventory(plugin,p,s.title,s.inventory,s.actions);
|
||||
}
|
||||
private void planetMenu(Player p) {
|
||||
Screen s=screen(p,"Planet Filter");
|
||||
|
|
@ -114,7 +116,7 @@ final class ExchangeMenu implements Listener, CommandExecutor, TabCompleter {
|
|||
String planet=PLANETS.get(i);
|
||||
button(s,11+i,Material.COMPASS,planet,()->{planets.put(p.getUniqueId(),planet); browse(p,"all",0,false,false);});
|
||||
}
|
||||
p.openInventory(s.inventory);
|
||||
com.example.dunegui.NativeMenus.inventory(plugin,p,s.title,s.inventory,s.actions);
|
||||
}
|
||||
private void admin(Player p) {
|
||||
if(!p.hasPermission("dune.admin")) return;
|
||||
|
|
@ -123,7 +125,7 @@ final class ExchangeMenu implements Listener, CommandExecutor, TabCompleter {
|
|||
button(s,24,Material.REDSTONE,"Check Database",()->{
|
||||
if(connected(p)) p.sendMessage(ChatColor.GREEN+"Shared CHOAM database connected.");
|
||||
});
|
||||
p.openInventory(s.inventory);
|
||||
com.example.dunegui.NativeMenus.inventory(plugin,p,s.title,s.inventory,s.actions);
|
||||
}
|
||||
private ItemStack decode(ExchangeStore.Listing offer) {
|
||||
ItemStack item;
|
||||
|
|
@ -158,7 +160,7 @@ final class ExchangeMenu implements Listener, CommandExecutor, TabCompleter {
|
|||
if(rows.isEmpty()) s.inventory.setItem(22,icon(Material.PAPER,"No matching listings","Try another planet or list a held item."));
|
||||
if(current>0) button(s,45,Material.ARROW,"Previous",()->browse(p,category,current-1,mine,admin));
|
||||
if(rows.size()>28) button(s,53,Material.ARROW,"Next",()->browse(p,category,current+1,mine,admin));
|
||||
p.openInventory(s.inventory);
|
||||
com.example.dunegui.NativeMenus.inventory(plugin,p,s.title,s.inventory,s.actions);
|
||||
});
|
||||
}
|
||||
private void confirm(Player p,long id,boolean reclaim) {
|
||||
|
|
@ -171,7 +173,7 @@ final class ExchangeMenu implements Listener, CommandExecutor, TabCompleter {
|
|||
button(s,30,Material.LIME_CONCRETE,reclaim?"Confirm Reclaim":"Confirm Purchase",()->{
|
||||
p.closeInventory(); if(reclaim) cancel(p,id); else buy(p,id);
|
||||
});
|
||||
button(s,32,Material.RED_CONCRETE,"Never Mind",()->home(p)); p.openInventory(s.inventory);
|
||||
button(s,32,Material.RED_CONCRETE,"Never Mind",()->home(p)); com.example.dunegui.NativeMenus.inventory(plugin,p,s.title,s.inventory,s.actions);
|
||||
});
|
||||
}
|
||||
private boolean fits(Player p,ItemStack item,int amount) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff