Compare commits

...

4 Commits

Author SHA1 Message Date
105d564ec0
Notification on /void give 2024-01-27 00:17:47 +01:00
a7fdff2dd9
Next Item In Merchand 2024-01-27 00:17:24 +01:00
2b2683b22b
Discord Binding 2024-01-26 23:47:46 +01:00
402b94a797
Check if give is not negative 2024-01-26 23:38:12 +01:00
4 changed files with 32 additions and 27 deletions

11
TODO.md
View File

@ -1,8 +1,13 @@
# TODO list
- [ ] i18n
- [-] Make Discord Webhoook for item changes
- [+] Make Discord Webhoook for item changes
- [x] deathBan reset
- [ ] voids exchanges
- [ ] chest name
- [x] voids exchanges
- [x] /void give négatives values
- [+] chest name
- [+] Show next Item
- [ ] /void manage bring
- [ ] Dupe bug (respawn) -> Gamerule
- [+] /void give afficher title
- subtitle + chat

View File

@ -15,7 +15,6 @@ import org.bukkit.entity.Player;
import net.kyori.adventure.text.Component;
import ovh.herisson.thevoidroad.DatabaseManager;
import ovh.herisson.thevoidroad.DiscordWebhook;
import ovh.herisson.thevoidroad.TheVoidRoad;
import ovh.herisson.thevoidroad.Voids;
import ovh.herisson.thevoidroad.Entity.Merchand;
@ -44,7 +43,7 @@ public class VoidCommands implements CommandExecutor, TabCompleter{
case "give":
if(args.length < 2) return false;
Player target = Bukkit.getPlayer(args[1]);
if(target != null && sender instanceof Player ply)
if(target != null && sender instanceof Player ply && Integer.parseInt(args[2]) > 0)
Voids.give(ply,target, Integer.parseInt(args[2]));
break;
case "event":
@ -69,19 +68,6 @@ public class VoidCommands implements CommandExecutor, TabCompleter{
return true;
case "skip":
//TODO(Merchand): Skip trade
break;
case "discord":
String link = DatabaseManager.getInstance().getConfig("discord-wh");
if(!link.equals("")){
DiscordWebhook discord = new DiscordWebhook(link);
discord.setContent("Item mis en vente pendant une heure: " + Merchand.current.x + " au prix de " + Merchand.current.y + TheVoidRoad.CoinGlyph);
try {
discord.execute();
} catch(Exception e){
e.printStackTrace();
}
}
break;
case "goto":
if(sender instanceof Player ply && m.getLocation() != null){

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,12 +121,18 @@ 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);
discord.setContent("Item mis en vente pendant une heure: " + current.x + " au prix de " + current.y + TheVoidRoad.CoinGlyph);
discord.setUsername(m.getName());
discord.setContent("Salut, Je vend actuellement `" + current.x + "` au prix de " + current.y + TheVoidRoad.CoinGlyph);
try {
discord.execute();
} catch(Exception ex){
ex.printStackTrace();
}
}
next = genTrade(e.unixhour + 1);
regenerate();
}
@ -135,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);
}
}

View File

@ -19,6 +19,8 @@ import org.bukkit.scoreboard.ScoreboardManager;
import net.kyori.adventure.bossbar.BossBar;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.title.Title;
public final class Voids implements Listener{
@ -48,11 +50,13 @@ public final class Voids implements Listener{
}
public static boolean give(Player giver, Player receiver, int amount){
if(subtract(giver, amount, false)){
add(receiver, amount);
return true;
}
if( amount < 0 || !subtract(giver, amount, false))
return false;
add(receiver, amount);
giver.sendMessage("Vous avez donné " + amount + TheVoidRoad.CoinGlyph + " à " + receiver.getName());
receiver.sendMessage("Vous avez reçu " + amount + TheVoidRoad.CoinGlyph + " de " + giver.getName());
receiver.showTitle(Title.title(Component.empty(), Component.text("+" + amount + TheVoidRoad.CoinGlyph + " from " + giver.getName()).color(NamedTextColor.GREEN)));
return true;
}
public static HashMap<Player, Integer> scoreboard(){