Skip to content

Commit

Permalink
Update hook dependencies, fix bad HuskHomes hook logic
Browse files Browse the repository at this point in the history
  • Loading branch information
WiIIiam278 committed Dec 17, 2022
1 parent 4752d3d commit a1f1382
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 37 deletions.
4 changes: 2 additions & 2 deletions bukkit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ dependencies {
compileOnly 'xyz.jpenilla:squaremap-api:1.1.8'
compileOnly 'com.github.MilkBowl:VaultAPI:1.7.1'
compileOnly 'net.luckperms:api:5.4'
compileOnly 'net.william278:HuskHomes2:3.0.2'
compileOnly 'com.github.Emibergo02:RedisEconomy:2.1-9d36505cbb-1'
compileOnly 'net.william278:HuskHomes2:3.2.1'
compileOnly 'com.github.Emibergo02:RedisEconomy:9f4f9c86f4'
}

shadowJar {
Expand Down
22 changes: 16 additions & 6 deletions bukkit/src/main/java/net/william278/husktowns/HuskTowns.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public static PlayerList getPlayerList() {
private static Settings settings;

private VaultHook economyHook;
private HuskHomesHook huskHomesHook;

public void reloadSettings() throws IOException {
settings = new Settings(YamlDocument.create(new File(getDataFolder(), "config.yml"),
Expand Down Expand Up @@ -266,7 +267,7 @@ public void onEnable() {
getLatestVersionIfOutdated().thenAccept(newestVersion ->
newestVersion.ifPresent(newVersion -> getLogger().log(Level.WARNING,
"An update is available for HuskHomes, v" + newVersion
+ " (Currently running v" + getDescription().getVersion() + ")")));
+ " (Currently running v" + getDescription().getVersion() + ")")));
}

// Fetch plugin messages from file
Expand Down Expand Up @@ -304,25 +305,29 @@ public void onEnable() {


// Setup Economy integration
if(Bukkit.getPluginManager().getPlugin("RedisEconomy")!=null){
if (Bukkit.getPluginManager().getPlugin("RedisEconomy") != null) {
economyHook = new RedisEconomyHook(this);
}else{
} else {
economyHook = new VaultHook(this);
}

getSettings().doEconomy = (getSettings().doEconomy && economyHook.initialize());

// Setup HuskHomes integration
getSettings().doHuskHomes = (getSettings().doHuskHomes && HuskHomesHook.initialize());
if (Bukkit.getPluginManager().getPlugin("HuskHomes") != null) {
if (getSettings().doHuskHomes) {
huskHomesHook = new HuskHomesHook();
}
}

// Initialise caches & cached data
initializeCaches();

// Register events via listener classes
getServer().getPluginManager().registerEvents(new EventListener(), this);
if (getSettings().doHuskHomes && getSettings().disableHuskHomesSetHomeInOtherTown) {
if (huskHomesHook != null && getSettings().disableHuskHomesSetHomeInOtherTown) {
try {
getServer().getPluginManager().registerEvents(new HuskHomesHook(), this);
getServer().getPluginManager().registerEvents(huskHomesHook, this);
} catch (IllegalPluginAccessException e) {
getLogger().log(Level.WARNING, "Your version of HuskHomes is not compatible with HuskTowns.\nPlease update to HuskHomes v1.4.2+; certain features will not work.");
}
Expand Down Expand Up @@ -397,7 +402,12 @@ public CompletableFuture<Optional<Version>> getLatestVersionIfOutdated() {
}
});
}

public VaultHook getEconomyHook() {
return economyHook;
}

public HuskHomesHook getHuskHomesHook() {
return huskHomesHook;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.william278.huskhomes.position.Position;
import net.william278.huskhomes.position.Server;
import net.william278.huskhomes.position.World;
import net.william278.huskhomes.teleport.TimedTeleport;
import net.william278.husktowns.HuskTowns;
import net.william278.husktowns.MessageManager;
import net.william278.husktowns.chunk.ClaimedChunk;
Expand All @@ -14,47 +15,32 @@
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;

import java.time.Instant;
import java.util.UUID;

public class HuskHomesHook implements Listener {

private static HuskHomesAPI huskHomesAPI;
private static final HuskTowns plugin = HuskTowns.getInstance();
private final HuskHomesAPI huskHomes;

public static boolean initialize() {
if (!HuskTowns.getSettings().doHuskHomes) {
return false;
}
Plugin huskHomesPlugin = Bukkit.getPluginManager().getPlugin("HuskHomes");
if (huskHomesPlugin == null) {
plugin.getConfig().set("integrations.huskhomes.enabled", false);
plugin.saveConfig();
return false;
}
if (!huskHomesPlugin.isEnabled()) {
plugin.getConfig().set("integrations.huskhomes.enabled", false);
plugin.saveConfig();
return false;
}
huskHomesAPI = HuskHomesAPI.getInstance();
return true;
public HuskHomesHook() {
this.huskHomes = HuskHomesAPI.getInstance();
}

public static void queueTeleport(Player player, TeleportationPoint point) {
huskHomesAPI.teleportPlayer(huskHomesAPI.adaptUser(player),
new Position(point.getX(), point.getY(), point.getZ(),
public void queueTeleport(Player player, TeleportationPoint point) {
huskHomes.teleportBuilder(huskHomes.adaptUser(player))
.setTarget(new Position(point.getX(), point.getY(), point.getZ(),
point.getYaw(), point.getPitch(),
new World(point.getWorldName(), UUID.randomUUID()),
new Server(point.getServer())), true);
new Server(point.getServer())))
.toTimedTeleport()
.thenAccept(TimedTeleport::execute);
}

@EventHandler
public void onPlayerSetHome(HomeSaveEvent e) {
final Player player = Bukkit.getPlayer(e.getHome().owner.uuid);
final Location location = huskHomesAPI.getLocation(e.getHome());
final Location location = huskHomes.getLocation(e.getHome());
final String playerTown = HuskTowns.getPlayerCache().getPlayerTown(e.getHome().owner.uuid);
final ClaimedChunk chunk = HuskTowns.getClaimCache().getChunkAt(location.getChunk().getX(),
location.getChunk().getZ(), e.getHome().world.name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,13 @@ public void run() {
}

public static void teleportPlayer(Player player, TeleportationPoint point) {
if (HuskTowns.getSettings().doHuskHomes) {
Bukkit.getScheduler().runTask(plugin, () -> HuskHomesHook.queueTeleport(player, point));
} else {
queueTeleport(player, point);
final HuskHomesHook hook = plugin.getHuskHomesHook();
if (hook != null) {
hook.queueTeleport(player, point);
return;
}

queueTeleport(player, point);
}

}

0 comments on commit a1f1382

Please sign in to comment.