diff --git a/pom.xml b/pom.xml
index 8fd1e50..1447579 100644
--- a/pom.xml
+++ b/pom.xml
@@ -24,9 +24,25 @@
papermc
https://repo.papermc.io/repository/maven-public/
+
+ jitpack.io
+ https://jitpack.io
+
+
+ net.dv8tion
+ JDA
+ 5.0.1
+ compile
+
+
+ club.minnced
+ discord-webhooks
+ 0.1.6
+ compile
+
org.postgresql
postgresql
diff --git a/src/main/java/rip/iwakura/civilcore/CivilCore.java b/src/main/java/rip/iwakura/civilcore/CivilCore.java
index efa312e..cf40b56 100644
--- a/src/main/java/rip/iwakura/civilcore/CivilCore.java
+++ b/src/main/java/rip/iwakura/civilcore/CivilCore.java
@@ -4,18 +4,28 @@ import java.sql.SQLException;
import java.util.ArrayList;
import org.bukkit.Bukkit;
+import org.bukkit.WorldCreator;
import org.bukkit.plugin.java.JavaPlugin;
import net.md_5.bungee.api.ChatColor;
import rip.iwakura.civilcore.commands.TeamCommand;
+import rip.iwakura.civilcore.discord.Discord;
public class CivilCore extends JavaPlugin {
public Database db = new Database();
+ public Discord bot;
@Override
public void onEnable() {
this.saveDefaultConfig();
+ this.bot = new Discord(getConfig().getString("discord.token"), getConfig().getString("discord.channel"), this);
+ this.bot.initialize();
+
+ if (Bukkit.getWorld("court") == null) {
+ new WorldCreator("court").createWorld();
+ }
+
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
@@ -28,6 +38,8 @@ public class CivilCore extends JavaPlugin {
e.printStackTrace();
}
getServer().getPluginManager().registerEvents(new PlayerHandler(this), this);
+ getServer().getPluginManager().registerEvents(new Court(), this);
this.getCommand("team").setExecutor(new TeamCommand(this));
+ this.getCommand("court").setExecutor(new Court());
}
}
diff --git a/src/main/java/rip/iwakura/civilcore/Court.java b/src/main/java/rip/iwakura/civilcore/Court.java
new file mode 100644
index 0000000..30fd160
--- /dev/null
+++ b/src/main/java/rip/iwakura/civilcore/Court.java
@@ -0,0 +1,64 @@
+package rip.iwakura.civilcore;
+
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.block.BlockBreakEvent;
+import org.bukkit.event.block.BlockBurnEvent;
+import org.bukkit.event.block.BlockPlaceEvent;
+import org.bukkit.event.block.BlockSpreadEvent;
+
+public class Court implements Listener,CommandExecutor{
+ private World court_world = Bukkit.getWorld("court");
+
+ private Location court_location = new Location(court_world, 4.5, 70.0, 0.5, -90f, 1.0f);
+
+ @EventHandler
+ public void PlayerBreak(BlockBreakEvent e) {
+ if (e.getPlayer().isOp()) return;
+ if (e.getBlock().getWorld().getName().equals(court_world.getName())) e.setCancelled(true);
+ }
+ @EventHandler
+ public void PlayerPlace(BlockPlaceEvent e) {
+ if (e.getPlayer().isOp()) return;
+ if (e.getBlock().getWorld().getName().equals(court_world.getName())) e.setCancelled(true);
+ }
+ @EventHandler
+ public void PlayerBurn(BlockBurnEvent e) {
+ if (e.getBlock().getWorld().getName().equals(court_world.getName())) e.setCancelled(true);
+ }
+ @EventHandler
+ public void FireSpread(BlockSpreadEvent e) {
+ if (e.getBlock().getWorld().getName().equals(court_world.getName())) e.setCancelled(true);
+ }
+ @Override
+ public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
+ if (!(sender instanceof Player)) {
+ sender.sendMessage("Non-player type.");
+ return true;
+ }
+
+ Player p = (Player) sender;
+
+ switch (args[0]) {
+ case "enter":
+ p.teleport(court_location);
+ break;
+ case "leave":
+ Location loc = p.getBedSpawnLocation();
+ if (loc == null) {
+ loc = Bukkit.getWorld("world").getSpawnLocation();
+ }
+ p.teleport(loc);
+ break;
+ }
+ return true;
+ }
+
+}
diff --git a/src/main/java/rip/iwakura/civilcore/PlayerHandler.java b/src/main/java/rip/iwakura/civilcore/PlayerHandler.java
index 15cc9ac..219cfc2 100644
--- a/src/main/java/rip/iwakura/civilcore/PlayerHandler.java
+++ b/src/main/java/rip/iwakura/civilcore/PlayerHandler.java
@@ -31,6 +31,8 @@ public class PlayerHandler implements Listener {
String prefix = dbPlayer.team.prefix == null ? "" : ChatColor.translateAlternateColorCodes('&', dbPlayer.team.prefix) + " ";
Bukkit.broadcastMessage(String.format("%s%s: %s", prefix, player_name, e.getMessage()));
+
+ civilCore.bot.sendMessage(e);
}
@EventHandler
public void PlayerJoinEvent(PlayerJoinEvent e) {
diff --git a/src/main/java/rip/iwakura/civilcore/commands/TeamCommand.java b/src/main/java/rip/iwakura/civilcore/commands/TeamCommand.java
index 0e1a282..66040dd 100644
--- a/src/main/java/rip/iwakura/civilcore/commands/TeamCommand.java
+++ b/src/main/java/rip/iwakura/civilcore/commands/TeamCommand.java
@@ -22,7 +22,7 @@ public class TeamCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- args = Utils.parser(args).toArray(new String[args.length]);
+ args = Utils.parser(args).toArray(new String[0]);
if(args.length == 0) {
sender.sendMessage(ChatColor.RED + "Usage: /team [options]");
diff --git a/src/main/java/rip/iwakura/civilcore/discord/Discord.java b/src/main/java/rip/iwakura/civilcore/discord/Discord.java
new file mode 100644
index 0000000..85c9fb2
--- /dev/null
+++ b/src/main/java/rip/iwakura/civilcore/discord/Discord.java
@@ -0,0 +1,73 @@
+package rip.iwakura.civilcore.discord;
+
+import java.util.EnumSet;
+
+import org.bukkit.Bukkit;
+import org.bukkit.event.player.AsyncPlayerChatEvent;
+import org.checkerframework.common.reflection.qual.GetConstructor;
+
+import club.minnced.discord.webhook.WebhookClient;
+import club.minnced.discord.webhook.WebhookClientBuilder;
+import club.minnced.discord.webhook.send.WebhookMessage;
+import club.minnced.discord.webhook.send.WebhookMessageBuilder;
+import net.dv8tion.jda.api.JDA;
+import net.dv8tion.jda.api.JDABuilder;
+import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
+import net.dv8tion.jda.api.hooks.ListenerAdapter;
+import net.dv8tion.jda.api.requests.GatewayIntent;
+import rip.iwakura.civilcore.CivilCore;
+import net.dv8tion.jda.api.events.session.ReadyEvent;
+
+public class Discord extends ListenerAdapter {
+ private String token;
+ private CivilCore civilCore;
+
+ public String channelId;
+
+ private TextChannel channel;
+ private WebhookClient webhook;
+
+ public JDA bot;
+
+ private EnumSet intents = EnumSet.of(GatewayIntent.GUILD_MESSAGES, GatewayIntent.MESSAGE_CONTENT, GatewayIntent.GUILD_WEBHOOKS);
+
+ public Discord(String token, String channelId, CivilCore civilCore){
+ this.civilCore = civilCore;
+ this.channelId = channelId;
+ this.token = token;
+ }
+
+ public void initialize() {
+ this.bot = JDABuilder.createLight(token, intents)
+ .addEventListeners(new MessageReceive(civilCore))
+ .addEventListeners(this)
+ .build();
+ }
+
+ public void sendMessage(AsyncPlayerChatEvent e) {
+ String player_name = e.getPlayer().getName();
+ WebhookMessageBuilder builder = new WebhookMessageBuilder()
+ .setUsername(player_name)
+ .setAvatarUrl(String.format("https://mc-heads.net/avatar/%s", player_name))
+ .setContent(e.getMessage());
+ webhook.send(builder.build());
+ //channel.sendMessage(String.format("%s: %s", e.getPlayer().getName(), e.getMessage())).complete();
+ }
+
+ @Override
+ public void onReady(ReadyEvent e) {
+ this.channel = bot.getTextChannelById(channelId);
+ String webhook_token = civilCore.getConfig().getString("discord.webhook.token");
+ Long webhook_id = Long.parseLong(civilCore.getConfig().getString("discord.webhook.id"));
+ if (webhook_token != null) {
+ this.webhook = new WebhookClientBuilder(webhook_id, webhook_token).build();
+ } else {
+ channel.createWebhook("CivilBot").queue((hook) -> {
+ civilCore.getConfig().set("discord.webhook.id", hook.getId());
+ civilCore.getConfig().set("discord.webhook.token", hook.getToken());
+ civilCore.saveConfig();
+ this.webhook = new WebhookClientBuilder(Long.parseLong(hook.getId()), hook.getToken()).build();
+ });
+ }
+ }
+}
diff --git a/src/main/java/rip/iwakura/civilcore/discord/MessageReceive.java b/src/main/java/rip/iwakura/civilcore/discord/MessageReceive.java
new file mode 100644
index 0000000..a2a5617
--- /dev/null
+++ b/src/main/java/rip/iwakura/civilcore/discord/MessageReceive.java
@@ -0,0 +1,22 @@
+package rip.iwakura.civilcore.discord;
+
+import org.bukkit.Bukkit;
+
+import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
+import net.dv8tion.jda.api.hooks.ListenerAdapter;
+import net.md_5.bungee.api.ChatColor;
+import rip.iwakura.civilcore.CivilCore;
+
+public class MessageReceive extends ListenerAdapter {
+ private CivilCore civilCore;
+
+ public MessageReceive (CivilCore civilCore) {
+ this.civilCore = civilCore;
+ }
+
+ @Override
+ public void onMessageReceived(MessageReceivedEvent e) {
+ if (e.getAuthor().isBot()) return;
+ if(e.getChannel().getId().equals(civilCore.bot.channelId)) Bukkit.broadcastMessage(String.format("%sDiscord%s %s: %s", ChatColor.BLUE, ChatColor.RESET, e.getAuthor().getName(), e.getMessage()));
+ }
+}
diff --git a/src/main/java/rip/iwakura/civilcore/types/CoreCommand.java b/src/main/java/rip/iwakura/civilcore/types/CoreCommand.java
new file mode 100644
index 0000000..9f24454
--- /dev/null
+++ b/src/main/java/rip/iwakura/civilcore/types/CoreCommand.java
@@ -0,0 +1,7 @@
+package rip.iwakura.civilcore.types;
+
+import org.bukkit.command.CommandSender;
+
+public interface CoreCommand {
+ public boolean run(CommandSender sender);
+}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 7152f6b..097916b 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -8,3 +8,7 @@ commands:
team:
description: Team Manager
usage: /
+ permission: "civil.teams"
+ court:
+ description: Court Manager
+ usage: /