Next Item In Merchand

This commit is contained in:
Debucquoy Anthony 2024-01-27 00:17:24 +01:00
parent 2b2683b22b
commit a7fdff2dd9
Signed by: tonitch
GPG Key ID: A78D6421F083D42E

View File

@ -37,7 +37,7 @@ public class Merchand implements Listener{
private static Merchand instance;
private static final ArrayList<Material> mat = new ArrayList<>();
private static final ArrayList<String> names = new ArrayList<>();
private final Inventory inv;
private static Inventory inv;
private Villager m ;
private static final NamespacedKey tagger = new NamespacedKey(TheVoidRoad.instance, "merchand") ;
@ -49,7 +49,6 @@ public class Merchand implements Listener{
}
private Merchand() {
inv = Bukkit.createInventory(null, 9);
//Get file materials
File f = new File(TheVoidRoad.instance.getDataFolder(), "materials.txt");
@ -81,6 +80,7 @@ public class Merchand implements Listener{
public void regenerate(){
if(m != null){ m.remove(); }
current = genTrade(System.currentTimeMillis() / (1000 * 60 * 60));
next = genTrade(1 + System.currentTimeMillis() / (1000 * 60 * 60));
Location center = Bukkit.getWorld("world").getWorldBorder().getCenter();
double brdSize = Bukkit.getWorld("world").getWorldBorder().getSize();
double x = new Random().nextDouble(brdSize) - brdSize/2, z = new Random().nextDouble(brdSize) - brdSize/2;
@ -89,6 +89,7 @@ public class Merchand implements Listener{
m.setGlowing(true);
m.setInvulnerable(true);
m.customName(Component.text(names.get(new Random().nextInt(names.size()))));
inv = Bukkit.createInventory(null, 9, Component.text(m.getName()));
Bukkit.getServer().forEachAudience((a) -> {
if(a instanceof Player ply){
ply.setCompassTarget(m.getLocation());
@ -120,6 +121,7 @@ public class Merchand implements Listener{
@EventHandler
public void onHour(HourEvent e){
current = genTrade(e.unixhour);
next = genTrade(e.unixhour + 1);
String link = DatabaseManager.getInstance().getConfig("discord-wh");
if(!link.equals("")){
DiscordWebhook discord = new DiscordWebhook(link);
@ -131,7 +133,6 @@ public class Merchand implements Listener{
ex.printStackTrace();
}
}
next = genTrade(e.unixhour + 1);
regenerate();
}
@ -141,6 +142,9 @@ public class Merchand implements Listener{
e.setCancelled(true);
inv.clear();
inv.setItem(4, new ItemStack(current.x, current.y));
ItemStack nextItem = new ItemStack(next.x,next.y);
nextItem.editMeta(m ->{ m.setDisplayName("Prochain item en vente"); });
inv.setItem(8, nextItem);
e.getPlayer().openInventory(inv);
}
}