mirror of
https://github.com/SimplexDevelopment/SimplexCore.git
synced 2024-12-22 08:37:37 +00:00
Simplex Update v1.13 BLEEDING
This commit is contained in:
parent
e80e3a5121
commit
9315a55dbc
4
.gitignore
vendored
4
.gitignore
vendored
@ -23,3 +23,7 @@
|
||||
hs_err_pid*
|
||||
*.iml
|
||||
*.xml
|
||||
*.txt
|
||||
*.lst
|
||||
*.lst
|
||||
target/classes/config.yml
|
||||
|
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>io.github.paldiu.simplexcore</groupId>
|
||||
<artifactId>SimplexCore</artifactId>
|
||||
<version>1.1.0-EDGE</version>
|
||||
<version>1.13-BLEEDING</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>SimplexCore</name>
|
||||
|
@ -50,6 +50,7 @@ public final class BanFactory {
|
||||
|
||||
/**
|
||||
* Creates a new instance of the abstract class Ban.
|
||||
*
|
||||
* @return A new ban instance.
|
||||
*/
|
||||
public Ban create() {
|
||||
|
@ -10,10 +10,6 @@ public enum BanType {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public static String value(BanType type) {
|
||||
if (type.equals(PERMANENT)) {
|
||||
return "Permanent";
|
||||
@ -23,4 +19,8 @@ public enum BanType {
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package io.github.paldiu.simplexcore.command;
|
||||
|
||||
import io.github.paldiu.simplexcore.utils.Constants;
|
||||
import io.github.paldiu.simplexcore.utils.Utilities;
|
||||
import jdk.jfr.BooleanFlag;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -16,7 +15,7 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class SimplexCommand implements CommandExecutor, TabCompleter {
|
||||
@BooleanFlag
|
||||
|
||||
public boolean isPlayer(CommandSender sender) {
|
||||
return sender instanceof Player;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
import java.util.Date;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
// TODO: Rewrite this entire class and the task system to have more control over tasks.
|
||||
public abstract class SimplexTask implements Consumer<BukkitTask> {
|
||||
protected final long DELAY;
|
||||
protected final long INTERVAL;
|
||||
@ -29,13 +30,13 @@ public abstract class SimplexTask implements Consumer<BukkitTask> {
|
||||
|
||||
public <T extends SimplexTask> void register(T task, SimplexAddon<?> plugin, boolean repeating, boolean delayed) {
|
||||
if (delayed && repeating) {
|
||||
Constants.getScheduler().runTaskTimerAsynchronously(plugin, task, DELAY, INTERVAL);
|
||||
Constants.getScheduler().runTaskTimer(plugin, task, DELAY, INTERVAL);
|
||||
} else if (delayed) {
|
||||
Constants.getScheduler().runTaskLaterAsynchronously(plugin, task, DELAY);
|
||||
Constants.getScheduler().runTaskLater(plugin, task, DELAY);
|
||||
} else if (repeating) {
|
||||
Constants.getScheduler().runTaskTimerAsynchronously(plugin, task, 0L, INTERVAL);
|
||||
Constants.getScheduler().runTaskTimer(plugin, task, 0L, INTERVAL);
|
||||
} else {
|
||||
Constants.getScheduler().runTaskAsynchronously(plugin, task);
|
||||
Constants.getScheduler().runTask(plugin, task);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,4 @@
|
||||
package io.github.paldiu.simplexcore.concurrent;
|
||||
|
||||
public final class TaskFactory {
|
||||
}
|
@ -1,10 +1,7 @@
|
||||
package io.github.paldiu.simplexcore.config;
|
||||
|
||||
import io.github.paldiu.simplexcore.functional.Guard;
|
||||
import io.github.paldiu.simplexcore.plugin.SimplexAddon;
|
||||
import io.github.paldiu.simplexcore.utils.Bean;
|
||||
import io.github.paldiu.simplexcore.utils.Constants;
|
||||
import io.github.paldiu.simplexcore.utils.Utilities;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
121
src/main/java/io/github/paldiu/simplexcore/gui/AbstractGUI.java
Normal file
121
src/main/java/io/github/paldiu/simplexcore/gui/AbstractGUI.java
Normal file
@ -0,0 +1,121 @@
|
||||
package io.github.paldiu.simplexcore.gui;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public abstract class AbstractGUI implements InventoryHolder, IGUI {
|
||||
private final Inventory INV;
|
||||
private final Map<Integer, Action> actions;
|
||||
private final UUID uuid;
|
||||
|
||||
private final List<Integer> validSize = new ArrayList<>(){{
|
||||
add(9);
|
||||
add(18);
|
||||
add(27);
|
||||
add(36);
|
||||
add(45);
|
||||
add(54);
|
||||
}};
|
||||
|
||||
public static final Map<UUID, IGUI> invByUUId = new HashMap<>();
|
||||
public static final Map<UUID, UUID> openInvs = new HashMap<>();
|
||||
|
||||
public AbstractGUI(int size, String name) {
|
||||
uuid = UUID.randomUUID();
|
||||
if (!validSize.contains(size)) {
|
||||
throw new NumberFormatException("Inventory sizes must be a multiple of nine!");
|
||||
}
|
||||
INV = Bukkit.createInventory(null, size, name);
|
||||
actions = new HashMap<>();
|
||||
invByUUId.put(getInvUUId(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getInvUUId() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
return INV;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int slot, @NotNull ItemStack stack, @Nullable Action action) {
|
||||
INV.setItem(slot, stack);
|
||||
if (action != null) {
|
||||
actions.put(slot, action);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int slot, @NotNull ItemStack stack) {
|
||||
setItem(slot, stack, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(@NotNull Player player) {
|
||||
player.openInventory(INV);
|
||||
openInvs.put(player.getUniqueId(), getInvUUId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(@NotNull Player player) {
|
||||
player.closeInventory();
|
||||
openInvs.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() {
|
||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||
UUID id = openInvs.get(player.getUniqueId());
|
||||
if (id.equals(getInvUUId())) {
|
||||
player.closeInventory();
|
||||
}
|
||||
});
|
||||
invByUUId.remove(getInvUUId());
|
||||
}
|
||||
|
||||
public static Map<UUID, IGUI> getInvByUUId() {
|
||||
return invByUUId;
|
||||
}
|
||||
|
||||
public static Map<UUID, UUID> getOpenInvs() {
|
||||
return openInvs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, Action> getActions() {
|
||||
return actions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack newItem(@NotNull Material material, @NotNull String name, String... lore) {
|
||||
ItemStack item = new ItemStack(material, 1);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta == null) {
|
||||
return item;
|
||||
}
|
||||
meta.setDisplayName(name);
|
||||
ArrayList<String> metaLore = new ArrayList<>(Arrays.asList(lore));
|
||||
meta.setLore(metaLore);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack newItem(@NotNull Material material, @NotNull String name) {
|
||||
return newItem(material, name, "");
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package io.github.paldiu.simplexcore.gui;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Action {
|
||||
void onClick(Player player);
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package io.github.paldiu.simplexcore.gui;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public final class GUIHandler implements Listener {
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void invClick(InventoryClickEvent event) {
|
||||
if (!(event.getWhoClicked() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
UUID pID = player.getUniqueId();
|
||||
UUID invUUID = AbstractGUI.getOpenInvs().get(pID);
|
||||
|
||||
if (invUUID != null) {
|
||||
event.setCancelled(true);
|
||||
IGUI gui = AbstractGUI.getInvByUUId().get(invUUID);
|
||||
Action action = gui.getActions().get(event.getSlot());
|
||||
if (action != null) {
|
||||
action.onClick(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onClose(InventoryCloseEvent event) {
|
||||
Player player = (Player) event.getPlayer();
|
||||
AbstractGUI.getOpenInvs().remove(player.getUniqueId());
|
||||
}
|
||||
}
|
33
src/main/java/io/github/paldiu/simplexcore/gui/IGUI.java
Normal file
33
src/main/java/io/github/paldiu/simplexcore/gui/IGUI.java
Normal file
@ -0,0 +1,33 @@
|
||||
package io.github.paldiu.simplexcore.gui;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface IGUI {
|
||||
UUID getInvUUId();
|
||||
|
||||
Inventory getInventory();
|
||||
|
||||
void setItem(int slot, @NotNull ItemStack stack, @Nullable Action action);
|
||||
|
||||
void setItem(int slot, @NotNull ItemStack stack);
|
||||
|
||||
void open(@NotNull Player player);
|
||||
|
||||
void close(@NotNull Player player);
|
||||
|
||||
void delete();
|
||||
|
||||
Map<Integer, Action> getActions();
|
||||
|
||||
ItemStack newItem(@NotNull Material material, @NotNull String name, String... lore);
|
||||
|
||||
ItemStack newItem(@NotNull Material material, @NotNull String name);
|
||||
}
|
@ -14,4 +14,6 @@ public interface IUsableSign {
|
||||
String getSignText();
|
||||
|
||||
void executeOnInteract();
|
||||
|
||||
String signTag();
|
||||
}
|
||||
|
@ -14,11 +14,6 @@ import org.bukkit.scheduler.BukkitScheduler;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public final class Constants {
|
||||
// Utility class should not be instantiated.
|
||||
private Constants() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
private static final SimplexCore plugin = JavaPlugin.getPlugin(SimplexCore.class);
|
||||
private static final Server server = plugin.getServer();
|
||||
private static final Logger logger = plugin.getLogger();
|
||||
@ -27,6 +22,10 @@ public final class Constants {
|
||||
private static final DependencyManagement dpm = new DependencyManagement();
|
||||
private static final Yaml config = new YamlFactory(plugin).setDefaultPathways();
|
||||
private static final TimeValues time = new TimeValues();
|
||||
// Utility class should not be instantiated.
|
||||
private Constants() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static SimplexCore getPlugin() {
|
||||
return plugin;
|
||||
|
@ -2,11 +2,30 @@ package io.github.paldiu.simplexcore.utils;
|
||||
|
||||
import io.github.paldiu.simplexcore.ban.BanType;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.SplittableRandom;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public final class Utilities {
|
||||
private static final SplittableRandom random = new SplittableRandom();
|
||||
private static final SplittableRandom numbers = new SplittableRandom();
|
||||
private static final List<Character> list = new ArrayList<>() {{
|
||||
add('0');
|
||||
add('1');
|
||||
add('2');
|
||||
add('3');
|
||||
add('4');
|
||||
add('5');
|
||||
add('6');
|
||||
add('7');
|
||||
add('8');
|
||||
add('9');
|
||||
add('-');
|
||||
}};
|
||||
|
||||
//Utility class should not be instantiated.
|
||||
private Utilities() {
|
||||
throw new AssertionError();
|
||||
@ -41,22 +60,6 @@ public final class Utilities {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static final SplittableRandom random = new SplittableRandom();
|
||||
private static final SplittableRandom numbers = new SplittableRandom();
|
||||
private static final List<Character> list = new ArrayList<>(){{
|
||||
add('0');
|
||||
add('1');
|
||||
add('2');
|
||||
add('3');
|
||||
add('4');
|
||||
add('5');
|
||||
add('6');
|
||||
add('7');
|
||||
add('8');
|
||||
add('9');
|
||||
add('-');
|
||||
}};
|
||||
|
||||
private static char capitalize(char character) {
|
||||
if (list.contains(character)) {
|
||||
return character;
|
||||
|
@ -1,30 +1,51 @@
|
||||
io\github\paldiu\simplexcore\command\defaults\Command_info.class
|
||||
io\github\paldiu\simplexcore\listener\ServerPluginListener.class
|
||||
io\github\paldiu\simplexcore\command\CommandLoader.class
|
||||
io\github\paldiu\simplexcore\ban\BanType.class
|
||||
io\github\paldiu\simplexcore\command\CommandInfo.class
|
||||
io\github\paldiu\simplexcore\future\Announcer$1.class
|
||||
io\github\paldiu\simplexcore\plugin\AddonRegistry.class
|
||||
io\github\paldiu\simplexcore\command\CommandLoader$Registry.class
|
||||
io\github\paldiu\simplexcore\CoreState$1.class
|
||||
io\github\paldiu\simplexcore\utils\Constants$TimeValues.class
|
||||
io\github\paldiu\simplexcore\CoreState.class
|
||||
io\github\paldiu\simplexcore\config\YamlFactory.class
|
||||
io\github\paldiu\simplexcore\concurrent\TaskFactory.class
|
||||
io\github\paldiu\simplexcore\listener\DependencyListener$1.class
|
||||
io\github\paldiu\simplexcore\concurrent\SimplexTask.class
|
||||
io\github\paldiu\simplexcore\potion\PotionsFactory.class
|
||||
io\github\paldiu\simplexcore\plugin\SimplexAddon.class
|
||||
io\github\paldiu\simplexcore\chat\Messages.class
|
||||
io\github\paldiu\simplexcore\gui\Action.class
|
||||
io\github\paldiu\simplexcore\gui\GUIHandler.class
|
||||
io\github\paldiu\simplexcore\plugin\AddonManager.class
|
||||
io\github\paldiu\simplexcore\chat\ChatUtils.class
|
||||
io\github\paldiu\simplexcore\structures\Structure.class
|
||||
io\github\paldiu\simplexcore\gui\AbstractGUI.class
|
||||
io\github\paldiu\simplexcore\command\defaults\DefaultCommand.class
|
||||
io\github\paldiu\simplexcore\utils\Utilities.class
|
||||
io\github\paldiu\simplexcore\chat\TextComponentFactory.class
|
||||
io\github\paldiu\simplexcore\command\SimplexCommand.class
|
||||
io\github\paldiu\simplexcore\ban\BanFactory.class
|
||||
io\github\paldiu\simplexcore\math\Size.class
|
||||
io\github\paldiu\simplexcore\config\Path.class
|
||||
io\github\paldiu\simplexcore\utils\Bean.class
|
||||
io\github\paldiu\simplexcore\utils\Constants.class
|
||||
io\github\paldiu\simplexcore\future\SimplexTask.class
|
||||
io\github\paldiu\simplexcore\ban\Ban.class
|
||||
io\github\paldiu\simplexcore\config\JsonFactory.class
|
||||
io\github\paldiu\simplexcore\listener\DependencyListener.class
|
||||
io\github\paldiu\simplexcore\SimplexCore.class
|
||||
io\github\paldiu\simplexcore\utils\Trio.class
|
||||
io\github\paldiu\simplexcore\listener\SimplexListener.class
|
||||
io\github\paldiu\simplexcore\future\Announcer.class
|
||||
io\github\paldiu\simplexcore\config\IConfig.class
|
||||
io\github\paldiu\simplexcore\math\Cuboid.class
|
||||
io\github\paldiu\simplexcore\CoreState$State.class
|
||||
io\github\paldiu\simplexcore\concurrent\Announcer.class
|
||||
io\github\paldiu\simplexcore\command\defaults\Command_info.class
|
||||
io\github\paldiu\simplexcore\particle\IParticleEffect.class
|
||||
io\github\paldiu\simplexcore\structures\IStructure.class
|
||||
io\github\paldiu\simplexcore\concurrent\Announcer$1.class
|
||||
io\github\paldiu\simplexcore\plugin\AddonRegistry.class
|
||||
io\github\paldiu\simplexcore\CoreState$1.class
|
||||
io\github\paldiu\simplexcore\config\YamlFactory.class
|
||||
io\github\paldiu\simplexcore\potion\IPotionEffect.class
|
||||
io\github\paldiu\simplexcore\gui\AbstractGUI$1.class
|
||||
io\github\paldiu\simplexcore\chat\ChatUtils.class
|
||||
io\github\paldiu\simplexcore\gui\IGUI.class
|
||||
io\github\paldiu\simplexcore\chat\TextComponentFactory.class
|
||||
io\github\paldiu\simplexcore\command\SimplexCommand.class
|
||||
io\github\paldiu\simplexcore\ban\BanFactory$1.class
|
||||
io\github\paldiu\simplexcore\sign\IUsableSign.class
|
||||
io\github\paldiu\simplexcore\utils\Constants.class
|
||||
io\github\paldiu\simplexcore\ban\IBan.class
|
||||
io\github\paldiu\simplexcore\listener\SimplexListener.class
|
||||
io\github\paldiu\simplexcore\listener\DependencyListener$2.class
|
||||
|
Loading…
Reference in New Issue
Block a user