+ /suicide command with a not working death message
+ Buggy /hat
+ A function to register controllers likes register events and commands
* Moved command utility to a single package cn.citycraft/SimpleEssential/command/utils

! Sometimes language file dosn't working and I don't know what happened
! Hat cannot judge is a air on hand... I tried to if but not working!
! Death message for suicide is not working!

# I know that's all my fault and please fix them!
# Symbols: + Add - Remove x Fixed ! Bug # Description * Change
# Wish you know!
pull/1/HEAD
代小呆 2015-08-16 14:19:11 +08:00
parent 1c529d697c
commit 1ff9008275
11 changed files with 420 additions and 274 deletions

View File

@ -1,7 +1,8 @@
package cn.citycraft.SimpleEssential;
/**
*
*/
package cn.citycraft.SimpleEssential;
import java.util.ArrayList;
import java.util.List;
@ -14,18 +15,20 @@ import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.SimpleEssential.command.CommandBack;
import cn.citycraft.SimpleEssential.command.CommandHat;
import cn.citycraft.SimpleEssential.command.CommandHome;
import cn.citycraft.SimpleEssential.command.CommandSetHome;
import cn.citycraft.SimpleEssential.command.CommandSuicide;
import cn.citycraft.SimpleEssential.command.CommandTop;
import cn.citycraft.SimpleEssential.command.CommandTpa;
import cn.citycraft.SimpleEssential.command.CommandTpaccept;
import cn.citycraft.SimpleEssential.command.CommandTpdeny;
import cn.citycraft.SimpleEssential.command.CommandTphere;
import cn.citycraft.SimpleEssential.command.SimpleEssentialCommand;
import cn.citycraft.SimpleEssential.command.utils.teleport.TeleportControl;
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.listeners.TeleportDeathBackListener;
import cn.citycraft.SimpleEssential.utils.VersionChecker;
/**
@ -36,7 +39,7 @@ import cn.citycraft.SimpleEssential.utils.VersionChecker;
public class SimpleEssential extends JavaPlugin {
/**
*
*
*/
public TeleportControl tpcontrol;
/**
@ -75,9 +78,9 @@ public class SimpleEssential extends JavaPlugin {
@Override
public void onEnable() {
tpcontrol = new TeleportControl(this);
this.registerCommands();
this.registerEvents();
this.registerControllers();
new VersionChecker(this);
}
@ -85,7 +88,13 @@ public class SimpleEssential extends JavaPlugin {
*
*/
private void registerEvents() {
registerEvent(new PlayerLocationListen(this));
registerEvent(new TeleportDeathBackListener(this));
}
/**
*
*/
private void registerControllers(){
tpcontrol = new TeleportControl(this);
}
@Override
@ -107,7 +116,9 @@ public class SimpleEssential extends JavaPlugin {
registerCommand(new CommandBack(this));
registerCommand(new CommandSetHome(this));
registerCommand(new CommandHome(this));
registerCommand(new CommandSuicide(this));
registerCommand(new CommandHat(this));
}
/**

View File

@ -0,0 +1,60 @@
package cn.citycraft.SimpleEssential.command;
import org.bukkit.Material;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import cn.citycraft.SimpleEssential.SimpleEssential;
import cn.citycraft.SimpleEssential.config.Language;
/**
*@Author created in 20158161:44:22
*/
public class CommandHat extends SimpleEssentialCommand{
@SuppressWarnings("unused")
private SimpleEssential plugin;
public CommandHat(SimpleEssential se) {
super("hat","sehat");
this.plugin = se;
}
@Override
public String getPossibleArguments() {
return "";
}
@Override
public int getMinimumArguments() {
return 0;
}
@Override
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
Player p = (Player)sender;
if(p.getItemInHand() == null){
sender.sendMessage(Language.getMessage("Hat.empty"));
return;
}else{
ItemStack hand = p.getItemInHand();
p.setItemInHand(null);
ItemStack helmet = p.getInventory().getHelmet();
if(!(helmet == null)){
p.getInventory().addItem(helmet);
}
p.getInventory().setHelmet(hand);
sender.sendMessage(Language.getMessage("Hat.enjoy"));
}
}
@Override
public boolean isOnlyPlayerExecutable() {
return true;
}
}

View File

@ -0,0 +1,61 @@
package cn.citycraft.SimpleEssential.command;
import java.util.Arrays;
import cn.citycraft.SimpleEssential.SimpleEssential;
import org.bukkit.Effect;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
//import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.event.entity.PlayerDeathEvent;
//import cn.citycraft.SimpleEssential.config.Language;
import cn.citycraft.SimpleEssential.utils.EffectUtil;
//import cn.citycraft.SimpleEssential.utils.Randomer;
/**
*
*@Author created in 20158144:24:19
*/
public class CommandSuicide extends SimpleEssentialCommand{
private SimpleEssential plugin;
public CommandSuicide(SimpleEssential main) {
super("suicide", new String[]{"sesuicide","sd"});
this.plugin = main;
}
@Override
public String getPossibleArguments() {
return "";
}
@Override
public int getMinimumArguments() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
Player p = (Player)sender;
EffectUtil.run(p.getLocation(), 10, Effect.POTION_BREAK);
PlayerDeathEvent pd = new PlayerDeathEvent(p,Arrays.asList(p.getInventory().getContents()),
(int) Math.floor(p.getExp()),p.getName() + "自杀了");
plugin.getServer().getPluginManager().callEvent(pd);
// plugin.getServer().broadcastMessage(Language.getMessage("Suicide.suicide",sender.getName()));
p.setHealth(0);
}
@Override
public boolean isOnlyPlayerExecutable() {
return true;
}
}

View File

@ -9,8 +9,8 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import cn.citycraft.SimpleEssential.SimpleEssential;
import cn.citycraft.SimpleEssential.command.utils.teleport.TeleportType;
import cn.citycraft.SimpleEssential.config.Language;
import cn.citycraft.SimpleEssential.teleport.TeleportType;
/**
*

View File

@ -9,8 +9,8 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import cn.citycraft.SimpleEssential.SimpleEssential;
import cn.citycraft.SimpleEssential.command.utils.teleport.TeleportType;
import cn.citycraft.SimpleEssential.config.Language;
import cn.citycraft.SimpleEssential.teleport.TeleportType;
/**
*

View File

@ -1,183 +1,183 @@
/**
*
*/
package cn.citycraft.SimpleEssential.teleport;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import cn.citycraft.SimpleEssential.SimpleEssential;
import cn.citycraft.SimpleEssential.config.Config;
import cn.citycraft.SimpleEssential.config.Language;
import cn.citycraft.SimpleEssential.utils.EffectUtil;
/**
* @author 20158122: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 = Config.getInstance().getInt("Teleport.delay", 3);
public TeleportControl(SimpleEssential plugin) {
this.plugin = plugin;
}
/**
*
*
* @param player
* -
*/
public void accept(Player player) {
TeleportInfo ti = teleportList.remove(player);
if (ti != null) {
Player target = ti.getTarget();
Location loc = null;
if (!target.isOnline()) {
player.sendMessage(Language.getMessage("Teleport.offline"));
return;
}
if (ti.getTptype() == TeleportType.TPA) {
target = ti.getTarget();
loc = player.getLocation();
} else {
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(Language.getMessage("Teleport.none"));
}
/**
*
*
* @param player
* -
* @param target
* -
* @param tptype
* -
*/
public void addtp(Player player, Player target, TeleportType tptype) {
teleportList.put(target, new TeleportInfo(player, tptype));
}
/**
*
*
* @param player
* -
*/
public void back(Player player) {
Location loc = lastlocList.get(player);
if (loc != null) {
magicTeleport(player, loc, 3);
} else {
player.sendMessage(Language.getMessage("Teleport.nobackloc"));
}
}
/**
*
*
* @param player
* -
*/
public void deny(Player player) {
TeleportInfo ti = teleportList.remove(player);
if (ti != null) {
Player target = ti.getTarget();
if (target.isOnline()) {
player.sendMessage(Language.getMessage("Teleport.deny"));
target.sendMessage(Language.getMessage("Teleport.denyfrom"));
}
return;
}
player.sendMessage(Language.getMessage("Teleport.none"));
}
/**
*
*
* @param player
* -
* @param loc
* -
*/
public void magicTeleport(final Player player, final Location loc) {
magicTeleport(player, loc, TpDelay);
}
/**
*
*
* @param player
* -
* @param loc
* -
* @param delay
* -
*/
public void magicTeleport(final Player player, final Location loc, final int delay) {
int petime = delay * 20 + 10;
setLastloc(player, player.getLocation());
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));
player.addPotionEffects(pe);
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
long timeoutmark = System.currentTimeMillis() + delay * 1000;
long lrng = 0;
@Override
public void run() {
while (System.currentTimeMillis() < timeoutmark) {
if (player.isOnline()) {
EffectUtil.run(player.getLocation(), lrng, Effect.MOBSPAWNER_FLAMES, Effect.PORTAL);
}
lrng++;
try {
Thread.sleep(128);
} catch (Exception e) {
}
}
}
});
plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
@Override
public void run() {
if (player.isOnline()) {
player.teleport(loc);
}
}
}, delay * 20);
}
/**
*
*
* @param player
* -
* @param loc
* -
*/
public void setLastloc(Player player, Location loc) {
lastlocList.put(player, loc);
}
}
/**
*
*/
package cn.citycraft.SimpleEssential.command.utils.teleport;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import cn.citycraft.SimpleEssential.SimpleEssential;
import cn.citycraft.SimpleEssential.config.Config;
import cn.citycraft.SimpleEssential.config.Language;
import cn.citycraft.SimpleEssential.utils.EffectUtil;
/**
* @author 20158122: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 = Config.getInstance().getInt("Teleport.delay", 3);
public TeleportControl(SimpleEssential plugin) {
this.plugin = plugin;
}
/**
*
*
* @param player
* -
*/
public void accept(Player player) {
TeleportInfo ti = teleportList.remove(player);
if (ti != null) {
Player target = ti.getTarget();
Location loc = null;
if (!target.isOnline()) {
player.sendMessage(Language.getMessage("Teleport.offline"));
return;
}
if (ti.getTptype() == TeleportType.TPA) {
target = ti.getTarget();
loc = player.getLocation();
} else {
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(Language.getMessage("Teleport.none"));
}
/**
*
*
* @param player
* -
* @param target
* -
* @param tptype
* -
*/
public void addtp(Player player, Player target, TeleportType tptype) {
teleportList.put(target, new TeleportInfo(player, tptype));
}
/**
*
*
* @param player
* -
*/
public void back(Player player) {
Location loc = lastlocList.get(player);
if (loc != null) {
magicTeleport(player, loc, 3);
} else {
player.sendMessage(Language.getMessage("Teleport.nobackloc"));
}
}
/**
*
*
* @param player
* -
*/
public void deny(Player player) {
TeleportInfo ti = teleportList.remove(player);
if (ti != null) {
Player target = ti.getTarget();
if (target.isOnline()) {
player.sendMessage(Language.getMessage("Teleport.deny"));
target.sendMessage(Language.getMessage("Teleport.denyfrom"));
}
return;
}
player.sendMessage(Language.getMessage("Teleport.none"));
}
/**
*
*
* @param player
* -
* @param loc
* -
*/
public void magicTeleport(final Player player, final Location loc) {
magicTeleport(player, loc, TpDelay);
}
/**
*
*
* @param player
* -
* @param loc
* -
* @param delay
* -
*/
public void magicTeleport(final Player player, final Location loc, final int delay) {
int petime = delay * 20 + 10;
setLastloc(player, player.getLocation());
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));
player.addPotionEffects(pe);
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
long timeoutmark = System.currentTimeMillis() + delay * 1000;
long lrng = 0;
@Override
public void run() {
while (System.currentTimeMillis() < timeoutmark) {
if (player.isOnline()) {
EffectUtil.run(player.getLocation(), lrng, Effect.MOBSPAWNER_FLAMES, Effect.PORTAL);
}
lrng++;
try {
Thread.sleep(128);
} catch (Exception e) {
}
}
}
});
plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
@Override
public void run() {
if (player.isOnline()) {
player.teleport(loc);
}
}
}, delay * 20);
}
/**
*
*
* @param player
* -
* @param loc
* -
*/
public void setLastloc(Player player, Location loc) {
lastlocList.put(player, loc);
}
}

View File

@ -1,31 +1,31 @@
/**
*
*/
package cn.citycraft.SimpleEssential.teleport;
import org.bukkit.entity.Player;
/**
*
*
* @author
* 20158122:56:25
*
*/
public class TeleportInfo {
protected TeleportType tptype;
protected Player target;
public TeleportInfo(Player target, TeleportType tptype) {
this.target = target;
this.tptype = tptype;
}
public TeleportType getTptype() {
return tptype;
}
public Player getTarget() {
return target;
}
}
/**
*
*/
package cn.citycraft.SimpleEssential.command.utils.teleport;
import org.bukkit.entity.Player;
/**
*
*
* @author
* 20158122:56:25
*
*/
public class TeleportInfo {
protected TeleportType tptype;
protected Player target;
public TeleportInfo(Player target, TeleportType tptype) {
this.target = target;
this.tptype = tptype;
}
public TeleportType getTptype() {
return tptype;
}
public Player getTarget() {
return target;
}
}

View File

@ -1,15 +1,15 @@
/**
*
*/
package cn.citycraft.SimpleEssential.teleport;
/**
*
*
* @author
* 20158122:56:59
*
*/
public enum TeleportType {
TPA, TPH
}
/**
*
*/
package cn.citycraft.SimpleEssential.command.utils.teleport;
/**
*
*
* @author
* 20158122:56:59
*
*/
public enum TeleportType {
TPA, TPH
}

View File

@ -1,35 +1,35 @@
/**
*
*/
package cn.citycraft.SimpleEssential.listen;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import cn.citycraft.SimpleEssential.SimpleEssential;
/**
*
*
* @author
* 20158128:19:33
*
*/
public class PlayerLocationListen implements Listener {
SimpleEssential plugin;
public PlayerLocationListen(SimpleEssential main) {
this.plugin = main;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerDeath(PlayerDeathEvent e) {
Player player = e.getEntity();
Location loc = player.getLocation();
plugin.tpcontrol.setLastloc(player, loc);
}
}
/**
*
*/
package cn.citycraft.SimpleEssential.listeners;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import cn.citycraft.SimpleEssential.SimpleEssential;
/**
*
*
* @author
* 20158128:19:33
*
*/
public class TeleportDeathBackListener implements Listener {
SimpleEssential plugin;
public TeleportDeathBackListener(SimpleEssential main) {
this.plugin = main;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerDeath(PlayerDeathEvent e) {
Player player = e.getEntity();
Location loc = player.getLocation();
plugin.tpcontrol.setLastloc(player, loc);
}
}

View File

@ -23,4 +23,11 @@ Teleport:
tphere: '§b玩家: %s§b请求你传送到他那里!'
tpaccept: '§a输入命令/tpaccept 或 /tpok 接受传送'
tpdeny: '§c输入命令/tpdeny 或 /tpno 拒绝传送'
nobackloc: '§c未找到可以Back的地点!'
nobackloc: '§c未找到可以Back的地点!'
#自杀
Suicide:
suicide: '玩家 %s 自刎了!'
#帽子
Hat:
empty: '§c看上去你手上什么都没有啊'
enjoy: '§2享受你的新帽子吧'

View File

@ -63,6 +63,12 @@ commands:
usage: §b使用/suicide结束自己的生命!
permission: se.suicide
permission-message: §c你没有 <permission> 的权限来执行此命令!
hat:
description: 戴上手中的物品到脑袋上
aliases: [sehat]
usage: §b使用/hat戴上一款亮闪闪的帽子
permission: se.hat
permission-message: §c你没有 <permission> 的权限来执行此命令!
permissions:
se.*:
description: 简单基础插件所有权限!
@ -81,4 +87,5 @@ permissions:
se.sethome: true
se.home: true
se.suicide: true
se.hat: true