-
Notifications
You must be signed in to change notification settings - Fork 0
/
Speaker.java
96 lines (93 loc) · 3.11 KB
/
Speaker.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package nexus;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.LinkedHashMap;
import cn.nukkit.Player;
import cn.nukkit.command.CommandSender;
import cn.nukkit.event.EventHandler;
import cn.nukkit.event.Listener;
import cn.nukkit.event.player.PlayerChatEvent;
import cn.nukkit.plugin.PluginBase;
import cn.nukkit.utils.Config;
import me.onebone.economyapi.EconomyAPI;
public class Speaker extends PluginBase implements Listener{
final Pattern chatReg=Pattern.compile("^@(ㅎ|확|s|S) ");
public Config config;
@Override
public void onEnable(){
LinkedHashMap<String, Object> map=new LinkedHashMap<String, Object>();
this.getServer().getPluginManager().registerEvents(this, this);
this.getDataFolder().mkdirs();
map.put("default-chat","world");
map.put("default-chat-op","server");
map.put("speaker-cost","10000");
map.put("speaker-pattern","§b[확성기] {NAME} : {MESSAGE}");
this.config=new Config(this.getDataFolder()+"/settings.json",Config.JSON,map);
if(Integer.parseInt(this.config.get("speaker-cost").toString())<0){
this.config.set("speaker-cost", "10000");
this.getServer().getLogger().alert("speaker-cost이(가) 0보다 작으므로 기본값인 10000으로 맞춥니다.");
//settings.json : speaker-cost 를 0 으로 해놓으면 무료입니다.
}
}
@Override
public void onDisable(){
this.config.save();
}
@EventHandler
public void onChat(PlayerChatEvent event){
String message=event.getMessage();
Player player=event.getPlayer();
String name=player.getDisplayName();
Matcher result=chatReg.matcher(message);
Set<CommandSender> set=new HashSet<CommandSender>();
int money=(int)EconomyAPI.getInstance().myMoney(player);
int cost=Integer.parseInt(this.config.get("speaker-cost").toString());
if(result.find()){
message=message.substring(3);
String format=this.config.get("speaker-pattern").toString();
if(money<cost){
if(!player.isOp()){
player.sendMessage("§e[확성기] 돈이 부족합니다.");
event.setCancelled();
return;
}
}
if(!player.isOp()){
EconomyAPI.getInstance().reduceMoney(player,cost);
player.sendMessage("§e[확성기] -"+this.config.get("speaker-cost")+"원");
}
this.getServer().broadcastMessage(format.replace("{NAME}",name).replace("{MESSAGE}",message));
event.setCancelled();
return;
}
else{
if(player.isOp()){
if(this.config.get("default-chat-op").toString().equalsIgnoreCase("server")){
return;
}
}
switch(this.config.get("default-chat").toString()){
case "world":
for(Player players:player.getLevel().getPlayers().values()){
set.add((CommandSender)players);
}
this.getLogger().info(player.getDisplayName()+" : "+message);
event.setRecipients(set);
break;
case "server":
break;
default:
this.config.set("default-chat","world");
for(Player players:player.getLevel().getPlayers().values()){
set.add((CommandSender)players);
}
this.getLogger().info(player.getDisplayName()+" : "+message);
event.setRecipients(set);
break;
}
return;
}
}
}