Skip to content

Commit

Permalink
v1.2.0 Update
Browse files Browse the repository at this point in the history
- Added BungeeCord support
- Added Velocity support
- Added HEX RGB support
- Update message can now be disabled in PowerLib's config.yml
- Added MariaDB and MySQL Drivers inside PowerLib's JAR file
- Deprecated older bukkit-only classes
  • Loading branch information
AlbeMiglio committed Jan 3, 2022
1 parent a66ee15 commit e33b377
Show file tree
Hide file tree
Showing 14 changed files with 176 additions and 89 deletions.
4 changes: 2 additions & 2 deletions Example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>PowerLibAPI</artifactId>
<groupId>it.mycraft</groupId>
<version>1.2.0-TEST-12</version>
<version>1.2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>PowerLibExample</artifactId>
Expand Down Expand Up @@ -60,7 +60,7 @@
<dependency>
<groupId>it.mycraft</groupId>
<artifactId>PowerLib</artifactId>
<version>1.2.0-TEST-12</version>
<version>1.2.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion Java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>PowerLibAPI</artifactId>
<groupId>it.mycraft</groupId>
<version>1.2.0-TEST-12</version>
<version>1.2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>PowerLib</artifactId>
Expand Down
15 changes: 15 additions & 0 deletions Java/src/main/java/it/mycraft/powerlib/bukkit/PowerLib.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package it.mycraft.powerlib.bukkit;

import it.mycraft.powerlib.bukkit.config.ConfigManager;
import it.mycraft.powerlib.bukkit.updater.PluginUpdater;
import it.mycraft.powerlib.common.chat.Message;
import lombok.Getter;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -24,17 +26,25 @@ public class PowerLib extends JavaPlugin implements Listener {
@Getter
private static PowerLib instance;

@Getter
private ConfigManager configManager;

private PluginUpdater updater;

public void onEnable() {
instance = this;
this.configManager = new ConfigManager(this);
this.configManager.create("config.yml");
this.updater = new PluginUpdater(this).setGitHubURL("AlbeMiglio", "PowerLib");
Bukkit.getPluginManager().registerEvents(this, this);
Metrics metrics = new Metrics(this, 11161);
}

@EventHandler
public void onJoin(PlayerJoinEvent event) {
if(!getConfig().getBoolean("check-for-updates")) {
return;
}
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
Player player = event.getPlayer();
if (!player.isOp() && !player.hasPermission("powerlib.update")) {
Expand All @@ -52,4 +62,9 @@ public void onJoin(PlayerJoinEvent event) {
}
});
}

@Override
public FileConfiguration getConfig() {
return this.configManager.get("config.yml");
}
}
84 changes: 44 additions & 40 deletions Java/src/main/java/it/mycraft/powerlib/bukkit/item/ItemBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import it.mycraft.powerlib.bukkit.PowerLib;
import it.mycraft.powerlib.common.utils.ColorAPI;
import it.mycraft.powerlib.reflection.ReflectionAPI;
import lombok.Getter;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
Expand All @@ -23,25 +24,27 @@
import java.lang.reflect.Field;
import java.util.*;
import java.util.logging.Level;
import java.util.stream.Collectors;

@Getter
public class ItemBuilder {

//TODO: Add addEnchant method

private Material material;

private String name;
private List<String> lore;
private int amount;
private short metadata;
private boolean glowing;
private Map<Enchantment, Integer> enchantments;
private Map<PotionEffect, Boolean> potion;
private HashMap<Enchantment, Integer> enchantments;
private HashMap<PotionEffect, Boolean> potions;
private HashMap<String, Object> placeholders;

public ItemBuilder() {
lore = new ArrayList<>();
enchantments = new HashMap<>();
potion = new HashMap<>();
potions = new HashMap<>();
placeholders = new HashMap<>();
amount = 1;
metadata = 0;
}
Expand Down Expand Up @@ -74,7 +77,7 @@ public ItemBuilder setMaterial(String material) {
* Sets the item's material getting it from an int ID. 1.13+
*
* @param id The ID
* @return The ItemBuilder
* @return The ItemBuilder
*/
public ItemBuilder setMaterial(int id) {
this.material = LegacyItemAPI.getMaterial(id);
Expand All @@ -86,7 +89,7 @@ public ItemBuilder setMaterial(int id) {
*
* @param id The ID
* @param data The Data
* @return The ItemBuilder
* @return The ItemBuilder
*/
public ItemBuilder setMaterial(int id, int data) {
this.material = LegacyItemAPI.getMaterial(id, data);
Expand Down Expand Up @@ -190,7 +193,7 @@ public ItemBuilder setPotionEffect(PotionEffectType type, int duration, int leve
* @return The ItemBuilder
*/
public ItemBuilder setPotionEffect(PotionEffectType type, int duration, int level, boolean overwrite, boolean ambient, boolean particles) {
potion.put(new PotionEffect(type, duration, (level - 1), overwrite, ambient), particles);
potions.put(new PotionEffect(type, duration, (level - 1), overwrite, ambient), particles);
return this;
}

Expand Down Expand Up @@ -239,8 +242,9 @@ public ItemBuilder clone(ItemStack itemStack) {
amount = itemStack.getAmount();
metadata = itemStack.getDurability();

if (itemMeta.getDisplayName() != null)
if (itemMeta != null) {
name = itemMeta.getDisplayName();
}

if (itemMeta.hasLore())
lore = itemMeta.getLore();
Expand Down Expand Up @@ -342,21 +346,23 @@ private ItemStack setColorToArmor(int red, int green, int blue, ItemBuilder item
* @return The ItemBuilder
*/
public ItemBuilder addPlaceHolder(String placeholder, Object value) {
name = name.replaceAll(placeholder, value.toString());

List<String> newLore = new ArrayList<>();
lore.forEach((s) -> newLore.add(s.replaceAll(placeholder, value.toString())));

lore = newLore;
placeholders.put(placeholder, value);
return this;
}

/**
* Builds an Itemstack with the data provided previously
* Builds an ItemStack with the data provided previously
*
* @return The ItemStack
*/
public ItemStack build() {
for(String placeholder : placeholders.keySet()) {
Object value = placeholders.get(placeholder);
setName(name.replace(placeholder, value.toString()));

setLore(lore.stream().map((s) -> s.replace(placeholder, value.toString()))
.collect(Collectors.toList()));
}
ItemStack itemStack = new ItemStack(material, amount, metadata);

ItemMeta itemMeta = itemStack.getItemMeta();
Expand All @@ -380,15 +386,13 @@ public ItemStack build() {

itemStack.setItemMeta(itemMeta);

if (material == Material.POTION && !potion.isEmpty()) {
if (material == Material.POTION && !potions.isEmpty()) {
PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();
for (PotionEffect potionEffect : potion.keySet()) {
potionMeta.addCustomEffect(potionEffect, potion.get(potionEffect));
for (PotionEffect potionEffect : potions.keySet()) {
potionMeta.addCustomEffect(potionEffect, potions.get(potionEffect));
}
itemStack.setItemMeta(potionMeta);
}

reset();
return itemStack;
}

Expand Down Expand Up @@ -445,9 +449,9 @@ public ItemStack coloredArmorBuild(int red, int green, int blue) {
*
* @param fileConfiguration The file configuration to get the item's info from
* @param path The section where the item's info are stored
* @return The built ItemStack
* @return The related ItemBuilder
*/
public ItemStack fromConfig(FileConfiguration fileConfiguration, String path) {
public ItemBuilder fromConfig(FileConfiguration fileConfiguration, String path) {
boolean legacy = false, glowing = false;
String newPath, material = "STONE", name = null;
List<String> lore = null;
Expand Down Expand Up @@ -489,30 +493,30 @@ public ItemStack fromConfig(FileConfiguration fileConfiguration, String path) {
break;
}
}
return new ItemBuilder()
.setMaterial(material)
.setName(name)
.setLore(lore)
.setAmount(amount)
.setMetaData(metadata)
.setGlowing(glowing)
.build();
return this.setMaterial(material)
.setName(name).setLore(lore)
.setAmount(amount).setMetaData(metadata)
.setGlowing(glowing);
}

public ItemBuilder hex() {
setName(ColorAPI.hex(getName()));
setLore(ColorAPI.hex(getLore()));
return this;
}

/**
* Just puts in the ItemBuilder object its default values
*/
private void reset() {
material = null;
name = null;

lore = null;
enchantments = null;
potion = null;

material = Material.STONE;
name = "";
glowing = false;
lore = new ArrayList<>();
enchantments = new HashMap<>();
potions = new HashMap<>();
placeholders = new HashMap<>();
amount = 1;
metadata = 0;

glowing = false;
}
}
14 changes: 14 additions & 0 deletions Java/src/main/java/it/mycraft/powerlib/bungee/PowerLib.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package it.mycraft.powerlib.bungee;

import it.mycraft.powerlib.bungee.config.ConfigManager;
import it.mycraft.powerlib.bungee.updater.PluginUpdater;
import it.mycraft.powerlib.common.chat.Message;
import it.mycraft.powerlib.configuration.Configuration;
import lombok.Getter;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.ClickEvent;
Expand All @@ -24,17 +26,25 @@ public class PowerLib extends Plugin implements Listener {
@Getter
private static PowerLib instance;

@Getter
private ConfigManager configManager;

private PluginUpdater updater;

public void onEnable() {
instance = this;
this.configManager = new ConfigManager(this);
this.configManager.create("config.yml");
this.updater = new PluginUpdater(this).setGitHubURL("AlbeMiglio", "PowerLib");
getProxy().getPluginManager().registerListener(this, this);
Metrics metrics = new Metrics(this, 11162);
}

@EventHandler
public void onJoin(ServerConnectedEvent event) {
if(!getConfig().getBoolean("check-for-updates")) {
return;
}
ProxyServer.getInstance().getScheduler().runAsync(this, () -> {
ProxiedPlayer player = event.getPlayer();
if (!player.hasPermission("powerlib.update")) {
Expand All @@ -52,4 +62,8 @@ public void onJoin(ServerConnectedEvent event) {
}
});
}

public Configuration getConfig() {
return this.configManager.get("config.yml");
}
}
Loading

0 comments on commit e33b377

Please sign in to comment.