From 315459159eaa28413f11c527fb33759f6b50d5d2 Mon Sep 17 00:00:00 2001 From: j502647092 Date: Thu, 21 May 2015 19:49:22 +0800 Subject: [PATCH] init project... Signed-off-by: j502647092 --- .gitignore | 40 +++++++ pom.xml | 45 ++++++++ .../SimpleProtect/SimpleProtect.java | 70 ++++++++++++ .../SimpleProtect/config/Config.java | 55 ++++++++++ .../SimpleProtect/config/ConfigLoader.java | 102 ++++++++++++++++++ .../SimpleProtect/config/FileConfig.java | 88 +++++++++++++++ .../SimpleProtect/listen/BreakFarm.java | 43 ++++++++ .../SimpleProtect/listen/Explosion.java | 13 +++ .../SimpleProtect/listen/HighRedstone.java | 99 +++++++++++++++++ .../SimpleProtect/listen/NetherDoor.java | 66 ++++++++++++ .../SimpleProtect/listen/Nightvision.java | 71 ++++++++++++ .../citycraft/SimpleProtect/listen/Tip.java | 34 ++++++ src/config.yml | 51 +++++++++ src/plugin.yml | 16 +++ 14 files changed, 793 insertions(+) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/cn/citycraft/SimpleProtect/SimpleProtect.java create mode 100644 src/cn/citycraft/SimpleProtect/config/Config.java create mode 100644 src/cn/citycraft/SimpleProtect/config/ConfigLoader.java create mode 100644 src/cn/citycraft/SimpleProtect/config/FileConfig.java create mode 100644 src/cn/citycraft/SimpleProtect/listen/BreakFarm.java create mode 100644 src/cn/citycraft/SimpleProtect/listen/Explosion.java create mode 100644 src/cn/citycraft/SimpleProtect/listen/HighRedstone.java create mode 100644 src/cn/citycraft/SimpleProtect/listen/NetherDoor.java create mode 100644 src/cn/citycraft/SimpleProtect/listen/Nightvision.java create mode 100644 src/cn/citycraft/SimpleProtect/listen/Tip.java create mode 100644 src/config.yml create mode 100644 src/plugin.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9626090 --- /dev/null +++ b/.gitignore @@ -0,0 +1,40 @@ +# Eclipse stuff +/.classpath +/.project +/.settings + +# netbeans +/nbproject + +# we use maven! +/build.xml + +# maven +/target +/repo + +# vim +.*.sw[a-p] + +# various other potential build files +/build +/bin +/dist +/manifest.mf + +/world + +# Mac filesystem dust +*.DS_Store + +# intellij +*.iml +*.ipr +*.iws +.idea/ + +# Project Stuff +/src/main/resources/Soulbound + +# Atlassian Stuff +/atlassian-ide-plugin.xml \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..df8d1ac --- /dev/null +++ b/pom.xml @@ -0,0 +1,45 @@ + + 4.0.0 + cn.CityCraft + SimpleProtect + 0.0.1-SNAPSHOT + SimpleProtect + + src + + + src + + **/*.java + + + + + + maven-compiler-plugin + 3.1 + + 1.7 + 1.7 + + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + + + org.spigotmc + spigot-api + jar + 1.8.3-R0.1-SNAPSHOT + + + + UTF-8 + + \ No newline at end of file diff --git a/src/cn/citycraft/SimpleProtect/SimpleProtect.java b/src/cn/citycraft/SimpleProtect/SimpleProtect.java new file mode 100644 index 0000000..cf3fbdd --- /dev/null +++ b/src/cn/citycraft/SimpleProtect/SimpleProtect.java @@ -0,0 +1,70 @@ +package cn.citycraft.SimpleProtect; + +import org.bukkit.Bukkit; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; + +import cn.citycraft.SimpleProtect.config.Config; +import cn.citycraft.SimpleProtect.listen.BreakFarm; +import cn.citycraft.SimpleProtect.listen.Explosion; +import cn.citycraft.SimpleProtect.listen.HighRedstone; +import cn.citycraft.SimpleProtect.listen.NetherDoor; +import cn.citycraft.SimpleProtect.listen.Nightvision; +import cn.citycraft.SimpleProtect.listen.Tip; + +public class SimpleProtect extends JavaPlugin { + + public String servername; + public String pluginname; + + public void onLoad() { + Config.load(this, "1.0"); + servername = getmessage("servername"); + pluginname = getmessage("pluginname"); + } + + public void onEnable() { + getLogger().info("==========" + servername + pluginname + "=========="); + + PluginManager pm = Bukkit.getPluginManager(); + + if (Config.getInstance().getBoolean("Tip.Enable", true)) { + pm.registerEvents(new Tip(this), this); + getLogger().info("保护插件提醒功能已加载!"); + } + if (Config.getInstance().getBoolean("SafeNetherDoor.Enable", true)) { + pm.registerEvents(new NetherDoor(this), this); + getLogger().info("防止登录卡地狱门已加载!"); + } + + if (Config.getInstance().getBoolean("BreakFarm.Enable", true)) { + pm.registerEvents(new BreakFarm(this), this); + getLogger().info("防止玩家踩坏耕地已加载!"); + } + if (Config.getInstance().getBoolean("Explosion.Enable", true)) { + pm.registerEvents(new Explosion(), this); + getLogger().info("防止爆炸破坏地形已加载!"); + } + if (Config.getInstance().getBoolean("Nightvision.Enable", true)) { + pm.registerEvents(new Nightvision(this), this); + getLogger().info("防止无限夜视作弊已加载!"); + } + if (Config.getInstance().getBoolean("HighRedstone.Enable", true)) { + HighRedstone redstone = new HighRedstone(this); + pm.registerEvents(redstone, this); + Bukkit.getScheduler().runTaskTimer(this, redstone, 20, 20); + getLogger().info("防止玩家高频红石已加载!"); + } + + getLogger().info("==========" + servername + pluginname + "=========="); + } + + public String getfullmsg(String path) { + return servername + pluginname + " " + getmessage(path); + } + + public String getmessage(String path) { + return Config.getMessage(path); + } + +} diff --git a/src/cn/citycraft/SimpleProtect/config/Config.java b/src/cn/citycraft/SimpleProtect/config/Config.java new file mode 100644 index 0000000..6776585 --- /dev/null +++ b/src/cn/citycraft/SimpleProtect/config/Config.java @@ -0,0 +1,55 @@ +package cn.citycraft.SimpleProtect.config; + +import java.io.File; +import java.io.IOException; + +import org.bukkit.plugin.Plugin; + +public class Config extends ConfigLoader { + private static String CONFIG_NAME = "config.yml"; + private static FileConfig instance; + private static File file; + + public Config(Plugin p) { + super(p, CONFIG_NAME); + file = new File(p.getDataFolder(), CONFIG_NAME); + instance = super.getInstance(); + } + + public Config(Plugin p, String ver) { + super(p, CONFIG_NAME, ver); + instance = super.getInstance(); + } + + public static void load(Plugin p) { + new Config(p); + } + + public static void load(Plugin p, String ver) { + new Config(p, ver); + } + + public static FileConfig getInstance() { + return instance; + } + + public static String getMessage(String path) { + String message = instance.getString(path); + if (message != null) + message = message.replaceAll("&", "§"); + return message; + } + + public static String[] getStringArray(String path) { + return instance.getStringList(path).toArray(new String[0]); + } + + public static void save(){ + try { + instance.save(file); + } catch (IOException e) { + saveError(file); + e.printStackTrace(); + } + } +} diff --git a/src/cn/citycraft/SimpleProtect/config/ConfigLoader.java b/src/cn/citycraft/SimpleProtect/config/ConfigLoader.java new file mode 100644 index 0000000..3da94f3 --- /dev/null +++ b/src/cn/citycraft/SimpleProtect/config/ConfigLoader.java @@ -0,0 +1,102 @@ +package cn.citycraft.SimpleProtect.config; + +import java.io.File; +import java.io.IOException; + +import org.bukkit.plugin.Plugin; + +public class ConfigLoader extends FileConfig { + protected static FileConfig config; + protected static boolean tip = true; + protected static Plugin plugin; + + public ConfigLoader(Plugin p, File file) { + ConfigLoader.plugin = p; + config = loadConfig(p, file, null, true); + } + + public ConfigLoader(Plugin p, File file, boolean res) { + ConfigLoader.plugin = p; + config = loadConfig(p, file, null, res); + } + + public ConfigLoader(Plugin p, File file, String ver) { + ConfigLoader.plugin = p; + config = loadConfig(p, file, ver, true); + } + + public ConfigLoader(Plugin p, File file, String ver, boolean res) { + ConfigLoader.plugin = p; + config = loadConfig(p, file, ver, res); + } + + public ConfigLoader(Plugin p, String filename) { + ConfigLoader.plugin = p; + config = loadConfig(p, new File(p.getDataFolder(), filename), null, + true); + } + + public ConfigLoader(Plugin p, String filename, boolean res) { + ConfigLoader.plugin = p; + config = loadConfig(p, new File(p.getDataFolder(), filename), null, res); + } + + public ConfigLoader(Plugin p, String filename, String ver) { + ConfigLoader.plugin = p; + config = loadConfig(p, new File(p.getDataFolder(), filename), ver, true); + } + + public ConfigLoader(Plugin p, String filename, String ver, boolean res) { + ConfigLoader.plugin = p; + config = loadConfig(p, new File(p.getDataFolder(), filename), ver, true); + } + + public static FileConfig getInstance() { + return config; + } + + public FileConfig loadConfig(Plugin p, File file, String ver, boolean res) { + tip = res ; + if (!file.getParentFile().exists()) { + file.getParentFile().mkdirs(); + p.getLogger().info("创建新的文件夹" + file.getParentFile().getAbsolutePath() + "..."); + } + if (!file.exists()) { + fileCreate(p, file, res); + } else { + if (ver != null) { + FileConfig configcheck = init(file); + String version = configcheck.getString("version"); + if (version == null || !version.equals(ver)) { + p.saveResource(file.getName(), true); + p.getLogger().warning( + "配置文件: " + file.getName() + " 版本过低 正在升级..."); + } + } + } + if (tip) + p.getLogger().info( + "载入配置文件: " + file.getName() + + (ver != null ? " 版本: " + ver : "")); + return init(file); + } + + private void fileCreate(Plugin p, File file, boolean res) { + if (res) { + p.saveResource(file.getName(), false); + } else { + try { + p.getLogger().info("创建新的配置文件" + file.getAbsolutePath() + "..."); + file.createNewFile(); + } catch (IOException e) { + p.getLogger().info("配置文件" + file.getName() + "创建失败..."); + e.printStackTrace(); + } + } + } + + public static void saveError(File file) { + plugin.getLogger().info("配置文件" + file.getName() + "保存错误..."); + } + +} diff --git a/src/cn/citycraft/SimpleProtect/config/FileConfig.java b/src/cn/citycraft/SimpleProtect/config/FileConfig.java new file mode 100644 index 0000000..23df59d --- /dev/null +++ b/src/cn/citycraft/SimpleProtect/config/FileConfig.java @@ -0,0 +1,88 @@ +package cn.citycraft.SimpleProtect.config; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.util.logging.Level; + +import org.apache.commons.lang.Validate; +import org.bukkit.Bukkit; +import org.bukkit.configuration.Configuration; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.configuration.file.YamlConstructor; +import org.bukkit.configuration.file.YamlRepresenter; +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.representer.Representer; + +import com.google.common.base.Charsets; +import com.google.common.io.Files; + +/** + * An implementation of {@link Configuration} which saves all files in Yaml. + * Note that this implementation is not synchronized. + */ +public class FileConfig extends YamlConfiguration { + + protected final DumperOptions yamlOptions = new DumperOptions(); + protected final Representer yamlRepresenter = new YamlRepresenter(); + protected final Yaml yaml = new Yaml(new YamlConstructor(), + yamlRepresenter, yamlOptions); + + public static FileConfig init(File file) { + return FileConfig.loadConfiguration(file); + } + + public static FileConfig loadConfiguration(File file) { + Validate.notNull(file, "File cannot be null"); + FileConfig config = new FileConfig(); + try { + config.load(file); + } catch (FileNotFoundException ex) { + } catch (IOException ex) { + Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex); + } catch (InvalidConfigurationException ex) { + Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex); + } + return config; + } + + @Override + public String saveToString() { + yamlOptions.setIndent(options().indent()); + yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + String header = buildHeader(); + String dump = yaml.dump(getValues(false)); + if (dump.equals(BLANK_CONFIG)) { + dump = ""; + } + return header + dump; + } + + public void load(File file) throws FileNotFoundException, IOException, + InvalidConfigurationException { + Validate.notNull(file, "File cannot be null"); + final FileInputStream stream = new FileInputStream(file); + load(new InputStreamReader(stream, Charsets.UTF_8)); + } + + public void save(File file) throws IOException { + Validate.notNull(file, "File cannot be null"); + Files.createParentDirs(file); + String data = saveToString(); + Writer writer = new OutputStreamWriter(new FileOutputStream(file), + Charsets.UTF_8); + try { + writer.write(data); + } finally { + writer.close(); + } + } +} diff --git a/src/cn/citycraft/SimpleProtect/listen/BreakFarm.java b/src/cn/citycraft/SimpleProtect/listen/BreakFarm.java new file mode 100644 index 0000000..9aed3c1 --- /dev/null +++ b/src/cn/citycraft/SimpleProtect/listen/BreakFarm.java @@ -0,0 +1,43 @@ +package cn.citycraft.SimpleProtect.listen; + +import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.entity.EntityInteractEvent; +import org.bukkit.event.player.PlayerInteractEvent; + +import cn.citycraft.SimpleProtect.SimpleProtect; + +public class BreakFarm implements Listener { + + SimpleProtect plugin; + + public BreakFarm(SimpleProtect main) { + plugin = main; + } + + @EventHandler + public void soilChangePlayer(PlayerInteractEvent event) { + if (event.isCancelled()) { + return; + } + if (event.getAction().equals(Action.PHYSICAL) + && event.getClickedBlock().getType().equals(Material.SOIL)) { + event.getPlayer().sendMessage(plugin.getfullmsg("BreakFarm.Tip")); + event.setCancelled(true); + } + } + + @EventHandler + public void soilChangeEntity(EntityInteractEvent event) { + if (event.isCancelled()) { + return; + } + if (event.getEntityType() != EntityType.PLAYER + && event.getBlock().getType().equals(Material.SOIL)) { + event.setCancelled(true); + } + } +} diff --git a/src/cn/citycraft/SimpleProtect/listen/Explosion.java b/src/cn/citycraft/SimpleProtect/listen/Explosion.java new file mode 100644 index 0000000..180f566 --- /dev/null +++ b/src/cn/citycraft/SimpleProtect/listen/Explosion.java @@ -0,0 +1,13 @@ +package cn.citycraft.SimpleProtect.listen; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityExplodeEvent; + +public class Explosion implements Listener { + + @EventHandler + public void onExplosion(EntityExplodeEvent event) { + event.blockList().clear(); + } +} diff --git a/src/cn/citycraft/SimpleProtect/listen/HighRedstone.java b/src/cn/citycraft/SimpleProtect/listen/HighRedstone.java new file mode 100644 index 0000000..059040e --- /dev/null +++ b/src/cn/citycraft/SimpleProtect/listen/HighRedstone.java @@ -0,0 +1,99 @@ +package cn.citycraft.SimpleProtect.listen; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.block.BlockRedstoneEvent; + +import cn.citycraft.SimpleProtect.SimpleProtect; +import cn.citycraft.SimpleProtect.config.Config; + +public class HighRedstone implements Runnable, Listener { + + HashMap map = new HashMap(); + HashMap pmap = new HashMap(); + SimpleProtect plugin; + ArrayList tipop = new ArrayList(); + + public HighRedstone(SimpleProtect main) { + plugin = main; + } + + public void run() { + List blocks = new ArrayList(); + for (Entry entry : map.entrySet()) { + if (entry.getValue() > Config.getInstance().getLong( + "HighRedstone.Maxevents")) { + blocks.add(entry.getKey()); + } + } + Boolean tip = true; + for (Block block : blocks) { + World rw = block.getWorld(); + int rx = block.getX(); + int ry = block.getY(); + int rz = block.getZ(); + Player rp = pmap.get(block); + if (rp != null) { + if (rp.isOp() || rp.hasPermission("sp.ignore.highredstone")) { + if (!tipop.contains(rp)) { + rp.sendMessage(plugin.getfullmsg("HighRedstone.Admin")); + tipop.add(rp); + } + continue; + } + } + if (tip) { + Bukkit.broadcastMessage(plugin.getfullmsg("HighRedstone.Find") + .replaceAll("%world%", rw.getName()) + .replaceAll("%x%", rx + "").replaceAll("%y%", ry + "") + .replaceAll("%z%", rz + "")); + if (rp != null) { + Bukkit.broadcastMessage(plugin.getfullmsg( + "HighRedstone.Check").replaceAll("%player%", + rp.getName())); + pmap.remove(block); + } + tip = !tip; + } + block.breakNaturally(); + } + map.clear(); + } + + @EventHandler(ignoreCancelled = true) + public void RedStonePlace(BlockPlaceEvent event) { + Block rb = event.getBlock(); + Player rp = event.getPlayer(); + if (rb.getType() == Material.REDSTONE_WIRE) { + pmap.put(rb, rp); + } + } + + @EventHandler + public void onRedClock(BlockRedstoneEvent event) { + Block rb = event.getBlock(); + if (rb.getType() == Material.REDSTONE_WIRE) { + put(event.getBlock()); + } + } + + private void put(Block block) { + if (map.containsKey(block)) { + int i = map.remove(block); + map.put(block, i + 1); + } else { + map.put(block, 1); + } + } +} diff --git a/src/cn/citycraft/SimpleProtect/listen/NetherDoor.java b/src/cn/citycraft/SimpleProtect/listen/NetherDoor.java new file mode 100644 index 0000000..306faf3 --- /dev/null +++ b/src/cn/citycraft/SimpleProtect/listen/NetherDoor.java @@ -0,0 +1,66 @@ +package cn.citycraft.SimpleProtect.listen; + +import org.bukkit.*; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.scheduler.BukkitRunnable; + +import cn.citycraft.SimpleProtect.SimpleProtect; +import cn.citycraft.SimpleProtect.config.Config; + +public class NetherDoor implements Listener { + + public FileConfiguration getConfig; + public Location spawn; + SimpleProtect plugin; + + public NetherDoor(SimpleProtect main) { + plugin = main; + } + + // public NetherDoor() { + // throw new UnsupportedOperationException("Not yet implemented"); + // } + @EventHandler + public void onJoin(final PlayerJoinEvent e) { + new BukkitRunnable() { + + public void run() { + Player p = e.getPlayer(); + Location loc = p.getLocation(); + World world = loc.getWorld(); + double x = loc.getX(); + double y = loc.getY(); + double z = loc.getZ(); + Location loc_top = new Location(world, x, y + 1.0D, z); + Location loc_bottom = new Location(world, x, y - 1.0D, z); + Location loc_xleft = new Location(world, x + 1.0D, y, z); + Location loc_xright = new Location(world, x - 1.0D, y, z); + Location loc_zleft = new Location(world, x, y, z + 1.0D); + Location loc_zright = new Location(world, x, y, z - 1.0D); + if (loc_top.getBlock().getType() == Material.PORTAL + || loc_bottom.getBlock().getType() == Material.PORTAL + || loc_xleft.getBlock().getType() == Material.PORTAL + || loc_xright.getBlock().getType() == Material.PORTAL + || loc_zleft.getBlock().getType() == Material.PORTAL + || loc_zright.getBlock().getType() == Material.PORTAL) { + p.sendMessage(plugin.getfullmsg("SafeNetherDoor.Tip")); + World lworld = Bukkit + .getWorld((String) Config.getInstance().get( + "SafeNetherDoor.World", "world")); + double lx = Config.getInstance().getInt("SafeNetherDoor.X", + 0); + double ly = Config.getInstance().getInt("SafeNetherDoor.Y", + 0); + double lz = Config.getInstance().getInt("SafeNetherDoor.Z", + 0); + spawn = new Location(lworld, lx, ly, lz); + p.teleport(spawn); + } + } + }.runTaskLater(plugin, 15); + } +} diff --git a/src/cn/citycraft/SimpleProtect/listen/Nightvision.java b/src/cn/citycraft/SimpleProtect/listen/Nightvision.java new file mode 100644 index 0000000..11d782e --- /dev/null +++ b/src/cn/citycraft/SimpleProtect/listen/Nightvision.java @@ -0,0 +1,71 @@ +package cn.citycraft.SimpleProtect.listen; + +import java.util.Collection; +import java.util.Iterator; + +import org.bukkit.*; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.potion.PotionEffect; + +import cn.citycraft.SimpleProtect.SimpleProtect; + +public class Nightvision implements Listener { + + SimpleProtect plugin; + + public Nightvision(SimpleProtect main) { + plugin = main; + } + + @EventHandler + public void OnBlockBreak(BlockBreakEvent e) { + Player p = e.getPlayer(); + if (p.hasPermission("sp.ignore.nightvision") || p.isOp()) { + return; + } + int light = p.getLocation().getBlock().getLightLevel(); + if (light > 0) { + return; + } + Block b = e.getBlock(); + Material blockid = b.getType(); + Location loc = b.getLocation(); + World World = loc.getWorld(); + int x = loc.getBlockX(); + int y = loc.getBlockY(); + int z = loc.getBlockZ(); + Location loc_top = new Location(World, x, y + 1, z); + if (loc_top.getBlock().getType() == Material.AIR) { + return; + } + Collection effect = p.getActivePotionEffects(); + Iterator iterator = effect.iterator(); + Boolean flag = Boolean.valueOf(false); + while (iterator.hasNext()) { + PotionEffect element = (PotionEffect) iterator.next(); + if (element.toString().toUpperCase().contains("NIGHT_VISION")) { + flag = Boolean.valueOf(true); + break; + } + } + if (!flag.booleanValue()) { + if (blockid == Material.AIR) { + return; + } + if (blockid == Material.STONE || blockid == Material.GOLD_ORE + || blockid == Material.IRON_ORE + || blockid == Material.COAL_ORE + || blockid == Material.DIAMOND_ORE + || blockid == Material.REDSTONE_ORE + || blockid == Material.LAPIS_ORE + || blockid == Material.EMERALD_ORE) { + e.setCancelled(true); + p.sendMessage(plugin.getfullmsg("Nightvision.Tip")); + } + } + } +} \ No newline at end of file diff --git a/src/cn/citycraft/SimpleProtect/listen/Tip.java b/src/cn/citycraft/SimpleProtect/listen/Tip.java new file mode 100644 index 0000000..6b4b7d3 --- /dev/null +++ b/src/cn/citycraft/SimpleProtect/listen/Tip.java @@ -0,0 +1,34 @@ +package cn.citycraft.SimpleProtect.listen; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +import cn.citycraft.SimpleProtect.SimpleProtect; +import cn.citycraft.SimpleProtect.config.Config; + +public class Tip implements Listener { + SimpleProtect plugin; + + public Tip(SimpleProtect instance) { + plugin = instance; + } + + @EventHandler + public void onJoin(final PlayerJoinEvent e) { + plugin.getServer().getScheduler() + .runTaskLaterAsynchronously(plugin, new Runnable() { + public void run() { + Player p = e.getPlayer(); + String[] msg = Config.getStringArray("Tip.Message"); + for (String s : msg) { + s = s.replaceAll("&", "§"); + p.sendMessage(plugin.servername + plugin.pluginname + + s); + } + } + }, 15); + } + +} diff --git a/src/config.yml b/src/config.yml new file mode 100644 index 0000000..b0faf48 --- /dev/null +++ b/src/config.yml @@ -0,0 +1,51 @@ +#本文件为保护插件的主配置文件 +version: 1.0 +#服务器名称 +servername: '' +#插件名称 +pluginname: '&6[&b保护系统&6]&r' +#登陆提示 +Tip: + #是否开启 + Enable: true + Message: + - '&a服务器已开启保护功能!' + - '&c将会实时监控您的操作!' + - '&b城市世界请圈地后建筑!' + - '&e挖矿请带上火把或药水!' + +#耕地保护配置 +BreakFarm: + #是否开启 + Enable: true + Tip: '&c服务器已开启耕地保护,请不要踩庄稼!' + +#爆炸保护配置 +Explosion: + #是否开启 + Enable: true + +#高频红石检测 +HighRedstone: + #是否开启 + Enable: true + Maxevents: 35 + Find: '&c发现高频红石 &3世界:%world% &d坐标: X:%x% Y:%y% Z:%z% §a已清理!' + Check: '&c高频红石数据监测 &5上述高频红石由 &6玩家:&a%player%& 6放置!' + Admin: '&c发现您放置高频红石,由于您是管理员,在服务器重启之前此高频将不会被清理,请用完后及时清理!' + +#防止无限夜视 +Nightvision: + #是否开启 + Enable: true + Tip: '&c为防止无限夜视作弊,以阻止挖矿,请插火把或用夜视药水!' + +#安全地狱门 +SafeNetherDoor: + #是否开启 + Enable: true + Tip: '&5为防止您卡在地狱门,现在将您传送回主城!' + World: world + X: -51 + Y: 73 + Z: 38 \ No newline at end of file diff --git a/src/plugin.yml b/src/plugin.yml new file mode 100644 index 0000000..63e10fc --- /dev/null +++ b/src/plugin.yml @@ -0,0 +1,16 @@ +name: SimpleProtect +main: cn.citycraft.SimpleProtect.SimpleProtect +version: 0.0.1 +permissions: + sp.ignore.*: + description: 允许忽略插件的检测! + default: op + children: + sp.ignore.highredstone: true + sp.ignore.nightvision: true + sp.ignore.nightvision: + description: 允许零亮度挖矿! + default: op + sp.ignore.highredstone: + description: 允许忽略高频检测限制! + default: op \ No newline at end of file