4
1
mirror of https://e.coding.net/circlecloud/MiaoChat.git synced 2024-11-14 13:28:46 +00:00

feat: 添加跨服配置

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-12-08 20:34:01 +08:00
parent 8ee853c1cf
commit e85f69e03a
6 changed files with 256 additions and 18 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>pw.yumc</groupId> <groupId>pw.yumc</groupId>
<artifactId>MiaoChat</artifactId> <artifactId>MiaoChat</artifactId>
<version>1.5.1</version> <version>1.6</version>
<build> <build>
<finalName>${project.name}</finalName> <finalName>${project.name}</finalName>
<resources> <resources>
@ -105,7 +105,7 @@
<groupId>pw.yumc</groupId> <groupId>pw.yumc</groupId>
<artifactId>YumCore</artifactId> <artifactId>YumCore</artifactId>
<type>jar</type> <type>jar</type>
<version>1.2</version> <version>1.5</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -8,18 +8,19 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.messaging.PluginMessageListener; import org.bukkit.plugin.messaging.PluginMessageListener;
import pw.yumc.MiaoChat.config.ChatConfig; import pw.yumc.MiaoChat.config.ChatConfig;
import pw.yumc.MiaoChat.listeners.ChatListener; import pw.yumc.MiaoChat.listeners.ChatListener;
import pw.yumc.YumCore.bukkit.Log; import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.bukkit.compatible.C; import pw.yumc.YumCore.bukkit.compatible.C;
import pw.yumc.YumCore.commands.CommandManager; import pw.yumc.YumCore.commands.CommandSub;
import pw.yumc.YumCore.commands.annotation.Cmd; import pw.yumc.YumCore.commands.annotation.Cmd;
import pw.yumc.YumCore.commands.annotation.Help; import pw.yumc.YumCore.commands.annotation.Help;
import pw.yumc.YumCore.commands.interfaces.CommandExecutor; import pw.yumc.YumCore.commands.interfaces.Executor;
import pw.yumc.YumCore.config.FileConfig; import pw.yumc.YumCore.config.FileConfig;
import pw.yumc.YumCore.global.L10N; import pw.yumc.YumCore.global.L10N;
public class MiaoChat extends JavaPlugin implements CommandExecutor, PluginMessageListener { public class MiaoChat extends JavaPlugin implements Executor, PluginMessageListener {
private FileConfig cfg; private FileConfig cfg;
private ChatConfig chatConfig; private ChatConfig chatConfig;
@ -36,20 +37,20 @@ public class MiaoChat extends JavaPlugin implements CommandExecutor, PluginMessa
@Help("关闭聊天功能") @Help("关闭聊天功能")
public void off(CommandSender sender) { public void off(CommandSender sender) {
ChatListener.offList.add(sender.getName()); ChatListener.offList.add(sender.getName());
Log.toSender(sender, "§c聊天功能已关闭!"); Log.sender(sender, "§c聊天功能已关闭!");
} }
@Cmd(permission = "MiaoChat.toggle") @Cmd(permission = "MiaoChat.toggle")
@Help("开启聊天功能") @Help("开启聊天功能")
public void on(CommandSender sender) { public void on(CommandSender sender) {
ChatListener.offList.remove(sender.getName()); ChatListener.offList.remove(sender.getName());
Log.toSender(sender, "§a聊天功能已开启!"); Log.sender(sender, "§a聊天功能已开启!");
} }
@Override @Override
public void onEnable() { public void onEnable() {
new ChatListener(); new ChatListener();
new CommandManager("MiaoChat", this); new CommandSub("MiaoChat", this);
if (getChatConfig().isBungeeCord()) { if (getChatConfig().isBungeeCord()) {
Log.info("已开启 BUngeeCord 模式!"); Log.info("已开启 BUngeeCord 模式!");
Bukkit.getMessenger().registerIncomingPluginChannel(this, MiaoMessage.CHANNEL, this); Bukkit.getMessenger().registerIncomingPluginChannel(this, MiaoMessage.CHANNEL, this);
@ -71,7 +72,7 @@ public class MiaoChat extends JavaPlugin implements CommandExecutor, PluginMessa
public void reload(CommandSender sender) { public void reload(CommandSender sender) {
cfg.reload(); cfg.reload();
chatConfig.reload(); chatConfig.reload();
Log.toSender(sender, "§a配置文件已重载!"); Log.sender(sender, "§a配置文件已重载!");
} }
public static void send(byte[] in) { public static void send(byte[] in) {

View File

@ -0,0 +1,193 @@
package pw.yumc.MiaoChat.bungee;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
/**
*
* Created by 蒋天蓓 on 2016/11/7 0007.
*/
public class FileConfig {
private File file;
private Configuration config;
public FileConfig(Plugin plugin) {
this(plugin, "config.yml");
}
public <T> T get(String path, T def) {
return config.get(path, def);
}
public boolean contains(String path) {
return config.contains(path);
}
public Object get(String path) {
return config.get(path);
}
public Object getDefault(String path) {
return config.getDefault(path);
}
public void set(String path, Object value) {
config.set(path, value);
}
public Configuration getSection(String path) {
return config.getSection(path);
}
public Collection<String> getKeys() {
return config.getKeys();
}
public byte getByte(String path) {
return config.getByte(path);
}
public byte getByte(String path, byte def) {
return config.getByte(path, def);
}
public List<Byte> getByteList(String path) {
return config.getByteList(path);
}
public short getShort(String path) {
return config.getShort(path);
}
public short getShort(String path, short def) {
return config.getShort(path, def);
}
public List<Short> getShortList(String path) {
return config.getShortList(path);
}
public int getInt(String path) {
return config.getInt(path);
}
public int getInt(String path, int def) {
return config.getInt(path, def);
}
public List<Integer> getIntList(String path) {
return config.getIntList(path);
}
public long getLong(String path) {
return config.getLong(path);
}
public long getLong(String path, long def) {
return config.getLong(path, def);
}
public List<Long> getLongList(String path) {
return config.getLongList(path);
}
public float getFloat(String path) {
return config.getFloat(path);
}
public float getFloat(String path, float def) {
return config.getFloat(path, def);
}
public List<Float> getFloatList(String path) {
return config.getFloatList(path);
}
public double getDouble(String path) {
return config.getDouble(path);
}
public double getDouble(String path, double def) {
return config.getDouble(path, def);
}
public List<Double> getDoubleList(String path) {
return config.getDoubleList(path);
}
public boolean getBoolean(String path) {
return config.getBoolean(path);
}
public boolean getBoolean(String path, boolean def) {
return config.getBoolean(path, def);
}
public List<Boolean> getBooleanList(String path) {
return config.getBooleanList(path);
}
public char getChar(String path) {
return config.getChar(path);
}
public char getChar(String path, char def) {
return config.getChar(path, def);
}
public List<Character> getCharList(String path) {
return config.getCharList(path);
}
public String getString(String path) {
return config.getString(path);
}
public String getString(String path, String def) {
return config.getString(path, def);
}
public List<String> getStringList(String path) {
return config.getStringList(path);
}
public List<?> getList(String path) {
return config.getList(path);
}
public List<?> getList(String path, List<?> def) {
return config.getList(path, def);
}
public FileConfig(Plugin plugin, String name) {
this.file = new File(plugin.getDataFolder(), name);
try {
this.config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
} catch (IOException e) {
Log.w("配置文件读取失败!");
e.printStackTrace();
}
}
public Configuration getConfig() {
return config;
}
public void save() {
try {
ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, file);
} catch (IOException e) {
Log.w("配置文件保存失败!");
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,49 @@
package pw.yumc.MiaoChat.bungee;
import java.util.logging.Logger;
import net.md_5.bungee.api.plugin.Plugin;
/**
* 插件日志输出类
*
* @author
* @since 2016年7月23日 上午9:11:01
*/
public class Log {
private static boolean debug = false;
public static Plugin plugin;
public static Logger logger;
public static void init(Plugin plugin) {
Log.plugin = plugin;
Log.logger = plugin.getLogger();
}
public static void d(String s, Exception e) {
if (debug) {
logger.info(s);
e.printStackTrace();
}
}
public static void i(String s, Object... objects) {
logger.info(String.format(s, objects));
}
public static void d(String s) {
if (debug) {
logger.info(s);
}
}
public static void d(Exception e) {
if (debug) {
e.printStackTrace();
}
}
public static void w(String s, Object... objects) {
logger.warning(String.format(s, objects));
}
}

View File

@ -39,16 +39,11 @@ public class ChatMessagePart extends InjectConfigurationSection {
String tc = f(p, command); String tc = f(p, command);
switch (type) { switch (type) {
case COMMAND: case COMMAND:
tr.command(tc); return tr.command(tc);
break;
case OPENURL: case OPENURL:
tr.openurl(tc); return tr.openurl(tc);
break;
case SUGGEST: case SUGGEST:
tr.suggest(tc); return tr.suggest(tc);
break;
default:
break;
} }
} }
return tr; return tr;

View File

@ -157,7 +157,7 @@ public class ChatListener implements Listener {
LinkedList<String> il = handlePattern(message); LinkedList<String> il = handlePattern(message);
// 如果返回null说明存在相同的物品 // 如果返回null说明存在相同的物品
if (il == null) { if (il == null) {
Log.toSender(player, "§c不允许展示相同的物品!"); Log.sender(player, "§c不允许展示相同的物品!");
return; return;
} }
LinkedList<String> ml = handleMessage(il, message); LinkedList<String> ml = handleMessage(il, message);