Ongoing fee feature

Former-commit-id: bbb52c5073cac0ffd20b31ae07dbee2a4baa62f1 [formerly 5e65427e6ef1b8cf0a6945d9442795520344f309]
Former-commit-id: a8dcd392461495c709528c81a2b73c684bfc7a9c
This commit is contained in:
Ghost_chu committed 2019-11-10 18:46:39 +08:00
1 parent 9fe6da1081
commit a1a6ec6900
7 files changed
+130 -7

No files matched your search

@@ -152,6 +152,7 @@ public class QuickShop extends JavaPlugin {
* The manager to check permissions.
*/
private static PermissionManager permissionManager;
private OngoingFeeWatcher ongoingFeeWatcher;
/**
* Get the Player's Shop limit.
@@ -429,6 +430,7 @@ public class QuickShop extends JavaPlugin {
displayWatcher = new DisplayWatcher(this);
syncTaskWatcher = new SyncTaskWatcher(this);
shopVaildWatcher = new ShopVaildWatcher(this);
ongoingFeeWatcher = new OngoingFeeWatcher(this);
lockListener = new LockListener(this);
Bukkit.getPluginManager().registerEvents(blockListener, this);
Bukkit.getPluginManager().registerEvents(playerListener, this);
@@ -464,6 +466,11 @@ public class QuickShop extends JavaPlugin {
}.runTaskLater(this, 1);
Util.debugLog("Registering shop watcher...");
shopVaildWatcher.runTaskTimer(this, 0, 20 * 60);
if(getConfig().getBoolean("shop.ongoing-fee.enable")){
getLogger().info("Ongoine fee feature is enabled.");
ongoingFeeWatcher.runTaskTimerAsynchronously(this, getConfig().getInt("shop.ongoing-fee.ticks"), getConfig().getInt("shop.ongoing-fee.ticks"));
}
if(this.display){
if(getConfig().getBoolean("shop.display-auto-despawn")){
new BukkitRunnable(){
@@ -1002,7 +1009,14 @@ public class QuickShop extends JavaPlugin {
getConfig().set("config-version", 63);
selectedVersion = 63;
}
if(selectedVersion == 63){ //Ahhh fuck versions
getConfig().set("shop.ongoing-fee.enable", false);
getConfig().set("shop.ongoing-fee.ticks", 42000);
getConfig().set("shop.ongoing-fee.cost-per-shop", 2);
getConfig().set("shop.ongoing-fee.ignore-unlimited",true);
getConfig().set("config-version", 64);
selectedVersion = 64;
}
saveConfig();
reloadConfig();
File file = new File(getDataFolder(), "example.config.yml");
@@ -2,6 +2,7 @@ package org.maxgamer.quickshop.Shop;
import com.lishid.openinv.OpenInv;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -31,6 +32,7 @@ import java.util.logging.Level;
* ChestShop core
*/
@EqualsAndHashCode
@ToString
public class ContainerShop implements Shop {
private DisplayItem displayItem;
@EqualsAndHashCode.Exclude
@@ -849,6 +849,24 @@ public class ShopManager {
return new ShopIterator();
}
/**
* Returns all shops in the whole database, include unloaded.
*
* Make sure you have caching this, because this need a while to get all shops
* @return All shop in the database
*/
public Collection<Shop> getAllShops(){
//noinspection unchecked
HashMap<String, HashMap<ShopChunk, HashMap<Location, Shop>>> worldsMap = (HashMap<String, HashMap<ShopChunk, HashMap<Location, Shop>>>) getShops()
.clone();
Collection<Shop> shops = new ArrayList<>();
for (HashMap<ShopChunk, HashMap<Location, Shop>> shopMapData : worldsMap.values()){
for (HashMap<Location, Shop> shopData : shopMapData.values()){
shops.addAll(shopData.values());
}
}
return shops;
}
/**
* Returns a hashmap of World - Chunk - Shop
*
@@ -470,13 +470,17 @@ public class MsgUtil {
Util.debugLog("Unknown error, send by plain text.");
p.getPlayer().sendMessage(msgData[0] + msgData[1] + msgData[2]);
} catch (ArrayIndexOutOfBoundsException e2){
Util.debugLog("Message is legacy format, send as plain message...");
p.getPlayer().sendMessage(message);
try{
sendItemholochat(p.getPlayer(), msgData[0], Util.deserialize(msgData[1]),"");
}catch (Exception any){
//Normal msg
p.getPlayer().sendMessage(message);
}
}
}
}
}
@SneakyThrows
public static void sendItemholochat(@NotNull Player player, @NotNull String left, @NotNull ItemStack itemStack, @NotNull String right) {
String json = ItemNMS.saveJsonfromNMS(itemStack);
@@ -1059,6 +1063,11 @@ public class MsgUtil {
setAndUpdate("language-version", 21);
selectedVersion = 21;
}
if (selectedVersion == 21) {
setAndUpdate("shop-removed-cause-ongoing-fee", "&cYou shop at {0} was removed cause you had no enough money to keep it!");
setAndUpdate("language-version", 22);
selectedVersion = 22;
}
messagei18n.save(messageFile);
}
@@ -0,0 +1,69 @@
package org.maxgamer.quickshop.Watcher;
import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull;
import org.maxgamer.quickshop.QuickShop;
import org.maxgamer.quickshop.Shop.Shop;
import org.maxgamer.quickshop.Util.MsgUtil;
import org.maxgamer.quickshop.Util.Util;
import java.util.UUID;
/**
* Check the shops after server booted up, make sure shop can correct self-deleted when container lost.
*/
public class OngoingFeeWatcher extends BukkitRunnable {
private QuickShop plugin;
public OngoingFeeWatcher(@NotNull QuickShop plugin) {
this.plugin = plugin;
}
@Override
public void run() {
Util.debugLog("Run task for ongoing fee...");
if (plugin.getEconomy() == null) {
Util.debugLog("Economy hadn't get ready.");
return;
}
int cost = plugin.getConfig().getInt("shop.ongoing-fee.cost-per-shop");
boolean allowLoan = plugin.getConfig().getBoolean("shop.allow-economy-loan");
boolean ignoreUnlimited = plugin.getConfig().getBoolean("shop.ongoing-fee.ignore-unlimited");
for (Shop shop : plugin.getShopManager().getAllShops()) {
if (!shop.isUnlimited() || !ignoreUnlimited) {
UUID shopOwner = shop.getOwner();
if (!allowLoan) {
//Disallow loan
if (plugin.getEconomy().getBalance(shopOwner) < cost) {
removeShop(shop);
continue;
}
}
boolean success = plugin.getEconomy().withdraw(shop.getOwner(), cost);
if (!success) {
removeShop(shop);
continue;
}
try {
//noinspection ConstantConditions
plugin.getEconomy().deposit(Bukkit.getOfflinePlayer(plugin.getConfig().getString("tax")).getUniqueId(), cost);
} catch (Exception ignored) {
}
}else{
Util.debugLog("Shop was ignored for ongoing fee cause it is unlimited and ignoreUnlimited = true : "+shop.toString());
}
}
}
/**
* Remove shop and send alert to shop owner
*
* @param shop The shop was remove cause no enough ongoing fee
*/
public void removeShop(@NotNull Shop shop) {
Bukkit.getScheduler().runTask(plugin, (@NotNull Runnable) shop::delete);
MsgUtil.send(shop.getOwner(), MsgUtil.getMessageOfflinePlayer("shop-removed-cause-ongoing-fee", Bukkit.getOfflinePlayer(shop.getOwner()), "World:" + shop.getLocation().getWorld().getName() + " X:" + shop.getLocation().getBlockX() + " Y:" + shop.getLocation().getBlockY() + " Z:" + shop.getLocation().getBlockZ()), shop.isUnlimited());
}
}
+11 -1
View File
@@ -1,7 +1,7 @@
#This is example config, don't direct modify this file, all changes will revert when you reload the plugin.
#Do not touch if you not clear know about this
config-version: 63
config-version: 64
#Select the language you want to use, (e.g de), use only supported language codes from the list below.
#If you use a not exist/not support language, plugin will move to use en_US to keep everything working.
@@ -245,6 +245,16 @@ shop:
#The word to trade all items in player inventory
word-for-trade-all-items: "all"
#The shop ongoing fee, if a shop's owner had no enough money, shop will auto-remove.
ongoing-fee:
enable: false
#How often we will take the ongoing-fee from the players?
ticks: 42000
#How many money we take from the shop's owner every times?
cost-per-shop: 2
#Should we ignore the unlimited shop?
ignore-unlimited: true
#List of items that can't be sold in shops. Anyone with quickshop.bypass.<itemID> can bypass it
blacklist:
- Bedrock
+3 -2
View File
@@ -11,7 +11,7 @@ translation-version: "&c&lSupport Version: &b&lReremake"
translation-country: "&c&lLanguage Zone: &b&lEnglish (en_US)"
# ======================================================================
language-version: 20
language-version: 22
not-looking-at-shop: "&cNo QuickShop was found, you must be looking at one."
no-anythings-in-your-hand: "&cThere is nothing in your hand."
@@ -226,4 +226,5 @@ updatenotify:
qualityverifyed: "[Quality]"
github: "[Github]"
spigotmc: "[SpigotMC]"
bukkitdev: "[BukkitDev]"
bukkitdev: "[BukkitDev]"
shop-removed-cause-ongoing-fee: "&cYou shop at {0} was removed cause you had no enough money to keep it!"