Add option to delete essentials homes when players are kicked from Factions. Adds #1089.

This option is set to true by default in the config.yml for new users, users that are updating need to add delete-ess-homes: true to their config.yml to get this new option enabled.
This commit is contained in:
Trent Hensler 2018-03-18 14:11:42 -07:00
parent 1e2a6b34b4
commit 587182478b
4 changed files with 69 additions and 3 deletions

View File

@ -1,5 +1,6 @@
package com.massivecraft.factions; package com.massivecraft.factions;
import com.earth2me.essentials.IEssentials;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.massivecraft.factions.cmd.CmdAutoHelp; import com.massivecraft.factions.cmd.CmdAutoHelp;
@ -34,7 +35,6 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
public class P extends MPlugin { public class P extends MPlugin {
// Our single plugin instance. // Our single plugin instance.
@ -78,8 +78,19 @@ public class P extends MPlugin {
// Load Conf from disk // Load Conf from disk
Conf.load(); Conf.load();
Essentials.setup();
// Check for Essentials
IEssentials ess = Essentials.setup();
// We set the option to TRUE by default in the config.yml for new users,
// BUT we leave it set to false for users updating that haven't added it to their config.
if (ess != null && getConfig().getBoolean("delete-ess-homes", false)) {
P.p.log(Level.INFO, "Found Essentials. We'll delete player homes in their old Faction's when kicked.");
getServer().getPluginManager().registerEvents(new EssentialsListener(ess), this);
}
hookedPlayervaults = setupPlayervaults(); hookedPlayervaults = setupPlayervaults();
FPlayers.getInstance().load(); FPlayers.getInstance().load();
Factions.getInstance().load(); Factions.getInstance().load();
for (FPlayer fPlayer : FPlayers.getInstance().getAllFPlayers()) { for (FPlayer fPlayer : FPlayers.getInstance().getAllFPlayers()) {

View File

@ -14,11 +14,14 @@ public class Essentials {
private static IEssentials essentials; private static IEssentials essentials;
public static void setup() { public static IEssentials setup() {
Plugin ess = Bukkit.getPluginManager().getPlugin("Essentials"); Plugin ess = Bukkit.getPluginManager().getPlugin("Essentials");
if (ess != null) { if (ess != null) {
essentials = (IEssentials) ess; essentials = (IEssentials) ess;
return essentials;
} }
return null;
} }
// return false if feature is disabled or Essentials isn't available // return false if feature is disabled or Essentials isn't available

View File

@ -0,0 +1,46 @@
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.UUID;
import java.util.logging.Level;
public class EssentialsListener implements Listener {
private final IEssentials ess;
public EssentialsListener(IEssentials essentials) {
this.ess = essentials;
}
@EventHandler
public void onLeave(FPlayerLeaveEvent event) throws Exception {
// Get the USER from their UUID.
Faction faction = event.getFaction();
User user = ess.getUser(UUID.fromString(event.getfPlayer().getId()));
// Not a great way to do this on essential's side.
for (String homeName : user.getHomes()) {
// This can throw an exception for some reason.
Location loc = user.getHome(homeName);
FLocation floc = new FLocation(loc);
// We're only going to remove homes in territory that belongs to THEIR faction.
if (Board.getInstance().getFactionAt(floc).equals(faction)) {
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

@ -20,6 +20,12 @@ findfactionsexploit:
cooldown: 2000 # in miliseconds. 2000 = 2 seconds. cooldown: 2000 # in miliseconds. 2000 = 2 seconds.
log: false log: false
# Essentials Hook
# Should we delete player homes that they set via Essentials when they leave a Faction if they have homes set in that
# Faction's territory?
delete-ess-homes: true
### Hard Core Settings ### ### Hard Core Settings ###
# Many of the features that are / are to come in this section have been requested by # Many of the features that are / are to come in this section have been requested by
# people in relation to HCF servers. All settings are set to the normal Factions # people in relation to HCF servers. All settings are set to the normal Factions