From 8424722f00a83d2aa51b4478802bf6c67cf0962f Mon Sep 17 00:00:00 2001 From: LSDog <2509863159@qq.com> Date: Tue, 19 Jul 2022 21:20:33 +0800 Subject: [PATCH] 1.6.0 dev-> major update 1: manage java files Signed-off-by: LSDog <2509863159@qq.com> --- README.md | 2 +- .../CoolDownManager.java => CoolDown.java} | 5 +- src/fun/LSDog/CustomSprays/CustomSprays.java | 79 +----------------- .../LSDog/CustomSprays/CustomSpraysAPI.java | 9 +- src/fun/LSDog/CustomSprays/Events.java | 13 +-- src/fun/LSDog/CustomSprays/SprayParticle.java | 3 +- .../commands/CommandCustomSprays.java | 30 +++---- .../CustomSprays/commands/CommandSpray.java | 9 +- .../{Data => data}/DataManager.java | 2 +- .../{Data => data}/DataMySQL.java | 2 +- .../CustomSprays/{Data => data}/DataYml.java | 2 +- .../CustomSprays/{Data => data}/IData.java | 2 +- .../CustomSprays/{ => metrics}/Metrics.java | 2 +- .../{utils => spray}/ImageParticles.java | 2 +- src/fun/LSDog/CustomSprays/spray/Spray.java | 83 +++++++++++++++++++ .../CustomSprays/{ => spray}/SprayBig.java | 12 +-- .../{ => spray}/SprayFactory.java | 3 +- .../CustomSprays/spray/SprayParticle.java | 4 + .../{Spray.java => spray/SpraySmall.java} | 10 +-- .../{manager => spray}/SpraysManager.java | 29 ++++--- .../CustomSprays/utils/ImageDownloader.java | 2 +- .../CustomSprays/utils/SprayRayTracer.java | 10 +-- 22 files changed, 166 insertions(+), 149 deletions(-) rename src/fun/LSDog/CustomSprays/{manager/CoolDownManager.java => CoolDown.java} (94%) rename src/fun/LSDog/CustomSprays/{Data => data}/DataManager.java (99%) rename src/fun/LSDog/CustomSprays/{Data => data}/DataMySQL.java (99%) rename src/fun/LSDog/CustomSprays/{Data => data}/DataYml.java (99%) rename src/fun/LSDog/CustomSprays/{Data => data}/IData.java (87%) rename src/fun/LSDog/CustomSprays/{ => metrics}/Metrics.java (99%) rename src/fun/LSDog/CustomSprays/{utils => spray}/ImageParticles.java (99%) create mode 100644 src/fun/LSDog/CustomSprays/spray/Spray.java rename src/fun/LSDog/CustomSprays/{ => spray}/SprayBig.java (94%) rename src/fun/LSDog/CustomSprays/{ => spray}/SprayFactory.java (99%) create mode 100644 src/fun/LSDog/CustomSprays/spray/SprayParticle.java rename src/fun/LSDog/CustomSprays/{Spray.java => spray/SpraySmall.java} (96%) rename src/fun/LSDog/CustomSprays/{manager => spray}/SpraysManager.java (82%) diff --git a/README.md b/README.md index 027855f..27288b1 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ ___ > |:---:|---| > |名字
Name |CustomSprays ~ 花样喷漆| > |作者
Author |LSDog| -> |版本
Version |1.5.6| +> |版本
Version |1.6.0| > |支持
Support | Bukkit \ Spigot \ Paper **1.8 ~ 1.19** | > |介绍
Description |让玩家在服务器"喷涂"自定义图片!
Let players spray theirs image in the server!| > |指令
Cmd |`/cspray ...` - 主命令
`/spray` - 喷漆
`/spray big` - 喷大喷漆| diff --git a/src/fun/LSDog/CustomSprays/manager/CoolDownManager.java b/src/fun/LSDog/CustomSprays/CoolDown.java similarity index 94% rename from src/fun/LSDog/CustomSprays/manager/CoolDownManager.java rename to src/fun/LSDog/CustomSprays/CoolDown.java index d059ac1..ed0c7ba 100644 --- a/src/fun/LSDog/CustomSprays/manager/CoolDownManager.java +++ b/src/fun/LSDog/CustomSprays/CoolDown.java @@ -1,13 +1,12 @@ -package fun.LSDog.CustomSprays.manager; +package fun.LSDog.CustomSprays; -import fun.LSDog.CustomSprays.CustomSprays; import org.bukkit.entity.Player; import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -public class CoolDownManager { +public class CoolDown { private static final Map sprayCooldown = new ConcurrentHashMap<>(); private static final Map uploadCooldown = new ConcurrentHashMap<>(); diff --git a/src/fun/LSDog/CustomSprays/CustomSprays.java b/src/fun/LSDog/CustomSprays/CustomSprays.java index 1b6bb5d..5402c34 100644 --- a/src/fun/LSDog/CustomSprays/CustomSprays.java +++ b/src/fun/LSDog/CustomSprays/CustomSprays.java @@ -1,16 +1,15 @@ package fun.LSDog.CustomSprays; -import fun.LSDog.CustomSprays.Data.DataManager; import fun.LSDog.CustomSprays.commands.CommandCustomSprays; import fun.LSDog.CustomSprays.commands.CommandSpray; -import fun.LSDog.CustomSprays.manager.CoolDownManager; +import fun.LSDog.CustomSprays.data.DataManager; import fun.LSDog.CustomSprays.map.MapViewId; +import fun.LSDog.CustomSprays.metrics.Metrics; import fun.LSDog.CustomSprays.utils.MapColors; import fun.LSDog.CustomSprays.utils.UpdateChecker; import org.bukkit.Bukkit; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import java.io.File; @@ -30,82 +29,10 @@ public class CustomSprays extends JavaPlugin { public static String latestVersion = null; - /** - * 让玩家喷漆,若玩家进行大喷漆(3*3)却没有权限,则会变为小喷漆(1*1),默认展示给全服玩家
- * 务必使用 runTaskAsynchronously 异步执行, 否则可能造成卡顿!! - * @param player 喷漆玩家 - * @param isBigSpray 是否为大型喷漆 - */ - public static void spray(Player player, boolean isBigSpray) { - - // 检测喷漆权限 - if (player.isPermissionSet("CustomSprays.spray") && !player.hasPermission("CustomSprays.spray")) { - player.sendMessage(CustomSprays.prefix + DataManager.getMsg(player, "NO_PERMISSION")); - return; - } - // 检测禁止的世界 - if (!player.hasPermission("CustomSprays.nodisable") && DataManager.disableWorlds != null && DataManager.disableWorlds.contains(player.getWorld().getName())) { - player.sendMessage(CustomSprays.prefix + DataManager.getMsg(player, "SPRAY.DISABLED_WORLD")); - return; - } - // 检测CD - if (!player.hasPermission("CustomSprays.nocd") && CoolDownManager.isSprayCooling(player)) { - player.sendMessage(CustomSprays.prefix + DataManager.getMsg(player, "IN_COOLING")+" §7("+CoolDownManager.getSprayCD(player)+")"); - return; - } - - - try { - // 如果 [不是大喷漆 或者 (是大喷漆却)没有大喷漆权限] - if (!isBigSpray || (player.isPermissionSet("CustomSprays.bigspray") && !player.hasPermission("CustomSprays.bigspray"))) { - - // 小喷漆 - byte[] bytes = DataManager.get128pxImageBytes(player); - if (bytes == null) { - player.sendMessage(CustomSprays.prefix + DataManager.getMsg(player, "SPRAY.NO_IMAGE")); - player.sendMessage(CustomSprays.prefix + DataManager.getMsg(player, "SPRAY.NO_IMAGE_TIP")); - return; - } - Spray spray = new Spray(player, bytes, Bukkit.getOnlinePlayers()); - if (spray.create((long) (CustomSprays.instant.getConfig().getDouble("destroy")*20L))) { - CoolDownManager.setSprayCooldown(player,1); - CustomSprays.debug("§f§l" + player.getName() + "§b spray §7->§r " + spray.location.getX() + " " + spray.location.getY() + " " + spray.location.getZ()); - } - - } else { - - // 大喷漆 - int length = CustomSprays.instant.getConfig().getInt("big_size"); - byte[] bytes; - if (length == 3) { - bytes = DataManager.get384pxImageBytes(player); - } else if (length == 5) { - bytes = DataManager.getSizedImageBytes(player, 640, 640); - } else { - return; - } - if (bytes == null) { - player.sendMessage(CustomSprays.prefix + DataManager.getMsg(player, "SPRAY.NO_IMAGE")); - player.sendMessage(CustomSprays.prefix + DataManager.getMsg(player, "SPRAY.NO_IMAGE_TIP")); - return; - } - - Spray spray = new SprayBig(player, length, bytes, Bukkit.getOnlinePlayers()); - if (spray.create((long) (CustomSprays.instant.getConfig().getDouble("destroy")*20L))) { - CoolDownManager.setSprayCooldown(player, CustomSprays.instant.getConfig().getDouble("big_spray_cooldown_multiple")); - CustomSprays.debug("§f§l" + player.getName() + "§b spray §7->§r " + spray.location.getX() + " " + spray.location.getY() + " " + spray.location.getZ() + " (big)"); - } - - } - } catch (Exception e) { - e.printStackTrace(); - } - } - @Override public void onDisable() { try { // ↓ SpraysManager.removeAllSpray(); - Class.forName("fun.LSDog.CustomSprays.manager.SpraysManager").getMethod("removeAllSpray").invoke(null); + Class.forName("fun.LSDog.CustomSprays.spray.SpraysManager").getMethod("removeAllSpray").invoke(null); } catch (Exception ignored) { } // cancel async tasks Bukkit.getScheduler().getActiveWorkers().forEach(bukkitWorker -> { diff --git a/src/fun/LSDog/CustomSprays/CustomSpraysAPI.java b/src/fun/LSDog/CustomSprays/CustomSpraysAPI.java index bc095cb..38a279b 100644 --- a/src/fun/LSDog/CustomSprays/CustomSpraysAPI.java +++ b/src/fun/LSDog/CustomSprays/CustomSpraysAPI.java @@ -1,6 +1,7 @@ package fun.LSDog.CustomSprays; -import fun.LSDog.CustomSprays.Data.DataManager; +import fun.LSDog.CustomSprays.data.DataManager; +import fun.LSDog.CustomSprays.spray.Spray; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -23,9 +24,9 @@ public static Plugin getPlugin() { /** * Get the manager of sprays - * @see fun.LSDog.CustomSprays.manager.SpraysManager + * @see fun.LSDog.CustomSprays.spray.SpraysManager */ - public static class SpraysManager extends fun.LSDog.CustomSprays.manager.SpraysManager { + public static class SpraysManager extends fun.LSDog.CustomSprays.spray.SpraysManager { } /** @@ -39,7 +40,7 @@ public static class ImageUtil extends fun.LSDog.CustomSprays.utils.ImageUtil { * Let player spray his/her image */ public static void spray(Player player, boolean isBigSpray) { - CustomSprays.spray(player, isBigSpray); + Spray.spray(player, isBigSpray); } /** diff --git a/src/fun/LSDog/CustomSprays/Events.java b/src/fun/LSDog/CustomSprays/Events.java index 9f2b527..7e0a286 100644 --- a/src/fun/LSDog/CustomSprays/Events.java +++ b/src/fun/LSDog/CustomSprays/Events.java @@ -1,8 +1,9 @@ package fun.LSDog.CustomSprays; -import fun.LSDog.CustomSprays.Data.DataManager; -import fun.LSDog.CustomSprays.Data.DataMySQL; -import fun.LSDog.CustomSprays.manager.SpraysManager; +import fun.LSDog.CustomSprays.data.DataManager; +import fun.LSDog.CustomSprays.data.DataMySQL; +import fun.LSDog.CustomSprays.spray.Spray; +import fun.LSDog.CustomSprays.spray.SpraysManager; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -38,9 +39,9 @@ public void onToggleF(PlayerSwapHandItemsEvent e) { } else { timeMap.remove(uuid); if (!player.isSneaking()) { // 小喷漆 - Bukkit.getScheduler().runTaskAsynchronously(CustomSprays.instant, () -> CustomSprays.spray(player, false)); + Bukkit.getScheduler().runTaskAsynchronously(CustomSprays.instant, () -> Spray.spray(player, false)); } else { // 大喷漆 - Bukkit.getScheduler().runTaskAsynchronously(CustomSprays.instant, () -> CustomSprays.spray(player, true)); + Bukkit.getScheduler().runTaskAsynchronously(CustomSprays.instant, () -> Spray.spray(player, true)); } } }); @@ -79,7 +80,7 @@ public void onUse(PlayerInteractEvent e) { || !item.getItemMeta().getLore().contains(lore) ) return; } - CustomSprays.spray(e.getPlayer(), e.getPlayer().isSneaking()); + Spray.spray(e.getPlayer(), e.getPlayer().isSneaking()); } } diff --git a/src/fun/LSDog/CustomSprays/SprayParticle.java b/src/fun/LSDog/CustomSprays/SprayParticle.java index d6fc160..11ccd9f 100644 --- a/src/fun/LSDog/CustomSprays/SprayParticle.java +++ b/src/fun/LSDog/CustomSprays/SprayParticle.java @@ -1,10 +1,11 @@ package fun.LSDog.CustomSprays; +import fun.LSDog.CustomSprays.spray.SpraySmall; import org.bukkit.entity.Player; import java.util.Collection; -public class SprayParticle extends Spray { +public class SprayParticle extends SpraySmall { /** diff --git a/src/fun/LSDog/CustomSprays/commands/CommandCustomSprays.java b/src/fun/LSDog/CustomSprays/commands/CommandCustomSprays.java index b1fa843..f0e0883 100644 --- a/src/fun/LSDog/CustomSprays/commands/CommandCustomSprays.java +++ b/src/fun/LSDog/CustomSprays/commands/CommandCustomSprays.java @@ -1,11 +1,11 @@ package fun.LSDog.CustomSprays.commands; +import fun.LSDog.CustomSprays.CoolDown; import fun.LSDog.CustomSprays.CustomSprays; -import fun.LSDog.CustomSprays.Data.DataManager; -import fun.LSDog.CustomSprays.Spray; -import fun.LSDog.CustomSprays.SprayFactory; -import fun.LSDog.CustomSprays.manager.CoolDownManager; -import fun.LSDog.CustomSprays.manager.SpraysManager; +import fun.LSDog.CustomSprays.data.DataManager; +import fun.LSDog.CustomSprays.spray.SprayFactory; +import fun.LSDog.CustomSprays.spray.SpraySmall; +import fun.LSDog.CustomSprays.spray.SpraysManager; import fun.LSDog.CustomSprays.utils.ImageDownloader; import fun.LSDog.CustomSprays.utils.ImageUtil; import fun.LSDog.CustomSprays.utils.NMS; @@ -70,7 +70,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St SpraysManager.removeAllSpray(); CustomSprays.instant.reloadConfig(); DataManager.initialize(CustomSprays.instant.getConfig().getString("storage")); - CoolDownManager.reset(); + CoolDown.reset(); RegionChecker.reload(); Bukkit.getScheduler().getActiveWorkers().forEach(bukkitWorker -> { if (bukkitWorker.getOwner().getName().equals("CustomSprays")) //noinspection deprecation @@ -90,14 +90,14 @@ public void run() { player.sendMessage(CustomSprays.prefix + ". . . . . ."); return; } - if ( !player.hasPermission("CustomSprays.noCD") && CoolDownManager.isUploadCooling(player) ) { - player.sendMessage(CustomSprays.prefix + DataManager.getMsg(player, "IN_COOLING") + " §7("+CoolDownManager.getUploadCool(player)+")"); + if ( !player.hasPermission("CustomSprays.noCD") && CoolDown.isUploadCooling(player) ) { + player.sendMessage(CustomSprays.prefix + DataManager.getMsg(player, "IN_COOLING") + " §7("+ CoolDown.getUploadCool(player)+")"); uploadingSet.remove(player.getUniqueId()); return; } uploadingSet.add(player.getUniqueId()); /* 上传失败了就缩短冷却时间,所谓人性化是也~~ */ - CoolDownManager.setUploadCooldown(player, CustomSprays.instant.getConfig().getDouble("upload_failed_cooldown_multiple")); + CoolDown.setUploadCooldown(player, CustomSprays.instant.getConfig().getDouble("upload_failed_cooldown_multiple")); if (args.length == 1) { player.sendMessage(CustomSprays.prefix + DataManager.getMsg(player, "COMMAND_UPLOAD.NO_URL")); @@ -137,7 +137,7 @@ public void run() { } int size = DataManager.saveImageBytes(player, imgBytes); /* 上传成功了就用原冷却时间,所谓人性化是也~~ */ - CoolDownManager.setUploadCooldown(player, 1); + CoolDown.setUploadCooldown(player, 1); CustomSprays.debug("§f§l" + player.getName() + "§b upload §7->§r (§e§l"+ imageDownloader.size+"k§7>>§e§l"+size/1024+"k§r) " + url); player.sendMessage(CustomSprays.prefix + DataManager.getMsg(player, "COMMAND_UPLOAD.OK")); imageDownloader.close(); @@ -182,8 +182,8 @@ public void run() { player.sendMessage(CustomSprays.prefix + target.getName() + DataManager.getMsg(player, "COMMAND_COPY.NOT_ALLOW")); return; } - if ( !player.hasPermission("CustomSprays.noCD") && CoolDownManager.isUploadCooling(player) ) { - player.sendMessage(CustomSprays.prefix + DataManager.getMsg(player, "IN_COOLING") + " §7("+CoolDownManager.getUploadCool(player)+")"); + if ( !player.hasPermission("CustomSprays.noCD") && CoolDown.isUploadCooling(player) ) { + player.sendMessage(CustomSprays.prefix + DataManager.getMsg(player, "IN_COOLING") + " §7("+ CoolDown.getUploadCool(player)+")"); uploadingSet.remove(player.getUniqueId()); return; } byte[] data = DataManager.data.getImageBytes(target); @@ -192,7 +192,7 @@ public void run() { return; } DataManager.saveImageBytes(player, data); - CoolDownManager.setUploadCooldown(player, CustomSprays.instant.getConfig().getDouble("copy_cooldown_multiple")); + CoolDown.setUploadCooldown(player, CustomSprays.instant.getConfig().getDouble("copy_cooldown_multiple")); sender.sendMessage(CustomSprays.prefix + "OK!" + (player.isOp()&&!allow?" §7§l(OP-bypass)":"") ); } } @@ -274,7 +274,7 @@ public void run() { new BukkitRunnable() { public void run() { - Spray spray = SpraysManager.getSprayInSight(player); + SpraySmall spray = SpraysManager.getSprayInSight(player); if (spray != null) player.sendMessage(CustomSprays.prefix + "§7[" + spray.player.getName() + "§7]"); else player.sendMessage(CustomSprays.prefix + "§7[§8X§7]"); } @@ -293,7 +293,7 @@ public void run() { new BukkitRunnable() { public void run() { - Spray spray = SpraysManager.getSprayInSight(player); + SpraySmall spray = SpraysManager.getSprayInSight(player); if (spray != null) { player.sendMessage(CustomSprays.prefix + "§7[" + spray.player.getName() + "§7]"); spray.remove(); diff --git a/src/fun/LSDog/CustomSprays/commands/CommandSpray.java b/src/fun/LSDog/CustomSprays/commands/CommandSpray.java index f2b3198..6bd2a9d 100644 --- a/src/fun/LSDog/CustomSprays/commands/CommandSpray.java +++ b/src/fun/LSDog/CustomSprays/commands/CommandSpray.java @@ -1,7 +1,8 @@ package fun.LSDog.CustomSprays.commands; import fun.LSDog.CustomSprays.CustomSprays; -import fun.LSDog.CustomSprays.Data.DataManager; +import fun.LSDog.CustomSprays.data.DataManager; +import fun.LSDog.CustomSprays.spray.Spray; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -21,17 +22,17 @@ public boolean onCommand(CommandSender sender, Command command, String label, St if (args.length != 0) { // 大喷漆 if (args[0].equalsIgnoreCase("big")) { - CustomSprays.spray(player, true); + Spray.spray(player, true); return; } else if (args[0].equalsIgnoreCase("small")) { - CustomSprays.spray(player, false); + Spray.spray(player, false); return; } player.sendMessage(CustomSprays.prefix + DataManager.getMsg(player, "SPRAY.TOO_MANY_ARGUMENTS")); return; } // 小喷漆 - CustomSprays.spray(player, false); + Spray.spray(player, false); }); return true; } diff --git a/src/fun/LSDog/CustomSprays/Data/DataManager.java b/src/fun/LSDog/CustomSprays/data/DataManager.java similarity index 99% rename from src/fun/LSDog/CustomSprays/Data/DataManager.java rename to src/fun/LSDog/CustomSprays/data/DataManager.java index 120d63c..8d4a88a 100644 --- a/src/fun/LSDog/CustomSprays/Data/DataManager.java +++ b/src/fun/LSDog/CustomSprays/data/DataManager.java @@ -1,4 +1,4 @@ -package fun.LSDog.CustomSprays.Data; +package fun.LSDog.CustomSprays.data; import fun.LSDog.CustomSprays.CustomSprays; import fun.LSDog.CustomSprays.utils.ImageUtil; diff --git a/src/fun/LSDog/CustomSprays/Data/DataMySQL.java b/src/fun/LSDog/CustomSprays/data/DataMySQL.java similarity index 99% rename from src/fun/LSDog/CustomSprays/Data/DataMySQL.java rename to src/fun/LSDog/CustomSprays/data/DataMySQL.java index 19efdaf..8b6f94b 100644 --- a/src/fun/LSDog/CustomSprays/Data/DataMySQL.java +++ b/src/fun/LSDog/CustomSprays/data/DataMySQL.java @@ -1,4 +1,4 @@ -package fun.LSDog.CustomSprays.Data; +package fun.LSDog.CustomSprays.data; import fun.LSDog.CustomSprays.CustomSprays; import org.bukkit.Bukkit; diff --git a/src/fun/LSDog/CustomSprays/Data/DataYml.java b/src/fun/LSDog/CustomSprays/data/DataYml.java similarity index 99% rename from src/fun/LSDog/CustomSprays/Data/DataYml.java rename to src/fun/LSDog/CustomSprays/data/DataYml.java index 241fcfd..196dbae 100644 --- a/src/fun/LSDog/CustomSprays/Data/DataYml.java +++ b/src/fun/LSDog/CustomSprays/data/DataYml.java @@ -1,4 +1,4 @@ -package fun.LSDog.CustomSprays.Data; +package fun.LSDog.CustomSprays.data; import fun.LSDog.CustomSprays.CustomSprays; import org.bukkit.configuration.file.FileConfiguration; diff --git a/src/fun/LSDog/CustomSprays/Data/IData.java b/src/fun/LSDog/CustomSprays/data/IData.java similarity index 87% rename from src/fun/LSDog/CustomSprays/Data/IData.java rename to src/fun/LSDog/CustomSprays/data/IData.java index 188b2dc..b95b8ac 100644 --- a/src/fun/LSDog/CustomSprays/Data/IData.java +++ b/src/fun/LSDog/CustomSprays/data/IData.java @@ -1,4 +1,4 @@ -package fun.LSDog.CustomSprays.Data; +package fun.LSDog.CustomSprays.data; import org.bukkit.entity.Player; diff --git a/src/fun/LSDog/CustomSprays/Metrics.java b/src/fun/LSDog/CustomSprays/metrics/Metrics.java similarity index 99% rename from src/fun/LSDog/CustomSprays/Metrics.java rename to src/fun/LSDog/CustomSprays/metrics/Metrics.java index e0f633a..d9b32fa 100644 --- a/src/fun/LSDog/CustomSprays/Metrics.java +++ b/src/fun/LSDog/CustomSprays/metrics/Metrics.java @@ -1,4 +1,4 @@ -package fun.LSDog.CustomSprays; +package fun.LSDog.CustomSprays.metrics; import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; diff --git a/src/fun/LSDog/CustomSprays/utils/ImageParticles.java b/src/fun/LSDog/CustomSprays/spray/ImageParticles.java similarity index 99% rename from src/fun/LSDog/CustomSprays/utils/ImageParticles.java rename to src/fun/LSDog/CustomSprays/spray/ImageParticles.java index 890a57a..8136681 100644 --- a/src/fun/LSDog/CustomSprays/utils/ImageParticles.java +++ b/src/fun/LSDog/CustomSprays/spray/ImageParticles.java @@ -1,4 +1,4 @@ -package fun.LSDog.CustomSprays.utils; +package fun.LSDog.CustomSprays.spray; import org.bukkit.Color; import org.bukkit.Location; diff --git a/src/fun/LSDog/CustomSprays/spray/Spray.java b/src/fun/LSDog/CustomSprays/spray/Spray.java new file mode 100644 index 0000000..dd888e5 --- /dev/null +++ b/src/fun/LSDog/CustomSprays/spray/Spray.java @@ -0,0 +1,83 @@ +package fun.LSDog.CustomSprays.spray; + +import fun.LSDog.CustomSprays.CoolDown; +import fun.LSDog.CustomSprays.CustomSprays; +import fun.LSDog.CustomSprays.data.DataManager; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class Spray { + + /** + * 让玩家喷漆,若玩家进行大喷漆(3*3)却没有权限,则会变为小喷漆(1*1),默认展示给全服玩家
+ * 务必使用 runTaskAsynchronously 异步执行, 否则可能造成卡顿!! + * @param player 喷漆玩家 + * @param isBigSpray 是否为大型喷漆 + */ + public static void spray(Player player, boolean isBigSpray) { + + // 检测喷漆权限 + if (player.isPermissionSet("CustomSprays.spray") && !player.hasPermission("CustomSprays.spray")) { + player.sendMessage(CustomSprays.prefix + DataManager.getMsg(player, "NO_PERMISSION")); + return; + } + // 检测禁止的世界 + if (!player.hasPermission("CustomSprays.nodisable") && DataManager.disableWorlds != null && DataManager.disableWorlds.contains(player.getWorld().getName())) { + player.sendMessage(CustomSprays.prefix + DataManager.getMsg(player, "SPRAY.DISABLED_WORLD")); + return; + } + // 检测CD + if (!player.hasPermission("CustomSprays.nocd") && CoolDown.isSprayCooling(player)) { + player.sendMessage(CustomSprays.prefix + DataManager.getMsg(player, "IN_COOLING")+" §7("+ CoolDown.getSprayCD(player)+")"); + return; + } + + + try { + // 如果 [不是大喷漆 或者 (是大喷漆却)没有大喷漆权限] + if (!isBigSpray || (player.isPermissionSet("CustomSprays.bigspray") && !player.hasPermission("CustomSprays.bigspray"))) { + + // 小喷漆 + byte[] bytes = DataManager.get128pxImageBytes(player); + if (bytes == null) { + player.sendMessage(CustomSprays.prefix + DataManager.getMsg(player, "SPRAY.NO_IMAGE")); + player.sendMessage(CustomSprays.prefix + DataManager.getMsg(player, "SPRAY.NO_IMAGE_TIP")); + return; + } + SpraySmall spray = new SpraySmall(player, bytes, Bukkit.getOnlinePlayers()); + if (spray.create((long) (CustomSprays.instant.getConfig().getDouble("destroy")*20L))) { + CoolDown.setSprayCooldown(player,1); + CustomSprays.debug("§f§l" + player.getName() + "§b spray §7->§r " + spray.location.getX() + " " + spray.location.getY() + " " + spray.location.getZ()); + } + + } else { + + // 大喷漆 + int length = CustomSprays.instant.getConfig().getInt("big_size"); + byte[] bytes; + if (length == 3) { + bytes = DataManager.get384pxImageBytes(player); + } else if (length == 5) { + bytes = DataManager.getSizedImageBytes(player, 640, 640); + } else { + return; + } + if (bytes == null) { + player.sendMessage(CustomSprays.prefix + DataManager.getMsg(player, "SPRAY.NO_IMAGE")); + player.sendMessage(CustomSprays.prefix + DataManager.getMsg(player, "SPRAY.NO_IMAGE_TIP")); + return; + } + + SpraySmall spray = new SprayBig(player, length, bytes, Bukkit.getOnlinePlayers()); + if (spray.create((long) (CustomSprays.instant.getConfig().getDouble("destroy")*20L))) { + CoolDown.setSprayCooldown(player, CustomSprays.instant.getConfig().getDouble("big_spray_cooldown_multiple")); + CustomSprays.debug("§f§l" + player.getName() + "§b spray §7->§r " + spray.location.getX() + " " + spray.location.getY() + " " + spray.location.getZ() + " (big)"); + } + + } + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/src/fun/LSDog/CustomSprays/SprayBig.java b/src/fun/LSDog/CustomSprays/spray/SprayBig.java similarity index 94% rename from src/fun/LSDog/CustomSprays/SprayBig.java rename to src/fun/LSDog/CustomSprays/spray/SprayBig.java index 7a75a9a..6b38291 100644 --- a/src/fun/LSDog/CustomSprays/SprayBig.java +++ b/src/fun/LSDog/CustomSprays/spray/SprayBig.java @@ -1,6 +1,6 @@ -package fun.LSDog.CustomSprays; +package fun.LSDog.CustomSprays.spray; -import fun.LSDog.CustomSprays.manager.SpraysManager; +import fun.LSDog.CustomSprays.CustomSprays; import fun.LSDog.CustomSprays.map.MapViewId; import fun.LSDog.CustomSprays.utils.NMS; import org.bukkit.Bukkit; @@ -14,7 +14,7 @@ /** * 3*3或5*5大喷漆 */ -public class SprayBig extends Spray { +public class SprayBig extends SpraySmall { private final int length; private final int[] itemFrameIds; // 九宫格展示框ID (0 ~ length*length) @@ -23,8 +23,8 @@ public class SprayBig extends Spray { /** * BigSpray 的构造器
* - * @see fun.LSDog.CustomSprays.Data.DataManager#get384pxImageBytes(Player) - * @see fun.LSDog.CustomSprays.Data.DataManager#getSizedImageBytes(Player, int, int) + * @see fun.LSDog.CustomSprays.data.DataManager#get384pxImageBytes(Player) + * @see fun.LSDog.CustomSprays.data.DataManager#getSizedImageBytes(Player, int, int) * @param player 喷漆的玩家 * @param pixels Byte color array 必为 384*384 或 640*640 * @param showTo 能看到这个喷漆的玩家 @@ -108,7 +108,7 @@ public void spawn(Collection playersShowTo, boolean playSound) } - if (playSound) Spray.playSpraySound(player); + if (playSound) SpraySmall.playSpraySound(player); } diff --git a/src/fun/LSDog/CustomSprays/SprayFactory.java b/src/fun/LSDog/CustomSprays/spray/SprayFactory.java similarity index 99% rename from src/fun/LSDog/CustomSprays/SprayFactory.java rename to src/fun/LSDog/CustomSprays/spray/SprayFactory.java index 4b425bb..11bb492 100644 --- a/src/fun/LSDog/CustomSprays/SprayFactory.java +++ b/src/fun/LSDog/CustomSprays/spray/SprayFactory.java @@ -1,5 +1,6 @@ -package fun.LSDog.CustomSprays; +package fun.LSDog.CustomSprays.spray; +import fun.LSDog.CustomSprays.CustomSprays; import fun.LSDog.CustomSprays.utils.NMS; import org.bukkit.Location; import org.bukkit.block.BlockFace; diff --git a/src/fun/LSDog/CustomSprays/spray/SprayParticle.java b/src/fun/LSDog/CustomSprays/spray/SprayParticle.java new file mode 100644 index 0000000..b1083cd --- /dev/null +++ b/src/fun/LSDog/CustomSprays/spray/SprayParticle.java @@ -0,0 +1,4 @@ +package fun.LSDog.CustomSprays.spray; + +public class SprayParticle { +} diff --git a/src/fun/LSDog/CustomSprays/Spray.java b/src/fun/LSDog/CustomSprays/spray/SpraySmall.java similarity index 96% rename from src/fun/LSDog/CustomSprays/Spray.java rename to src/fun/LSDog/CustomSprays/spray/SpraySmall.java index f581f26..10bff35 100644 --- a/src/fun/LSDog/CustomSprays/Spray.java +++ b/src/fun/LSDog/CustomSprays/spray/SpraySmall.java @@ -1,7 +1,7 @@ -package fun.LSDog.CustomSprays; +package fun.LSDog.CustomSprays.spray; -import fun.LSDog.CustomSprays.Data.DataManager; -import fun.LSDog.CustomSprays.manager.SpraysManager; +import fun.LSDog.CustomSprays.CustomSprays; +import fun.LSDog.CustomSprays.data.DataManager; import fun.LSDog.CustomSprays.map.MapViewId; import fun.LSDog.CustomSprays.utils.NMS; import fun.LSDog.CustomSprays.utils.RayTracer; @@ -22,7 +22,7 @@ /** * 喷漆本体,包括所有的反射发包方法 */ -public class Spray { +public class SpraySmall { public final Player player; protected final World world; @@ -46,7 +46,7 @@ public class Spray { * @param pixels Byte color array 必为 128*128 * @param showTo The players who can see this spray (in spraying). */ - public Spray(Player player, byte[] pixels, Collection showTo) { + public SpraySmall(Player player, byte[] pixels, Collection showTo) { this.player = player; this.world = player.getWorld(); this.pixels = pixels; diff --git a/src/fun/LSDog/CustomSprays/manager/SpraysManager.java b/src/fun/LSDog/CustomSprays/spray/SpraysManager.java similarity index 82% rename from src/fun/LSDog/CustomSprays/manager/SpraysManager.java rename to src/fun/LSDog/CustomSprays/spray/SpraysManager.java index 2629e4f..fef4360 100644 --- a/src/fun/LSDog/CustomSprays/manager/SpraysManager.java +++ b/src/fun/LSDog/CustomSprays/spray/SpraysManager.java @@ -1,7 +1,6 @@ -package fun.LSDog.CustomSprays.manager; +package fun.LSDog.CustomSprays.spray; import fun.LSDog.CustomSprays.CustomSprays; -import fun.LSDog.CustomSprays.Spray; import fun.LSDog.CustomSprays.utils.SprayRayTracer; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -15,21 +14,21 @@ public class SpraysManager { - public static Map> playerSprayMap = new ConcurrentHashMap<>(); + public static Map> playerSprayMap = new ConcurrentHashMap<>(); - public static Map> locationSprayMap = new ConcurrentHashMap<>(); + public static Map> locationSprayMap = new ConcurrentHashMap<>(); // 注意block指的是喷漆所在的方块而不是依附着的方块 /** * 在喷漆列表中加入新的喷漆, 玩家将会在进入相应世界的时候看到列表中的喷漆 */ - public static void addSpray(Spray spray) { + public static void addSpray(SpraySmall spray) { - List list = playerSprayMap.getOrDefault(spray.player.getUniqueId(), new ArrayList<>()); + List list = playerSprayMap.getOrDefault(spray.player.getUniqueId(), new ArrayList<>()); list.add(spray); playerSprayMap.put(spray.player.getUniqueId(), list); - List locList = locationSprayMap.getOrDefault(spray.block, new ArrayList<>()); + List locList = locationSprayMap.getOrDefault(spray.block, new ArrayList<>()); locList.add(spray); locationSprayMap.put(spray.block, locList); @@ -52,7 +51,7 @@ public static void sendExistSprays(Player player) { /** * 获取某个玩家视角中的喷漆 */ - public static Spray getSprayInSight(Player player) { + public static SpraySmall getSprayInSight(Player player) { Location eyeLocation = player.getEyeLocation(); return new SprayRayTracer(eyeLocation.getDirection(), eyeLocation, CustomSprays.instant.getConfig().getDouble("distance")).rayTraceSpray(SpraysManager::isSpraySurfaceBlock); @@ -64,11 +63,11 @@ public static Spray getSprayInSight(Player player) { * @param blockFace 喷漆朝向 * @return 相应位置的喷漆, 或者没有喷漆返回 null */ - public static Spray getSpray(Block block, BlockFace blockFace) { + public static SpraySmall getSpray(Block block, BlockFace blockFace) { if (block == null || blockFace == null) return null; - for (Spray spray : locationSprayMap.getOrDefault(block, Collections.emptyList())) { + for (SpraySmall spray : locationSprayMap.getOrDefault(block, Collections.emptyList())) { if (blockFace == spray.blockFace) return spray; } @@ -79,15 +78,15 @@ public static Spray getSpray(Block block, BlockFace blockFace) { * 清除喷漆和记录用map中的spray * @param spray 喷漆 */ - public static void removeSpray(Spray spray) { + public static void removeSpray(SpraySmall spray) { // spray.remove(); - List playerSprayList = playerSprayMap.getOrDefault(spray.player.getUniqueId(), new ArrayList<>()); + List playerSprayList = playerSprayMap.getOrDefault(spray.player.getUniqueId(), new ArrayList<>()); if (!playerSprayList.isEmpty()) playerSprayList.remove(spray); playerSprayMap.put(spray.player.getUniqueId(), playerSprayList); - List locSprayList = locationSprayMap.getOrDefault(spray.block, new ArrayList<>()); + List locSprayList = locationSprayMap.getOrDefault(spray.block, new ArrayList<>()); if (!locSprayList.isEmpty()) locSprayList.remove(spray); locationSprayMap.put(spray.block, locSprayList); } @@ -97,12 +96,12 @@ public static void removeSpray(Spray spray) { */ public static void removeAllSpray() { - Set deleteSprays = new HashSet<>(); + Set deleteSprays = new HashSet<>(); locationSprayMap.values().forEach(deleteSprays::addAll); // 我们姑且不去担心两个map不一样的情况,随便吧 - deleteSprays.forEach(Spray::remove); + deleteSprays.forEach(SpraySmall::remove); playerSprayMap.clear(); locationSprayMap.clear(); diff --git a/src/fun/LSDog/CustomSprays/utils/ImageDownloader.java b/src/fun/LSDog/CustomSprays/utils/ImageDownloader.java index 4e5ebed..8eb12e5 100644 --- a/src/fun/LSDog/CustomSprays/utils/ImageDownloader.java +++ b/src/fun/LSDog/CustomSprays/utils/ImageDownloader.java @@ -1,7 +1,7 @@ package fun.LSDog.CustomSprays.utils; import fun.LSDog.CustomSprays.CustomSprays; -import fun.LSDog.CustomSprays.Data.DataManager; +import fun.LSDog.CustomSprays.data.DataManager; import javax.imageio.ImageIO; import javax.net.ssl.SSLHandshakeException; diff --git a/src/fun/LSDog/CustomSprays/utils/SprayRayTracer.java b/src/fun/LSDog/CustomSprays/utils/SprayRayTracer.java index 39d6e26..5575a9c 100644 --- a/src/fun/LSDog/CustomSprays/utils/SprayRayTracer.java +++ b/src/fun/LSDog/CustomSprays/utils/SprayRayTracer.java @@ -1,7 +1,7 @@ package fun.LSDog.CustomSprays.utils; -import fun.LSDog.CustomSprays.Spray; -import fun.LSDog.CustomSprays.manager.SpraysManager; +import fun.LSDog.CustomSprays.spray.SpraySmall; +import fun.LSDog.CustomSprays.spray.SpraysManager; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.util.Vector; @@ -25,7 +25,7 @@ public SprayRayTracer(Vector direction, Location startLocation, double maxLong) * 检测视线中的喷漆 * @param blockChecker 算遮挡方块 */ - public Spray rayTraceSpray(Predicate blockChecker) { + public SpraySmall rayTraceSpray(Predicate blockChecker) { // 循环向前查找方块 while (distance <= max) { @@ -62,8 +62,8 @@ public Spray rayTraceSpray(Predicate blockChecker) { // 循环探测中取到的方块 Block block = world.getBlockAt(bx, by, bz); // 获取目标点的方块 - Spray spray = SpraysManager.getSpray(block.getRelative(face), face); // 获取指向的可能存在的喷漆 - Spray backSpray = SpraysManager.getSpray(block, face.getOppositeFace()); // 获取指向的可能存在的背对着视线的喷漆 + SpraySmall spray = SpraysManager.getSpray(block.getRelative(face), face); // 获取指向的可能存在的喷漆 + SpraySmall backSpray = SpraysManager.getSpray(block, face.getOppositeFace()); // 获取指向的可能存在的背对着视线的喷漆 if (backSpray != null) return backSpray; // 背向视线的喷漆总是先被"指向" if (spray != null) return spray; // 如果没有就看看背向视角的 if (blockChecker.test(block)) return null; // 如果是遮挡方块则返回null