mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-23 05:36:46 +01:00
Moved hudType back to PlayerProfile
Removed some convenient methods from PlayerProfile to avoid NPE because of spoutHud
This commit is contained in:
parent
5571e0bc0c
commit
ede08ce5ac
@ -30,21 +30,22 @@ public class MchudCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (args.length) {
|
||||
case 1:
|
||||
Player player = (Player) sender;
|
||||
PlayerProfile playerProfile = Users.getProfile(player);
|
||||
SpoutHud spoutHud = playerProfile.getSpoutHud();
|
||||
|
||||
if (spoutHud == null) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.Disabled"));
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (args.length) {
|
||||
case 1:
|
||||
for (HudType hudType : HudType.values()) {
|
||||
if (hudType.toString().equalsIgnoreCase(args[0])) {
|
||||
playerProfile.setHudType(hudType);
|
||||
|
||||
SpoutHud spoutHud = playerProfile.getSpoutHud();
|
||||
|
||||
if (spoutHud != null) {
|
||||
spoutHud.initializeXpBar();
|
||||
spoutHud.updateXpBar();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -54,7 +55,7 @@ public class MchudCommand implements CommandExecutor {
|
||||
return true;
|
||||
|
||||
default:
|
||||
sender.sendMessage(usage);
|
||||
player.sendMessage(usage);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.SpoutConfig;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
import com.gmail.nossr50.datatypes.SpoutHud;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
@ -34,20 +35,26 @@ public class XplockCommand implements CommandExecutor {
|
||||
|
||||
Player player = (Player) sender;
|
||||
PlayerProfile playerProfile = Users.getProfile(player);
|
||||
SpoutHud spoutHud = playerProfile.getSpoutHud();
|
||||
|
||||
if (spoutHud == null) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.Disabled"));
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
if (playerProfile.getXpBarLocked()) {
|
||||
playerProfile.toggleXpBarLocked();
|
||||
if (spoutHud.getXpBarLocked()) {
|
||||
spoutHud.toggleXpBarLocked();
|
||||
player.sendMessage(LocaleLoader.getString("Commands.xplock.unlocked"));
|
||||
return true;
|
||||
}
|
||||
|
||||
SkillType lastGained = playerProfile.getLastGained();
|
||||
SkillType lastGained = spoutHud.getLastGained();
|
||||
|
||||
if (lastGained != null) {
|
||||
playerProfile.toggleXpBarLocked();
|
||||
playerProfile.setSkillLock(lastGained);
|
||||
spoutHud.toggleXpBarLocked();
|
||||
spoutHud.setSkillLock(lastGained);
|
||||
player.sendMessage(LocaleLoader.getString("Commands.xplock.locked", new Object[] { Misc.getCapitalized(lastGained.toString()) }));
|
||||
}
|
||||
else {
|
||||
@ -59,9 +66,9 @@ public class XplockCommand implements CommandExecutor {
|
||||
case 1:
|
||||
if (Skills.isSkill(args[0])) {
|
||||
if (Permissions.getInstance().permission(player, "mcmmo.skills." + args[0].toLowerCase())) {
|
||||
playerProfile.setXpBarLocked(true);
|
||||
playerProfile.setSkillLock(Skills.getSkillType(args[0]));
|
||||
playerProfile.updateXpBar();
|
||||
spoutHud.setXpBarLocked(true);
|
||||
spoutHud.setSkillLock(Skills.getSkillType(args[0]));
|
||||
spoutHud.updateXpBar();
|
||||
|
||||
player.sendMessage(LocaleLoader.getString("Commands.xplock.locked", new Object[] { Misc.getCapitalized(args[0]) }));
|
||||
}
|
||||
|
@ -92,7 +92,12 @@ public class McMMOPlayer {
|
||||
else {
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, skillType, xp));
|
||||
profile.setSkillXPLevel(skillType, profile.getSkillXpLevel(skillType) + xp);
|
||||
profile.setLastGained(skillType);
|
||||
|
||||
SpoutHud spoutHud = profile.getSpoutHud();
|
||||
|
||||
if (spoutHud != null) {
|
||||
spoutHud.setLastGained(skillType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,7 +167,12 @@ public class McMMOPlayer {
|
||||
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, skillType, xp));
|
||||
profile.setSkillXPLevel(skillType, profile.getSkillXpLevel(skillType) + xp);
|
||||
profile.setLastGained(skillType);
|
||||
|
||||
SpoutHud spoutHud = profile.getSpoutHud();
|
||||
|
||||
if (spoutHud != null) {
|
||||
spoutHud.setLastGained(skillType);
|
||||
}
|
||||
}
|
||||
|
||||
// Players & Profiles
|
||||
|
@ -20,6 +20,7 @@ public class PlayerProfile {
|
||||
|
||||
/* HUD */
|
||||
private SpoutHud spoutHud;
|
||||
private HudType hudType = SpoutConfig.getInstance().defaultHudType;
|
||||
|
||||
/* Party Stuff */
|
||||
private Party party;
|
||||
@ -98,7 +99,7 @@ public class PlayerProfile {
|
||||
else {
|
||||
for (HudType type : HudType.values()) {
|
||||
if (type.toString().equals(huds.get(1).get(0))) {
|
||||
spoutHud.setHudType(type);
|
||||
hudType = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -238,7 +239,7 @@ public class PlayerProfile {
|
||||
if (character.length > 33) {
|
||||
for (HudType type : HudType.values()) {
|
||||
if (type.toString().equalsIgnoreCase(character[33])) {
|
||||
spoutHud.setHudType(type);
|
||||
hudType = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -267,7 +268,7 @@ public class PlayerProfile {
|
||||
|
||||
// if we are using mysql save to database
|
||||
if (Config.getInstance().getUseMySQL()) {
|
||||
mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "huds SET hudtype = '" + spoutHud.getHudType().toString() + "' WHERE user_id = " + userId);
|
||||
mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "huds SET hudtype = '" + hudType.toString() + "' WHERE user_id = " + userId);
|
||||
mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "users SET lastlogin = " + timestamp.intValue() + " WHERE id = " + userId);
|
||||
mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "cooldowns SET "
|
||||
+ " mining = " + skillsDATS.get(AbilityType.SUPER_BREAKER)
|
||||
@ -361,7 +362,7 @@ public class PlayerProfile {
|
||||
writer.append(String.valueOf(skillsDATS.get(AbilityType.SERRATED_STRIKES)) + ":");
|
||||
writer.append(String.valueOf(skillsDATS.get(AbilityType.SKULL_SPLIITER)) + ":");
|
||||
writer.append(String.valueOf(skillsDATS.get(AbilityType.SUPER_BREAKER)) + ":");
|
||||
writer.append(spoutHud.getHudType().toString() + ":");
|
||||
writer.append(hudType.toString() + ":");
|
||||
writer.append(skills.get(SkillType.FISHING) + ":");
|
||||
writer.append(skillsXp.get(SkillType.FISHING) + ":");
|
||||
writer.append(String.valueOf(skillsDATS.get(AbilityType.BLAST_MINING)) + ":");
|
||||
@ -475,6 +476,10 @@ public class PlayerProfile {
|
||||
* HUD Stuff
|
||||
*/
|
||||
|
||||
public HudType getHudType() {
|
||||
return hudType;
|
||||
}
|
||||
|
||||
public SpoutHud getSpoutHud() {
|
||||
return spoutHud;
|
||||
}
|
||||
@ -483,44 +488,8 @@ public class PlayerProfile {
|
||||
this.spoutHud = spoutHud;
|
||||
}
|
||||
|
||||
public void setXpBarLocked(boolean locked) {
|
||||
spoutHud.setXpBarLocked(locked);
|
||||
}
|
||||
|
||||
public boolean getXpBarLocked() {
|
||||
return spoutHud.getXpBarLocked();
|
||||
}
|
||||
|
||||
public void toggleXpBarLocked() {
|
||||
spoutHud.toggleXpBarLocked();
|
||||
}
|
||||
|
||||
public void setSkillLock(SkillType type) {
|
||||
spoutHud.setSkillLock(type);
|
||||
}
|
||||
|
||||
public SkillType getSkillLock() {
|
||||
return spoutHud.getSkillLock();
|
||||
}
|
||||
|
||||
public HudType getHudType() {
|
||||
return spoutHud.getHudType();
|
||||
}
|
||||
|
||||
public void setHudType(HudType type) {
|
||||
spoutHud.setHudType(type);
|
||||
}
|
||||
|
||||
public void setLastGained(SkillType type) {
|
||||
spoutHud.setLastGained(type);
|
||||
}
|
||||
|
||||
public SkillType getLastGained() {
|
||||
return spoutHud.getLastGained();
|
||||
}
|
||||
|
||||
public void updateXpBar() {
|
||||
spoutHud.updateXpBar();
|
||||
public void setHudType(HudType hudType) {
|
||||
this.hudType = hudType;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -12,7 +12,6 @@ public class SpoutHud {
|
||||
private Player player;
|
||||
private PlayerProfile profile;
|
||||
|
||||
private HudType hudType = SpoutConfig.getInstance().defaultHudType;
|
||||
private SkillType lastGained;
|
||||
private SkillType skillLock;
|
||||
private boolean xpBarLocked;
|
||||
@ -36,7 +35,7 @@ public class SpoutHud {
|
||||
xpBar.removeWidgets();
|
||||
}
|
||||
|
||||
xpBar = new XpBar(SpoutManager.getPlayer(player), hudType);
|
||||
xpBar = new XpBar(SpoutManager.getPlayer(player), profile.getHudType());
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,14 +72,6 @@ public class SpoutHud {
|
||||
SpoutManager.getPlayer(player).getMainScreen().removeWidgets(mcMMO.p);
|
||||
}
|
||||
|
||||
public HudType getHudType() {
|
||||
return hudType;
|
||||
}
|
||||
|
||||
public void setHudType(HudType type) {
|
||||
this.hudType = type;
|
||||
}
|
||||
|
||||
public SkillType getLastGained() {
|
||||
return lastGained;
|
||||
}
|
||||
|
@ -230,14 +230,10 @@ public class Skills {
|
||||
String capitalized = Misc.getCapitalized(skillType.toString());
|
||||
|
||||
/* Spout Stuff */
|
||||
if (mcMMO.spoutEnabled && player instanceof SpoutPlayer) {
|
||||
if (mcMMO.spoutEnabled) {
|
||||
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
|
||||
|
||||
if (spoutPlayer.isSpoutCraftEnabled()) {
|
||||
if (SpoutConfig.getInstance().getXPBarEnabled()) {
|
||||
profile.updateXpBar();
|
||||
}
|
||||
|
||||
if (spoutPlayer != null && spoutPlayer.isSpoutCraftEnabled()) {
|
||||
SpoutStuff.levelUpNotification(skillType, spoutPlayer);
|
||||
|
||||
/* Update custom titles */
|
||||
@ -254,12 +250,12 @@ public class Skills {
|
||||
}
|
||||
}
|
||||
|
||||
/* Always update XP Bar (Check if no levels were gained first to remove redundancy) */
|
||||
if (skillups == 0 && mcMMO.spoutEnabled && player instanceof SpoutPlayer) {
|
||||
if (mcMMO.spoutEnabled) {
|
||||
SpoutPlayer spoutPlayer = (SpoutPlayer) player;
|
||||
if (spoutPlayer.isSpoutCraftEnabled()) {
|
||||
|
||||
if (spoutPlayer != null && spoutPlayer.isSpoutCraftEnabled()) {
|
||||
if (SpoutConfig.getInstance().getXPBarEnabled()) {
|
||||
profile.updateXpBar();
|
||||
profile.getSpoutHud().updateXpBar();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user