mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 23:26:45 +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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
switch (args.length) {
|
||||||
case 1:
|
case 1:
|
||||||
Player player = (Player) sender;
|
|
||||||
PlayerProfile playerProfile = Users.getProfile(player);
|
|
||||||
|
|
||||||
for (HudType hudType : HudType.values()) {
|
for (HudType hudType : HudType.values()) {
|
||||||
if (hudType.toString().equalsIgnoreCase(args[0])) {
|
if (hudType.toString().equalsIgnoreCase(args[0])) {
|
||||||
playerProfile.setHudType(hudType);
|
playerProfile.setHudType(hudType);
|
||||||
|
spoutHud.initializeXpBar();
|
||||||
SpoutHud spoutHud = playerProfile.getSpoutHud();
|
spoutHud.updateXpBar();
|
||||||
|
|
||||||
if (spoutHud != null) {
|
|
||||||
spoutHud.initializeXpBar();
|
|
||||||
spoutHud.updateXpBar();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -54,7 +55,7 @@ public class MchudCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
sender.sendMessage(usage);
|
player.sendMessage(usage);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import com.gmail.nossr50.config.Config;
|
|||||||
import com.gmail.nossr50.config.SpoutConfig;
|
import com.gmail.nossr50.config.SpoutConfig;
|
||||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||||
import com.gmail.nossr50.datatypes.SkillType;
|
import com.gmail.nossr50.datatypes.SkillType;
|
||||||
|
import com.gmail.nossr50.datatypes.SpoutHud;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
import com.gmail.nossr50.util.Misc;
|
import com.gmail.nossr50.util.Misc;
|
||||||
import com.gmail.nossr50.util.Permissions;
|
import com.gmail.nossr50.util.Permissions;
|
||||||
@ -34,20 +35,26 @@ public class XplockCommand implements CommandExecutor {
|
|||||||
|
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
PlayerProfile playerProfile = Users.getProfile(player);
|
PlayerProfile playerProfile = Users.getProfile(player);
|
||||||
|
SpoutHud spoutHud = playerProfile.getSpoutHud();
|
||||||
|
|
||||||
|
if (spoutHud == null) {
|
||||||
|
sender.sendMessage(LocaleLoader.getString("Commands.Disabled"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 0:
|
case 0:
|
||||||
if (playerProfile.getXpBarLocked()) {
|
if (spoutHud.getXpBarLocked()) {
|
||||||
playerProfile.toggleXpBarLocked();
|
spoutHud.toggleXpBarLocked();
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.xplock.unlocked"));
|
player.sendMessage(LocaleLoader.getString("Commands.xplock.unlocked"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkillType lastGained = playerProfile.getLastGained();
|
SkillType lastGained = spoutHud.getLastGained();
|
||||||
|
|
||||||
if (lastGained != null) {
|
if (lastGained != null) {
|
||||||
playerProfile.toggleXpBarLocked();
|
spoutHud.toggleXpBarLocked();
|
||||||
playerProfile.setSkillLock(lastGained);
|
spoutHud.setSkillLock(lastGained);
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.xplock.locked", new Object[] { Misc.getCapitalized(lastGained.toString()) }));
|
player.sendMessage(LocaleLoader.getString("Commands.xplock.locked", new Object[] { Misc.getCapitalized(lastGained.toString()) }));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -59,9 +66,9 @@ public class XplockCommand implements CommandExecutor {
|
|||||||
case 1:
|
case 1:
|
||||||
if (Skills.isSkill(args[0])) {
|
if (Skills.isSkill(args[0])) {
|
||||||
if (Permissions.getInstance().permission(player, "mcmmo.skills." + args[0].toLowerCase())) {
|
if (Permissions.getInstance().permission(player, "mcmmo.skills." + args[0].toLowerCase())) {
|
||||||
playerProfile.setXpBarLocked(true);
|
spoutHud.setXpBarLocked(true);
|
||||||
playerProfile.setSkillLock(Skills.getSkillType(args[0]));
|
spoutHud.setSkillLock(Skills.getSkillType(args[0]));
|
||||||
playerProfile.updateXpBar();
|
spoutHud.updateXpBar();
|
||||||
|
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.xplock.locked", new Object[] { Misc.getCapitalized(args[0]) }));
|
player.sendMessage(LocaleLoader.getString("Commands.xplock.locked", new Object[] { Misc.getCapitalized(args[0]) }));
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,12 @@ public class McMMOPlayer {
|
|||||||
else {
|
else {
|
||||||
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, skillType, xp));
|
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, skillType, xp));
|
||||||
profile.setSkillXPLevel(skillType, profile.getSkillXpLevel(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));
|
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, skillType, xp));
|
||||||
profile.setSkillXPLevel(skillType, profile.getSkillXpLevel(skillType) + xp);
|
profile.setSkillXPLevel(skillType, profile.getSkillXpLevel(skillType) + xp);
|
||||||
profile.setLastGained(skillType);
|
|
||||||
|
SpoutHud spoutHud = profile.getSpoutHud();
|
||||||
|
|
||||||
|
if (spoutHud != null) {
|
||||||
|
spoutHud.setLastGained(skillType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Players & Profiles
|
// Players & Profiles
|
||||||
|
@ -20,6 +20,7 @@ public class PlayerProfile {
|
|||||||
|
|
||||||
/* HUD */
|
/* HUD */
|
||||||
private SpoutHud spoutHud;
|
private SpoutHud spoutHud;
|
||||||
|
private HudType hudType = SpoutConfig.getInstance().defaultHudType;
|
||||||
|
|
||||||
/* Party Stuff */
|
/* Party Stuff */
|
||||||
private Party party;
|
private Party party;
|
||||||
@ -98,7 +99,7 @@ public class PlayerProfile {
|
|||||||
else {
|
else {
|
||||||
for (HudType type : HudType.values()) {
|
for (HudType type : HudType.values()) {
|
||||||
if (type.toString().equals(huds.get(1).get(0))) {
|
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) {
|
if (character.length > 33) {
|
||||||
for (HudType type : HudType.values()) {
|
for (HudType type : HudType.values()) {
|
||||||
if (type.toString().equalsIgnoreCase(character[33])) {
|
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 we are using mysql save to database
|
||||||
if (Config.getInstance().getUseMySQL()) {
|
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() + "users SET lastlogin = " + timestamp.intValue() + " WHERE id = " + userId);
|
||||||
mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "cooldowns SET "
|
mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "cooldowns SET "
|
||||||
+ " mining = " + skillsDATS.get(AbilityType.SUPER_BREAKER)
|
+ " 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.SERRATED_STRIKES)) + ":");
|
||||||
writer.append(String.valueOf(skillsDATS.get(AbilityType.SKULL_SPLIITER)) + ":");
|
writer.append(String.valueOf(skillsDATS.get(AbilityType.SKULL_SPLIITER)) + ":");
|
||||||
writer.append(String.valueOf(skillsDATS.get(AbilityType.SUPER_BREAKER)) + ":");
|
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(skills.get(SkillType.FISHING) + ":");
|
||||||
writer.append(skillsXp.get(SkillType.FISHING) + ":");
|
writer.append(skillsXp.get(SkillType.FISHING) + ":");
|
||||||
writer.append(String.valueOf(skillsDATS.get(AbilityType.BLAST_MINING)) + ":");
|
writer.append(String.valueOf(skillsDATS.get(AbilityType.BLAST_MINING)) + ":");
|
||||||
@ -475,6 +476,10 @@ public class PlayerProfile {
|
|||||||
* HUD Stuff
|
* HUD Stuff
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
public HudType getHudType() {
|
||||||
|
return hudType;
|
||||||
|
}
|
||||||
|
|
||||||
public SpoutHud getSpoutHud() {
|
public SpoutHud getSpoutHud() {
|
||||||
return spoutHud;
|
return spoutHud;
|
||||||
}
|
}
|
||||||
@ -483,44 +488,8 @@ public class PlayerProfile {
|
|||||||
this.spoutHud = spoutHud;
|
this.spoutHud = spoutHud;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setXpBarLocked(boolean locked) {
|
public void setHudType(HudType hudType) {
|
||||||
spoutHud.setXpBarLocked(locked);
|
this.hudType = hudType;
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -12,7 +12,6 @@ public class SpoutHud {
|
|||||||
private Player player;
|
private Player player;
|
||||||
private PlayerProfile profile;
|
private PlayerProfile profile;
|
||||||
|
|
||||||
private HudType hudType = SpoutConfig.getInstance().defaultHudType;
|
|
||||||
private SkillType lastGained;
|
private SkillType lastGained;
|
||||||
private SkillType skillLock;
|
private SkillType skillLock;
|
||||||
private boolean xpBarLocked;
|
private boolean xpBarLocked;
|
||||||
@ -36,7 +35,7 @@ public class SpoutHud {
|
|||||||
xpBar.removeWidgets();
|
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);
|
SpoutManager.getPlayer(player).getMainScreen().removeWidgets(mcMMO.p);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HudType getHudType() {
|
|
||||||
return hudType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHudType(HudType type) {
|
|
||||||
this.hudType = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SkillType getLastGained() {
|
public SkillType getLastGained() {
|
||||||
return lastGained;
|
return lastGained;
|
||||||
}
|
}
|
||||||
|
@ -230,14 +230,10 @@ public class Skills {
|
|||||||
String capitalized = Misc.getCapitalized(skillType.toString());
|
String capitalized = Misc.getCapitalized(skillType.toString());
|
||||||
|
|
||||||
/* Spout Stuff */
|
/* Spout Stuff */
|
||||||
if (mcMMO.spoutEnabled && player instanceof SpoutPlayer) {
|
if (mcMMO.spoutEnabled) {
|
||||||
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
|
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
|
||||||
|
|
||||||
if (spoutPlayer.isSpoutCraftEnabled()) {
|
if (spoutPlayer != null && spoutPlayer.isSpoutCraftEnabled()) {
|
||||||
if (SpoutConfig.getInstance().getXPBarEnabled()) {
|
|
||||||
profile.updateXpBar();
|
|
||||||
}
|
|
||||||
|
|
||||||
SpoutStuff.levelUpNotification(skillType, spoutPlayer);
|
SpoutStuff.levelUpNotification(skillType, spoutPlayer);
|
||||||
|
|
||||||
/* Update custom titles */
|
/* 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 (mcMMO.spoutEnabled) {
|
||||||
if (skillups == 0 && mcMMO.spoutEnabled && player instanceof SpoutPlayer) {
|
|
||||||
SpoutPlayer spoutPlayer = (SpoutPlayer) player;
|
SpoutPlayer spoutPlayer = (SpoutPlayer) player;
|
||||||
if (spoutPlayer.isSpoutCraftEnabled()) {
|
|
||||||
|
if (spoutPlayer != null && spoutPlayer.isSpoutCraftEnabled()) {
|
||||||
if (SpoutConfig.getInstance().getXPBarEnabled()) {
|
if (SpoutConfig.getInstance().getXPBarEnabled()) {
|
||||||
profile.updateXpBar();
|
profile.getSpoutHud().updateXpBar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user