diff --git a/README.md b/README.md index 87b4996..1bc0d05 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# Starlin_L2 -[![License](https://img.shields.io/badge/license-CC%20BY--NC--ND--4.0-green?style=flat-square)](http://creativecommons.org/licenses/by-nc-nd/4.0) [![Pull Requests](https://img.shields.io/github/issues-pr-closed/katorlys/Starlin_L2?style=flat-square)](https://github.com/katorlys/Starlin_L2/pulls) [![Issues](https://img.shields.io/github/issues-closed/katorlys/Starlin_L2?style=flat-square)](https://github.com/katorlys/Starlin_L2/issues) [![Lines](https://img.shields.io/tokei/lines/github/katorlys/Starlin_L2?style=flat-square)](https://github.com/katorlys/Starlin_L2) [![Build](https://img.shields.io/github/workflow/status/katorlys/Starlin_L2/Build?style=flat-square)](https://github.com/katorlys/Starlin_L2/actions/workflows/build.yml) [![Codacy](https://img.shields.io/codacy/grade/b187c52b9b754ed8a670a3017201c05f?style=flat-square)](https://app.codacy.com/gh/katorlys/Starlin_L2) +# StarlinUtils +[![License](https://img.shields.io/badge/license-CC%20BY--NC--ND--4.0-green?style=flat-square)](http://creativecommons.org/licenses/by-nc-nd/4.0) [![Pull Requests](https://img.shields.io/github/issues-pr-closed/katorlys/StarlinUtils?style=flat-square)](https://github.com/katorlys/StarlinUtils/pulls) [![Issues](https://img.shields.io/github/issues-closed/katorlys/StarlinUtils?style=flat-square)](https://github.com/katorlys/StarlinUtils/issues) [![Lines](https://img.shields.io/tokei/lines/github/katorlys/StarlinUtils?style=flat-square)](https://github.com/katorlys/StarlinUtils) [![Build](https://img.shields.io/github/workflow/status/katorlys/StarlinUtils/Build?style=flat-square)](https://github.com/katorlys/StarlinUtils/actions/workflows/build.yml) [![Codacy](https://img.shields.io/codacy/grade/b187c52b9b754ed8a670a3017201c05f?style=flat-square)](https://app.codacy.com/gh/katorlys/StarlinUtils) ## Introduction -Starlin_L2 Minecraft Spigot plugin made for StarlinWorld (星林宇宙) server.
+StarlinUtils Minecraft Spigot plugin made for StarlinWorld (星林宇宙) server.
Main functions:
- Prevent players from stucking in the Nether Portal when logging in. @@ -12,11 +12,14 @@ Main functions:
- Record player's first-join time and monthly online time. - Record the server's monthly players. ![](https://cdn.jsdelivr.net/gh/katorly/Gallery001/plugins/2022-01-20_14.52.png) -- Conveniently manage player's fly. +- Conveniently manage player's flying permission. - Displays the help document when player excutes `/help`. +- Modifys colored concretes' recipe into the following **shapeless** recipe: +![](https://cdn.jsdelivr.net/gh/katorly/Gallery001/plugins/2022_03_11_11.28.30.PNG) ## Commands -- `/l2 time [player]` Displays the first-join time and total online time of the excutor or the specific player. +- `/su time [player]` Displays the first-join time and total online time of the excutor or the specific player. +- `/su info` Displays information about the player who excutes the command. - `/help` Displays the help document. For server OPs, - `/givefly ` Gives a specific player fly. diff --git a/pom.xml b/pom.xml index 8354584..85a7197 100644 --- a/pom.xml +++ b/pom.xml @@ -2,9 +2,9 @@ 4.0.0 - starlin_l2 + StarlinUtils com.github.katorly - 1.0.4 + 1.0.5 diff --git a/src/main/java/com/github/katorly/starlin_l2/EventListener.java b/src/main/java/com/github/katorly/starlinutils/EventListener.java similarity index 86% rename from src/main/java/com/github/katorly/starlin_l2/EventListener.java rename to src/main/java/com/github/katorly/starlinutils/EventListener.java index badc50d..1f1e2ae 100644 --- a/src/main/java/com/github/katorly/starlin_l2/EventListener.java +++ b/src/main/java/com/github/katorly/starlinutils/EventListener.java @@ -1,13 +1,13 @@ -package com.github.katorly.starlin_l2; +package com.github.katorly.starlinutils; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; -import com.github.katorly.starlin_l2.backup.ConfigReader; -import com.github.katorly.starlin_l2.backup.Messager; -import com.github.katorly.starlin_l2.utils.PlayTime; +import com.github.katorly.starlinutils.backup.ConfigReader; +import com.github.katorly.starlinutils.backup.Messager; +import com.github.katorly.starlinutils.utils.PlayTime; import org.bukkit.Location; import org.bukkit.Material; @@ -30,21 +30,21 @@ public void onPlayerJoin(PlayerJoinEvent e) throws ParseException { PlayTime.initialize(e.getPlayer()); //Get player's join time and check whether player has joined before. long t = System.currentTimeMillis(); - FileConfiguration monthly = starlin_l2.monthly.getConfig(); //Record monthly players. + FileConfiguration monthly = StarlinUtils.monthly.getConfig(); //Record monthly players. String pname = e.getPlayer().getName(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM"); String timenow = dateFormat.format(t); - if (!starlin_l2.monthly.getConfig().contains(timenow)) { + if (!StarlinUtils.monthly.getConfig().contains(timenow)) { List plist = new ArrayList(); plist.add(pname); monthly.set(timenow, plist); - ConfigReader.save(starlin_l2.monthly); + ConfigReader.save(StarlinUtils.monthly); } else { List plist = monthly.getStringList(timenow); if (!plist.contains(pname)) { plist.add(pname); monthly.set(timenow, plist); - ConfigReader.save(starlin_l2.monthly); + ConfigReader.save(StarlinUtils.monthly); } } @@ -71,7 +71,7 @@ public void run() { String x0 = String.format("%.2f", x); String y0 = String.format("%.2f", y); String z0 = String.format("%.2f", z); Messager.sendMessage(p, "&b&l星林宇宙 &r&8>> &7下界门位置: " + x0 + ", " + y0 + ", " + z0); } - }.runTaskLater(starlin_l2.INSTANCE, 4L); + }.runTaskLater(StarlinUtils.INSTANCE, 4L); } } diff --git a/src/main/java/com/github/katorly/starlinutils/Recipe.java b/src/main/java/com/github/katorly/starlinutils/Recipe.java new file mode 100644 index 0000000..14506d7 --- /dev/null +++ b/src/main/java/com/github/katorly/starlinutils/Recipe.java @@ -0,0 +1,34 @@ +package com.github.katorly.starlinutils; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.ShapelessRecipe; + +public class Recipe { + public static void registerConcreteRecipe() { //Add colored concrete recipe onEnable + Recipe.concreteRecipe(Material.BLACK_CONCRETE, Material.BLACK_DYE); + Recipe.concreteRecipe(Material.BLUE_CONCRETE, Material.BLUE_DYE); + Recipe.concreteRecipe(Material.BROWN_CONCRETE, Material.BROWN_DYE); + Recipe.concreteRecipe(Material.CYAN_CONCRETE, Material.CYAN_DYE); + Recipe.concreteRecipe(Material.GRAY_CONCRETE, Material.GRAY_DYE); + Recipe.concreteRecipe(Material.GREEN_CONCRETE, Material.GREEN_DYE); + Recipe.concreteRecipe(Material.LIGHT_BLUE_CONCRETE, Material.LIGHT_BLUE_DYE); + Recipe.concreteRecipe(Material.LIGHT_GRAY_CONCRETE, Material.LIGHT_GRAY_DYE); + Recipe.concreteRecipe(Material.LIME_CONCRETE, Material.LIME_DYE); + Recipe.concreteRecipe(Material.MAGENTA_CONCRETE, Material.MAGENTA_DYE); + Recipe.concreteRecipe(Material.ORANGE_CONCRETE, Material.ORANGE_DYE); + Recipe.concreteRecipe(Material.PINK_CONCRETE, Material.PINK_DYE); + Recipe.concreteRecipe(Material.PURPLE_CONCRETE, Material.PURPLE_DYE); + Recipe.concreteRecipe(Material.RED_CONCRETE, Material.RED_DYE); + Recipe.concreteRecipe(Material.WHITE_CONCRETE, Material.WHITE_DYE); + Recipe.concreteRecipe(Material.YELLOW_CONCRETE, Material.YELLOW_DYE); + } + + public static void concreteRecipe(Material concrete, Material dye) { //8*colored concrete = 1*dye + 8*stones. + ShapelessRecipe concreteRecipe = new ShapelessRecipe(new NamespacedKey(StarlinUtils.INSTANCE, concrete.toString() + "_recipe"), new ItemStack(concrete, 8)); + concreteRecipe = concreteRecipe.addIngredient(1, dye).addIngredient(8, Material.STONE); + Bukkit.addRecipe(concreteRecipe); + } +} \ No newline at end of file diff --git a/src/main/java/com/github/katorly/starlin_l2/starlin_l2.java b/src/main/java/com/github/katorly/starlinutils/StarlinUtils.java similarity index 61% rename from src/main/java/com/github/katorly/starlin_l2/starlin_l2.java rename to src/main/java/com/github/katorly/starlinutils/StarlinUtils.java index c0e3c3e..4147069 100644 --- a/src/main/java/com/github/katorly/starlin_l2/starlin_l2.java +++ b/src/main/java/com/github/katorly/starlinutils/StarlinUtils.java @@ -1,22 +1,23 @@ -package com.github.katorly.starlin_l2; +package com.github.katorly.starlinutils; import java.text.ParseException; import java.util.HashMap; import java.util.Map; import java.util.UUID; -import com.github.katorly.starlin_l2.backup.ConfigReader; -import com.github.katorly.starlin_l2.utils.PlayTime; -import com.github.katorly.starlin_l2.commands.*; +import com.github.katorly.starlinutils.backup.ConfigReader; +import com.github.katorly.starlinutils.commands.*; +import com.github.katorly.starlinutils.festival.AprilFools; +import com.github.katorly.starlinutils.utils.PlayTime; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; import org.bukkit.plugin.java.JavaPlugin; -public class starlin_l2 extends JavaPlugin { - public static starlin_l2 INSTANCE; - public starlin_l2() { +public class StarlinUtils extends JavaPlugin { + public static StarlinUtils INSTANCE; + public StarlinUtils() { INSTANCE = this; } @@ -28,25 +29,27 @@ public starlin_l2() { @Override public void onEnable() { getServer().getPluginManager().registerEvents(new EventListener(),this); + getServer().getPluginManager().registerEvents(new AprilFools(),this); config = new ConfigReader(this,"","config.yml"); config.saveDefaultConfig(); timedata = new ConfigReader(this,"","timedata.yml"); monthly = new ConfigReader(this,"","monthly.yml"); - Bukkit.getPluginCommand("l2").setExecutor(new l2()); - Bukkit.getPluginCommand("l2").setTabCompleter(new l2()); + Bukkit.getPluginCommand("su").setExecutor(new su()); + Bukkit.getPluginCommand("su").setTabCompleter(new su()); Bukkit.getPluginCommand("help").setExecutor(new help()); Bukkit.getPluginCommand("givefly").setExecutor(new givefly()); Bukkit.getPluginCommand("givefly").setTabCompleter(new givefly()); Bukkit.getPluginCommand("listfly").setExecutor(new listfly()); Bukkit.getPluginCommand("delfly").setExecutor(new delfly()); Bukkit.getPluginCommand("delfly").setTabCompleter(new delfly()); - Bukkit.getLogger().info("[starlin_l2] Repo: https://github.com/katorlys/Starlin_L2"); - Bukkit.getLogger().info("[starlin_l2] Starlin_L2 enabled! Made for StarlinWorld server only."); + Recipe.registerConcreteRecipe(); //Add colored concrete + Bukkit.getLogger().info("[StarlinUtils] Repo: https://github.com/katorlys/StarlinUtils"); + Bukkit.getLogger().info("[StarlinUtils] StarlinUtils enabled! Made for StarlinWorld server only."); for (Player p : Bukkit.getOnlinePlayers()) { try { PlayTime.initialize(p); } catch (ParseException e) { - Bukkit.getLogger().severe("[starlin_l2] Error counting player's monthly play time."); + Bukkit.getLogger().severe("[StarlinUtils] Error counting player's monthly play time."); e.printStackTrace(); } } @@ -58,14 +61,15 @@ public void onDisable() { try { PlayTime.settle(p); } catch (ParseException e) { - Bukkit.getLogger().severe("[starlin_l2] Error counting player's monthly play time."); + Bukkit.getLogger().severe("[StarlinUtils] Error counting player's monthly play time."); e.printStackTrace(); } } + Bukkit.clearRecipes(); HandlerList.unregisterAll(this); ConfigReader.save(config); ConfigReader.save(timedata); ConfigReader.save(monthly); - Bukkit.getLogger().info("[starlin_l2] Starlin_L2 disabled!"); + Bukkit.getLogger().info("[StarlinUtils] StarlinUtils disabled!"); } } \ No newline at end of file diff --git a/src/main/java/com/github/katorly/starlin_l2/backup/ConfigReader.java b/src/main/java/com/github/katorly/starlinutils/backup/ConfigReader.java similarity index 98% rename from src/main/java/com/github/katorly/starlin_l2/backup/ConfigReader.java rename to src/main/java/com/github/katorly/starlinutils/backup/ConfigReader.java index ca8b23f..57ea217 100644 --- a/src/main/java/com/github/katorly/starlin_l2/backup/ConfigReader.java +++ b/src/main/java/com/github/katorly/starlinutils/backup/ConfigReader.java @@ -1,4 +1,4 @@ -package com.github.katorly.starlin_l2.backup; +package com.github.katorly.starlinutils.backup; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; diff --git a/src/main/java/com/github/katorly/starlin_l2/backup/Messager.java b/src/main/java/com/github/katorly/starlinutils/backup/Messager.java similarity index 94% rename from src/main/java/com/github/katorly/starlin_l2/backup/Messager.java rename to src/main/java/com/github/katorly/starlinutils/backup/Messager.java index 55a33df..3c74870 100644 --- a/src/main/java/com/github/katorly/starlin_l2/backup/Messager.java +++ b/src/main/java/com/github/katorly/starlinutils/backup/Messager.java @@ -1,4 +1,4 @@ -package com.github.katorly.starlin_l2.backup; +package com.github.katorly.starlinutils.backup; import java.util.Objects; import org.bukkit.Bukkit; diff --git a/src/main/java/com/github/katorly/starlin_l2/commands/delfly.java b/src/main/java/com/github/katorly/starlinutils/commands/delfly.java similarity index 93% rename from src/main/java/com/github/katorly/starlin_l2/commands/delfly.java rename to src/main/java/com/github/katorly/starlinutils/commands/delfly.java index e11f478..e489f38 100644 --- a/src/main/java/com/github/katorly/starlin_l2/commands/delfly.java +++ b/src/main/java/com/github/katorly/starlinutils/commands/delfly.java @@ -1,10 +1,10 @@ -package com.github.katorly.starlin_l2.commands; +package com.github.katorly.starlinutils.commands; import java.util.ArrayList; import java.util.List; import java.util.Objects; -import com.github.katorly.starlin_l2.backup.Messager; +import com.github.katorly.starlinutils.backup.Messager; import org.bukkit.Bukkit; import org.bukkit.command.Command; diff --git a/src/main/java/com/github/katorly/starlin_l2/commands/givefly.java b/src/main/java/com/github/katorly/starlinutils/commands/givefly.java similarity index 93% rename from src/main/java/com/github/katorly/starlin_l2/commands/givefly.java rename to src/main/java/com/github/katorly/starlinutils/commands/givefly.java index 2dbb24f..cad59ce 100644 --- a/src/main/java/com/github/katorly/starlin_l2/commands/givefly.java +++ b/src/main/java/com/github/katorly/starlinutils/commands/givefly.java @@ -1,10 +1,10 @@ -package com.github.katorly.starlin_l2.commands; +package com.github.katorly.starlinutils.commands; import java.util.ArrayList; import java.util.List; import java.util.Objects; -import com.github.katorly.starlin_l2.backup.Messager; +import com.github.katorly.starlinutils.backup.Messager; import org.bukkit.Bukkit; import org.bukkit.command.Command; diff --git a/src/main/java/com/github/katorly/starlin_l2/commands/help.java b/src/main/java/com/github/katorly/starlinutils/commands/help.java similarity index 73% rename from src/main/java/com/github/katorly/starlin_l2/commands/help.java rename to src/main/java/com/github/katorly/starlinutils/commands/help.java index f36cb76..2500d24 100644 --- a/src/main/java/com/github/katorly/starlin_l2/commands/help.java +++ b/src/main/java/com/github/katorly/starlinutils/commands/help.java @@ -1,7 +1,7 @@ -package com.github.katorly.starlin_l2.commands; +package com.github.katorly.starlinutils.commands; -import com.github.katorly.starlin_l2.starlin_l2; -import com.github.katorly.starlin_l2.backup.Messager; +import com.github.katorly.starlinutils.StarlinUtils; +import com.github.katorly.starlinutils.backup.Messager; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -11,7 +11,7 @@ public class help implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - FileConfiguration config = starlin_l2.config.getConfig(); + FileConfiguration config = StarlinUtils.config.getConfig(); if (command.getName().equalsIgnoreCase("help")) { //Displays the help document when player excutes "/help". Messager.senderMessage(sender, "&b&l星林宇宙 &r&8>> &7新手指南: &f" + config.getString("help-document")); } diff --git a/src/main/java/com/github/katorly/starlin_l2/commands/listfly.java b/src/main/java/com/github/katorly/starlinutils/commands/listfly.java similarity index 90% rename from src/main/java/com/github/katorly/starlin_l2/commands/listfly.java rename to src/main/java/com/github/katorly/starlinutils/commands/listfly.java index b93c899..c289340 100644 --- a/src/main/java/com/github/katorly/starlin_l2/commands/listfly.java +++ b/src/main/java/com/github/katorly/starlinutils/commands/listfly.java @@ -1,6 +1,6 @@ -package com.github.katorly.starlin_l2.commands; +package com.github.katorly.starlinutils.commands; -import com.github.katorly.starlin_l2.backup.Messager; +import com.github.katorly.starlinutils.backup.Messager; import org.bukkit.Bukkit; import org.bukkit.command.Command; diff --git a/src/main/java/com/github/katorly/starlin_l2/commands/l2.java b/src/main/java/com/github/katorly/starlinutils/commands/su.java similarity index 54% rename from src/main/java/com/github/katorly/starlin_l2/commands/l2.java rename to src/main/java/com/github/katorly/starlinutils/commands/su.java index 09395ab..b97e1e2 100644 --- a/src/main/java/com/github/katorly/starlin_l2/commands/l2.java +++ b/src/main/java/com/github/katorly/starlinutils/commands/su.java @@ -1,11 +1,11 @@ -package com.github.katorly.starlin_l2.commands; +package com.github.katorly.starlinutils.commands; import java.util.ArrayList; import java.util.List; import java.util.Objects; -import com.github.katorly.starlin_l2.starlin_l2; -import com.github.katorly.starlin_l2.backup.Messager; +import com.github.katorly.starlinutils.StarlinUtils; +import com.github.katorly.starlinutils.backup.Messager; import org.bukkit.Bukkit; import org.bukkit.command.Command; @@ -14,31 +14,31 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; -public class l2 implements TabExecutor { +public class su implements TabExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - FileConfiguration timedata = starlin_l2.timedata.getConfig(); - if (command.getName().equalsIgnoreCase("l2")) { //Main command of the plugin. + FileConfiguration timedata = StarlinUtils.timedata.getConfig(); + if (command.getName().equalsIgnoreCase("su")) { //Main command of the plugin. if (args.length < 1) { - Messager.senderMessage(sender, "&b&l星林宇宙 &r&8>> &7用法: /l2 <参数>. 可用参数: time"); + Messager.senderMessage(sender, "&b&l星林宇宙 &r&8>> &7用法: /su <参数>. 可用参数: time"); } else if (Objects.equals(args[0], "time")) { //Get player's play time information. if (args.length == 1) { if (!(sender instanceof Player)) { - Messager.senderMessage(sender, "&b&l星林宇宙 &r&8>> &7用法: /l2 time <玩家ID>."); + Messager.senderMessage(sender, "&b&l星林宇宙 &r&8>> &7用法: /su time <玩家ID>."); } else { Player player = (Player) sender; String u = player.getUniqueId().toString(); String pname = player.getName().toString(); String first_time; - if (starlin_l2.timedata.getConfig().contains(u + ".first-time")) first_time = timedata.getString(u + ".first-time"); + if (StarlinUtils.timedata.getConfig().contains(u + ".first-time")) first_time = timedata.getString(u + ".first-time"); else first_time = "未知"; String total_time; - if (starlin_l2.timedata.getConfig().contains(u + ".total")) total_time = String.format("%.1f", timedata.getDouble(u + ".total")); + if (StarlinUtils.timedata.getConfig().contains(u + ".total")) total_time = String.format("%.1f", timedata.getDouble(u + ".total")); else total_time = "未知"; - Messager.sendMessage(player, "&b&l星林宇宙 &r&8>> &7您 (&f" + pname + "&7) 的游玩信息:"); + Messager.sendMessage(player, "&b&l星林宇宙 &r&8>> &7您 (&f" + pname + "&7) 的在线时长:"); Messager.sendMessage(player, " &7首次加入: &f" + first_time); Messager.sendMessage(player, " &7总计时长: &f" + total_time + " 小时"); - Messager.sendMessage(player, " &7游玩信息在您退出重进后会更新."); + Messager.sendMessage(player, " &7在线时长在您退出重进后会更新."); } } else if (args.length == 2) { Player p = null; @@ -51,23 +51,39 @@ public boolean onCommand(CommandSender sender, Command command, String label, St String u = p.getUniqueId().toString(); String pname = p.getName().toString(); String first_time; - if (starlin_l2.timedata.getConfig().contains(u + ".first-time")) first_time = timedata.getString(u + ".first-time"); + if (StarlinUtils.timedata.getConfig().contains(u + ".first-time")) first_time = timedata.getString(u + ".first-time"); else first_time = "未知"; String total_time; - if (starlin_l2.timedata.getConfig().contains(u + ".total")) total_time = String.format("%.1f", timedata.getDouble(u + ".total")); + if (StarlinUtils.timedata.getConfig().contains(u + ".total")) total_time = String.format("%.1f", timedata.getDouble(u + ".total")); else total_time = "未知"; - Messager.senderMessage(sender, "&b&l星林宇宙 &r&8>> &7玩家 &f" + pname + "&7 的游玩信息:"); + Messager.senderMessage(sender, "&b&l星林宇宙 &r&8>> &7玩家 &f" + pname + "&7 的在线时长:"); Messager.senderMessage(sender, " &7首次加入: &f" + first_time); Messager.senderMessage(sender, " &7总计时长: &f" + total_time + " 小时"); - Messager.senderMessage(sender, " &7游玩信息在该玩家退出重进后会更新."); + Messager.senderMessage(sender, " &7在线时长在该玩家退出重进后会更新."); } else { Messager.senderMessage(sender, "&b&l星林宇宙 &r&8>> &7玩家不在线或不存在!"); } } else { - Messager.senderMessage(sender, "&b&l星林宇宙 &r&8>> &7用法: /l2 time [玩家ID]."); + Messager.senderMessage(sender, "&b&l星林宇宙 &r&8>> &7用法: /su time [玩家ID]."); + } + } else if (Objects.equals(args[0], "info")) { //Displays player's in-game information + if (!(sender instanceof Player)) { + Messager.senderMessage(sender, "&b&l星林宇宙 &r&8>> &7只有玩家才能查看自己的游戏状态!"); + } else { + Player p= (Player) sender; + Messager.senderMessage(p, "&b&l星林宇宙 &r&8>> &7您当前的游戏状态:"); + Messager.senderMessage(p, " &7游戏ID: &f" + p.getName()); + Messager.senderMessage(p, " &7UUID: &f" + p.getUniqueId()); + Messager.senderMessage(p, " &7生命值: &f" + p.getHealth()); + Messager.senderMessage(p, " &7饱食度: &f" + p.getFoodLevel()); + Messager.senderMessage(p, " &7经验等级: &f" + p.getLevel()); + Messager.senderMessage(p, " &7游戏模式: &f" + p.getGameMode()); + Messager.senderMessage(p, " &7面朝: &f" + p.getFacing()); + Messager.senderMessage(p, " &7当前位置: &f" + p.getWorld().getName() + ", " + String.format("%.2f", p.getLocation().getX()) + ", " + String.format("%.2f", p.getLocation().getY()) + ", " + String.format("%.2f", p.getLocation().getZ())); + Messager.senderMessage(p, " &7延迟: &f" + p.getPing() + "ms"); } } else { - Messager.senderMessage(sender, "&b&l星林宇宙 &r&8>> &7用法: /l2 <参数>. 可用参数: time"); + Messager.senderMessage(sender, "&b&l星林宇宙 &r&8>> &7用法: /su <参数>. 可用参数: time"); } } return true; @@ -81,6 +97,7 @@ public List onTabComplete(CommandSender sender, Command command, String if (args.length == 1) { List sub = new ArrayList<>(); sub.add("time"); + sub.add("info"); return sub; } if (args.length == 2) { diff --git a/src/main/java/com/github/katorly/starlinutils/festival/AprilFools.java b/src/main/java/com/github/katorly/starlinutils/festival/AprilFools.java new file mode 100644 index 0000000..3994389 --- /dev/null +++ b/src/main/java/com/github/katorly/starlinutils/festival/AprilFools.java @@ -0,0 +1,51 @@ +package com.github.katorly.starlinutils.festival; + +import java.text.SimpleDateFormat; +import java.util.Objects; + +import com.github.katorly.starlinutils.backup.Messager; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.*; +import org.bukkit.event.player.*; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class AprilFools implements Listener { + public boolean isToday(String date) { + long t = System.currentTimeMillis(); + SimpleDateFormat d = new SimpleDateFormat("MM-dd"); + String n = d.format(t); + if (Objects.equals(n, date)) return true; + else return false; + } + + @EventHandler + public void onPlayerLogin(PlayerLoginEvent e) { + if (isToday("04-01") && !e.getPlayer().isOp()) { + Messager.sendMessage(e.getPlayer(), "&7&o[Server: 你被选中作为地球ol测试者, 将于今晚23:00入睡后进入游戏"); + } + } + + @EventHandler + public void onPlayerDeath(PlayerDeathEvent e) { + if (isToday("04-01")) { + e.setDeathMessage(e.getEntity().getName() + "被海林干死了"); + } + } + + @EventHandler + public void onPlayerEat(PlayerToggleSneakEvent e) { + if (isToday("04-01")) { + e.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, 200, 1)); + } + } + + @EventHandler + public void onPlayerTP(PlayerTeleportEvent e) { + if (isToday("04-01")) { + Messager.sendTitle(e.getPlayer(), "&c&l芜湖, 起飞!", "&7你起飞了!"); + } + } +} diff --git a/src/main/java/com/github/katorly/starlin_l2/utils/PlayTime.java b/src/main/java/com/github/katorly/starlinutils/utils/PlayTime.java similarity index 72% rename from src/main/java/com/github/katorly/starlin_l2/utils/PlayTime.java rename to src/main/java/com/github/katorly/starlinutils/utils/PlayTime.java index 8f8a71a..1d97a5c 100644 --- a/src/main/java/com/github/katorly/starlin_l2/utils/PlayTime.java +++ b/src/main/java/com/github/katorly/starlinutils/utils/PlayTime.java @@ -1,11 +1,11 @@ -package com.github.katorly.starlin_l2.utils; +package com.github.katorly.starlinutils.utils; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; -import com.github.katorly.starlin_l2.starlin_l2; -import com.github.katorly.starlin_l2.backup.ConfigReader; +import com.github.katorly.starlinutils.StarlinUtils; +import com.github.katorly.starlinutils.backup.ConfigReader; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; @@ -16,35 +16,35 @@ public static void initialize(Player p) throws ParseException { //Get player's j SimpleDateFormat dnow = new SimpleDateFormat("yyyy-MM-dd HH:mm"); Date d1 = dnow.parse(dnow.format(t)); Long t1 = d1.getTime(); - starlin_l2.INSTANCE.StartTime.put(p.getPlayer().getUniqueId(), t1); + StarlinUtils.INSTANCE.StartTime.put(p.getPlayer().getUniqueId(), t1); } public static void settle(Player p) throws ParseException { //Count player's total & monthly play time. - FileConfiguration timedata = starlin_l2.timedata.getConfig(); + FileConfiguration timedata = StarlinUtils.timedata.getConfig(); long t = System.currentTimeMillis(); SimpleDateFormat d = new SimpleDateFormat("yyyy"); String year = d.format(t); String u = p.getPlayer().getUniqueId().toString(); Long minutes; - if (!starlin_l2.timedata.getConfig().contains(u)) { + if (!StarlinUtils.timedata.getConfig().contains(u)) { timedata.set(u + ".name", p.getName()); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm"); String timenow = dateFormat.format(t); timedata.set(u + ".first-time", timenow); timedata.set(u + ".total", 0.0); timedata.set(u + ".month-time." + year, "0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0"); - ConfigReader.save(starlin_l2.timedata); - } else if (!starlin_l2.timedata.getConfig().contains(u + ".month-time." + year)) { + ConfigReader.save(StarlinUtils.timedata); + } else if (!StarlinUtils.timedata.getConfig().contains(u + ".month-time." + year)) { timedata.set(u + ".month-time." + year, "0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0"); - ConfigReader.save(starlin_l2.timedata); + ConfigReader.save(StarlinUtils.timedata); } else { - if (starlin_l2.INSTANCE.StartTime.containsKey(p.getPlayer().getUniqueId())) { - Long t1 =starlin_l2.INSTANCE.StartTime.get(p.getPlayer().getUniqueId()); + if (StarlinUtils.INSTANCE.StartTime.containsKey(p.getPlayer().getUniqueId())) { + Long t1 =StarlinUtils.INSTANCE.StartTime.get(p.getPlayer().getUniqueId()); SimpleDateFormat dnow = new SimpleDateFormat("yyyy-MM-dd HH:mm"); Date d2 = dnow.parse(dnow.format(t)); Long t2 = d2.getTime(); minutes = (t2 - t1) / (1000 * 60); - starlin_l2.INSTANCE.StartTime.remove(p.getPlayer().getUniqueId()); + StarlinUtils.INSTANCE.StartTime.remove(p.getPlayer().getUniqueId()); String ytime = timedata.getString(u + ".month-time." + year); String[] mtime = ytime.split(","); SimpleDateFormat n = new SimpleDateFormat("M"); @@ -55,7 +55,7 @@ public static void settle(Player p) throws ParseException { //Count player's tot timedata.set(u + ".month-time." + year, newtime); Double newtotal = Double.valueOf(String.format("%.1f", timedata.getDouble(u + ".total"))) + minutes / 60.0; timedata.set(u + ".total", Double.valueOf(String.format("%.1f", newtotal))); - ConfigReader.save(starlin_l2.timedata); + ConfigReader.save(StarlinUtils.timedata); } } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index a511407..946077e 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,13 +1,13 @@ -name: starlin_l2 -version: "1.0.4" +name: StarlinUtils +version: 1.0.5 author: Katorly -main: com.github.katorly.starlin_l2.starlin_l2 +main: com.github.katorly.starlinutils.StarlinUtils api-version: 1.18 description: A Spigot plugin made for StarlinWorld. commands: - l2: - description: The main command of Starlin_L2. - usage: /l2 + su: + description: The main command of StarlinUtils. + usage: /su help: description: Displays the help document. usage: /help