mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-27 19:24:44 +02:00
Major refactoring. This WILL break any mcMMO-related plugin that
does not properly hook into the API classes. This consolidates the skill-related classes into their own individual packages, and moves several misc skill classes into the main Skill package as well. This also moves all Party & Spout related files into their own respective packages as well.
This commit is contained in:
95
src/main/java/com/gmail/nossr50/spout/SpoutConfig.java
Normal file
95
src/main/java/com/gmail/nossr50/spout/SpoutConfig.java
Normal file
@ -0,0 +1,95 @@
|
||||
package com.gmail.nossr50.spout;
|
||||
|
||||
import com.gmail.nossr50.config.ConfigLoader;
|
||||
import com.gmail.nossr50.spout.huds.HudType;
|
||||
|
||||
public class SpoutConfig extends ConfigLoader {
|
||||
private static SpoutConfig instance;
|
||||
public HudType defaultHudType;
|
||||
|
||||
private SpoutConfig() {
|
||||
super("spout.yml");
|
||||
loadKeys();
|
||||
}
|
||||
|
||||
public static SpoutConfig getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new SpoutConfig();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadKeys() {
|
||||
// Setup default HUD
|
||||
String temp = config.getString("Spout.HUD.Default", "STANDARD");
|
||||
|
||||
for (HudType hudType : HudType.values()) {
|
||||
if (hudType.toString().equalsIgnoreCase(temp.toString())) {
|
||||
defaultHudType = hudType;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (defaultHudType == null) {
|
||||
defaultHudType = HudType.STANDARD;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getShowPowerLevel() { return config.getBoolean("HUD.Show_Power_Level", true); }
|
||||
public String getMenuKey() { return config.getString("Menu.Key", "KEY_M"); }
|
||||
|
||||
/* XP Bar */
|
||||
public boolean getXPBarEnabled() { return config.getBoolean("XP.Bar.Enabled", true); }
|
||||
public boolean getXPBarIconEnabled() { return config.getBoolean("XP.Icon.Enabled", true); }
|
||||
public int getXPBarXPosition() { return config.getInt("XP.Bar.X_POS", 95); }
|
||||
public int getXPBarYPosition() { return config.getInt("XP.Bar.Y_POS", 6); }
|
||||
public int getXPIconXPosition() { return config.getInt("XP.Icon.X_POS", 78); }
|
||||
public int getXPIconYPosition() { return config.getInt("XP.Icon.Y_POS", 2); }
|
||||
|
||||
/* HUD Colors */
|
||||
public double getRetroHUDXPBorderRed() { return config.getDouble("HUD.Retro.Colors.Border.RED", 0.0); }
|
||||
public double getRetroHUDXPBorderGreen() { return config.getDouble("HUD.Retro.Colors.Border.GREEN", 0.0); }
|
||||
public double getRetroHUDXPBorderBlue() { return config.getDouble("HUD.Retro.Colors.Border.BLUE", 0.0); }
|
||||
public double getRetroHUDXPBackgroundRed() { return config.getDouble("HUD.Retro.Colors.Background.RED", 0.75); }
|
||||
public double getRetroHUDXPBackgroundGreen() { return config.getDouble("HUD.Retro.Colors.Background.GREEN", 0.75); }
|
||||
public double getRetroHUDXPBackgroundBlue() { return config.getDouble("HUD.Retro.Colors.Background.BLUE", 0.75); }
|
||||
|
||||
public double getRetroHUDAcrobaticsRed() { return config.getDouble("HUD.Retro.Colors.Acrobatics.RED", 0.3); }
|
||||
public double getRetroHUDAcrobaticsGreen() { return config.getDouble("HUD.Retro.Colors.Acrobatics.GREEN", 0.3); }
|
||||
public double getRetroHUDAcrobaticsBlue() { return config.getDouble("HUD.Retro.Colors.Acrobatics.BLUE", 0.75); }
|
||||
public double getRetroHUDArcheryRed() { return config.getDouble("HUD.Retro.Colors.Archery.RED", 0.3); }
|
||||
public double getRetroHUDArcheryGreen() { return config.getDouble("HUD.Retro.Colors.Archery.GREEN", 0.3); }
|
||||
public double getRetroHUDArcheryBlue() { return config.getDouble("HUD.Retro.Colors.Archery.BLUE", 0.75); }
|
||||
public double getRetroHUDAxesRed() { return config.getDouble("HUD.Retro.Colors.Axes.RED", 0.3); }
|
||||
public double getRetroHUDAxesGreen() { return config.getDouble("HUD.Retro.Colors.Axes.GREEN", 0.3); }
|
||||
public double getRetroHUDAxesBlue() { return config.getDouble("HUD.Retro.Colors.Axes.BLUE", 0.75); }
|
||||
public double getRetroHUDExcavationRed() { return config.getDouble("HUD.Retro.Colors.Excavation.RED", 0.3); }
|
||||
public double getRetroHUDExcavationGreen() { return config.getDouble("HUD.Retro.Colors.Excavation.GREEN", 0.3); }
|
||||
public double getRetroHUDExcavationBlue() { return config.getDouble("HUD.Retro.Colors.Excavation.BLUE", 0.75); }
|
||||
public double getRetroHUDHerbalismRed() { return config.getDouble("HUD.Retro.Colors.Herbalism.RED", 0.3); }
|
||||
public double getRetroHUDHerbalismGreen() { return config.getDouble("HUD.Retro.Colors.Herbalism.GREEN", 0.3); }
|
||||
public double getRetroHUDHerbalismBlue() { return config.getDouble("HUD.Retro.Colors.Herbalism.BLUE", 0.75); }
|
||||
public double getRetroHUDMiningRed() { return config.getDouble("HUD.Retro.Colors.Mining.RED", 0.3); }
|
||||
public double getRetroHUDMiningGreen() { return config.getDouble("HUD.Retro.Colors.Mining.GREEN", 0.3); }
|
||||
public double getRetroHUDMiningBlue() { return config.getDouble("HUD.Retro.Colors.Mining.BLUE", 0.75); }
|
||||
public double getRetroHUDRepairRed() { return config.getDouble("HUD.Retro.Colors.Repair.RED", 0.3); }
|
||||
public double getRetroHUDRepairGreen() { return config.getDouble("HUD.Retro.Colors.Repair.GREEN", 0.3); }
|
||||
public double getRetroHUDRepairBlue() { return config.getDouble("HUD.Retro.Colors.Repair.BLUE", 0.75); }
|
||||
public double getRetroHUDSwordsRed() { return config.getDouble("HUD.Retro.Colors.Swords.RED", 0.3); }
|
||||
public double getRetroHUDSwordsGreen() { return config.getDouble("HUD.Retro.Colors.Swords.GREEN", 0.3); }
|
||||
public double getRetroHUDSwordsBlue() { return config.getDouble("HUD.Retro.Colors.Swords.BLUE", 0.75); }
|
||||
public double getRetroHUDTamingRed() { return config.getDouble("HUD.Retro.Colors.Taming.RED", 0.3); }
|
||||
public double getRetroHUDTamingGreen() { return config.getDouble("HUD.Retro.Colors.Taming.GREEN", 0.3); }
|
||||
public double getRetroHUDTamingBlue() { return config.getDouble("HUD.Retro.Colors.Taming.BLUE", 0.75); }
|
||||
public double getRetroHUDUnarmedRed() { return config.getDouble("HUD.Retro.Colors.Unarmed.RED", 0.3); }
|
||||
public double getRetroHUDUnarmedGreen() { return config.getDouble("HUD.Retro.Colors.Unarmed.GREEN", 0.3); }
|
||||
public double getRetroHUDUnarmedBlue() { return config.getDouble("HUD.Retro.Colors.Unarmed.BLUE", 0.75); }
|
||||
public double getRetroHUDWoodcuttingRed() { return config.getDouble("HUD.Retro.Colors.Woodcutting.RED", 0.3); }
|
||||
public double getRetroHUDWoodcuttingGreen() { return config.getDouble("HUD.Retro.Colors.Woodcutting.GREEN", 0.3); }
|
||||
public double getRetroHUDWoodcuttingBlue() { return config.getDouble("HUD.Retro.Colors.Woodcutting.BLUE", 0.75); }
|
||||
public double getRetroHUDFishingRed() { return config.getDouble("HUD.Retro.Colors.Fishing.RED", 0.3); }
|
||||
public double getRetroHUDFishingGreen() { return config.getDouble("HUD.Retro.Colors.Fishing.GREEN", 0.3); }
|
||||
public double getRetroHUDFishingBlue() { return config.getDouble("HUD.Retro.Colors.Fishing.BLUE", 0.75); }
|
||||
}
|
38
src/main/java/com/gmail/nossr50/spout/SpoutStart.java
Normal file
38
src/main/java/com/gmail/nossr50/spout/SpoutStart.java
Normal file
@ -0,0 +1,38 @@
|
||||
package com.gmail.nossr50.spout;
|
||||
|
||||
import org.getspout.spoutapi.SpoutManager;
|
||||
import org.getspout.spoutapi.player.FileManager;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
|
||||
public class SpoutStart implements Runnable{
|
||||
private final mcMMO plugin;
|
||||
|
||||
public SpoutStart(final mcMMO plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (plugin.getServer().getPluginManager().getPlugin("Spout") != null) {
|
||||
mcMMO.spoutEnabled = true;
|
||||
}
|
||||
else {
|
||||
mcMMO.spoutEnabled = false;
|
||||
}
|
||||
|
||||
//Spout Stuff
|
||||
if (mcMMO.spoutEnabled) {
|
||||
SpoutConfig.getInstance();
|
||||
SpoutStuff.setupSpoutConfigs();
|
||||
SpoutStuff.registerCustomEvent();
|
||||
SpoutStuff.extractFiles(); //Extract source materials
|
||||
|
||||
FileManager FM = SpoutManager.getFileManager();
|
||||
FM.addToPreLoginCache(plugin, SpoutStuff.getFiles());
|
||||
|
||||
//Handle spout players after a /reload
|
||||
SpoutStuff.reloadSpoutPlayers();
|
||||
}
|
||||
}
|
||||
}
|
@ -20,13 +20,12 @@ import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.SpoutConfig;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
import com.gmail.nossr50.listeners.SpoutListener;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.skills.SkillType;
|
||||
import com.gmail.nossr50.skills.Skills;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Skills;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
public class SpoutStuff {
|
||||
|
@ -0,0 +1,61 @@
|
||||
package com.gmail.nossr50.spout.commands;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.commands.CommandHelper;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.spout.SpoutConfig;
|
||||
import com.gmail.nossr50.spout.huds.HudType;
|
||||
import com.gmail.nossr50.spout.huds.SpoutHud;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
public class MchudCommand implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
String usage = LocaleLoader.getString("Commands.Usage.1", new Object[] {"mchud", "<DISABLED | STANDARD | SMALL | RETRO>"});
|
||||
String invalid = LocaleLoader.getString("Commands.mchud.Invalid");
|
||||
|
||||
if (CommandHelper.noConsoleUsage(sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!mcMMO.spoutEnabled || !SpoutConfig.getInstance().getXPBarEnabled()) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.Disabled"));
|
||||
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) {
|
||||
case 1:
|
||||
for (HudType hudType : HudType.values()) {
|
||||
if (hudType.toString().equalsIgnoreCase(args[0])) {
|
||||
playerProfile.setHudType(hudType);
|
||||
spoutHud.initializeXpBar();
|
||||
spoutHud.updateXpBar();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
player.sendMessage(invalid);
|
||||
return true;
|
||||
|
||||
default:
|
||||
player.sendMessage(usage);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package com.gmail.nossr50.spout.commands;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.commands.CommandHelper;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.skills.SkillType;
|
||||
import com.gmail.nossr50.skills.Skills;
|
||||
import com.gmail.nossr50.spout.SpoutConfig;
|
||||
import com.gmail.nossr50.spout.huds.SpoutHud;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
public class XplockCommand implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
String usage = LocaleLoader.getString("Commands.Usage.1", new Object[] {"xplock", "[skill]"});
|
||||
|
||||
if (CommandHelper.noConsoleUsage(sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!mcMMO.spoutEnabled || !SpoutConfig.getInstance().getXPBarEnabled() || !Config.getInstance().getCommandXPLockEnabled()) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.Disabled"));
|
||||
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) {
|
||||
case 0:
|
||||
if (spoutHud.getXpBarLocked()) {
|
||||
spoutHud.toggleXpBarLocked();
|
||||
player.sendMessage(LocaleLoader.getString("Commands.xplock.unlocked"));
|
||||
return true;
|
||||
}
|
||||
|
||||
SkillType lastGained = spoutHud.getLastGained();
|
||||
|
||||
if (lastGained != null) {
|
||||
spoutHud.toggleXpBarLocked();
|
||||
spoutHud.setSkillLock(lastGained);
|
||||
player.sendMessage(LocaleLoader.getString("Commands.xplock.locked", new Object[] { Misc.getCapitalized(lastGained.toString()) }));
|
||||
}
|
||||
else {
|
||||
player.sendMessage(usage);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
case 1:
|
||||
if (Skills.isSkill(args[0])) {
|
||||
if (Permissions.hasPermission(player, "mcmmo.skills." + args[0].toLowerCase())) {
|
||||
spoutHud.setXpBarLocked(true);
|
||||
spoutHud.setSkillLock(Skills.getSkillType(args[0]));
|
||||
spoutHud.updateXpBar();
|
||||
|
||||
player.sendMessage(LocaleLoader.getString("Commands.xplock.locked", new Object[] { Misc.getCapitalized(args[0]) }));
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString("mcMMO.NoPermission"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
default:
|
||||
player.sendMessage(usage);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
12
src/main/java/com/gmail/nossr50/spout/huds/HudType.java
Normal file
12
src/main/java/com/gmail/nossr50/spout/huds/HudType.java
Normal file
@ -0,0 +1,12 @@
|
||||
package com.gmail.nossr50.spout.huds;
|
||||
|
||||
public enum HudType {
|
||||
DISABLED,
|
||||
STANDARD,
|
||||
SMALL,
|
||||
RETRO;
|
||||
|
||||
public HudType getNext() {
|
||||
return values()[(ordinal() + 1) % values().length];
|
||||
}
|
||||
}
|
105
src/main/java/com/gmail/nossr50/spout/huds/SpoutHud.java
Normal file
105
src/main/java/com/gmail/nossr50/spout/huds/SpoutHud.java
Normal file
@ -0,0 +1,105 @@
|
||||
package com.gmail.nossr50.spout.huds;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.getspout.spoutapi.SpoutManager;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.popups.Menu;
|
||||
import com.gmail.nossr50.datatypes.popups.XpBar;
|
||||
import com.gmail.nossr50.skills.SkillType;
|
||||
import com.gmail.nossr50.spout.SpoutConfig;
|
||||
|
||||
public class SpoutHud {
|
||||
private Player player;
|
||||
private PlayerProfile profile;
|
||||
|
||||
private SkillType lastGained;
|
||||
private SkillType skillLock;
|
||||
private boolean xpBarLocked;
|
||||
|
||||
private Menu menu;
|
||||
private XpBar xpBar;
|
||||
|
||||
public SpoutHud(McMMOPlayer mcMMOPlayer) {
|
||||
this.player = mcMMOPlayer.getPlayer();
|
||||
this.profile = mcMMOPlayer.getProfile();
|
||||
|
||||
initializeXpBar();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the HUD.
|
||||
*/
|
||||
public void initializeXpBar() {
|
||||
if (SpoutConfig.getInstance().getXPBarEnabled()) {
|
||||
if (xpBar != null) {
|
||||
xpBar.removeWidgets();
|
||||
}
|
||||
|
||||
xpBar = new XpBar(SpoutManager.getPlayer(player), profile.getHudType());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the XP bar.
|
||||
*/
|
||||
public void updateXpBar() {
|
||||
SkillType skillType = xpBarLocked ? skillLock : lastGained;
|
||||
|
||||
if (skillType == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
xpBar.update(skillType, profile);
|
||||
}
|
||||
|
||||
public boolean isMenuOpened() {
|
||||
return (menu != null) ? true : false;
|
||||
}
|
||||
|
||||
public void openMenu() {
|
||||
menu = new Menu(SpoutManager.getPlayer(player), profile);
|
||||
}
|
||||
|
||||
public void onMenuClose() {
|
||||
menu = null;
|
||||
}
|
||||
|
||||
public void removeWidgets() {
|
||||
if (menu != null) {
|
||||
menu.close();
|
||||
}
|
||||
|
||||
SpoutManager.getPlayer(player).getMainScreen().removeWidgets(mcMMO.p);
|
||||
}
|
||||
|
||||
public SkillType getLastGained() {
|
||||
return lastGained;
|
||||
}
|
||||
|
||||
public void setLastGained(SkillType type) {
|
||||
this.lastGained = type;
|
||||
}
|
||||
|
||||
public boolean getXpBarLocked() {
|
||||
return xpBarLocked;
|
||||
}
|
||||
|
||||
public void setXpBarLocked(boolean locked) {
|
||||
this.xpBarLocked = locked;
|
||||
}
|
||||
|
||||
public void toggleXpBarLocked() {
|
||||
xpBarLocked = !xpBarLocked;
|
||||
}
|
||||
|
||||
public SkillType getSkillLock() {
|
||||
return skillLock;
|
||||
}
|
||||
|
||||
public void setSkillLock(SkillType type) {
|
||||
this.skillLock = type;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user