mirror of
https://e.coding.net/circlecloud/TeleportRandom.git
synced 2024-12-26 16:38:49 +00:00
add VersionChecer add TPR World and updata config class...
This commit is contained in:
parent
c6170678de
commit
8b782a6910
@ -2,6 +2,7 @@ package cn.citycraft.TeleportRandom;
|
|||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -11,7 +12,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import cn.citycraft.Utils.config.Config;
|
import cn.citycraft.config.Config;
|
||||||
|
|
||||||
public class TeleportRandom extends JavaPlugin implements CommandExecutor {
|
public class TeleportRandom extends JavaPlugin implements CommandExecutor {
|
||||||
public String servername;
|
public String servername;
|
||||||
@ -23,29 +24,36 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String string,
|
public boolean onCommand(CommandSender sender, Command cmd, String string, String[] args) {
|
||||||
String[] args) {
|
if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
|
||||||
if (cmd.getName().equalsIgnoreCase("tpr")) {
|
|
||||||
if (args.length != 1)
|
|
||||||
return false;
|
|
||||||
if (args[0].equalsIgnoreCase("reload")) {
|
|
||||||
this.onLoad();
|
this.onLoad();
|
||||||
sender.sendMessage(servername + pluginname
|
sender.sendMessage(servername + pluginname + getmessage("Message.Reload"));
|
||||||
+ getmessage("Message.Reload"));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
Player p = (Player) sender;
|
Player p = (Player) sender;
|
||||||
if (!p.hasPermission("tpr.use")) {
|
if (!p.hasPermission("tpr.use")) {
|
||||||
sender.sendMessage(servername + pluginname
|
sender.sendMessage(servername + pluginname + getmessage("Message.NoPerm"));
|
||||||
+ getmessage("Message.NoPerm"));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
RandomTP(args, p);
|
try {
|
||||||
return true;
|
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非法的参数或不存在的世界!");
|
||||||
}
|
}
|
||||||
sender.sendMessage(servername + pluginname + "控制台无法使用此命令!");
|
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
sender.sendMessage("§c控制台无法使用此命令!");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -57,27 +65,24 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor {
|
|||||||
pluginname = getmessage("pluginname");
|
pluginname = getmessage("pluginname");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RandomTP(String[] limit, Player p) {
|
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();
|
Random rr = new Random();
|
||||||
int lr = Config.getInstance().getInt("default");
|
int lr = Config.getInstance().getInt("default");
|
||||||
if (limit.length != 1) {
|
if (limit == 0) {
|
||||||
p.sendMessage(servername + pluginname
|
p.sendMessage(servername + pluginname + getmessage("Message.default1"));
|
||||||
+ getmessage("Message.default1"));
|
p.sendMessage(servername + pluginname + getmessage("Message.default2"));
|
||||||
p.sendMessage(servername + pluginname
|
|
||||||
+ getmessage("Message.default2"));
|
|
||||||
} else {
|
} else {
|
||||||
lr = Integer.parseInt(limit[0]);
|
lr = limit;
|
||||||
int lrLimit = Config.getInstance().getInt("Limit");
|
int lrLimit = Config.getInstance().getInt("Limit");
|
||||||
if (lr > lrLimit) {
|
if (lr > lrLimit) {
|
||||||
lr = lrLimit;
|
lr = lrLimit;
|
||||||
p.sendMessage(servername
|
p.sendMessage(servername + pluginname + getmessage("Message.Wran").replace("%limit%", lrLimit + ""));
|
||||||
+ pluginname
|
|
||||||
+ getmessage("Message.Wran").replace("%limit%",
|
|
||||||
lrLimit + ""));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Location l = p.getLocation();
|
|
||||||
World world = l.getWorld();
|
|
||||||
int x = rr.nextInt(lr);
|
int x = rr.nextInt(lr);
|
||||||
int z = rr.nextInt(lr);
|
int z = rr.nextInt(lr);
|
||||||
int xf = rr.nextInt(x);
|
int xf = rr.nextInt(x);
|
||||||
@ -92,14 +97,11 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor {
|
|||||||
final Location trl = new Location(world, x, y - 1, z);
|
final Location trl = new Location(world, x, y - 1, z);
|
||||||
final Material rbm = trl.getBlock().getType();
|
final Material rbm = trl.getBlock().getType();
|
||||||
String blockname = rbm.name();
|
String blockname = rbm.name();
|
||||||
for (String protectblock : Config.getInstance().getStringList(
|
for (String protectblock : Config.getInstance().getStringList("ProtectBlock")) {
|
||||||
"ProtectBlock")) {
|
|
||||||
if (protectblock.equalsIgnoreCase(blockname)) {
|
if (protectblock.equalsIgnoreCase(blockname)) {
|
||||||
trl.getBlock().setType(Material.GLASS);
|
trl.getBlock().setType(Material.GLASS);
|
||||||
p.sendMessage(servername + pluginname
|
p.sendMessage(servername + pluginname + getmessage("Message.Protect"));
|
||||||
+ getmessage("Message.Protect"));
|
this.getServer().getScheduler().runTaskLater(this, new Runnable() {
|
||||||
this.getServer().getScheduler()
|
|
||||||
.runTaskLater(this, new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
trl.getBlock().setType(rbm);
|
trl.getBlock().setType(rbm);
|
||||||
@ -109,10 +111,7 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
Location nrl = new Location(world, x, y + 3, z);
|
Location nrl = new Location(world, x, y + 3, z);
|
||||||
p.teleport(nrl);
|
p.teleport(nrl);
|
||||||
p.sendMessage(servername
|
p.sendMessage(servername + pluginname
|
||||||
+ pluginname
|
+ getmessage("Message.Tip").replaceAll("%world%", world.getName()).replaceAll("%x%", x + "").replaceAll("%z%", z + ""));
|
||||||
+ getmessage("Message.Tip")
|
|
||||||
.replaceAll("%world%", world.getName())
|
|
||||||
.replaceAll("%x%", x + "").replaceAll("%z%", z + ""));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
112
src/cn/citycraft/TeleportRandom/utils/VersionChecker.java
Normal file
112
src/cn/citycraft/TeleportRandom/utils/VersionChecker.java
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
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,4 +1,4 @@
|
|||||||
package cn.citycraft.Utils.config;
|
package cn.citycraft.config;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
@ -1,4 +1,4 @@
|
|||||||
package cn.citycraft.Utils.config;
|
package cn.citycraft.config;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
@ -1,4 +1,4 @@
|
|||||||
package cn.citycraft.Utils.config;
|
package cn.citycraft.config;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
@ -4,7 +4,7 @@ version: 1.0
|
|||||||
commands:
|
commands:
|
||||||
tpr:
|
tpr:
|
||||||
description: 随机传送插件命令
|
description: 随机传送插件命令
|
||||||
usage: 使用/tpr [随机传送范围] 进行随机传送!
|
usage: §6使用§a/tpr [随机传送范围] [随机传送世界]§6进行随机传送!
|
||||||
permissions:
|
permissions:
|
||||||
tpr.*:
|
tpr.*:
|
||||||
description: 允许使用所有命令!
|
description: 允许使用所有命令!
|
||||||
|
Loading…
Reference in New Issue
Block a user