mirror of
https://e.coding.net/circlecloud/TeleportRandom.git
synced 2025-11-04 18:26:03 +00:00
remove old class and update frame...
Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
112
src/main/java/cn/citycraft/TeleportRandom/TeleportRandom.java
Normal file
112
src/main/java/cn/citycraft/TeleportRandom/TeleportRandom.java
Normal file
@@ -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));
|
||||
}
|
||||
}
|
||||
39
src/main/resources/config.yml
Normal file
39
src/main/resources/config.yml
Normal file
@@ -0,0 +1,39 @@
|
||||
#本文件为随机传送插件的主配置文件
|
||||
version: 1.0
|
||||
#服务器名称
|
||||
servername: ''
|
||||
#插件名称
|
||||
pluginname: '§6[§b随机传送§6]&r'
|
||||
#是否提示
|
||||
tipplayer: true
|
||||
#提示消息
|
||||
Message:
|
||||
Reload: '&a配置文件已重新载入!'
|
||||
|
||||
#随机传送提示
|
||||
#默认提示
|
||||
default1: '&5未指定随机范围 使用默认值1000!'
|
||||
default2: '&c正确使用方法/tpr [随机传送范围]!'
|
||||
#提示
|
||||
Tip: '&a您被传送至 &6世界: %s &dX: %s Z: %s !'
|
||||
#警告
|
||||
Wran: '&c超过最大允许传送范围 已限制为%s !'
|
||||
#传送保护提示
|
||||
Protect: '&3传送保护 下方有&c危险&3 已自动生成玻璃(10秒后消失) !'
|
||||
#没有传送的权限
|
||||
NoPerm: '&c当前没有使用随机传送的权限!'
|
||||
|
||||
#允许传送的世界(不区分大小写)
|
||||
AllowWorld:
|
||||
- World
|
||||
|
||||
#默认传送距离
|
||||
default: 10000
|
||||
#最大传送距离
|
||||
Limit: 10000
|
||||
|
||||
#传送保护列表(不区分大小写)
|
||||
ProtectBlock:
|
||||
- WATER
|
||||
- LAVA
|
||||
- CACTUS
|
||||
21
src/main/resources/plugin.yml
Normal file
21
src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
name: TeleportRandom
|
||||
main: cn.citycraft.TeleportRandom.TeleportRandom
|
||||
website: http://ci.citycraft.cn:8800/jenkins/job/TeleportRandom/
|
||||
version: 1.0
|
||||
commands:
|
||||
tpr:
|
||||
description: 随机传送插件命令
|
||||
usage: §6使用§a/tpr [随机传送范围] [随机传送世界]§6进行随机传送!
|
||||
permissions:
|
||||
tpr.*:
|
||||
description: 允许使用所有命令!
|
||||
default: op
|
||||
children:
|
||||
tpr.use: true
|
||||
tpr.reload: true
|
||||
tpr.use:
|
||||
description: 允许使用随机传送!
|
||||
default: true
|
||||
tpr.reload:
|
||||
description: 允许重载随机传送!
|
||||
default: op
|
||||
Reference in New Issue
Block a user