Move all miscellaneous Spout code to a single location.

This commit is contained in:
GJ 2013-05-16 10:51:18 -04:00
parent 936bec8ff5
commit a7861fc54b
5 changed files with 93 additions and 73 deletions

View File

@ -1,17 +1,17 @@
package com.gmail.nossr50.commands; package com.gmail.nossr50.commands;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.getspout.spoutapi.player.SpoutPlayer; import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.party.PartySubcommandType; import com.gmail.nossr50.commands.party.PartySubcommandType;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.spout.SpoutUtils;
public class McmmoCommand implements CommandExecutor { public class McmmoCommand implements CommandExecutor {
@Override @Override
@ -28,14 +28,14 @@ public class McmmoCommand implements CommandExecutor {
sender.sendMessage(mcSplit); sender.sendMessage(mcSplit);
if (Config.getInstance().getDonateMessageEnabled()) { if (Config.getInstance().getDonateMessageEnabled()) {
if (mcMMO.isSpoutEnabled() && sender instanceof SpoutPlayer) { if (mcMMO.isSpoutEnabled() && sender instanceof Player) {
SpoutPlayer spoutPlayer = (SpoutPlayer) sender; SpoutUtils.sendDonationNotification((Player) sender);
spoutPlayer.sendNotification(LocaleLoader.getString("Spout.Donate"), ChatColor.GREEN + "gjmcferrin@gmail.com", Material.DIAMOND);
} }
else {
sender.sendMessage(LocaleLoader.getString("MOTD.Donate")); sender.sendMessage(LocaleLoader.getString("MOTD.Donate"));
sender.sendMessage(ChatColor.GOLD + " - " + ChatColor.GREEN + "gjmcferrin@gmail.com" + ChatColor.GOLD + " Paypal"); sender.sendMessage(ChatColor.GOLD + " - " + ChatColor.GREEN + "gjmcferrin@gmail.com" + ChatColor.GOLD + " Paypal");
} }
}
sender.sendMessage(LocaleLoader.getString("MOTD.Version", mcMMO.p.getDescription().getVersion())); sender.sendMessage(LocaleLoader.getString("MOTD.Version", mcMMO.p.getDescription().getVersion()));
return true; return true;

View File

@ -40,6 +40,30 @@ public class Repair {
return false; return false;
} }
public static String getAnvilMessage(int blockId) {
if (blockId == repairAnvilId) {
return LocaleLoader.getString("Repair.Listener.Anvil");
}
if (blockId == salvageAnvilId) {
return LocaleLoader.getString("Repair.Listener.Anvil2");
}
return "";
}
public static String[] getSpoutAnvilMessages(int blockId) {
if (blockId == repairAnvilId) {
return new String[] {LocaleLoader.getString("Repair.AnvilPlaced.Spout1"), LocaleLoader.getString("Repair.AnvilPlaced.Spout2")};
}
if (blockId == salvageAnvilId) {
return new String[] {"[mcMMO] Anvil Placed", "Right click to salvage!"};
}
return new String[] {"", ""};
}
/** /**
* Search the inventory for an item and return the index. * Search the inventory for an item and return the index.
* *
@ -99,30 +123,6 @@ public class Repair {
inventory.removeItem(item); inventory.removeItem(item);
} }
protected static String[] getSpoutAnvilMessages(int blockId) {
if (blockId == repairAnvilId) {
return new String[] {LocaleLoader.getString("Repair.AnvilPlaced.Spout1"), LocaleLoader.getString("Repair.AnvilPlaced.Spout2")};
}
if (blockId == salvageAnvilId) {
return new String[] {"[mcMMO] Anvil Placed", "Right click to salvage!"};
}
return new String[] {"", ""};
}
protected static String getAnvilMessage(int blockId) {
if (blockId == repairAnvilId) {
return LocaleLoader.getString("Repair.Listener.Anvil");
}
if (blockId == salvageAnvilId) {
return LocaleLoader.getString("Repair.Listener.Anvil2");
}
return "";
}
protected static Material getSalvagedItem(ItemStack inHand) { protected static Material getSalvagedItem(ItemStack inHand) {
if (ItemUtils.isDiamondTool(inHand) || ItemUtils.isDiamondArmor(inHand)) { if (ItemUtils.isDiamondTool(inHand) || ItemUtils.isDiamondArmor(inHand)) {
return Material.DIAMOND; return Material.DIAMOND;

View File

@ -10,8 +10,6 @@ import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.PlayerInventory;
import org.getspout.spoutapi.SpoutManager;
import org.getspout.spoutapi.player.SpoutPlayer;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
@ -26,6 +24,7 @@ import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
import com.gmail.nossr50.util.spout.SpoutUtils;
public class RepairManager extends SkillManager { public class RepairManager extends SkillManager {
public RepairManager(McMMOPlayer mcMMOPlayer) { public RepairManager(McMMOPlayer mcMMOPlayer) {
@ -45,15 +44,7 @@ public class RepairManager extends SkillManager {
} }
if (mcMMO.isSpoutEnabled()) { if (mcMMO.isSpoutEnabled()) {
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player); SpoutUtils.sendRepairNotifications(player, anvilId);
if (spoutPlayer.isSpoutCraftEnabled()) {
String[] spoutMessages = Repair.getSpoutAnvilMessages(anvilId);
spoutPlayer.sendNotification(spoutMessages[0], spoutMessages[1], Material.getMaterial(anvilId));
}
else {
player.sendMessage(Repair.getAnvilMessage(anvilId));
}
} }
else { else {
player.sendMessage(Repair.getAnvilMessage(anvilId)); player.sendMessage(Repair.getAnvilMessage(anvilId));

View File

@ -13,14 +13,11 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.getspout.spoutapi.SpoutManager;
import org.getspout.spoutapi.player.SpoutPlayer;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.HiddenConfig; import com.gmail.nossr50.config.HiddenConfig;
import com.gmail.nossr50.config.spout.SpoutConfig;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.AbilityType;
@ -43,7 +40,6 @@ import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.spout.SpoutUtils; import com.gmail.nossr50.util.spout.SpoutUtils;
public class SkillUtils { public class SkillUtils {
public static int handleFoodSkills(Player player, SkillType skill, int eventFoodLevel, int baseLevel, int maxLevel, int rankChange) { public static int handleFoodSkills(Player player, SkillType skill, int eventFoodLevel, int baseLevel, int maxLevel, int rankChange) {
int skillLevel = UserManager.getPlayer(player).getProfile().getSkillLevel(skill); int skillLevel = UserManager.getPlayer(player).getProfile().getSkillLevel(skill);
@ -151,7 +147,7 @@ public class SkillUtils {
* @param profile The profile of the player whose skill to check * @param profile The profile of the player whose skill to check
*/ */
public static void xpCheckSkill(SkillType skillType, Player player, PlayerProfile profile) { public static void xpCheckSkill(SkillType skillType, Player player, PlayerProfile profile) {
int skillups = 0; int levelsGained = 0;
float xpRemoved = 0; float xpRemoved = 0;
if (profile.getSkillXpLevelRaw(skillType) >= profile.getXpToLevel(skillType)) { if (profile.getSkillXpLevelRaw(skillType) >= profile.getXpToLevel(skillType)) {
@ -163,7 +159,7 @@ public class SkillUtils {
xpRemoved += xp; xpRemoved += xp;
profile.removeXp(skillType, xp); profile.removeXp(skillType, xp);
skillups++; levelsGained++;
profile.skillUp(skillType, 1); profile.skillUp(skillType, 1);
} }
else { else {
@ -171,46 +167,27 @@ public class SkillUtils {
} }
} }
McMMOPlayerLevelUpEvent eventToFire = new McMMOPlayerLevelUpEvent(player, skillType, skillups); McMMOPlayerLevelUpEvent eventToFire = new McMMOPlayerLevelUpEvent(player, skillType, levelsGained);
mcMMO.p.getServer().getPluginManager().callEvent(eventToFire); mcMMO.p.getServer().getPluginManager().callEvent(eventToFire);
if (eventToFire.isCancelled()) { if (eventToFire.isCancelled()) {
profile.modifySkill(skillType, profile.getSkillLevel(skillType) - skillups); profile.modifySkill(skillType, profile.getSkillLevel(skillType) - levelsGained);
profile.setSkillXpLevel(skillType, profile.getSkillXpLevelRaw(skillType) + xpRemoved); profile.setSkillXpLevel(skillType, profile.getSkillXpLevelRaw(skillType) + xpRemoved);
return; return;
} }
String capitalized = StringUtils.getCapitalized(skillType.toString()); String capitalized = StringUtils.getCapitalized(skillType.toString());
/* Spout Stuff */
if (mcMMO.isSpoutEnabled()) { if (mcMMO.isSpoutEnabled()) {
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player); SpoutUtils.processLevelup(mcMMOPlayer, skillType, levelsGained);
if (spoutPlayer != null && spoutPlayer.isSpoutCraftEnabled()) {
SpoutUtils.levelUpNotification(skillType, spoutPlayer);
/* Update custom titles */
if (SpoutConfig.getInstance().getShowPowerLevel()) {
spoutPlayer.setTitle(LocaleLoader.getString("Spout.Title", spoutPlayer.getName(), UserManager.getPlayer(player).getPowerLevel()));
}
} }
else { else {
player.sendMessage(LocaleLoader.getString(capitalized + ".Skillup", skillups, profile.getSkillLevel(skillType))); player.sendMessage(LocaleLoader.getString(capitalized + ".Skillup", levelsGained, profile.getSkillLevel(skillType)));
}
}
else {
player.sendMessage(LocaleLoader.getString(capitalized + ".Skillup", skillups, profile.getSkillLevel(skillType)));
} }
} }
if (mcMMO.isSpoutEnabled()) { if (mcMMO.isSpoutEnabled()) {
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player); SpoutUtils.processXpGain(player, profile);
if (spoutPlayer != null && spoutPlayer.isSpoutCraftEnabled()) {
if (SpoutConfig.getInstance().getXPBarEnabled()) {
profile.getSpoutHud().updateXpBar();
}
}
} }
} }

View File

@ -9,6 +9,7 @@ import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
@ -18,9 +19,11 @@ import org.getspout.spoutapi.player.SpoutPlayer;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.spout.SpoutConfig; import com.gmail.nossr50.config.spout.SpoutConfig;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.repair.Repair;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
@ -423,4 +426,53 @@ public class SpoutUtils {
public static void preCacheFiles() { public static void preCacheFiles() {
SpoutManager.getFileManager().addToPreLoginCache(mcMMO.p, extractFiles()); SpoutManager.getFileManager().addToPreLoginCache(mcMMO.p, extractFiles());
} }
public static void processLevelup(McMMOPlayer mcMMOPlayer, SkillType skillType, int levelsGained) {
Player player = mcMMOPlayer.getPlayer();
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
if (spoutPlayer.isSpoutCraftEnabled()) {
levelUpNotification(skillType, spoutPlayer);
/* Update custom titles */
if (SpoutConfig.getInstance().getShowPowerLevel()) {
spoutPlayer.setTitle(LocaleLoader.getString("Spout.Title", spoutPlayer.getName(), mcMMOPlayer.getPowerLevel()));
}
}
else {
player.sendMessage(LocaleLoader.getString(StringUtils.getCapitalized(skillType.toString()) + ".Skillup", levelsGained, mcMMOPlayer.getProfile().getSkillLevel(skillType)));
}
}
public static void processXpGain(Player player, PlayerProfile profile) {
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
if (spoutPlayer.isSpoutCraftEnabled() && SpoutConfig.getInstance().getXPBarEnabled()) {
profile.getSpoutHud().updateXpBar();
}
}
public static void sendRepairNotifications(Player player, int anvilId) {
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
if (spoutPlayer.isSpoutCraftEnabled()) {
String[] spoutMessages = Repair.getSpoutAnvilMessages(anvilId);
spoutPlayer.sendNotification(spoutMessages[0], spoutMessages[1], Material.getMaterial(anvilId));
}
else {
player.sendMessage(Repair.getAnvilMessage(anvilId));
}
}
public static void sendDonationNotification(Player player) {
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
if (spoutPlayer.isSpoutCraftEnabled()) {
spoutPlayer.sendNotification(LocaleLoader.getString("Spout.Donate"), ChatColor.GREEN + "gjmcferrin@gmail.com", Material.DIAMOND);
}
else {
player.sendMessage(LocaleLoader.getString("MOTD.Donate"));
player.sendMessage(ChatColor.GOLD + " - " + ChatColor.GREEN + "gjmcferrin@gmail.com" + ChatColor.GOLD + " Paypal");
}
}
} }