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
Expand Up @@ -206,7 +206,7 @@ void playerQuit(final PlayerQuitEvent event) {
));
profileDataSource.setLoadOnLogin(player.getUniqueId(), true);
}
SingleShareWriter.of(this.inventories, player, Sharables.LAST_LOCATION).write(player.getLocation());
SingleShareWriter.of(this.inventories, player, Sharables.LAST_LOCATION).write(player.getLocation().clone());
}

private void verifyCorrectWorld(Player player, String world, GlobalProfile globalProfile) {
Expand All @@ -233,7 +233,7 @@ void playerGameModeChange(PlayerGameModeChangeEvent event) {
return;
}
Player player = event.getPlayer();
SingleShareWriter.of(this.inventories, player, Sharables.LAST_LOCATION).write(player.getLocation());
SingleShareWriter.of(this.inventories, player, Sharables.LAST_LOCATION).write(player.getLocation().clone());
new GameModeShareHandler(this.inventories, player,
player.getGameMode(), event.getNewGameMode()).handleSharing();
}
Expand Down Expand Up @@ -279,7 +279,7 @@ void playerTeleport(PlayerTeleportEvent event) {
}

Player player = event.getPlayer();
SingleShareWriter.of(this.inventories, player, Sharables.LAST_LOCATION).write(event.getFrom());
SingleShareWriter.of(this.inventories, player, Sharables.LAST_LOCATION).write(event.getFrom().clone());

// Possibly prevents item duping exploit
player.closeInventory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
import org.bukkit.entity.Player;
import org.mvplugins.multiverse.inventories.MultiverseInventories;
import org.mvplugins.multiverse.inventories.config.InventoriesConfig;
import org.mvplugins.multiverse.inventories.profile.PlayerProfile;
import org.mvplugins.multiverse.inventories.profile.ProfileDataSource;
import org.mvplugins.multiverse.inventories.profile.container.ContainerType;
import org.mvplugins.multiverse.inventories.profile.container.ProfileContainerStoreProvider;
import org.mvplugins.multiverse.inventories.profile.group.WorldGroupManager;
import org.mvplugins.multiverse.inventories.share.Sharable;

import java.util.Objects;

/**
* Write a single share to the relevant world and group profiles.
*
Expand All @@ -23,14 +27,20 @@ public static <T> SingleShareWriter<T> of(MultiverseInventories inventories, Pla
private final MultiverseInventories inventories;
private final Player player;
private final Sharable<T> sharable;
private final ProfileDataSource profileDataSource;

private SingleShareWriter(MultiverseInventories inventories, Player player, Sharable<T> sharable) {
this.inventories = inventories;
this.player = player;
this.sharable = sharable;
this.profileDataSource = inventories.getServiceLocator().getService(ProfileDataSource.class);
}

public void write(T value) {
write(value, false);
}

public void write(T value, boolean save) {
if (sharable.isOptional() &&
!inventories.getServiceLocator().getService(InventoriesConfig.class).getOptionalShares().contains(sharable)) {
Logging.finer("Skipping write for optional share: " + sharable);
Expand All @@ -39,15 +49,31 @@ public void write(T value) {
Logging.finer("Writing single share: " + sharable.getNames()[0]);
String worldName = this.player.getWorld().getName();
var profileContainerStoreProvider = this.inventories.getServiceLocator().getService(ProfileContainerStoreProvider.class);
profileContainerStoreProvider.getStore(ContainerType.WORLD)
.getContainer(worldName)
.getPlayerData(this.player)
.set(this.sharable, value);
writeNewValueToProfile(
profileContainerStoreProvider.getStore(ContainerType.WORLD)
.getContainer(worldName)
.getPlayerData(this.player),
value,
save
);

this.inventories.getServiceLocator().getService(WorldGroupManager.class)
.getGroupsForWorld(worldName)
.forEach(worldGroup ->
worldGroup.getGroupProfileContainer().getPlayerData(this.player)
.set(this.sharable, value));
.forEach(worldGroup -> writeNewValueToProfile(
worldGroup.getGroupProfileContainer().getPlayerData(this.player),
value,
save
));
}

private void writeNewValueToProfile(PlayerProfile profile, T value, boolean save) {
if (Objects.equals(profile.get(sharable), value)) {
return;
}
Logging.finest("Writing %s value: %s for profile %s", sharable, value, profile);
profile.set(sharable, value);
if (save) {
profileDataSource.updatePlayerData(profile);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ public SpawnChangeListener(MultiverseInventories inventories) {
@EventHandler(priority = EventPriority.MONITOR)
void onSpawnChange(PlayerSpawnChangeEvent event) {
Player player = event.getPlayer();

Logging.fine("Respawn cause: %s", event.getCause());

if (event.getCause() == Cause.BED) {
updatePlayerSpawn(player, findBedFromRespawnLocation(event.getNewSpawn()));
return;
Expand All @@ -47,6 +44,7 @@ void onSpawnChange(PlayerSpawnChangeEvent event) {
}

private void updatePlayerSpawn(Player player, Location location) {
SingleShareWriter.of(this.inventories, player, Sharables.BED_SPAWN).write(location);
SingleShareWriter.of(this.inventories, player, Sharables.BED_SPAWN)
.write(location == null ? null : location.clone(), true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,14 @@ public PlayerProfile clone() {
public Map<Sharable, Object> getData() {
return data;
}

@Override
public String toString() {
return "PlayerProfile{" +
"player=" + player.getName() +
", containerType=" + containerType +
", containerName='" + containerName + '\'' +
", profileType=" + profileType +
'}';
}
}