Permalink
Browse files

Cleanup some more Bukkit specific code.

  • Loading branch information...
me4502 committed Aug 7, 2018
1 parent ba61919 commit b850b5caf84a5b73cee1acd164ca9b090d494a04
Showing with 173 additions and 131 deletions.
  1. +9 −2 ...orldguard/bukkit → worldguard-core/src/main/java/com/sk89q/worldguard}/chest/ChestProtection.java
  2. +18 −51 ...guard/bukkit → worldguard-core/src/main/java/com/sk89q/worldguard}/chest/SignChestProtection.java
  3. +3 −0 worldguard-core/src/main/java/com/sk89q/worldguard/config/WorldConfiguration.java
  4. +1 −1 worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/FlagContext.java
  5. +0 −31 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/BukkitUtil.java
  6. +3 −6 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldConfiguration.java
  7. +1 −1 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldGuardPlatform.java
  8. +1 −1 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java
  9. +54 −0 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/chest/BukkitSignChestProtection.java
  10. +1 −1 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/commands/DebuggingCommands.java
  11. +74 −31 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/SpongeUtil.java
  12. +3 −3 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardBlockListener.java
  13. +1 −1 ...va/com/sk89q/worldguard/{protection → bukkit/protection/events}/flags/FlagContextCreateEvent.java
  14. +1 −1 ...uard-legacy/src/main/java/com/sk89q/worldguard/{ → bukkit}/util/logging/ClassSourceValidator.java
  15. +3 −1 worldguard-legacy/src/main/java/com/sk89q/worldguard/{ → bukkit}/util/report/CancelReport.java
@@ -17,10 +17,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.chest;
package com.sk89q.worldguard.chest;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldguard.LocalPlayer;
/**
@@ -62,6 +63,12 @@
* @param blockType The blockType to check
* @return Whether a type is a 'chest' (protectable block)
*/
boolean isChest(BlockType blockType);
default boolean isChest(BlockType blockType) {
return blockType == BlockTypes.CHEST
|| blockType == BlockTypes.DISPENSER
|| blockType == BlockTypes.FURNACE
|| blockType == BlockTypes.TRAPPED_CHEST
|| blockType == BlockTypes.DROPPER;
}
}
@@ -17,23 +17,21 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.chest;
package com.sk89q.worldguard.chest;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldguard.LocalPlayer;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
/**
* Sign-based chest protection.
*
*
* @author sk89q
*/
public class SignChestProtection implements ChestProtection {
public abstract class SignChestProtection implements ChestProtection {
public abstract Boolean isProtectedSign(Location block, LocalPlayer player);
public boolean isProtected(Location location, LocalPlayer player) {
com.sk89q.worldedit.world.block.BlockState blockState = location.getExtent().getBlock(location.toVector());
if (isChest(blockState.getBlockType())) {
@@ -46,68 +44,45 @@ public boolean isProtected(Location location, LocalPlayer player) {
return false;
}
}
public boolean isProtectedPlacement(Location block, LocalPlayer player) {
return isProtectedSignAround(block, player);
}
private boolean isProtectedSignAround(Location searchBlock, LocalPlayer player) {
Location side;
Boolean res;
side = searchBlock;
res = isProtectedSign(side, player);
if (res != null && res) return res;
side = searchBlock.setX(searchBlock.getX() - 1);
res = isProtectedSignAndChest(side, player);
if (res != null && res) return res;
side = searchBlock.setX(searchBlock.getX() + 1);
res = isProtectedSignAndChest(side, player);
if (res != null && res) return res;
side = searchBlock.setZ(searchBlock.getZ() - 1);
res = isProtectedSignAndChest(side, player);
if (res != null && res) return res;
side = searchBlock.setZ(searchBlock.getZ() + 1);
res = isProtectedSignAndChest(side, player);
if (res != null && res) return res;
return false;
}
private Boolean isProtectedSign(Sign sign, LocalPlayer player) {
if (sign.getLine(0).equalsIgnoreCase("[Lock]")) {
if (player == null) { // No player, no access
return true;
}
String name = player.getName();
return !name.equalsIgnoreCase(sign.getLine(1).trim())
&& !name.equalsIgnoreCase(sign.getLine(2).trim())
&& !name.equalsIgnoreCase(sign.getLine(3).trim());
}
return null;
}
private Boolean isProtectedSign(Location block, LocalPlayer player) {
BlockState state = BukkitAdapter.adapt(block).getBlock().getState();
if (!(state instanceof Sign)) {
return null;
}
return isProtectedSign((Sign) state, player);
}
private Boolean isProtectedSignAndChest(Location block, LocalPlayer player) {
if (!isChest(block.getExtent().getBlock(block.setY(block.getY() + 1).toVector()).getBlockType())) {
return null;
}
return isProtectedSign(block, player);
}
private boolean isProtectedSignAndChestBinary(Location block, LocalPlayer player) {
Boolean res = isProtectedSignAndChest(block, player);
return !(res == null || !res);
@@ -116,7 +91,7 @@ private boolean isProtectedSignAndChestBinary(Location block, LocalPlayer player
public boolean isAdjacentChestProtected(Location searchBlock, LocalPlayer player) {
Location side;
boolean res;
side = searchBlock;
res = isProtected(side, player);
if (res) return res;
@@ -136,15 +111,7 @@ public boolean isAdjacentChestProtected(Location searchBlock, LocalPlayer player
side = searchBlock.setZ(searchBlock.getZ() + 1);
res = isProtected(side, player);
if (res) return res;
return false;
}
public boolean isChest(BlockType type) {
return type == BlockTypes.CHEST
|| type == BlockTypes.DISPENSER
|| type == BlockTypes.FURNACE
|| type == BlockTypes.TRAPPED_CHEST
|| type == BlockTypes.DROPPER;
return false;
}
}
@@ -56,6 +56,9 @@
public boolean boundedLocationFlags;
public boolean useRegions;
public boolean simulateSponge;
public int spongeRadius;
public boolean redstoneSponges;
/**
* Load the configuration.
@@ -156,7 +156,7 @@ public FlagContextBuilder setObject(String key, Object value) {
return this;
}
protected boolean tryAddToMap(String key, Object value) {
public boolean tryAddToMap(String key, Object value) {
if (map.containsKey(key)) return false;
this.map.put(key, value);
return true;
@@ -28,7 +28,6 @@
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
@@ -65,36 +64,6 @@ public static Player matchSinglePlayer(Server server, String name) {
return players.get(0);
}
/**
* Sets the given block to fluid water.
* Used by addSpongeWater()
*
* @param world
* @param ox
* @param oy
* @param oz
*/
public static void setBlockToWater(World world, int ox, int oy, int oz) {
Block block = world.getBlockAt(ox, oy, oz);
if (block.getType() == Material.AIR) {
block.setType(Material.WATER);
}
}
/**
* Checks if the given block is water
*
* @param world the world
* @param ox x
* @param oy y
* @param oz z
* @return true if it's water
*/
public static boolean isBlockWater(World world, int ox, int oy, int oz) {
Block block = world.getBlockAt(ox, oy, oz);
return block.getType() == Material.WATER;
}
/**
* Checks if the given potion is a vial of water.
*
@@ -31,8 +31,8 @@
import com.sk89q.worldguard.blacklist.logger.FileHandler;
import com.sk89q.worldguard.blacklist.target.TargetMatcherParseException;
import com.sk89q.worldguard.blacklist.target.TargetMatcherParser;
import com.sk89q.worldguard.bukkit.chest.ChestProtection;
import com.sk89q.worldguard.bukkit.chest.SignChestProtection;
import com.sk89q.worldguard.chest.ChestProtection;
import com.sk89q.worldguard.bukkit.chest.BukkitSignChestProtection;
import com.sk89q.worldguard.bukkit.commands.CommandUtils;
import com.sk89q.worldguard.bukkit.internal.TargetMatcherSet;
import com.sk89q.worldguard.config.YamlWorldConfiguration;
@@ -67,7 +67,7 @@
@Unreported private String worldName;
@Unreported private ChestProtection chestProtection = new SignChestProtection();
@Unreported private ChestProtection chestProtection = new BukkitSignChestProtection();
/* Configuration data start */
public boolean summaryOnStart;
@@ -76,13 +76,10 @@
public String buildPermissionDenyMessage = "";
public boolean fireSpreadDisableToggle;
public boolean itemDurability;
public boolean simulateSponge;
public int spongeRadius;
public boolean disableExpDrops;
public Set<PotionEffectType> blockPotions;
public boolean blockPotionsAlways;
public boolean pumpkinScuba;
public boolean redstoneSponges;
public boolean noPhysicsGravel;
public boolean noPhysicsSand;
public boolean ropeLadders;
@@ -28,7 +28,7 @@
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.internal.platform.WorldGuardPlatform;
import com.sk89q.worldguard.protection.flags.FlagContext;
import com.sk89q.worldguard.protection.flags.FlagContextCreateEvent;
import com.sk89q.worldguard.bukkit.protection.events.flags.FlagContextCreateEvent;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import com.sk89q.worldguard.bukkit.session.BukkitSessionManager;
import com.sk89q.worldguard.session.SessionManager;
@@ -81,7 +81,7 @@
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.util.UnresolvedNamesException;
import com.sk89q.worldguard.util.concurrent.EvenMoreExecutors;
import com.sk89q.worldguard.util.logging.ClassSourceValidator;
import com.sk89q.worldguard.bukkit.util.logging.ClassSourceValidator;
import com.sk89q.worldguard.util.logging.RecordMessagePrefixer;
import com.sk89q.worldguard.util.task.SimpleSupervisor;
import com.sk89q.worldguard.util.task.Supervisor;
@@ -0,0 +1,54 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.chest;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.chest.SignChestProtection;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
public class BukkitSignChestProtection extends SignChestProtection {
private Boolean isProtectedSign(Sign sign, LocalPlayer player) {
if (sign.getLine(0).equalsIgnoreCase("[Lock]")) {
if (player == null) { // No player, no access
return true;
}
String name = player.getName();
return !name.equalsIgnoreCase(sign.getLine(1).trim())
&& !name.equalsIgnoreCase(sign.getLine(2).trim())
&& !name.equalsIgnoreCase(sign.getLine(3).trim());
}
return null;
}
@Override
public Boolean isProtectedSign(Location block, LocalPlayer player) {
BlockState state = BukkitAdapter.adapt(block).getBlock().getState();
if (!(state instanceof Sign)) {
return null;
}
return isProtectedSign((Sign) state, player);
}
}
@@ -22,7 +22,7 @@
import com.sk89q.minecraft.util.commands.*;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.event.debug.*;
import com.sk89q.worldguard.util.report.CancelReport;
import com.sk89q.worldguard.bukkit.util.report.CancelReport;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
Oops, something went wrong.

0 comments on commit b850b5c

Please sign in to comment.