Add ability to send shop owner notifications via BungeeCord
This commit is contained in:
parent
38f93c1d1d
commit
2075693e12
|
@ -40,6 +40,9 @@ import com.Acrobot.ChestShop.Signs.RestrictedSign;
|
|||
import com.Acrobot.ChestShop.UUIDs.NameManager;
|
||||
import com.Acrobot.ChestShop.Updater.Updater;
|
||||
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
|
@ -122,6 +125,8 @@ public class ChestShop extends JavaPlugin {
|
|||
|
||||
registerEvents();
|
||||
|
||||
registerPluginMessagingChannels();
|
||||
|
||||
if (Properties.LOG_TO_FILE) {
|
||||
File log = loadFile("ChestShop.log");
|
||||
|
||||
|
@ -379,6 +384,12 @@ public class ChestShop extends JavaPlugin {
|
|||
registerEvent(new TaxModule());
|
||||
}
|
||||
|
||||
private void registerPluginMessagingChannels() {
|
||||
if (Properties.BUNGEECORD_MESSAGES) {
|
||||
getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
||||
}
|
||||
}
|
||||
|
||||
public void registerEvent(Listener listener) {
|
||||
getServer().getPluginManager().registerEvents(listener, this);
|
||||
}
|
||||
|
@ -443,4 +454,15 @@ public class ChestShop extends JavaPlugin {
|
|||
public static void callEvent(Event event) {
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
}
|
||||
|
||||
public static void sendBungeeMessage(String playerName, String message) {
|
||||
if (Properties.BUNGEECORD_MESSAGES && !Bukkit.getOnlinePlayers().isEmpty()) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("Message");
|
||||
out.writeUTF(playerName);
|
||||
out.writeUTF(message);
|
||||
|
||||
Bukkit.getOnlinePlayers().iterator().next().sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -159,6 +159,10 @@ public class Properties {
|
|||
@ConfigurationComment("Can '?' be put in place of item name in order for the sign to be auto-filled?")
|
||||
public static boolean ALLOW_AUTO_ITEM_FILL = true;
|
||||
|
||||
@PrecededBySpace
|
||||
@ConfigurationComment("Enable this if you use BungeeCord and want players to receive shop notifications on other servers")
|
||||
public static boolean BUNGEECORD_MESSAGES = false;
|
||||
|
||||
@PrecededBySpace
|
||||
@ConfigurationComment("Do you want to show \"Out of stock\" messages?")
|
||||
public static boolean SHOW_MESSAGE_OUT_OF_STOCK = true;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.Acrobot.ChestShop.Listeners.PostTransaction;
|
||||
|
||||
import com.Acrobot.Breeze.Utils.MaterialUtil;
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
import com.Acrobot.ChestShop.Commands.Toggle;
|
||||
import com.Acrobot.ChestShop.Configuration.Messages;
|
||||
import com.Acrobot.ChestShop.Configuration.Properties;
|
||||
|
@ -30,14 +31,12 @@ public class TransactionMessageSender implements Listener {
|
|||
Player player = event.getClient();
|
||||
|
||||
if (Properties.SHOW_TRANSACTION_INFORMATION_CLIENT) {
|
||||
sendMessage(player, Messages.YOU_BOUGHT_FROM_SHOP, event, "owner", event.getOwnerAccount().getName());
|
||||
sendMessage(player, event.getClient().getName(), Messages.YOU_BOUGHT_FROM_SHOP, event, "owner", event.getOwnerAccount().getName());
|
||||
}
|
||||
|
||||
if (Properties.SHOW_TRANSACTION_INFORMATION_OWNER && !Toggle.isIgnoring(event.getOwnerAccount().getUuid())) {
|
||||
Player owner = Bukkit.getPlayer(event.getOwnerAccount().getUuid());
|
||||
if (owner != null) {
|
||||
sendMessage(owner, Messages.SOMEBODY_BOUGHT_FROM_YOUR_SHOP, event, "buyer", player.getName());
|
||||
}
|
||||
sendMessage(owner, event.getOwnerAccount().getName(), Messages.SOMEBODY_BOUGHT_FROM_YOUR_SHOP, event, "buyer", player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,18 +44,16 @@ public class TransactionMessageSender implements Listener {
|
|||
Player player = event.getClient();
|
||||
|
||||
if (Properties.SHOW_TRANSACTION_INFORMATION_CLIENT) {
|
||||
sendMessage(player, Messages.YOU_SOLD_TO_SHOP, event, "buyer", event.getOwnerAccount().getName());
|
||||
sendMessage(player, event.getClient().getName(), Messages.YOU_SOLD_TO_SHOP, event, "buyer", event.getOwnerAccount().getName());
|
||||
}
|
||||
|
||||
if (Properties.SHOW_TRANSACTION_INFORMATION_OWNER && !Toggle.isIgnoring(event.getOwnerAccount().getUuid())) {
|
||||
Player owner = Bukkit.getPlayer(event.getOwnerAccount().getUuid());
|
||||
if (owner != null) {
|
||||
sendMessage(owner, Messages.SOMEBODY_SOLD_TO_YOUR_SHOP, event, "seller", player.getName());
|
||||
}
|
||||
sendMessage(owner, event.getOwnerAccount().getName(), Messages.SOMEBODY_SOLD_TO_YOUR_SHOP, event, "seller", player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private static void sendMessage(Player player, String rawMessage, TransactionEvent event, String... replacements) {
|
||||
private static void sendMessage(Player player, String playerName, String rawMessage, TransactionEvent event, String... replacements) {
|
||||
Location loc = event.getSign().getLocation();
|
||||
String message = Messages.prefix(rawMessage)
|
||||
.replace("%price", Economy.formatBalance(event.getExactPrice()))
|
||||
|
@ -68,11 +65,15 @@ public class TransactionMessageSender implements Listener {
|
|||
for (int i = 0; i + 1 < replacements.length; i+=2) {
|
||||
message = message.replace("%" + replacements[i], replacements[i + 1]);
|
||||
}
|
||||
|
||||
if (Properties.SHOWITEM_MESSAGE && MaterialUtil.Show.sendMessage(player, message, event.getStock())) {
|
||||
return;
|
||||
|
||||
if (player != null) {
|
||||
if (Properties.SHOWITEM_MESSAGE && MaterialUtil.Show.sendMessage(player, message, event.getStock())) {
|
||||
return;
|
||||
}
|
||||
player.sendMessage(message.replace("%item", MaterialUtil.getItemList(event.getStock())));
|
||||
} else if (playerName != null) {
|
||||
ChestShop.sendBungeeMessage(playerName, message.replace("%item", MaterialUtil.getItemList(event.getStock())));
|
||||
}
|
||||
player.sendMessage(message.replace("%item", MaterialUtil.getItemList(event.getStock())));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.Acrobot.ChestShop.Listeners.PreTransaction;
|
||||
|
||||
import com.Acrobot.Breeze.Utils.MaterialUtil;
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
import com.Acrobot.ChestShop.Commands.Toggle;
|
||||
import com.Acrobot.ChestShop.Configuration.Messages;
|
||||
import com.Acrobot.ChestShop.Configuration.Properties;
|
||||
|
@ -121,22 +122,26 @@ public class ErrorMessageSender implements Listener {
|
|||
|
||||
private static void sendMessageToOwner(Account ownerAccount, String message, ItemStack... stock) {
|
||||
Player player = Bukkit.getPlayer(ownerAccount.getUuid());
|
||||
if (player != null) {
|
||||
if (player != null || Properties.BUNGEECORD_MESSAGES) {
|
||||
message = message.replace("%material", "%item");
|
||||
String replacedMessage = message.replace("%item", MaterialUtil.getItemList(stock));
|
||||
|
||||
if (Properties.NOTIFICATION_MESSAGE_COOLDOWN > 0) {
|
||||
Long last = notificationCooldowns.get(player.getUniqueId(), replacedMessage);
|
||||
Long last = notificationCooldowns.get(ownerAccount.getUuid(), replacedMessage);
|
||||
if (last != null && last + Properties.NOTIFICATION_MESSAGE_COOLDOWN * 1000 > System.currentTimeMillis()) {
|
||||
return;
|
||||
}
|
||||
notificationCooldowns.put(player.getUniqueId(), replacedMessage, System.currentTimeMillis());
|
||||
notificationCooldowns.put(ownerAccount.getUuid(), replacedMessage, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
if (Properties.SHOWITEM_MESSAGE && MaterialUtil.Show.sendMessage(player, message, stock)) {
|
||||
return;
|
||||
if (player != null) {
|
||||
if (Properties.SHOWITEM_MESSAGE && MaterialUtil.Show.sendMessage(player, message, stock)) {
|
||||
return;
|
||||
}
|
||||
player.sendMessage(replacedMessage);
|
||||
} else {
|
||||
ChestShop.sendBungeeMessage(ownerAccount.getName(), replacedMessage);
|
||||
}
|
||||
player.sendMessage(replacedMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue