mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-01-03 13:57:35 +01:00
Ignore signs and transactions made by players with invalid names
This commit is contained in:
parent
2305c759b8
commit
435bf0f3cc
@ -319,6 +319,7 @@ public class ChestShop extends JavaPlugin {
|
|||||||
registerEvent(new AmountAndPriceChecker());
|
registerEvent(new AmountAndPriceChecker());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registerEvent(new InvalidNameIgnorer());
|
||||||
registerEvent(new CreativeModeIgnorer());
|
registerEvent(new CreativeModeIgnorer());
|
||||||
registerEvent(new ErrorMessageSender());
|
registerEvent(new ErrorMessageSender());
|
||||||
registerEvent(new PermissionChecker());
|
registerEvent(new PermissionChecker());
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.Acrobot.ChestShop.Listeners.PreTransaction;
|
||||||
|
|
||||||
|
import com.Acrobot.ChestShop.Events.PreTransactionEvent;
|
||||||
|
import com.Acrobot.ChestShop.Signs.ChestShopSign;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class InvalidNameIgnorer implements Listener {
|
||||||
|
|
||||||
|
private final static Pattern USERNAME_PATTERN = Pattern.compile("^\\w+$");
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public static void onPreTransaction(PreTransactionEvent event) {
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String name = event.getClient().getName();
|
||||||
|
if (ChestShopSign.isAdminShop(name) || !USERNAME_PATTERN.matcher(name).matches()) {
|
||||||
|
event.setCancelled(PreTransactionEvent.TransactionOutcome.CLIENT_DOES_NOT_HAVE_PERMISSION);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -26,10 +26,10 @@ public class ChestShopSign {
|
|||||||
public static final byte ITEM_LINE = 3;
|
public static final byte ITEM_LINE = 3;
|
||||||
|
|
||||||
public static final Pattern[] SHOP_SIGN_PATTERN = {
|
public static final Pattern[] SHOP_SIGN_PATTERN = {
|
||||||
Pattern.compile("^?[\\w -.:]*$"),
|
Pattern.compile("^?[\\w \\-.:]*$"),
|
||||||
Pattern.compile("^[1-9][0-9]{0,5}$"),
|
Pattern.compile("^[1-9][0-9]{0,5}$"),
|
||||||
Pattern.compile("(?i)^[\\d.bs(free) :]+$"),
|
Pattern.compile("(?i)^[\\d.bs(free) :]+$"),
|
||||||
Pattern.compile("^[\\w? #:-]+$")
|
Pattern.compile("^[\\w? #:\\-]+$")
|
||||||
};
|
};
|
||||||
public static final String AUTOFILL_CODE = "?";
|
public static final String AUTOFILL_CODE = "?";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user