mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-24 17:39:52 -05:00
Fix #207
Former-commit-id: 8aeb6efc449bd421bac535ae5930c0c1354f258b [formerly 91603644b019c7c2af5f2999fe91a319196421a4] Former-commit-id: 42510f03f4caf43ce5ba38c20ab6c8c1b9df1244
This commit is contained in:
1 parent
39fb65367d
commit
279781bcb5
3 files changed
+61
-48
No files matched your search
@@ -1,14 +1,15 @@
|
||||
package org.maxgamer.quickshop.InternalListener;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.maxgamer.quickshop.Event.*;
|
||||
import org.maxgamer.quickshop.Listeners.ListenerHelper;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class InternalListener implements Listener {
|
||||
private QuickShop plugin = QuickShop.instance;
|
||||
private QuickShop plugin;
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void shopCreate(ShopCreateEvent event) {
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.maxgamer.quickshop.Command.CommandManager;
|
||||
import org.maxgamer.quickshop.Database.*;
|
||||
import org.maxgamer.quickshop.Database.Database.ConnectionException;
|
||||
import org.maxgamer.quickshop.Economy.*;
|
||||
import org.maxgamer.quickshop.InternalListener.InternalListener;
|
||||
import org.maxgamer.quickshop.Listeners.*;
|
||||
import org.maxgamer.quickshop.Permission.PermissionManager;
|
||||
import org.maxgamer.quickshop.Shop.Shop;
|
||||
@@ -113,6 +114,7 @@ public class QuickShop extends JavaPlugin {
|
||||
**/
|
||||
private PermissionChecker permissionChecker;
|
||||
private PlayerListener playerListener;
|
||||
private InternalListener internalListener;
|
||||
/**
|
||||
* Whether we players are charged a fee to change the price on their shop (To
|
||||
* help deter endless undercutting
|
||||
@@ -182,7 +184,7 @@ public class QuickShop extends JavaPlugin {
|
||||
getLogger().info("Successfully loaded OpenInv support!");
|
||||
}
|
||||
}
|
||||
if(getConfig().getBoolean("plugin.PlaceHolderAPI")){
|
||||
if (getConfig().getBoolean("plugin.PlaceHolderAPI")) {
|
||||
this.placeHolderAPI = Bukkit.getPluginManager().getPlugin("PlaceholderAPI");
|
||||
if (this.placeHolderAPI != null) {
|
||||
getLogger().info("Successfully loaded PlaceHolderAPI support!");
|
||||
@@ -432,6 +434,7 @@ public class QuickShop extends JavaPlugin {
|
||||
shopVaildWatcher = new ShopVaildWatcher(this);
|
||||
ongoingFeeWatcher = new OngoingFeeWatcher(this);
|
||||
lockListener = new LockListener(this);
|
||||
internalListener = new InternalListener(this);
|
||||
Bukkit.getPluginManager().registerEvents(blockListener, this);
|
||||
Bukkit.getPluginManager().registerEvents(playerListener, this);
|
||||
Bukkit.getPluginManager().registerEvents(chatListener, this);
|
||||
@@ -441,6 +444,7 @@ public class QuickShop extends JavaPlugin {
|
||||
Bukkit.getPluginManager().registerEvents(customInventoryListener, this);
|
||||
Bukkit.getPluginManager().registerEvents(displayBugFixListener, this);
|
||||
Bukkit.getPluginManager().registerEvents(shopProtectListener, this);
|
||||
Bukkit.getPluginManager().registerEvents(internalListener,this);
|
||||
if (getConfig().getBoolean("shop.lock")) {
|
||||
Bukkit.getPluginManager().registerEvents(lockListener, this);
|
||||
}
|
||||
@@ -466,22 +470,26 @@ 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")){
|
||||
if (logWatcher != null) {
|
||||
logWatcher.runTaskTimerAsynchronously(this, 10, 10);
|
||||
getLogger().info("Log actions is enabled, actions will log in the qs.log file!");
|
||||
}
|
||||
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(){
|
||||
|
||||
if (this.display) {
|
||||
if (getConfig().getBoolean("shop.display-auto-despawn")) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(getShopManager().getLoadedShops() == null){
|
||||
if (getShopManager().getLoadedShops() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
//noinspection unchecked
|
||||
getShopManager().getLoadedShops().parallelStream().forEach(shop-> {
|
||||
getShopManager().getLoadedShops().parallelStream().forEach(shop -> {
|
||||
//Check the range has player?
|
||||
int range = getConfig().getInt("shop.display-despawn-range");
|
||||
boolean anyPlayerInRegion = Bukkit.getOnlinePlayers()
|
||||
@@ -506,7 +514,7 @@ public class QuickShop extends JavaPlugin {
|
||||
}.runTask(QuickShop.instance);
|
||||
});
|
||||
}
|
||||
}.runTaskTimerAsynchronously(this,0,getConfig().getInt("shop.display-check-time" ));
|
||||
}.runTaskTimerAsynchronously(this, 0, getConfig().getInt("shop.display-check-time"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -647,7 +655,7 @@ public class QuickShop extends JavaPlugin {
|
||||
String shop_find_distance = getConfig().getString("shop.find-distance");
|
||||
String economyType = Economy.getNowUsing().name();
|
||||
String useDisplayAutoDespawn = String.valueOf(getConfig().getBoolean("shop.display-auto-despawn"));
|
||||
String useEnhanceDisplayProtect= String.valueOf(getConfig().getBoolean("shop.enchance-display-protect"));
|
||||
String useEnhanceDisplayProtect = String.valueOf(getConfig().getBoolean("shop.enchance-display-protect"));
|
||||
String useEnhanceShopProtect = String.valueOf(getConfig().getBoolean("shop.enchance-shop-protect"));
|
||||
String useOngoingFee = String.valueOf(getConfig().getBoolean("shop.ongoing-fee.enable"));
|
||||
// Version
|
||||
@@ -978,24 +986,24 @@ public class QuickShop extends JavaPlugin {
|
||||
}
|
||||
if (selectedVersion == 48) {
|
||||
getConfig().set("permission-type", null);
|
||||
getConfig().set("shop.use-protection-checking-filter",null);
|
||||
getConfig().set("shop.protection-checking-filter",null);
|
||||
getConfig().set("shop.use-protection-checking-filter", null);
|
||||
getConfig().set("shop.protection-checking-filter", null);
|
||||
getConfig().set("config-version", 49);
|
||||
selectedVersion = 49;
|
||||
}
|
||||
if(selectedVersion == 49 || selectedVersion == 50){
|
||||
if (selectedVersion == 49 || selectedVersion == 50) {
|
||||
getConfig().set("shop.enchance-display-protect", false);
|
||||
getConfig().set("shop.enchance-shop-protect", false);
|
||||
getConfig().set("protect", null);
|
||||
getConfig().set("config-version", 51);
|
||||
selectedVersion = 51;
|
||||
}
|
||||
if(selectedVersion < 60){ //Ahhh fuck versions
|
||||
if (selectedVersion < 60) { //Ahhh fuck versions
|
||||
getConfig().set("matcher.use-bukkit-matcher", false);
|
||||
getConfig().set("config-version", 60);
|
||||
selectedVersion = 60;
|
||||
}
|
||||
if(selectedVersion == 60){ //Ahhh fuck versions
|
||||
if (selectedVersion == 60) { //Ahhh fuck versions
|
||||
getConfig().set("matcher.use-bukkit-matcher", null);
|
||||
getConfig().set("shop.strict-matches-check", null);
|
||||
getConfig().set("matcher.work-type", 0);
|
||||
@@ -1005,24 +1013,24 @@ public class QuickShop extends JavaPlugin {
|
||||
getConfig().set("config-version", 61);
|
||||
selectedVersion = 61;
|
||||
}
|
||||
if(selectedVersion == 61){ //Ahhh fuck versions
|
||||
if (selectedVersion == 61) { //Ahhh fuck versions
|
||||
getConfig().set("shop.word-for-sell-all-items", "all");
|
||||
getConfig().set("plugin.PlaceHolderAPI", true);
|
||||
getConfig().set("config-version", 62);
|
||||
selectedVersion = 62;
|
||||
}
|
||||
if(selectedVersion == 62){ //Ahhh fuck versions
|
||||
if (selectedVersion == 62) { //Ahhh fuck versions
|
||||
getConfig().set("shop.display-auto-despawn", false);
|
||||
getConfig().set("shop.word-for-trade-all-items", getConfig().getString("shop.word-for-sell-all-items"));
|
||||
|
||||
getConfig().set("config-version", 63);
|
||||
selectedVersion = 63;
|
||||
}
|
||||
if(selectedVersion == 63){ //Ahhh fuck versions
|
||||
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("shop.ongoing-fee.ignore-unlimited", true);
|
||||
getConfig().set("config-version", 64);
|
||||
selectedVersion = 64;
|
||||
}
|
||||
|
||||
@@ -1,28 +1,32 @@
|
||||
package org.maxgamer.quickshop.Watcher;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.SneakyThrows;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
import org.maxgamer.quickshop.Util.Util;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
public class LogWatcher implements Runnable {
|
||||
public class LogWatcher extends BukkitRunnable {
|
||||
private Queue<String> logs = new LinkedList<>();
|
||||
private PrintStream ps;
|
||||
private FileWriter logFileWriter = null;
|
||||
|
||||
public LogWatcher(QuickShop plugin, File log) {
|
||||
try {
|
||||
if (!log.exists()) {
|
||||
log.createNewFile();
|
||||
}
|
||||
FileOutputStream fos = new FileOutputStream(log, true);
|
||||
this.ps = new PrintStream(fos);
|
||||
logFileWriter = new FileWriter(log);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
plugin.getLogger().severe("Log file was not found!");
|
||||
@@ -33,20 +37,15 @@ public class LogWatcher implements Runnable {
|
||||
}
|
||||
|
||||
public void add(@NotNull String s) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
logs.add(s);
|
||||
}
|
||||
}.runTask(QuickShop.instance);
|
||||
|
||||
logs.add(s);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void close() {
|
||||
if (ps != null) {
|
||||
this.ps.close();
|
||||
if (logFileWriter != null) {
|
||||
logFileWriter.flush();
|
||||
logFileWriter.close();
|
||||
}
|
||||
ps = null;
|
||||
}
|
||||
|
||||
public void log(@NonNull String log) {
|
||||
@@ -57,18 +56,23 @@ public class LogWatcher implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (String log : logs) {
|
||||
if (ps == null) {
|
||||
continue;
|
||||
}
|
||||
ps.print(log + "\n");
|
||||
}
|
||||
logs.clear();
|
||||
|
||||
for (String log : logs) {
|
||||
if (logFileWriter == null) {
|
||||
continue;
|
||||
}
|
||||
}.runTaskAsynchronously(QuickShop.instance);
|
||||
try {
|
||||
logFileWriter.write(log + System.getProperty("line.separator"));
|
||||
} catch (IOException ioe) {
|
||||
Util.debugLog("Failed to write log to disk: " + ioe.getMessage() + ", the log was dropped.");
|
||||
}
|
||||
}
|
||||
logs.clear();
|
||||
if (logFileWriter != null) {
|
||||
try {
|
||||
logFileWriter.flush();
|
||||
} catch (IOException ioe) {
|
||||
Util.debugLog("Failed to flush log to disk: " + ioe.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user