Skip to content

Commit

Permalink
Fixed a few more migration issues
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Aug 13, 2018
1 parent 66eb8fa commit bd89bd9
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 129 deletions.
Expand Up @@ -24,7 +24,9 @@
import com.sk89q.worldguard.util.report.Unreported;

import java.io.File;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;

/**
* Holds the configuration for individual worlds.
Expand Down Expand Up @@ -68,6 +70,10 @@ public String getWorldName() {
return this.worldName;
}

public List<String> convertLegacyItems(List<String> legacyItems) {
return legacyItems.stream().map(this::convertLegacyItem).collect(Collectors.toList());
}

public String convertLegacyItem(String legacy) {
String item = legacy;
try {
Expand All @@ -86,4 +92,27 @@ public String convertLegacyItem(String legacy) {

return item;
}

public List<String> convertLegacyBlocks(List<String> legacyBlocks) {
return legacyBlocks.stream().map(this::convertLegacyBlock).collect(Collectors.toList());
}

public String convertLegacyBlock(String legacy) {
String block = legacy;
try {
String[] splitter = block.split(":", 2);
int id = 0;
byte data = 0;
if (splitter.length == 1) {
id = Integer.parseInt(block);
} else {
id = Integer.parseInt(splitter[0]);
data = Byte.parseByte(splitter[1]);
}
block = LegacyMapper.getInstance().getBlockFromLegacy(id, data).getBlockType().getId();
} catch (Throwable e) {
}

return block;
}
}
Expand Up @@ -87,12 +87,12 @@ public class BukkitWorldConfiguration extends YamlWorldConfiguration {
public boolean noPhysicsSand;
public boolean ropeLadders;
public boolean allowPortalAnywhere;
public Set<Integer> preventWaterDamage;
public Set<String> preventWaterDamage;
public boolean blockLighter;
public boolean disableFireSpread;
public Set<Integer> disableFireSpreadBlocks;
public Set<String> disableFireSpreadBlocks;
public boolean preventLavaFire;
public Set<Integer> allowedLavaSpreadOver;
public Set<String> allowedLavaSpreadOver;
public boolean blockTNTExplosions;
public boolean blockTNTBlockDamage;
public boolean blockCreeperExplosions;
Expand Down Expand Up @@ -142,7 +142,7 @@ public class BukkitWorldConfiguration extends YamlWorldConfiguration {
public boolean disableCreatureCropTrampling;
public boolean disablePlayerCropTrampling;
public boolean preventLightningFire;
public Set<Integer> disallowedLightningBlocks;
public Set<String> disallowedLightningBlocks;
public boolean disableThunder;
public boolean disableWeather;
public boolean alwaysRaining;
Expand All @@ -162,7 +162,7 @@ public class BukkitWorldConfiguration extends YamlWorldConfiguration {
public boolean disableEndermanGriefing;
public boolean disableSnowmanTrails;
public boolean disableSoilDehydration;
public Set<Integer> allowedSnowFallOver;
public Set<String> allowedSnowFallOver;
public boolean regionInvinciblityRemovesMobs;
public boolean regionNetherPortalProtection;
public boolean fakePlayerBuildOverride;
Expand Down Expand Up @@ -279,16 +279,16 @@ public void loadConfiguration() {
noPhysicsSand = getBoolean("physics.no-physics-sand", false);
ropeLadders = getBoolean("physics.vine-like-rope-ladders", false);
allowPortalAnywhere = getBoolean("physics.allow-portal-anywhere", false);
preventWaterDamage = new HashSet<>(getIntList("physics.disable-water-damage-blocks", null));
preventWaterDamage = new HashSet<>(convertLegacyBlocks(getStringList("physics.disable-water-damage-blocks", null)));

blockTNTExplosions = getBoolean("ignition.block-tnt", false);
blockTNTBlockDamage = getBoolean("ignition.block-tnt-block-damage", false);
blockLighter = getBoolean("ignition.block-lighter", false);

preventLavaFire = getBoolean("fire.disable-lava-fire-spread", true);
disableFireSpread = getBoolean("fire.disable-all-fire-spread", false);
disableFireSpreadBlocks = new HashSet<>(getIntList("fire.disable-fire-spread-blocks", null));
allowedLavaSpreadOver = new HashSet<>(getIntList("fire.lava-spread-blocks", null));
disableFireSpreadBlocks = new HashSet<>(convertLegacyBlocks(getStringList("fire.disable-fire-spread-blocks", null)));
allowedLavaSpreadOver = new HashSet<>(convertLegacyBlocks(getStringList("fire.lava-spread-blocks", null)));

blockCreeperExplosions = getBoolean("mobs.block-creeper-explosions", false);
blockCreeperBlockDamage = getBoolean("mobs.block-creeper-block-damage", false);
Expand Down Expand Up @@ -332,7 +332,7 @@ public void loadConfiguration() {
disableCreatureCropTrampling = getBoolean("crops.disable-creature-trampling", false);
disablePlayerCropTrampling = getBoolean("crops.disable-player-trampling", false);

disallowedLightningBlocks = new HashSet<>(getIntList("weather.prevent-lightning-strike-blocks", null));
disallowedLightningBlocks = new HashSet<>(convertLegacyBlocks(getStringList("weather.prevent-lightning-strike-blocks", null)));
preventLightningFire = getBoolean("weather.disable-lightning-strike-fire", false);
disableThunder = getBoolean("weather.disable-thunderstorm", false);
disableWeather = getBoolean("weather.disable-weather", false);
Expand All @@ -351,7 +351,7 @@ public void loadConfiguration() {
disableMyceliumSpread = getBoolean("dynamics.disable-mycelium-spread", false);
disableVineGrowth = getBoolean("dynamics.disable-vine-growth", false);
disableSoilDehydration = getBoolean("dynamics.disable-soil-dehydration", false);
allowedSnowFallOver = new HashSet<>(getIntList("dynamics.snow-fall-blocks", null));
allowedSnowFallOver = new HashSet<>(convertLegacyBlocks(getStringList("dynamics.snow-fall-blocks", null)));

useRegions = getBoolean("regions.enable", true);
regionInvinciblityRemovesMobs = getBoolean("regions.invincibility-removes-mobs", false);
Expand Down
Expand Up @@ -72,15 +72,14 @@
import com.sk89q.worldguard.bukkit.listener.WorldGuardWeatherListener;
import com.sk89q.worldguard.bukkit.listener.WorldGuardWorldListener;
import com.sk89q.worldguard.bukkit.listener.WorldRulesListener;
import com.sk89q.worldguard.bukkit.session.BukkitSessionManager;
import com.sk89q.worldguard.bukkit.util.Events;
import com.sk89q.worldguard.protection.GlobalRegionManager;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry;
import com.sk89q.worldguard.protection.managers.storage.StorageException;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.util.UnresolvedNamesException;
import com.sk89q.worldguard.bukkit.session.BukkitSessionManager;
import com.sk89q.worldguard.util.concurrent.EvenMoreExecutors;
import com.sk89q.worldguard.util.logging.ClassSourceValidator;
import com.sk89q.worldguard.util.logging.RecordMessagePrefixer;
Expand Down Expand Up @@ -128,7 +127,6 @@ public class WorldGuardPlugin extends JavaPlugin {
private static WorldGuardPlugin inst;
private static BukkitWorldGuardPlatform platform;
private final CommandsManager<CommandSender> commands;
private GlobalRegionManager globalRegionManager;
private final Supervisor supervisor = new SimpleSupervisor();
private ListeningExecutorService executorService;
private ProfileService profileService;
Expand Down Expand Up @@ -189,7 +187,6 @@ public void onEnable() {
WorldGuard.getInstance().setPlatform(platform = new BukkitWorldGuardPlatform()); // Initialise WorldGuard
WorldGuard.getInstance().setup();
BukkitSessionManager sessionManager = (BukkitSessionManager) platform.getSessionManager();
globalRegionManager = new GlobalRegionManager(WorldGuard.getInstance().getPlatform().getRegionContainer());

// Set the proper command injector
commands.setInjector(new SimpleInjector(this));
Expand Down Expand Up @@ -338,17 +335,6 @@ public String convertThrowable(@Nullable Throwable throwable) {
}
}

/**
* Get the GlobalRegionManager.
*
* @return the plugin's global region manager
* @deprecated use #getRegionContainer()
*/
@Deprecated
public GlobalRegionManager getGlobalRegionManager() {
return globalRegionManager;
}

/**
* Get the supervisor.
*
Expand Down
Expand Up @@ -19,10 +19,7 @@

package com.sk89q.worldguard.bukkit.listener;

import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.BukkitWorldConfiguration;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
Expand Down Expand Up @@ -176,7 +173,7 @@ public void onBlockFromTo(BlockFromToEvent event) {
Material targetId = blockTo.getType();

if ((isAir || isWater) &&
wcfg.preventWaterDamage.contains(targetId)) {
wcfg.preventWaterDamage.contains(BukkitAdapter.asBlockType(targetId).getId())) {
event.setCancelled(true);
return;
}
Expand All @@ -185,7 +182,7 @@ public void onBlockFromTo(BlockFromToEvent event) {
if (wcfg.allowedLavaSpreadOver.size() > 0 && isLava) {
Material targetId = blockTo.getRelative(0, -1, 0).getType();

if (!wcfg.allowedLavaSpreadOver.contains(targetId)) {
if (!wcfg.allowedLavaSpreadOver.contains(BukkitAdapter.asBlockType(targetId).getId())) {
event.setCancelled(true);
return;
}
Expand Down Expand Up @@ -261,11 +258,11 @@ public void onBlockIgnite(BlockIgniteEvent event) {
int y = block.getY();
int z = block.getZ();

if (wcfg.disableFireSpreadBlocks.contains(world.getBlockAt(x, y - 1, z).getType())
|| wcfg.disableFireSpreadBlocks.contains(world.getBlockAt(x + 1, y, z).getType())
|| wcfg.disableFireSpreadBlocks.contains(world.getBlockAt(x - 1, y, z).getType())
|| wcfg.disableFireSpreadBlocks.contains(world.getBlockAt(x, y, z - 1).getType())
|| wcfg.disableFireSpreadBlocks.contains(world.getBlockAt(x, y, z + 1).getType())) {
if (wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(world.getBlockAt(x, y - 1, z).getType()).getId())
|| wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(world.getBlockAt(x + 1, y, z).getType()).getId())
|| wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(world.getBlockAt(x - 1, y, z).getType()).getId())
|| wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(world.getBlockAt(x, y, z - 1).getType()).getId())
|| wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(world.getBlockAt(x, y, z + 1).getType()).getId())) {
event.setCancelled(true);
return;
}
Expand Down Expand Up @@ -330,7 +327,7 @@ public void onBlockBurn(BlockBurnEvent event) {
if (wcfg.disableFireSpreadBlocks.size() > 0) {
Block block = event.getBlock();

if (wcfg.disableFireSpreadBlocks.contains(block.getType())) {
if (wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(block.getType()).getId())) {
event.setCancelled(true);
checkAndDestroyAround(block.getWorld(), block.getX(), block.getY(), block.getZ(), Material.FIRE);
return;
Expand Down Expand Up @@ -520,8 +517,8 @@ public void onBlockForm(BlockFormEvent event) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions && !plugin.getGlobalRegionManager().allows(
Flags.ICE_FORM, BukkitAdapter.adapt(event.getBlock().getLocation()))) {
if (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery()
.queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.ICE_FORM))) {
event.setCancelled(true);
return;
}
Expand All @@ -535,13 +532,13 @@ public void onBlockForm(BlockFormEvent event) {
if (wcfg.allowedSnowFallOver.size() > 0) {
Material targetId = event.getBlock().getRelative(0, -1, 0).getType();

if (!wcfg.allowedSnowFallOver.contains(targetId)) {
if (!wcfg.allowedSnowFallOver.contains(BukkitAdapter.asBlockType(targetId).getId())) {
event.setCancelled(true);
return;
}
}
if (wcfg.useRegions && !plugin.getGlobalRegionManager().allows(
Flags.SNOW_FALL, BukkitAdapter.adapt(event.getBlock().getLocation()))) {
if (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery()
.queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.SNOW_FALL))) {
event.setCancelled(true);
return;
}
Expand All @@ -568,8 +565,8 @@ public void onBlockSpread(BlockSpreadEvent event) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions && !plugin.getGlobalRegionManager().allows(
Flags.MUSHROOMS, BukkitAdapter.adapt(event.getBlock().getLocation()))) {
if (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery()
.queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.MUSHROOMS))) {
event.setCancelled(true);
return;
}
Expand All @@ -580,8 +577,8 @@ public void onBlockSpread(BlockSpreadEvent event) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions && !plugin.getGlobalRegionManager().allows(
Flags.GRASS_SPREAD, BukkitAdapter.adapt(event.getBlock().getLocation()))) {
if (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery()
.queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.GRASS_SPREAD))) {
event.setCancelled(true);
return;
}
Expand All @@ -593,9 +590,8 @@ public void onBlockSpread(BlockSpreadEvent event) {
return;
}

if (wcfg.useRegions
&& !plugin.getGlobalRegionManager().allows(
Flags.MYCELIUM_SPREAD, BukkitAdapter.adapt(event.getBlock().getLocation()))) {
if (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery()
.queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.MYCELIUM_SPREAD))) {
event.setCancelled(true);
return;
}
Expand All @@ -607,9 +603,8 @@ public void onBlockSpread(BlockSpreadEvent event) {
return;
}

if (wcfg.useRegions
&& !plugin.getGlobalRegionManager().allows(
Flags.VINE_GROWTH, BukkitAdapter.adapt(event.getBlock().getLocation()))) {
if (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery()
.queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.VINE_GROWTH))) {
event.setCancelled(true);
return;
}
Expand All @@ -630,8 +625,8 @@ public void onBlockFade(BlockFadeEvent event) {
return;
}

if (wcfg.useRegions && !plugin.getGlobalRegionManager().allows(
Flags.ICE_MELT, BukkitAdapter.adapt(event.getBlock().getLocation()))) {
if (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery()
.queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.ICE_MELT))) {
event.setCancelled(true);
return;
}
Expand All @@ -641,8 +636,8 @@ public void onBlockFade(BlockFadeEvent event) {
return;
}

if (wcfg.useRegions && !plugin.getGlobalRegionManager().allows(
Flags.SNOW_MELT, BukkitAdapter.adapt(event.getBlock().getLocation()))) {
if (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery()
.queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.SNOW_MELT))) {
event.setCancelled(true);
return;
}
Expand All @@ -651,8 +646,8 @@ public void onBlockFade(BlockFadeEvent event) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions && !plugin.getGlobalRegionManager().allows(
Flags.SOIL_DRY, BukkitAdapter.adapt(event.getBlock().getLocation()))) {
if (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery()
.queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.SOIL_DRY))) {
event.setCancelled(true);
return;
}
Expand Down
Expand Up @@ -168,7 +168,8 @@ private void onEntityDamageByBlock(EntityDamageByBlockEvent event) {
if (type == DamageCause.BLOCK_EXPLOSION
&& (wcfg.disableExplosionDamage || wcfg.blockOtherExplosions
|| (wcfg.explosionFlagCancellation
&& !plugin.getGlobalRegionManager().allows(Flags.OTHER_EXPLOSION, localPlayer.getLocation())))) {
&& !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery()
.queryState(localPlayer.getLocation(), (RegionAssociable) null, Flags.OTHER_EXPLOSION))))) {
event.setCancelled(true);
return;
}
Expand All @@ -179,9 +180,11 @@ private void onEntityDamageByBlock(EntityDamageByBlockEvent event) {
if (type == DamageCause.BLOCK_EXPLOSION
&& (wcfg.blockOtherExplosions
|| (wcfg.explosionFlagCancellation
&& !plugin.getGlobalRegionManager().allows(Flags.OTHER_EXPLOSION, BukkitAdapter.adapt(defender.getLocation()))))) {
&& !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery()
.queryState(BukkitAdapter.adapt(defender.getLocation()), (RegionAssociable) null, Flags.OTHER_EXPLOSION))))) {
event.setCancelled(true);
return;

}
}
}
Expand Down

0 comments on commit bd89bd9

Please sign in to comment.