mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-24 17:39:52 -05:00
Merge remote-tracking branch 'origin/master'
Former-commit-id: 0b52724bd6352a8524b87902424d2a584ac9108c
This commit is contained in:
commit
365eeb14c7
5 files changed
+88
-54
No files matched your search
@@ -24,6 +24,7 @@ import me.minebuilders.clearlag.Clearlag;
|
||||
import me.minebuilders.clearlag.listeners.ItemMergeListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
@@ -60,11 +61,13 @@ import org.maxgamer.quickshop.Watcher.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.file.Files;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
public class QuickShop extends JavaPlugin {
|
||||
@@ -775,50 +778,49 @@ public class QuickShop extends JavaPlugin {
|
||||
return true;
|
||||
}
|
||||
|
||||
// public void configVaildate() {
|
||||
// YamlConfiguration attached = YamlConfiguration.loadConfiguration(new InputStreamReader(Objects.requireNonNull(getResource("config.yml"))));
|
||||
// Set<String> keysA = new HashSet<>(attached.getKeys(true));
|
||||
// Set<String> keysB = new HashSet<>(getConfig().getKeys(true));
|
||||
// Set<String> ignoreCheckKeys = new HashSet<>();
|
||||
// ignoreCheckKeys.add("server-uuid");
|
||||
// final String msgForConfiguration = "Missing options in config.yml, the key [%key%] not exist in config.yml, it may cause plugin errors, please fix it! There is guide for you to fix: \n" +
|
||||
// ".....\n" +
|
||||
// "%data%\n" +
|
||||
// ".....\n" +
|
||||
// "Tips: Add \"auto-fix-configuration: true\" in config.yml to allow QuickShop automatic fix your configuration!";
|
||||
// keysA.stream().filter((key) -> !keysB.contains(key)).filter((key) -> !ignoreCheckKeys.contains(key)).collect(Collectors.toList()).forEach((miss) -> {
|
||||
// if(!getConfig().getBoolean("auto-fix-configuration",false)){
|
||||
// String theMsg = msgForConfiguration;
|
||||
// theMsg = theMsg.replace("%key%", miss);
|
||||
// List<String> tiers = new ArrayList<>(Arrays.asList(miss.split("\\.")));
|
||||
// StringBuilder miss2Yaml = new StringBuilder();
|
||||
// int spaces = 2;
|
||||
// Iterator<String> iterator = tiers.iterator();
|
||||
// while (true) {
|
||||
// String tier = iterator.next();
|
||||
// miss2Yaml.append(tier);
|
||||
// if (iterator.hasNext()) {
|
||||
// miss2Yaml.append(": ");
|
||||
// miss2Yaml.append("\n");
|
||||
// for (int i = 0; i < spaces; i++) {
|
||||
// miss2Yaml.append(" ");
|
||||
// }
|
||||
// spaces += 2;
|
||||
// } else {
|
||||
// miss2Yaml.append(": ");
|
||||
// miss2Yaml.append(attached.get(miss));
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// theMsg = theMsg.replace("%data%", miss2Yaml.toString());
|
||||
// getLogger().warning(theMsg);
|
||||
// }else{
|
||||
// getConfig().set(miss,attached.get(miss));
|
||||
// }
|
||||
//
|
||||
//
|
||||
// });
|
||||
// }
|
||||
public void configVaildate() {
|
||||
YamlConfiguration attached = YamlConfiguration.loadConfiguration(new InputStreamReader(Objects.requireNonNull(getResource("config.yml"))));
|
||||
Set<String> keysA = new HashSet<>(attached.getKeys(true));
|
||||
Set<String> keysB = new HashSet<>(getConfig().getKeys(true));
|
||||
Set<String> ignoreCheckKeys = new HashSet<>();
|
||||
ignoreCheckKeys.add("server-uuid");
|
||||
final String msgForConfiguration = "Missing options in config.yml, the key [%key%] not exist in config.yml, it may cause plugin errors, please fix it! There is guide for you to fix: \n" +
|
||||
".....\n" +
|
||||
"%data%\n" +
|
||||
".....\n" +
|
||||
"Tips: Add \"auto-fix-configuration: true\" in config.yml to allow QuickShop automatic fix your configuration!";
|
||||
keysA.stream().filter((key) -> !keysB.contains(key)).filter((key) -> !ignoreCheckKeys.contains(key)).collect(Collectors.toList()).forEach((miss) -> {
|
||||
if(!getConfig().getBoolean("auto-fix-configuration",false)){
|
||||
String theMsg = msgForConfiguration;
|
||||
theMsg = theMsg.replace("%key%", miss);
|
||||
List<String> tiers = new ArrayList<>(Arrays.asList(miss.split("\\.")));
|
||||
StringBuilder miss2Yaml = new StringBuilder();
|
||||
int spaces = 2;
|
||||
Iterator<String> iterator = tiers.iterator();
|
||||
while (true) {
|
||||
String tier = iterator.next();
|
||||
miss2Yaml.append(tier);
|
||||
if (iterator.hasNext()) {
|
||||
miss2Yaml.append(": ");
|
||||
miss2Yaml.append("\n");
|
||||
for (int i = 0; i < spaces; i++) {
|
||||
miss2Yaml.append(" ");
|
||||
}
|
||||
spaces += 2;
|
||||
} else {
|
||||
miss2Yaml.append(": ");
|
||||
miss2Yaml.append(attached.get(miss)); break;
|
||||
}
|
||||
}
|
||||
theMsg = theMsg.replace("%data%", miss2Yaml.toString());
|
||||
getLogger().warning(theMsg);
|
||||
}else{
|
||||
getConfig().set(miss,attached.get(miss));
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private void submitMeritcs() {
|
||||
if (!getConfig().getBoolean("disabled-metrics")) {
|
||||
@@ -1377,7 +1379,7 @@ public class QuickShop extends JavaPlugin {
|
||||
} catch (IOException ioe) {
|
||||
getLogger().warning("Error on spawning the example config file: " + ioe.getMessage());
|
||||
}
|
||||
//configVaildate();
|
||||
configVaildate();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -304,4 +304,16 @@ public class ArmorStandDisplayItem implements DisplayItem {
|
||||
}
|
||||
return this.armorStand.isValid();
|
||||
}
|
||||
|
||||
boolean pendingRemoval;
|
||||
|
||||
@Override
|
||||
public boolean pendingRemoval() {
|
||||
return pendingRemoval = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPendingRemoval() {
|
||||
return pendingRemoval;
|
||||
}
|
||||
}
|
||||
@@ -277,4 +277,7 @@ public interface DisplayItem {
|
||||
*/
|
||||
boolean isSpawned();
|
||||
|
||||
boolean pendingRemoval();
|
||||
|
||||
boolean isPendingRemoval();
|
||||
}
|
||||
@@ -242,4 +242,16 @@ public class RealDisplayItem implements DisplayItem {
|
||||
}
|
||||
return this.item.isValid();
|
||||
}
|
||||
|
||||
boolean pendingRemoval;
|
||||
|
||||
@Override
|
||||
public boolean pendingRemoval() {
|
||||
return pendingRemoval = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPendingRemoval() {
|
||||
return pendingRemoval;
|
||||
}
|
||||
}
|
||||
@@ -31,26 +31,31 @@ public class DisplayAutoDespawnWatcher extends BukkitRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
plugin.getShopManager().getLoadedShops().stream().forEach(shop -> {
|
||||
int range = plugin.getConfig().getInt("shop.display-despawn-range");
|
||||
|
||||
plugin.getShopManager().getLoadedShops().parallelStream()
|
||||
.filter(shop -> shop.getDisplay() != null)
|
||||
.forEach(shop -> {
|
||||
//Check the range has player?
|
||||
int range = plugin.getConfig().getInt("shop.display-despawn-range");
|
||||
boolean anyPlayerInRegion = Bukkit.getOnlinePlayers()
|
||||
.stream()
|
||||
.filter(player -> player.getWorld().equals(shop.getLocation().getWorld()))
|
||||
.filter(player -> player.getWorld() == shop.getLocation().getWorld())
|
||||
.anyMatch(player -> player.getLocation().distance(shop.getLocation()) < range);
|
||||
|
||||
if (shop.getDisplay() == null) {
|
||||
return;
|
||||
}
|
||||
if (anyPlayerInRegion) {
|
||||
if (!shop.getDisplay().isSpawned()) {
|
||||
Util.debugLog("Respawning the shop " + shop + " the display, cause it was despawned and a player close it");
|
||||
shop.checkDisplay();
|
||||
}
|
||||
} else {
|
||||
if (shop.getDisplay().isSpawned()) {
|
||||
} else if (shop.getDisplay().isSpawned()) {
|
||||
if (shop.getDisplay().isPendingRemoval()) {
|
||||
// Actually remove the pending display
|
||||
Util.debugLog("Removing the shop " + shop + " the display, cause nobody can see it");
|
||||
shop.getDisplay().remove();
|
||||
shop.getDisplay().remove();
|
||||
} else {
|
||||
// Delayed to next cycle
|
||||
Util.debugLog("Pending to remove the shop " + shop + " the display, cause nobody can see it");
|
||||
shop.getDisplay().pendingRemoval();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user