Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package org.mvplugins.multiverse.inventories;

import com.dumptruckman.minecraft.util.Logging;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
import org.jvnet.hk2.annotations.Service;
import org.mvplugins.multiverse.core.event.MVConfigReloadEvent;
import org.mvplugins.multiverse.core.event.MVDebugModeEvent;
import org.mvplugins.multiverse.core.event.MVDumpsDebugInfoEvent;
import org.mvplugins.multiverse.external.jakarta.inject.Inject;
import org.mvplugins.multiverse.inventories.config.InventoriesConfig;
import org.mvplugins.multiverse.inventories.profile.group.WorldGroup;
import org.mvplugins.multiverse.inventories.profile.group.WorldGroupManager;

import java.io.File;

@Service
final class MVEventsListener implements Listener {

private final MultiverseInventories inventories;
private final InventoriesConfig config;
private final WorldGroupManager worldGroupManager;

@Inject
MVEventsListener(@NotNull MultiverseInventories inventories, @NotNull InventoriesConfig config, @NotNull WorldGroupManager worldGroupManager) {
this.inventories = inventories;
this.config = config;
this.worldGroupManager = worldGroupManager;
}

/**
* Adds Multiverse-Inventories version info to /mv version.
*
* @param event The MVVersionEvent that this plugin will listen for.
*/
@EventHandler
void dumpsDebugInfoRequest(MVDumpsDebugInfoEvent event) {
event.appendDebugInfo(getDebugInfo());
File configFile = new File(this.inventories.getDataFolder(), "config.yml");
File groupsFile = new File(this.inventories.getDataFolder(), "groups.yml");
event.putDetailedDebugInfo("multiverse-inventories/config.yml", configFile);
event.putDetailedDebugInfo("multiverse-inventories/groups.yml", groupsFile);
}

/**
* Builds a String containing Multiverse-Inventories' version info.
*
* @return The version info.
*/
private String getDebugInfo() {
StringBuilder versionInfo = new StringBuilder("[Multiverse-Inventories] Multiverse-Inventories Version: " + inventories.getDescription().getVersion() + '\n'
+ "[Multiverse-Inventories] === Settings ===" + '\n'
+ "[Multiverse-Inventories] First Run: " + config.getFirstRun() + '\n'
+ "[Multiverse-Inventories] Using Bypass: " + config.getEnableBypassPermissions() + '\n'
+ "[Multiverse-Inventories] Default Ungrouped Worlds: " + config.getDefaultUngroupedWorlds() + '\n'
+ "[Multiverse-Inventories] Save and Load on Log In and Out: " + config.getSavePlayerdataOnQuit() + '\n'
+ "[Multiverse-Inventories] Using GameMode Profiles: " + config.getEnableGamemodeShareHandling() + '\n'
+ "[Multiverse-Inventories] === Shares ===" + '\n'
+ "[Multiverse-Inventories] Optionals for Ungrouped Worlds: " + config.getUseOptionalsForUngroupedWorlds() + '\n'
+ "[Multiverse-Inventories] Enabled Optionals: " + config.getActiveOptionalShares() + '\n'
+ "[Multiverse-Inventories] === Groups ===" + '\n');

for (WorldGroup group : worldGroupManager.getGroups()) {
versionInfo.append("[Multiverse-Inventories] ").append(group.toString()).append('\n');
}

return versionInfo.toString();
}

@EventHandler
void onDebugModeChange(MVDebugModeEvent event) {
Logging.setDebugLevel(event.getLevel());
}

/**
* Hooks Multiverse-Inventories into the Multiverse reload command.
*
* @param event The MVConfigReloadEvent that this plugin will listen for.
*/
@EventHandler
void configReload(MVConfigReloadEvent event) {
this.inventories.reloadConfig();
event.addConfig("Multiverse-Inventories - config.yml");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public class MultiverseInventories extends MultiversePlugin {
@Inject
private Provider<RespawnListener> respawnListener;
@Inject
private Provider<MVEventsListener> mvEventsListener;
@Inject
private Provider<WorldGroupManager> worldGroupManager;
@Inject
private Provider<ProfileDataSource> profileDataSource;
Expand Down Expand Up @@ -88,6 +90,7 @@ public final void onEnable() {
super.onEnable();

initializeDependencyInjection();
Sharables.init(this);
Perm.register(this);
this.reloadConfig();
inventoriesConfig.get().save().onFailure(e -> Logging.severe("Failed to save config file!"));
Expand All @@ -96,21 +99,22 @@ public final void onEnable() {
PluginManager pluginManager = this.getServer().getPluginManager();
pluginManager.registerEvents(shareHandleListener.get(), this);
pluginManager.registerEvents(respawnListener.get(), this);
try {
Class.forName("org.bukkit.event.player.PlayerSpawnChangeEvent");
pluginManager.registerEvents(new SpawnChangeListener(this), this);
usingSpawnChangeEvent = true;
Logging.fine("Yayy PlayerSpawnChangeEvent will be used!");
} catch (ClassNotFoundException e) {
Logging.fine("PlayerSpawnChangeEvent will not be used!");
usingSpawnChangeEvent = false;
pluginManager.registerEvents(mvEventsListener.get(), this);
if (inventoriesConfig.get().getUseImprovedRespawnLocationDetection()) {
try {
Class.forName("org.bukkit.event.player.PlayerSpawnChangeEvent");
pluginManager.registerEvents(new SpawnChangeListener(this), this);
usingSpawnChangeEvent = true;
Logging.fine("Yayy PlayerSpawnChangeEvent will be used!");
} catch (ClassNotFoundException e) {
Logging.fine("PlayerSpawnChangeEvent will not be used!");
}
}

// Register Commands
this.registerCommands();
// Hook plugins that can be imported from
this.hookImportables();
Sharables.init(this);
this.dupingPatch = InventoriesDupingPatch.enableDupingPatch(this);

Logging.config("Version %s (API v%s) Enabled - By %s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,43 @@ public Try<Void> setActiveOptionalShares(Shares shares) {
return this.configHandle.set(configNodes.activeOptionalShares, shares);
}

public boolean getUseImprovedRespawnLocationDetection() {
return this.configHandle.get(configNodes.useImprovedRespawnLocationDetection);
}

public Try<Void> setUseImprovedRespawnLocationDetection(boolean useImprovedRespawnLocationDetection) {
return this.configHandle.set(configNodes.useImprovedRespawnLocationDetection, useImprovedRespawnLocationDetection);
}

public boolean getResetLastLocationOnDeath() {
return this.configHandle.get(configNodes.resetLastLocationOnDeath);
}

public Try<Void> setResetLastLocationOnDeath(boolean resetLastLocationOnDeath) {
return this.configHandle.set(configNodes.resetLastLocationOnDeath, resetLastLocationOnDeath);
}

public boolean getApplyLastLocationForAllTeleports() {
return this.configHandle.get(configNodes.applyLastLocationForAllTeleports);
}

public Try<Void> setApplyLastLocationForAllTeleports(boolean applyLastLocationForAllTeleports) {
return this.configHandle.set(configNodes.applyLastLocationForAllTeleports, applyLastLocationForAllTeleports);
}

/**
* Tells whether Multiverse-Inventories should save on player logout and load on player login.
* Tells whether Multiverse-Inventories should save on player logout.
*
* @return True if should save and load on player log out and in.
* @return True if should save on player log out.
*/
public boolean getSavePlayerdataOnQuit() {
return this.configHandle.get(configNodes.savePlayerdataOnQuit);
}

/**
* Sets whether Multiverse-Inventories should save on player logout and load on player login.
* Sets whether Multiverse-Inventories should save on player logout.
*
* @param useLoggingSaveLoad true if should save and load on player log out and in.
* @param useLoggingSaveLoad true if should save on player log out.
*/
public Try<Void> setSavePlayerdataOnQuit(boolean useLoggingSaveLoad) {
return this.configHandle.set(configNodes.savePlayerdataOnQuit, useLoggingSaveLoad);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,36 @@ public Object serialize(Shares sharables, Class<Shares> aClass) {
return sharables.toStringList();
}
})
.onSetValue((oldValue, newValue) -> Sharables.recalculateEnabledShares())
.build());

private final ConfigHeaderNode sharablesHeader = node(ConfigHeaderNode.builder("sharables")
.comment("")
.comment("")
.build());

final ConfigNode<Boolean> useImprovedRespawnLocationDetection = node(ConfigNode.builder("sharables.use-improved-respawn-location-detection", Boolean.class)
.comment("")
.comment("When enabled, we will use 1.21's PlayerSpawnChangeEvent to better detect bed and anchor respawn locations.")
.comment("This options is not applicable for older minecraft server versions.")
.defaultValue(true)
.name("use-improved-respawn-location-detection")
.build());

final ConfigNode<Boolean> resetLastLocationOnDeath = node(ConfigNode.builder("sharables.reset-last-location-on-death", Boolean.class)
.comment("When set to true, the last location of the player will be reset when they die.")
.comment("This is useful if they respawn in a different world and you do not want them to return to their death location.")
.defaultValue(false)
.name("reset-last-location-on-death")
.build());

final ConfigNode<Boolean> applyLastLocationForAllTeleports = node(ConfigNode.builder("sharables.apply-last-location-for-all-teleports", Boolean.class)
.comment("")
.comment("When enabled, the last location of the player will be applied for any teleportation.")
.comment("This is useful as you want to use the last location for any teleportation, such as the warp system.")
.comment("When disabled, you can only use `/mvinv tplastlocation [player] <world>` to teleport to the player's last location.")
.defaultValue(true)
.name("apply-last-location-for-all-teleports")
.build());

private final ConfigHeaderNode performanceHeader = node(ConfigHeaderNode.builder("performance")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.LinkedList;
import java.util.List;

import static org.mvplugins.multiverse.inventories.share.Sharables.allOf;
import static org.mvplugins.multiverse.inventories.share.Sharables.enabled;

public final class AffectedProfiles {

Expand All @@ -18,7 +18,7 @@ public final class AffectedProfiles {
}

void setAlwaysWriteProfile(PlayerProfile profile) {
alwaysWriteProfile = new PersistingProfile(allOf(), profile);
alwaysWriteProfile = new PersistingProfile(enabled(), profile);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ final class GameModeShareHandler extends ShareHandler {
this.toType = ProfileTypes.forGameMode(toGameMode);
this.world = player.getWorld().getName();
this.worldGroups = getAffectedWorldGroups();

prepareProfiles();
}

private List<WorldGroup> getAffectedWorldGroups() {
Expand All @@ -49,11 +47,12 @@ protected ShareHandlingEvent createEvent() {
return new GameModeChangeShareHandlingEvent(player, affectedProfiles, fromGameMode, toGameMode);
}

private void prepareProfiles() {
@Override
protected void prepareProfiles() {
Logging.finer("=== " + player.getName() + " changing game mode from: " + fromType
+ " to: " + toType + " for world: " + world + " ===");

setAlwaysWriteProfile(worldProfileContainerStore.getContainer(world).getPlayerData(fromType, player));
affectedProfiles.setAlwaysWriteProfile(worldProfileContainerStore.getContainer(world).getPlayerData(fromType, player));

if (isPlayerAffectedByChange()) {
addProfiles();
Expand All @@ -78,8 +77,8 @@ private void addProfiles() {
worldGroups.forEach(this::addProfilesForWorldGroup);
} else {
Logging.finer("No groups for world.");
addReadProfile(worldProfileContainerStore.getContainer(world).getPlayerData(toType, player),
Sharables.allOf());
affectedProfiles.addReadProfile(worldProfileContainerStore.getContainer(world).getPlayerData(toType, player),
inventoriesConfig.getUseOptionalsForUngroupedWorlds() ? Sharables.enabled() : Sharables.standardOf());
}
}

Expand All @@ -89,8 +88,7 @@ private boolean hasWorldGroups() {

private void addProfilesForWorldGroup(WorldGroup worldGroup) {
ProfileContainer container = worldGroup.getGroupProfileContainer();
addWriteProfile(container.getPlayerData(fromType, player), Sharables.allOf());
addReadProfile(container.getPlayerData(toType, player), Sharables.allOf());
affectedProfiles.addWriteProfile(container.getPlayerData(fromType, player), Sharables.enabled());
affectedProfiles.addReadProfile(container.getPlayerData(toType, player), Sharables.enabled());
}
}

Loading
Loading