Skip to content

Commit

Permalink
[U] 小修小补
Browse files Browse the repository at this point in the history
  • Loading branch information
LovesAsuna committed Jul 1, 2020
1 parent c5ca81c commit 3840e64
Show file tree
Hide file tree
Showing 17 changed files with 98 additions and 102 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies {
}

group = 'org.sct'
version = '1.5.3-Alpha'
version = '1.5.5-Alpha'
description = 'Lock'
sourceCompatibility = '8'

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/sct/lock/Lock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.sct.easylib.EasyLibAPI
import org.sct.easylib.util.plugin.CheckUpdate
import org.sct.easylib.util.plugin.FileUpdate
import org.sct.easylib.util.plugin.Metrics
import org.sct.easylib.util.reflectutil.ClassUtil
import org.sct.lock.command.SubCommandHandler
import org.sct.lock.data.LockData.pool
import org.sct.lock.enumeration.ConfigType
Expand All @@ -24,7 +25,8 @@ class Lock : JavaPlugin() {
Metrics(this, 6910)
easyLibAPI = EasyLib.getEasyLibAPI()
ListenerManager.register()
Lang.loadLang()
ClassUtil.forceLoad(Lang::class.java)
Lang.load()
easyLibAPI.getEcoAPI().loadVault()
pool!!.submit {
FileUpdate.update(instance, "config.yml", dataFolder.path)
Expand Down Expand Up @@ -53,6 +55,7 @@ class Lock : JavaPlugin() {
@JvmStatic
lateinit var instance: Lock
private set

@JvmStatic
lateinit var easyLibAPI: EasyLibAPI
private set
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/sct/lock/command/sub/Help.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Help implements SubCommand {

@Override
public boolean execute(CommandSender sender, String[] args) {
List<String> helpList = Lang.getStringList(LangType.LANGUAGE_COMMANDHELP);
List<String> helpList = Lang.getStringList(LangType.LANGUAGE_COMMANDHELP.getPath());

for (String cmd : helpList) {
sender.sendMessage(cmd);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/sct/lock/command/sub/Reload.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ public class Reload implements SubCommand {
@Override
public boolean execute(CommandSender sender, String[] args) {
if (!sender.isOp()) {
sender.sendMessage(Lang.getString(LangType.LANG_NOPERMISSION));
sender.sendMessage(Lang.getString(LangType.LANG_NOPERMISSION.getPath()));
}

Lang.loadLang();
Lang.load();
Lock.getInstance().saveDefaultConfig();
Config.loadConfig();
Config.reload();

sender.sendMessage(Lang.getString(LangType.LANG_RELOAD));
sender.sendMessage(Lang.getString(LangType.LANG_RELOAD.getPath()));
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/sct/lock/command/sub/Update.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public boolean execute(CommandSender sender, String[] args) {
boolean error = true;

if (!sender.isOp()) {
sender.sendMessage(Lang.getString(LangType.LANG_NOPERMISSION));
sender.sendMessage(Lang.getString(LangType.LANG_NOPERMISSION.getPath()));
}

if (args.length == 2) {
Expand All @@ -41,7 +41,7 @@ public boolean execute(CommandSender sender, String[] args) {
}

if (error) {
sender.sendMessage(Lang.getString(LangType.LANG_COMMANDERROR));
sender.sendMessage(Lang.getString(LangType.LANG_COMMANDERROR.getPath()));
}
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/sct/lock/command/sub/addType.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ public boolean execute(CommandSender sender, String[] args) {
boolean error = true;

if (!(sender instanceof Player)) {
sender.sendMessage(BasicUtil.convert(Lang.getString(LangType.LANG_NOTAPLAYER)));
sender.sendMessage(BasicUtil.convert(Lang.getString(LangType.LANG_NOTAPLAYER.getPath())));
return false;
}

if (!sender.isOp()) {
sender.sendMessage(Lang.getString(LangType.LANG_NOPERMISSION));
sender.sendMessage(Lang.getString(LangType.LANG_NOPERMISSION.getPath()));
}

if (args.length == 2 && args[0].equalsIgnoreCase("addType")) {
if ("door".equalsIgnoreCase(args[1])) {
LockData.INSTANCE.getAddStatus().put("door", true);
sender.sendMessage(BasicUtil.convert(BasicUtil.replace(Lang.getString(LangType.LANG_ADDTYPE), "%type", "DOOR")));
sender.sendMessage(BasicUtil.convert(BasicUtil.replace(Lang.getString(LangType.LANG_ADDTYPE.getPath()), "%type", "DOOR")));
error = false;
}
}

if (error) {
sender.sendMessage(Lang.getString(LangType.LANG_COMMANDERROR));
sender.sendMessage(Lang.getString(LangType.LANG_COMMANDERROR.getPath()));
}
return true;
}
Expand Down
49 changes: 29 additions & 20 deletions src/main/java/org/sct/lock/file/Config.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,52 @@
package org.sct.lock.file;

import org.bukkit.configuration.file.FileConfiguration;
import org.sct.easylib.util.BasicUtil;
import org.sct.lock.Lock;
import org.sct.lock.enumeration.ConfigType;

import java.util.List;

/**
* @author LovesAsuna
* @date 2020/7/1 12:29
*/

public class Config {
private static FileConfiguration getConfig() {
return Lock.getInstance().getConfig();
}

private static FileConfiguration config = Lock.getInstance().getConfig();
public static String getString(String path) {
reload();
String string = getConfig().getString(path);
return string == null ? "Empty String" : string;
}

public static void loadConfig() {
public static void reload() {
Lock.getInstance().reloadConfig();
config = Lock.getInstance().getConfig();
}

public static String getString(ConfigType configType) {
loadConfig();
return config.getString(configType.getPath());
public static List<String> getStringList(String path) {
reload();
return BasicUtil.convert(getConfig().getStringList(path));
}

public static int getInteger(ConfigType configType) {
loadConfig();
return config.getInt(configType.getPath());
public static double getDouble(String path) {
reload();
return getConfig().getDouble(path);
}

public static boolean getBoolean(ConfigType configType) {
loadConfig();
return config.getBoolean(configType.getPath());
public static int getInt(String path) {
reload();
return (int) getDouble(path);
}

public static List<String> getStringList(ConfigType configType) {
loadConfig();
return config.getStringList(configType.getPath());
public static float getFloat(String path) {
reload();
return (float) getDouble(path);
}

public static boolean setStringList(ConfigType configType, List list) {
loadConfig();
config.set(configType.getPath(), list);
return true;
public static void setStringList(String path, List<String> list) {
getConfig().set(path, list);
}
}
29 changes: 5 additions & 24 deletions src/main/java/org/sct/lock/file/Lang.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
package org.sct.lock.file;

import org.bukkit.configuration.file.YamlConfiguration;
import org.sct.easylib.util.function.file.AbstractFile;
import org.sct.lock.Lock;
import org.sct.lock.enumeration.ConfigType;
import org.sct.lock.enumeration.LangType;
import org.sct.easylib.util.BasicUtil;
import java.io.File;
import java.util.List;

public class Lang {

private static File file;
private static YamlConfiguration config;

public static void loadLang() {
file = new File(Lock.getInstance().getDataFolder() + File.separator + Config.getString(ConfigType.SETTING_LANGUAGE) + ".yml");
if (!file.exists()) { Lock.getInstance().saveResource(Config.getString(ConfigType.SETTING_LANGUAGE) + ".yml",false); }
config = YamlConfiguration.loadConfiguration(file);
}

public static String getString(LangType langType) {
loadLang();
return BasicUtil.convert(config.getString(langType.getPath()));
}
import java.io.File;

public static List<String> getStringList(LangType langType) {
loadLang();
return BasicUtil.convert(config.getStringList(langType.getPath()));
public class Lang extends AbstractFile {
static {
load(new File(Config.getString(ConfigType.SETTING_LANGUAGE.getPath()) + ".yml"), Lock.getInstance());
}

}
4 changes: 2 additions & 2 deletions src/main/java/org/sct/lock/listener/BlockBreak.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ class BlockBreak : Listener {
val doorBelow = Location(e.player.world, BlockX.toDouble(), (BlockY + 1).toDouble(), BlockZ.toDouble()).block
if (checkDoor(e, block) || checkDoor(e, doorAbove) || checkDoor(e, doorBelow) || checkSign(e, e.block)) {
e.isCancelled = true
e.player.sendMessage(Lang.getString(LangType.LANG_DENYBREAK))
e.player.sendMessage(Lang.getString(LangType.LANG_DENYBREAK.path))
}
}

private fun checkDoor(e: BlockBreakEvent, doorBlock: Block): Boolean {
val doorList = Config.getStringList(ConfigType.SETTING_DOORTYPE)
val doorList = Config.getStringList(ConfigType.SETTING_DOORTYPE.path)

/*判断是否符合门类型*/for (door in doorList) {
/*如果破坏的门符合类型*/
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/sct/lock/listener/LockDoorAccessListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class LockDoorAccessListener : Listener {
val direction = LockUtil.getDirection(e.block)
if (direction != status.DOUBLE && e.payer.name != e.owner.name) {
if (s != direction) {
e.payer.sendMessage(BasicUtil.convert(Lang.getString(LangType.LANG_DENYDIRECTION)))
e.payer.sendMessage(BasicUtil.convert(Lang.getString(LangType.LANG_DENYDIRECTION.path)))
return
}
}
Expand All @@ -44,7 +44,7 @@ class LockDoorAccessListener : Listener {
if (conditons.isNotEmpty()) {
if (conditons.contains("1")) {
if (!InventoryUtil.isInvEmpty(e.payer)) {
e.payer.sendMessage(BasicUtil.convert(Lang.getString(LangType.LANG_DENYNOTEMPTYINV)))
e.payer.sendMessage(BasicUtil.convert(Lang.getString(LangType.LANG_DENYNOTEMPTYINV.path)))
return
}
}
Expand All @@ -56,37 +56,37 @@ class LockDoorAccessListener : Listener {
val symbol = moneyDetail.keys.iterator().next()
val access = moneyDetail[symbol]!!
if (!access && !symbol.isEmpty()) {
e.payer.sendMessage(BasicUtil.replace(Lang.getString(LangType.LANG_DENYMONEY), "%needmoney", symbol + money))
e.payer.sendMessage(BasicUtil.replace(Lang.getString(LangType.LANG_DENYMONEY.path), "%needmoney", symbol + money))
return
}
}
if (conditons.contains("3")) {
if (!e.payer.activePotionEffects.isEmpty()) {
e.payer.sendMessage(BasicUtil.convert(Lang.getString(LangType.LANG_DENYHAVEEFFECT)))
e.payer.sendMessage(BasicUtil.convert(Lang.getString(LangType.LANG_DENYHAVEEFFECT.path)))
return
}
}
}

/*如果余额不足*/
if (!Lock.easyLibAPI.ecoAPI.has(e.payer, charge.toDouble())) {
e.payer.sendMessage(Lang.getString(LangType.LANG_NOTENOUGHMONEY))
e.payer.sendMessage(Lang.getString(LangType.LANG_NOTENOUGHMONEY.path))
return
}
teleportAPI.Tp(status.ENTER, e.payer)
/*payer付钱部分*/

/*如果owner是vip或权限未设置*/
if (!"".equals(Config.getString(ConfigType.SETTING_VIPALLOWED), ignoreCase = true) || (LockUtil.getOwner(e.block) as Player).hasPermission(Config.getString(ConfigType.SETTING_VIPALLOWED))) {
if (!"".equals(Config.getString(ConfigType.SETTING_VIPALLOWED.path), ignoreCase = true) || (LockUtil.getOwner(e.block) as Player).hasPermission(Config.getString(ConfigType.SETTING_VIPALLOWED.path))) {
Lock.easyLibAPI.ecoAPI.take(e.payer, charge.toDouble())
Lock.easyLibAPI.ecoAPI.give(LockUtil.getOwner(e.block), charge.toDouble())
} else {
/*owner不是vip,扣税*/
Lock.easyLibAPI.ecoAPI.take(e.payer, charge.toDouble())
charge = (1 - Config.getInteger(ConfigType.SETTING_TAXPERCENT)) * charge
charge = (1 - Config.getInt(ConfigType.SETTING_TAXPERCENT.path)) * charge
Lock.easyLibAPI.ecoAPI.give(LockUtil.getOwner(e.block), charge.toDouble())
}
e.payer.sendMessage(BasicUtil.replace(Lang.getString(LangType.LANG_ENTER), "%charge", charge))
e.payer.sendMessage(BasicUtil.replace(Lang.getString(LangType.LANG_ENTER.path), "%charge", charge))
} else {
teleportAPI.Tp(status.LEAVE, e.payer)
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/sct/lock/listener/PlayerInteractListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PlayerInteractListener : Listener {
if (!InteractInhit.getInhibitStatus(player, 50)) {
return
}
val doorList = Config.getStringList(ConfigType.SETTING_DOORTYPE)
val doorList = Config.getStringList(ConfigType.SETTING_DOORTYPE.path)
if (LockUtil.addStatus(e)) {
return
}
Expand Down Expand Up @@ -73,10 +73,10 @@ class PlayerInteractListener : Listener {
}

/*事件抑制确认*/
val orignDelay = Config.getInteger(ConfigType.SETTING_ENTERDELAY)
val orignDelay = Config.getInt(ConfigType.SETTING_ENTERDELAY.path)
val delay = (orignDelay.toDouble() / 50).toLong()
Inhibition.getInhibitStatus(player, Config.getInteger(ConfigType.SETTING_ENTERDELAY), TimeUnit.MILLISECONDS)
val inhit = Inhibition.getInhibitStatus(player, Config.getInteger(ConfigType.SETTING_ENTERDELAY), TimeUnit.MILLISECONDS)
Inhibition.getInhibitStatus(player, Config.getInt(ConfigType.SETTING_ENTERDELAY.path), TimeUnit.MILLISECONDS)
val inhit = Inhibition.getInhibitStatus(player, Config.getInt(ConfigType.SETTING_ENTERDELAY.path), TimeUnit.MILLISECONDS)
Bukkit.getScheduler().runTaskLaterAsynchronously(Lock.instance, { LockData.ensure?.set(player, false) }, delay)
LockData.ensure?.putIfAbsent(player, false)
val ensure = LockData.ensure?.get(player)!!
Expand All @@ -102,7 +102,7 @@ class PlayerInteractListener : Listener {
val sign = LockData.PlayerSign?.get(e.player)
val player = e.player
val conditions = SIgnProcessUtil.getHoverTextAPI().getText(sign!!.location)
val details = BasicUtil.convert(Lang.getStringList(LangType.LANG_DoorDetail))
val details = BasicUtil.convert(Lang.getStringList(LangType.LANG_DoorDetail.path))
for (detail in details) {
var editDetail = detail
editDetail = BasicUtil.replace(editDetail, "%conditons%", conditions)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/sct/lock/listener/SignChangeListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SignChangeListener : Listener {
if (LockData.PlayerDoorLocation?.get(e.player) == null) {
return
}
for (doors in Config.getStringList(ConfigType.SETTING_DOORTYPE)) {
for (doors in Config.getStringList(ConfigType.SETTING_DOORTYPE.path)) {
if (LockData.PlayerDoorLocation?.get(e.player)!!.block.type == Material.getMaterial(doors)) {
cancel = false
break
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/sct/lock/util/function/LocationUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class LocationUtil {
public static boolean checkWorld(Location location) {
boolean in = false;
for (String world : Config.getStringList(ConfigType.SETTING_WORLDS)) {
for (String world : Config.getStringList(ConfigType.SETTING_WORLDS.getPath())) {
if (world.equals(location.getWorld().getName())) {
in = true;
}
Expand Down
Loading

0 comments on commit 3840e64

Please sign in to comment.