parent
c028015d5e
commit
88a23a38db
|
@ -5,6 +5,7 @@ import com.Acrobot.ChestShop.Commands.Give;
|
|||
import com.Acrobot.ChestShop.Commands.ItemInfo;
|
||||
import com.Acrobot.ChestShop.Commands.Toggle;
|
||||
import com.Acrobot.ChestShop.Commands.Version;
|
||||
import com.Acrobot.ChestShop.Commands.AccessToggle;
|
||||
import com.Acrobot.ChestShop.Configuration.Messages;
|
||||
import com.Acrobot.ChestShop.Configuration.Properties;
|
||||
import com.Acrobot.ChestShop.Database.Migrations;
|
||||
|
@ -108,6 +109,7 @@ public class ChestShop extends JavaPlugin {
|
|||
registerCommand("csVersion", new Version(), Permission.ADMIN);
|
||||
registerCommand("csGive", new Give(), Permission.ADMIN);
|
||||
registerCommand("cstoggle", new Toggle(), Permission.NOTIFY_TOGGLE);
|
||||
registerCommand("csaccess", new AccessToggle(), Permission.ACCESS_TOGGLE);
|
||||
|
||||
loadConfig();
|
||||
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
package com.Acrobot.ChestShop.Commands;
|
||||
|
||||
import com.Acrobot.ChestShop.Configuration.Messages;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author g--o
|
||||
*/
|
||||
public class AccessToggle implements CommandExecutor {
|
||||
private static final Set<UUID> toggledPlayers = new HashSet<>();
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
|
||||
if (setIgnoring(player, !isIgnoring(player))) {
|
||||
player.sendMessage(Messages.prefix(Messages.TOGGLE_ACCESS_OFF));
|
||||
} else {
|
||||
player.sendMessage(Messages.prefix(Messages.TOGGLE_ACCESS_ON));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isIgnoring(OfflinePlayer player) {
|
||||
return player != null && isIgnoring(player.getUniqueId());
|
||||
}
|
||||
|
||||
private static boolean isIgnoring(UUID playerId) {
|
||||
return toggledPlayers.contains(playerId);
|
||||
}
|
||||
|
||||
public static boolean setIgnoring(Player player, boolean ignoring) {
|
||||
Validate.notNull(player); // Make sure the player instance is not null, in case there are any errors in the code
|
||||
|
||||
if (ignoring) {
|
||||
toggledPlayers.add(player.getUniqueId());
|
||||
} else {
|
||||
toggledPlayers.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
return ignoring;
|
||||
}
|
||||
}
|
|
@ -83,6 +83,10 @@ public class Messages {
|
|||
public static String TOGGLE_MESSAGES_OFF = "You will no longer receive messages from your shop(s).";
|
||||
public static String TOGGLE_MESSAGES_ON = "You will now receive messages from your shop(s).";
|
||||
|
||||
@PrecededBySpace
|
||||
public static String TOGGLE_ACCESS_ON = "You can no longer trade at shops that you have access to";
|
||||
public static String TOGGLE_ACCESS_OFF = "You can now trade at shops that you have access to";
|
||||
|
||||
public static String prefix(String message) {
|
||||
return Configuration.getColoured(prefix + message);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.Acrobot.ChestShop.Listeners.Player;
|
||||
|
||||
import com.Acrobot.Breeze.Utils.*;
|
||||
import com.Acrobot.ChestShop.Commands.AccessToggle;
|
||||
import com.Acrobot.ChestShop.Configuration.Messages;
|
||||
import com.Acrobot.ChestShop.Configuration.Properties;
|
||||
import com.Acrobot.ChestShop.Containers.AdminInventory;
|
||||
|
@ -40,7 +41,6 @@ import static com.Acrobot.Breeze.Utils.BlockUtil.isSign;
|
|||
import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType;
|
||||
import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.BUY;
|
||||
import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.SELL;
|
||||
import static com.Acrobot.ChestShop.Permission.OTHER_NAME_ACCESS;
|
||||
import static com.Acrobot.ChestShop.Permission.OTHER_NAME_CREATE;
|
||||
import static com.Acrobot.ChestShop.Permission.OTHER_NAME_DESTROY;
|
||||
import static com.Acrobot.ChestShop.Signs.ChestShopSign.*;
|
||||
|
@ -114,8 +114,7 @@ public class PlayerInteract implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
if (ChestShopSign.hasPermission(player, OTHER_NAME_ACCESS, sign) && !ChestShopSign.isAdminShop(sign)) {
|
||||
if (!AccessToggle.isIgnoring(player) && ChestShopSign.canAccess(player, sign) && !ChestShopSign.isAdminShop(sign)) {
|
||||
if (Properties.IGNORE_ACCESS_PERMS || ChestShopSign.isOwner(player, sign)) {
|
||||
if (Properties.ALLOW_SIGN_CHEST_OPEN && !(Properties.IGNORE_CREATIVE_MODE && player.getGameMode() == GameMode.CREATIVE)) {
|
||||
if (player.isSneaking() || player.isInsideVehicle()
|
||||
|
|
|
@ -40,6 +40,7 @@ public enum Permission {
|
|||
NO_SELL_TAX("ChestShop.notax.sell"),
|
||||
|
||||
NOTIFY_TOGGLE("ChestShop.toggle"),
|
||||
ACCESS_TOGGLE("ChestShop.accesstoggle"),
|
||||
ITEMINFO("ChestShop.iteminfo");
|
||||
|
||||
private final String permission;
|
||||
|
|
|
@ -25,6 +25,9 @@ commands:
|
|||
cstoggle:
|
||||
description: Toggle messages to the owner of a shop
|
||||
usage: /<command>
|
||||
csaccess:
|
||||
description: Allows trading at shops that you have access to
|
||||
usage: /<command>
|
||||
|
||||
permissions:
|
||||
ChestShop.*:
|
||||
|
@ -72,6 +75,9 @@ permissions:
|
|||
ChestShop.toggle:
|
||||
description: Allows user to toggle messages.
|
||||
default: true
|
||||
ChestShop.accesstoggle:
|
||||
description: Allows toggling of trading at shops that you have access to.
|
||||
default: op
|
||||
ChestShop.iteminfo:
|
||||
description: Allows user to see item info with the command.
|
||||
default: true
|
||||
|
|
Loading…
Reference in New Issue