generated from beanbeanjuice/SpigotPluginTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from beanbeanjuice/164-private-messaging
Add Private Messaging
- Loading branch information
Showing
15 changed files
with
360 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/com/beanbeanjuice/simpleproxychat/commands/bungee/BungeeReplyCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.beanbeanjuice.simpleproxychat.commands.bungee; | ||
|
||
import com.beanbeanjuice.simpleproxychat.SimpleProxyChatBungee; | ||
import com.beanbeanjuice.simpleproxychat.utility.Helper; | ||
import com.beanbeanjuice.simpleproxychat.utility.Tuple; | ||
import com.beanbeanjuice.simpleproxychat.utility.config.Config; | ||
import com.beanbeanjuice.simpleproxychat.utility.config.ConfigDataKey; | ||
import com.beanbeanjuice.simpleproxychat.utility.config.Permission; | ||
import net.md_5.bungee.api.CommandSender; | ||
import net.md_5.bungee.api.plugin.Command; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class BungeeReplyCommand extends Command { | ||
|
||
private final SimpleProxyChatBungee plugin; | ||
private final Config config; | ||
|
||
public BungeeReplyCommand(SimpleProxyChatBungee plugin, Config config, String... aliases) { | ||
super("Spc-reply", Permission.USE_WHISPER.getPermissionNode(), aliases); | ||
this.plugin = plugin;; | ||
this.config = config; | ||
} | ||
|
||
@Override | ||
public void execute(CommandSender sender, String[] args) { | ||
plugin.getWhisperHandler().getLink(sender.getName()).map((playerName) -> plugin.getProxy().getPlayer(playerName)).ifPresentOrElse( | ||
(receiver) -> { | ||
String message = Helper.translateLegacyCodes(String.join(" ", args)); | ||
|
||
String senderString = config.getAsString(ConfigDataKey.MINECRAFT_WHISPER_SEND); | ||
String receiverString = config.getAsString(ConfigDataKey.MINECRAFT_WHISPER_RECEIVE); | ||
|
||
List<Tuple<String, String>> replacements = new ArrayList<>(); | ||
replacements.add(Tuple.of("sender", sender.getName())); | ||
replacements.add(Tuple.of("receiver", receiver.getName())); | ||
replacements.add(Tuple.of("message", message)); | ||
replacements.add(Tuple.of("plugin-prefix", config.getAsString(ConfigDataKey.PLUGIN_PREFIX))); | ||
|
||
senderString = Helper.replaceKeys(senderString, replacements); | ||
receiverString = Helper.replaceKeys(receiverString, replacements); | ||
|
||
sender.sendMessage(Helper.convertToBungee(senderString)); | ||
receiver.sendMessage(Helper.convertToBungee(receiverString)); | ||
|
||
plugin.getWhisperHandler().set(sender.getName(), receiver.getName()); | ||
}, | ||
() -> sender.sendMessage(Helper.convertToBungee(config.getAsString(ConfigDataKey.MINECRAFT_WHISPER_ERROR))) | ||
); | ||
|
||
} | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/com/beanbeanjuice/simpleproxychat/commands/bungee/BungeeWhisperCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.beanbeanjuice.simpleproxychat.commands.bungee; | ||
|
||
import com.beanbeanjuice.simpleproxychat.SimpleProxyChatBungee; | ||
import com.beanbeanjuice.simpleproxychat.utility.Helper; | ||
import com.beanbeanjuice.simpleproxychat.utility.Tuple; | ||
import com.beanbeanjuice.simpleproxychat.utility.config.Config; | ||
import com.beanbeanjuice.simpleproxychat.utility.config.ConfigDataKey; | ||
import com.beanbeanjuice.simpleproxychat.utility.config.Permission; | ||
import net.md_5.bungee.api.CommandSender; | ||
import net.md_5.bungee.api.connection.ProxiedPlayer; | ||
import net.md_5.bungee.api.plugin.Command; | ||
import net.md_5.bungee.api.plugin.TabExecutor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class BungeeWhisperCommand extends Command implements TabExecutor { | ||
|
||
private final SimpleProxyChatBungee plugin; | ||
private final Config config; | ||
|
||
public BungeeWhisperCommand(SimpleProxyChatBungee plugin, Config config, String... aliases) { | ||
super("Spc-whisper", Permission.USE_WHISPER.getPermissionNode(), aliases); | ||
this.plugin = plugin; | ||
this.config = config; | ||
} | ||
|
||
@Override | ||
public void execute(CommandSender sender, String[] args) { | ||
if (args.length < 2) { | ||
sender.sendMessage(Helper.convertToBungee(config.getAsString(ConfigDataKey.MINECRAFT_WHISPER_ERROR))); | ||
return; | ||
} | ||
|
||
ProxiedPlayer receiver = plugin.getProxy().getPlayer(args[0]); | ||
if (receiver == null) { | ||
sender.sendMessage(Helper.convertToBungee(config.getAsString(ConfigDataKey.MINECRAFT_WHISPER_ERROR))); | ||
return; | ||
} | ||
|
||
String message = Helper.translateLegacyCodes(Arrays.stream(args).skip(1).collect(Collectors.joining(" "))); | ||
|
||
String senderString = config.getAsString(ConfigDataKey.MINECRAFT_WHISPER_SEND); | ||
String receiverString = config.getAsString(ConfigDataKey.MINECRAFT_WHISPER_RECEIVE); | ||
|
||
List<Tuple<String, String>> replacements = new ArrayList<>(); | ||
replacements.add(Tuple.of("sender", sender.getName())); | ||
replacements.add(Tuple.of("receiver", receiver.getName())); | ||
replacements.add(Tuple.of("message", message)); | ||
replacements.add(Tuple.of("plugin-prefix", config.getAsString(ConfigDataKey.PLUGIN_PREFIX))); | ||
|
||
senderString = Helper.replaceKeys(senderString, replacements); | ||
receiverString = Helper.replaceKeys(receiverString, replacements); | ||
|
||
sender.sendMessage(Helper.convertToBungee(senderString)); | ||
receiver.sendMessage(Helper.convertToBungee(receiverString)); | ||
|
||
plugin.getWhisperHandler().set(sender.getName(), receiver.getName()); | ||
} | ||
|
||
@Override | ||
public Iterable<String> onTabComplete(CommandSender sender, String[] args) { | ||
if (args.length <= 1) | ||
return plugin.getProxy().getPlayers().stream().map(ProxiedPlayer::getName).filter((username) -> { | ||
if (args.length == 1) { | ||
return username.toLowerCase().startsWith(args[0].toLowerCase()); | ||
} | ||
return true; | ||
}).toList(); | ||
|
||
return List.of(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/java/com/beanbeanjuice/simpleproxychat/commands/velocity/VelocityReplyCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.beanbeanjuice.simpleproxychat.commands.velocity; | ||
|
||
import com.beanbeanjuice.simpleproxychat.SimpleProxyChatVelocity; | ||
import com.beanbeanjuice.simpleproxychat.utility.Helper; | ||
import com.beanbeanjuice.simpleproxychat.utility.Tuple; | ||
import com.beanbeanjuice.simpleproxychat.utility.config.Config; | ||
import com.beanbeanjuice.simpleproxychat.utility.config.ConfigDataKey; | ||
import com.beanbeanjuice.simpleproxychat.utility.config.Permission; | ||
import com.velocitypowered.api.command.SimpleCommand; | ||
import com.velocitypowered.api.proxy.Player; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class VelocityReplyCommand implements SimpleCommand { | ||
|
||
private final SimpleProxyChatVelocity plugin; | ||
private final Config config; | ||
|
||
public VelocityReplyCommand(SimpleProxyChatVelocity plugin, Config config) { | ||
this.plugin = plugin; | ||
this.config = config; | ||
} | ||
|
||
@Override | ||
public void execute(Invocation invocation) { | ||
plugin.getProxyServer().getPlayer(plugin.getWhisperHandler().getLink(((Player) invocation.source()).getUsername()).orElse("")).ifPresentOrElse( | ||
(receiver) -> { | ||
String message = Helper.translateLegacyCodes(String.join(" ", invocation.arguments())); | ||
|
||
String senderString = config.getAsString(ConfigDataKey.MINECRAFT_WHISPER_SEND); | ||
String receiverString = config.getAsString(ConfigDataKey.MINECRAFT_WHISPER_RECEIVE); | ||
|
||
List<Tuple<String, String>> replacements = new ArrayList<>(); | ||
replacements.add(Tuple.of("sender", ((Player) invocation.source()).getUsername())); | ||
replacements.add(Tuple.of("receiver", receiver.getUsername())); | ||
replacements.add(Tuple.of("message", message)); | ||
replacements.add(Tuple.of("plugin-prefix", config.getAsString(ConfigDataKey.PLUGIN_PREFIX))); | ||
|
||
senderString = Helper.replaceKeys(senderString, replacements); | ||
receiverString = Helper.replaceKeys(receiverString, replacements); | ||
|
||
invocation.source().sendMessage(Helper.stringToComponent(senderString)); | ||
receiver.sendMessage(Helper.stringToComponent(receiverString)); | ||
|
||
plugin.getWhisperHandler().set(((Player) invocation.source()).getUsername(), receiver.getUsername()); | ||
}, | ||
() -> invocation.source().sendMessage(Helper.stringToComponent(config.getAsString(ConfigDataKey.MINECRAFT_WHISPER_ERROR))) | ||
); | ||
} | ||
|
||
@Override | ||
public boolean hasPermission(Invocation invocation) { | ||
return invocation.source().hasPermission(Permission.USE_WHISPER.getPermissionNode()); | ||
} | ||
|
||
} |
Oops, something went wrong.