mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-01-08 08:08:05 +01:00
Move account access check to an event
This should be the final addition that allows other plugins to implement multi-owner/group shops like requested in #119 and #133 by listening to all the transaction events to handle money flow and shop/account access events to enable access to the actual shop.
This commit is contained in:
parent
c6f6672188
commit
3bed1261aa
@ -0,0 +1,57 @@
|
||||
package com.Acrobot.ChestShop.Events;
|
||||
|
||||
import com.Acrobot.ChestShop.Database.Account;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
/**
|
||||
* Represents an access request for a specific account.
|
||||
*/
|
||||
public class AccountAccessEvent extends PlayerEvent {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private final Account account;
|
||||
private boolean canAccess = false;
|
||||
|
||||
public AccountAccessEvent(Player player, Account account) {
|
||||
super(player);
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
/**
|
||||
* The account to check the access for
|
||||
*
|
||||
* @return The account
|
||||
*/
|
||||
public Account getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the player can access the account.
|
||||
*
|
||||
* @return Whether or not the player can access the account
|
||||
*/
|
||||
public boolean canAccess() {
|
||||
return canAccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether or not the player can access the account.
|
||||
*
|
||||
* @param canAccess Whether or not the player can access the account
|
||||
*/
|
||||
public void setAccess(boolean canAccess) {
|
||||
this.canAccess = canAccess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
}
|
@ -7,6 +7,7 @@ import com.Acrobot.ChestShop.ChestShop;
|
||||
import com.Acrobot.ChestShop.Configuration.Properties;
|
||||
import com.Acrobot.ChestShop.Database.Account;
|
||||
import com.Acrobot.ChestShop.Database.DaoCreator;
|
||||
import com.Acrobot.ChestShop.Events.AccountAccessEvent;
|
||||
import com.Acrobot.ChestShop.Events.AccountQueryEvent;
|
||||
import com.Acrobot.ChestShop.Permission;
|
||||
import com.Acrobot.ChestShop.Signs.ChestShopSign;
|
||||
@ -363,8 +364,22 @@ public class NameManager implements Listener {
|
||||
}
|
||||
|
||||
Account account = getAccountFromShortName(name, false);
|
||||
return account != null && (account.getUuid().equals(player.getUniqueId())
|
||||
|| (!account.getName().equalsIgnoreCase(name) && Permission.otherName(player, base, account.getName())));
|
||||
if (account == null) {
|
||||
return false;
|
||||
}
|
||||
if (!account.getName().equalsIgnoreCase(name) && Permission.otherName(player, base, account.getName())) {
|
||||
return true;
|
||||
}
|
||||
AccountAccessEvent event = new AccountAccessEvent(player, account);
|
||||
ChestShop.callEvent(event);
|
||||
return event.canAccess();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public static void onAccountAccessCheck(AccountAccessEvent event) {
|
||||
if (!event.canAccess()) {
|
||||
event.setAccess(event.getPlayer().getUniqueId().equals(event.getAccount().getUuid()));
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isAdminShop(UUID uuid) {
|
||||
|
Loading…
Reference in New Issue
Block a user