Skip to content

Commit

Permalink
Merge pull request #2 from xinyihl/master
Browse files Browse the repository at this point in the history
删除无用import & 添加是否开启告示牌添加标记配置选项 & 分离api
  • Loading branch information
YDHusky authored Nov 8, 2023
2 parents b2cf8ab + 431a610 commit 082001d
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 83 deletions.
37 changes: 37 additions & 0 deletions src/main/java/org/siberianhusy/bluemapsetmarkers/api/Api.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.siberianhusy.bluemapsetmarkers.api;

import com.flowpowered.math.vector.Vector2i;
import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.api.markers.POIMarker;
import org.bukkit.Location;
import org.bukkit.World;
import org.siberianhusy.bluemapsetmarkers.data.Data;
import org.siberianhusy.bluemapsetmarkers.utils.Judge;

import java.awt.image.BufferedImage;

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

public class Api {
//删除标记点
public static boolean delMarker(String name, World world){
if (!Judge.judgeMarkerName(name)){
return false;
}else {
Data.worldMarkers.get(world).getMarkers().remove(name);
return true;
}
}

//添加标记
public static void addMarker(Location location, String name, String icon){
Vector2i anchor;
BufferedImage image = getBufferedImage(icon);
int width = image.getWidth();
int height = image.getHeight();
anchor = new Vector2i(height/2, width/2);
Vector3d pos = new Vector3d(location.getX(), location.getY(), location.getZ());
POIMarker marker = POIMarker.builder().label(name).position(pos).maxDistance(100000).icon(icon,anchor).build();
Data.worldMarkers.get(location.getWorld()).put(name, marker);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.siberianhusy.bluemapsetmarkers.commands;

import org.bukkit.Location;
import org.bukkit.command.*;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
package org.siberianhusy.bluemapsetmarkers.data;


import de.bluecolored.bluemap.api.markers.Marker;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;

public class PlayerData {
private String player;
private String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
import org.siberianhusy.bluemapsetmarkers.gui.AdminGUI;
import org.siberianhusy.bluemapsetmarkers.utils.DelMarker;
import org.siberianhusy.bluemapsetmarkers.utils.Get;
import org.siberianhusy.bluemapsetmarkers.utils.Replace;
import org.siberianhusy.bluemapsetmarkers.utils.SendMessages;

import javax.script.ScriptEngine;
import java.util.List;

public class AdminGUIEvent implements Listener {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
package org.siberianhusy.bluemapsetmarkers.events;

import org.bukkit.World;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
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.Replace;

import java.time.DayOfWeek;
import java.util.ArrayList;
import java.util.List;

public class PlayerGUIEvent implements Listener {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.siberianhusy.bluemapsetmarkers.events;

import com.flowpowered.math.vector.Vector2i;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Location;
Expand All @@ -9,42 +8,39 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.SignChangeEvent;
import org.siberianhusy.bluemapsetmarkers.data.Data;
import org.siberianhusy.bluemapsetmarkers.utils.AddMarker;
import org.siberianhusy.bluemapsetmarkers.utils.Get;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import static org.siberianhusy.bluemapsetmarkers.BlueMapSetMarkers.plugin;

public class SignWatcher implements Listener {
@EventHandler
public void onSignWrite(SignChangeEvent event) {
Component header = event.line(0);
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;
if(plugin.getConfig().getBoolean("isSignWatcher",true)){
Component header = event.line(0);
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 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);
Component cicon = event.line(3);
if (cicon == Component.empty() || cicon == null) {
AddMarker.addMarker(location,label,Get.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());
return;
event.line(3, Component.empty());
}
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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
Expand All @@ -16,8 +15,6 @@ public static void mapList(Player player,String title){
Inventory mapList = Bukkit.createInventory(player,9,title);
//设置地图的图标
ItemStack worldItem = new ItemStack(Material.GRASS_BLOCK);
//设置计数器
int count = 0;
//遍历世界
for (int i = 0; i < Data.worldList.size(); i++) {
ItemMeta worldMeta = worldItem.getItemMeta();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
import org.siberianhusy.bluemapsetmarkers.utils.Get;
import org.siberianhusy.bluemapsetmarkers.utils.Replace;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

public class PlayerGUI {
//玩家标记GUI
Expand All @@ -31,13 +29,17 @@ public static void playerGUI(Player player,String title,World world){
for (Map.Entry<String, Marker> entry : Data.worldMarkers.get(world).getMarkers().entrySet()){
ItemMeta markerMeta = markerItem.getItemMeta();
markerMeta.setDisplayName(entry.getKey());
List<String> lore = new ArrayList<>();
List<String> lore;
lore = Get.getMarkerInfo(entry.getKey(), world);
PlayerData playerData = Data.playerData.get(Get.getPlayerData(entry.getKey()));
if (playerData.getPlayer().equals(player.getName())){
lore.add("&c右键删除该标记!");
if (lore != null) {
lore.add("&c右键删除该标记!");
}
}
if (lore != null) {
markerMeta.setLore(Replace.replaceColor(lore));
}
markerMeta.setLore(Replace.replaceColor(lore));
markerItem.setItemMeta(markerMeta);
playerGUI.setItem(count,markerItem);
count++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,7 @@
import static org.siberianhusy.bluemapsetmarkers.utils.Get.getBufferedImage;

public class AddMarker {
//添加标记(对SWUSTMCTOWN提供)
public static void addMarker(Location location, String name, String icon){
Vector2i anchor;
BufferedImage image = getBufferedImage(icon);
int width = image.getWidth();
int height = image.getHeight();
anchor = new Vector2i(height/2, width/2);
Vector3d pos = new Vector3d(location.getX(), location.getY(), location.getZ());
POIMarker marker = POIMarker.builder().label(name).position(pos).maxDistance(100000).icon(icon,anchor).build();
Data.worldMarkers.get(location.getWorld()).put(name, marker);
}

public static void addMarker(Location location,String name,String icon,Player player,Vector2i anchor){
if (Judge.judgeMarkerName(name)){
SendMessages.sendMessagesString(player,"Error.name",name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@


public class DelMarker {
//删除标记点,对SWUSTMCTOWN提供
public static boolean delMarker(String name, World world){
if (!Judge.judgeMarkerName(name)){
return false;
}else {
Data.worldMarkers.get(world).getMarkers().remove(name);
return true;
}
}
//删除标记点
public static void delMarker(String name, World world,Player player){
if (!Judge.judgeMarkerName(name)){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.siberianhusy.bluemapsetmarkers.utils;

import com.flowpowered.math.vector.Vector3d;
import com.sun.org.apache.bcel.internal.generic.PUSH;
import de.bluecolored.bluemap.api.markers.Marker;
import org.bukkit.Bukkit;
import org.bukkit.Location;
Expand All @@ -11,7 +10,6 @@
import org.siberianhusy.bluemapsetmarkers.data.Data;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.siberianhusy.bluemapsetmarkers.utils;

import org.bukkit.World;
import org.bukkit.entity.Player;
import org.siberianhusy.bluemapsetmarkers.data.Data;
import org.siberianhusy.bluemapsetmarkers.data.PlayerData;
Expand All @@ -9,7 +8,7 @@

public class Judge {
//判断标签名字是否存在,若存在则返回true
protected static boolean judgeMarkerName(String name){
public static boolean judgeMarkerName(String name){
List<String> MarkersName = Get.getMarkersNameList();
for (String s : MarkersName) {
if (s.equals(name)) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#默认标记图片直链
iconUrl: "https://i.mcmod.cn/item/icon/32x32/0/3167.png?v=4"
iconUrl: "https://i.mcmod.cn/item/icon/32x32/0/3167.png?v=4"
#是否允许使用告示牌添加标记
isSignWatcher: true
4 changes: 1 addition & 3 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ commands:
BlueMapSerMarkersAdmin:
aliases: asm
description: BlueMapSetMarkers Admin help
permission: bluemapsetmarkers.admin


permission: bluemapsetmarkers.admin

0 comments on commit 082001d

Please sign in to comment.