Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
fc048a450b | |||
e5e2d065a4 | |||
710d2679a6 | |||
a6a710f671 | |||
dfb821ca23 | |||
9c462690dc | |||
7744442575 | |||
78bb6c9447 | |||
5896a30928 |
18
README.md
18
README.md
@ -18,9 +18,7 @@
|
|||||||
|
|
||||||
## 说明
|
## 说明
|
||||||
|
|
||||||
本插件大约相当于 [ImageFrame](https://github.com/LOOHP/ImageFrame)
|
本插件大约相当于 [ImageFrame](https://github.com/LOOHP/ImageFrame)的简版以及 [ImageMaps](https://github.com/SydMontague/ImageMaps) 的高版本重制版。前者功能丰富,不过可能由于项目体量较大,对于新版本的兼容较慢,后者在1.18 开始就停止了更新,且不支持 Folia 核心。
|
||||||
的简版以及 [ImageMaps](https://github.com/SydMontague/ImageMaps) 的高版本重制版。前者功能丰富,不过可能由于项目体量较大,对于新版本的兼容较慢,后者在
|
|
||||||
1.18 开始就停止了更新,切不支持 Folia 核心。
|
|
||||||
|
|
||||||
## 功能介绍
|
## 功能介绍
|
||||||
|
|
||||||
@ -31,7 +29,7 @@
|
|||||||
|
|
||||||
## 支持版本
|
## 支持版本
|
||||||
|
|
||||||
- 1.20.1+ (Spigot、Paper、Folia)
|
- 1.20.1+ (Paper、Folia)
|
||||||
|
|
||||||
## 安装方法
|
## 安装方法
|
||||||
|
|
||||||
@ -76,15 +74,21 @@
|
|||||||
### 配置文件参考
|
### 配置文件参考
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
# 地图画阵列的最大尺寸 宽
|
||||||
MaxFrameX: 32
|
MaxFrameX: 32
|
||||||
|
|
||||||
|
# 地图画阵列的最大尺寸 高
|
||||||
MaxFrameY: 18
|
MaxFrameY: 18
|
||||||
|
|
||||||
CheckUpdate: true
|
# 是否启用经济系统 消耗玩家金钱生成地图画
|
||||||
|
|
||||||
Economy:
|
Economy:
|
||||||
Enable: false
|
Enable: false
|
||||||
CostPerMap: 100.0
|
CostPerMap: 100.0 # 每张地图画的单价 - 3*3的地图画需要9张地图画 也就是 9*100 = 900
|
||||||
|
|
||||||
|
# 图床地址白名单,不在白名单中的图床将无法使用,留空表示不启用地址白名单
|
||||||
|
AddressWhiteList: []
|
||||||
|
|
||||||
|
CheckUpdate: true
|
||||||
|
|
||||||
Debug: false
|
Debug: false
|
||||||
```
|
```
|
||||||
|
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>cn.lunadeer</groupId>
|
<groupId>cn.lunadeer</groupId>
|
||||||
<artifactId>ColorfulMap</artifactId>
|
<artifactId>ColorfulMap</artifactId>
|
||||||
<version>2.1</version>
|
<version>2.6</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>ColorfulMap</name>
|
<name>ColorfulMap</name>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package cn.lunadeer.colorfulmap;
|
package cn.lunadeer.colorfulmap;
|
||||||
|
|
||||||
|
import cn.lunadeer.colorfulmap.commands.Purge;
|
||||||
import cn.lunadeer.colorfulmap.commands.Reload;
|
import cn.lunadeer.colorfulmap.commands.Reload;
|
||||||
import cn.lunadeer.colorfulmap.commands.ToMap;
|
import cn.lunadeer.colorfulmap.commands.ToMap;
|
||||||
import cn.lunadeer.colorfulmap.utils.*;
|
import cn.lunadeer.colorfulmap.utils.*;
|
||||||
@ -14,14 +15,15 @@ public final class ColorfulMap extends JavaPlugin {
|
|||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
// Plugin startup logic
|
// Plugin startup logic
|
||||||
instance = this;
|
instance = this;
|
||||||
config = new Configuration(this);
|
|
||||||
new XLogger(this);
|
new XLogger(this);
|
||||||
|
config = new Configuration(this);
|
||||||
XLogger.setDebug(config.isDebug());
|
XLogger.setDebug(config.isDebug());
|
||||||
new Notification(this);
|
new Notification(this);
|
||||||
new Scheduler(this);
|
new Scheduler(this);
|
||||||
|
|
||||||
Objects.requireNonNull(Bukkit.getPluginCommand("tomap")).setExecutor(new ToMap());
|
Objects.requireNonNull(Bukkit.getPluginCommand("tomap")).setExecutor(new ToMap());
|
||||||
Objects.requireNonNull(Bukkit.getPluginCommand("reloadColorfulMap")).setExecutor(new Reload());
|
Objects.requireNonNull(Bukkit.getPluginCommand("reloadColorfulMap")).setExecutor(new Reload());
|
||||||
|
Objects.requireNonNull(Bukkit.getPluginCommand("purgeColorfulMap")).setExecutor(new Purge());
|
||||||
|
|
||||||
Bukkit.getPluginManager().registerEvents(new Events(), this);
|
Bukkit.getPluginManager().registerEvents(new Events(), this);
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@ import cn.lunadeer.colorfulmap.utils.VaultConnect.VaultConnect;
|
|||||||
import cn.lunadeer.colorfulmap.utils.XLogger;
|
import cn.lunadeer.colorfulmap.utils.XLogger;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Configuration {
|
public class Configuration {
|
||||||
|
|
||||||
public Configuration(ColorfulMap plugin) {
|
public Configuration(ColorfulMap plugin) {
|
||||||
@ -22,10 +24,12 @@ public class Configuration {
|
|||||||
_check_update = _file.getBoolean("CheckUpdate", true);
|
_check_update = _file.getBoolean("CheckUpdate", true);
|
||||||
_economy_enable = _file.getBoolean("Economy.Enable", false);
|
_economy_enable = _file.getBoolean("Economy.Enable", false);
|
||||||
_price = (float) _file.getDouble("Economy.CostPerMap", 100.0);
|
_price = (float) _file.getDouble("Economy.CostPerMap", 100.0);
|
||||||
|
_address_white_list = _file.getStringList("AddressWhiteList");
|
||||||
if (_economy_enable) {
|
if (_economy_enable) {
|
||||||
XLogger.info("已启用经济系统");
|
XLogger.info("已启用经济系统");
|
||||||
new VaultConnect(_plugin);
|
new VaultConnect(_plugin);
|
||||||
}
|
}
|
||||||
|
saveAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveAll() {
|
public void saveAll() {
|
||||||
@ -35,6 +39,7 @@ public class Configuration {
|
|||||||
_file.set("CheckUpdate", _check_update);
|
_file.set("CheckUpdate", _check_update);
|
||||||
_file.set("Economy.Enable", _economy_enable);
|
_file.set("Economy.Enable", _economy_enable);
|
||||||
_file.set("Economy.CostPerMap", _price);
|
_file.set("Economy.CostPerMap", _price);
|
||||||
|
_file.set("AddressWhiteList", _address_white_list);
|
||||||
_plugin.saveConfig();
|
_plugin.saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,6 +103,16 @@ public class Configuration {
|
|||||||
_plugin.saveConfig();
|
_plugin.saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getAddressWhiteList() {
|
||||||
|
return _address_white_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAddressWhiteList(List<String> address_white_list) {
|
||||||
|
_address_white_list = address_white_list;
|
||||||
|
_file.set("AddressWhiteList", address_white_list);
|
||||||
|
_plugin.saveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
private final ColorfulMap _plugin;
|
private final ColorfulMap _plugin;
|
||||||
private FileConfiguration _file;
|
private FileConfiguration _file;
|
||||||
private Boolean _debug;
|
private Boolean _debug;
|
||||||
@ -106,4 +121,5 @@ public class Configuration {
|
|||||||
private Boolean _check_update;
|
private Boolean _check_update;
|
||||||
private Boolean _economy_enable;
|
private Boolean _economy_enable;
|
||||||
private Float _price;
|
private Float _price;
|
||||||
|
private List<String > _address_white_list;
|
||||||
}
|
}
|
||||||
|
@ -122,6 +122,27 @@ public class MapManager implements Listener {
|
|||||||
return savedImages.get(world_name.getName()).get(id);
|
return savedImages.get(world_name.getName()).get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Integer> getMapIds(World world) {
|
||||||
|
if (!savedImages.containsKey(world.getName())) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
return new ArrayList<>(savedImages.get(world.getName()).keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeMap(World world, Integer id) {
|
||||||
|
if (!savedImages.containsKey(world.getName())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FileConfiguration config = dataFile.getConfig();
|
||||||
|
String path = config.getString(world.getName() + "." + id);
|
||||||
|
if (path == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
new File(path).delete();
|
||||||
|
config.set(world.getName() + "." + id, null);
|
||||||
|
dataFile.saveConfig();
|
||||||
|
savedImages.get(world.getName()).remove(id);
|
||||||
|
}
|
||||||
|
|
||||||
static class MapsFile {
|
static class MapsFile {
|
||||||
|
|
||||||
|
@ -110,4 +110,34 @@ public class StorageMaps {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void purgeStorageFolder() {
|
||||||
|
File[] map_folders = new File(data_folder, "maps").listFiles();
|
||||||
|
if (map_folders == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (File map_folder : map_folders) {
|
||||||
|
if (!map_folder.isDirectory()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
File[] files = map_folder.listFiles();
|
||||||
|
if (files == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<String> filenames = new ArrayList<>();
|
||||||
|
for (File file : files) {
|
||||||
|
filenames.add(file.getName());
|
||||||
|
}
|
||||||
|
if (filenames.isEmpty()) {
|
||||||
|
map_folder.delete();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!filenames.contains("meta.txt")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (files.length == 3 && filenames.contains("raw.png") && filenames.contains("thumb.png") && filenames.contains("meta.txt")) {
|
||||||
|
map_folder.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
49
src/main/java/cn/lunadeer/colorfulmap/commands/Purge.java
Normal file
49
src/main/java/cn/lunadeer/colorfulmap/commands/Purge.java
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package cn.lunadeer.colorfulmap.commands;
|
||||||
|
|
||||||
|
import cn.lunadeer.colorfulmap.ColorfulMap;
|
||||||
|
import cn.lunadeer.colorfulmap.MapManager;
|
||||||
|
import cn.lunadeer.colorfulmap.StorageMaps;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Item;
|
||||||
|
import org.bukkit.entity.ItemFrame;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.map.MapView;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Purge implements CommandExecutor {
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
|
ColorfulMap.instance.getServer().getWorlds().forEach(world -> {
|
||||||
|
List<Integer> worldMapIds = new ArrayList<>();
|
||||||
|
world.getEntities().forEach(entity -> {
|
||||||
|
if (!(entity instanceof org.bukkit.entity.ItemFrame)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ItemFrame itemFrame = (ItemFrame) entity;
|
||||||
|
if (!itemFrame.getItem().getType().equals(org.bukkit.Material.FILLED_MAP)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ItemStack item = itemFrame.getItem();
|
||||||
|
MapView mapView = ((org.bukkit.inventory.meta.MapMeta) item.getItemMeta()).getMapView();
|
||||||
|
if (mapView == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
worldMapIds.add(mapView.getId());
|
||||||
|
});
|
||||||
|
List<Integer> currentIds = MapManager.instance.getMapIds(world);
|
||||||
|
for (Integer id : currentIds) {
|
||||||
|
if (!worldMapIds.contains(id)) {
|
||||||
|
MapManager.instance.removeMap(world, id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
StorageMaps.purgeStorageFolder();
|
||||||
|
MapManager.instance.reloadImages();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ import cn.lunadeer.colorfulmap.ColorfulMap;
|
|||||||
import cn.lunadeer.colorfulmap.StorageMaps;
|
import cn.lunadeer.colorfulmap.StorageMaps;
|
||||||
import cn.lunadeer.colorfulmap.utils.ImageTool;
|
import cn.lunadeer.colorfulmap.utils.ImageTool;
|
||||||
import cn.lunadeer.colorfulmap.utils.Notification;
|
import cn.lunadeer.colorfulmap.utils.Notification;
|
||||||
|
import cn.lunadeer.colorfulmap.utils.UrlTools;
|
||||||
import cn.lunadeer.colorfulmap.utils.VaultConnect.VaultConnect;
|
import cn.lunadeer.colorfulmap.utils.VaultConnect.VaultConnect;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -24,8 +25,16 @@ public class Multi {
|
|||||||
|
|
||||||
public static ItemStack generate(Player player, String url, Float scale) {
|
public static ItemStack generate(Player player, String url, Float scale) {
|
||||||
try {
|
try {
|
||||||
|
if (!UrlTools.isInWhiteList(url)) {
|
||||||
|
Notification.error(player, "无法生成地图画: 此图床地址不被允许使用");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
URL _url = new URL(url);
|
URL _url = new URL(url);
|
||||||
BufferedImage raw_image = ImageIO.read(_url);
|
BufferedImage raw_image = ImageIO.read(_url);
|
||||||
|
if (raw_image == null) {
|
||||||
|
Notification.error(player, "无法读取有效图片,请检查图片地址是否正确或者更换图床");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
BufferedImage resized_image;
|
BufferedImage resized_image;
|
||||||
if (scale != 1.0) {
|
if (scale != 1.0) {
|
||||||
resized_image = ImageTool.resize(raw_image, scale);
|
resized_image = ImageTool.resize(raw_image, scale);
|
||||||
|
25
src/main/java/cn/lunadeer/colorfulmap/utils/UrlTools.java
Normal file
25
src/main/java/cn/lunadeer/colorfulmap/utils/UrlTools.java
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package cn.lunadeer.colorfulmap.utils;
|
||||||
|
|
||||||
|
import cn.lunadeer.colorfulmap.ColorfulMap;
|
||||||
|
|
||||||
|
public class UrlTools {
|
||||||
|
|
||||||
|
public static boolean isInWhiteList(String url) {
|
||||||
|
if (ColorfulMap.config.getAddressWhiteList().isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
for (String whiteUrl : ColorfulMap.config.getAddressWhiteList()) {
|
||||||
|
if (url.startsWith(whiteUrl)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (url.startsWith("http://" + whiteUrl)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (url.startsWith("https://" + whiteUrl)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -6,6 +6,8 @@ Economy:
|
|||||||
Enable: false
|
Enable: false
|
||||||
CostPerMap: 100.0
|
CostPerMap: 100.0
|
||||||
|
|
||||||
|
AddressWhiteList: []
|
||||||
|
|
||||||
CheckUpdate: true
|
CheckUpdate: true
|
||||||
|
|
||||||
Debug: false
|
Debug: false
|
@ -13,6 +13,10 @@ commands:
|
|||||||
description: 重载ColorfulMap配置
|
description: 重载ColorfulMap配置
|
||||||
usage: /reloadColorfulMap
|
usage: /reloadColorfulMap
|
||||||
permission: colorfulmap.reload
|
permission: colorfulmap.reload
|
||||||
|
purgeColorfulMap:
|
||||||
|
description: 清除无效的地图画
|
||||||
|
usage: /purgeColorfulMap
|
||||||
|
permission: colorfulmap.purge
|
||||||
permissions:
|
permissions:
|
||||||
colorfulmap.tomap:
|
colorfulmap.tomap:
|
||||||
description: 允许使用/tomap命令
|
description: 允许使用/tomap命令
|
||||||
@ -20,3 +24,6 @@ permissions:
|
|||||||
colorfulmap.reload:
|
colorfulmap.reload:
|
||||||
description: 允许使用/reloadColorfulMap命令
|
description: 允许使用/reloadColorfulMap命令
|
||||||
default: op
|
default: op
|
||||||
|
colorfulmap.purge:
|
||||||
|
description: 允许使用/purgeColorfulMap命令
|
||||||
|
default: op
|
||||||
|
Loading…
Reference in New Issue
Block a user