You can now level up the default class

This commit is contained in:
Jules 2020-04-03 00:18:51 +02:00
parent 8e9744f02b
commit ae3d8897e8
4 changed files with 39 additions and 26 deletions

View File

@ -54,12 +54,16 @@ import net.mmogroup.mmolib.version.VersionSound;
public class PlayerData extends OfflinePlayerData { public class PlayerData extends OfflinePlayerData {
/* /*
* is updated everytime the player joins the server. it is kept when the * is updated everytime the player joins the server. it is kept when the player
* player is offline so the plugin can use #isOnline to check if the player * is offline so the plugin can use #isOnline to check if the player is online
* is online
*/ */
private Player player; private Player player;
/*
* 'profess' can be null, you need to retrieve the player class using the
* getProfess() method which should never return null if the plugin is
* configured right
*/
private PlayerClass profess; private PlayerClass profess;
private int level, experience, classPoints, skillPoints, attributePoints, attributeReallocationPoints;// skillReallocationPoints, private int level, experience, classPoints, skillPoints, attributePoints, attributeReallocationPoints;// skillReallocationPoints,
private double mana, stamina, stellium; private double mana, stamina, stellium;
@ -104,7 +108,8 @@ public class PlayerData extends OfflinePlayerData {
try { try {
profess = profess == null ? null : MMOCore.plugin.classManager.get(profess.getId()); profess = profess == null ? null : MMOCore.plugin.classManager.get(profess.getId());
} catch (NullPointerException exception) { } catch (NullPointerException exception) {
MMOCore.log(Level.SEVERE, "[Userdata] Could not find class " + getProfess().getId() + " while refreshing player data."); MMOCore.log(Level.SEVERE,
"[Userdata] Could not find class " + getProfess().getId() + " while refreshing player data.");
} }
int j = 0; int j = 0;
@ -114,7 +119,8 @@ public class PlayerData extends OfflinePlayerData {
j++; j++;
} catch (NullPointerException notFound) { } catch (NullPointerException notFound) {
boundSkills.remove(j); boundSkills.remove(j);
MMOCore.log(Level.SEVERE, "[Userdata] Could not find skill " + boundSkills.get(j).getSkill().getId() + " in class " + getProfess().getId() + " while refreshing player data."); MMOCore.log(Level.SEVERE, "[Userdata] Could not find skill " + boundSkills.get(j).getSkill().getId()
+ " in class " + getProfess().getId() + " while refreshing player data.");
} }
} }
@ -218,13 +224,13 @@ public class PlayerData extends OfflinePlayerData {
public void giveLevels(int value) { public void giveLevels(int value) {
int total = 0; int total = 0;
while (value-- > 0) while (value-- > 0)
total += MMOCore.plugin.configManager.getNeededExperience(getLevel() + value + 1, profess); total += MMOCore.plugin.configManager.getNeededExperience(getLevel() + value + 1, getProfess());
giveExperience(total); giveExperience(total);
} }
public void setExperience(int value) { public void setExperience(int value) {
experience = Math.max(0, value); experience = Math.max(0, value);
refreshVanillaExp(MMOCore.plugin.configManager.getNeededExperience(getLevel() + 1, profess)); refreshVanillaExp(MMOCore.plugin.configManager.getNeededExperience(getLevel() + 1, getProfess()));
} }
public void refreshVanillaExp(float needed) { public void refreshVanillaExp(float needed) {
@ -295,7 +301,8 @@ public class PlayerData extends OfflinePlayerData {
} }
public void heal(double heal) { public void heal(double heal) {
double newest = Math.max(0, Math.min(player.getHealth() + heal, player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue())); double newest = Math.max(0,
Math.min(player.getHealth() + heal, player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()));
if (player.getHealth() == newest) if (player.getHealth() == newest)
return; return;
@ -341,7 +348,9 @@ public class PlayerData extends OfflinePlayerData {
setLastFriendRequest(System.currentTimeMillis()); setLastFriendRequest(System.currentTimeMillis());
FriendRequest request = new FriendRequest(this, target); FriendRequest request = new FriendRequest(this, target);
new ConfigMessage("friend-request").addPlaceholders("player", getPlayer().getName(), "uuid", request.getUniqueId().toString()).sendAsJSon(target.getPlayer()); new ConfigMessage("friend-request")
.addPlaceholders("player", getPlayer().getName(), "uuid", request.getUniqueId().toString())
.sendAsJSon(target.getPlayer());
MMOCore.plugin.requestManager.registerRequest(request); MMOCore.plugin.requestManager.registerRequest(request);
} }
@ -350,10 +359,12 @@ public class PlayerData extends OfflinePlayerData {
giveStellium(-waypoint.getStelliumCost()); giveStellium(-waypoint.getStelliumCost());
new BukkitRunnable() { new BukkitRunnable() {
int x = player.getLocation().getBlockX(), y = player.getLocation().getBlockY(), z = player.getLocation().getBlockZ(), t; int x = player.getLocation().getBlockX(), y = player.getLocation().getBlockY(),
z = player.getLocation().getBlockZ(), t;
public void run() { public void run() {
if (player.getLocation().getBlockX() != x || player.getLocation().getBlockY() != y || player.getLocation().getBlockZ() != z) { if (player.getLocation().getBlockX() != x || player.getLocation().getBlockY() != y
|| player.getLocation().getBlockZ() != z) {
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, .5f); player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, .5f);
MMOCore.plugin.configManager.getSimpleMessage("warping-canceled").send(player); MMOCore.plugin.configManager.getSimpleMessage("warping-canceled").send(player);
giveStellium(waypoint.getStelliumCost()); giveStellium(waypoint.getStelliumCost());
@ -361,7 +372,8 @@ public class PlayerData extends OfflinePlayerData {
return; return;
} }
MMOCore.plugin.configManager.getSimpleMessage("warping-comencing", "left", "" + ((120 - t) / 20)).send(player); MMOCore.plugin.configManager.getSimpleMessage("warping-comencing", "left", "" + ((120 - t) / 20))
.send(player);
if (t++ >= 100) { if (t++ >= 100) {
player.teleport(waypoint.getLocation()); player.teleport(waypoint.getLocation());
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20, 1, false, false)); player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20, 1, false, false));
@ -370,10 +382,13 @@ public class PlayerData extends OfflinePlayerData {
return; return;
} }
player.playSound(player.getLocation(), VersionSound.BLOCK_NOTE_BLOCK_BELL.toSound(), 1, (float) (t / Math.PI * .015 + .5)); player.playSound(player.getLocation(), VersionSound.BLOCK_NOTE_BLOCK_BELL.toSound(), 1,
(float) (t / Math.PI * .015 + .5));
double r = Math.sin((double) t / 100 * Math.PI); double r = Math.sin((double) t / 100 * Math.PI);
for (double j = 0; j < Math.PI * 2; j += Math.PI / 4) for (double j = 0; j < Math.PI * 2; j += Math.PI / 4)
MMOLib.plugin.getVersion().getWrapper().spawnParticle(Particle.REDSTONE, player.getLocation().add(Math.cos((double) t / 20 + j) * r, (double) t / 50, Math.sin((double) t / 20 + j) * r), 1.25f, Color.PURPLE); MMOLib.plugin.getVersion().getWrapper().spawnParticle(Particle.REDSTONE, player.getLocation()
.add(Math.cos((double) t / 20 + j) * r, (double) t / 50, Math.sin((double) t / 20 + j) * r),
1.25f, Color.PURPLE);
} }
}.runTaskTimer(MMOCore.plugin, 0, 1); }.runTaskTimer(MMOCore.plugin, 0, 1);
} }
@ -387,7 +402,7 @@ public class PlayerData extends OfflinePlayerData {
} }
public void giveExperience(int value, Location loc) { public void giveExperience(int value, Location loc) {
if (profess == null || hasReachedMaxLevel()) { if (hasReachedMaxLevel()) {
setExperience(0); setExperience(0);
return; return;
} }
@ -395,7 +410,9 @@ public class PlayerData extends OfflinePlayerData {
// display hologram // display hologram
if (MMOCore.plugin.getConfig().getBoolean("display-exp-holograms")) if (MMOCore.plugin.getConfig().getBoolean("display-exp-holograms"))
if (loc != null && MMOCore.plugin.hologramSupport != null) if (loc != null && MMOCore.plugin.hologramSupport != null)
MMOCore.plugin.hologramSupport.displayIndicator(loc.add(.5, 1.5, .5), MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message(), getPlayer()); MMOCore.plugin.hologramSupport.displayIndicator(loc.add(.5, 1.5, .5),
MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message(),
getPlayer());
value = MMOCore.plugin.boosterManager.calculateExp(null, value); value = MMOCore.plugin.boosterManager.calculateExp(null, value);
value *= 1 + getStats().getStat(StatType.ADDITIONAL_EXPERIENCE) / 100; value *= 1 + getStats().getStat(StatType.ADDITIONAL_EXPERIENCE) / 100;
@ -409,7 +426,7 @@ public class PlayerData extends OfflinePlayerData {
int needed; int needed;
boolean check = false; boolean check = false;
while (experience >= (needed = MMOCore.plugin.configManager.getNeededExperience(getLevel() + 1, profess))) { while (experience >= (needed = MMOCore.plugin.configManager.getNeededExperience(getLevel() + 1, getProfess()))) {
if (hasReachedMaxLevel()) { if (hasReachedMaxLevel()) {
experience = 0; experience = 0;
@ -517,8 +534,8 @@ public class PlayerData extends OfflinePlayerData {
} }
/* /*
* returns if the action bar is not being used to display anything else and * returns if the action bar is not being used to display anything else and if
* if the general info action bar can be displayed * the general info action bar can be displayed
*/ */
public boolean canSeeActionBar() { public boolean canSeeActionBar() {
return actionBarTimeOut < System.currentTimeMillis(); return actionBarTimeOut < System.currentTimeMillis();
@ -614,10 +631,6 @@ public class PlayerData extends OfflinePlayerData {
getStats().getMap().updateAll(); getStats().getMap().updateAll();
} }
public void setProfess(PlayerClass profess) {
this.profess = profess;
}
public boolean hasSkillBound(int slot) { public boolean hasSkillBound(int slot) {
return slot < boundSkills.size(); return slot < boundSkills.size();
} }

View File

@ -72,7 +72,7 @@ public class ClassManager extends MMOManager {
} }
public void reloadPlayerClasses() { public void reloadPlayerClasses() {
PlayerData.getAll().forEach(data -> data.setProfess(get(data.getProfess().getId()))); PlayerData.getAll().forEach(data -> data.setClass(get(data.getProfess().getId())));
} }
@Override @Override

View File

@ -50,7 +50,7 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
data.setLevel(result.getInt("level")); data.setLevel(result.getInt("level"));
data.setExperience(result.getInt("experience")); data.setExperience(result.getInt("experience"));
if (!isEmpty(result.getString("class"))) if (!isEmpty(result.getString("class")))
data.setProfess(MMOCore.plugin.classManager.get(result.getString("class"))); data.setClass(MMOCore.plugin.classManager.get(result.getString("class")));
data.setMana(data.getStats().getStat(StatType.MAX_MANA)); data.setMana(data.getStats().getStat(StatType.MAX_MANA));
data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA)); data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA));
data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM)); data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM));

View File

@ -31,7 +31,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
data.setLevel(config.getInt("level")); data.setLevel(config.getInt("level"));
data.setExperience(config.getInt("experience")); data.setExperience(config.getInt("experience"));
if (config.contains("class")) if (config.contains("class"))
data.setProfess(MMOCore.plugin.classManager.get(config.getString("class"))); data.setClass(MMOCore.plugin.classManager.get(config.getString("class")));
data.setMana(data.getStats().getStat(StatType.MAX_MANA)); data.setMana(data.getStats().getStat(StatType.MAX_MANA));
data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA)); data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA));
data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM)); data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM));