mirror of
https://e.coding.net/circlecloud/SimpleEssential.git
synced 2024-11-17 01:18:47 +00:00
update BaseCommand...
Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
parent
16003a3526
commit
df46033903
@ -11,7 +11,7 @@
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<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>
|
||||
|
4
pom.xml
4
pom.xml
@ -19,8 +19,8 @@
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
@ -13,9 +13,9 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||
import cn.citycraft.PluginHelper.config.FileConfig;
|
||||
import cn.citycraft.PluginHelper.utils.VersionChecker;
|
||||
import cn.citycraft.SimpleEssential.command.BaseCommand;
|
||||
import cn.citycraft.SimpleEssential.command.CommandBack;
|
||||
import cn.citycraft.SimpleEssential.command.CommandEnchantBench;
|
||||
import cn.citycraft.SimpleEssential.command.CommandGc;
|
||||
@ -42,7 +42,6 @@ import cn.citycraft.SimpleEssential.teleport.TeleportControl;
|
||||
* @author 蒋天蓓 2015年8月11日下午3:29:32
|
||||
*/
|
||||
public class SimpleEssential extends JavaPlugin {
|
||||
FileConfig config;
|
||||
/**
|
||||
* 传送控制
|
||||
*/
|
||||
@ -51,10 +50,11 @@ public class SimpleEssential extends JavaPlugin {
|
||||
* 命令监听列表
|
||||
*/
|
||||
private List<BaseCommand> commandlist;
|
||||
FileConfig config;
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
for (BaseCommand command : commandlist)
|
||||
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
|
||||
for (final BaseCommand command : commandlist) {
|
||||
if (command.isValidTrigger(label)) {
|
||||
if (!command.hasPermission(sender)) {
|
||||
sender.sendMessage(I18n.p("Base.no-permission"));
|
||||
@ -64,14 +64,16 @@ public class SimpleEssential extends JavaPlugin {
|
||||
sender.sendMessage(I18n.p("Base.playercommand"));
|
||||
return true;
|
||||
}
|
||||
if (args.length >= command.getMinimumArguments())
|
||||
if (args.length >= command.getMinimumArguments()) {
|
||||
try {
|
||||
command.execute(sender, label, args);
|
||||
command.execute(sender, cmd, label, args);
|
||||
return true;
|
||||
} catch (CommandException e) {
|
||||
} catch (final CommandException e) {
|
||||
sender.sendMessage(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -95,7 +97,7 @@ public class SimpleEssential extends JavaPlugin {
|
||||
* @param command
|
||||
* - 被注册的命令类
|
||||
*/
|
||||
public void registerCommand(BaseCommand command) {
|
||||
public void registerCommand(final BaseCommand command) {
|
||||
commandlist.add(command);
|
||||
}
|
||||
|
||||
@ -128,13 +130,13 @@ public class SimpleEssential extends JavaPlugin {
|
||||
* @param listener
|
||||
* - 被注册的事件类
|
||||
*/
|
||||
public void registerEvent(Listener listener) {
|
||||
public void registerEvent(final Listener listener) {
|
||||
getServer().getPluginManager().registerEvents(listener, this);
|
||||
}
|
||||
|
||||
private void initTeleportControl() {
|
||||
int tpdelay = config.getInt("Teleport.delay", 3);
|
||||
String tpcontorlname = config.getMessage("Teleport.name");
|
||||
final int tpdelay = config.getInt("Teleport.delay", 3);
|
||||
final String tpcontorlname = config.getMessage("Teleport.name");
|
||||
tpcontrol = new TeleportControl(this, tpcontorlname, tpdelay);
|
||||
}
|
||||
|
||||
|
@ -1,128 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package cn.citycraft.SimpleEssential.command;
|
||||
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* 基础命令类
|
||||
*
|
||||
* @author 蒋天蓓 2015年8月12日下午12:49:34
|
||||
*/
|
||||
public abstract class BaseCommand {
|
||||
private String name;
|
||||
private String permission;
|
||||
private String[] aliases;
|
||||
|
||||
public BaseCommand(String name) {
|
||||
this(name, new String[0]);
|
||||
}
|
||||
|
||||
public BaseCommand(String name, String... aliases) {
|
||||
this.name = name;
|
||||
this.aliases = aliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令参数
|
||||
*
|
||||
* @param sender
|
||||
* - 命令发送者
|
||||
* @param label
|
||||
* - 命令
|
||||
* @param args
|
||||
* - 命令附加参数
|
||||
* @throws CommandException
|
||||
* - 命令异常
|
||||
*/
|
||||
public abstract void execute(CommandSender sender, String label, String[] args) throws CommandException;
|
||||
|
||||
/**
|
||||
* 获得命令描述
|
||||
*
|
||||
* @return 命令描述
|
||||
*/
|
||||
public abstract String getDescription();
|
||||
|
||||
/**
|
||||
* 获得最小参数个数
|
||||
*
|
||||
* @return 最小参数个数
|
||||
*/
|
||||
public abstract int getMinimumArguments();
|
||||
|
||||
/**
|
||||
* 获取命令名称
|
||||
*
|
||||
* @return 命令名称
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得命令权限
|
||||
*
|
||||
* @return 目录命令权限
|
||||
*/
|
||||
public String getPermission() {
|
||||
return permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得可能的参数
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract String getPossibleArguments();
|
||||
|
||||
/**
|
||||
* 检查Sender权限
|
||||
*
|
||||
* @param sender
|
||||
* - 命令发送者
|
||||
* @return 是否有权限执行命令
|
||||
*/
|
||||
public final boolean hasPermission(CommandSender sender) {
|
||||
if (permission == null)
|
||||
return true;
|
||||
return sender.hasPermission(permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否只有玩家才能执行此命令
|
||||
*
|
||||
* @return 是否为玩家命令
|
||||
*/
|
||||
public abstract boolean isOnlyPlayerExecutable();
|
||||
|
||||
/**
|
||||
* 命令匹配检测
|
||||
*
|
||||
* @param name
|
||||
* - 命令
|
||||
* @return 是否匹配
|
||||
*/
|
||||
public final boolean isValidTrigger(String name) {
|
||||
if (this.name.equalsIgnoreCase(name))
|
||||
return true;
|
||||
if (aliases != null)
|
||||
for (String alias : aliases)
|
||||
if (alias.equalsIgnoreCase(name))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置命令权限
|
||||
*
|
||||
* @param permission
|
||||
* - 命令权限
|
||||
*/
|
||||
public void setPermission(String permission) {
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
}
|
@ -3,10 +3,12 @@
|
||||
*/
|
||||
package cn.citycraft.SimpleEssential.command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||
import cn.citycraft.SimpleEssential.SimpleEssential;
|
||||
|
||||
/**
|
||||
@ -18,33 +20,14 @@ public class CommandBack extends BaseCommand {
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandBack(SimpleEssential main) {
|
||||
public CommandBack(final SimpleEssential main) {
|
||||
super("back", "seback");
|
||||
setOnlyPlayerExecutable();
|
||||
this.plugin = main;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
plugin.tpcontrol.back((Player) sender);
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "回到上一个地点";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPossibleArguments() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyPlayerExecutable() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -3,49 +3,35 @@
|
||||
*/
|
||||
package cn.citycraft.SimpleEssential.command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||
import cn.citycraft.SimpleEssential.SimpleEssential;
|
||||
|
||||
/**
|
||||
* @author 蒋天蓓 2015年8月12日下午2:04:05
|
||||
*/
|
||||
public class CommandEnchantBench extends BaseCommand {
|
||||
|
||||
SimpleEssential plugin;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandEnchantBench(SimpleEssential main) {
|
||||
public CommandEnchantBench(final SimpleEssential main) {
|
||||
super("enchantbench", "seenchantbench", "eb", "seeb");
|
||||
this.plugin = main;
|
||||
setOnlyPlayerExecutable();
|
||||
setDescription("打开随声附魔台");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
Player p = (Player) sender;
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
final Player p = (Player) sender;
|
||||
p.openEnchanting(null, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "打开随声附魔台";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPossibleArguments() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyPlayerExecutable() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -8,9 +8,11 @@ import java.util.logging.Level;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||
import cn.citycraft.PluginHelper.utils.StringUtil;
|
||||
import cn.citycraft.PluginHelper.utils.SystemUtil;
|
||||
import cn.citycraft.SimpleEssential.SimpleEssential;
|
||||
@ -29,50 +31,33 @@ public class CommandGc extends BaseCommand {
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandGc(SimpleEssential main) {
|
||||
public CommandGc(final SimpleEssential main) {
|
||||
super("gc", "mem");
|
||||
this.plugin = main;
|
||||
setDescription("清理内存");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
Runtime rt = Runtime.getRuntime();
|
||||
if (label.equalsIgnoreCase("gc"))
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
final Runtime rt = Runtime.getRuntime();
|
||||
if (label.equalsIgnoreCase("gc")) {
|
||||
rt.gc();
|
||||
}
|
||||
sender.sendMessage(I18n.p("Gc.runTime", StringUtil.formatDate(SystemUtil.getRunTime())));
|
||||
sender.sendMessage(I18n.p("Gc.Processors", rt.availableProcessors()));
|
||||
sender.sendMessage(I18n.p("Gc.maxMem", StringUtil.b2mb(rt.maxMemory())));
|
||||
sender.sendMessage(I18n.p("Gc.totalMem", StringUtil.b2mb(rt.totalMemory())));
|
||||
sender.sendMessage(I18n.p("Gc.freeMem", StringUtil.b2mb(rt.freeMemory())));
|
||||
for (World wd : Bukkit.getWorlds()) {
|
||||
for (final World wd : Bukkit.getWorlds()) {
|
||||
int tileEntities = 0;
|
||||
try {
|
||||
for (Chunk chunk : wd.getLoadedChunks())
|
||||
for (final Chunk chunk : wd.getLoadedChunks()) {
|
||||
tileEntities += chunk.getTileEntities().length;
|
||||
} catch (ClassCastException ex) {
|
||||
}
|
||||
} catch (final ClassCastException ex) {
|
||||
org.bukkit.Bukkit.getLogger().log(Level.SEVERE, "无法读取区块信息 错误世界: " + wd, ex);
|
||||
}
|
||||
sender.sendMessage(I18n.p("World.info", wd.getName(), wd.getEnvironment().toString(), wd.getLoadedChunks().length, wd.getEntities().size(), tileEntities, wd.getPlayers().size()));
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "清理内存";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPossibleArguments() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyPlayerExecutable() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
package cn.citycraft.SimpleEssential.command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||
import cn.citycraft.SimpleEssential.SimpleEssential;
|
||||
import cn.citycraft.SimpleEssential.config.I18n;
|
||||
|
||||
@ -15,49 +17,30 @@ import cn.citycraft.SimpleEssential.config.I18n;
|
||||
public class CommandHat extends BaseCommand {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private SimpleEssential plugin;
|
||||
private final SimpleEssential plugin;
|
||||
|
||||
public CommandHat(SimpleEssential main) {
|
||||
public CommandHat(final SimpleEssential main) {
|
||||
super("hat", "sehat");
|
||||
this.plugin = main;
|
||||
setDescription("把手上的方块带在手上");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
Player p = (Player) sender;
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
final Player p = (Player) sender;
|
||||
if (p.getItemInHand() == null) {
|
||||
sender.sendMessage(I18n.p("Hat.empty"));
|
||||
return;
|
||||
} else {
|
||||
ItemStack hand = p.getItemInHand();
|
||||
final ItemStack hand = p.getItemInHand();
|
||||
p.setItemInHand(null);
|
||||
ItemStack helmet = p.getInventory().getHelmet();
|
||||
if (!(helmet == null))
|
||||
final ItemStack helmet = p.getInventory().getHelmet();
|
||||
if (!(helmet == null)) {
|
||||
p.getInventory().addItem(helmet);
|
||||
}
|
||||
p.getInventory().setHelmet(hand);
|
||||
sender.sendMessage(I18n.p("Hat.enjoy"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "把手上的方块带在手上";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPossibleArguments() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyPlayerExecutable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,10 +4,12 @@
|
||||
package cn.citycraft.SimpleEssential.command;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||
import cn.citycraft.SimpleEssential.SimpleEssential;
|
||||
import cn.citycraft.SimpleEssential.config.I18n;
|
||||
|
||||
@ -22,39 +24,21 @@ public class CommandHome extends BaseCommand {
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandHome(SimpleEssential main) {
|
||||
public CommandHome(final SimpleEssential main) {
|
||||
super("home", "eshome");
|
||||
this.plugin = main;
|
||||
setOnlyPlayerExecutable();
|
||||
setDescription("传送回家");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
Player p = (Player) sender;
|
||||
Location loc = p.getBedSpawnLocation();
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
final Player p = (Player) sender;
|
||||
final Location loc = p.getBedSpawnLocation();
|
||||
if (loc == null) {
|
||||
p.sendMessage(I18n.p("Teleport.homelose"));
|
||||
return;
|
||||
}
|
||||
plugin.tpcontrol.magicTeleport(p, loc);
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "回到家";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPossibleArguments() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyPlayerExecutable() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,12 @@ package cn.citycraft.SimpleEssential.command;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||
import cn.citycraft.SimpleEssential.SimpleEssential;
|
||||
import cn.citycraft.SimpleEssential.config.I18n;
|
||||
|
||||
@ -20,39 +22,22 @@ import cn.citycraft.SimpleEssential.config.I18n;
|
||||
public class CommandSetHome extends BaseCommand {
|
||||
SimpleEssential plugin;
|
||||
|
||||
public CommandSetHome(SimpleEssential main) {
|
||||
public CommandSetHome(final SimpleEssential main) {
|
||||
super("sethome", "essethome");
|
||||
this.plugin = main;
|
||||
setOnlyPlayerExecutable();
|
||||
setDescription("设置家");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
Player p = (Player) sender;
|
||||
Block b = p.getLocation().getBlock();
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
final Player p = (Player) sender;
|
||||
final Block b = p.getLocation().getBlock();
|
||||
if (b.getType() == Material.BED_BLOCK) {
|
||||
p.setBedSpawnLocation(b.getLocation(), true);
|
||||
p.sendMessage(I18n.p("Teleport.sethomesuccess"));
|
||||
} else
|
||||
} else {
|
||||
p.sendMessage(I18n.p("Teleport.sethomeerror"));
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "设置家";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPossibleArguments() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyPlayerExecutable() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -4,10 +4,12 @@
|
||||
package cn.citycraft.SimpleEssential.command;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||
import cn.citycraft.SimpleEssential.SimpleEssential;
|
||||
import cn.citycraft.SimpleEssential.config.I18n;
|
||||
|
||||
@ -20,36 +22,18 @@ public class CommandSetSpawn extends BaseCommand {
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandSetSpawn(SimpleEssential main) {
|
||||
public CommandSetSpawn(final SimpleEssential main) {
|
||||
super("setspawn", "sesetspawn");
|
||||
this.plugin = main;
|
||||
setOnlyPlayerExecutable();
|
||||
setDescription("设置出生点");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
Player p = (Player) sender;
|
||||
Location loc = p.getLocation();
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
final Player p = (Player) sender;
|
||||
final Location loc = p.getLocation();
|
||||
p.getWorld().setSpawnLocation(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
p.sendMessage(I18n.p("Teleport.setspawn", p.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "设置出生点";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPossibleArguments() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyPlayerExecutable() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,12 @@
|
||||
*/
|
||||
package cn.citycraft.SimpleEssential.command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||
import cn.citycraft.SimpleEssential.SimpleEssential;
|
||||
|
||||
/**
|
||||
@ -18,34 +20,16 @@ public class CommandSpawn extends BaseCommand {
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandSpawn(SimpleEssential main) {
|
||||
public CommandSpawn(final SimpleEssential main) {
|
||||
super("spawn", "sespawn");
|
||||
this.plugin = main;
|
||||
setOnlyPlayerExecutable();
|
||||
setDescription("回到主城");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
Player p = (Player) sender;
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
final Player p = (Player) sender;
|
||||
plugin.tpcontrol.magicTeleport(p, p.getWorld().getSpawnLocation());
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "回到主城";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPossibleArguments() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyPlayerExecutable() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -5,12 +5,14 @@ import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||
import cn.citycraft.SimpleEssential.SimpleEssential;
|
||||
import cn.citycraft.SimpleEssential.config.I18n;
|
||||
import cn.citycraft.SimpleEssential.utils.EffectUtil;
|
||||
@ -22,45 +24,25 @@ import cn.citycraft.SimpleEssential.utils.EffectUtil;
|
||||
*/
|
||||
|
||||
public class CommandSuicide extends BaseCommand {
|
||||
private SimpleEssential plugin;
|
||||
private final SimpleEssential plugin;
|
||||
|
||||
public CommandSuicide(SimpleEssential main) {
|
||||
public CommandSuicide(final SimpleEssential main) {
|
||||
super("suicide", "sesuicide", "sd");
|
||||
this.plugin = main;
|
||||
|
||||
setOnlyPlayerExecutable();
|
||||
setDescription("自杀");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
Player p = (Player) sender;
|
||||
List<ItemStack> drops = Arrays.asList(p.getInventory().getContents());
|
||||
int deoppedexp = (int) Math.floor(p.getExp());
|
||||
String deathMessage = I18n.p("Suicide.msg");
|
||||
PlayerDeathEvent pd = new PlayerDeathEvent(p, drops, deoppedexp, deathMessage);
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
final Player p = (Player) sender;
|
||||
final List<ItemStack> drops = Arrays.asList(p.getInventory().getContents());
|
||||
final int deoppedexp = (int) Math.floor(p.getExp());
|
||||
final String deathMessage = I18n.p("Suicide.msg");
|
||||
final PlayerDeathEvent pd = new PlayerDeathEvent(p, drops, deoppedexp, deathMessage);
|
||||
plugin.getServer().getPluginManager().callEvent(pd);
|
||||
Bukkit.broadcastMessage(pd.getDeathMessage());
|
||||
EffectUtil.run(p.getLocation(), 10, Effect.POTION_BREAK);
|
||||
p.setHealth(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "自杀";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPossibleArguments() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyPlayerExecutable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,10 +4,12 @@
|
||||
package cn.citycraft.SimpleEssential.command;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||
import cn.citycraft.SimpleEssential.SimpleEssential;
|
||||
import cn.citycraft.SimpleEssential.config.I18n;
|
||||
|
||||
@ -24,38 +26,20 @@ public class CommandTop extends BaseCommand {
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandTop(SimpleEssential main) {
|
||||
public CommandTop(final SimpleEssential main) {
|
||||
super("top", "estop");
|
||||
this.plugin = main;
|
||||
setOnlyPlayerExecutable();
|
||||
setDescription("传送到最高点");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
Player p = (Player) sender;
|
||||
Location loc = p.getLocation();
|
||||
int top = loc.getWorld().getHighestBlockYAt(loc);
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
final Player p = (Player) sender;
|
||||
final Location loc = p.getLocation();
|
||||
final int top = loc.getWorld().getHighestBlockYAt(loc);
|
||||
loc.setY(top);
|
||||
p.teleport(loc);
|
||||
p.sendMessage(I18n.p("Teleport.top"));
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "传送到最高点";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPossibleArguments() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyPlayerExecutable() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -4,10 +4,12 @@
|
||||
package cn.citycraft.SimpleEssential.command;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||
import cn.citycraft.SimpleEssential.SimpleEssential;
|
||||
import cn.citycraft.SimpleEssential.config.I18n;
|
||||
import cn.citycraft.SimpleEssential.teleport.TeleportType;
|
||||
@ -25,42 +27,24 @@ public class CommandTpa extends BaseCommand {
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandTpa(SimpleEssential main) {
|
||||
public CommandTpa(final SimpleEssential main) {
|
||||
super("tpa");
|
||||
this.plugin = main;
|
||||
setOnlyPlayerExecutable();
|
||||
setMinimumArguments(1);
|
||||
setDescription("传送到玩家");
|
||||
setPossibleArguments("<目标玩家>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
final Player target = Bukkit.getPlayer(args[0]);
|
||||
if (target == null) {
|
||||
sender.sendMessage(I18n.p("Base.offline", args[0]));
|
||||
return;
|
||||
}
|
||||
plugin.tpcontrol.addtp((Player) sender, Bukkit.getPlayer(args[0]), TeleportType.TPA);
|
||||
sender.sendMessage(I18n.p("Teleport.tpsend"));
|
||||
target.sendMessage(new String[] { I18n.p("Teleport.tpa", sender.getName()),
|
||||
I18n.p("Teleport.tpaccept"),
|
||||
I18n.p("Teleport.tpdeny") });
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "传送到玩家";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPossibleArguments() {
|
||||
return "<目标玩家>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyPlayerExecutable() {
|
||||
return true;
|
||||
target.sendMessage(new String[] { I18n.p("Teleport.tpa", sender.getName()), I18n.p("Teleport.tpaccept"), I18n.p("Teleport.tpdeny") });
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,12 @@
|
||||
*/
|
||||
package cn.citycraft.SimpleEssential.command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||
import cn.citycraft.SimpleEssential.SimpleEssential;
|
||||
|
||||
/**
|
||||
@ -22,33 +24,15 @@ public class CommandTpaccept extends BaseCommand {
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandTpaccept(SimpleEssential main) {
|
||||
public CommandTpaccept(final SimpleEssential main) {
|
||||
super("tpaccept", "tpok");
|
||||
this.plugin = main;
|
||||
setOnlyPlayerExecutable();
|
||||
setDescription("接受邀请");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
plugin.tpcontrol.accept((Player) sender);
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "接受传送";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPossibleArguments() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyPlayerExecutable() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,12 @@
|
||||
*/
|
||||
package cn.citycraft.SimpleEssential.command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||
import cn.citycraft.SimpleEssential.SimpleEssential;
|
||||
|
||||
/**
|
||||
@ -19,34 +21,16 @@ import cn.citycraft.SimpleEssential.SimpleEssential;
|
||||
public class CommandTpdeny extends BaseCommand {
|
||||
SimpleEssential plugin;
|
||||
|
||||
public CommandTpdeny(SimpleEssential main) {
|
||||
public CommandTpdeny(final SimpleEssential main) {
|
||||
super("tpdeny", "tpno");
|
||||
this.plugin = main;
|
||||
setOnlyPlayerExecutable();
|
||||
setDescription("拒绝传送");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
plugin.tpcontrol.accept((Player) sender);
|
||||
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "拒绝传送";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPossibleArguments() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyPlayerExecutable() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -4,10 +4,12 @@
|
||||
package cn.citycraft.SimpleEssential.command;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||
import cn.citycraft.SimpleEssential.SimpleEssential;
|
||||
import cn.citycraft.SimpleEssential.config.I18n;
|
||||
import cn.citycraft.SimpleEssential.teleport.TeleportType;
|
||||
@ -20,42 +22,24 @@ import cn.citycraft.SimpleEssential.teleport.TeleportType;
|
||||
public class CommandTphere extends BaseCommand {
|
||||
SimpleEssential plugin;
|
||||
|
||||
public CommandTphere(SimpleEssential main) {
|
||||
public CommandTphere(final SimpleEssential main) {
|
||||
super("tphere", "tph");
|
||||
this.plugin = main;
|
||||
setOnlyPlayerExecutable();
|
||||
setDescription("邀请玩家");
|
||||
setMinimumArguments(1);
|
||||
setPossibleArguments("<目标玩家>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
final Player target = Bukkit.getPlayer(args[0]);
|
||||
if (target == null) {
|
||||
sender.sendMessage(I18n.p("Base.offline", args[0]));
|
||||
return;
|
||||
}
|
||||
plugin.tpcontrol.addtp((Player) sender, Bukkit.getPlayer(args[0]), TeleportType.TPH);
|
||||
sender.sendMessage(I18n.p("Teleport.tpsend"));
|
||||
target.sendMessage(new String[] { I18n.p("Teleport.tphere", sender.getName()),
|
||||
I18n.p("Teleport.tpaccept"),
|
||||
I18n.p("Teleport.tpdeny") });
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "邀请玩家";
|
||||
};
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPossibleArguments() {
|
||||
return "<目标玩家>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyPlayerExecutable() {
|
||||
return true;
|
||||
target.sendMessage(new String[] { I18n.p("Teleport.tphere", sender.getName()), I18n.p("Teleport.tpaccept"), I18n.p("Teleport.tpdeny") });
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,11 @@
|
||||
package cn.citycraft.SimpleEssential.command;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||
import cn.citycraft.SimpleEssential.SimpleEssential;
|
||||
|
||||
/**
|
||||
@ -18,33 +20,15 @@ public class CommandWorkBench extends BaseCommand {
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandWorkBench(SimpleEssential main) {
|
||||
public CommandWorkBench(final SimpleEssential main) {
|
||||
super("workbench", "seworkbench", "wb", "sewb");
|
||||
this.plugin = main;
|
||||
setOnlyPlayerExecutable();
|
||||
setDescription("随身工作台");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
Bukkit.getPlayer(sender.getName()).openWorkbench(null, true);
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "随身工作台";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPossibleArguments() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyPlayerExecutable() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,14 @@
|
||||
package cn.citycraft.SimpleEssential.command;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||
import cn.citycraft.SimpleEssential.SimpleEssential;
|
||||
import cn.citycraft.SimpleEssential.config.I18n;
|
||||
|
||||
@ -21,45 +24,31 @@ public class CommandWorld extends BaseCommand {
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandWorld(SimpleEssential main) {
|
||||
public CommandWorld(final SimpleEssential main) {
|
||||
super("world", "seworld");
|
||||
this.plugin = main;
|
||||
setPossibleArguments("[世界名称|世界序号]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
Player p = (Player) sender;
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
p.sendMessage(I18n.p("World.title"));
|
||||
for (World wd : Bukkit.getWorlds())
|
||||
p.sendMessage(I18n.p("World.info", wd.getName(), wd.getEnvironment().toString(), wd.getLoadedChunks().length, wd.getEntities().size(), wd.getPlayers().size()));
|
||||
sender.sendMessage(I18n.p("World.title"));
|
||||
for (final World wd : Bukkit.getWorlds()) {
|
||||
sender.sendMessage(I18n.p("World.info", wd.getName(), wd.getEnvironment().toString(), wd.getLoadedChunks().length, wd.getEntities().size(), wd.getPlayers().size()));
|
||||
}
|
||||
case 1:
|
||||
World wd = Bukkit.getWorld(args[1]);
|
||||
if (wd != null)
|
||||
p.teleport(wd.getSpawnLocation());
|
||||
else
|
||||
p.sendMessage(I18n.p("World.unknow", args[1]));
|
||||
final World wd = Bukkit.getWorld(args[1]);
|
||||
if (wd != null) {
|
||||
if (sender instanceof Player) {
|
||||
((Player) sender).teleport(wd.getSpawnLocation());
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + I18n.p("Base.playercommand"));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(I18n.p("World.unknow", args[1]));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPossibleArguments() {
|
||||
return "[世界名称|世界序号]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyPlayerExecutable() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -5,18 +5,18 @@ import org.bukkit.plugin.Plugin;
|
||||
import cn.citycraft.PluginHelper.config.FileConfig;
|
||||
|
||||
public class I18n {
|
||||
private static String CONFIG_NAME = "language.yml";
|
||||
private static FileConfig config;
|
||||
private static String CONFIG_NAME = "language.yml";
|
||||
|
||||
public static void load(Plugin p) {
|
||||
public static void load(final Plugin p) {
|
||||
config = new FileConfig(p, CONFIG_NAME);
|
||||
}
|
||||
|
||||
public static String p(String path, Object... args) {
|
||||
return String.format(p(path), args);
|
||||
}
|
||||
|
||||
public static String p(String path) {
|
||||
public static String p(final String path) {
|
||||
return config.getMessage(path);
|
||||
}
|
||||
|
||||
public static String p(final String path, final Object... args) {
|
||||
return String.format(p(path), args);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
package cn.citycraft.SimpleEssential.listen;
|
||||
|
||||
@ -14,22 +14,22 @@ import cn.citycraft.SimpleEssential.SimpleEssential;
|
||||
|
||||
/**
|
||||
* 玩家传送点记录监听
|
||||
*
|
||||
*
|
||||
* @author 蒋天蓓
|
||||
* 2015年8月12日下午8:19:33
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class PlayerLocationListen implements Listener {
|
||||
SimpleEssential plugin;
|
||||
|
||||
public PlayerLocationListen(SimpleEssential main) {
|
||||
public PlayerLocationListen(final SimpleEssential main) {
|
||||
this.plugin = main;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||
Player player = e.getEntity();
|
||||
Location loc = player.getLocation();
|
||||
public void onPlayerDeath(final PlayerDeathEvent e) {
|
||||
final Player player = e.getEntity();
|
||||
final Location loc = player.getLocation();
|
||||
plugin.tpcontrol.setLastloc(player, loc);
|
||||
}
|
||||
}
|
||||
|
@ -21,14 +21,14 @@ import cn.citycraft.SimpleEssential.utils.EffectUtil;
|
||||
* @author 蒋天蓓 2015年8月12日下午2:26:10 传送控制类
|
||||
*/
|
||||
public class TeleportControl {
|
||||
protected HashMap<Player, TeleportInfo> teleportList = new HashMap<Player, TeleportInfo>();
|
||||
protected HashMap<Player, Location> lastlocList = new HashMap<Player, Location>();
|
||||
private SimpleEssential plugin;
|
||||
|
||||
private int TpDelay = 0;
|
||||
private final SimpleEssential plugin;
|
||||
private String TpControlName = "";
|
||||
private int TpDelay = 0;
|
||||
|
||||
public TeleportControl(SimpleEssential plugin, String tpcontrolname, int tpdelay) {
|
||||
protected HashMap<Player, Location> lastlocList = new HashMap<Player, Location>();
|
||||
protected HashMap<Player, TeleportInfo> teleportList = new HashMap<Player, TeleportInfo>();
|
||||
|
||||
public TeleportControl(final SimpleEssential plugin, final String tpcontrolname, final int tpdelay) {
|
||||
this.plugin = plugin;
|
||||
this.TpDelay = tpdelay;
|
||||
this.TpControlName = tpcontrolname;
|
||||
@ -40,8 +40,8 @@ public class TeleportControl {
|
||||
* @param player
|
||||
* - 执行的玩家
|
||||
*/
|
||||
public void accept(Player player) {
|
||||
TeleportInfo ti = teleportList.remove(player);
|
||||
public void accept(final Player player) {
|
||||
final TeleportInfo ti = teleportList.remove(player);
|
||||
if (ti != null) {
|
||||
Player target = ti.getTarget();
|
||||
Location loc = null;
|
||||
@ -74,7 +74,7 @@ public class TeleportControl {
|
||||
* @param tptype
|
||||
* - 传送类型
|
||||
*/
|
||||
public void addtp(Player player, Player target, TeleportType tptype) {
|
||||
public void addtp(final Player player, final Player target, final TeleportType tptype) {
|
||||
teleportList.put(target, new TeleportInfo(player, tptype));
|
||||
}
|
||||
|
||||
@ -84,12 +84,13 @@ public class TeleportControl {
|
||||
* @param player
|
||||
* - 被传送的玩家
|
||||
*/
|
||||
public void back(Player player) {
|
||||
Location loc = lastlocList.get(player);
|
||||
if (loc != null)
|
||||
public void back(final Player player) {
|
||||
final Location loc = lastlocList.get(player);
|
||||
if (loc != null) {
|
||||
magicTeleport(player, loc, 3);
|
||||
else
|
||||
} else {
|
||||
player.sendMessage(TpControlName + I18n.p("Teleport.nobackloc"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -98,10 +99,10 @@ public class TeleportControl {
|
||||
* @param player
|
||||
* - 执行的玩家
|
||||
*/
|
||||
public void deny(Player player) {
|
||||
TeleportInfo ti = teleportList.remove(player);
|
||||
public void deny(final Player player) {
|
||||
final TeleportInfo ti = teleportList.remove(player);
|
||||
if (ti != null) {
|
||||
Player target = ti.getTarget();
|
||||
final Player target = ti.getTarget();
|
||||
if (target.isOnline()) {
|
||||
player.sendMessage(TpControlName + I18n.p("Teleport.deny", target.getDisplayName()));
|
||||
target.sendMessage(TpControlName + I18n.p("Teleport.denyfrom", player.getDisplayName()));
|
||||
@ -134,34 +135,39 @@ public class TeleportControl {
|
||||
* - 传送延时
|
||||
*/
|
||||
public void magicTeleport(final Player player, final Location loc, final int delay) {
|
||||
int petime = delay * 20 + 10;
|
||||
final int petime = delay * 20 + 10;
|
||||
setLastloc(player, player.getLocation());
|
||||
player.sendMessage(TpControlName + I18n.p("Teleport.tp", delay, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockZ()));
|
||||
List<PotionEffect> pe = new ArrayList<PotionEffect>();
|
||||
final List<PotionEffect> pe = new ArrayList<PotionEffect>();
|
||||
pe.add(new PotionEffect(PotionEffectType.SLOW, petime, 255));
|
||||
pe.add(new PotionEffect(PotionEffectType.CONFUSION, petime, 255));
|
||||
player.addPotionEffects(pe);
|
||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
long timeoutmark = System.currentTimeMillis() + delay * 1000;
|
||||
long lrng = 0;
|
||||
long timeoutmark = System.currentTimeMillis() + delay * 1000;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (System.currentTimeMillis() < timeoutmark) {
|
||||
if (player.isOnline())
|
||||
if (player.isOnline()) {
|
||||
EffectUtil.run(player.getLocation(), lrng, Effect.MOBSPAWNER_FLAMES, Effect.PORTAL);
|
||||
}
|
||||
lrng++;
|
||||
try {
|
||||
Thread.sleep(128);
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
plugin.getServer().getScheduler().runTaskLater(plugin, () -> {
|
||||
if (player.isOnline())
|
||||
player.teleport(loc);
|
||||
} , delay * 20);
|
||||
plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (player.isOnline()) {
|
||||
player.teleport(loc);
|
||||
}
|
||||
}
|
||||
}, delay * 20);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -172,7 +178,7 @@ public class TeleportControl {
|
||||
* @param loc
|
||||
* - 地点
|
||||
*/
|
||||
public void setLastloc(Player player, Location loc) {
|
||||
public void setLastloc(final Player player, final Location loc) {
|
||||
lastlocList.put(player, loc);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
package cn.citycraft.SimpleEssential.teleport;
|
||||
|
||||
@ -7,25 +7,25 @@ import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* 玩家传送记录
|
||||
*
|
||||
*
|
||||
* @author 蒋天蓓
|
||||
* 2015年8月12日下午2:56:25
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class TeleportInfo {
|
||||
protected TeleportType tptype;
|
||||
protected Player target;
|
||||
protected TeleportType tptype;
|
||||
|
||||
public TeleportInfo(Player target, TeleportType tptype) {
|
||||
public TeleportInfo(final Player target, final TeleportType tptype) {
|
||||
this.target = target;
|
||||
this.tptype = tptype;
|
||||
}
|
||||
|
||||
public TeleportType getTptype() {
|
||||
return tptype;
|
||||
}
|
||||
|
||||
public Player getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public TeleportType getTptype() {
|
||||
return tptype;
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,16 @@
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
package cn.citycraft.SimpleEssential.teleport;
|
||||
|
||||
/**
|
||||
* 传送类型枚举
|
||||
*
|
||||
*
|
||||
* @author 蒋天蓓
|
||||
* 2015年8月12日下午2:56:59
|
||||
*
|
||||
*
|
||||
*/
|
||||
public enum TeleportType {
|
||||
TPA, TPH
|
||||
TPA,
|
||||
TPH
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
package cn.citycraft.SimpleEssential.utils;
|
||||
|
||||
@ -8,16 +8,16 @@ import org.bukkit.Location;
|
||||
|
||||
/**
|
||||
* 粒子发生器
|
||||
*
|
||||
*
|
||||
* @author 蒋天蓓
|
||||
* 2015年8月14日下午2:07:02
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class EffectUtil {
|
||||
|
||||
/**
|
||||
* 粒子发生器
|
||||
*
|
||||
*
|
||||
* @param loc
|
||||
* - 粒子产生地点
|
||||
* @param range
|
||||
@ -25,18 +25,18 @@ public class EffectUtil {
|
||||
* @param effects
|
||||
* - 粒子类型
|
||||
*/
|
||||
public static void run(Location loc, long range, Effect... effects) {
|
||||
public static void run(final Location loc, long range, final Effect... effects) {
|
||||
try {
|
||||
int i;
|
||||
if (range < 2) {
|
||||
range = 2;
|
||||
}
|
||||
for (i = 0; i < range; i++) {
|
||||
for (Effect effect : effects) {
|
||||
for (final Effect effect : effects) {
|
||||
loc.getWorld().playEffect(loc, effect, 10, 100);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ Gc:
|
||||
runTime: '§6运行时间: §a%s'
|
||||
Processors: '§6CPU 核心: §a%s'
|
||||
maxMem: '§6最大内存: §a%s'
|
||||
totalMem: '§6已用内存: §a%s'
|
||||
totalMem: '§6分配内存: §a%s'
|
||||
freeMem: '§6空闲内存: §a%s'
|
||||
World:
|
||||
title: '§6当前服务器的启用的世界如下'
|
||||
|
Loading…
Reference in New Issue
Block a user