Skip to content

Commit

Permalink
Merge pull request #3 from xinyihl/master
Browse files Browse the repository at this point in the history
Some update
  • Loading branch information
YDHusky authored Nov 10, 2023
2 parents 082001d + b05f3e5 commit eff8e9a
Show file tree
Hide file tree
Showing 20 changed files with 95 additions and 129 deletions.
41 changes: 21 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,36 @@
### 玩家指令
- /sm help 插件帮助
- /sm gui 打开标记点GUI
- /sm add [name] [icon] 添加标记点
- /sm add [name] <icon> 添加标记点
- /sm addhelp 添加标记点帮助
- /sm del [name] 删除标记点
### 添加帮助
/sm add name [icon] 添加标记点
[icon]为可选参数,应该为图片直链
建议32x32大小的图片
若不加[icon]则默认为命名牌
icon默认图片链接可在config.yml修改
也可以使用指令修改
#### 告示牌添加

### 管理员指令
- /asm help 插件管理员帮助
- /asm gui 打开标记点管理GUI
- /asm del [name] 删除标记点
- /asm info [name] 查看name标记点的所有信息
- /asm set [icon] 设置默认icon链接
- /asm search 查看所有标记点
- /asm reload 插件重载

#### 添加帮助
/sm add [name] <icon> 添加标记点
[icon]为可选参数,应该为图片直链,建议32x32大小的图片
若不加 <icon> 则默认为命名牌,icon默认图片链接可在config.yml修改
也可以使用指令 /asm set [icon] 修改

### 告示牌添加
第一行:[map]
第二行:name1
第三行:name2
第四行:icon直链
前三行为必要,第四行不写使用默认图标
破坏告示牌不会删除标记,需要使用指令删除
### 管理员指令
- /asm help 插件管理员帮助
- /asm gui 打开标记点管理GUI
- /asm del name 删除标记点
- /asm get name 查看name标记点的所有信息
- /asm set icon 设置默认icon链接
- /asm search &查看所有标记点
- /asm reload 插件重载

### 注意事项
本插件需要以[BlueMap](https://github.com/BlueMap-Minecraft/BlueMap)作为前置插件
本插件使用1.19的paper-api,但1.20测试可用
其他版本未测试
本插件使用1.19的paper-api,但1.20测试可用,其他版本未测试
管理员权限节点:`bluemapsetmarkers.admin`

>欢迎各位对插件提出建议反馈bug(QQ:3088506834)
> 欢迎各位对插件提出建议反馈bug(QQ:3088506834)
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.siberianhusy</groupId>
<artifactId>BlueMapSetMarkers</artifactId>
<version>2.0</version>
<version>2.1</version>
<packaging>jar</packaging>

<name>BlueMapSetMarkers</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
import org.siberianhusy.bluemapsetmarkers.events.AdminGUIEvent;
import org.siberianhusy.bluemapsetmarkers.events.PlayerGUIEvent;
import org.siberianhusy.bluemapsetmarkers.events.SignWatcher;
import org.siberianhusy.bluemapsetmarkers.utils.LoadData;

import java.util.Objects;

import static org.siberianhusy.bluemapsetmarkers.utils.LoadData.*;

public class BlueMapSetMarkers extends JavaPlugin {
public static BlueMapSetMarkers plugin;

Expand All @@ -24,19 +23,19 @@ public void onEnable() {
plugin = this;
this.saveResource("Data/data.yml",false);
//创建标记数据储存文件
createFiles();
LoadData.createFiles();
//加载并注册标签和标记
for (World world : Bukkit.getWorlds()) {
loadWorldMarkerSet(world);
registerWorld(world);
LoadData.loadWorldMarkerSet(world);
LoadData.registerWorld(world);
}
//获取BlueMap WEB路径
BlueMapAPI.onEnable(api -> Data.webRoot = api.getWebApp().getWebRoot());
//保存默认配置文件
this.saveDefaultConfig();
//保存语言文件
this.saveResource("Messages/messages.yml",false);
loadPlayerData();
LoadData.loadPlayerData();
//注册玩家指令
Objects.requireNonNull(Bukkit.getPluginCommand("BlueMapSetMarkers")).setExecutor(new PlayerCommands());
Objects.requireNonNull(Bukkit.getPluginCommand("BlueMapSerMarkersAdmin")).setExecutor(new AdminCommands());
Expand All @@ -46,16 +45,15 @@ public void onEnable() {
//注册事件
Bukkit.getPluginManager().registerEvents(new PlayerGUIEvent(),this);
Bukkit.getPluginManager().registerEvents(new AdminGUIEvent(),this);
Bukkit.getPluginManager().registerEvents(new SignWatcher(), this);
Bukkit.getPluginManager().registerEvents(new SignWatcher(),this);
this.getLogger().info("BlueMapMarkers加载完成!欢迎使用!");
}

@Override
public void onDisable() {
this.getLogger().info("开始保存数据!");
// 插件卸载时执行
for (World world : Bukkit.getWorlds()) saveWorldMarkerSet(world);
savePlayerData();
for (World world : Bukkit.getWorlds()) LoadData.saveWorldMarkerSet(world);
LoadData.savePlayerData();
this.getLogger().info("BlueMapSetMarkers已卸载!感谢使用!");
}
}
12 changes: 11 additions & 1 deletion src/main/java/org/siberianhusy/bluemapsetmarkers/api/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@

import java.awt.image.BufferedImage;

import static org.siberianhusy.bluemapsetmarkers.utils.Get.getBufferedImage;
import static org.siberianhusy.bluemapsetmarkers.utils.Util.getBufferedImage;

public class Api {
/**
* @param name 要删除的标记名称
* @param world 要删除的标记所在世界
* @return 返回 true 删除成功
*/
//删除标记点
public static boolean delMarker(String name, World world){
if (!Judge.judgeMarkerName(name)){
Expand All @@ -23,6 +28,11 @@ public static boolean delMarker(String name, World world){
}
}

/**
* @param location Location
* @param name 要添加的标记名称
* @param icon 要添加的标记图标
*/
//添加标记
public static void addMarker(Location location, String name, String icon){
Vector2i anchor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ else if (args.length==1){
}
//查看所有标记点名字
else if (args[0].equalsIgnoreCase("search")){
List<String> nameList = Get.getMarkersNameList();
List<String> nameList = Util.getMarkersNameList();
StringBuilder message = new StringBuilder("&c现有的标记点:&9");
for (String mes : nameList){
message.append(mes).append(" ");
Expand Down Expand Up @@ -63,7 +63,7 @@ else if (args.length==2) {
return true;
}
//获取标记点信息
else if (args[0].equalsIgnoreCase("get")){
else if (args[0].equalsIgnoreCase("info")){
SendMessages.sendMarkerInfo(args[1],player);
return true;
}
Expand Down Expand Up @@ -108,14 +108,13 @@ else if (args[0].equalsIgnoreCase("reload")){
//其他指令需要在游戏中使用
else {
sender.sendMessage(Replace.replaceColor("&c其他指令需要在游戏中使用"));

return true;
}
}
}

@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
return AdminTabList.returnList(strings,strings.length,commandSender);
return AdminTabList.returnList(strings,strings.length);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ else if (args.length==2) {
//添加默认图标的标记
if (args[0].equalsIgnoreCase("add")){
Location location = player.getLocation();
AddMarker.addMarker(location,args[1],Get.getConfigString("iconUrl"),player);
AddMarker.addMarker(location,args[1], Util.getConfigString("iconUrl"),player);
return true;
}
//删除标记
Expand All @@ -68,19 +68,17 @@ else if (args[0].equalsIgnoreCase("del")) {
Location location = player.getLocation();
AddMarker.addMarker(location,args[1],args[2],player);
SendMessages.sendMessagesString(sender,"add",args[1]);
return true;
}
//否则返回帮助列表
else {
SendMessages.sendMessagesList(sender,"help");
return true;
}
}
//返回帮助列表
else {
SendMessages.sendMessagesList(sender,"help");
return true;
}
return true;
}
//当命令发送者不为玩家时执行
else {
Expand All @@ -91,6 +89,6 @@ else if (args[0].equalsIgnoreCase("del")) {

@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
return PlayerTabList.returnList(strings,strings.length,commandSender);
return PlayerTabList.returnList(strings,strings.length);
}
}
10 changes: 2 additions & 8 deletions src/main/java/org/siberianhusy/bluemapsetmarkers/data/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.siberianhusy.bluemapsetmarkers.BlueMapSetMarkers;
import org.siberianhusy.bluemapsetmarkers.utils.Get;
import org.siberianhusy.bluemapsetmarkers.utils.Util;

import java.io.File;
import java.nio.file.Path;
Expand All @@ -15,22 +15,16 @@
import java.util.concurrent.ConcurrentHashMap;

public class Data {

//BlueMap WEB路径
public static Path webRoot;

//创建存储地图和MarkerSet的映射
public static Map<World, MarkerSet> worldMarkers = new ConcurrentHashMap<>();

//创建数据配置
public static List<PlayerData> playerData = new ArrayList<>();
public static File messagesFile = new File(BlueMapSetMarkers.plugin.getDataFolder(), "Messages/messages.yml");
public static FileConfiguration messages = YamlConfiguration.loadConfiguration(messagesFile);

//世界列表
public static List<World> worldList = Get.getWorldList();


public static List<World> worldList = Util.getWorldList();
public static File dataFile = new File(BlueMapSetMarkers.plugin.getDataFolder(), "Data/data.yml");
public static FileConfiguration data = YamlConfiguration.loadConfiguration(dataFile);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@
public class PlayerData {
private String player;
private String name;

public String getPlayer() {
return player;
}

public void setPlayer(String player) {
this.player = player;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import org.siberianhusy.bluemapsetmarkers.data.Data;
import org.siberianhusy.bluemapsetmarkers.gui.AdminGUI;
import org.siberianhusy.bluemapsetmarkers.utils.DelMarker;
import org.siberianhusy.bluemapsetmarkers.utils.Get;
import org.siberianhusy.bluemapsetmarkers.utils.SendMessages;
import org.siberianhusy.bluemapsetmarkers.utils.Util;

import java.util.List;

Expand All @@ -34,9 +34,9 @@ public static void adminMarkerGUIClick(InventoryClickEvent event){
if (event.getWhoClicked().getOpenInventory().getTitle().equals("标记列表-管理")){
event.setCancelled(true);
Player player = (Player) event.getWhoClicked();
List<String> markers = Get.getMarkerList(world);
List<String> markers = Util.getMarkerList(world);
if (event.getRawSlot()<= markers.size()){
Marker marker = Get.getMarker(world,markers.get(event.getRawSlot()));
Marker marker = Util.getMarker(world,markers.get(event.getRawSlot()));
if (event.isLeftClick()){
Vector3d pos ;
if (marker!=null){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.siberianhusy.bluemapsetmarkers.data.Data;
import org.siberianhusy.bluemapsetmarkers.gui.PlayerGUI;
import org.siberianhusy.bluemapsetmarkers.utils.DelMarker;
import org.siberianhusy.bluemapsetmarkers.utils.Get;
import org.siberianhusy.bluemapsetmarkers.utils.Util;

import java.util.List;

Expand All @@ -31,7 +31,7 @@ public static void playerMarkerGUIClick(InventoryClickEvent event){
if (event.getWhoClicked().getOpenInventory().getTitle().equals("标记列表-玩家")){
event.setCancelled(true);
Player player = (Player) event.getWhoClicked();
List<String> markerList = Get.getMarkerList(world);
List<String> markerList = Util.getMarkerList(world);
if (event.getRawSlot()<=markerList.size()){
if (event.isRightClick()){
DelMarker.delMarker(markerList.get(event.getRawSlot()),world,player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.block.SignChangeEvent;
import org.siberianhusy.bluemapsetmarkers.utils.AddMarker;
import org.siberianhusy.bluemapsetmarkers.utils.Get;
import org.siberianhusy.bluemapsetmarkers.utils.Util;

import static org.siberianhusy.bluemapsetmarkers.BlueMapSetMarkers.plugin;

Expand All @@ -21,24 +21,25 @@ public void onSignWrite(SignChangeEvent event) {
Block block = event.getBlock();
Location location = block.getLocation();
Player player = event.getPlayer();

if (header == Component.empty() || header == null) return;
if (!header.toString().contains("[map]")) return;
Component clabel1 = event.line(1);
if (clabel1 == Component.empty() || clabel1 == null) return;

Component clabel2 = event.line(2);
String label = LegacyComponentSerializer.legacySection().serialize(clabel1)
+ LegacyComponentSerializer.legacySection().serialize(clabel2);

Component cicon = event.line(3);
if (cicon == Component.empty() || cicon == null) {
AddMarker.addMarker(location,label,Get.getConfigString("iconUrl"),player);
AddMarker.addMarker(location,label, Util.getConfigString("iconUrl"),player);
event.line(0, Component.empty());
return;
}

String icon = LegacyComponentSerializer.legacySection().serialize(cicon);
AddMarker.addMarker(location,label,icon,player);
// Delete [map] and icon lines

event.line(0, Component.empty());
event.line(3, Component.empty());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.siberianhusy.bluemapsetmarkers.utils.Get;
import org.siberianhusy.bluemapsetmarkers.utils.Replace;
import org.siberianhusy.bluemapsetmarkers.utils.Util;

import java.util.List;

Expand All @@ -17,14 +17,12 @@ public static void adminGUI(Player player,String titie,World world){
Inventory adminGUI = Bukkit.createInventory(player,6*9,titie);
//设置图标
ItemStack markerItem = new ItemStack(Material.NAME_TAG);
//设置计数器
int count=0;
//遍历世界标记
List<String> markers = Get.getMarkerList(world);
List<String> markers = Util.getMarkerList(world);
for (int i = 0; i < markers.size(); i++) {
ItemMeta markerMeta = markerItem.getItemMeta();
markerMeta.setDisplayName(markers.get(i));
List<String> lore = Get.getMarkerInfo(markers.get(i),world);
List<String> lore = Util.getMarkerInfo(markers.get(i),world);
lore.add("&c左键传送到标记点");
lore.add("&c右键删除标记点");
lore = Replace.replaceColor(lore);
Expand Down
Loading

0 comments on commit eff8e9a

Please sign in to comment.