Added chunk unload flag

This commit is contained in:
isokissa3 2017-01-22 18:20:42 +02:00
parent 368f96c51e
commit 031a69a000
4 changed files with 74 additions and 2 deletions

View file

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.goldtreeservers</groupId>
<artifactId>worldguardextraflags</artifactId>
<version>2.11.2</version>
<version>2.12.0</version>
<name>WorldGuardExtraFlags</name>
<build>

View file

@ -1,6 +1,8 @@
package net.goldtreeservers.worldguardextraflags;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.event.entity.EntityToggleGlideEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
@ -8,6 +10,7 @@ import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import com.earth2me.essentials.Essentials;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.BooleanFlag;
@ -17,6 +20,8 @@ import com.sk89q.worldguard.protection.flags.LocationFlag;
import com.sk89q.worldguard.protection.flags.SetFlag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.flags.StringFlag;
import com.sk89q.worldguard.protection.flags.StateFlag.State;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import net.goldtreeservers.worldguardextraflags.flags.BlockedEffectsFlag;
import net.goldtreeservers.worldguardextraflags.flags.CommandOnEntryFlag;
@ -42,6 +47,7 @@ import net.goldtreeservers.worldguardextraflags.listeners.EntityListenerOnePoint
import net.goldtreeservers.worldguardextraflags.listeners.EssentialsListener;
import net.goldtreeservers.worldguardextraflags.listeners.PlayerListener;
import net.goldtreeservers.worldguardextraflags.listeners.WorldEditListener;
import net.goldtreeservers.worldguardextraflags.listeners.WorldListener;
import net.goldtreeservers.worldguardextraflags.utils.PluginUtils;
import net.goldtreeservers.worldguardextraflags.utils.SoundData;
@ -82,6 +88,7 @@ public class WorldGuardExtraFlagsPlugin extends JavaPlugin
public final static SetFlag<Material> allowBlockBreak = new SetFlag<Material>("allow-block-break", new MaterialFlag(null));
public final static SetFlag<Material> denyBlockBreak = new SetFlag<Material>("deny-block-break", new MaterialFlag(null));
public final static StateFlag glide = new StateFlag("glide", false);
public final static StateFlag chunkUnload = new StateFlag("chunk-unload", true);
public WorldGuardExtraFlagsPlugin()
{
@ -132,6 +139,7 @@ public class WorldGuardExtraFlagsPlugin extends JavaPlugin
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.allowBlockBreak);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.denyBlockBreak);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.glide);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.chunkUnload);
}
@Override
@ -154,6 +162,7 @@ public class WorldGuardExtraFlagsPlugin extends JavaPlugin
this.getServer().getPluginManager().registerEvents(new PlayerListener(), this);
this.getServer().getPluginManager().registerEvents(new BlockListener(), this);
this.getServer().getPluginManager().registerEvents(new EntityListener(), this);
this.getServer().getPluginManager().registerEvents(new WorldListener(), this);
try
{
@ -189,6 +198,11 @@ public class WorldGuardExtraFlagsPlugin extends JavaPlugin
{
this.getServer().getPluginManager().registerEvents(new EssentialsListener(), this);
}
for(World world : this.getServer().getWorlds())
{
WorldGuardExtraFlagsPlugin.doUnloadChunkFlagWorldCheck(world);
}
}
public static WorldGuardExtraFlagsPlugin getPlugin()
@ -230,4 +244,26 @@ public class WorldGuardExtraFlagsPlugin extends JavaPlugin
{
return WorldGuardExtraFlagsPlugin.essentialsPlugin;
}
public static void doUnloadChunkFlagWorldCheck(World world)
{
for (ProtectedRegion region : WorldGuardExtraFlagsPlugin.getWorldGuard().getRegionManager(world).getRegions().values())
{
if (region.getFlag(WorldGuardExtraFlagsPlugin.chunkUnload) == State.DENY)
{
System.out.println("Loading chunks for region " + region.getId() + " located in " + world.getName());
Location min = BukkitUtil.toLocation(world, region.getMinimumPoint());
Location max = BukkitUtil.toLocation(world, region.getMaximumPoint());
for(int x = min.getChunk().getX(); x <= max.getChunk().getX(); x++)
{
for(int z = min.getChunk().getZ(); z <= max.getChunk().getZ(); z++)
{
world.getChunkAt(x, z).load(true);
}
}
}
}
}
}

View file

@ -0,0 +1,36 @@
package net.goldtreeservers.worldguardextraflags.listeners;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.event.world.WorldLoadEvent;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldguard.protection.flags.StateFlag.State;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
public class WorldListener implements Listener
{
@EventHandler(priority = EventPriority.MONITOR)
public void onWorldLoadEvent(WorldLoadEvent event)
{
WorldGuardExtraFlagsPlugin.doUnloadChunkFlagWorldCheck(event.getWorld());
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onChunkUnloadEvent(ChunkUnloadEvent event)
{
for (ProtectedRegion region : WorldGuardExtraFlagsPlugin.getWorldGuard().getRegionManager(event.getWorld()).getApplicableRegions(new ProtectedCuboidRegion("UnloadChunkFlagTester", new BlockVector(event.getChunk().getX() * 16, 0, event.getChunk().getZ() * 16), new BlockVector(event.getChunk().getX() * 16 + 15, 256, event.getChunk().getZ() * 16 + 15))))
{
if (region.getFlag(WorldGuardExtraFlagsPlugin.chunkUnload) == State.DENY)
{
event.setCancelled(true);
break;
}
}
}
}

View file

@ -1,5 +1,5 @@
name: WorldGuardExtraFlags
version: 2.11.2
version: 2.12.0
description: Add more flags to worldguard to help manage your server easily!
author: isokissa3
authors: [isokissa3]