Skip to content

Commit

Permalink
1.6.0 dev-> major update 1: manage java files
Browse files Browse the repository at this point in the history
Signed-off-by: LSDog <2509863159@qq.com>
  • Loading branch information
LSDog committed Jul 19, 2022
1 parent 2db52c4 commit 8424722
Show file tree
Hide file tree
Showing 22 changed files with 166 additions and 149 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ___
> |:---:|---|
> |名字 <br> Name |CustomSprays ~ 花样喷漆|
> |作者 <br> Author |LSDog|
> |版本 <br> Version |1.5.6|
> |版本 <br> Version |1.6.0|
> |支持 <br> Support | Bukkit \ Spigot \ Paper **1.8 ~ 1.19** |
> |介绍 <br> Description |让玩家在服务器"喷涂"自定义图片!<br>Let players spray theirs image in the server!|
> |指令 <br> Cmd |`/cspray ...` - 主命令 <br>`/spray` - 喷漆<br>`/spray big` - 喷大喷漆|
Expand Down
Original file line number Diff line number Diff line change
@@ -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<UUID, Long> sprayCooldown = new ConcurrentHashMap<>();
private static final Map<UUID, Long> uploadCooldown = new ConcurrentHashMap<>();
Expand Down
79 changes: 3 additions & 76 deletions src/fun/LSDog/CustomSprays/CustomSprays.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -30,82 +29,10 @@ public class CustomSprays extends JavaPlugin {

public static String latestVersion = null;

/**
* 让玩家喷漆,若玩家进行大喷漆(3*3)却没有权限,则会变为小喷漆(1*1),默认展示给全服玩家 <br>
* <b>务必使用 runTaskAsynchronously 异步执行, 否则可能造成卡顿!!</b>
* @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 -> {
Expand Down
9 changes: 5 additions & 4 deletions src/fun/LSDog/CustomSprays/CustomSpraysAPI.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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 {
}

/**
Expand All @@ -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);
}

/**
Expand Down
13 changes: 7 additions & 6 deletions src/fun/LSDog/CustomSprays/Events.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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));
}
}
});
Expand Down Expand Up @@ -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());
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/fun/LSDog/CustomSprays/SprayParticle.java
Original file line number Diff line number Diff line change
@@ -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 {


/**
Expand Down
30 changes: 15 additions & 15 deletions src/fun/LSDog/CustomSprays/commands/CommandCustomSprays.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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"));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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)":"") );
}
}
Expand Down Expand Up @@ -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]");
}
Expand All @@ -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();
Expand Down
9 changes: 5 additions & 4 deletions src/fun/LSDog/CustomSprays/commands/CommandSpray.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fun.LSDog.CustomSprays.Data;
package fun.LSDog.CustomSprays.data;

import fun.LSDog.CustomSprays.CustomSprays;
import org.bukkit.Bukkit;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fun.LSDog.CustomSprays.Data;
package fun.LSDog.CustomSprays.data;

import org.bukkit.entity.Player;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fun.LSDog.CustomSprays;
package fun.LSDog.CustomSprays.metrics;

import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fun.LSDog.CustomSprays.utils;
package fun.LSDog.CustomSprays.spray;

import org.bukkit.Color;
import org.bukkit.Location;
Expand Down
Loading

0 comments on commit 8424722

Please sign in to comment.