1
0
mirror of https://e.coding.net/circlecloud/TeleportRandom.git synced 2024-10-31 07:28:47 +00:00

refactor: 修改版本 格式化代码

This commit is contained in:
502647092 2016-04-13 20:43:15 +08:00
parent 5c83588b39
commit 106a83af06
2 changed files with 126 additions and 120 deletions

26
pom.xml
View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>cn.citycraft</groupId>
<artifactId>TeleportRandom</artifactId>
<version>1.1</version>
<version>1.2</version>
<name>TeleportRandom</name>
<build>
<finalName>${project.name}</finalName>
@ -52,29 +52,35 @@
</plugin>
</plugins>
</build>
<ciManagement>
<system>Jenkins</system>
<url>http://ci.yumc.pw/job/${project.artifactId}/</url>
</ciManagement>
<properties>
<jenkins.url>http://ci.citycraft.cn:8080</jenkins.url>
<update.description>修复一直提示更新的问题...</update.description>
<update.description>&amp;e添加后台传送功能...</update.description>
<update.changes></update.changes>
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>citycraft-repo</id>
<url>${jenkins.url}/plugin/repository/everything/</url>
<id>yumc-repo</id>
<url>http://repo.yumc.pw/content/groups/public/</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>jtb</id>
<name>YUMC</name>
<url>http://repo.yumc.pw/content/repositories/yumcenter/</url>
</repository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<type>jar</type>
<version>1.8.8-R0.1-SNAPSHOT</version>
<version>1.9-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.citycraft</groupId>

View File

@ -16,120 +16,120 @@ import cn.citycraft.PluginHelper.config.FileConfig;
import cn.citycraft.PluginHelper.utils.VersionChecker;
public class TeleportRandom extends JavaPlugin implements CommandExecutor {
public FileConfig config;
public String pluginname;
public String servername;
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;
}
if(args.length>0){
try {
switch (args.length) {
case 1:
RandomTP(0,Bukkit.getPlayer(args[0]));
break;
case 2:
RandomTP(Integer.parseInt(args[1]),Bukkit.getPlayer(args[0]));
break;
case 3:
RandomTP(Integer.parseInt(args[1]),Bukkit.getWorld(args[2]),Bukkit.getPlayer(args[0]));
break;
}
return true;
} catch (final Exception e) {
sender.sendMessage(pluginname + "§c非法的参数或不存在的世界!");
}
@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;
}
sender.sendMessage(pluginname + "§c非法的参数!");
return false;
}
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;
}
if (args.length > 0) {
try {
switch (args.length) {
case 1:
RandomTP(0, Bukkit.getPlayer(args[0]));
break;
case 2:
RandomTP(Integer.parseInt(args[1]), Bukkit.getPlayer(args[0]));
break;
case 3:
RandomTP(Integer.parseInt(args[1]), Bukkit.getWorld(args[2]), Bukkit.getPlayer(args[0]));
break;
}
return true;
} catch (final Exception e) {
sender.sendMessage(pluginname + "§c非法的参数或不存在的世界!");
}
}
sender.sendMessage(pluginname + "§c非法的参数!");
return false;
}
@Override
public void onEnable() {
new VersionChecker(this);
}
@Override
public void onEnable() {
new VersionChecker(this);
}
@Override
public void onLoad() {
config = new FileConfig(this);
servername = config.getMessage("servername");
pluginname = config.getMessage("pluginname");
}
@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 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));
}
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));
}
}