2.15.0 - Added a whitelist for filter categories

This commit is contained in:
Kiran Hart 2021-06-22 21:37:05 -04:00
parent 04178d9910
commit 13425cfcbd
18 changed files with 517 additions and 17 deletions

View File

@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>ca.tweetzy</groupId>
<artifactId>auctionhouse</artifactId>
<version>2.14.0</version>
<version>2.15.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -5,10 +5,12 @@ import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.commands.*;
import ca.tweetzy.auctionhouse.database.DataManager;
import ca.tweetzy.auctionhouse.database.migrations._1_InitialMigration;
import ca.tweetzy.auctionhouse.database.migrations._2_FilterWhitelistMigration;
import ca.tweetzy.auctionhouse.listeners.AuctionListeners;
import ca.tweetzy.auctionhouse.listeners.PlayerListeners;
import ca.tweetzy.auctionhouse.managers.AuctionItemManager;
import ca.tweetzy.auctionhouse.managers.AuctionPlayerManager;
import ca.tweetzy.auctionhouse.managers.FilterManager;
import ca.tweetzy.auctionhouse.managers.TransactionManager;
import ca.tweetzy.auctionhouse.settings.LocaleSettings;
import ca.tweetzy.auctionhouse.settings.Settings;
@ -72,6 +74,9 @@ public class AuctionHouse extends TweetyPlugin {
@Getter
private TransactionManager transactionManager;
@Getter
private FilterManager filterManager;
@Getter
private DatabaseConnector databaseConnector;
@ -126,7 +131,7 @@ public class AuctionHouse extends TweetyPlugin {
if (Settings.DATABASE_USE.getBoolean()) {
this.databaseConnector = new MySQLConnector(this, Settings.DATABASE_HOST.getString(), Settings.DATABASE_PORT.getInt(), Settings.DATABASE_NAME.getString(), Settings.DATABASE_USERNAME.getString(), Settings.DATABASE_PASSWORD.getString(), Settings.DATABASE_USE_SSL.getBoolean());
this.dataManager = new DataManager(this.databaseConnector, this);
DataMigrationManager dataMigrationManager = new DataMigrationManager(this.databaseConnector, this.dataManager, new _1_InitialMigration());
DataMigrationManager dataMigrationManager = new DataMigrationManager(this.databaseConnector, this.dataManager, new _1_InitialMigration(), new _2_FilterWhitelistMigration());
dataMigrationManager.runMigrations();
}
@ -138,6 +143,10 @@ public class AuctionHouse extends TweetyPlugin {
this.transactionManager = new TransactionManager();
this.transactionManager.loadTransactions(Settings.DATABASE_USE.getBoolean());
// load the filter whitelist items
this.filterManager = new FilterManager();
this.filterManager.loadItems(Settings.DATABASE_USE.getBoolean());
// gui manager
this.guiManager.init();
@ -154,6 +163,7 @@ public class AuctionHouse extends TweetyPlugin {
new CommandSettings(),
new CommandConvert(),
new CommandReload(),
new CommandFilter(),
new CommandUpload(),
new CommandStatus(),
new CommandAdmin()
@ -177,6 +187,7 @@ public class AuctionHouse extends TweetyPlugin {
public void onPluginDisable() {
this.auctionItemManager.saveItems(Settings.DATABASE_USE.getBoolean(), false);
this.transactionManager.saveTransactions(Settings.DATABASE_USE.getBoolean(), false);
this.filterManager.saveFilterWhitelist(Settings.DATABASE_USE.getBoolean(), false);
instance = null;
}

View File

@ -0,0 +1,33 @@
package ca.tweetzy.auctionhouse.auction;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.inventory.ItemStack;
import java.io.Serializable;
/**
* The current file has been created by Kiran Hart
* Date Created: June 22 2021
* Time Created: 3:39 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
@Getter
@Setter
public class AuctionFilterItem implements Serializable {
private byte[] rawItem;
private AuctionItemCategory category;
public AuctionFilterItem(ItemStack item, AuctionItemCategory category) {
this.rawItem = AuctionAPI.getInstance().serializeItem(item);
this.category = category;
}
public ItemStack getItemStack() {
return AuctionAPI.getInstance().deserializeItem(this.rawItem);
}
}

View File

@ -10,29 +10,35 @@ import ca.tweetzy.auctionhouse.AuctionHouse;
*/
public enum AuctionItemCategory {
ALL("All"),
FOOD("Food"),
ARMOR("Armor"),
BLOCKS("Blocks"),
TOOLS("Tools"),
WEAPONS("Weapons"),
SPAWNERS("Spawners"),
ENCHANTS("Enchants"),
MISC("Misc"),
SEARCH("Search"),
SELF("Self");
ALL("All", false),
FOOD("Food", true),
ARMOR("Armor", true),
BLOCKS("Blocks", true),
TOOLS("Tools", true),
WEAPONS("Weapons", true),
SPAWNERS("Spawners", true),
ENCHANTS("Enchants", true),
MISC("Misc", true),
SEARCH("Search", false),
SELF("Self", false);
private final String type;
private final boolean whitelistAllowed;
AuctionItemCategory(String type) {
AuctionItemCategory(String type, boolean whitelistAllowed) {
this.type = type;
this.whitelistAllowed = whitelistAllowed;
}
public String getType() {
return type;
}
public boolean isWhitelistAllowed() {
return whitelistAllowed;
}
public String getTranslatedType() {
switch (this) {
case ALL:

View File

@ -0,0 +1,95 @@
package ca.tweetzy.auctionhouse.commands;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionFilterItem;
import ca.tweetzy.auctionhouse.auction.AuctionItemCategory;
import ca.tweetzy.auctionhouse.guis.filter.GUIFilterWhitelist;
import ca.tweetzy.auctionhouse.helpers.PlayerHelper;
import ca.tweetzy.core.commands.AbstractCommand;
import ca.tweetzy.core.compatibility.XMaterial;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**
* The current file has been created by Kiran Hart
* Date Created: June 22 2021
* Time Created: 3:18 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public class CommandFilter extends AbstractCommand {
public CommandFilter() {
super(CommandType.PLAYER_ONLY, "filter");
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
Player player = (Player) sender;
if (args.length == 0) {
AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIFilterWhitelist());
return ReturnType.SUCCESS;
}
if (args.length == 2 && args[0].equalsIgnoreCase("additem")) {
boolean isValid = false;
for (AuctionItemCategory value : AuctionItemCategory.values()) {
if (args[1].toUpperCase().equals(value.name())) {
isValid = true;
break;
}
}
if (isValid && AuctionItemCategory.valueOf(args[1].toUpperCase()).isWhitelistAllowed()) {
ItemStack held = PlayerHelper.getHeldItem(player);
if (held.getType() == XMaterial.AIR.parseMaterial()) {
AuctionHouse.getInstance().getLocale().getMessage("general.filter air").sendPrefixedMessage(player);
return ReturnType.FAILURE;
}
if (AuctionHouse.getInstance().getFilterManager().getFilteredItem(held) != null && AuctionHouse.getInstance().getFilterManager().getFilteredItem(held).getCategory() == AuctionItemCategory.valueOf(args[1].toUpperCase())) {
AuctionHouse.getInstance().getLocale().getMessage("general.filteritemaddedalready").sendPrefixedMessage(player);
return ReturnType.FAILURE;
}
AuctionFilterItem filterItem = new AuctionFilterItem(held, AuctionItemCategory.valueOf(args[1].toUpperCase()));
AuctionHouse.getInstance().getFilterManager().addFilterItem(filterItem);
AuctionHouse.getInstance().getLocale().getMessage("general.addeditemtofilterwhitelist").processPlaceholder("item_name", AuctionAPI.getInstance().getItemName(held)).processPlaceholder("filter_category", args[1]).sendPrefixedMessage(player);
}
}
return ReturnType.SUCCESS;
}
@Override
public String getPermissionNode() {
return "auctionhouse.cmd.filter";
}
@Override
public String getSyntax() {
return AuctionHouse.getInstance().getLocale().getMessage("commands.syntax.filter").getMessage();
}
@Override
public String getDescription() {
return AuctionHouse.getInstance().getLocale().getMessage("commands.description.filter").getMessage();
}
@Override
protected List<String> onTab(CommandSender sender, String... args) {
if (args.length == 1) return Collections.singletonList("additem");
if (args.length == 2)
return Arrays.stream(AuctionItemCategory.values()).filter(AuctionItemCategory::isWhitelistAllowed).map(AuctionItemCategory::getTranslatedType).collect(Collectors.toList());
return null;
}
}

View File

@ -1,6 +1,7 @@
package ca.tweetzy.auctionhouse.database;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionFilterItem;
import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.auctionhouse.transaction.Transaction;
import ca.tweetzy.core.database.DataManagerAbstract;
@ -66,6 +67,48 @@ public class DataManager extends DataManagerAbstract {
}
}
public void saveFilterWhitelist(List<AuctionFilterItem> filterItems, boolean async){
if (async) {
this.async(() -> this.databaseConnector.connect(connection -> {
String saveItems = "INSERT IGNORE INTO " + this.getTablePrefix() + "filter_whitelist SET data = ?";
String truncate = "TRUNCATE TABLE " + this.getTablePrefix() + "filter_whitelist";
try (PreparedStatement statement = connection.prepareStatement(truncate)) {
statement.execute();
}
PreparedStatement statement = connection.prepareStatement(saveItems);
filterItems.forEach(filterItem -> {
try {
statement.setString(1, AuctionAPI.getInstance().convertToBase64(filterItem));
statement.addBatch();
} catch (SQLException e) {
e.printStackTrace();
}
});
statement.executeBatch();
}));
} else {
this.databaseConnector.connect(connection -> {
String saveItems = "INSERT IGNORE INTO " + this.getTablePrefix() + "filter_whitelist SET data = ?";
String truncate = "TRUNCATE TABLE " + this.getTablePrefix() + "filter_whitelist";
try (PreparedStatement statement = connection.prepareStatement(truncate)) {
statement.execute();
}
PreparedStatement statement = connection.prepareStatement(saveItems);
filterItems.forEach(filterItem -> {
try {
statement.setString(1, AuctionAPI.getInstance().convertToBase64(filterItem));
statement.addBatch();
} catch (SQLException e) {
e.printStackTrace();
}
});
statement.executeBatch();
});
}
}
public void saveTransactions(List<Transaction> transactions, boolean async) {
if (async) {
this.async(() -> this.databaseConnector.connect(connection -> {
@ -123,6 +166,21 @@ public class DataManager extends DataManagerAbstract {
}));
}
public void getFilterWhitelist(Consumer<ArrayList<AuctionFilterItem>> callback) {
ArrayList<AuctionFilterItem> filterItems = new ArrayList<>();
this.async(() -> this.databaseConnector.connect(connection -> {
String select = "SELECT * FROM " + this.getTablePrefix() + "filter_whitelist";
try (Statement statement = connection.createStatement()) {
ResultSet result = statement.executeQuery(select);
while (result.next()) {
filterItems.add((AuctionFilterItem) AuctionAPI.getInstance().convertBase64ToObject(result.getString("data")));
}
}
this.sync(() -> callback.accept(filterItems));
}));
}
public void getItems(Consumer<ArrayList<AuctionItem>> callback) {
ArrayList<AuctionItem> items = new ArrayList<>();
this.async(() -> this.databaseConnector.connect(connection -> {

View File

@ -0,0 +1,33 @@
package ca.tweetzy.auctionhouse.database.migrations;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.core.database.DataMigration;
import ca.tweetzy.core.database.MySQLConnector;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
/**
* The current file has been created by Kiran Hart
* Date Created: June 22 2021
* Time Created: 3:46 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public class _2_FilterWhitelistMigration extends DataMigration {
public _2_FilterWhitelistMigration() {
super(2);
}
@Override
public void migrate(Connection connection, String tablePrefix) throws SQLException {
String autoIncrement = AuctionHouse.getInstance().getDatabaseConnector() instanceof MySQLConnector ? " AUTO_INCREMENT" : "";
try (Statement statement = connection.createStatement()) {
statement.execute("CREATE TABLE " + tablePrefix + "filter_whitelist (" +
"id INTEGER PRIMARY KEY" + autoIncrement + ", " +
"data LONGTEXT NOT NULL )");
}
}
}

View File

@ -3,6 +3,7 @@ package ca.tweetzy.auctionhouse.guis;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.*;
import ca.tweetzy.auctionhouse.guis.filter.GUIFilterSelection;
import ca.tweetzy.auctionhouse.guis.transaction.GUITransactionList;
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
import ca.tweetzy.auctionhouse.managers.SoundManager;
@ -72,7 +73,7 @@ public class GUIAuctionHouse extends Gui {
}
if (this.auctionPlayer.getSelectedFilter() != AuctionItemCategory.ALL && this.auctionPlayer.getSelectedFilter() != AuctionItemCategory.SEARCH && this.auctionPlayer.getSelectedFilter() != AuctionItemCategory.SELF) {
this.items = this.items.stream().filter(item -> item.getCategory() == this.auctionPlayer.getSelectedFilter()).collect(Collectors.toList());
this.items = this.items.stream().filter(item -> checkFilterCriteria(item, this.auctionPlayer.getSelectedFilter())).collect(Collectors.toList());
} else if (this.auctionPlayer.getSelectedFilter() == AuctionItemCategory.SELF) {
this.items = this.items.stream().filter(item -> item.getOwner().equals(this.auctionPlayer.getPlayer().getUniqueId())).collect(Collectors.toList());
} else if (this.auctionPlayer.getSelectedFilter() == AuctionItemCategory.SEARCH && this.auctionPlayer.getCurrentSearchPhrase().length() != 0) {
@ -103,6 +104,11 @@ public class GUIAuctionHouse extends Gui {
}).execute();
}
private boolean checkFilterCriteria(AuctionItem auctionItem, AuctionItemCategory category) {
return auctionItem.getCategory() == category ||
AuctionHouse.getInstance().getFilterManager().getFilterWhitelist(category).stream().anyMatch(item -> item.isSimilar(AuctionAPI.getInstance().deserializeItem(auctionItem.getRawItem())));
}
private boolean checkSearchCriteria(String phrase, AuctionItem item) {
return AuctionAPI.getInstance().match(phrase, item.getItemName()) ||
AuctionAPI.getInstance().match(phrase, item.getCategory().getTranslatedType()) ||

View File

@ -1,9 +1,10 @@
package ca.tweetzy.auctionhouse.guis;
package ca.tweetzy.auctionhouse.guis.filter;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionItemCategory;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.guis.GUIAuctionHouse;
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.gui.Gui;

View File

@ -0,0 +1,61 @@
package ca.tweetzy.auctionhouse.guis.filter;
import ca.tweetzy.auctionhouse.auction.AuctionItemCategory;
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.gui.Gui;
import ca.tweetzy.core.utils.TextUtils;
/**
* The current file has been created by Kiran Hart
* Date Created: June 22 2021
* Time Created: 3:14 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public class GUIFilterWhitelist extends Gui {
public GUIFilterWhitelist() {
setTitle(TextUtils.formatText(Settings.GUI_FILTER_WHITELIST_TITLE.getString()));
setRows(6);
setAcceptsItems(false);
setDefaultItem(Settings.GUI_FILTER_WHITELIST_BG_ITEM.getMaterial().parseItem());
setUseLockedCells(true);
draw();
}
private void draw() {
setButton(2, 1, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_FILTER_WHITELIST_ITEMS_BLOCKS_ITEM.getString(), Settings.GUI_FILTER_WHITELIST_ITEMS_BLOCKS_NAME.getString(), Settings.GUI_FILTER_WHITELIST_ITEMS_BLOCKS_LORE.getStringList(), null), e -> {
e.manager.showGUI(e.player, new GUIFilterWhitelistList(AuctionItemCategory.BLOCKS));
});
setButton(2, 3, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_FILTER_WHITELIST_ITEMS_FOOD_ITEM.getString(), Settings.GUI_FILTER_WHITELIST_ITEMS_FOOD_NAME.getString(), Settings.GUI_FILTER_WHITELIST_ITEMS_FOOD_LORE.getStringList(), null), e -> {
e.manager.showGUI(e.player, new GUIFilterWhitelistList(AuctionItemCategory.FOOD));
});
setButton(2, 5, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_FILTER_WHITELIST_ITEMS_ARMOR_ITEM.getString(), Settings.GUI_FILTER_WHITELIST_ITEMS_ARMOR_NAME.getString(), Settings.GUI_FILTER_WHITELIST_ITEMS_ARMOR_LORE.getStringList(), null), e -> {
e.manager.showGUI(e.player, new GUIFilterWhitelistList(AuctionItemCategory.ARMOR));
});
setButton(2, 7, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_FILTER_WHITELIST_ITEMS_TOOLS_ITEM.getString(), Settings.GUI_FILTER_WHITELIST_ITEMS_TOOLS_NAME.getString(), Settings.GUI_FILTER_WHITELIST_ITEMS_TOOLS_LORE.getStringList(), null), e -> {
e.manager.showGUI(e.player, new GUIFilterWhitelistList(AuctionItemCategory.TOOLS));
});
// 2ND ROW STARTS
setButton(3, 1, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_FILTER_WHITELIST_ITEMS_SPAWNERS_ITEM.getString(), Settings.GUI_FILTER_WHITELIST_ITEMS_SPAWNERS_NAME.getString(), Settings.GUI_FILTER_WHITELIST_ITEMS_SPAWNERS_LORE.getStringList(), null), e -> {
e.manager.showGUI(e.player, new GUIFilterWhitelistList(AuctionItemCategory.SPAWNERS));
});
setButton(3, 3, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_FILTER_WHITELIST_ITEMS_ENCHANTS_ITEM.getString(), Settings.GUI_FILTER_WHITELIST_ITEMS_ENCHANTS_NAME.getString(), Settings.GUI_FILTER_WHITELIST_ITEMS_ENCHANTS_LORE.getStringList(), null), e -> {
e.manager.showGUI(e.player, new GUIFilterWhitelistList(AuctionItemCategory.ENCHANTS));
});
setButton(3, 5, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_FILTER_WHITELIST_ITEMS_WEAPONS_ITEM.getString(), Settings.GUI_FILTER_WHITELIST_ITEMS_WEAPONS_NAME.getString(), Settings.GUI_FILTER_WHITELIST_ITEMS_WEAPONS_LORE.getStringList(), null), e -> {
e.manager.showGUI(e.player, new GUIFilterWhitelistList(AuctionItemCategory.WEAPONS));
});
setButton(3, 7, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_FILTER_WHITELIST_ITEMS_MISC_ITEM.getString(), Settings.GUI_FILTER_WHITELIST_ITEMS_MISC_NAME.getString(), Settings.GUI_FILTER_WHITELIST_ITEMS_MISC_LORE.getStringList(), null), e -> {
e.manager.showGUI(e.player, new GUIFilterWhitelistList(AuctionItemCategory.MISC));
});
}
}

View File

@ -0,0 +1,65 @@
package ca.tweetzy.auctionhouse.guis.filter;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.auction.AuctionFilterItem;
import ca.tweetzy.auctionhouse.auction.AuctionItemCategory;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.compatibility.XSound;
import ca.tweetzy.core.gui.Gui;
import ca.tweetzy.core.utils.TextUtils;
import ca.tweetzy.core.utils.items.TItemBuilder;
import org.bukkit.event.inventory.ClickType;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* The current file has been created by Kiran Hart
* Date Created: June 22 2021
* Time Created: 4:06 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public class GUIFilterWhitelistList extends Gui {
final AuctionItemCategory filerCategory;
List<AuctionFilterItem> items;
public GUIFilterWhitelistList(AuctionItemCategory filerCategory) {
this.filerCategory = filerCategory;
setTitle(TextUtils.formatText(Settings.GUI_FILTER_WHITELIST_LIST_TITLE.getString().replace("%filter_category%", filerCategory.getTranslatedType())));
setRows(6);
setAcceptsItems(false);
setDefaultItem(Settings.GUI_FILTER_WHITELIST_LIST_BG_ITEM.getMaterial().parseItem());
setUseLockedCells(true);
draw();
setOnClose(close -> close.manager.showGUI(close.player, new GUIFilterWhitelist()));
}
private void draw() {
reset();
setPrevPage(5, 3, new TItemBuilder(Objects.requireNonNull(Settings.GUI_BACK_BTN_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_BACK_BTN_NAME.getString()).setLore(Settings.GUI_BACK_BTN_LORE.getStringList()).toItemStack());
setButton(5, 4, new TItemBuilder(Objects.requireNonNull(Settings.GUI_CLOSE_BTN_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_CLOSE_BTN_NAME.getString()).setLore(Settings.GUI_CLOSE_BTN_LORE.getStringList()).toItemStack(), e -> e.manager.showGUI(e.player, new GUIFilterWhitelist()));
setNextPage(5, 5, new TItemBuilder(Objects.requireNonNull(Settings.GUI_NEXT_BTN_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_NEXT_BTN_NAME.getString()).setLore(Settings.GUI_NEXT_BTN_LORE.getStringList()).toItemStack());
setOnPage(e -> draw());
AuctionHouse.newChain().asyncFirst(() -> {
this.items = AuctionHouse.getInstance().getFilterManager().getFilterWhitelist().stream().filter(item -> item.getCategory() == filerCategory).collect(Collectors.toList());
return this.items.stream().skip((page - 1) * 28L).limit(28L).collect(Collectors.toList());
}).asyncLast((data) -> {
pages = (int) Math.max(1, Math.ceil(this.items.size() / (double) 28L));
int slot = 10;
for (AuctionFilterItem item : data) {
setButton(slot, item.getItemStack(), ClickType.RIGHT, e -> {
AuctionHouse.getInstance().getFilterManager().removeFilterItem(item);
draw();
});
slot = Arrays.asList(16, 25, 34).contains(slot) ? slot + 3 : slot + 1;
}
}).execute();
}
}

View File

@ -40,6 +40,7 @@ public class ConfigurationItemHelper {
}
meta.setDisplayName(TextUtils.formatText(title));
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ENCHANTS);
meta.setLore(lore.stream().map(TextUtils::formatText).collect(Collectors.toList()));
stack.setItemMeta(meta);
if (nbtData != null) {

View File

@ -2,6 +2,7 @@ package ca.tweetzy.auctionhouse.managers;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionFilterItem;
import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.core.utils.TextUtils;
import org.bukkit.Bukkit;
@ -45,6 +46,7 @@ public class AuctionItemManager {
return this.auctionItems;
}
public Set<AuctionItem> getGarbageBin() {
return garbageBin;
}

View File

@ -0,0 +1,74 @@
package ca.tweetzy.auctionhouse.managers;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionFilterItem;
import ca.tweetzy.auctionhouse.auction.AuctionItemCategory;
import ca.tweetzy.core.utils.TextUtils;
import org.bukkit.Bukkit;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* The current file has been created by Kiran Hart
* Date Created: June 22 2021
* Time Created: 3:41 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public class FilterManager {
private final List<AuctionFilterItem> filterWhitelist = new ArrayList<>();
public void addFilterItem(AuctionFilterItem auctionFilterItem) {
if (auctionFilterItem == null) return;
this.filterWhitelist.add(auctionFilterItem);
}
public void removeFilterItem(AuctionFilterItem auctionFilterItem) {
if (auctionFilterItem == null) return;
this.filterWhitelist.remove(auctionFilterItem);
}
public AuctionFilterItem getFilteredItem(ItemStack itemStack) {
return this.filterWhitelist.stream().filter(items -> items.getItemStack().isSimilar(itemStack)).findFirst().orElse(null);
}
public List<AuctionFilterItem> getFilterWhitelist() {
return this.filterWhitelist;
}
public List<ItemStack> getFilterWhitelist(AuctionItemCategory category) {
return this.filterWhitelist.stream().filter(item -> item.getCategory() == category).map(item -> AuctionAPI.getInstance().deserializeItem(item.getRawItem())).collect(Collectors.toList());
}
public void loadItems(boolean useDatabase) {
if (useDatabase) {
AuctionHouse.getInstance().getDataManager().getFilterWhitelist(all -> all.forEach(this::addFilterItem));
} else {
if (AuctionHouse.getInstance().getData().contains("auction filter whitelist") && AuctionHouse.getInstance().getData().isList("auction filter whitelist")) {
List<AuctionFilterItem> items = AuctionHouse.getInstance().getData().getStringList("auction filter whitelist").stream().map(AuctionAPI.getInstance()::convertBase64ToObject).map(object -> (AuctionFilterItem) object).collect(Collectors.toList());
long start = System.currentTimeMillis();
items.forEach(this::addFilterItem);
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText(String.format("&aLoaded &2%d &aauction filter items(s) in &e%d&fms", items.size(), System.currentTimeMillis() - start))).sendPrefixedMessage(Bukkit.getConsoleSender());
AuctionHouse.getInstance().getData().set("auction filter whitelist", null);
AuctionHouse.getInstance().getData().save();
}
}
}
public void saveFilterWhitelist(boolean useDatabase, boolean async) {
if (useDatabase) {
AuctionHouse.getInstance().getDataManager().saveFilterWhitelist(getFilterWhitelist(), async);
} else {
this.adjustItemsInFile(this.getFilterWhitelist());
}
}
public void adjustItemsInFile(List<AuctionFilterItem> items) {
AuctionHouse.getInstance().getData().set("auction filter whitelist", items.stream().map(AuctionAPI.getInstance()::convertToBase64).collect(Collectors.toList()));
AuctionHouse.getInstance().getData().save();
}
}

View File

@ -26,6 +26,7 @@ public class LocaleSettings {
languageNodes.put("general.blockedname", "&cThat item contains a blocked name phrase");
languageNodes.put("general.blockedlore", "&cThat item contains a blocked lore phrase");
languageNodes.put("general.air", "&cSorry, but you cannot sell air o.O");
languageNodes.put("general.filter air", "&cSorry, but you cannot add air to a filter whitelist");
languageNodes.put("general.blocked", "&cSorry, you are not allowed to sell &e%item%");
languageNodes.put("general.sellinglimit", "&cYou cannot sell more items, please remove/sell current active items");
languageNodes.put("general.noroom", "&cPlease clear room in your inventory to purchase that item.");
@ -33,7 +34,9 @@ public class LocaleSettings {
languageNodes.put("general.endedallauctions", "&cYou force ended all active auctions");
languageNodes.put("general.relisteditems", "&aYou relisted all expired items!");
languageNodes.put("general.cannotsellbundleditem", "&cYou cannot sell a bundled item as a bundle.");
languageNodes.put("general.entersearchphrase", "&Enter a search phrase into chat");
languageNodes.put("general.entersearchphrase", "&aEnter a search phrase into chat");
languageNodes.put("general.filteritemaddedalready", "&cThat item already exists within that category's filter whitelist.");
languageNodes.put("general.addeditemtofilterwhitelist", "&aAdded &2%item_name%&a to the &2%filter_category%&a's whitelist");
languageNodes.put("pricing.minbaseprice", "&cThe minimum base price must be &a$%price%");
@ -100,6 +103,7 @@ public class LocaleSettings {
languageNodes.put("commands.syntax.settings", "settings");
languageNodes.put("commands.syntax.transactions", "transactions");
languageNodes.put("commands.syntax.upload", "upload");
languageNodes.put("commands.syntax.filter", "filter [additem] [category]");
languageNodes.put("commands.description.active", "View all your auction listings");
languageNodes.put("commands.description.auctionhouse", "Main command for the plugin, it opens the auction window.");
@ -111,6 +115,7 @@ public class LocaleSettings {
languageNodes.put("commands.description.settings", "Open the in-game config editor");
languageNodes.put("commands.description.transactions", "Used to open the transactions menu");
languageNodes.put("commands.description.upload", "Used to upload flat file data to the database");
languageNodes.put("commands.description.filter", "Edit the filter whitelist items");
}
public static void setup() {

View File

@ -524,6 +524,50 @@ public class Settings {
public static final ConfigSetting GUI_FILTER_ITEMS_BLOCKS_NAME = new ConfigSetting(config, "gui.filter.items.blocks.name", "&e&lBlocks");
public static final ConfigSetting GUI_FILTER_ITEMS_BLOCKS_LORE = new ConfigSetting(config, "gui.filter.items.blocks.lore", Collections.singletonList("&7Click to set the filter to&f: &eBlocks"));
/* ===============================
* CUSTOM ITEM FILTER GUI
* ===============================*/
public static final ConfigSetting GUI_FILTER_WHITELIST_TITLE = new ConfigSetting(config, "gui.filter whitelist.title", "&7Auction Filter - &eWhitelist");
public static final ConfigSetting GUI_FILTER_WHITELIST_BG_ITEM = new ConfigSetting(config, "gui.filter whitelist.bg item", XMaterial.BLACK_STAINED_GLASS_PANE.name());
public static final ConfigSetting GUI_FILTER_WHITELIST_ITEMS_BLOCKS_ITEM = new ConfigSetting(config, "gui.filter whitelist.items.blocks.item", XMaterial.GRASS_BLOCK.name());
public static final ConfigSetting GUI_FILTER_WHITELIST_ITEMS_BLOCKS_NAME = new ConfigSetting(config, "gui.filter whitelist.items.blocks.name", "&e&lBlock Filters");
public static final ConfigSetting GUI_FILTER_WHITELIST_ITEMS_BLOCKS_LORE = new ConfigSetting(config, "gui.filter whitelist.items.blocks.lore", Collections.singletonList("&7Click to adjust the item whitelist for this filter"));
public static final ConfigSetting GUI_FILTER_WHITELIST_ITEMS_FOOD_ITEM = new ConfigSetting(config, "gui.filter whitelist.items.food.item", XMaterial.CAKE.name());
public static final ConfigSetting GUI_FILTER_WHITELIST_ITEMS_FOOD_NAME = new ConfigSetting(config, "gui.filter whitelist.items.food.name", "&e&lFood Filters");
public static final ConfigSetting GUI_FILTER_WHITELIST_ITEMS_FOOD_LORE = new ConfigSetting(config, "gui.filter whitelist.items.food.lore", Collections.singletonList("&7Click to adjust the item whitelist for this filter"));
public static final ConfigSetting GUI_FILTER_WHITELIST_ITEMS_ARMOR_ITEM = new ConfigSetting(config, "gui.filter whitelist.items.armor.item", XMaterial.DIAMOND_HELMET.name());
public static final ConfigSetting GUI_FILTER_WHITELIST_ITEMS_ARMOR_NAME = new ConfigSetting(config, "gui.filter whitelist.items.armor.name", "&e&LArmor Filters");
public static final ConfigSetting GUI_FILTER_WHITELIST_ITEMS_ARMOR_LORE = new ConfigSetting(config, "gui.filter whitelist.items.armor.lore", Collections.singletonList("&7Click to adjust the item whitelist for this filter"));
public static final ConfigSetting GUI_FILTER_WHITELIST_ITEMS_TOOLS_ITEM = new ConfigSetting(config, "gui.filter whitelist.items.tools.item", XMaterial.IRON_PICKAXE.name());
public static final ConfigSetting GUI_FILTER_WHITELIST_ITEMS_TOOLS_NAME = new ConfigSetting(config, "gui.filter whitelist.items.tools.name", "&e&lTool Filters");
public static final ConfigSetting GUI_FILTER_WHITELIST_ITEMS_TOOLS_LORE = new ConfigSetting(config, "gui.filter whitelist.items.tools.lore", Collections.singletonList("&7Click to adjust the item whitelist for this filter"));
public static final ConfigSetting GUI_FILTER_WHITELIST_ITEMS_SPAWNERS_ITEM = new ConfigSetting(config, "gui.filter whitelist.items.spawners.item", XMaterial.SPAWNER.name());
public static final ConfigSetting GUI_FILTER_WHITELIST_ITEMS_SPAWNERS_NAME = new ConfigSetting(config, "gui.filter whitelist.items.spawners.name", "&e&lSpawner Filters");
public static final ConfigSetting GUI_FILTER_WHITELIST_ITEMS_SPAWNERS_LORE = new ConfigSetting(config, "gui.filter whitelist.items.spawners.lore", Collections.singletonList("&7Click to adjust the item whitelist for this filter"));
public static final ConfigSetting GUI_FILTER_WHITELIST_ITEMS_ENCHANTS_ITEM = new ConfigSetting(config, "gui.filter whitelist.items.enchants.item", XMaterial.ENCHANTED_BOOK.name());
public static final ConfigSetting GUI_FILTER_WHITELIST_ITEMS_ENCHANTS_NAME = new ConfigSetting(config, "gui.filter whitelist.items.enchants.name", "&e&lEnchantment Filters");
public static final ConfigSetting GUI_FILTER_WHITELIST_ITEMS_ENCHANTS_LORE = new ConfigSetting(config, "gui.filter whitelist.items.enchants.lore", Collections.singletonList("&7Click to adjust the item whitelist for this filter"));
public static final ConfigSetting GUI_FILTER_WHITELIST_ITEMS_WEAPONS_ITEM = new ConfigSetting(config, "gui.filter whitelist.items.weapons.item", XMaterial.DIAMOND_SWORD.name());
public static final ConfigSetting GUI_FILTER_WHITELIST_ITEMS_WEAPONS_NAME = new ConfigSetting(config, "gui.filter whitelist.items.weapons.name", "&e&lWeapon Filters");
public static final ConfigSetting GUI_FILTER_WHITELIST_ITEMS_WEAPONS_LORE = new ConfigSetting(config, "gui.filter whitelist.items.weapons.lore", Collections.singletonList("&7Click to adjust the item whitelist for this filter"));
public static final ConfigSetting GUI_FILTER_WHITELIST_ITEMS_MISC_ITEM = new ConfigSetting(config, "gui.filter whitelist.items.misc.item", XMaterial.BONE_MEAL.name());
public static final ConfigSetting GUI_FILTER_WHITELIST_ITEMS_MISC_NAME = new ConfigSetting(config, "gui.filter whitelist.items.misc.name", "&e&lMiscellaneous Filters");
public static final ConfigSetting GUI_FILTER_WHITELIST_ITEMS_MISC_LORE = new ConfigSetting(config, "gui.filter whitelist.items.misc.lore", Collections.singletonList("&7Click to adjust the item whitelist for this filter"));
/* ===============================
* CUSTOM ITEM FILTER GUI
* ===============================*/
public static final ConfigSetting GUI_FILTER_WHITELIST_LIST_TITLE = new ConfigSetting(config, "gui.filter whitelist list.title", "&7Filter Whitelist - &e%filter_category%");
public static final ConfigSetting GUI_FILTER_WHITELIST_LIST_BG_ITEM = new ConfigSetting(config, "gui.filter whitelist list.bg item", XMaterial.BLACK_STAINED_GLASS_PANE.name());
/* ===============================
* AUCTION STACKS

View File

@ -28,6 +28,7 @@ public class AutoSaveTask extends BukkitRunnable {
public void run() {
AuctionHouse.getInstance().getAuctionItemManager().saveItems(Settings.DATABASE_USE.getBoolean(), true);
AuctionHouse.getInstance().getTransactionManager().saveTransactions(Settings.DATABASE_USE.getBoolean(), true);
AuctionHouse.getInstance().getFilterManager().saveFilterWhitelist(Settings.DATABASE_USE.getBoolean(), true);
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&aAuto saved auction items & transactions")).sendPrefixedMessage(Bukkit.getConsoleSender());
}
}

View File

@ -29,6 +29,7 @@ permissions:
auctionhouse.cmd.upload: true
auctionhouse.cmd.status: true
auctionhouse.cmd.admin: true
auctionhouse.cmd.filter: true
auctionhouse.cmd:
description: Allows the user to use /ah
default: op
@ -61,4 +62,7 @@ permissions:
default: op
auctionhouse.cmd.admin:
description: Allows the user to access admin commands
default: op
auctionhouse.cmd.filter:
description: Allows the user to access the filter whitelist menu
default: op