Compare commits

..

5 Commits

Author SHA1 Message Date
131d131dfe
Trying to fix villager spawn 2024-02-05 22:47:19 +01:00
c9dd268c14
Feat: Change way of handling voids
Only store to database when fetching scoreboard or on disconnect.
else just use the persistentStorage from players
2024-02-04 21:38:28 +01:00
a7a88bb619
Log Voids interaction
This is just in case the server would crash and not save current score.
log can be used to see what was the last score at some point
2024-02-04 21:29:03 +01:00
d92a8c6125
Seend a death message to the webhook 2024-02-04 21:28:26 +01:00
30be45065f
Need thevoidmanager.score to execute /void score 2024-02-04 21:27:53 +01:00
6 changed files with 56 additions and 18 deletions

View File

@ -24,5 +24,19 @@ public class BanHourly implements Listener{
e.setKeepLevel(false);
e.getDrops().clear();
e.getPlayer().kick(Component.text("Vous etes mort dans la dernière heure... Patientez la prochaine!"), Cause.BANNED);
// Send death
String link = DatabaseManager.getInstance().getConfig("discord-wh");
if(!link.equals("")){
DiscordWebhook discord = new DiscordWebhook(link);
discord.setUsername("Ange de la mort");
discord.setAvatarUrl("http://static.planetminecraft.com/files/banners/minecraft_banner_18d1g881yg5831c.png");
discord.setContent(e.getDeathMessage());
try {
discord.execute();
} catch(Exception ex){
ex.printStackTrace();
}
}
}
}

View File

@ -67,6 +67,7 @@ public class DatabaseManager {
}
public void setVoids(UUID uuid, int amount) {
Bukkit.getLogger().info("[VOIDS] -> " + uuid.toString() + " to " + amount);
try {
Statement st = con.createStatement();
String query = "INSERT OR REPLACE INTO voids (uuid, amount) VALUES (?, ?)";

View File

@ -76,9 +76,9 @@ public class Merchand implements Listener{
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 brdSize = Bukkit.getWorld("world").getWorldBorder().getSize() - 1;
double x = new Random().nextDouble(brdSize) - brdSize/2, z = new Random().nextDouble(brdSize) - brdSize/2;
m = (Villager) Bukkit.getWorld("world").spawnEntity(center.add(x, 100, z), EntityType.VILLAGER);
m = (Villager) Bukkit.getWorld("world").spawnEntity(center.add(x, 200, z), EntityType.VILLAGER);
m.getPersistentDataContainer().set(tagger, PersistentDataType.BOOLEAN, true);
m.setGlowing(true);
m.setInvulnerable(true);

View File

@ -14,10 +14,6 @@ import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import net.kyori.adventure.text.Component;
import ovh.herisson.thevoidroad.DatabaseManager;
import ovh.herisson.thevoidroad.TheVoidRoad;
import ovh.herisson.thevoidroad.Voids;
import ovh.herisson.thevoidroad.Merchand;
public class VoidCommands implements CommandExecutor, TabCompleter{
private final Merchand m = Merchand.getInstance();
@ -36,10 +32,13 @@ public class VoidCommands implements CommandExecutor, TabCompleter{
}
switch (args[0]) {
case "score":
if(!sender.hasPermission("void.score")){
Voids.scoreboard().forEach((p, a) -> {
sender.sendMessage(p + " : " + a);
});
return true;
}
return false;
case "give":
if(args.length < 2) return false;
Player target = Bukkit.getPlayer(args[1]);
@ -117,10 +116,13 @@ public class VoidCommands implements CommandExecutor, TabCompleter{
ArrayList<String> list = new ArrayList<>();
if(args.length == 1){
list.addAll(List.of("give","event", "score"));
list.addAll(List.of("give","event"));
if(sender.hasPermission("void.manage")){
list.add("manage");
}
if(sender.hasPermission("void.score")){
list.add("score");
}
}
if(args.length >= 2){
switch (args[0]) {

View File

@ -5,17 +5,18 @@ import java.util.HashMap;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.scoreboard.Criteria;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.RenderType;
import org.bukkit.scoreboard.Score;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.ScoreboardManager;
import net.kyori.adventure.bossbar.BossBar;
import net.kyori.adventure.text.Component;
@ -25,26 +26,30 @@ import net.kyori.adventure.title.Title;
public final class Voids implements Listener{
private static HashMap<Player, BossBar> bossbars = new HashMap<>();
private static final NamespacedKey voids = new NamespacedKey(TheVoidRoad.instance, "voids");
public static int get(Player ply){
if(ply.getPersistentDataContainer().has(voids)){
return ply.getPersistentDataContainer().get(voids, PersistentDataType.INTEGER);
}
return TheVoidRoad.db.getVoids(ply.getUniqueId());
}
public static void set(Player ply, int amount){
TheVoidRoad.db.setVoids(ply.getUniqueId(), amount);
ply.getPersistentDataContainer().set(voids, PersistentDataType.INTEGER, amount);
UpdateVoids(ply);
}
public static void add(Player ply, int amount){
int curr = DatabaseManager.getInstance().getVoids(ply.getUniqueId());
DatabaseManager.getInstance().setVoids(ply.getUniqueId(), curr + amount);
int curr = get(ply);
set(ply, curr + amount);
UpdateVoids(ply);
}
public static boolean subtract(Player ply, int amount, boolean force){
int curr = TheVoidRoad.db.getVoids(ply.getUniqueId());
int curr = get(ply);
if(curr - amount < 0 && !force) return false;
TheVoidRoad.db.setVoids(ply.getUniqueId(), curr - amount);
set(ply, curr - amount);
UpdateVoids(ply);
return true;
}
@ -59,7 +64,15 @@ public final class Voids implements Listener{
return true;
}
public static void save(Player ply){
int curr = get(ply);
TheVoidRoad.db.setVoids(ply.getUniqueId(), curr);
}
public static HashMap<Player, Integer> scoreboard(){
Bukkit.getServer().forEachAudience(a -> {
if(a instanceof Player ply) save(ply);
});
HashMap<Player, Integer> ret = new HashMap<>();
try {
HashMap<UUID, Integer> scores_uuid = TheVoidRoad.db.getVoidsScoreboard();
@ -95,4 +108,9 @@ public final class Voids implements Listener{
public void UpdateVoids(PlayerJoinEvent e){
UpdateVoids(e.getPlayer());
}
@EventHandler
public void SaveToDbBeforeQuit(PlayerQuitEvent e){
save(e.getPlayer());
}
}

View File

@ -16,6 +16,9 @@ permissions:
void.manage:
description: "GameMaster's command"
default: op
void.score:
description: "score the voids"
default: op
void.balance:
description: "User of thevoidroad"
default: not op