Skip to content

Commit

Permalink
Don't default to ProfileType SURVIVAL for spectator gamemode change.
Browse files Browse the repository at this point in the history
This improves performance slightly as it doesnt rewrite SURVIVAL to SURVIVAL when changing from survival to spectator. There is no need to read or write anything to gamemode spectator.
  • Loading branch information
benwoo1110 committed Jul 15, 2021
1 parent 207790f commit c5fc189
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.multiverseinventories.event.ShareHandlingEvent;
import com.onarandombox.multiverseinventories.profile.PlayerProfile;
import com.onarandombox.multiverseinventories.profile.ProfileTypes;
import com.onarandombox.multiverseinventories.share.PersistingProfile;
import com.onarandombox.multiverseinventories.share.Shares;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -42,15 +43,19 @@ final void handleSharing() {
}

protected final void setAlwaysWriteProfile(PlayerProfile profile) {
affectedProfiles.setAlwaysWriteProfile(profile);
if (!profile.getProfileType().equals(ProfileTypes.NONE)) {
affectedProfiles.setAlwaysWriteProfile(profile);
}
}

/**
* @param profile The player profile that will need data saved to.
* @param shares What from this group needs to be saved.
*/
protected final void addWriteProfile(PlayerProfile profile, Shares shares) {
affectedProfiles.addWriteProfile(profile, shares);
if (!profile.getProfileType().equals(ProfileTypes.NONE)) {
affectedProfiles.addWriteProfile(profile, shares);
}
}

/**
Expand All @@ -61,7 +66,9 @@ protected final void addWriteProfile(PlayerProfile profile, Shares shares) {
* @param shares What from this group needs to be loaded.
*/
protected final void addReadProfile(PlayerProfile profile, Shares shares) {
affectedProfiles.addReadProfile(profile, shares);
if (!profile.getProfileType().equals(ProfileTypes.NONE)) {
affectedProfiles.addReadProfile(profile, shares);
}
}

protected abstract ShareHandlingEvent createEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public final class ProfileTypes {
*/
public static final ProfileType ADVENTURE = ProfileType.createProfileType("ADVENTURE");

/**
* The profile type for the any other Game Modes, i.e. spectator.
*/
public static final ProfileType NONE = ProfileType.createProfileType("NONE");

/**
* Returns the appropriate ProfileType for the given game mode.
*
Expand All @@ -37,7 +42,7 @@ public static ProfileType forGameMode(GameMode mode) {
case ADVENTURE:
return ADVENTURE;
default:
return SURVIVAL;
return NONE;
}
}

Expand Down

0 comments on commit c5fc189

Please sign in to comment.