diff --git a/WinfxkLib.jar b/WinfxkLib.jar index c499c94..606fe59 100644 Binary files a/WinfxkLib.jar and b/WinfxkLib.jar differ diff --git a/Winfxklib/.idea/artifacts/WinfxkLib.xml b/Winfxklib/.idea/artifacts/WinfxkLib.xml index 52a48f5..b377aeb 100644 --- a/Winfxklib/.idea/artifacts/WinfxkLib.xml +++ b/Winfxklib/.idea/artifacts/WinfxkLib.xml @@ -1,18 +1,18 @@ - - D:/数据内容/Java/Nukkit/1.11.0.23/plugins + + $USER_HOME$/Desktop - - - - + + - + + + \ No newline at end of file diff --git a/Winfxklib/.idea/compiler.xml b/Winfxklib/.idea/compiler.xml new file mode 100644 index 0000000..b99172b --- /dev/null +++ b/Winfxklib/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Winfxklib/.idea/encodings.xml b/Winfxklib/.idea/encodings.xml deleted file mode 100644 index 97626ba..0000000 --- a/Winfxklib/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Winfxklib/.idea/inspectionProfiles/Project_Default.xml b/Winfxklib/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 278ef68..0000000 --- a/Winfxklib/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - \ No newline at end of file diff --git a/Winfxklib/.idea/jarRepositories.xml b/Winfxklib/.idea/jarRepositories.xml new file mode 100644 index 0000000..2cb2f35 --- /dev/null +++ b/Winfxklib/.idea/jarRepositories.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Winfxklib/.idea/libraries/EconomyAPI.xml b/Winfxklib/.idea/libraries/EconomyAPI.xml deleted file mode 100644 index 7c0a907..0000000 --- a/Winfxklib/.idea/libraries/EconomyAPI.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/Winfxklib/.idea/libraries/KotlinJavaRuntime.xml b/Winfxklib/.idea/libraries/KotlinJavaRuntime.xml deleted file mode 100644 index 9fbfb0d..0000000 --- a/Winfxklib/.idea/libraries/KotlinJavaRuntime.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Winfxklib/.idea/libraries/PowerNukkit.xml b/Winfxklib/.idea/libraries/PowerNukkit.xml deleted file mode 100644 index a4ffadc..0000000 --- a/Winfxklib/.idea/libraries/PowerNukkit.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/Winfxklib/.idea/libraries/me_onebone_economyapi.xml b/Winfxklib/.idea/libraries/me_onebone_economyapi.xml new file mode 100644 index 0000000..5113caf --- /dev/null +++ b/Winfxklib/.idea/libraries/me_onebone_economyapi.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Winfxklib/.idea/misc.xml b/Winfxklib/.idea/misc.xml index 4af51a3..fe0f65d 100644 --- a/Winfxklib/.idea/misc.xml +++ b/Winfxklib/.idea/misc.xml @@ -1,11 +1,12 @@ - - - - - - - + + + + \ No newline at end of file diff --git a/Winfxklib/.idea/modules.xml b/Winfxklib/.idea/modules.xml deleted file mode 100644 index 3bd07b3..0000000 --- a/Winfxklib/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/Winfxklib/.idea/uiDesigner.xml b/Winfxklib/.idea/uiDesigner.xml deleted file mode 100644 index e96534f..0000000 --- a/Winfxklib/.idea/uiDesigner.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Winfxklib/Winfxklib.iml b/Winfxklib/Winfxklib.iml deleted file mode 100644 index 53766e1..0000000 --- a/Winfxklib/Winfxklib.iml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Winfxklib/logs/server.log b/Winfxklib/logs/server.log deleted file mode 100644 index e69de29..0000000 diff --git a/Winfxklib/plugin.yml b/Winfxklib/plugin.yml index 47d3be1..e6d340a 100644 --- a/Winfxklib/plugin.yml +++ b/Winfxklib/plugin.yml @@ -2,7 +2,7 @@ name: WinfxkLib main: cn.winfxk.nukkit.winfxklib.WinfxkLib api: - 1.0.0 -version: 1.2 +version: 1.1.22.6.19.12.33 load: STARTUP website: http://Winfxk.cn author: Winfxk diff --git a/Winfxklib/pom.xml b/Winfxklib/pom.xml new file mode 100644 index 0000000..d271736 --- /dev/null +++ b/Winfxklib/pom.xml @@ -0,0 +1,27 @@ + + + 4.0.0 + cn.winfxk.nukkit.winfxklib + WinfxkLib + 1.1.22.6.19.12.33 + + 8 + 8 + + + + org.powernukkit + powernukkit + 1.6.0.1-PN + + + org.jetbrains + annotations + RELEASE + compile + + + + \ No newline at end of file diff --git a/Winfxklib/res/Message.yml b/Winfxklib/res/Message.yml index eeb35d0..51dcc5d 100644 --- a/Winfxklib/res/Message.yml +++ b/Winfxklib/res/Message.yml @@ -17,6 +17,46 @@ Command: LeaveWord: 查看留言板 LeaveWord: JoinServer: '{RandColor}欢迎来到{ServerName}{RandColor},您当前有{LeaveWordCount}条未读留言,使用“/WinfxkLib LeaveWord”可以查看您的留言。' + AddLeaveWord: + Title: '{RandColor}添加留言' + Content: " " + AddLeaveWord: §4添加留言 + AddItem: §4添加物品 + ItemContent: '§4Item§f: §6{ItemName}§f(§6{ItemID}§f:§6{ItemDamage}§f)' + ClickDelete: §4点击可以删除物品 + SelectItem: §4选择一个要添加的物品 + ItemCountNUll: §4物品数量不合法!请输入一个大于零的纯整数。 + ItemCountExcessive: §4您的物品不足! + ItemCount: §4请输入投送的物品数量 + ItemAddSucceed: §4物品添加成功! + EconomyContent: '§5Money§f: §6{EconomyID}§f>§b>§2{EconomyMoney}§6{EconomyUnits}' + EconomyNUll: §4输入的金额数量不合法!这个数只能是一个大于零的纯数字! + EconomyExcessive: §4您的资产不足! + EconomyMoney: §4请输入金额 + AddEconomy: §4添加金钱 + EconomyAddSucceed: §4资产添加成功! + ClickDeleteEconomy: §4点击删除附带款项 + SelectEconomy: §4请选择经济种类 + LeaveWordTitle: §4留言标题 + LeaveWordContent: §4留言内容 + LeaveWordContentIsNull: §4请输入想要留言的内容! + Recipients: §4收件人名称<请注意区分大小写> + RecipientsDropdown: §4请选择收件人,若上方编辑框已输入内容则本行不生效 + PlayerNull: §4请输入收件人名称 + Succeed: §4留言成功! + MarkRead: + Title: "{RandColor}已读读留言" + Content: " " + NotLeaveWord: §4当前你还没有留言哦! + Item: '{RandColor}{LeaveWordTitle} {LeaveWordDate}{n}{Streamline}' + ClearMessage: "{RandColor}清空留言" + ClearMessageSucceed: §4成功清空了所有的留言 + DeleteSucceed: §4删除成功! + Exception: §4出现异常!请联系管理员{n}{Error} + ShowAccessory: §4显示附件 + ShowAccessoryContent: '{n}{n}所有附件均在阅读时发放,点击任意按钮返回上级' + ItemButton: '§4Item§f: §6{ItemName}§f(§6{ItemID}§f:§6{ItemDamage}§f)' + EconomyButton: '§5Money§f: §6{EconomyID}§f>§b>§2{EconomyMoney}§6{EconomyUnits}' Unread: Title: "{RandColor}未读留言" Content: " " diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/leave_word/AddLeaveWord.java b/Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/leave_word/AddLeaveWord.java deleted file mode 100644 index f5daef0..0000000 --- a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/leave_word/AddLeaveWord.java +++ /dev/null @@ -1,15 +0,0 @@ -package cn.winfxk.nukkit.winfxklib.module.leave_word; - -import cn.nukkit.Player; -import cn.winfxk.nukkit.winfxklib.form.BaseFormin; - -public class AddLeaveWord extends LeaveWordForm { - public AddLeaveWord(Player player, BaseFormin Update, boolean isBack) { - super(player, Update, isBack); - } - - @Override - public boolean MakeForm() { - return false; - } -} diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/leave_word/LeaveWord.java b/Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/leave_word/LeaveWord.java deleted file mode 100644 index 7a04e18..0000000 --- a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/leave_word/LeaveWord.java +++ /dev/null @@ -1,68 +0,0 @@ -package cn.winfxk.nukkit.winfxklib.module.leave_word; - -import cn.nukkit.Player; -import cn.winfxk.nukkit.winfxklib.WinfxkLib; -import cn.winfxk.nukkit.winfxklib.form.BaseFormin; -import cn.winfxk.nukkit.winfxklib.form.api.SimpleForm; -import cn.winfxk.nukkit.winfxklib.tool.Tool; -import org.jetbrains.annotations.NotNull; - -import java.util.HashMap; -import java.util.Map; - -public class LeaveWord extends LeaveWordForm { - - public LeaveWord(Player player, BaseFormin Update, boolean isBack) { - super(player, Update, isBack); - FormKey = "Main"; - } - - @Override - public boolean MakeForm() { - if (!player.hasPermission(Permission)) - return makeShow(player, NotPermissions()); - SimpleForm form = new SimpleForm(getID(), getTitle(), getContent()); - if (Unread.size() + MarkRead.size() <= 0) - form.setContent(form.getContent() + "\n" + NotLeaveWord()); - if (Unread.size() > 1) - form.addButton(message.getSun(MainKey, FormKey, "Unread", LeaveWordkey, new Object[]{player.getName(), WinfxkLib.getMyPlayer(player).getMoney(), Unread.size(), WinfxkLib.getconfig().getInt("LeaveWordAstrict", 10)}), (a, b) -> show(new Unread(player, this, true))); - if (MarkRead.size() > 1) - form.addButton(message.getSun(MainKey, FormKey, "MarkRead", LeaveWordkey, new Object[]{player.getName(), WinfxkLib.getMyPlayer(player).getMoney(), MarkRead.size(), WinfxkLib.getconfig().getInt("LeaveWordAstrict", 10)}), (a, b) -> show(new MarkRead(player, this, true))); - if (MarkRead.size() > 0 || Unread.size() > 0) - form.addButton(getString("ClearMessage"), (player1, data) -> { - Unread = new HashMap<>(); - MarkRead = new HashMap<>(); - LeaveWordMap.put("MarkRead", MarkRead); - LeaveWordMap.put("Unread", Unread); - config.set(player1.getName(), LeaveWordMap); - player1.sendMessage(getString("ClearMessageSucceed")); - return config.save() | isBack(); - }); - form.addButton(getString("AddLeaveWord"), (a, b) -> show(new AddLeaveWord(player, this, true))); - form.addButton(getBack(), (player1, data) -> isBack()); - form.show(player); - return true; - } - - public static void PlayerJoinEvent(@NotNull Player player) { - Map map; - if (!config.containsKey(player.getName())) { - map = new HashMap<>(); - map.put("Unread", new HashMap<>()); - map.put("MarkRead", new HashMap<>()); - } - Object o = config.get("Player"); - map = o instanceof Map ? (Map) o : new HashMap<>(); - o = map.get("Unread"); - Map Unread = o instanceof Map ? (Map) o : new HashMap<>(); - if (Unread.size() > 0) - player.sendMessage(message.getSon(MainKey, "JoinServer", LeaveWordkey, new Object[]{player.getName(), WinfxkLib.getMyPlayer(player).getMoney(), Unread.size(), WinfxkLib.getconfig().getInt("LeaveWordAstrict", 10)})); - String LeaveWordDate = Tool.objToString(map.get("LeaveWordDate"), null); - if (LeaveWordDate == null || !LeaveWordDate.equals(Tool.getDate())) { - map.put("LeaveWordCount", WinfxkLib.getconfig().getInt("LeaveWordAstrict", 10)); - map.put("LeaveWordDate", Tool.getDate()); - } - config.set(player.getName(), map); - config.save(); - } -} diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/leave_word/MarkRead.java b/Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/leave_word/MarkRead.java deleted file mode 100644 index 2704937..0000000 --- a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/leave_word/MarkRead.java +++ /dev/null @@ -1,15 +0,0 @@ -package cn.winfxk.nukkit.winfxklib.module.leave_word; - -import cn.nukkit.Player; -import cn.winfxk.nukkit.winfxklib.form.BaseFormin; - -public class MarkRead extends LeaveWordForm { - public MarkRead(Player player, BaseFormin Update, boolean isBack) { - super(player, Update, isBack); - } - - @Override - public boolean MakeForm() { - return false; - } -} diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/Check.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/Check.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/Check.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/Check.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/Message.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/Message.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/Message.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/Message.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/MyBase.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/MyBase.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/MyBase.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/MyBase.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/MyPlayer.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/MyPlayer.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/MyPlayer.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/MyPlayer.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/MyPlayerin.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/MyPlayerin.java similarity index 96% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/MyPlayerin.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/MyPlayerin.java index bc803cb..96fdf71 100644 --- a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/MyPlayerin.java +++ b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/MyPlayerin.java @@ -64,7 +64,7 @@ public static boolean showForm(Player player, BaseFormin form) { */ public static boolean showForm(String player, BaseFormin form) { MyPlayerin myPlayer = WinfxkLib.getMyPlayer(player); - return myPlayer == null ? false : myPlayer.showForm(form); + return myPlayer != null && myPlayer.showForm(form); } /** diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/WinfxkLib.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/WinfxkLib.java similarity index 96% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/WinfxkLib.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/WinfxkLib.java index f4a0690..58c8535 100644 --- a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/WinfxkLib.java +++ b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/WinfxkLib.java @@ -11,12 +11,11 @@ import cn.winfxk.nukkit.winfxklib.cmd.AdminCommand; import cn.winfxk.nukkit.winfxklib.cmd.PlayerCommand; import cn.winfxk.nukkit.winfxklib.form.FormID; -import cn.winfxk.nukkit.winfxklib.module.leave_word.LeaveWord; +import cn.winfxk.nukkit.winfxklib.module.LeaveWord; import cn.winfxk.nukkit.winfxklib.money.EasyEconomy; import cn.winfxk.nukkit.winfxklib.money.EconomyAPI; import cn.winfxk.nukkit.winfxklib.money.MyEconomy; import cn.winfxk.nukkit.winfxklib.tool.*; -import com.sun.org.apache.bcel.internal.generic.RET; import java.io.File; import java.time.Duration; @@ -85,6 +84,10 @@ public void onFormResponded(PlayerFormRespondedEvent event) { } } + public static List getEconomys() { + return new ArrayList<>(Economys.values()); + } + @Deprecated @Override public cn.nukkit.utils.Config getConfig() { @@ -143,6 +146,7 @@ public void onEnable() { effectlist = new Effectlist(); enchantlist = new Enchantlist(); formID = new FormID(); + getServer().getPluginManager().registerEvents(this, this); getServer().getCommandMap().register(getFullName() + "-AdminCommand", new AdminCommand()); getServer().getCommandMap().register(getFullName() + "-PlayerCommand", new PlayerCommand()); super.onEnable(); @@ -188,7 +192,7 @@ public static boolean setEconomy(String EconomyID) { */ public static MyEconomy getEconomy(String EconomyID) { if (BlacklistEconomy.contains(EconomyID)) return null; - return Economys.get(EconomyID); + return Economys.getOrDefault(EconomyID, null); } /** diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/cmd/AdminCommand.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/cmd/AdminCommand.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/cmd/AdminCommand.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/cmd/AdminCommand.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/cmd/MyCommand.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/cmd/MyCommand.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/cmd/MyCommand.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/cmd/MyCommand.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/cmd/PlayerCommand.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/cmd/PlayerCommand.java similarity index 84% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/cmd/PlayerCommand.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/cmd/PlayerCommand.java index 0fd201a..542bb2c 100644 --- a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/cmd/PlayerCommand.java +++ b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/cmd/PlayerCommand.java @@ -4,14 +4,14 @@ import cn.nukkit.command.data.CommandParameter; import cn.winfxk.nukkit.winfxklib.MyPlayer; import cn.winfxk.nukkit.winfxklib.WinfxkLib; -import cn.winfxk.nukkit.winfxklib.module.leave_word.LeaveWord; +import cn.winfxk.nukkit.winfxklib.module.LeaveWord; import cn.winfxk.nukkit.winfxklib.tool.Tool; import java.util.Locale; public class PlayerCommand extends MyCommand { public PlayerCommand() { - super("admin-" + lib.getName().toLowerCase(Locale.ROOT), msg.getSun("Command", "PlayerCommand", "Description"), msg.getSun("Command", "PlayerCommand", "usageMessage"), Tool.getArray(config.getList("PlayerCommand"), new String[]{})); + super(lib.getName().toLowerCase(Locale.ROOT), msg.getSun("Command", "PlayerCommand", "Description"), msg.getSun("Command", "PlayerCommand", "usageMessage"), Tool.getArray(config.getList("PlayerCommand"), new String[]{})); commandParameters.clear(); commandParameters.put(getString("Help"), new CommandParameter[]{new CommandParameter(getString("Help"), false, new String[]{"help", "h"})}); commandParameters.put(getString("LeaveWord"), new CommandParameter[]{new CommandParameter(getString("LeaveWord"), false, new String[]{"leaveword", "lw"})}); diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/form/BaseForm.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/form/BaseForm.java similarity index 95% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/form/BaseForm.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/form/BaseForm.java index a07c4e3..8c2d434 100644 --- a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/form/BaseForm.java +++ b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/form/BaseForm.java @@ -7,7 +7,6 @@ public abstract class BaseForm extends BaseFormin { public static WinfxkLib main = WinfxkLib.getMain(); protected MyPlayer myPlayer; - protected Player player; private BaseFormin UpForm; protected static final String MainKey = "Form"; diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/form/BaseFormin.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/form/BaseFormin.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/form/BaseFormin.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/form/BaseFormin.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/form/Disposeform.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/form/Disposeform.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/form/Disposeform.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/form/Disposeform.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/form/FormID.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/form/FormID.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/form/FormID.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/form/FormID.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/form/api/CustomForm.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/form/api/CustomForm.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/form/api/CustomForm.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/form/api/CustomForm.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/form/api/ModalForm.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/form/api/ModalForm.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/form/api/ModalForm.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/form/api/ModalForm.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/form/api/RootForm.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/form/api/RootForm.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/form/api/RootForm.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/form/api/RootForm.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/form/api/SimpleForm.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/form/api/SimpleForm.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/form/api/SimpleForm.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/form/api/SimpleForm.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/Itemlist.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/Itemlist.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/Itemlist.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/Itemlist.java diff --git a/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/LeaveWord.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/LeaveWord.java new file mode 100644 index 0000000..7054d48 --- /dev/null +++ b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/LeaveWord.java @@ -0,0 +1,159 @@ +package cn.winfxk.nukkit.winfxklib.module; + +import cn.nukkit.Player; +import cn.nukkit.item.Item; +import cn.winfxk.nukkit.winfxklib.WinfxkLib; +import cn.winfxk.nukkit.winfxklib.form.BaseFormin; +import cn.winfxk.nukkit.winfxklib.form.api.SimpleForm; +import cn.winfxk.nukkit.winfxklib.module.leave_word.AddLeaveWord; +import cn.winfxk.nukkit.winfxklib.module.leave_word.LeaveWordForm; +import cn.winfxk.nukkit.winfxklib.module.leave_word.MarkRead; +import cn.winfxk.nukkit.winfxklib.module.leave_word.Unread; +import cn.winfxk.nukkit.winfxklib.money.MyEconomy; +import cn.winfxk.nukkit.winfxklib.tool.MyMap; +import cn.winfxk.nukkit.winfxklib.tool.Tool; +import org.jetbrains.annotations.NotNull; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class LeaveWord extends LeaveWordForm { + + public LeaveWord(Player player, BaseFormin Update, boolean isBack) { + super(player, Update, isBack); + FormKey = "Main"; + } + + @Override + public boolean MakeForm() { + if (!player.hasPermission(Permission)) + return makeShow(player, NotPermissions()); + SimpleForm form = new SimpleForm(getID(), getTitle(), getContent()); + if (Unread.size() + MarkRead.size() <= 0) + form.setContent(form.getContent() + "\n" + NotLeaveWord()); + if (Unread.size() > 1) + form.addButton(message.getSun(MainKey, FormKey, "Unread", LeaveWordkey, new Object[]{player.getName(), WinfxkLib.getMyPlayer(player).getMoney(), Unread.size(), WinfxkLib.getconfig().getInt("LeaveWordAstrict", 10)}), (a, b) -> show(new Unread(player, this, true))); + if (MarkRead.size() > 1) + form.addButton(message.getSun(MainKey, FormKey, "MarkRead", LeaveWordkey, new Object[]{player.getName(), WinfxkLib.getMyPlayer(player).getMoney(), MarkRead.size(), WinfxkLib.getconfig().getInt("LeaveWordAstrict", 10)}), (a, b) -> show(new MarkRead(player, this, true))); + if (MarkRead.size() > 0 || Unread.size() > 0) + form.addButton(getString("ClearMessage"), (player1, data) -> { + Unread = new HashMap<>(); + MarkRead = new HashMap<>(); + LeaveWordMap.put("MarkRead", MarkRead); + LeaveWordMap.put("Unread", Unread); + config.set(player1.getName(), LeaveWordMap); + player1.sendMessage(getString("ClearMessageSucceed")); + return config.save() | isBack(); + }); + form.addButton(getString("AddLeaveWord"), (a, b) -> show(new AddLeaveWord(player, this, true))); + form.addButton(getBack(), (player1, data) -> isBack()); + form.show(player); + return true; + } + + /** + * 给一个玩家留言 + * + * @param player 玩家名称 + * @param Content 留言内容 + * @param Items 包含的物品 + * @param Economys 包含的经济 + * @return 留言是否成功 + */ + public static boolean addLeaveWord(@NotNull String player, @NotNull String Title, @NotNull String Content, List Items, List Economys) { + if (!config.containsKey(player) && !WinfxkLib.getconfig().getBoolean("UnrealLeaveWord")) return false; + MyMap playerMap = config.getMap(player, new MyMap<>()); + Map Unread = playerMap.getMap("Unread", new MyMap<>()); + StringBuilder Key = new StringBuilder(Tool.getRandString()); + Map ItemMap = new HashMap<>(); + Map LeaveWordMap = new HashMap<>(); + for (Item item : Items) { + while (ItemMap.containsKey(Key.toString())) + Key.append(Tool.getRandString()); + ItemMap.put(Key.toString(), Tool.saveItem(item)); + } + LeaveWordMap.put("Items", ItemMap); + ItemMap = new HashMap<>(); + Key = new StringBuilder(Tool.getRandString()); + for (Economy economy : Economys) { + while (ItemMap.containsKey(Key.toString())) + Key.append(Tool.getRandString()); + ItemMap.put(Key.toString(), MyMap.make("Economy", (Object) economy.EconomyID).add("Money", economy.Money)); + } + Key = new StringBuilder(Tool.getRandString()); + while (Unread.containsKey(Key.toString())) + Key.append(Tool.getRandString()); + LeaveWordMap.put("Economy", ItemMap); + LeaveWordMap.put("Title", Title); + LeaveWordMap.put("Content", Content); + Unread.put(Key.toString(), LeaveWordMap); + playerMap.put("Unread", Unread); + return config.set(player, playerMap).save(); + } + + /** + * 给一个玩家留言 + * + * @param player 玩家对象 + * @param Content 留言内容 + * @param Items 包含的物品 + * @param Economys 包含的经济 + * @return 留言是否成功 + */ + public static boolean addLeaveWord(@NotNull Player player, @NotNull String Title, @NotNull String Content, List Items, List Economys) { + return addLeaveWord(player.getName(), Title, Content, Items, Economys); + } + + public static void PlayerJoinEvent(@NotNull Player player) { + Map map; + if (!config.containsKey(player.getName())) { + map = new HashMap<>(); + map.put("Unread", new HashMap<>()); + map.put("MarkRead", new HashMap<>()); + } + Object o = config.get("Player"); + map = o instanceof Map ? (Map) o : new HashMap<>(); + o = map.get("Unread"); + Map Unread = o instanceof Map ? (Map) o : new HashMap<>(); + if (Unread.size() > 0) + player.sendMessage(message.getSon(MainKey, "JoinServer", LeaveWordkey, new Object[]{player.getName(), WinfxkLib.getMyPlayer(player).getMoney(), Unread.size(), WinfxkLib.getconfig().getInt("LeaveWordAstrict", 10)})); + String LeaveWordDate = Tool.objToString(map.get("LeaveWordDate"), null); + if (LeaveWordDate == null || !LeaveWordDate.equals(Tool.getDate())) { + map.put("LeaveWordCount", WinfxkLib.getconfig().getInt("LeaveWordAstrict", 10)); + map.put("LeaveWordDate", Tool.getDate()); + } + config.set(player.getName(), map); + config.save(); + } + + public static class Economy { + private final String EconomyID; + private final double Money; + private MyEconomy economy; + + public Economy(String EconomyID, double Money) { + this.EconomyID = EconomyID; + this.Money = Money; + economy = WinfxkLib.getEconomy(EconomyID); + } + + public Economy(MyEconomy myEconomy, double Money) { + this.EconomyID = myEconomy.getEconomyName(); + this.Money = Money; + economy = myEconomy; + } + + public String getEconomyID() { + return EconomyID; + } + + public double getMoney() { + return Money; + } + + public MyEconomy getEconomy() { + return economy; + } + } +} diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/PostData.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/PostData.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/PostData.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/PostData.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/itemlist/AddItem.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/itemlist/AddItem.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/itemlist/AddItem.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/itemlist/AddItem.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/itemlist/AlterItem.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/itemlist/AlterItem.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/itemlist/AlterItem.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/itemlist/AlterItem.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/itemlist/BaseItem.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/itemlist/BaseItem.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/itemlist/BaseItem.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/itemlist/BaseItem.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/itemlist/DelItem.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/itemlist/DelItem.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/itemlist/DelItem.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/itemlist/DelItem.java diff --git a/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/leave_word/AddLeaveWord.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/leave_word/AddLeaveWord.java new file mode 100644 index 0000000..f54ea69 --- /dev/null +++ b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/leave_word/AddLeaveWord.java @@ -0,0 +1,199 @@ +package cn.winfxk.nukkit.winfxklib.module.leave_word; + +import cn.nukkit.Player; +import cn.nukkit.Server; +import cn.nukkit.form.response.FormResponseCustom; +import cn.nukkit.item.Item; +import cn.winfxk.nukkit.winfxklib.WinfxkLib; +import cn.winfxk.nukkit.winfxklib.form.BaseFormin; +import cn.winfxk.nukkit.winfxklib.form.api.CustomForm; +import cn.winfxk.nukkit.winfxklib.form.api.SimpleForm; +import cn.winfxk.nukkit.winfxklib.module.LeaveWord; +import cn.winfxk.nukkit.winfxklib.money.MyEconomy; +import cn.winfxk.nukkit.winfxklib.tool.Tool; + +import java.util.ArrayList; +import java.util.List; + +public class AddLeaveWord extends LeaveWordForm { + private static final String[] EconomyKey = {"{Player}", "{Money}", "{EconomyID}", "{EconomyMoney}", "{EconomyUnits}"}; + private static final String[] ItemKey = {"{Player}", "{Money}", "{ItemName}", "{ItemID}", "{ItemDamage}"}; + private String LeaveWordTitle = "", LeaveWordContent = "", Recipients; + private final List Economys = new ArrayList<>(); + private final List SelectEconomys = new ArrayList<>(); + private final List Items = new ArrayList<>(); + private final List SelectItem = new ArrayList<>(); + private boolean Succeed = false; + private boolean isOnline = false; + + public AddLeaveWord(Player player, BaseFormin Update, boolean isBack) { + super(player, Update, isBack); + } + + @Override + public boolean MakeForm() { + SimpleForm form = new SimpleForm(getID(), getTitle(), getContent()); + form.addButton(getString("AddLeaveWord"), (a, b) -> addLeaveWord()); + form.addButton(getString("AddItem"), (a, b) -> AddItem()); + form.addButton(getString("AddEconomy"), (a, b) -> AddEconomy()); + form.addButton(getConfirm(), (a, b) -> (Succeed = true) & (Recipients == null || Recipients.isEmpty() ? addLeaveWord() : LeaveWord.addLeaveWord(Recipients, LeaveWordTitle, LeaveWordContent, Items, Economys))); + form.addButton(getBack(), (a, b) -> isBack()); + return true; + } + + private boolean AddEconomy() { + SimpleForm form = new SimpleForm(getID(), getTitle(), getContent()); + if (Economys.size() > 0) form.setContent(getContent() + "\n" + getString("ClickDeleteEconomy")); + LeaveWord.Economy economy; + for (int i = 0; i < Economys.size(); i++) { + economy = Economys.get(i); + int finalI = i; + form.addButton(message.getSun(MainKey, FormKey, "EconomyContent", EconomyKey, new Object[]{player.getName(), myPlayer.getMoney(), economy.getEconomyID(), economy.getMoney(), economy.getEconomy().getMoneyName()}), (a, b) -> { + Economys.remove(finalI); + return AddEconomy(); + }); + } + form.addButton(getString("AddEconomy"), (a, b) -> MakeEconomy()); + form.addButton(getBackString(), (a, b) -> MakeForm()); + form.show(player); + return true; + } + + private boolean MakeEconomy() { + CustomForm form = new CustomForm(getID(), getTitle()); + form.addLabel(getContent()); + form.addDropdown(getString("SelectEconomy"), getEconomys()); + form.addInput(getString("EconomyMoney"), 1); + form.show(player, (a, b) -> { + FormResponseCustom data = (FormResponseCustom) b; + int index = data.getDropdownResponse(1).getElementID(); + MyEconomy economy = SelectEconomys.get(index); + String s = data.getInputResponse(2); + double Money = Tool.objToDouble(s); + if (s == null || s.isEmpty() || !Tool.isInteger(s) || Money <= 0) + return sendMessage(getString("EconomyNUll")) | MakeEconomy(); + if (Money > economy.getMoney(player)) + return sendMessage(getString("EconomyExcessive")) | MakeEconomy(); + Economys.add(new LeaveWord.Economy(economy.getEconomyName(), Money)); + return sendMessage(getString("EconomyAddSucceed")) | AddEconomy(); + }, (a, b) -> MakeForm()); + return true; + } + + private List getEconomys() { + SelectEconomys.clear(); + List list = new ArrayList<>(); + MyEconomy def = WinfxkLib.getEconomy(); + SelectEconomys.add(def); + list.add(message.getSun(MainKey, FormKey, "EconomyContent", EconomyKey, new Object[]{player.getName(), myPlayer.getMoney(), def.getEconomyName(), "0", def.getMoneyName()})); + for (MyEconomy economy : WinfxkLib.getEconomys()) { + if (economy.equals(def) || WinfxkLib.getBlacklistEconomy().contains(economy.getEconomyName())) continue; + list.add(message.getSun(MainKey, FormKey, "EconomyContent", EconomyKey, new Object[]{player.getName(), myPlayer.getMoney(), economy.getEconomyName(), "0", economy.getMoneyName()})); + SelectEconomys.add(economy); + } + return list; + } + + private boolean AddItem() { + SimpleForm form = new SimpleForm(getID(), getTitle(), getContent()); + if (Items.size() > 0) form.setContent(form.getContent() + "\n" + getString("点击可以删除物品")); + Item item; + for (int i = 0; i < Items.size(); i++) { + item = Items.get(i); + int finalI = i; + form.addButton(message.getSun(MainKey, FormKey, "ItemContent", ItemKey, new Object[]{player.getName(), myPlayer.getMoney(), item.hasCustomName() ? item.getCustomName() : WinfxkLib.getMain().getItemlist().getName(item), item.getId(), item.getDamage()}), (a, b) -> { + Items.remove(finalI); + return AddItem(); + }); + } + form.addButton(getString("AddItem"), (a, b) -> MakeItem()); + form.addButton(getBackString(), (a, b) -> MakeForm()); + form.show(player); + return true; + } + + private boolean MakeItem() { + CustomForm form = new CustomForm(getID(), getTitle()); + form.addLabel(getContent()); + form.addDropdown(getString("SelectItem"), getItems()); + form.addInput(getString("ItemCount"), 1, getString("ItemCount")); + form.show(player, (a, b) -> { + FormResponseCustom data = (FormResponseCustom) b; + int index = data.getDropdownResponse(1).getElementID(); + Item item = SelectItem.get(index); + String s = data.getInputResponse(2); + int Count = Tool.ObjToInt(s); + if (s == null || s.isEmpty() || !Tool.isInteger(s) || Count <= 0) + return sendMessage(getString("ItemCountNUll")) & MakeItem(); + if (Count > item.getCount()) + return sendMessage(getString("ItemCountExcessive")); + item.setCount(Count); + Items.add(item); + return sendMessage(getString("ItemAddSucceed")) | AddItem(); + }, (a, b) -> AddItem()); + return true; + } + + private List getItems() { + SelectItem.clear(); + List list = new ArrayList<>(); + for (Item item : player.getInventory().getContents().values()) { + list.add(message.getSon(MainKey, FormKey, ItemKey, new Object[]{player.getName(), myPlayer.getMoney(), item.hasCustomName() ? item.getCustomName() : WinfxkLib.getMain().getItemlist().getName(item), item.getId(), item.getDamage()})); + SelectItem.add(item); + } + return list; + } + + private boolean addLeaveWord() { + CustomForm form = new CustomForm(getID(), getTitle()); + form.addLabel(getContent()); + form.addInput(getString("LeaveWordTitle"), LeaveWordTitle, getString("LeaveWordTitle")); + form.addInput(getString("LeaveWordContent"), LeaveWordContent, getString("LeaveWordContent")); + form.addInput(getString("Recipients"), Recipients == null ? "" : Recipients, getString("Recipients")); + if (isOnline) form.addDropdown(getString("RecipientsDropdown"), getPlayerlist()); + form.show(player, (a, b) -> { + FormResponseCustom data = (FormResponseCustom) b; + String s = data.getInputResponse(2); + if (s == null || s.isEmpty()) { + sendMessage(getString("LeaveWordContentIsNull")); + return addLeaveWord(); + } + LeaveWordContent = s; + s = data.getInputResponse(1); + if (s == null || s.isEmpty()) + s = LeaveWordContent; + LeaveWordTitle = s.length() > 10 ? s.substring(0, 10) : s; + s = data.getInputResponse(3); + if (s == null || s.isEmpty()) { + if (isOnline) + s = data.getDropdownResponse(4).getElementContent(); + else { + sendMessage(getString("PlayerNull")); + return addLeaveWord(); + } + } + Recipients = s; + return true; + }, (a, b) -> Succeed ? Deduct() | sendMessage("Succeed") | LeaveWord.addLeaveWord(Recipients, LeaveWordTitle, LeaveWordContent, Items, Economys) : MakeForm()); + return true; + } + + private boolean Deduct() { + for (Item item : Items) + player.getInventory().removeItem(item); + for (LeaveWord.Economy economy : Economys) + economy.getEconomy().reduceMoney(player, economy.getMoney()); + return true; + } + + private List getPlayerlist() { + isOnline = false; + List list = new ArrayList<>(); + for (Player player : Server.getInstance().getOnlinePlayers().values()) + if (player.isOnline() && !player.getName().equals(this.player.getName())) { + list.add(player.getName()); + isOnline = true; + } + return list; + } +} \ No newline at end of file diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/leave_word/LeaveWordForm.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/leave_word/LeaveWordForm.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/leave_word/LeaveWordForm.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/leave_word/LeaveWordForm.java diff --git a/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/leave_word/MarkRead.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/leave_word/MarkRead.java new file mode 100644 index 0000000..6b3c1a9 --- /dev/null +++ b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/leave_word/MarkRead.java @@ -0,0 +1,46 @@ +package cn.winfxk.nukkit.winfxklib.module.leave_word; + +import cn.nukkit.Player; +import cn.winfxk.nukkit.winfxklib.form.BaseFormin; +import cn.winfxk.nukkit.winfxklib.form.api.SimpleForm; +import cn.winfxk.nukkit.winfxklib.module.leave_word.reading.RepeatReading; +import cn.winfxk.nukkit.winfxklib.tool.Tool; + +import java.util.HashMap; +import java.util.Map; + +public class MarkRead extends LeaveWordForm { + private static final String[] ItemKey = {"{Player}", "{Money}", "{LeaveWordTitle}", "{LeaveWordDate}", "{LeaveWordPlayer}", "{LeaveWordContent}", "{Streamline}"}; + + public MarkRead(Player player, BaseFormin Update, boolean isBack) { + super(player, Update, isBack); + } + + @Override + public boolean MakeForm() { + if (!player.hasPermission(Permission)) + return makeShow(player, NotPermissions()); + if (Unread.size() <= 0) + return makeShow(true, player.getName(), getTitle(), NotLeaveWord(), getConfirm(), (a, b) -> isBack(), getExitString(), (a, b) -> false); + SimpleForm form = new SimpleForm(getID(), getTitle(), getContent()); + for (Map.Entry entry : MarkRead.entrySet()) { + if (!(entry.getValue() instanceof Map)) continue; + Map item = (Map) entry.getValue(); + form.addButton(message.getSun(MainKey, FormKey, "ItemKey", ItemKey, new Object[]{player.getName(), myPlayer.getMoney(), item.get("Title"), item.get("Date"), item.get("Player"), item.get("Content"), getStreamline(Tool.objToString(item.get("Content")))}), (a, b) -> show(new RepeatReading(a, this, true, entry.getKey()))); + } + form.addButton(getString("ClearMessage"), (player1, data) -> makeShow(true, player.getName(), getTitle(), getString("Sure"), getConfirm(), (a, b) -> { + MarkRead = new HashMap<>(); + LeaveWordMap.put("MarkRead", MarkRead); + config.set(player.getName(), LeaveWordMap); + player1.sendMessage(getString("ClearMessageSucceed")); + return config.save(); + }, getBack(), (a, b) -> isBack())); + form.addButton(getBack(), (player1, data) -> isBack()); + form.show(player); + return true; + } + + private String getStreamline(String s) { + return s == null || s.isEmpty() ? s : s.length() > 10 ? s.substring(0, 10) : s; + } +} diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/leave_word/Unread.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/leave_word/Unread.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/leave_word/Unread.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/leave_word/Unread.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/leave_word/reading/Reading.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/leave_word/reading/Reading.java similarity index 96% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/leave_word/reading/Reading.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/leave_word/reading/Reading.java index ca1de5b..557d5ae 100644 --- a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/module/leave_word/reading/Reading.java +++ b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/leave_word/reading/Reading.java @@ -64,11 +64,11 @@ private boolean read() { EsMap = (Map) entry.getValue(); economy = WinfxkLib.getEconomy(Tool.objToString(EsMap.get("Economy"))); if (economy == null) { - player.sendMessage(message.getSun(MainKey, FormKey, "Exception", ErrorKey, new Object[]{player.getName(), myPlayer.getMoney(), "不支持的经济支持"})); + player.sendMessage(message.getSun(MainKey, FormKey, "Exception", ErrorKey, new Object[]{player.getName(), myPlayer.getMoney(), "不支持的经济支持 " + EsMap.get("Economy")})); continue; } if (WinfxkLib.getBlacklistEconomy().contains(economy.getEconomyName())) { - player.sendMessage(message.getSun(MainKey, FormKey, "Exception", ErrorKey, new Object[]{player.getName(), myPlayer.getMoney(), "被管理员禁用的经济支持"})); + player.sendMessage(message.getSun(MainKey, FormKey, "Exception", ErrorKey, new Object[]{player.getName(), myPlayer.getMoney(), "被管理员禁用的经济支持 " + EsMap.get("Economy")})); continue; } economy.addMoney(player.getName(), Tool.objToDouble(EsMap.get("Money"))); diff --git a/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/leave_word/reading/RepeatReading.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/leave_word/reading/RepeatReading.java new file mode 100644 index 0000000..b68ed1d --- /dev/null +++ b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/module/leave_word/reading/RepeatReading.java @@ -0,0 +1,82 @@ +package cn.winfxk.nukkit.winfxklib.module.leave_word.reading; + +import cn.nukkit.Player; +import cn.nukkit.item.Item; +import cn.winfxk.nukkit.winfxklib.WinfxkLib; +import cn.winfxk.nukkit.winfxklib.form.BaseFormin; +import cn.winfxk.nukkit.winfxklib.form.api.SimpleForm; +import cn.winfxk.nukkit.winfxklib.module.leave_word.LeaveWordForm; +import cn.winfxk.nukkit.winfxklib.money.MyEconomy; +import cn.winfxk.nukkit.winfxklib.tool.Tool; + +import java.util.HashMap; +import java.util.Map; + +public class RepeatReading extends LeaveWordForm { + private final String Key; + private final Map Item; + private final Map Items; + private final Map Economy; + private static final String[] ErrorKey = {"{Player}", "{Money}", "{Error}"}; + private static final String[] EconomyKey = {"{Player}", "{Money}", "{EconomyID}", "{EconomyMoney}", "{EconomyUnits}"}; + private static final String[] ItemKey = {"{Player}", "{Money}", "{ItemName}", "{ItemID}", "{ItemDamage}"}; + + public RepeatReading(Player player, BaseFormin Update, boolean isBack, String Key) { + super(player, Update, isBack); + this.Key = Key; + Item = (Map) MarkRead.get(Key); + FormKey = "MarkRead"; + Object o = Item.get("Items"); + Items = o instanceof Map ? (Map) o : new HashMap<>(); + o = Item.get("Economy"); + Economy = o instanceof Map ? (Map) o : new HashMap<>(); + } + + @Override + public boolean MakeForm() { + SimpleForm form = new SimpleForm(getID(), Tool.objToString(Item.get("Title")), Tool.objToString(Item.get("Content"))); + if (Economy.size() + Items.size() > 0) + form.setContent(getContent() + "\n" + getString("Attachment")); + form.addButton(getString("ShowAccessory"), (player1, data) -> showAccessory()); + form.addButton(getString("Delete"), (player1, data) -> Delete()); + form.addButton(getBack(), (a, b) -> isBack()); + form.show(player); + return true; + } + + private boolean Delete() { + MarkRead.remove(Key); + LeaveWordMap.put("MarkRead", MarkRead); + config.set(player.getName(), LeaveWordMap); + player.sendMessage(getString("DeleteSucceed")); + return config.save(); + } + + private boolean showAccessory() { + SimpleForm form = new SimpleForm(getID(), getTitle() + " " + getString("ShowAccessory"), getContent() + " " + getString("ShowAccessoryContent")); + Map EsMap; + MyEconomy economy; + Item item; + for (Map.Entry entry : Items.entrySet()) { + item = Tool.loadItem((Map) entry.getValue()); + form.addButton(message.getSun(MainKey, FormKey, "ItemButton", ItemKey, new Object[]{player.getName(), myPlayer.getMoney(), item.hasCustomName() ? item.getCustomName() : WinfxkLib.getMain().getItemlist().getName(item), item.getId(), item.getDamage()}), (A, b) -> MakeForm()); + } + for (Map.Entry entry : Economy.entrySet()) { + if (!(entry.getValue() instanceof Map)) continue; + EsMap = (Map) entry.getValue(); + economy = WinfxkLib.getEconomy(Tool.objToString(EsMap.get("Economy"))); + if (economy == null) { + player.sendMessage(message.getSun(MainKey, FormKey, "Exception", ErrorKey, new Object[]{player.getName(), myPlayer.getMoney(), "不支持的经济支持 " + EsMap.get("Economy")})); + continue; + } + if (WinfxkLib.getBlacklistEconomy().contains(economy.getEconomyName())) { + player.sendMessage(message.getSun(MainKey, FormKey, "Exception", ErrorKey, new Object[]{player.getName(), myPlayer.getMoney(), "被管理员禁用的经济支持 " + EsMap.get("Economy")})); + continue; + } + form.addButton(message.getSun(MainKey, FormKey, "EconomyButton", EconomyKey, new Object[]{player.getName(), myPlayer.getMoney(), EsMap.get("Economy"), Tool.objToDouble(EsMap.get("Money")), economy.getMoneyName()}), (a, b) -> MakeForm()); + } + form.addButton(getBackString(), (a, b) -> MakeForm()); + form.show(player); + return true; + } +} diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/money/EasyEconomy.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/money/EasyEconomy.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/money/EasyEconomy.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/money/EasyEconomy.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/money/EconomyAPI.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/money/EconomyAPI.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/money/EconomyAPI.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/money/EconomyAPI.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/money/MyEconomy.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/money/MyEconomy.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/money/MyEconomy.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/money/MyEconomy.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/tool/Config.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/tool/Config.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/tool/Config.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/tool/Config.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/tool/Effectlist.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/tool/Effectlist.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/tool/Effectlist.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/tool/Effectlist.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/tool/Enchantlist.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/tool/Enchantlist.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/tool/Enchantlist.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/tool/Enchantlist.java diff --git a/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/tool/ItemLoad.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/tool/ItemLoad.java new file mode 100644 index 0000000..1d3a4bf --- /dev/null +++ b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/tool/ItemLoad.java @@ -0,0 +1,88 @@ +package cn.winfxk.nukkit.winfxklib.tool; + +import cn.nukkit.item.Item; +import cn.winfxk.nukkit.winfxklib.WinfxkLib; +import cn.winfxk.nukkit.winfxklib.module.LeaveWord; +import cn.winfxk.nukkit.winfxklib.money.MyEconomy; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class ItemLoad { + @Contract("null, !null -> param2") + public static @NotNull List getEconomy(Map map, List list) { + if (list == null) list = new ArrayList<>(); + if (map == null || map.isEmpty()) return list; + Map map1; + MyEconomy economy; + String EconomyID; + double Money; + for (Object obj : map.entrySet()) { + try { + if (obj == null) continue; + if (!(obj instanceof Map)) { + if (!Tool.isInteger(obj)) continue; + list.add(new LeaveWord.Economy(WinfxkLib.getEconomy(), Tool.objToDouble(obj))); + continue; + } + map1 = (Map) obj; + if (map1.isEmpty()) continue; + EconomyID = Tool.objToString(map1.get("Money")); + if (EconomyID == null || EconomyID.isEmpty() || !Tool.isInteger(EconomyID)) continue; + Money = Tool.objToDouble(EconomyID); + if (Money == 0) continue; + EconomyID = Tool.objToString(map1.get("ID"), null); + if (EconomyID == null || EconomyID.isEmpty()) continue; + economy = WinfxkLib.getEconomy(EconomyID); + if (economy == null) continue; + list.add(new LeaveWord.Economy(economy, Money)); + } catch (Exception e) { + e.printStackTrace(); + } + } + return list; + } + + @Contract("null, !null -> param2") + public static @NotNull List getItem(Map map, List list) { + if (list == null) list = new ArrayList<>(); + if (map == null || map.isEmpty()) return list; + String[] strings; + String SID; + Item item; + Itemlist itemlist; + for (Object obj : map.entrySet()) { + if (obj == null) continue; + try { + if (obj instanceof Map) { + list.add(Tool.loadItem((Map) obj)); + continue; + } + SID = Tool.objToString(obj); + if (Tool.isNumeric(SID)) { + list.add(Item.get(Tool.ObjToInt(SID))); + continue; + } + if (SID.contains("|")) { + strings = SID.split("|"); + itemlist = WinfxkLib.getMain().getItemlist().getItem(strings[0]); + if (itemlist == null) continue; + item = itemlist.getItem(); + if (strings.length > 1 && strings[1] != null && !strings[1].isEmpty() && Tool.isInteger(strings[1])) + item.setCount(Tool.ObjToInt(strings[1])); + list.add(item); + continue; + } + itemlist = WinfxkLib.getMain().getItemlist().getItem(SID); + if (itemlist == null) continue; + list.add(itemlist.getItem()); + } catch (Exception e) { + e.printStackTrace(); + } + } + return list; + } +} diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/tool/Itemlist.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/tool/Itemlist.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/tool/Itemlist.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/tool/Itemlist.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/tool/MyList.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/tool/MyList.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/tool/MyList.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/tool/MyList.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/tool/MyMap.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/tool/MyMap.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/tool/MyMap.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/tool/MyMap.java diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/tool/Tool.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/tool/Tool.java similarity index 98% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/tool/Tool.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/tool/Tool.java index 0c6ab0a..53d5018 100644 --- a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/tool/Tool.java +++ b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/tool/Tool.java @@ -77,7 +77,7 @@ public static String getSize(long size) { index++; Size /= 1024; } - return Tool.Double2(Size) + FileSizeUnit[index > FileSizeUnit.length - 1 ? FileSizeUnit.length - 1 : index]; + return Tool.Double2(Size) + FileSizeUnit[Math.min(index, FileSizeUnit.length - 1)]; } /** @@ -1293,7 +1293,7 @@ public static Double ObjToDouble(Object obj, Double double1) { String S = String.valueOf(obj); if (S == null || S.isEmpty()) return double1; - d = Double.valueOf(S); + d = Double.parseDouble(S); } catch (Exception e) { return double1; } @@ -1310,12 +1310,7 @@ public static Double ObjToDouble(Object obj, Double double1) { */ public static > Map sortByValueAscending(Map map) { List> list = new LinkedList<>(map.entrySet()); - Collections.sort(list, new Comparator>() { - @Override - public int compare(Entry a, Entry b) { - return a.getValue().compareTo(b.getValue()); - } - }); + list.sort(Entry.comparingByValue()); Map result = new LinkedHashMap<>(); for (Entry entry : list) result.put(entry.getKey(), entry.getValue()); @@ -1332,12 +1327,7 @@ public int compare(Entry a, Entry b) { */ public static > Map sortByValueDescending(Map map) { List> list = new LinkedList<>(map.entrySet()); - Collections.sort(list, new Comparator>() { - @Override - public int compare(Entry a, Entry b) { - return -(a.getValue().compareTo(b.getValue())); - } - }); + list.sort((a, b) -> -(a.getValue().compareTo(b.getValue()))); Map result = new LinkedHashMap<>(); for (Entry entry : list) result.put(entry.getKey(), entry.getValue()); diff --git a/Winfxklib/src/cn/winfxk/nukkit/winfxklib/tool/Update.java b/Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/tool/Update.java similarity index 100% rename from Winfxklib/src/cn/winfxk/nukkit/winfxklib/tool/Update.java rename to Winfxklib/src/main/java/cn/winfxk/nukkit/winfxklib/tool/Update.java