This commit is contained in:
Paldiu 2021-02-21 23:37:17 -06:00
parent eb05f43058
commit c28c7064a8
11 changed files with 77 additions and 20 deletions

View File

@ -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.chat.Messages;
import io.github.paldiu.simplexcore.config.Yaml; 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. * This class provides a way for you to handle your own banning.
* Simply extend this class and create a new instance of the subclass. * Simply extend this class and create a new instance of the subclass.
* Alternatively, you may use the * 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.
* @link BanFactory * 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.
* 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.
*/ */
public abstract class Ban implements IBan { public abstract class Ban implements IBan {
private final Player player; private final Player player;
@ -58,7 +56,7 @@ public abstract class Ban implements IBan {
File fileLocation = new File(Constants.getPlugin().getDataFolder(), "bans"); File fileLocation = new File(Constants.getPlugin().getDataFolder(), "bans");
if (separateFiles) { 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()); yaml.getConfig().createSection(getOffender().toString());
ConfigurationSection section = yaml.getConfigurationSection(getOffender().toString()); ConfigurationSection section = yaml.getConfigurationSection(getOffender().toString());
section.set("name", player.getName()); section.set("name", player.getName());

View File

@ -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.chat.Messages;
import io.github.paldiu.simplexcore.functional.Guard; import io.github.paldiu.simplexcore.functional.Guard;
@ -48,6 +48,10 @@ public final class BanFactory {
return this; return this;
} }
/**
* Creates a new instance of the abstract class Ban.
* @return A new ban instance.
*/
public Ban create() { public Ban create() {
return new Ban(player, sender, type, banDuration) { return new Ban(player, sender, type, banDuration) {
@Override @Override

View File

@ -1,4 +1,4 @@
package io.github.paldiu.simplexcore.banning; package io.github.paldiu.simplexcore.ban;
public enum BanType { public enum BanType {
PERMANENT("P-"), PERMANENT("P-"),

View File

@ -1,7 +1,6 @@
package io.github.paldiu.simplexcore.banning; package io.github.paldiu.simplexcore.ban;
import java.util.Date; import java.util.Date;
import java.util.SplittableRandom;
import java.util.UUID; import java.util.UUID;
public interface IBan { public interface IBan {

View File

@ -15,7 +15,7 @@ public final class YamlFactory {
this.plugin = plugin; 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.resourcePath = resourcePath;
this.directory = directory; this.directory = directory;
this.fileName = fileName; this.fileName = fileName;
@ -23,7 +23,7 @@ public final class YamlFactory {
} }
public Yaml setDefaultPathways() { public Yaml setDefaultPathways() {
return setPathways("config.yml", plugin.getDataFolder(), "config.yml"); return from("config.yml", plugin.getDataFolder(), "config.yml");
} }
public Trio<String, File, String> pathways() { public Trio<String, File, String> pathways() {

View File

@ -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();
}

View File

@ -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.
}
}

View File

@ -93,6 +93,5 @@ public final class Constants {
return 622080000L; return 622080000L;
} }
} }
} }

View File

@ -1,13 +1,9 @@
package io.github.paldiu.simplexcore.utils; package io.github.paldiu.simplexcore.utils;
import io.github.paldiu.simplexcore.banning.BanType; import io.github.paldiu.simplexcore.ban.BanType;
import io.github.paldiu.simplexcore.functional.Guard;
import io.github.paldiu.simplexcore.functional.Validate;
import java.util.*; import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
public final class Utilities { public final class Utilities {
@ -22,6 +18,10 @@ public final class Utilities {
} }
} }
public static <T> Stream<T> stream(T[] array) {
return Arrays.stream(array);
}
public static String generateBanId(BanType type) { public static String generateBanId(BanType type) {
final String charList = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"; final String charList = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz";
final String numList = "0123456789"; final String numList = "0123456789";

View File

@ -0,0 +1 @@
# Empty configuration file.

View File

@ -1,7 +1,7 @@
package io.github.paldiu.simplexcore.utils; package io.github.paldiu.simplexcore.utils;
import junit.framework.TestCase; import junit.framework.TestCase;
import io.github.paldiu.simplexcore.banning.BanType; import io.github.paldiu.simplexcore.ban.BanType;
public class UtilitiesTest extends TestCase { public class UtilitiesTest extends TestCase {
public void testGenerateBanId() { public void testGenerateBanId() {