初始化项目
This commit is contained in:
71
src/main/java/com/io/yaohun/myitems/util/MessageUtil.java
Normal file
71
src/main/java/com/io/yaohun/myitems/util/MessageUtil.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package com.io.yaohun.myitems.util;
|
||||
|
||||
import com.io.yaohun.myitems.MyItems;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class MessageUtil {
|
||||
|
||||
private static HashMap<String,String> messageMap = new HashMap<>();
|
||||
|
||||
public static void init(MyItems plugin) {
|
||||
messageMap.clear();
|
||||
File file = new File(plugin.getDataFolder(),"lang.yml");
|
||||
// 如果没有这个文件就新建一个~
|
||||
if(!file.exists()){
|
||||
plugin.saveResource("lang.yml",false);
|
||||
}
|
||||
FileConfiguration yml = YamlConfiguration.loadConfiguration(file);
|
||||
for (String ymlKey : yml.getKeys(false)){
|
||||
ConfigurationSection section = yml.getConfigurationSection(ymlKey);
|
||||
for (String key : section.getKeys(false)){
|
||||
String message = DemonAPI.convertHexColor(section.getString(key));
|
||||
messageMap.put(key,message.replace("&","§"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getMessage(String key){
|
||||
if(messageMap.containsKey(key)){
|
||||
return messageMap.get(key);
|
||||
}
|
||||
return "§c未找到节点.§7#"+key;
|
||||
}
|
||||
|
||||
public static void broadcast(String msg) {
|
||||
Bukkit.getServer().broadcastMessage( msg.replace("&","§"));
|
||||
}
|
||||
|
||||
public static void sendMessage(CommandSender sender, String message){
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
|
||||
public static void sendMessageKey(CommandSender sender, String key, Sound sound){
|
||||
sender.sendMessage(getMessage(key));
|
||||
if(sender instanceof Player player){
|
||||
player.playSound(player.getLocation(),sound,1,1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendMessage(CommandSender sender, String message, Sound sound){
|
||||
sender.sendMessage(message);
|
||||
if(sender instanceof Player player){
|
||||
player.playSound(player.getLocation(),sound,1,1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendDescMessage(CommandSender sender, String message, Sound sound){
|
||||
sender.sendMessage("§f[§c消息§f] §a正确用法: §e"+message);
|
||||
if(sender instanceof Player player){
|
||||
player.playSound(player.getLocation(),sound,1,1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user