use of org.bukkit.Material in project RedProtect by FabioZumbi12.
the class RPPlayerListener method onPlayerInteract.
@EventHandler(priority = EventPriority.LOW)
public void onPlayerInteract(PlayerInteractEvent event) {
RedProtect.get().logger.debug("RPPlayerListener - PlayerInteractEvent canceled? " + event.isCancelled());
final Player p = event.getPlayer();
Block b = event.getClickedBlock();
ItemStack itemInHand = event.getItem();
Location l;
if (RedProtect.get().tpWait.contains(p.getName())) {
RedProtect.get().tpWait.remove(p.getName());
RPLang.sendMessage(p, "cmdmanager.region.tpcancelled");
}
if (b != null) {
l = b.getLocation();
RedProtect.get().logger.debug("RPPlayerListener - Is PlayerInteractEvent event. The block is " + b.getType().name());
} else {
l = p.getLocation();
}
if (itemInHand != null && !itemInHand.getType().equals(Material.AIR)) {
String claimmode = RPConfig.getWorldClaimType(p.getWorld().getName());
if (itemInHand.getType().name().equalsIgnoreCase(RPConfig.getString("wands.adminWandID")) && ((claimmode.equalsIgnoreCase("WAND") || claimmode.equalsIgnoreCase("BOTH")) || p.hasPermission("redprotect.admin.claim"))) {
if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK) || event.getAction().equals(Action.RIGHT_CLICK_AIR)) {
if (!RPUtil.canBuildNear(p, l)) {
event.setCancelled(true);
return;
}
RedProtect.get().secondLocationSelections.put(p, l);
p.sendMessage(RPLang.get("playerlistener.wand2") + RPLang.get("general.color") + " (" + ChatColor.GOLD + l.getBlockX() + RPLang.get("general.color") + ", " + ChatColor.GOLD + l.getBlockY() + RPLang.get("general.color") + ", " + ChatColor.GOLD + l.getBlockZ() + RPLang.get("general.color") + ").");
event.setCancelled(true);
} else if (event.getAction().equals(Action.LEFT_CLICK_BLOCK) || event.getAction().equals(Action.LEFT_CLICK_AIR)) {
if (!RPUtil.canBuildNear(p, l)) {
event.setCancelled(true);
return;
}
RedProtect.get().firstLocationSelections.put(p, l);
p.sendMessage(RPLang.get("playerlistener.wand1") + RPLang.get("general.color") + " (" + ChatColor.GOLD + l.getBlockX() + RPLang.get("general.color") + ", " + ChatColor.GOLD + l.getBlockY() + RPLang.get("general.color") + ", " + ChatColor.GOLD + l.getBlockZ() + RPLang.get("general.color") + ").");
event.setCancelled(true);
}
// show preview border
if (RedProtect.get().firstLocationSelections.containsKey(p) && RedProtect.get().secondLocationSelections.containsKey(p)) {
Location loc1 = RedProtect.get().firstLocationSelections.get(p);
Location loc2 = RedProtect.get().secondLocationSelections.get(p);
if (loc1.getWorld().equals(loc2.getWorld()) && loc1.distanceSquared(loc2) > RPConfig.getInt("region-settings.define-max-distance") && !RedProtect.get().ph.hasPerm(p, "redprotect.bypass.define-max-distance")) {
Double dist = loc1.distanceSquared(loc2);
RPLang.sendMessage(p, String.format(RPLang.get("regionbuilder.selection.maxdefine"), RPConfig.getInt("region-settings.define-max-distance"), dist.intValue()));
} else {
RPUtil.addBorder(p, RPUtil.get4Points(loc1, loc2, p.getLocation().getBlockY()));
}
}
return;
}
if (itemInHand.getType().name().equalsIgnoreCase(RPConfig.getString("wands.infoWandID"))) {
Region r = RedProtect.get().rm.getTopRegion(l);
if (p.hasPermission("redprotect.infowand")) {
if (r == null) {
RPLang.sendMessage(p, "playerlistener.noregion.atblock");
} else if (r.canBuild(p)) {
p.sendMessage(RPLang.get("general.color") + "--------------- [" + ChatColor.GOLD + r.getName() + RPLang.get("general.color") + "] ---------------");
p.sendMessage(r.info());
p.sendMessage(RPLang.get("general.color") + "-----------------------------------------");
} else {
p.sendMessage(RPLang.get("playerlistener.region.entered").replace("{region}", r.getName()).replace("{leaders}", r.getLeadersDesc()));
}
event.setCancelled(true);
return;
}
}
}
if (event.isCancelled()) {
return;
}
Region r = RedProtect.get().rm.getTopRegion(l);
// start player checks
if (r == null) {
if (b != null && (b.getType().equals(Material.ANVIL) || b.getState() instanceof InventoryHolder || RPConfig.getStringList("private.allowed-blocks").contains(b.getType().name()))) {
Boolean out = RPConfig.getBool("private.allow-outside");
if (out && !cont.canOpen(b, p)) {
RPLang.sendMessage(p, "playerlistener.region.cantopen");
event.setCancelled(true);
}
}
} else {
// other blocks and interactions
if (itemInHand != null && (event.getAction().name().equals("RIGHT_CLICK_BLOCK") || b == null)) {
Material hand = itemInHand.getType();
if (hand.equals(Material.ENDER_PEARL) && !r.canTeleport(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantuse");
event.setCancelled(true);
event.setUseItemInHand(Event.Result.DENY);
return;
} else if ((hand.equals(Material.BOW) || (hand.name().contains("SNOW") && hand.name().contains("BALL")) || hand.name().contains("FIREWORK") || hand.equals(Material.EGG)) && !r.canProtectiles(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantuse");
event.setCancelled(true);
event.setUseItemInHand(Event.Result.DENY);
return;
} else if (hand.equals(Material.POTION) && !r.usePotions(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantuse");
event.setCancelled(true);
event.setUseItemInHand(Event.Result.DENY);
return;
} else if (hand.name().contains("_EGG") && !r.canInteractPassives(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantuse");
event.setCancelled(true);
event.setUseItemInHand(Event.Result.DENY);
return;
}
}
// if (r != null) && (b != null) >>
if (b != null) {
if (b.getType().equals(Material.DRAGON_EGG) || b.getType().name().equalsIgnoreCase("BED") || b.getType().name().contains("NOTE_BLOCK") || b.getType().name().contains("CAKE")) {
if (!r.canBuild(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantinteract");
event.setCancelled(true);
}
} else if (b.getState() instanceof Sign && RPConfig.getBool("region-settings.enable-flag-sign")) {
Sign s = (Sign) b.getState();
String[] lines = s.getLines();
if (lines[0].equalsIgnoreCase("[flag]") && r.flags.containsKey(lines[1])) {
String flag = lines[1];
if (!(r.flags.get(flag) instanceof Boolean)) {
RPLang.sendMessage(p, RPLang.get("playerlistener.region.sign.cantflag"));
return;
}
if (RedProtect.get().ph.hasPerm(p, "redprotect.flag." + flag)) {
if (r.isAdmin(p) || r.isLeader(p) || RedProtect.get().ph.hasPerm(p, "redprotect.admin.flag." + flag)) {
if (RPConfig.getBool("flags-configuration.change-flag-delay.enable")) {
if (RPConfig.getStringList("flags-configuration.change-flag-delay.flags").contains(flag)) {
if (!RedProtect.get().changeWait.contains(r.getName() + flag)) {
RPUtil.startFlagChanger(r.getName(), flag, p);
changeFlag(r, flag, p, s);
return;
} else {
RPLang.sendMessage(p, RPLang.get("gui.needwait.tochange").replace("{seconds}", RPConfig.getString("flags-configuration.change-flag-delay.seconds")));
return;
}
}
}
changeFlag(r, flag, p, s);
return;
}
}
RPLang.sendMessage(p, "cmdmanager.region.flag.nopermregion");
}
} else if (b.getType().equals(Material.ENDER_CHEST)) {
if (!r.canEnderChest(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantopen");
event.setCancelled(true);
}
} else if (!b.getType().equals(Material.ENDER_CHEST) && (b.getType().equals(Material.ANVIL) || b.getState() instanceof InventoryHolder || RPConfig.getStringList("private.allowed-blocks").contains(b.getType().name()))) {
if ((r.canChest(p) && !cont.canOpen(b, p) || (!r.canChest(p) && cont.canOpen(b, p)) || (!r.canChest(p) && !cont.canOpen(b, p)))) {
RPLang.sendMessage(p, "playerlistener.region.cantopen");
event.setCancelled(true);
}
} else if (b.getType().name().contains("LEVER") || (b.getType().name().contains("REDSTONE") && !b.getType().equals(Material.REDSTONE_ORE))) {
if (!r.canLever(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantlever");
event.setCancelled(true);
}
} else if (b.getType().name().contains("BUTTON")) {
if (!r.canButton(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantbutton");
event.setCancelled(true);
}
} else if (RPDoor.isOpenable(b) && event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
if (!r.canDoor(p)) /* || (r.canDoor(p) && !cont.canOpen(b, p))*/
{
RPLang.sendMessage(p, "playerlistener.region.cantdoor");
event.setCancelled(true);
} else {
RPDoor.ChangeDoor(b, r);
}
} else if (itemInHand != null && (itemInHand.getType().name().startsWith("BOAT") || itemInHand.getType().name().contains("MINECART"))) {
if (!r.canMinecart(p)) {
RPLang.sendMessage(p, "blocklistener.region.cantplace");
event.setUseItemInHand(Event.Result.DENY);
event.setCancelled(true);
}
} else if ((event.getAction().equals(Action.LEFT_CLICK_BLOCK) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && b.getType().name().contains("SIGN") && !r.canSign(p)) {
Sign sign = (Sign) b.getState();
for (String tag : RPConfig.getStringList("region-settings.allow-sign-interact-tags")) {
// check first rule
if (sign != null && tag.equalsIgnoreCase(sign.getLine(0))) {
return;
}
// check if tag is owners or members names
if (tag.equalsIgnoreCase("{membername}")) {
for (String leader : r.getLeaders()) {
if (sign.getLine(0).equalsIgnoreCase(RPUtil.UUIDtoPlayer(leader))) {
return;
}
}
for (String admin : r.getAdmins()) {
if (sign.getLine(0).equalsIgnoreCase(RPUtil.UUIDtoPlayer(admin))) {
return;
}
}
for (String member : r.getMembers()) {
if (sign.getLine(0).equalsIgnoreCase(RPUtil.UUIDtoPlayer(member))) {
return;
}
}
}
// check if tag is player name
if (tag.equalsIgnoreCase("{playername}")) {
if (sign.getLine(0).equalsIgnoreCase(RPUtil.UUIDtoPlayer(p.getName()))) {
return;
}
}
}
RPLang.sendMessage(p, "playerlistener.region.cantinteract.signs");
event.setUseItemInHand(Event.Result.DENY);
event.setCancelled(true);
} else if ((itemInHand != null && !itemInHand.getType().equals(Material.AIR)) && !r.canBuild(p) && !r.canPlace(itemInHand.getType()) && (itemInHand.getType().equals(Material.FLINT_AND_STEEL) || itemInHand.getType().equals(Material.WATER_BUCKET) || itemInHand.getType().equals(Material.BUCKET) || itemInHand.getType().equals(Material.LAVA_BUCKET) || itemInHand.getType().equals(Material.ITEM_FRAME) || itemInHand.getType().equals(Material.PAINTING))) {
RPLang.sendMessage(p, "playerlistener.region.cantuse");
event.setCancelled(true);
event.setUseItemInHand(Event.Result.DENY);
event.setUseInteractedBlock(Event.Result.DENY);
} else if (!r.allowMod(p) && !RPUtil.isBukkitBlock(b)) {
RPLang.sendMessage(p, "playerlistener.region.cantinteract");
event.setCancelled(true);
event.setUseInteractedBlock(Event.Result.DENY);
}
}
}
}
use of org.bukkit.Material in project RedProtect by FabioZumbi12.
the class RPConfig method init.
public static void init() {
gflags = new YamlConfiguration();
signs = new YamlConfiguration();
GuiItems = new YamlConfiguration();
Prots = new YamlConfiguration();
EconomyConfig = new YamlConfiguration();
comConfig = new RPCommentedConfig();
File main = RedProtect.get().getDataFolder();
File data = new File(main, "data");
File gui = new File(main, "guiconfig.yml");
File bvalues = new File(main, "economy.yml");
File globalflags = new File(main, "globalflags.yml");
File protections = new File(main, "protections.yml");
File logs = new File(main, "logs");
File signsf = new File(main, "signs.yml");
File schema = new File(main, "schematics" + File.separator + "house1.schematic");
if (!main.exists()) {
main.mkdir();
RedProtect.get().logger.info("Created folder: " + main);
}
if (!data.exists()) {
data.mkdir();
RedProtect.get().logger.info("Created folder: " + main);
}
// init config
comConfig.addDef();
if (!globalflags.exists()) {
try {
// create globalflags file
globalflags.createNewFile();
RedProtect.get().logger.info("Created globalflags file: " + globalflags);
} catch (IOException e) {
e.printStackTrace();
}
}
if (!signsf.exists()) {
try {
// create PathSigns file
signsf.createNewFile();
RedProtect.get().logger.info("Created signs file: " + signsf);
} catch (IOException e) {
e.printStackTrace();
}
}
if (!gui.exists()) {
// create guiconfig file
RPUtil.saveResource("/assets/redprotect/guiconfig.yml", gui);
RedProtect.get().logger.info("Created guiconfig file: " + gui);
}
if (!bvalues.exists()) {
// create blockvalues file
RPUtil.saveResource("/assets/redprotect/economy.yml", bvalues);
RedProtect.get().logger.info("Created economy file: " + bvalues);
}
if (!protections.exists()) {
// create protections file
RPUtil.saveResource("/assets/redprotect/protections.yml", protections);
RedProtect.get().logger.info("Created protections file: " + protections);
}
if (!schema.exists()) {
new File(main, "schematics").mkdir();
// save schematic file
RPUtil.saveResource("/assets/redprotect/schematics/house1.schematic", schema);
RedProtect.get().logger.info("Saved schematic file: house1.schematic");
}
RedProtect.get().logger.info("Server version: " + RedProtect.get().serv.getBukkitVersion());
// check if can enable json support
if (getBool("region-settings.region-list.hover-and-click-teleport")) {
try {
Class.forName("com.google.gson.JsonParser");
if (RedProtect.get().serv.getBukkitVersion().contains("1.7")) {
RedProtect.get().getConfig().set("region-settings.region-list.hover-and-click-teleport", false);
RedProtect.get().logger.warning("Your server version do not support Hover and Clicking region features, only 1.8.+");
}
} catch (ClassNotFoundException e) {
RedProtect.get().getConfig().set("region-settings.region-list.hover-and-click-teleport", false);
RedProtect.get().logger.warning("Your server version do not support JSON events, disabling Hover and Clicking region features.");
}
}
// add op to ignore list fro purge
if (RedProtect.get().getConfig().getStringList("purge.ignore-regions-from-players").size() <= 0) {
List<String> ops = RedProtect.get().getConfig().getStringList("purge.ignore-regions-from-players");
for (OfflinePlayer play : RedProtect.get().serv.getOperators()) {
ops.add(play.getName());
}
RedProtect.get().getConfig().set("purge.ignore-regions-from-players", ops);
}
// add op to ignore list fro sell
if (RedProtect.get().getConfig().getStringList("sell.ignore-regions-from-players").size() <= 0) {
List<String> ops = RedProtect.get().getConfig().getStringList("sell.ignore-regions-from-players");
for (OfflinePlayer play : RedProtect.get().serv.getOperators()) {
ops.add(play.getName());
}
RedProtect.get().getConfig().set("sell.ignore-regions-from-players", ops);
}
// add allowed claim worlds to config
if (RedProtect.get().getConfig().getStringList("allowed-claim-worlds").get(0).equals("example_world")) {
List<String> worlds = new ArrayList<>();
for (World w : RedProtect.get().serv.getWorlds()) {
worlds.add(w.getName());
RedProtect.get().logger.warning("Added world to claim list " + w.getName());
}
worlds.remove("example_world");
RedProtect.get().getConfig().set("allowed-claim-worlds", worlds);
}
// add worlds to color list
for (World w : RedProtect.get().serv.getWorlds()) {
if (RedProtect.get().getConfig().getString("region-settings.claim-type.worlds." + w.getName()) == null) {
RedProtect.get().getConfig().set("region-settings.claim-type.worlds." + w.getName(), "BLOCK");
}
if (RedProtect.get().getConfig().getString("region-settings.world-colors." + w.getName()) == null) {
if (w.getEnvironment().equals(Environment.NORMAL)) {
RedProtect.get().getConfig().set("region-settings.world-colors." + w.getName(), "&a&l");
} else if (w.getEnvironment().equals(Environment.NETHER)) {
RedProtect.get().getConfig().set("region-settings.world-colors." + w.getName(), "&c&l");
} else if (w.getEnvironment().equals(Environment.THE_END)) {
RedProtect.get().getConfig().set("region-settings.world-colors." + w.getName(), "&5&l");
}
RedProtect.get().logger.warning("Added world to color list " + w.getName());
}
}
/*----------------- Add default config for not updateable configs ------------------*/
// update new player flags according version
List<String> flags = RedProtect.get().getConfig().getStringList("flags-configuration.enabled-flags");
int configUp = 0;
if (RedProtect.get().getConfig().getDouble("config-version") < 6.8D) {
RedProtect.get().getConfig().set("config-version", 6.8D);
if (!flags.contains("smart-door")) {
flags.add("smart-door");
}
if (!flags.contains("allow-potions")) {
flags.add("allow-potions");
}
if (!flags.contains("mob-loot")) {
flags.add("mob-loot");
}
if (!flags.contains("flow-damage")) {
flags.add("flow-damage");
}
configUp++;
}
if (RedProtect.get().getConfig().getDouble("config-version") < 6.9D) {
RedProtect.get().getConfig().set("config-version", 6.9D);
if (!flags.contains("iceform-player")) {
flags.add("iceform-player");
}
if (!flags.contains("iceform-entity")) {
flags.add("iceform-entity");
}
configUp++;
}
if (RedProtect.get().getConfig().getDouble("config-version") < 7.0D) {
RedProtect.get().getConfig().set("config-version", 7.0D);
if (!flags.contains("allow-fly")) {
flags.add("allow-fly");
}
configUp++;
}
if (RedProtect.get().getConfig().getDouble("config-version") < 7.1D) {
RedProtect.get().getConfig().set("config-version", 7.1D);
if (!flags.contains("teleport")) {
flags.add("teleport");
}
configUp++;
}
if (RedProtect.get().getConfig().getDouble("config-version") < 7.2D) {
RedProtect.get().getConfig().set("config-version", 7.2D);
if (!flags.contains("clan")) {
flags.add("clan");
}
configUp++;
}
if (RedProtect.get().getConfig().getDouble("config-version") < 7.3D) {
RedProtect.get().getConfig().set("config-version", 7.3D);
if (!flags.contains("ender-chest")) {
flags.add("ender-chest");
}
configUp++;
}
if (RedProtect.get().getConfig().getDouble("config-version") < 7.5D) {
RedProtect.get().getConfig().set("config-version", 7.5D);
if (flags.contains("iceform-entity")) {
flags.add("iceform-world");
flags.remove("iceform-entity");
}
if (!flags.contains("can-grow")) {
flags.add("can-grow");
}
configUp++;
}
if (RedProtect.get().getConfig().getDouble("config-version") < 7.6D) {
RedProtect.get().getConfig().set("config-version", 7.6D);
if (flags.contains("allow-potions")) {
flags.remove("allow-potions");
}
if (!flags.contains("use-potions")) {
flags.add("use-potions");
}
if (!flags.contains("allow-effects")) {
flags.add("allow-effects");
}
configUp++;
}
if (RedProtect.get().getConfig().getDouble("config-version") < 7.7D) {
RedProtect.get().getConfig().set("config-version", 7.7D);
if (!flags.contains("allow-spawner")) {
flags.add("allow-spawner");
}
configUp++;
}
if (RedProtect.get().getConfig().getDouble("config-version") < 7.8D) {
RedProtect.get().getConfig().set("config-version", 7.8D);
if (!flags.contains("leaves-decay")) {
flags.add("leaves-decay");
}
configUp++;
}
if (RedProtect.get().getConfig().getDouble("config-version") < 7.9D) {
RedProtect.get().getConfig().set("config-version", 7.9D);
if (!flags.contains("build")) {
flags.add("build");
}
configUp++;
}
if (RedProtect.get().getConfig().getDouble("config-version") < 7.10D) {
RedProtect.get().getConfig().set("config-version", 7.10D);
RedProtect.get().getConfig().set("language", RedProtect.get().getConfig().getString("language").toUpperCase());
configUp++;
}
if (RedProtect.get().getConfig().getDouble("config-version") < 7.11D) {
RedProtect.get().getConfig().set("config-version", 7.11D);
RedProtect.get().getConfig().set("wands.adminWandID", "GLASS_BOTTLE");
RedProtect.get().getConfig().set("wands.infoWandID", "PAPER");
configUp++;
}
if (configUp > 0) {
RedProtect.get().getConfig().set("flags-configuration.enabled-flags", flags);
RedProtect.get().logger.warning("Configuration UPDATE! We added new flags or new options, or just updated some other config. See change log for details.");
}
/*------------------------------------------------------------------------------------*/
// load protections file
Prots = updateFile(protections);
/*------------------------------------------------------------------------------------*/
// load and write globalflags to global file
gflags = YamlConfiguration.loadConfiguration(globalflags);
for (World w : RedProtect.get().serv.getWorlds()) {
gflags.set(w.getName() + ".build", gflags.getBoolean(w.getName() + ".build", true));
gflags.set(w.getName() + ".liquid-flow", gflags.getBoolean(w.getName() + ".liquid-flow", true));
gflags.set(w.getName() + ".allow-changes-of.water-flow", gflags.getBoolean(w.getName() + ".allow-changes-of.water-flow", true));
gflags.set(w.getName() + ".allow-changes-of.lava-flow", gflags.getBoolean(w.getName() + ".allow-changes-of.lava-flow", true));
gflags.set(w.getName() + ".allow-changes-of.leaves-decay", gflags.getBoolean(w.getName() + ".allow-changes-of.leaves-decay", true));
gflags.set(w.getName() + ".allow-changes-of.flow-damage", gflags.getBoolean(w.getName() + ".allow-changes-of.flow-damage", true));
gflags.set(w.getName() + ".if-build-false.break-blocks", gflags.getStringList(w.getName() + ".if-build-false.break-blocks"));
gflags.set(w.getName() + ".if-build-false.place-blocks", gflags.getStringList(w.getName() + ".if-build-false.place-blocks"));
gflags.set(w.getName() + ".pvp", gflags.getBoolean(w.getName() + ".pvp", true));
gflags.set(w.getName() + ".iceform-by.player", gflags.getBoolean(w.getName() + ".iceform-by.player", false));
gflags.set(w.getName() + ".iceform-by.world", gflags.getBoolean(w.getName() + ".iceform-by.world", true));
gflags.set(w.getName() + ".interact", gflags.getBoolean(w.getName() + ".interact", true));
gflags.set(w.getName() + ".if-interact-false.allow-blocks", gflags.getStringList(w.getName() + ".if-interact-false.allow-blocks"));
gflags.set(w.getName() + ".if-interact-false.allow-entities", gflags.getStringList(w.getName() + ".if-interact-false.allow-entities"));
gflags.set(w.getName() + ".use-minecart", gflags.getBoolean(w.getName() + ".use-minecart", true));
gflags.set(w.getName() + ".entity-block-damage", gflags.getBoolean(w.getName() + ".entity-block-damage", false));
gflags.set(w.getName() + ".explosion-entity-damage", gflags.getBoolean(w.getName() + ".explosion-entity-damage", true));
gflags.set(w.getName() + ".fire-block-damage", gflags.getBoolean(w.getName() + ".fire-block-damage", false));
gflags.set(w.getName() + ".fire-spread", gflags.getBoolean(w.getName() + ".fire-spread", false));
gflags.set(w.getName() + ".player-hurt-monsters", gflags.getBoolean(w.getName() + ".player-hurt-monsters", true));
gflags.set(w.getName() + ".player-hurt-passives", gflags.getBoolean(w.getName() + ".player-hurt-passives", true));
gflags.set(w.getName() + ".spawn-monsters", gflags.getBoolean(w.getName() + ".spawn-monsters", true));
gflags.set(w.getName() + ".spawn-passives", gflags.getBoolean(w.getName() + ".spawn-passives", true));
gflags.set(w.getName() + ".remove-entities-not-allowed-to-spawn", gflags.getBoolean(w.getName() + ".remove-entities-not-allowed-to-spawn", false));
gflags.set(w.getName() + ".elytra.allow", gflags.getBoolean(w.getName() + ".elytra.allow", true));
gflags.set(w.getName() + ".elytra.boost", gflags.getDouble(w.getName() + ".elytra.boost", 0.5D));
gflags.set(w.getName() + ".deny-item-usage.allow-on-claimed-rps", gflags.getBoolean(w.getName() + ".deny-item-usage.allow-on-claimed-rps", true));
gflags.set(w.getName() + ".deny-item-usage.allow-on-wilderness", gflags.getBoolean(w.getName() + ".deny-item-usage.allow-on-wilderness", true));
gflags.set(w.getName() + ".deny-item-usage.items", gflags.getStringList(w.getName() + ".deny-item-usage.items"));
gflags.set(w.getName() + ".player-velocity.walk-speed", gflags.getDouble(w.getName() + ".player-velocity.walk-speed", -1));
gflags.set(w.getName() + ".player-velocity.fly-speed", gflags.getDouble(w.getName() + ".player-velocity.fly-speed", -1));
gflags.set(w.getName() + ".on-enter-cmds", gflags.getStringList(w.getName() + ".on-enter-cmds"));
gflags.set(w.getName() + ".on-exit-cmds", gflags.getStringList(w.getName() + ".on-exit-cmds"));
gflags.set(w.getName() + ".spawn-wither", gflags.getBoolean(w.getName() + ".spawn-wither", true));
gflags.set(w.getName() + ".invincible", gflags.getBoolean(w.getName() + ".invincible", false));
gflags.set(w.getName() + ".player-candrop", gflags.getBoolean(w.getName() + ".player-candrop", true));
gflags.set(w.getName() + ".player-canpickup", gflags.getBoolean(w.getName() + ".player-canpickup", true));
gflags.set(w.getName() + ".rain.trys-before-rain", gflags.getInt(w.getName() + ".rain.trys-before-rain", 3));
gflags.set(w.getName() + ".rain.duration", gflags.getInt(w.getName() + ".rain.duration", 60));
gflags.set(w.getName() + ".allow-crops-trample", gflags.getBoolean(w.getName() + ".allow-crops-trample", true));
if (!gflags.contains(w.getName() + ".command-ranges")) {
gflags.set(w.getName() + ".command-ranges.home.min-range", gflags.getDouble(w.getName() + ".command-ranges.home.min-range", 0));
gflags.set(w.getName() + ".command-ranges.home.max-range", gflags.getDouble(w.getName() + ".command-ranges.home.max-range", w.getMaxHeight()));
gflags.set(w.getName() + ".command-ranges.home.message", gflags.getString(w.getName() + ".command-ranges.home.message", "&cYou cant use /home when mining or in caves!"));
}
w.setSpawnFlags(gflags.getBoolean(w.getName() + ".spawn-monsters"), gflags.getBoolean(w.getName() + ".spawn-passives"));
RedProtect.get().logger.debug("Spawn Animals: " + w.getAllowAnimals() + " | " + "Spawn Monsters: " + w.getAllowMonsters());
}
// load and write GuiItems to guiconfig file
try {
GuiItems.load(gui);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
YamlConfiguration GuiBase = inputLoader(RedProtect.get().getResource("assets/redprotect/guiconfig.yml"));
GuiItems.set("gui-strings.value", GuiItems.getString("gui-strings.value", "&bValue: "));
GuiItems.set("gui-strings.true", GuiItems.getString("gui-strings.true", "&atrue"));
GuiItems.set("gui-strings.false", GuiItems.getString("gui-strings.false", "&cfalse"));
GuiItems.set("gui-strings.separator", GuiItems.getString("gui-strings.separator", "&7|"));
GuiItems.set("gui-separator.material", GuiItems.getString("gui-separator.material", "THIN_GLASS"));
GuiItems.set("gui-separator.data", GuiItems.getInt("gui-separator.data", 0));
for (String key : getDefFlagsValues().keySet()) {
GuiItems.set("gui-flags." + key + ".slot", GuiItems.get("gui-flags." + key + ".slot", GuiBase.get("gui-flags." + key + ".slot", getDefFlagsValues().size())));
GuiItems.set("gui-flags." + key + ".material", GuiItems.get("gui-flags." + key + ".material", GuiBase.get("gui-flags." + key + ".material", "GOLDEN_APPLE")));
GuiItems.set("gui-flags." + key + ".name", GuiItems.get("gui-flags." + key + ".name", GuiBase.get("gui-flags." + key + ".name", "&e" + key)));
GuiItems.set("gui-flags." + key + ".description", GuiItems.get("gui-flags." + key + ".description", GuiBase.get("gui-flags." + key + ".description", "&bDescription: &2Add a flag description here.")));
GuiItems.set("gui-flags." + key + ".description1", GuiItems.get("gui-flags." + key + ".description1", GuiBase.get("gui-flags." + key + ".description1", "")));
GuiItems.set("gui-flags." + key + ".description2", GuiItems.get("gui-flags." + key + ".description2", GuiBase.get("gui-flags." + key + ".description2", "")));
}
// load blockvalues file
try {
EconomyConfig.load(bvalues);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
YamlConfiguration tempEco = inputLoader(RedProtect.get().getResource("assets/redprotect/economy.yml"));
for (String key : tempEco.getKeys(false)) {
if (EconomyConfig.get(key) == null) {
EconomyConfig.set(key, tempEco.get(key));
}
}
if (EconomyConfig.getConfigurationSection("items.values").getKeys(false).size() != Material.values().length) {
for (Material mat : Material.values()) {
if (EconomyConfig.getString("items.values." + mat.name()) == null) {
EconomyConfig.set("items.values." + mat.name(), 0.0);
}
}
}
if (EconomyConfig.getConfigurationSection("enchantments.values").getKeys(false).size() != Enchantment.values().length) {
for (Enchantment ench : Enchantment.values()) {
if (EconomyConfig.getString("enchantments.values." + ench.getName()) == null) {
EconomyConfig.set("enchantments.values." + ench.getName(), 0.0);
}
}
}
// ////////////////////
/*------------------------------------------------------------------------------------*/
String v = RedProtect.get().serv.getBukkitVersion();
if (RedProtect.get().getConfig().getString("notify.region-enter-mode").equalsIgnoreCase("TITLE") && (v == null || !v.contains("1.8"))) {
RedProtect.get().getConfig().set("notify.region-enter-mode", "CHAT");
RedProtect.get().logger.warning("Title notifications is not suported on servers not running 1.8! Defaulting to CHAT.");
}
// create logs folder
if (getBool("log-actions") && !logs.exists()) {
logs.mkdir();
RedProtect.get().logger.info("Created folder: " + logs);
}
// Load signs file
try {
signs.load(signsf);
} catch (Exception e) {
e.printStackTrace();
}
save();
RedProtect.get().logger.info("All configurations loaded!");
}
use of org.bukkit.Material in project RedProtect by FabioZumbi12.
the class RPBlockListener method onBlockPlace.
@EventHandler(priority = EventPriority.HIGH)
public void onBlockPlace(BlockPlaceEvent e) {
RedProtect.get().logger.debug("BlockListener - Is BlockPlaceEvent event! Cancelled? " + e.isCancelled());
if (e.isCancelled()) {
return;
}
Player p = e.getPlayer();
Block b = e.getBlockPlaced();
World w = p.getWorld();
Material m = null;
if (e.getItemInHand() != null) {
m = e.getItemInHand().getType();
}
Boolean antih = RPConfig.getBool("region-settings.anti-hopper");
Region r = RedProtect.get().rm.getTopRegion(b.getLocation());
if (!RedProtect.get().ph.hasPerm(p, "redprotect.bypass") && antih && m != null && (m.equals(Material.HOPPER) || m.name().contains("RAIL"))) {
int x = b.getX();
int y = b.getY();
int z = b.getZ();
Block ib = w.getBlockAt(x, y + 1, z);
if (!cont.canBreak(p, ib) || !cont.canBreak(p, b)) {
RPLang.sendMessage(p, "blocklistener.container.chestinside");
e.setCancelled(true);
return;
}
}
if (r == null && RPConfig.getGlobalFlagList(p.getWorld().getName() + ".if-build-false.place-blocks").contains(b.getType().name())) {
return;
}
if (r != null) {
if (m != null && !r.canMinecart(p) && (m.name().contains("MINECART") || m.name().contains("BOAT"))) {
RPLang.sendMessage(p, "blocklistener.region.cantplace");
e.setCancelled(true);
return;
}
if (b.getType().equals(Material.MOB_SPAWNER) && r.allowSpawner(p)) {
return;
}
if (!r.canBuild(p) && !r.canPlace(b.getType())) {
RPLang.sendMessage(p, "blocklistener.region.cantbuild");
e.setCancelled(true);
}
}
}
use of org.bukkit.Material in project Citizens2 by CitizensDev.
the class NMSImpl method minecartItemLogic.
@SuppressWarnings("deprecation")
public static void minecartItemLogic(EntityMinecartAbstract minecart) {
NPC npc = ((NPCHolder) minecart).getNPC();
if (npc == null)
return;
Material mat = Material.getMaterial(npc.data().get(NPC.MINECART_ITEM_METADATA, ""));
int data = npc.data().get(NPC.MINECART_ITEM_DATA_METADATA, 0);
int offset = npc.data().get(NPC.MINECART_OFFSET_METADATA, 0);
minecart.a(mat != null);
if (mat != null) {
minecart.setDisplayBlock(Block.getById(mat.getId()).fromLegacyData(data));
}
minecart.setDisplayBlockOffset(offset);
}
use of org.bukkit.Material in project Citizens2 by CitizensDev.
the class ItemController method createEntity.
@Override
protected Entity createEntity(Location at, NPC npc) {
WorldServer ws = ((CraftWorld) at.getWorld()).getHandle();
Material id = Material.STONE;
int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
if (npc.data().has(NPC.ITEM_ID_METADATA)) {
id = Material.getMaterial(npc.data().<String>get(NPC.ITEM_ID_METADATA));
}
final EntityItemNPC handle = new EntityItemNPC(ws, npc, at.getX(), at.getY(), at.getZ(), CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(id, 1, (short) data)));
return handle.getBukkitEntity();
}
Aggregations