Added error messages and message config

This commit is contained in:
Teriuihi 2022-07-10 21:00:12 +02:00
parent d536712814
commit c0bb58fe5c
3 changed files with 51 additions and 4 deletions

View File

@ -1,6 +1,7 @@
package com.alttd.playershops;
import com.alttd.playershops.api.ShopHandler;
import com.alttd.playershops.config.MessageConfig;
import com.alttd.playershops.listener.PlayerListener;
import com.alttd.playershops.listener.ShopListener;
import com.alttd.playershops.config.Config;
@ -75,6 +76,7 @@ public class PlayerShops extends JavaPlugin {
public void reloadConfigs() {
Config.reload();
MessageConfig.reload();
}
}

View File

@ -0,0 +1,42 @@
package com.alttd.playershops.config;
import com.alttd.galaxy.configuration.AbstractConfiguration;
import com.alttd.playershops.api.ShopType;
import java.io.File;
import java.util.HashMap;
public class MessageConfig extends AbstractConfiguration {
public MessageConfig() {
super(new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs" + File.separator + "com/alttd/playershops"), "messageconfig");
}
static MessageConfig config;
static int version;
static HashMap<ShopType, ShopTypeConfig> shopTypeConfigs;
public static void reload() {
config = new MessageConfig();
version = config.getInt("config-version", 1);
config.set("config-version", 1);
config.readConfig(Config.class, null);
shopTypeConfigs = new HashMap<>();
for (ShopType shopType : ShopType.values()) {
shopTypeConfigs.put(shopType, new ShopTypeConfig(shopType.toString()));
}
}
public static String SHOP_ALREADY_EXISTS = "<red>This block is already a Shop</red>";
public static String NO_SHOP_CREATE_PERMISSION = "<red>You don't have permission to create shops.</red>";
public static String SHOP_LIMIT_REACHED = "<red>You cannot create this shop as you already have reached the limit (<limit>).</red>";
void loadErrorMessages() {
SHOP_ALREADY_EXISTS = getString("errors.shop-already-exists", SHOP_ALREADY_EXISTS);
NO_SHOP_CREATE_PERMISSION = getString("errors.no-shop-create-permission", NO_SHOP_CREATE_PERMISSION);
SHOP_LIMIT_REACHED = getString("errors.shop-limit-reached", SHOP_LIMIT_REACHED);
}
}

View File

@ -4,7 +4,9 @@ import com.alttd.playershops.PlayerShops;
import com.alttd.playershops.api.Shop;
import com.alttd.playershops.api.ShopHandler;
import com.alttd.playershops.config.Config;
import com.alttd.playershops.config.MessageConfig;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@ -99,17 +101,18 @@ public class PlayerListener extends EventListener {
return;
Shop shop = shopHandler.getShop(bRelative.getLocation());
Player player = event.getPlayer();
if(shop != null) {
event.setCancelled(true);
// TODO MESSAGE: There is a shop here already.
player.sendMiniMessage(MessageConfig.SHOP_ALREADY_EXISTS, null);
return;
}
Player player = event.getPlayer();
UUID playerUUID = player.getUniqueId();
if (!player.hasPermission("shop.create")) {
event.setCancelled(true);
// TODO MESSAGE: You don't have permission to create shops.
player.sendMiniMessage(MessageConfig.NO_SHOP_CREATE_PERMISSION, null);
return;
}
@ -118,7 +121,7 @@ public class PlayerListener extends EventListener {
if (numberOfShops >= shopLimit) {
event.setCancelled(true);
// TODO MESSAGE: You cannot create this shop as you already have reached the limit.
player.sendMiniMessage(MessageConfig.SHOP_LIMIT_REACHED, Placeholder.parsed("limit", String.valueOf(shopLimit)));
return;
}