Add more logical perms and remove stupid settings.

This commit is contained in:
Brianna 2020-04-30 12:23:28 -04:00
parent e5abde1edd
commit 8c3d95fb94
9 changed files with 23 additions and 31 deletions

View File

@ -48,8 +48,7 @@ public class CommandKit extends AbstractCommand {
if (!(sender instanceof Player))
return ReturnType.NEEDS_PLAYER;
if (!kit.hasPermission((Player) sender)) {
if (!kit.hasPermissionToClaim((Player) sender)) {
instance.getLocale().getMessage("command.general.noperms").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}

View File

@ -25,7 +25,7 @@ public class CategorySelectorGui extends Gui {
Set<Category> categories = new LinkedHashSet<>();
for (Kit kit : plugin.getKitManager().getKits())
if (kit.hasPermission(player) && kit.getCategory() != null)
if (kit.hasPermissionToPreview(player) && kit.getCategory() != null)
categories.add(kit.getCategory());
setTitle(plugin.getLocale().getMessage("interface.categoryselector.title").getMessage());

View File

@ -18,9 +18,8 @@ public class ConfirmBuyGui extends Gui {
setRows(3);
double cost = kit.getPrice();
if (Settings.KITS_FREE_WITH_PERMS.getBoolean() && kit.hasPermission(player)) {
if (kit.hasPermissionToClaim(player))
cost = 0;
}
setTitle(plugin.getLocale().getMessage("interface.yesno.title")
.processPlaceholder("price", cost)

View File

@ -84,7 +84,7 @@ public class KitEditorGui extends DoubleGui {
setItem(0, 4, GuiUtils.createButtonItem(CompatibleMaterial.CHEST,
plugin.getLocale().getMessage("interface.kiteditor.info")
.processPlaceholder("kit", kit.getKey())
.processPlaceholder("perm", "ultimatekits.kit." + kit.getKey().toLowerCase())
.processPlaceholder("perm", "ultimatekits.claim." + kit.getKey().toLowerCase())
.getMessage().split("\\|"))
);

View File

@ -103,9 +103,8 @@ public class KitSelectorGui extends Gui {
}
private void loadKits() {
boolean showAll = !Settings.ONLY_SHOW_KITS_WITH_PERMS.getBoolean();
kitList = plugin.getKitManager().getKits().stream()
.filter(kit -> !kit.isHidden() && (showAll || kit.hasPermission(player))
.filter(kit -> !kit.isHidden() && kit.hasPermissionToPreview(player)
&& (category == null || kit.getCategory() == category))
.map(Kit::getKey)
.collect(Collectors.toList());
@ -186,7 +185,7 @@ public class KitSelectorGui extends Gui {
for (String line : parts)
lore.add(ChatColor.translateAlternateColorCodes('&', line));
}
if (kit.hasPermission(player)) {
if (kit.hasPermissionToClaim(player)) {
if (kit.getNextUse(player) == -1) {
lore.add(plugin.getLocale().getMessage("event.claim.once").getMessage());
} else if (kit.getNextUse(player) > 0) {
@ -202,7 +201,7 @@ public class KitSelectorGui extends Gui {
lore.add(plugin.getLocale().getMessage("event.claim.noaccess").getMessage());
lore.add("");
lore.add(plugin.getLocale().getMessage("interface.selector.leftpreview").getMessage());
if (kit.hasPermission(player)) {
if (kit.hasPermissionToClaim(player)) {
lore.add(plugin.getLocale().getMessage("interface.selector.rightclaim").getMessage());
} else if (kit.getPrice() != 0 || kit.getLink() != null) {
lore.add(plugin.getLocale().getMessage("interface.selector.rightbuy").getMessage());

View File

@ -17,7 +17,6 @@ import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
public class PreviewKitGui extends Gui {
@ -169,7 +168,7 @@ public class PreviewKitGui extends Gui {
List<String> getBuyLore() {
ArrayList<String> lore = new ArrayList<>();
if (kit.hasPermission(player) && Settings.KITS_FREE_WITH_PERMS.getBoolean()) {
if (kit.hasPermissionToClaim(player)) {
lore.add(plugin.getLocale().getMessage("interface.button.clickeco")
.processPlaceholder("price", "0").getMessage());
if (player.isOp()) {

View File

@ -3,7 +3,6 @@ package com.songoda.ultimatekits.kit;
import com.songoda.core.compatibility.CompatibleHand;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.CompatibleSound;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.core.configuration.Config;
import com.songoda.core.gui.Gui;
import com.songoda.core.gui.GuiManager;
@ -57,12 +56,12 @@ public class Kit {
}
public void buy(Player player, GuiManager manager) {
if (hasPermission(player) && plugin.getConfig().getBoolean("Main.Allow Players To Receive Kits For Free If They Have Permission")) {
if (hasPermissionToClaim(player)) {
processGenericUse(player, false);
return;
}
if (!player.hasPermission("ultimatekits.buy." + key)) {
if (!hasPermissionToBuy(player)) {
UltimateKits.getInstance().getLocale().getMessage("command.general.noperms")
.sendPrefixedMessage(player);
return;
@ -202,10 +201,7 @@ public class Kit {
@SuppressWarnings("Duplicates")
public void display(Player player, GuiManager manager, Gui back) {
if (!player.hasPermission("previewkit.use")
&& !player.hasPermission("previewkit." + key)
&& !player.hasPermission("ultimatekits.use")
&& !player.hasPermission("ultimatekits." + key)) {
if (!hasPermissionToPreview(player)) {
UltimateKits.getInstance().getLocale().getMessage("command.general.noperms")
.sendPrefixedMessage(player);
return;
@ -401,13 +397,21 @@ public class Kit {
} else if (this.delay == -1) return -1L;
long last = config.getLong(configSectionPlayer);
long delay = (long) this.delay * 1000;
long delay = this.delay * 1000;
return (last + delay) >= System.currentTimeMillis() ? (last + delay) - System.currentTimeMillis() : 0L;
}
public boolean hasPermission(Player player) {
return player.hasPermission("essentials.kit." + key.toLowerCase());
public boolean hasPermissionToClaim(Player player) {
return player.hasPermission("ultimatekits.claim." + key.toLowerCase());
}
public boolean hasPermissionToPreview(Player player) {
return player.hasPermission("ultimatekits.preview." + key.toLowerCase());
}
public boolean hasPermissionToBuy(Player player) {
return player.hasPermission("ultimatekits.buy." + key.toLowerCase());
}
public double getPrice() {

View File

@ -60,7 +60,7 @@ public class InteractListeners implements Listener {
}
if (kitBlockData.getType() != KitType.PREVIEW) {
if (!kit.hasPermission(player)) {
if (!kit.hasPermissionToClaim(player)) {
plugin.getLocale().getMessage("command.general.noperms").sendPrefixedMessage(player);
return;
}

View File

@ -13,14 +13,6 @@ public class Settings {
static final Config config = UltimateKits.getInstance().getCoreConfig();
public static final ConfigSetting ONLY_SHOW_KITS_WITH_PERMS = new ConfigSetting(config, "Main.Only Show Players Kits They Have Permission To Use", false);
public static final ConfigSetting KITS_FREE_WITH_PERMS = new ConfigSetting(config, "Main.Allow Players To Receive Kits For Free If They Have Permission", true,
"I'm fully aware that this is a strange setting to have",
"enabled by default. The reason I do this is because a lot of our users",
"come from the plugin essentials where the user having permission to the",
"kit allows them to get the kit for free. So when they come to this plugin",
"they would often report this mechanic as a bug. So enabling this by default",
"kind of made sense and we get a lot less tickets about this plugin because of that.");
public static final ConfigSetting DONT_PREVIEW_COMMANDS = new ConfigSetting(config, "Main.Dont Preview Commands In Kits", false);
public static final ConfigSetting HOLOGRAM_LAYOUT = new ConfigSetting(config, "Main.Hologram Layout", Arrays.asList("{TITLE}", "{LEFT-CLICK}", "{RIGHT-CLICK}"));
public static final ConfigSetting SOUNDS_ENABLED = new ConfigSetting(config, "Main.Sounds Enabled", true);