Permalink
Browse files

1st commit v1.6.2_1

  • Loading branch information...
hide92795 committed Aug 5, 2013
0 parents commit cabf0695213825d0afda6df5ba7bc99d9609d161
Binary file not shown.
@@ -0,0 +1,6 @@
Blocks:
- 54
- 95
- 130
- 146
OnlyWarnPlayer: true
@@ -0,0 +1,84 @@
package hide92795.bukkit.plugin.chestrestrictions;
import hide92795.bukkit.plugin.chestrestrictions.listener.ChestListener;
import hide92795.bukkit.plugin.corelib.Localize;
import hide92795.bukkit.plugin.mcbansdetector.MCBansDetector;
import hide92795.bukkit.plugin.mcbansdetector.MCBansDetectorAPI;
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.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
public class ChestRestrictions extends JavaPlugin {
public List<?> blockList;
private Logger logger;
public Localize localize;
public boolean onlyWarnPlayer;
public MCBansDetectorAPI mcbansdetector;
@Override
public void onEnable() {
getConfig().options().copyDefaults(true);
saveConfig();
reloadConfig();
logger = getLogger();
localize = new Localize(this);
try {
reload();
} catch (Exception e1) {
logger.severe("Error has occured on loading config.");
}
PluginManager pm = this.getServer().getPluginManager();
pm.registerEvents(new ChestListener(this), this);
// hook MCBansDetector
try {
MCBansDetector mcbans = (MCBansDetector) pm.getPlugin("MCBansDetector");
mcbansdetector = mcbans.getAPI();
logger.info("Hook into MCBansDetector.");
} catch (Exception e) {
mcbansdetector = null;
}
}
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;
}
}
blockList = getConfig().getList("Blocks");
if (blockList == null) {
saveDefaultConfig();
blockList = new ArrayList<Object>();
}
onlyWarnPlayer = getConfig().getBoolean("OnlyWarnPlayer");
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (command.getName().toLowerCase()) {
case "chestrestrictions-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));
}
break;
default:
break;
}
return true;
}
}
@@ -0,0 +1,17 @@
package hide92795.bukkit.plugin.chestrestrictions;
import hide92795.bukkit.plugin.corelib.Localizable;
public enum Type implements Localizable {
RELOADED_SETTING("ReloadedSetting"), ERROR_RELOAD_SETTING("ErrorReloadSetting"), OPEN_CHEST("OpenChest");
private final String type;
private Type(String type) {
this.type = type;
}
@Override
public String getName() {
return type;
}
}
@@ -0,0 +1,42 @@
package hide92795.bukkit.plugin.chestrestrictions.listener;
import hide92795.bukkit.plugin.chestrestrictions.ChestRestrictions;
import hide92795.bukkit.plugin.chestrestrictions.Type;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
public class ChestListener implements Listener {
private ChestRestrictions plugin;
public ChestListener(ChestRestrictions chestRestrictions) {
this.plugin = chestRestrictions;
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
switch (event.getAction()) {
case LEFT_CLICK_BLOCK:
case RIGHT_CLICK_BLOCK:
Block b = event.getClickedBlock();
Player player = event.getPlayer();
if (plugin.onlyWarnPlayer && plugin.mcbansdetector != null) {
if (!plugin.mcbansdetector.isPlayerWarned(player)) {
break;
}
}
if (plugin.blockList.contains(b.getTypeId())) {
if (!player.hasPermission("chestrestrictions.open") && !player.isOp()) {
event.setCancelled(true);
player.sendMessage(plugin.localize.getString(Type.OPEN_CHEST));
}
}
break;
default:
break;
}
}
}
@@ -0,0 +1,3 @@
OpenChest: "&cこのチェストを開けることはできません。"
ReloadedSetting: "&6設定をリロードしました。"
ErrorReloadSetting: "&cリロード中にエラーが発生しました。"
@@ -0,0 +1,11 @@
name: ChestRestrictions
main: hide92795.bukkit.plugin.chestrestrictions.ChestRestrictions
version: 1.6.2_1
description: Add permission to open chest
author: hide92795
depend: [hide92795CoreLib]
softdepend: [MCBansDetector]
commands:
chestrestrictions-reload:
permission: chestrestrictions.reload

0 comments on commit cabf069

Please sign in to comment.