Tweaks to API

This commit is contained in:
nossr50 2021-04-20 14:09:15 -07:00
parent 70b1c23f50
commit f643010f4b
2 changed files with 25 additions and 23 deletions

View File

@ -7,17 +7,21 @@ import com.gmail.nossr50.datatypes.chat.ChatChannel;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.subskills.taming.CallOfTheWildType;
import com.gmail.nossr50.events.McMMOReplaceVanillaTreasureEvent;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.party.ShareHandler;
import com.gmail.nossr50.runnables.player.PlayerProfileLoadingTask;
import com.gmail.nossr50.skills.fishing.FishingManager;
import com.gmail.nossr50.skills.herbalism.HerbalismManager;
import com.gmail.nossr50.skills.mining.MiningManager;
import com.gmail.nossr50.skills.repair.Repair;
import com.gmail.nossr50.skills.repair.RepairManager;
import com.gmail.nossr50.skills.salvage.Salvage;
import com.gmail.nossr50.skills.salvage.SalvageManager;
import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.util.*;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
@ -28,9 +32,11 @@ import com.gmail.nossr50.util.sounds.SoundType;
import com.gmail.nossr50.worldguard.WorldGuardManager;
import com.gmail.nossr50.worldguard.WorldGuardUtils;
import com.neetgames.mcmmo.player.OnlineMMOPlayer;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.*;
import org.bukkit.entity.minecart.PoweredMinecart;
@ -195,7 +201,6 @@ public class PlayerListener implements Listener {
*
* @param event The event to monitor
*/
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerWorldChange(PlayerChangedWorldEvent event) {
Player player = event.getPlayer();

View File

@ -3,7 +3,6 @@ package com.gmail.nossr50.util.player;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.runnables.skills.BleedTimerTask;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
import com.google.common.collect.ImmutableList;
import org.bukkit.OfflinePlayer;
@ -104,12 +103,8 @@ public final class UserManager {
return playerCollection;
}
/**
* This method is called by PlayerQuitEvent to tear down the mcMMOPlayer.
*
* @param syncSave if true, data is saved synchronously
*/
public static void logout(@NotNull McMMOPlayer mmoPlayer, boolean syncSave) {
//TODO: T&C copy impl again from master
Player targetPlayer = mmoPlayer.getPlayer();
BleedTimerTask.bleedOut(targetPlayer);
@ -136,17 +131,16 @@ public final class UserManager {
mcMMO.getDatabaseManager().cleanupUser(targetPlayer.getUniqueId());
}
/**
* Get the McMMOPlayer of a player by name.
*
* @param playerName The name of the player whose McMMOPlayer to retrieve
* @return the player's McMMOPlayer object
*/
public static McMMOPlayer getPlayer(String playerName) {
@Deprecated
public static @NotNull McMMOPlayer getPlayer(@NotNull String playerName) {
return retrieveMcMMOPlayer(playerName, false);
}
public static McMMOPlayer getOfflinePlayer(OfflinePlayer player) {
public static @NotNull McMMOPlayer queryPlayer(@NotNull String playerName) {
return retrieveMcMMOPlayer(playerName, false);
}
public static @NotNull McMMOPlayer getOfflinePlayer(@NotNull OfflinePlayer player) {
if (player instanceof Player) {
return getPlayer((Player) player);
}
@ -154,16 +148,11 @@ public final class UserManager {
return retrieveMcMMOPlayer(player.getName(), true);
}
public static McMMOPlayer getOfflinePlayer(String playerName) {
public static @NotNull McMMOPlayer getOfflinePlayer(@NotNull String playerName) {
return retrieveMcMMOPlayer(playerName, true);
}
/**
* Gets the McMMOPlayer object for a player, this can be null if the player has not yet been loaded.
* @param player target player
* @return McMMOPlayer object for this player, null if Player has not been loaded
*/
public static McMMOPlayer getPlayer(Player player) {
public static @NotNull McMMOPlayer queryPlayer(@NotNull Player player) {
//Avoid Array Index out of bounds
if(player != null && player.hasMetadata(mcMMO.playerDataKey))
return (McMMOPlayer) player.getMetadata(mcMMO.playerDataKey).get(0).value();
@ -171,7 +160,15 @@ public final class UserManager {
return null;
}
private static McMMOPlayer retrieveMcMMOPlayer(String playerName, boolean offlineValid) {
public static @NotNull McMMOPlayer getPlayer(@NotNull Player player) {
//Avoid Array Index out of bounds
if(player != null && player.hasMetadata(mcMMO.playerDataKey))
return (McMMOPlayer) player.getMetadata(mcMMO.playerDataKey).get(0).value();
else
return null;
}
private static @NotNull McMMOPlayer retrieveMcMMOPlayer(@NotNull String playerName, boolean offlineValid) {
Player player = mcMMO.p.getServer().getPlayerExact(playerName);
if (player == null) {