diff --git a/pom.xml b/pom.xml
index 848403b..38c537d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -169,7 +169,7 @@
system
${project.basedir}/lib/PlotSquared-Bukkit-4.4.495.jar
-
+
org.codemc.worldguardwrapper
diff --git a/src/main/java/de/epiceric/shopchest/ShopChest.java b/src/main/java/de/epiceric/shopchest/ShopChest.java
index fd9daca..e760ab7 100644
--- a/src/main/java/de/epiceric/shopchest/ShopChest.java
+++ b/src/main/java/de/epiceric/shopchest/ShopChest.java
@@ -214,6 +214,8 @@ public class ShopChest extends JavaPlugin {
registerExternalListeners();
initializeShops();
+ getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
+
updater = new ShopUpdater(this);
updater.start();
}
diff --git a/src/main/java/de/epiceric/shopchest/config/Config.java b/src/main/java/de/epiceric/shopchest/config/Config.java
index ba136f6..21e9cb3 100644
--- a/src/main/java/de/epiceric/shopchest/config/Config.java
+++ b/src/main/java/de/epiceric/shopchest/config/Config.java
@@ -219,6 +219,11 @@ public class Config {
**/
public static boolean enableVendorMessages;
+ /**
+ * Whether the vendor of the shop should get messages on all servers about buys and sells
+ **/
+ public static boolean enableVendorBungeeMessages;
+
/**
* Whether the extension of a potion or tipped arrow (if available) should be appended to the item name.
**/
@@ -486,6 +491,7 @@ public class Config {
enableGriefPreventionIntegration = plugin.getConfig().getBoolean("enable-griefprevention-integration");
enableAreaShopIntegration = plugin.getConfig().getBoolean("enable-areashop-integration");
enableVendorMessages = plugin.getConfig().getBoolean("enable-vendor-messages");
+ enableVendorBungeeMessages = plugin.getConfig().getBoolean("enable-vendor-bungee-messages");
onlyShowShopsInSight = plugin.getConfig().getBoolean("only-show-shops-in-sight");
appendPotionLevelToItemName = plugin.getConfig().getBoolean("append-potion-level-to-item-name");
removeShopOnError = plugin.getConfig().getBoolean("remove-shop-on-error");
diff --git a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java
index ee09b38..c53edaa 100644
--- a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java
+++ b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java
@@ -1,5 +1,7 @@
package de.epiceric.shopchest.listeners;
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -343,6 +345,11 @@ public class ShopInteractListener implements Listener {
shop.getVendor().getPlayer().sendMessage(LanguageUtils.getMessage(Message.VENDOR_OUT_OF_STOCK,
new Replacement(Placeholder.AMOUNT, String.valueOf(shop.getProduct().getAmount())),
new Replacement(Placeholder.ITEM_NAME, shop.getProduct().getLocalizedName())));
+ } else if(!shop.getVendor().isOnline() && Config.enableVendorBungeeMessages){
+ String message = LanguageUtils.getMessage(Message.VENDOR_OUT_OF_STOCK,
+ new Replacement(Placeholder.AMOUNT, String.valueOf(shop.getProduct().getAmount())),
+ new Replacement(Placeholder.ITEM_NAME, shop.getProduct().getLocalizedName()));
+ sendBungeeMessage(shop.getVendor().getName(), message);
}
plugin.debug("Shop is out of stock");
}
@@ -827,6 +834,11 @@ public class ShopInteractListener implements Listener {
shop.getVendor().getPlayer().sendMessage(LanguageUtils.getMessage(Message.SOMEONE_BOUGHT, new Replacement(Placeholder.AMOUNT, String.valueOf(newAmount)),
new Replacement(Placeholder.ITEM_NAME, newProduct.getLocalizedName()), new Replacement(Placeholder.BUY_PRICE, String.valueOf(newPrice)),
new Replacement(Placeholder.PLAYER, executor.getName())));
+ } else if(!shop.getVendor().isOnline() && Config.enableVendorBungeeMessages){
+ String message = LanguageUtils.getMessage( Message.SOMEONE_BOUGHT, new Replacement(Placeholder.AMOUNT, String.valueOf(newAmount)),
+ new Replacement(Placeholder.ITEM_NAME, newProduct.getLocalizedName()), new Replacement(Placeholder.BUY_PRICE, String.valueOf(newPrice)),
+ new Replacement(Placeholder.PLAYER, executor.getName()));
+ sendBungeeMessage(shop.getVendor().getName(),message);
}
} else {
@@ -990,6 +1002,11 @@ public class ShopInteractListener implements Listener {
shop.getVendor().getPlayer().sendMessage(LanguageUtils.getMessage(Message.SOMEONE_SOLD, new Replacement(Placeholder.AMOUNT, String.valueOf(newAmount)),
new Replacement(Placeholder.ITEM_NAME, newProduct.getLocalizedName()), new Replacement(Placeholder.SELL_PRICE, String.valueOf(newPrice)),
new Replacement(Placeholder.PLAYER, executor.getName())));
+ } else if(!shop.getVendor().isOnline() && Config.enableVendorBungeeMessages){
+ String message = LanguageUtils.getMessage( Message.SOMEONE_SOLD, new Replacement(Placeholder.AMOUNT, String.valueOf(newAmount)),
+ new Replacement(Placeholder.ITEM_NAME, newProduct.getLocalizedName()), new Replacement(Placeholder.SELL_PRICE, String.valueOf(newPrice)),
+ new Replacement(Placeholder.PLAYER, executor.getName()));
+ sendBungeeMessage(shop.getVendor().getName(),message);
}
} else {
@@ -1167,4 +1184,25 @@ public class ShopInteractListener implements Listener {
return (removed == amount);
}
+ public void sendBungeeMessage(String player, String message) {
+ try {
+ ByteArrayOutputStream b = new ByteArrayOutputStream();
+ DataOutputStream out = new DataOutputStream(b);
+
+ out.writeUTF("Message");
+ out.writeUTF(player);
+ out.writeUTF(message);
+
+ if (!plugin.getServer().getOnlinePlayers().isEmpty()) {
+ plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
+ Player p = plugin.getServer().getOnlinePlayers().iterator().next();
+ p.sendPluginMessage(plugin, "BungeeCord", b.toByteArray());
+ });
+ }
+ } catch (Exception e) {
+ plugin.debug("Failed to send bungee message");
+ plugin.debug(e);
+ plugin.getLogger().warning("Failed to send BungeeCord message");
+ }
+ }
}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 2dafa5b..f00e5d5 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -66,6 +66,10 @@ enable-areashop-integration: true
# or sell something from/to his shop or when his shop is out of stock.
enable-vendor-messages: true
+# Set whether the vendor of a shop should get messages on all servers when players
+# buy or sell something from/to his shop or when his shop is out of stock.
+enable-vendor-bungee-messages: false
+
# Set whether only the shop a player is pointing at should be shown.
# If set to false, every shop near the player (with the specified
# distance) will be shown to him.