Fix issues with 1.17 Paper

This commit is contained in:
Ghoti 2021-06-22 09:17:22 -05:00
parent b33d0685c1
commit 1abdd0ac7f
12 changed files with 225 additions and 51 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.fpghoti</groupId>
<artifactId>FPChat</artifactId>
<version>1.1.4</version>
<version>1.1.6</version>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.fpghoti</groupId>
<artifactId>FPChat</artifactId>
<version>1.1.4</version>
<version>1.1.6</version>
<repositories>
<repository>
<id>spigot-repo</id>
@ -77,7 +77,7 @@
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.4.5</version>
<version>4.0.3</version>
<scope>compile</scope>
</dependency>
</dependencies>

View File

@ -1,12 +1,18 @@
package com.fpghoti.fpchatx.chat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import com.fpghoti.fpchatx.FPChat;
import com.fpghoti.fpchatx.event.ShoutChannelChatEvent;
import com.fpghoti.fpchatx.player.FPlayer;
public class ShoutChannel extends ChatChannel{
@ -26,8 +32,8 @@ public class ShoutChannel extends ChatChannel{
*
* Many functions here will do nothing. Shout extends ChatChannel
* for the sake of treating shouts as a form of chat message.
*/
*/
public ShoutChannel(FPChat plugin) {
super(plugin);
this.name = "Shout";
@ -53,7 +59,7 @@ public class ShoutChannel extends ChatChannel{
// No real reason to use this. It will hush the player if called.
// Leaving the shout channel is impossible. Standard channel should
// be used if the ability to leave is required.
p.hush();
}
@ -121,7 +127,7 @@ public class ShoutChannel extends ChatChannel{
public int getRadius() {
return 0;
}
@Override
public ArrayList<FPlayer> getPlayers(){
return FPlayer.getPlayers();
@ -132,7 +138,7 @@ public class ShoutChannel extends ChatChannel{
// No real reason to use this. It will hush the player if called.
// Leaving the shout channel is impossible. Standard channel should
// be used if the ability to leave is required.
p.hush();
}
@ -141,18 +147,28 @@ public class ShoutChannel extends ChatChannel{
// No real reason to use this. It will hush the player if called.
// Leaving the shout channel is impossible. Standard channel should
// be used if the ability to leave is required.
p.unhush();
}
@Override
public void sendMessage(String msg, FPlayer from) {
plugin.log(Level.INFO, "Shout: " + msg);
for(FPlayer p : FPlayer.getPlayers()) {
if(p.isShoutVisible() && !p.isIgnoring(from)) {
p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&4&lS&r&8]&r") + msg);
CompletableFuture.runAsync(() -> {
plugin.log(Level.INFO, "Shout: " + msg);
Set<Player> recipients = new HashSet<Player>();
for(FPlayer p : FPlayer.getPlayers()) {
if(p.isShoutVisible() && !p.isIgnoring(from)) {
recipients.add(p.getPlayer());
}
}
}
ShoutChannelChatEvent event = new ShoutChannelChatEvent(true, from.getPlayer(), msg, recipients, this);
Bukkit.getPluginManager().callEvent(event);
if(!event.isCancelled()) {
for(Player recipient : recipients) {
recipient.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&4&lS&r&8]&r") + msg);
}
}
});
}
}

View File

@ -2,15 +2,20 @@ package com.fpghoti.fpchatx.chat;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.fpghoti.fpchatx.FPChat;
import com.fpghoti.fpchatx.config.ChannelFile;
import com.fpghoti.fpchatx.event.StandardChannelChatEvent;
import com.fpghoti.fpchatx.player.FPlayer;
import com.fpghoti.fpchatx.util.Util;
@ -322,22 +327,32 @@ public class StandardChannel extends ChatChannel{
@Override
public void sendMessage(String msg, FPlayer from) {
Player pf = Util.getEP(from.getName());
plugin.log(Level.INFO, name + ": " + msg);
for(FPlayer p : FPlayer.getPlayers()) {
if(p.getChannels().contains(name) && !p.isIgnoring(from)) {
if(hasRadius) {
Player pp = Util.getEP(p.getName());
if(pp.getWorld() == pf.getWorld()) {
if(pp.getLocation().distance(pf.getLocation()) < chatRadius){
p.sendMessage(msg);
CompletableFuture.runAsync(() -> {
Player pf = Util.getEP(from.getName());
plugin.log(Level.INFO, name + ": " + msg);
Set<Player> recipients = new HashSet<Player>();
for(FPlayer p : FPlayer.getPlayers()) {
if(p.getChannels().contains(name) && !p.isIgnoring(from)) {
if(hasRadius) {
Player pp = Util.getEP(p.getName());
if(pp.getWorld() == pf.getWorld()) {
if(pp.getLocation().distance(pf.getLocation()) < chatRadius){
recipients.add(p.getPlayer());
}
}
}else {
recipients.add(p.getPlayer());
}
}else {
p.sendMessage(msg);
}
}
}
StandardChannelChatEvent event = new StandardChannelChatEvent(true, from.getPlayer(), msg, recipients, this);
Bukkit.getPluginManager().callEvent(event);
if(!event.isCancelled()) {
for(Player recipient : recipients) {
recipient.sendMessage(msg);
}
}
});
}
public void update(ChannelFile file) {

View File

@ -1,19 +1,24 @@
package com.fpghoti.fpchatx.chat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import com.fpghoti.fpchatx.FPChat;
import com.fpghoti.fpchatx.event.TempChannelChatEvent;
import com.fpghoti.fpchatx.player.FPlayer;
public class TempChannel extends ChatChannel{
private UUID owner;
public TempChannel(FPChat plugin, FPlayer owner, String name) {
super(plugin);
this.name = name;
@ -22,12 +27,12 @@ public class TempChannel extends ChatChannel{
this.distinguishedChatFormat = plugin.getMainConfig().getTempChannelFormat();
this.banned = new ArrayList<UUID>();
}
public FPlayer getOwner() {
OfflinePlayer p = Bukkit.getOfflinePlayer(owner);
return FPlayer.getPlayer(p, !p.isOnline());
}
public boolean isOwner(FPlayer p) {
return p.getUniqueId() == this.owner;
}
@ -35,7 +40,7 @@ public class TempChannel extends ChatChannel{
public void setOwner(FPlayer p) {
this.owner = p.getUniqueId();
}
@Override
public boolean isTemp() {
return true;
@ -96,7 +101,7 @@ public class TempChannel extends ChatChannel{
public void enableWhitelist() {
this.isWhitelisted = true;
}
@Override
public void disableWhitelist() {
this.isWhitelisted = false;
@ -111,7 +116,7 @@ public class TempChannel extends ChatChannel{
public void whitelistRemove(UUID uuid) {
this.whitelist.remove(uuid);
}
@Override
public void addBanned(FPlayer p) {
this.banned.add(p.getUniqueId());
@ -132,7 +137,7 @@ public class TempChannel extends ChatChannel{
public void setDistinguishedChatFormat(String chatFormat) {
this.distinguishedChatFormat = chatFormat;
}
@Override
public ArrayList<FPlayer> getPlayers(){
ArrayList<FPlayer> players = new ArrayList<FPlayer>();
@ -143,15 +148,25 @@ public class TempChannel extends ChatChannel{
}
return players;
}
@Override
public void sendMessage(String msg, FPlayer from) {
plugin.log(Level.INFO, "[TC] " + name + ": " + msg);
for(FPlayer p : FPlayer.getPlayers()) {
if(p.getTempChannels().contains(name) && !p.isIgnoring(from)) {
p.sendMessage(msg);
CompletableFuture.runAsync(() -> {
plugin.log(Level.INFO, "[TC] " + name + ": " + msg);
Set<Player> recipients = new HashSet<Player>();
for(FPlayer p : FPlayer.getPlayers()) {
if(p.getTempChannels().contains(name) && !p.isIgnoring(from)) {
recipients.add(p.getPlayer());
}
}
}
TempChannelChatEvent event = new TempChannelChatEvent(true, from.getPlayer(), msg, recipients, this);
Bukkit.getPluginManager().callEvent(event);
if(!event.isCancelled()) {
for(Player recipient : recipients) {
recipient.sendMessage(msg);
}
}
});
}
}

View File

@ -0,0 +1,23 @@
package com.fpghoti.fpchatx.event;
import java.util.Set;
import org.bukkit.entity.Player;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import com.fpghoti.fpchatx.chat.ChatChannel;
public abstract class FPChatEvent extends AsyncPlayerChatEvent {
private ChatChannel channel;
public FPChatEvent(boolean async, Player who, String message, Set<Player> players, ChatChannel channel) {
super(async, who, message, players);
this.channel = channel;
}
public ChatChannel getChannel() {
return channel;
};
}

View File

@ -0,0 +1,22 @@
package com.fpghoti.fpchatx.event;
import java.util.Set;
import org.bukkit.entity.Player;
import com.fpghoti.fpchatx.chat.ShoutChannel;
public class ShoutChannelChatEvent extends FPChatEvent {
private ShoutChannel channel;
public ShoutChannelChatEvent(boolean async, Player who, String message, Set<Player> players, ShoutChannel channel) {
super(async, who, message, players, channel);
this.channel = channel;
}
public ShoutChannel getChannel() {
return channel;
}
}

View File

@ -0,0 +1,22 @@
package com.fpghoti.fpchatx.event;
import java.util.Set;
import org.bukkit.entity.Player;
import com.fpghoti.fpchatx.chat.StandardChannel;
public class StandardChannelChatEvent extends FPChatEvent {
private StandardChannel channel;
public StandardChannelChatEvent(boolean async, Player who, String message, Set<Player> players, StandardChannel channel) {
super(async, who, message, players, channel);
this.channel = channel;
}
public StandardChannel getChannel() {
return this.channel;
}
}

View File

@ -0,0 +1,22 @@
package com.fpghoti.fpchatx.event;
import java.util.Set;
import org.bukkit.entity.Player;
import com.fpghoti.fpchatx.chat.TempChannel;
public class TempChannelChatEvent extends FPChatEvent {
private TempChannel channel;
public TempChannelChatEvent(boolean async, Player who, String message, Set<Player> players, TempChannel channel) {
super(async, who, message, players, channel);
this.channel = channel;
}
public TempChannel getChannel() {
return channel;
}
}

View File

@ -13,12 +13,33 @@ import org.bukkit.event.player.PlayerQuitEvent;
import com.fpghoti.fpchatx.FPChat;
import com.fpghoti.fpchatx.chat.ChatChannel;
import com.fpghoti.fpchatx.event.FPChatEvent;
import com.fpghoti.fpchatx.player.FPlayer;
public class PlayerListener implements Listener {
private boolean enabled = true;
// @EventHandler (priority = EventPriority.HIGH)
// public void onPlayerChat(AsyncPlayerChatEvent event) {
// if(enabled) {
// if (event.isCancelled()) {
// return;
// }
// Player sender = event.getPlayer();
// FPlayer p = FPlayer.getPlayer(sender);
// if(p.toTalk() && p.getTalkChannel() != null) {
// p.setTalk(false);
// ChatChannel c = p.getTalkChannel();
// p.setTalkChannel(null);
// p.chat(c, event.getMessage());
// }else {
// p.chat(event.getMessage());
// }
// event.setCancelled(true);
// }
// }
@EventHandler (priority = EventPriority.HIGH)
public void onPlayerChat(AsyncPlayerChatEvent event) {
if(enabled) {
@ -27,15 +48,17 @@ public class PlayerListener implements Listener {
}
Player sender = event.getPlayer();
FPlayer p = FPlayer.getPlayer(sender);
if(p.toTalk() && p.getTalkChannel() != null) {
p.setTalk(false);
ChatChannel c = p.getTalkChannel();
p.setTalkChannel(null);
p.chat(c, event.getMessage());
}else {
p.chat(event.getMessage());
if(!(event instanceof FPChatEvent)) {
if(p.toTalk() && p.getTalkChannel() != null) {
p.setTalk(false);
ChatChannel c = p.getTalkChannel();
p.setTalkChannel(null);
p.chat(c, event.getMessage());
}else {
p.chat(event.getMessage());
}
event.setCancelled(true);
}
event.setCancelled(true);
}
}

View File

@ -29,7 +29,7 @@ public class MySQLConnection{
port = config.getPort();
hikari = new HikariDataSource();
hikari.setMaximumPoolSize(10);
hikari.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
hikari.setDataSourceClassName("com.mysql.cj.jdbc.MysqlDataSource");
hikari.addDataSourceProperty("serverName", host);
hikari.addDataSourceProperty("user", user);
hikari.addDataSourceProperty("password", password);
@ -55,7 +55,9 @@ public class MySQLConnection{
e.printStackTrace();
}finally {
try {
connection.close();
if(connection != null) {
connection.close();
}
} catch (SQLException e) {
e.printStackTrace();
}

View File

@ -441,6 +441,21 @@ public class FPlayer {
channel.sendMessage(formatChat(channel,msg), this);
}
// public void chat(String msg) {
// if(toShout) {
// toShout = false;
// ChatChannel.getShout().sendMessage(formatChat(ChatChannel.getShout(),msg), this);
// if(FPChat.getPlugin().getMainConfig().shoutCooldownEnabled()) {
// shoutCooldown = FPChat.getPlugin().getMainConfig().getShoutSeconds();
// }
// }else if(tempspeak) {
// getPrimaryTempChannel().sendMessage(formatChat(getPrimaryTempChannel(),msg), this);
// }else {
// getPrimaryChannel().sendMessage(formatChat(msg), this);
// }
// }
public void chat(String msg) {
if(toShout) {
toShout = false;
@ -454,7 +469,6 @@ public class FPlayer {
getPrimaryChannel().sendMessage(formatChat(msg), this);
}
}
public boolean shout(String message) {
if(!hushed && FPChat.getPlugin().getMainConfig().shoutCooldownEnabled() && shoutCooldown > 0) {
int i = shoutCooldown;