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

This commit is contained in:
jascotty2 2019-08-23 09:08:09 -05:00
commit a4ff6edcf2
9 changed files with 307 additions and 1 deletions

View File

@ -11,6 +11,7 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.spigotmc:spigot:1.14.4" level="project" />
<orderEntry type="library" name="Maven: com.gmail.filoghost.holographicdisplays:holographicdisplays-api:2.3.2" level="project" />
<orderEntry type="library" name="Maven: com.sainttx.holograms:holograms:2.9.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.tnemc:Reserve:0.1.3.0" level="project" />
<orderEntry type="library" name="Maven: org.black_ixx:playerpoints:2.1.4" level="project" />
<orderEntry type="library" name="Maven: net.milkbowl:vault:1.7.1" level="project" />
@ -36,5 +37,8 @@
<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" />
<orderEntry type="library" name="Maven: com.songoda:UltimateStacker:1.2.8" level="project" />
<orderEntry type="library" name="Maven: com.bgsoftware:WildStacker:2-9-0" level="project" />
<orderEntry type="library" name="Maven: uk.antiperson:stackmob:4-0-2" level="project" />
</component>
</module>

15
pom.xml
View File

@ -91,5 +91,20 @@
<version>7.0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.songoda</groupId>
<artifactId>UltimateStacker</artifactId>
<version>1.2.8</version>
</dependency>
<dependency>
<groupId>com.bgsoftware</groupId>
<artifactId>WildStacker</artifactId>
<version>2-9-0</version>
</dependency>
<dependency>
<groupId>uk.antiperson</groupId>
<artifactId>stackmob</artifactId>
<version>4-0-2</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,131 @@
package com.songoda.core.library.entitystacker;
import com.songoda.core.library.entitystacker.stackers.Stacker;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.bukkit.plugin.PluginManager;
import java.util.*;
public class EntityStackerManager {
private final static Map<EntityStackerType, Stacker> registeredStackers = new HashMap<>();
private static Stacker defaultStacker = null;
/**
* Load all supported Stacker plugins. <br />
* Note: This method should be called in your plugin's onEnable() section
*/
public static void load() {
if (!registeredStackers.isEmpty()) return;
PluginManager pluginManager = Bukkit.getPluginManager();
for (EntityStackerType type : EntityStackerType.values()) {
if (pluginManager.isPluginEnabled(type.plugin)) {
Stacker stacker = type.getInstance();
registeredStackers.put(type, stacker);
if (defaultStacker == null)
defaultStacker = stacker;
}
}
}
/**
* Set the default stacker 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 stacker assumes that this library is shaded
*
* @param type stacker plugin to use
*/
public static void setPreferredStackerPlugin(EntityStackerType type) {
Stacker stacker = getStacker(type);
if (stacker != null)
defaultStacker = stacker;
}
/**
* Set the default stacker 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 stacker assumes that this library is shaded
*
* @param name name of the plugin to use
*/
public static void setPreferredStackerPlugin(String name) {
Stacker stacker = getStacker(name);
if (stacker != null)
defaultStacker = stacker;
}
/**
* Try to grab the handler for this specific stacker plugin.
*
* @param name plugin to useH
* @return returns null if plugin is not enabled
*/
public static Stacker getStacker(String name) {
if (name == null) return null;
final String plugin = name.trim();
return registeredStackers.get(registeredStackers.keySet().stream()
.filter(type -> type.plugin.equalsIgnoreCase(plugin))
.findFirst().orElse(null));
}
/**
* Try to grab the handler for this specific stacker plugin.
*
* @param stacker plugin to use
* @return returns null if plugin is not enabled
*/
public static Stacker getStacker(EntityStackerType stacker) {
return registeredStackers.get(stacker);
}
/**
* 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 Stacker getStacker() {
return defaultStacker;
}
/**
* Grab a list of all supported stacker plugins that are loaded.
*
* @return an immutable collection of the loaded stacker, handler instances
*/
public static Collection<Stacker> getRegisteredStackers() {
return Collections.unmodifiableCollection(registeredStackers.values());
}
public static boolean isStacked(LivingEntity entity) {
return defaultStacker != null && defaultStacker.isStacked(entity);
}
public int getSize(LivingEntity entity) {
return defaultStacker != null ? defaultStacker.getSize(entity) : 1;
}
public void removeOne(LivingEntity entity) {
remove(entity, 1);
}
public void remove(LivingEntity entity, int amount) {
if (defaultStacker != null)
defaultStacker.remove(entity, amount);
}
public void addOne(LivingEntity entity) {
add(entity, 1);
}
public void add(LivingEntity entity, int amount) {
if (defaultStacker != null)
defaultStacker.add(entity, amount);
}
}

View File

@ -0,0 +1,33 @@
package com.songoda.core.library.entitystacker;
import com.songoda.core.library.entitystacker.stackers.StackMob;
import com.songoda.core.library.entitystacker.stackers.Stacker;
import com.songoda.core.library.entitystacker.stackers.UltimateStacker;
import com.songoda.core.library.entitystacker.stackers.WildStacker;
import org.bukkit.Bukkit;
import java.util.logging.Level;
public enum EntityStackerType {
ULTIMATE_STACKER("UltimateStacker", UltimateStacker.class),
WILD_STACKER("WildStacker", WildStacker.class),
STACK_MOB("StackMob", StackMob.class);
public final String plugin;
protected final Class managerClass;
private EntityStackerType(String plugin, Class managerClass) {
this.plugin = plugin;
this.managerClass = managerClass;
}
protected Stacker getInstance() {
try {
return (Stacker) managerClass.newInstance();
} catch (InstantiationException | IllegalAccessException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Unexpected Error while creating a new Stacker Manager for " + name(), ex);
}
return null;
}
}

View File

@ -0,0 +1,38 @@
package com.songoda.core.library.entitystacker.stackers;
import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity;
import uk.antiperson.stackmob.api.EntityManager;
import uk.antiperson.stackmob.api.StackedEntity;
public class StackMob extends Stacker {
private final EntityManager plugin;
public StackMob() {
this.plugin = new EntityManager((uk.antiperson.stackmob.StackMob)
Bukkit.getPluginManager().getPlugin("StackMob"));
}
@Override
public boolean isStacked(LivingEntity entity) {
return plugin.isStackedEntity(entity);
}
@Override
public int getSize(LivingEntity entity) {
return plugin.getStackedEntity(entity).getSize();
}
@Override
public void remove(LivingEntity entity, int amount) {
StackedEntity stackedEntity = plugin.getStackedEntity(entity);
stackedEntity.setSize(stackedEntity.getSize() - amount);
}
@Override
public void add(LivingEntity entity, int amount) {
StackedEntity stackedEntity = plugin.getStackedEntity(entity);
stackedEntity.setSize(stackedEntity.getSize() + amount);
}
}

View File

@ -0,0 +1,22 @@
package com.songoda.core.library.entitystacker.stackers;
import org.bukkit.entity.LivingEntity;
public abstract class Stacker {
public abstract boolean isStacked(LivingEntity entity);
public abstract int getSize(LivingEntity entity);
public void removeOne(LivingEntity entity) {
remove(entity, 1);
}
public abstract void remove(LivingEntity entity, int amount);
public void addOne(LivingEntity entity) {
add(entity, 1);
}
public abstract void add(LivingEntity entity, int amount);
}

View File

@ -0,0 +1,34 @@
package com.songoda.core.library.entitystacker.stackers;
import com.songoda.ultimatestacker.entity.EntityStack;
import org.bukkit.entity.LivingEntity;
public class UltimateStacker extends Stacker {
private final com.songoda.ultimatestacker.UltimateStacker plugin;
public UltimateStacker() {
this.plugin = com.songoda.ultimatestacker.UltimateStacker.getInstance();
}
@Override
public boolean isStacked(LivingEntity entity) {
return plugin.getEntityStackManager().isStacked(entity);
}
@Override
public int getSize(LivingEntity entity) {
return isStacked(entity) ? plugin.getEntityStackManager().getStack(entity).getAmount() : 0;
}
@Override
public void remove(LivingEntity entity, int amount) {
EntityStack stack = plugin.getEntityStackManager().getStack(entity);
stack.setAmount(stack.getAmount() - amount);
}
@Override
public void add(LivingEntity entity, int amount) {
plugin.getEntityStackManager().getStack(entity).addAmount(amount);
}
}

View File

@ -0,0 +1,30 @@
package com.songoda.core.library.entitystacker.stackers;
import com.bgsoftware.wildstacker.api.WildStackerAPI;
import com.bgsoftware.wildstacker.api.objects.StackedEntity;
import org.bukkit.entity.LivingEntity;
public class WildStacker extends Stacker {
@Override
public boolean isStacked(LivingEntity entity) {
return WildStackerAPI.getEntityAmount(entity) != 0;
}
@Override
public int getSize(LivingEntity entity) {
return WildStackerAPI.getEntityAmount(entity);
}
@Override
public void remove(LivingEntity entity, int amount) {
StackedEntity stackedEntity = WildStackerAPI.getStackedEntity(entity);
stackedEntity.setStackAmount(stackedEntity.getStackAmount() - amount, true);
}
@Override
public void add(LivingEntity entity, int amount) {
StackedEntity stackedEntity = WildStackerAPI.getStackedEntity(entity);
stackedEntity.setStackAmount(stackedEntity.getStackAmount() + amount, true);
}
}

View File

@ -136,5 +136,4 @@ public class HologramManager {
if (defaultHolo != null)
defaultHolo.updateHologram(location, lines);
}
}