More generic cleanup.

This commit is contained in:
GJ 2012-03-08 16:17:57 -05:00
parent 88ab232ccd
commit e9e7d462f7
6 changed files with 657 additions and 551 deletions

View File

@ -1,5 +1,6 @@
package com.gmail.nossr50.listeners; package com.gmail.nossr50.listeners;
import com.gmail.nossr50.BlockChecks;
import com.gmail.nossr50.ItemChecks; import com.gmail.nossr50.ItemChecks;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.m; import com.gmail.nossr50.m;
@ -56,7 +57,7 @@ public class mcBlockListener implements Listener
Material mat = block.getType(); Material mat = block.getType();
//Check if the blocks placed should be monitored so they do not give out XP in the future //Check if the blocks placed should be monitored so they do not give out XP in the future
if(m.shouldBeWatched(mat)) if(BlockChecks.shouldBeWatched(mat))
{ {
//Only needed for blocks that use their block data (wood, pumpkins, etc.) //Only needed for blocks that use their block data (wood, pumpkins, etc.)
boolean shouldBeChanged = true; boolean shouldBeChanged = true;
@ -171,7 +172,7 @@ public class mcBlockListener implements Listener
} }
//Change the byte back when broken //Change the byte back when broken
if(block.getData() == 5 && m.shouldBeWatched(block.getType())) if(block.getData() == 5 && BlockChecks.shouldBeWatched(block.getType()))
{ {
block.setData((byte) 0); block.setData((byte) 0);
if(plugin.misc.blockWatchList.contains(block)) if(plugin.misc.blockWatchList.contains(block))
@ -192,7 +193,7 @@ public class mcBlockListener implements Listener
/* /*
* ABILITY PREPARATION CHECKS * ABILITY PREPARATION CHECKS
*/ */
if(m.abilityBlockCheck(mat)) if(BlockChecks.abilityBlockCheck(mat))
{ {
if(PP.getHoePreparationMode() && Herbalism.canBeGreenTerra(block)) if(PP.getHoePreparationMode() && Herbalism.canBeGreenTerra(block))
Skills.abilityCheck(player, SkillType.HERBALISM); Skills.abilityCheck(player, SkillType.HERBALISM);
@ -300,7 +301,7 @@ public class mcBlockListener implements Listener
{ {
Block blockFrom = event.getBlock(); Block blockFrom = event.getBlock();
Block blockTo = event.getToBlock(); Block blockTo = event.getToBlock();
if(m.shouldBeWatched(blockFrom.getType()) && blockFrom.getData() == (byte)5) if(BlockChecks.shouldBeWatched(blockFrom.getType()) && blockFrom.getData() == (byte)5)
blockTo.setData((byte)5); blockTo.setData((byte)5);
} }
} }

View File

@ -28,6 +28,7 @@ import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.BlockChecks;
import com.gmail.nossr50.Combat; import com.gmail.nossr50.Combat;
import com.gmail.nossr50.Item; import com.gmail.nossr50.Item;
import com.gmail.nossr50.ItemChecks; import com.gmail.nossr50.ItemChecks;
@ -177,7 +178,7 @@ public class mcPlayerListener implements Listener
player.updateInventory(); player.updateInventory();
} }
if(LoadProperties.enableAbilities && m.abilityBlockCheck(mat)) if(LoadProperties.enableAbilities && BlockChecks.abilityBlockCheck(mat))
{ {
if(block != null && ItemChecks.isHoe(is) && !mat.equals(Material.DIRT) && !mat.equals(Material.GRASS) && !mat.equals(Material.SOIL)) if(block != null && ItemChecks.isHoe(is) && !mat.equals(Material.DIRT) && !mat.equals(Material.GRASS) && !mat.equals(Material.SOIL))
Skills.activationCheck(player, SkillType.HERBALISM); Skills.activationCheck(player, SkillType.HERBALISM);
@ -247,7 +248,7 @@ public class mcPlayerListener implements Listener
*/ */
if(action == Action.RIGHT_CLICK_AIR) if(action == Action.RIGHT_CLICK_AIR)
Item.itemchecks(player); Item.itemchecks(player);
if(action == Action.RIGHT_CLICK_BLOCK && m.abilityBlockCheck(mat)) if(action == Action.RIGHT_CLICK_BLOCK && BlockChecks.abilityBlockCheck(mat))
Item.itemchecks(player); Item.itemchecks(player);
if(player.isSneaking() && mcPermissions.getInstance().taming(player) && (action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK)) if(player.isSneaking() && mcPermissions.getInstance().taming(player) && (action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK))

View File

@ -7,7 +7,6 @@ import java.util.logging.Logger;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.*; import org.bukkit.entity.*;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
@ -73,54 +72,6 @@ public class m {
} }
} }
/**
* Checks to see if a block type awards XP.
*
* @param material Block type to check
* @return true if the block type awards XP, false otherwise
*/
public static boolean shouldBeWatched(Material material) {
switch (material) {
case BROWN_MUSHROOM:
case CACTUS:
case CLAY:
case COAL_ORE:
case DIAMOND_ORE:
case DIRT:
case ENDER_STONE:
case GLOWING_REDSTONE_ORE:
case GLOWSTONE:
case GOLD_ORE:
case GRASS:
case GRAVEL:
case IRON_ORE:
case JACK_O_LANTERN:
case LAPIS_ORE:
case LOG:
case MELON_BLOCK:
case MOSSY_COBBLESTONE:
case MYCEL:
case NETHERRACK:
case OBSIDIAN:
case PUMPKIN:
case RED_MUSHROOM:
case RED_ROSE:
case REDSTONE_ORE:
case SAND:
case SANDSTONE:
case SOUL_SAND:
case STONE:
case SUGAR_CANE_BLOCK:
case VINE:
case WATER_LILY:
case YELLOW_FLOWER:
return true;
default:
return false;
}
}
/** /**
* Gets the power level of a player. * Gets the power level of a player.
* *
@ -173,199 +124,282 @@ public class m {
* @param inHand The item to check the tier of * @param inHand The item to check the tier of
* @return the tier of the item * @return the tier of the item
*/ */
public static Integer getTier(ItemStack inHand) public static Integer getTier(ItemStack inHand) {
{ int tier = 0;
if(Repair.isWoodTools(inHand))
return 1;
if(Repair.isStoneTools(inHand))
return 2;
if(Repair.isIronTools(inHand))
return 3;
if(Repair.isGoldTools(inHand))
return 1;
if(Repair.isDiamondTools(inHand))
return 4;
return 1; if (Repair.isWoodTools(inHand)) {
tier = 1;
}
else if (Repair.isStoneTools(inHand)) {
tier = 2;
}
else if (Repair.isIronTools(inHand)) {
tier = 3;
}
else if(Repair.isGoldTools(inHand)) {
tier = 1;
}
else if(Repair.isDiamondTools(inHand))
tier = 4;
return tier;
} }
/**
* Determine if two locations are near each other.
*
* @param first The first location
* @param second The second location
* @param maxDistance The max distance apart
* @return true if the distance between <code>first</code> and <code>second</code> is less than <code>maxDistance</code>, false otherwise
*/
public static boolean isNear(Location first, Location second, int maxDistance) { public static boolean isNear(Location first, Location second, int maxDistance) {
double relX = first.getX() - second.getX(); double relX = first.getX() - second.getX();
double relY = first.getY() - second.getY(); double relY = first.getY() - second.getY();
double relZ = first.getZ() - second.getZ(); double relZ = first.getZ() - second.getZ();
double dist = relX * relX + relY * relY + relZ * relZ; double dist = (relX * relX) + (relY * relY) + (relZ * relZ);
if (dist < maxDistance * maxDistance) if (dist < maxDistance * maxDistance) {
return true; return true;
}
return false; else {
}
public static boolean abilityBlockCheck(Material material)
{
switch(material){
case BED_BLOCK:
case BREWING_STAND:
case BOOKSHELF:
case BURNING_FURNACE:
case CAKE_BLOCK:
case CHEST:
case DISPENSER:
case ENCHANTMENT_TABLE:
case FENCE_GATE:
case FURNACE:
case IRON_DOOR_BLOCK:
case JUKEBOX:
case LEVER:
case NOTE_BLOCK:
case STONE_BUTTON:
case TRAP_DOOR:
case WALL_SIGN:
case WOODEN_DOOR:
case WORKBENCH:
return false; return false;
} }
if(Material.getMaterial(LoadProperties.anvilID).equals(material))
return false;
return true;
} }
public static boolean isInt(String string) /**
{ * Determine if a string represents an Integer
try *
{ * @param string String to check
* @return true if the string is an Integer, false otherwise
*/
public static boolean isInt(String string) {
try {
Integer.parseInt(string); Integer.parseInt(string);
return true;
} }
catch(NumberFormatException nFE) catch (NumberFormatException nFE) {
{
return false; return false;
} }
return true;
} }
public static void mcDropItems(Location location, ItemStack is, int quantity) /**
{ * Drop items at a given location.
for(int i = 0; i < quantity; i++) *
* @param location The location to drop the items at
* @param is The items to drop
* @param quantity The amount of items to drop
*/
public static void mcDropItems(Location location, ItemStack is, int quantity) {
for (int i = 0; i < quantity; i++) {
mcDropItem(location, is); mcDropItem(location, is);
}
} }
public static void mcRandomDropItem(Location location, ItemStack is, int chance) /**
{ * Randomly drop an item at a given location.
if(Math.random() * 100 < chance) *
* @param location The location to drop the items at
* @param is The item to drop
* @param chance The percentage chance for the item to drop
*/
public static void mcRandomDropItem(Location location, ItemStack is, double chance) {
if (Math.random() * 100 < chance) {
mcDropItem(location, is); mcDropItem(location, is);
}
} }
public static void mcRandomDropItems(Location location, ItemStack is, int chance, int quantity) /**
{ * Randomly drop items at a given location.
for(int i = 0; i < quantity; i++) *
* @param location The location to drop the items at
* @param is The item to drop
* @param chance The percentage chance for the item to drop
* @param quantity The amount of items to drop
*/
public static void mcRandomDropItems(Location location, ItemStack is, int chance, int quantity) {
for(int i = 0; i < quantity; i++) {
mcRandomDropItem(location, is, chance); mcRandomDropItem(location, is, chance);
}
} }
/**
* Drop an item at a given location.
*
* @param location The location to drop the item at
* @param itemStack The item to drop
*/
public static void mcDropItem(Location location, ItemStack itemStack) { public static void mcDropItem(Location location, ItemStack itemStack) {
// 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); Bukkit.getPluginManager().callEvent(event);
if(event.isCancelled()) return;
location.getWorld().dropItemNaturally(location, itemStack); if (event.isCancelled()) {
}
public static boolean isOre(Block block)
{
switch (block.getType()) {
case COAL_ORE:
case DIAMOND_ORE:
case GLOWING_REDSTONE_ORE:
case GOLD_ORE:
case IRON_ORE:
case LAPIS_ORE:
case REDSTONE_ORE:
return true;
}
return false;
}
public static void convertToMySQL()
{
if(!LoadProperties.useMySQL)
return; return;
}
else {
location.getWorld().dropItemNaturally(location, itemStack);
}
}
Bukkit.getScheduler().scheduleAsyncDelayedTask(Bukkit.getServer().getPluginManager().getPlugin("mcMMO"), new Runnable(){ /**
* Convert FlatFile data to MySQL data.
*/
public static void convertToMySQL() {
if (!LoadProperties.useMySQL) {
return;
}
Bukkit.getScheduler().scheduleAsyncDelayedTask(Bukkit.getPluginManager().getPlugin("mcMMO"), new Runnable() {
public void run() { public void run() {
String location = "plugins/mcMMO/FlatFileStuff/mcmmo.users"; String location = "plugins/mcMMO/FlatFileStuff/mcmmo.users";
try { try {
//Open the user file //Open the user file
FileReader file = new FileReader(location); FileReader file = new FileReader(location);
BufferedReader in = new BufferedReader(file); BufferedReader in = new BufferedReader(file);
String line = ""; String line = "";
String playerName = null, mining = null, party = null, miningXP = null, woodcutting = null, woodCuttingXP = null, repair = null, unarmed = null, herbalism = null, excavation = null, archery = null, swords = null, axes = null, acrobatics = null, repairXP = null, unarmedXP = null, herbalismXP = null, excavationXP = null, archeryXP = null, swordsXP = null, axesXP = null, acrobaticsXP = null, taming = null, tamingXP = null, fishing = null, fishingXP = null; String playerName = null;
int id = 0, theCount = 0; String party = null;
String mining = null;
String woodcutting = null;
String repair = null;
String unarmed = null;
String herbalism = null;
String excavation = null;
String archery = null;
String swords = null;
String axes = null;
String acrobatics = null;
String taming = null;
String fishing = null;
String miningXP = null;
String woodCuttingXP = null;
String repairXP = null;
String unarmedXP = null;
String herbalismXP = null;
String excavationXP = null;
String archeryXP = null;
String swordsXP = null;
String axesXP = null;
String acrobaticsXP = null;
String tamingXP = null;
String fishingXP = null;
int id = 0;
int theCount = 0;
while ((line = in.readLine()) != null) { while ((line = in.readLine()) != null) {
//Find if the line contains the player we want. //Find if the line contains the player we want.
String[] character = line.split(":"); String[] character = line.split(":");
playerName = character[0]; playerName = character[0];
//Check for things we don't want put in the DB
if (playerName == null
|| playerName.equals("null")
|| playerName
.equals("#Storage place for user information"))
continue;
//Get Mining //Check for things we don't want put in the DB
if (character.length > 1) if (playerName == null || playerName.equals("null") || playerName.equals("#Storage place for user information")) {
continue;
}
if (character.length > 1) {
mining = character[1]; mining = character[1];
//Party }
if (character.length > 3)
if (character.length > 3) {
party = character[3]; party = character[3];
//Mining XP }
if (character.length > 4)
if (character.length > 4) {
miningXP = character[4]; miningXP = character[4];
if (character.length > 5) }
if (character.length > 5) {
woodcutting = character[5]; woodcutting = character[5];
if (character.length > 6) }
if (character.length > 6) {
woodCuttingXP = character[6]; woodCuttingXP = character[6];
if (character.length > 7) }
if (character.length > 7) {
repair = character[7]; repair = character[7];
if (character.length > 8) }
if (character.length > 8) {
unarmed = character[8]; unarmed = character[8];
if (character.length > 9) }
if (character.length > 9) {
herbalism = character[9]; herbalism = character[9];
if (character.length > 10) }
if (character.length > 10) {
excavation = character[10]; excavation = character[10];
if (character.length > 11) }
if (character.length > 11) {
archery = character[11]; archery = character[11];
if (character.length > 12) }
if (character.length > 12) {
swords = character[12]; swords = character[12];
if (character.length > 13) }
if (character.length > 13) {
axes = character[13]; axes = character[13];
if (character.length > 14) }
if (character.length > 14) {
acrobatics = character[14]; acrobatics = character[14];
if (character.length > 15) }
if (character.length > 15) {
repairXP = character[15]; repairXP = character[15];
if (character.length > 16) }
if (character.length > 16) {
unarmedXP = character[16]; unarmedXP = character[16];
if (character.length > 17) }
if (character.length > 17) {
herbalismXP = character[17]; herbalismXP = character[17];
if (character.length > 18) }
if (character.length > 18) {
excavationXP = character[18]; excavationXP = character[18];
if (character.length > 19) }
if (character.length > 19) {
archeryXP = character[19]; archeryXP = character[19];
if (character.length > 20) }
if (character.length > 20) {
swordsXP = character[20]; swordsXP = character[20];
if (character.length > 21) }
if (character.length > 21) {
axesXP = character[21]; axesXP = character[21];
if (character.length > 22) }
if (character.length > 22) {
acrobaticsXP = character[22]; acrobaticsXP = character[22];
if (character.length > 24) }
if (character.length > 24) {
taming = character[24]; taming = character[24];
if (character.length > 25) }
if (character.length > 25) {
tamingXP = character[25]; tamingXP = character[25];
if (character.length > 34) }
if (character.length > 34) {
fishing = character[34]; fishing = character[34];
if (character.length > 35) }
if (character.length > 35) {
fishingXP = character[35]; fishingXP = character[35];
}
//Check to see if the user is in the DB //Check to see if the user is in the DB
id = mcMMO.database.getInt("SELECT id FROM " id = mcMMO.database.getInt("SELECT id FROM "
@ -374,6 +408,7 @@ public class m {
if (id > 0) { if (id > 0) {
theCount++; theCount++;
//Update the skill values //Update the skill values
mcMMO.database.write("UPDATE " mcMMO.database.write("UPDATE "
+ LoadProperties.MySQLtablePrefix + LoadProperties.MySQLtablePrefix
@ -415,8 +450,10 @@ public class m {
+ getInt(acrobaticsXP) + ", fishing = " + getInt(acrobaticsXP) + ", fishing = "
+ getInt(fishingXP) + " WHERE user_id = " + getInt(fishingXP) + " WHERE user_id = "
+ id); + id);
} else { }
else {
theCount++; theCount++;
//Create the user in the DB //Create the user in the DB
mcMMO.database.write("INSERT INTO " mcMMO.database.write("INSERT INTO "
+ LoadProperties.MySQLtablePrefix + LoadProperties.MySQLtablePrefix
@ -478,14 +515,12 @@ public class m {
+ id); + id);
} }
} }
System.out
.println("[mcMMO] MySQL Updated from users file, " System.out.println("[mcMMO] MySQL Updated from users file, " + theCount + " items added/updated to MySQL DB");
+ theCount
+ " items added/updated to MySQL DB");
in.close(); in.close();
} catch (Exception e) { }
log.log(Level.SEVERE, "Exception while reading " + location catch (Exception e) {
+ " (Are you sure you formatted it correctly?)", e); log.log(Level.SEVERE, "Exception while reading " + location + " (Are you sure you formatted it correctly?)", e);
} }
} }
}, 1); }, 1);

View File

@ -17,8 +17,6 @@ import com.gmail.nossr50.locale.mcLocale;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.skills.*; import com.gmail.nossr50.skills.*;
import org.bukkit.Bukkit;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
@ -35,6 +33,7 @@ import java.util.HashMap;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -46,367 +45,437 @@ import org.bukkit.entity.Player;
import org.getspout.spoutapi.SpoutManager; import org.getspout.spoutapi.SpoutManager;
import org.getspout.spoutapi.player.FileManager; import org.getspout.spoutapi.player.FileManager;
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");
public static final Logger log = Logger.getLogger("Minecraft");
public static String maindirectory = "plugins" + File.separator + "mcMMO"; private final mcPlayerListener playerListener = new mcPlayerListener(this);
File file = new File(maindirectory + File.separator + "config.yml"); private final mcBlockListener blockListener = new mcBlockListener(this);
static File versionFile = new File(maindirectory + File.separator + "VERSION"); private final mcEntityListener entityListener = new mcEntityListener(this);
public static final Logger log = Logger.getLogger("Minecraft");
private final mcPlayerListener playerListener = new mcPlayerListener(this); //Queue for block data change for R2+ fix
private final mcBlockListener blockListener = new mcBlockListener(this); public ArrayDeque<Block> changeQueue = new ArrayDeque<Block>();
private final mcEntityListener entityListener = new mcEntityListener(this); public ArrayDeque<Block> fastChangeQueue = new ArrayDeque<Block>();
//Queue for block data change for R2+ fix private Runnable mcMMO_Timer = new mcTimer(this); //BLEED AND REGENERATION
public ArrayDeque<Block> changeQueue = new ArrayDeque<Block>(); private Runnable mcMMO_SaveTimer = new mcSaveTimer(this); //Periodic saving of Player Data
public ArrayDeque<Block> fastChangeQueue = new ArrayDeque<Block>(); private Runnable ChangeDataValueTimer = new ChangeDataValueTimer(changeQueue); //R2 block place workaround
private Runnable FastChangeDataValueTimer = new ChangeDataValueTimer(fastChangeQueue); //R2 block place workaround for instant-break stuff
private Runnable mcMMO_Timer = new mcTimer(this); //BLEED AND REGENERATION //Alias - Command
private Runnable mcMMO_SaveTimer = new mcSaveTimer(this); //Periodic saving of Player Data public HashMap<String, String> aliasMap = new HashMap<String, String>();
private Runnable ChangeDataValueTimer = new ChangeDataValueTimer(changeQueue); //R2 block place workaround
private Runnable FastChangeDataValueTimer = new ChangeDataValueTimer(fastChangeQueue);
//Alias - Command public static Database database = null;
public HashMap<String, String> aliasMap = new HashMap<String, String>(); public Misc misc = new Misc(this);
public static Database database = null; //Config file stuff
public Misc misc = new Misc(this); LoadProperties config;
LoadTreasures config2;
//Config file stuff //Jar stuff
LoadProperties config; public static File mcmmo;
LoadTreasures config2;
//Jar stuff /**
public static File mcmmo; * Things to be run when the plugin is enabled.
*/
public void onEnable() {
final Plugin thisPlugin = this;
mcmmo = this.getFile();
new File(maindirectory).mkdir();
public void onEnable() if (!versionFile.exists()) {
{ updateVersion();
final Plugin thisPlugin = this; }
mcmmo = this.getFile(); else {
new File(maindirectory).mkdir(); String vnum = readVersion();
if(!versionFile.exists()) //This will be changed to whatever version preceded when we actually need updater code.
{ //Version 1.0.48 is the first to implement this, no checking before that version can be done.
updateVersion(); if (vnum.equalsIgnoreCase("1.0.48")) {
} else updateFrom(1);
{ }
String vnum = readVersion();
//This will be changed to whatever version preceded when we actually need updater code.
//Version 1.0.48 is the first to implement this, no checking before that version can be done.
if(vnum.equalsIgnoreCase("1.0.48")) {
updateFrom(1);
}
//Just add in more else if blocks for versions that need updater code. Increment the updateFrom age int as we do so.
//Catch all for versions not matching and no specific code being needed
else if(!vnum.equalsIgnoreCase(this.getDescription().getVersion())) updateFrom(-1);
}
this.config = new LoadProperties(this); //Just add in more else if blocks for versions that need updater code. Increment the updateFrom age int as we do so.
this.config.load(); //Catch all for versions not matching and no specific code being needed
else if (!vnum.equalsIgnoreCase(this.getDescription().getVersion())) {
updateFrom(-1);
}
}
this.config2 = new LoadTreasures(this); this.config = new LoadProperties(this);
this.config2.load(); this.config.load();
Party.getInstance().loadParties(); this.config2 = new LoadTreasures(this);
new Party(this); this.config2.load();
if(!LoadProperties.useMySQL) Party.getInstance().loadParties();
Users.getInstance().loadUsers(); //Load Users file new Party(this);
/*
* REGISTER EVENTS
*/
PluginManager pm = getServer().getPluginManager(); if (!LoadProperties.useMySQL) {
Users.getInstance().loadUsers();
}
if(pm.getPlugin("Spout") != null) PluginManager pm = getServer().getPluginManager();
LoadProperties.spoutEnabled = true;
else
LoadProperties.spoutEnabled = false;
//Register events if (pm.getPlugin("Spout") != null) {
pm.registerEvents(playerListener, this); LoadProperties.spoutEnabled = true;
pm.registerEvents(blockListener, this); }
pm.registerEvents(entityListener, this); else {
LoadProperties.spoutEnabled = false;
}
PluginDescriptionFile pdfFile = this.getDescription(); //Register events
pm.registerEvents(playerListener, this);
pm.registerEvents(blockListener, this);
pm.registerEvents(entityListener, this);
if(LoadProperties.useMySQL) PluginDescriptionFile pdfFile = this.getDescription();
{
database = new Database(this);
database.createStructure();
} else
Leaderboard.makeLeaderboards(); //Make the leaderboards
for(Player player : getServer().getOnlinePlayers()){Users.addUser(player);} //In case of reload add all users back into PlayerProfile //Setup the leaderboards
System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" ); if (LoadProperties.useMySQL) {
database = new Database(this);
database.createStructure();
}
else {
Leaderboard.makeLeaderboards();
}
//Periodic save timer (Saves every 10 minutes) for (Player player : getServer().getOnlinePlayers()) {
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, mcMMO_SaveTimer, 0, LoadProperties.saveInterval * 1200); Users.addUser(player); //In case of reload add all users back into PlayerProfile
}
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, mcMMO_Timer, 0, 20); System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
//R2+ block place fix
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, ChangeDataValueTimer, 0, 10);
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, FastChangeDataValueTimer, 0, 1);
registerCommands(); //Periodic save timer (Saves every 10 minutes)
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, mcMMO_SaveTimer, 0, LoadProperties.saveInterval * 1200);
//Spout Stuff //Bleed & Regen timer (Runs every 20 seconds)
if(LoadProperties.spoutEnabled) Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, mcMMO_Timer, 0, 20);
{
SpoutStuff.setupSpoutConfigs();
SpoutStuff.registerCustomEvent();
SpoutStuff.extractFiles(); //Extract source materials
FileManager FM = SpoutManager.getFileManager(); //R2+ block place fix
FM.addToPreLoginCache(this, SpoutStuff.getFiles()); Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, ChangeDataValueTimer, 0, 10);
} Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, FastChangeDataValueTimer, 0, 1);
if(LoadProperties.statsTracking) { registerCommands();
//Plugin Metrics running in a new thread
new Thread(new Runnable() {
public void run() {
try {
// create a new metrics object
Metrics metrics = new Metrics();
// 'this' in this context is the Plugin object //Spout Stuff
metrics.beginMeasuringPlugin(thisPlugin); if (LoadProperties.spoutEnabled) {
} catch (IOException e) { SpoutStuff.setupSpoutConfigs();
// Failed to submit the stats :-( SpoutStuff.registerCustomEvent();
} SpoutStuff.extractFiles(); //Extract source materials
}
}).start();
}
}
public PlayerProfile getPlayerProfile(Player player) FileManager FM = SpoutManager.getFileManager();
{ FM.addToPreLoginCache(this, SpoutStuff.getFiles());
return Users.getProfile(player); }
}
public void checkXp(Player player, SkillType skillType) if (LoadProperties.statsTracking) {
{ //Plugin Metrics running in a new thread
if(skillType == SkillType.ALL) new Thread(new Runnable() {
Skills.XpCheckAll(player); public void run() {
else try {
Skills.XpCheckSkill(skillType, player); // create a new metrics object
} Metrics metrics = new Metrics();
public boolean inSameParty(Player playera, Player playerb) // 'this' in this context is the Plugin object
{ metrics.beginMeasuringPlugin(thisPlugin);
if(Users.getProfile(playera).inParty() && Users.getProfile(playerb).inParty()){ }
if(Users.getProfile(playera).getParty().equals(Users.getProfile(playerb).getParty())){ catch (IOException e) {
return true; System.out.println("Failed to submit stats.");
} else { }
return false; }
} }).start();
} else { }
return false; }
}
}
public ArrayList<String> getParties(){
String location = "plugins/mcMMO/mcmmo.users";
ArrayList<String> parties = new ArrayList<String>();
try {
//Open the users file
FileReader file = new FileReader(location);
BufferedReader in = new BufferedReader(file);
String line = "";
while((line = in.readLine()) != null)
{
String[] character = line.split(":");
String theparty = null;
//Party
if(character.length > 3)
theparty = character[3];
if(!parties.contains(theparty))
parties.add(theparty);
}
in.close();
} catch (Exception e) {
log.log(Level.SEVERE, "Exception while reading "
+ location + " (Are you sure you formatted it correctly?)", e);
}
return parties;
}
public static String getPartyName(Player player){
PlayerProfile PP = Users.getProfile(player);
return PP.getParty();
}
public static boolean inParty(Player player){
PlayerProfile PP = Users.getProfile(player);
return PP.inParty();
}
public void onDisable() /**
{ * Get profile of the player.
//Make sure to save player information if the server shuts down * </br>
for(Player x : Bukkit.getServer().getOnlinePlayers()) * This function is designed for API usage.
{ *
Users.getProfile(x).save(); * @param player Player whose profile to get
} * @return the PlayerProfile object
*/
public PlayerProfile getPlayerProfile(Player player) {
return Users.getProfile(player);
}
Bukkit.getServer().getScheduler().cancelTasks(this); //This removes our tasks /**
* Check the XP of a player.
* </br>
* This function is designed for API usage.
*
* @param player
* @param skillType
*/
public void checkXp(Player player, SkillType skillType) {
if (skillType == SkillType.ALL) {
Skills.XpCheckAll(player);
}
else {
Skills.XpCheckSkill(skillType, player);
}
}
System.out.println("mcMMO was disabled."); //How informative! /**
} * Check if two players are in the same party.
* </br>
* This function is designed for API usage.
*
* @param playera The first player to check
* @param playerb The second player to check
* @return true if the two players are in the same party, false otherwise
*/
public boolean inSameParty(Player playera, Player playerb) {
if (Users.getProfile(playera).inParty() && Users.getProfile(playerb).inParty()) {
if (Users.getProfile(playera).getParty().equals(Users.getProfile(playerb).getParty())) {
return true;
}
else {
return false;
}
}
else {
return false;
}
}
private void registerCommands() { /**
//Register aliases with the aliasmap (used in the playercommandpreprocessevent to ugly alias them to actual commands) * Get a list of all current party names.
//Skills commands * </br>
aliasMap.put(mcLocale.getString("m.SkillAcrobatics").toLowerCase(), "acrobatics"); * This function is designed for API usage.
aliasMap.put(mcLocale.getString("m.SkillArchery").toLowerCase(), "archery"); *
aliasMap.put(mcLocale.getString("m.SkillAxes").toLowerCase(), "axes"); * @return the list of parties.
aliasMap.put(mcLocale.getString("m.SkillExcavation").toLowerCase(), "excavation"); */
aliasMap.put(mcLocale.getString("m.SkillFishing").toLowerCase(), "fishing"); public ArrayList<String> getParties() {
aliasMap.put(mcLocale.getString("m.SkillHerbalism").toLowerCase(), "herbalism"); String location = "plugins/mcMMO/mcmmo.users";
aliasMap.put(mcLocale.getString("m.SkillMining").toLowerCase(), "mining"); ArrayList<String> parties = new ArrayList<String>();
aliasMap.put(mcLocale.getString("m.SkillRepair").toLowerCase(), "repair");
aliasMap.put(mcLocale.getString("m.SkillSwords").toLowerCase(), "swords"); try {
aliasMap.put(mcLocale.getString("m.SkillTaming").toLowerCase(), "taming");
aliasMap.put(mcLocale.getString("m.SkillUnarmed").toLowerCase(), "unarmed"); //Open the users file
aliasMap.put(mcLocale.getString("m.SkillWoodCutting").toLowerCase(), "woodcutting"); FileReader file = new FileReader(location);
BufferedReader in = new BufferedReader(file);
String line = "";
while((line = in.readLine()) != null) {
String[] character = line.split(":");
String theparty = null;
//Party
if (character.length > 3) {
theparty = character[3];
}
if (!parties.contains(theparty)) {
parties.add(theparty);
}
}
in.close();
}
catch (Exception e) {
log.log(Level.SEVERE, "Exception while reading " + location + " (Are you sure you formatted it correctly?)", e);
}
return parties;
}
/**
* Get the name of the party a player is in.
* </br>
* This function is designed for API usage.
*
* @param player The player to check the party name of
* @return the name of the player's party
*/
public static String getPartyName(Player player) {
PlayerProfile PP = Users.getProfile(player);
return PP.getParty();
}
/**
* Checks if a player is in a party.
* </br>
* This function is designed for API usage.
*
* @param player The player to check
* @return true if the player is in a party, false otherwise
*/
public static boolean inParty(Player player) {
PlayerProfile PP = Users.getProfile(player);
return PP.inParty();
}
/**
* Things to be run when the plugin is disabled.
*/
public void onDisable() {
//Make sure to save player information if the server shuts down
for(Player x : Bukkit.getOnlinePlayers()) {
Users.getProfile(x).save();
}
Bukkit.getServer().getScheduler().cancelTasks(this); //This removes our tasks
System.out.println("mcMMO was disabled."); //How informative!
}
private void registerCommands() {
//Register aliases with the aliasmap (used in the playercommandpreprocessevent to ugly alias them to actual commands)
//Skills commands
aliasMap.put(mcLocale.getString("m.SkillAcrobatics").toLowerCase(), "acrobatics");
aliasMap.put(mcLocale.getString("m.SkillArchery").toLowerCase(), "archery");
aliasMap.put(mcLocale.getString("m.SkillAxes").toLowerCase(), "axes");
aliasMap.put(mcLocale.getString("m.SkillExcavation").toLowerCase(), "excavation");
aliasMap.put(mcLocale.getString("m.SkillFishing").toLowerCase(), "fishing");
aliasMap.put(mcLocale.getString("m.SkillHerbalism").toLowerCase(), "herbalism");
aliasMap.put(mcLocale.getString("m.SkillMining").toLowerCase(), "mining");
aliasMap.put(mcLocale.getString("m.SkillRepair").toLowerCase(), "repair");
aliasMap.put(mcLocale.getString("m.SkillSwords").toLowerCase(), "swords");
aliasMap.put(mcLocale.getString("m.SkillTaming").toLowerCase(), "taming");
aliasMap.put(mcLocale.getString("m.SkillUnarmed").toLowerCase(), "unarmed");
aliasMap.put(mcLocale.getString("m.SkillWoodCutting").toLowerCase(), "woodcutting");
//Register commands //Register commands
//Skills commands //Skills commands
getCommand("acrobatics").setExecutor(new AcrobaticsCommand()); getCommand("acrobatics").setExecutor(new AcrobaticsCommand());
getCommand("archery").setExecutor(new ArcheryCommand()); getCommand("archery").setExecutor(new ArcheryCommand());
getCommand("axes").setExecutor(new AxesCommand()); getCommand("axes").setExecutor(new AxesCommand());
getCommand("excavation").setExecutor(new ExcavationCommand()); getCommand("excavation").setExecutor(new ExcavationCommand());
getCommand("fishing").setExecutor(new FishingCommand()); getCommand("fishing").setExecutor(new FishingCommand());
getCommand("herbalism").setExecutor(new HerbalismCommand()); getCommand("herbalism").setExecutor(new HerbalismCommand());
getCommand("mining").setExecutor(new MiningCommand()); getCommand("mining").setExecutor(new MiningCommand());
getCommand("repair").setExecutor(new RepairCommand()); getCommand("repair").setExecutor(new RepairCommand());
getCommand("swords").setExecutor(new SwordsCommand()); getCommand("swords").setExecutor(new SwordsCommand());
getCommand("taming").setExecutor(new TamingCommand()); getCommand("taming").setExecutor(new TamingCommand());
getCommand("unarmed").setExecutor(new UnarmedCommand()); getCommand("unarmed").setExecutor(new UnarmedCommand());
getCommand("woodcutting").setExecutor(new WoodcuttingCommand()); getCommand("woodcutting").setExecutor(new WoodcuttingCommand());
//Mc* commands //Mc* commands
if(LoadProperties.mcremoveEnable) getCommand("mcremove").setExecutor(new McremoveCommand()); if(LoadProperties.mcremoveEnable) getCommand("mcremove").setExecutor(new McremoveCommand());
if(LoadProperties.mcabilityEnable) getCommand("mcability").setExecutor(new McabilityCommand()); if(LoadProperties.mcabilityEnable) getCommand("mcability").setExecutor(new McabilityCommand());
if(LoadProperties.mccEnable) getCommand("mcc").setExecutor(new MccCommand()); if(LoadProperties.mccEnable) getCommand("mcc").setExecutor(new MccCommand());
if(LoadProperties.mcgodEnable) getCommand("mcgod").setExecutor(new McgodCommand()); if(LoadProperties.mcgodEnable) getCommand("mcgod").setExecutor(new McgodCommand());
if(LoadProperties.mcmmoEnable) getCommand("mcmmo").setExecutor(new McmmoCommand()); if(LoadProperties.mcmmoEnable) getCommand("mcmmo").setExecutor(new McmmoCommand());
if(LoadProperties.mcrefreshEnable) getCommand("mcrefresh").setExecutor(new McrefreshCommand(this)); if(LoadProperties.mcrefreshEnable) getCommand("mcrefresh").setExecutor(new McrefreshCommand(this));
if(LoadProperties.mctopEnable) getCommand("mctop").setExecutor(new MctopCommand()); if(LoadProperties.mctopEnable) getCommand("mctop").setExecutor(new MctopCommand());
//Party commands //Party commands
if(LoadProperties.acceptEnable) getCommand("accept").setExecutor(new AcceptCommand()); if(LoadProperties.acceptEnable) getCommand("accept").setExecutor(new AcceptCommand());
if(LoadProperties.aEnable) getCommand("a").setExecutor(new ACommand()); if(LoadProperties.aEnable) getCommand("a").setExecutor(new ACommand());
if(LoadProperties.inviteEnable) getCommand("invite").setExecutor(new InviteCommand(this)); if(LoadProperties.inviteEnable) getCommand("invite").setExecutor(new InviteCommand(this));
if(LoadProperties.partyEnable) getCommand("party").setExecutor(new PartyCommand()); if(LoadProperties.partyEnable) getCommand("party").setExecutor(new PartyCommand());
if(LoadProperties.pEnable) getCommand("p").setExecutor(new PCommand()); if(LoadProperties.pEnable) getCommand("p").setExecutor(new PCommand());
if(LoadProperties.ptpEnable) getCommand("ptp").setExecutor(new PtpCommand(this)); if(LoadProperties.ptpEnable) getCommand("ptp").setExecutor(new PtpCommand(this));
//Other commands //Other commands
if(LoadProperties.addxpEnable) getCommand("addxp").setExecutor(new AddxpCommand(this)); if(LoadProperties.addxpEnable) getCommand("addxp").setExecutor(new AddxpCommand(this));
if(LoadProperties.addlevelsEnable) getCommand("addlevels").setExecutor(new AddlevelsCommand(this)); if(LoadProperties.addlevelsEnable) getCommand("addlevels").setExecutor(new AddlevelsCommand(this));
if(LoadProperties.mmoeditEnable) getCommand("mmoedit").setExecutor(new MmoeditCommand(this)); if(LoadProperties.mmoeditEnable) getCommand("mmoedit").setExecutor(new MmoeditCommand(this));
getCommand("mmoupdate").setExecutor(new MmoupdateCommand()); getCommand("mmoupdate").setExecutor(new MmoupdateCommand());
if(LoadProperties.mcstatsEnable) getCommand("mcstats").setExecutor(new McstatsCommand()); if(LoadProperties.mcstatsEnable) getCommand("mcstats").setExecutor(new McstatsCommand());
if(LoadProperties.inspectEnable) getCommand("inspect").setExecutor(new InspectCommand(this)); if(LoadProperties.inspectEnable) getCommand("inspect").setExecutor(new InspectCommand(this));
if(LoadProperties.xprateEnable) getCommand("xprate").setExecutor(new XprateCommand()); if(LoadProperties.xprateEnable) getCommand("xprate").setExecutor(new XprateCommand());
//Spout commands //Spout commands
getCommand("mchud").setExecutor(new MchudCommand()); getCommand("mchud").setExecutor(new MchudCommand());
if(LoadProperties.xplockEnable) getCommand("xplock").setExecutor(new XplockCommand()); if(LoadProperties.xplockEnable) getCommand("xplock").setExecutor(new XplockCommand());
} }
/* /*
* It is important to always assume that you are updating from the lowest possible version. * It is important to always assume that you are updating from the lowest possible version.
* Thus, every block of updater code should be complete and self-contained; finishing all * Thus, every block of updater code should be complete and self-contained; finishing all
* SQL transactions and closing all file handlers, such that the next block of updater code * SQL transactions and closing all file handlers, such that the next block of updater code
* if called will handle updating as expected. * if called will handle updating as expected.
*/ */
public void updateFrom(int age) { public void updateFrom(int age) {
//No updater code needed, just update the version. //No updater code needed, just update the version.
if(age == -1) { if(age == -1) {
updateVersion(); updateVersion();
return; return;
} }
//Updater code from age 1 goes here //Updater code from age 1 goes here
if(age <= 1) { if(age <= 1) {
//Since age 1 is an example for now, we will just let it do nothing. //Since age 1 is an example for now, we will just let it do nothing.
} }
//If we are updating from age 1 but we need more to reach age 2, this will run too. //If we are updating from age 1 but we need more to reach age 2, this will run too.
if(age <= 2) { if(age <= 2) {
} }
updateVersion(); updateVersion();
} }
public void updateVersion() { public void updateVersion() {
try { try {
versionFile.createNewFile(); versionFile.createNewFile();
BufferedWriter vout = new BufferedWriter(new FileWriter(versionFile)); BufferedWriter vout = new BufferedWriter(new FileWriter(versionFile));
vout.write(this.getDescription().getVersion()); vout.write(this.getDescription().getVersion());
vout.close(); vout.close();
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
} catch (SecurityException ex) { } catch (SecurityException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
public String readVersion() { public String readVersion() {
byte[] buffer = new byte[(int) versionFile.length()]; byte[] buffer = new byte[(int) versionFile.length()];
BufferedInputStream f = null; BufferedInputStream f = null;
try { try {
f = new BufferedInputStream(new FileInputStream(versionFile)); f = new BufferedInputStream(new FileInputStream(versionFile));
f.read(buffer); f.read(buffer);
} catch (FileNotFoundException ex) { } catch (FileNotFoundException ex) {
ex.printStackTrace(); ex.printStackTrace();
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
} finally { } finally {
if (f != null) try { f.close(); } catch (IOException ignored) { } if (f != null) try { f.close(); } catch (IOException ignored) { }
} }
return new String(buffer); return new String(buffer);
} }
/* /*
* Boilerplate Custom Config Stuff * Boilerplate Custom Config Stuff
*/ */
private FileConfiguration treasuresConfig = null; private FileConfiguration treasuresConfig = null;
private File treasuresConfigFile = null; private File treasuresConfigFile = null;
public void reloadTreasuresConfig() { public void reloadTreasuresConfig() {
if (treasuresConfigFile == null) { if (treasuresConfigFile == null) {
treasuresConfigFile = new File(getDataFolder(), "treasures.yml"); treasuresConfigFile = new File(getDataFolder(), "treasures.yml");
} }
treasuresConfig = YamlConfiguration.loadConfiguration(treasuresConfigFile); treasuresConfig = YamlConfiguration.loadConfiguration(treasuresConfigFile);
// Look for defaults in the jar // Look for defaults in the jar
InputStream defConfigStream = getResource("treasures.yml"); InputStream defConfigStream = getResource("treasures.yml");
if (defConfigStream != null) { if (defConfigStream != null) {
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream); YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
treasuresConfig.setDefaults(defConfig); treasuresConfig.setDefaults(defConfig);
} }
} }
public FileConfiguration getTreasuresConfig() { public FileConfiguration getTreasuresConfig() {
if (treasuresConfig == null) { if (treasuresConfig == null) {
reloadTreasuresConfig(); reloadTreasuresConfig();
} }
return treasuresConfig; return treasuresConfig;
} }
public void saveTreasuresConfig() { public void saveTreasuresConfig() {
if (treasuresConfig == null || treasuresConfigFile == null) { if (treasuresConfig == null || treasuresConfigFile == null) {
return; return;
} }
try { try {
treasuresConfig.save(treasuresConfigFile); treasuresConfig.save(treasuresConfigFile);
} catch (IOException ex) { } catch (IOException ex) {
Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Could not save config to " + treasuresConfigFile, ex); Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Could not save config to " + treasuresConfigFile, ex);
} }
} }
} }

View File

@ -10,8 +10,8 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent; import org.bukkit.event.entity.ExplosionPrimeEvent;
import com.gmail.nossr50.BlockChecks;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.m;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
@ -89,7 +89,7 @@ public class BlastMining{
while(iterator.hasNext()) while(iterator.hasNext())
{ {
Block temp = iterator.next(); Block temp = iterator.next();
if(m.isOre(temp)) if(BlockChecks.isOre(temp.getType()))
ores.add(temp); ores.add(temp);
else else
debris.add(temp); debris.add(temp);