auto commit

This commit is contained in:
destro174
2021-07-27 18:46:58 +02:00
parent 04ac327365
commit 0891e252f9
25 changed files with 362 additions and 70 deletions
+2 -2
View File
@@ -21,8 +21,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>15</source>
<target>15</target>
<source>16</source>
<target>16</target>
</configuration>
</plugin>
<plugin>
+2 -2
View File
@@ -28,8 +28,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>15</source>
<target>15</target>
<source>16</source>
<target>16</target>
</configuration>
</plugin>
<plugin>
@@ -1,9 +1,6 @@
package com.alttd.chat;
import com.alttd.chat.commands.GlobalChat;
import com.alttd.chat.commands.Message;
import com.alttd.chat.commands.Reply;
import com.alttd.chat.commands.ToggleGlobalChat;
import com.alttd.chat.commands.*;
import com.alttd.chat.config.Config;
import com.alttd.chat.database.DatabaseConnection;
import com.alttd.chat.handler.ChatHandler;
@@ -36,6 +33,8 @@ public class ChatPlugin extends JavaPlugin {
registerCommand("toggleglobalchat", new ToggleGlobalChat());
registerCommand("message", new Message());
registerCommand("reply", new Reply());
registerCommand("ignore", new Ignore());
registerCommand("unignore", new Unignore());
messageChannel = Config.MESSAGECHANNEL;
getServer().getMessenger().registerOutgoingPluginChannel(this, messageChannel);
+51
View File
@@ -0,0 +1,51 @@
package com.alttd.chat.commands;
import com.alttd.chat.ChatPlugin;
import com.alttd.chat.database.Queries;
import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.objects.ChatUser;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.UUID;
public class Ignore implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) { // must be a player
return true;
}
if(args.length > 1) return false; // todo error message or command info
String targetName = args[0];
Player targetPlayer = Bukkit.getPlayer(targetName);
if(targetPlayer == null) { // can't ignore offline players
//sender.sendMessage("Target not found..."); // TODO load from config and minimessage
return false;
}
if(targetPlayer.hasPermission("chat.ignorebypass")) {
sender.sendMessage("You can't ignore this player"); // TODO load from config and minimessage
return false;
}
UUID target = targetPlayer.getUniqueId();
new BukkitRunnable() {
@Override
public void run() {
ChatUser chatUser = ChatUserManager.getChatUser(((Player) sender).getUniqueId());
if(!chatUser.getIgnoredPlayers().contains(target)) {
chatUser.addIgnoredPlayers(target);
Queries.ignoreUser(((Player) sender).getUniqueId(), target);
sender.sendMessage("You have turned ignored " + targetName + "."); // TODO load from config and minimessage
} else {
sender.sendMessage("You have already ignored " + targetName + "."); // TODO load from config and minimessage
}
}
}.runTaskAsynchronously(ChatPlugin.getInstance());
return false;
}
}
@@ -0,0 +1,25 @@
package com.alttd.chat.commands;
import com.alttd.chat.ChatPlugin;
import org.apache.commons.lang.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Mail implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) { // must be a player, @teri should console be able to /msg?
return true;
}
Player player = (Player) sender;
if(args.length > 2) return false; // todo error message or command info
String message = StringUtils.join(args, " ", 1, args.length);
ChatPlugin.getInstance().getChatHandler().privateMessage(player, args[0], message);
return false;
}
}
@@ -11,11 +11,11 @@ public class Message implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) { // must be a player, @teri should console be able to /msg?
if(!(sender instanceof Player)) {
return true;
}
Player player = (Player) sender;
if(args.length > 2) return false; // todo error message or command info
if(args.length < 2) return false; // todo error message or command info
String message = StringUtils.join(args, " ", 1, args.length);
ChatPlugin.getInstance().getChatHandler().privateMessage(player, args[0], message);
@@ -13,7 +13,7 @@ public class Reply implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) { // must be a player, @teri should console be able to /msg?
if(!(sender instanceof Player)) {
return true;
}
Player player = (Player) sender;
@@ -1,8 +1,10 @@
package com.alttd.chat.commands;
import com.alttd.chat.ChatPlugin;
import com.alttd.chat.database.Queries;
import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.objects.ChatUser;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.apache.commons.lang.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@@ -24,9 +26,10 @@ public class ToggleGlobalChat implements CommandExecutor {
public void run() {
ChatUser chatUser = ChatUserManager.getChatUser(((Player) sender).getUniqueId());
chatUser.toggleGc();
sender.sendMessage("You have turned globalchat " + (chatUser.isGcOn() ? "<green>on." : "<red>off.")); // TODO load from config and minimessage
Queries.setGlobalChatState(chatUser.isGcOn(), chatUser.getUuid());
sender.sendMessage(MiniMessage.get().parse("You have turned globalchat " + (chatUser.isGcOn() ? "<green>on." : "<red>off."))); // TODO load from config and minimessage
}
}.runTask(ChatPlugin.getInstance());
}.runTaskAsynchronously(ChatPlugin.getInstance());
return false;
}
+46
View File
@@ -0,0 +1,46 @@
package com.alttd.chat.commands;
import com.alttd.chat.ChatPlugin;
import com.alttd.chat.database.Queries;
import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.objects.ChatUser;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.UUID;
public class Unignore implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) { // must be a player
return true;
}
if(args.length > 1) return false; // todo error message or command info
String targetName = args[0];
UUID target = Bukkit.getOfflinePlayer(targetName).getUniqueId();
if(target == null) {
//sender.sendMessage("Target not found..."); // TODO load from config and minimessage
return false;
}
new BukkitRunnable() {
@Override
public void run() {
ChatUser chatUser = ChatUserManager.getChatUser(((Player) sender).getUniqueId());
if(chatUser.getIgnoredPlayers().contains(target)) {
chatUser.removeIgnoredPlayers(target);
Queries.ignoreUser(((Player) sender).getUniqueId(), target);
sender.sendMessage("You no longer ignore " + targetName + "."); // TODO load from config and minimessage
} else {
sender.sendMessage("You don't have " + targetName + " ignored."); // TODO load from config and minimessage
}
}
}.runTaskAsynchronously(ChatPlugin.getInstance());
return false;
}
}
@@ -9,6 +9,7 @@ import com.alttd.chat.util.Utility;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.Template;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
@@ -49,7 +50,7 @@ public class ChatHandler {
List<Template> templates = new ArrayList<>(List.of(
Template.of("message", message),
Template.of("[i]", itemComponent(player.getInventory().getItemInMainHand())))); // yes cross server [i];)
Template.of("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
Component component = miniMessage.parse("<message>", templates);
@@ -65,7 +66,7 @@ public class ChatHandler {
}
long timeLeft = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - user.getGcCooldown());
if(timeLeft <= Config.GCCOOLDOWN) { // player is on cooldown and should wait x seconds
player.sendMessage(miniMessage.parse(Config.GCONCOOLDOWN, Template.of("cooldown", timeLeft+"")));
player.sendMessage(miniMessage.parse(Config.GCONCOOLDOWN, Template.of("cooldown", Config.GCCOOLDOWN-timeLeft+"")));
return;
}
@@ -90,7 +91,7 @@ public class ChatHandler {
Template.of("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
Component component = miniMessage.parse(Config.GCFORMAT, templates);
user.setGcCooldown(System.currentTimeMillis());
sendPluginMessage(player, "globalchat", component);
}
@@ -112,15 +113,16 @@ public class ChatHandler {
// Start - move these to util
public static Component itemComponent(ItemStack item) {
Component component = Component.text("[i]");
if(item.getType().equals(Material.AIR)) // do we want to show the <players hand>?
return component;
Component component = Component.text("[i]", NamedTextColor.AQUA);
if(item.getType().equals(Material.AIR))
return component.color(NamedTextColor.WHITE);
boolean dname = item.hasItemMeta() && item.getItemMeta().hasDisplayName();
if(dname) {
component = component.append(item.getItemMeta().displayName());
} else {
component = Component.text(materialToName(item.getType()));
component = component.append(Component.text(materialToName(item.getType()), NamedTextColor.WHITE));
}
component = component.append(Component.text(" x" + item.getAmount(), NamedTextColor.AQUA));
component = component.hoverEvent(item.asHoverEvent());
return component;
}
@@ -1,5 +1,6 @@
package com.alttd.chat.listeners;
import com.alttd.chat.database.Queries;
import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.managers.RegexManager;
import com.alttd.chat.objects.ChatUser;
@@ -9,6 +10,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.List;
import java.util.UUID;
@@ -23,9 +25,16 @@ public class PlayerListener implements Listener {
// todo actually load the users from db
ChatUserManager.addUser(new ChatUser(uuid, -1, false, false));
}
@EventHandler
private void onPlayerLogout(PlayerQuitEvent event) {
UUID uuid = event.getPlayer().getUniqueId();
ChatUser user = ChatUserManager.getChatUser(uuid);
ChatUserManager.removeUser(user);
}
@EventHandler(ignoreCancelled = true) // untested
public void onSignChangeE(SignChangeEvent event) {
for (int i = 0; i < 4; i++) {
@@ -1,11 +1,19 @@
package com.alttd.chat.listeners;
import com.alttd.chat.ChatPlugin;
import com.alttd.chat.config.Config;
import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.objects.ChatUser;
import com.alttd.chat.util.ALogger;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import java.util.UUID;
public class PluginMessage implements PluginMessageListener {
@Override
@@ -16,6 +24,16 @@ public class PluginMessage implements PluginMessageListener {
ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
String subChannel = in.readUTF();
switch (subChannel) {
case "privatemessage":
UUID uuid = UUID.fromString(in.readUTF());
String target = in.readUTF();
Player p = Bukkit.getPlayer(uuid);
if(p != null) {
ChatUser user = ChatUserManager.getChatUser(uuid);
user.setReplyTarget(target);
p.sendMessage(GsonComponentSerializer.gson().deserialize(in.readUTF()));
}
break;
case "globalchat":
break;
default:
+5 -1
View File
@@ -18,4 +18,8 @@ commands:
aliases: msg
reply:
permission: command.message
aliases: r
aliases: r
ignore:
permission: command.ignore
unignore:
permission: command.ignore