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.
  • Loading branch information
benwoo1110 committed Jul 15, 2021
1 parent 207790f commit bdf5dcf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 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 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 bdf5dcf

Please sign in to comment.