Permalink
Browse files

1st commit v1.6.2_1

  • Loading branch information...
hide92795 committed Aug 3, 2013
0 parents commit ed0b2b225929d980a1c1b841826e11a0e137d202
Binary file not shown.
@@ -0,0 +1 @@
Language: jp
@@ -0,0 +1,61 @@
package hide92795.bukkit.plugin.blockrestrictions;
import hide92795.bukkit.plugin.blockrestrictions.listener.BlockPlaceListener;
import hide92795.bukkit.plugin.blockrestrictions.listener.TNTListener;
import hide92795.bukkit.plugin.corelib.Localize;
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 BlockRestrictions extends JavaPlugin {
private final BlockPlaceListener blockPlaceListener = new BlockPlaceListener(this);
private final TNTListener tntListener = new TNTListener(this);
public Localize localize;
private Logger logger;
public void onEnable() {
getConfig().options().copyDefaults(true);
saveConfig();
reloadConfig();
logger = getLogger();
localize = new Localize(this);
PluginManager pm = getServer().getPluginManager();
pm.registerEvents(this.blockPlaceListener, this);
pm.registerEvents(this.tntListener, this);
logger.info("BlockRestrictions enabled!");
}
public boolean onCommand(CommandSender sender, Command command, String name, String[] args) {
switch (command.getName().toLowerCase()) {
case "blockrestrictions-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;
}
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;
}
}
}
}
@@ -0,0 +1,17 @@
package hide92795.bukkit.plugin.blockrestrictions;
import hide92795.bukkit.plugin.corelib.Localizable;
public enum Type implements Localizable {
RELOADED_SETTING("ReloadedSetting"), ERROR_RELOAD_SETTING("ErrorReloadSetting"), PLACE_BANED_BLOCK("PlaceBanedBlock"), DETONATE_TNT("DetonateTNT");
private final String type;
private Type(String type) {
this.type = type;
}
@Override
public String getName() {
return type;
}
}
@@ -0,0 +1,73 @@
package hide92795.bukkit.plugin.blockrestrictions.listener;
import hide92795.bukkit.plugin.blockrestrictions.BlockRestrictions;
import hide92795.bukkit.plugin.blockrestrictions.Type;
import java.util.logging.Logger;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
public class BlockPlaceListener implements Listener {
private BlockRestrictions plugin;
private Logger logger;
public BlockPlaceListener(BlockRestrictions instance) {
plugin = instance;
logger = plugin.getLogger();
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
if (plugin.isEnabled()) {
Player player = event.getPlayer();
Block block = event.getBlockPlaced();
if (player.isOp()) {
return;
}
if (block.getType() == Material.TNT) {
if (!player.hasPermission("blockrestrictions.place.tnt")) {
String message = String.format(plugin.localize.getString(Type.PLACE_BANED_BLOCK), "TNT");
player.sendMessage(message);
StringBuilder consoleMessage = new StringBuilder();
consoleMessage.append("Player ");
consoleMessage.append(player.getName());
consoleMessage.append("placed TNT at ");
consoleMessage.append(block.getX());
consoleMessage.append(", ");
consoleMessage.append(block.getY());
consoleMessage.append(", ");
consoleMessage.append(block.getZ());
consoleMessage.append(" in world ");
consoleMessage.append(block.getWorld());
consoleMessage.append("!");
logger.warning(consoleMessage.toString());
event.setCancelled(true);
}
}
if (block.getType() == Material.BEDROCK)
if (!player.hasPermission("blockrestrictions.place.bedrock")) {
String message = String.format(plugin.localize.getString(Type.PLACE_BANED_BLOCK), "BedRock");
player.sendMessage(message);
StringBuilder consoleMessage = new StringBuilder();
consoleMessage.append("Player ");
consoleMessage.append(player.getName());
consoleMessage.append("placed BedRock at ");
consoleMessage.append(block.getX());
consoleMessage.append(", ");
consoleMessage.append(block.getY());
consoleMessage.append(", ");
consoleMessage.append(block.getZ());
consoleMessage.append(" in world ");
consoleMessage.append(block.getWorld());
consoleMessage.append("!");
logger.warning(consoleMessage.toString());
event.setCancelled(true);
}
}
}
}
@@ -0,0 +1,55 @@
package hide92795.bukkit.plugin.blockrestrictions.listener;
import hide92795.bukkit.plugin.blockrestrictions.BlockRestrictions;
import hide92795.bukkit.plugin.blockrestrictions.Type;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
public class TNTListener implements Listener {
public BlockRestrictions plugin;
public TNTListener(BlockRestrictions instance) {
plugin = instance;
}
@EventHandler
public void onEntityExplode(EntityExplodeEvent event) {
if (plugin.isEnabled()) {
if (event.getEntity() instanceof TNTPrimed) {
Location location = event.getLocation();
Player[] players = plugin.getServer().getOnlinePlayers();
for (Player player : players) {
if (player.isOp()) {
continue;
}
if (isPlayerDetonate(player, location)) {
if (!player.hasPermission("blockrestrictions.canexplode")) {
player.sendMessage(plugin.localize.getString(Type.DETONATE_TNT));
event.setCancelled(true);
}
}
}
}
}
}
private boolean isPlayerDetonate(Player player, Location location) {
if (player.getLocation().getX() > location.getX() + 20.0d) {
return false;
}
if (player.getLocation().getY() > location.getY() + 20.0d) {
return false;
}
if (player.getLocation().getY() > location.getZ() + 20.0d) {
return false;
}
if (player.getLocation().getY() > location.getZ() + 20.0d) {
return false;
}
return true;
}
}
@@ -0,0 +1,4 @@
ReloadedSetting: "&6設定をリロードしました。"
ErrorReloadSetting: "&cリロード中にエラーが発生しました。"
PlaceBanedBlock: "&c以下のアイテムを設置する権限がありません: &e%1$s"
DetonateTNT: "&cTNTを起爆させる権限がありません。"
@@ -0,0 +1,11 @@
name: BlockRestrictions
main: hide92795.bukkit.plugin.blockrestrictions.BlockRestrictions
description: Restrict TNT and BedRock
version: 1.5.2_1
depend: [hide92795CoreLib]
author: hide92795
commands:
blockrestrictions-reload:
permission: blockrestrictions.reload
aliases: [brr]

0 comments on commit ed0b2b2

Please sign in to comment.