T getOrSet(@NotNull String path, @NotNull T fallback);
-
- /**
- * Gets location
- *
- * @param path location path to get
- * @return {@link Location}
- */
- @NotNull Location getLocation(@NotNull String path);
-
- /**
- * Sets location into the path
- *
- * @param path location path to set
- * @param location {@link Location}
- */
- void setLocation(@NotNull String path, @NotNull Location location);
-
- /**
- * Pattern:
- *
- * path: (material): 'DIAMOND' [amount]: 1 [data]: 0 [display-name]: 'Diamond Sword'
- * [enchants]: DAMAGE_ALL: 10 FIRE_ASPECT: 2 [lore]: - 'Lore 1' - 'Lore 2'
- *
- * @param path itemstack path to get
- * @return {@link ItemStack}
- */
- @NotNull ItemStack getCustomItemStack(@NotNull String path);
-
- /**
- * Sets custom itemstack to path
- *
- * @param path itemstack path to set
- * @param itemStack {@link ItemStack}
- */
- void setCustomItemStack(@NotNull String path, @NotNull ItemStack itemStack);
-
- /**
- * Gets string
- *
- * @param path string path to get
- * @return {@link String}
- */
- @NotNull Optional getString(@NotNull String path);
-
- /**
- * Sets object to path
- *
- * @param path object path to set
- * @param object {@link Object}
- */
- void set(@NotNull String path, @Nullable Object object);
-
- /**
- * Gets string list
- *
- * @param path string list path to get
- * @return string list
- */
- @NotNull List getStringList(@NotNull String path);
-
- /**
- * Gets int
- *
- * @param path integer path to get
- * @return {@link Integer}
- */
- int getInt(@NotNull String path);
-
- /**
- * Gets double
- *
- * @param path double path to get
- * @return {@link Double}
- */
- double getDouble(@NotNull String path);
-
- /**
- * Gets long
- *
- * @param path long path to get
- * @return {@link Integer}
- */
- long getLong(@NotNull String path);
-
- /**
- * Gets byte
- *
- * @param path byte path to get
- * @return {@link Byte}
- */
- byte getByte(@NotNull String path);
-
- /**
- * Gets short
- *
- * @param path short path to get
- * @return {@link Short}
- */
- short getShort(@NotNull String path);
-
- /**
- * Gets boolean
- *
- * @param path boolean path to get
- * @return {@link Boolean}
- */
- boolean getBoolean(@NotNull String path);
-
- /**
- * Creates configuration section into path
- *
- * @param path configuration section path to create
- * @return {@link ConfigurationSection}
- */
- @NotNull ConfigurationSection createSection(@NotNull String path);
-
- /**
- * Gets configuration section from path
- *
- * @param path configurations section path to get
- * @return if there isn't section returns {@link MckFileConfiguration}
- */
- @NotNull ConfigurationSection getSection(@NotNull String path);
-
- /**
- * Gets configuration section from path if there is no section It will create
- *
- * @param path configurations section path to get
- * @return {@link ConfigurationSection}
- */
- @NotNull ConfigurationSection getOrCreateSection(@NotNull String path);
-
-}
+///*
+// * This file is a part of project QuickShop, the name is IFile.java
+// * Copyright (C) PotatoCraft Studio and contributors
+// *
+// * This program is free software: you can redistribute it and/or modify it
+// * under the terms of the GNU General Public License as published by the
+// * Free Software Foundation, either version 3 of the License, or
+// * (at your option) any later version.
+// *
+// * This program is distributed in the hope that it will be useful, but WITHOUT
+// * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// * for more details.
+// *
+// * You should have received a copy of the GNU General Public License
+// * along with this program. If not, see .
+// *
+// */
+//
+//package org.maxgamer.quickshop.fileportlek.old;
+//
+//import org.bukkit.Location;
+//import org.bukkit.configuration.ConfigurationSection;
+//import org.bukkit.configuration.InvalidConfigurationException;
+//import org.bukkit.inventory.ItemStack;
+//import org.jetbrains.annotations.NotNull;
+//import org.jetbrains.annotations.Nullable;
+//import org.maxgamer.quickshop.mock.MckFileConfiguration;
+//
+//import java.io.InputStream;
+//import java.util.List;
+//import java.util.Optional;
+//
+//public interface IFile {
+//
+// /**
+// * Creates yml file on the path
+// */
+// void create();
+//
+// @NotNull InputStream getInputStream();
+//
+// /**
+// * Reloads file
+// */
+// void reload();
+//
+// /**
+// * Saves file
+// */
+// void save();
+//
+// /**
+// * @return the string of the file
+// */
+// @NotNull String saveToString();
+//
+// /**
+// * Loads from the data
+// *
+// * @param data the data
+// * @throws InvalidConfigurationException if config is invalid
+// */
+// void loadFromString(@NotNull String data) throws InvalidConfigurationException;
+//
+// /**
+// * Gets the object
+// *
+// * @param path object path to get
+// * @return if path does not exist returns null
+// */
+// @Nullable Object get(@NotNull String path);
+//
+// /**
+// * Gets the object with fallback
+// *
+// * @param path object path to get
+// * @param fallback fallback object to get if path does not exist
+// * @return if path does not exist returns fallback object
+// */
+// @Nullable Object get(@NotNull String path, @Nullable Object fallback);
+//
+// /**
+// * Gets or sets the object
+// *
+// * @param path object path to get
+// * @param fallback fallback object to get if path does not exist
+// * @param object type
+// * @return if path does not exist returns and set the path with fallback object
+// */
+// @NotNull T getOrSet(@NotNull String path, @NotNull T fallback);
+//
+// /**
+// * Gets location
+// *
+// * @param path location path to get
+// * @return {@link Location}
+// */
+// @NotNull Location getLocation(@NotNull String path);
+//
+// /**
+// * Sets location into the path
+// *
+// * @param path location path to set
+// * @param location {@link Location}
+// */
+// void setLocation(@NotNull String path, @NotNull Location location);
+//
+// /**
+// * Pattern:
+// *
+// * path: (material): 'DIAMOND' [amount]: 1 [data]: 0 [display-name]: 'Diamond Sword'
+// * [enchants]: DAMAGE_ALL: 10 FIRE_ASPECT: 2 [lore]: - 'Lore 1' - 'Lore 2'
+// *
+// * @param path itemstack path to get
+// * @return {@link ItemStack}
+// */
+// @NotNull ItemStack getCustomItemStack(@NotNull String path);
+//
+// /**
+// * Sets custom itemstack to path
+// *
+// * @param path itemstack path to set
+// * @param itemStack {@link ItemStack}
+// */
+// void setCustomItemStack(@NotNull String path, @NotNull ItemStack itemStack);
+//
+// /**
+// * Gets string
+// *
+// * @param path string path to get
+// * @return {@link String}
+// */
+// @NotNull Optional getString(@NotNull String path);
+//
+// /**
+// * Sets object to path
+// *
+// * @param path object path to set
+// * @param object {@link Object}
+// */
+// void set(@NotNull String path, @Nullable Object object);
+//
+// /**
+// * Gets string list
+// *
+// * @param path string list path to get
+// * @return string list
+// */
+// @NotNull List getStringList(@NotNull String path);
+//
+// /**
+// * Gets int
+// *
+// * @param path integer path to get
+// * @return {@link Integer}
+// */
+// int getInt(@NotNull String path);
+//
+// /**
+// * Gets double
+// *
+// * @param path double path to get
+// * @return {@link Double}
+// */
+// double getDouble(@NotNull String path);
+//
+// /**
+// * Gets long
+// *
+// * @param path long path to get
+// * @return {@link Integer}
+// */
+// long getLong(@NotNull String path);
+//
+// /**
+// * Gets byte
+// *
+// * @param path byte path to get
+// * @return {@link Byte}
+// */
+// byte getByte(@NotNull String path);
+//
+// /**
+// * Gets short
+// *
+// * @param path short path to get
+// * @return {@link Short}
+// */
+// short getShort(@NotNull String path);
+//
+// /**
+// * Gets boolean
+// *
+// * @param path boolean path to get
+// * @return {@link Boolean}
+// */
+// boolean getBoolean(@NotNull String path);
+//
+// /**
+// * Creates configuration section into path
+// *
+// * @param path configuration section path to create
+// * @return {@link ConfigurationSection}
+// */
+// @NotNull ConfigurationSection createSection(@NotNull String path);
+//
+// /**
+// * Gets configuration section from path
+// *
+// * @param path configurations section path to get
+// * @return if there isn't section returns {@link MckFileConfiguration}
+// */
+// @NotNull ConfigurationSection getSection(@NotNull String path);
+//
+// /**
+// * Gets configuration section from path if there is no section It will create
+// *
+// * @param path configurations section path to get
+// * @return {@link ConfigurationSection}
+// */
+// @NotNull ConfigurationSection getOrCreateSection(@NotNull String path);
+//
+//}
diff --git a/src/main/java/org/maxgamer/quickshop/fileportlek/old/JSONFile.java b/src/main/java/org/maxgamer/quickshop/fileportlek/old/JSONFile.java
index 0f3a0c2fb..e777e315a 100644
--- a/src/main/java/org/maxgamer/quickshop/fileportlek/old/JSONFile.java
+++ b/src/main/java/org/maxgamer/quickshop/fileportlek/old/JSONFile.java
@@ -1,64 +1,64 @@
-/*
- * This file is a part of project QuickShop, the name is JSONFile.java
- * Copyright (C) PotatoCraft Studio and contributors
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-
-package org.maxgamer.quickshop.fileportlek.old;
-
-import com.dumptruckman.bukkit.configuration.json.JsonConfiguration;
-import org.bukkit.configuration.InvalidConfigurationException;
-import org.bukkit.plugin.Plugin;
-import org.jetbrains.annotations.NotNull;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
-import java.util.logging.Level;
-
-public class JSONFile extends FileEnvelope {
-
- public JSONFile(@NotNull final Plugin plugin, @NotNull final File file, @NotNull final String resourcePath, boolean loadDefault) {
- super(plugin, file, resourcePath.endsWith(".json") ? resourcePath : resourcePath + ".json", loadDefault);
- }
-
- public JSONFile(@NotNull final Plugin plugin, @NotNull final String fileName) {
- this(plugin, "", fileName);
- }
-
- public JSONFile(@NotNull final Plugin plugin, @NotNull final String resourcePath, @NotNull final String fileName) {
- this(plugin, new File(plugin.getDataFolder().getAbsolutePath() + (resourcePath.startsWith(File.separator) ? resourcePath : File.separator + resourcePath), fileName.endsWith(".json") ? fileName : fileName + ".json"), resourcePath.isEmpty() ? fileName : resourcePath.endsWith(File.separator) ? resourcePath + fileName : resourcePath + File.separator + fileName);
- }
-
- public JSONFile(@NotNull final Plugin plugin, @NotNull final File file, @NotNull final String resourcePath) {
- super(plugin, file, resourcePath.endsWith(".json") ? resourcePath : resourcePath + ".json", true);
- }
-
- @Override
- public void reload() {
- fileConfiguration = HumanReadableJsonConfiguration.loadConfiguration(file);
- if (loadDefault) {
- try {
- JsonConfiguration defaultConfig = new HumanReadableJsonConfiguration();
- defaultConfig.load(new InputStreamReader(getInputStream(), StandardCharsets.UTF_8));
- fileConfiguration.setDefaults(defaultConfig);
- } catch (IOException | InvalidConfigurationException e) {
- plugin.getLogger().log(Level.SEVERE, "Could not load json file " + resourcePath, e);
- }
- }
- }
-}
+///*
+// * This file is a part of project QuickShop, the name is JSONFile.java
+// * Copyright (C) PotatoCraft Studio and contributors
+// *
+// * This program is free software: you can redistribute it and/or modify it
+// * under the terms of the GNU General Public License as published by the
+// * Free Software Foundation, either version 3 of the License, or
+// * (at your option) any later version.
+// *
+// * This program is distributed in the hope that it will be useful, but WITHOUT
+// * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// * for more details.
+// *
+// * You should have received a copy of the GNU General Public License
+// * along with this program. If not, see .
+// *
+// */
+//
+//package org.maxgamer.quickshop.fileportlek.old;
+//
+//import com.dumptruckman.bukkit.configuration.json.JsonConfiguration;
+//import org.bukkit.configuration.InvalidConfigurationException;
+//import org.bukkit.plugin.Plugin;
+//import org.jetbrains.annotations.NotNull;
+//
+//import java.io.File;
+//import java.io.IOException;
+//import java.io.InputStreamReader;
+//import java.nio.charset.StandardCharsets;
+//import java.util.logging.Level;
+//
+//public class JSONFile extends FileEnvelope {
+//
+// public JSONFile(@NotNull final Plugin plugin, @NotNull final File file, @NotNull final String resourcePath, boolean loadDefault) {
+// super(plugin, file, resourcePath.endsWith(".json") ? resourcePath : resourcePath + ".json", loadDefault);
+// }
+//
+// public JSONFile(@NotNull final Plugin plugin, @NotNull final String fileName) {
+// this(plugin, "", fileName);
+// }
+//
+// public JSONFile(@NotNull final Plugin plugin, @NotNull final String resourcePath, @NotNull final String fileName) {
+// this(plugin, new File(plugin.getDataFolder().getAbsolutePath() + (resourcePath.startsWith(File.separator) ? resourcePath : File.separator + resourcePath), fileName.endsWith(".json") ? fileName : fileName + ".json"), resourcePath.isEmpty() ? fileName : resourcePath.endsWith(File.separator) ? resourcePath + fileName : resourcePath + File.separator + fileName);
+// }
+//
+// public JSONFile(@NotNull final Plugin plugin, @NotNull final File file, @NotNull final String resourcePath) {
+// super(plugin, file, resourcePath.endsWith(".json") ? resourcePath : resourcePath + ".json", true);
+// }
+//
+// @Override
+// public void reload() {
+// fileConfiguration = HumanReadableJsonConfiguration.loadConfiguration(file);
+// if (loadDefault) {
+// try {
+// JsonConfiguration defaultConfig = new HumanReadableJsonConfiguration();
+// defaultConfig.load(new InputStreamReader(getInputStream(), StandardCharsets.UTF_8));
+// fileConfiguration.setDefaults(defaultConfig);
+// } catch (IOException | InvalidConfigurationException e) {
+// plugin.getLogger().log(Level.SEVERE, "Could not load json file " + resourcePath, e);
+// }
+// }
+// }
+//}
diff --git a/src/main/java/org/maxgamer/quickshop/fileportlek/old/YAMLFile.java b/src/main/java/org/maxgamer/quickshop/fileportlek/old/YAMLFile.java
index 37b76ff6c..30a1fe0f1 100644
--- a/src/main/java/org/maxgamer/quickshop/fileportlek/old/YAMLFile.java
+++ b/src/main/java/org/maxgamer/quickshop/fileportlek/old/YAMLFile.java
@@ -1,55 +1,55 @@
-/*
- * This file is a part of project QuickShop, the name is YAMLFile.java
- * Copyright (C) PotatoCraft Studio and contributors
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-
-package org.maxgamer.quickshop.fileportlek.old;
-
-import org.bukkit.configuration.file.YamlConfiguration;
-import org.bukkit.plugin.Plugin;
-import org.jetbrains.annotations.NotNull;
-
-import java.io.File;
-import java.io.InputStreamReader;
-
-public class YAMLFile extends FileEnvelope {
-
- public YAMLFile(@NotNull final Plugin plugin, @NotNull final File file, @NotNull final String resourcePath, boolean loadDefault) {
- super(plugin, file, resourcePath.endsWith(".yml") ? resourcePath : resourcePath + ".yml", loadDefault);
- }
-
- public YAMLFile(@NotNull final Plugin plugin, @NotNull final String fileName) {
- this(plugin, "", fileName);
- }
-
- public YAMLFile(@NotNull final Plugin plugin, @NotNull final String resourcePath, @NotNull final String fileName) {
- this(plugin, new File(plugin.getDataFolder().getAbsolutePath() + (resourcePath.startsWith(File.separator) ? resourcePath : File.separator + resourcePath), fileName.endsWith(".yml") ? fileName : fileName + ".yml"), resourcePath.isEmpty() ? fileName : resourcePath.endsWith(File.separator) ? resourcePath + fileName : resourcePath + File.separator + fileName);
- }
-
- public YAMLFile(@NotNull final Plugin plugin, @NotNull final File file, @NotNull final String resourcePath) {
- super(plugin, file, resourcePath.endsWith(".yml") ? resourcePath : resourcePath + ".yml", true);
- }
-
- @Override
- public void reload() {
- fileConfiguration = YamlConfiguration.loadConfiguration(file);
- if (loadDefault) {
- fileConfiguration.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(getInputStream())));
- }
- }
-
-}
+///*
+// * This file is a part of project QuickShop, the name is YAMLFile.java
+// * Copyright (C) PotatoCraft Studio and contributors
+// *
+// * This program is free software: you can redistribute it and/or modify it
+// * under the terms of the GNU General Public License as published by the
+// * Free Software Foundation, either version 3 of the License, or
+// * (at your option) any later version.
+// *
+// * This program is distributed in the hope that it will be useful, but WITHOUT
+// * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// * for more details.
+// *
+// * You should have received a copy of the GNU General Public License
+// * along with this program. If not, see .
+// *
+// */
+//
+//package org.maxgamer.quickshop.fileportlek.old;
+//
+//import org.bukkit.configuration.file.YamlConfiguration;
+//import org.bukkit.plugin.Plugin;
+//import org.jetbrains.annotations.NotNull;
+//
+//import java.io.File;
+//import java.io.InputStreamReader;
+//
+//public class YAMLFile extends FileEnvelope {
+//
+// public YAMLFile(@NotNull final Plugin plugin, @NotNull final File file, @NotNull final String resourcePath, boolean loadDefault) {
+// super(plugin, file, resourcePath.endsWith(".yml") ? resourcePath : resourcePath + ".yml", loadDefault);
+// }
+//
+// public YAMLFile(@NotNull final Plugin plugin, @NotNull final String fileName) {
+// this(plugin, "", fileName);
+// }
+//
+// public YAMLFile(@NotNull final Plugin plugin, @NotNull final String resourcePath, @NotNull final String fileName) {
+// this(plugin, new File(plugin.getDataFolder().getAbsolutePath() + (resourcePath.startsWith(File.separator) ? resourcePath : File.separator + resourcePath), fileName.endsWith(".yml") ? fileName : fileName + ".yml"), resourcePath.isEmpty() ? fileName : resourcePath.endsWith(File.separator) ? resourcePath + fileName : resourcePath + File.separator + fileName);
+// }
+//
+// public YAMLFile(@NotNull final Plugin plugin, @NotNull final File file, @NotNull final String resourcePath) {
+// super(plugin, file, resourcePath.endsWith(".yml") ? resourcePath : resourcePath + ".yml", true);
+// }
+//
+// @Override
+// public void reload() {
+// fileConfiguration = YamlConfiguration.loadConfiguration(file);
+// if (loadDefault) {
+// fileConfiguration.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(getInputStream())));
+// }
+// }
+//
+//}
diff --git a/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java b/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java
index a4b18451c..cf0eebc3a 100644
--- a/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java
+++ b/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java
@@ -19,6 +19,7 @@
package org.maxgamer.quickshop.util;
+import com.dumptruckman.bukkit.configuration.json.JsonConfiguration;
import com.google.common.collect.Maps;
import lombok.Getter;
import lombok.SneakyThrows;
@@ -45,8 +46,7 @@ import org.maxgamer.quickshop.QuickShop;
import org.maxgamer.quickshop.ServiceInjector;
import org.maxgamer.quickshop.database.WarpedResultSet;
import org.maxgamer.quickshop.event.ShopControlPanelOpenEvent;
-import org.maxgamer.quickshop.fileportlek.old.IFile;
-import org.maxgamer.quickshop.fileportlek.old.JSONFile;
+import org.maxgamer.quickshop.fileportlek.old.HumanReadableJsonConfiguration;
import org.maxgamer.quickshop.shop.Shop;
import org.maxgamer.quickshop.util.language.game.GameLanguage;
import org.maxgamer.quickshop.util.language.game.MojangGameLanguageImpl;
@@ -75,10 +75,10 @@ public class MsgUtil {
private static boolean inited;
@Getter
private static YamlConfiguration itemi18n;
- private static IFile messagei18n;
+ private static JsonConfiguration messagei18n;
@Getter
private static YamlConfiguration potioni18n;
- private static IFile builtInLang;
+ private static JsonConfiguration builtInLang;
private static DecimalFormat processFormat() {
try {
@@ -172,11 +172,11 @@ public class MsgUtil {
public static String getMessageOfflinePlayer(
@NotNull String loc, @Nullable OfflinePlayer player, @NotNull String... args) {
try {
- Optional raw = messagei18n.getString(loc);
- if (!raw.isPresent()) {
+ String raw = messagei18n.getString(loc);
+ if (raw == null) {
return invaildMsg + ": " + loc;
}
- String filled = fillArgs(raw.get(), args);
+ String filled = fillArgs(raw, args);
if (player != null) {
if (plugin.getConfig().getBoolean("plugin.PlaceHolderAPI") && plugin.getPlaceHolderAPI() != null && plugin.getPlaceHolderAPI().isEnabled()) {
filled = PlaceholderAPI.setPlaceholders(player, filled);
@@ -228,16 +228,21 @@ public class MsgUtil {
String languageCode = plugin.getConfig().getString("language", "en-US").replace("_", "-");
// Init message file instance
- IFile messageFile;
+ JsonConfiguration messageFile;
File extractedMessageFile = new File(plugin.getDataFolder(), "messages.json");
String buildInMessageFilePath = "lang/" + languageCode + "/messages.json";
if (plugin.getResource(buildInMessageFilePath) == null) {
//Use default
buildInMessageFilePath = "lang-original/messages.json";
}
- messageFile = new JSONFile(plugin, extractedMessageFile, buildInMessageFilePath, true);
- messageFile.create();
-
+ if (!extractedMessageFile.exists()) {
+ try {
+ Files.copy(Objects.requireNonNull(plugin.getResource(buildInMessageFilePath)), extractedMessageFile.toPath());
+ } catch (IOException ioException) {
+ plugin.getLogger().log(Level.WARNING, "Cannot extract the messages.json file", ioException);
+ }
+ }
+ messageFile = HumanReadableJsonConfiguration.loadConfiguration(extractedMessageFile);
//Handle old message file and load it up
File oldMsgFile = new File(plugin.getDataFolder(), "messages.yml");
if (oldMsgFile.exists()) {
@@ -248,7 +253,11 @@ public class MsgUtil {
for (String key : oldMsgI18n.getKeys(true)) {
messageFile.set(key, oldMsgI18n.get(key));
}
- messageFile.save();
+ try {
+ messageFile.save(extractedMessageFile);
+ } catch (IOException ioException) {
+ ioException.printStackTrace();
+ }
try {
Files.move(
oldMsgFile.toPath(), new File(plugin.getDataFolder(), "messages.yml.bak").toPath());
@@ -269,16 +278,20 @@ public class MsgUtil {
}
//Init global instance
+ File buildInLangFile = new File(Util.getCacheFolder(), "bulitin-messages.json");
messagei18n = messageFile;
- builtInLang = new JSONFile(plugin, buildInMessageFilePath);
-
-
+ try {
+ Files.copy(Objects.requireNonNull(plugin.getResource(buildInMessageFilePath)), buildInLangFile.toPath());
+ } catch (IOException ioException) {
+ ioException.printStackTrace();
+ }
+ builtInLang = HumanReadableJsonConfiguration.loadConfiguration(buildInLangFile);
//Check the i18n language name and backup
- if (!messagei18n.getString("language-name").isPresent()) {
+ if (StringUtils.isEmpty(messagei18n.getString("language-name"))) {
setAndUpdate("language-name");
}
- String messageCodeInFile = messagei18n.getString("language-name").get();
- if (!messageCodeInFile.equals(languageCode)) {
+ String messageCodeInFile = messagei18n.getString("language-name");
+ if (!Objects.equals(messageCodeInFile, languageCode)) {
String backupFileName = "messages-bak-" + UUID.randomUUID().toString() + ".json";
Util.debugLog("Language name " + messageCodeInFile + " not matched with " + languageCode + ", replacing with build-in files and renaming current file to " + backupFileName);
plugin.getLogger().warning("Language name " + messageCodeInFile + " not matched with " + languageCode + ", replacing with build-in files and renaming current file to " + backupFileName);
@@ -296,10 +309,10 @@ public class MsgUtil {
/* Set default language vesion and update messages.yml */
int ver = 0;
- Optional strVer = messagei18n.getString("language-version");
- if (strVer.isPresent()) {
+ String strVer = messagei18n.getString("language-version");
+ if (StringUtils.isNumeric(strVer)) {
try {
- ver = Integer.parseInt(strVer.get());
+ ver = Integer.parseInt(strVer);
} catch (NumberFormatException ignore) {
}
}
@@ -323,7 +336,11 @@ public class MsgUtil {
}
/* Save the upgraded messages.yml */
- messagei18n.save();
+ try {
+ messagei18n.save(extractedMessageFile);
+ } catch (IOException ioException) {
+ ioException.printStackTrace();
+ }
plugin.getLogger().info("Completed to load plugin translations files.");
}
@@ -708,13 +725,13 @@ public class MsgUtil {
public static String getMessage(
@NotNull String loc, @Nullable CommandSender player, @NotNull String... args) {
try {
- final Optional raw = messagei18n.getString(loc);
- if (!raw.isPresent()) {
+ final String raw = messagei18n.getString(loc);
+ if (raw == null) {
Util.debugLog("ERR: MsgUtil cannot find the the phrase at " + loc + ", printing the all readed datas: " + messagei18n);
return invaildMsg + ": " + loc;
}
- String filled = fillArgs(raw.get(), args);
+ String filled = fillArgs(raw, args);
if (player instanceof OfflinePlayer) {
if (plugin.getPlaceHolderAPI() != null && plugin.getPlaceHolderAPI().isEnabled() && plugin.getConfig().getBoolean("plugin.PlaceHolderAPI")) {
try {
@@ -972,7 +989,7 @@ public class MsgUtil {
return Util.prettifyText(potionString);
}
- public static IFile getI18nFile() {
+ public static JsonConfiguration getI18nFile() {
return messagei18n;
}
@@ -1451,7 +1468,7 @@ public class MsgUtil {
}
for (String msg : messages) {
try {
- if (msg == null || msg.isEmpty()) {
+ if (StringUtils.isEmpty(msg)) {
continue;
}
plugin.getQuickChat().send(sender, chatColor + msg);
From a69142d96be0fea1cd73b9066ca981079015db19 Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Thu, 8 Apr 2021 16:35:09 +0800
Subject: [PATCH 12/36] Fix build error
---
.../quickshop/shop/ArmorStandDisplayItem.java | 39 +++++++++----------
1 file changed, 19 insertions(+), 20 deletions(-)
diff --git a/src/main/java/org/maxgamer/quickshop/shop/ArmorStandDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/ArmorStandDisplayItem.java
index a2c68cc1f..e175aa0d8 100644
--- a/src/main/java/org/maxgamer/quickshop/shop/ArmorStandDisplayItem.java
+++ b/src/main/java/org/maxgamer/quickshop/shop/ArmorStandDisplayItem.java
@@ -1,23 +1,22 @@
-///*
-// * This file is a part of project QuickShop, the name is ArmorStandDisplayItem.java
-// * Copyright (C) PotatoCraft Studio and contributors
-// *
-// * This program is free software: you can redistribute it and/or modify it
-// * under the terms of the GNU General Public License as published by the
-// * Free Software Foundation, either version 3 of the License, or
-// * (at your option) any later version.
-// *
-// * This program is distributed in the hope that it will be useful, but WITHOUT
-// * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-// * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-// * for more details.
-// *
-// * You should have received a copy of the GNU General Public License
-// * along with this program. If not, see .
-// *
-// */
-//
-//package org.maxgamer.quickshop.shop;
+/*
+ * This file is a part of project QuickShop, the name is ArmorStandDisplayItem.java
+ * Copyright (C) PotatoCraft Studio and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+package org.maxgamer.quickshop.shop;
//
//import lombok.ToString;
//import org.bukkit.Location;
From 9619a2d426249893cbeb95b70328a6d75cc5d8d4 Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Thu, 8 Apr 2021 16:36:35 +0800
Subject: [PATCH 13/36] Fix build error
---
.../quickshop/shop/ArmorStandDisplayItem.java | 334 ------------------
1 file changed, 334 deletions(-)
delete mode 100644 src/main/java/org/maxgamer/quickshop/shop/ArmorStandDisplayItem.java
diff --git a/src/main/java/org/maxgamer/quickshop/shop/ArmorStandDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/ArmorStandDisplayItem.java
deleted file mode 100644
index e175aa0d8..000000000
--- a/src/main/java/org/maxgamer/quickshop/shop/ArmorStandDisplayItem.java
+++ /dev/null
@@ -1,334 +0,0 @@
-/*
- * This file is a part of project QuickShop, the name is ArmorStandDisplayItem.java
- * Copyright (C) PotatoCraft Studio and contributors
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-package org.maxgamer.quickshop.shop;
-//
-//import lombok.ToString;
-//import org.bukkit.Location;
-//import org.bukkit.Material;
-//import org.bukkit.NamespacedKey;
-//import org.bukkit.block.BlockFace;
-//import org.bukkit.block.data.Directional;
-//import org.bukkit.entity.ArmorStand;
-//import org.bukkit.entity.Entity;
-//import org.bukkit.entity.EntityType;
-//import org.bukkit.util.EulerAngle;
-//import org.jetbrains.annotations.NotNull;
-//import org.jetbrains.annotations.Nullable;
-//import org.maxgamer.quickshop.event.ShopDisplayItemDespawnEvent;
-//import org.maxgamer.quickshop.event.ShopDisplayItemSpawnEvent;
-//import org.maxgamer.quickshop.util.GameVersion;
-//import org.maxgamer.quickshop.util.MsgUtil;
-//import org.maxgamer.quickshop.util.ReflectFactory;
-//import org.maxgamer.quickshop.util.Util;
-//
-//import java.util.Objects;
-//
-//@ToString
-//@Deprecated
-//
-//public class ArmorStandDisplayItem extends DisplayItem {
-//
-// @Nullable
-// private volatile ArmorStand armorStand;
-//
-// /**
-// * @deprecated This display type pending for removal in future
-// */
-// ArmorStandDisplayItem(@NotNull Shop shop) {
-// super(shop);
-// }
-//
-// private static boolean isTool(Material material) {
-// String nlc = material.name().toLowerCase();
-// return nlc.contains("sword") || nlc.contains("shovel") || nlc.contains("axe"); //TODO: Needs a better impl. Maybe NamespacedKey
-// }
-//
-// @Override
-// public boolean checkDisplayIsMoved() {
-// if (this.armorStand == null) {
-// return false;
-// }
-// return !this.armorStand.getLocation().equals(getDisplayLocation());
-// }
-//
-// public Location getCenter(Location loc) {
-// // This is always '+' instead of '-' even in negative pos
-// return new Location(
-// loc.getWorld(), loc.getBlockX() + .5, loc.getBlockY() + .5, loc.getBlockZ() + .5);
-// }
-//
-// @Override
-// public boolean checkDisplayNeedRegen() {
-// if (this.armorStand == null) {
-// return false;
-// }
-// return !this.armorStand.isValid() || this.armorStand.isDead();
-// }
-//
-// @Override
-// public boolean checkIsShopEntity(@NotNull Entity entity) {
-// if (!(entity instanceof ArmorStand)) {
-// return false;
-// }
-// return DisplayItem.checkIsGuardItemStack(((ArmorStand) entity).getItemInHand()); //FIXME: Update this when drop 1.13 supports
-// }
-//
-// @Override
-// public void fixDisplayMoved() {
-// Location location = this.getDisplayLocation();
-// //if (this.armorStand != null) {
-// if (location != null) {
-// this.armorStand.teleport(location);
-// } else {
-// fixDisplayMovedOld();
-// }
-//// } else {
-//// fixDisplayMovedOld();
-//// }
-// }
-//
-// public void fixDisplayMovedOld() {
-// for (Entity entity : Objects.requireNonNull(this.shop.getLocation().getWorld()).getEntities()) {
-// if (!(entity instanceof ArmorStand)) {
-// continue;
-// }
-// ArmorStand eArmorStand = (ArmorStand) entity;
-// if (eArmorStand.getUniqueId().equals(Objects.requireNonNull(this.armorStand).getUniqueId())) {
-// Util.debugLog(
-// "Fixing moved ArmorStand displayItem "
-// + eArmorStand.getUniqueId()
-// + " at "
-// + eArmorStand.getLocation());
-// eArmorStand.teleport(getDisplayLocation());
-// return;
-// }
-// }
-// }
-//
-// @Override
-// public void fixDisplayNeedRegen() {
-// respawn();
-// }
-//
-// @Override
-// public void remove() {
-// if (this.armorStand == null) {
-// Util.debugLog("Ignore the armorStand removing because the armorStand not spawned.");
-// return;
-// }
-// this.armorStand.remove();
-// this.armorStand = null;
-// this.guardedIstack = null;
-// ShopDisplayItemDespawnEvent shopDisplayItemDespawnEvent =
-// new ShopDisplayItemDespawnEvent(this.shop, this.originalItemStack, DisplayType.ARMORSTAND);
-// plugin.getServer().getPluginManager().callEvent(shopDisplayItemDespawnEvent);
-// }
-//
-// @Override
-// public boolean removeDupe() {
-// if (this.armorStand == null) {
-// Util.debugLog("Warning: Trying to removeDupe for a null display shop.");
-// return false;
-// }
-// boolean removed = false;
-// for (Entity entity : armorStand.getNearbyEntities(1.5, 1.5, 1.5)) {
-// if (entity.getType() != EntityType.ARMOR_STAND) {
-// continue;
-// }
-// ArmorStand eArmorStand = (ArmorStand) entity;
-//
-// if (!eArmorStand.getUniqueId().equals(this.armorStand.getUniqueId()) && DisplayItem.checkIsTargetShopDisplay(eArmorStand.getItemInHand(), this.shop)) {//FIXME: Update this when drop 1.13 supports
-// Util.debugLog("Removing dupes ArmorEntity " + eArmorStand.getUniqueId() + " at " + eArmorStand.getLocation());
-// entity.remove();
-// removed = true;
-// }
-// }
-// return removed;
-// }
-//
-// @Override
-// public void respawn() {
-// remove();
-// spawn();
-// }
-//
-// @Override
-// public void safeGuard(@NotNull Entity entity) {
-// if (!(entity instanceof ArmorStand)) {
-// Util.debugLog(
-// "Failed to safeGuard " + entity.getLocation() + ", cause target not a ArmorStand");
-// return;
-// }
-// ArmorStand armorStand = (ArmorStand) entity;
-// // Set item protect in the armorstand's hand
-// this.guardedIstack = DisplayItem.createGuardItemStack(this.originalItemStack, this.shop);
-// Objects.requireNonNull(armorStand.getEquipment()).setHelmet(guardedIstack);
-// if (GameVersion.get(ReflectFactory.getServerVersion()).isPersistentStorageApiSupports()) {
-// armorStand
-// .getPersistentDataContainer()
-// .set(
-// new NamespacedKey(plugin, "displayMark"),
-// DisplayItemPersistentDataType.INSTANCE,
-// DisplayItem.createShopProtectionFlag(this.originalItemStack, shop));
-//
-// }
-// }
-//
-// @Override
-// public void spawn() {
-// if (shop.isDeleted() || !shop.isLoaded()) {
-// return;
-// }
-// if (shop.getLocation().getWorld() == null) {
-// Util.debugLog("Canceled the displayItem spawning because the location in the world is null.");
-// return;
-// }
-//
-// if (originalItemStack == null) {
-// Util.debugLog("Canceled the displayItem spawning because the ItemStack is null.");
-// return;
-// }
-//
-// if (armorStand != null && armorStand.isValid() && !armorStand.isDead()) {
-// Util.debugLog(
-// "Warning: Spawning the armorStand for DisplayItem when there is already an existing armorStand may cause a duplicated armorStand!");
-// MsgUtil.debugStackTrace(Thread.currentThread().getStackTrace());
-//
-// ShopDisplayItemSpawnEvent shopDisplayItemSpawnEvent =
-// new ShopDisplayItemSpawnEvent(shop, originalItemStack, DisplayType.ARMORSTAND);
-// plugin.getServer().getPluginManager().callEvent(shopDisplayItemSpawnEvent);
-// if (shopDisplayItemSpawnEvent.isCancelled()) {
-// Util.debugLog(
-// "Canceled the displayItem from spawning because a plugin setCancelled the spawning event, usually it is a QuickShop Add on");
-// return;
-// }
-//
-// Location location = getDisplayLocation();
-// this.armorStand =
-// this.shop
-// .getLocation()
-// .getWorld()
-// .spawn(
-// location,
-// ArmorStand.class,
-// armorStand -> {
-// // Set basic armorstand datas.
-// armorStand.setGravity(false);
-// armorStand.setVisible(false);
-// armorStand.setMarker(true);
-// armorStand.setCollidable(false);
-// armorStand.setSmall(true);
-// armorStand.setArms(false);
-// armorStand.setBasePlate(false);
-// armorStand.setSilent(true);
-// armorStand.setAI(false);
-// armorStand.setCanPickupItems(false);
-// // Set pose (this is for hand while we use helmet)
-// // setPoseForArmorStand();
-// });
-// // Set safeGuard
-// Util.debugLog(
-// "Spawned armor stand @ "
-// + this.armorStand.getLocation()
-// + " with UUID "
-// + this.armorStand.getUniqueId());
-// safeGuard(this.armorStand); // Helmet must be set after spawning
-// }
-// }
-//
-// @Override
-// public @Nullable Entity getDisplay() {
-// return this.armorStand;
-// }
-//
-// @Override
-// public Location getDisplayLocation() {
-// BlockFace containerBlockFace = BlockFace.NORTH; // Set default vaule
-// if (this.shop.getLocation().getBlock().getBlockData() instanceof Directional) {
-// containerBlockFace =
-// ((Directional) this.shop.getLocation().getBlock().getBlockData())
-// .getFacing(); // Replace by container face.
-// }
-// // Fix specific block facing
-// Material type = this.shop.getLocation().getBlock().getType();
-// if (type.name().contains("ANVIL")
-// || type.name().contains("FENCE")
-// || type.name().contains("WALL")) {
-// switch (containerBlockFace) {
-// case SOUTH:
-// containerBlockFace = BlockFace.WEST;
-// break;
-// case NORTH:
-// containerBlockFace = BlockFace.EAST;
-// case EAST:
-// containerBlockFace = BlockFace.NORTH;
-// case WEST:
-// containerBlockFace = BlockFace.SOUTH;
-// default:
-// break;
-// }
-// }
-//
-// Location asloc = getCenter(this.shop.getLocation());
-// Util.debugLog("containerBlockFace " + containerBlockFace);
-// if (this.originalItemStack.getType().isBlock()) {
-// asloc.add(0, 0.5, 0);
-// }
-// switch (containerBlockFace) {
-// case SOUTH:
-// asloc.add(0, -0.5, 0);
-// asloc.setYaw(0);
-// Util.debugLog("Block face as SOUTH");
-// break;
-// case WEST:
-// asloc.add(0, -0.5, 0);
-// asloc.setYaw(90);
-// Util.debugLog("Block face as WEST");
-// break;
-// case EAST:
-// asloc.add(0, -0.5, 0);
-// asloc.setYaw(-90);
-// Util.debugLog("Block face as EAST");
-// break;
-// case NORTH:
-// asloc.add(0, -0.5, 0);
-// asloc.setYaw(180);
-// Util.debugLog("Block face as NORTH");
-// break;
-// default:
-// break;
-// }
-// return asloc;
-// }
-//
-// @Override
-// public synchronized boolean isSpawned() {
-// return this.armorStand != null && this.armorStand.isValid();
-// }
-//
-// @Deprecated // no use, will be removed soon
-// private void setPoseForArmorStand() {
-// if (this.originalItemStack.getType().isBlock()) {
-// Objects.requireNonNull(armorStand).setRightArmPose(new EulerAngle(-0.2, 0, 0));
-// } else {
-// Objects.requireNonNull(armorStand).setRightArmPose(new EulerAngle(-89.5, 0, 0));
-// }
-// }
-//
-//}
From 1167c4632b4a532df85dfdb855f167aaac33bc4d Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Thu, 8 Apr 2021 16:42:13 +0800
Subject: [PATCH 14/36] Fix build error
---
.../org/maxgamer/quickshop/QuickShop.java | 2 +-
.../listener/DisplayBugFixListener.java | 63 ---------------
.../listener/DisplayProtectionListener.java | 30 ++++---
.../EnhanceDisplayProtectionListener.java | 78 +++++++++----------
.../quickshop/shop/ContainerShop.java | 12 +--
5 files changed, 58 insertions(+), 127 deletions(-)
delete mode 100644 src/main/java/org/maxgamer/quickshop/listener/DisplayBugFixListener.java
diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java
index c862c1d4f..73304111a 100644
--- a/src/main/java/org/maxgamer/quickshop/QuickShop.java
+++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java
@@ -808,7 +808,7 @@ public class QuickShop extends JavaPlugin {
Bukkit.getPluginManager().registerEvents(internalListener, this);
if (isDisplay() && DisplayItem.getNowUsing() != DisplayType.VIRTUALITEM) {
displayWatcher = new DisplayWatcher(this);
- new DisplayBugFixListener(this).register();
+// new DisplayBugFixListener(this).register();
new DisplayProtectionListener(this, this.shopCache).register();
if (Bukkit.getPluginManager().getPlugin("ClearLag") != null) {
new ClearLaggListener(this).register();
diff --git a/src/main/java/org/maxgamer/quickshop/listener/DisplayBugFixListener.java b/src/main/java/org/maxgamer/quickshop/listener/DisplayBugFixListener.java
deleted file mode 100644
index 1172ff918..000000000
--- a/src/main/java/org/maxgamer/quickshop/listener/DisplayBugFixListener.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * This file is a part of project QuickShop, the name is DisplayBugFixListener.java
- * Copyright (C) PotatoCraft Studio and contributors
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-
-package org.maxgamer.quickshop.listener;
-
-import org.bukkit.entity.ArmorStand;
-import org.bukkit.entity.Entity;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.block.BlockCanBuildEvent;
-import org.maxgamer.quickshop.QuickShop;
-import org.maxgamer.quickshop.shop.DisplayItem;
-import org.maxgamer.quickshop.shop.DisplayType;
-import org.maxgamer.quickshop.util.Util;
-
-import java.util.Collection;
-
-
-public class DisplayBugFixListener extends QSListener {
- public DisplayBugFixListener(QuickShop plugin) {
- super(plugin);
- }
-
- @EventHandler(ignoreCancelled = true)
- public void canBuild(BlockCanBuildEvent e) {
- if (!plugin.isDisplay()
- || DisplayItem.getNowUsing() != DisplayType.ARMORSTAND
- || e.isBuildable()) {
- return;
- }
-
- final Collection entities =
- e.getBlock().getWorld().getNearbyEntities(e.getBlock().getLocation(), 1.0, 1, 1.0);
-
- for (final Entity entity : entities) {
- if (!(entity instanceof ArmorStand)
- || !DisplayItem.checkIsGuardItemStack(((ArmorStand) entity).getItemInHand())) { //FIXME: Update this when drop 1.13 supports
- continue;
- }
-
- e.setBuildable(true);
- Util.debugLog(
- "Re-set the allowed build flag here because it found the cause of the display-item blocking it before.");
- return;
- }
- }
-
-}
diff --git a/src/main/java/org/maxgamer/quickshop/listener/DisplayProtectionListener.java b/src/main/java/org/maxgamer/quickshop/listener/DisplayProtectionListener.java
index ec4fd64c2..955fec10b 100644
--- a/src/main/java/org/maxgamer/quickshop/listener/DisplayProtectionListener.java
+++ b/src/main/java/org/maxgamer/quickshop/listener/DisplayProtectionListener.java
@@ -20,12 +20,10 @@
package org.maxgamer.quickshop.listener;
import org.bukkit.Location;
-import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
-import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityPortalEvent;
import org.bukkit.event.entity.ItemDespawnEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
@@ -81,20 +79,20 @@ public class DisplayProtectionListener extends ProtectionListenerBase {
+ " , QuickShop already cancel it.");
}
}
-
- @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
- public void entity(EntityDamageEvent event) {
- if (!(event.getEntity() instanceof ArmorStand)) {
- return;
- }
- if (DisplayItem.getNowUsing() != DisplayType.ARMORSTAND) {
- return;
- }
- if (!DisplayItem.checkIsGuardItemStack(((ArmorStand) event.getEntity()).getItemInHand())) { //FIXME: Update this when drop 1.13 supports
- return;
- }
- event.setCancelled(true);
- }
+//
+// @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
+// public void entity(EntityDamageEvent event) {
+// if (!(event.getEntity() instanceof ArmorStand)) {
+// return;
+// }
+// if (DisplayItem.getNowUsing() != DisplayType.ARMORSTAND) {
+// return;
+// }
+// if (!DisplayItem.checkIsGuardItemStack(((ArmorStand) event.getEntity()).getItemInHand())) { //FIXME: Update this when drop 1.13 supports
+// return;
+// }
+// event.setCancelled(true);
+// }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
diff --git a/src/main/java/org/maxgamer/quickshop/listener/EnhanceDisplayProtectionListener.java b/src/main/java/org/maxgamer/quickshop/listener/EnhanceDisplayProtectionListener.java
index 6e22c509e..6f02fa1cd 100644
--- a/src/main/java/org/maxgamer/quickshop/listener/EnhanceDisplayProtectionListener.java
+++ b/src/main/java/org/maxgamer/quickshop/listener/EnhanceDisplayProtectionListener.java
@@ -25,7 +25,6 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.Furnace;
-import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
@@ -34,8 +33,6 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
-import org.bukkit.event.entity.EntityDeathEvent;
-import org.bukkit.event.entity.EntityInteractEvent;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.inventory.*;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
@@ -46,7 +43,6 @@ import org.jetbrains.annotations.NotNull;
import org.maxgamer.quickshop.Cache;
import org.maxgamer.quickshop.QuickShop;
import org.maxgamer.quickshop.shop.DisplayItem;
-import org.maxgamer.quickshop.shop.DisplayType;
import org.maxgamer.quickshop.shop.Shop;
import org.maxgamer.quickshop.util.MsgUtil;
import org.maxgamer.quickshop.util.Util;
@@ -251,44 +247,44 @@ public class EnhanceDisplayProtectionListener extends ProtectionListenerBase imp
}
}
- @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
- public void entity(EntityDeathEvent event) {
- if (DisplayItem.getNowUsing() != DisplayType.ARMORSTAND) {
- return;
- }
- if (!(event.getEntity() instanceof ArmorStand)) {
- return;
- }
- if (!DisplayItem.checkIsGuardItemStack(((ArmorStand) event.getEntity()).getItemInHand())) { //FIXME: Update this when drop 1.13 supports
- return;
- }
- event.setDroppedExp(0);
- event.getDrops().clear();
- }
+// @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
+// public void entity(EntityDeathEvent event) {
+// if (DisplayItem.getNowUsing() != DisplayType.ARMORSTAND) {
+// return;
+// }
+// if (!(event.getEntity() instanceof ArmorStand)) {
+// return;
+// }
+// if (!DisplayItem.checkIsGuardItemStack(((ArmorStand) event.getEntity()).getItemInHand())) { //FIXME: Update this when drop 1.13 supports
+// return;
+// }
+// event.setDroppedExp(0);
+// event.getDrops().clear();
+// }
- @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
- public void entity(EntityInteractEvent event) {
- if (DisplayItem.getNowUsing() != DisplayType.ARMORSTAND) {
- return;
- }
- if (!(event.getEntity() instanceof ArmorStand)) {
- return;
- }
- if (!DisplayItem.checkIsGuardItemStack(((ArmorStand) event.getEntity()).getItemInHand())) { //FIXME: Update this when drop 1.13 supports
- return;
- }
- event.setCancelled(true);
- final Entity entity = event.getEntity();
- if (entity instanceof InventoryHolder) {
- Util.inventoryCheck(((InventoryHolder) entity).getInventory());
- }
- sendAlert(
- "[DisplayGuard] Entity "
- + event.getEntityType().name()
- + " # "
- + event.getEntity().getLocation()
- + " trying interact the hold displayItem's entity.");
- }
+// @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
+// public void entity(EntityInteractEvent event) {
+// if (DisplayItem.getNowUsing() != DisplayType.ARMORSTAND) {
+// return;
+// }
+// if (!(event.getEntity() instanceof ArmorStand)) {
+// return;
+// }
+// if (!DisplayItem.checkIsGuardItemStack(((ArmorStand) event.getEntity()).getItemInHand())) { //FIXME: Update this when drop 1.13 supports
+// return;
+// }
+// event.setCancelled(true);
+// final Entity entity = event.getEntity();
+// if (entity instanceof InventoryHolder) {
+// Util.inventoryCheck(((InventoryHolder) entity).getInventory());
+// }
+// sendAlert(
+// "[DisplayGuard] Entity "
+// + event.getEntityType().name()
+// + " # "
+// + event.getEntity().getLocation()
+// + " trying interact the hold displayItem's entity.");
+// }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void inventory(InventoryClickEvent event) {
diff --git a/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java b/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java
index ef7b78e12..4bbce7d17 100644
--- a/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java
+++ b/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java
@@ -178,21 +178,21 @@ public class ContainerShop implements Shop {
switch (DisplayItem.getNowUsing()) {
case UNKNOWN:
Util.debugLog(
- "Failed to create a ContainerShop displayItem, the type is unknown, fallback to RealDisplayItem");
+ "Failed to create a ContainerShop displayItem, the type is unknown, fallback to RealDisplayItem");
this.displayItem = new RealDisplayItem(this);
break;
case REALITEM:
this.displayItem = new RealDisplayItem(this);
break;
- case ARMORSTAND:
- this.displayItem = new ArmorStandDisplayItem(this);
- break;
+// case ARMORSTAND:
+// this.displayItem = new ArmorStandDisplayItem(this);
+// break;
case VIRTUALITEM:
try {
if (!GameVersion.get(ReflectFactory.getServerVersion())
- .isVirtualDisplaySupports()) {
+ .isVirtualDisplaySupports()) {
throw new IllegalStateException(
- "Version not supports Virtual DisplayItem.");
+ "Version not supports Virtual DisplayItem.");
}
this.displayItem = new VirtualDisplayItem(this);
From 1025fa4d5a8f012a0158a31e3e70da3a1aacd3dd Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Thu, 8 Apr 2021 16:46:34 +0800
Subject: [PATCH 15/36] Fix javadoc in ShopTaxEvent
---
src/main/java/org/maxgamer/quickshop/event/ShopTaxEvent.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/org/maxgamer/quickshop/event/ShopTaxEvent.java b/src/main/java/org/maxgamer/quickshop/event/ShopTaxEvent.java
index a086d1282..d90dade15 100644
--- a/src/main/java/org/maxgamer/quickshop/event/ShopTaxEvent.java
+++ b/src/main/java/org/maxgamer/quickshop/event/ShopTaxEvent.java
@@ -75,7 +75,7 @@ public class ShopTaxEvent extends QSEvent {
/**
* Sets the new tax in purchase
*
- * @return new tax
+ * @param tax New tax
*/
public void setTax(double tax) {
this.tax = tax;
From cd304e128dd0af7bd7677a77fdfc1eb240324544 Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Thu, 8 Apr 2021 16:51:34 +0800
Subject: [PATCH 16/36] Remove Adventure flag
---
.../org/maxgamer/quickshop/QuickShop.java | 8 +++----
src/main/resources/config.yml | 22 ++++++++++++++++---
2 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java
index 73304111a..a5ea72acb 100644
--- a/src/main/java/org/maxgamer/quickshop/QuickShop.java
+++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java
@@ -524,10 +524,10 @@ public class QuickShop extends JavaPlugin {
//noinspection ResultOfMethodCallIgnored
getDataFolder().mkdirs();
// replaceLogger();
- if (getConfig().getBoolean("debug.adventure", false)) {
- System.setProperty("net.kyori.adventure.debug", "true");
- getLogger().warning("Adventure debug flag was set! You can disable this anytime in config by set `debug.adventure` to false.");
- }
+// if (getConfig().getBoolean("debug.adventure", false)) {
+// System.setProperty("net.kyori.adventure.debug", "true");
+// getLogger().warning("Adventure debug flag was set! You can disable this anytime in config by set `debug.adventure` to false.");
+// }
this.bootError = null;
getLogger().info("Loading up integration modules.");
this.integrationHelper = new IntegrationHelper(this);
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index faacfa666..114c9f8a3 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -1,7 +1,25 @@
#This is example config, don't direct modify this file, all changes will revert when you reload the plugin.
#This is example config, don't direct modify this file, all changes will revert when you reload the plugin.
#This is example config, don't direct modify this file, all changes will revert when you reload the plugin.
-
+#This is example config, don't direct modify this file, all changes will revert when you reload the plugin.
+#This is example config, don't direct modify this file, all changes will revert when you reload the plugin.
+#This is example config, don't direct modify this file, all changes will revert when you reload the plugin.
+#This is example config, don't direct modify this file, all changes will revert when you reload the plugin.
+#This is example config, don't direct modify this file, all changes will revert when you reload the plugin.
+#This is example config, don't direct modify this file, all changes will revert when you reload the plugin.
+#This is example config, don't direct modify this file, all changes will revert when you reload the plugin.
+#This is example config, don't direct modify this file, all changes will revert when you reload the plugin.
+#This is example config, don't direct modify this file, all changes will revert when you reload the plugin.
+#This is example config, don't direct modify this file, all changes will revert when you reload the plugin.
+#This is example config, don't direct modify this file, all changes will revert when you reload the plugin.
+#This is example config, don't direct modify this file, all changes will revert when you reload the plugin.
+#This is example config, don't direct modify this file, all changes will revert when you reload the plugin.
+#This is example config, don't direct modify this file, all changes will revert when you reload the plugin.
+#This is example config, don't direct modify this file, all changes will revert when you reload the plugin.
+#This is example config, don't direct modify this file, all changes will revert when you reload the plugin.
+#This is example config, don't direct modify this file, all changes will revert when you reload the plugin.
+# READ ABOVE READ ABOVE READ ABOVE READ ABOVE READ ABOVE READ ABOVE READ ABOVE READ ABOVE READ ABOVE READ ABOVE
+# IF YOU WANT EDIT CONFIGURATION, THE FILE "config.yml" IS THE CORRECT FILE
#Do not touch if you not clear know about this
config-version: 126
@@ -688,8 +706,6 @@ debug:
disable-debuglogger: false
#logging stacktrace when deleting shop
shop-deletion: false
- #Enable adventure debug flag
- adventure: false
From c914911449d880bb7ed14d6c41665f34c287f85e Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Thu, 8 Apr 2021 17:11:19 +0800
Subject: [PATCH 17/36] Start async handler correctly
---
.../maxgamer/quickshop/shop/VirtualDisplayItem.java | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
index e5e192804..249e20b55 100644
--- a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
+++ b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
@@ -21,6 +21,7 @@ package org.maxgamer.quickshop.shop;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
+import com.comphenix.protocol.async.AsyncListenerHandler;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
@@ -85,6 +86,8 @@ public class VirtualDisplayItem extends DisplayItem {
@Nullable
private BukkitTask asyncSendingTask;
+ private AsyncListenerHandler handler;
+
public VirtualDisplayItem(@NotNull Shop shop) throws RuntimeException {
super(shop);
@@ -249,7 +252,9 @@ public class VirtualDisplayItem extends DisplayItem {
private void unload() {
packetSenders.clear();
if (packetAdapter != null) {
- protocolManager.getAsynchronousManager().unregisterAsyncHandler(packetAdapter);
+ handler.stop();
+ protocolManager.getAsynchronousManager().unregisterAsyncHandler(handler);
+ //protocolManager.getAsynchronousManager().unregisterAsyncHandler(packetAdapter);
}
if (asyncSendingTask != null && !asyncSendingTask.isCancelled()) {
asyncSendingTask.cancel();
@@ -383,7 +388,8 @@ public class VirtualDisplayItem extends DisplayItem {
}
};
}
- protocolManager.getAsynchronousManager().registerAsyncHandler(packetAdapter); //TODO: This may affects performance
+ AsyncListenerHandler handler = protocolManager.getAsynchronousManager().registerAsyncHandler(packetAdapter); //TODO: This may affects performance
+ handler.start();
asyncSendingTask = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, () -> {
Runnable runnable = asyncPacketSendQueue.poll();
while (runnable != null) {
From 94bbc787255f00456d1c1284e902869f988c11e9 Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Thu, 8 Apr 2021 17:11:38 +0800
Subject: [PATCH 18/36] Fix file not exist exception
---
src/main/java/org/maxgamer/quickshop/util/MsgUtil.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java b/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java
index cf0eebc3a..4c97dae4c 100644
--- a/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java
+++ b/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java
@@ -281,9 +281,12 @@ public class MsgUtil {
File buildInLangFile = new File(Util.getCacheFolder(), "bulitin-messages.json");
messagei18n = messageFile;
try {
+ if (buildInLangFile.exists()) {
+ buildInLangFile.delete();
+ }
Files.copy(Objects.requireNonNull(plugin.getResource(buildInMessageFilePath)), buildInLangFile.toPath());
} catch (IOException ioException) {
- ioException.printStackTrace();
+ Util.debugLog("Cannow load default built-in language file: " + ioException.getMessage());
}
builtInLang = HumanReadableJsonConfiguration.loadConfiguration(buildInLangFile);
//Check the i18n language name and backup
From b5c81da37132115e1ff1d375cbb3a8ce3b28dc98 Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Thu, 8 Apr 2021 17:11:53 +0800
Subject: [PATCH 19/36] fix typo
---
src/main/java/org/maxgamer/quickshop/util/MsgUtil.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java b/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java
index 4c97dae4c..d83a0a31c 100644
--- a/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java
+++ b/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java
@@ -286,7 +286,7 @@ public class MsgUtil {
}
Files.copy(Objects.requireNonNull(plugin.getResource(buildInMessageFilePath)), buildInLangFile.toPath());
} catch (IOException ioException) {
- Util.debugLog("Cannow load default built-in language file: " + ioException.getMessage());
+ Util.debugLog("Cannot load default built-in language file: " + ioException.getMessage());
}
builtInLang = HumanReadableJsonConfiguration.loadConfiguration(buildInLangFile);
//Check the i18n language name and backup
From 532200cb15e7d10a2882283c362f3f6cbf03c0bd Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Thu, 8 Apr 2021 17:14:52 +0800
Subject: [PATCH 20/36] Fix wrong args passed into ProtocolLib
---
.../maxgamer/quickshop/shop/VirtualDisplayItem.java | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
index 249e20b55..70549c590 100644
--- a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
+++ b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
@@ -86,7 +86,7 @@ public class VirtualDisplayItem extends DisplayItem {
@Nullable
private BukkitTask asyncSendingTask;
- private AsyncListenerHandler handler;
+ private AsyncListenerHandler asyncHandler;
public VirtualDisplayItem(@NotNull Shop shop) throws RuntimeException {
@@ -252,8 +252,8 @@ public class VirtualDisplayItem extends DisplayItem {
private void unload() {
packetSenders.clear();
if (packetAdapter != null) {
- handler.stop();
- protocolManager.getAsynchronousManager().unregisterAsyncHandler(handler);
+ asyncHandler.stop();
+ protocolManager.getAsynchronousManager().unregisterAsyncHandler(asyncHandler);
//protocolManager.getAsynchronousManager().unregisterAsyncHandler(packetAdapter);
}
if (asyncSendingTask != null && !asyncSendingTask.isCancelled()) {
@@ -388,8 +388,8 @@ public class VirtualDisplayItem extends DisplayItem {
}
};
}
- AsyncListenerHandler handler = protocolManager.getAsynchronousManager().registerAsyncHandler(packetAdapter); //TODO: This may affects performance
- handler.start();
+ asyncHandler = protocolManager.getAsynchronousManager().registerAsyncHandler(packetAdapter); //TODO: This may affects performance
+ asyncHandler.start();
asyncSendingTask = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, () -> {
Runnable runnable = asyncPacketSendQueue.poll();
while (runnable != null) {
From a70589d5ce112a9309359385f0ce47aaea93ec74 Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Thu, 8 Apr 2021 17:20:11 +0800
Subject: [PATCH 21/36] Optimize logic about sending VDI to players
---
.../quickshop/shop/VirtualDisplayItem.java | 71 +++++++++----------
1 file changed, 35 insertions(+), 36 deletions(-)
diff --git a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
index 70549c590..3427de27c 100644
--- a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
+++ b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
@@ -43,7 +43,6 @@ import org.maxgamer.quickshop.util.Util;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
-import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicInteger;
@@ -64,7 +63,7 @@ public class VirtualDisplayItem extends DisplayItem {
//The List which store packet sender
private final Set packetSenders = new ConcurrentSkipListSet<>();
- private final Queue asyncPacketSendQueue = new ConcurrentLinkedQueue<>();
+ // private final Queue asyncPacketSendQueue = new ConcurrentLinkedQueue<>();
private volatile boolean isDisplay;
@@ -335,6 +334,10 @@ public class VirtualDisplayItem extends DisplayItem {
}
}
}
+
+ asyncHandler = protocolManager.getAsynchronousManager().registerAsyncHandler(packetAdapter); //TODO: This may affects performance
+ asyncHandler.start();
+
if (packetAdapter == null) {
packetAdapter = new PacketAdapter(plugin, ListenerPriority.HIGH, PacketType.Play.Server.MAP_CHUNK) {
@Override
@@ -348,32 +351,29 @@ public class VirtualDisplayItem extends DisplayItem {
int x = event.getPacket().getIntegers().read(0);
//chunk z
int z = event.getPacket().getIntegers().read(1);
- asyncPacketSendQueue.offer(() -> {
- //lazy initialize
- if (chunkLocation == null) {
- World world = shop.getLocation().getWorld();
- Chunk chunk = null;
- try {
- //sync getting chunk
- chunk = plugin.getServer().getScheduler().callSyncMethod(plugin, () -> shop.getLocation().getChunk()).get();
- } catch (InterruptedException | ExecutionException e) {
- throw new RuntimeException("An error occurred when getting chunk from the world", e);
- }
- chunkLocation = new ShopChunk(world.getName(), chunk.getX(), chunk.getZ());
+
+ if (chunkLocation == null) {
+ World world = shop.getLocation().getWorld();
+ Chunk chunk;
+ try {
+ //sync getting chunk
+ chunk = plugin.getServer().getScheduler().callSyncMethod(plugin, () -> shop.getLocation().getChunk()).get();
+ } catch (InterruptedException | ExecutionException e) {
+ throw new RuntimeException("An error occurred when getting chunk from the world", e);
}
- Player player = event.getPlayer();
- if (player instanceof TemporaryPlayer) {
- return;
- }
- if (player == null || !player.isOnline()) {
- Util.debugLog("Cancelled packet sending cause player logged out when sending packets.");
- return;
- }
- if (chunkLocation.isSame(player.getWorld().getName(), x, z)) {
- packetSenders.add(player.getUniqueId());
- sendFakeItem(player);
- }
- });
+ chunkLocation = new ShopChunk(world.getName(), chunk.getX(), chunk.getZ());
+ }
+ Player player = event.getPlayer();
+ if (player instanceof TemporaryPlayer) {
+ return;
+ }
+ if (player == null || !player.isOnline()) {
+ return;
+ }
+ if (chunkLocation.isSame(player.getWorld().getName(), x, z)) {
+ packetSenders.add(player.getUniqueId());
+ sendFakeItem(player);
+ }
// Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {
// if (chunkLocation == null) {
// World world = shop.getLocation().getWorld();
@@ -388,15 +388,14 @@ public class VirtualDisplayItem extends DisplayItem {
}
};
}
- asyncHandler = protocolManager.getAsynchronousManager().registerAsyncHandler(packetAdapter); //TODO: This may affects performance
- asyncHandler.start();
- asyncSendingTask = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, () -> {
- Runnable runnable = asyncPacketSendQueue.poll();
- while (runnable != null) {
- runnable.run();
- runnable = asyncPacketSendQueue.poll();
- }
- }, 0, 1);
+
+// asyncSendingTask = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, () -> {
+// Runnable runnable = asyncPacketSendQueue.poll();
+// while (runnable != null) {
+// runnable.run();
+// runnable = asyncPacketSendQueue.poll();
+// }
+// }, 0, 1);
}
public void sendFakeItem(@NotNull Player player) {
From 1d5b65cb31ec8b4c229a86d20374f223b2b2eda5 Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Thu, 8 Apr 2021 17:21:35 +0800
Subject: [PATCH 22/36] Optimize VDI CPU time cost
---
.../org/maxgamer/quickshop/shop/VirtualDisplayItem.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
index 3427de27c..87b356bd8 100644
--- a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
+++ b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
@@ -27,6 +27,7 @@ import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.server.TemporaryPlayer;
+import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import org.bukkit.Chunk;
@@ -344,13 +345,14 @@ public class VirtualDisplayItem extends DisplayItem {
public void onPacketSending(@NotNull PacketEvent event) {
//is really full chunk data
boolean isFull = event.getPacket().getBooleans().read(0);
- if (!shop.isLoaded() || !isDisplay || !isFull || !Util.isLoaded(shop.getLocation()) || shop.isLeftShop()) {
+ if (!shop.isLoaded() || !isDisplay || !isFull || shop.isLeftShop()) {
return;
}
+ StructureModifier integerStructureModifier = event.getPacket().getIntegers();
//chunk x
- int x = event.getPacket().getIntegers().read(0);
+ int x = integerStructureModifier.read(0);
//chunk z
- int z = event.getPacket().getIntegers().read(1);
+ int z = integerStructureModifier.read(1);
if (chunkLocation == null) {
World world = shop.getLocation().getWorld();
From 10ad07c45206c75da75db37c8e9e0d66d7d072d2 Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Thu, 8 Apr 2021 17:22:41 +0800
Subject: [PATCH 23/36] Optimize VDI CPU time cost
---
.../org/maxgamer/quickshop/shop/VirtualDisplayItem.java | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
index 87b356bd8..d1f6a2e80 100644
--- a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
+++ b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
@@ -124,9 +124,10 @@ public class VirtualDisplayItem extends DisplayItem {
switch (version) {
case "v1_13_R1":
case "v1_13_R2":
- fakeItemPacket.getIntegers().write(6, 2);
- //int data to mark
- fakeItemPacket.getIntegers().write(7, 1);
+ fakeItemPacket.getIntegers()
+ .write(6, 2)
+ //int data to mark
+ .write(7, 1);
break;
//int data to mark
default:
From d2f59c9d621e226e3a2fb96f32ceb2e1693af9bb Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Thu, 8 Apr 2021 17:30:02 +0800
Subject: [PATCH 24/36] Fix listener not be null exception
---
.../org/maxgamer/quickshop/shop/VirtualDisplayItem.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
index d1f6a2e80..052b43f2f 100644
--- a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
+++ b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
@@ -337,8 +337,7 @@ public class VirtualDisplayItem extends DisplayItem {
}
}
- asyncHandler = protocolManager.getAsynchronousManager().registerAsyncHandler(packetAdapter); //TODO: This may affects performance
- asyncHandler.start();
+
if (packetAdapter == null) {
packetAdapter = new PacketAdapter(plugin, ListenerPriority.HIGH, PacketType.Play.Server.MAP_CHUNK) {
@@ -391,7 +390,8 @@ public class VirtualDisplayItem extends DisplayItem {
}
};
}
-
+ asyncHandler = protocolManager.getAsynchronousManager().registerAsyncHandler(packetAdapter); //TODO: This may affects performance
+ asyncHandler.start();
// asyncSendingTask = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, () -> {
// Runnable runnable = asyncPacketSendQueue.poll();
// while (runnable != null) {
From 32509c8f896f28c9b0edae82b3aeb1707986c75c Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Thu, 8 Apr 2021 17:36:40 +0800
Subject: [PATCH 25/36] unregister before stop
---
.../quickshop/shop/VirtualDisplayItem.java | 25 +++++++++++--------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
index 052b43f2f..d0bf75899 100644
--- a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
+++ b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
@@ -250,17 +250,6 @@ public class VirtualDisplayItem extends DisplayItem {
}
}
- private void unload() {
- packetSenders.clear();
- if (packetAdapter != null) {
- asyncHandler.stop();
- protocolManager.getAsynchronousManager().unregisterAsyncHandler(asyncHandler);
- //protocolManager.getAsynchronousManager().unregisterAsyncHandler(packetAdapter);
- }
- if (asyncSendingTask != null && !asyncSendingTask.isCancelled()) {
- asyncSendingTask.cancel();
- }
- }
private void sendPacket(@NotNull Player player, @NotNull PacketContainer packet) {
try {
@@ -401,6 +390,20 @@ public class VirtualDisplayItem extends DisplayItem {
// }, 0, 1);
}
+ private void unload() {
+ packetSenders.clear();
+ if (packetAdapter != null) {
+ protocolManager.getAsynchronousManager().unregisterAsyncHandler(asyncHandler);
+ asyncHandler.stop();
+
+ //protocolManager.getAsynchronousManager().unregisterAsyncHandler(packetAdapter);
+ }
+ if (asyncSendingTask != null && !asyncSendingTask.isCancelled()) {
+ asyncSendingTask.cancel();
+ }
+ }
+
+
public void sendFakeItem(@NotNull Player player) {
sendPacket(player, fakeItemPacket);
sendPacket(player, fakeItemMetaPacket);
From 3c8a764e950b75a26f64250ac2128a880e6b4c3e Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Thu, 8 Apr 2021 17:43:20 +0800
Subject: [PATCH 26/36] Revert "Update dependency manually, avoid
CVE-2021-27568"
This reverts commit ff311875
---
pom.xml | 15 ---------------
1 file changed, 15 deletions(-)
diff --git a/pom.xml b/pom.xml
index fe78e3bc0..debcbe4f1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -411,21 +411,6 @@
com.dumptruckman.minecraft
JsonConfiguration
1.1
-
-
-
-
- net.minidev
- json-smart
-
-
-
-
-
-
- net.minidev
- json-smart
- 1.3.2
com.github.MilkBowl
From 74b353e065ea40996ded02e89166694482f60af4 Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Thu, 8 Apr 2021 17:46:39 +0800
Subject: [PATCH 27/36] Revert "Fix display conflict with PacketListenerAPI"
---
.../maxgamer/quickshop/shop/VirtualDisplayItem.java | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
index d0bf75899..f85314865 100644
--- a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
+++ b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
@@ -326,8 +326,6 @@ public class VirtualDisplayItem extends DisplayItem {
}
}
-
-
if (packetAdapter == null) {
packetAdapter = new PacketAdapter(plugin, ListenerPriority.HIGH, PacketType.Play.Server.MAP_CHUNK) {
@Override
@@ -379,8 +377,7 @@ public class VirtualDisplayItem extends DisplayItem {
}
};
}
- asyncHandler = protocolManager.getAsynchronousManager().registerAsyncHandler(packetAdapter); //TODO: This may affects performance
- asyncHandler.start();
+ protocolManager.addPacketListener(packetAdapter); //TODO: This may affects performance
// asyncSendingTask = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, () -> {
// Runnable runnable = asyncPacketSendQueue.poll();
// while (runnable != null) {
@@ -393,10 +390,7 @@ public class VirtualDisplayItem extends DisplayItem {
private void unload() {
packetSenders.clear();
if (packetAdapter != null) {
- protocolManager.getAsynchronousManager().unregisterAsyncHandler(asyncHandler);
- asyncHandler.stop();
-
- //protocolManager.getAsynchronousManager().unregisterAsyncHandler(packetAdapter);
+ protocolManager.removePacketListener(packetAdapter);
}
if (asyncSendingTask != null && !asyncSendingTask.isCancelled()) {
asyncSendingTask.cancel();
From b738c61366081a052213d554f02954621ba0c3d9 Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Thu, 8 Apr 2021 17:55:54 +0800
Subject: [PATCH 28/36] Fix dead lock
---
.../org/maxgamer/quickshop/listener/PlayerListener.java | 4 ++++
.../org/maxgamer/quickshop/shop/VirtualDisplayItem.java | 9 +--------
2 files changed, 5 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java b/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java
index fe6aa9a32..4e422f9d8 100644
--- a/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java
+++ b/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java
@@ -52,6 +52,8 @@ import java.util.UUID;
public class PlayerListener extends QSListener {
+ boolean actionSwapping = false;
+
public PlayerListener(QuickShop plugin) {
super(plugin);
}
@@ -69,6 +71,8 @@ public class PlayerListener extends QSListener {
}
final Block b = e.getClickedBlock();
final Player p = e.getPlayer();
+
+
if (!e.getAction().equals(Action.LEFT_CLICK_BLOCK) && b != null) {
if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK) && Util.isWallSign(b.getType())) {
final Block block;
diff --git a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
index f85314865..69baf0c68 100644
--- a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
+++ b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
@@ -45,7 +45,6 @@ import org.maxgamer.quickshop.util.Util;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.concurrent.ConcurrentSkipListSet;
-import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicInteger;
public class VirtualDisplayItem extends DisplayItem {
@@ -343,13 +342,7 @@ public class VirtualDisplayItem extends DisplayItem {
if (chunkLocation == null) {
World world = shop.getLocation().getWorld();
- Chunk chunk;
- try {
- //sync getting chunk
- chunk = plugin.getServer().getScheduler().callSyncMethod(plugin, () -> shop.getLocation().getChunk()).get();
- } catch (InterruptedException | ExecutionException e) {
- throw new RuntimeException("An error occurred when getting chunk from the world", e);
- }
+ Chunk chunk = shop.getLocation().getChunk();
chunkLocation = new ShopChunk(world.getName(), chunk.getX(), chunk.getZ());
}
Player player = event.getPlayer();
From 5ef66da294e6de8f7191c8beab20963617d0d184 Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Thu, 8 Apr 2021 18:10:56 +0800
Subject: [PATCH 29/36] Add adventure mode debug
---
.../org/maxgamer/quickshop/QuickShop.java | 1 +
.../quickshop/listener/PlayerListener.java | 78 ++++++++++++-------
src/main/resources/config.yml | 2 +
3 files changed, 55 insertions(+), 26 deletions(-)
diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java
index a5ea72acb..75f1e8c9e 100644
--- a/src/main/java/org/maxgamer/quickshop/QuickShop.java
+++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java
@@ -1727,6 +1727,7 @@ public class QuickShop extends JavaPlugin {
getConfig().set("integration.superiorskyblock.enable", false);
getConfig().set("integration.superiorskyblock.owner-create-only", false);
getConfig().set("integration.superiorskyblock.delete-shop-on-member-leave", true);
+ getConfig().set("shop.interact.swap-click-behavior", false);
getConfig().set("config-version", ++selectedVersion);
}
diff --git a/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java b/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java
index 4e422f9d8..8e9b817ac 100644
--- a/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java
+++ b/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java
@@ -27,7 +27,7 @@ import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
-import org.bukkit.event.Event.Result;
+import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
@@ -52,10 +52,34 @@ import java.util.UUID;
public class PlayerListener extends QSListener {
- boolean actionSwapping = false;
+
+ boolean swapBehavior = false;
public PlayerListener(QuickShop plugin) {
super(plugin);
+ swapBehavior = plugin.getConfig().getBoolean("shop.interact.swap-click-behavior");
+ }
+
+ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
+ public void onClick(PlayerInteractEvent e) {
+ if (e.getPlayer().getGameMode() == GameMode.ADVENTURE) {
+ plugin.getLogger().info(e.getHand().name());
+ plugin.getLogger().info(e.getAction().name());
+ plugin.getLogger().info(e.getClickedBlock().toString());
+ }
+ if (e.getHand() != EquipmentSlot.HAND) {
+ return;
+ }
+ final Block b = e.getClickedBlock();
+
+ if (!e.getAction().equals(Action.LEFT_CLICK_BLOCK) && b != null) {
+ if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
+ postControlPanel(e);
+ return;
+ }
+ }
+
+ postTrade(e);
}
private void playClickSound(@NotNull Player player) {
@@ -64,32 +88,29 @@ public class PlayerListener extends QSListener {
}
}
- @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
- public void onClick(PlayerInteractEvent e) {
- if (e.getHand() != EquipmentSlot.HAND) {
- return;
- }
+ private void postControlPanel(PlayerInteractEvent e) {
final Block b = e.getClickedBlock();
final Player p = e.getPlayer();
-
-
- if (!e.getAction().equals(Action.LEFT_CLICK_BLOCK) && b != null) {
- if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK) && Util.isWallSign(b.getType())) {
- final Block block;
- if (Util.isWallSign(b.getType())) {
- block = Util.getAttached(b);
- } else {
- block = e.getClickedBlock();
- }
- Shop controlPanelShop = plugin.getShopManager().getShop(Objects.requireNonNull(block).getLocation());
- if (controlPanelShop != null && (controlPanelShop.getOwner().equals(p.getUniqueId()) || QuickShop.getPermissionManager().hasPermission(p, "quickshop.other.control"))) {
- MsgUtil.sendControlPanelInfo(p, Objects.requireNonNull(plugin.getShopManager().getShop(block.getLocation())));
- this.playClickSound(e.getPlayer());
- Objects.requireNonNull(plugin.getShopManager().getShop(block.getLocation())).setSignText();
- }
+ if (Util.isWallSign(b.getType())) {
+ final Block block;
+ if (Util.isWallSign(b.getType())) {
+ block = Util.getAttached(b);
+ } else {
+ block = e.getClickedBlock();
+ }
+ Shop controlPanelShop = plugin.getShopManager().getShop(Objects.requireNonNull(block).getLocation());
+ if (controlPanelShop != null && (controlPanelShop.getOwner().equals(p.getUniqueId()) || QuickShop.getPermissionManager().hasPermission(p, "quickshop.other.control"))) {
+ MsgUtil.sendControlPanelInfo(p, Objects.requireNonNull(plugin.getShopManager().getShop(block.getLocation())));
+ this.playClickSound(e.getPlayer());
+ Objects.requireNonNull(plugin.getShopManager().getShop(block.getLocation())).setSignText();
}
- return;
}
+ return;
+ }
+
+ private void postTrade(PlayerInteractEvent e) {
+ final Block b = e.getClickedBlock();
+ final Player p = e.getPlayer();
if (b == null) {
return;
}
@@ -182,13 +203,13 @@ public class PlayerListener extends QSListener {
actions.put(p.getUniqueId(), info);
}
// Handles creating shops
- else if (e.useInteractedBlock() == Result.ALLOW
+ else if (e.useInteractedBlock() == Event.Result.ALLOW
&& shop == null
&& item != null
&& item.getType() != Material.AIR
&& QuickShop.getPermissionManager().hasPermission(p, "quickshop.create.sell")
&& p.getGameMode() != GameMode.CREATIVE) {
- if (e.useInteractedBlock() == Result.DENY
+ if (e.useInteractedBlock() == Event.Result.DENY
|| !InteractUtil.check(InteractUtil.Action.CREATE, p.isSneaking())
|| plugin.getConfig().getBoolean("shop.disable-quick-create")
|| !plugin.getShopManager().canBuildShop(p, b, e.getBlockFace())) {
@@ -242,6 +263,11 @@ public class PlayerListener extends QSListener {
}
}
+ enum InteractAction {
+ TRADE,
+ CONTROL_PANEL
+ }
+
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryClose(InventoryCloseEvent e) {
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 114c9f8a3..4ef6a3db6 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -239,6 +239,8 @@ shop:
sneak-to-create: false
sneak-to-trade: false
sneak-to-control: false
+ #Swap left and right click behavior
+ swap-click-behavior: false
#Should we automatically create the sign for the chest?
auto-sign: true
From 162223c45340efedcffd4e4befa33d980c224ea0 Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Thu, 8 Apr 2021 18:28:08 +0800
Subject: [PATCH 30/36] beta: adventure mode click
---
.../quickshop/listener/PlayerListener.java | 40 +++++++++++++++----
1 file changed, 32 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java b/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java
index 8e9b817ac..d7e159493 100644
--- a/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java
+++ b/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java
@@ -62,24 +62,48 @@ public class PlayerListener extends QSListener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onClick(PlayerInteractEvent e) {
- if (e.getPlayer().getGameMode() == GameMode.ADVENTURE) {
- plugin.getLogger().info(e.getHand().name());
- plugin.getLogger().info(e.getAction().name());
- plugin.getLogger().info(e.getClickedBlock().toString());
- }
if (e.getHand() != EquipmentSlot.HAND) {
return;
}
final Block b = e.getClickedBlock();
-
+ plugin.getLogger().info("CLICK");
if (!e.getAction().equals(Action.LEFT_CLICK_BLOCK) && b != null) {
if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
- postControlPanel(e);
+ if (!swapBehavior) {
+ postControlPanel(e);
+ } else {
+ postTrade(e);
+ }
return;
}
}
+ if (!swapBehavior) {
+ postTrade(e);
+ } else {
+ postControlPanel(e);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
+ public void onAdventureClick(PlayerAnimationEvent event) {
+ if (event.getPlayer().getGameMode() != GameMode.ADVENTURE) {
+ return;
+ }
+ plugin.getLogger().info("ANIMATION");
+ Block focused = event.getPlayer().getTargetBlock(null, 5);
+ PlayerInteractEvent interactEvent
+ = new PlayerInteractEvent(event.getPlayer(),
+ focused.getType() == Material.AIR ? Action.LEFT_CLICK_AIR : Action.LEFT_CLICK_BLOCK,
+ event.getPlayer().getInventory().getItemInMainHand(),
+ focused,
+ event.getPlayer().getFacing().getOppositeFace());
+
+ if (!swapBehavior) {
+ postTrade(interactEvent);
+ } else {
+ postControlPanel(interactEvent);
+ }
- postTrade(e);
}
private void playClickSound(@NotNull Player player) {
From 40d17585fb4bf3f8da650461fd2cf8104bf9f5fb Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Thu, 8 Apr 2021 18:39:30 +0800
Subject: [PATCH 31/36] Adventure mode dupe bug workaround
---
.../quickshop/listener/PlayerListener.java | 30 +++++++++++++++----
1 file changed, 25 insertions(+), 5 deletions(-)
diff --git a/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java b/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java
index d7e159493..a08228458 100644
--- a/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java
+++ b/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java
@@ -19,6 +19,8 @@
package org.maxgamer.quickshop.listener;
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
import io.papermc.lib.PaperLib;
import org.bukkit.GameMode;
import org.bukkit.Location;
@@ -49,11 +51,16 @@ import org.maxgamer.quickshop.util.Util;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
+import java.util.concurrent.TimeUnit;
public class PlayerListener extends QSListener {
-
-
- boolean swapBehavior = false;
+ private final Cache dupeClickPrevent = Caffeine
+ .newBuilder()
+ .initialCapacity(10)
+ .expireAfterAccess(1, TimeUnit.SECONDS)
+ .weakKeys()
+ .build();
+ private boolean swapBehavior = false;
public PlayerListener(QuickShop plugin) {
super(plugin);
@@ -66,7 +73,12 @@ public class PlayerListener extends QSListener {
return;
}
final Block b = e.getClickedBlock();
- plugin.getLogger().info("CLICK");
+
+ // ----Adventure dupe click workaround start----
+ if (e.getPlayer().getGameMode() == GameMode.ADVENTURE) {
+ dupeClickPrevent.put(e.getPlayer(), System.currentTimeMillis());
+ }
+ // ----Adventure dupe click workaround end----
if (!e.getAction().equals(Action.LEFT_CLICK_BLOCK) && b != null) {
if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
if (!swapBehavior) {
@@ -82,6 +94,7 @@ public class PlayerListener extends QSListener {
} else {
postControlPanel(e);
}
+
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
@@ -89,7 +102,14 @@ public class PlayerListener extends QSListener {
if (event.getPlayer().getGameMode() != GameMode.ADVENTURE) {
return;
}
- plugin.getLogger().info("ANIMATION");
+ // ----Adventure dupe click workaround start----
+ Long dupeTime = dupeClickPrevent.getIfPresent(event.getPlayer());
+ if (dupeTime != null && dupeTime > System.currentTimeMillis() - 1000) {
+ return;
+ } else if (dupeTime != null) {
+ dupeClickPrevent.invalidate(event.getPlayer());
+ }
+ // ----Adventure dupe click workaround end----
Block focused = event.getPlayer().getTargetBlock(null, 5);
PlayerInteractEvent interactEvent
= new PlayerInteractEvent(event.getPlayer(),
From b3462ea88d4e2ada108ef78249277a6993ca514b Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Thu, 8 Apr 2021 19:41:31 +0800
Subject: [PATCH 32/36] 4.0.7.8
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index debcbe4f1..160f46f20 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
4.0.0
org.maxgamer
QuickShop
- 4.0.7.6
+ 4.0.7.8
From 71330089529c6f12b56f0476f4485ceec7f696c2 Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Thu, 8 Apr 2021 20:10:53 +0800
Subject: [PATCH 33/36] add PacketListenerAPI check
---
.../quickshop/util/envcheck/EnvironmentChecker.java | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/src/main/java/org/maxgamer/quickshop/util/envcheck/EnvironmentChecker.java b/src/main/java/org/maxgamer/quickshop/util/envcheck/EnvironmentChecker.java
index b198e0a2d..5031418d2 100644
--- a/src/main/java/org/maxgamer/quickshop/util/envcheck/EnvironmentChecker.java
+++ b/src/main/java/org/maxgamer/quickshop/util/envcheck/EnvironmentChecker.java
@@ -20,6 +20,7 @@
package org.maxgamer.quickshop.util.envcheck;
import lombok.SneakyThrows;
+import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.event.HandlerList;
import org.bukkit.event.block.BlockPlaceEvent;
@@ -27,6 +28,8 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredListener;
import org.jetbrains.annotations.NotNull;
import org.maxgamer.quickshop.QuickShop;
+import org.maxgamer.quickshop.shop.DisplayItem;
+import org.maxgamer.quickshop.shop.DisplayType;
import org.maxgamer.quickshop.util.GameVersion;
import org.maxgamer.quickshop.util.JsonUtil;
import org.maxgamer.quickshop.util.ReflectFactory;
@@ -404,4 +407,12 @@ public class EnvironmentChecker {
}
return new ResultContainer(CheckResult.PASSED, "Passed checks");
}
+
+ @EnvCheckEntry(name = "PacketListenerAPI conflict Test", priority = 9)
+ public ResultContainer plapiConflictTest() {
+ if (plugin.isDisplay() && DisplayItem.getNowUsing() == DisplayType.VIRTUALITEM && Bukkit.getPluginManager().isPluginEnabled("ProtocolLib") && Bukkit.getPluginManager().isPluginEnabled("PacketListenerAPI")) {
+ return new ResultContainer(CheckResult.WARNING, "Virtual DisplayItem may stop working on your server. We already know plugin [PacketListenerAPI] conflict with plugin [ProtocolLib] (that we required to sending fake items). If you display not showing, please uninstall [PacketListenerAPI]. And it's fine to keep them if nothing wrong.");
+ }
+ return new ResultContainer(CheckResult.PASSED, "Passed checks");
+ }
}
From a9120ac2f9b64a78ce7f78f0a3556ea6da4bb2b3 Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Thu, 8 Apr 2021 21:28:11 +0800
Subject: [PATCH 34/36] Remove useless field
---
.../org/maxgamer/quickshop/shop/VirtualDisplayItem.java | 9 ---------
1 file changed, 9 deletions(-)
diff --git a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
index 69baf0c68..bb7232bde 100644
--- a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
+++ b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java
@@ -21,7 +21,6 @@ package org.maxgamer.quickshop.shop;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
-import com.comphenix.protocol.async.AsyncListenerHandler;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
@@ -36,7 +35,6 @@ import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
-import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.maxgamer.quickshop.event.ShopDisplayItemSpawnEvent;
@@ -82,10 +80,6 @@ public class VirtualDisplayItem extends DisplayItem {
//cache chunk x and z
private ShopChunk chunkLocation;
- @Nullable
- private BukkitTask asyncSendingTask;
-
- private AsyncListenerHandler asyncHandler;
public VirtualDisplayItem(@NotNull Shop shop) throws RuntimeException {
@@ -385,9 +379,6 @@ public class VirtualDisplayItem extends DisplayItem {
if (packetAdapter != null) {
protocolManager.removePacketListener(packetAdapter);
}
- if (asyncSendingTask != null && !asyncSendingTask.isCancelled()) {
- asyncSendingTask.cancel();
- }
}
From 3e9800987dff7815df63906420f4d9c4bf39aadc Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Thu, 8 Apr 2021 21:30:44 +0800
Subject: [PATCH 35/36] Register & unregister events
---
.../SuperiorSkyblock2Integration.java | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/src/main/java/org/maxgamer/quickshop/integration/superiorskyblock/SuperiorSkyblock2Integration.java b/src/main/java/org/maxgamer/quickshop/integration/superiorskyblock/SuperiorSkyblock2Integration.java
index 6008ff2d7..245f9caaf 100644
--- a/src/main/java/org/maxgamer/quickshop/integration/superiorskyblock/SuperiorSkyblock2Integration.java
+++ b/src/main/java/org/maxgamer/quickshop/integration/superiorskyblock/SuperiorSkyblock2Integration.java
@@ -20,6 +20,9 @@
package org.maxgamer.quickshop.integration.superiorskyblock;
import com.bgsoftware.superiorskyblock.api.SuperiorSkyblockAPI;
+import com.bgsoftware.superiorskyblock.api.events.IslandChunkResetEvent;
+import com.bgsoftware.superiorskyblock.api.events.IslandKickEvent;
+import com.bgsoftware.superiorskyblock.api.events.IslandQuitEvent;
import com.bgsoftware.superiorskyblock.api.island.Island;
import com.bgsoftware.superiorskyblock.api.wrappers.SuperiorPlayer;
import org.bukkit.Bukkit;
@@ -45,9 +48,7 @@ public class SuperiorSkyblock2Integration extends QSIntegratedPlugin implements
super(plugin);
onlyOwnerCanCreateShop = plugin.getConfig().getBoolean("integration.superiorskyblock.owner-create-only");
deleteShopOnMemberLeave = plugin.getConfig().getBoolean("integration.superiorskyblock.delete-shop-on-member-leave");
- if (plugin.getConfig().getBoolean("integration.superiorskyblock.delete-shop-on-member-leave")) {
- Bukkit.getPluginManager().registerEvents(this, plugin);
- }
+
}
/**
@@ -102,7 +103,9 @@ public class SuperiorSkyblock2Integration extends QSIntegratedPlugin implements
*/
@Override
public void load() {
-
+ if (plugin.getConfig().getBoolean("integration.superiorskyblock.delete-shop-on-member-leave")) {
+ Bukkit.getPluginManager().registerEvents(this, plugin);
+ }
}
/**
@@ -111,7 +114,9 @@ public class SuperiorSkyblock2Integration extends QSIntegratedPlugin implements
*/
@Override
public void unload() {
-
+ IslandQuitEvent.getHandlerList().unregister(this);
+ IslandKickEvent.getHandlerList().unregister(this);
+ IslandChunkResetEvent.getHandlerList().unregister(this);
}
@EventHandler
From 36ef5b5be3588ed5d1d6605dec8dac873412acfa Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Thu, 8 Apr 2021 23:35:59 +0800
Subject: [PATCH 36/36] Hot fix for display issue
---
pom.xml | 2 +-
src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index 160f46f20..5b9bc693f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
4.0.0
org.maxgamer
QuickShop
- 4.0.7.8
+ 4.0.7.9
diff --git a/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java b/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java
index 4bbce7d17..57f572460 100644
--- a/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java
+++ b/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java
@@ -813,7 +813,7 @@ public class ContainerShop implements Shop {
checkDisplay();
- if (!isLeftShop) {
+ if (!isLeftShop && plugin.isDisplay()) {
initDisplayItem();
displayItem.spawn();
}