Essentials Home Removal on Player Leave
This commit is contained in:
parent
a10864015c
commit
84f4e0f732
@ -84,6 +84,7 @@ public class Conf {
|
||||
public static String modChatFormat = ChatColor.RED + "%s:" + ChatColor.WHITE + " %s";
|
||||
public static int stealthFlyCheckRadius = 32;
|
||||
public static int factionBufferSize = 20;
|
||||
public static boolean removeHomesOnLeave = true;
|
||||
public static boolean gracePeriod = false;
|
||||
public static boolean noEnderpearlsInFly = false;
|
||||
public static boolean broadcastDescriptionChanges = false;
|
||||
|
@ -2,12 +2,14 @@ package com.massivecraft.factions;
|
||||
|
||||
import ch.njol.skript.Skript;
|
||||
import ch.njol.skript.SkriptAddon;
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.massivecraft.factions.cmd.CmdAutoHelp;
|
||||
import com.massivecraft.factions.cmd.FCmdRoot;
|
||||
import com.massivecraft.factions.cmd.chest.ChestLogsHandler;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.factions.integration.Essentials;
|
||||
import com.massivecraft.factions.integration.Worldguard;
|
||||
import com.massivecraft.factions.integration.dynmap.EngineDynmap;
|
||||
import com.massivecraft.factions.listeners.*;
|
||||
@ -264,6 +266,12 @@ public class P extends MPlugin {
|
||||
for (Listener eventListener : eventsListener)
|
||||
getServer().getPluginManager().registerEvents(eventListener, this);
|
||||
|
||||
IEssentials ess = Essentials.setup();
|
||||
|
||||
if(ess != null && Conf.removeHomesOnLeave){
|
||||
getServer().getPluginManager().registerEvents(new EssentialsHomeHandler(ess), this);
|
||||
}
|
||||
|
||||
// since some other plugins execute commands directly through this command interface, provide it
|
||||
getCommand(this.refCommand).setExecutor(this);
|
||||
getCommand(this.refCommand).setTabCompleter(this);
|
||||
|
@ -19,11 +19,12 @@ public class Essentials {
|
||||
|
||||
private static IEssentials essentials;
|
||||
|
||||
public static void setup() {
|
||||
public static IEssentials setup() {
|
||||
Plugin ess = Bukkit.getPluginManager().getPlugin("Essentials");
|
||||
if (ess != null) {
|
||||
essentials = (IEssentials) ess;
|
||||
return Essentials.essentials = (IEssentials)ess;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isOverBalCap(EconomyParticipator participator, double amount) {
|
||||
|
@ -0,0 +1,44 @@
|
||||
package com.massivecraft.factions.listeners;
|
||||
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.massivecraft.factions.Board;
|
||||
import com.massivecraft.factions.FLocation;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.P;
|
||||
import com.massivecraft.factions.event.FPlayerLeaveEvent;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class EssentialsHomeHandler implements Listener {
|
||||
|
||||
private IEssentials ess;
|
||||
|
||||
public EssentialsHomeHandler(IEssentials essentials) {
|
||||
this.ess = essentials;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLeave(FPlayerLeaveEvent event) throws Exception {
|
||||
Faction faction = event.getFaction();
|
||||
User user = ess.getUser(UUID.fromString(event.getfPlayer().getId()));
|
||||
List<String> homes = user.getHomes();
|
||||
if (homes == null || homes.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (String homeName : user.getHomes()) {
|
||||
Location loc = user.getHome(homeName);
|
||||
FLocation floc = new FLocation(loc);
|
||||
Faction factionAt = Board.getInstance().getFactionAt(floc);
|
||||
if (factionAt.equals(faction) && factionAt.isNormal()) {
|
||||
user.delHome(homeName);
|
||||
P.p.log(Level.INFO, "FactionLeaveEvent: Removing home %s, player %s, in territory of %s", homeName, event.getfPlayer().getName(), faction.getTag());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -28,6 +28,7 @@ public enum Permission {
|
||||
CORNER("corner"),
|
||||
DEFAULTRANK("defaultrank"),
|
||||
DEINVITE("deinvite"),
|
||||
DELHOME("delhome"),
|
||||
DESCRIPTION("description"),
|
||||
DISBAND("disband"),
|
||||
DISBAND_ANY("disband.any"),
|
||||
|
Loading…
Reference in New Issue
Block a user