mirror of
https://e.coding.net/circlecloud/JoinMessage.git
synced 2025-11-24 21:36:16 +00:00
35
src/cn/citycraft/JoinMessage/Main.java
Normal file
35
src/cn/citycraft/JoinMessage/Main.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package cn.citycraft.JoinMessage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import cn.citycraft.JoinMessage.listen.PlayerJoin;
|
||||
|
||||
public class Main extends JavaPlugin{
|
||||
|
||||
HashMap<String, String[]> msg = new HashMap<String, String[]>();
|
||||
List<Map<String, String[]>> perms = new ArrayList<Map<String, String[]>>();
|
||||
|
||||
public boolean authme;
|
||||
|
||||
public void onLoad() {
|
||||
this.saveDefaultConfig();
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
this.getLogger().info("登录提示语已加载...");
|
||||
PluginManager pm = Bukkit.getPluginManager();
|
||||
pm.registerEvents(new PlayerJoin(this), this);
|
||||
if (pm.isPluginEnabled("AuthMe")) {
|
||||
this.getLogger().info("Find AuthMe Hook...");
|
||||
authme = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
78
src/cn/citycraft/JoinMessage/listen/PlayerJoin.java
Normal file
78
src/cn/citycraft/JoinMessage/listen/PlayerJoin.java
Normal file
@@ -0,0 +1,78 @@
|
||||
package cn.citycraft.JoinMessage.listen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import cn.citycraft.JoinMessage.Main;
|
||||
import fr.xephi.authme.events.LoginEvent;
|
||||
|
||||
public class PlayerJoin implements Listener {
|
||||
|
||||
Main plugin;
|
||||
|
||||
String[] lines;
|
||||
|
||||
Player p;
|
||||
|
||||
public PlayerJoin(Main main) {
|
||||
plugin = main;
|
||||
|
||||
}
|
||||
|
||||
// Message:
|
||||
// - joinmessage.vip:
|
||||
// - '%name%'
|
||||
// - '%displayname%'
|
||||
// - joinmessage
|
||||
// - vip
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
if (e.getJoinMessage() == null) {
|
||||
return;
|
||||
}
|
||||
if (plugin.authme) {
|
||||
return;
|
||||
}
|
||||
e.setJoinMessage(null);
|
||||
Player p = e.getPlayer();
|
||||
this.sendJoinMessage(p);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onLogin(LoginEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
this.sendJoinMessage(p);
|
||||
}
|
||||
|
||||
void sendJoinMessage(Player p) {
|
||||
String pn = p.getName();
|
||||
String pdn = p.getDisplayName();
|
||||
List<Map<?, ?>> perms = plugin.getConfig().getMapList("Message");
|
||||
for (Map<?, ?> smp : perms) {
|
||||
for (Entry<?, ?> key : smp.entrySet()) {
|
||||
String permission = (String) key.getKey();
|
||||
if (p.hasPermission(permission)) {
|
||||
String[] msg = ((ArrayList<?>) key.getValue())
|
||||
.toArray(new String[0]);
|
||||
for (String message : msg) {
|
||||
message = message.replaceAll("%name%", pn)
|
||||
.replaceAll("%displayname%", pdn)
|
||||
.replaceAll("&", "§");
|
||||
Bukkit.broadcastMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
19
src/config.yml
Normal file
19
src/config.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
#本文件为登录插件的主配置文件
|
||||
#服务器名称
|
||||
servername: ''
|
||||
#插件名称
|
||||
pluginname: '&6[&3JoinMessage&6]&r'
|
||||
#提示消息
|
||||
Message:
|
||||
#exapmle
|
||||
#- permission.vip 权限节点
|
||||
# - 'fist line' 自定义消息(%name% ==> 玩家名称,%displayname% ==> 带称号的名称)
|
||||
# - '%name%'
|
||||
# - '%displayname%'
|
||||
# - 'fourth line'
|
||||
- joinmessage.vip:
|
||||
- '&1==&2==&3==&4==&5==&6==&7==&8==&9==&a==&b==&c==&d==&e==&f==&1==&2==&3==&4==&5==&6==&7==&8==&9==&a==&b==&c==&d==&e==&f=='
|
||||
- ''
|
||||
- ' &6欢迎&a&l至&e&l尊&c&l会员 &a%displayname% &3回到了&d服务器!'
|
||||
- ''
|
||||
- '&1==&2==&3==&4==&5==&6==&7==&8==&9==&a==&b==&c==&d==&e==&f==&1==&2==&3==&4==&5==&6==&7==&8==&9==&a==&b==&c==&d==&e==&f=='
|
||||
8
src/plugin.yml
Normal file
8
src/plugin.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
name: JoinMessage
|
||||
main: cn.citycraft.JoinMessage.Main
|
||||
version: 1.0
|
||||
auther: 喵♂呜
|
||||
commands:
|
||||
joinmessage:
|
||||
description: 登录消息
|
||||
usage: 使用/joinmessage reload 重载配置!
|
||||
Reference in New Issue
Block a user