From 3dd40513e0940a7479eac3722a43471e24238e22 Mon Sep 17 00:00:00 2001 From: kamcdev Date: Sun, 20 Oct 2024 17:16:16 +0800 Subject: [PATCH 1/3] Update README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 服主正在剪视频🤔 --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1de2394..9b29b4f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@
- + + get_All_Tasks() { + List tasks = (List) getMain().Daily_Tasks.get("daily_tasks"); + if (tasks == null) { + return new ArrayList(); + } else { + return tasks; + } + } + + public static List get_All_Task_Names() { + List out = new ArrayList(); + List tasks = (List) AllUse.getMain().Daily_Tasks.get("daily_tasks"); + if (tasks == null) {return out;} + tasks.forEach((task) -> {out.add(new ArrayList(task.keySet()).get(0));}); + return out; + } + + public static List get_All_Items() { + List space_name = Stream.of(Material.values()) + .filter(material -> material.isItem()) + .map(material -> material.getKey().toString()) + .collect(Collectors.toList()); + List item_name = Stream.of(Material.values()) + .filter(material -> material.isItem()) + .map(Enum::name) + .collect(Collectors.toList()); + item_name.forEach((name) -> { + space_name.add(name.toLowerCase()); + }); + return space_name; + } + + public static List get_Max_Daily_Task() { + Integer int_max = (int) AllUse.getMain().Daily_Tasks.get("max_daily_task"); + if (int_max == null) { + return Arrays.asList("5"); + } else { + return Arrays.asList(int_max.toString()); + } + } + + public static List get_Random_Tasks() { + int max = new Integer(get_Max_Daily_Task().get(0)); + List AllTasks = get_All_Task_Names(); + int AllTasks_len = AllTasks.toArray().length; + if (AllTasks_len <= max) { + return AllTasks; + } else { + List out = new ArrayList<>(); + String Temp = AllTasks.get(0); + for (int i=0;i tasks = (List) getMain().Daily_Tasks.get("daily_tasks"); + HashMap out = new HashMap(); + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + HashMap task = iterator.next(); + String task_name = new ArrayList(task.keySet()).get(0); + if (task_name.equalsIgnoreCase(name)) { + out = task.get(task_name); + } + } + return out; + } + + public ItemStack get_Item_At_Name(String name) { + NamespacedKey key = NamespacedKey.fromString(name); + Material material = Material.matchMaterial(key.getKey()); + if (material == null) { + material = Material.matchMaterial(name.toUpperCase()); + if (material == null) { + return null; + } + } + return new ItemStack(material); + } + + public int get_Player_Item_Count(Player player,ItemStack item) { + int count = 0;Iterator iterator = player.getInventory().iterator(); + while (iterator.hasNext()) { + ItemStack oitem = (ItemStack) iterator.next(); + if (oitem != null && oitem.getType() == item.getType()) { + count = count + oitem.getAmount(); + } + } + return count; + } + + public boolean remove_Player_Amount_Item(Player player,ItemStack item,int count) { + int amount = count;PlayerInventory player_inventory = player.getInventory(); + Iterator iterator = player_inventory.iterator(); + boolean removed = false;int i = 0; + while (iterator.hasNext() & amount > 0) { + ItemStack oitem = (ItemStack) iterator.next(); + if (oitem != null && oitem.getType() == item.getType()) { + Integer currentAmount = oitem.getAmount(); + logger.info(currentAmount.toString()); + if (currentAmount <= amount) { + amount -= currentAmount; + player_inventory.setItem(i,new ItemStack(Material.AIR)); + } else { + oitem.setAmount(currentAmount - amount); + amount = 0;removed = true;break; + } + } + i = i + 1; + } + player.updateInventory(); + return removed; + } + + public Essentials get_Essentials() { + return getMain().essentials; + } + + public BigDecimal get_Player_Money(Player player) { + return get_Essentials().getUser(player).getMoney(); + } + + public void set_Player_Money(Player player,BigDecimal money) { + try { + get_Essentials().getUser(player).setMoney(money); + } catch (Exception e) {} } } diff --git a/src/main/java/com/DrakGod/KaMCUP/CommandHandler.java b/src/main/java/com/DrakGod/KaMCUP/CommandHandler.java index a9f1eca..b06d7c5 100644 --- a/src/main/java/com/DrakGod/KaMCUP/CommandHandler.java +++ b/src/main/java/com/DrakGod/KaMCUP/CommandHandler.java @@ -1,34 +1,22 @@ package com.DrakGod.KaMCUP; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; + import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; public class CommandHandler extends AllUse implements CommandExecutor{ @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { String CommandName = cmd.getName(); - if (CommandName.equalsIgnoreCase("car")) { - if (sender instanceof Player) { - Player player = (Player) sender; - int wait_time = getMain().Car_Wait_Time.getOrDefault(player.getUniqueId(), 0); - - if (wait_time <= 0) { - player.addScoreboardTag("Cared"); - player.getInventory().addItem(getMain().Train); - - sender.sendMessage("§a已获得§d1§a个§d矿车"); - getMain().Car_Wait_Time.put(player.getUniqueId(), 10); - } else { - sender.sendMessage("§c冷却中,剩余§d"+Integer.toString(wait_time)+"秒"); - } - } else { - sender.sendMessage("§4此命令仅可由玩家执行"); - } - return true; - } - if (CommandName.equalsIgnoreCase("uuid")) { if (args.length == 1) { Player player = server.getPlayer(args[0]); @@ -44,23 +32,225 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String return true; } + if (CommandName.equalsIgnoreCase("dailytask")) { + if (!(sender instanceof Player)) { + sender.sendMessage("§4此命令仅可由玩家执行"); + return true; + } + + Player player = (Player) sender; + if (args.length == 0) { + sender.sendMessage("§6------ ======= 每日任务帮助 ======= ------"); + sender.sendMessage("§b/dailytask put - 提交一个任务"); + sender.sendMessage("§b/dailytask list - 获取今日任务"); + sender.sendMessage("§6------ ======= 每日任务帮助 ======= ------"); + return true; + } + + if (args[0].equalsIgnoreCase("put")) { + if (args.length != 2) { + sender.sendMessage("§4请输入正确的参数"); + return true; + } + String name = args[1]; + List tasks = getMain().Player_Daily_Tasks.getOrDefault(player.getUniqueId(),new ArrayList()); + if (!tasks.contains(name)) { + sender.sendMessage("§4该任务名称不存在"); + return true; + } + HashMap task = get_Daily_Task(name); + ItemStack item = get_Item_At_Name((String) task.get("item")); + int count = get_Player_Item_Count(player,item); + if (count >= (int) task.get("count")) { + remove_Player_Amount_Item(player,item,(int) task.get("count")); + BigDecimal give_money = new BigDecimal(task.get("give_money").toString()); + try { + set_Player_Money(player,get_Player_Money(player).add(give_money)); + } catch (Exception e) {} + + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + String oname = iterator.next(); + if (oname.equalsIgnoreCase(name)) { + tasks.set(tasks.indexOf(oname),oname+" OK"); + } + } + sender.sendMessage("§6提交任务§a成功,§6已获得§e"+task.get("give_money").toString()+"金钱"); + } else { + sender.sendMessage("§4所需物品不足"); + } + return true; + } + + if (args[0].equalsIgnoreCase("list")) { + sender.sendMessage("§6------ ======= 今日任务列表 ======= ------"); + List tasks = getMain().Player_Daily_Tasks.getOrDefault(player.getUniqueId(),new ArrayList()); + tasks.forEach((task) -> { + String is_OK = " - §4未完成"; + if (task.contains(" OK")) { + is_OK = " - §a已完成"; + task = task.replaceAll(" OK",""); + } + HashMap one_task = (HashMap) get_Daily_Task(task); + sender.sendMessage("§b任务名称:"+task+" 需要物品:"+one_task.get("item")+" 需要数量:" + +one_task.get("count")+" 给予金钱:"+one_task.get("give_money")+is_OK); + }); + sender.sendMessage("§6------ ======= 今日任务列表 ======= ------"); + return true; + } + } + if (CommandName.equalsIgnoreCase("kamcup")) { if (args.length == 0 || args[0].equalsIgnoreCase("help")) { sender.sendMessage("§6------ ======= KaMC实用插件帮助 ======= ------"); - getMain().kamcupcmds.forEach((key,value) -> {sender.sendMessage("§b/kamcup "+key+" "+value);}); + getMain().kamcupcmds.forEach((key,value) -> {sender.sendMessage("§b/kamcup "+key+" "+value.get(0));}); sender.sendMessage("§6------ ======= KaMC实用插件帮助 ======= ------"); return true; } + if (!getMain().kamcupcmds.containsKey(args[0])) { + sender.sendMessage("§4没有此命令,请使用/kamcup help查看"); + return true; + } + if (args[0].equalsIgnoreCase("version")) { - sender.sendMessage("§6KaMC实用插件当前版本:"+getMain().CCheckUpdate.getNowVersion()); - sender.sendMessage("§6KaMC实用插件最新版本:"+getMain().CCheckUpdate.getNewVersion()); + sender.sendMessage("§6KaMC实用插件当前版本:"+getCheckUpdate().getNowVersion()); + sender.sendMessage("§6KaMC实用插件最新版本:"+getCheckUpdate().getNewVersion()); + } + + if (args[0].equalsIgnoreCase("dailytask")) { + if (args.length == 1) { + sender.sendMessage("§6------ ======= 每日任务帮助 ======= ------"); + HashMap Temp = (HashMap) getMain().kamcupcmds.get("dailytask").get(1); + Temp.forEach((key,value) -> {sender.sendMessage("§b/kamcup dailytask "+key+" "+value.get(0));}); + sender.sendMessage("§6------ ======= 每日任务帮助 ======= ------"); + return true; + } + + if (Arrays.asList("add","set").contains(args[1])) { + if (args.length != 6) { + sender.sendMessage("§4请输入正确的参数"); + return true; + } + String name = args[2];String item = args[3]; + int count;BigDecimal give_money; + if (args[1].equalsIgnoreCase("add")) { + if (get_All_Task_Names().contains(name)) { + sender.sendMessage("§4该任务名称已存在"); + return true; + } + } else { + if (!get_All_Task_Names().contains(name)) { + sender.sendMessage("§4该任务名称不存在"); + return true; + } + } + + if (!get_All_Items().contains(item)) { + sender.sendMessage("§4该物品名称不存在"); + return true; + } + try { + count = new Integer(args[4]); + give_money = new BigDecimal(args[5]); + int result = give_money.compareTo(new BigDecimal(0)); + if (count <= 0 | result < 0) {int a = 1/0;} + } catch (Exception e) { + sender.sendMessage("§4数量必须为大于0的正整数,给予金钱数量必须为大于0的数"); + return true; + } + + List tasks = get_All_Tasks(); + if (tasks == null) {tasks = new ArrayList();} + if (args[1].equalsIgnoreCase("add")) { + HashMap Temp1 = new HashMap(); + HashMap Temp2 = new HashMap(); + Temp2.put("item",item); + Temp2.put("count",count); + Temp2.put("give_money",give_money); + Temp1.put(name,Temp2); + tasks.add(Temp1); + } else { + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + HashMap task = (HashMap) iterator.next(); + String task_name = new ArrayList(task.keySet()).get(0); + if (name.equalsIgnoreCase(task_name)) { + HashMap Temp = (HashMap) task.get(task_name); + Temp.put("item",item); + Temp.put("count",count); + Temp.put("give_money",give_money); + task.put(task_name,Temp); + tasks.set(tasks.indexOf(task),task); + } + } + } + getMain().Daily_Tasks.set("daily_tasks",tasks); + Save_File(getMain().Daily_Tasks,getMain().Daily_Tasks_File); + if (args[1].equalsIgnoreCase("add")) { + sender.sendMessage("§6添加每日任务:"+name+" 成功"); + } else { + sender.sendMessage("§6修改每日任务:"+name+" 成功"); + } + } + + if (args[1].equalsIgnoreCase("remove")) { + if (args.length != 3) { + sender.sendMessage("§4请输入正确的参数"); + } else { + String name = args[2]; + if (!get_All_Task_Names().contains(name)) { + sender.sendMessage("§4该任务名称不存在"); + return true; + } + + List tasks = get_All_Tasks(); + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + HashMap task = iterator.next(); + String task_name = new ArrayList(task.keySet()).get(0); + if (task_name.equalsIgnoreCase(name)) { + iterator.remove(); + } + } + getMain().Daily_Tasks.set("daily_tasks",tasks); + Save_File(getMain().Daily_Tasks,getMain().Daily_Tasks_File); + sender.sendMessage("§6删除每日任务:"+name+" 成功"); + } + } + + if (args[1].equalsIgnoreCase("max")) { + if (args.length != 3) { + sender.sendMessage("§6当前每日任务最大数量为:"+get_Max_Daily_Task().get(0)); + } else { + try { + int in_max = new Integer(args[2]); + if (in_max <= 0) {int a = 0 / 0;} + int max = (int) new Integer(get_Max_Daily_Task().get(0)); + getMain().Daily_Tasks.set("max_daily_task",in_max); + Save_File(getMain().Daily_Tasks,getMain().Daily_Tasks_File); + sender.sendMessage("§6当前每日任务最大数量为:"+get_Max_Daily_Task().get(0)); + if (in_max < max) {sender.sendMessage("§e警告:改为更小值第二天生效!");} + } catch (Exception e) { + sender.sendMessage("§4请输入大于0的正整数类型"); + } + } + } + + if (args[1].equalsIgnoreCase("list")) { + sender.sendMessage("§6------ ======= 每日任务列表 ======= ------"); + List tasks = get_All_Tasks(); + tasks.forEach((task) -> { + String task_name = new ArrayList(task.keySet()).get(0); + HashMap one_task = (HashMap) task.get(task_name); + sender.sendMessage("§b名称:"+task_name+" 物品:"+one_task.get("item" + )+" 数量:"+one_task.get("count")+" 给予金钱:"+one_task.get("give_money")); + }); + } } - if (!getMain().kamcupcmds.containsKey(args[0])) { - sender.sendMessage("§4没有此命令,请使用/kamcup help查看");} return true; } return false; } -} +} \ No newline at end of file diff --git a/src/main/java/com/DrakGod/KaMCUP/Listeners.java b/src/main/java/com/DrakGod/KaMCUP/Listeners.java index ce99683..834156d 100644 --- a/src/main/java/com/DrakGod/KaMCUP/Listeners.java +++ b/src/main/java/com/DrakGod/KaMCUP/Listeners.java @@ -1,53 +1,61 @@ package com.DrakGod.KaMCUP; -import org.bukkit.Location; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Minecart; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; +import java.time.LocalDateTime; +import java.util.Iterator; +import java.util.List; +import java.util.UUID; + import org.bukkit.event.Listener; -import org.bukkit.event.vehicle.VehicleEnterEvent; -import org.bukkit.event.vehicle.VehicleMoveEvent; +import org.bukkit.scheduler.BukkitRunnable; public class Listeners extends AllUse implements Listener { - @EventHandler(priority = EventPriority.NORMAL) - public void onPlayerEnterVehicle(VehicleEnterEvent event) { - if (event.getVehicle().getType() == EntityType.MINECART) { - Minecart minecart = (Minecart) event.getVehicle(); - Player player = (Player) event.getEntered(); - if (player == null || !player.getScoreboardTags().contains("Cared")) {return;} - - minecart.setMaxSpeed(65536); - player.removeScoreboardTag("Cared"); - player.sendTitle("§a欢迎乘坐§bKaMC§e快速列车","§4如果被清除,请重新执行/car"); - } - } - - @EventHandler(priority = EventPriority.NORMAL) - public void onMinecartMove(VehicleMoveEvent event) { - if (!(event.getVehicle() instanceof Minecart)) {return;} - - Minecart minecart = (Minecart) event.getVehicle(); - Player player = (Player) minecart.getPassenger(); - if (player == null) {return;} - - Location from = event.getFrom(); - Location to = event.getTo(); - - double deltaX = to.getX() - from.getX(); - double deltaY = to.getY() - from.getY(); - double deltaZ = to.getZ() - from.getZ(); - - double distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ); - if (distance <= 0) {return;} - - Integer ispeed = (int) (distance * 72.0); - StringBuilder out = new StringBuilder(ispeed.toString()); - while (out.length() < 5) { - out.insert(0, " "); + BukkitRunnable Seconds_Update = new BukkitRunnable() { + @Override + public void run() { + server.getOnlinePlayers().forEach((player) -> { + UUID player_uuid = player.getUniqueId(); + List player_tasks = getMain().Player_Daily_Tasks.getOrDefault(player_uuid,null); + List all_tasks = AllUse.get_All_Task_Names(); + if (player_tasks == null) { + player_tasks = AllUse.get_Random_Tasks(); + } else { + Iterator iterator = player_tasks.iterator(); + while (iterator.hasNext()) { + String task = iterator.next(); + if (!all_tasks.contains(task) & !task.contains(" OK")) { + player_tasks = AllUse.get_Random_Tasks(); + break; + } + } + + int player_task_lenth = player_tasks.toArray().length; + if (player_task_lenth < new Integer(get_Max_Daily_Task().get(0))) { + if (player_task_lenth < all_tasks.toArray().length) { + iterator = all_tasks.iterator(); + while (iterator.hasNext()) { + String task = iterator.next(); + if (!player_tasks.contains(task)) { + player_tasks.add(task); + } + player_task_lenth = player_tasks.toArray().length; + if (player_task_lenth == new Integer(get_Max_Daily_Task().get(0))){ + break; + } + } + } + } + } + getMain().Player_Daily_Tasks.put(player_uuid,player_tasks); + }); + + getMain().now = LocalDateTime.now(); + if (getMain().now.isAfter(getMain().midnightToday)) { + server.getOnlinePlayers().forEach((player) -> { + getMain().Player_Daily_Tasks.put(player.getUniqueId(),get_Random_Tasks()); + }); + getMain().midnightToday = getMain().now.toLocalDate().atStartOfDay().plusDays(1); + } } - - player.sendActionBar("当前速度:" + out + " km/h"); - } + }; } + diff --git a/src/main/java/com/DrakGod/KaMCUP/Main.java b/src/main/java/com/DrakGod/KaMCUP/Main.java index 5fc663f..400552e 100644 --- a/src/main/java/com/DrakGod/KaMCUP/Main.java +++ b/src/main/java/com/DrakGod/KaMCUP/Main.java @@ -1,46 +1,49 @@ package com.DrakGod.KaMCUP; -import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.Server; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.PluginCommand; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.scheduler.BukkitRunnable; +import com.earth2me.essentials.Essentials; + +import java.io.File; +import java.io.InputStreamReader; +import java.time.LocalDateTime; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.UUID; import java.util.logging.Logger; public class Main extends JavaPlugin { - Server server = Bukkit.getServer(); + Server server = getServer(); + File pluginfolder = getDataFolder(); + Logger logger = server.getLogger(); PluginManager pluginmanager = server.getPluginManager(); ConsoleCommandSender console = server.getConsoleSender(); - Logger logger = server.getLogger(); + Essentials essentials = (Essentials) pluginmanager.getPlugin("Essentials"); - HashMap kamcupcmds = new HashMap(); - HashMap Car_Wait_Time = new HashMap(); + HashMap kamcupcmds = new HashMap(); + HashMap Player_Daily_Tasks = new HashMap(); ItemStack Train = new ItemStack(Material.MINECART); + LocalDateTime now = LocalDateTime.now(); + LocalDateTime midnightToday = now.toLocalDate().atStartOfDay().plusDays(1); - CheckUpdate CCheckUpdate = new CheckUpdate(); - CommandHandler CCommandHandler = new CommandHandler(); - Listeners CListeners = new Listeners(); - TabCompleters CTabCompleters = new TabCompleters(); - private static Main CMain; - - BukkitRunnable CWTremove = new BukkitRunnable() { - @Override - public void run() { - Car_Wait_Time.forEach((key,value) -> { - if (Car_Wait_Time.get(key) > 0) { - Car_Wait_Time.put(key, value-1); - } - }); - } - }; + public FileConfiguration Daily_Tasks; + public File Daily_Tasks_File; + public static Main CMain; + public AllUse CAllUse; + public CheckUpdate CCheckUpdate; + public CommandHandler CCommandHandler; + public Listeners CListeners; + public TabCompleters CTabCompleters; BukkitRunnable UCMain = new BukkitRunnable() {@Override public void run() {CMain = getThis();}}; public Main getThis() {return this;} @@ -48,34 +51,106 @@ public void run() { @Override public void onEnable() { - kamcupcmds.put("help","- 获取帮助"); - kamcupcmds.put("version","- 获取当前版本"); + AllUse.Tab_to_run get_alltasks = new AllUse.Tab_to_run() { + @Override + public List run() {return AllUse.get_All_Task_Names();} + }; - ItemMeta Train_Name = Train.getItemMeta(); - Train_Name.setItemName("列车"); - Train.setItemMeta(Train_Name); - - pluginmanager.registerEvents(CListeners,this); - CWTremove.runTaskTimer(this, 20, 20); + AllUse.Tab_to_run get_allitems = new AllUse.Tab_to_run() { + @Override + public List run() {return AllUse.get_All_Items();} + }; + + AllUse.Tab_to_run get_tasksmax = new AllUse.Tab_to_run() { + @Override + public List run() {return AllUse.get_Max_Daily_Task();} + }; + + HashMap addset_hashmap = new HashMap() {{ + put("|to_run|",Arrays.asList("",new HashMap() {{ + put("|to_run|",Arrays.asList("",new HashMap() {{ + put("1", Arrays.asList("",new HashMap() {{ + put("1", Arrays.asList()); + }})); + }},get_allitems)); + }},get_alltasks)); + }}; + + kamcupcmds.put("help",Arrays.asList("- 获取帮助",new HashMap<>())); + kamcupcmds.put("version",Arrays.asList("- 获取当前版本",new HashMap<>())); + + if (essentials != null) { + kamcupcmds.put("dailytask",Arrays.asList("- 查看每日任务系统",new HashMap() {{ + put("add",Arrays.asList(" - 添加任务",addset_hashmap)); + put("set",Arrays.asList(" - 设置任务",addset_hashmap)); + put("remove",Arrays.asList(" - 删除任务",new HashMap() {{ + put("|to_run|",Arrays.asList("",new HashMap<>(),get_alltasks)); + }})); + put("max",Arrays.asList(" - 设置每日最大任务数",new HashMap() {{ + put("|to_run|",Arrays.asList("",new HashMap<>(),get_tasksmax)); + }})); + put("list",Arrays.asList("- 列出任务",new HashMap<>())); + }})); + } + + CMain = getThis(); UCMain.runTaskTimer(this, 0, 1); - CCheckUpdate.CheckUpdateMain.runTaskTimer(this, 20, 72000); + CAllUse = new AllUse(); + CCheckUpdate = new CheckUpdate(); + CCommandHandler = new CommandHandler(); + CListeners = new Listeners(); + CTabCompleters = new TabCompleters(); + + if (!pluginfolder.exists()) { + pluginfolder.mkdir(); + } + Daily_Tasks_File = new File(pluginfolder,"Daily_Tasks.yml"); + List Daily_Tasks_Load_Out = CAllUse.Load_File(Daily_Tasks_File); + if ((boolean) Daily_Tasks_Load_Out.get(0)) { + Daily_Tasks = YamlConfiguration.loadConfiguration(new InputStreamReader(getClass().getResourceAsStream("/Daily_Tasks.yml"))); + } else { + Daily_Tasks = (FileConfiguration) Daily_Tasks_Load_Out.get(1); + } + if (Daily_Tasks != null) { + CAllUse.Save_File(Daily_Tasks,Daily_Tasks_File); + } else { + logger.warning("无法加载配置文件:Daily_Tasks.yml"); + } + + pluginmanager.registerEvents(CListeners,this); + CListeners.Seconds_Update.runTaskTimer(this, 20, 20); + CCheckUpdate.CheckUpdateMain.runTaskTimer(this, 20, 864000); PluginCommand kamcup = this.getCommand("kamcup"); - PluginCommand car = this.getCommand("car"); PluginCommand uuid = this.getCommand("uuid"); + PluginCommand dailytask = this.getCommand("dailytask"); + if (essentials != null) { + dailytask.setExecutor(CCommandHandler); + dailytask.setTabCompleter(CTabCompleters); + } kamcup.setExecutor(CCommandHandler); kamcup.setTabCompleter(CTabCompleters); - car.setExecutor(CCommandHandler); uuid.setExecutor(CCommandHandler); + if (essentials == null) { + dailytask.setPermission("kamcup.null"); + logger.warning("[KaMC实用插件] 未加载essentials服务,无法使用/dailytask指令"); + } else { + dailytask.setPermission("kamcup.commands.dailytask"); + } + logger.info("[KaMC实用插件] 插件成功启用"); } @Override public void onDisable() { - CCheckUpdate.CheckUpdateMain.cancel(); - CWTremove.cancel(); - Car_Wait_Time.clear(); + try { + CCheckUpdate.CheckUpdateMain.cancel(); + CListeners.Seconds_Update.cancel(); + } catch (Exception e) { + logger.warning("[KaMC实用插件] 禁用时出现错误:"+e.toString()); + } + logger.info("[KaMC实用插件] 插件已被禁用"); } } \ No newline at end of file diff --git a/src/main/java/com/DrakGod/KaMCUP/TabCompleters.java b/src/main/java/com/DrakGod/KaMCUP/TabCompleters.java index 27a4687..1f4146e 100644 --- a/src/main/java/com/DrakGod/KaMCUP/TabCompleters.java +++ b/src/main/java/com/DrakGod/KaMCUP/TabCompleters.java @@ -1,19 +1,65 @@ package com.DrakGod.KaMCUP; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; import java.util.List; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; public class TabCompleters extends AllUse implements TabCompleter{ + public int i; + public List Temp1; + public HashMap Temp2; + @Override public List onTabComplete(CommandSender sender, Command cmd, String alias, String[] args) { List completions = new ArrayList<>(); if (cmd.getName().equalsIgnoreCase("kamcup")) { if (args.length == 1) { getMain().kamcupcmds.forEach((key,value) -> {completions.add(key);}); + } else { + Temp1 = getMain().kamcupcmds.getOrDefault(args[0],Arrays.asList("",new HashMap())); + Temp2 = (HashMap) Temp1.get(1); + + try { + for (i=2;i {if (key.contains("|to_run|")) {Temp1 = value;}}); + Temp2 = (HashMap) Temp1.get(1); + } + } catch (Exception e) { + return completions; + } + + Temp2.forEach((key,value) -> { + if (key.contains("|to_run|")) { + AllUse.Tab_to_run Temp3 = (AllUse.Tab_to_run) value.get(2); + Temp3.run().forEach((str) -> {completions.add(str);}); + } else { + completions.add(key); + } + }); + } + } + if (cmd.getName().equalsIgnoreCase("dailytask")) { + if (args.length == 1) { + Arrays.asList("put","list").forEach((value) -> {completions.add(value);}); + } + + if (args[0].equalsIgnoreCase("put") & args.length == 2) { + if (sender instanceof Player) { + Player player = (Player) sender; + List tasks = getMain().Player_Daily_Tasks.getOrDefault(player.getUniqueId(),new ArrayList()); + tasks.forEach((value) -> { + if (!value.contains("OK")) { + completions.add(value); + } + }); + } } } return completions; diff --git a/src/main/resources/Daily_Tasks.yml b/src/main/resources/Daily_Tasks.yml new file mode 100644 index 0000000..e5d3435 --- /dev/null +++ b/src/main/resources/Daily_Tasks.yml @@ -0,0 +1,6 @@ +max_daily_task: 5 +daily_tasks: +- Test: + item: apple + count: 1 + give_money: !!float '1' \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 31013a2..aed2ba8 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,23 +1,23 @@ name: KaMC_UtilityPlugin main: com.DrakGod.KaMCUP.Main -version: Beta1.0.1 +version: 1.0 api-version: 1.20.6 description: 这是一个专门为KaMC打造的插件 authors: [Drakgod] website: https://www.kamc.fun +depend: [Essentials] commands: kamcup: description: KaMC实用插件主指令 - usage: /help + usage: /kamcup permission: kamcup.commands.kamcup - car: - description: 领取一个矿车,冷却10秒 - usage: /car - permission: kamcup.commands.car uuid: description: 获取一个玩家的uuid usage: /uuid permission: kamcup.commands.uuid + dailytask: + description: 任务系统指令 + usage: /dailytask [name] permissions: kamcup.*: @@ -25,6 +25,9 @@ permissions: default: op children: kamcup.admin: true + kamcup.null: + description: Null权限 + default: false kamcup.admin: description: 授予管理员权限 default: false @@ -35,14 +38,14 @@ permissions: default: false children: kamcup.commands.kamcup: true - kamcup.commands.car: true kamcup.commands.uuid: true + kamcup.commands.dailytask: true kamcup.commands.kamcup: description: 授予执行/kamcup里所有指令的权限 default: false - kamcup.commands.car: - description: 授予执行/car权限 - default: true kamcup.commands.uuid: description: 授予执行/uuid权限 - default: false \ No newline at end of file + default: false + kamcup.commands.dailytask: + description: 授予执行/dailytask权限 + default: true \ No newline at end of file From b067825af236e0aeecaf1bc8aedac680dfce0818 Mon Sep 17 00:00:00 2001 From: DrakGod <123858459+Drak-God@users.noreply.github.com> Date: Tue, 5 Nov 2024 20:05:13 +0800 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9b29b4f..f9a6eb4 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ - # 简介