Removed lootsplosions console message when MM is off

This commit is contained in:
Indyuce 2020-12-20 23:20:51 +01:00
parent 688a9c5e8d
commit c7466b191c
5 changed files with 140 additions and 155 deletions

View File

@ -1,5 +1,21 @@
package net.Indyuce.mmoitems;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import javax.annotation.Nullable;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import net.Indyuce.mmoitems.api.ClaseMuyImportante;
import net.Indyuce.mmoitems.api.ConfigFile;
import net.Indyuce.mmoitems.api.ItemTier;
@ -72,20 +88,6 @@ import net.Indyuce.mmoitems.manager.TypeManager;
import net.Indyuce.mmoitems.manager.UpgradeManager;
import net.Indyuce.mmoitems.manager.WorldGenManager;
import net.mmogroup.mmolib.version.SpigotPlugin;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import javax.annotation.Nullable;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
public class MMOItems extends JavaPlugin {
public static MMOItems plugin;
@ -124,19 +126,21 @@ public class MMOItems extends JavaPlugin {
public void onLoad() {
plugin = this;
if (getServer().getPluginManager().getPlugin("WorldGuard") != null) try {
flagPlugin = new WorldGuardFlags();
getLogger().log(Level.INFO, "Hooked onto WorldGuard");
} catch (Exception exception) {
getLogger().log(Level.WARNING, "Could not initialize support with WorldGuard 7: " + exception.getMessage());
}
if (getServer().getPluginManager().getPlugin("WorldGuard") != null)
try {
flagPlugin = new WorldGuardFlags();
getLogger().log(Level.INFO, "Hooked onto WorldGuard");
} catch (Exception exception) {
getLogger().log(Level.WARNING, "Could not initialize support with WorldGuard 7: " + exception.getMessage());
}
if (getServer().getPluginManager().getPlugin("WorldEdit") != null) try {
new WorldEditSupport();
getLogger().log(Level.INFO, "Hooked onto WorldEdit");
} catch (Exception exception) {
getLogger().log(Level.WARNING, "Could not initialize support with WorldEdit 7: " + exception.getMessage());
}
if (getServer().getPluginManager().getPlugin("WorldEdit") != null)
try {
new WorldEditSupport();
getLogger().log(Level.INFO, "Hooked onto WorldEdit");
} catch (Exception exception) {
getLogger().log(Level.WARNING, "Could not initialize support with WorldEdit 7: " + exception.getMessage());
}
saveDefaultConfig();
@ -148,7 +152,8 @@ public class MMOItems extends JavaPlugin {
typeManager.reload();
templateManager.preloadTemplates();
if (Bukkit.getPluginManager().getPlugin("MMOCore") != null) new MMOCoreMMOLoader();
if (Bukkit.getPluginManager().getPlugin("MMOCore") != null)
new MMOCoreMMOLoader();
}
public void onEnable() {
@ -162,13 +167,15 @@ public class MMOItems extends JavaPlugin {
final int defConfigVersion = getConfig().getDefaults().getInt("config-version");
if (configVersion != defConfigVersion || MMOItems.plugin.getLanguage().arruinarElPrograma) {
getLogger().warning("You may be using an outdated config.yml!");
getLogger().warning("(Your config version: '" + configVersion + "' | Expected config version: '" +
(MMOItems.plugin.getLanguage().arruinarElPrograma ? "steelballrun" : defConfigVersion) + "')");
getLogger().warning("(Your config version: '" + configVersion + "' | Expected config version: '"
+ (MMOItems.plugin.getLanguage().arruinarElPrograma ? "steelballrun" : defConfigVersion) + "')");
}
// registering here so the stats will load with the templates
if (Bukkit.getPluginManager().getPlugin("MythicMobs") != null) {
new MythicMobsLoader();
if (getConfig().getBoolean("lootsplosion.enabled"))
Bukkit.getPluginManager().registerEvents(new LootsplosionListener(), this);
getLogger().log(Level.INFO, "Hooked onto MythicMobs");
}
@ -193,7 +200,8 @@ public class MMOItems extends JavaPlugin {
worldGenManager = new WorldGenManager();
blockManager = new BlockManager();
if (Bukkit.getPluginManager().getPlugin("Vault") != null) vaultSupport = new VaultSupport();
if (Bukkit.getPluginManager().getPlugin("Vault") != null)
vaultSupport = new VaultSupport();
getLogger().log(Level.INFO, "Loading crafting stations, please wait..");
layoutManager.reload();
@ -210,22 +218,10 @@ public class MMOItems extends JavaPlugin {
Bukkit.getPluginManager().registerEvents(new GuiListener(), this);
Bukkit.getPluginManager().registerEvents(new ElementListener(), this);
Bukkit.getPluginManager().registerEvents(new CustomBlockListener(), this);
if (getConfig().getBoolean("lootsplosion.enabled")) {
if(Bukkit.getPluginManager().isPluginEnabled("MythicMobs"))
Bukkit.getPluginManager().registerEvents(new LootsplosionListener(), this);
else getLogger().warning("Lootsplosions are enabled, but MythicMobs was not found!");
}
/*
* this class implements the Listener, if the option
* perm-effects-apply-on-move is enabled the loop will not apply perm
* effects and this class will be registered as a listener. starts with
* a 5s delay to let the other plugins time to load nicely
*/
Bukkit.getScheduler().runTaskTimer(this, () -> Bukkit.getOnlinePlayers().forEach(player -> PlayerData.get(player).updateStats()), 100, 20);
if(MMOItems.plugin.getLanguage().arruinarElPrograma)
if (MMOItems.plugin.getLanguage().arruinarElPrograma)
Bukkit.getScheduler().runTaskTimer(this, ClaseMuyImportante::metodoMuyImportante, 780000L, 780000L);
/*
@ -282,7 +278,8 @@ public class MMOItems extends JavaPlugin {
if (Bukkit.getPluginManager().getPlugin("GlowAPI") != null && Bukkit.getPluginManager().getPlugin("PacketListenerApi") != null) {
Bukkit.getPluginManager().registerEvents(new ItemGlowListener(), this);
getLogger().log(Level.INFO, "Hooked onto GlowAPI (Item Glow)");
} else Bukkit.getPluginManager().registerEvents(new NoGlowListener(), this);
} else
Bukkit.getPluginManager().registerEvents(new NoGlowListener(), this);
}
if (Bukkit.getPluginManager().getPlugin("RealDualWield") != null) {
@ -310,7 +307,8 @@ public class MMOItems extends JavaPlugin {
}
recipeManager.load(book, amounts);
if (amounts) Bukkit.getPluginManager().registerEvents(new CraftingListener(), this);
if (amounts)
Bukkit.getPluginManager().registerEvents(new CraftingListener(), this);
// amount and bukkit recipes
getLogger().log(Level.INFO, "Loading recipes, please wait...");
@ -488,11 +486,14 @@ public class MMOItems extends JavaPlugin {
* External API's
*/
public boolean hasPermissions() {
if(vaultSupport == null) return false;
if (vaultSupport == null)
return false;
return vaultSupport.getPermissions() != null;
}
public boolean hasEconomy() {
if(vaultSupport == null) return false;
if (vaultSupport == null)
return false;
return vaultSupport.getEconomy() != null;
}
@ -505,7 +506,8 @@ public class MMOItems extends JavaPlugin {
}
public void findRpgPlugin() {
if (rpgPlugin != null) return;
if (rpgPlugin != null)
return;
for (RPGHandler.PluginEnum plugin : RPGHandler.PluginEnum.values())
if (Bukkit.getPluginManager().getPlugin(plugin.getName()) != null) {
@ -519,9 +521,9 @@ public class MMOItems extends JavaPlugin {
/**
* @return Generates an item given an item template. The item level will
* scale according to the player RPG level if the template has the
* 'level-item' option. The item will pick a random tier if the
* template has the 'tiered' option
* scale according to the player RPG level if the template has the
* 'level-item' option. The item will pick a random tier if the
* template has the 'tiered' option
*/
public MMOItem getMMOItem(Type type, String id, PlayerData player) {
return templateManager.getTemplate(type, id).newBuilder(player.getRPG()).build();
@ -532,10 +534,10 @@ public class MMOItems extends JavaPlugin {
}
/**
* @param itemLevel The desired item level
* @param itemTier The desired item tier, can be null
* @return Generates an item given an item template with a specific item
* level and item tier
* @param itemLevel The desired item level
* @param itemTier The desired item tier, can be null
* @return Generates an item given an item template with a
* specific item level and item tier
*/
public MMOItem getMMOItem(Type type, String id, int itemLevel, @Nullable ItemTier itemTier) {
return templateManager.getTemplate(type, id).newBuilder(itemLevel, itemTier).build();
@ -547,8 +549,8 @@ public class MMOItems extends JavaPlugin {
/**
* @return Generates an item given an item template. The item level will be
* 0 and the item will have no item tier unless one is specified in
* the base item data.
* 0 and the item will have no item tier unless one is specified in
* the base item data.
*/
public MMOItem getMMOItem(Type type, String id) {
return templateManager.getTemplate(type, id).newBuilder(0, null).build();

View File

@ -21,13 +21,18 @@ public class DurabilityListener implements Listener {
private final List<DamageCause> ignoredCauses = Arrays.asList(DamageCause.DROWNING, DamageCause.SUICIDE, DamageCause.FALL, DamageCause.VOID,
DamageCause.FIRE_TICK, DamageCause.SUFFOCATION, DamageCause.POISON, DamageCause.WITHER, DamageCause.STARVATION, DamageCause.MAGIC);
/**
* Handles custom durability for player heads
*/
@EventHandler(ignoreCancelled = true)
public void playerDamage(EntityDamageEvent event) {
if (event.getEntityType() != EntityType.PLAYER || ignoredCauses.contains(event.getCause()))
return;
Player player = (Player) event.getEntity();
if (player.getEquipment().getHelmet() == null || player.getEquipment().getHelmet().getType() != Material.PLAYER_HEAD)
return;
ItemStack helmet = player.getEquipment().getHelmet();
DurabilityItem item = new DurabilityItem(player, helmet);

View File

@ -28,8 +28,7 @@ public class LootsplosionListener implements Listener {
private final boolean colored;
public LootsplosionListener() {
colored = Bukkit.getPluginManager().getPlugin("MMOItems") != null
&& MMOItems.plugin.getConfig().getBoolean("lootsplosion.show-color");
colored = MMOItems.plugin.getConfig().getBoolean("lootsplosion.show-color");
}
@EventHandler(priority = EventPriority.HIGH)
@ -80,7 +79,6 @@ public class LootsplosionListener implements Listener {
}
});
}
}
private Vector randomVector() {

View File

@ -26,60 +26,57 @@ import java.util.List;
import java.util.Optional;
public class MaterialStat extends ItemStat {
public MaterialStat() {
super("MATERIAL", VersionMaterial.GRASS_BLOCK.toMaterial(), "Material",
new String[]{"Your item material."}, new String[]{"all"});
}
public MaterialStat() {
super("MATERIAL", VersionMaterial.GRASS_BLOCK.toMaterial(), "Material", new String[] { "Your item material." }, new String[] { "all" });
}
@Override
public MaterialData whenInitialized(Object object) {
Validate.isTrue(object instanceof String, "Must specify material name as string");
return new MaterialData(Material.valueOf(((String) object).toUpperCase().replace("-", "_").replace(" ", "_")));
}
@Override
public MaterialData whenInitialized(Object object) {
Validate.isTrue(object instanceof String, "Must specify material name as string");
return new MaterialData(Material.valueOf(((String) object).toUpperCase().replace("-", "_").replace(" ", "_")));
}
@Override
public void whenClicked(EditionInventory inv, InventoryClickEvent event) {
new StatEdition(inv, ItemStats.MATERIAL).enable("Write in the chat the material you want.");
}
@Override
public void whenClicked(EditionInventory inv, InventoryClickEvent event) {
new StatEdition(inv, ItemStats.MATERIAL).enable("Write in the chat the material you want.");
}
@Override
public void whenInput(EditionInventory inv, String message, Object... info) {
Optional<Material> material = EnumUtils.getIfPresent(Material.class,
message.toUpperCase().replace("-", "_").replace(" ", "_"));
if(MMOItems.plugin.getLanguage().arruinarElPrograma)
material = Optional.of(Material.GLISTERING_MELON_SLICE);
if (material.isPresent()) {
inv.getEditedSection().set("material", material.get().name());
inv.registerTemplateEdition();
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Material successfully changed to " + material.get().name() + ".");
} else
inv.getPlayer().spigot().sendMessage(
new ComponentBuilder("Invalid material! (Click for a list of valid materials)").color(ChatColor.RED).event(
new ClickEvent(Action.OPEN_URL, "https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html")).create());
}
@Override
public void whenInput(EditionInventory inv, String message, Object... info) {
Optional<Material> material = EnumUtils.getIfPresent(Material.class, message.toUpperCase().replace("-", "_").replace(" ", "_"));
if (MMOItems.plugin.getLanguage().arruinarElPrograma)
material = Optional.of(Material.GLISTERING_MELON_SLICE);
if (material.isPresent()) {
inv.getEditedSection().set("material", material.get().name());
inv.registerTemplateEdition();
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Material successfully changed to " + material.get().name() + ".");
} else
inv.getPlayer().spigot().sendMessage(new ComponentBuilder("Invalid material! (Click for a list of valid materials)").color(ChatColor.RED)
.event(new ClickEvent(Action.OPEN_URL, "https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html")).create());
}
@Override
public void whenApplied(ItemStackBuilder item, StatData data) {
/*
* material is handled directly in the MMOBuilder constructor,
* therefore nothing needs to be done here
*/
}
@Override
public void whenApplied(ItemStackBuilder item, StatData data) {
/*
* material is handled directly in the MMOBuilder constructor, therefore
* nothing needs to be done here
*/
}
@Override
public void whenLoaded(ReadMMOItem mmoitem) {
mmoitem.setData(this, new MaterialData(mmoitem.getNBT().getItem().getType()));
}
@Override
public void whenLoaded(ReadMMOItem mmoitem) {
mmoitem.setData(this, new MaterialData(mmoitem.getNBT().getItem().getType()));
}
@Override
public void whenDisplayed(List<String> lore, RandomStatData statData) {
lore.add(ChatColor.GRAY + "Current Value: "
+ (statData.isPresent() ? ChatColor.GREEN + MMOUtils.caseOnWords(
((MaterialData) statData).getMaterial().name().toLowerCase().replace("_", " "))
: ChatColor.RED + "None"));
@Override
public void whenDisplayed(List<String> lore, RandomStatData statData) {
lore.add(ChatColor.GRAY + "Current Value: "
+ (statData.isPresent()
? ChatColor.GREEN + MMOUtils.caseOnWords(((MaterialData) statData).getMaterial().name().toLowerCase().replace("_", " "))
: ChatColor.RED + "None"));
lore.add("");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Left click to change this value.");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove this value.");
}
lore.add("");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Left click to change this value.");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove this value.");
}
}

View File

@ -15,7 +15,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public abstract class ItemStat {
private final String id, name;
private final Material material;
@ -33,21 +32,17 @@ public abstract class ItemStat {
/**
* Initializes an item stat
*
* @param id
* The item stat ID, used internally. Also determines the lower
* case path for config files
* @param material
* The material used to display the stat in the item edition GUI
* @param name
* The stat name which has a translation in the language files
* @param lore
* The stat description used in the edition GUI
* @param types
* Compatible types. Use 'all' to support all item types or
* !{type-name} to blacklist an item type
* @param materials
* Materials compatible with the item stat (eg Shield Pattern),
* any if empty
* @param id The item stat ID, used internally. Also determines the
* lower case path for config files
* @param material The material used to display the stat in the item
* edition GUI
* @param name The stat name which has a translation in the language
* files
* @param lore The stat description used in the edition GUI
* @param types Compatible types. Use 'all' to support all item types or
* !{type-name} to blacklist an item type
* @param materials Materials compatible with the item stat (eg Shield
* Pattern), any if empty
*/
public ItemStat(String id, Material material, String name, String[] lore, String[] types, Material... materials) {
this.id = id;
@ -61,9 +56,8 @@ public abstract class ItemStat {
/**
* When random stat data is being read from a config file
*
* @param object
* Could be a config section, a string, a string list, etc.
* @return Random stat data read from config, or throws an IAE
* @param object Could be a config section, a string, a string list, etc.
* @return Random stat data read from config, or throws an IAE
*/
public abstract RandomStatData whenInitialized(Object object);
@ -71,20 +65,16 @@ public abstract class ItemStat {
* Called when applying a stat onto an mmoitem builder instance. Applies
* item tags, adds required lines to the item lore, etc.
*
* @param item
* MMOItem builder which must be completed
* @param data
* Stat data being applied
* @param item MMOItem builder which must be completed
* @param data Stat data being applied
*/
public abstract void whenApplied(ItemStackBuilder item, StatData data);
/**
* Called when the stat item is clicked in the item edition menu
*
* @param inv
* Inventory clicked
* @param event
* Click event
* @param inv Inventory clicked
* @param event Click event
*/
public abstract void whenClicked(EditionInventory inv, InventoryClickEvent event);
@ -94,22 +84,18 @@ public abstract class ItemStat {
* the player. Stat edition is not canceled until a right input is given or
* the player inputs 'cancel'
*
* @param inv
* Previously opened edition menu
* @param message
* Player input
* @param info
* Extra information given by the stat when instanciating
* StatEdition given to this method to identify what is being
* edited
* @param inv Previously opened edition menu
* @param message Player input
* @param info Extra information given by the stat when instanciating
* StatEdition given to this method to identify what is being
* edited
*/
public abstract void whenInput(EditionInventory inv, String message, Object... info);
/**
* Called when stat data is read from an ItemStack in a player inventory
*
* @param mmoitem
* NBTItem being read and transformed into a MMOItem instance
* @param mmoitem NBTItem being read and transformed into a MMOItem instance
*/
public abstract void whenLoaded(ReadMMOItem mmoitem);
@ -119,11 +105,9 @@ public abstract class ItemStat {
* modifier or base item data. It is much easier to display RandomStatData
* if it exists
*
* @param lore
* Current item lore which must be completed
* @param statData
* Stat data being displayed, optional is empty if there is no
* stat data
* @param lore Current item lore which must be completed
* @param statData Stat data being displayed, optional is empty if there is
* no stat data
*/
public abstract void whenDisplayed(List<String> lore, RandomStatData statData);
@ -136,7 +120,7 @@ public abstract class ItemStat {
}
/**
* @return The stat ID
* @return The stat ID
* @deprecated Use getId() instead. Type is no longer an util since they can
* now be registered from external plugins
*/
@ -175,9 +159,8 @@ public abstract class ItemStat {
}
/**
* @param type
* The item type to check
* @return If a certain item type is compatible with this item stat
* @param type The item type to check
* @return If a certain item type is compatible with this item stat
*/
public boolean isCompatible(Type type) {
String lower = type.getId().toLowerCase();