Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
7sat committed Apr 22, 2023
1 parent abb593d commit c9e9808
Show file tree
Hide file tree
Showing 14 changed files with 360 additions and 365 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.sat7</groupId>
<artifactId>DynamicShop</artifactId>
<version>3.15.0</version>
<version>3.15.1</version>
<packaging>jar</packaging>

<name>DynamicShop</name>
Expand Down
92 changes: 53 additions & 39 deletions src/main/java/me/sat7/dynamicshop/DynaShopAPI.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.sat7.dynamicshop;

import lombok.NonNull;
import me.sat7.dynamicshop.constants.Constants;
import me.sat7.dynamicshop.files.CustomConfig;
import me.sat7.dynamicshop.guis.*;
import me.sat7.dynamicshop.models.DSItem;
Expand Down Expand Up @@ -224,7 +225,7 @@ public static ArrayList<ItemStack> getShopItems(@NonNull String shopName)
if (validateShopName(shopName))
{
CustomConfig data = ShopUtil.shopConfigFiles.get(shopName);

ArrayList<ItemStack> list = new ArrayList<>();
for (String s : data.get().getKeys(false))
{
Expand Down Expand Up @@ -365,44 +366,6 @@ public static int getMedian(@NonNull String shopName, @NonNull ItemStack itemSta
}
}

/**
* Get whether a shop is for Vault money or Jobs points
*
* @param shopName The shop to check the type of
* @return True if it is a Job Point shop, False if it is a Vault economy money shop
* @throws IllegalArgumentException When the shop does not exist
*/
public static boolean isJobsPointShop(@NonNull String shopName) throws IllegalArgumentException
{
if (validateShopName(shopName))
{
CustomConfig data = ShopUtil.shopConfigFiles.get(shopName);
return data.get().getString("Options.currency","").equalsIgnoreCase("jobpoint");
} else
{
throw new IllegalArgumentException("Shop: " + shopName + " does not exist");
}
}

/**
* Get whether a shop is for Vault money or Player points
*
* @param shopName The shop to check the type of
* @return True if it is a Player Point shop, False if it is a Vault economy money shop
* @throws IllegalArgumentException When the shop does not exist
*/
public static boolean isPlayerPointShop(@NonNull String shopName) throws IllegalArgumentException
{
if (validateShopName(shopName))
{
CustomConfig data = ShopUtil.shopConfigFiles.get(shopName);
return data.get().getString("Options.currency","").equalsIgnoreCase("playerpoint");
} else
{
throw new IllegalArgumentException("Shop: " + shopName + " does not exist");
}
}

/**
* Check if a shop exists
*
Expand Down Expand Up @@ -478,4 +441,55 @@ public static int FindEmptySlot(String shopName)
{
return ShopUtil.findEmptyShopSlot(shopName, 0, false);
}

//------------
/**
* Get whether a shop is for Vault money or Jobs points
*
* @param shopName The shop to check the type of
* @return True if it is a Job Point shop.
* @throws IllegalArgumentException When the shop does not exist
*/
public static boolean isJobsPointShop(@NonNull String shopName) throws IllegalArgumentException
{
if (validateShopName(shopName))
{
CustomConfig data = ShopUtil.shopConfigFiles.get(shopName);
return ShopUtil.GetCurrency(data).equalsIgnoreCase(Constants.S_JOBPOINT);
} else
{
throw new IllegalArgumentException("Shop: " + shopName + " does not exist");
}
}

/**
* Get whether a shop is for Vault money or Player points
*
* @param shopName The shop to check the type of
* @return True if it is a Player Point shop
* @throws IllegalArgumentException When the shop does not exist
*/
public static boolean isPlayerPointShop(@NonNull String shopName) throws IllegalArgumentException
{
if (validateShopName(shopName))
{
CustomConfig data = ShopUtil.shopConfigFiles.get(shopName);
return ShopUtil.GetCurrency(data).equalsIgnoreCase(Constants.S_PLAYERPOINT);
} else
{
throw new IllegalArgumentException("Shop: " + shopName + " does not exist");
}
}

public static String GetShopCurrency(@NonNull String shopName)
{
if (validateShopName(shopName))
{
CustomConfig data = ShopUtil.shopConfigFiles.get(shopName);
return ShopUtil.GetCurrency(data);
} else
{
throw new IllegalArgumentException("Shop: " + shopName + " does not exist");
}
}
}
3 changes: 2 additions & 1 deletion src/main/java/me/sat7/dynamicshop/commands/CreateShop.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.sat7.dynamicshop.commands;

import me.sat7.dynamicshop.constants.Constants;
import me.sat7.dynamicshop.files.CustomConfig;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -51,7 +52,7 @@ public void RunCMD(String[] args, CommandSender sender)
data.get().set("Options.enable", false);
data.get().set("Options.lore", "");
data.get().set("Options.page", 2);
data.get().set("Options.currency", "vault");
data.get().set("Options.currency", Constants.S_VAULT);
if (args.length >= 3)
{
if (args[2].equalsIgnoreCase("true"))
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/me/sat7/dynamicshop/commands/shop/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import me.sat7.dynamicshop.DynamicShop;
import me.sat7.dynamicshop.commands.DSCMD;
import me.sat7.dynamicshop.commands.Shop;
import me.sat7.dynamicshop.constants.Constants;
import me.sat7.dynamicshop.economyhook.PlayerpointHook;
import me.sat7.dynamicshop.files.CustomConfig;
import me.sat7.dynamicshop.economyhook.JobsHook;
Expand Down Expand Up @@ -117,7 +118,7 @@ public void RunCMD(String[] args, CommandSender sender)
}

// 출발 상점과 도착 상점의 통화 유형이 다름
if (!shopData.get().getString("Options.currency", "").equals(targetShopData.get().getString("Options.currency", "")))
if (!ShopUtil.GetCurrency(shopData).equals(ShopUtil.GetCurrency(targetShopData)))
{
sender.sendMessage(DynamicShop.dsPrefix(sender) + t(sender, "ERR.SHOP_DIFF_CURRENCY"));
return;
Expand Down Expand Up @@ -156,17 +157,17 @@ public void RunCMD(String[] args, CommandSender sender)
// 출발 상점에 돈이 부족
if (ShopUtil.getShopBalance(args[1]) < amount)
{
if (shopData.get().getString("Options.currency","").equalsIgnoreCase("jobpoint"))
if (ShopUtil.GetCurrency(shopData).equalsIgnoreCase(Constants.S_JOBPOINT))
{
sender.sendMessage(DynamicShop.dsPrefix(sender) + t(sender, "MESSAGE.NOT_ENOUGH_POINT").
replace("{bal}", n(ShopUtil.getShopBalance(args[1]))));
}
else if (shopData.get().getString("Options.currency","").equalsIgnoreCase("playerpoint"))
else if (ShopUtil.GetCurrency(shopData).equalsIgnoreCase(Constants.S_PLAYERPOINT))
{
sender.sendMessage(DynamicShop.dsPrefix(sender) + t(sender, "MESSAGE.NOT_ENOUGH_PLAYER_POINT").
replace("{bal}", n(ShopUtil.getShopBalance(args[1]))));
}
else if (shopData.get().getString("Options.currency","").equalsIgnoreCase("exp"))
else if (ShopUtil.GetCurrency(shopData).equalsIgnoreCase(Constants.S_EXP))
{
sender.sendMessage(DynamicShop.dsPrefix(sender) + t(sender, "MESSAGE.NOT_ENOUGH_EXP_POINT").
replace("{bal}", n(ShopUtil.getShopBalance(args[1]))));
Expand Down Expand Up @@ -197,7 +198,7 @@ else if (shopData.get().getString("Options.currency","").equalsIgnoreCase("exp")
}

// 출발 상점과 도착 상점의 통화 유형이 다름
if (!shopData.get().getString("Options.currency", "").equals(targetShopData.get().getString("Options.currency", "")))
if (!ShopUtil.GetCurrency(shopData).equals(ShopUtil.GetCurrency(targetShopData)))
{
sender.sendMessage(DynamicShop.dsPrefix(sender) + t(sender, "ERR.SHOP_DIFF_CURRENCY"));
return;
Expand Down Expand Up @@ -225,23 +226,23 @@ else if (shopData.get().getString("Options.currency","").equalsIgnoreCase("exp")
return;
}

if (shopData.get().getString("Options.currency","").equalsIgnoreCase("jobpoint"))
if (ShopUtil.GetCurrency(shopData).equalsIgnoreCase(Constants.S_JOBPOINT))
{
JobsHook.addJobsPoint(target, amount);
ShopUtil.addShopBalance(args[1], amount * -1);
shopData.save();

sender.sendMessage(DynamicShop.dsPrefix(sender) + t(sender, "MESSAGE.TRANSFER_SUCCESS"));
}
else if (shopData.get().getString("Options.currency","").equalsIgnoreCase("playerpoint"))
else if (ShopUtil.GetCurrency(shopData).equalsIgnoreCase(Constants.S_PLAYERPOINT))
{
PlayerpointHook.addPP(target, amount);
ShopUtil.addShopBalance(args[1], amount * -1);
shopData.save();

sender.sendMessage(DynamicShop.dsPrefix(sender) + t(sender, "MESSAGE.TRANSFER_SUCCESS"));
}
else if (shopData.get().getString("Options.currency","").equalsIgnoreCase("exp"))
else if (ShopUtil.GetCurrency(shopData).equalsIgnoreCase(Constants.S_EXP))
{
target.giveExp((int)amount);
ShopUtil.addShopBalance(args[1], amount * -1);
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/me/sat7/dynamicshop/commands/shop/Currency.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import me.sat7.dynamicshop.DynamicShop;
import me.sat7.dynamicshop.commands.DSCMD;
import me.sat7.dynamicshop.commands.Shop;
import me.sat7.dynamicshop.constants.Constants;
import me.sat7.dynamicshop.files.CustomConfig;
import me.sat7.dynamicshop.utilities.ShopUtil;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -38,10 +39,10 @@ public void RunCMD(String[] args, CommandSender sender)
String shopName = Shop.GetShopName(args);
CustomConfig shopData = ShopUtil.shopConfigFiles.get(shopName);

if (args[3].equalsIgnoreCase("vault") ||
args[3].equalsIgnoreCase("exp") ||
args[3].equalsIgnoreCase("playerpoint") ||
args[3].equalsIgnoreCase("jobpoint"))
if (args[3].equalsIgnoreCase(Constants.S_VAULT) ||
args[3].equalsIgnoreCase(Constants.S_EXP) ||
args[3].equalsIgnoreCase(Constants.S_PLAYERPOINT) ||
args[3].equalsIgnoreCase(Constants.S_JOBPOINT))
{
shopData.get().set("Options.currency", args[3].toLowerCase());
shopData.save();
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/me/sat7/dynamicshop/constants/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

public final class Constants
{
// Prefix
public static final String DYNAMIC_SHOP_PREFIX = "§3[DShop]§f";

// Permission_Admin
public static final String P_ADMIN_CREATIVE = "dshop.admin.creative";
public static final String P_ADMIN_REMOTE_ACCESS = "dshop.admin.remoteaccess";
public static final String P_ADMIN_DELETE_OLD_USER = "dshop.admin.deleteOldUser";
public static final String P_ADMIN_SET_DEFAULT_SHOP = "dshop.admin.setdefaultshop";
public static final String P_ADMIN_SET_TAX = "dshop.admin.settax";
public static final String P_ADMIN_RELOAD = "dshop.admin.reload";

public static final String P_ADMIN_CREATE_SIGN = "dshop.admin.createsign";
public static final String P_ADMIN_DESTROY_SIGN = "dshop.admin.destroysign";

public static final String P_ADMIN_CREATE_SHOP = "dshop.admin.createshop";
public static final String P_ADMIN_DELETE_SHOP = "dshop.admin.deleteshop";
public static final String P_ADMIN_MERGE_SHOP = "dshop.admin.mergeshop";
Expand All @@ -24,12 +24,14 @@ public final class Constants
public static final String P_ADMIN_EDIT_ALL = "dshop.admin.editall";
public static final String P_ADMIN_ITEM_INFO = "dshop.admin.iteminfo";

// Permission_User
public static final String P_USE = "dshop.use"; // 이 권한은 기본적으로 지급됨
public static final String P_SELL = "dshop.sell"; // 이 권한은 기본적으로 지급됨
public static final String P_USE_QSELL = "dshop.use.qsell"; // 이 권한은 기본적으로 지급됨

private Constants()
{

}
// Currency
public static final String S_VAULT = "Vault";
public static final String S_EXP = "Exp";
public static final String S_PLAYERPOINT = "PlayerPoint";
public static final String S_JOBPOINT = "JobPoint";
}
Loading

0 comments on commit c9e9808

Please sign in to comment.