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

This commit is contained in:
nossr50
2020-07-26 05:08:49 -07:00
259 changed files with 2025 additions and 2270 deletions

View File

@@ -250,7 +250,7 @@ public final class BlockUtils {
* @return HashSet with the IDs of every transparent block
*/
public static HashSet<Material> getTransparentBlocks() {
HashSet<Material> transparentBlocks = new HashSet<Material>();
HashSet<Material> transparentBlocks = new HashSet<>();
for (Material material : Material.values()) {
if (material.isTransparent()) {

View File

@@ -152,9 +152,10 @@ public final class ChimaeraWing {
ItemStack itemStack = new ItemStack(Config.getInstance().getChimaeraItem(), amount);
ItemMeta itemMeta = itemStack.getItemMeta();
//noinspection ConstantConditions
itemMeta.setDisplayName(ChatColor.GOLD + LocaleLoader.getString("Item.ChimaeraWing.Name"));
List<String> itemLore = new ArrayList<String>();
List<String> itemLore = new ArrayList<>();
itemLore.add("mcMMO Item");
itemLore.add(LocaleLoader.getString("Item.ChimaeraWing.Lore"));
itemMeta.setLore(itemLore);

View File

@@ -6,7 +6,7 @@ import java.util.HashMap;
public class EnchantmentUtils {
private static final HashMap<String, Enchantment> enchants = new HashMap<String, Enchantment>();
private static final HashMap<String, Enchantment> enchants = new HashMap<>();
static {
enchants.put("SHARPNESS", Enchantment.DAMAGE_ALL);

View File

@@ -31,8 +31,8 @@ public final class HardcoreManager {
PlayerProfile playerProfile = UserManager.getPlayer(player).getProfile();
int totalLevelsLost = 0;
HashMap<String, Integer> levelChanged = new HashMap<String, Integer>();
HashMap<String, Float> experienceChanged = new HashMap<String, Float>();
HashMap<String, Integer> levelChanged = new HashMap<>();
HashMap<String, Float> experienceChanged = new HashMap<>();
for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) {
if (!primarySkillType.getHardcoreStatLossEnabled()) {
@@ -83,8 +83,8 @@ public final class HardcoreManager {
PlayerProfile victimProfile = UserManager.getPlayer(victim).getProfile();
int totalLevelsStolen = 0;
HashMap<String, Integer> levelChanged = new HashMap<String, Integer>();
HashMap<String, Float> experienceChanged = new HashMap<String, Float>();
HashMap<String, Integer> levelChanged = new HashMap<>();
HashMap<String, Float> experienceChanged = new HashMap<>();
for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) {
if (!primarySkillType.getHardcoreVampirismEnabled()) {

View File

@@ -25,8 +25,8 @@ import java.util.*;
import java.util.regex.Pattern;
public final class HolidayManager {
private ArrayList<String> hasCelebrated;
private int currentYear;
private final ArrayList<String> hasCelebrated;
private final int currentYear;
private static final int START_YEAR = 2011;
private static final List<Color> ALL_COLORS;
@@ -96,9 +96,9 @@ public final class HolidayManager {
Statistic.PIG_ONE_CM);
static {
List<Color> colors = new ArrayList<Color>();
List<ChatColor> chatColors = new ArrayList<ChatColor>();
List<ChatColor> chatFormats = new ArrayList<ChatColor>();
List<Color> colors = new ArrayList<>();
List<ChatColor> chatColors = new ArrayList<>();
List<ChatColor> chatFormats = new ArrayList<>();
for (ChatColor color : ChatColor.values()) {
if (color.isColor()) {
@@ -137,7 +137,7 @@ public final class HolidayManager {
}
}
hasCelebrated = new ArrayList<String>();
hasCelebrated = new ArrayList<>();
try {
hasCelebrated.clear();
@@ -161,7 +161,7 @@ public final class HolidayManager {
private void cleanupFiles() {
File FlatFileDir = new File(mcMMO.getFlatFileDirectory());
File legacy = new File(FlatFileDir, "anniversary.yml");
List<File> toDelete = new ArrayList<File>();
List<File> toDelete = new ArrayList<>();
if (legacy.exists()) {
toDelete.add(legacy);

View File

@@ -501,7 +501,12 @@ public final class ItemUtils {
}
ItemMeta itemMeta = item.getItemMeta();
return itemMeta.hasLore() && itemMeta.getLore().contains("mcMMO Item");
if(itemMeta == null)
return false;
return itemMeta.getLore() != null
&& itemMeta.getLore().contains("mcMMO Item");
}
public static boolean isChimaeraWing(ItemStack item) {
@@ -510,6 +515,10 @@ public final class ItemUtils {
}
ItemMeta itemMeta = item.getItemMeta();
if(itemMeta == null)
return false;
return itemMeta.hasDisplayName() && itemMeta.getDisplayName().equals(ChatColor.GOLD + LocaleLoader.getString("Item.ChimaeraWing.Name"));
}
}

View File

@@ -6,7 +6,7 @@ import java.util.logging.Filter;
import java.util.logging.LogRecord;
public class LogFilter implements Filter {
private boolean debug;
private final boolean debug;
public LogFilter(mcMMO plugin) {
// Doing a config loading lite here, because we can't depend on the config loader to have loaded before any debug messages are sent

View File

@@ -57,7 +57,6 @@ public class MaterialMapStore {
private HashMap<String, Integer> tierValue;
public MaterialMapStore()
{
abilityBlackList = new HashSet<>();

View File

@@ -18,7 +18,7 @@ import java.util.Random;
import java.util.Set;
public final class Misc {
private static Random random = new Random();
private static final Random random = new Random();
public static final int TIME_CONVERSION_FACTOR = 1000;
public static final int TICK_CONVERSION_FACTOR = 20;
@@ -39,7 +39,7 @@ public final class Misc {
public static final Set<String> modNames = ImmutableSet.of("LOTR", "BUILDCRAFT", "ENDERIO", "ENHANCEDBIOMES", "IC2", "METALLURGY", "FORESTRY", "GALACTICRAFT", "RAILCRAFT", "TWILIGHTFOREST", "THAUMCRAFT", "GRAVESTONEMOD", "GROWTHCRAFT", "ARCTICMOBS", "DEMONMOBS", "INFERNOMOBS", "SWAMPMOBS", "MARICULTURE", "MINESTRAPPOLATION");
private Misc() {};
private Misc() {}
/**
* Determines if an entity is an NPC but not a villager

View File

@@ -138,19 +138,19 @@ public final class MobHealthbarUtils {
int coloredDisplay = (int) Math.ceil(fullDisplay * (healthPercentage / 100.0D));
int grayDisplay = fullDisplay - coloredDisplay;
String healthbar = color + "";
StringBuilder healthbar = new StringBuilder(color + "");
for (int i = 0; i < coloredDisplay; i++) {
healthbar += symbol;
healthbar.append(symbol);
}
healthbar += ChatColor.GRAY;
healthbar.append(ChatColor.GRAY);
for (int i = 0; i < grayDisplay; i++) {
healthbar += symbol;
healthbar.append(symbol);
}
return healthbar;
return healthbar.toString();
}
/**

View File

@@ -22,36 +22,36 @@ import java.util.HashMap;
import java.util.List;
public class ModManager {
private List<Repairable> repairables = new ArrayList<Repairable>();
private final List<Repairable> repairables = new ArrayList<>();
// Armor Mods
private List<Material> customBoots = new ArrayList<Material>();
private List<Material> customChestplates = new ArrayList<Material>();
private List<Material> customHelmets = new ArrayList<Material>();
private List<Material> customLeggings = new ArrayList<Material>();
private final List<Material> customBoots = new ArrayList<>();
private final List<Material> customChestplates = new ArrayList<>();
private final List<Material> customHelmets = new ArrayList<>();
private final List<Material> customLeggings = new ArrayList<>();
// Block Mods
private List<Material> customExcavationBlocks = new ArrayList<Material>();
private List<Material> customHerbalismBlocks = new ArrayList<Material>();
private List<Material> customMiningBlocks = new ArrayList<Material>();
private List<Material> customOres = new ArrayList<Material>();
private List<Material> customLogs = new ArrayList<Material>();
private List<Material> customLeaves = new ArrayList<Material>();
private List<Material> customAbilityBlocks = new ArrayList<Material>();
private HashMap<Material, CustomBlock> customBlockMap = new HashMap<>();
private final List<Material> customExcavationBlocks = new ArrayList<>();
private final List<Material> customHerbalismBlocks = new ArrayList<>();
private final List<Material> customMiningBlocks = new ArrayList<>();
private final List<Material> customOres = new ArrayList<>();
private final List<Material> customLogs = new ArrayList<>();
private final List<Material> customLeaves = new ArrayList<>();
private final List<Material> customAbilityBlocks = new ArrayList<>();
private final HashMap<Material, CustomBlock> customBlockMap = new HashMap<>();
// Entity Mods
private HashMap<String, CustomEntity> customEntityClassMap = new HashMap<String, CustomEntity>();
private HashMap<String, CustomEntity> customEntityTypeMap = new HashMap<String, CustomEntity>();
private final HashMap<String, CustomEntity> customEntityClassMap = new HashMap<>();
private final HashMap<String, CustomEntity> customEntityTypeMap = new HashMap<>();
// Tool Mods
private List<Material> customAxes = new ArrayList<Material>();
private List<Material> customBows = new ArrayList<Material>();
private List<Material> customHoes = new ArrayList<Material>();
private List<Material> customPickaxes = new ArrayList<Material>();
private List<Material> customShovels = new ArrayList<Material>();
private List<Material> customSwords = new ArrayList<Material>();
private HashMap<Material, CustomTool> customToolMap = new HashMap<Material, CustomTool>();
private final List<Material> customAxes = new ArrayList<>();
private final List<Material> customBows = new ArrayList<>();
private final List<Material> customHoes = new ArrayList<>();
private final List<Material> customPickaxes = new ArrayList<>();
private final List<Material> customShovels = new ArrayList<>();
private final List<Material> customSwords = new ArrayList<>();
private final HashMap<Material, CustomTool> customToolMap = new HashMap<>();
public void registerCustomArmor(CustomArmorConfig config) {
customBoots.addAll(config.customBoots);

View File

@@ -44,8 +44,7 @@ public class TextComponentFactory {
public static TextComponent getNotificationLevelUpTextComponent(PrimarySkillType skill, int levelsGained, int currentLevel)
{
TextComponent textComponent = new TextComponent(LocaleLoader.getString("Overhaul.Levelup", LocaleLoader.getString("Overhaul.Name."+StringUtils.getCapitalized(skill.toString())), levelsGained, currentLevel));
return textComponent;
return new TextComponent(LocaleLoader.getString("Overhaul.Levelup", LocaleLoader.getString("Overhaul.Name."+StringUtils.getCapitalized(skill.toString())), levelsGained, currentLevel));
}
private static TextComponent getNotificationTextComponent(String text)
@@ -347,7 +346,6 @@ public class TextComponentFactory {
ChatColor ccRank = ChatColor.BLUE;
ChatColor ccCurRank = ChatColor.GREEN;
ChatColor ccPossessive = ChatColor.WHITE;
ChatColor ccNumRanks = ccCurRank;
//ChatColor ccDescriptionHeader = ChatColor.DARK_PURPLE;
//ChatColor ccDescription = ChatColor.WHITE;
ChatColor ccLocked = ChatColor.DARK_GRAY;
@@ -375,7 +373,7 @@ public class TextComponentFactory {
nextRank = RankUtils.getRankUnlockLevel(abstractSubSkill, curRank+1);
}
addRanked(ccRank, ccCurRank, ccPossessive, ccNumRanks, componentBuilder, abstractSubSkill.getNumRanks(), RankUtils.getRank(player, abstractSubSkill), nextRank);
addRanked(ccRank, ccCurRank, ccPossessive, ccCurRank, componentBuilder, abstractSubSkill.getNumRanks(), RankUtils.getRank(player, abstractSubSkill), nextRank);
componentBuilder.append(LocaleLoader.getString("JSON.DescriptionHeader"));
componentBuilder.append("\n").append(abstractSubSkill.getDescription()).append("\n");
@@ -456,7 +454,6 @@ public class TextComponentFactory {
ChatColor ccRank = ChatColor.BLUE;
ChatColor ccCurRank = ChatColor.GREEN;
ChatColor ccPossessive = ChatColor.WHITE;
ChatColor ccNumRanks = ccCurRank;
ChatColor ccDescriptionHeader = ChatColor.DARK_PURPLE;
ChatColor ccDescription = ChatColor.DARK_GRAY;
ChatColor ccLocked = ChatColor.DARK_GRAY;
@@ -484,7 +481,7 @@ public class TextComponentFactory {
nextRank = RankUtils.getRankUnlockLevel(subSkillType, curRank+1);
}
addRanked(ccRank, ccCurRank, ccPossessive, ccNumRanks, componentBuilder, subSkillType.getNumRanks(), RankUtils.getRank(player, subSkillType), nextRank);
addRanked(ccRank, ccCurRank, ccPossessive, ccCurRank, componentBuilder, subSkillType.getNumRanks(), RankUtils.getRank(player, subSkillType), nextRank);
}

View File

@@ -10,8 +10,8 @@ public class BiomeAdapter {
static {
List<Biome> allBiomes = Arrays.asList(Biome.values());
List<Biome> waterBiomes = new ArrayList<Biome>();
List<Biome> iceBiomes = new ArrayList<Biome>();
List<Biome> waterBiomes = new ArrayList<>();
List<Biome> iceBiomes = new ArrayList<>();
for (Biome biome : allBiomes) {
if (isWater(biome.name()) && !isCold(biome.name())) {
waterBiomes.add(biome);

View File

@@ -12,7 +12,7 @@ public interface ChunkletManager {
* @param cz Chunklet Z coordinate that needs to be loaded
* @param world World that the chunklet needs to be loaded in
*/
public void loadChunklet(int cx, int cy, int cz, World world);
void loadChunklet(int cx, int cy, int cz, World world);
/**
* Unload a specific chunklet
@@ -22,7 +22,7 @@ public interface ChunkletManager {
* @param cz Chunklet Z coordinate that needs to be unloaded
* @param world World that the chunklet needs to be unloaded from
*/
public void unloadChunklet(int cx, int cy, int cz, World world);
void unloadChunklet(int cx, int cy, int cz, World world);
/**
* Load a given Chunk's Chunklet data
@@ -31,7 +31,7 @@ public interface ChunkletManager {
* @param cz Chunk Z coordinate that is to be loaded
* @param world World that the Chunk is in
*/
public void loadChunk(int cx, int cz, World world);
void loadChunk(int cx, int cz, World world);
/**
* Unload a given Chunk's Chunklet data
@@ -40,7 +40,7 @@ public interface ChunkletManager {
* @param cz Chunk Z coordinate that is to be unloaded
* @param world World that the Chunk is in
*/
public void unloadChunk(int cx, int cz, World world);
void unloadChunk(int cx, int cz, World world);
/**
* Informs the ChunkletManager a chunk is loaded
@@ -49,7 +49,7 @@ public interface ChunkletManager {
* @param cz Chunk Z coordinate that is loaded
* @param world World that the chunk was loaded in
*/
public void chunkLoaded(int cx, int cz, World world);
void chunkLoaded(int cx, int cz, World world);
/**
* Informs the ChunkletManager a chunk is unloaded
@@ -58,38 +58,38 @@ public interface ChunkletManager {
* @param cz Chunk Z coordinate that is unloaded
* @param world World that the chunk was unloaded in
*/
public void chunkUnloaded(int cx, int cz, World world);
void chunkUnloaded(int cx, int cz, World world);
/**
* Save all ChunkletStores related to the given world
*
* @param world World to save
*/
public void saveWorld(World world);
void saveWorld(World world);
/**
* Unload all ChunkletStores from memory related to the given world after saving them
*
* @param world World to unload
*/
public void unloadWorld(World world);
void unloadWorld(World world);
/**
* Load all ChunkletStores from all loaded chunks from this world into memory
*
* @param world World to load
*/
public void loadWorld(World world);
void loadWorld(World world);
/**
* Save all ChunkletStores
*/
public void saveAll();
void saveAll();
/**
* Unload all ChunkletStores after saving them
*/
public void unloadAll();
void unloadAll();
/**
* Check to see if a given location is set to true
@@ -100,7 +100,7 @@ public interface ChunkletManager {
* @param world World to check in
* @return true if the given location is set to true, false if otherwise
*/
public boolean isTrue(int x, int y, int z, World world);
boolean isTrue(int x, int y, int z, World world);
/**
* Check to see if a given block location is set to true
@@ -108,7 +108,7 @@ public interface ChunkletManager {
* @param block Block location to check
* @return true if the given block location is set to true, false if otherwise
*/
public boolean isTrue(Block block);
boolean isTrue(Block block);
/**
* Set a given location to true, should create stores as necessary if the location does not exist
@@ -118,14 +118,14 @@ public interface ChunkletManager {
* @param z Z coordinate to set
* @param world World to set in
*/
public void setTrue(int x, int y, int z, World world);
void setTrue(int x, int y, int z, World world);
/**
* Set a given block location to true, should create stores as necessary if the location does not exist
*
* @param block Block location to set
*/
public void setTrue(Block block);
void setTrue(Block block);
/**
* Set a given location to false, should not create stores if one does not exist for the given location
@@ -135,17 +135,17 @@ public interface ChunkletManager {
* @param z Z coordinate to set
* @param world World to set in
*/
public void setFalse(int x, int y, int z, World world);
void setFalse(int x, int y, int z, World world);
/**
* Set a given block location to false, should not create stores if one does not exist for the given location
*
* @param block Block location to set
*/
public void setFalse(Block block);
void setFalse(Block block);
/**
* Delete any ChunkletStores that are empty
*/
public void cleanUp();
void cleanUp();
}

View File

@@ -14,7 +14,7 @@ public interface ChunkletStore extends Serializable {
* @param z z coordinate in current chunklet
* @return true if the value is true at the given coordinates, false if otherwise
*/
public boolean isTrue(int x, int y, int z);
boolean isTrue(int x, int y, int z);
/**
* Set the value to true at the given coordinates
@@ -23,7 +23,7 @@ public interface ChunkletStore extends Serializable {
* @param y y coordinate in current chunklet
* @param z z coordinate in current chunklet
*/
public void setTrue(int x, int y, int z);
void setTrue(int x, int y, int z);
/**
* Set the value to false at the given coordinates
@@ -32,17 +32,17 @@ public interface ChunkletStore extends Serializable {
* @param y y coordinate in current chunklet
* @param z z coordinate in current chunklet
*/
public void setFalse(int x, int y, int z);
void setFalse(int x, int y, int z);
/**
* @return true if all values in the chunklet are false, false if otherwise
*/
public boolean isEmpty();
boolean isEmpty();
/**
* Set all values in this ChunkletStore to the values from another provided ChunkletStore
*
* @param otherStore Another ChunkletStore that this one should copy all data from
*/
public void copyFrom(ChunkletStore otherStore);
void copyFrom(ChunkletStore otherStore);
}

View File

@@ -8,7 +8,7 @@ import java.io.*;
import java.util.HashMap;
public class HashChunkletManager implements ChunkletManager {
public HashMap<String, ChunkletStore> store = new HashMap<String, ChunkletStore>();
public HashMap<String, ChunkletStore> store = new HashMap<>();
@Override
public void loadChunklet(int cx, int cy, int cz, World world) {

View File

@@ -11,57 +11,46 @@ import org.bukkit.block.Block;
public class NullChunkletManager implements ChunkletManager {
@Override
public void loadChunklet(int cx, int cy, int cz, World world) {
return;
}
@Override
public void unloadChunklet(int cx, int cy, int cz, World world) {
return;
}
@Override
public void loadChunk(int cx, int cz, World world) {
return;
}
@Override
public void unloadChunk(int cx, int cz, World world) {
return;
}
@Override
public void chunkLoaded(int cx, int cz, World world) {
return;
}
@Override
public void chunkUnloaded(int cx, int cz, World world) {
return;
}
@Override
public void saveWorld(World world) {
return;
}
@Override
public void unloadWorld(World world) {
return;
}
@Override
public void loadWorld(World world) {
return;
}
@Override
public void saveAll() {
return;
}
@Override
public void unloadAll() {
return;
}
@Override
@@ -76,26 +65,21 @@ public class NullChunkletManager implements ChunkletManager {
@Override
public void setTrue(int x, int y, int z, World world) {
return;
}
@Override
public void setTrue(Block block) {
return;
}
@Override
public void setFalse(int x, int y, int z, World world) {
return;
}
@Override
public void setFalse(Block block) {
return;
}
@Override
public void cleanUp() {
return;
}
}

View File

@@ -8,13 +8,13 @@ import org.bukkit.entity.Entity;
import java.io.IOException;
public interface ChunkManager {
public void closeAll();
void closeAll();
public ChunkStore readChunkStore(World world, int x, int z) throws IOException;
ChunkStore readChunkStore(World world, int x, int z) throws IOException;
public void writeChunkStore(World world, int x, int z, ChunkStore data);
void writeChunkStore(World world, int x, int z, ChunkStore data);
public void closeChunkStore(World world, int x, int z);
void closeChunkStore(World world, int x, int z);
/**
* Loads a specific chunklet
@@ -24,7 +24,7 @@ public interface ChunkManager {
* @param cz Chunklet Z coordinate that needs to be loaded
* @param world World that the chunklet needs to be loaded in
*/
public void loadChunklet(int cx, int cy, int cz, World world);
void loadChunklet(int cx, int cy, int cz, World world);
/**
* Unload a specific chunklet
@@ -34,7 +34,7 @@ public interface ChunkManager {
* @param cz Chunklet Z coordinate that needs to be unloaded
* @param world World that the chunklet needs to be unloaded from
*/
public void unloadChunklet(int cx, int cy, int cz, World world);
void unloadChunklet(int cx, int cy, int cz, World world);
/**
* Load a given Chunk's Chunklet data
@@ -43,7 +43,7 @@ public interface ChunkManager {
* @param cz Chunk Z coordinate that is to be loaded
* @param world World that the Chunk is in
*/
public void loadChunk(int cx, int cz, World world, Entity[] entities);
void loadChunk(int cx, int cz, World world, Entity[] entities);
/**
* Unload a given Chunk's Chunklet data
@@ -52,7 +52,7 @@ public interface ChunkManager {
* @param cz Chunk Z coordinate that is to be unloaded
* @param world World that the Chunk is in
*/
public void unloadChunk(int cx, int cz, World world);
void unloadChunk(int cx, int cz, World world);
/**
* Saves a given Chunk's Chunklet data
@@ -61,9 +61,9 @@ public interface ChunkManager {
* @param cz Chunk Z coordinate that is to be saved
* @param world World that the Chunk is in
*/
public void saveChunk(int cx, int cz, World world);
void saveChunk(int cx, int cz, World world);
public boolean isChunkLoaded(int cx, int cz, World world);
boolean isChunkLoaded(int cx, int cz, World world);
/**
* Informs the ChunkletManager a chunk is loaded
@@ -72,7 +72,7 @@ public interface ChunkManager {
* @param cz Chunk Z coordinate that is loaded
* @param world World that the chunk was loaded in
*/
public void chunkLoaded(int cx, int cz, World world);
void chunkLoaded(int cx, int cz, World world);
/**
* Informs the ChunkletManager a chunk is unloaded
@@ -81,38 +81,38 @@ public interface ChunkManager {
* @param cz Chunk Z coordinate that is unloaded
* @param world World that the chunk was unloaded in
*/
public void chunkUnloaded(int cx, int cz, World world);
void chunkUnloaded(int cx, int cz, World world);
/**
* Save all ChunkletStores related to the given world
*
* @param world World to save
*/
public void saveWorld(World world);
void saveWorld(World world);
/**
* Unload all ChunkletStores from memory related to the given world after saving them
*
* @param world World to unload
*/
public void unloadWorld(World world);
void unloadWorld(World world);
/**
* Load all ChunkletStores from all loaded chunks from this world into memory
*
* @param world World to load
*/
public void loadWorld(World world);
void loadWorld(World world);
/**
* Save all ChunkletStores
*/
public void saveAll();
void saveAll();
/**
* Unload all ChunkletStores after saving them
*/
public void unloadAll();
void unloadAll();
/**
* Check to see if a given location is set to true
@@ -123,7 +123,7 @@ public interface ChunkManager {
* @param world World to check in
* @return true if the given location is set to true, false if otherwise
*/
public boolean isTrue(int x, int y, int z, World world);
boolean isTrue(int x, int y, int z, World world);
/**
* Check to see if a given block location is set to true
@@ -131,7 +131,7 @@ public interface ChunkManager {
* @param block Block location to check
* @return true if the given block location is set to true, false if otherwise
*/
public boolean isTrue(Block block);
boolean isTrue(Block block);
/**
* Check to see if a given BlockState location is set to true
@@ -139,7 +139,7 @@ public interface ChunkManager {
* @param blockState BlockState to check
* @return true if the given BlockState location is set to true, false if otherwise
*/
public boolean isTrue(BlockState blockState);
boolean isTrue(BlockState blockState);
/**
* Set a given location to true, should create stores as necessary if the location does not exist
@@ -149,21 +149,21 @@ public interface ChunkManager {
* @param z Z coordinate to set
* @param world World to set in
*/
public void setTrue(int x, int y, int z, World world);
void setTrue(int x, int y, int z, World world);
/**
* Set a given block location to true, should create stores as necessary if the location does not exist
*
* @param block Block location to set
*/
public void setTrue(Block block);
void setTrue(Block block);
/**
* Set a given BlockState location to true, should create stores as necessary if the location does not exist
*
* @param blockState BlockState location to set
*/
public void setTrue(BlockState blockState);
void setTrue(BlockState blockState);
/**
* Set a given location to false, should not create stores if one does not exist for the given location
@@ -173,24 +173,24 @@ public interface ChunkManager {
* @param z Z coordinate to set
* @param world World to set in
*/
public void setFalse(int x, int y, int z, World world);
void setFalse(int x, int y, int z, World world);
/**
* Set a given block location to false, should not create stores if one does not exist for the given location
*
* @param block Block location to set
*/
public void setFalse(Block block);
void setFalse(Block block);
/**
* Set a given BlockState location to false, should not create stores if one does not exist for the given location
*
* @param blockState BlockState location to set
*/
public void setFalse(BlockState blockState);
void setFalse(BlockState blockState);
/**
* Delete any ChunkletStores that are empty
*/
public void cleanUp();
void cleanUp();
}

View File

@@ -13,28 +13,28 @@ public interface ChunkStore extends Serializable {
*
* @return true if the has been modified since it was last saved
*/
public boolean isDirty();
boolean isDirty();
/**
* Checks the chunk's save state
*
* @param dirty the save state of the current chunk
*/
public void setDirty(boolean dirty);
void setDirty(boolean dirty);
/**
* Checks the chunk's x coordinate
*
* @return the chunk's x coordinate.
*/
public int getChunkX();
int getChunkX();
/**
* Checks the chunk's z coordinate
*
* @return the chunk's z coordinate.
*/
public int getChunkZ();
int getChunkZ();
/**
* Checks the value at the given coordinates
@@ -44,7 +44,7 @@ public interface ChunkStore extends Serializable {
* @param z z coordinate in current chunklet
* @return true if the value is true at the given coordinates, false if otherwise
*/
public boolean isTrue(int x, int y, int z);
boolean isTrue(int x, int y, int z);
/**
* Set the value to true at the given coordinates
@@ -53,7 +53,7 @@ public interface ChunkStore extends Serializable {
* @param y y coordinate in current chunklet
* @param z z coordinate in current chunklet
*/
public void setTrue(int x, int y, int z);
void setTrue(int x, int y, int z);
/**
* Set the value to false at the given coordinates
@@ -62,17 +62,17 @@ public interface ChunkStore extends Serializable {
* @param y y coordinate in current chunklet
* @param z z coordinate in current chunklet
*/
public void setFalse(int x, int y, int z);
void setFalse(int x, int y, int z);
/**
* @return true if all values in the chunklet are false, false if otherwise
*/
public boolean isEmpty();
boolean isEmpty();
/**
* Set all values in this ChunkletStore to the values from another provided ChunkletStore
*
* @param otherStore Another ChunkletStore that this one should copy all data from
*/
public void copyFrom(ChunkletStore otherStore);
void copyFrom(ChunkletStore otherStore);
}

View File

@@ -11,10 +11,10 @@ import java.io.*;
import java.util.*;
public class HashChunkManager implements ChunkManager {
private HashMap<UUID, HashMap<Long, McMMOSimpleRegionFile>> regionFiles = new HashMap<UUID, HashMap<Long, McMMOSimpleRegionFile>>();
public HashMap<String, ChunkStore> store = new HashMap<String, ChunkStore>();
public ArrayList<BlockStoreConversionZDirectory> converters = new ArrayList<BlockStoreConversionZDirectory>();
private HashMap<UUID, Boolean> oldData = new HashMap<UUID, Boolean>();
private final HashMap<UUID, HashMap<Long, McMMOSimpleRegionFile>> regionFiles = new HashMap<>();
public HashMap<String, ChunkStore> store = new HashMap<>();
public ArrayList<BlockStoreConversionZDirectory> converters = new ArrayList<>();
private final HashMap<UUID, Boolean> oldData = new HashMap<>();
@Override
public synchronized void closeAll() {
@@ -38,31 +38,19 @@ public class HashChunkManager implements ChunkManager {
if (in == null) {
return null;
}
ObjectInputStream objectStream = new ObjectInputStream(in);
try {
try (ObjectInputStream objectStream = new ObjectInputStream(in)) {
Object o = objectStream.readObject();
if (o instanceof ChunkStore) {
return (ChunkStore) o;
}
throw new RuntimeException("Wrong class type read for chunk meta data for " + x + ", " + z);
}
catch (IOException e) {
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
// Assume the format changed
return null;
//throw new RuntimeException("Unable to process chunk meta data for " + x + ", " + z, e);
}
catch (ClassNotFoundException e) {
e.printStackTrace();
// Assume the format changed
//System.out.println("[SpoutPlugin] is Unable to find serialized class for " + x + ", " + z + ", " + e.getMessage());
return null;
//throw new RuntimeException("Unable to find serialized class for " + x + ", " + z, e);
}
finally {
objectStream.close();
}
}
@Override
@@ -98,12 +86,7 @@ public class HashChunkManager implements ChunkManager {
UUID key = world.getUID();
HashMap<Long, McMMOSimpleRegionFile> worldRegions = regionFiles.get(key);
if (worldRegions == null) {
worldRegions = new HashMap<Long, McMMOSimpleRegionFile>();
regionFiles.put(key, worldRegions);
}
HashMap<Long, McMMOSimpleRegionFile> worldRegions = regionFiles.computeIfAbsent(key, k -> new HashMap<>());
int rx = x >> 5;
int rz = z >> 5;
@@ -222,7 +205,7 @@ public class HashChunkManager implements ChunkManager {
closeAll();
String worldName = world.getName();
List<String> keys = new ArrayList<String>(store.keySet());
List<String> keys = new ArrayList<>(store.keySet());
for (String key : keys) {
String[] info = key.split(",");
if (worldName.equals(info[0])) {
@@ -244,7 +227,7 @@ public class HashChunkManager implements ChunkManager {
String worldName = world.getName();
List<String> keys = new ArrayList<String>(store.keySet());
List<String> keys = new ArrayList<>(store.keySet());
for (String key : keys) {
String[] info = key.split(",");
if (worldName.equals(info[0])) {

View File

@@ -29,7 +29,7 @@ public class McMMOSimpleRegionFile {
private final int[] dataStart = new int[1024];
private final int[] dataActualLength = new int[1024];
private final int[] dataLength = new int[1024];
private final ArrayList<Boolean> inuse = new ArrayList<Boolean>();
private final ArrayList<Boolean> inuse = new ArrayList<>();
private int segmentSize;
private int segmentMask;
private final int rx;
@@ -39,7 +39,7 @@ public class McMMOSimpleRegionFile {
@SuppressWarnings("unused")
private long lastAccessTime = System.currentTimeMillis();
@SuppressWarnings("unused")
private static long TIMEOUT_TIME = 300000; // 5 min
private static final long TIMEOUT_TIME = 300000; // 5 min
public McMMOSimpleRegionFile(File f, int rx, int rz) {
this(f, rx, rz, 10);

View File

@@ -28,7 +28,6 @@ public class BlockStoreConversionMain implements Runnable {
}
this.taskID = this.scheduler.runTaskLater(mcMMO.p, this, 1).getTaskId();
return;
}
@Override
@@ -87,6 +86,5 @@ public class BlockStoreConversionMain implements Runnable {
this.world = null;
this.scheduler = null;
this.converters = null;
return;
}
}

View File

@@ -29,7 +29,6 @@ public class BlockStoreConversionXDirectory implements Runnable {
}
this.taskID = this.scheduler.runTaskLater(mcMMO.p, this, 1).getTaskId();
return;
}
@Override

View File

@@ -42,7 +42,6 @@ public class BlockStoreConversionZDirectory implements Runnable {
}
this.taskID = this.scheduler.runTaskLater(mcMMO.p, this, 1).getTaskId();
return;
}
@Override

View File

@@ -32,9 +32,9 @@ import java.util.List;
import java.util.Locale;
public final class CommandRegistrationManager {
private CommandRegistrationManager() {};
private CommandRegistrationManager() {}
private static String permissionsMessage = LocaleLoader.getString("mcMMO.NoPermission");
private static final String permissionsMessage = LocaleLoader.getString("mcMMO.NoPermission");
private static void registerSkillCommands() {
for (PrimarySkillType skill : PrimarySkillType.values()) {
@@ -199,7 +199,7 @@ public final class CommandRegistrationManager {
}
private static void registerXprateCommand() {
List<String> aliasList = new ArrayList<String>();
List<String> aliasList = new ArrayList<>();
aliasList.add("mcxprate");
PluginCommand command = mcMMO.p.getCommand("xprate");

View File

@@ -106,7 +106,7 @@ public final class CommandUtils {
}
public static boolean hasPlayerDataKey(CommandSender sender) {
if (sender == null || !(sender instanceof Player)) {
if (!(sender instanceof Player)) {
return false;
}
@@ -221,7 +221,7 @@ public final class CommandUtils {
PlayerProfile profile = UserManager.getPlayer(inspect).getProfile();
List<String> displayData = new ArrayList<String>();
List<String> displayData = new ArrayList<>();
displayData.add(header);
for (PrimarySkillType skill : skillGroup) {
@@ -239,7 +239,7 @@ public final class CommandUtils {
public static List<String> getOnlinePlayerNames(CommandSender sender) {
Player player = sender instanceof Player ? (Player) sender : null;
List<String> onlinePlayerNames = new ArrayList<String>();
List<String> onlinePlayerNames = new ArrayList<>();
for (Player onlinePlayer : mcMMO.p.getServer().getOnlinePlayers()) {
if (player != null && player.canSee(onlinePlayer)) {
@@ -286,7 +286,7 @@ public final class CommandUtils {
* @return List of all possible names
*/
private static List<String> matchPlayer(String partialName) {
List<String> matchedPlayers = new ArrayList<String>();
List<String> matchedPlayers = new ArrayList<>();
for (OfflinePlayer offlinePlayer : mcMMO.p.getServer().getOfflinePlayers()) {
String playerName = offlinePlayer.getName();

View File

@@ -104,23 +104,21 @@ public class CompatibilityManager {
}
private NMSVersion determineNMSVersion() {
switch(minecraftGameVersion.getMajorVersion().asInt()) {
case 1:
switch(minecraftGameVersion.getMinorVersion().asInt()) {
case 12:
return NMSVersion.NMS_1_12_2;
case 13:
return NMSVersion.NMS_1_13_2;
case 14:
return NMSVersion.NMS_1_14_4;
case 15:
return NMSVersion.NMS_1_15_2;
case 16:
switch(minecraftGameVersion.getPatchVersion().asInt()) {
case 1:
return NMSVersion.NMS_1_16_1;
}
}
if (minecraftGameVersion.getMajorVersion().asInt() == 1) {
switch (minecraftGameVersion.getMinorVersion().asInt()) {
case 12:
return NMSVersion.NMS_1_12_2;
case 13:
return NMSVersion.NMS_1_13_2;
case 14:
return NMSVersion.NMS_1_14_4;
case 15:
return NMSVersion.NMS_1_15_2;
case 16:
if (minecraftGameVersion.getPatchVersion().asInt() == 1) {
return NMSVersion.NMS_1_16_1;
}
}
}
return NMSVersion.UNSUPPORTED;

View File

@@ -28,6 +28,5 @@ public class DummyPlayerAttackCooldownExploitPreventionLayer extends PlayerAttac
@Override
public void resetAttackStrength(Player player) throws InvocationTargetException, IllegalAccessException {
//Do nothing
return;
}
}

View File

@@ -12,7 +12,7 @@ import java.util.HashMap;
import java.util.Map;
public class FormulaManager {
private static File formulaFile = new File(mcMMO.getFlatFileDirectory() + "formula.yml");
private static final File formulaFile = new File(mcMMO.getFlatFileDirectory() + "formula.yml");
// Experience needed to reach a level, cached values to improve conversion speed
private Map<Integer, Integer> experienceNeededRetroLinear;
@@ -116,9 +116,9 @@ public class FormulaManager {
* @return amount of experience needed to reach next level
*/
public int getXPtoNextLevel(int level, FormulaType formulaType) {
/**
* Retro mode XP requirements are the default requirements
* Standard mode XP requirements are multiplied by a factor of 10
/*
Retro mode XP requirements are the default requirements
Standard mode XP requirements are multiplied by a factor of 10
*/
//TODO: When the heck is Unknown used?

View File

@@ -3,7 +3,7 @@ package com.gmail.nossr50.util.platform.version;
import org.jetbrains.annotations.NotNull;
public class SimpleNumericVersion extends SimpleVersion implements NumericVersioned {
private int versionNumber;
private final int versionNumber;
public SimpleNumericVersion(int versionNumber) {
super(String.valueOf(versionNumber));

View File

@@ -33,7 +33,7 @@ public final class UserManager {
}
public static void cleanupPlayer(McMMOPlayer mcMMOPlayer) {
if(playerDataSet != null && playerDataSet.contains(mcMMOPlayer))
if(playerDataSet != null)
playerDataSet.remove(mcMMOPlayer);
}
@@ -47,7 +47,7 @@ public final class UserManager {
mcMMOPlayer.cleanup();
player.removeMetadata(mcMMO.playerDataKey, mcMMO.p);
if(playerDataSet != null && playerDataSet.contains(mcMMOPlayer)) {
if(playerDataSet != null) {
playerDataSet.remove(mcMMOPlayer); //Clear sync save tracking
}
}
@@ -91,7 +91,7 @@ public final class UserManager {
}
public static Collection<McMMOPlayer> getPlayers() {
Collection<McMMOPlayer> playerCollection = new ArrayList<McMMOPlayer>();
Collection<McMMOPlayer> playerCollection = new ArrayList<>();
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
if (hasPlayerDataKey(player)) {

View File

@@ -25,7 +25,7 @@ import java.util.*;
* Manages the Scoreboards used to display a variety of mcMMO related information to the player
*/
public class ScoreboardManager {
static final Map<String, ScoreboardWrapper> PLAYER_SCOREBOARDS = new HashMap<String, ScoreboardWrapper>();
static final Map<String, ScoreboardWrapper> PLAYER_SCOREBOARDS = new HashMap<>();
// do not localize; these are internal identifiers
static final String SIDEBAR_OBJECTIVE = "mcmmo_sidebar";
@@ -90,10 +90,10 @@ public class ScoreboardManager {
skillLabelBuilder.put(type, getShortenedName(colors.get(i) + type.getName(), false));
if (type.getAbility() != null) {
abilityLabelBuilder.put(type.getAbility(), getShortenedName(colors.get(i) + type.getAbility().getName()));
abilityLabelBuilder.put(type.getAbility(), getShortenedName(colors.get(i) + type.getAbility().getLocalizedName()));
if (type == PrimarySkillType.MINING) {
abilityLabelBuilder.put(SuperAbilityType.BLAST_MINING, getShortenedName(colors.get(i) + SuperAbilityType.BLAST_MINING.getName()));
abilityLabelBuilder.put(SuperAbilityType.BLAST_MINING, getShortenedName(colors.get(i) + SuperAbilityType.BLAST_MINING.getLocalizedName()));
}
}
@@ -112,17 +112,17 @@ public class ScoreboardManager {
skillLabelBuilder.put(type, getShortenedName(ChatColor.GREEN + type.getName()));
if (type.getAbility() != null) {
abilityLabelBuilder.put(type.getAbility(), formatAbility(type.getAbility().getName()));
abilityLabelBuilder.put(type.getAbility(), formatAbility(type.getAbility().getLocalizedName()));
if (type == PrimarySkillType.MINING) {
abilityLabelBuilder.put(SuperAbilityType.BLAST_MINING, formatAbility(SuperAbilityType.BLAST_MINING.getName()));
abilityLabelBuilder.put(SuperAbilityType.BLAST_MINING, formatAbility(SuperAbilityType.BLAST_MINING.getLocalizedName()));
}
}
}
}
for (SuperAbilityType type : SuperAbilityType.values()) {
abilityLabelSkillBuilder.put(type, formatAbility((type == SuperAbilityType.BLAST_MINING ? ChatColor.BLUE : ChatColor.AQUA), type.getName()));
abilityLabelSkillBuilder.put(type, formatAbility((type == SuperAbilityType.BLAST_MINING ? ChatColor.BLUE : ChatColor.AQUA), type.getLocalizedName()));
}
skillLabels = skillLabelBuilder.build();
@@ -130,7 +130,7 @@ public class ScoreboardManager {
abilityLabelsSkill = abilityLabelSkillBuilder.build();
}
private static List<String> dirtyPowerLevels = new ArrayList<String>();
private static final List<String> dirtyPowerLevels = new ArrayList<>();
public enum SidebarType {
NONE,
@@ -138,7 +138,7 @@ public class ScoreboardManager {
STATS_BOARD,
COOLDOWNS_BOARD,
RANK_BOARD,
TOP_BOARD;
TOP_BOARD
}
private static String formatAbility(String abilityName) {

View File

@@ -37,7 +37,7 @@ public class ScoreboardWrapper {
// Internal usage variables (should exist)
private SidebarType sidebarType;
private Objective sidebarObjective;
private Objective powerObjective;
private final Objective powerObjective;
// Parameter variables (May be null / invalid)
private Scoreboard oldBoard = null;
@@ -235,8 +235,8 @@ public class ScoreboardWrapper {
if (oldBoard != null) {
if (player.getScoreboard() == scoreboard) {
/**
* Call the revert scoreboard custom event
/*
Call the revert scoreboard custom event
*/
McMMOScoreboardRevertEvent event = new McMMOScoreboardRevertEvent(oldBoard, player.getScoreboard(), player, ScoreboardEventReason.REVERTING_BOARD);
player.getServer().getPluginManager().callEvent(event);

View File

@@ -958,7 +958,7 @@ public final class CombatUtils {
@Deprecated
public static double getFakeDamageFinalResult(Entity attacker, Entity target, double damage) {
return getFakeDamageFinalResult(attacker, target, DamageCause.ENTITY_ATTACK, new EnumMap<DamageModifier, Double>(ImmutableMap.of(DamageModifier.BASE, damage)));
return getFakeDamageFinalResult(attacker, target, DamageCause.ENTITY_ATTACK, new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, damage)));
}
@Deprecated
@@ -1004,7 +1004,7 @@ public final class CombatUtils {
}
private static Map<DamageModifier, Double> getModifiers(EntityDamageEvent event) {
Map<DamageModifier, Double> modifiers = new HashMap<DamageModifier, Double>();
Map<DamageModifier, Double> modifiers = new HashMap<>();
for (DamageModifier modifier : DamageModifier.values()) {
modifiers.put(modifier, event.getDamage(modifier));
}
@@ -1013,7 +1013,7 @@ public final class CombatUtils {
}
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<>();
for (DamageModifier modifier : modifiers.keySet()) {
if (modifier == DamageModifier.BASE) {

View File

@@ -14,7 +14,7 @@ import org.bukkit.entity.Player;
public final class ParticleEffectUtils {
private ParticleEffectUtils() {};
private ParticleEffectUtils() {}
public static void playGreenThumbEffect(Location location) {
World world = location.getWorld();
@@ -85,19 +85,8 @@ public final class ParticleEffectUtils {
livingEntity.getWorld().playEffect(livingEntity.getEyeLocation(), Effect.MOBSPAWNER_FLAMES, 1);
}
public static void playAbilityEnabledEffect(Player player) {
if (!Config.getInstance().getAbilityActivationEffectEnabled()) {
return;
}
/* if (hasHeadRoom(player)) {
fireworkParticleShower(player, Color.GREEN);
}*/
}
public static void playAbilityDisabledEffect(Player player) {
if (!Config.getInstance().getAbilityDeactivationEffectEnabled()) {
return;
}
/*if (hasHeadRoom(player)) {

View File

@@ -11,7 +11,7 @@ public final class PerksUtils {
private static final int LUCKY_SKILL_ACTIVATION_CHANCE = 75;
private static final int NORMAL_SKILL_ACTIVATION_CHANCE = 100;
private PerksUtils() {};
private PerksUtils() {}
public static int handleCooldownPerks(Player player, int cooldown) {
if (Permissions.halvedCooldowns(player)) {
@@ -47,7 +47,6 @@ public final class PerksUtils {
public static float handleXpPerks(Player player, float xp, PrimarySkillType skill) {
double modifier = 1.0F;
double originalXP = xp;
if (Permissions.customXpBoost(player, skill)) {
if(UserManager.getPlayer(player) != null && UserManager.getPlayer(player).isDebugMode()) {
@@ -79,7 +78,7 @@ public final class PerksUtils {
if(UserManager.getPlayer(player) != null && UserManager.getPlayer(player).isDebugMode()) {
player.sendMessage(ChatColor.GOLD + "[DEBUG] " + ChatColor.RESET + "XP Perk Multiplier - " + ChatColor.GOLD + modifier);
player.sendMessage(ChatColor.GOLD + "[DEBUG] " + ChatColor.RESET + "Original XP before perk boosts " + ChatColor.RED + originalXP);
player.sendMessage(ChatColor.GOLD + "[DEBUG] " + ChatColor.RESET + "Original XP before perk boosts " + ChatColor.RED + (double) xp);
player.sendMessage(ChatColor.GOLD + "[DEBUG] " + ChatColor.RESET + "XP AFTER PERKS " + ChatColor.DARK_RED + modifiedXP);
}

View File

@@ -276,8 +276,7 @@ public class RankUtils {
if (subSkillRanks == null)
subSkillRanks = new HashMap<>();
if (subSkillRanks.get(s) == null)
subSkillRanks.put(s, new HashMap<>());
subSkillRanks.computeIfAbsent(s, k -> new HashMap<>());
}
/* public static int getSubSkillUnlockRequirement(SubSkillType subSkillType)

View File

@@ -172,7 +172,7 @@ public class SkillUtils {
int efficiencyLevel = heldItem.getEnchantmentLevel(Enchantment.DIG_SPEED);
ItemMeta itemMeta = heldItem.getItemMeta();
List<String> itemLore = new ArrayList<String>();
List<String> itemLore = new ArrayList<>();
if (itemMeta.hasLore()) {
itemLore = itemMeta.getLore();

View File

@@ -0,0 +1,62 @@
package com.gmail.nossr50.util.skills;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.smelting.Smelting;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Permissions;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Furnace;
import org.bukkit.entity.Player;
import org.bukkit.inventory.FurnaceInventory;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
public class SmeltingTracker {
private HashMap<Furnace, OfflinePlayer> furnaceOwners;
public SmeltingTracker() {
furnaceOwners = new HashMap<>();
}
private void changeFurnaceOwnership(Furnace furnace, Player player) {
furnaceOwners.put(furnace, player);
}
@Nullable
public Furnace getFurnaceFromInventory(Inventory inventory) {
if (!(inventory instanceof FurnaceInventory)) {
return null;
}
return (Furnace) inventory.getHolder();
}
@Nullable
public OfflinePlayer getPlayerFromFurnace(Furnace furnace) {
return furnaceOwners.get(furnace);
}
public boolean isFurnaceOwned(Furnace furnace) {
return furnaceOwners.get(furnace) != null;
}
public void removeFurnaceOwner(Furnace furnace) {
furnaceOwners.remove(furnace);
}
public void processFurnaceOwnership(Furnace furnace, Player player) {
if(!Permissions.skillEnabled(player, PrimarySkillType.SMELTING))
return;
changeFurnaceOwnership(furnace, player);
}
public void untrackFurnace(Furnace furnace) {
furnaceOwners.remove(furnace);
}
}

View File

@@ -1,111 +0,0 @@
package com.gmail.nossr50.util.uuid;
import com.google.common.collect.ImmutableList;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.ByteBuffer;
import java.util.*;
import java.util.concurrent.Callable;
public class UUIDFetcher implements Callable<Map<String, UUID>> {
private static final int PROFILES_PER_REQUEST = 10;
private static final long RATE_LIMIT = 100L;
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
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();
List<String> nameSubList = names.subList(i * PROFILES_PER_REQUEST, Math.min((i + 1) * PROFILES_PER_REQUEST, names.size()));
JsonArray array = new JsonArray();
for(String name : nameSubList)
{
JsonPrimitive element = new JsonPrimitive(name);
array.add(element);
}
Gson gson = new Gson();
String body = array.toString();
writeBody(connection, body);
InputStreamReader tempStream = new InputStreamReader(connection.getInputStream());
JsonObject[] jsonStreamArray = gson.fromJson(tempStream, JsonObject[].class);
tempStream.close();
for (JsonObject jsonProfile : jsonStreamArray) {
String id = jsonProfile.get("id").getAsString();
String name = jsonProfile.get("name").getAsString();
UUID uuid = UUIDFetcher.getUUID(id);
uuidMap.put(name, uuid);
}
if (rateLimiting && i != requests - 1) {
Thread.sleep(RATE_LIMIT);
}
}
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);
}
}