From 9bb8902eed4859d2ab6bd3a658ed19afbe65245f Mon Sep 17 00:00:00 2001 From: Paldiu Date: Fri, 26 Feb 2021 22:32:01 -0600 Subject: [PATCH] BLEEDING EDGE v1.3_02 --- build.gradle | 2 + .../simplexdev/api/IParticleEffect.java | 12 ++- .../api/annotations/ServerInfo.java | 16 ++++ .../simplexcore/particle/ParticleFactory.java | 93 +++++++++++++++++++ .../simplexcore/plugin/AddonRegistry.java | 49 ++++++++++ .../simplexcore/utils/Instances.java | 2 +- src/main/resources/plugin.yml | 3 + 7 files changed, 173 insertions(+), 4 deletions(-) create mode 100644 src/main/java/io/github/simplexdev/api/annotations/ServerInfo.java create mode 100644 src/main/java/io/github/simplexdev/simplexcore/particle/ParticleFactory.java diff --git a/build.gradle b/build.gradle index f521291..168dfe0 100644 --- a/build.gradle +++ b/build.gradle @@ -28,6 +28,8 @@ dependencies { //provided [ "com.destroystokyo.paper:paper-api:1.16.4-R0.1-SNAPSHOT", + "net.md-5:bungeecord-api:1.16-R0.4-SNAPSHOT", + "io.github.waterfallmc:waterfall-api:1.16-R0.4-SNAPSHOT", "me.clip:placeholderapi:2.10.9", ].each {s -> compileOnly s diff --git a/src/main/java/io/github/simplexdev/api/IParticleEffect.java b/src/main/java/io/github/simplexdev/api/IParticleEffect.java index 463c6af..425bc89 100644 --- a/src/main/java/io/github/simplexdev/api/IParticleEffect.java +++ b/src/main/java/io/github/simplexdev/api/IParticleEffect.java @@ -1,12 +1,18 @@ package io.github.simplexdev.api; import org.bukkit.Color; +import org.bukkit.Effect; import org.bukkit.Particle; -public interface IParticleEffect { - Particle[] getParticles(); +import java.util.Map; +import java.util.Set; - Color[] getParticleColors(); +public interface IParticleEffect { + Set getParticles(); + + Map getParticleColors(); + + Set getEffects(); Float getSize(); diff --git a/src/main/java/io/github/simplexdev/api/annotations/ServerInfo.java b/src/main/java/io/github/simplexdev/api/annotations/ServerInfo.java new file mode 100644 index 0000000..7980453 --- /dev/null +++ b/src/main/java/io/github/simplexdev/api/annotations/ServerInfo.java @@ -0,0 +1,16 @@ +package io.github.simplexdev.api.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface ServerInfo { + boolean isPaper() default false; + + boolean isWaterfall() default false; + + boolean isBungeeCord() default false; +} diff --git a/src/main/java/io/github/simplexdev/simplexcore/particle/ParticleFactory.java b/src/main/java/io/github/simplexdev/simplexcore/particle/ParticleFactory.java new file mode 100644 index 0000000..58329b6 --- /dev/null +++ b/src/main/java/io/github/simplexdev/simplexcore/particle/ParticleFactory.java @@ -0,0 +1,93 @@ +package io.github.simplexdev.simplexcore.particle; + +import io.github.simplexdev.api.IParticleEffect; +import org.bukkit.*; + +import java.util.*; + +public class ParticleFactory { + private float size = 2F; + private long duration = 20L * 15L; + private final Set particleSet = new HashSet<>(); + private final Map particleColorMap = new HashMap<>(); + private final Set particleEffects = new HashSet<>(); + + public ParticleFactory() { + } + + public ParticleFactory setSize(float size) { + this.size = size; + return this; + } + + public ParticleFactory setDuration(long duration) { + this.duration = duration; + return this; + } + + public ParticleFactory setParticles(Particle... particles) { + Collections.addAll(particleSet, particles); + return this; + } + + public ParticleFactory setParticleColor(Particle particle, Color color) { + particleColorMap.put(particle, color); + return this; + } + + /** + * Sets a color for more than one particle. + * @param color + * @param particles + * @return + */ + public ParticleFactory setMultipleParticleColors(Color color, Particle... particles) { + for (Particle particle : particles) { + particleColorMap.put(particle, color); + } + return this; + } + + public ParticleFactory setParticleEffects(Effect... effects) { + particleEffects.addAll(Arrays.asList(effects)); + return this; + } + + public IParticleEffect create() { + return new IParticleEffect() { + @Override + public Set getParticles() { + return particleSet; + } + + @Override + public Map getParticleColors() { + return particleColorMap; + } + + @Override + public Set getEffects() { + return particleEffects; + } + + @Override + public Float getSize() { + return size; + } + + @Override + public Long getDuration() { + return duration; + } + }; + } + + // TODO: Needs work :) + public void spawnParticle(IParticleEffect effect, Location location) { + World world = location.getWorld(); + effect.getParticles().forEach(particle -> { + Color color = effect.getParticleColors().get(particle); + world.spawnParticle(particle, location, 20); + }); + } +} diff --git a/src/main/java/io/github/simplexdev/simplexcore/plugin/AddonRegistry.java b/src/main/java/io/github/simplexdev/simplexcore/plugin/AddonRegistry.java index 17457cf..f9ac4cb 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/plugin/AddonRegistry.java +++ b/src/main/java/io/github/simplexdev/simplexcore/plugin/AddonRegistry.java @@ -1,5 +1,9 @@ package io.github.simplexdev.simplexcore.plugin; +import io.github.simplexdev.api.annotations.ServerInfo; +import io.github.simplexdev.api.func.Guard; +import io.github.simplexdev.simplexcore.utils.Constants; + import java.util.HashSet; import java.util.Set; @@ -14,7 +18,52 @@ public final class AddonRegistry { return instance; } + public > boolean isPaper(T addon) { + try { + Class.forName(com.destroystokyo.paper.Namespaced.class.getName()); + return true; + } catch (ClassNotFoundException ignored) { + addon.stop(); + Constants.getLogger().severe(addon.getName() + " has been disabled: This module requires Paper!"); + return false; + } + } + + private > boolean isBungee(T addon) { + try { + Class.forName(net.md_5.bungee.Util.class.getName()); + return true; + } catch (ClassNotFoundException ignored) { + addon.stop(); + Constants.getLogger().severe(addon.getName() + " has been disabled: This module requires Bungeecord!"); + return false; + } + } + + private > boolean isWaterfall(T addon) { + try { + Class.forName(io.github.waterfallmc.waterfall.utils.Hex.class.getName()); + return true; + } catch (ClassNotFoundException ignored) { + addon.stop(); + Constants.getLogger().severe(addon.getName() + " has been disabled: This module requires Waterfall!"); + return false; + } + } + public > void register(T addon) { + if (addon.getClass().isAnnotationPresent(ServerInfo.class)) { + ServerInfo info = addon.getClass().getDeclaredAnnotation(ServerInfo.class); + if (info.isPaper() && !isPaper(addon)) { + return; + } + if (info.isBungeeCord() && !isBungee(addon)) { + return; + } + if (info.isWaterfall() && !isWaterfall(addon)) { + return; + } + } getComponents().add(addon); } diff --git a/src/main/java/io/github/simplexdev/simplexcore/utils/Instances.java b/src/main/java/io/github/simplexdev/simplexcore/utils/Instances.java index 5293a65..cd83b86 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/utils/Instances.java +++ b/src/main/java/io/github/simplexdev/simplexcore/utils/Instances.java @@ -6,7 +6,7 @@ import io.github.simplexdev.simplexcore.config.YamlFactory; import io.github.simplexdev.simplexcore.plugin.AddonRegistry; import io.github.simplexdev.simplexcore.plugin.DependencyManagement; -public class Instances { +public final class Instances { private final DependencyManagement dpm = new DependencyManagement(); private final Yaml config = new YamlFactory(Constants.getPlugin()).setDefaultPathways(); private final TimeValues time = new TimeValues(); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 5850d54..9f01ec4 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -7,3 +7,6 @@ authors: - Paldiu - Conclure description: Core for a group of plugins designed to enhance gameplay to the max +softdepend: + - PlaceholderAPI + - ProtocolLib