mirror of
https://github.com/kiranhart/Auction-House.git
synced 2025-02-16 19:21:20 +01:00
created a command "middleware" to perform checks easier across all commands
This commit is contained in:
parent
f1dbcc4eea
commit
96830d5ac8
24
pom.xml
24
pom.xml
@ -6,7 +6,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>ca.tweetzy</groupId>
|
||||
<artifactId>auctionhouse</artifactId>
|
||||
<version>2.45.0</version>
|
||||
<version>2.45.1</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
@ -180,14 +180,8 @@
|
||||
<url>https://nexus.neetgames.com/repository/maven-releases/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>opencollab-snapshot-repo</id>
|
||||
<id>opencollab-snapshot</id>
|
||||
<url>https://repo.opencollab.dev/maven-snapshots/</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
@ -200,7 +194,7 @@
|
||||
<dependency>
|
||||
<groupId>ca.tweetzy</groupId>
|
||||
<artifactId>tweetycore</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.gmail.nossr50.mcMMO</groupId>
|
||||
@ -240,12 +234,12 @@
|
||||
<version>1.4.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.geysermc</groupId>-->
|
||||
<!-- <artifactId>core</artifactId>-->
|
||||
<!-- <version>2.0.0-SNAPSHOT</version>-->
|
||||
<!-- <scope>provided</scope>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>org.geysermc.floodgate</groupId>
|
||||
<artifactId>api</artifactId>
|
||||
|
@ -1,10 +1,27 @@
|
||||
package ca.tweetzy.auctionhouse.api.hook;
|
||||
|
||||
import ca.tweetzy.auctionhouse.settings.Settings;
|
||||
import lombok.NonNull;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.geysermc.floodgate.api.FloodgateApi;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: December 14 2021
|
||||
* Time Created: 1:57 p.m.
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
|
||||
*/
|
||||
@UtilityClass
|
||||
public final class FloodGateHook {
|
||||
|
||||
private boolean isFloodGateActive() {
|
||||
return Bukkit.getServer().getPluginManager().isPluginEnabled("floodgate");
|
||||
}
|
||||
|
||||
public boolean isFloodGateUser(@NonNull final Player player) {
|
||||
if (!isFloodGateActive()) return false;
|
||||
return !Settings.ALLOW_FLOODGATE_PLAYERS.getBoolean() && FloodgateApi.getInstance().isFloodgatePlayer(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
@ -29,15 +29,7 @@ public class CommandActive extends AbstractCommand {
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
if (AuctionAPI.tellMigrationStatus(player)) return ReturnType.FAILURE;
|
||||
if (Settings.USE_AUCTION_CHEST_MODE.getBoolean()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.visit auction chest").sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
if (AuctionHouse.getInstance().getAuctionBanManager().checkAndHandleBan(player)) {
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE;
|
||||
|
||||
if (AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) {
|
||||
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender());
|
||||
|
@ -31,15 +31,8 @@ public class CommandAuctionHouse extends AbstractCommand {
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if (AuctionAPI.tellMigrationStatus(player)) return ReturnType.FAILURE;
|
||||
if (Settings.USE_AUCTION_CHEST_MODE.getBoolean()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.visit auction chest").sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
if (AuctionHouse.getInstance().getAuctionBanManager().checkAndHandleBan(player)) {
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE;
|
||||
|
||||
if (AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) {
|
||||
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender());
|
||||
|
@ -33,7 +33,7 @@ public class CommandBan extends AbstractCommand {
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
Player player = (Player) sender;
|
||||
if (AuctionAPI.tellMigrationStatus(player)) return ReturnType.FAILURE;
|
||||
if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE;
|
||||
|
||||
if (args.length == 0) {
|
||||
// Open the bans menu
|
||||
|
@ -28,16 +28,7 @@ public class CommandExpired extends AbstractCommand {
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
Player player = (Player) sender;
|
||||
if (AuctionAPI.tellMigrationStatus(player)) return ReturnType.FAILURE;
|
||||
|
||||
if (Settings.USE_AUCTION_CHEST_MODE.getBoolean()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.visit auction chest").sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
if (AuctionHouse.getInstance().getAuctionBanManager().checkAndHandleBan(player)) {
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE;
|
||||
|
||||
if (AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) {
|
||||
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender());
|
||||
|
@ -32,7 +32,7 @@ public class CommandFilter extends AbstractCommand {
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
Player player = (Player) sender;
|
||||
if (AuctionAPI.tellMigrationStatus(player)) return ReturnType.FAILURE;
|
||||
if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE;
|
||||
|
||||
if (args.length == 0) {
|
||||
AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIFilterWhitelist());
|
||||
|
@ -28,10 +28,11 @@ public final class CommandMarkChest extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (AuctionAPI.tellMigrationStatus(sender)) return ReturnType.FAILURE;
|
||||
if (!ServerVersion.isServerVersionAtLeast(ServerVersion.V1_14)) return ReturnType.FAILURE;
|
||||
final Player player = (Player) sender;
|
||||
|
||||
if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE;
|
||||
|
||||
final Block targetBlock = player.getTargetBlock(null, 10);
|
||||
if (targetBlock.getType() != XMaterial.CHEST.parseMaterial()) return ReturnType.FAILURE;
|
||||
|
||||
|
@ -0,0 +1,36 @@
|
||||
package ca.tweetzy.auctionhouse.commands;
|
||||
|
||||
import ca.tweetzy.auctionhouse.AuctionHouse;
|
||||
import ca.tweetzy.auctionhouse.api.AuctionAPI;
|
||||
import ca.tweetzy.auctionhouse.api.hook.FloodGateHook;
|
||||
import ca.tweetzy.auctionhouse.settings.Settings;
|
||||
import ca.tweetzy.core.commands.AbstractCommand;
|
||||
import lombok.NonNull;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: December 14 2021
|
||||
* Time Created: 2:19 p.m.
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
|
||||
*/
|
||||
@UtilityClass
|
||||
public final class CommandMiddleware {
|
||||
|
||||
public AbstractCommand.ReturnType handle(@NonNull final Player player) {
|
||||
if (AuctionAPI.tellMigrationStatus(player)) return AbstractCommand.ReturnType.FAILURE;
|
||||
if (Settings.USE_AUCTION_CHEST_MODE.getBoolean()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.visit auction chest").sendPrefixedMessage(player);
|
||||
return AbstractCommand.ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
if (AuctionHouse.getInstance().getAuctionBanManager().checkAndHandleBan(player)) {
|
||||
return AbstractCommand.ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
if (FloodGateHook.isFloodGateUser(player)) return AbstractCommand.ReturnType.FAILURE;
|
||||
|
||||
return AbstractCommand.ReturnType.SUCCESS;
|
||||
}
|
||||
}
|
@ -29,16 +29,8 @@ public class CommandSearch extends AbstractCommand {
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length <= 0) return ReturnType.SYNTAX_ERROR;
|
||||
Player player = (Player) sender;
|
||||
if (AuctionAPI.tellMigrationStatus(player)) return ReturnType.FAILURE;
|
||||
|
||||
if (Settings.USE_AUCTION_CHEST_MODE.getBoolean()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.visit auction chest").sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
if (AuctionHouse.getInstance().getAuctionBanManager().checkAndHandleBan(player)) {
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE;
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (String arg : args) {
|
||||
|
@ -39,16 +39,8 @@ public final class CommandSell extends AbstractCommand {
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
Player player = (Player) sender;
|
||||
if (AuctionAPI.tellMigrationStatus(player)) return ReturnType.FAILURE;
|
||||
|
||||
if (Settings.USE_AUCTION_CHEST_MODE.getBoolean()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.visit auction chest").sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
if (AuctionHouse.getInstance().getAuctionBanManager().checkAndHandleBan(player)) {
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE;
|
||||
|
||||
AuctionPlayer auctionPlayer = AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId());
|
||||
|
||||
|
@ -23,8 +23,9 @@ public class CommandStatus extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (AuctionAPI.tellMigrationStatus(sender)) return ReturnType.FAILURE;
|
||||
Player player = (Player) sender;
|
||||
if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE;
|
||||
|
||||
AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIStats(player));
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
@ -25,16 +25,8 @@ public class CommandTransactions extends AbstractCommand {
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
Player player = (Player) sender;
|
||||
if (AuctionAPI.tellMigrationStatus(player)) return ReturnType.FAILURE;
|
||||
|
||||
if (Settings.USE_AUCTION_CHEST_MODE.getBoolean()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.visit auction chest").sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
if (AuctionHouse.getInstance().getAuctionBanManager().checkAndHandleBan(player)) {
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE;
|
||||
|
||||
AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUITransactionType());
|
||||
return ReturnType.SUCCESS;
|
||||
|
@ -49,6 +49,8 @@ public class Settings {
|
||||
public static final ConfigSetting INCREASE_TIME_ON_BID = new ConfigSetting(config, "auction setting.increase time on bid", true, "Should the remaining time be increased when a bid is placed?");
|
||||
public static final ConfigSetting TIME_TO_INCREASE_BY_ON_BID = new ConfigSetting(config, "auction setting.time to increase by on the bid", 20, "How many seconds should be added to the remaining time?");
|
||||
public static final ConfigSetting ALLOW_SALE_OF_DAMAGED_ITEMS = new ConfigSetting(config, "auction setting.allow sale of damaged items", true, "If true, player's can sell items that are damaged (not max durability)");
|
||||
public static final ConfigSetting ALLOW_FLOODGATE_PLAYERS = new ConfigSetting(config, "auction setting.allow flood gate players", false, "If true, player's who connected using floodgate (bedrock players) won't be able to use the auction house");
|
||||
public static final ConfigSetting RESTRICT_ALL_TRANSACTIONS_TO_PERM = new ConfigSetting(config, "auction setting.restrict viewing all transactions", false, "If true, player's will need the perm: auctionhouse.transactions.viewall to view all transactions");
|
||||
|
||||
public static final ConfigSetting TICK_UPDATE_TIME = new ConfigSetting(config, "auction setting.tick auctions every", 1, "How many seconds should pass before the plugin updates all the times on items?");
|
||||
public static final ConfigSetting CLAIM_MS_DELAY = new ConfigSetting(config, "auction setting.item claim delay", 100, "How many ms should a player wait before being allowed to claim an item?, Ideally you don't wanna change this. It's meant to prevent auto clicker dupe claims");
|
||||
@ -92,7 +94,6 @@ public class Settings {
|
||||
public static final ConfigSetting SYNC_BASE_PRICE_TO_HIGHEST_PRICE = new ConfigSetting(config, "auction setting.sync the base price to the current price", true, "Ex. If the buy now price was 100, and the current price exceeds 100 to say 200, the buy now price will become 200.");
|
||||
|
||||
public static final ConfigSetting CURRENCY_FORMAT = new ConfigSetting(config, "auction setting.currency format", "%,.2f");
|
||||
// public static final ConfigSetting CURRENCY_DECIMAL_FORMAT = new ConfigSetting(config, "auction setting.currency decimal format", "#,###.#", "Primarily used for the short number format");
|
||||
|
||||
public static final ConfigSetting USE_ALTERNATE_CURRENCY_FORMAT = new ConfigSetting(config, "auction setting.use alternate currency format", false, "If true, $123,456.78 will become $123.456,78");
|
||||
public static final ConfigSetting USE_FLAT_NUMBER_FORMAT = new ConfigSetting(config, "auction setting.use flat number format", false, "If true, $123,456.78 will become $12345678");
|
||||
|
Loading…
Reference in New Issue
Block a user