Discard more unfinished API, eliminate more errors

This commit is contained in:
nossr50 2021-03-16 16:16:00 -07:00
parent 1c63e34dbb
commit 3d6b9ba539
26 changed files with 69 additions and 701 deletions

View File

@ -1,336 +0,0 @@
package com.gmail.nossr50.commands;
import com.gmail.nossr50.datatypes.skills.ModConfigType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Misc;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
public class McImportCommand implements CommandExecutor {
int fileAmount;
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
if (args.length == 0) {
importModConfig();
return true;
}
return false;
}
public boolean importModConfig() {
String importFilePath = mcMMO.getModDirectory() + File.separator + "import";
File importFile = new File(importFilePath, "import.log");
mcMMO.p.getLogger().info("Starting import of mod materials...");
fileAmount = 0;
HashMap<ModConfigType, ArrayList<String>> materialNames = new HashMap<>();
BufferedReader in = null;
try {
// Open the file
in = new BufferedReader(new FileReader(importFile));
String line;
String materialName;
String modName;
// While not at the end of the file
while ((line = in.readLine()) != null) {
String[] split1 = line.split("material ");
if (split1.length != 2) {
continue;
}
String[] split2 = split1[1].split(" with");
if (split2.length != 2) {
continue;
}
materialName = split2[0];
// Categorise each material under a mod config type
ModConfigType type = ModConfigType.getModConfigType(materialName);
if (!materialNames.containsKey(type)) {
materialNames.put(type, new ArrayList<>());
}
materialNames.get(type).add(materialName);
}
}
catch (FileNotFoundException e) {
mcMMO.p.getLogger().warning("Could not find " + importFile.getAbsolutePath() + " ! (No such file or directory)");
mcMMO.p.getLogger().warning("Copy and paste latest.log to " + importFile.getParentFile().getAbsolutePath() + " and rename it to import.log");
return false;
}
catch (Exception e) {
e.printStackTrace();
return false;
}
finally {
tryClose(in);
}
createOutput(materialNames);
mcMMO.p.getLogger().info("Import finished! Created " + fileAmount + " files!");
return true;
}
private void createOutput(HashMap<ModConfigType, ArrayList<String>> materialNames) {
for (ModConfigType modConfigType : materialNames.keySet()) {
HashMap<String, ArrayList<String>> materialNamesType = new HashMap<>();
for (String materialName : materialNames.get(modConfigType)) {
String modName = Misc.getModName(materialName);
if (!materialNamesType.containsKey(modName)) {
materialNamesType.put(modName, new ArrayList<>());
}
materialNamesType.get(modName).add(materialName);
}
createOutput(modConfigType, materialNamesType);
}
}
private void tryClose(Closeable c) {
if (c == null) {
return;
}
try {
c.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
private void createOutput(ModConfigType modConfigType, HashMap<String, ArrayList<String>> materialNames) {
File outputFilePath = new File(mcMMO.getModDirectory() + File.separator + "output");
if (!outputFilePath.exists() && !outputFilePath.mkdirs()) {
mcMMO.p.getLogger().severe("Could not create output directory! " + outputFilePath.getAbsolutePath());
}
FileWriter out = null;
String type = modConfigType.name().toLowerCase(Locale.ENGLISH);
for (String modName : materialNames.keySet()) {
File outputFile = new File(outputFilePath, modName + "." + type + ".yml");
mcMMO.p.getLogger().info("Creating " + outputFile.getName());
try {
if (outputFile.exists() && !outputFile.delete()) {
mcMMO.p.getLogger().severe("Not able to delete old output file! " + outputFile.getAbsolutePath());
}
if (!outputFile.createNewFile()) {
mcMMO.p.getLogger().severe("Could not create output file! " + outputFile.getAbsolutePath());
continue;
}
StringBuilder writer = new StringBuilder();
HashMap<String, ArrayList<String>> configSections = getConfigSections(modConfigType, modName, materialNames);
if (configSections == null) {
mcMMO.p.getLogger().severe("Something went wrong!! type is " + type);
return;
}
// Write the file, go through each skill and write all the materials
for (String configSection : configSections.keySet()) {
if (configSection.equals("UNIDENTIFIED")) {
writer.append("# This isn't a valid config section and all materials in this category need to be").append("\r\n");
writer.append("# copy and pasted to a valid section of this config file.").append("\r\n");
}
writer.append(configSection).append(":").append("\r\n");
for (String line : configSections.get(configSection)) {
writer.append(line).append("\r\n");
}
writer.append("\r\n");
}
out = new FileWriter(outputFile);
out.write(writer.toString());
} catch (Exception e) {
e.printStackTrace();
return;
} finally {
tryClose(out);
fileAmount++;
}
}
}
private HashMap<String, ArrayList<String>> getConfigSections(ModConfigType type, String modName, HashMap<String, ArrayList<String>> materialNames) {
switch (type) {
case BLOCKS:
return getConfigSectionsBlocks(modName, materialNames);
case TOOLS:
return getConfigSectionsTools(modName, materialNames);
case ARMOR:
return getConfigSectionsArmor(modName, materialNames);
case UNKNOWN:
return getConfigSectionsUnknown(modName, materialNames);
}
return null;
}
private HashMap<String, ArrayList<String>> getConfigSectionsBlocks(String modName, HashMap<String, ArrayList<String>> materialNames) {
HashMap<String, ArrayList<String>> configSections = new HashMap<>();
// Go through all the materials and categorise them under a skill
for (String materialName : materialNames.get(modName)) {
String skillName = "UNIDENTIFIED";
if (materialName.contains("ORE")) {
skillName = "Mining";
}
else if (materialName.contains("LOG") || materialName.contains("LEAVES")) {
skillName = "Woodcutting";
}
else if (materialName.contains("GRASS") || materialName.contains("FLOWER") || materialName.contains("CROP")) {
skillName = "Herbalism";
}
else if (materialName.contains("DIRT") || materialName.contains("SAND")) {
skillName = "Excavation";
}
if (!configSections.containsKey(skillName)) {
configSections.put(skillName, new ArrayList<>());
}
ArrayList<String> skillContents = configSections.get(skillName);
skillContents.add(" " + materialName + "|0:");
skillContents.add(" " + " " + "XP_Gain: 99");
skillContents.add(" " + " " + "Double_Drops_Enabled: true");
if (skillName.equals("Mining")) {
skillContents.add(" " + " " + "Smelting_XP_Gain: 9");
}
else if (skillName.equals("Woodcutting")) {
skillContents.add(" " + " " + "Is_Log: " + materialName.contains("LOG"));
}
}
return configSections;
}
private HashMap<String, ArrayList<String>> getConfigSectionsTools(String modName, HashMap<String, ArrayList<String>> materialNames) {
HashMap<String, ArrayList<String>> configSections = new HashMap<>();
// Go through all the materials and categorise them under a tool type
for (String materialName : materialNames.get(modName)) {
String toolType = "UNIDENTIFIED";
if (materialName.contains("PICKAXE")) {
toolType = "Pickaxes";
}
else if (materialName.contains("AXE")) {
toolType = "Axes";
}
else if (materialName.contains("BOW")) {
toolType = "Bows";
}
else if (materialName.contains("HOE")) {
toolType = "Hoes";
}
else if (materialName.contains("SHOVEL") || materialName.contains("SPADE")) {
toolType = "Shovels";
}
else if (materialName.contains("SWORD")) {
toolType = "Swords";
}
if (!configSections.containsKey(toolType)) {
configSections.put(toolType, new ArrayList<>());
}
ArrayList<String> skillContents = configSections.get(toolType);
skillContents.add(" " + materialName + ":");
skillContents.add(" " + " " + "XP_Modifier: 1.0");
skillContents.add(" " + " " + "Tier: 1");
skillContents.add(" " + " " + "Ability_Enabled: true");
addRepairableLines(materialName, skillContents);
}
return configSections;
}
private HashMap<String, ArrayList<String>> getConfigSectionsArmor(String modName, HashMap<String, ArrayList<String>> materialNames) {
HashMap<String, ArrayList<String>> configSections = new HashMap<>();
// Go through all the materials and categorise them under an armor type
for (String materialName : materialNames.get(modName)) {
String toolType = "UNIDENTIFIED";
if (materialName.contains("BOOT") || materialName.contains("SHOE")) {
toolType = "Boots";
}
else if (materialName.contains("CHESTPLATE") || materialName.contains("CHEST")) {
toolType = "Chestplates";
}
else if (materialName.contains("HELM") || materialName.contains("HAT")) {
toolType = "Helmets";
}
else if (materialName.contains("LEGGINGS") || materialName.contains("LEGS") || materialName.contains("PANTS")) {
toolType = "Leggings";
}
if (!configSections.containsKey(toolType)) {
configSections.put(toolType, new ArrayList<>());
}
ArrayList<String> skillContents = configSections.get(toolType);
skillContents.add(" " + materialName + ":");
addRepairableLines(materialName, skillContents);
}
return configSections;
}
private void addRepairableLines(String materialName, ArrayList<String> skillContents) {
skillContents.add(" " + " " + "Repairable: true");
skillContents.add(" " + " " + "Repair_Material: REPAIR_MATERIAL_NAME");
skillContents.add(" " + " " + "Repair_Material_Data_Value: 0");
skillContents.add(" " + " " + "Repair_Material_Quantity: 9");
skillContents.add(" " + " " + "Repair_Material_Pretty_Name: Repair Item Name");
skillContents.add(" " + " " + "Repair_MinimumLevel: 0");
skillContents.add(" " + " " + "Repair_XpMultiplier: 1.0");
Material material = Material.matchMaterial(materialName);
short durability = (material == null) ? (short) 9999 : material.getMaxDurability();
skillContents.add(" " + " " + "Durability: " + ((durability > 0) ? durability : (short) 9999));
}
private HashMap<String, ArrayList<String>> getConfigSectionsUnknown(String modName, HashMap<String, ArrayList<String>> materialNames) {
HashMap<String, ArrayList<String>> configSections = new HashMap<>();
// Go through all the materials and print them
for (String materialName : materialNames.get(modName)) {
String configKey = "UNIDENTIFIED";
if (!configSections.containsKey(configKey)) {
configSections.put(configKey, new ArrayList<>());
}
ArrayList<String> skillContents = configSections.get(configKey);
skillContents.add(" " + materialName);
}
return configSections;
}
}

View File

@ -1,29 +0,0 @@
package com.gmail.nossr50.commands;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import org.bukkit.command.CommandSender;
public class McabilityCommand extends ToggleCommand {
@Override
protected boolean hasOtherPermission(CommandSender sender) {
return Permissions.mcabilityOthers(sender);
}
@Override
protected boolean hasSelfPermission(CommandSender sender) {
return Permissions.mcability(sender);
}
@Override
protected void applyCommandAction(McMMOPlayer mcMMOPlayer) {
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.Ability." + (mcMMOPlayer.getAbilityUse() ? "Off" : "On")));
mcMMOPlayer.toggleAbilityUse();
}
@Override
protected void sendSuccessMessage(CommandSender sender, String playerName) {
sender.sendMessage(LocaleLoader.getString("Commands.Ability.Toggle", playerName));
}
}

View File

@ -1,54 +0,0 @@
package com.gmail.nossr50.commands.database;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.google.common.collect.ImmutableList;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class McremoveCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
if (args.length == 1) {
String playerName = CommandUtils.getMatchedPlayerName(args[0]);
if (UserManager.getOfflinePlayer(playerName) == null && CommandUtils.unloadedProfile(sender, mcMMO.getDatabaseManager().loadPlayerProfile(playerName))) {
return true;
}
UUID uuid = null;
if (Bukkit.getPlayer(playerName) != null) {
uuid = Bukkit.getPlayer(playerName).getUniqueId();
}
if (mcMMO.getDatabaseManager().removeUser(playerName, uuid)) {
sender.sendMessage(LocaleLoader.getString("Commands.mcremove.Success", playerName));
} else {
sender.sendMessage(playerName + " could not be removed from the database."); // Pretty sure this should NEVER happen.
}
return true;
}
return false;
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
if (args.length == 1) {
List<String> playerNames = CommandUtils.getOnlinePlayerNames(sender);
return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<>(playerNames.size()));
}
return ImmutableList.of();
}
}

View File

@ -1,8 +1,6 @@
package com.gmail.nossr50.commands.party;
import com.gmail.nossr50.commands.party.alliance.PartyAllianceCommand;
import com.gmail.nossr50.commands.party.teleport.PtpCommand;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
@ -38,23 +36,19 @@ public class PartyCommand implements TabExecutor {
PARTY_SUBCOMMANDS = ImmutableList.copyOf(subcommands);
}
private final CommandExecutor partyJoinCommand = new PartyJoinCommand();
private final CommandExecutor partyAcceptCommand = new PartyAcceptCommand();
private final CommandExecutor partyCreateCommand = new PartyCreateCommand();
private final CommandExecutor partyQuitCommand = new PartyQuitCommand();
private final CommandExecutor partyXpShareCommand = new PartyXpShareCommand();
private final CommandExecutor partyItemShareCommand = new PartyItemShareCommand();
private final CommandExecutor partyInviteCommand = new PartyInviteCommand();
private final CommandExecutor partyKickCommand = new PartyKickCommand();
private final CommandExecutor partyDisbandCommand = new PartyDisbandCommand();
private final CommandExecutor partyChangeOwnerCommand = new PartyChangeOwnerCommand();
private final CommandExecutor partyLockCommand = new PartyLockCommand();
private final CommandExecutor partyChangePasswordCommand = new PartyChangePasswordCommand();
private final CommandExecutor partyRenameCommand = new PartyRenameCommand();
private final CommandExecutor partyInfoCommand = new PartyInfoCommand();
private final CommandExecutor partyHelpCommand = new PartyHelpCommand();
private final CommandExecutor partyTeleportCommand = new PtpCommand();
private final CommandExecutor partyAllianceCommand = new PartyAllianceCommand();
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {

View File

@ -1,88 +0,0 @@
package com.gmail.nossr50.commands.party;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class PartyJoinCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
switch (args.length) {
case 2:
case 3:
String targetName = CommandUtils.getMatchedPlayerName(args[1]);
McMMOPlayer mcMMOTarget = UserManager.getPlayer(targetName);
if (!CommandUtils.checkPlayerExistence(sender, targetName, mcMMOTarget)) {
return true;
}
Player target = mcMMOTarget.getPlayer();
if (!mcMMOTarget.inParty()) {
sender.sendMessage(LocaleLoader.getString("Party.PlayerNotInParty", targetName));
return true;
}
Player player = (Player) sender;
if(UserManager.getPlayer((Player) sender) == null)
{
sender.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
return true;
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
Party targetParty = mcMMOTarget.getParty();
if (player.equals(target) || (mcMMOPlayer.inParty() && mcMMOPlayer.getParty().equals(targetParty))) {
sender.sendMessage(LocaleLoader.getString("Party.Join.Self"));
return true;
}
String password = getPassword(args);
// Make sure party passwords match
if (!PartyManager.checkPartyPassword(player, targetParty, password)) {
return true;
}
String partyName = targetParty.getName();
// Changing parties
if (!PartyManager.changeOrJoinParty(mcMMOPlayer, partyName)) {
return true;
}
if(PartyManager.isPartyFull(player, targetParty))
{
player.sendMessage(LocaleLoader.getString("Commands.Party.PartyFull", targetParty.toString()));
return true;
}
player.sendMessage(LocaleLoader.getString("Commands.Party.Join", partyName));
PartyManager.addToParty(mcMMOPlayer, targetParty);
return true;
default:
sender.sendMessage(LocaleLoader.getString("Commands.Usage.3", "party", "join", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">", "[" + LocaleLoader.getString("Commands.Usage.Password") + "]"));
return true;
}
}
private String getPassword(String[] args) {
if (args.length == 3) {
return args[2];
}
return null;
}
}

View File

@ -1,8 +1,11 @@
package com.gmail.nossr50.commands.skills;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.util.text.TextComponentFactory;
import com.neetgames.mcmmo.player.OnlineMMOPlayer;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@ -29,10 +32,10 @@ public class TridentsCommand extends SkillCommand {
}
@Override
protected @NotNull List<Component> getTextComponents(@NotNull OnlineMMOPlayer mmoPlayer) {
protected @NotNull List<Component> getTextComponents(@NotNull Player player) {
List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(mmoPlayer, textComponents, PrimarySkillType.TRIDENTS);
TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.TRIDENTS);
return textComponents;
}

View File

@ -1,18 +0,0 @@
package com.gmail.nossr50.datatypes.experience;
import com.neetgames.mcmmo.experience.context.NullExperienceContext;
import org.jetbrains.annotations.NotNull;
public class ExperienceContextBuilder {
private static final @NotNull NullExperienceContext nullExperienceContext = new NullExperienceContext();
/**
* Return a null experience context
* @return a null experience context
*/
public static NullExperienceContext nullContext() {
return nullExperienceContext;
}
}

View File

@ -1,20 +0,0 @@
package com.gmail.nossr50.datatypes.experience;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public interface ExperienceGain {
/**
* Get the target skill for this XP gain
* We define this by a String to allow for custom skills
* @return The target skill
*/
@NotNull UUID getTargetSkill();
/**
* Value of the experience gain, this is the raw value before any mutations are done via modifiers or otherwise
* @return the value of this {@link ExperienceGain}
*/
int getValue();
}

View File

@ -1,5 +0,0 @@
package com.gmail.nossr50.datatypes.experience;
public class ExperienceGainBuilder {
}

View File

@ -1,5 +0,0 @@
package com.gmail.nossr50.datatypes.experience;
public class ExperienceProcessor {
}

View File

@ -1,6 +0,0 @@
package com.gmail.nossr50.datatypes.experience;
public enum ExperienceVector {
ALL,
TARGETED,
}

View File

@ -2,5 +2,5 @@ package com.gmail.nossr50.datatypes.experience;
import com.neetgames.mcmmo.experience.ExperienceHandler;
public class OfflineExperienceProcessor implements ExperienceHandler {
public class OfflineExperienceProcessor {
}

View File

@ -5,12 +5,9 @@ import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.neetgames.mcmmo.party.Party;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.neetgames.mcmmo.experience.ExperienceHandler;
import com.neetgames.mcmmo.experience.XPGainReason;
import com.neetgames.mcmmo.experience.XPGainSource;
import com.neetgames.mcmmo.player.MMOPlayer;
import com.neetgames.mcmmo.player.MMOPlayerData;
import com.gmail.nossr50.datatypes.skills.CoreSkills;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.party.ShareHandler;
import com.gmail.nossr50.skills.child.FamilyTree;
@ -21,7 +18,6 @@ import com.gmail.nossr50.util.skills.PerksUtils;
import com.gmail.nossr50.util.sounds.SoundManager;
import com.gmail.nossr50.util.sounds.SoundType;
import com.neetgames.mcmmo.exceptions.UnknownSkillException;
import com.neetgames.mcmmo.skill.RootSkill;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@ -29,7 +25,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.Map;
import java.util.Set;
public class OnlineExperienceProcessor implements ExperienceHandler {
public class OnlineExperienceProcessor {
private boolean isUsingUnarmed = false;

View File

@ -1,11 +0,0 @@
package com.gmail.nossr50.datatypes.experience;
public interface PartyExperienceGain extends ExperienceGain {
/**
* The original value of this experience gain
* This is not equivalent to the amount of XP the players in party will get, but it was the value of the XP before it was distributed to party members
* @return the original value of the experience gain
*/
int originalValue();
}

View File

@ -1,24 +0,0 @@
package com.gmail.nossr50.datatypes.experience.context;
import com.neetgames.jmal.Block;
import com.neetgames.mcmmo.experience.context.BlockExperienceContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class BlockExperienceContextImpl implements BlockExperienceContext {
@NotNull Block blockExperienceContext;
public BlockExperienceContextImpl(@NotNull Block block) {
this.blockExperienceContext = block;
}
@Nullable
@Override
public Object getContext() {
return blockExperienceContext;
}
public @NotNull Block getBlockExperienceContext() {
return blockExperienceContext;
}
}

View File

@ -1,30 +0,0 @@
package com.gmail.nossr50.datatypes.experience.context;
import com.neetgames.jmal.LivingEntity;
import com.neetgames.mcmmo.experience.context.CombatExperienceContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class CombatExperienceContextImpl implements CombatExperienceContext {
private final @NotNull LivingEntity livingEntity;
public CombatExperienceContextImpl(@NotNull LivingEntity livingEntity) {
this.livingEntity = livingEntity;
}
@Nullable
@Override
public Object getContext() {
return livingEntity;
}
/**
* Get the {@link LivingEntity} involved in this experience context
*
* @return the {@link LivingEntity} involved in this experience context
*/
public @NotNull LivingEntity getLivingEntity() {
return livingEntity;
}
}

View File

@ -1,14 +0,0 @@
package com.gmail.nossr50.datatypes.experience.context;
import com.neetgames.mcmmo.experience.context.ExperienceContext;
import org.jetbrains.annotations.Nullable;
/**
* Represents an experience context with an undefined source
*/
public class NullExperienceContext implements ExperienceContext {
@Override
public @Nullable Object getContext() {
return null;
}
}

View File

@ -8,8 +8,6 @@ import com.neetgames.mcmmo.player.MMOPlayerData;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public abstract class AbstractMMOPlayer implements MMOPlayer {
/* All of the persistent data for a player that gets saved and loaded from DB */
protected final @NotNull MMOPlayerData mmoPlayerData; //All persistent data is kept here
@ -24,7 +22,7 @@ public abstract class AbstractMMOPlayer implements MMOPlayer {
*
* @param mmoPlayerData player data
*/
public AbstractMMOPlayer(@NotNull Player player, @NotNull MMOPlayerData mmoPlayerData) {
public AbstractMMOPlayer(@NotNull Player player, @NotNull MMOPlayerDataImpl mmoPlayerData) {
this.mmoPlayerData = mmoPlayerData;
this.experienceHandler = new OnlineExperienceProcessor(mmoPlayerData);
this.cooldownManager = new CooldownManager(mmoPlayerData);
@ -35,7 +33,7 @@ public abstract class AbstractMMOPlayer implements MMOPlayer {
*
* @param mmoPlayerData player data
*/
public AbstractMMOPlayer(@NotNull MMOPlayerData mmoPlayerData) {
public AbstractMMOPlayer(@NotNull MMOPlayerDataImpl mmoPlayerData) {
this.mmoPlayerData = mmoPlayerData;
this.experienceHandler = new OfflineExperienceProcessor(mmoPlayerData);
this.cooldownManager = new CooldownManager(mmoPlayerData);

View File

@ -8,9 +8,9 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class CooldownManager {
private final @NotNull PersistentPlayerData playerDataRef;
private final @NotNull MMOPlayerDataImpl playerDataRef;
public CooldownManager(@NotNull PersistentPlayerData playerDataRef) {
public CooldownManager(@NotNull MMOPlayerDataImpl playerDataRef) {
this.playerDataRef = playerDataRef;
}

View File

@ -3,7 +3,6 @@ package com.gmail.nossr50.datatypes.player;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.experience.MMOExperienceBarManager;
import com.neetgames.mcmmo.MobHealthBarType;
import com.neetgames.mcmmo.UniqueDataType;
import com.neetgames.mcmmo.player.MMOPlayerData;
import com.neetgames.mcmmo.skill.RootSkill;
@ -15,8 +14,6 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@ -61,7 +58,7 @@ public class MMODataBuilder {
/*
* New Profile with default values
*/
return new PersistentPlayerData(playerUUID, playerName);
return new MMOPlayerDataImpl(playerUUID, playerName);
}
public @NotNull MMOPlayerData build() throws Exception {
@ -96,7 +93,7 @@ public class MMODataBuilder {
validateBarStateMapEntries(barStateMap);
return new PersistentPlayerData(playerUUID, playerName, partyChatSpying, skillLevelValues, skillExperienceValues, abilityDeactivationTimestamps, uniquePlayerData, barStateMap, scoreboardTipsShown, lastLogin, leaderBoardExemption);
return new MMOPlayerDataImpl(playerUUID, playerName, partyChatSpying, skillLevelValues, skillExperienceValues, abilityDeactivationTimestamps, uniquePlayerData, barStateMap, scoreboardTipsShown, lastLogin, leaderBoardExemption);
}
private void validateBarStateMapEntries(@NotNull Map<RootSkill, SkillBossBarState> map) {

View File

@ -25,7 +25,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class PersistentPlayerData implements MMOPlayerData {
public class MMOPlayerDataImpl implements MMOPlayerData {
private final @NotNull MutableBoolean dirtyFlag; //Dirty values in this class will change this flag as needed
@ -58,7 +58,7 @@ public class PersistentPlayerData implements MMOPlayerData {
* @param playerName target player's name
* @throws NullArgumentException thrown when never null arguments are null
*/
public PersistentPlayerData(@NotNull UUID playerUUID, @NotNull String playerName) throws NullArgumentException {
public MMOPlayerDataImpl(@NotNull UUID playerUUID, @NotNull String playerName) throws NullArgumentException {
/*
* New Data
*/
@ -109,17 +109,17 @@ public class PersistentPlayerData implements MMOPlayerData {
* @param lastLogin target player's last login
* @param leaderBoardExclusion target player's leaderboard exemption status
*/
public PersistentPlayerData(@NotNull UUID playerUUID,
@NotNull String playerName,
boolean partyChatSpying,
@NotNull Map<PrimarySkillType, Integer> skillLevelValues,
@NotNull Map<PrimarySkillType, Float> skillExperienceValues,
@NotNull Map<SuperSkill, Integer> abilityDeactivationTimestamps,
@NotNull Map<UniqueDataType, Integer> uniquePlayerData,
@NotNull Map<RootSkill, SkillBossBarState> barStateMap,
int scoreboardTipsShown,
long lastLogin,
boolean leaderBoardExclusion) throws Exception {
public MMOPlayerDataImpl(@NotNull UUID playerUUID,
@NotNull String playerName,
boolean partyChatSpying,
@NotNull Map<PrimarySkillType, Integer> skillLevelValues,
@NotNull Map<PrimarySkillType, Float> skillExperienceValues,
@NotNull Map<SuperSkill, Integer> abilityDeactivationTimestamps,
@NotNull Map<UniqueDataType, Integer> uniquePlayerData,
@NotNull Map<RootSkill, SkillBossBarState> barStateMap,
int scoreboardTipsShown,
long lastLogin,
boolean leaderBoardExclusion) throws Exception {
/*
* Skills Data

View File

@ -93,7 +93,7 @@ public class McMMOPlayer extends PlayerProfile implements OnlineMMOPlayer, Ident
* New
* Player
*/
super(new PersistentPlayerData(player.getUniqueId(), player.getName()));
super(new MMOPlayerDataImpl(player.getUniqueId(), player.getName()));
UUID uuid = player.getUniqueId();
identity = Identity.identity(uuid);

View File

@ -11,7 +11,7 @@ import java.util.UUID;
public class PlayerProfile extends AbstractMMOPlayer {
/**
* Initialize an {@link PlayerProfile} for {@link PersistentPlayerData}
* Initialize an {@link PlayerProfile} for {@link MMOPlayerDataImpl}
* This will be used for existing data
*
* @param mmoPlayerData target persistent player data

View File

@ -5,6 +5,7 @@ import com.gmail.nossr50.config.WorldBlacklist;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.chat.ChatChannel;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.util.player.UserManager;
import com.neetgames.mcmmo.player.OnlineMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
@ -537,36 +538,20 @@ public class PlayerListener implements Listener {
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
if (!mcMMO.getUserManager().hasPlayerDataKey(player)) {
if (!UserManager.hasPlayerDataKey(player)) {
return;
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
//Profile not loaded
McMMOPlayer mmoPlayer = mcMMO.getUserManager().queryPlayer(player);
if(mmoPlayer == null) {
if(mcMMOPlayer == null) {
return;
}
mcMMO.getUserManager().saveUserImmediately(mmoPlayer, mcMMO.isServerShutdownExecuted());
//Use a sync save if the server is shutting down to avoid race conditions
//TODO: Make sure this cleans up
//TODO: Make sure this cleans up
//TODO: Make sure this cleans up
//TODO: Make sure this cleans up
//TODO: Make sure this cleans up
//TODO: Make sure this cleans up
//TODO: Make sure this cleans up
//TODO: Make sure this cleans up
//TODO: Make sure this cleans up
//TODO: Make sure this cleans up
//TODO: Make sure this cleans up
//TODO: Make sure this cleans up
//TODO: Make sure this cleans up
//TODO: Make sure this cleans up
mmoPlayer.logout(mcMMO.isServerShutdownExecuted());
//TODO: Actually never sure its possible for this event to fire during server shutdown, should double check that...
UserManager.logout(mcMMOPlayer, mcMMO.isServerShutdownExecuted());
}
/**

View File

@ -5,7 +5,6 @@ import com.gmail.nossr50.commands.admin.CompatibilityCommand;
import com.gmail.nossr50.commands.admin.McmmoReloadLocaleCommand;
import com.gmail.nossr50.commands.admin.PlayerDebugCommand;
import com.gmail.nossr50.commands.chat.McChatSpy;
import com.gmail.nossr50.commands.database.DatabaseRemovePlayerCommand;
import com.gmail.nossr50.commands.database.McpurgeCommand;
import com.gmail.nossr50.commands.database.MmoshowdbCommand;
import com.gmail.nossr50.commands.experience.AddlevelsCommand;

View File

@ -1,12 +1,16 @@
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;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collection;
@ -102,6 +106,38 @@ 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) {
Player targetPlayer = mmoPlayer.getPlayer();
BleedTimerTask.bleedOut(targetPlayer);
//Cleanup
mmoPlayer.resetAbilityMode(); //TODO: T&C Wire this up, see master branch com.gmail.nossr50.datatypes.player.McMMOPlayer#resetAbilityMode for example
mmoPlayer.getTamingManager().cleanupAllSummons();
if (syncSave) {
getProfile().save(true); //TODO: T&C Wire this up, see master branch com.gmail.nossr50.datatypes.player.PlayerProfile#save
} else {
getProfile().scheduleAsyncSave(); //TODO: T&C Wire this up, see master branch com.gmail.nossr50.datatypes.player.PlayerProfile#scheduleAsyncSave
}
UserManager.remove(targetPlayer);
if(Config.getInstance().getScoreboardsEnabled())
ScoreboardManager.teardownPlayer(targetPlayer);
if (inParty()) { //TODO: T&C Wire this up
party.removeOnlineMember(targetPlayer); //TODO: T&C Wire this up
}
//Remove user from cache
mcMMO.getDatabaseManager().cleanupUser(targetPlayer.getUniqueId());
}
/**
* Get the McMMOPlayer of a player by name.
*