add Language file and Complete Teleport System...

Signed-off-by: j502647092 <jtb1@163.com>
pull/1/HEAD
j502647092 2015-08-14 13:50:24 +08:00
parent 60bc20b7f0
commit b9edf12f09
10 changed files with 136 additions and 31 deletions

View File

@ -23,6 +23,7 @@ import cn.citycraft.SimpleEssential.command.CommandTpdeny;
import cn.citycraft.SimpleEssential.command.CommandTphere;
import cn.citycraft.SimpleEssential.command.SimpleEssentialCommand;
import cn.citycraft.SimpleEssential.config.Config;
import cn.citycraft.SimpleEssential.config.Language;
import cn.citycraft.SimpleEssential.listen.PlayerLocationListen;
import cn.citycraft.SimpleEssential.teleport.TeleportControl;
import cn.citycraft.SimpleEssential.utils.VersionChecker;
@ -84,6 +85,7 @@ public class SimpleEssential extends JavaPlugin {
@Override
public void onLoad() {
Config.load(this, "1.0");
Language.load(this, "1.0");
}
/**

View File

@ -9,6 +9,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import cn.citycraft.SimpleEssential.SimpleEssential;
import cn.citycraft.SimpleEssential.config.Language;
/**
* @author 20158122:04:05 TODO
@ -29,7 +30,7 @@ public class CommandHome extends SimpleEssentialCommand {
Player p = (Player) sender;
Location loc = p.getBedSpawnLocation();
if (loc == null) {
p.sendMessage("§c你的床丢失了或者被方块阻挡了!");
p.sendMessage(Language.getMessage("Teleport.homelose"));
return;
}
plugin.tpcontrol.magicTeleport(p, loc);

View File

@ -10,6 +10,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import cn.citycraft.SimpleEssential.SimpleEssential;
import cn.citycraft.SimpleEssential.config.Language;
/**
* @author 20158122:04:05 TODO
@ -31,9 +32,9 @@ public class CommandSetHome extends SimpleEssentialCommand {
Block b = p.getLocation().getBlock();
if (b.getType() == Material.BED_BLOCK) {
p.setBedSpawnLocation(b.getLocation(), true);
p.sendMessage("§a家设置成功!");
p.sendMessage(Language.getMessage("Teleport.sethomesuccess"));
} else {
p.sendMessage("§c请站在床上设置家!");
p.sendMessage(Language.getMessage("Teleport.sethomeerror"));
}
}

View File

@ -9,6 +9,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import cn.citycraft.SimpleEssential.SimpleEssential;
import cn.citycraft.SimpleEssential.config.Language;
/**
* @author
@ -43,6 +44,6 @@ public class CommandTop extends SimpleEssentialCommand {
int top = loc.getWorld().getHighestBlockYAt(loc);
loc.setY(top);
p.teleport(loc);
p.sendMessage("&a已传送至当前位置最高方块!");
p.sendMessage(Language.getMessage("Teleport.top"));
}
}

View File

@ -9,6 +9,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import cn.citycraft.SimpleEssential.SimpleEssential;
import cn.citycraft.SimpleEssential.config.Language;
import cn.citycraft.SimpleEssential.teleport.TeleportType;
/**
@ -41,15 +42,15 @@ public class CommandTpa extends SimpleEssentialCommand {
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
Player target = Bukkit.getPlayer(args[0]);
if (target == null) {
sender.sendMessage("§c玩家 " + args[0] + " 不存在或不在线!");
sender.sendMessage(Language.getMessage("Base.offline", args[0]));
return;
}
plugin.tpcontrol.addtp((Player) sender, Bukkit.getPlayer(args[0]), TeleportType.TPA);
sender.sendMessage("§a已经向玩家 " + target.getDisplayName() + " §a发送传送请求!");
sender.sendMessage(Language.getMessage("Teleport.tpsend"));
target.sendMessage(new String[] {
"§a玩家: " + sender.getName() + "§a请求传送到你这里!",
"§a输入命令/tpaccept 或 /tpok 接受传送",
"§c输入命令/tpdeny 或 /tpno 拒绝传送"
Language.getMessage("Teleport.tpa", sender.getName()),
Language.getMessage("Teleport.tpaccept"),
Language.getMessage("Teleport.tpdeny")
});
}
}

View File

@ -9,6 +9,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import cn.citycraft.SimpleEssential.SimpleEssential;
import cn.citycraft.SimpleEssential.config.Language;
import cn.citycraft.SimpleEssential.teleport.TeleportType;
/**
@ -26,15 +27,15 @@ public class CommandTphere extends SimpleEssentialCommand {
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
Player target = Bukkit.getPlayer(args[0]);
if (target == null) {
sender.sendMessage("§c玩家 " + args[0] + " 不存在或不在线!");
sender.sendMessage(Language.getMessage("Base.offline", args[0]));
return;
}
plugin.tpcontrol.addtp((Player) sender, Bukkit.getPlayer(args[0]), TeleportType.TPH);
sender.sendMessage("§a已经向玩家 " + target.getDisplayName() + " §a发送传送请求!");
sender.sendMessage(Language.getMessage("Teleport.tpsend"));
target.sendMessage(new String[] {
"§b玩家: " + sender.getName() + "§b请求你传送到他那里!",
"§a输入命令/tpaccept 或 /tpok 接受传送",
"§c输入命令/tpdeny 或 /tpno 拒绝传送"
Language.getMessage("Teleport.tphere", sender.getName()),
Language.getMessage("Teleport.tpaccept"),
Language.getMessage("Teleport.tpdeny")
});
}

View File

@ -0,0 +1,65 @@
package cn.citycraft.SimpleEssential.config;
import java.io.File;
import java.io.IOException;
import org.bukkit.plugin.Plugin;
public class Language extends ConfigLoader {
private static String CONFIG_NAME = "language.yml";
private static FileConfig instance;
private static File file;
public Language(Plugin p) {
super(p, CONFIG_NAME);
file = new File(p.getDataFolder(), CONFIG_NAME);
instance = super.getInstance();
}
public Language(Plugin p, String ver) {
super(p, CONFIG_NAME, ver);
instance = super.getInstance();
}
public static void load(Plugin p) {
new Language(p);
}
public static void load(Plugin p, String ver) {
new Language(p, ver);
}
public static FileConfig getInstance() {
return instance;
}
public static String getMessage(String path, Object... paramVarArgs) {
String message = instance.getString(path);
try {
if (message != null)
message = String.format(message.replaceAll("&", "§"), paramVarArgs);
} catch (Exception e) {
}
return message;
}
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();
}
}
}

View File

@ -15,6 +15,7 @@ import org.bukkit.potion.PotionEffectType;
import cn.citycraft.SimpleEssential.SimpleEssential;
import cn.citycraft.SimpleEssential.config.Config;
import cn.citycraft.SimpleEssential.config.Language;
/**
* @author 20158122:26:10
@ -29,13 +30,16 @@ public class TeleportControl {
* -
*/
static void pEffect(Location loc, long range) {
int i;
if (range < 2) {
range = 2;
}
for (i = 0; i < range; i++) {
loc.getWorld().playEffect(loc, Effect.LAVA_POP, 10, 100);
loc.getWorld().playEffect(loc, Effect.PORTAL, 10, 100);
try {
int i;
if (range < 2) {
range = 2;
}
for (i = 0; i < range; i++) {
loc.getWorld().playEffect(loc, Effect.LAVA_POP, 10, 100);
loc.getWorld().playEffect(loc, Effect.PORTAL, 10, 100);
}
} catch (Exception e) {
}
}
@ -47,6 +51,7 @@ public class TeleportControl {
public TeleportControl(SimpleEssential plugin) {
this.plugin = plugin;
}
/**
@ -61,10 +66,9 @@ public class TeleportControl {
Player target = ti.getTarget();
Location loc = null;
if (!target.isOnline()) {
player.sendMessage("§c目标玩家已离线 传送失败!");
player.sendMessage(Language.getMessage("Teleport.offline"));
return;
}
target.sendMessage("§a玩家: " + player.getDisplayName() + "§a受了您的请求!");
if (ti.getTptype() == TeleportType.TPA) {
target = ti.getTarget();
loc = player.getLocation();
@ -72,10 +76,12 @@ public class TeleportControl {
target = player;
loc = ti.getTarget().getLocation();
}
player.sendMessage(Language.getMessage("Teleport.accept"));
target.sendMessage(Language.getMessage("Teleport.acceptfrom"));
magicTeleport(target, loc, TpDelay);
return;
}
player.sendMessage("§c未找到需要处理的队列!");
player.sendMessage(Language.getMessage("Teleport.none"));
}
/**
@ -103,7 +109,7 @@ public class TeleportControl {
if (loc != null) {
magicTeleport(player, loc, 3);
} else {
player.sendMessage("§c未找到可以Back的地点!");
player.sendMessage(Language.getMessage("Teleport.nobackloc"));
}
}
@ -116,14 +122,14 @@ public class TeleportControl {
public void deny(Player player) {
TeleportInfo ti = teleportList.remove(player);
if (ti != null) {
player.sendMessage("§c已拒绝玩家的传送请求!");
Player target = ti.getTarget();
if (target.isOnline()) {
target.sendMessage("§c玩家: " + player.getDisplayName() + "§c拒绝了您的请求!");
player.sendMessage(Language.getMessage("Teleport.deny"));
target.sendMessage(Language.getMessage("Teleport.denyfrom"));
}
return;
}
player.sendMessage("§c未找到需要处理的队列!");
player.sendMessage(Language.getMessage("Teleport.none"));
}
/**
@ -151,8 +157,7 @@ public class TeleportControl {
public void magicTeleport(final Player player, final Location loc, final int delay) {
int petime = delay * 20 + 10;
setLastloc(player, player.getLocation());
player.sendMessage("§a传送开始 " + delay + "秒 后到达目的地 §d世界: " + loc.getWorld().getName()
+ " §3X: " + loc.getBlockX() + " Z: " + loc.getBlockZ() + "!");
player.sendMessage(Language.getMessage("Teleport.tp", delay, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockZ()));
List<PotionEffect> pe = new ArrayList<PotionEffect>();
pe.add(new PotionEffect(PotionEffectType.SLOW, petime, 255));
pe.add(new PotionEffect(PotionEffectType.CONFUSION, petime, 255));

View File

@ -3,9 +3,10 @@ version: 1.0
#服务器名称
servername: ''
#插件名称
pluginname: '&6[&b保护系统&6]&r'
pluginname: '&6[&b基础系统&6]&r'
#基础传送系统
Teleport:
name: '&6[&b传送系统&6]&r'
#所有传送延时
delay: 3

27
src/language.yml Normal file
View File

@ -0,0 +1,27 @@
#本文件为基础插件的语言配置文件
version: 1.0
#基础语言配置
Base:
offline: "§c玩家 {0} 不存在或不在线!"
#基础传送系统
Teleport:
tp: '§a传送开始 {0}秒 后到达 目的地 §d世界: {1} §3X: {2} Z: {3}!'
accept: '§a已接受玩家: {0} §a的传送请求!'
acceptfrom: '§a玩家: {0}§a接受了您的请求!'
deny: '§c已拒绝玩家: {0} §c的传送请求!'
denyfrom: '§c玩家: {0}§c拒绝了您的请求!'
offline: '§c目标玩家已离线 本次传送取消!'
none: '§c没有找到需要传送的队列!'
sethomesuccess: '§a家设置成功!'
sethomeerror: '§c请站在床上设置家!'
homelose: '§c你的床丢失了或者被方块阻挡了!'
top: '&a已传送至当前位置最高方块!'
tpsend: '§a已经向玩家 {0} §a发送传送请求!'
tpa: '§a玩家: {0}§a请求传送到你这里!'
tphere: '§b玩家: {0}§b请求你传送到他那里!'
tpaccept: '§a输入命令/tpaccept 或 /tpok 接受传送'
tpdeny: '§c输入命令/tpdeny 或 /tpno 拒绝传送'
nobackloc: '§c未找到可以Back的地点!'
Language.getMessage("Teleport.none")