1
0
mirror of https://e.coding.net/circlecloud/SimpleProtect.git synced 2024-12-29 07:59:04 +00:00

fix spam config error...

Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
j502647092 2015-07-26 19:43:42 +08:00
parent 1661e5cf99
commit ef43de56e8
4 changed files with 123 additions and 93 deletions

View File

@ -1,13 +1,10 @@
package cn.citycraft.SimpleProtect;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.SimpleProtect.command.SimpleProtectCommand;
import cn.citycraft.SimpleProtect.config.Config;
import cn.citycraft.SimpleProtect.listen.BreakFarm;
import cn.citycraft.SimpleProtect.listen.Explosion;
@ -22,6 +19,7 @@ public class SimpleProtect extends JavaPlugin {
public String servername;
public String pluginname;
public Spam spam = new Spam(this);
public String getfullmsg(String path) {
return servername + pluginname + " " + getmessage(path);
@ -31,35 +29,10 @@ public class SimpleProtect extends JavaPlugin {
return Config.getMessage(path);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 1:
switch (args[0]) {
case "setspawn":
if (sender instanceof Player) {
Location l = ((Player) sender).getLocation();
Config.getInstance().set("SafeNetherDoor.World", l.getWorld().getName());
Config.getInstance().set("SafeNetherDoor.X", l.getBlockX());
Config.getInstance().set("SafeNetherDoor.Y", l.getBlockY());
Config.getInstance().set("SafeNetherDoor.Z", l.getBlockZ());
sender.sendMessage(pluginname + Config.getMessage("SafeNetherDoor.Set"));
}
return true;
case "reload":
onLoad();
sender.sendMessage(pluginname + "§a配置文件已重载!");
}
break;
}
return false;
}
@Override
public void onEnable() {
getServer().getConsoleSender().sendMessage(
"==========" + servername + pluginname + "==========");
PluginManager pm = Bukkit.getPluginManager();
if (Config.getInstance().getBoolean("Tip.Enable", true)) {
@ -90,14 +63,12 @@ public class SimpleProtect extends JavaPlugin {
}
if (Config.getInstance().getBoolean("Spam.Enable", true)) {
Spam spam = new Spam(this);
Bukkit.getPluginManager().registerEvents(spam, this);
int resettime = Config.getInstance().getInt("Spam.MuteReset") * 20;
Bukkit.getScheduler().runTaskTimer(this, spam, resettime, resettime);
getCommand("spam").setExecutor(spam);
getLogger().info("防止玩家聊天刷屏已加载!");
}
getCommand("simpleprotect").setExecutor(new SimpleProtectCommand(this));
getServer().getConsoleSender().sendMessage(
"==========" + servername + pluginname + "==========");
new VersionChecker(this);

View File

@ -0,0 +1,93 @@
/**
*
*/
package cn.citycraft.SimpleProtect.command;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import cn.citycraft.SimpleProtect.SimpleProtect;
import cn.citycraft.SimpleProtect.config.Config;
/**
* @author Administrator
*
*/
public class SimpleProtectCommand implements CommandExecutor {
SimpleProtect plugin;
/**
* @param simpleProtect
*/
public SimpleProtectCommand(SimpleProtect simpleProtect) {
plugin = simpleProtect;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 1:
switch (args[0]) {
case "setspawn":
if (sender instanceof Player) {
Location l = ((Player) sender).getLocation();
Config.getInstance().set("SafeNetherDoor.World", l.getWorld().getName());
Config.getInstance().set("SafeNetherDoor.X", l.getBlockX());
Config.getInstance().set("SafeNetherDoor.Y", l.getBlockY());
Config.getInstance().set("SafeNetherDoor.Z", l.getBlockZ());
sender.sendMessage(plugin.pluginname + Config.getMessage("SafeNetherDoor.Set"));
}
return true;
case "reload":
plugin.onLoad();
sender.sendMessage(plugin.pluginname + "§a配置文件已重载!");
return true;
case "list":
break;
case "admin":
if (args[1].equalsIgnoreCase("on")) {
plugin.spam.setAdminchat(true);
sender.sendMessage(plugin.getfullmsg("Spam.AdminChatOn"));
return true;
}
if (args[1].equalsIgnoreCase("off")) {
plugin.spam.setAdminchat(false);
sender.sendMessage(plugin.getfullmsg("Spam.AdminChatOff"));
return true;
}
break;
}
break;
case 2:
Player p = Bukkit.getPlayer(args[1]);
switch (args[0]) {
case "add":
if (p != null) {
plugin.spam.getCc().add(p.getName());
sender.sendMessage(plugin.getfullmsg("Spam.MuteOn").replace("%player%",
p.getDisplayName()));
} else {
sender.sendMessage(plugin.getfullmsg("Spam.OffLine"));
}
case "del":
if (p != null && plugin.spam.getCc().contains(p.getName())) {
plugin.spam.getCc().remove(p);
sender.sendMessage(plugin.getfullmsg("Spam.MuteOff").replace("%player%",
p.getDisplayName()));
} else {
sender.sendMessage(plugin.getfullmsg("Spam.NotMute"));
}
}
break;
}
return false;
}
}

View File

@ -3,12 +3,10 @@
*/
package cn.citycraft.SimpleProtect.listen;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@ -16,19 +14,22 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import cn.citycraft.SimpleProtect.SimpleProtect;
import cn.citycraft.SimpleProtect.config.Config;
/**
*
* @author 蒋天蓓
*/
public class Spam implements Runnable, Listener, CommandExecutor {
public class Spam implements Runnable, Listener {
private final HashMap<String, Long> lT;
private final HashMap<String, String> lC;
HashMap<Player, Integer> tc = new HashMap<Player, Integer>();
HashMap<Player, Player> cc = new HashMap<Player, Player>();
HashMap<String, Integer> tc = new HashMap<String, Integer>();
List<String> cc = new ArrayList<String>();
String AntiMsg;
boolean adminchat;
SimpleProtect plugin;
public Spam(SimpleProtect main) {
@ -46,12 +47,12 @@ public class Spam implements Runnable, Listener, CommandExecutor {
SaveMsg(n, s);
return false;
}
if (lt + plugin.getConfig().getLong("Spam.ChatWait", 1) > nt) {
if (lt + Config.getInstance().getLong("Spam.ChatWait", 1) > nt) {
AntiMsg = plugin.getmessage("Spam.TooMuchChat");
return true;
}
if (lm.equals(s)) {
if (lt + plugin.getConfig().getLong("Spam.SameChatWait", 5) > nt) {
if (lt + Config.getInstance().getLong("Spam.SameChatWait", 5) > nt) {
AntiMsg = plugin.getmessage("Spam.TooMuchSameChat");
return true;
}
@ -70,12 +71,12 @@ public class Spam implements Runnable, Listener, CommandExecutor {
SaveMsg(n, s);
return false;
}
if (lt + plugin.getConfig().getLong("Spam.CommandWait", 1) > nt) {
if (lt + Config.getInstance().getLong("Spam.CommandWait", 1) > nt) {
AntiMsg = plugin.getmessage("Spam.TooMuchCommand");
return true;
}
if (lm.equals(s)) {
if (lt + plugin.getConfig().getLong("Spam.SameCommandWait", 3) > nt) {
if (lt + Config.getInstance().getLong("Spam.SameCommandWait", 3) > nt) {
AntiMsg = plugin.getmessage("Spam.TooMuchSameCommand");
return true;
}
@ -84,46 +85,8 @@ public class Spam implements Runnable, Listener, CommandExecutor {
return false;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (command.getName().equalsIgnoreCase("sp")) {
if (args.length == 2) {
Player p = Bukkit.getPlayer(args[1]);
if (args[0].equalsIgnoreCase("add")) {
if (p != null) {
cc.put(p, p);
sender.sendMessage(plugin.getfullmsg("Spam.MuteOn").replace("%player%",
p.getDisplayName()));
} else {
sender.sendMessage(plugin.getfullmsg("Spam.OffLine"));
}
}
if (args[0].equalsIgnoreCase("del")) {
if (p != null && cc.containsKey(p)) {
cc.remove(p);
sender.sendMessage(plugin.getfullmsg("Spam.MuteOff").replace("%player%",
p.getDisplayName()));
} else {
sender.sendMessage(plugin.getfullmsg("Spam.NotMute"));
}
}
if (args[0].equalsIgnoreCase("admin")) {
if (args[1].equalsIgnoreCase("on")) {
adminchat = true;
sender.sendMessage(plugin.getfullmsg("Spam.AdminChatOn"));
return true;
}
if (args[1].equalsIgnoreCase("off")) {
adminchat = false;
sender.sendMessage(plugin.getfullmsg("Spam.AdminChatOff"));
return true;
}
}
return true;
}
return false;
}
return false;
public List<String> getCc() {
return cc;
}
@EventHandler(ignoreCancelled = true)
@ -138,7 +101,7 @@ public class Spam implements Runnable, Listener, CommandExecutor {
e.setCancelled(true);
return;
}
if (cc.containsKey(p)) {
if (cc.contains(p)) {
p.sendMessage(plugin.getfullmsg("Spam.MuteMsg"));
e.setCancelled(true);
return;
@ -164,16 +127,16 @@ public class Spam implements Runnable, Listener, CommandExecutor {
}
public void put(Player p) {
if (tc.containsKey(p)) {
int t = tc.get(p);
if (t > plugin.getConfig().getLong("Spam.MuteCheck", 3)) {
if (tc.containsKey(p.getName())) {
int t = tc.get(p.getName());
if (t > Config.getInstance().getLong("Spam.MuteCheck", 3)) {
p.sendMessage(plugin.getfullmsg("Spam.MuteMsg"));
cc.put(p, p);
cc.add(p.getName());
} else {
tc.put(p, t + 1);
tc.put(p.getName(), t + 1);
}
} else {
tc.put(p, 1);
tc.put(p.getName(), 1);
}
}
@ -187,4 +150,8 @@ public class Spam implements Runnable, Listener, CommandExecutor {
lT.put(n, System.currentTimeMillis() / 1000);
}
public void setAdminchat(boolean adminchat) {
this.adminchat = adminchat;
}
}

View File

@ -7,7 +7,7 @@ pluginname: '&6[&b保护系统&6]&r'
#登陆提示
Tip:
#是否开启
Enable: true
Enable: false
Message:
- '&a服务器已开启保护功能'
- '&c将会实时监控您的操作'
@ -45,7 +45,7 @@ SafeNetherDoor:
Enable: true
Tip: '&5为防止您卡在地狱门现在将您传送回主城'
Set: '&a新的传送点已设置'
World: world
World: world
X: 0
Y: 70
Z: 0
@ -72,4 +72,3 @@ Spam:
AdminChatOff: '&c服务器已关闭管理员聊天'
AdminChat: '&c服务器已开启管理员聊天'
MuteMsg: '&c您由于多次刷屏已被禁言请联系管理解禁'