Whoops I forgot to push these

This commit is contained in:
nossr50 2019-01-18 12:42:05 -08:00
parent cf6d95b575
commit 9ae58fd2f7
8 changed files with 277 additions and 112 deletions

View File

@ -8,6 +8,7 @@ Key:
- Removal - Removal
Version 2.1.0 Version 2.1.0
+ mcMMO now features XP bars! Configurable in experience.yml
+ Prevented exploits involving blocks made from entities (snowmen, etc..) + Prevented exploits involving blocks made from entities (snowmen, etc..)
+ Added JSON integration to all Skill Commands + Added JSON integration to all Skill Commands
+ Added config setting to enable or disable old mcMMO skill scaling (General.RetroMode) this is on by default for existing installs + Added config setting to enable or disable old mcMMO skill scaling (General.RetroMode) this is on by default for existing installs

View File

@ -8,6 +8,8 @@ import com.gmail.nossr50.datatypes.skills.alchemy.PotionStage;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import java.util.ArrayList; import java.util.ArrayList;
@ -245,6 +247,37 @@ public class ExperienceConfig extends AutoUpdateConfigLoader {
return config.contains(wildcardString); return config.contains(wildcardString);
} }
/*
* Experience Bar Stuff
*/
public BarColor getExperienceBarColor(PrimarySkillType primarySkillType)
{
String colorValueFromConfig = config.getString("Experience_Bars.Style."+StringUtils.getCapitalized(primarySkillType.toString())+".Color");
for(BarColor barColor : BarColor.values())
{
if(barColor.toString().equalsIgnoreCase(colorValueFromConfig))
return barColor;
}
//In case the value is invalid
return BarColor.WHITE;
}
public BarStyle getExperienceBarStyle(PrimarySkillType primarySkillType)
{
String colorValueFromConfig = config.getString("Experience_Bars.Style."+StringUtils.getCapitalized(primarySkillType.toString())+".BarStyle");
for(BarStyle barStyle : BarStyle.values())
{
if(barStyle.toString().equalsIgnoreCase(colorValueFromConfig))
return barStyle;
}
//In case the value is invalid
return BarStyle.SOLID;
}
/* Acrobatics */ /* Acrobatics */
public int getDodgeXPModifier() { return config.getInt("Experience.Acrobatics.Dodge", 120); } public int getDodgeXPModifier() { return config.getInt("Experience.Acrobatics.Dodge", 120); }
public int getRollXPModifier() { return config.getInt("Experience.Acrobatics.Roll", 80); } public int getRollXPModifier() { return config.getInt("Experience.Acrobatics.Roll", 80); }

View File

@ -39,6 +39,7 @@ import com.gmail.nossr50.skills.woodcutting.WoodcuttingManager;
import com.gmail.nossr50.util.EventUtils; import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.experience.ExperienceBarManager;
import com.gmail.nossr50.util.player.NotificationManager; import com.gmail.nossr50.util.player.NotificationManager;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager; import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
@ -65,6 +66,7 @@ public class McMMOPlayer {
private PlayerProfile profile; private PlayerProfile profile;
private final Map<PrimarySkillType, SkillManager> skillManagers = new HashMap<PrimarySkillType, SkillManager>(); private final Map<PrimarySkillType, SkillManager> skillManagers = new HashMap<PrimarySkillType, SkillManager>();
private ExperienceBarManager experienceBarManager;
private Party party; private Party party;
private Party invite; private Party invite;
@ -131,6 +133,34 @@ public class McMMOPlayer {
for (ToolType toolType : ToolType.values()) { for (ToolType toolType : ToolType.values()) {
toolMode.put(toolType, false); toolMode.put(toolType, false);
} }
experienceBarManager = new ExperienceBarManager(this);
}
/*public void hideXpBar(PrimarySkillType primarySkillType)
{
experienceBarManager.hideExperienceBar(primarySkillType);
}*/
public void processPostXpEvent(PrimarySkillType primarySkillType, mcMMO plugin)
{
updateXPBar(primarySkillType, plugin);
}
public void updateXPBar(PrimarySkillType primarySkillType, mcMMO plugin)
{
/*if(experienceBarManager == null)
experienceBarManager = new ExperienceBarManager(this);*/
experienceBarManager.updateExperienceBar(primarySkillType, plugin);
}
public double getProgressInCurrentSkillLevel(PrimarySkillType primarySkillType)
{
double currentXP = profile.getSkillXpLevel(primarySkillType);
double maxXP = profile.getXpToLevel(primarySkillType);
return (currentXP / maxXP);
} }
public AcrobaticsManager getAcrobaticsManager() { public AcrobaticsManager getAcrobaticsManager() {

View File

@ -8,6 +8,7 @@ import com.gmail.nossr50.datatypes.skills.XPGainReason;
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent; import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent; import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityActivateEvent; import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityActivateEvent;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager; import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -16,6 +17,14 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
public class SelfListener implements Listener { public class SelfListener implements Listener {
//Used in task scheduling and other things
private final mcMMO plugin;
public SelfListener(mcMMO plugin)
{
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerLevelUp(McMMOPlayerLevelUpEvent event) { public void onPlayerLevelUp(McMMOPlayerLevelUpEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
@ -44,12 +53,23 @@ public class SelfListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerXpGain(McMMOPlayerXpGainEvent event) { public void onPlayerXpGain(McMMOPlayerXpGainEvent event) {
if (event.getXpGainReason() == XPGainReason.COMMAND) Player player = event.getPlayer();
return; McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
PrimarySkillType primarySkillType = event.getSkill(); PrimarySkillType primarySkillType = event.getSkill();
if (event.getXpGainReason() == XPGainReason.COMMAND)
{
//Update the XP Bar
mcMMOPlayer.processPostXpEvent(primarySkillType, plugin);
return;
}
int threshold = ExperienceConfig.getInstance().getDiminishedReturnsThreshold(primarySkillType); int threshold = ExperienceConfig.getInstance().getDiminishedReturnsThreshold(primarySkillType);
if (threshold <= 0 || !ExperienceConfig.getInstance().getDiminishedReturnsEnabled()) { if (threshold <= 0 || !ExperienceConfig.getInstance().getDiminishedReturnsEnabled()) {
// Diminished returns is turned off // Diminished returns is turned off
//Update the XP Bar
mcMMOPlayer.processPostXpEvent(primarySkillType, plugin);
return; return;
} }
@ -59,9 +79,6 @@ public class SelfListener implements Listener {
return; return;
} }
Player player = event.getPlayer();
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if (primarySkillType.isChildSkill()) { if (primarySkillType.isChildSkill()) {
return; return;
} }
@ -95,5 +112,9 @@ public class SelfListener implements Listener {
} }
} }
//Update the XP Bar
if(!event.isCancelled())
mcMMOPlayer.processPostXpEvent(primarySkillType, plugin);
} }
} }

View File

@ -441,7 +441,7 @@ public class mcMMO extends JavaPlugin {
pluginManager.registerEvents(new BlockListener(this), this); pluginManager.registerEvents(new BlockListener(this), this);
pluginManager.registerEvents(new EntityListener(this), this); pluginManager.registerEvents(new EntityListener(this), this);
pluginManager.registerEvents(new InventoryListener(this), this); pluginManager.registerEvents(new InventoryListener(this), this);
pluginManager.registerEvents(new SelfListener(), this); pluginManager.registerEvents(new SelfListener(this), this);
pluginManager.registerEvents(new WorldListener(this), this); pluginManager.registerEvents(new WorldListener(this), this);
} }

View File

@ -1,5 +1,69 @@
package com.gmail.nossr50.util.experience; package com.gmail.nossr50.util.experience;
public class ExperienceBar { import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.runnables.skills.ExperienceBarHideTask;
import java.util.HashMap;
/**
* ExperienceBarManager handles displaying and updating mcMMO experience bars for players
* Each ExperienceBarManager only manages a single player
*/
public class ExperienceBarManager {
private McMMOPlayer mcMMOPlayer;
HashMap<PrimarySkillType, ExperienceBarWrapper> experienceBars;
HashMap<PrimarySkillType, ExperienceBarHideTask> experienceBarHideTaskHashMap;
public ExperienceBarManager(McMMOPlayer mcMMOPlayer)
{
//Init map
experienceBars = new HashMap<>();
experienceBarHideTaskHashMap = new HashMap<>();
this.mcMMOPlayer = mcMMOPlayer;
}
public void updateExperienceBar(PrimarySkillType primarySkillType, mcMMO plugin)
{
//Init Bar
if(experienceBars.get(primarySkillType) == null)
experienceBars.put(primarySkillType, new ExperienceBarWrapper(primarySkillType, mcMMOPlayer));
//Get Bar
ExperienceBarWrapper experienceBarWrapper = experienceBars.get(primarySkillType);
//Update Progress
experienceBarWrapper.setProgress(mcMMOPlayer.getProgressInCurrentSkillLevel(primarySkillType));
//Show Bar
experienceBarWrapper.showExperienceBar();
//Setup Hide Bar Task
if(experienceBarHideTaskHashMap.get(primarySkillType) != null)
{
experienceBarHideTaskHashMap.get(primarySkillType).cancel();
scheduleHideTask(primarySkillType, plugin);
} else {
scheduleHideTask(primarySkillType, plugin);
}
}
private void scheduleHideTask(PrimarySkillType primarySkillType, mcMMO plugin) {
ExperienceBarHideTask experienceBarHideTask = new ExperienceBarHideTask(this, mcMMOPlayer, primarySkillType);
experienceBarHideTask.runTaskLater(plugin, 20*2);
experienceBarHideTaskHashMap.put(primarySkillType, experienceBarHideTask);
}
public void hideExperienceBar(PrimarySkillType primarySkillType)
{
experienceBars.get(primarySkillType).hideExperienceBar();
}
public void clearTask(PrimarySkillType primarySkillType)
{
experienceBarHideTaskHashMap.remove(primarySkillType);
}
} }

View File

@ -1,149 +1,139 @@
package com.gmail.nossr50.util.experience; package com.gmail.nossr50.util.experience;
import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.Server;
import org.bukkit.boss.*; import org.bukkit.boss.*;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* A visual representation of a players skill level progress for a PrimarySkillType * A visual representation of a players skill level progress for a PrimarySkillType
*/ */
public class ExperienceBar { public class ExperienceBarWrapper {
private final PrimarySkillType primarySkillType; //Primary Skill private final PrimarySkillType primarySkillType; //Primary Skill
protected String experienceBarTitle; //Name Shown Above XP Bar private BossBar bossBar;
protected BarColor barColor; //Color of the XP Bar private final Server server;
protected BarStyle barStyle; protected final McMMOPlayer mcMMOPlayer;
protected Player player; private int lastLevelUpdated;
protected double progress;
protected boolean isVisible;
public ExperienceBar(PrimarySkillType primarySkillType, Player player) /*
* This is stored to help optimize updating the title
*/
protected String niceSkillName;
protected String title;
public ExperienceBarWrapper(PrimarySkillType primarySkillType, McMMOPlayer mcMMOPlayer)
{ {
this.player = player; this.mcMMOPlayer = mcMMOPlayer;
this.server = mcMMOPlayer.getPlayer().getServer(); //Might not be good for bungee to do this
this.primarySkillType = primarySkillType; this.primarySkillType = primarySkillType;
experienceBarTitle = StringUtils.getCapitalized(primarySkillType.getName()); title = "";
barColor = ExperienceConfig.getInstance().getExperienceBarColor(primarySkillType); lastLevelUpdated = 0;
barStyle = BarStyle.SOLID;
isVisible = false; //These vars are stored to help reduce operations involving strings
progress = 0.0D; niceSkillName = StringUtils.getCapitalized(primarySkillType.toString());
//Create the bar
initBar();
}
private void initBar()
{
title = getTitleTemplate();
createBossBar();
}
public void updateTitle() {
title = getTitleTemplate();
bossBar.setTitle(title);
}
private String getTitleTemplate() {
return niceSkillName + " Lv." + ChatColor.GOLD + getLevel();
}
private int getLevel() {
return mcMMOPlayer.getSkillLevel(primarySkillType);
} }
public String getTitle() { public String getTitle() {
return experienceBarTitle; return bossBar.getTitle();
} }
public void setTitle(String s) { public void setTitle(String s) {
experienceBarTitle = s; bossBar.setTitle(s);
} }
public BarColor getColor() { public BarColor getColor() {
return barColor; return bossBar.getColor();
} }
public void setColor(BarColor barColor) { public void setColor(BarColor barColor) {
this.barColor = barColor; bossBar.setColor(barColor);
} }
public BarStyle getStyle() { public BarStyle getStyle() {
//TODO: Add config for style return bossBar.getStyle();
return barStyle;
} }
public void setStyle(BarStyle barStyle) { public void setStyle(BarStyle barStyle) {
this.barStyle = barStyle; bossBar.setStyle(barStyle);
} }
public void removeFlag(BarFlag barFlag) {
//Do nothing
}
public void addFlag(BarFlag barFlag) {
//Do nothing
}
public boolean hasFlag(BarFlag barFlag) {
return false;
}
public void setProgress(double v) { public void setProgress(double v) {
//Clamp progress between 0.00 -> 1.00 //Clamp Values
if(v < 0) if(v < 0)
progress = 0.0D; bossBar.setProgress(0.0D);
else if(progress > 1)
progress = 1.0D;
else progress = v;
}
else if(v > 1)
bossBar.setProgress(1.0D);
else
bossBar.setProgress(v);
//Every time progress updates we need to check for a title update
if(getLevel() != lastLevelUpdated)
{
updateTitle();
lastLevelUpdated = getLevel();
}
}
public double getProgress() { public double getProgress() {
return progress; return bossBar.getProgress();
} }
public void addPlayer(Player player) {
//Do nothing
}
public void removePlayer(Player player) {
//Do nothing
}
public void removeAll() {
//Do nothing
}
public List<Player> getPlayers() { public List<Player> getPlayers() {
List<Player> players = new ArrayList<>(); return bossBar.getPlayers();
players.add(player);
return players;
} }
public void setVisible(boolean b) {
isVisible = b;
if(isVisible)
showExperienceBar();
}
public boolean isVisible() { public boolean isVisible() {
return isVisible; return bossBar.isVisible();
}
public void hideExperienceBar()
{
bossBar.setVisible(false);
} }
public void showExperienceBar() public void showExperienceBar()
{ {
player.getServer().createBossBar() bossBar.setVisible(true);
} }
/** /*public NamespacedKey getKey()
* @deprecated {
*/ return bossBar
}*/
public void show() { private void createBossBar()
//Do nothing {
} bossBar = mcMMOPlayer.getPlayer().getServer().createBossBar(title, ExperienceConfig.getInstance().getExperienceBarColor(primarySkillType), ExperienceConfig.getInstance().getExperienceBarStyle(primarySkillType));
bossBar.addPlayer(mcMMOPlayer.getPlayer());
/**
* @deprecated
*/
public void hide() {
//Do nothing
} }
} }

View File

@ -11,38 +11,64 @@
# https://hub.spigotmc.org/javadocs/spigot/org/bukkit/boss/BarColor.html # https://hub.spigotmc.org/javadocs/spigot/org/bukkit/boss/BarColor.html
# These are the only valid colors for Experience Bars, use the exact name found here # These are the only valid colors for Experience Bars, use the exact name found here
# BLUE, GREEN, PINK, PURPLE, RED, WHITE, YELLOW (As of the time of this update these are the only Bar colors available, this could change in the future so check the BarColor enum to see if it has) # BLUE, GREEN, PINK, PURPLE, RED, WHITE, YELLOW (As of the time of this update these are the only Bar colors available, this could change in the future so check the BarColor enum to see if it has)
# BarStyle Settings (USE THE EXACT NAME) :
#SEGMENTED_10
# Splits the boss bar into 10 segments
#SEGMENTED_12
# Splits the boss bar into 12 segments
#SEGMENTED_20
# Splits the boss bar into 20 segments
#SEGMENTED_6
# Splits the boss bar into 6 segments
#SOLID
# The bar is one solid piece
Experience_Bars: Experience_Bars:
Style: Style:
Acrobatics: Acrobatics:
Color: BLUE Color: PINK
BarStyle: SEGMENTED_6
Alchemy: Alchemy:
Color: BLUE Color: PURPLE
BarStyle: SEGMENTED_6
Archery: Archery:
Color: RED Color: BLUE
BarStyle: SEGMENTED_6
Axes: Axes:
Color: RED Color: BLUE
BarStyle: SEGMENTED_6
Excavation: Excavation:
Color: YELLOW Color: YELLOW
BarStyle: SEGMENTED_6
Fishing: Fishing:
Color: BLUE Color: PURPLE
BarStyle: SEGMENTED_6
Herbalism: Herbalism:
Color: GREEN Color: GREEN
BarStyle: SEGMENTED_6
Mining: Mining:
Color: YELLOW Color: YELLOW
BarStyle: SEGMENTED_6
Repair: Repair:
Color: BLUE
Salvage:
Color: BLUE
Smelting:
Color: BLUE
Swords:
Color: RED
Taming:
Color: PURPLE Color: PURPLE
Unarmed: BarStyle: SEGMENTED_6
Salvage:
Color: PURPLE
BarStyle: SEGMENTED_6
Smelting:
Color: PURPLE
BarStyle: SEGMENTED_6
Swords:
Color: BLUE
BarStyle: SEGMENTED_6
Taming:
Color: RED Color: RED
BarStyle: SEGMENTED_6
Unarmed:
Color: BLUE
BarStyle: SEGMENTED_6
Woodcutting: Woodcutting:
Color: GREEN Color: GREEN
BarStyle: SEGMENTED_6
# #
# Settings for XP formula # Settings for XP formula
### ###