Remove Maven

This commit is contained in:
Olof Larsson
2015-01-19 09:58:25 +01:00
parent 5e4a42d2ac
commit c81d7d8794
177 changed files with 42 additions and 70 deletions

View File

@@ -0,0 +1,158 @@
package com.massivecraft.factions.integration.lwc;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.plugin.Plugin;
import com.griefcraft.lwc.LWC;
import com.griefcraft.model.Protection;
import com.griefcraft.sql.PhysDB;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.event.EventFactionsChunksChange;
import com.massivecraft.factions.event.EventFactionsChunkChangeType;
import com.massivecraft.massivecore.EngineAbstract;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.IdUtil;
public class EngineLwc extends EngineAbstract
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineLwc i = new EngineLwc();
public static EngineLwc get() { return i; }
private EngineLwc() {}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public Plugin getPlugin()
{
return Factions.get();
}
@Override
public void activate()
{
super.activate();
LWC.getInstance().getModuleLoader().registerModule(Factions.get(), new FactionsLwcModule(Factions.get()));
}
@Override
public void deactivate()
{
super.deactivate();
LWC.getInstance().getModuleLoader().removeModules(Factions.get());
}
// -------------------------------------------- //
// LISTENER
// -------------------------------------------- //
public void removeProtectionsOnChunkChange(Faction newFaction, EventFactionsChunkChangeType type, Set<PS> chunks)
{
// If we are supposed to clear at this chunk change type ...
Boolean remove = MConf.get().lwcRemoveOnChange.get(type);
if (remove == null) return;
if (remove == false) return;
// ... then remove for all other factions than the new one.
// First we wait one tick to make sure the chunk ownership changes have been applied.
// Then we remove the protections but we do it asynchronously to not lock the main thread.
for (PS chunk : chunks)
{
removeAlienProtectionsAsyncNextTick(chunk, newFaction);
}
}
public void removeProtectionsOnChunkChange(Faction newFaction, Map<EventFactionsChunkChangeType, Set<PS>> typeChunks)
{
for (Entry<EventFactionsChunkChangeType, Set<PS>> typeChunk : typeChunks.entrySet())
{
final EventFactionsChunkChangeType type = typeChunk.getKey();
final Set<PS> chunks = typeChunk.getValue();
removeProtectionsOnChunkChange(newFaction, type, chunks);
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void removeProtectionsOnChunkChange(EventFactionsChunksChange event)
{
removeProtectionsOnChunkChange(event.getNewFaction(), event.getTypeChunks());
}
// -------------------------------------------- //
// UTIL
// -------------------------------------------- //
// This method causes LWC to run an SQL query which can take a few milliseconds.
// For that reason this method should not be executed in the main server thread.
// After looking through the source code of LWC I am also hopeful this is thread safe.
public static List<Protection> getProtectionsInChunk(PS chunkPs)
{
final int xmin = chunkPs.getChunkX() * 16;
final int xmax = xmin + 15;
final int ymin = 0;
final int ymax = 255;
final int zmin = chunkPs.getChunkZ() * 16;
final int zmax = zmin + 15;
PhysDB db = LWC.getInstance().getPhysicalDatabase();
return db.loadProtections(chunkPs.getWorld(), xmin, xmax, ymin, ymax, zmin, zmax);
}
// As with the method above: Thread safe and slow. Do run asynchronously.
public static void removeAlienProtectionsRaw(PS chunkPs, Faction faction)
{
List<MPlayer> nonAliens = faction.getMPlayers();
for (Protection protection : getProtectionsInChunk(chunkPs))
{
// NOTE: The LWC protection owner is still the name and not the UUID. For that reason we must convert it.
String ownerName = protection.getOwner();
String ownerId = IdUtil.getId(ownerName);
MPlayer owner = MPlayer.get(ownerId);
if (nonAliens.contains(owner)) continue;
protection.remove();
}
}
public static void removeAlienProtectionsAsync(final PS chunkPs, final Faction faction)
{
Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable()
{
@Override
public void run()
{
removeAlienProtectionsRaw(chunkPs, faction);
}
});
}
public static void removeAlienProtectionsAsyncNextTick(final PS chunkPs, final Faction faction)
{
Bukkit.getScheduler().runTaskLater(Factions.get(), new Runnable()
{
@Override
public void run()
{
removeAlienProtectionsAsync(chunkPs, faction);
}
}, 0);
}
}

View File

@@ -0,0 +1,104 @@
package com.massivecraft.factions.integration.lwc;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import com.griefcraft.lwc.LWC;
import com.griefcraft.model.Protection;
import com.griefcraft.scripting.JavaModule;
import com.griefcraft.scripting.event.LWCProtectionInteractEvent;
import com.griefcraft.scripting.event.LWCProtectionRegisterEvent;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.engine.EngineMain;
import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.mixin.Mixin;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.IdUtil;
import com.massivecraft.massivecore.util.SmokeUtil;
import com.massivecraft.massivecore.util.Txt;
@SuppressWarnings("unused")
public class FactionsLwcModule extends JavaModule
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
// These plugin variables must be present.
// They are set by LWC using reflection somehow.
private Factions plugin;
private LWC lwc;
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public FactionsLwcModule(Factions plugin)
{
this.plugin = plugin;
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
//
@Override
public void onRegisterProtection(LWCProtectionRegisterEvent event)
{
// If this feature is enabled ...
if ( ! MConf.get().lwcMustHaveBuildRightsToCreate) return;
// ... and the player don't have build rights here ...
// NOTE: We verbosely check the build rights so that a proper info message is sent
if (EngineMain.canPlayerBuildAt(event.getPlayer(), PS.valueOf(event.getBlock()), true)) return;
// ... then cancel the event.
event.setCancelled(true);
}
@Override
public void onProtectionInteract(LWCProtectionInteractEvent event)
{
// If this feature is enabled ...
if ( ! MConf.get().lwcRemoveIfNoBuildRights) return;
// ... gather data ...
final Protection protection = event.getProtection();
final Block block = protection.getBlock();
final PS ps = PS.valueOf(block);
// NOTE: The LWC protection owner is still the name and not the UUID. For that reason we must convert it.
final String ownerName = protection.getOwner();
final String ownerId = IdUtil.getId(ownerName);
final MPlayer mowner = MPlayer.get(ownerId);
if (mowner == null) return;
// ... and if the protection owner no longer has build rights for the area ...
// NOTE: We silently check the build rights for the protection owner.
// NOTE: The protection owner may even be offline at the moment.
if (EngineMain.canPlayerBuildAt(mowner, ps, false)) return;
// ... remove the protection ...
protection.remove();
// ... cancel the event ...
// NOTE: The first time you click nothing but the unlock should happen.
// NOTE: This way it's more obvious the auto unlock system kicked in.
// NOTE: No inventory will get opened.
event.setResult(Result.CANCEL);
// ... play FX ...
Location location = block.getLocation();
SmokeUtil.spawnCloudSimple(location);
location.getWorld().playSound(location, Sound.DOOR_OPEN, 1, 1);
// ... and inform.
Player player = event.getPlayer();
String message = Txt.parse("<i>Factions removed <h>%s's <i>LWC. They lacked build rights.", mowner.getDisplayName(player));
player.sendMessage(message);
}
}

View File

@@ -0,0 +1,31 @@
package com.massivecraft.factions.integration.lwc;
import com.massivecraft.massivecore.integration.IntegrationAbstract;
public class IntegrationLwc extends IntegrationAbstract
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static IntegrationLwc i = new IntegrationLwc();
public static IntegrationLwc get() { return i; }
private IntegrationLwc() { super("LWC"); }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void activate()
{
EngineLwc.get().activate();
}
@Override
public void deactivate()
{
EngineLwc.get().deactivate();
}
}