1
0
mirror of https://github.com/mcMMO-Dev/mcMMO.git synced 2026-02-18 17:53:00 +01:00

Compare commits

..

1 Commits

64 changed files with 1217 additions and 3272 deletions

View File

@@ -17,7 +17,6 @@ Version 1.5.01-dev
+ Added API to check if an entity is bleeding + Added API to check if an entity is bleeding
+ Added options to tools.yml and armor.yml config files to set a pretty repair material name + Added options to tools.yml and armor.yml config files to set a pretty repair material name
+ Added full support for repairables in tools.yml and armor.yml config files + Added full support for repairables in tools.yml and armor.yml config files
+ Added new API class SkillAPI used to get a list of valid skill names
= Fixed bug where pistons would mess with the block tracking = Fixed bug where pistons would mess with the block tracking
= Fixed bug where the Updater was running on the main thread. = Fixed bug where the Updater was running on the main thread.
= Fixed bug when players would use /ptp without being in a party = Fixed bug when players would use /ptp without being in a party
@@ -28,20 +27,12 @@ Version 1.5.01-dev
= Fixed bug where Alchemy would not fire BrewEvents = Fixed bug where Alchemy would not fire BrewEvents
= Fixed bug with setting custom names and lore in treasures config = Fixed bug with setting custom names and lore in treasures config
= Fixed bug which would cause a NullPointerException with getFlowerAndGrassXp() = Fixed bug which would cause a NullPointerException with getFlowerAndGrassXp()
= Fixed bug which could cause and SQLException regarding the connection property 'maxReconnects'.
= Fixed bug where falling blocks were incorrectly tracked
= Fixed bug where items would get deleted when in Berserk with a full inventory
= Fixed bug where the console would not correctly show party chat colors
= Fixed bug where party chat was using non thread safe methods
= Fixed bug where Blast Mining unlock levels could be to high in certain occasions
= Fixed bug where Blast Minings ability "Demolition Expert" would not work
! Changed SecondaryAbilityEvent to implement Cancellable and it now gets fired for damage related secondary abilities ! Changed SecondaryAbilityEvent to implement Cancellable and it now gets fired for damage related secondary abilities
! Changed the way mcMMO handles bonus damage, updated for the new damage event API ! Changed the way mcMMO handles bonus damage, updated for the new damage event API
! Changed player data saving. Save tasks are now asynchronous ! Changed player data saving. Save tasks are now asynchronous
! Vanished players no longer get hit by AoE effects ! Vanished players no longer get hit by AoE effects
! Changed Alchemy config option 'Prevent_Hopper_Transfer' renamed to 'Prevent_Hopper_Transfer_Ingredients' ! Changed Alchemy config option 'Prevent_Hopper_Transfer' renamed to 'Prevent_Hopper_Transfer_Ingredients'
! Changed Alchemy XP distribution. XP is granted based on the stage of the potion. ! Changed Alchemy XP distribution. XP is granted based on the stage of the potion.
! Changed behavior of the Blast Mining ability "Demolition Expert"; now only decreases damage for the ability user
! Updated for new getOnlinePlayers() behavior ! Updated for new getOnlinePlayers() behavior
- Removed salvage ability from Repair, salvage has it's own (child) skill now - Removed salvage ability from Repair, salvage has it's own (child) skill now

View File

@@ -1,132 +0,0 @@
# Config created by joulesbeef
# Created For twilightforest-2.2.3
#
#
# Settings for Boots
###
Boots:
# Ironwood
TWILIGHTFOREST_ITEM_IRONWOODBOOTS:
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_IRONWOODINGOT
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
# Fiery
TWILIGHTFOREST_ITEM_FIERYBOOTS:
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_FIERYINGOT
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
# Stealeaf
TWILIGHTFOREST_ITEM_STEELEAFBOOTS:
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_STEELEAFINGOT
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
# Knightmetal
TWILIGHTFOREST_ITEM_KNIGHTLYBOOTS:
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_KNIGHTMETAL
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
#
# Settings for Chestplates
###
Chestplates:
# Ironwood
TWILIGHTFOREST_ITEM_IRONWOODPLATE:
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_IRONWOODINGOT
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
# Fiery
TWILIGHTFOREST_ITEM_FIERYPLATE:
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_FIERYINGOT
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
# Stealeaf
TWILIGHTFOREST_ITEM_STEELEAFPLATE:
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_STEELEAFINGOT
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
# Knightmetal
TWILIGHTFOREST_ITEM_KNIGHTLYPLATE:
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_KNIGHTMETAL
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
#
# Settings for Helmets
###
Helmets:
# Ironwood
TWILIGHTFOREST_ITEM_IRONWOODHELM:
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_IRONWOODINGOT
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
# Fiery
TWILIGHTFOREST_ITEM_FIERYHELM:
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_FIERYINGOT
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
# Stealeaf
TWILIGHTFOREST_ITEM_STEELEAFHELM:
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_STEELEAFINGOT
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
# Knightmetal
TWILIGHTFOREST_ITEM_KNIGHTLYHELM:
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_KNIGHTMETAL
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 50
# Settings for Leggings
###
Leggings:
# Ironwood
TWILIGHTFOREST_ITEM_IRONWOODLEGS:
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_IRONWOODINGOT
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
# Fiery
TWILIGHTFOREST_ITEM_FIERYLEGS:
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_FIERYINGOT
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
# Stealeaf
TWILIGHTFOREST_ITEM_STEELEAFLEGS:
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_STEELEAFINGOT
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
# Knightmetal
TWILIGHTFOREST_ITEM_KNIGHTLYLEGS:
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_KNIGHTMETAL
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500

View File

@@ -1,116 +0,0 @@
# Config created by joulesbeef
# Created For twilightforest-2.2.3
#
#
# Settings for Custom Herbalism Blocks
###
Herbalism:
# Mushgloom
TWILIGHTFOREST_TILE_TFLOG|9:
XP_Gain: 150
Double_Drops_Enabled: true
# Torchberry Plant
TWILIGHTFOREST_TILE_TFLOG|13:
XP_Gain: 20
Double_Drops_Enabled: true
# Mayapple
TWILIGHTFOREST_TILE_TFLOG|4:
XP_Gain: 30
Double_Drops_Enabled: true
# Fiddlehead
TWILIGHTFOREST_TILE_TFLOG|8:
XP_Gain: 35
Double_Drops_Enabled: true
#
# Settings for Custom Mining Blocks
###
Mining:
# Mazestone
TWILIGHTFOREST_TILE_TFMAZESTONE|0:
XP_Gain: 250
Double_Drops_Enabled: true
Is_Ore: false
TWILIGHTFOREST_TILE_TFMAZESTONE|1:
XP_Gain: 250
Double_Drops_Enabled: true
Is_Ore: false
TWILIGHTFOREST_TILE_TFMAZESTONE|2:
XP_Gain: 250
Double_Drops_Enabled: true
Is_Ore: false
TWILIGHTFOREST_TILE_TFMAZESTONE|3:
XP_Gain: 250
Double_Drops_Enabled: true
Is_Ore: false
TWILIGHTFOREST_TILE_TFMAZESTONE|4:
XP_Gain: 250
Double_Drops_Enabled: true
Is_Ore: false
TWILIGHTFOREST_TILE_TFMAZESTONE|5:
XP_Gain: 250
Double_Drops_Enabled: true
Is_Ore: false
TWILIGHTFOREST_TILE_TFMAZESTONE|6:
XP_Gain: 250
Double_Drops_Enabled: true
Is_Ore: false
TWILIGHTFOREST_TILE_TFMAZESTONE|7:
XP_Gain: 250
Double_Drops_Enabled: true
Is_Ore: false
#
# Settings for Custom Woodcutting Blocks
###
Woodcutting:
# Twilight Oak
TWILIGHTFOREST_TILE_TFLOG|0:
XP_Gain: 70
Double_Drops_Enabled: true
Is_Log: true
# Canopy
TWILIGHTFOREST_TILE_TFLOG|1:
XP_Gain: 80
Double_Drops_Enabled: true
Is_Log: true
# Mangrove
TWILIGHTFOREST_TILE_TFLOG|2:
XP_Gain: 90
Double_Drops_Enabled: true
Is_Log: true
# Darkwood
TWILIGHTFOREST_TILE_TFLOG|3:
XP_Gain: 100
Double_Drops_Enabled: true
Is_Log: true
# Roots
TWILIGHTFOREST_TILE_TFROOTS|0:
XP_Gain: 10
Double_Drops_Enabled: true
Is_Log: false
TWILIGHTFOREST_TILE_TFROOTS|1:
XP_Gain: 10
Double_Drops_Enabled: true
Is_Log: false
# Timewood
TWILIGHTFOREST_TILE_TFMAGICLOG|0:
XP_Gain: 1000
Double_Drops_Enabled: true
Is_Log: true
# Transwood
TWILIGHTFOREST_TILE_TFMAGICLOG|1:
XP_Gain: 1000
Double_Drops_Enabled: true
Is_Log: true
# Minewood
TWILIGHTFOREST_TILE_TFMAGICLOG|2:
XP_Gain: 1000
Double_Drops_Enabled: true
Is_Log: true
# Sortingwood
TWILIGHTFOREST_TILE_TFMAGICLOG|3:
XP_Gain: 1000
Double_Drops_Enabled: true
Is_Log: true

View File

@@ -1,152 +0,0 @@
# Config created by joulesbeef
# Created For twilightforest-2.2.3
#
# Settings for Custom Mobs
MoCreatures-Ogre:
Class: Monster
XP_Multiplier: 1.0
Tameable: false
Taming_XP: 0
CanBeSummoned: false
COTW_Material: ''
COTW_Material_Data: 0
COTW_Material_Amount: 0
TwilightForest-TwilightLich:
Class: Monster
XP_Multiplier: 1.0
Tameable: false
Taming_XP: 0
CanBeSummoned: false
COTW_Material: ''
COTW_Material_Data: 0
COTW_Material_Amount: 0
TwilightForest-HelmetCrab:
Class: Monster
XP_Multiplier: 1.0
Tameable: false
Taming_XP: 0
CanBeSummoned: false
COTW_Material: ''
COTW_Material_Data: 0
COTW_Material_Amount: 0
TwilightForest-SlimeBeetle:
Class: Monster
XP_Multiplier: 1.0
Tameable: false
Taming_XP: 0
CanBeSummoned: false
COTW_Material: ''
COTW_Material_Data: 0
COTW_Material_Amount: 0
TwilightForest-TwilightWraith:
Class: Monster
XP_Multiplier: 1.0
Tameable: false
Taming_XP: 0
CanBeSummoned: false
COTW_Material: ''
COTW_Material_Data: 0
COTW_Material_Amount: 0
TwilightForest-Naga:
Class: Monster
XP_Multiplier: 1.0
Tameable: false
Taming_XP: 0
CanBeSummoned: false
COTW_Material: ''
COTW_Material_Data: 0
COTW_Material_Amount: 0
MoCreatures-Shark:
Class: Monster
XP_Multiplier: 1.0
Tameable: false
Taming_XP: 0
CanBeSummoned: false
COTW_Material: ''
COTW_Material_Data: 0
COTW_Material_Amount: 0
TwilightForest-TowerTermite:
Class: Monster
XP_Multiplier: 1.0
Tameable: false
Taming_XP: 0
CanBeSummoned: false
COTW_Material: ''
COTW_Material_Data: 0
COTW_Material_Amount: 0
MoCreatures-SmallFish:
Class: Monster
XP_Multiplier: 1.0
Tameable: false
Taming_XP: 0
CanBeSummoned: false
COTW_Material: ''
COTW_Material_Data: 0
COTW_Material_Amount: 0
TwilightForest-Redcap:
Class: Monster
XP_Multiplier: 1.0
Tameable: false
Taming_XP: 0
CanBeSummoned: false
COTW_Material: ''
COTW_Material_Data: 0
COTW_Material_Amount: 0
TwilightForest-YetiBoss:
Class: Monster
XP_Multiplier: 1.0
Tameable: false
Taming_XP: 0
CanBeSummoned: false
COTW_Material: ''
COTW_Material_Data: 0
COTW_Material_Amount: 0
MoCreatures-HellRat:
Class: Monster
XP_Multiplier: 1.0
Tameable: false
Taming_XP: 0
CanBeSummoned: false
COTW_Material: ''
COTW_Material_Data: 0
COTW_Material_Amount: 0
TwilightForest-Hydra:
XP_Multiplier: 1.0
Tameable: false
Taming_XP: 0
CanBeSummoned: false
COTW_Material: ''
COTW_Material_Data: 0
COTW_Material_Amount: 0
TwilightForest-Firefly:
XP_Multiplier: 1.0
Tameable: false
Taming_XP: 0
CanBeSummoned: false
COTW_Material: ''
COTW_Material_Data: 0
COTW_Material_Amount: 0
TwilightForest-KnightPhantom:
XP_Multiplier: 1.0
Tameable: false
Taming_XP: 0
CanBeSummoned: false
COTW_Material: ''
COTW_Material_Data: 0
COTW_Material_Amount: 0
TwilightForest-TowerGolem:
XP_Multiplier: 1.0
Tameable: false
Taming_XP: 0
CanBeSummoned: false
COTW_Material: ''
COTW_Material_Data: 0
COTW_Material_Amount: 0
MoCreatures-FishBowl:
XP_Multiplier: 1.0
Tameable: false
Taming_XP: 0
CanBeSummoned: false
COTW_Material: ''
COTW_Material_Data: 0
COTW_Material_Amount: 0

View File

@@ -1,184 +0,0 @@
# Config created by joulesbeef
# Created For twilightforest-2.2.3
#
#
# Settings for Axes
###
Axes:
# Ironwood
TWILIGHTFOREST_ITEM_IRONWOODAXE:
XP_Modifer: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_IRONWOODINGOT
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
# Steeleaf
TWILIGHTFOREST_ITEM_STEELEAFAXE:
XP_Modifer: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_STEELEAFINGOT
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
# Knightmetal
TWILIGHTFOREST_ITEM_KNIGHTLYAXE:
XP_Modifer: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_KNIGHTMETAL
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
# Minotaur
TWILIGHTFOREST_ITEM_MINOTAURAXE:
XP_Modifer: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: Diamond
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
#
# Settings for Hoes
###
Hoes:
# Ironwood
TWILIGHTFOREST_ITEM_IRONWOODHOE:
XP_Modifer: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_IRONWOODINGOT
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
# Steeleaf
TWILIGHTFOREST_ITEM_STEELEAFHOE:
XP_Modifer: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_STEELEAFINGOT
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
#
# Settings for Pickaxes
###
Pickaxes:
# Ironwood
TWILIGHTFOREST_ITEM_IRONWOODPICK:
XP_Modifer: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_IRONWOODINGOT
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
# Fiery
TWILIGHTFOREST_ITEM_FIERYPICK:
XP_Modifer: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_FIERYINGOT
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
# Steeleaf
TWILIGHTFOREST_ITEM_STEELEAFPICK:
XP_Modifer: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_STEELEAFINGOT
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
# Knightmetal
TWILIGHTFOREST_ITEM_KNIGHTLYPICK:
XP_Modifer: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_KNIGHTMETAL
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
#
# Settings for Shovels
###
Shovels:
# Ironwood
TWILIGHTFOREST_ITEM_IRONWOODSHOVEL:
XP_Modifer: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_IRONWOODINGOT
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
# Steeleaf
TWILIGHTFOREST_ITEM_STEELEAFSHOVEL:
XP_Modifer: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_STEELEAFINGOT
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
#
# Settings for Swords
###
Swords:
# Ironwood
TWILIGHTFOREST_ITEM_IRONWOODSWORD:
XP_Modifer: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_IRONWOODINGOT
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
# Fiery
TWILIGHTFOREST_ITEM_FIERYSWORD:
XP_Modifer: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_FIERYINGOT
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
# Steeleaf
TWILIGHTFOREST_ITEM_STEELEAFSWORD:
XP_Modifer: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_STEELEAFINGOT
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500
# Knightmetal
TWILIGHTFOREST_ITEM_KNIGHTLYSWORD:
XP_Modifer: 1.0
Ability_Enabled: true
Tier: 1
Repairable: true
Repair_Material: TWILIGHTFOREST_ITEM_KNIGHTMETAL
Repair_Material_Data_Value: 0
Repair_Material_Quantity: 2
Durability: 500

15
pom.xml
View File

@@ -76,8 +76,6 @@
<artifactSet> <artifactSet>
<includes> <includes>
<include>com.turt2live.metrics:MetricsExtension</include> <include>com.turt2live.metrics:MetricsExtension</include>
<include>commons-logging:commons-logging</include>
<include>net.snaq:dbpool</include>
</includes> </includes>
</artifactSet> </artifactSet>
<relocations> <relocations>
@@ -85,14 +83,6 @@
<pattern>com.turt2live.metrics</pattern> <pattern>com.turt2live.metrics</pattern>
<shadedPattern>com.gmail.nossr50.metrics.mcstats</shadedPattern> <shadedPattern>com.gmail.nossr50.metrics.mcstats</shadedPattern>
</relocation> </relocation>
<relocation>
<pattern>org.apache.commons.logging</pattern>
<shadedPattern>com.gmail.nossr50.commons.logging</shadedPattern>
</relocation>
<relocation>
<pattern>net.snaq</pattern>
<shadedPattern>com.gmail.nossr50.dbpool</shadedPattern>
</relocation>
</relocations> </relocations>
</configuration> </configuration>
<executions> <executions>
@@ -146,11 +136,6 @@
<artifactId>MetricsExtension</artifactId> <artifactId>MetricsExtension</artifactId>
<version>0.0.5-SNAPSHOT</version> <version>0.0.5-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>net.snaq</groupId>
<artifactId>dbpool</artifactId>
<version>5.1</version>
</dependency>
</dependencies> </dependencies>
<distributionManagement> <distributionManagement>
<repository> <repository>

View File

@@ -1,7 +1,6 @@
package com.gmail.nossr50.api; package com.gmail.nossr50.api;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -87,14 +86,6 @@ public final class ExperienceAPI {
UserManager.getPlayer(player).applyXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason)); UserManager.getPlayer(player).applyXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason));
} }
/**
* Adds raw XP to an offline player.
* </br>
* This function is designed for API usage.
*
* @deprecated We're using float for our XP values now
* replaced by {@link #addRawXPOffline(String playerName, String skillType, float XP)}
*/
@Deprecated @Deprecated
public static void addRawXPOffline(String playerName, String skillType, int XP) { public static void addRawXPOffline(String playerName, String skillType, int XP) {
addRawXPOffline(playerName, skillType, (float) XP); addRawXPOffline(playerName, skillType, (float) XP);
@@ -105,9 +96,6 @@ public final class ExperienceAPI {
* </br> * </br>
* This function is designed for API usage. * This function is designed for API usage.
* *
* @deprecated We're using uuids to get an offline player
* replaced by {@link #addRawXPOffline(UUID uuid, String skillType, float XP)}
*
* @param playerName The player to add XP to * @param playerName The player to add XP to
* @param skillType The skill to add XP to * @param skillType The skill to add XP to
* @param XP The amount of XP to add * @param XP The amount of XP to add
@@ -115,27 +103,10 @@ public final class ExperienceAPI {
* @throws InvalidSkillException if the given skill is not valid * @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database * @throws InvalidPlayerException if the given player does not exist in the database
*/ */
@Deprecated
public static void addRawXPOffline(String playerName, String skillType, float XP) { public static void addRawXPOffline(String playerName, String skillType, float XP) {
addOfflineXP(playerName, getSkillType(skillType), (int) Math.floor(XP)); addOfflineXP(playerName, getSkillType(skillType), (int) Math.floor(XP));
} }
/**
* Adds raw XP to an offline player.
* </br>
* This function is designed for API usage.
*
* @param uuid The UUID of player to add XP to
* @param skillType The skill to add XP to
* @param XP The amount of XP to add
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
*/
public static void addRawXPOffline(UUID uuid, String skillType, float XP) {
addOfflineXP(uuid, getSkillType(skillType), (int) Math.floor(XP));
}
/** /**
* Adds XP to the player, calculates for XP Rate only. * Adds XP to the player, calculates for XP Rate only.
* </br> * </br>
@@ -181,7 +152,6 @@ public final class ExperienceAPI {
* @throws InvalidSkillException if the given skill is not valid * @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database * @throws InvalidPlayerException if the given player does not exist in the database
*/ */
@Deprecated
public static void addMultipliedXPOffline(String playerName, String skillType, int XP) { public static void addMultipliedXPOffline(String playerName, String skillType, int XP) {
addOfflineXP(playerName, getSkillType(skillType), (int) (XP * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier())); addOfflineXP(playerName, getSkillType(skillType), (int) (XP * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()));
} }
@@ -233,7 +203,6 @@ public final class ExperienceAPI {
* @throws InvalidSkillException if the given skill is not valid * @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database * @throws InvalidPlayerException if the given player does not exist in the database
*/ */
@Deprecated
public static void addModifiedXPOffline(String playerName, String skillType, int XP) { public static void addModifiedXPOffline(String playerName, String skillType, int XP) {
SkillType skill = getSkillType(skillType); SkillType skill = getSkillType(skillType);
@@ -304,28 +273,10 @@ public final class ExperienceAPI {
* @throws InvalidPlayerException if the given player does not exist in the database * @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill * @throws UnsupportedOperationException if the given skill is a child skill
*/ */
@Deprecated
public static int getOfflineXP(String playerName, String skillType) { public static int getOfflineXP(String playerName, String skillType) {
return getOfflineProfile(playerName).getSkillXpLevel(getNonChildSkillType(skillType)); return getOfflineProfile(playerName).getSkillXpLevel(getNonChildSkillType(skillType));
} }
/**
* Get the amount of XP an offline player has in a specific skill.
* </br>
* This function is designed for API usage.
*
* @param uuid The player to get XP for
* @param skillType The skill to get XP for
* @return the amount of XP in a given skill
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
*/
public static int getOfflineXP(UUID uuid, String skillType) {
return getOfflineProfile(uuid).getSkillXpLevel(getNonChildSkillType(skillType));
}
/** /**
* Get the raw amount of XP a player has in a specific skill. * Get the raw amount of XP a player has in a specific skill.
* </br> * </br>
@@ -355,28 +306,10 @@ public final class ExperienceAPI {
* @throws InvalidPlayerException if the given player does not exist in the database * @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill * @throws UnsupportedOperationException if the given skill is a child skill
*/ */
@Deprecated
public static float getOfflineXPRaw(String playerName, String skillType) { public static float getOfflineXPRaw(String playerName, String skillType) {
return getOfflineProfile(playerName).getSkillXpLevelRaw(getNonChildSkillType(skillType)); return getOfflineProfile(playerName).getSkillXpLevelRaw(getNonChildSkillType(skillType));
} }
/**
* Get the raw amount of XP an offline player has in a specific skill.
* </br>
* This function is designed for API usage.
*
* @param uuid The player to get XP for
* @param skillType The skill to get XP for
* @return the amount of XP in a given skill
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
*/
public static float getOfflineXPRaw(UUID uuid, String skillType) {
return getOfflineProfile(uuid).getSkillXpLevelRaw(getNonChildSkillType(skillType));
}
/** /**
* Get the total amount of XP needed to reach the next level. * Get the total amount of XP needed to reach the next level.
* </br> * </br>
@@ -406,28 +339,10 @@ public final class ExperienceAPI {
* @throws InvalidPlayerException if the given player does not exist in the database * @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill * @throws UnsupportedOperationException if the given skill is a child skill
*/ */
@Deprecated
public static int getOfflineXPToNextLevel(String playerName, String skillType) { public static int getOfflineXPToNextLevel(String playerName, String skillType) {
return getOfflineProfile(playerName).getXpToLevel(getNonChildSkillType(skillType)); return getOfflineProfile(playerName).getXpToLevel(getNonChildSkillType(skillType));
} }
/**
* Get the total amount of XP an offline player needs to reach the next level.
* </br>
* This function is designed for API usage.
*
* @param uuid The player to get XP for
* @param skillType The skill to get XP for
* @return the total amount of XP needed to reach the next level
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
*/
public static int getOfflineXPToNextLevel(UUID uuid, String skillType) {
return getOfflineProfile(uuid).getXpToLevel(getNonChildSkillType(skillType));
}
/** /**
* Get the amount of XP remaining until the next level. * Get the amount of XP remaining until the next level.
* </br> * </br>
@@ -461,34 +376,14 @@ public final class ExperienceAPI {
* @throws InvalidPlayerException if the given player does not exist in the database * @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill * @throws UnsupportedOperationException if the given skill is a child skill
*/ */
@Deprecated
public static int getOfflineXPRemaining(String playerName, String skillType) { public static int getOfflineXPRemaining(String playerName, String skillType) {
SkillType skill = getNonChildSkillType(skillType); SkillType skill = getNonChildSkillType(skillType);
PlayerProfile profile = getOfflineProfile(playerName); PlayerProfile profile = getOfflineProfile(playerName);
return profile.getXpToLevel(skill) - profile.getSkillXpLevel(skill); return profile.getXpToLevel(skill) - profile.getSkillXpLevel(skill);
} }
/**
* Get the amount of XP an offline player has left before leveling up.
* </br>
* This function is designed for API usage.
*
* @param uuid The player to get XP for
* @param skillType The skill to get XP for
* @return the amount of XP needed to reach the next level
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
*/
public static float getOfflineXPRemaining(UUID uuid, String skillType) {
SkillType skill = getNonChildSkillType(skillType);
PlayerProfile profile = getOfflineProfile(uuid);
return profile.getXpToLevel(skill) - profile.getSkillXpLevelRaw(skill);
}
/** /**
* Add levels to a skill. * Add levels to a skill.
* </br> * </br>
@@ -516,7 +411,6 @@ public final class ExperienceAPI {
* @throws InvalidSkillException if the given skill is not valid * @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database * @throws InvalidPlayerException if the given player does not exist in the database
*/ */
@Deprecated
public static void addLevelOffline(String playerName, String skillType, int levels) { public static void addLevelOffline(String playerName, String skillType, int levels) {
PlayerProfile profile = getOfflineProfile(playerName); PlayerProfile profile = getOfflineProfile(playerName);
SkillType skill = getSkillType(skillType); SkillType skill = getSkillType(skillType);
@@ -536,37 +430,6 @@ public final class ExperienceAPI {
profile.scheduleAsyncSave(); profile.scheduleAsyncSave();
} }
/**
* Add levels to a skill for an offline player.
* </br>
* This function is designed for API usage.
*
* @param uuid The player to add levels to
* @param skillType Type of skill to add levels to
* @param levels Number of levels to add
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
*/
public static void addLevelOffline(UUID uuid, String skillType, int levels) {
PlayerProfile profile = getOfflineProfile(uuid);
SkillType skill = getSkillType(skillType);
if (skill.isChildSkill()) {
Set<SkillType> parentSkills = FamilyTree.getParents(skill);
for (SkillType parentSkill : parentSkills) {
profile.addLevels(parentSkill, (levels / parentSkills.size()));
}
profile.scheduleAsyncSave();
return;
}
profile.addLevels(skill, levels);
profile.scheduleAsyncSave();
}
/** /**
* Get the level a player has in a specific skill. * Get the level a player has in a specific skill.
* </br> * </br>
@@ -594,27 +457,10 @@ public final class ExperienceAPI {
* @throws InvalidSkillException if the given skill is not valid * @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database * @throws InvalidPlayerException if the given player does not exist in the database
*/ */
@Deprecated
public static int getLevelOffline(String playerName, String skillType) { public static int getLevelOffline(String playerName, String skillType) {
return getOfflineProfile(playerName).getSkillLevel(getSkillType(skillType)); return getOfflineProfile(playerName).getSkillLevel(getSkillType(skillType));
} }
/**
* Get the level an offline player has in a specific skill.
* </br>
* This function is designed for API usage.
*
* @param uuid The player to get the level for
* @param skillType The skill to get the level for
* @return the level of a given skill
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
*/
public static int getLevelOffline(UUID uuid, String skillType) {
return getOfflineProfile(uuid).getSkillLevel(getSkillType(skillType));
}
/** /**
* Gets the power level of a player. * Gets the power level of a player.
* </br> * </br>
@@ -637,7 +483,6 @@ public final class ExperienceAPI {
* *
* @throws InvalidPlayerException if the given player does not exist in the database * @throws InvalidPlayerException if the given player does not exist in the database
*/ */
@Deprecated
public static int getPowerLevelOffline(String playerName) { public static int getPowerLevelOffline(String playerName) {
int powerLevel = 0; int powerLevel = 0;
PlayerProfile profile = getOfflineProfile(playerName); PlayerProfile profile = getOfflineProfile(playerName);
@@ -649,27 +494,6 @@ public final class ExperienceAPI {
return powerLevel; return powerLevel;
} }
/**
* Gets the power level of an offline player.
* </br>
* This function is designed for API usage.
*
* @param uuid The player to get the power level for
* @return the power level of the player
*
* @throws InvalidPlayerException if the given player does not exist in the database
*/
public static int getPowerLevelOffline(UUID uuid) {
int powerLevel = 0;
PlayerProfile profile = getOfflineProfile(uuid);
for (SkillType type : SkillType.NON_CHILD_SKILLS) {
powerLevel += profile.getSkillLevel(type);
}
return powerLevel;
}
/** /**
* Get the level cap of a specific skill. * Get the level cap of a specific skill.
* </br> * </br>
@@ -709,28 +533,10 @@ public final class ExperienceAPI {
* *
* @return the position on the leaderboard * @return the position on the leaderboard
*/ */
@Deprecated
public static int getPlayerRankSkill(String playerName, String skillType) { public static int getPlayerRankSkill(String playerName, String skillType) {
return mcMMO.getDatabaseManager().readRank(getOfflineProfile(playerName).getPlayerName()).get(getNonChildSkillType(skillType)); return mcMMO.getDatabaseManager().readRank(getOfflineProfile(playerName).getPlayerName()).get(getNonChildSkillType(skillType));
} }
/**
* Get the position on the leaderboard of a player.
* </br>
* This function is designed for API usage.
*
* @param uuid The name of the player to check
* @param skillType The skill to check
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
*
* @return the position on the leaderboard
*/
public static int getPlayerRankSkill(UUID uuid, String skillType) {
return mcMMO.getDatabaseManager().readRank(getOfflineProfile(uuid).getPlayerName()).get(getNonChildSkillType(skillType));
}
/** /**
* Get the position on the power level leaderboard of a player. * Get the position on the power level leaderboard of a player.
@@ -743,26 +549,10 @@ public final class ExperienceAPI {
* *
* @return the position on the power level leaderboard * @return the position on the power level leaderboard
*/ */
@Deprecated
public static int getPlayerRankOverall(String playerName) { public static int getPlayerRankOverall(String playerName) {
return mcMMO.getDatabaseManager().readRank(getOfflineProfile(playerName).getPlayerName()).get(null); return mcMMO.getDatabaseManager().readRank(getOfflineProfile(playerName).getPlayerName()).get(null);
} }
/**
* Get the position on the power level leaderboard of a player.
* </br>
* This function is designed for API usage.
*
* @param uuid The name of the player to check
*
* @throws InvalidPlayerException if the given player does not exist in the database
*
* @return the position on the power level leaderboard
*/
public static int getPlayerRankOverall(UUID uuid) {
return mcMMO.getDatabaseManager().readRank(getOfflineProfile(uuid).getPlayerName()).get(null);
}
/** /**
* Sets the level of a player in a specific skill type. * Sets the level of a player in a specific skill type.
* </br> * </br>
@@ -790,27 +580,10 @@ public final class ExperienceAPI {
* @throws InvalidSkillException if the given skill is not valid * @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database * @throws InvalidPlayerException if the given player does not exist in the database
*/ */
@Deprecated
public static void setLevelOffline(String playerName, String skillType, int skillLevel) { public static void setLevelOffline(String playerName, String skillType, int skillLevel) {
getOfflineProfile(playerName).modifySkill(getSkillType(skillType), skillLevel); getOfflineProfile(playerName).modifySkill(getSkillType(skillType), skillLevel);
} }
/**
* Sets the level of an offline player in a specific skill type.
* </br>
* This function is designed for API usage.
*
* @param uuid The player to set the level of
* @param skillType The skill to set the level for
* @param skillLevel The value to set the level to
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
*/
public static void setLevelOffline(UUID uuid, String skillType, int skillLevel) {
getOfflineProfile(uuid).modifySkill(getSkillType(skillType), skillLevel);
}
/** /**
* Sets the XP of a player in a specific skill type. * Sets the XP of a player in a specific skill type.
* </br> * </br>
@@ -840,28 +613,10 @@ public final class ExperienceAPI {
* @throws InvalidPlayerException if the given player does not exist in the database * @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill * @throws UnsupportedOperationException if the given skill is a child skill
*/ */
@Deprecated
public static void setXPOffline(String playerName, String skillType, int newValue) { public static void setXPOffline(String playerName, String skillType, int newValue) {
getOfflineProfile(playerName).setSkillXpLevel(getNonChildSkillType(skillType), newValue); getOfflineProfile(playerName).setSkillXpLevel(getNonChildSkillType(skillType), newValue);
} }
/**
* Sets the XP of an offline player in a specific skill type.
* </br>
* This function is designed for API usage.
*
* @param uuid The player to set the XP of
* @param skillType The skill to set the XP for
* @param newValue The value to set the XP to
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
*/
public static void setXPOffline(UUID uuid, String skillType, int newValue) {
getOfflineProfile(uuid).setSkillXpLevel(getNonChildSkillType(skillType), newValue);
}
/** /**
* Removes XP from a player in a specific skill type. * Removes XP from a player in a specific skill type.
* </br> * </br>
@@ -891,37 +646,12 @@ public final class ExperienceAPI {
* @throws InvalidPlayerException if the given player does not exist in the database * @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill * @throws UnsupportedOperationException if the given skill is a child skill
*/ */
@Deprecated
public static void removeXPOffline(String playerName, String skillType, int xp) { public static void removeXPOffline(String playerName, String skillType, int xp) {
getOfflineProfile(playerName).removeXp(getNonChildSkillType(skillType), xp); getOfflineProfile(playerName).removeXp(getNonChildSkillType(skillType), xp);
} }
/**
* Removes XP from an offline player in a specific skill type.
* </br>
* This function is designed for API usage.
*
* @param uuid The player to change the XP of
* @param skillType The skill to change the XP for
* @param xp The amount of XP to remove
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
*/
public static void removeXPOffline(UUID uuid, String skillType, int xp) {
getOfflineProfile(uuid).removeXp(getNonChildSkillType(skillType), xp);
}
// Utility methods follow. // Utility methods follow.
private static void addOfflineXP(UUID playerUniqueId, SkillType skill, int XP) {
PlayerProfile profile = getOfflineProfile(playerUniqueId);
profile.addXp(skill, XP);
profile.save();
}
@Deprecated
private static void addOfflineXP(String playerName, SkillType skill, int XP) { private static void addOfflineXP(String playerName, SkillType skill, int XP) {
PlayerProfile profile = getOfflineProfile(playerName); PlayerProfile profile = getOfflineProfile(playerName);
@@ -929,20 +659,8 @@ public final class ExperienceAPI {
profile.scheduleAsyncSave(); profile.scheduleAsyncSave();
} }
private static PlayerProfile getOfflineProfile(UUID uuid) {
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(uuid);
if (!profile.isLoaded()) {
throw new InvalidPlayerException();
}
return profile;
}
@Deprecated
private static PlayerProfile getOfflineProfile(String playerName) { private static PlayerProfile getOfflineProfile(String playerName) {
UUID uuid = mcMMO.p.getServer().getOfflinePlayer(playerName).getUniqueId(); PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, false);
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(uuid);
if (!profile.isLoaded()) { if (!profile.isLoaded()) {
throw new InvalidPlayerException(); throw new InvalidPlayerException();

View File

@@ -1,93 +0,0 @@
package com.gmail.nossr50.api;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.gmail.nossr50.datatypes.skills.SkillType;
public final class SkillAPI {
private SkillAPI() {}
/**
* Returns a list of strings with mcMMO's skills
* This includes parent and child skills
* </br>
* This function is designed for API usage.
*
* @return a list of strings with valid skill names
*/
public static List<String> getSkills() {
return getListFromEnum(Arrays.asList(SkillType.values()));
}
/**
* Returns a list of strings with mcMMO's skills
* This only includes parent skills
* </br>
* This function is designed for API usage.
*
* @return a list of strings with valid skill names
*/
public static List<String> getNonChildSkills() {
return getListFromEnum(SkillType.NON_CHILD_SKILLS);
}
/**
* Returns a list of strings with mcMMO's skills
* This only includes child skills
* </br>
* This function is designed for API usage.
*
* @return a list of strings with valid skill names
*/
public static List<String> getChildSkills() {
return getListFromEnum(SkillType.CHILD_SKILLS);
}
/**
* Returns a list of strings with mcMMO's skills
* This only includes combat skills
* </br>
* This function is designed for API usage.
*
* @return a list of strings with valid skill names
*/
public static List<String> getCombatSkills() {
return getListFromEnum(SkillType.COMBAT_SKILLS);
}
/**
* Returns a list of strings with mcMMO's skills
* This only includes gathering skills
* </br>
* This function is designed for API usage.
*
* @return a list of strings with valid skill names
*/
public static List<String> getGatheringSkills() {
return getListFromEnum(SkillType.GATHERING_SKILLS);
}
/**
* Returns a list of strings with mcMMO's skills
* This only includes misc skills
* </br>
* This function is designed for API usage.
*
* @return a list of strings with valid skill names
*/
public static List<String> getMiscSkills() {
return getListFromEnum(SkillType.MISC_SKILLS);
}
private static List<String> getListFromEnum(List<SkillType> skillsTypes) {
List<String> skills = new ArrayList<String>();
for (SkillType skillType : skillsTypes) {
skills.add(skillType.name());
}
return skills;
}
}

View File

@@ -1,11 +1,16 @@
package com.gmail.nossr50.chat; package com.gmail.nossr50.chat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.events.chat.McMMOPartyChatEvent; import com.gmail.nossr50.events.chat.McMMOPartyChatEvent;
import com.gmail.nossr50.runnables.party.PartyChatTask; import com.gmail.nossr50.locale.LocaleLoader;
public class PartyChatManager extends ChatManager { public class PartyChatManager extends ChatManager {
private Party party; private Party party;
@@ -25,6 +30,21 @@ public class PartyChatManager extends ChatManager {
@Override @Override
protected void sendMessage() { protected void sendMessage() {
new PartyChatTask(plugin, party, senderName, displayName, message).runTask(plugin); if (Config.getInstance().getPartyChatColorLeaderName() && senderName.equalsIgnoreCase(party.getLeader())) {
message = message.replaceFirst(Pattern.quote(displayName), ChatColor.GOLD + Matcher.quoteReplacement(displayName) + ChatColor.RESET);
}
for (Player member : party.getOnlineMembers()) {
member.sendMessage(message);
}
if (party.getAlly() != null) {
for (Player member : party.getAlly().getOnlineMembers()) {
String allyPrefix = LocaleLoader.formatString(Config.getInstance().getPartyChatPrefixAlly());
member.sendMessage(allyPrefix + message);
}
}
plugin.getLogger().info("[P]<" + party.getName() + ">" + message);
} }
} }

View File

@@ -12,7 +12,6 @@ import com.gmail.nossr50.datatypes.database.DatabaseType;
import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.database.DatabaseConversionTask; import com.gmail.nossr50.runnables.database.DatabaseConversionTask;
import com.gmail.nossr50.runnables.player.PlayerProfileLoadingTask;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class ConvertDatabaseCommand implements CommandExecutor { public class ConvertDatabaseCommand implements CommandExecutor {
@@ -56,13 +55,13 @@ public class ConvertDatabaseCommand implements CommandExecutor {
UserManager.clearAll(); UserManager.clearAll();
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) { for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
PlayerProfile profile = oldDatabase.loadPlayerProfile(player.getUniqueId()); PlayerProfile profile = oldDatabase.loadPlayerProfile(player.getName(), false);
if (profile.isLoaded()) { if (profile.isLoaded()) {
mcMMO.getDatabaseManager().saveUser(profile); mcMMO.getDatabaseManager().saveUser(profile);
} }
new PlayerProfileLoadingTask(player).runTaskTimerAsynchronously(mcMMO.p, 1, 20); // 1 Tick delay to ensure the player is marked as online before we begin loading UserManager.addUser(player);
} }
new DatabaseConversionTask(oldDatabase, sender, previousType.toString(), newType.toString()).runTaskAsynchronously(mcMMO.p); new DatabaseConversionTask(oldDatabase, sender, previousType.toString(), newType.toString()).runTaskAsynchronously(mcMMO.p);

View File

@@ -9,7 +9,6 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.experience.FormulaType; import com.gmail.nossr50.datatypes.experience.FormulaType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.database.FormulaConversionTask; import com.gmail.nossr50.runnables.database.FormulaConversionTask;
import com.gmail.nossr50.runnables.player.PlayerProfileLoadingTask;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class ConvertExperienceCommand implements CommandExecutor { public class ConvertExperienceCommand implements CommandExecutor {
@@ -38,7 +37,7 @@ public class ConvertExperienceCommand implements CommandExecutor {
new FormulaConversionTask(sender, newType).runTaskLater(mcMMO.p, 1); new FormulaConversionTask(sender, newType).runTaskLater(mcMMO.p, 1);
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) { for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
new PlayerProfileLoadingTask(player).runTaskTimerAsynchronously(mcMMO.p, 1, 20); // 1 Tick delay to ensure the player is marked as online before we begin loading UserManager.addUser(player);
} }
return true; return true;

View File

@@ -9,7 +9,6 @@ import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.datatypes.skills.SecondaryAbility; import com.gmail.nossr50.datatypes.skills.SecondaryAbility;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.mining.BlastMining;
import com.gmail.nossr50.skills.mining.BlastMining.Tier; import com.gmail.nossr50.skills.mining.BlastMining.Tier;
import com.gmail.nossr50.skills.mining.MiningManager; import com.gmail.nossr50.skills.mining.MiningManager;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
@@ -127,7 +126,7 @@ public class MiningCommand extends SkillCommand {
} }
if (canBiggerBombs) { if (canBiggerBombs) {
int unlockLevel = BlastMining.getBiggerBombsUnlockLevel(); int unlockLevel = AdvancedConfig.getInstance().getBlastMiningRankLevel(Tier.TWO);
if (skillValue < unlockLevel) { if (skillValue < unlockLevel) {
messages.add(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.1", unlockLevel))); messages.add(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.1", unlockLevel)));
@@ -138,7 +137,7 @@ public class MiningCommand extends SkillCommand {
} }
if (canDemoExpert) { if (canDemoExpert) {
int unlockLevel = BlastMining.getDemolitionExpertUnlockLevel(); int unlockLevel = AdvancedConfig.getInstance().getBlastMiningRankLevel(Tier.FOUR);
if (skillValue < unlockLevel) { if (skillValue < unlockLevel) {
messages.add(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.2", unlockLevel))); messages.add(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Mining.Ability.Locked.2", unlockLevel)));

View File

@@ -232,7 +232,6 @@ public class Config extends AutoUpdateConfigLoader {
/* General Settings */ /* General Settings */
public String getLocale() { return config.getString("General.Locale", "en_us"); } public String getLocale() { return config.getString("General.Locale", "en_us"); }
public boolean getMOTDEnabled() { return config.getBoolean("General.MOTD_Enabled", true); } public boolean getMOTDEnabled() { return config.getBoolean("General.MOTD_Enabled", true); }
public boolean getShowProfileLoadedMessage() { return config.getBoolean("General.Show_Profile_Loaded", true); }
public boolean getDonateMessageEnabled() { return config.getBoolean("Commands.mcmmo.Donate_Message", true); } public boolean getDonateMessageEnabled() { return config.getBoolean("Commands.mcmmo.Donate_Message", true); }
public int getSaveInterval() { return config.getInt("General.Save_Interval", 10); } public int getSaveInterval() { return config.getInt("General.Save_Interval", 10); }
public boolean getStatsTrackingEnabled() { return config.getBoolean("General.Stats_Tracking", true); } public boolean getStatsTrackingEnabled() { return config.getBoolean("General.Stats_Tracking", true); }
@@ -314,8 +313,6 @@ public class Config extends AutoUpdateConfigLoader {
public int getMySQLServerPort() { return config.getInt("MySQL.Server.Port", 3306); } public int getMySQLServerPort() { return config.getInt("MySQL.Server.Port", 3306); }
public String getMySQLServerName() { return config.getString("MySQL.Server.Address", "localhost"); } public String getMySQLServerName() { return config.getString("MySQL.Server.Address", "localhost"); }
public String getMySQLUserPassword() { return getStringIncludingInts("MySQL.Database.User_Password"); } public String getMySQLUserPassword() { return getStringIncludingInts("MySQL.Database.User_Password"); }
public int getMySQLMaxConnections() { return config.getInt("MySQL.Database.MaxConnections"); }
public int getMySQLMaxPoolSize() { return config.getInt("MySQL.Database.MaxPoolSize"); }
private String getStringIncludingInts(String key) { private String getStringIncludingInts(String key) {
String str = config.getString(key); String str = config.getString(key);
@@ -477,7 +474,6 @@ public class Config extends AutoUpdateConfigLoader {
/* Unarmed */ /* Unarmed */
public boolean getUnarmedBlockCrackerSmoothbrickToCracked() { return config.getBoolean("Skills.Unarmed.Block_Cracker.SmoothBrick_To_CrackedBrick", true); } public boolean getUnarmedBlockCrackerSmoothbrickToCracked() { return config.getBoolean("Skills.Unarmed.Block_Cracker.SmoothBrick_To_CrackedBrick", true); }
public boolean getUnarmedItemPickupDisabled() { return config.getBoolean("Skills.Unarmed.Item_Pickup_Disabled_Full_Inventory", true); }
/* Taming */ /* Taming */
public Material getTamingCOTWMaterial(EntityType type) { return Material.matchMaterial(config.getString("Skills.Taming.Call_Of_The_Wild." + StringUtils.getPrettyEntityTypeString(type) + ".Item_Material")); } public Material getTamingCOTWMaterial(EntityType type) { return Material.matchMaterial(config.getString("Skills.Taming.Call_Of_The_Wild." + StringUtils.getPrettyEntityTypeString(type) + ".Item_Material")); }

View File

@@ -12,7 +12,6 @@ public class HiddenConfig {
private static int conversionRate; private static int conversionRate;
private static boolean useEnchantmentBuffs; private static boolean useEnchantmentBuffs;
private static boolean resendChunksAfterBlockAbility; private static boolean resendChunksAfterBlockAbility;
private static int uuidConvertAmount;
public HiddenConfig(String fileName) { public HiddenConfig(String fileName) {
HiddenConfig.fileName = fileName; HiddenConfig.fileName = fileName;
@@ -34,7 +33,6 @@ public class HiddenConfig {
conversionRate = config.getInt("Options.ConversionRate", 1); conversionRate = config.getInt("Options.ConversionRate", 1);
useEnchantmentBuffs = config.getBoolean("Options.EnchantmentBuffs", true); useEnchantmentBuffs = config.getBoolean("Options.EnchantmentBuffs", true);
resendChunksAfterBlockAbility = config.getBoolean("Options.RefreshChunks", false); resendChunksAfterBlockAbility = config.getBoolean("Options.RefreshChunks", false);
uuidConvertAmount = config.getInt("Options.UUIDConvertAmount", 5);
} }
} }
@@ -53,8 +51,4 @@ public class HiddenConfig {
public boolean resendChunksAfterBlockAbility() { public boolean resendChunksAfterBlockAbility() {
return resendChunksAfterBlockAbility; return resendChunksAfterBlockAbility;
} }
public int getUUIDConvertAmount() {
return uuidConvertAmount;
}
} }

View File

@@ -2,7 +2,6 @@ package com.gmail.nossr50.database;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.database.DatabaseType; import com.gmail.nossr50.datatypes.database.DatabaseType;
@@ -68,42 +67,19 @@ public interface DatabaseManager {
* *
* @param playerName The name of the player to be added to the database * @param playerName The name of the player to be added to the database
*/ */
public void newUser(String playerName, String uuid); public void newUser(String playerName);
/** /**
* Load a player from the database. * Load a player from the database.
* *
* @deprecated replaced by {@link #loadPlayerProfile(String playerName, UUID uuid, boolean createNew)}
*
* @param playerName The name of the player to load from the database * @param playerName The name of the player to load from the database
* @param createNew Whether to create a new record if the player is not * @param createNew Whether to create a new record if the player is not
* found * found
* @return The player's data, or an unloaded PlayerProfile if not found * @return The player's data, or an unloaded PlayerProfile if not found
* and createNew is false * and createNew is false
*/ */
@Deprecated
public PlayerProfile loadPlayerProfile(String playerName, boolean createNew); public PlayerProfile loadPlayerProfile(String playerName, boolean createNew);
/**
* Load a player from the database.
*
* @param uuid The uuid of the player to load from the database
* @return The player's data, or an unloaded PlayerProfile if not found
*/
public PlayerProfile loadPlayerProfile(UUID uuid);
/**
* Load a player from the database. Attempt to use uuid, fall back on playername
*
* @param playerName The name of the player to load from the database
* @param uuid The uuid of the player to load from the database
* @param createNew Whether to create a new record if the player is not
* found
* @return The player's data, or an unloaded PlayerProfile if not found
* and createNew is false
*/
public PlayerProfile loadPlayerProfile(String playerName, UUID uuid, boolean createNew);
/** /**
* Get all users currently stored in the database. * Get all users currently stored in the database.
* *
@@ -119,19 +95,10 @@ public interface DatabaseManager {
*/ */
public void convertUsers(DatabaseManager destination); public void convertUsers(DatabaseManager destination);
public boolean saveUserUUID(String userName, UUID uuid);
public boolean saveUserUUIDs(Map<String, UUID> fetchedUUIDs);
/** /**
* Retrieve the type of database in use. Custom databases should return CUSTOM. * Retrieve the type of database in use. Custom databases should return CUSTOM.
* *
* @return The type of database * @return The type of database
*/ */
public DatabaseType getDatabaseType(); public DatabaseType getDatabaseType();
/**
* Called when the plugin disables
*/
public void onDisable();
} }

View File

@@ -2,6 +2,7 @@ package com.gmail.nossr50.database;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
@@ -9,12 +10,10 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.EnumMap;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
@@ -23,11 +22,9 @@ import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.MobHealthbarType; import com.gmail.nossr50.datatypes.MobHealthbarType;
import com.gmail.nossr50.datatypes.database.DatabaseType; import com.gmail.nossr50.datatypes.database.DatabaseType;
import com.gmail.nossr50.datatypes.database.PlayerStat; import com.gmail.nossr50.datatypes.database.PlayerStat;
import com.gmail.nossr50.datatypes.database.UpgradeType;
import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.runnables.database.UUIDUpdateAsyncTask;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
@@ -46,10 +43,6 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
usersFile = new File(mcMMO.getUsersFilePath()); usersFile = new File(mcMMO.getUsersFilePath());
checkStructure(); checkStructure();
updateLeaderboards(); updateLeaderboards();
if (mcMMO.getUpgradeManager().shouldUpgrade(UpgradeType.ADD_UUIDS)) {
new UUIDUpdateAsyncTask(mcMMO.p, getStoredUsers()).runTaskAsynchronously(mcMMO.p);
}
} }
public void purgePowerlessUsers() { public void purgePowerlessUsers() {
@@ -98,22 +91,8 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString()); mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
} }
finally { finally {
if (in != null) { tryClose(in);
try { tryClose(out);
in.close();
}
catch (IOException e) {
// Ignore
}
}
if (out != null) {
try {
out.close();
}
catch (IOException e) {
// Ignore
}
}
} }
} }
@@ -178,22 +157,8 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString()); mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
} }
finally { finally {
if (in != null) { tryClose(in);
try { tryClose(out);
in.close();
}
catch (IOException e) {
// Ignore
}
}
if (out != null) {
try {
out.close();
}
catch (IOException e) {
// Ignore
}
}
} }
} }
@@ -231,22 +196,8 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString()); mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
} }
finally { finally {
if (in != null) { tryClose(in);
try { tryClose(out);
in.close();
}
catch (IOException e) {
// Ignore
}
}
if (out != null) {
try {
out.close();
}
catch (IOException e) {
// Ignore
}
}
} }
} }
@@ -257,7 +208,6 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
public boolean saveUser(PlayerProfile profile) { public boolean saveUser(PlayerProfile profile) {
String playerName = profile.getPlayerName(); String playerName = profile.getPlayerName();
UUID uuid = profile.getUniqueId();
BufferedReader in = null; BufferedReader in = null;
FileWriter out = null; FileWriter out = null;
@@ -272,9 +222,8 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
// While not at the end of the file // While not at the end of the file
while ((line = in.readLine()) != null) { while ((line = in.readLine()) != null) {
// Read the line in and copy it to the output if it's not the player we want to edit // Read the line in and copy it to the output it's not the player we want to edit
String[] character = line.split(":"); if (!line.split(":")[0].equalsIgnoreCase(playerName)) {
if (!character[41].equalsIgnoreCase(uuid.toString()) && !character[0].equalsIgnoreCase(playerName)) {
writer.append(line).append("\r\n"); writer.append(line).append("\r\n");
} }
else { else {
@@ -321,7 +270,6 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
writer.append(mobHealthbarType == null ? Config.getInstance().getMobHealthbarDefault().toString() : mobHealthbarType.toString()).append(":"); writer.append(mobHealthbarType == null ? Config.getInstance().getMobHealthbarDefault().toString() : mobHealthbarType.toString()).append(":");
writer.append(profile.getSkillLevel(SkillType.ALCHEMY)).append(":"); writer.append(profile.getSkillLevel(SkillType.ALCHEMY)).append(":");
writer.append(profile.getSkillXpLevel(SkillType.ALCHEMY)).append(":"); writer.append(profile.getSkillXpLevel(SkillType.ALCHEMY)).append(":");
writer.append(uuid.toString()).append(":");
writer.append("\r\n"); writer.append("\r\n");
} }
} }
@@ -336,22 +284,8 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
return false; return false;
} }
finally { finally {
if (in != null) { tryClose(in);
try { tryClose(out);
in.close();
}
catch (IOException e) {
// Ignore
}
}
if (out != null) {
try {
out.close();
}
catch (IOException e) {
// Ignore
}
}
} }
} }
} }
@@ -367,7 +301,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
public Map<SkillType, Integer> readRank(String playerName) { public Map<SkillType, Integer> readRank(String playerName) {
updateLeaderboards(); updateLeaderboards();
Map<SkillType, Integer> skills = new EnumMap<SkillType, Integer>(SkillType.class); Map<SkillType, Integer> skills = new HashMap<SkillType, Integer>();
for (SkillType skill : SkillType.NON_CHILD_SKILLS) { for (SkillType skill : SkillType.NON_CHILD_SKILLS) {
skills.put(skill, getPlayerRank(playerName, playerStatHash.get(skill))); skills.put(skill, getPlayerRank(playerName, playerStatHash.get(skill)));
@@ -378,7 +312,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
return skills; return skills;
} }
public void newUser(String playerName, String uuid) { public void newUser(String playerName) {
BufferedWriter out = null; BufferedWriter out = null;
synchronized (fileWritingLock) { synchronized (fileWritingLock) {
try { try {
@@ -427,8 +361,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
out.append(Config.getInstance().getMobHealthbarDefault().toString()).append(":"); // Mob Healthbar HUD out.append(Config.getInstance().getMobHealthbarDefault().toString()).append(":"); // Mob Healthbar HUD
out.append("0:"); // Alchemy out.append("0:"); // Alchemy
out.append("0:"); // AlchemyXp out.append("0:"); // AlchemyXp
out.append(uuid).append(":"); // UUID
// Add more in the same format as the line above // Add more in the same format as the line above
out.newLine(); out.newLine();
@@ -437,32 +370,12 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
e.printStackTrace(); e.printStackTrace();
} }
finally { finally {
if (out != null) { tryClose(out);
try {
out.close();
}
catch (IOException e) {
// Ignore
}
}
} }
} }
} }
@Deprecated
public PlayerProfile loadPlayerProfile(String playerName, boolean create) { public PlayerProfile loadPlayerProfile(String playerName, boolean create) {
return loadPlayerProfile(playerName, "", false);
}
public PlayerProfile loadPlayerProfile(UUID uuid) {
return loadPlayerProfile("", uuid.toString(), false);
}
public PlayerProfile loadPlayerProfile(String playerName, UUID uuid, boolean create) {
return loadPlayerProfile(playerName, uuid.toString(), create);
}
private PlayerProfile loadPlayerProfile(String playerName, String uuid, boolean create) {
BufferedReader in = null; BufferedReader in = null;
String usersFilePath = mcMMO.getUsersFilePath(); String usersFilePath = mcMMO.getUsersFilePath();
@@ -476,14 +389,8 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
// 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(":");
if (!character[41].equalsIgnoreCase(uuid) && !character[0].equalsIgnoreCase(playerName)) {
continue;
}
// Update playerName in database after name change
if (!character[0].equalsIgnoreCase(playerName)) { if (!character[0].equalsIgnoreCase(playerName)) {
mcMMO.p.debug("Name change detected: " + character[0] + " => " + playerName); continue;
character[0] = playerName;
} }
return loadFromLine(character); return loadFromLine(character);
@@ -491,13 +398,8 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
// Didn't find the player, create a new one // Didn't find the player, create a new one
if (create) { if (create) {
if (uuid.isEmpty()) { newUser(playerName);
newUser(playerName, uuid); return new PlayerProfile(playerName, true);
return new PlayerProfile(playerName, true);
}
newUser(playerName, uuid);
return new PlayerProfile(playerName, UUID.fromString(uuid), true);
} }
} }
catch (Exception e) { catch (Exception e) {
@@ -511,18 +413,14 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
in.close(); in.close();
} }
catch (IOException e) { catch (IOException e) {
// Ignore e.printStackTrace();
} }
} }
} }
} }
// Return unloaded profile // Return unloaded profile
if (uuid.isEmpty()) { return new PlayerProfile(playerName);
return new PlayerProfile(playerName);
}
return new PlayerProfile(playerName, UUID.fromString(uuid));
} }
public void convertUsers(DatabaseManager destination) { public void convertUsers(DatabaseManager destination) {
@@ -554,131 +452,11 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
e.printStackTrace(); e.printStackTrace();
} }
finally { finally {
if (in != null) { tryClose(in);
try {
in.close();
}
catch (IOException e) {
// Ignore
}
}
} }
} }
} }
public boolean saveUserUUID(String userName, UUID uuid) {
boolean worked = false;
BufferedReader in = null;
FileWriter out = null;
String usersFilePath = mcMMO.getUsersFilePath();
synchronized (fileWritingLock) {
try {
in = new BufferedReader(new FileReader(usersFilePath));
StringBuilder writer = new StringBuilder();
String line;
while ((line = in.readLine()) != null) {
String[] character = line.split(":");
if (!worked && character[0].equalsIgnoreCase(userName)) {
if (character.length < 42) {
mcMMO.p.getLogger().severe("Could not update UUID for " + userName + "!");
mcMMO.p.getLogger().severe("Database entry is invalid.");
break;
}
line = line.replace(character[41], uuid.toString());
worked = true;
}
writer.append(line).append("\r\n");
}
out = new FileWriter(usersFilePath); // Write out the new file
out.write(writer.toString());
}
catch (Exception e) {
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
}
finally {
if (in != null) {
try {
in.close();
}
catch (IOException e) {
// Ignore
}
}
if (out != null) {
try {
out.close();
}
catch (IOException e) {
// Ignore
}
}
}
}
return worked;
}
public boolean saveUserUUIDs(Map<String, UUID> fetchedUUIDs) {
BufferedReader in = null;
FileWriter out = null;
String usersFilePath = mcMMO.getUsersFilePath();
synchronized (fileWritingLock) {
try {
in = new BufferedReader(new FileReader(usersFilePath));
StringBuilder writer = new StringBuilder();
String line;
while (((line = in.readLine()) != null) && !fetchedUUIDs.isEmpty()) {
String[] character = line.split(":");
if (fetchedUUIDs.containsKey(character[0])) {
if (character.length < 42) {
mcMMO.p.getLogger().severe("Could not update UUID for " + character[0] + "!");
mcMMO.p.getLogger().severe("Database entry is invalid.");
return false;
}
line = line.replace(character[41], fetchedUUIDs.remove(character[0]).toString());
}
writer.append(line).append("\r\n");
}
out = new FileWriter(usersFilePath); // Write out the new file
out.write(writer.toString());
}
catch (Exception e) {
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
}
finally {
if (in != null) {
try {
in.close();
}
catch (IOException e) {
// Ignore
}
}
if (out != null) {
try {
out.close();
}
catch (IOException e) {
// Ignore
}
}
}
}
return true;
}
public List<String> getStoredUsers() { public List<String> getStoredUsers() {
ArrayList<String> users = new ArrayList<String>(); ArrayList<String> users = new ArrayList<String>();
BufferedReader in = null; BufferedReader in = null;
@@ -699,14 +477,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
e.printStackTrace(); e.printStackTrace();
} }
finally { finally {
if (in != null) { tryClose(in);
try {
in.close();
}
catch (IOException e) {
// Ignore
}
}
} }
} }
return users; return users;
@@ -776,14 +547,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " during user " + playerName + " (Are you sure you formatted it correctly?) " + e.toString()); mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " during user " + playerName + " (Are you sure you formatted it correctly?) " + e.toString());
} }
finally { finally {
if (in != null) { tryClose(in);
try {
in.close();
}
catch (IOException e) {
// Ignore
}
}
} }
} }
@@ -833,7 +597,6 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
in = new BufferedReader(new FileReader(usersFilePath)); in = new BufferedReader(new FileReader(usersFilePath));
StringBuilder writer = new StringBuilder(); StringBuilder writer = new StringBuilder();
String line; String line;
HashSet<String> usernames = new HashSet<String>();
HashSet<String> players = new HashSet<String>(); HashSet<String> players = new HashSet<String>();
while ((line = in.readLine()) != null) { while ((line = in.readLine()) != null) {
@@ -848,13 +611,8 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
} }
String[] character = line.split(":"); String[] character = line.split(":");
// Prevent the same username from being present multiple times
if (!usernames.add(character[0])) {
continue;
}
// Prevent the same player from being present multiple times // Prevent the same player from being present multiple times
if (character.length == 42 && (!character[41].isEmpty() && !players.add(character[41]))) { if (!players.add(character[0])) {
continue; continue;
} }
@@ -886,7 +644,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
} }
// If they're valid, rewrite them to the file. // If they're valid, rewrite them to the file.
if (character.length == 42) { if (character.length == 41) {
writer.append(line).append("\r\n"); writer.append(line).append("\r\n");
continue; continue;
} }
@@ -940,25 +698,16 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
oldVersion = "1.4.08"; oldVersion = "1.4.08";
} }
} }
if (character.length <= 41) {
// Addition of UUIDs
// Version 1.5.01
// Add a space because otherwise it gets removed
newLine.append(" :");
if (oldVersion == null) {
oldVersion = "1.5.01";
}
}
// Remove any blanks that shouldn't be there, and validate the other fields // Remove any blanks that shouldn't be there, and validate the other fields
String[] newCharacter = newLine.toString().split(":"); String[] newCharacter = newLine.toString().split(":");
boolean corrupted = false; boolean corrupted = false;
for (int i = 0; i < newCharacter.length; i++) { for (int i = 0; i < newCharacter.length; i++) {
if (newCharacter[i].isEmpty() && !(i == 2 || i == 3 || i == 23 || i == 33 || i == 41)) { if (newCharacter[i].isEmpty() && !(i == 2 || i == 3 || i == 23 || i == 33)) {
corrupted = true; corrupted = true;
if (newCharacter.length != 42) { if (newCharacter.length != 41) {
newCharacter = (String[]) ArrayUtils.remove(newCharacter, i); newCharacter = (String[]) ArrayUtils.remove(newCharacter, i);
} }
else { else {
@@ -979,7 +728,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
newCharacter[i] = Config.getInstance().getMobHealthbarDefault().toString(); newCharacter[i] = Config.getInstance().getMobHealthbarDefault().toString();
} }
if (!StringUtils.isInt(newCharacter[i]) && !(i == 0 || i == 2 || i == 3 || i == 23 || i == 33 || i == 38 || i == 41)) { if (!StringUtils.isInt(newCharacter[i]) && !(i == 0 || i == 2 || i == 3 || i == 23 || i == 33 || i == 38)) {
corrupted = true; corrupted = true;
newCharacter[i] = "0"; newCharacter[i] = "0";
} }
@@ -987,15 +736,11 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
if (corrupted) { if (corrupted) {
mcMMO.p.debug("Updating corrupted database line for player " + newCharacter[0]); mcMMO.p.debug("Updating corrupted database line for player " + newCharacter[0]);
newLine = new StringBuilder(org.apache.commons.lang.StringUtils.join(newCharacter, ":"));
} }
if (oldVersion != null) { if (oldVersion != null) {
mcMMO.p.debug("Updating database line from before version " + oldVersion + " for player " + character[0]); mcMMO.p.debug("Updating database line for player " + character[0] + " from before version " + oldVersion);
}
if (corrupted || oldVersion != null) {
newLine = new StringBuilder(org.apache.commons.lang.StringUtils.join(newCharacter, ":"));
newLine = newLine.append(":");
} }
writer.append(newLine).append("\r\n"); writer.append(newLine).append("\r\n");
@@ -1009,32 +754,10 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString()); mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
} }
finally { finally {
if (in != null) { tryClose(in);
try { tryClose(out);
in.close();
}
catch (IOException e) {
// Ignore
}
}
if (out != null) {
try {
out.close();
}
catch (IOException e) {
// Ignore
}
}
} }
} }
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_FISHING);
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_BLAST_MINING_COOLDOWN);
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_SQL_INDEXES);
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_MOB_HEALTHBARS);
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.DROP_SQL_PARTY_NAMES);
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.DROP_SPOUT);
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_ALCHEMY);
return; return;
} }
@@ -1049,6 +772,18 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
} }
} }
private void tryClose(Closeable c) {
if (c == null) {
return;
}
try {
c.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
private Integer getPlayerRank(String playerName, List<PlayerStat> statsList) { private Integer getPlayerRank(String playerName, List<PlayerStat> statsList) {
if (statsList == null) { if (statsList == null) {
return null; return null;
@@ -1081,8 +816,8 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
private PlayerProfile loadFromLine(String[] character) { private PlayerProfile loadFromLine(String[] character) {
Map<SkillType, Integer> skills = getSkillMapFromLine(character); // Skill levels Map<SkillType, Integer> skills = getSkillMapFromLine(character); // Skill levels
Map<SkillType, Float> skillsXp = new EnumMap<SkillType, Float>(SkillType.class); // Skill & XP Map<SkillType, Float> skillsXp = new HashMap<SkillType, Float>(); // Skill & XP
Map<AbilityType, Integer> skillsDATS = new EnumMap<AbilityType, Integer>(AbilityType.class); // Ability & Cooldown Map<AbilityType, Integer> skillsDATS = new HashMap<AbilityType, Integer>(); // Ability & Cooldown
MobHealthbarType mobHealthbarType; MobHealthbarType mobHealthbarType;
// TODO on updates, put new values in a try{} ? // TODO on updates, put new values in a try{} ?
@@ -1121,19 +856,11 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
mobHealthbarType = Config.getInstance().getMobHealthbarDefault(); mobHealthbarType = Config.getInstance().getMobHealthbarDefault();
} }
UUID uuid; return new PlayerProfile(character[0], skills, skillsXp, skillsDATS, mobHealthbarType);
try {
uuid = UUID.fromString(character[41]);
}
catch (Exception e) {
uuid = null;
}
return new PlayerProfile(character[0], uuid, skills, skillsXp, skillsDATS, mobHealthbarType);
} }
private Map<SkillType, Integer> getSkillMapFromLine(String[] character) { private Map<SkillType, Integer> getSkillMapFromLine(String[] character) {
Map<SkillType, Integer> skills = new EnumMap<SkillType, Integer>(SkillType.class); // Skill & Level Map<SkillType, Integer> skills = new HashMap<SkillType, Integer>(); // Skill & Level
skills.put(SkillType.TAMING, Integer.valueOf(character[24])); skills.put(SkillType.TAMING, Integer.valueOf(character[24]));
skills.put(SkillType.MINING, Integer.valueOf(character[1])); skills.put(SkillType.MINING, Integer.valueOf(character[1]));
@@ -1155,7 +882,4 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
public DatabaseType getDatabaseType() { public DatabaseType getDatabaseType() {
return DatabaseType.FLATFILE; return DatabaseType.FLATFILE;
} }
@Override
public void onDisable() { }
} }

View File

@@ -0,0 +1,13 @@
package com.gmail.nossr50.datatypes.database;
public enum DatabaseUpdateType {
FISHING,
BLAST_MINING,
INDEX,
MOB_HEALTHBARS,
PARTY_NAMES,
KILL_ORPHANS,
DROPPED_SPOUT,
ALCHEMY
;
}

View File

@@ -1,12 +0,0 @@
package com.gmail.nossr50.datatypes.database;
public enum UpgradeType {
ADD_FISHING,
ADD_BLAST_MINING_COOLDOWN,
ADD_SQL_INDEXES,
ADD_MOB_HEALTHBARS,
DROP_SQL_PARTY_NAMES,
DROP_SPOUT,
ADD_ALCHEMY,
ADD_UUIDS;
}

View File

@@ -3,7 +3,6 @@ package com.gmail.nossr50.datatypes.player;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
@@ -93,20 +92,15 @@ public class McMMOPlayer {
private boolean isUsingUnarmed; private boolean isUsingUnarmed;
private final FixedMetadataValue playerMetadata; private final FixedMetadataValue playerMetadata;
public McMMOPlayer(Player player, PlayerProfile profile) { public McMMOPlayer(Player player) {
String playerName = player.getName(); String playerName = player.getName();
UUID uuid = player.getUniqueId();
this.player = player; this.player = player;
playerMetadata = new FixedMetadataValue(mcMMO.p, playerName); playerMetadata = new FixedMetadataValue(mcMMO.p, playerName);
this.profile = profile; profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, true);
party = PartyManager.getPlayerParty(playerName); party = PartyManager.getPlayerParty(playerName);
ptpRecord = new PartyTeleportRecord(); ptpRecord = new PartyTeleportRecord();
if (profile.getUniqueId() == null) {
profile.setUniqueId(uuid);
}
/* /*
* I'm using this method because it makes code shorter and safer (we don't have to add all SkillTypes manually), * I'm using this method because it makes code shorter and safer (we don't have to add all SkillTypes manually),
* but I actually have no idea about the performance impact, if there is any. * but I actually have no idea about the performance impact, if there is any.
@@ -130,6 +124,69 @@ public class McMMOPlayer {
for (ToolType toolType : ToolType.values()) { for (ToolType toolType : ToolType.values()) {
toolMode.put(toolType, false); toolMode.put(toolType, false);
} }
if (!profile.isLoaded()) {
mcMMO.p.getLogger().warning("Unable to load the PlayerProfile for " + playerName + ". Will retry over the next several seconds.");
new RetryProfileLoadingTask().runTaskTimerAsynchronously(mcMMO.p, 11L, 31L);
}
}
private class RetryProfileLoadingTask extends BukkitRunnable {
private static final int MAX_TRIES = 5;
private final String playerName = McMMOPlayer.this.player.getName();
private int attempt = 0;
// WARNING: ASYNC TASK
// DO NOT MODIFY THE McMMOPLAYER FROM THIS CODE
@Override
public void run() {
// Quit if they logged out
if (!player.isOnline()) {
mcMMO.p.getLogger().info("Aborting profile loading recovery for " + playerName + " - player logged out");
this.cancel();
return;
}
// Send the message that we're doing the recovery
if (attempt == 0) {
player.sendMessage(LocaleLoader.getString("Recovery.Notice"));
}
// Increment attempt counter and try
attempt++;
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, true);
// If successful, schedule the apply
if (profile.isLoaded()) {
new ApplySuccessfulProfile(profile).runTask(mcMMO.p);
player.sendMessage(LocaleLoader.getString("Recovery.Success"));
this.cancel();
return;
}
// If we've failed five times, give up
if (attempt >= MAX_TRIES) {
mcMMO.p.getLogger().severe("Giving up on attempting to load the PlayerProfile for " + playerName);
mcMMO.p.getServer().broadcast(LocaleLoader.getString("Recovery.AdminFailureNotice", playerName), Server.BROADCAST_CHANNEL_ADMINISTRATIVE);
player.sendMessage(LocaleLoader.getString("Recovery.Failure").split("\n"));
this.cancel();
return;
}
}
}
private class ApplySuccessfulProfile extends BukkitRunnable {
private final PlayerProfile profile;
private ApplySuccessfulProfile(PlayerProfile profile) {
this.profile = profile;
}
// Synchronized task
// No database access permitted
@Override
public void run() {
McMMOPlayer.this.profile = profile;
}
} }
public AcrobaticsManager getAcrobaticsManager() { public AcrobaticsManager getAcrobaticsManager() {

View File

@@ -3,7 +3,6 @@ package com.gmail.nossr50.datatypes.player;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
@@ -20,7 +19,6 @@ import com.google.common.collect.ImmutableMap;
public class PlayerProfile { public class PlayerProfile {
private final String playerName; private final String playerName;
private UUID uuid;
private boolean loaded; private boolean loaded;
private volatile boolean changed; private volatile boolean changed;
@@ -32,13 +30,7 @@ public class PlayerProfile {
private final Map<SkillType, Float> skillsXp = new HashMap<SkillType, Float>(); // Skill & XP private final Map<SkillType, Float> skillsXp = new HashMap<SkillType, Float>(); // Skill & XP
private final Map<AbilityType, Integer> abilityDATS = new HashMap<AbilityType, Integer>(); // Ability & Cooldown private final Map<AbilityType, Integer> abilityDATS = new HashMap<AbilityType, Integer>(); // Ability & Cooldown
@Deprecated
public PlayerProfile(String playerName) { public PlayerProfile(String playerName) {
this(playerName, null);
}
public PlayerProfile(String playerName, UUID uuid) {
this.uuid = uuid;
this.playerName = playerName; this.playerName = playerName;
mobHealthbarType = Config.getInstance().getMobHealthbarDefault(); mobHealthbarType = Config.getInstance().getMobHealthbarDefault();
@@ -53,20 +45,13 @@ public class PlayerProfile {
} }
} }
@Deprecated
public PlayerProfile(String playerName, boolean isLoaded) { public PlayerProfile(String playerName, boolean isLoaded) {
this(playerName); this(playerName);
this.loaded = isLoaded; this.loaded = isLoaded;
} }
public PlayerProfile(String playerName, UUID uuid, boolean isLoaded) { public PlayerProfile(String playerName, Map<SkillType, Integer> levelData, Map<SkillType, Float> xpData, Map<AbilityType, Integer> cooldownData, MobHealthbarType mobHealthbarType) {
this(playerName, uuid);
this.loaded = isLoaded;
}
public PlayerProfile(String playerName, UUID uuid, Map<SkillType, Integer> levelData, Map<SkillType, Float> xpData, Map<AbilityType, Integer> cooldownData, MobHealthbarType mobHealthbarType) {
this.playerName = playerName; this.playerName = playerName;
this.uuid = uuid;
this.mobHealthbarType = mobHealthbarType; this.mobHealthbarType = mobHealthbarType;
skills.putAll(levelData); skills.putAll(levelData);
@@ -86,11 +71,11 @@ public class PlayerProfile {
} }
// TODO should this part be synchronized? // TODO should this part be synchronized?
PlayerProfile profileCopy = new PlayerProfile(playerName, uuid, ImmutableMap.copyOf(skills), ImmutableMap.copyOf(skillsXp), ImmutableMap.copyOf(abilityDATS), mobHealthbarType); PlayerProfile profileCopy = new PlayerProfile(playerName, ImmutableMap.copyOf(skills), ImmutableMap.copyOf(skillsXp), ImmutableMap.copyOf(abilityDATS), mobHealthbarType);
changed = !mcMMO.getDatabaseManager().saveUser(profileCopy); changed = !mcMMO.getDatabaseManager().saveUser(profileCopy);
if (changed) { if (changed) {
mcMMO.p.getLogger().warning("PlayerProfile saving failed for player: " + playerName + " " + uuid); mcMMO.p.getLogger().warning("PlayerProfile for " + playerName + " failed to save");
} }
} }
@@ -98,16 +83,6 @@ public class PlayerProfile {
return playerName; return playerName;
} }
public UUID getUniqueId() {
return uuid;
}
public void setUniqueId(UUID uuid) {
changed = true;
this.uuid = uuid;
}
public boolean isLoaded() { public boolean isLoaded() {
return loaded; return loaded;
} }

View File

@@ -7,7 +7,6 @@ import java.util.Map.Entry;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
public class AlchemyPotion { public class AlchemyPotion {
@@ -51,10 +50,6 @@ public class AlchemyPotion {
return potion; return potion;
} }
public Potion toPotion(int amount) {
return Potion.fromItemStack(this.toItemStack(amount));
}
public short getDataValue() { public short getDataValue() {
return dataValue; return dataValue;
} }

View File

@@ -1,5 +1,7 @@
package com.gmail.nossr50.datatypes.skills.alchemy; package com.gmail.nossr50.datatypes.skills.alchemy;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.Potion; import org.bukkit.potion.Potion;
public enum PotionStage { public enum PotionStage {
@@ -39,11 +41,11 @@ public enum PotionStage {
} }
private static boolean isWaterBottle(AlchemyPotion input) { private static boolean isWaterBottle(AlchemyPotion input) {
return input.getDataValue() == 0; return input.getEffects().isEmpty();
} }
public static PotionStage getPotionStage(AlchemyPotion alchemyPotion) { public static PotionStage getPotionStage(AlchemyPotion alchemyPotion) {
Potion potion = alchemyPotion.toPotion(1); Potion potion = Potion.fromItemStack(new ItemStack(Material.POTION, 1, alchemyPotion.getDataValue()));
int stage = 1; int stage = 1;

View File

@@ -1,36 +1,20 @@
package com.gmail.nossr50.events.fake; package com.gmail.nossr50.events.fake;
import java.util.EnumMap;
import java.util.Map; import java.util.Map;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import com.google.common.base.Function;
import com.google.common.base.Functions;
/** /**
* Called when mcMMO applies damage from an entity due to special abilities. * Called when mcMMO applies damage from an entity due to special abilities.
*/ */
public class FakeEntityDamageByEntityEvent extends EntityDamageByEntityEvent { public class FakeEntityDamageByEntityEvent extends EntityDamageByEntityEvent {
public FakeEntityDamageByEntityEvent(Entity damager, Entity damagee, DamageCause cause, final Map<DamageModifier, Double> modifiers) { public FakeEntityDamageByEntityEvent(Entity damager, Entity damagee, DamageCause cause, final Map<DamageModifier, Double> modifiers) {
super(damager, damagee, cause, modifiers, getFunctionModifiers(modifiers)); super(damager, damagee, cause, modifiers);
} }
@Deprecated @Deprecated
public FakeEntityDamageByEntityEvent(Entity damager, Entity damagee, DamageCause cause, double damage) { public FakeEntityDamageByEntityEvent(Entity damager, Entity damagee, DamageCause cause, double damage) {
super(damager, damagee, cause, damage); super(damager, damagee, cause, damage);
} }
public static EnumMap<DamageModifier, Function<? super Double, Double>> getFunctionModifiers(Map<DamageModifier, Double> modifiers) {
EnumMap<DamageModifier, Function<? super Double, Double>> modifierFunctions = new EnumMap<DamageModifier, Function<? super Double, Double>>(DamageModifier.class);
Function<? super Double, Double> ZERO = Functions.constant(-0.0);
for (DamageModifier modifier : modifiers.keySet()) {
modifierFunctions.put(modifier, ZERO);
}
return modifierFunctions;
}
} }

View File

@@ -1,36 +1,20 @@
package com.gmail.nossr50.events.fake; package com.gmail.nossr50.events.fake;
import java.util.EnumMap;
import java.util.Map; import java.util.Map;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import com.google.common.base.Function;
import com.google.common.base.Functions;
/** /**
* Called when mcMMO applies damage due to special abilities. * Called when mcMMO applies damage due to special abilities.
*/ */
public class FakeEntityDamageEvent extends EntityDamageEvent { public class FakeEntityDamageEvent extends EntityDamageEvent {
public FakeEntityDamageEvent(Entity damagee, DamageCause cause, final Map<DamageModifier, Double> modifiers) { public FakeEntityDamageEvent(Entity damagee, DamageCause cause, final Map<DamageModifier, Double> modifiers) {
super(damagee, cause, modifiers, getFunctionModifiers(modifiers)); super(damagee, cause, modifiers);
} }
@Deprecated @Deprecated
public FakeEntityDamageEvent(Entity damagee, DamageCause cause, double damage) { public FakeEntityDamageEvent(Entity damagee, DamageCause cause, double damage) {
super(damagee, cause, damage); super(damagee, cause, damage);
} }
public static EnumMap<DamageModifier, Function<? super Double, Double>> getFunctionModifiers(Map<DamageModifier, Double> modifiers) {
EnumMap<DamageModifier, Function<? super Double, Double>> modifierFunctions = new EnumMap<DamageModifier, Function<? super Double, Double>>(DamageModifier.class);
Function<? super Double, Double> ZERO = Functions.constant(-0.0);
for (DamageModifier modifier : modifiers.keySet()) {
modifierFunctions.put(modifier, ZERO);
}
return modifierFunctions;
}
} }

View File

@@ -53,7 +53,6 @@ import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
import com.gmail.nossr50.skills.archery.Archery; import com.gmail.nossr50.skills.archery.Archery;
import com.gmail.nossr50.skills.fishing.Fishing; import com.gmail.nossr50.skills.fishing.Fishing;
import com.gmail.nossr50.skills.herbalism.Herbalism; import com.gmail.nossr50.skills.herbalism.Herbalism;
import com.gmail.nossr50.skills.mining.BlastMining;
import com.gmail.nossr50.skills.mining.MiningManager; import com.gmail.nossr50.skills.mining.MiningManager;
import com.gmail.nossr50.skills.taming.Taming; import com.gmail.nossr50.skills.taming.Taming;
import com.gmail.nossr50.skills.taming.TamingManager; import com.gmail.nossr50.skills.taming.TamingManager;
@@ -110,9 +109,7 @@ public class EntityListener implements Listener {
public void onEntityChangeBlock(EntityChangeBlockEvent event) { public void onEntityChangeBlock(EntityChangeBlockEvent event) {
Block block = event.getBlock(); Block block = event.getBlock();
// When the event is fired for the falling block that changes back to a normal block if (!BlockUtils.shouldBeWatched(block.getState())) {
// event.getBlock().getType() returns AIR
if (!BlockUtils.shouldBeWatched(block.getState()) && block.getType() != Material.AIR) {
return; return;
} }
@@ -193,11 +190,6 @@ public class EntityListener implements Listener {
attacker = (Entity) animalTamer; attacker = (Entity) animalTamer;
} }
} }
else if (attacker instanceof TNTPrimed && defender instanceof Player) {
if (BlastMining.processBlastMiningExplosion(event, (TNTPrimed) attacker, (Player) defender)) {
return;
}
}
if (defender instanceof Player && attacker instanceof Player) { if (defender instanceof Player && attacker instanceof Player) {
Player defendingPlayer = (Player) defender; Player defendingPlayer = (Player) defender;
@@ -291,6 +283,19 @@ public class EntityListener implements Listener {
} }
break; break;
case BLOCK_EXPLOSION:
MiningManager miningManager = mcMMOPlayer.getMiningManager();
if (miningManager.canUseDemolitionsExpertise()) {
event.setDamage(miningManager.processDemolitionsExpertise(event.getDamage()));
if (event.getFinalDamage() == 0) {
event.setCancelled(true);
return;
}
}
break;
default: default:
break; break;
} }

View File

@@ -41,7 +41,7 @@ import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.ShareHandler; import com.gmail.nossr50.party.ShareHandler;
import com.gmail.nossr50.runnables.player.PlayerProfileLoadingTask; import com.gmail.nossr50.runnables.commands.McScoreboardKeepTask;
import com.gmail.nossr50.runnables.skills.BleedTimerTask; import com.gmail.nossr50.runnables.skills.BleedTimerTask;
import com.gmail.nossr50.skills.fishing.FishingManager; import com.gmail.nossr50.skills.fishing.FishingManager;
import com.gmail.nossr50.skills.herbalism.HerbalismManager; import com.gmail.nossr50.skills.herbalism.HerbalismManager;
@@ -332,11 +332,9 @@ public class PlayerListener implements Listener {
} }
if ((mcMMOPlayer.isUsingUnarmed() && ItemUtils.isSharable(dropStack)) || mcMMOPlayer.getAbilityMode(AbilityType.BERSERK)) { if ((mcMMOPlayer.isUsingUnarmed() && ItemUtils.isSharable(dropStack)) || mcMMOPlayer.getAbilityMode(AbilityType.BERSERK)) {
boolean pickupSuccess = Unarmed.handleItemPickup(player.getInventory(), drop); event.setCancelled(Unarmed.handleItemPickup(player.getInventory(), drop));
boolean cancel = Config.getInstance().getUnarmedItemPickupDisabled() || pickupSuccess;
event.setCancelled(cancel);
if (pickupSuccess) { if (event.isCancelled()) {
player.playSound(player.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.getPopPitch()); player.playSound(player.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.getPopPitch());
player.updateInventory(); player.updateInventory();
return; return;
@@ -387,7 +385,9 @@ public class PlayerListener implements Listener {
return; return;
} }
new PlayerProfileLoadingTask(player).runTaskTimerAsynchronously(mcMMO.p, 1, 20); // 1 Tick delay to ensure the player is marked as online before we begin loading McMMOPlayer mcMMOPlayer = UserManager.addUser(player);
mcMMOPlayer.actualizeRespawnATS();
ScoreboardManager.setupPlayer(player);
if (Config.getInstance().getMOTDEnabled() && Permissions.motd(player)) { if (Config.getInstance().getMOTDEnabled() && Permissions.motd(player)) {
Motd.displayAll(player); Motd.displayAll(player);
@@ -401,6 +401,11 @@ public class PlayerListener implements Listener {
player.sendMessage(LocaleLoader.getString("UpdateChecker.Outdated")); player.sendMessage(LocaleLoader.getString("UpdateChecker.Outdated"));
player.sendMessage(LocaleLoader.getString("UpdateChecker.NewAvailable")); player.sendMessage(LocaleLoader.getString("UpdateChecker.NewAvailable"));
} }
if (Config.getInstance().getShowStatsAfterLogin()) {
ScoreboardManager.enablePlayerStatsScoreboard(player);
new McScoreboardKeepTask(player).runTaskLater(mcMMO.p, 1 * Misc.TICK_CONVERSION_FACTOR);
}
} }
/** /**

View File

@@ -38,7 +38,6 @@ import com.gmail.nossr50.runnables.UpdaterResultAsyncTask;
import com.gmail.nossr50.runnables.backups.CleanBackupsTask; import com.gmail.nossr50.runnables.backups.CleanBackupsTask;
import com.gmail.nossr50.runnables.database.UserPurgeTask; import com.gmail.nossr50.runnables.database.UserPurgeTask;
import com.gmail.nossr50.runnables.party.PartyAutoKickTask; import com.gmail.nossr50.runnables.party.PartyAutoKickTask;
import com.gmail.nossr50.runnables.player.PlayerProfileLoadingTask;
import com.gmail.nossr50.runnables.player.PowerLevelUpdatingTask; import com.gmail.nossr50.runnables.player.PowerLevelUpdatingTask;
import com.gmail.nossr50.runnables.skills.BleedTimerTask; import com.gmail.nossr50.runnables.skills.BleedTimerTask;
import com.gmail.nossr50.skills.alchemy.Alchemy; import com.gmail.nossr50.skills.alchemy.Alchemy;
@@ -61,7 +60,6 @@ import com.gmail.nossr50.util.commands.CommandRegistrationManager;
import com.gmail.nossr50.util.experience.FormulaManager; import com.gmail.nossr50.util.experience.FormulaManager;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager; import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
import com.gmail.nossr50.util.upgrade.UpgradeManager;
import net.shatteredlands.shatt.backup.ZipLibrary; import net.shatteredlands.shatt.backup.ZipLibrary;
@@ -74,7 +72,6 @@ public class mcMMO extends JavaPlugin {
private static DatabaseManager databaseManager; private static DatabaseManager databaseManager;
private static FormulaManager formulaManager; private static FormulaManager formulaManager;
private static HolidayManager holidayManager; private static HolidayManager holidayManager;
private static UpgradeManager upgradeManager;
/* File Paths */ /* File Paths */
private static String mainDirectory; private static String mainDirectory;
@@ -132,8 +129,6 @@ public class mcMMO extends JavaPlugin {
PluginManager pluginManager = getServer().getPluginManager(); PluginManager pluginManager = getServer().getPluginManager();
healthBarPluginEnabled = pluginManager.getPlugin("HealthBar") != null; healthBarPluginEnabled = pluginManager.getPlugin("HealthBar") != null;
upgradeManager = new UpgradeManager();
setupFilePaths(); setupFilePaths();
modManager = new ModManager(); modManager = new ModManager();
@@ -168,7 +163,8 @@ public class mcMMO extends JavaPlugin {
holidayManager = new HolidayManager(); holidayManager = new HolidayManager();
for (Player player : getServer().getOnlinePlayers()) { for (Player player : getServer().getOnlinePlayers()) {
new PlayerProfileLoadingTask(player).runTaskTimerAsynchronously(mcMMO.p, 1, 20); // 1 Tick delay to ensure the player is marked as online before we begin loading UserManager.addUser(player); // In case of reload add all users back into UserManager
ScoreboardManager.setupPlayer(player);
} }
debug("Version " + getDescription().getVersion() + " is enabled!"); debug("Version " + getDescription().getVersion() + " is enabled!");
@@ -242,7 +238,6 @@ public class mcMMO extends JavaPlugin {
} }
} }
databaseManager.onDisable();
debug("Was disabled."); // How informative! debug("Was disabled."); // How informative!
} }
@@ -314,10 +309,6 @@ public class mcMMO extends JavaPlugin {
return modManager; return modManager;
} }
public static UpgradeManager getUpgradeManager() {
return upgradeManager;
}
@Deprecated @Deprecated
public static void setDatabaseManager(DatabaseManager databaseManager) { public static void setDatabaseManager(DatabaseManager databaseManager) {
mcMMO.databaseManager = databaseManager; mcMMO.databaseManager = databaseManager;

View File

@@ -0,0 +1,39 @@
package com.gmail.nossr50.runnables.database;
import java.lang.ref.WeakReference;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.database.SQLDatabaseManager;
/**
* This task is in charge of sending a MySQL ping over the MySQL connection
* every hour to prevent the connection from timing out and losing players'
* data when they join.
* <p/>
* A WeakReference is used to keep the database instance, because
* {@link com.gmail.nossr50.commands.database.ConvertDatabaseCommand database
* conversion} may create a SQLDatabaseManager that will be thrown out. If a
* normal reference was used, the conversion would cause a combined data and
* resource leak through this task.
*/
public class SQLDatabaseKeepaliveTask extends BukkitRunnable {
WeakReference<SQLDatabaseManager> databaseInstance;
public SQLDatabaseKeepaliveTask(SQLDatabaseManager dbman) {
databaseInstance = new WeakReference<SQLDatabaseManager>(dbman);
}
public void run() {
SQLDatabaseManager dbman = databaseInstance.get();
if (dbman != null) {
dbman.checkConnected();
}
else {
// This happens when the database was started for a conversion,
// or discarded by its creator for any other reason. If this code
// was not present, we would leak the connection resources.
this.cancel();
}
}
}

View File

@@ -0,0 +1,22 @@
package com.gmail.nossr50.runnables.database;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.database.SQLDatabaseManager;
import com.gmail.nossr50.util.player.UserManager;
public class SQLReconnectTask extends BukkitRunnable {
@Override
public void run() {
if (((SQLDatabaseManager) mcMMO.getDatabaseManager()).checkConnected()) {
UserManager.saveAll(); // Save all profiles
UserManager.clearAll(); // Clear the profiles
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
UserManager.addUser(player); // Add in new profiles, forcing them to 'load' again from MySQL
}
}
}
}

View File

@@ -1,73 +0,0 @@
package com.gmail.nossr50.runnables.database;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.HiddenConfig;
import com.gmail.nossr50.database.DatabaseManager;
import com.gmail.nossr50.datatypes.database.UpgradeType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.uuid.UUIDFetcher;
public class UUIDUpdateAsyncTask extends BukkitRunnable {
private mcMMO plugin;
private static final int MAX_LOOKUP = Math.max(HiddenConfig.getInstance().getUUIDConvertAmount(), 100);
private List<String> userNames;
private int size;
private int checkedUsers;
private long startMillis;
public UUIDUpdateAsyncTask(mcMMO plugin, List<String> userNames) {
this.plugin = plugin;
this.userNames = userNames;
this.checkedUsers = 0;
this.startMillis = System.currentTimeMillis();
}
@Override
public void run() {
size = userNames.size();
plugin.getLogger().info("Starting to check and update UUIDs, total amount of users: " + size);
List<String> userNamesSection;
Map<String, UUID> fetchedUUIDs = new HashMap<String, UUID>();
while (size != 0) {
if (size > MAX_LOOKUP) {
userNamesSection = userNames.subList(size - MAX_LOOKUP, size);
size -= MAX_LOOKUP;
}
else {
userNamesSection = userNames.subList(0, size);
size = 0;
}
try {
fetchedUUIDs.putAll(new UUIDFetcher(userNamesSection).call());
}
catch (Exception e) {
plugin.getLogger().severe("Unable to fetch UUIDs!");
return;
}
checkedUsers += userNamesSection.size();
userNamesSection.clear();
size = userNames.size();
Misc.printProgress(checkedUsers, DatabaseManager.progressInterval, startMillis);
}
if (mcMMO.getDatabaseManager().saveUserUUIDs(fetchedUUIDs)) {
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_UUIDS);
plugin.getLogger().info("UUID upgrade completed!");
}
}
}

View File

@@ -1,51 +0,0 @@
package com.gmail.nossr50.runnables.party;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.locale.LocaleLoader;
public class PartyChatTask extends BukkitRunnable {
private Plugin plugin;
private Party party;
private String senderName;
private String displayName;
private String message;
public PartyChatTask(Plugin plugin, Party party, String senderName, String displayName, String message) {
this.plugin = plugin;
this.party = party;
this.senderName = senderName;
this.displayName = displayName;
this.message = message;
}
@Override
public void run() {
if (Config.getInstance().getPartyChatColorLeaderName() && senderName.equalsIgnoreCase(party.getLeader())) {
message = message.replaceFirst(Pattern.quote(displayName), ChatColor.GOLD + Matcher.quoteReplacement(displayName) + ChatColor.RESET);
}
for (Player member : party.getOnlineMembers()) {
member.sendMessage(message);
}
if (party.getAlly() != null) {
for (Player member : party.getAlly().getOnlineMembers()) {
String allyPrefix = LocaleLoader.formatString(Config.getInstance().getPartyChatPrefixAlly());
member.sendMessage(allyPrefix + message);
}
}
plugin.getServer().getConsoleSender().sendMessage("[mcMMO] [P]<" + party.getName() + ">" + message);
}
}

View File

@@ -1,108 +0,0 @@
package com.gmail.nossr50.runnables.player;
import java.util.concurrent.locks.ReentrantLock;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.commands.McScoreboardKeepTask;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
public class PlayerProfileLoadingTask extends BukkitRunnable {
private static final int MAX_TRIES = 5;
private final Player player;
private int attempt = 0;
private ReentrantLock lock = new ReentrantLock();
private boolean cancelled = false;
public PlayerProfileLoadingTask(Player player) {
this.player = player;
}
// WARNING: ASYNC TASK
// DO NOT MODIFY THE McMMOPLAYER FROM THIS CODE
@Override
public void run() {
lock.lock();
if (this.cancelled) {
return;
}
// Quit if they logged out
if (!player.isOnline()) {
mcMMO.p.getLogger().info("Aborting profile loading recovery for " + player.getName() + " - player logged out");
this.cancel();
cancelled = true;
lock.unlock();
return;
}
// Increment attempt counter and try
attempt++;
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(player.getName(), player.getUniqueId(), true);
// If successful, schedule the apply
if (profile.isLoaded()) {
new ApplySuccessfulProfile(profile).runTask(mcMMO.p);
this.cancel();
cancelled = true;
lock.unlock();
return;
}
// If we've failed five times, give up
if (attempt >= MAX_TRIES) {
mcMMO.p.getLogger().severe("Giving up on attempting to load the PlayerProfile for " + player.getName());
mcMMO.p.getServer().broadcast(LocaleLoader.getString("Profile.Loading.AdminFailureNotice", player.getName()), Server.BROADCAST_CHANNEL_ADMINISTRATIVE);
player.sendMessage(LocaleLoader.getString("Profile.Loading.Failure").split("\n"));
this.cancel();
cancelled = true;
lock.unlock();
return;
}
lock.unlock();
}
private class ApplySuccessfulProfile extends BukkitRunnable {
private final PlayerProfile profile;
private ApplySuccessfulProfile(PlayerProfile profile) {
this.profile = profile;
}
// Synchronized task
// No database access permitted
@Override
public void run() {
if (!player.isOnline()) {
mcMMO.p.getLogger().info("Aborting profile loading recovery for " + player.getName() + " - player logged out");
return;
}
McMMOPlayer mcMMOPlayer = new McMMOPlayer(player, profile);
UserManager.track(mcMMOPlayer);
mcMMOPlayer.actualizeRespawnATS();
ScoreboardManager.setupPlayer(player);
if (Config.getInstance().getShowProfileLoadedMessage()) {
player.sendMessage(LocaleLoader.getString("Profile.Loading.Success"));
}
if (Config.getInstance().getShowStatsAfterLogin()) {
ScoreboardManager.enablePlayerStatsScoreboard(player);
new McScoreboardKeepTask(player).runTaskLater(mcMMO.p, 1 * Misc.TICK_CONVERSION_FACTOR);
}
}
}
}

View File

@@ -1,18 +1,9 @@
package com.gmail.nossr50.skills.mining; package com.gmail.nossr50.skills.mining;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.util.player.UserManager;
public class BlastMining { public class BlastMining {
// The order of the values is extremely important, a few methods depend on it to work properly // The order of the values is extremely important, a few methods depend on it to work properly
@@ -64,58 +55,4 @@ public class BlastMining {
public static Material detonator = Config.getInstance().getDetonatorItem(); public static Material detonator = Config.getInstance().getDetonatorItem();
public final static int MAXIMUM_REMOTE_DETONATION_DISTANCE = 100; public final static int MAXIMUM_REMOTE_DETONATION_DISTANCE = 100;
public static int getDemolitionExpertUnlockLevel() {
List<Tier> tierList = Arrays.asList(Tier.values());
for (Tier tier : tierList) {
if (tier.getBlastDamageDecrease() > 0) {
continue;
}
return tier == Tier.EIGHT ? tier.getLevel() : tierList.get(tierList.indexOf(tier) - 1).getLevel();
}
return 0;
}
public static int getBiggerBombsUnlockLevel() {
List<Tier> tierList = Arrays.asList(Tier.values());
for (Tier tier : tierList) {
if (tier.getBlastRadiusModifier() > 1.0) {
continue;
}
return tier == Tier.EIGHT ? tier.getLevel() : tierList.get(tierList.indexOf(tier) - 1).getLevel();
}
return 0;
}
public static boolean processBlastMiningExplosion(EntityDamageByEntityEvent event, TNTPrimed tnt, Player defender) {
if (!tnt.hasMetadata(mcMMO.tntMetadataKey) || !UserManager.hasPlayerDataKey(defender)) {
return false;
}
// We can make this assumption because we (should) be the only ones using this exact metadata
Player player = mcMMO.p.getServer().getPlayerExact(tnt.getMetadata(mcMMO.tntMetadataKey).get(0).asString());
if (!player.equals(defender)) {
return false;
}
MiningManager miningManager = UserManager.getPlayer(defender).getMiningManager();
if (!miningManager.canUseDemolitionsExpertise()) {
return false;
}
event.setDamage(DamageModifier.BASE, miningManager.processDemolitionsExpertise(event.getDamage()));
if (event.getFinalDamage() == 0) {
event.setCancelled(true);
return false;
}
return true;
}
} }

View File

@@ -33,7 +33,7 @@ public class MiningManager extends SkillManager {
} }
public boolean canUseDemolitionsExpertise() { public boolean canUseDemolitionsExpertise() {
return getSkillLevel() >= BlastMining.getDemolitionExpertUnlockLevel() && Permissions.demolitionsExpertise(getPlayer()); return getSkillLevel() >= BlastMining.Tier.FOUR.getLevel() && Permissions.demolitionsExpertise(getPlayer());
} }
public boolean canDetonate() { public boolean canDetonate() {
@@ -47,7 +47,7 @@ public class MiningManager extends SkillManager {
} }
public boolean canUseBiggerBombs() { public boolean canUseBiggerBombs() {
return getSkillLevel() >= BlastMining.getBiggerBombsUnlockLevel() && Permissions.biggerBombs(getPlayer()); return getSkillLevel() >= BlastMining.Tier.TWO.getLevel() && Permissions.biggerBombs(getPlayer());
} }
/** /**

View File

@@ -69,9 +69,6 @@ public class Unarmed {
nextSlot++; nextSlot++;
} }
// Inventory is full - cancel the item pickup
return false;
} }
else if (firstEmpty != -1) { else if (firstEmpty != -1) {
drop.remove(); drop.remove();

View File

@@ -13,7 +13,6 @@ import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.events.items.McMMOItemSpawnEvent; import com.gmail.nossr50.events.items.McMMOItemSpawnEvent;
import com.gmail.nossr50.runnables.player.PlayerProfileLoadingTask;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public final class Misc { public final class Misc {
@@ -113,7 +112,7 @@ public final class Misc {
if (player != null) { if (player != null) {
UserManager.remove(player); UserManager.remove(player);
new PlayerProfileLoadingTask(player).runTaskTimerAsynchronously(mcMMO.p, 1, 20); // 1 Tick delay to ensure the player is marked as online before we begin loading UserManager.addUser(player);
} }
} }

View File

@@ -18,12 +18,16 @@ public final class UserManager {
private UserManager() {} private UserManager() {}
/** /**
* Track a new user. * Add a new user.
* *
* @param mcMMOPlayer the player profile to start tracking * @param player The player to create a user record for
* @return the player's {@link McMMOPlayer} object
*/ */
public static void track(McMMOPlayer mcMMOPlayer) { public static McMMOPlayer addUser(Player player) {
mcMMOPlayer.getPlayer().setMetadata(mcMMO.playerDataKey, new FixedMetadataValue(mcMMO.p, mcMMOPlayer)); McMMOPlayer mcMMOPlayer = new McMMOPlayer(player);
player.setMetadata(mcMMO.playerDataKey, new FixedMetadataValue(mcMMO.p, mcMMOPlayer));
return mcMMOPlayer;
} }
/** /**

View File

@@ -602,14 +602,7 @@ public final class CombatUtils {
@Deprecated @Deprecated
public static double callFakeDamageEvent(Entity attacker, Entity target, DamageCause damageCause, double damage) { public static double callFakeDamageEvent(Entity attacker, Entity target, DamageCause damageCause, double damage) {
EntityDamageEvent damageEvent = attacker == null ? new FakeEntityDamageEvent(target, damageCause, damage) : new FakeEntityDamageByEntityEvent(attacker, target, damageCause, damage); return callFakeDamageEvent(attacker, target, damageCause, new EnumMap<DamageModifier, Double>(ImmutableMap.of(DamageModifier.BASE, damage)));
mcMMO.p.getServer().getPluginManager().callEvent(damageEvent);
if (damageEvent.isCancelled()) {
return 0;
}
return damageEvent.getFinalDamage();
} }
public static double callFakeDamageEvent(Entity attacker, Entity target, Map<DamageModifier, Double> modifiers) { public static double callFakeDamageEvent(Entity attacker, Entity target, Map<DamageModifier, Double> modifiers) {
@@ -643,9 +636,9 @@ public final class CombatUtils {
private static Map<DamageModifier, Double> getScaledModifiers(double damage, Map<DamageModifier, Double> modifiers) { private static Map<DamageModifier, Double> getScaledModifiers(double damage, Map<DamageModifier, Double> modifiers) {
Map<DamageModifier, Double> scaledModifiers = new HashMap<DamageModifier, Double>(); Map<DamageModifier, Double> scaledModifiers = new HashMap<DamageModifier, Double>();
for (DamageModifier modifier : modifiers.keySet()) { for (DamageModifier modifier : DamageModifier.values()) {
if (modifier == DamageModifier.BASE) { if (modifier == DamageModifier.BASE) {
scaledModifiers.put(modifier, damage); modifiers.put(modifier, damage);
continue; continue;
} }

View File

@@ -1,65 +0,0 @@
package com.gmail.nossr50.util.upgrade;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.Set;
import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.datatypes.database.UpgradeType;
public class UpgradeManager extends ConfigLoader {
private final Set<UpgradeType> setNeededUpgrades;
public UpgradeManager() {
super("upgrades.yml");
setNeededUpgrades = EnumSet.allOf(UpgradeType.class);
loadKeys();
}
/**
* Check if the given {@link UpgradeType} is necessary.
*
* @param type Upgrade type to check
*
* @return true if plugin data needs to have the given upgrade
*/
public boolean shouldUpgrade(final UpgradeType type) {
return setNeededUpgrades.contains(type);
}
/**
* Set the given {@link UpgradeType} as completed. Does nothing if
* the upgrade was applied previously.
*
* @param type Upgrade type to set as complete
*/
public void setUpgradeCompleted(final UpgradeType type) {
if (!setNeededUpgrades.remove(type)) {
return;
}
plugin.debug("Saving upgrade status for type " + type.toString() + "...");
config.set("Upgrades_Finished." + type.toString(), true);
try {
config.save(getFile());
}
catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void loadKeys() {
for (UpgradeType type : UpgradeType.values()) {
if (config.getBoolean("Upgrades_Finished." + type.toString())) {
setNeededUpgrades.remove(type);
}
}
plugin.debug("Needed upgrades: " + Arrays.toString(setNeededUpgrades.toArray(new UpgradeType[setNeededUpgrades.size()])));
}
}

View File

@@ -1,100 +0,0 @@
package com.gmail.nossr50.util.uuid;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.Callable;
import com.google.common.collect.ImmutableList;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
public class UUIDFetcher implements Callable<Map<String, UUID>> {
private static final double PROFILES_PER_REQUEST = 100;
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
private final JSONParser jsonParser = new JSONParser();
private final List<String> names;
private final boolean rateLimiting;
public UUIDFetcher(List<String> names, boolean rateLimiting) {
this.names = ImmutableList.copyOf(names);
this.rateLimiting = rateLimiting;
}
public UUIDFetcher(List<String> names) {
this(names, true);
}
public Map<String, UUID> call() throws Exception {
Map<String, UUID> uuidMap = new HashMap<String, UUID>();
int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST);
for (int i = 0; i < requests; i++) {
HttpURLConnection connection = createConnection();
String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size())));
writeBody(connection, body);
JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
for (Object profile : array) {
JSONObject jsonProfile = (JSONObject) profile;
String id = (String) jsonProfile.get("id");
String name = (String) jsonProfile.get("name");
UUID uuid = UUIDFetcher.getUUID(id);
uuidMap.put(name, uuid);
}
if (rateLimiting && i != requests - 1) {
Thread.sleep(100L);
}
}
return uuidMap;
}
private static void writeBody(HttpURLConnection connection, String body) throws Exception {
OutputStream stream = connection.getOutputStream();
stream.write(body.getBytes());
stream.flush();
stream.close();
}
private static HttpURLConnection createConnection() throws Exception {
URL url = new URL(PROFILE_URL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
return connection;
}
private static UUID getUUID(String id) {
return UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" + id.substring(20, 32));
}
public static byte[] toBytes(UUID uuid) {
ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]);
byteBuffer.putLong(uuid.getMostSignificantBits());
byteBuffer.putLong(uuid.getLeastSignificantBits());
return byteBuffer.array();
}
public static UUID fromBytes(byte[] array) {
if (array.length != 16) {
throw new IllegalArgumentException("Illegal byte array length: " + array.length);
}
ByteBuffer byteBuffer = ByteBuffer.wrap(array);
long mostSignificant = byteBuffer.getLong();
long leastSignificant = byteBuffer.getLong();
return new UUID(mostSignificant, leastSignificant);
}
public static UUID getUUIDOf(String name) throws Exception {
return new UUIDFetcher(Arrays.asList(name)).call().get(name);
}
}

View File

@@ -10,8 +10,6 @@
General: General:
Locale: en_US Locale: en_US
MOTD_Enabled: true MOTD_Enabled: true
# Send a message to the player when his profile was successfully loaded
Show_Profile_Loaded: false
# Amount of time (in minutes) to wait between saves of player information # Amount of time (in minutes) to wait between saves of player information
Save_Interval: 10 Save_Interval: 10
# Allow mcMMO to report on basic anonymous usage # Allow mcMMO to report on basic anonymous usage
@@ -124,12 +122,6 @@ MySQL:
User_Password: UserPassword User_Password: UserPassword
Name: DataBaseName Name: DataBaseName
TablePrefix: mcmmo_ TablePrefix: mcmmo_
# This setting is the max simultaneous mysql connections allowed at a time, needs to be
# high enough to support multiple player logins in quick succession
MaxConnections: 30
# This setting is the max size of the pool of cached connections that we hold available
# at any given time
MaxPoolSize: 20
Server: Server:
Port: 3306 Port: 3306
Address: localhost Address: localhost
@@ -360,9 +352,6 @@ Skills:
Level_Cap: 0 Level_Cap: 0
Block_Cracker: Block_Cracker:
SmoothBrick_To_CrackedBrick: true SmoothBrick_To_CrackedBrick: true
# When using Unarmed, picked up items will automatically get moved to a free slot instead of going in the slot
# of your hand. Should item pickup be disabled when your entire inventory - except for your hand - is full?
Item_Pickup_Disabled_Full_Inventory: true
Woodcutting: Woodcutting:
Tree_Feller_Sounds: true Tree_Feller_Sounds: true
Level_Cap: 0 Level_Cap: 0

View File

@@ -11,6 +11,3 @@ Options:
EnchantmentBuffs: true EnchantmentBuffs: true
# true to enable refreshing of chunks around a player at the end of Super Breaker, Giga Drill Breaker, and Berserk. This should fix blocks being broken client side, but not server-side # true to enable refreshing of chunks around a player at the end of Super Breaker, Giga Drill Breaker, and Berserk. This should fix blocks being broken client side, but not server-side
RefreshChunks: false RefreshChunks: false
# Amount of users to convert every interval
UUIDConvertAmount: 100

View File

@@ -739,7 +739,7 @@ Guides.Axes.Section.5=[[DARK_AQUA]]How does Greater Impact work?\n[[YELLOW]]You
##Excavation ##Excavation
Guides.Excavation.Section.0=[[DARK_AQUA]]About Excavation:\n[[YELLOW]]Excavation is the act of digging up dirt to find treasures.\n[[YELLOW]]By excavating the land you will find treasures.\n[[YELLOW]]The more you do this the more treasures you can find.\n\n[[DARK_AQUA]]XP GAIN:\n[[YELLOW]]To gain XP in this skill you must dig with a shovel in hand.\n[[YELLOW]]Only certain materials can be dug up for treasures and XP. Guides.Excavation.Section.0=[[DARK_AQUA]]About Excavation:\n[[YELLOW]]Excavation is the act of digging up dirt to find treasures.\n[[YELLOW]]By excavating the land you will find treasures.\n[[YELLOW]]The more you do this the more treasures you can find.\n\n[[DARK_AQUA]]XP GAIN:\n[[YELLOW]]To gain XP in this skill you must dig with a shovel in hand.\n[[YELLOW]]Only certain materials can be dug up for treasures and XP.
Guides.Excavation.Section.1=[[DARK_AQUA]]Compatible Materials:\n[[YELLOW]]Grass, Dirt, Sand, Clay, Gravel, Mycelium, Soul Sand, Snow Guides.Excavation.Section.1=[[DARK_AQUA]]Compatible Materials:\n[[YELLOW]]Grass, Dirt, Sand, Clay, Gravel, Mycelium, Soul Sand
Guides.Excavation.Section.2=[[DARK_AQUA]]How to use Giga Drill Breaker:\n[[YELLOW]]With a shovel in hand right click to ready your tool.\n[[YELLOW]]Once in this state you have about 4 seconds to make\n[[YELLOW]]contact with Excavation compatible materials this will\n[[YELLOW]]activate Giga Drill Breaker. Guides.Excavation.Section.2=[[DARK_AQUA]]How to use Giga Drill Breaker:\n[[YELLOW]]With a shovel in hand right click to ready your tool.\n[[YELLOW]]Once in this state you have about 4 seconds to make\n[[YELLOW]]contact with Excavation compatible materials this will\n[[YELLOW]]activate Giga Drill Breaker.
Guides.Excavation.Section.3=[[DARK_AQUA]]What is Giga Drill Breaker?\n[[YELLOW]]Giga Drill Breaker is an ability with a cooldown\n[[YELLOW]]tied to Excavation skill. It triples your chance\n[[YELLOW]]of finding treasures and enables instant break\n[[YELLOW]]on Excavation materials. Guides.Excavation.Section.3=[[DARK_AQUA]]What is Giga Drill Breaker?\n[[YELLOW]]Giga Drill Breaker is an ability with a cooldown\n[[YELLOW]]tied to Excavation skill. It triples your chance\n[[YELLOW]]of finding treasures and enables instant break\n[[YELLOW]]on Excavation materials.
Guides.Excavation.Section.4=[[DARK_AQUA]]How does Treasure Hunter work?\n[[YELLOW]]Every possible treasure for Excavation has its own\n[[YELLOW]]skill level requirement for it to drop, as a result it's\n[[YELLOW]]difficult to say how much it is helping you.\n[[YELLOW]]Just keep in mind that the higher your Excavation skill\n[[YELLOW]]is, the more treasures that can be found.\n[[YELLOW]]And also keep in mind that each type of Excavation\n[[YELLOW]]compatible material has its own unique list of treasures.\n[[YELLOW]]In other words you will find different treasures in Dirt\n[[YELLOW]]than you would in Gravel. Guides.Excavation.Section.4=[[DARK_AQUA]]How does Treasure Hunter work?\n[[YELLOW]]Every possible treasure for Excavation has its own\n[[YELLOW]]skill level requirement for it to drop, as a result it's\n[[YELLOW]]difficult to say how much it is helping you.\n[[YELLOW]]Just keep in mind that the higher your Excavation skill\n[[YELLOW]]is, the more treasures that can be found.\n[[YELLOW]]And also keep in mind that each type of Excavation\n[[YELLOW]]compatible material has its own unique list of treasures.\n[[YELLOW]]In other words you will find different treasures in Dirt\n[[YELLOW]]than you would in Gravel.
@@ -960,6 +960,7 @@ Scoreboard.Misc.Cooldown=[[LIGHT_PURPLE]]Cooldown
Scoreboard.Misc.Overall=[[GOLD]]Overall Scoreboard.Misc.Overall=[[GOLD]]Overall
#DATABASE RECOVERY #DATABASE RECOVERY
Profile.Loading.Success=[[GREEN]]Your mcMMO profile has been loaded. Recovery.Notice=[[RED]]Notice: mcMMO was [[DARK_RED]]unable to load your data.[[RED]] Retrying 5 times...
Profile.Loading.Failure=[[RED]]mcMMO still cannot load your data. You may want to [[AQUA]]contact the server owner.\n[[YELLOW]]You can still play on the server, but you will have [[BOLD]]no mcMMO levels[[YELLOW]] and any XP you get [[BOLD]]will not be saved[[YELLOW]]. Recovery.Success=[[GREEN]]Success! Your mcMMO data was loaded.
Profile.Loading.AdminFailureNotice=[[DARK_RED]][A][[RED]] mcMMO was unable to load the player data for [[YELLOW]]{0}[[RED]]. [[LIGHT_PURPLE]]Please inspect your database setup. Recovery.Failure=[[RED]]mcMMO still cannot load your data. You may want to [[AQUA]]contact the server owner.\n[[YELLOW]]You can still play on the server, but you will have [[BOLD]]no mcMMO levels[[YELLOW]] and any XP you get [[BOLD]]will not be saved[[YELLOW]].
Recovery.AdminFailureNotice=[[DARK_RED]][A][[RED]] mcMMO was unable to load the player data for [[YELLOW]]{0}[[RED]]. [[LIGHT_PURPLE]]Please inspect your database setup.

View File

@@ -1,9 +0,0 @@
# WARNING: DO NOT MODIFY THIS CONFIG
Upgrades_Finished:
ADD_FISHING: false
ADD_BLAST_MINING_COOLDOWN: false
ADD_SQL_INDEXES: false
ADD_MOB_HEALTHBARS: false
DROP_SQL_PARTY_NAMES: false
DROP_SPOUT: false
ADD_ALCHEMY: false