remove old class and update frame...
Signed-off-by: 502647092 <jtb1@163.com>pull/1/MERGE
parent
fc2d800436
commit
88e34574a2
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" path="src/main/java"/>
|
||||||
|
<classpathentry kind="src" path="src/main/resources"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
|
</classpath>
|
|
@ -1,6 +1,4 @@
|
||||||
# Eclipse stuff
|
# Eclipse stuff
|
||||||
/.classpath
|
|
||||||
/.project
|
|
||||||
/.settings
|
/.settings
|
||||||
|
|
||||||
# netbeans
|
# netbeans
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>TeleportRandom</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
59
pom.xml
59
pom.xml
|
@ -1,19 +1,16 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>cn.CityCraft</groupId>
|
<groupId>cn.citycraft</groupId>
|
||||||
<artifactId>TeleportRandom</artifactId>
|
<artifactId>TeleportRandom</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>1.0</version>
|
||||||
<name>TeleportRandom</name>
|
<name>TeleportRandom</name>
|
||||||
<build>
|
<build>
|
||||||
<finalName>${project.name}</finalName>
|
<finalName>${project.name}</finalName>
|
||||||
<sourceDirectory>src</sourceDirectory>
|
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
<directory>src</directory>
|
<directory>src/main/resources</directory>
|
||||||
<excludes>
|
<filtering>true</filtering>
|
||||||
<exclude>**/*.java</exclude>
|
|
||||||
</excludes>
|
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
@ -25,23 +22,63 @@
|
||||||
<target>1.7</target>
|
<target>1.7</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>2.3</version>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
<minimizeJar>true</minimizeJar>
|
||||||
|
<artifactSet>
|
||||||
|
<includes>
|
||||||
|
<include>cn.citycraft:PluginHelper</include>
|
||||||
|
</includes>
|
||||||
|
</artifactSet>
|
||||||
|
<relocations>
|
||||||
|
<relocation>
|
||||||
|
<pattern>cn.citycraft.PluginHelper</pattern>
|
||||||
|
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
</relocations>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
<properties>
|
||||||
|
<jenkins.url>http://ci.citycraft.cn:8080</jenkins.url>
|
||||||
|
<update.description>更新插件框架...</update.description>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>spigot-repo</id>
|
<id>spigot-repo</id>
|
||||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>citycraft-repo</id>
|
||||||
|
<url>${jenkins.url}/plugin/repository/everything/</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<version>1.8.3-R0.1-SNAPSHOT</version>
|
<version>1.8.8-R0.1-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.citycraft</groupId>
|
||||||
|
<artifactId>PluginHelper</artifactId>
|
||||||
|
<type>jar</type>
|
||||||
|
<version>1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<properties>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
</project>
|
</project>
|
|
@ -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 + ""));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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("版本更新检查失败!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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() + "保存错误...");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,9 +15,9 @@ Message:
|
||||||
default1: '&5未指定随机范围 使用默认值1000!'
|
default1: '&5未指定随机范围 使用默认值1000!'
|
||||||
default2: '&c正确使用方法/tpr [随机传送范围]!'
|
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秒后消失) !'
|
Protect: '&3传送保护 下方有&c危险&3 已自动生成玻璃(10秒后消失) !'
|
||||||
#没有传送的权限
|
#没有传送的权限
|
||||||
|
@ -25,8 +25,7 @@ Message:
|
||||||
|
|
||||||
#允许传送的世界(不区分大小写)
|
#允许传送的世界(不区分大小写)
|
||||||
AllowWorld:
|
AllowWorld:
|
||||||
- FutureCity
|
- World
|
||||||
- ZiYuan
|
|
||||||
|
|
||||||
#默认传送距离
|
#默认传送距离
|
||||||
default: 10000
|
default: 10000
|
Loading…
Reference in New Issue