From c28c7064a8c997d37517d341f02f392aa402fef3 Mon Sep 17 00:00:00 2001 From: Paldiu Date: Sun, 21 Feb 2021 23:37:17 -0600 Subject: [PATCH] Updated --- .../simplexcore/{banning => ban}/Ban.java | 12 +++---- .../{banning => ban}/BanFactory.java | 6 +++- .../simplexcore/{banning => ban}/BanType.java | 2 +- .../simplexcore/{banning => ban}/IBan.java | 3 +- .../simplexcore/config/YamlFactory.java | 4 +-- .../simplexcore/potion/IPotionEffect.java | 35 +++++++++++++++++++ .../simplexcore/potion/PotionsFactory.java | 21 +++++++++++ .../paldiu/simplexcore/utils/Constants.java | 1 - .../paldiu/simplexcore/utils/Utilities.java | 10 +++--- src/main/resources/config.yml | 1 + .../simplexcore/utils/UtilitiesTest.java | 2 +- 11 files changed, 77 insertions(+), 20 deletions(-) rename src/main/java/io/github/paldiu/simplexcore/{banning => ban}/Ban.java (82%) rename src/main/java/io/github/paldiu/simplexcore/{banning => ban}/BanFactory.java (95%) rename src/main/java/io/github/paldiu/simplexcore/{banning => ban}/BanType.java (91%) rename src/main/java/io/github/paldiu/simplexcore/{banning => ban}/IBan.java (75%) create mode 100644 src/main/java/io/github/paldiu/simplexcore/potion/IPotionEffect.java create mode 100644 src/main/java/io/github/paldiu/simplexcore/potion/PotionsFactory.java create mode 100644 src/main/resources/config.yml diff --git a/src/main/java/io/github/paldiu/simplexcore/banning/Ban.java b/src/main/java/io/github/paldiu/simplexcore/ban/Ban.java similarity index 82% rename from src/main/java/io/github/paldiu/simplexcore/banning/Ban.java rename to src/main/java/io/github/paldiu/simplexcore/ban/Ban.java index e708452..729db59 100644 --- a/src/main/java/io/github/paldiu/simplexcore/banning/Ban.java +++ b/src/main/java/io/github/paldiu/simplexcore/ban/Ban.java @@ -1,4 +1,4 @@ -package io.github.paldiu.simplexcore.banning; +package io.github.paldiu.simplexcore.ban; import io.github.paldiu.simplexcore.chat.Messages; import io.github.paldiu.simplexcore.config.Yaml; @@ -16,11 +16,9 @@ import java.util.Date; /** * This class provides a way for you to handle your own banning. * Simply extend this class and create a new instance of the subclass. - * Alternatively, you may use the - * - * @link BanFactory - * Use this in synchrony with SimplexListener to process bans on player login/join. - * Use this in synchrony with YamlFactory to create a new yaml file to store your bans, or to create an individual yaml file per user ban. + * Alternatively, you may use {@link BanFactory#create} to create a new Ban instance. + * Use this in synchrony with {@link io.github.paldiu.simplexcore.listener.SimplexListener} to process bans on player login/join. + * Use this in synchrony with {@link io.github.paldiu.simplexcore.config.YamlFactory} to create a new yaml file to store your bans, or to create an individual yaml file per user ban. */ public abstract class Ban implements IBan { private final Player player; @@ -58,7 +56,7 @@ public abstract class Ban implements IBan { File fileLocation = new File(Constants.getPlugin().getDataFolder(), "bans"); if (separateFiles) { - Yaml yaml = new YamlFactory(Constants.getPlugin()).setPathways(null, fileLocation, player.getName() + ".yml"); + Yaml yaml = new YamlFactory(Constants.getPlugin()).from(null, fileLocation, player.getName() + ".yml"); yaml.getConfig().createSection(getOffender().toString()); ConfigurationSection section = yaml.getConfigurationSection(getOffender().toString()); section.set("name", player.getName()); diff --git a/src/main/java/io/github/paldiu/simplexcore/banning/BanFactory.java b/src/main/java/io/github/paldiu/simplexcore/ban/BanFactory.java similarity index 95% rename from src/main/java/io/github/paldiu/simplexcore/banning/BanFactory.java rename to src/main/java/io/github/paldiu/simplexcore/ban/BanFactory.java index 0250f4a..e43cb78 100644 --- a/src/main/java/io/github/paldiu/simplexcore/banning/BanFactory.java +++ b/src/main/java/io/github/paldiu/simplexcore/ban/BanFactory.java @@ -1,4 +1,4 @@ -package io.github.paldiu.simplexcore.banning; +package io.github.paldiu.simplexcore.ban; import io.github.paldiu.simplexcore.chat.Messages; import io.github.paldiu.simplexcore.functional.Guard; @@ -48,6 +48,10 @@ public final class BanFactory { return this; } + /** + * Creates a new instance of the abstract class Ban. + * @return A new ban instance. + */ public Ban create() { return new Ban(player, sender, type, banDuration) { @Override diff --git a/src/main/java/io/github/paldiu/simplexcore/banning/BanType.java b/src/main/java/io/github/paldiu/simplexcore/ban/BanType.java similarity index 91% rename from src/main/java/io/github/paldiu/simplexcore/banning/BanType.java rename to src/main/java/io/github/paldiu/simplexcore/ban/BanType.java index 0a66ed8..05acec2 100644 --- a/src/main/java/io/github/paldiu/simplexcore/banning/BanType.java +++ b/src/main/java/io/github/paldiu/simplexcore/ban/BanType.java @@ -1,4 +1,4 @@ -package io.github.paldiu.simplexcore.banning; +package io.github.paldiu.simplexcore.ban; public enum BanType { PERMANENT("P-"), diff --git a/src/main/java/io/github/paldiu/simplexcore/banning/IBan.java b/src/main/java/io/github/paldiu/simplexcore/ban/IBan.java similarity index 75% rename from src/main/java/io/github/paldiu/simplexcore/banning/IBan.java rename to src/main/java/io/github/paldiu/simplexcore/ban/IBan.java index fce08ed..6896cde 100644 --- a/src/main/java/io/github/paldiu/simplexcore/banning/IBan.java +++ b/src/main/java/io/github/paldiu/simplexcore/ban/IBan.java @@ -1,7 +1,6 @@ -package io.github.paldiu.simplexcore.banning; +package io.github.paldiu.simplexcore.ban; import java.util.Date; -import java.util.SplittableRandom; import java.util.UUID; public interface IBan { diff --git a/src/main/java/io/github/paldiu/simplexcore/config/YamlFactory.java b/src/main/java/io/github/paldiu/simplexcore/config/YamlFactory.java index 7e890df..d65a8b4 100644 --- a/src/main/java/io/github/paldiu/simplexcore/config/YamlFactory.java +++ b/src/main/java/io/github/paldiu/simplexcore/config/YamlFactory.java @@ -15,7 +15,7 @@ public final class YamlFactory { this.plugin = plugin; } - public Yaml setPathways(String resourcePath, File directory, String fileName) { + public Yaml from(String resourcePath, File directory, String fileName) { this.resourcePath = resourcePath; this.directory = directory; this.fileName = fileName; @@ -23,7 +23,7 @@ public final class YamlFactory { } public Yaml setDefaultPathways() { - return setPathways("config.yml", plugin.getDataFolder(), "config.yml"); + return from("config.yml", plugin.getDataFolder(), "config.yml"); } public Trio pathways() { diff --git a/src/main/java/io/github/paldiu/simplexcore/potion/IPotionEffect.java b/src/main/java/io/github/paldiu/simplexcore/potion/IPotionEffect.java new file mode 100644 index 0000000..134e865 --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/potion/IPotionEffect.java @@ -0,0 +1,35 @@ +package io.github.paldiu.simplexcore.potion; + +import org.bukkit.Color; +import org.bukkit.NamespacedKey; +import org.bukkit.Particle; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * This interface is intended for creating custom potion effects. + */ +public interface IPotionEffect { + @NotNull + PotionEffect getEffect(); + + @NotNull + PotionEffectType getType(); + + @NotNull + String getName(); + + @NotNull + Long getDuration(); + + @Nullable + Particle getParticleType(); + + @Nullable + Color getParticleColor(); + + @NotNull + NamespacedKey getNamespacedKey(); +} diff --git a/src/main/java/io/github/paldiu/simplexcore/potion/PotionsFactory.java b/src/main/java/io/github/paldiu/simplexcore/potion/PotionsFactory.java new file mode 100644 index 0000000..4379dd0 --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/potion/PotionsFactory.java @@ -0,0 +1,21 @@ +package io.github.paldiu.simplexcore.potion; + +import io.github.paldiu.simplexcore.utils.Utilities; +import org.bukkit.entity.LivingEntity; +import org.bukkit.potion.PotionEffect; + +import java.util.stream.Collectors; + +public final class PotionsFactory { + private PotionsFactory() { + + } + + public static void applyEffect(LivingEntity entity, PotionEffect... effect) { + entity.addPotionEffects(Utilities.stream(effect).collect(Collectors.toSet())); + } + + public static void applyEffect(LivingEntity entity, IPotionEffect... effect) { + Utilities.forEach(effect, sim -> sim.getEffect().apply(entity)); // Interesting, not how it will be done in the end though. + } +} diff --git a/src/main/java/io/github/paldiu/simplexcore/utils/Constants.java b/src/main/java/io/github/paldiu/simplexcore/utils/Constants.java index 12d8fc7..46e05f2 100644 --- a/src/main/java/io/github/paldiu/simplexcore/utils/Constants.java +++ b/src/main/java/io/github/paldiu/simplexcore/utils/Constants.java @@ -93,6 +93,5 @@ public final class Constants { return 622080000L; } } - } diff --git a/src/main/java/io/github/paldiu/simplexcore/utils/Utilities.java b/src/main/java/io/github/paldiu/simplexcore/utils/Utilities.java index 28a1c17..88ff103 100644 --- a/src/main/java/io/github/paldiu/simplexcore/utils/Utilities.java +++ b/src/main/java/io/github/paldiu/simplexcore/utils/Utilities.java @@ -1,13 +1,9 @@ package io.github.paldiu.simplexcore.utils; -import io.github.paldiu.simplexcore.banning.BanType; -import io.github.paldiu.simplexcore.functional.Guard; -import io.github.paldiu.simplexcore.functional.Validate; +import io.github.paldiu.simplexcore.ban.BanType; import java.util.*; -import java.util.function.BiConsumer; import java.util.function.Consumer; -import java.util.stream.Collectors; import java.util.stream.Stream; public final class Utilities { @@ -22,6 +18,10 @@ public final class Utilities { } } + public static Stream stream(T[] array) { + return Arrays.stream(array); + } + public static String generateBanId(BanType type) { final String charList = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"; final String numList = "0123456789"; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..f1c7fee --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1 @@ +# Empty configuration file. \ No newline at end of file diff --git a/src/test/java/io/github/paldiu/simplexcore/utils/UtilitiesTest.java b/src/test/java/io/github/paldiu/simplexcore/utils/UtilitiesTest.java index 8b3639e..25eea89 100644 --- a/src/test/java/io/github/paldiu/simplexcore/utils/UtilitiesTest.java +++ b/src/test/java/io/github/paldiu/simplexcore/utils/UtilitiesTest.java @@ -1,7 +1,7 @@ package io.github.paldiu.simplexcore.utils; import junit.framework.TestCase; -import io.github.paldiu.simplexcore.banning.BanType; +import io.github.paldiu.simplexcore.ban.BanType; public class UtilitiesTest extends TestCase { public void testGenerateBanId() {