This commit is contained in:
ASangarin 2020-09-26 19:48:16 +02:00
commit 06cb4d7d17
9 changed files with 87 additions and 55 deletions

View File

@ -89,9 +89,10 @@ import net.mmogroup.mmolib.api.player.MMOPlayerData;
import net.mmogroup.mmolib.version.SpigotPlugin;
public class MMOItems extends JavaPlugin {
/* Introducing: The commit comment!
* Just change this a tiny bit each time you
* need to push a new build. It's convenient!
/*
* Introducing: The commit comment! Just change this a tiny bit each time
* you need to push a new build. It's convenient!
*/
public static MMOItems plugin;
@ -149,7 +150,7 @@ public class MMOItems extends JavaPlugin {
*/
statManager = new StatManager();
typeManager.reload();
templateManager.loadCompatibility();
templateManager.preloadTemplates();
if (Bukkit.getPluginManager().getPlugin("MMOCore") != null)
new MMOCoreMMOLoader();
@ -177,14 +178,15 @@ public class MMOItems extends JavaPlugin {
findRpgPlugin();
templateManager.reload();
/*
* After tiers, sets and upgrade templates are loaded, MI template data
* CAN be fully loaded
* can be fully loaded
*/
tierManager = new TierManager();
setManager = new SetManager();
upgradeManager = new UpgradeManager();
templateManager.postloadTemplates();
dropTableManager = new DropTableManager();
dynamicUpdater = new UpdaterManager();
@ -294,14 +296,13 @@ public class MMOItems extends JavaPlugin {
// compatibility with /reload
Bukkit.getScheduler().runTask(this, () -> Bukkit.getOnlinePlayers().forEach(player -> PlayerData.load(player)));
if(getConfig().getBoolean("recipes.recipe-amounts")) {
if (getConfig().getBoolean("recipes.recipe-amounts")) {
RecipeBookUtil.enableAmounts();
Bukkit.getPluginManager().registerEvents(new CraftingListener(), this);
}
if(getConfig().getBoolean("recipes.use-recipe-book"))
if (getConfig().getBoolean("recipes.use-recipe-book"))
RecipeBookUtil.enableBook();
// amount and bukkit recipes
getLogger().log(Level.INFO, "Loading recipes, please wait...");
recipeManager.loadRecipes();

View File

@ -71,7 +71,7 @@ public class GemStone extends UseItem {
* permanent effects. also REGISTER gem stone in the item gem stone
* list.
*/
LiveMMOItem mmo = new LiveMMOItem(nbt);
LiveMMOItem mmo = new LiveMMOItem(getNBTItem());
GemstoneData gemData = new GemstoneData(mmo);
sockets.apply(gemType, gemData);

View File

@ -28,7 +28,7 @@ public class Tool extends UseItem {
public boolean miningEffects(Block block) {
boolean cancel = false;
if (nbt.getBoolean("MMOITEMS_AUTOSMELT"))
if (getNBTItem().getBoolean("MMOITEMS_AUTOSMELT"))
if (block.getType() == Material.IRON_ORE || block.getType() == Material.GOLD_ORE) {
ItemStack item = new ItemStack(Material.valueOf(block.getType().name().replace("_ORE", "") + "_INGOT"));
@ -39,7 +39,7 @@ public class Tool extends UseItem {
cancel = true;
}
if (nbt.getBoolean("MMOITEMS_BOUNCING_CRACK"))
if (getNBTItem().getBoolean("MMOITEMS_BOUNCING_CRACK"))
new BukkitRunnable() {
Vector v = player.getEyeLocation().getDirection().multiply(.5);
Location loc = block.getLocation().clone().add(.5, .5, .5);
@ -60,8 +60,8 @@ public class Tool extends UseItem {
}
}.runTaskTimer(MMOItems.plugin, 0, 1);
if (nbt.hasTag("MMOITEMS_BREAK_SIZE")) {
int breakSize = nbt.getInteger("MMOITEMS_BREAK_SIZE");
if (getNBTItem().hasTag("MMOITEMS_BREAK_SIZE")) {
int breakSize = getNBTItem().getInteger("MMOITEMS_BREAK_SIZE");
if(breakSize % 2 != 0) {
BlockFace face = player.getFacing();
System.out.println("Debug: Facing - " + face);

View File

@ -28,7 +28,6 @@ public class UseItem {
protected final Player player;
protected final PlayerData playerData;
protected final VolatileMMOItem mmoitem;
protected final NBTItem nbt;
protected static final Random random = new Random();
@ -40,7 +39,6 @@ public class UseItem {
this.player = playerData.getPlayer();
this.playerData = playerData;
this.mmoitem = new VolatileMMOItem(nbtItem);
this.nbt = nbtItem;
}
public Player getPlayer() {
@ -56,15 +54,15 @@ public class UseItem {
}
public NBTItem getNBTItem() {
return nbt;
return mmoitem.getNBT();
}
public ItemStack getItem() {
return nbt.getItem();
return mmoitem.getNBT().getItem();
}
public boolean canBeUsed() {
return playerData.getRPG().canUse(nbt, true);
return playerData.getRPG().canUse(mmoitem.getNBT(), true);
}
public void executeCommands() {

View File

@ -20,8 +20,9 @@ import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
import net.Indyuce.mmoitems.api.player.RPGPlayer;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.mmogroup.mmolib.api.util.PostLoadObject;
public class MMOItemTemplate implements ItemReference {
public class MMOItemTemplate extends PostLoadObject implements ItemReference {
private final Type type;
private final String id;
@ -42,6 +43,8 @@ public class MMOItemTemplate implements ItemReference {
* different item types share the same ID
*/
public MMOItemTemplate(Type type, String id) {
super(null);
this.type = type;
this.id = id;
}
@ -55,11 +58,15 @@ public class MMOItemTemplate implements ItemReference {
* The config file read to load the template
*/
public MMOItemTemplate(Type type, ConfigurationSection config) {
super(config);
Validate.notNull(config, "Could not load template config");
this.type = type;
this.id = config.getName().toUpperCase().replace("-", "_").replace(" ", "_");
}
@Override
protected void whenPostLoaded(ConfigurationSection config) {
if (config.contains("option"))
for (TemplateOption option : TemplateOption.values())
if (config.getBoolean("option." + option.name().toLowerCase().replace("_", "-")))

View File

@ -4,21 +4,16 @@ import org.bukkit.Sound;
import org.bukkit.entity.Player;
public class SoundReader {
private Sound sound;
private boolean valid;
private final Sound sound;
public SoundReader(String tag, Sound defaultSound) {
if (tag.equals("")) {
sound = defaultSound;
return;
}
Sound sound;
try {
sound = Sound.valueOf(tag);
valid = true;
} catch (Exception e) {
sound = defaultSound;
}
this.sound = sound;
}
public Sound getSound() {
@ -30,7 +25,6 @@ public class SoundReader {
}
public void play(Player player, float vol, float pitch) {
if (valid)
player.playSound(player.getLocation(), sound, vol, pitch);
player.playSound(player.getLocation(), sound, vol, pitch);
}
}

View File

@ -172,7 +172,7 @@ public class ItemUse implements Listener {
event.setDamage(result.getDamage());
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void c(BlockBreakEvent event) {
Player player = event.getPlayer();
Block block = event.getBlock();

View File

@ -217,7 +217,7 @@ public class RecipeManager {
}
/**
* Used to handle furnace/smoker/campifire/furnace extra crafting recipe
* Used to handle furnace/smoker/campfire/furnace extra crafting recipe
* parameters
*
* @author ASangarin

View File

@ -113,6 +113,7 @@ public class TemplateManager {
try {
MMOItemTemplate template = new MMOItemTemplate(type,
type.getConfigFile().getConfig().getConfigurationSection(id));
template.postLoad();
registerTemplate(template);
return template;
@ -174,6 +175,58 @@ public class TemplateManager {
return (int) found;
}
/**
* Templates must be loaded whenever MMOItems enables so that other plugins
* like MMOCore can load template references in drop items or other objects.
* Template data is only loaded when MMOItems enables, once sets, tiers..
* are initialized
*/
public void preloadTemplates() {
for (Type type : MMOItems.plugin.getTypes().getAll()) {
FileConfiguration config = type.getConfigFile().getConfig();
for (String key : config.getKeys(false))
try {
registerTemplate(new MMOItemTemplate(type, config.getConfigurationSection(key)));
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.INFO, "Could not preload item template '" + key + "': " + exception.getMessage());
}
}
}
/**
* Loads item generator modifiers and post load item templates.
*/
public void postloadTemplates() {
MMOItems.plugin.getLogger().log(Level.INFO, "Loading template modifiers, please wait..");
for (File file : new File(MMOItems.plugin.getDataFolder() + "/modifiers").listFiles()) {
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
for (String key : config.getKeys(false))
try {
TemplateModifier modifier = new TemplateModifier(config.getConfigurationSection(key));
modifiers.put(modifier.getId(), modifier);
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.INFO, "Could not load template modifier '" + key + "': " + exception.getMessage());
}
}
MMOItems.plugin.getLogger().log(Level.INFO, "Loading item templates, please wait..");
templates.forEach(template -> {
try {
template.postLoad();
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.INFO, "Could not load item template '" + template.getId() + "': " + exception.getMessage());
}
});
}
/**
* Reloads the item templates. This is the method used to reload the manager
* when the server is already running. It clears all the maps and loads
* everything again. Template references in other plugins like MMOCore must
* be refreshed afterwards.
*/
public void reload() {
templates.clear();
modifiers.clear();
@ -186,8 +239,7 @@ public class TemplateManager {
TemplateModifier modifier = new TemplateModifier(config.getConfigurationSection(key));
modifiers.put(modifier.getId(), modifier);
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.INFO,
"Could not load template modifier '" + key + "': " + exception.getMessage());
MMOItems.plugin.getLogger().log(Level.INFO, "Could not load template modifier '" + key + "': " + exception.getMessage());
}
}
@ -198,28 +250,8 @@ public class TemplateManager {
try {
registerTemplate(new MMOItemTemplate(type, config.getConfigurationSection(key)));
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.INFO,
"Could not load item template '" + key + "': " + exception.getMessage());
MMOItems.plugin.getLogger().log(Level.INFO, "Could not load item template '" + key + "': " + exception.getMessage());
}
}
}
// this loads dummy items for on load so
// plugins that enable before mmoitems that use
// items (mmocore) don't error out and need
// a reload
public void loadCompatibility() {
templates.clear();
for (Type type : MMOItems.plugin.getTypes().getAll()) {
FileConfiguration config = type.getConfigFile().getConfig();
for (String key : config.getKeys(false))
try {
registerTemplate(new MMOItemTemplate(type, key));
} catch (IllegalArgumentException ignored) {
}
}
}
}