Merge branch 'master' of github.com:mcMMO-Dev/mcMMO

Conflicts:
	Changelog.txt
This commit is contained in:
nossr50 2012-03-08 17:07:34 -08:00
commit 1107e9f36a
12 changed files with 1337 additions and 911 deletions

View File

@ -14,9 +14,13 @@ Version 2.0.00-dev
+ Added bookshelves to list of blocks that don't trigger abilities. + Added bookshelves to list of blocks that don't trigger abilities.
= Fixed ClassCastException from Taming preventDamage checks = Fixed ClassCastException from Taming preventDamage checks
= Fixed issue with Blast Mining not seeing TNT for detonation due to snow = Fixed issue with Blast Mining not seeing TNT for detonation due to snow
! Changed mmoedit to save a profile when used (this will make mctop update) = Fixed issue with block interaction returning NPEs
= Fixed issue where every block broken had a mining check applied
= Fixed issue where every block broken had a herbalism check applied
= Fixed issue where blocks weren't being removed from the watchlist
! Changed Call of the Wild to activate on left-click rather than right-click ! Changed Call of the Wild to activate on left-click rather than right-click
! Changed Blast Mining to track based on Entity ID vs. Location ! Changed Blast Mining to track based on Entity ID vs. Location
! Changed mmoedit to save a profile when used (this will make mctop update)
Version 1.3.02 Version 1.3.02
+ Added in game guides for Mining, Excavation, and Acrobatics. Simply type /skillname ? to access them + Added in game guides for Mining, Excavation, and Acrobatics. Simply type /skillname ? to access them

View File

@ -0,0 +1,161 @@
package com.gmail.nossr50;
import org.bukkit.Material;
import org.bukkit.block.Block;
import com.gmail.nossr50.config.LoadProperties;
public class BlockChecks {
/**
* Checks to see if a block type awards XP.
*
* @param material The type of Block 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;
}
}
/**
* Check if a block should allow for the activation of abilities.
*
* @param material The type of Block to check
* @return true if the block should allow ability activation, false otherwise
*/
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;
default:
break;
}
if (Material.getMaterial(LoadProperties.anvilID).equals(material)) {
return false;
}
else {
return true;
}
}
/**
* Check if a block type is an ore.
*
* @param material The type of Block to check
* @return true if the Block is an ore, false otherwise
*/
public static boolean isOre(Material material) {
switch (material) {
case COAL_ORE:
case DIAMOND_ORE:
case GLOWING_REDSTONE_ORE:
case GOLD_ORE:
case IRON_ORE:
case LAPIS_ORE:
case REDSTONE_ORE:
return true;
default:
return false;
}
}
/**
* Adds the block the the appropriate watchlist.
*
* @param material the type of Block to watch
* @param block the Block to watch
* @param plugin mcMMO plugin instance
*/
public static void watchBlock(Material material, Block block, mcMMO plugin) {
boolean addToChangeQueue = true;
switch (material) {
case CACTUS:
case GLOWING_REDSTONE_ORE:
case JACK_O_LANTERN:
case LOG:
case PUMPKIN:
case REDSTONE_ORE:
case SUGAR_CANE_BLOCK:
case VINE:
addToChangeQueue = false; //We don't want these added to changeQueue - these use their data
plugin.misc.blockWatchList.add(block);
break;
case BROWN_MUSHROOM:
case RED_MUSHROOM:
case RED_ROSE:
case YELLOW_FLOWER:
case WATER_LILY:
addToChangeQueue = false; //We don't want these added to chaneQueue - they're already being added to the fast queue
plugin.fastChangeQueue.push(block);
break;
default:
break;
}
if(addToChangeQueue)
plugin.changeQueue.push(block);
}
}

View File

@ -99,16 +99,16 @@ public class Combat {
} }
else if (itemInHand.getType().equals(Material.BONE) && mcPermissions.getInstance().taming(attacker) && targetType.equals(EntityType.WOLF)) { else if (itemInHand.getType().equals(Material.BONE) && mcPermissions.getInstance().taming(attacker) && targetType.equals(EntityType.WOLF)) {
Wolf wolf = (Wolf) target; Wolf wolf = (Wolf) target;
String message = "Combat.BeastLore" + " "; String message = mcLocale.getString("Combat.BeastLore") + " ";
int health = wolf.getHealth(); int health = wolf.getHealth();
event.setCancelled(true); event.setCancelled(true);
if (wolf.isTamed()) { if (wolf.isTamed()) {
message.concat(mcLocale.getString("Combat.BeastLoreOwner", new Object[] {Taming.getOwnerName(wolf)}) + " "); message = message.concat(mcLocale.getString("Combat.BeastLoreOwner", new Object[] {Taming.getOwnerName(wolf)}) + " ");
message.concat(mcLocale.getString("Combat.BeastLoreHealthWolfTamed", new Object[] {health})); message = message.concat(mcLocale.getString("Combat.BeastLoreHealthWolfTamed", new Object[] {health}));
} }
else { else {
message.concat(mcLocale.getString("Combat.BeastLoreHealthWolf", new Object[] {health})); message = message.concat(mcLocale.getString("Combat.BeastLoreHealthWolf", new Object[] {health}));
} }
attacker.sendMessage(message); attacker.sendMessage(message);

View File

@ -1,88 +1,94 @@
package com.gmail.nossr50; package com.gmail.nossr50;
import java.io.*; import java.io.*;
import java.util.Properties;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.HashMap; import java.util.HashMap;
import org.bukkit.entity.*; 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; private static volatile Users instance;
protected static final Logger log = Logger.getLogger("Minecraft"); protected static final Logger log = Logger.getLogger("Minecraft");
String location = "plugins/mcMMO/FlatFileStuff/mcmmo.users"; String location = "plugins/mcMMO/FlatFileStuff/mcmmo.users";
String directory = "plugins/mcMMO/FlatFileStuff/"; String directory = "plugins/mcMMO/FlatFileStuff/";
String directoryb = "plugins/mcMMO/FlatFileStuff/Leaderboards/"; String directoryb = "plugins/mcMMO/FlatFileStuff/Leaderboards/";
//public static ArrayList<PlayerProfile> players;
public static HashMap<Player, PlayerProfile> players = new HashMap<Player, PlayerProfile>(); public static HashMap<Player, PlayerProfile> players = new HashMap<Player, PlayerProfile>();
private Properties properties = new Properties();
//To load /**
public void load() throws IOException { * Load users.
properties.load(new FileInputStream(location)); */
} public void loadUsers() {
//To save
public void save()
{
try
{
properties.store(new FileOutputStream(location), null);
}catch(IOException ex) {
}
}
public 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);
if(!theDir.exists())
{ if (!theDir.exists()) {
try { try {
FileWriter writer = new FileWriter(theDir); FileWriter writer = new FileWriter(theDir);
writer.close(); writer.close();
} catch (IOException e) { }
// TODO Auto-generated catch block catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
/**
public static void addUser(Player player) * Add a new user.
{ *
if(!players.containsKey(player)) * @param player The player to create a user record for
*/
public static void addUser(Player player) {
if (!players.containsKey(player)) {
players.put(player, new PlayerProfile(player.getName())); players.put(player, new PlayerProfile(player.getName()));
} }
public static void clearUsers() }
{
/**
* Clear all users.
*/
public static void clearUsers() {
players.clear(); players.clear();
} }
/**
* Get all PlayerProfiles.
*
* @return a HashMap containing the PlayerProfile of everyone in the database
*/
public static HashMap<Player, PlayerProfile> getProfiles() { public static HashMap<Player, PlayerProfile> getProfiles() {
return players; return players;
} }
public static void removeUser(Player player) /**
{ * Remove a user from the database.
*
* @param player The player to remove
*/
public static void removeUser(Player player) {
//Only remove PlayerProfile if user is offline and we have it in memory //Only remove PlayerProfile if user is offline and we have it in memory
if(!player.isOnline() && players.containsKey(player)) if (!player.isOnline() && players.containsKey(player)) {
{
players.get(player).save(); players.get(player).save();
players.remove(player); players.remove(player);
} }
} }
public static void removeUserByName(String playerName) /**
{ * Remove a user from the DB by name.
*
* @param playerName The name of the player to remove
*/
public static void removeUserByName(String playerName) {
Player target = null; Player target = null;
for(Player player : players.keySet())
{ for (Player player : players.keySet()) {
PlayerProfile PP = players.get(player); PlayerProfile PP = players.get(player);
if(PP.getPlayerName().equals(playerName))
{ if (PP.getPlayerName().equals(playerName)) {
target = player; target = player;
} }
} }
@ -90,25 +96,41 @@ public class Users {
players.remove(target); players.remove(target);
} }
/**
* Get the profile of an online player.
*
* @param player The player whose profile to retrieve
* @return the player's profile
*/
public static PlayerProfile getProfile(Player player) { public static PlayerProfile getProfile(Player player) {
if(players.get(player) != null) if(players.get(player) != null) {
return players.get(player); return players.get(player);
else }
{ else {
players.put(player, new PlayerProfile(player.getName())); players.put(player, new PlayerProfile(player.getName()));
return players.get(player); return players.get(player);
} }
} }
/**
* Get the profile of an offline player.
*
* @param playerName Name of the player whose profile to retrieve
* @return the player's profile
*/
public static PlayerProfile getOfflineProfile(String playerName) { public static PlayerProfile getOfflineProfile(String playerName) {
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() { public static Users getInstance() {
if (instance == null) { if (instance == null) {
instance = new Users(); instance = new Users();
} }
return instance; return instance;
} }
} }

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;
@ -30,151 +31,142 @@ import com.gmail.nossr50.locale.mcLocale;
import com.gmail.nossr50.skills.*; import com.gmail.nossr50.skills.*;
import com.gmail.nossr50.events.FakeBlockBreakEvent; import com.gmail.nossr50.events.FakeBlockBreakEvent;
public class mcBlockListener implements Listener public class mcBlockListener implements Listener {
{
private final mcMMO plugin; private final mcMMO plugin;
public mcBlockListener(final mcMMO plugin) public mcBlockListener(final mcMMO plugin) {
{
this.plugin = plugin; this.plugin = plugin;
} }
/**
* Monitor BlockPlace events.
*
* @param event The event to monitor
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) public void onBlockPlace(BlockPlaceEvent event) {
{
//Setup some basic variables
Block block; Block block;
Player player = event.getPlayer(); Player player = event.getPlayer();
//When blocks are placed on snow this event reports the wrong block. //When blocks are placed on snow this event reports the wrong block.
if (event.getBlockReplacedState() != null && event.getBlockReplacedState().getType().equals(Material.SNOW)) if (event.getBlockReplacedState() != null && event.getBlockReplacedState().getType().equals(Material.SNOW)) {
block = event.getBlockAgainst(); block = event.getBlockAgainst();
else }
else {
block = event.getBlock(); block = event.getBlock();
}
int id = block.getTypeId(); int id = block.getTypeId();
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)) {
{ BlockChecks.watchBlock(mat, block, plugin);
//Only needed for blocks that use their block data (wood, pumpkins, etc.)
boolean shouldBeChanged = true;
switch(mat)
{
case CACTUS:
case GLOWING_REDSTONE_ORE:
case JACK_O_LANTERN:
case LOG:
case PUMPKIN:
case REDSTONE_ORE:
case SUGAR_CANE_BLOCK:
case VINE:
shouldBeChanged = false; //We don't want these added to changeQueue
plugin.misc.blockWatchList.add(block);
break;
case BROWN_MUSHROOM:
case RED_MUSHROOM:
case RED_ROSE:
case YELLOW_FLOWER:
case WATER_LILY:
plugin.fastChangeQueue.push(block);
break;
} }
if(shouldBeChanged) if (id == LoadProperties.anvilID && LoadProperties.anvilmessages) {
plugin.changeQueue.push(block);
}
if(id == LoadProperties.anvilID && LoadProperties.anvilmessages)
{
PlayerProfile PP = Users.getProfile(player); PlayerProfile PP = Users.getProfile(player);
if(!PP.getPlacedAnvil())
{ if (!PP.getPlacedAnvil()) {
if(LoadProperties.spoutEnabled) if (LoadProperties.spoutEnabled) {
{
SpoutPlayer sPlayer = SpoutManager.getPlayer(player); SpoutPlayer sPlayer = SpoutManager.getPlayer(player);
if(sPlayer.isSpoutCraftEnabled())
sPlayer.sendNotification("[mcMMO] Anvil Placed", "Right click to repair!", Material.IRON_BLOCK); if (sPlayer.isSpoutCraftEnabled()) {
sPlayer.sendNotification("[mcMMO] Anvil Placed", "Right click to repair!", Material.getMaterial(id));
}
}
else {
event.getPlayer().sendMessage(mcLocale.getString("mcBlockListener.PlacedAnvil"));
} }
else
event.getPlayer().sendMessage(mcLocale.getString("mcBlockListener.PlacedAnvil")); //$NON-NLS-1$
PP.togglePlacedAnvil(); PP.togglePlacedAnvil();
} }
} }
} }
/**
* Monitor BlockBreak events.
*
* @param event The event to monitor
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) public void onBlockBreak(BlockBreakEvent event) {
{
Player player = event.getPlayer(); Player player = event.getPlayer();
PlayerProfile PP = Users.getProfile(player); PlayerProfile PP = Users.getProfile(player);
Block block = event.getBlock(); Block block = event.getBlock();
int id = block.getTypeId(); Material mat = block.getType();
ItemStack inhand = player.getItemInHand(); ItemStack inhand = player.getItemInHand();
if(event instanceof FakeBlockBreakEvent) if(event instanceof FakeBlockBreakEvent) {
return; return;
}
/* /*
* HERBALISM * HERBALISM
*/ */
//Green Terra //Green Terra
if(PP.getHoePreparationMode() && mcPermissions.getInstance().herbalismAbility(player) && ((id == 59 && block.getData() == (byte) 0x07) || Herbalism.canBeGreenTerra(block))) if (PP.getHoePreparationMode() && mcPermissions.getInstance().herbalismAbility(player) && ((mat.equals(Material.CROPS) && block.getData() == (byte) 0x7) || Herbalism.canBeGreenTerra(block))) {
Skills.abilityCheck(player, SkillType.HERBALISM); Skills.abilityCheck(player, SkillType.HERBALISM);
}
//Wheat && Triple drops //Wheat && Triple drops
if(PP.getGreenTerraMode() && Herbalism.canBeGreenTerra(block)) if (PP.getGreenTerraMode() && Herbalism.canBeGreenTerra(block)) {
Herbalism.herbalismProcCheck(block, player, event, plugin); Herbalism.herbalismProcCheck(block, player, event, plugin);
}
if(mcPermissions.getInstance().herbalism(player) && block.getData() != (byte) 5) if (mcPermissions.getInstance().herbalism(player) && block.getData() != (byte) 0x5 && Herbalism.canBeGreenTerra(block)) {
Herbalism.herbalismProcCheck(block, player, event, plugin); Herbalism.herbalismProcCheck(block, player, event, plugin);
}
/* /*
* MINING * MINING
*/ */
if(mcPermissions.getInstance().mining(player))
{ if (mcPermissions.getInstance().mining(player) && Mining.canBeSuperBroken(block)) {
if(LoadProperties.miningrequirespickaxe && ItemChecks.isMiningPick(inhand)) if (LoadProperties.miningrequirespickaxe && ItemChecks.isMiningPick(inhand)) {
Mining.miningBlockCheck(player, block, plugin); Mining.miningBlockCheck(player, block, plugin);
else if(!LoadProperties.miningrequirespickaxe) }
else if (!LoadProperties.miningrequirespickaxe) {
Mining.miningBlockCheck(player, block, plugin); Mining.miningBlockCheck(player, block, plugin);
} }
}
/* /*
* WOOD CUTTING * WOOD CUTTING
*/ */
if(mcPermissions.getInstance().woodcutting(player) && id == 17) if(mcPermissions.getInstance().woodcutting(player) && mat.equals(Material.LOG)) {
{ if (LoadProperties.woodcuttingrequiresaxe && ItemChecks.isAxe(inhand)) {
if(LoadProperties.woodcuttingrequiresaxe && ItemChecks.isAxe(inhand))
WoodCutting.woodcuttingBlockCheck(player, block, plugin); WoodCutting.woodcuttingBlockCheck(player, block, plugin);
else if(!LoadProperties.woodcuttingrequiresaxe) }
else if (!LoadProperties.woodcuttingrequiresaxe) {
WoodCutting.woodcuttingBlockCheck(player, block, plugin); WoodCutting.woodcuttingBlockCheck(player, block, plugin);
}
if(PP.getTreeFellerMode()) if (PP.getTreeFellerMode()) {
WoodCutting.treeFeller(event, plugin); WoodCutting.treeFeller(event, plugin);
} }
}
/* /*
* EXCAVATION * EXCAVATION
*/ */
if(Excavation.canBeGigaDrillBroken(block) && mcPermissions.getInstance().excavation(player) && block.getData() != (byte) 5)
{ if (Excavation.canBeGigaDrillBroken(block) && mcPermissions.getInstance().excavation(player) && block.getData() != (byte) 0x5) {
if(LoadProperties.excavationRequiresShovel && ItemChecks.isShovel(inhand)) if(LoadProperties.excavationRequiresShovel && ItemChecks.isShovel(inhand)) {
Excavation.excavationProcCheck(block, player); Excavation.excavationProcCheck(block, player);
else if(!LoadProperties.excavationRequiresShovel) }
else if(!LoadProperties.excavationRequiresShovel) {
Excavation.excavationProcCheck(block, player); Excavation.excavationProcCheck(block, player);
} }
}
//Change the byte back when broken //Change the byte back when broken
if(block.getData() == 5 && m.shouldBeWatched(block.getType())) if (block.getData() == (byte) 0x5 && BlockChecks.shouldBeWatched(mat)) {
{ block.setData((byte) 0x0);
block.setData((byte) 0); }
if(plugin.misc.blockWatchList.contains(block)) else if(plugin.misc.blockWatchList.contains(block)) {
plugin.misc.blockWatchList.remove(block); plugin.misc.blockWatchList.remove(block);
} }
} }
@ -192,7 +184,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 +292,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

@ -60,8 +60,10 @@ public class mcEntityListener implements Listener
{ {
if(!defender.getWorld().getPVP()) if(!defender.getWorld().getPVP())
return; return;
if(Party.getInstance().inSameParty((Player)defender, (Player)attacker)) if(Party.getInstance().inSameParty((Player)defender, (Player)attacker)) {
event.setCancelled(true); event.setCancelled(true);
return;
}
} }
//Make sure defender is not invincible //Make sure defender is not invincible
@ -91,8 +93,10 @@ public class mcEntityListener implements Listener
*/ */
Player player = (Player) entity; Player player = (Player) entity;
PlayerProfile PP = Users.getProfile(player); PlayerProfile PP = Users.getProfile(player);
if(PP.getGodMode()) if(PP.getGodMode()) {
event.setCancelled(true); event.setCancelled(true);
return;
}
if(!m.isInvincible(player, event)) if(!m.isInvincible(player, event))
{ {

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;
@ -156,7 +157,13 @@ public class mcPlayerListener implements Listener
Action action = event.getAction(); Action action = event.getAction();
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
ItemStack is = player.getItemInHand(); ItemStack is = player.getItemInHand();
Material mat = block.getType(); Material mat;
if (block == null) {
mat = Material.AIR;
}
else {
mat = block.getType();
}
/* /*
* Ability checks * Ability checks
@ -171,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);
@ -241,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)
return true;
return false;
}
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;
}
if(Material.getMaterial(LoadProperties.anvilID).equals(material))
return false;
if (dist < maxDistance * maxDistance) {
return true; return true;
} }
else {
return false;
}
}
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);
}
catch(NumberFormatException nFE)
{
return false;
}
return true; return true;
} }
catch (NumberFormatException nFE) {
public static void mcDropItems(Location location, ItemStack is, int quantity) return false;
{ }
for(int i = 0; i < quantity; i++)
mcDropItem(location, is);
} }
public static void mcRandomDropItem(Location location, ItemStack is, int chance) /**
{ * Drop items at a given location.
if(Math.random() * 100 < chance) *
* @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 mcRandomDropItems(Location location, ItemStack is, int chance, int quantity) /**
{ * Randomly drop an item 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
*/
public static void mcRandomDropItem(Location location, ItemStack is, double chance) {
if (Math.random() * 100 < chance) {
mcDropItem(location, is);
}
}
/**
* Randomly drop items at a given location.
*
* @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;
if (event.isCancelled()) {
return;
}
else {
location.getWorld().dropItemNaturally(location, itemStack); location.getWorld().dropItemNaturally(location, itemStack);
} }
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() /**
{ * Convert FlatFile data to MySQL data.
if(!LoadProperties.useMySQL) */
public static void convertToMySQL() {
if (!LoadProperties.useMySQL) {
return; return;
}
Bukkit.getScheduler().scheduleAsyncDelayedTask(Bukkit.getServer().getPluginManager().getPlugin("mcMMO"), new Runnable(){ 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,13 +45,11 @@ 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 String maindirectory = "plugins" + File.separator + "mcMMO";
File file = new File(maindirectory + File.separator + "config.yml"); public static File file = new File(maindirectory + File.separator + "config.yml");
static File versionFile = new File(maindirectory + File.separator + "VERSION"); public static File versionFile = new File(maindirectory + File.separator + "VERSION");
public static final Logger log = Logger.getLogger("Minecraft"); public static final Logger log = Logger.getLogger("Minecraft");
private final mcPlayerListener playerListener = new mcPlayerListener(this); private final mcPlayerListener playerListener = new mcPlayerListener(this);
@ -66,7 +63,7 @@ public class mcMMO extends JavaPlugin
private Runnable mcMMO_Timer = new mcTimer(this); //BLEED AND REGENERATION private Runnable mcMMO_Timer = new mcTimer(this); //BLEED AND REGENERATION
private Runnable mcMMO_SaveTimer = new mcSaveTimer(this); //Periodic saving of Player Data private Runnable mcMMO_SaveTimer = new mcSaveTimer(this); //Periodic saving of Player Data
private Runnable ChangeDataValueTimer = new ChangeDataValueTimer(changeQueue); //R2 block place workaround private Runnable ChangeDataValueTimer = new ChangeDataValueTimer(changeQueue); //R2 block place workaround
private Runnable FastChangeDataValueTimer = new ChangeDataValueTimer(fastChangeQueue); private Runnable FastChangeDataValueTimer = new ChangeDataValueTimer(fastChangeQueue); //R2 block place workaround for instant-break stuff
//Alias - Command //Alias - Command
public HashMap<String, String> aliasMap = new HashMap<String, String>(); public HashMap<String, String> aliasMap = new HashMap<String, String>();
@ -81,26 +78,31 @@ public class mcMMO extends JavaPlugin
//Jar stuff //Jar stuff
public static File mcmmo; public static File mcmmo;
public void onEnable() /**
{ * Things to be run when the plugin is enabled.
*/
public void onEnable() {
final Plugin thisPlugin = this; final Plugin thisPlugin = this;
mcmmo = this.getFile(); mcmmo = this.getFile();
new File(maindirectory).mkdir(); new File(maindirectory).mkdir();
if(!versionFile.exists()) if (!versionFile.exists()) {
{
updateVersion(); updateVersion();
} else }
{ else {
String vnum = readVersion(); String vnum = readVersion();
//This will be changed to whatever version preceded when we actually need updater code. //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. //Version 1.0.48 is the first to implement this, no checking before that version can be done.
if (vnum.equalsIgnoreCase("1.0.48")) { if (vnum.equalsIgnoreCase("1.0.48")) {
updateFrom(1); updateFrom(1);
} }
//Just add in more else if blocks for versions that need updater code. Increment the updateFrom age int as we do so. //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 //Catch all for versions not matching and no specific code being needed
else if(!vnum.equalsIgnoreCase(this.getDescription().getVersion())) updateFrom(-1); else if (!vnum.equalsIgnoreCase(this.getDescription().getVersion())) {
updateFrom(-1);
}
} }
this.config = new LoadProperties(this); this.config = new LoadProperties(this);
@ -112,18 +114,18 @@ public class mcMMO extends JavaPlugin
Party.getInstance().loadParties(); Party.getInstance().loadParties();
new Party(this); new Party(this);
if(!LoadProperties.useMySQL) if (!LoadProperties.useMySQL) {
Users.getInstance().loadUsers(); //Load Users file Users.getInstance().loadUsers();
/* }
* REGISTER EVENTS
*/
PluginManager pm = getServer().getPluginManager(); PluginManager pm = getServer().getPluginManager();
if(pm.getPlugin("Spout") != null) if (pm.getPlugin("Spout") != null) {
LoadProperties.spoutEnabled = true; LoadProperties.spoutEnabled = true;
else }
else {
LoadProperties.spoutEnabled = false; LoadProperties.spoutEnabled = false;
}
//Register events //Register events
pm.registerEvents(playerListener, this); pm.registerEvents(playerListener, this);
@ -132,20 +134,27 @@ public class mcMMO extends JavaPlugin
PluginDescriptionFile pdfFile = this.getDescription(); PluginDescriptionFile pdfFile = this.getDescription();
if(LoadProperties.useMySQL) //Setup the leaderboards
{ if (LoadProperties.useMySQL) {
database = new Database(this); database = new Database(this);
database.createStructure(); database.createStructure();
} else }
Leaderboard.makeLeaderboards(); //Make the leaderboards else {
Leaderboard.makeLeaderboards();
}
for (Player player : getServer().getOnlinePlayers()) {
Users.addUser(player); //In case of reload add all users back into PlayerProfile
}
for(Player player : getServer().getOnlinePlayers()){Users.addUser(player);} //In case of reload add all users back into PlayerProfile
System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" ); System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
//Periodic save timer (Saves every 10 minutes) //Periodic save timer (Saves every 10 minutes)
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, mcMMO_SaveTimer, 0, LoadProperties.saveInterval * 1200); Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, mcMMO_SaveTimer, 0, LoadProperties.saveInterval * 1200);
//Bleed & Regen timer (Runs every 20 seconds)
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, mcMMO_Timer, 0, 20); Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, mcMMO_Timer, 0, 20);
//R2+ block place fix //R2+ block place fix
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, ChangeDataValueTimer, 0, 10); Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, ChangeDataValueTimer, 0, 10);
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, FastChangeDataValueTimer, 0, 1); Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, FastChangeDataValueTimer, 0, 1);
@ -153,8 +162,7 @@ public class mcMMO extends JavaPlugin
registerCommands(); registerCommands();
//Spout Stuff //Spout Stuff
if(LoadProperties.spoutEnabled) if (LoadProperties.spoutEnabled) {
{
SpoutStuff.setupSpoutConfigs(); SpoutStuff.setupSpoutConfigs();
SpoutStuff.registerCustomEvent(); SpoutStuff.registerCustomEvent();
SpoutStuff.extractFiles(); //Extract source materials SpoutStuff.extractFiles(); //Extract source materials
@ -173,87 +181,151 @@ public class mcMMO extends JavaPlugin
// 'this' in this context is the Plugin object // 'this' in this context is the Plugin object
metrics.beginMeasuringPlugin(thisPlugin); metrics.beginMeasuringPlugin(thisPlugin);
} catch (IOException e) { }
// Failed to submit the stats :-( catch (IOException e) {
System.out.println("Failed to submit stats.");
} }
} }
}).start(); }).start();
} }
} }
public PlayerProfile getPlayerProfile(Player player) /**
{ * Get profile of the player.
* </br>
* This function is designed for API usage.
*
* @param player Player whose profile to get
* @return the PlayerProfile object
*/
public PlayerProfile getPlayerProfile(Player player) {
return Users.getProfile(player); return Users.getProfile(player);
} }
public void checkXp(Player player, SkillType skillType) /**
{ * Check the XP of a player.
if(skillType == SkillType.ALL) * </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); Skills.XpCheckAll(player);
else }
else {
Skills.XpCheckSkill(skillType, player); Skills.XpCheckSkill(skillType, player);
} }
}
public boolean inSameParty(Player playera, Player playerb) /**
{ * 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).inParty() && Users.getProfile(playerb).inParty()) {
if (Users.getProfile(playera).getParty().equals(Users.getProfile(playerb).getParty())) { if (Users.getProfile(playera).getParty().equals(Users.getProfile(playerb).getParty())) {
return true; return true;
} else {
return false;
} }
} else { else {
return false; return false;
} }
} }
else {
return false;
}
}
/**
* Get a list of all current party names.
* </br>
* This function is designed for API usage.
*
* @return the list of parties.
*/
public ArrayList<String> getParties() { public ArrayList<String> getParties() {
String location = "plugins/mcMMO/mcmmo.users"; String location = "plugins/mcMMO/mcmmo.users";
ArrayList<String> parties = new ArrayList<String>(); ArrayList<String> parties = new ArrayList<String>();
try { try {
//Open the users file //Open the users 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 = "";
while((line = in.readLine()) != null)
{ while((line = in.readLine()) != null) {
String[] character = line.split(":"); String[] character = line.split(":");
String theparty = null; String theparty = null;
//Party //Party
if(character.length > 3) if (character.length > 3) {
theparty = character[3]; theparty = character[3];
if(!parties.contains(theparty)) }
if (!parties.contains(theparty)) {
parties.add(theparty); parties.add(theparty);
} }
}
in.close(); in.close();
} catch (Exception e) { }
log.log(Level.SEVERE, "Exception while reading " catch (Exception e) {
+ location + " (Are you sure you formatted it correctly?)", e); log.log(Level.SEVERE, "Exception while reading " + location + " (Are you sure you formatted it correctly?)", e);
} }
return parties; 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) { public static String getPartyName(Player player) {
PlayerProfile PP = Users.getProfile(player); PlayerProfile PP = Users.getProfile(player);
return PP.getParty(); 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) { public static boolean inParty(Player player) {
PlayerProfile PP = Users.getProfile(player); PlayerProfile PP = Users.getProfile(player);
return PP.inParty(); return PP.inParty();
} }
public void onDisable() /**
{ * Things to be run when the plugin is disabled.
*/
public void onDisable() {
//Make sure to save player information if the server shuts down //Make sure to save player information if the server shuts down
for(Player x : Bukkit.getServer().getOnlinePlayers()) for (Player x : Bukkit.getOnlinePlayers()) {
{
Users.getProfile(x).save(); Users.getProfile(x).save();
} }
Bukkit.getServer().getScheduler().cancelTasks(this); //This removes our tasks Bukkit.getServer().getScheduler().cancelTasks(this); //This removes our tasks
System.out.println("mcMMO was disabled."); //How informative! System.out.println("mcMMO was disabled."); //How informative!
} }
/**
* Register the commands.
*/
private void registerCommands() { private void registerCommands() {
//Register aliases with the aliasmap (used in the playercommandpreprocessevent to ugly alias them to actual commands) //Register aliases with the aliasmap (used in the playercommandpreprocessevent to ugly alias them to actual commands)
//Skills commands //Skills commands
aliasMap.put(mcLocale.getString("m.SkillAcrobatics").toLowerCase(), "acrobatics"); aliasMap.put(mcLocale.getString("m.SkillAcrobatics").toLowerCase(), "acrobatics");
@ -269,7 +341,6 @@ public class mcMMO extends JavaPlugin
aliasMap.put(mcLocale.getString("m.SkillUnarmed").toLowerCase(), "unarmed"); aliasMap.put(mcLocale.getString("m.SkillUnarmed").toLowerCase(), "unarmed");
aliasMap.put(mcLocale.getString("m.SkillWoodCutting").toLowerCase(), "woodcutting"); 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());
@ -285,55 +356,118 @@ public class mcMMO extends JavaPlugin
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) {
if(LoadProperties.mcabilityEnable) getCommand("mcability").setExecutor(new McabilityCommand()); getCommand("mcremove").setExecutor(new McremoveCommand());
if(LoadProperties.mccEnable) getCommand("mcc").setExecutor(new MccCommand());
if(LoadProperties.mcgodEnable) getCommand("mcgod").setExecutor(new McgodCommand());
if(LoadProperties.mcmmoEnable) getCommand("mcmmo").setExecutor(new McmmoCommand());
if(LoadProperties.mcrefreshEnable) getCommand("mcrefresh").setExecutor(new McrefreshCommand(this));
if(LoadProperties.mctopEnable) getCommand("mctop").setExecutor(new MctopCommand());
//Party commands
if(LoadProperties.acceptEnable) getCommand("accept").setExecutor(new AcceptCommand());
if(LoadProperties.aEnable) getCommand("a").setExecutor(new ACommand());
if(LoadProperties.inviteEnable) getCommand("invite").setExecutor(new InviteCommand(this));
if(LoadProperties.partyEnable) getCommand("party").setExecutor(new PartyCommand());
if(LoadProperties.pEnable) getCommand("p").setExecutor(new PCommand());
if(LoadProperties.ptpEnable) getCommand("ptp").setExecutor(new PtpCommand(this));
//Other commands
if(LoadProperties.addxpEnable) getCommand("addxp").setExecutor(new AddxpCommand(this));
if(LoadProperties.addlevelsEnable) getCommand("addlevels").setExecutor(new AddlevelsCommand(this));
if(LoadProperties.mmoeditEnable) getCommand("mmoedit").setExecutor(new MmoeditCommand(this));
getCommand("mmoupdate").setExecutor(new MmoupdateCommand());
if(LoadProperties.mcstatsEnable) getCommand("mcstats").setExecutor(new McstatsCommand());
if(LoadProperties.inspectEnable) getCommand("inspect").setExecutor(new InspectCommand(this));
if(LoadProperties.xprateEnable) getCommand("xprate").setExecutor(new XprateCommand());
//Spout commands
getCommand("mchud").setExecutor(new MchudCommand());
if(LoadProperties.xplockEnable) getCommand("xplock").setExecutor(new XplockCommand());
} }
/* if (LoadProperties.mcabilityEnable) {
getCommand("mcability").setExecutor(new McabilityCommand());
}
if (LoadProperties.mccEnable) {
getCommand("mcc").setExecutor(new MccCommand());
}
if (LoadProperties.mcgodEnable) {
getCommand("mcgod").setExecutor(new McgodCommand());
}
if (LoadProperties.mcmmoEnable) {
getCommand("mcmmo").setExecutor(new McmmoCommand());
}
if (LoadProperties.mcrefreshEnable) {
getCommand("mcrefresh").setExecutor(new McrefreshCommand(this));
}
if (LoadProperties.mctopEnable) {
getCommand("mctop").setExecutor(new MctopCommand());
}
if (LoadProperties.mcstatsEnable) {
getCommand("mcstats").setExecutor(new McstatsCommand());
}
//Party commands
if (LoadProperties.acceptEnable) {
getCommand("accept").setExecutor(new AcceptCommand());
}
if (LoadProperties.aEnable) {
getCommand("a").setExecutor(new ACommand());
}
if (LoadProperties.inviteEnable) {
getCommand("invite").setExecutor(new InviteCommand(this));
}
if (LoadProperties.partyEnable) {
getCommand("party").setExecutor(new PartyCommand());
}
if (LoadProperties.pEnable) {
getCommand("p").setExecutor(new PCommand());
}
if (LoadProperties.ptpEnable) {
getCommand("ptp").setExecutor(new PtpCommand(this));
}
//Other commands
if (LoadProperties.addxpEnable) {
getCommand("addxp").setExecutor(new AddxpCommand(this));
}
if (LoadProperties.addlevelsEnable) {
getCommand("addlevels").setExecutor(new AddlevelsCommand(this));
}
if (LoadProperties.mmoeditEnable) {
getCommand("mmoedit").setExecutor(new MmoeditCommand(this));
}
if (LoadProperties.inspectEnable) {
getCommand("inspect").setExecutor(new InspectCommand(this));
}
if (LoadProperties.xprateEnable) {
getCommand("xprate").setExecutor(new XprateCommand());
}
getCommand("mmoupdate").setExecutor(new MmoupdateCommand());
//Spout commands
if (LoadProperties.xplockEnable) {
getCommand("xplock").setExecutor(new XplockCommand());
}
getCommand("mchud").setExecutor(new MchudCommand());
}
/**
* Update mcMMO from a given version
* </p>
* 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.
*
* @param age Specifies which updater code to run
*/ */
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) {
@ -341,33 +475,51 @@ public class mcMMO extends JavaPlugin
updateVersion(); updateVersion();
} }
/**
* Update the version file.
*/
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();
} }
} }
/**
* Get the current mcMMO version.
*
* @return a String representing the current mcMMO version
*/
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) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (f != null) try { f.close(); } catch (IOException ignored) { }
} }
catch (FileNotFoundException ex) {
ex.printStackTrace();
}
catch (IOException ex) {
ex.printStackTrace();
}
finally {
if (f != null) {
try {
f.close();
}
catch (IOException ignored) {}
}
}
return new String(buffer); return new String(buffer);
} }
@ -378,35 +530,49 @@ public class mcMMO extends JavaPlugin
private FileConfiguration treasuresConfig = null; private FileConfiguration treasuresConfig = null;
private File treasuresConfigFile = null; private File treasuresConfigFile = null;
/**
* Reload the Treasures.yml file.
*/
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);
// Look for defaults in the jar treasuresConfig = YamlConfiguration.loadConfiguration(treasuresConfigFile);
InputStream defConfigStream = getResource("treasures.yml"); InputStream defConfigStream = getResource("treasures.yml"); // Look for defaults in the jar
if (defConfigStream != null) { if (defConfigStream != null) {
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream); YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
treasuresConfig.setDefaults(defConfig); treasuresConfig.setDefaults(defConfig);
} }
} }
/**
* Get the Treasures config information.
*
* @return the configuration object for treasures.yml
*/
public FileConfiguration getTreasuresConfig() { public FileConfiguration getTreasuresConfig() {
if (treasuresConfig == null) { if (treasuresConfig == null) {
reloadTreasuresConfig(); reloadTreasuresConfig();
} }
return treasuresConfig; return treasuresConfig;
} }
/**
* Save the Treasures config informtion.
*/
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) { }
Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Could not save config to " + treasuresConfigFile, ex); catch (IOException ex) {
log.log(Level.SEVERE, "Could not save config to " + treasuresConfigFile, ex);
} }
} }
} }

View File

@ -2,118 +2,153 @@ package com.gmail.nossr50;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class mcPermissions public class mcPermissions {
{
private static volatile mcPermissions instance; private static volatile mcPermissions instance;
public boolean permission(Player player, String perm) { public boolean permission(Player player, String perm) {
return player.hasPermission(perm); return player.hasPermission(perm);
} }
public boolean admin(Player player) { public boolean admin(Player player) {
return player.hasPermission("mcmmo.admin"); return player.hasPermission("mcmmo.admin");
} }
public boolean mcrefresh(Player player) { public boolean mcrefresh(Player player) {
return player.hasPermission("mcmmo.tools.mcrefresh"); return player.hasPermission("mcmmo.tools.mcrefresh");
} }
public boolean mcremove(Player player) { public boolean mcremove(Player player) {
return player.hasPermission("mcmmo.tools.mcremove"); return player.hasPermission("mcmmo.tools.mcremove");
} }
public boolean mmoedit(Player player) { public boolean mmoedit(Player player) {
return player.hasPermission("mcmmo.tools.mmoedit"); return player.hasPermission("mcmmo.tools.mmoedit");
} }
public boolean herbalismAbility(Player player) { public boolean herbalismAbility(Player player) {
return player.hasPermission("mcmmo.ability.herbalism"); return player.hasPermission("mcmmo.ability.herbalism");
} }
public boolean excavationAbility(Player player) { public boolean excavationAbility(Player player) {
return player.hasPermission("mcmmo.ability.excavation"); return player.hasPermission("mcmmo.ability.excavation");
} }
public boolean unarmedAbility(Player player) { public boolean unarmedAbility(Player player) {
return player.hasPermission("mcmmo.ability.unarmed"); return player.hasPermission("mcmmo.ability.unarmed");
} }
public boolean chimaeraWing(Player player) { public boolean chimaeraWing(Player player) {
return player.hasPermission("mcmmo.item.chimaerawing"); return player.hasPermission("mcmmo.item.chimaerawing");
} }
public boolean miningAbility(Player player) { public boolean miningAbility(Player player) {
return player.hasPermission("mcmmo.ability.mining"); return player.hasPermission("mcmmo.ability.mining");
} }
public boolean axesAbility(Player player) { public boolean axesAbility(Player player) {
return player.hasPermission("mcmmo.ability.axes"); return player.hasPermission("mcmmo.ability.axes");
} }
public boolean swordsAbility(Player player) { public boolean swordsAbility(Player player) {
return player.hasPermission("mcmmo.ability.swords"); return player.hasPermission("mcmmo.ability.swords");
} }
public boolean woodCuttingAbility(Player player) { public boolean woodCuttingAbility(Player player) {
return player.hasPermission("mcmmo.ability.woodcutting"); return player.hasPermission("mcmmo.ability.woodcutting");
} }
public boolean mcgod(Player player) { public boolean mcgod(Player player) {
return player.hasPermission("mcmmo.tools.mcgod"); return player.hasPermission("mcmmo.tools.mcgod");
} }
public boolean motd(Player player) { public boolean motd(Player player) {
return player.hasPermission("mcmmo.motd"); return player.hasPermission("mcmmo.motd");
} }
public boolean mcAbility(Player player) { public boolean mcAbility(Player player) {
return player.hasPermission("mcmmo.commands.ability"); return player.hasPermission("mcmmo.commands.ability");
} }
public boolean partyChat(Player player) { public boolean partyChat(Player player) {
return player.hasPermission("mcmmo.chat.partychat"); return player.hasPermission("mcmmo.chat.partychat");
} }
public boolean partyLock(Player player) { public boolean partyLock(Player player) {
return player.hasPermission("mcmmo.chat.partylock"); return player.hasPermission("mcmmo.chat.partylock");
} }
public boolean partyTeleport(Player player) { public boolean partyTeleport(Player player) {
return player.hasPermission("mcmmo.commands.ptp"); return player.hasPermission("mcmmo.commands.ptp");
} }
public boolean inspect(Player player) { public boolean inspect(Player player) {
return player.hasPermission("mcmmo.commands.inspect"); return player.hasPermission("mcmmo.commands.inspect");
} }
public boolean party(Player player) { public boolean party(Player player) {
return player.hasPermission("mcmmo.commands.party"); return player.hasPermission("mcmmo.commands.party");
} }
public boolean adminChat(Player player) { public boolean adminChat(Player player) {
return player.hasPermission("mcmmo.chat.adminchat"); return player.hasPermission("mcmmo.chat.adminchat");
} }
public static mcPermissions getInstance() { public static mcPermissions getInstance() {
if (instance == null) { if (instance == null) {
instance = new mcPermissions(); instance = new mcPermissions();
} }
return instance; return instance;
} }
public boolean taming(Player player) { public boolean taming(Player player) {
return player.hasPermission("mcmmo.skills.taming"); return player.hasPermission("mcmmo.skills.taming");
} }
public boolean mining(Player player) { public boolean mining(Player player) {
return player.hasPermission("mcmmo.skills.mining"); return player.hasPermission("mcmmo.skills.mining");
} }
public boolean blastMining(Player player) { public boolean blastMining(Player player) {
return player.hasPermission("mcmmo.skills.blastmining"); return player.hasPermission("mcmmo.skills.blastmining");
} }
public boolean fishing(Player player) { public boolean fishing(Player player) {
return player.hasPermission("mcmmo.skills.fishing"); return player.hasPermission("mcmmo.skills.fishing");
} }
public boolean woodcutting(Player player) { public boolean woodcutting(Player player) {
return player.hasPermission("mcmmo.skills.woodcutting"); return player.hasPermission("mcmmo.skills.woodcutting");
} }
public boolean repair(Player player) { public boolean repair(Player player) {
return player.hasPermission("mcmmo.skills.repair"); return player.hasPermission("mcmmo.skills.repair");
} }
public boolean unarmed(Player player) { public boolean unarmed(Player player) {
return player.hasPermission("mcmmo.skills.unarmed"); return player.hasPermission("mcmmo.skills.unarmed");
} }
public boolean archery(Player player) { public boolean archery(Player player) {
return player.hasPermission("mcmmo.skills.archery"); return player.hasPermission("mcmmo.skills.archery");
} }
public boolean herbalism(Player player) { public boolean herbalism(Player player) {
return player.hasPermission("mcmmo.skills.herbalism"); return player.hasPermission("mcmmo.skills.herbalism");
} }
public boolean excavation(Player player) { public boolean excavation(Player player) {
return player.hasPermission("mcmmo.skills.excavation"); return player.hasPermission("mcmmo.skills.excavation");
} }
public boolean swords(Player player) { public boolean swords(Player player) {
return player.hasPermission("mcmmo.skills.swords"); return player.hasPermission("mcmmo.skills.swords");
} }
public boolean axes(Player player) { public boolean axes(Player player) {
return player.hasPermission("mcmmo.skills.axes"); return player.hasPermission("mcmmo.skills.axes");
} }
public boolean acrobatics(Player player) { public boolean acrobatics(Player player) {
return player.hasPermission("mcmmo.skills.acrobatics"); return player.hasPermission("mcmmo.skills.acrobatics");
} }

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);