Merge branch 'Testing' of gitlab.com:Songoda/songodaupdater into Testing

This commit is contained in:
jascotty2 2019-08-21 23:59:02 -05:00
commit 8e1e3d1bc8
6 changed files with 272 additions and 12 deletions

View File

@ -18,5 +18,23 @@
<orderEntry type="library" name="Maven: org.slf4j:slf4j-nop:1.7.25" level="project" />
<orderEntry type="library" name="Maven: com.zaxxer:HikariCP:3.2.0" level="project" />
<orderEntry type="library" name="Maven: org.xerial:sqlite-jdbc:3.23.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.worldguard:worldguard-bukkit:7.0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.14.4-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:21.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.8.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.23" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.worldedit:worldedit-bukkit:7.0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.worldguard:worldguard-core:7.0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.worldguard.worldguard-libs:core:7.0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.worldedit:worldedit-core:7.0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.worldedit.worldedit-libs:core:7.0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: de.schlichtherle:truezip:6.8.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.mozilla:rhino:1.7.11" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.flywaydb:flyway-core:3.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: io.papermc:paperlib:1.0.2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:commandbook:2.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bstats:bstats-bukkit:1.5" level="project" />
</component>
</module>

View File

@ -24,11 +24,11 @@ public class EconomyManager {
PluginManager pluginManager = Bukkit.getPluginManager();
for(EconomyType type : EconomyType.values()) {
for (EconomyType type : EconomyType.values()) {
if (pluginManager.isPluginEnabled(type.plugin)) {
Economy econ = type.getInstance();
registeredEconomies.put(type, econ);
if(defaultEcon == null)
if (defaultEcon == null)
defaultEcon = econ;
}
}
@ -38,11 +38,12 @@ public class EconomyManager {
* Set the default economy to a different plugin, if that plugin exists.
* If the plugin is not loaded or supported, the previously defined default will be used. <br />
* NOTE: using a default economy assumes that this library is shaded
*
* @param name name of the plugin to use
*/
public static void setPreferredEconomy(String name) {
Economy econ = getEconomy(name);
if(econ != null)
if (econ != null)
defaultEcon = econ;
}
@ -50,21 +51,23 @@ public class EconomyManager {
* Set the default economy to a different plugin, if that plugin exists.
* If the plugin is not loaded or supported, the previously defined default will be used. <br />
* NOTE: using a default economy assumes that this library is shaded
*
* @param economy plugin to use
*/
public static void setPreferredEconomy(EconomyType economy) {
Economy econ = getEconomy(economy);
if(econ != null)
if (econ != null)
defaultEcon = econ;
}
/**
* Try to grab the handler for this specific economy plugin.
*
* @param name plugin to use
* @return returns null if plugin is not enabled
*/
public static Economy getEconomy(String name) {
if(name == null) return null;
if (name == null) return null;
final String plugin = name.trim();
return registeredEconomies.get(registeredEconomies.keySet().stream()
.filter(type -> type.plugin.equalsIgnoreCase(plugin))
@ -73,6 +76,7 @@ public class EconomyManager {
/**
* Try to grab the handler for this specific economy plugin.
*
* @param economy plugin to use
* @return returns null if plugin is not enabled
*/
@ -83,6 +87,7 @@ public class EconomyManager {
/**
* Grab the default economy plugin. <br />
* NOTE: using a default economy assumes that this library is shaded
*
* @return returns null if no plugin enabled
*/
public static Economy getEconomy() {
@ -91,6 +96,7 @@ public class EconomyManager {
/**
* Grab a list of all supported economy plugins.
*
* @return an immutable collection of the loaded economy handler instances
*/
public static Collection<Economy> getRegisteredEconomies() {
@ -99,6 +105,7 @@ public class EconomyManager {
/**
* Check to see if a specific economy plugin is enabled.
*
* @param name plugin to check
* @return true if this economy plugin is supported and loaded
*/
@ -108,6 +115,7 @@ public class EconomyManager {
/**
* Check to see if a specific economy plugin is enabled.
*
* @param economy plugin to check
* @return true if this economy plugin is supported and loaded
*/
@ -118,6 +126,7 @@ public class EconomyManager {
/**
* Check to see if there is a default economy loaded. <br />
* NOTE: using a default economy assumes that this library is shaded
*
* @return returns false if there are no supported economy plugins
*/
public static boolean isEnabled() {
@ -143,7 +152,7 @@ public class EconomyManager {
* @return true if this player can have this amount withdrawn
*/
public static boolean hasBalance(OfflinePlayer player, double cost) {
return defaultEcon != null ? defaultEcon.hasBalance(player, cost) : false;
return defaultEcon != null && defaultEcon.hasBalance(player, cost);
}
/**
@ -155,7 +164,7 @@ public class EconomyManager {
* @return true if the total amount was withdrawn successfully
*/
public static boolean withdrawBalance(OfflinePlayer player, double cost) {
return defaultEcon != null ? defaultEcon.withdrawBalance(player, cost) : false;
return defaultEcon != null && defaultEcon.withdrawBalance(player, cost);
}
/**
@ -167,6 +176,6 @@ public class EconomyManager {
* @return true if the total amount was added successfully
*/
public static boolean deposit(OfflinePlayer player, double amount) {
return defaultEcon != null ? defaultEcon.deposit(player, amount) : false;
return defaultEcon != null && defaultEcon.deposit(player, amount);
}
}

View File

@ -0,0 +1,105 @@
package com.songoda.core.library.hologram;
import com.songoda.core.library.hologram.holograms.Hologram;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.plugin.PluginManager;
import java.util.*;
public class HologramManager {
private final static Map<HologramType, Hologram> registeredHolograms = new HashMap<>();
private static Hologram defaultHolo = null;
/**
* Load all supported hologram plugins. <br />
* Note: This method should be called in your plugin's onEnable() section
*/
public static void load() {
if (!registeredHolograms.isEmpty()) return;
PluginManager pluginManager = Bukkit.getPluginManager();
for (HologramType type : HologramType.values()) {
if (pluginManager.isPluginEnabled(type.plugin)) {
Hologram holo = type.getInstance();
registeredHolograms.put(type, holo);
if (defaultHolo == null)
defaultHolo = holo;
}
}
}
/**
* Set the default hologram to a different plugin, if that plugin exists.
* If the plugin is not loaded or supported, the previously defined default will be used. <br />
* NOTE: using a default hologram assumes that this library is shaded
*
* @param name name of the plugin to use
*/
public static void setPreferredHologram(String name) {
Hologram holo = getHologram(name);
if (holo != null)
defaultHolo = holo;
}
/**
* Try to grab the handler for this specific hologram plugin.
*
* @param name plugin to useH
* @return returns null if plugin is not enabled
*/
public static Hologram getHologram(String name) {
if (name == null) return null;
final String plugin = name.trim();
return registeredHolograms.get(registeredHolograms.keySet().stream()
.filter(type -> type.plugin.equalsIgnoreCase(plugin))
.findFirst().orElse(null));
}
/**
* Try to grab the handler for this specific hologram plugin.
*
* @param hologram plugin to use
* @return returns null if plugin is not enabled
*/
public static Hologram getHologram(HologramType hologram) {
return registeredHolograms.get(hologram);
}
/**
* Grab the default hologram plugin. <br />
* NOTE: using a default hologram assumes that this library is shaded
*
* @return returns null if no plugin enabled
*/
public static Hologram getHologram() {
return defaultHolo;
}
/**
* Grab a list of all supported hologram plugins.
*
* @return an immutable collection of the loaded hologram, handler instances
*/
public static Collection<Hologram> getRegisteredHolograms() {
return Collections.unmodifiableCollection(registeredHolograms.values());
}
public void add(Location location, ArrayList<String> lines) {
if (defaultHolo != null)
defaultHolo.add(location, lines);
}
public void remove(Location location) {
if (defaultHolo != null)
defaultHolo.remove(location);
}
public void update(Location location, ArrayList<String> lines) {
if (defaultHolo != null)
defaultHolo.update(location, lines);
}
}

View File

@ -0,0 +1,33 @@
package com.songoda.core.library.hologram;
import com.songoda.core.library.economy.economies.Economy;
import com.songoda.core.library.economy.economies.PlayerPointsEconomy;
import com.songoda.core.library.economy.economies.ReserveEconomy;
import com.songoda.core.library.economy.economies.VaultEconomy;
import com.songoda.core.library.hologram.holograms.Hologram;
import com.songoda.core.library.hologram.holograms.HolographicDisplaysHologram;
import org.bukkit.Bukkit;
import java.util.logging.Level;
public enum HologramType {
VAULT("HolographicDisplays", HolographicDisplaysHologram.class);
public final String plugin;
protected final Class managerClass;
private HologramType(String plugin, Class managerClass) {
this.plugin = plugin;
this.managerClass = managerClass;
}
protected Hologram getInstance() {
try {
return (Hologram) managerClass.newInstance();
} catch (InstantiationException | IllegalAccessException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Unexpected Error while creating a new Hologram Manager for " + name(), ex);
}
return null;
}
}

View File

@ -0,0 +1,39 @@
package com.songoda.core.library.hologram.holograms;
import org.bukkit.Location;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.ArrayList;
public abstract class Hologram {
protected double x = 0.5;
protected double y = 1.5;
protected double z = 0.5;
protected final JavaPlugin plugin;
public Hologram(JavaPlugin plugin) {
this.plugin = plugin;
}
public Hologram setPosition(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
return this;
}
public abstract String getName();
public abstract void add(Location location, ArrayList<String> lines);
public abstract void remove(Location location);
public abstract void update(Location location, ArrayList<String> lines);
void fixLocation(Location location) {
location.add(x, y, z);
}
}

View File

@ -0,0 +1,56 @@
package com.songoda.core.library.hologram.holograms;
import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
import org.bukkit.Location;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.ArrayList;
public class HolographicDisplaysHologram extends Hologram {
public HolographicDisplaysHologram(JavaPlugin plugin) {
super(plugin);
}
@Override
public String getName() {
return "HolographicDisplays";
}
@Override
public void add(Location location, ArrayList<String> lines) {
fixLocation(location);
com.gmail.filoghost.holographicdisplays.api.Hologram hologram = HologramsAPI.createHologram(plugin, location);
for (String line : lines) {
hologram.appendTextLine(line);
}
}
@Override
public void remove(Location location) {
fixLocation(location);
for (com.gmail.filoghost.holographicdisplays.api.Hologram hologram : HologramsAPI.getHolograms(plugin)) {
if (hologram.getX() != location.getX()
|| hologram.getY() != location.getY()
|| hologram.getZ() != location.getZ()) continue;
hologram.delete();
}
}
@Override
public void update(Location location, ArrayList<String> lines) {
for (com.gmail.filoghost.holographicdisplays.api.Hologram hologram : HologramsAPI.getHolograms(plugin)) {
if (hologram.getX() != location.getX()
|| hologram.getY() != location.getY()
|| hologram.getZ() != location.getZ()) continue;
fixLocation(location);
hologram.clearLines();
for (String line : lines) {
hologram.appendTextLine(line);
}
return;
}
add(location, lines);
}
}