Use VCL14 for 1.15, player sender mock
Using VanillaCommandListener14 for 1.15 as well Using a mock for the DiscordPlayerSender too, to reduce the amount of code Made the mocks stub-only, which should lower memory usage
This commit is contained in:
parent
454265cd6f
commit
037ec3b9dd
9 changed files with 41 additions and 1246 deletions
|
@ -4,6 +4,7 @@ end_of_line = lf
|
||||||
insert_final_newline = false
|
insert_final_newline = false
|
||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 4
|
indent_size = 4
|
||||||
|
ij_any_field_annotation_wrap = off
|
||||||
|
|
||||||
[*.json]
|
[*.json]
|
||||||
indent_style = space
|
indent_style = space
|
||||||
|
@ -12,6 +13,8 @@ indent_size = 2
|
||||||
[*.java]
|
[*.java]
|
||||||
indent_style = tab
|
indent_style = tab
|
||||||
tab_width = 4
|
tab_width = 4
|
||||||
|
ij_java_do_not_wrap_after_single_annotation = true
|
||||||
|
ij_java_field_annotation_wrap = off
|
||||||
|
|
||||||
[{*.yml, *.yaml}]
|
[{*.yml, *.yaml}]
|
||||||
indent_style = space
|
indent_style = space
|
||||||
|
|
6
pom.xml
6
pom.xml
|
@ -176,6 +176,12 @@
|
||||||
<version>1.14.4-R0.1-SNAPSHOT</version>
|
<version>1.14.4-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc..</groupId>
|
||||||
|
<artifactId>spigot</artifactId>
|
||||||
|
<version>1.15.2-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
<!-- https://mvnrepository.com/artifact/com.discord4j/Discord4J -->
|
<!-- https://mvnrepository.com/artifact/com.discord4j/Discord4J -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.discord4j</groupId>
|
<groupId>com.discord4j</groupId>
|
||||||
|
|
|
@ -253,6 +253,7 @@ public abstract class DiscordConnectedPlayer extends DiscordSenderBase implement
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return RETURNS_DEFAULTS.answer(invocation);
|
return RETURNS_DEFAULTS.answer(invocation);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.stubOnly();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -51,17 +51,18 @@ public abstract class DiscordSenderBase implements CommandSender {
|
||||||
public void sendMessage(String message) {
|
public void sendMessage(String message) {
|
||||||
try {
|
try {
|
||||||
final boolean broadcast = new Exception().getStackTrace()[2].getMethodName().contains("broadcast");
|
final boolean broadcast = new Exception().getStackTrace()[2].getMethodName().contains("broadcast");
|
||||||
//if (broadcast && DiscordPlugin.hooked) - TODO: What should happen if unhooked
|
if (broadcast) //We're catching broadcasts using the Bukkit event
|
||||||
if (broadcast)
|
|
||||||
return;
|
return;
|
||||||
final String sendmsg = DPUtils.sanitizeString(message);
|
final String sendmsg = DPUtils.sanitizeString(message);
|
||||||
msgtosend += "\n" + sendmsg;
|
synchronized (this) {
|
||||||
if (sendtask == null)
|
msgtosend += "\n" + sendmsg;
|
||||||
sendtask = Bukkit.getScheduler().runTaskLaterAsynchronously(DiscordPlugin.plugin, () -> {
|
if (sendtask == null)
|
||||||
channel.createMessage((!broadcast && user != null ? user.getMention() + "\n" : "") + msgtosend.trim()).subscribe();
|
sendtask = Bukkit.getScheduler().runTaskLaterAsynchronously(DiscordPlugin.plugin, () -> {
|
||||||
sendtask = null;
|
channel.createMessage((user != null ? user.getMention() + "\n":"") + msgtosend.trim()).subscribe();
|
||||||
msgtosend = "";
|
sendtask = null;
|
||||||
}, 4); // Waits a 0.2 second to gather all/most of the different messages
|
msgtosend = "";
|
||||||
|
}, 4); // Waits a 0.2 second to gather all/most of the different messages
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
TBMCCoreAPI.SendException("An error occured while sending message to DiscordSender", e);
|
TBMCCoreAPI.SendException("An error occured while sending message to DiscordSender", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -349,7 +349,7 @@ public class MCChatListener implements Listener {
|
||||||
String mcpackage = Bukkit.getServer().getClass().getPackage().getName();
|
String mcpackage = Bukkit.getServer().getClass().getPackage().getName();
|
||||||
if (mcpackage.contains("1_12"))
|
if (mcpackage.contains("1_12"))
|
||||||
VanillaCommandListener.runBukkitOrVanillaCommand(dsender, cmd);
|
VanillaCommandListener.runBukkitOrVanillaCommand(dsender, cmd);
|
||||||
else if (mcpackage.contains("1_14"))
|
else if (mcpackage.contains("1_14") || mcpackage.contains("1_15"))
|
||||||
VanillaCommandListener14.runBukkitOrVanillaCommand(dsender, cmd);
|
VanillaCommandListener14.runBukkitOrVanillaCommand(dsender, cmd);
|
||||||
else
|
else
|
||||||
Bukkit.dispatchCommand(dsender, cmd);
|
Bukkit.dispatchCommand(dsender, cmd);
|
||||||
|
|
|
@ -55,9 +55,9 @@ class MCListener implements Listener {
|
||||||
if (dp != null) {
|
if (dp != null) {
|
||||||
DiscordPlugin.dc.getUserById(Snowflake.of(dp.getDiscordID())).flatMap(user -> user.getPrivateChannel().flatMap(chan -> module.chatChannelMono().flatMap(cc -> {
|
DiscordPlugin.dc.getUserById(Snowflake.of(dp.getDiscordID())).flatMap(user -> user.getPrivateChannel().flatMap(chan -> module.chatChannelMono().flatMap(cc -> {
|
||||||
MCChatUtils.addSender(MCChatUtils.OnlineSenders, dp.getDiscordID(),
|
MCChatUtils.addSender(MCChatUtils.OnlineSenders, dp.getDiscordID(),
|
||||||
new DiscordPlayerSender(user, chan, p));
|
DiscordPlayerSender.create(user, chan, p));
|
||||||
MCChatUtils.addSender(MCChatUtils.OnlineSenders, dp.getDiscordID(),
|
MCChatUtils.addSender(MCChatUtils.OnlineSenders, dp.getDiscordID(),
|
||||||
new DiscordPlayerSender(user, cc, p)); //Stored per-channel
|
DiscordPlayerSender.create(user, cc, p)); //Stored per-channel
|
||||||
return Mono.empty();
|
return Mono.empty();
|
||||||
}))).subscribe();
|
}))).subscribe();
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class VCMDWrapper {
|
||||||
String mcpackage = Bukkit.getServer().getClass().getPackage().getName();
|
String mcpackage = Bukkit.getServer().getClass().getPackage().getName();
|
||||||
if (mcpackage.contains("1_12"))
|
if (mcpackage.contains("1_12"))
|
||||||
return bukkitplayer == null ? new VanillaCommandListener<>(player) : new VanillaCommandListener<>(player, bukkitplayer);
|
return bukkitplayer == null ? new VanillaCommandListener<>(player) : new VanillaCommandListener<>(player, bukkitplayer);
|
||||||
else if (mcpackage.contains("1_14"))
|
else if (mcpackage.contains("1_14") || mcpackage.contains("1_15"))
|
||||||
return bukkitplayer == null ? new VanillaCommandListener14<>(player) : new VanillaCommandListener14<>(player, bukkitplayer);
|
return bukkitplayer == null ? new VanillaCommandListener14<>(player) : new VanillaCommandListener14<>(player, bukkitplayer);
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -20,9 +20,8 @@ public class VanillaCommandListener<T extends DiscordSenderBase & IMCPlayer<T>>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor will only send raw vanilla messages to the sender in plain text.
|
* This constructor will only send raw vanilla messages to the sender in plain text.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player The Discord sender player (the wrapper)
|
||||||
* The Discord sender player (the wrapper)
|
|
||||||
*/
|
*/
|
||||||
public VanillaCommandListener(T player) {
|
public VanillaCommandListener(T player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
@ -31,11 +30,9 @@ public class VanillaCommandListener<T extends DiscordSenderBase & IMCPlayer<T>>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor will send both raw vanilla messages to the sender in plain text and forward the raw message to the provided player.
|
* This constructor will send both raw vanilla messages to the sender in plain text and forward the raw message to the provided player.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player The Discord sender player (the wrapper)
|
||||||
* The Discord sender player (the wrapper)
|
* @param bukkitplayer The Bukkit player to send the raw message to
|
||||||
* @param bukkitplayer
|
|
||||||
* The Bukkit player to send the raw message to
|
|
||||||
*/
|
*/
|
||||||
public VanillaCommandListener(T player, Player bukkitplayer) {
|
public VanillaCommandListener(T player, Player bukkitplayer) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
@ -79,7 +76,7 @@ public class VanillaCommandListener<T extends DiscordSenderBase & IMCPlayer<T>>
|
||||||
|
|
||||||
if (!(dsender instanceof IMCPlayer))
|
if (!(dsender instanceof IMCPlayer))
|
||||||
throw new ClassCastException(
|
throw new ClassCastException(
|
||||||
"dsender needs to implement IMCPlayer to use vanilla commands as it implements Player.");
|
"dsender needs to implement IMCPlayer to use vanilla commands as it implements Player.");
|
||||||
|
|
||||||
IMCPlayer<?> sender = (IMCPlayer<?>) dsender; // Don't use val on recursive interfaces :P
|
IMCPlayer<?> sender = (IMCPlayer<?>) dsender; // Don't use val on recursive interfaces :P
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue