Essentials Home Removal on Player Leave

This commit is contained in:
Driftay 2019-08-24 12:23:04 -04:00
parent a10864015c
commit 84f4e0f732
5 changed files with 57 additions and 2 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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) {

View File

@ -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());
}
}
}
}

View File

@ -28,6 +28,7 @@ public enum Permission {
CORNER("corner"),
DEFAULTRANK("defaultrank"),
DEINVITE("deinvite"),
DELHOME("delhome"),
DESCRIPTION("description"),
DISBAND("disband"),
DISBAND_ANY("disband.any"),