mirror of
https://github.com/bloodmc/GriefDefender.git
synced 2025-01-07 19:38:56 +01:00
Fix some issues with new option GUI.
* Don't set transient option if a persisted one exists. * Add 'economy-block-cost' check for claim creation in economy mode.
This commit is contained in:
parent
1f812f367e
commit
c086316c23
@ -272,10 +272,10 @@ public int getInitialClaimBlocks() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public double getEconomyBlockCost() {
|
||||
public double getInternalEconomyBlockCost() {
|
||||
final Double value = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Double.class), this.getSubject(), Options.ECONOMY_BLOCK_COST);
|
||||
if (value == null) {
|
||||
return Options.INITIAL_BLOCKS.getDefaultValue();
|
||||
return Options.ECONOMY_BLOCK_COST.getDefaultValue();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@ -328,7 +328,7 @@ public int getInternalEconomyAvailablePurchaseCost() {
|
||||
}
|
||||
|
||||
final double currentFunds = this.vaultProvider.getApi().getBalance(this.getSubject().getOfflinePlayer());
|
||||
final Double economyBlockCost = this.getEconomyBlockCost();
|
||||
final Double economyBlockCost = this.getInternalEconomyBlockCost();
|
||||
return (int) Math.round((currentFunds / economyBlockCost));
|
||||
}
|
||||
return 0;
|
||||
|
@ -218,7 +218,7 @@ protected void showCustomFlags(GDPermissionUser src, GDClaim claim, String displ
|
||||
for (String group : groups) {
|
||||
flagHeadBuilder.append(" ").append(displayGroup.equalsIgnoreCase(group) ? TextComponent.builder()
|
||||
.append(whiteOpenBracket)
|
||||
.append(group.toUpperCase(), flagGroupCat.isAdminGroup() ? TextColor.RED : TextColor.GOLD)
|
||||
.append(group.toUpperCase(), flagGroups.get(group).isAdminGroup() ? TextColor.RED : TextColor.GOLD)
|
||||
.append(whiteCloseBracket).build() :
|
||||
TextComponent.builder().append(group.toUpperCase(), TextColor.GRAY)
|
||||
.clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(createCustomFlagConsumer(src, claim, group))))
|
||||
@ -388,16 +388,18 @@ protected void showFlagPermissions(GDPermissionUser src, GDClaim claim, MenuType
|
||||
if (contextSet.contains(claim.getDefaultTypeContext())) {
|
||||
this.addFilteredContexts(filteredContextMap, contextSet, MenuType.DEFAULT, mapEntry.getValue());
|
||||
}
|
||||
if (contextSet.contains(claim.getContext())) {
|
||||
this.addFilteredContexts(filteredContextMap, contextSet, MenuType.CLAIM, mapEntry.getValue());
|
||||
}
|
||||
if (contextSet.contains(ClaimContexts.GLOBAL_OVERRIDE_CONTEXT)) {
|
||||
this.addFilteredContexts(filteredContextMap, contextSet, MenuType.OVERRIDE, mapEntry.getValue());
|
||||
}
|
||||
if (contextSet.contains(claim.getOverrideClaimContext())) {
|
||||
this.addFilteredContexts(filteredContextMap, contextSet, MenuType.OVERRIDE, mapEntry.getValue());
|
||||
} else if (contextSet.contains(claim.getOverrideTypeContext())) {
|
||||
this.addFilteredContexts(filteredContextMap, contextSet, MenuType.OVERRIDE, mapEntry.getValue());
|
||||
if (displayType != MenuType.DEFAULT) {
|
||||
if (contextSet.contains(claim.getContext())) {
|
||||
this.addFilteredContexts(filteredContextMap, contextSet, MenuType.CLAIM, mapEntry.getValue());
|
||||
}
|
||||
if (contextSet.contains(ClaimContexts.GLOBAL_OVERRIDE_CONTEXT)) {
|
||||
this.addFilteredContexts(filteredContextMap, contextSet, MenuType.OVERRIDE, mapEntry.getValue());
|
||||
}
|
||||
if (contextSet.contains(claim.getOverrideClaimContext())) {
|
||||
this.addFilteredContexts(filteredContextMap, contextSet, MenuType.OVERRIDE, mapEntry.getValue());
|
||||
} else if (contextSet.contains(claim.getOverrideTypeContext())) {
|
||||
this.addFilteredContexts(filteredContextMap, contextSet, MenuType.OVERRIDE, mapEntry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -533,7 +535,16 @@ private Component getCustomClickableText(GDPermissionUser src, GDClaim claim, GD
|
||||
Map<CustomFlagData, Tristate> dataResults = new HashMap<>();
|
||||
for (CustomFlagData flagData : customFlag.getFlagData()) {
|
||||
Set<Context> newContexts = new HashSet<>(flagData.getContexts());
|
||||
newContexts.add(claim.getContext());
|
||||
boolean hasGDContext = false;
|
||||
for (Context context : newContexts) {
|
||||
if (context.getKey().contains("gd_claim")) {
|
||||
hasGDContext = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hasGDContext) {
|
||||
newContexts.add(claim.getContext());
|
||||
}
|
||||
Tristate result = PermissionUtil.getInstance().getPermissionValue(claim, GriefDefenderPlugin.DEFAULT_HOLDER, flagData.getFlag().getPermission(), newContexts);
|
||||
dataResults.put(flagData, result);
|
||||
}
|
||||
|
@ -335,6 +335,23 @@ protected void showOptionPermissions(GDPermissionUser src, GDClaim claim, MenuTy
|
||||
}
|
||||
}
|
||||
|
||||
if (displayType == MenuType.DEFAULT) {
|
||||
final Set<Context> contexts = new HashSet<>();
|
||||
contexts.add(ClaimContexts.GLOBAL_DEFAULT_CONTEXT);
|
||||
for (Option option : OptionRegistryModule.getInstance().getAll()) {
|
||||
boolean found = false;
|
||||
for (Entry<String, OptionData> optionEntry : filteredContextMap.entrySet()) {
|
||||
if (optionEntry.getValue().option == option) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
filteredContextMap.put(option.getPermission(), new OptionData(option, "undefined", displayType, contexts));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<Set<Context>, Map<String, String>> mapEntry : PermissionUtil.getInstance().getPermanentOptions(this.subject).entrySet()) {
|
||||
final Set<Context> contextSet = mapEntry.getKey();
|
||||
if (contextSet.contains(ClaimContexts.GLOBAL_DEFAULT_CONTEXT)) {
|
||||
@ -343,16 +360,18 @@ protected void showOptionPermissions(GDPermissionUser src, GDClaim claim, MenuTy
|
||||
if (contextSet.contains(claim.getDefaultTypeContext())) {
|
||||
this.addFilteredContexts(src, filteredContextMap, contextSet, MenuType.DEFAULT, mapEntry.getValue());
|
||||
}
|
||||
if (claim.isTown() && contextSet.contains(claim.getContext())) {
|
||||
this.addFilteredContexts(src, filteredContextMap, contextSet, MenuType.CLAIM, mapEntry.getValue());
|
||||
}
|
||||
if (contextSet.contains(ClaimContexts.GLOBAL_OVERRIDE_CONTEXT)) {
|
||||
this.addFilteredContexts(src, filteredContextMap, contextSet, MenuType.OVERRIDE, mapEntry.getValue());
|
||||
}
|
||||
if (contextSet.contains(claim.getOverrideClaimContext())) {
|
||||
this.addFilteredContexts(src, filteredContextMap, contextSet, MenuType.OVERRIDE, mapEntry.getValue());
|
||||
} else if (contextSet.contains(claim.getOverrideTypeContext())) {
|
||||
this.addFilteredContexts(src, filteredContextMap, contextSet, MenuType.OVERRIDE, mapEntry.getValue());
|
||||
if (displayType != MenuType.DEFAULT) {
|
||||
if (contextSet.contains(claim.getContext())) {
|
||||
this.addFilteredContexts(src, filteredContextMap, contextSet, MenuType.CLAIM, mapEntry.getValue());
|
||||
}
|
||||
if (contextSet.contains(ClaimContexts.GLOBAL_OVERRIDE_CONTEXT)) {
|
||||
this.addFilteredContexts(src, filteredContextMap, contextSet, MenuType.OVERRIDE, mapEntry.getValue());
|
||||
}
|
||||
if (contextSet.contains(claim.getOverrideClaimContext())) {
|
||||
this.addFilteredContexts(src, filteredContextMap, contextSet, MenuType.OVERRIDE, mapEntry.getValue());
|
||||
} else if (contextSet.contains(claim.getOverrideTypeContext())) {
|
||||
this.addFilteredContexts(src, filteredContextMap, contextSet, MenuType.OVERRIDE, mapEntry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -378,6 +397,9 @@ protected void showOptionPermissions(GDPermissionUser src, GDClaim claim, MenuTy
|
||||
if (displayType != MenuType.CLAIM && optionHolder.getType() != displayType) {
|
||||
continue;
|
||||
}
|
||||
if (option.getName().contains("tax") && !GriefDefenderPlugin.getGlobalConfig().getConfig().claim.bankTaxSystem) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final Set<Context> contexts = optionHolder.getAllContexts();
|
||||
Component optionText = getClickableOptionComponent(src, claim, option, optionHolder, contexts, displayType);
|
||||
|
@ -158,7 +158,7 @@ public void execute(CommandSender src, @Optional String[] args) throws InvalidCo
|
||||
final Component economyBlockAvailablePurchaseText = MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.PLAYERINFO_UI_ECONOMY_BLOCK_AVAILABLE_PURCHASE,
|
||||
ImmutableMap.of("amount", String.valueOf(playerData.getRemainingClaimBlocks())));
|
||||
final Component economyBlockCostText = MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.PLAYERINFO_UI_ECONOMY_BLOCK_COST,
|
||||
ImmutableMap.of("amount", String.valueOf("$" + playerData.getEconomyBlockCost())));
|
||||
ImmutableMap.of("amount", String.valueOf("$" + playerData.getInternalEconomyBlockCost())));
|
||||
final Component economyBlockSellReturnText = MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.PLAYERINFO_UI_ECONOMY_BLOCK_SELL_RETURN,
|
||||
ImmutableMap.of("amount", String.valueOf("$" + playerData.getEconomyClaimBlockReturn())));
|
||||
final Component minMaxLevelText = MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.PLAYERINFO_UI_CLAIM_LEVEL,
|
||||
|
@ -77,6 +77,8 @@
|
||||
import net.kyori.text.Component;
|
||||
import net.kyori.text.TextComponent;
|
||||
import net.kyori.text.adapter.bukkit.TextAdapter;
|
||||
import net.kyori.text.format.TextColor;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.GameMode;
|
||||
@ -1295,6 +1297,22 @@ private void createClaimStart(PlayerInteractEvent event, Player player, Location
|
||||
return;
|
||||
}
|
||||
|
||||
final ClaimType type = PlayerUtil.getInstance().getClaimTypeFromShovel(playerData.shovelMode);
|
||||
if ((type == ClaimTypes.BASIC || type == ClaimTypes.TOWN) && GriefDefenderPlugin.getGlobalConfig().getConfig().economy.economyMode) {
|
||||
// Check current economy mode cost
|
||||
final Double economyBlockCost = playerData.getInternalEconomyBlockCost();
|
||||
if (economyBlockCost == null || economyBlockCost <= 0) {
|
||||
GriefDefenderPlugin.sendMessage(player, TextComponent.builder().color(TextColor.RED)
|
||||
.append("Economy mode is enabled but the current cost for blocks is ")
|
||||
.append("0", TextColor.GOLD)
|
||||
.append("\nRaise the value for option 'economy-block-cost' in config or via '")
|
||||
.append("/gd option claim", TextColor.WHITE)
|
||||
.append("' command.", TextColor.RED)
|
||||
.build());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
playerData.revertActiveVisual(player);
|
||||
playerData.lastShovelLocation = location;
|
||||
final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.CLAIM_START,
|
||||
|
@ -73,6 +73,7 @@
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@ -391,6 +392,8 @@ private void setDefaultFlags(Set<Context> contexts, Map<String, Boolean> default
|
||||
}
|
||||
|
||||
private void setDefaultOptions(String type, Set<Context> contexts, Map<String, String> defaultOptions) {
|
||||
final Map<Set<Context>, Map<String, String>> permanentOptions = PermissionUtil.getInstance().getPermanentOptions(GriefDefenderPlugin.DEFAULT_HOLDER);
|
||||
final Map<String, String> options = permanentOptions.get(contexts);
|
||||
GriefDefenderPlugin.getInstance().executor.execute(() -> {
|
||||
for (Map.Entry<String, String> optionEntry : defaultOptions.entrySet()) {
|
||||
final Option option = OptionRegistryModule.getInstance().getById(optionEntry.getKey()).orElse(null);
|
||||
@ -401,6 +404,19 @@ private void setDefaultOptions(String type, Set<Context> contexts, Map<String, S
|
||||
if (!((GDOption) option).validateStringValue(optionEntry.getValue(), true)) {
|
||||
continue;
|
||||
}
|
||||
// Transient options are checked first so we must ignore setting if a persisted option exists
|
||||
boolean foundPersisted = false;
|
||||
if (options != null) {
|
||||
for (Entry<String, String> mapEntry : options.entrySet()) {
|
||||
if (mapEntry.getKey().equalsIgnoreCase(option.getPermission())) {
|
||||
foundPersisted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (foundPersisted) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
PermissionUtil.getInstance().setTransientOption(GriefDefenderPlugin.DEFAULT_HOLDER, option.getPermission(), optionEntry.getValue(), contexts);
|
||||
}
|
||||
PermissionUtil.getInstance().refreshCachedData(GriefDefenderPlugin.DEFAULT_HOLDER);
|
||||
|
@ -3,5 +3,5 @@ main: com.griefdefender.GDBootstrap
|
||||
softdepend: [WorldEdit, WorldGuard, Vault]
|
||||
depend: [LuckPerms]
|
||||
load: STARTUP
|
||||
version: '1.0.2'
|
||||
version: '1.2.0'
|
||||
api-version: 1.13
|
||||
|
Loading…
Reference in New Issue
Block a user