Compare commits
15 Commits
b08fb8e5a4
...
master
Author | SHA1 | Date | |
---|---|---|---|
131d131dfe
|
|||
c9dd268c14
|
|||
a7a88bb619
|
|||
d92a8c6125
|
|||
30be45065f
|
|||
f36e6b1aa0
|
|||
629695ac21
|
|||
8bf35896f4
|
|||
1d34a3040d
|
|||
af96c5a412
|
|||
105d564ec0
|
|||
a7fdff2dd9
|
|||
2b2683b22b
|
|||
402b94a797
|
|||
56b7ae97ef
|
21
TODO.md
21
TODO.md
@ -1,8 +1,19 @@
|
||||
# TODO list
|
||||
|
||||
- [ ] i18n
|
||||
- [-] Make Discord Webhoook for item changes
|
||||
- [x] deathBan reset
|
||||
- [ ] voids exchanges
|
||||
- [ ] chest name
|
||||
- [ ] /void manage bring
|
||||
- [x] voids exchanges
|
||||
- [x] /void give négatives values
|
||||
- [x] Make Discord Webhoook for item changes
|
||||
- [x] chest name
|
||||
- [x] Show next Item
|
||||
- [x] /void manage bring
|
||||
- [+] /void give afficher title
|
||||
- subtitle + chat
|
||||
- [+] Double Check Inventory reset on die
|
||||
- [+] Annonce
|
||||
- [+] Find Map : 51 (250, 300)
|
||||
- [+] Dupe bug (respawn)
|
||||
- [-] i18n
|
||||
- [ ] Events
|
||||
- [ ] Command completions
|
||||
- [ ] More descriptive /void commands
|
||||
|
@ -20,6 +20,23 @@ public class BanHourly implements Listener{
|
||||
@EventHandler
|
||||
public void died(PlayerDeathEvent e){
|
||||
DatabaseManager.getInstance().setDeath(e.getPlayer().getUniqueId());
|
||||
e.setKeepInventory(true);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class DatabaseManager {
|
||||
@ -68,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 (?, ?)";
|
||||
|
@ -1,4 +1,4 @@
|
||||
package ovh.herisson.thevoidroad.Event;
|
||||
package ovh.herisson.thevoidroad;
|
||||
|
||||
import java.time.LocalTime;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package ovh.herisson.thevoidroad.Entity;
|
||||
package ovh.herisson.thevoidroad;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
@ -24,12 +24,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
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.Event.HourEvent;
|
||||
import ovh.herisson.thevoidroad.util.Tuple;
|
||||
|
||||
//Unique, so singleton patern
|
||||
public class Merchand implements Listener{
|
||||
@ -37,7 +31,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 +43,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,14 +74,17 @@ 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 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);
|
||||
m.customName(Component.text(names.get(new Random().nextInt(names.size()))));
|
||||
m.setCustomNameVisible(true);
|
||||
inv = Bukkit.createInventory(null, 9, Component.text(m.getName()));
|
||||
Bukkit.getServer().forEachAudience((a) -> {
|
||||
if(a instanceof Player ply){
|
||||
ply.setCompassTarget(m.getLocation());
|
||||
@ -120,12 +116,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 +137,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);
|
||||
}
|
||||
}
|
||||
@ -167,4 +172,8 @@ public class Merchand implements Listener{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void teleport(Location location) {
|
||||
m.teleport(location);
|
||||
}
|
||||
}
|
@ -2,9 +2,9 @@ package ovh.herisson.thevoidroad;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import ovh.herisson.thevoidroad.Commands.VoidCommands;
|
||||
import ovh.herisson.thevoidroad.Entity.Merchand;
|
||||
import ovh.herisson.thevoidroad.Event.HourEvent;
|
||||
import ovh.herisson.thevoidroad.VoidCommands;
|
||||
import ovh.herisson.thevoidroad.Merchand;
|
||||
import ovh.herisson.thevoidroad.HourEvent;
|
||||
|
||||
public class TheVoidRoad extends JavaPlugin{
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package ovh.herisson.thevoidroad.util;
|
||||
package ovh.herisson.thevoidroad;
|
||||
|
||||
public class Tuple<X, Y> {
|
||||
public final X x;
|
@ -1,4 +1,4 @@
|
||||
package ovh.herisson.thevoidroad.Commands;
|
||||
package ovh.herisson.thevoidroad;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -14,11 +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.DiscordWebhook;
|
||||
import ovh.herisson.thevoidroad.TheVoidRoad;
|
||||
import ovh.herisson.thevoidroad.Voids;
|
||||
import ovh.herisson.thevoidroad.Entity.Merchand;
|
||||
|
||||
public class VoidCommands implements CommandExecutor, TabCompleter{
|
||||
private final Merchand m = Merchand.getInstance();
|
||||
@ -37,14 +32,17 @@ 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]);
|
||||
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 +67,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){
|
||||
@ -90,6 +75,14 @@ public class VoidCommands implements CommandExecutor, TabCompleter{
|
||||
sender.sendMessage("You can't teleport!");
|
||||
}
|
||||
break;
|
||||
case "bring":
|
||||
if(sender instanceof Player ply && m.getLocation() != null){
|
||||
m.teleport(ply.getLocation());
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case "balance":
|
||||
if(args.length < 5) return false;
|
||||
switch (args[2]) {
|
||||
@ -97,9 +90,6 @@ public class VoidCommands implements CommandExecutor, TabCompleter{
|
||||
Player target_ = Bukkit.getPlayer(args[3]);
|
||||
Voids.set(target_, Integer.parseInt(args[4]));
|
||||
return true;
|
||||
case "add":
|
||||
case "sub":
|
||||
sender.sendMessage("TODO"); //TODO
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -126,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]) {
|
@ -5,57 +5,74 @@ 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;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
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;
|
||||
}
|
||||
|
||||
public static boolean give(Player giver, Player receiver, int amount){
|
||||
if(subtract(giver, amount, false)){
|
||||
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;
|
||||
}
|
||||
return false;
|
||||
|
||||
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();
|
||||
@ -91,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());
|
||||
}
|
||||
}
|
||||
|
@ -10,13 +10,6 @@ COBBLED_DEEPSLATE
|
||||
POLISHED_DEEPSLATE
|
||||
CALCITE
|
||||
TUFF
|
||||
TUFF_WALL
|
||||
CHISELED_TUFF
|
||||
POLISHED_TUFF
|
||||
POLISHED_TUFF_WALL
|
||||
TUFF_BRICKS
|
||||
TUFF_BRICK_WALL
|
||||
CHISELED_TUFF_BRICKS
|
||||
DRIPSTONE_BLOCK
|
||||
GRASS_BLOCK
|
||||
DIRT
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user