diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..2c705bb --- /dev/null +++ b/.classpath @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore index 9626090..043fc2a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ # Eclipse stuff -/.classpath -/.project /.settings # netbeans diff --git a/.project b/.project new file mode 100644 index 0000000..0210880 --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + TeleportRandom + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/pom.xml b/pom.xml index 967cf0b..60e09fa 100644 --- a/pom.xml +++ b/pom.xml @@ -1,19 +1,16 @@ 4.0.0 - cn.CityCraft + cn.citycraft TeleportRandom - 0.0.1-SNAPSHOT + 1.0 TeleportRandom ${project.name} - src - src - - **/*.java - + src/main/resources + true @@ -25,23 +22,63 @@ 1.7 + + org.apache.maven.plugins + maven-shade-plugin + 2.3 + + false + true + + + cn.citycraft:PluginHelper + + + + + cn.citycraft.PluginHelper + ${project.groupId}.${project.artifactId} + + + + + + package + + shade + + + + + + http://ci.citycraft.cn:8080 + 更新插件框架... + UTF-8 + spigot-repo https://hub.spigotmc.org/nexus/content/groups/public/ + + citycraft-repo + ${jenkins.url}/plugin/repository/everything/ + org.spigotmc spigot-api jar - 1.8.3-R0.1-SNAPSHOT + 1.8.8-R0.1-SNAPSHOT + + + cn.citycraft + PluginHelper + jar + 1.0 - - UTF-8 - \ No newline at end of file diff --git a/src/cn/citycraft/TeleportRandom/TeleportRandom.java b/src/cn/citycraft/TeleportRandom/TeleportRandom.java deleted file mode 100644 index 8938817..0000000 --- a/src/cn/citycraft/TeleportRandom/TeleportRandom.java +++ /dev/null @@ -1,117 +0,0 @@ -package cn.citycraft.TeleportRandom; - -import java.util.Random; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -import cn.citycraft.config.Config; - -public class TeleportRandom extends JavaPlugin implements CommandExecutor { - public String servername; - public String pluginname; - - public String getmessage(String path) { - String message = Config.getMessage(path).replaceAll("&", "§"); - return message; - } - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String string, String[] args) { - if (args.length == 1 && args[0].equalsIgnoreCase("reload")) { - this.onLoad(); - sender.sendMessage(servername + pluginname + getmessage("Message.Reload")); - return true; - } - if (sender instanceof Player) { - Player p = (Player) sender; - if (!p.hasPermission("tpr.use")) { - sender.sendMessage(servername + pluginname + getmessage("Message.NoPerm")); - return true; - } - try { - switch (args.length) { - case 0: - RandomTP(0, p); - break; - case 1: - RandomTP(Integer.parseInt(args[0]), p); - break; - case 2: - RandomTP(Integer.parseInt(args[0]), Bukkit.getWorld(args[1]), p); - break; - } - } catch (Exception e) { - sender.sendMessage("§c非法的参数或不存在的世界!"); - } - return true; - } else { - sender.sendMessage("§c控制台无法使用此命令!"); - } - return false; - } - - @Override - public void onLoad() { - Config.load(this, "1.0"); - servername = getmessage("servername"); - pluginname = getmessage("pluginname"); - } - - public void RandomTP(int limit, Player p) { - RandomTP(limit, p.getWorld(), p); - } - - public void RandomTP(int limit, World world, Player p) { - Random rr = new Random(); - int lr = Config.getInstance().getInt("default"); - if (limit == 0) { - p.sendMessage(servername + pluginname + getmessage("Message.default1")); - p.sendMessage(servername + pluginname + getmessage("Message.default2")); - } else { - lr = limit; - int lrLimit = Config.getInstance().getInt("Limit"); - if (lr > lrLimit) { - lr = lrLimit; - p.sendMessage(servername + pluginname + getmessage("Message.Wran").replace("%limit%", lrLimit + "")); - } - } - int x = rr.nextInt(lr); - int z = rr.nextInt(lr); - int xf = rr.nextInt(x); - int yf = rr.nextInt(z); - if (xf % 2 != 0) { - x = -x; - } - if (yf % 2 != 0) { - z = -z; - } - int y = world.getHighestBlockYAt(x, z); - final Location trl = new Location(world, x, y - 1, z); - final Material rbm = trl.getBlock().getType(); - String blockname = rbm.name(); - for (String protectblock : Config.getInstance().getStringList("ProtectBlock")) { - if (protectblock.equalsIgnoreCase(blockname)) { - trl.getBlock().setType(Material.GLASS); - p.sendMessage(servername + pluginname + getmessage("Message.Protect")); - this.getServer().getScheduler().runTaskLater(this, new Runnable() { - @Override - public void run() { - trl.getBlock().setType(rbm); - } - }, 200); - } - } - Location nrl = new Location(world, x, y + 3, z); - p.teleport(nrl); - p.sendMessage(servername + pluginname - + getmessage("Message.Tip").replaceAll("%world%", world.getName()).replaceAll("%x%", x + "").replaceAll("%z%", z + "")); - } -} diff --git a/src/cn/citycraft/TeleportRandom/utils/VersionChecker.java b/src/cn/citycraft/TeleportRandom/utils/VersionChecker.java deleted file mode 100644 index c95cfbe..0000000 --- a/src/cn/citycraft/TeleportRandom/utils/VersionChecker.java +++ /dev/null @@ -1,112 +0,0 @@ -package cn.citycraft.TeleportRandom.utils; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.URL; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.plugin.Plugin; - -import com.google.common.base.Charsets; - -/** - * 自动更新类 - * - * @author 蒋天蓓 - * 2015年8月14日下午4:01:15 - */ -public class VersionChecker implements Listener { - Plugin plugin; - public String checkurl = "https://coding.net/u/502647092/p/%s/git/raw/%s/src/plugin.yml"; - public String branch = "master"; - - /** - * @param plugin - * - 插件 - */ - public VersionChecker(Plugin plugin) { - this.plugin = plugin; - plugin.getServer().getPluginManager().registerEvents(this, plugin); - this.versioncheck(null); - } - - /** - * @param plugin - * - 插件 - * @param branch - * - 分支名称 - */ - public VersionChecker(Plugin plugin, String branch) { - this.plugin = plugin; - plugin.getServer().getPluginManager().registerEvents(this, plugin); - this.checkurl = branch; - this.versioncheck(null); - } - - /** - * 获取插件更新链接 - * - * @param pluginName - * - 插件名称 - * @param branch - * - 插件分支 - * @return 更新链接 - */ - public String getCheckUrl(String pluginName, String branch) { - return String.format(checkurl, pluginName, branch); - } - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent e) { - if (e.getPlayer().isOp()) { - this.versioncheck(e.getPlayer()); - } - } - - /** - * 开始更新 - * - * @param player - * - 获取更新的玩家(null则默认为控制台) - */ - public void versioncheck(final Player player) { - Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { - @Override - public void run() { - String readURL = getCheckUrl(plugin.getName(), branch); - FileConfiguration config; - String currentVersion = plugin.getDescription().getVersion(); - try { - URL url = new URL(readURL); - BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(), Charsets.UTF_8)); - config = YamlConfiguration.loadConfiguration(br); - String newVersion = config.getString("version"); - br.close(); - if (!newVersion.equals(currentVersion)) { - String[] msg = new String[] { - ChatColor.GREEN + plugin.getName() + " 插件最新版本 v" + newVersion, - ChatColor.RED + "服务器运行版本: v" + currentVersion, - ChatColor.GOLD + "插件更新网站: " + ChatColor.BLUE + plugin.getDescription().getWebsite() - }; - if (player != null) { - player.sendMessage(msg); - } else { - plugin.getServer().getConsoleSender().sendMessage(msg); - } - } - } catch (IOException e) { - plugin.getLogger().warning("版本更新检查失败!"); - } - } - }); - } - -} diff --git a/src/cn/citycraft/config/Config.java b/src/cn/citycraft/config/Config.java deleted file mode 100644 index 18c866b..0000000 --- a/src/cn/citycraft/config/Config.java +++ /dev/null @@ -1,55 +0,0 @@ -package cn.citycraft.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/config/ConfigLoader.java b/src/cn/citycraft/config/ConfigLoader.java deleted file mode 100644 index 21ce458..0000000 --- a/src/cn/citycraft/config/ConfigLoader.java +++ /dev/null @@ -1,102 +0,0 @@ -package cn.citycraft.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/config/FileConfig.java b/src/cn/citycraft/config/FileConfig.java deleted file mode 100644 index 4261603..0000000 --- a/src/cn/citycraft/config/FileConfig.java +++ /dev/null @@ -1,108 +0,0 @@ -package cn.citycraft.config; - -import java.io.BufferedReader; -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.Reader; -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 { - - 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; - } - - protected final DumperOptions yamlOptions = new DumperOptions(); - - protected final Representer yamlRepresenter = new YamlRepresenter(); - - protected final Yaml yaml = new Yaml(new YamlConstructor(), yamlRepresenter, yamlOptions); - - @Override - 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)); - } - - @Override - public void load(Reader reader) throws IOException, InvalidConfigurationException { - BufferedReader input = (reader instanceof BufferedReader) ? (BufferedReader) reader - : new BufferedReader(reader); - StringBuilder builder = new StringBuilder(); - try { - String line; - while ((line = input.readLine()) != null) { - builder.append(line); - builder.append('\n'); - } - } finally { - input.close(); - } - loadFromString(builder.toString()); - } - - @Override - 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(); - } - } - - @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; - } -} diff --git a/src/main/java/cn/citycraft/TeleportRandom/TeleportRandom.java b/src/main/java/cn/citycraft/TeleportRandom/TeleportRandom.java new file mode 100644 index 0000000..52facd4 --- /dev/null +++ b/src/main/java/cn/citycraft/TeleportRandom/TeleportRandom.java @@ -0,0 +1,112 @@ +package cn.citycraft.TeleportRandom; + +import java.util.Random; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import cn.citycraft.PluginHelper.config.FileConfig; + +public class TeleportRandom extends JavaPlugin implements CommandExecutor { + public FileConfig config; + public String pluginname; + public String servername; + + @Override + public boolean onCommand(final CommandSender sender, final Command cmd, final String string, final String[] args) { + if (args.length == 1 && args[0].equalsIgnoreCase("reload")) { + this.onLoad(); + sender.sendMessage(servername + pluginname + config.getMessage("Message.Reload")); + return true; + } + if (sender instanceof Player) { + final Player p = (Player) sender; + if (!p.hasPermission("tpr.use")) { + sender.sendMessage(servername + pluginname + config.getMessage("Message.NoPerm")); + return true; + } + try { + switch (args.length) { + case 0: + RandomTP(0, p); + break; + case 1: + RandomTP(Integer.parseInt(args[0]), p); + break; + case 2: + RandomTP(Integer.parseInt(args[0]), Bukkit.getWorld(args[1]), p); + break; + } + } catch (final Exception e) { + sender.sendMessage(pluginname + "§c非法的参数或不存在的世界!"); + } + return true; + } else { + sender.sendMessage(pluginname + "§c控制台无法使用此命令!"); + } + return false; + } + + @Override + public void onLoad() { + config = new FileConfig(this); + servername = config.getMessage("servername"); + pluginname = config.getMessage("pluginname"); + } + + public void RandomTP(final int limit, final Player p) { + RandomTP(limit, p.getWorld(), p); + } + + public void RandomTP(final int limit, final World world, final Player p) { + final Random rr = new Random(); + int lr = config.getInt("default"); + if (limit == 0) { + p.sendMessage(pluginname + config.getMessage("Message.default1")); + p.sendMessage(pluginname + config.getMessage("Message.default2")); + } else { + lr = limit; + final int lrLimit = config.getInt("Limit"); + if (lr > lrLimit) { + lr = lrLimit; + p.sendMessage(String.format(pluginname + config.getMessage("Message.Wran"), lrLimit)); + } + } + int x = rr.nextInt(lr); + int z = rr.nextInt(lr); + final int xf = rr.nextInt(x); + final int yf = rr.nextInt(z); + if (xf % 2 != 0) { + x = -x; + } + if (yf % 2 != 0) { + z = -z; + } + final int y = world.getHighestBlockYAt(x, z); + final Location trl = new Location(world, x, y - 1, z); + final Material rbm = trl.getBlock().getType(); + final String blockname = rbm.name(); + for (final String protectblock : config.getStringList("ProtectBlock")) { + if (protectblock.equalsIgnoreCase(blockname)) { + trl.getBlock().setType(Material.GLASS); + p.sendMessage(pluginname + config.getMessage("Message.Protect")); + this.getServer().getScheduler().runTaskLater(this, new Runnable() { + @Override + public void run() { + trl.getBlock().setType(rbm); + } + }, 200); + } + } + final Location nrl = new Location(world, x, y + 3, z); + p.teleport(nrl); + p.sendMessage(String.format(pluginname + config.getMessage("Message.Tip"), world.getName(), x, y, z)); + } +} diff --git a/src/config.yml b/src/main/resources/config.yml similarity index 80% rename from src/config.yml rename to src/main/resources/config.yml index a44ecd2..f6f1807 100644 --- a/src/config.yml +++ b/src/main/resources/config.yml @@ -15,9 +15,9 @@ Message: default1: '&5未指定随机范围 使用默认值1000!' default2: '&c正确使用方法/tpr [随机传送范围]!' #提示 - Tip: '&a您被传送至 &6世界: %world% &dX: %x% Z: %z%!' + Tip: '&a您被传送至 &6世界: %s &dX: %s Z: %s !' #警告 - Wran: '&c超过最大允许传送范围 已限制为%limit%!' + Wran: '&c超过最大允许传送范围 已限制为%s !' #传送保护提示 Protect: '&3传送保护 下方有&c危险&3 已自动生成玻璃(10秒后消失) !' #没有传送的权限 @@ -25,8 +25,7 @@ Message: #允许传送的世界(不区分大小写) AllowWorld: - - FutureCity - - ZiYuan + - World #默认传送距离 default: 10000 diff --git a/src/plugin.yml b/src/main/resources/plugin.yml similarity index 100% rename from src/plugin.yml rename to src/main/resources/plugin.yml