mirror of
https://github.com/Flowsqy/ShopChest.git
synced 2024-11-26 01:05:12 +01:00
Bungee sync vendor messages (#320)
This commit is contained in:
parent
a402423b4b
commit
3669cf73be
2
pom.xml
2
pom.xml
@ -169,7 +169,7 @@
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/PlotSquared-Bukkit-4.4.495.jar</systemPath>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Shaded dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
|
@ -214,6 +214,8 @@ public class ShopChest extends JavaPlugin {
|
||||
registerExternalListeners();
|
||||
initializeShops();
|
||||
|
||||
getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
||||
|
||||
updater = new ShopUpdater(this);
|
||||
updater.start();
|
||||
}
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user