mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 07:06:45 +01:00
Move all miscellaneous Spout code to a single location.
This commit is contained in:
parent
936bec8ff5
commit
a7861fc54b
@ -1,17 +1,17 @@
|
||||
package com.gmail.nossr50.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
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.commands.party.PartySubcommandType;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.spout.SpoutUtils;
|
||||
|
||||
public class McmmoCommand implements CommandExecutor {
|
||||
@Override
|
||||
@ -28,13 +28,13 @@ public class McmmoCommand implements CommandExecutor {
|
||||
sender.sendMessage(mcSplit);
|
||||
|
||||
if (Config.getInstance().getDonateMessageEnabled()) {
|
||||
if (mcMMO.isSpoutEnabled() && sender instanceof SpoutPlayer) {
|
||||
SpoutPlayer spoutPlayer = (SpoutPlayer) sender;
|
||||
spoutPlayer.sendNotification(LocaleLoader.getString("Spout.Donate"), ChatColor.GREEN + "gjmcferrin@gmail.com", Material.DIAMOND);
|
||||
if (mcMMO.isSpoutEnabled() && sender instanceof Player) {
|
||||
SpoutUtils.sendDonationNotification((Player) sender);
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(LocaleLoader.getString("MOTD.Donate"));
|
||||
sender.sendMessage(ChatColor.GOLD + " - " + ChatColor.GREEN + "gjmcferrin@gmail.com" + ChatColor.GOLD + " Paypal");
|
||||
}
|
||||
|
||||
sender.sendMessage(LocaleLoader.getString("MOTD.Donate"));
|
||||
sender.sendMessage(ChatColor.GOLD + " - " + ChatColor.GREEN + "gjmcferrin@gmail.com" + ChatColor.GOLD + " Paypal");
|
||||
}
|
||||
|
||||
sender.sendMessage(LocaleLoader.getString("MOTD.Version", mcMMO.p.getDescription().getVersion()));
|
||||
|
@ -40,6 +40,30 @@ public class Repair {
|
||||
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.
|
||||
*
|
||||
@ -99,30 +123,6 @@ public class Repair {
|
||||
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) {
|
||||
if (ItemUtils.isDiamondTool(inHand) || ItemUtils.isDiamondArmor(inHand)) {
|
||||
return Material.DIAMOND;
|
||||
|
@ -10,8 +10,6 @@ import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
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.config.Config;
|
||||
@ -26,6 +24,7 @@ import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.StringUtils;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||
import com.gmail.nossr50.util.spout.SpoutUtils;
|
||||
|
||||
public class RepairManager extends SkillManager {
|
||||
public RepairManager(McMMOPlayer mcMMOPlayer) {
|
||||
@ -45,15 +44,7 @@ public class RepairManager extends SkillManager {
|
||||
}
|
||||
|
||||
if (mcMMO.isSpoutEnabled()) {
|
||||
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));
|
||||
}
|
||||
SpoutUtils.sendRepairNotifications(player, anvilId);
|
||||
}
|
||||
else {
|
||||
player.sendMessage(Repair.getAnvilMessage(anvilId));
|
||||
|
@ -13,14 +13,11 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
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.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
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.PlayerProfile;
|
||||
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;
|
||||
|
||||
public class SkillUtils {
|
||||
|
||||
public static int handleFoodSkills(Player player, SkillType skill, int eventFoodLevel, int baseLevel, int maxLevel, int rankChange) {
|
||||
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
|
||||
*/
|
||||
public static void xpCheckSkill(SkillType skillType, Player player, PlayerProfile profile) {
|
||||
int skillups = 0;
|
||||
int levelsGained = 0;
|
||||
float xpRemoved = 0;
|
||||
|
||||
if (profile.getSkillXpLevelRaw(skillType) >= profile.getXpToLevel(skillType)) {
|
||||
@ -163,7 +159,7 @@ public class SkillUtils {
|
||||
xpRemoved += xp;
|
||||
|
||||
profile.removeXp(skillType, xp);
|
||||
skillups++;
|
||||
levelsGained++;
|
||||
profile.skillUp(skillType, 1);
|
||||
}
|
||||
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);
|
||||
|
||||
if (eventToFire.isCancelled()) {
|
||||
profile.modifySkill(skillType, profile.getSkillLevel(skillType) - skillups);
|
||||
profile.modifySkill(skillType, profile.getSkillLevel(skillType) - levelsGained);
|
||||
profile.setSkillXpLevel(skillType, profile.getSkillXpLevelRaw(skillType) + xpRemoved);
|
||||
return;
|
||||
}
|
||||
|
||||
String capitalized = StringUtils.getCapitalized(skillType.toString());
|
||||
|
||||
/* Spout Stuff */
|
||||
if (mcMMO.isSpoutEnabled()) {
|
||||
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
|
||||
|
||||
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 {
|
||||
player.sendMessage(LocaleLoader.getString(capitalized + ".Skillup", skillups, profile.getSkillLevel(skillType)));
|
||||
}
|
||||
SpoutUtils.processLevelup(mcMMOPlayer, skillType, levelsGained);
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString(capitalized + ".Skillup", skillups, profile.getSkillLevel(skillType)));
|
||||
player.sendMessage(LocaleLoader.getString(capitalized + ".Skillup", levelsGained, profile.getSkillLevel(skillType)));
|
||||
}
|
||||
}
|
||||
|
||||
if (mcMMO.isSpoutEnabled()) {
|
||||
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
|
||||
|
||||
if (spoutPlayer != null && spoutPlayer.isSpoutCraftEnabled()) {
|
||||
if (SpoutConfig.getInstance().getXPBarEnabled()) {
|
||||
profile.getSpoutHud().updateXpBar();
|
||||
}
|
||||
}
|
||||
SpoutUtils.processXpGain(player, profile);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
@ -18,9 +19,11 @@ import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
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.skills.SkillType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.skills.repair.Repair;
|
||||
import com.gmail.nossr50.util.StringUtils;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||
@ -423,4 +426,53 @@ public class SpoutUtils {
|
||||
public static void preCacheFiles() {
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user