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