Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#111 And #112 #113

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>mineverse.Aust1n46.chat</groupId>
<artifactId>VentureChat</artifactId>
<version>3.7.1</version>
<version>3.7.2</version>
<url>https://bitbucket.org/Aust1n46/venturechat/src/master</url>
<scm>
<url>https://bitbucket.org/Aust1n46/venturechat/src/master</url>
Expand Down Expand Up @@ -221,6 +221,12 @@
<version>1.20-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mineverse/Aust1n46/chat/ChatMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public class ChatMessage {
private String coloredMessage;
private int hash;

public ChatMessage(WrappedChatComponent component, String message, String coloredMessage, int hash) {
public ChatMessage(WrappedChatComponent component, String message, String coloredMessage) {
this.component = component;
this.message = message;
this.coloredMessage = coloredMessage;
this.hash = hash;
this.hash = message.hashCode();
}

public WrappedChatComponent getComponent() {
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/mineverse/Aust1n46/chat/MineverseChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.bukkit.scheduler.BukkitScheduler;

import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.PacketContainer;

import me.clip.placeholderapi.PlaceholderAPI;
Expand All @@ -43,6 +44,7 @@
import mineverse.Aust1n46.chat.listeners.CommandListener;
import mineverse.Aust1n46.chat.listeners.LoginListener;
import mineverse.Aust1n46.chat.listeners.PacketListenerLegacyChat;
import mineverse.Aust1n46.chat.listeners.PacketListenerSystemChat;
import mineverse.Aust1n46.chat.listeners.SignListener;
import mineverse.Aust1n46.chat.localization.Localization;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
Expand Down Expand Up @@ -212,14 +214,17 @@ public void run() {
}

private void registerListeners() {
PluginManager pluginManager = getServer().getPluginManager();
final PluginManager pluginManager = getServer().getPluginManager();
pluginManager.registerEvents(new Channel(), this);
pluginManager.registerEvents(new ChatListener(), this);
pluginManager.registerEvents(new SignListener(), this);
pluginManager.registerEvents(new CommandListener(), this);
pluginManager.registerEvents(new LoginListener(), this);
final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
if (VersionHandler.isUnder_1_19()) {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketListenerLegacyChat());
protocolManager.addPacketListener(new PacketListenerLegacyChat());
} else {
protocolManager.addPacketListener(new PacketListenerSystemChat());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
Expand Down Expand Up @@ -46,7 +47,7 @@ public class MineverseChatPlayer {
private boolean partyChat;
private HashMap<ChatChannel, List<Long>> spam;
private boolean modified;
private List<ChatMessage> messages;
private LinkedList<ChatMessage> messages;
private String jsonFormat;
private boolean editing;
private int editHash;
Expand Down Expand Up @@ -83,7 +84,7 @@ public MineverseChatPlayer(UUID uuid, String name, ChatChannel currentChannel, S
this.replyPlayer = null;
this.partyChat = false;
this.modified = false;
this.messages = new ArrayList<ChatMessage>();
this.messages = new LinkedList<ChatMessage>();
this.jsonFormat = jsonFormat;
this.cooldowns = new HashMap<ChatChannel, Long>();
this.spam = new HashMap<ChatChannel, List<Long>>();
Expand Down Expand Up @@ -116,7 +117,7 @@ public MineverseChatPlayer(UUID uuid, String name) {
this.replyPlayer = null;
this.partyChat = false;
this.modified = false;
this.messages = new ArrayList<ChatMessage>();
this.messages = new LinkedList<ChatMessage>();
this.jsonFormat = "Default";
this.cooldowns = new HashMap<ChatChannel, Long>();
this.spam = new HashMap<ChatChannel, List<Long>>();
Expand Down Expand Up @@ -522,9 +523,9 @@ public List<ChatMessage> getMessages() {

public void addMessage(ChatMessage message) {
if(this.messages.size() >= 100) {
this.messages.remove(0);
this.messages.removeFirst();
}
this.messages.add(message);
this.messages.addLast(message);
}

public void clearMessages() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.List;
import java.util.Map;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -84,20 +83,6 @@ public void run() {
resend = true;
continue;
}
if (message.getMessage().contains(ChatColor.stripColor(Format.FormatStringAll(plugin.getConfig().getString("guiicon"))))) {
String submessage = message.getMessage().substring(0,
message.getMessage().length() - ChatColor.stripColor(Format.FormatStringAll(plugin.getConfig().getString("guiicon"))).length());
if (submessage.hashCode() == hash) {
WrappedChatComponent removedComponent = p.getPlayer().hasPermission("venturechat.message.bypass")
? Removemessage.this.getMessageDeletedChatComponentAdmin(message)
: Removemessage.this.getMessageDeletedChatComponentPlayer();
message.setComponent(removedComponent);
message.setHash(-1);
playerPackets.add(Format.createPacketPlayOutChat(removedComponent));
resend = true;
continue;
}
}
playerPackets.add(Format.createPacketPlayOutChat(message.getComponent()));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
Expand All @@ -20,6 +19,7 @@
import mineverse.Aust1n46.chat.api.MineverseChatPlayer;
import mineverse.Aust1n46.chat.channel.ChatChannel;
import mineverse.Aust1n46.chat.gui.GuiSlot;
import mineverse.Aust1n46.chat.gui.ModerationGuiInventory;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import mineverse.Aust1n46.chat.utilities.Format;
import mineverse.Aust1n46.chat.versions.VersionHandler;
Expand All @@ -34,7 +34,7 @@ public VentureChatGui() {
@Override
public boolean execute(CommandSender sender, String command, String[] args) {
if (!(sender instanceof Player)) {
Bukkit.getServer().getConsoleSender().sendMessage(LocalizedMessage.COMMAND_MUST_BE_RUN_BY_PLAYER.toString());
plugin.getServer().getConsoleSender().sendMessage(LocalizedMessage.COMMAND_MUST_BE_RUN_BY_PLAYER.toString());
return true;
}
if (args.length < 3) {
Expand Down Expand Up @@ -73,40 +73,33 @@ public boolean execute(CommandSender sender, String command, String[] args) {

@SuppressWarnings("deprecation")
private void openInventory(MineverseChatPlayer mcp, MineverseChatPlayer target, ChatChannel channel, int hash) {
Inventory inv = Bukkit.createInventory(null, this.getSlots(), "VentureChat: " + target.getName() + " GUI");
ItemStack close = null;
ItemStack skull = null;
final Inventory inv = plugin.getServer().createInventory(new ModerationGuiInventory(mcp, channel, hash), this.getSlots(), "VentureChat: " + target.getName() + " GUI");
final ItemStack close;
if (VersionHandler.is1_7()) {
close = new ItemStack(Material.BEDROCK);
} else {
close = new ItemStack(Material.BARRIER);
}
ItemMeta closeMeta = close.getItemMeta();
closeMeta.setDisplayName(ChatColor.RED + "" + ChatColor.ITALIC + "Close GUI");
close.setItemMeta(closeMeta);

final ItemStack skull;
if (VersionHandler.is1_7() || VersionHandler.is1_8() || VersionHandler.is1_9() || VersionHandler.is1_10() || VersionHandler.is1_11() || VersionHandler.is1_12()) {
skull = new ItemStack(Material.getMaterial("SKULL_ITEM"));
} else {
skull = new ItemStack(Material.PLAYER_HEAD);
}

ItemMeta closeMeta = close.getItemMeta();
closeMeta.setDisplayName(ChatColor.RED + "" + ChatColor.ITALIC + "Close GUI");
close.setItemMeta(closeMeta);

SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
skullMeta.setOwner(target.getName());
skullMeta.setOwningPlayer(plugin.getServer().getOfflinePlayer(target.getUUID()));
skullMeta.setDisplayName(ChatColor.AQUA + target.getName());
List<String> skullLore = new ArrayList<String>();
skullLore.add(ChatColor.GRAY + "Channel: " + channel.getColor() + channel.getName());
skullLore.add(ChatColor.GRAY + "Hash: " + channel.getColor() + hash);
skullMeta.setLore(skullLore);
skull.setItemMeta(skullMeta);
skull.setDurability((short) 3);
inv.setItem(0, skull);

for (GuiSlot g : GuiSlot.getGuiSlots()) {

for (final GuiSlot g : GuiSlot.getGuiSlots()) {
if (!g.hasPermission() || mcp.getPlayer().hasPermission(g.getPermission())) {
if (this.checkSlot(g.getSlot())) {
MineverseChat.getInstance().getServer().getConsoleSender()
plugin.getServer().getConsoleSender()
.sendMessage(Format.FormatStringAll("&cGUI: " + g.getName() + " has invalid slot: " + g.getSlot() + "!"));
continue;
}
Expand All @@ -125,13 +118,14 @@ private void openInventory(MineverseChatPlayer mcp, MineverseChatPlayer target,
}
}

inv.setItem(0, skull);
inv.setItem(8, close);
mcp.getPlayer().openInventory(inv);
}

@SuppressWarnings("deprecation")
private void openInventoryDiscord(MineverseChatPlayer mcp, ChatChannel channel, int hash) {
Inventory inv = Bukkit.createInventory(null, this.getSlots(), "VentureChat: Discord_Message GUI");
Inventory inv = plugin.getServer().createInventory(null, this.getSlots(), "VentureChat: Discord_Message GUI");
ItemStack close = null;
ItemStack skull = null;
if (VersionHandler.is1_7()) {
Expand Down Expand Up @@ -164,7 +158,7 @@ private void openInventoryDiscord(MineverseChatPlayer mcp, ChatChannel channel,
for (GuiSlot g : GuiSlot.getGuiSlots()) {
if (!g.hasPermission() || mcp.getPlayer().hasPermission(g.getPermission())) {
if (this.checkSlot(g.getSlot())) {
MineverseChat.getInstance().getServer().getConsoleSender()
plugin.getServer().getConsoleSender()
.sendMessage(Format.FormatStringAll("&cGUI: " + g.getName() + " has invalid slot: " + g.getSlot() + "!"));
continue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package mineverse.Aust1n46.chat.gui;

import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import mineverse.Aust1n46.chat.api.MineverseChatPlayer;
import mineverse.Aust1n46.chat.channel.ChatChannel;

@Getter
@Setter
@AllArgsConstructor
public class ModerationGuiInventory implements InventoryHolder {
private MineverseChatPlayer targetMcp;
private ChatChannel channel;
private int hash;

@Override
public Inventory getInventory() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.server.ServerCommandEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;

import me.clip.placeholderapi.PlaceholderAPI;
import mineverse.Aust1n46.chat.MineverseChat;
import mineverse.Aust1n46.chat.alias.Alias;
import mineverse.Aust1n46.chat.api.MineverseChatAPI;
import mineverse.Aust1n46.chat.api.MineverseChatPlayer;
import mineverse.Aust1n46.chat.channel.ChatChannel;
import mineverse.Aust1n46.chat.database.Database;
import mineverse.Aust1n46.chat.gui.GuiSlot;
import mineverse.Aust1n46.chat.gui.ModerationGuiInventory;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import mineverse.Aust1n46.chat.utilities.Format;
import mineverse.Aust1n46.chat.versions.VersionHandler;
Expand Down Expand Up @@ -137,19 +138,22 @@ public void onServerCommand(ServerCommandEvent event) {

@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOW)
public void InventoryClick(InventoryClickEvent e) {
ItemStack item = e.getCurrentItem();
if (item == null || !e.getView().getTitle().contains("VentureChat")) {
public void InventoryClick(final InventoryClickEvent event) {
final Inventory inventory = event.getInventory();
final InventoryHolder inventoryHolder = inventory.getHolder();
if (!(inventoryHolder instanceof ModerationGuiInventory)) {
return;
}
event.setCancelled(true);
final ModerationGuiInventory moderationGuiInventory = (ModerationGuiInventory) inventoryHolder;
final MineverseChatPlayer mcp = MineverseChatAPI.getOnlineMineverseChatPlayer((Player) event.getWhoClicked());
final MineverseChatPlayer target = moderationGuiInventory.getTargetMcp();
final ChatChannel channel = moderationGuiInventory.getChannel();
final int hash = moderationGuiInventory.getHash();
final ItemStack item = event.getCurrentItem();
if (item == null) {
return;
}
e.setCancelled(true);
MineverseChatPlayer mcp = MineverseChatAPI.getOnlineMineverseChatPlayer((Player) e.getWhoClicked());
String playerName = e.getView().getTitle().replace(" GUI", "").replace("VentureChat: ", "");
MineverseChatPlayer target = MineverseChatAPI.getMineverseChatPlayer(playerName);
ItemStack skull = e.getInventory().getItem(0);
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
ChatChannel channel = ChatChannel.getChannel(ChatColor.stripColor(skullMeta.getLore().get(0)).replace("Channel: ", ""));
int hash = Integer.parseInt(ChatColor.stripColor(skullMeta.getLore().get(1).replace("Hash: ", "")));
if (VersionHandler.is1_7()) {
if (item.getType() == Material.BEDROCK) {
mcp.getPlayer().closeInventory();
Expand All @@ -159,14 +163,11 @@ public void InventoryClick(InventoryClickEvent e) {
mcp.getPlayer().closeInventory();
}
}
for (GuiSlot g : GuiSlot.getGuiSlots()) {
if (g.getIcon() == item.getType() && g.getDurability() == item.getDurability() && g.getSlot() == e.getSlot()) {
for (final GuiSlot g : GuiSlot.getGuiSlots()) {
if (g.getIcon() == item.getType() && g.getDurability() == item.getDurability() && g.getSlot() == event.getSlot()) {
String command = g.getCommand().replace("{channel}", channel.getName()).replace("{hash}", hash + "");
if (target != null) {
command = command.replace("{player_name}", target.getName());
if (target.isOnline()) {
command = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(target.getPlayer(), command));
}
} else {
command = command.replace("{player_name}", "Discord_Message");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ else if(VersionHandler.is1_8() || VersionHandler.is1_9() || VersionHandler.is1_1
if(message == null) {
return;
}
int hash = message.hashCode();
mcp.addMessage(new ChatMessage(chat, message, coloredMessage, hash));
mcp.addMessage(new ChatMessage(chat, message, coloredMessage));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package mineverse.Aust1n46.chat.listeners;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.WrappedChatComponent;

import mineverse.Aust1n46.chat.ChatMessage;
import mineverse.Aust1n46.chat.MineverseChat;
import mineverse.Aust1n46.chat.api.MineverseChatAPI;
import mineverse.Aust1n46.chat.api.MineverseChatPlayer;
import mineverse.Aust1n46.chat.utilities.Format;

public class PacketListenerSystemChat extends PacketAdapter {
public PacketListenerSystemChat() {
super(MineverseChat.getInstance(), ListenerPriority.MONITOR, PacketType.Play.Server.SYSTEM_CHAT);
}

@Override
public void onPacketSending(final PacketEvent event) {
if (event.isCancelled()) {
return;
}
final MineverseChatPlayer mcp = MineverseChatAPI.getOnlineMineverseChatPlayer(event.getPlayer());
if (mcp == null) {
return;
}

final WrappedChatComponent chat = event.getPacket().getChatComponents().readSafely(0);
if (chat == null) {
return;
}
final String message = Format.toPlainText(chat.getHandle(), chat.getHandleType());
final String coloredMessage = Format.toColoredText(chat.getHandle(), chat.getHandleType());
if (message == null) {
return;
}
mcp.addMessage(new ChatMessage(chat, message, coloredMessage));
}
}
Loading