Permalink
Browse files

1st commit

1.5.2_1
Bukkit 1.5.2-R1.0
  • Loading branch information...
hide92795 committed Jun 28, 2013
0 parents commit b019a6ca9ccf93b483843f569fe65f8ad9a70bfd
Binary file not shown.
@@ -0,0 +1 @@
Language: jp
@@ -0,0 +1,19 @@
package hide92795.bukkit.plugin.vanishplayer;
import hide92795.bukkit.plugin.corelib.Localizable;
public enum Type implements Localizable {
VANISH("Vanish"), ALREADY_VANISHED("AlreadyVanished"), UNVANISH("Unvanish"), ALREADY_UNVANISHED("AlreadyUnvanished"), NO_VANISHED_PLAYER(
"NoVanishedPlayer"), VANISHED_PLAYER("VanishedPlayer"), RELOADED_SETTING("ReloadedSetting"), ERROR_RELOAD_SETTING(
"ErrorReloadSetting");
private final String type;
private Type(String type) {
this.type = type;
}
@Override
public String getName() {
return type;
}
}
@@ -0,0 +1,155 @@
package hide92795.bukkit.plugin.vanishplayer;
import hide92795.bukkit.plugin.corelib.Localize;
import hide92795.bukkit.plugin.vanishplayer.listener.PlayerLoginListener;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.dynmap.DynmapAPI;
public class VanishPlayer extends JavaPlugin {
public List<String> invisible;
private boolean enable_dynmap;
private DynmapAPI dynmap;
private Logger logger;
private Localize localize;
public void onEnable() {
getConfig().options().copyDefaults(true);
saveConfig();
reloadConfig();
logger = getLogger();
invisible = new ArrayList<String>();
localize = new Localize(this);
try {
reload();
} catch (Exception e1) {
logger.severe("Error has occured on loading config.");
}
getServer().getPluginManager().registerEvents(new PlayerLoginListener(this), this);
// Hook into dynmap
if (getServer().getPluginManager().isPluginEnabled("dynmap")) {
dynmap = (DynmapAPI) getServer().getPluginManager().getPlugin("dynmap");
getLogger().info("Hook into dynmap");
enable_dynmap = true;
}
}
@Override
public void onDisable() {
if (enable_dynmap) {
for (String player : invisible) {
dynmap.setPlayerVisiblity(player, true);
}
}
}
private void reload() throws Exception {
reloadConfig();
try {
localize.reload(getConfig().getString("Language"));
} catch (Exception e1) {
logger.severe("Can't load language file.");
try {
localize.reload("jp");
logger.severe("Loaded default language file.");
} catch (Exception e) {
throw e;
}
}
}
public void vanish(Player player) {
for (Player other : getServer().getOnlinePlayers()) {
if (!other.hasPermission("vanishplayer.showvanished")) {
other.hidePlayer(player);
}
}
if (enable_dynmap) {
dynmap.setPlayerVisiblity(player, false);
}
player.sendMessage(localize.getString(Type.VANISH));
}
public void unvanish(Player player) {
if (invisible.remove(player.getName())) {
for (Player other : getServer().getOnlinePlayers()) {
other.showPlayer(player);
}
if (enable_dynmap) {
dynmap.setPlayerVisiblity(player, true);
}
player.sendMessage(localize.getString(Type.UNVANISH));
} else {
player.sendMessage(localize.getString(Type.ALREADY_UNVANISHED));
}
}
public void showVanishList(CommandSender sender) {
String result = "";
boolean first = true;
for (String hidden : invisible) {
if (getServer().getPlayerExact(hidden) == null)
continue;
if (first) {
result += hidden;
first = false;
continue;
}
result += ", " + hidden;
}
if (result.length() == 0) {
sender.sendMessage(localize.getString(Type.NO_VANISHED_PLAYER));
} else {
sender.sendMessage(String.format(localize.getString(Type.VANISHED_PLAYER), result));
}
}
public boolean onCommand(CommandSender sender, Command command, String name, String[] args) {
if (command.getName().equalsIgnoreCase("vanish")) {
if (sender instanceof Player) {
// Player
Player player = (Player) sender;
if (invisible.contains(player.getName())) {
player.sendMessage(localize.getString(Type.ALREADY_VANISHED));
} else {
invisible.add(player.getName());
vanish(player);
}
} else {
// Console
sender.sendMessage("This command is only for player.");
}
} else if (command.getName().equalsIgnoreCase("unvanish")) {
if (sender instanceof Player) {
// Player
unvanish((Player) sender);
} else {
// Console
sender.sendMessage("This command is only for player.");
}
} else if (command.getName().equalsIgnoreCase("vanish-reload")) {
try {
reload();
sender.sendMessage(localize.getString(Type.RELOADED_SETTING));
logger.info("Reloaded successfully.");
} catch (Exception e) {
sender.sendMessage(localize.getString(Type.ERROR_RELOAD_SETTING));
logger.info("An error has occured on reloading config.");
}
} else if (command.getName().equalsIgnoreCase("vanish-list")) {
showVanishList(sender);
}
return true;
}
}
@@ -0,0 +1,30 @@
package hide92795.bukkit.plugin.vanishplayer.listener;
import hide92795.bukkit.plugin.vanishplayer.VanishPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class PlayerLoginListener implements Listener {
public VanishPlayer plugin;
public PlayerLoginListener(VanishPlayer plugin) {
this.plugin = plugin;
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
// 権限持ち以外のプレイヤーには現在透明化しているプレイヤーを透明化する。
Player player = event.getPlayer();
if (player.hasPermission("vanishplayer.showvanished") || player.isOp())
return;
for (String hidden : plugin.invisible) {
Player hiddenPlayer = plugin.getServer().getPlayerExact(hidden);
if (hiddenPlayer != null) {
player.hidePlayer(hiddenPlayer);
}
}
}
}
@@ -0,0 +1,8 @@
Vanish: "&c透明化しました。"
AlreadyVanished: "&c既に透明化しています。"
Unvanish: "&c透明化を解除しました。"
AlreadyUnvanished: "&c既に解除されています。"
NoVanishedPlayer: "&c透明化しているプレイヤーはいません。"
VanishedPlayer: "&c透明化しているプレイヤー: %1$s"
ReloadedSetting: "&6設定をリロードしました。"
ErrorReloadSetting: "&cリロード中にエラーが発生しました。"
@@ -0,0 +1,17 @@
name: VanishPlayer
main: hide92795.bukkit.plugin.vanishplayer.VanishPlayer
version: 1.5.2_1
description: Vanish player
author: hide92795
depend: [hide92795CoreLib]
softdepend: [dynmap]
commands:
vanish-reload:
permission: vanishplayer.reload
vanish-list:
permission: vanishplayer.list
vanish:
permission: vanishplayer.vanish
unvanish:
permission: vanishplayer.unvanish

0 comments on commit b019a6c

Please sign in to comment.