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> <modelVersion>4.0.0</modelVersion>
<groupId>com.fpghoti</groupId> <groupId>com.fpghoti</groupId>
<artifactId>FPChat</artifactId> <artifactId>FPChat</artifactId>
<version>1.1.4</version> <version>1.1.6</version>
<build> <build>
<sourceDirectory>src/main/java</sourceDirectory> <sourceDirectory>src/main/java</sourceDirectory>
<resources> <resources>

View File

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

View File

@ -1,12 +1,18 @@
package com.fpghoti.fpchatx.chat; package com.fpghoti.fpchatx.chat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level; import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import com.fpghoti.fpchatx.FPChat; import com.fpghoti.fpchatx.FPChat;
import com.fpghoti.fpchatx.event.ShoutChannelChatEvent;
import com.fpghoti.fpchatx.player.FPlayer; import com.fpghoti.fpchatx.player.FPlayer;
public class ShoutChannel extends ChatChannel{ public class ShoutChannel extends ChatChannel{
@ -26,8 +32,8 @@ public class ShoutChannel extends ChatChannel{
* *
* Many functions here will do nothing. Shout extends ChatChannel * Many functions here will do nothing. Shout extends ChatChannel
* for the sake of treating shouts as a form of chat message. * for the sake of treating shouts as a form of chat message.
*/ */
public ShoutChannel(FPChat plugin) { public ShoutChannel(FPChat plugin) {
super(plugin); super(plugin);
this.name = "Shout"; 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. // No real reason to use this. It will hush the player if called.
// Leaving the shout channel is impossible. Standard channel should // Leaving the shout channel is impossible. Standard channel should
// be used if the ability to leave is required. // be used if the ability to leave is required.
p.hush(); p.hush();
} }
@ -121,7 +127,7 @@ public class ShoutChannel extends ChatChannel{
public int getRadius() { public int getRadius() {
return 0; return 0;
} }
@Override @Override
public ArrayList<FPlayer> getPlayers(){ public ArrayList<FPlayer> getPlayers(){
return 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. // No real reason to use this. It will hush the player if called.
// Leaving the shout channel is impossible. Standard channel should // Leaving the shout channel is impossible. Standard channel should
// be used if the ability to leave is required. // be used if the ability to leave is required.
p.hush(); p.hush();
} }
@ -141,18 +147,28 @@ public class ShoutChannel extends ChatChannel{
// No real reason to use this. It will hush the player if called. // No real reason to use this. It will hush the player if called.
// Leaving the shout channel is impossible. Standard channel should // Leaving the shout channel is impossible. Standard channel should
// be used if the ability to leave is required. // be used if the ability to leave is required.
p.unhush(); p.unhush();
} }
@Override @Override
public void sendMessage(String msg, FPlayer from) { public void sendMessage(String msg, FPlayer from) {
plugin.log(Level.INFO, "Shout: " + msg); CompletableFuture.runAsync(() -> {
for(FPlayer p : FPlayer.getPlayers()) { plugin.log(Level.INFO, "Shout: " + msg);
if(p.isShoutVisible() && !p.isIgnoring(from)) { Set<Player> recipients = new HashSet<Player>();
p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&4&lS&r&8]&r") + msg); 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.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level; import java.util.logging.Level;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import com.fpghoti.fpchatx.FPChat; import com.fpghoti.fpchatx.FPChat;
import com.fpghoti.fpchatx.config.ChannelFile; import com.fpghoti.fpchatx.config.ChannelFile;
import com.fpghoti.fpchatx.event.StandardChannelChatEvent;
import com.fpghoti.fpchatx.player.FPlayer; import com.fpghoti.fpchatx.player.FPlayer;
import com.fpghoti.fpchatx.util.Util; import com.fpghoti.fpchatx.util.Util;
@ -322,22 +327,32 @@ public class StandardChannel extends ChatChannel{
@Override @Override
public void sendMessage(String msg, FPlayer from) { public void sendMessage(String msg, FPlayer from) {
Player pf = Util.getEP(from.getName()); CompletableFuture.runAsync(() -> {
plugin.log(Level.INFO, name + ": " + msg); Player pf = Util.getEP(from.getName());
for(FPlayer p : FPlayer.getPlayers()) { plugin.log(Level.INFO, name + ": " + msg);
if(p.getChannels().contains(name) && !p.isIgnoring(from)) { Set<Player> recipients = new HashSet<Player>();
if(hasRadius) { for(FPlayer p : FPlayer.getPlayers()) {
Player pp = Util.getEP(p.getName()); if(p.getChannels().contains(name) && !p.isIgnoring(from)) {
if(pp.getWorld() == pf.getWorld()) { if(hasRadius) {
if(pp.getLocation().distance(pf.getLocation()) < chatRadius){ Player pp = Util.getEP(p.getName());
p.sendMessage(msg); 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) { public void update(ChannelFile file) {

View File

@ -1,19 +1,24 @@
package com.fpghoti.fpchatx.chat; package com.fpghoti.fpchatx.chat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level; import java.util.logging.Level;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import com.fpghoti.fpchatx.FPChat; import com.fpghoti.fpchatx.FPChat;
import com.fpghoti.fpchatx.event.TempChannelChatEvent;
import com.fpghoti.fpchatx.player.FPlayer; import com.fpghoti.fpchatx.player.FPlayer;
public class TempChannel extends ChatChannel{ public class TempChannel extends ChatChannel{
private UUID owner; private UUID owner;
public TempChannel(FPChat plugin, FPlayer owner, String name) { public TempChannel(FPChat plugin, FPlayer owner, String name) {
super(plugin); super(plugin);
this.name = name; this.name = name;
@ -22,12 +27,12 @@ public class TempChannel extends ChatChannel{
this.distinguishedChatFormat = plugin.getMainConfig().getTempChannelFormat(); this.distinguishedChatFormat = plugin.getMainConfig().getTempChannelFormat();
this.banned = new ArrayList<UUID>(); this.banned = new ArrayList<UUID>();
} }
public FPlayer getOwner() { public FPlayer getOwner() {
OfflinePlayer p = Bukkit.getOfflinePlayer(owner); OfflinePlayer p = Bukkit.getOfflinePlayer(owner);
return FPlayer.getPlayer(p, !p.isOnline()); return FPlayer.getPlayer(p, !p.isOnline());
} }
public boolean isOwner(FPlayer p) { public boolean isOwner(FPlayer p) {
return p.getUniqueId() == this.owner; return p.getUniqueId() == this.owner;
} }
@ -35,7 +40,7 @@ public class TempChannel extends ChatChannel{
public void setOwner(FPlayer p) { public void setOwner(FPlayer p) {
this.owner = p.getUniqueId(); this.owner = p.getUniqueId();
} }
@Override @Override
public boolean isTemp() { public boolean isTemp() {
return true; return true;
@ -96,7 +101,7 @@ public class TempChannel extends ChatChannel{
public void enableWhitelist() { public void enableWhitelist() {
this.isWhitelisted = true; this.isWhitelisted = true;
} }
@Override @Override
public void disableWhitelist() { public void disableWhitelist() {
this.isWhitelisted = false; this.isWhitelisted = false;
@ -111,7 +116,7 @@ public class TempChannel extends ChatChannel{
public void whitelistRemove(UUID uuid) { public void whitelistRemove(UUID uuid) {
this.whitelist.remove(uuid); this.whitelist.remove(uuid);
} }
@Override @Override
public void addBanned(FPlayer p) { public void addBanned(FPlayer p) {
this.banned.add(p.getUniqueId()); this.banned.add(p.getUniqueId());
@ -132,7 +137,7 @@ public class TempChannel extends ChatChannel{
public void setDistinguishedChatFormat(String chatFormat) { public void setDistinguishedChatFormat(String chatFormat) {
this.distinguishedChatFormat = chatFormat; this.distinguishedChatFormat = chatFormat;
} }
@Override @Override
public ArrayList<FPlayer> getPlayers(){ public ArrayList<FPlayer> getPlayers(){
ArrayList<FPlayer> players = new ArrayList<FPlayer>(); ArrayList<FPlayer> players = new ArrayList<FPlayer>();
@ -143,15 +148,25 @@ public class TempChannel extends ChatChannel{
} }
return players; return players;
} }
@Override @Override
public void sendMessage(String msg, FPlayer from) { public void sendMessage(String msg, FPlayer from) {
plugin.log(Level.INFO, "[TC] " + name + ": " + msg); CompletableFuture.runAsync(() -> {
for(FPlayer p : FPlayer.getPlayers()) { plugin.log(Level.INFO, "[TC] " + name + ": " + msg);
if(p.getTempChannels().contains(name) && !p.isIgnoring(from)) { Set<Player> recipients = new HashSet<Player>();
p.sendMessage(msg); 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.FPChat;
import com.fpghoti.fpchatx.chat.ChatChannel; import com.fpghoti.fpchatx.chat.ChatChannel;
import com.fpghoti.fpchatx.event.FPChatEvent;
import com.fpghoti.fpchatx.player.FPlayer; import com.fpghoti.fpchatx.player.FPlayer;
public class PlayerListener implements Listener { public class PlayerListener implements Listener {
private boolean enabled = true; 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) @EventHandler (priority = EventPriority.HIGH)
public void onPlayerChat(AsyncPlayerChatEvent event) { public void onPlayerChat(AsyncPlayerChatEvent event) {
if(enabled) { if(enabled) {
@ -27,15 +48,17 @@ public class PlayerListener implements Listener {
} }
Player sender = event.getPlayer(); Player sender = event.getPlayer();
FPlayer p = FPlayer.getPlayer(sender); FPlayer p = FPlayer.getPlayer(sender);
if(p.toTalk() && p.getTalkChannel() != null) { if(!(event instanceof FPChatEvent)) {
p.setTalk(false); if(p.toTalk() && p.getTalkChannel() != null) {
ChatChannel c = p.getTalkChannel(); p.setTalk(false);
p.setTalkChannel(null); ChatChannel c = p.getTalkChannel();
p.chat(c, event.getMessage()); p.setTalkChannel(null);
}else { p.chat(c, event.getMessage());
p.chat(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(); port = config.getPort();
hikari = new HikariDataSource(); hikari = new HikariDataSource();
hikari.setMaximumPoolSize(10); hikari.setMaximumPoolSize(10);
hikari.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource"); hikari.setDataSourceClassName("com.mysql.cj.jdbc.MysqlDataSource");
hikari.addDataSourceProperty("serverName", host); hikari.addDataSourceProperty("serverName", host);
hikari.addDataSourceProperty("user", user); hikari.addDataSourceProperty("user", user);
hikari.addDataSourceProperty("password", password); hikari.addDataSourceProperty("password", password);
@ -55,7 +55,9 @@ public class MySQLConnection{
e.printStackTrace(); e.printStackTrace();
}finally { }finally {
try { try {
connection.close(); if(connection != null) {
connection.close();
}
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -441,6 +441,21 @@ public class FPlayer {
channel.sendMessage(formatChat(channel,msg), this); 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) { public void chat(String msg) {
if(toShout) { if(toShout) {
toShout = false; toShout = false;
@ -454,7 +469,6 @@ public class FPlayer {
getPrimaryChannel().sendMessage(formatChat(msg), this); getPrimaryChannel().sendMessage(formatChat(msg), this);
} }
} }
public boolean shout(String message) { public boolean shout(String message) {
if(!hushed && FPChat.getPlugin().getMainConfig().shoutCooldownEnabled() && shoutCooldown > 0) { if(!hushed && FPChat.getPlugin().getMainConfig().shoutCooldownEnabled() && shoutCooldown > 0) {
int i = shoutCooldown; int i = shoutCooldown;