Making our file path strings more user friendly.

This commit is contained in:
GJ 2012-04-21 14:05:39 -04:00
parent f94a617d94
commit c45cd56c78
19 changed files with 122 additions and 133 deletions

View File

@ -1,6 +1,5 @@
package com.gmail.nossr50; package com.gmail.nossr50;
import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Animals; import org.bukkit.entity.Animals;
@ -248,7 +247,7 @@ public class Combat {
private static void dealDamage(LivingEntity target, int dmg, DamageCause cause) { private static void dealDamage(LivingEntity target, int dmg, DamageCause cause) {
if (LoadProperties.eventCallback) { if (LoadProperties.eventCallback) {
EntityDamageEvent ede = (EntityDamageEvent) new FakeEntityDamageEvent(target, cause, dmg); EntityDamageEvent ede = (EntityDamageEvent) new FakeEntityDamageEvent(target, cause, dmg);
Bukkit.getPluginManager().callEvent(ede); mcMMO.p.getServer().getPluginManager().callEvent(ede);
if (ede.isCancelled()) { if (ede.isCancelled()) {
return; return;
@ -271,7 +270,7 @@ public class Combat {
private static void dealDamage(LivingEntity target, int dmg, Player attacker) { private static void dealDamage(LivingEntity target, int dmg, Player attacker) {
if (LoadProperties.eventCallback) { if (LoadProperties.eventCallback) {
EntityDamageEvent ede = (EntityDamageByEntityEvent) new FakeEntityDamageByEntityEvent(attacker, target, EntityDamageEvent.DamageCause.ENTITY_ATTACK, dmg); EntityDamageEvent ede = (EntityDamageByEntityEvent) new FakeEntityDamageByEntityEvent(attacker, target, EntityDamageEvent.DamageCause.ENTITY_ATTACK, dmg);
Bukkit.getPluginManager().callEvent(ede); mcMMO.p.getServer().getPluginManager().callEvent(ede);
if (ede.isCancelled()) { if (ede.isCancelled()) {
return; return;
@ -474,7 +473,7 @@ public class Combat {
} }
if (baseXP != 0) { if (baseXP != 0) {
Bukkit.getScheduler().scheduleSyncDelayedTask(pluginx, new GainXp(attacker, PP, skillType, baseXP, target), 0); mcMMO.p.getServer().getScheduler().scheduleSyncDelayedTask(pluginx, new GainXp(attacker, PP, skillType, baseXP, target), 0);
} }
} }
} }

View File

@ -7,15 +7,15 @@ import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import org.bukkit.Bukkit;
import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.datatypes.PlayerStat; import com.gmail.nossr50.datatypes.PlayerStat;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.datatypes.Tree; import com.gmail.nossr50.datatypes.Tree;
public class Leaderboard { public class Leaderboard {
static String location = "plugins/mcMMO/FlatFileStuff/mcmmo.users"; private static String leaderboardsDirectory = mcMMO.leaderboardDirectory;
private static String location = mcMMO.usersFile;
private static mcMMO plugin = mcMMO.p;
/** /**
* Create the leaderboards. * Create the leaderboards.
@ -121,7 +121,7 @@ public class Leaderboard {
in.close(); in.close();
} }
catch (Exception e) { catch (Exception e) {
Bukkit.getLogger().severe(("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString())); plugin.getLogger().severe(("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString()));
} }
//Write the leader board files //Write the leader board files
@ -147,7 +147,7 @@ public class Leaderboard {
* @param skillType Skill type to write the leaderboard of * @param skillType Skill type to write the leaderboard of
*/ */
private static void leaderWrite(PlayerStat[] ps, SkillType skillType) { private static void leaderWrite(PlayerStat[] ps, SkillType skillType) {
String theLocation = "plugins/mcMMO/FlatFileStuff/Leaderboards/" + skillType + ".mcmmo"; String theLocation = leaderboardsDirectory + skillType.toString().toLowerCase() + ".mcmmo";
File theDir = new File(theLocation); File theDir = new File(theLocation);
//CHECK IF THE FILE EXISTS //CHECK IF THE FILE EXISTS
@ -158,7 +158,7 @@ public class Leaderboard {
writer = new FileWriter(theLocation); writer = new FileWriter(theLocation);
} }
catch (Exception e) { catch (Exception e) {
Bukkit.getLogger().severe(("Exception while creating " + theLocation + e.toString())); plugin.getLogger().severe(("Exception while creating " + theLocation + e.toString()));
} }
finally { finally {
try { try {
@ -167,7 +167,7 @@ public class Leaderboard {
} }
} }
catch (IOException e) { catch (IOException e) {
Bukkit.getLogger().severe("Exception while closing writer for " + theLocation + e.toString()); plugin.getLogger().severe("Exception while closing writer for " + theLocation + e.toString());
} }
} }
} }
@ -196,7 +196,7 @@ public class Leaderboard {
out.close(); out.close();
} }
catch (Exception e) { catch (Exception e) {
Bukkit.getLogger().severe("Exception while writing to " + theLocation + " (Are you sure you formatted it correctly?)" + e.toString()); plugin.getLogger().severe("Exception while writing to " + theLocation + " (Are you sure you formatted it correctly?)" + e.toString());
} }
} }
} }
@ -209,7 +209,7 @@ public class Leaderboard {
* @return the requested leaderboard information * @return the requested leaderboard information
*/ */
public static String[] retrieveInfo(String skillName, int pagenumber) { public static String[] retrieveInfo(String skillName, int pagenumber) {
String theLocation = "plugins/mcMMO/FlatFileStuff/Leaderboards/" + skillName + ".mcmmo"; //$NON-NLS-1$ //$NON-NLS-2$ String theLocation = leaderboardsDirectory + skillName + ".mcmmo";
try { try {
FileReader file = new FileReader(theLocation); FileReader file = new FileReader(theLocation);
@ -242,7 +242,7 @@ public class Leaderboard {
return info; return info;
} }
catch (Exception e) { catch (Exception e) {
Bukkit.getLogger().severe("Exception while reading " + theLocation + " (Are you sure you formatted it correctly?)" + e.toString()); plugin.getLogger().severe("Exception while reading " + theLocation + " (Are you sure you formatted it correctly?)" + e.toString());
} }
return null; //Shouldn't get here return null; //Shouldn't get here
@ -259,7 +259,7 @@ public class Leaderboard {
return; return;
} }
String theLocation = "plugins/mcMMO/FlatFileStuff/Leaderboards/" + skillType + ".mcmmo"; String theLocation = leaderboardsDirectory + skillType.toString().toLowerCase() + ".mcmmo";
try { try {
FileReader file = new FileReader(theLocation); FileReader file = new FileReader(theLocation);
@ -294,7 +294,7 @@ public class Leaderboard {
out.close(); out.close();
} }
catch (Exception e) { catch (Exception e) {
Bukkit.getLogger().severe("Exception while writing to " + theLocation + " (Are you sure you formatted it correctly?)" + e.toString()); plugin.getLogger().severe("Exception while writing to " + theLocation + " (Are you sure you formatted it correctly?)" + e.toString());
} }
} }
} }

View File

@ -1,6 +1,5 @@
package com.gmail.nossr50; package com.gmail.nossr50;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
@ -44,7 +43,7 @@ public class Metrics {
/** /**
* The file where guid and opt out is stored in * The file where guid and opt out is stored in
*/ */
private static final String CONFIG_FILE = "plugins/PluginMetrics/config.yml"; private static final String CONFIG_FILE = "plugins" + File.separator + "PluginMetrics" + File.separator + "config.yml";
/** /**
* The separator to use for custom data. This MUST NOT change unless you are hosting your own * The separator to use for custom data. This MUST NOT change unless you are hosting your own
@ -200,7 +199,7 @@ public class Metrics {
String data = encode("guid") + '=' + encode(guid) String data = encode("guid") + '=' + encode(guid)
+ encodeDataPair("authors", authors) + encodeDataPair("authors", authors)
+ encodeDataPair("version", description.getVersion()) + encodeDataPair("version", description.getVersion())
+ encodeDataPair("server", Bukkit.getVersion()) + encodeDataPair("server", plugin.getServer().getVersion())
+ encodeDataPair("players", Integer.toString(plugin.getServer().getOnlinePlayers().length)) + encodeDataPair("players", Integer.toString(plugin.getServer().getOnlinePlayers().length))
+ encodeDataPair("revision", String.valueOf(REVISION)); + encodeDataPair("revision", String.valueOf(REVISION));

View File

@ -5,24 +5,22 @@ import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
public class Users { public class Users {
private static volatile Users instance;
String location = "plugins/mcMMO/FlatFileStuff/mcmmo.users"; public static String location = mcMMO.usersFile;
String directory = "plugins/mcMMO/FlatFileStuff/"; public static String directory = mcMMO.flatFileDirectory;
String directoryb = "plugins/mcMMO/FlatFileStuff/Leaderboards/"; public static String directoryb = mcMMO.leaderboardDirectory;
public static HashMap<String, PlayerProfile> players = new HashMap<String, PlayerProfile>(); public static HashMap<String, PlayerProfile> players = new HashMap<String, PlayerProfile>();
/** /**
* Load users. * Load users.
*/ */
public void loadUsers() { public static void loadUsers() {
new File(directory).mkdir(); new File(directory).mkdir();
new File(directoryb).mkdir(); new File(directoryb).mkdir();
File theDir = new File(location); File theDir = new File(location);
@ -105,7 +103,7 @@ public class Users {
* @return the player's profile * @return the player's profile
*/ */
public static PlayerProfile getProfileByName(String playerName) { public static PlayerProfile getProfileByName(String playerName) {
if (Bukkit.getServer().getOfflinePlayer(playerName).isOnline() || players.containsKey(playerName.toLowerCase())) { if (mcMMO.p.getServer().getOfflinePlayer(playerName).isOnline() || players.containsKey(playerName.toLowerCase())) {
if (players.get(playerName.toLowerCase()) != null) { if (players.get(playerName.toLowerCase()) != null) {
return players.get(playerName.toLowerCase()); return players.get(playerName.toLowerCase());
} }
@ -118,16 +116,4 @@ public class Users {
return new PlayerProfile(playerName, false); return new PlayerProfile(playerName, false);
} }
} }
/**
* Get an instance of this class.
*
* @return an instance of this class
*/
public static Users getInstance() {
if (instance == null) {
instance = new Users();
}
return instance;
}
} }

View File

@ -1,10 +1,10 @@
package com.gmail.nossr50.api; package com.gmail.nossr50.api;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.events.chat.McMMOAdminChatEvent; import com.gmail.nossr50.events.chat.McMMOAdminChatEvent;
import com.gmail.nossr50.events.chat.McMMOPartyChatEvent; import com.gmail.nossr50.events.chat.McMMOPartyChatEvent;
@ -21,7 +21,7 @@ public class ChatAPI {
*/ */
public void sendPartyChat(String sender, String party, String message) { public void sendPartyChat(String sender, String party, String message) {
McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent(sender, party, message); McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent(sender, party, message);
Bukkit.getPluginManager().callEvent(chatEvent); mcMMO.p.getServer().getPluginManager().callEvent(chatEvent);
if (chatEvent.isCancelled()) { if (chatEvent.isCancelled()) {
return; return;
@ -29,9 +29,9 @@ public class ChatAPI {
String pPrefix = ChatColor.GREEN + "(" + ChatColor.WHITE + chatEvent.getSender() + ChatColor.GREEN + ") "; String pPrefix = ChatColor.GREEN + "(" + ChatColor.WHITE + chatEvent.getSender() + ChatColor.GREEN + ") ";
Bukkit.getLogger().info("[P](" + chatEvent.getParty() + ")" + "<" + chatEvent.getSender() + "> " + chatEvent.getMessage()); mcMMO.p.getLogger().info("[P](" + chatEvent.getParty() + ")" + "<" + chatEvent.getSender() + "> " + chatEvent.getMessage());
for (Player player : Bukkit.getServer().getOnlinePlayers()) { for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
if (Users.getProfile(player).inParty()) { if (Users.getProfile(player).inParty()) {
if (Users.getProfile(player).getParty().equalsIgnoreCase(chatEvent.getParty())) { if (Users.getProfile(player).getParty().equalsIgnoreCase(chatEvent.getParty())) {
player.sendMessage(pPrefix + chatEvent.getMessage()); player.sendMessage(pPrefix + chatEvent.getMessage());
@ -50,7 +50,7 @@ public class ChatAPI {
*/ */
public void sendAdminChat(String sender, String message) { public void sendAdminChat(String sender, String message) {
McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent(sender, message); McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent(sender, message);
Bukkit.getPluginManager().callEvent(chatEvent); mcMMO.p.getServer().getPluginManager().callEvent(chatEvent);
if (chatEvent.isCancelled()) { if (chatEvent.isCancelled()) {
return; return;
@ -58,9 +58,9 @@ public class ChatAPI {
String aPrefix = ChatColor.AQUA + "{" + ChatColor.WHITE + chatEvent.getSender() + ChatColor.AQUA + "} "; String aPrefix = ChatColor.AQUA + "{" + ChatColor.WHITE + chatEvent.getSender() + ChatColor.AQUA + "} ";
Bukkit.getLogger().info("[A]<" + chatEvent.getSender() + "> " + chatEvent.getMessage()); mcMMO.p.getLogger().info("[A]<" + chatEvent.getSender() + "> " + chatEvent.getMessage());
for (Player player : Bukkit.getServer().getOnlinePlayers()) { for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
if (mcPermissions.getInstance().adminChat(player) || player.isOp()) if (mcPermissions.getInstance().adminChat(player) || player.isOp())
player.sendMessage(aPrefix + chatEvent.getMessage()); player.sendMessage(aPrefix + chatEvent.getMessage());
} }

View File

@ -4,10 +4,10 @@ import java.io.BufferedReader;
import java.io.FileReader; import java.io.FileReader;
import java.util.ArrayList; import java.util.ArrayList;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.Party;
public class PartyAPI { public class PartyAPI {
@ -57,7 +57,7 @@ public class PartyAPI {
* @return the list of parties. * @return the list of parties.
*/ */
public ArrayList<String> getParties() { public ArrayList<String> getParties() {
String location = "plugins/mcMMO/mcmmo.users"; String location = mcMMO.usersFile;
ArrayList<String> parties = new ArrayList<String>(); ArrayList<String> parties = new ArrayList<String>();
try { try {
@ -83,7 +83,7 @@ public class PartyAPI {
in.close(); in.close();
} }
catch (Exception e) { catch (Exception e) {
Bukkit.getLogger().severe("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString()); mcMMO.p.getLogger().severe("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString());
} }
return parties; return parties;
} }

View File

@ -17,7 +17,7 @@ import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;
public class McremoveCommand implements CommandExecutor { public class McremoveCommand implements CommandExecutor {
private final String LOCATION = "plugins/mcMMO/FlatFileStuff/mcmmo.users"; private final String location = mcMMO.usersFile;
private final mcMMO plugin; private final mcMMO plugin;
public McremoveCommand (mcMMO plugin) { public McremoveCommand (mcMMO plugin) {
@ -107,7 +107,7 @@ public class McremoveCommand implements CommandExecutor {
boolean worked = false; boolean worked = false;
try { try {
FileReader file = new FileReader(LOCATION); FileReader file = new FileReader(location);
BufferedReader in = new BufferedReader(file); BufferedReader in = new BufferedReader(file);
StringBuilder writer = new StringBuilder(); StringBuilder writer = new StringBuilder();
String line = ""; String line = "";
@ -126,14 +126,14 @@ public class McremoveCommand implements CommandExecutor {
} }
in.close(); in.close();
FileWriter out = new FileWriter(LOCATION); //Write out the new file FileWriter out = new FileWriter(location); //Write out the new file
out.write(writer.toString()); out.write(writer.toString());
out.close(); out.close();
return worked; return worked;
} }
catch (Exception e) { catch (Exception e) {
plugin.getLogger().severe("Exception while reading " + LOCATION + " (Are you sure you formatted it correctly?)" + e.toString()); plugin.getLogger().severe("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString());
return worked; return worked;
} }
} }

View File

@ -7,7 +7,6 @@ import java.io.FileWriter;
import java.util.HashMap; import java.util.HashMap;
import java.util.ArrayList; import java.util.ArrayList;
import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -61,7 +60,7 @@ public class PlayerProfile {
HashMap<ToolType, Integer> toolATS = new HashMap<ToolType, Integer>(); HashMap<ToolType, Integer> toolATS = new HashMap<ToolType, Integer>();
private String playerName; private String playerName;
private String location = "plugins/mcMMO/FlatFileStuff/mcmmo.users"; private String location = mcMMO.usersFile;
public PlayerProfile(String name, boolean addNew) { public PlayerProfile(String name, boolean addNew) {
hud = LoadProperties.defaulthud; hud = LoadProperties.defaulthud;
@ -282,7 +281,7 @@ public class PlayerProfile {
} }
in.close(); in.close();
} catch (Exception e) { } catch (Exception e) {
Bukkit.getLogger().severe("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString()); mcMMO.p.getLogger().severe("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString());
} }
return false; return false;
} }
@ -404,7 +403,7 @@ public class PlayerProfile {
out.write(writer.toString()); out.write(writer.toString());
out.close(); out.close();
} catch (Exception e) { } catch (Exception e) {
Bukkit.getLogger().severe("Exception while writing to " + location + " (Are you sure you formatted it correctly?)" + e.toString()); mcMMO.p.getLogger().severe("Exception while writing to " + location + " (Are you sure you formatted it correctly?)" + e.toString());
} }
} }
} }
@ -479,7 +478,7 @@ public class PlayerProfile {
out.newLine(); out.newLine();
out.close(); out.close();
} catch (Exception e) { } catch (Exception e) {
Bukkit.getLogger().severe("Exception while writing to " + location + " (Are you sure you formatted it correctly?)" + e.toString()); mcMMO.p.getLogger().severe("Exception while writing to " + location + " (Are you sure you formatted it correctly?)" + e.toString());
} }
} }
@ -993,7 +992,7 @@ public class PlayerProfile {
* @param newValue The amount of XP to add * @param newValue The amount of XP to add
*/ */
public void addXPOverride(SkillType skillType, int newValue) { public void addXPOverride(SkillType skillType, int newValue) {
Player player = Bukkit.getPlayer(playerName); Player player = mcMMO.p.getServer().getPlayer(playerName);
if (skillType.equals(SkillType.ALL)) { if (skillType.equals(SkillType.ALL)) {
for (SkillType x : SkillType.values()) { for (SkillType x : SkillType.values()) {
@ -1147,7 +1146,7 @@ public class PlayerProfile {
* @return the power level of the player * @return the power level of the player
*/ */
public int getPowerLevel() { public int getPowerLevel() {
Player player = Bukkit.getPlayer(playerName); Player player = mcMMO.p.getServer().getPlayer(playerName);
int powerLevel = 0; int powerLevel = 0;
for (SkillType type : SkillType.values()) { for (SkillType type : SkillType.values()) {
@ -1166,7 +1165,7 @@ public class PlayerProfile {
* @return the party bonus multiplier * @return the party bonus multiplier
*/ */
private double partyModifier(SkillType skillType) { private double partyModifier(SkillType skillType) {
Player player = Bukkit.getPlayer(playerName); Player player = mcMMO.p.getServer().getPlayer(playerName);
double bonusModifier = 0.0; double bonusModifier = 0.0;
for (Player x : Party.getInstance().getPartyMembers(player)) { for (Player x : Party.getInstance().getPartyMembers(player)) {

View File

@ -22,7 +22,6 @@ import com.gmail.nossr50.spout.SpoutSounds;
import com.gmail.nossr50.events.fake.FakeBlockBreakEvent; import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
import org.bukkit.Bukkit;
import org.bukkit.CropState; import org.bukkit.CropState;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -268,7 +267,7 @@ public class mcBlockListener implements Listener {
else if (PP.getAbilityMode(AbilityType.BERSERK) && Skills.triggerCheck(player, block, AbilityType.BERSERK)) { else if (PP.getAbilityMode(AbilityType.BERSERK) && Skills.triggerCheck(player, block, AbilityType.BERSERK)) {
if (inhand.getType().equals(Material.AIR)) { if (inhand.getType().equals(Material.AIR)) {
FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player); FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
Bukkit.getPluginManager().callEvent(armswing); plugin.getServer().getPluginManager().callEvent(armswing);
event.setInstaBreak(true); event.setInstaBreak(true);
} }

View File

@ -2,7 +2,6 @@ package com.gmail.nossr50;
import java.util.Random; import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -108,11 +107,11 @@ public class m {
//Support for NoCheat //Support for NoCheat
if (shouldArmSwing) { if (shouldArmSwing) {
FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player); FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
Bukkit.getPluginManager().callEvent(armswing); mcMMO.p.getServer().getPluginManager().callEvent(armswing);
} }
FakeBlockBreakEvent event = new FakeBlockBreakEvent(block, player); FakeBlockBreakEvent event = new FakeBlockBreakEvent(block, player);
Bukkit.getPluginManager().callEvent(event); mcMMO.p.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) { if (!event.isCancelled()) {
return true; return true;
@ -236,7 +235,7 @@ public class m {
// We can't get the item until we spawn it and we want to make it cancellable, so we have a custom event. // We can't get the item until we spawn it and we want to make it cancellable, so we have a custom event.
McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(location, itemStack); McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(location, itemStack);
Bukkit.getPluginManager().callEvent(event); mcMMO.p.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;

View File

@ -24,7 +24,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.HashMap; import java.util.HashMap;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -37,20 +36,16 @@ import org.bukkit.entity.Player;
public class mcMMO extends JavaPlugin { public class mcMMO extends JavaPlugin {
public static String maindirectory = "plugins" + File.separator + "mcMMO";
public static File file = new File(maindirectory + File.separator + "config.yml");
public static File versionFile = new File(maindirectory + File.separator + "VERSION");
private final mcPlayerListener playerListener = new mcPlayerListener(this); private final mcPlayerListener playerListener = new mcPlayerListener(this);
private final mcBlockListener blockListener = new mcBlockListener(this); private final mcBlockListener blockListener = new mcBlockListener(this);
private final mcEntityListener entityListener = new mcEntityListener(this); private final mcEntityListener entityListener = new mcEntityListener(this);
//Alias - Command public HashMap<String, String> aliasMap = new HashMap<String, String>(); //Alias - Command
public HashMap<String, String> aliasMap = new HashMap<String, String>();
public HashMap<Entity, Integer> arrowTracker = new HashMap<Entity, Integer>(); public HashMap<Entity, Integer> arrowTracker = new HashMap<Entity, Integer>();
public HashMap<Integer, Player> tntTracker = new HashMap<Integer, Player>(); public HashMap<Integer, Player> tntTracker = new HashMap<Integer, Player>();
public static Database database = null; public static File versionFile;
public static Database database;
public static mcMMO p; public static mcMMO p;
//Config file stuff //Config file stuff
@ -60,13 +55,24 @@ public class mcMMO extends JavaPlugin {
//Jar stuff //Jar stuff
public static File mcmmo; public static File mcmmo;
//File Paths
public static String mainDirectory;
public static String flatFileDirectory;
public static String usersFile;
public static String leaderboardDirectory;
/** /**
* Things to be run when the plugin is enabled. * Things to be run when the plugin is enabled.
*/ */
public void onEnable() { public void onEnable() {
p = this; p = this;
mcmmo = this.getFile(); mcmmo = getFile();
new File(maindirectory).mkdir(); versionFile = new File(getDataFolder(), "VERSION");
mainDirectory = getDataFolder().getPath() + File.separator;
flatFileDirectory = mainDirectory + "FlatFileStuff" + File.separator;
leaderboardDirectory = flatFileDirectory + "Leaderboards" + File.separator;
usersFile = flatFileDirectory + "mcmmo.users";
if (!versionFile.exists()) { if (!versionFile.exists()) {
updateVersion(); updateVersion();
@ -97,13 +103,11 @@ public class mcMMO extends JavaPlugin {
new Party(this); new Party(this);
if (!LoadProperties.useMySQL) { if (!LoadProperties.useMySQL) {
Users.getInstance().loadUsers(); Users.loadUsers();
} }
PluginManager pm = getServer().getPluginManager(); PluginManager pm = getServer().getPluginManager();
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new SpoutStart(this), 20); //Schedule Spout Activation 1 second after start-up
//Register events //Register events
pm.registerEvents(playerListener, this); pm.registerEvents(playerListener, this);
pm.registerEvents(blockListener, this); pm.registerEvents(blockListener, this);
@ -128,6 +132,8 @@ public class mcMMO extends JavaPlugin {
BukkitScheduler scheduler = getServer().getScheduler(); BukkitScheduler scheduler = getServer().getScheduler();
//Schedule Spout Activation 1 second after start-up
scheduler.scheduleSyncDelayedTask(this, new SpoutStart(this), 20);
//Periodic save timer (Saves every 10 minutes) //Periodic save timer (Saves every 10 minutes)
scheduler.scheduleSyncRepeatingTask(this, new mcSaveTimer(this), 0, LoadProperties.saveInterval * 1200); scheduler.scheduleSyncRepeatingTask(this, new mcSaveTimer(this), 0, LoadProperties.saveInterval * 1200);
//Regen & Cooldown timer (Runs every second) //Regen & Cooldown timer (Runs every second)
@ -202,7 +208,7 @@ public class mcMMO extends JavaPlugin {
x.save(); x.save();
} }
Bukkit.getServer().getScheduler().cancelTasks(this); //This removes our tasks this.getServer().getScheduler().cancelTasks(this); //This removes our tasks
System.out.println("mcMMO was disabled."); //How informative! System.out.println("mcMMO was disabled."); //How informative!
} }
@ -457,7 +463,7 @@ public class mcMMO extends JavaPlugin {
treasuresConfig.save(treasuresConfigFile); treasuresConfig.save(treasuresConfigFile);
} }
catch (IOException ex) { catch (IOException ex) {
Bukkit.getLogger().severe("Could not save config to " + treasuresConfigFile + ex.toString()); this.getLogger().severe("Could not save config to " + treasuresConfigFile + ex.toString());
} }
} }
} }

View File

@ -18,9 +18,10 @@ import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;
public class Party { public class Party {
public static String partyPlayersFile = mcMMO.maindirectory + File.separator + "FlatFileStuff" + File.separator + "partyPlayers"; public static String pluginPath;
public static String partyLocksFile = mcMMO.maindirectory + File.separator + "FlatFileStuff" + File.separator + "partyLocks"; public static String partyPlayersFile;
public static String partyPasswordsFile = mcMMO.maindirectory + File.separator + "FlatFileStuff" + File.separator + "partyPasswords"; public static String partyLocksFile;
public static String partyPasswordsFile;
HashMap<String, HashMap<String, Boolean>> partyPlayers = new HashMap<String, HashMap<String, Boolean>>(); HashMap<String, HashMap<String, Boolean>> partyPlayers = new HashMap<String, HashMap<String, Boolean>>();
HashMap<String, Boolean> partyLocks = new HashMap<String, Boolean>(); HashMap<String, Boolean> partyLocks = new HashMap<String, Boolean>();
@ -30,8 +31,12 @@ public class Party {
private static volatile Party instance; private static volatile Party instance;
public Party(mcMMO instance) { public Party(mcMMO instance) {
new File(mcMMO.maindirectory + File.separator + "FlatFileStuff").mkdir();
plugin = instance; plugin = instance;
pluginPath = plugin.getDataFolder().getPath();
partyPlayersFile = pluginPath + File.separator + "FlatFileStuff" + File.separator + "partyPlayers";
partyLocksFile = pluginPath + File.separator + "FlatFileStuff" + File.separator + "partyLocks";
partyPasswordsFile = pluginPath + File.separator + "FlatFileStuff" + File.separator + "partyPasswords";
new File(pluginPath + File.separator + "FlatFileStuff").mkdir();
} }
public static Party getInstance() { public static Party getInstance() {

View File

@ -16,7 +16,7 @@ public class SQLConversionTask implements Runnable {
@Override @Override
public void run() { public void run() {
String location = "plugins/mcMMO/FlatFileStuff/mcmmo.users"; String location = mcMMO.usersFile;
try { try {
FileReader file = new FileReader(location); FileReader file = new FileReader(location);

View File

@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -14,6 +13,7 @@ import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.spout.SpoutSounds; import com.gmail.nossr50.spout.SpoutSounds;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.m; import com.gmail.nossr50.m;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.config.LoadTreasures; import com.gmail.nossr50.config.LoadTreasures;
@ -135,7 +135,7 @@ public class Excavation {
if (!block.hasMetadata("mcmmoPlacedBlock")) { if (!block.hasMetadata("mcmmoPlacedBlock")) {
FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player); FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
Bukkit.getPluginManager().callEvent(armswing); mcMMO.p.getServer().getPluginManager().callEvent(armswing);
Excavation.excavationProcCheck(block, player); Excavation.excavationProcCheck(block, player);
Excavation.excavationProcCheck(block, player); Excavation.excavationProcCheck(block, player);

View File

@ -2,7 +2,6 @@ package com.gmail.nossr50.skills;
import java.util.Random; import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.CropState; import org.bukkit.CropState;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -279,7 +278,7 @@ public class Herbalism {
m.mcDropItem(loc, new ItemStack(Material.WHEAT)); m.mcDropItem(loc, new ItemStack(Material.WHEAT));
m.mcRandomDropItems(loc, new ItemStack(Material.SEEDS), 50, 3); m.mcRandomDropItems(loc, new ItemStack(Material.SEEDS), 50, 3);
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new GreenThumbTimer(block, PP), 1); plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new GreenThumbTimer(block, PP), 1);
inventory.removeItem(new ItemStack(Material.SEEDS)); inventory.removeItem(new ItemStack(Material.SEEDS));
player.updateInventory(); player.updateInventory();

View File

@ -4,7 +4,6 @@ import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
@ -430,7 +429,7 @@ public class Repair {
PlayerInventory inventory = player.getInventory(); PlayerInventory inventory = player.getInventory();
McMMOPlayerRepairCheckEvent event = new McMMOPlayerRepairCheckEvent(player, (short) (initialDurability - newDurability), repairMaterial, item); McMMOPlayerRepairCheckEvent event = new McMMOPlayerRepairCheckEvent(player, (short) (initialDurability - newDurability), repairMaterial, item);
Bukkit.getPluginManager().callEvent(event); mcMMO.p.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;

View File

@ -10,11 +10,11 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Tree; import org.bukkit.material.Tree;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.Bukkit;
import com.gmail.nossr50.Combat; import com.gmail.nossr50.Combat;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.m; import com.gmail.nossr50.m;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
@ -313,7 +313,7 @@ public class WoodCutting {
*/ */
public static void leafBlower(Player player, Block block) { public static void leafBlower(Player player, Block block) {
FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player); FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
Bukkit.getPluginManager().callEvent(armswing); mcMMO.p.getServer().getPluginManager().callEvent(armswing);
if (LoadProperties.woodcuttingrequiresaxe) { if (LoadProperties.woodcuttingrequiresaxe) {
Skills.abilityDurabilityLoss(player.getItemInHand(), LoadProperties.abilityDurabilityLoss); Skills.abilityDurabilityLoss(player.getItemInHand(), LoadProperties.abilityDurabilityLoss);

View File

@ -12,10 +12,10 @@ import java.util.HashMap;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.getspout.spoutapi.SpoutManager; import org.getspout.spoutapi.SpoutManager;
import org.getspout.spoutapi.keyboard.Keyboard; import org.getspout.spoutapi.keyboard.Keyboard;
import org.getspout.spoutapi.player.SpoutPlayer; import org.getspout.spoutapi.player.SpoutPlayer;
@ -32,7 +32,13 @@ import com.gmail.nossr50.listeners.mcSpoutListener;
import com.gmail.nossr50.listeners.mcSpoutScreenListener; import com.gmail.nossr50.listeners.mcSpoutScreenListener;
public class SpoutStuff { public class SpoutStuff {
static mcMMO plugin = mcMMO.p; private static mcMMO plugin = mcMMO.p;
public final static String spoutDirectory = mcMMO.mainDirectory + "Resources" + File.separator;
public final static String hudDirectory = spoutDirectory + "HUD" + File.separator;
public final static String hudStandardDirectory = hudDirectory + "Standard" + File.separator;
public final static String hudRetroDirectory = hudDirectory + "Retro" + File.separator;
public final static String soundDirectory = spoutDirectory + "Sound" + File.separator;
private final static mcSpoutListener spoutListener = new mcSpoutListener(plugin); private final static mcSpoutListener spoutListener = new mcSpoutListener(plugin);
private final static mcSpoutInputListener spoutInputListener = new mcSpoutInputListener(plugin); private final static mcSpoutInputListener spoutInputListener = new mcSpoutInputListener(plugin);
@ -49,12 +55,11 @@ public class SpoutStuff {
* @param theFileName The name of the file * @param theFileName The name of the file
* @param theFilePath The name of the file path * @param theFilePath The name of the file path
*/ */
public static void writeFile(String theFileName, String theFilePath) { private static void writeFile(String theFileName, String theFilePath) {
try { try {
File currentFile = new File("plugins/mcMMO/Resources/" + theFilePath + theFileName); File currentFile = new File(theFilePath + theFileName);
@SuppressWarnings("static-access") JarFile jar = new JarFile(mcMMO.mcmmo);
JarFile jar = new JarFile(plugin.mcmmo);
JarEntry entry = jar.getJarEntry("resources/" + theFileName); JarEntry entry = jar.getJarEntry("resources/" + theFileName);
InputStream is = jar.getInputStream(entry); InputStream is = jar.getInputStream(entry);
@ -84,15 +89,14 @@ public class SpoutStuff {
public static void extractFiles() { public static void extractFiles() {
//Setup directories //Setup directories
new File("plugins/mcMMO/Resources/").mkdir(); new File(spoutDirectory).mkdir();
new File("plugins/mcMMO/Resources/HUD/").mkdir(); new File(hudDirectory).mkdir();
new File("plugins/mcMMO/Resources/HUD/Standard/").mkdir(); new File(hudStandardDirectory).mkdir();
new File("plugins/mcMMO/Resources/HUD/Retro/").mkdir(); new File(hudRetroDirectory).mkdir();
new File("plugins/mcMMO/Resources/Sound/").mkdir(); new File(soundDirectory).mkdir();
//XP Bar images //XP Bar images
for (int x = 0; x < 255; x++) { for (int x = 0; x < 255; x++) {
String theFilePath = "HUD/Standard/";
String theFileName; String theFileName;
if (x < 10) { if (x < 10) {
@ -105,13 +109,10 @@ public class SpoutStuff {
theFileName = "xpbar_inc" + x + ".png"; theFileName = "xpbar_inc" + x + ".png";
} }
writeFile(theFileName, theFilePath); writeFile(theFileName, hudStandardDirectory);
} }
//Standard XP Icons //Standard XP Icons
String standardFilePath = "HUD/Standard/";
String retroFilePath = "HUD/Retro/";
for (SkillType y : SkillType.values()) { for (SkillType y : SkillType.values()) {
if (y.equals(SkillType.ALL)) { if (y.equals(SkillType.ALL)) {
continue; continue;
@ -120,19 +121,17 @@ public class SpoutStuff {
String standardFileName = m.getCapitalized(y.toString())+".png"; String standardFileName = m.getCapitalized(y.toString())+".png";
String retroFileName = m.getCapitalized(y.toString())+"_r.png"; String retroFileName = m.getCapitalized(y.toString())+"_r.png";
writeFile(standardFileName, standardFilePath); writeFile(standardFileName, hudStandardDirectory);
writeFile(retroFileName, retroFilePath); writeFile(retroFileName, hudRetroDirectory);
} }
//Blank icons //Blank icons
writeFile("Icon.png", standardFilePath); writeFile("Icon.png", hudStandardDirectory);
writeFile("Icon_r.png", retroFilePath); writeFile("Icon_r.png", hudRetroDirectory);
//Sound FX //Sound FX
String theSoundFilePath = "Sound/"; writeFile("repair.wav", soundDirectory);
writeFile("level.wav", soundDirectory);
writeFile("repair.wav", theSoundFilePath);
writeFile("level.wav", theSoundFilePath);
} }
/** /**
@ -160,18 +159,17 @@ public class SpoutStuff {
*/ */
public static ArrayList<File> getFiles() { public static ArrayList<File> getFiles() {
ArrayList<File> files = new ArrayList<File>(); ArrayList<File> files = new ArrayList<File>();
String dir = "plugins/mcMMO/Resources/";
/* XP BAR */ /* XP BAR */
for (int x = 0; x < 255; x++) { for (int x = 0; x < 255; x++) {
if (x < 10) { if (x < 10) {
files.add(new File(dir + "HUD/Standard/xpbar_inc00" + x + ".png")); files.add(new File(hudStandardDirectory + "xpbar_inc00" + x + ".png"));
} }
else if (x < 100) { else if (x < 100) {
files.add(new File(dir + "HUD/Standard/xpbar_inc0" + x + ".png")); files.add(new File(hudStandardDirectory + "xpbar_inc0" + x + ".png"));
} }
else { else {
files.add(new File(dir + "HUD/Standard/xpbar_inc" + x + ".png")); files.add(new File(hudStandardDirectory + "xpbar_inc" + x + ".png"));
} }
} }
@ -181,19 +179,19 @@ public class SpoutStuff {
continue; continue;
} }
files.add(new File(dir + "HUD/Standard/" + m.getCapitalized(y.toString()) + ".png")); files.add(new File(hudStandardDirectory + m.getCapitalized(y.toString()) + ".png"));
files.add(new File(dir + "HUD/Retro/" + m.getCapitalized(y.toString()) + "_r.png")); files.add(new File(hudRetroDirectory + m.getCapitalized(y.toString()) + "_r.png"));
} }
/* Blank icons */ /* Blank icons */
files.add(new File(dir + "HUD/Standard/Icon.png")); files.add(new File(hudStandardDirectory + "Icon.png"));
files.add(new File(dir + "HUD/Retro/Icon_r.png")); files.add(new File(hudRetroDirectory + "Icon_r.png"));
//Repair SFX //Repair SFX
files.add(new File(dir + "Sound/repair.wav")); files.add(new File(soundDirectory + "repair.wav"));
//Level SFX //Level SFX
files.add(new File(dir + "Sound/level.wav")); files.add(new File(soundDirectory + "level.wav"));
return files; return files;
} }
@ -202,9 +200,9 @@ public class SpoutStuff {
* Register custom Spout events. * Register custom Spout events.
*/ */
public static void registerCustomEvent() { public static void registerCustomEvent() {
Bukkit.getServer().getPluginManager().registerEvents(spoutListener, plugin); plugin.getServer().getPluginManager().registerEvents(spoutListener, plugin);
Bukkit.getServer().getPluginManager().registerEvents(spoutInputListener, plugin); plugin.getServer().getPluginManager().registerEvents(spoutInputListener, plugin);
Bukkit.getServer().getPluginManager().registerEvents(spoutScreenListener, plugin); plugin.getServer().getPluginManager().registerEvents(spoutScreenListener, plugin);
} }
/** /**
@ -214,7 +212,7 @@ public class SpoutStuff {
* @return the SpoutPlayer related to this player name, null if there's no player online with that name. * @return the SpoutPlayer related to this player name, null if there's no player online with that name.
*/ */
public static SpoutPlayer getSpoutPlayer(String playerName) { public static SpoutPlayer getSpoutPlayer(String playerName) {
for (Player x : Bukkit.getServer().getOnlinePlayers()) { for (Player x : plugin.getServer().getOnlinePlayers()) {
if (x.getName().equalsIgnoreCase(playerName)) { if (x.getName().equalsIgnoreCase(playerName)) {
return SpoutManager.getPlayer(x); return SpoutManager.getPlayer(x);
} }

View File

@ -1,4 +1,5 @@
name: mcMMO name: mcMMO
website: mcmmo.org
main: com.gmail.nossr50.mcMMO main: com.gmail.nossr50.mcMMO
version: ${project.version}-b${BUILD_NUMBER} version: ${project.version}-b${BUILD_NUMBER}
softdepend: [Spout] softdepend: [Spout]