Massive changes
* Changes SongodaCore to CraftaroCore * Adds CustomizablePagedInventory * Refactors the projects a bit, adds Compatibility * Minor fix to actions * Adds 1.19.4 + 1.20 NMS.
This commit is contained in:
parent
b9f62c027d
commit
975eaa9cb6
|
@ -1,7 +1,7 @@
|
|||
# These are supported funding model platforms
|
||||
|
||||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
patreon: songoda
|
||||
patreon: craftaro
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
|
@ -9,4 +9,4 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl
|
|||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
custom: [ 'https://songoda.com/songoda+' ]
|
||||
custom: [ 'https://craftaro.com/craftaro+' ]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# This workflow will build a Java project with Maven
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
||||
|
||||
name: Build SongodaCore
|
||||
name: Build CraftaroCore
|
||||
|
||||
on:
|
||||
push:
|
||||
|
@ -35,11 +35,11 @@ jobs:
|
|||
run: 'mvn -B -Duser.name="GitHub Runner on $GITHUB_REPOSITORY (id=$GITHUB_RUN_ID)" clean package'
|
||||
|
||||
# Upload build artifacts
|
||||
- name: 'Upload Build Artifact: SongodaCore-*.jar'
|
||||
- name: 'Upload Build Artifact: CraftaroCore-*.jar'
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: SongodaCore-artifacts
|
||||
path: ./Core/target/SongodaCore-*.jar
|
||||
name: CraftaroCore-artifacts
|
||||
path: ./Core/target/CraftaroCore-*.jar
|
||||
|
||||
##
|
||||
# Discord Webhook
|
||||
|
|
|
@ -43,6 +43,6 @@ jobs:
|
|||
|
||||
- name: Analyze project
|
||||
if: ${{ env.SONAR_TOKEN != null }}
|
||||
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=songoda_SongodaCore
|
||||
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=craftaro_CraftaroCore
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.craftaro</groupId>
|
||||
<artifactId>CraftaroCore3</artifactId>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>craftarocore-compatibility</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.19.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.cryptomorin</groupId>
|
||||
<artifactId>XSeries</artifactId>
|
||||
<version>9.1.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.compatibility;
|
||||
package com.craftaro.core.compatibility;
|
||||
|
||||
public enum ClassMapping {
|
||||
BIOME_BASE("world.level.biome", "BiomeBase"),
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.compatibility;
|
||||
package com.craftaro.core.compatibility;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.compatibility;
|
||||
package com.craftaro.core.compatibility;
|
||||
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.BlockFace;
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.compatibility;
|
||||
package com.craftaro.core.compatibility;
|
||||
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.compatibility;
|
||||
package com.craftaro.core.compatibility;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.compatibility;
|
||||
package com.craftaro.core.compatibility;
|
||||
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.compatibility;
|
||||
package com.craftaro.core.compatibility;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.compatibility;
|
||||
package com.craftaro.core.compatibility;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.compatibility;
|
||||
package com.craftaro.core.compatibility;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
89
Core/pom.xml
89
Core/pom.xml
|
@ -3,15 +3,15 @@
|
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>SongodaCore3</artifactId>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>CraftaroCore3</artifactId>
|
||||
<groupId>com.craftaro</groupId>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>songodacore-core</artifactId>
|
||||
<artifactId>craftarocore-core</artifactId>
|
||||
|
||||
<build>
|
||||
<finalName>SongodaCore-${project.version}</finalName>
|
||||
<finalName>CraftaroCore-${project.version}</finalName>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
@ -33,7 +33,7 @@
|
|||
<injections>
|
||||
<injection>
|
||||
<value>${project.version}</value>
|
||||
<pointCut>com.songoda.core.SongodaCoreConstants.getCoreVersion</pointCut>
|
||||
<pointCut>com.craftaro.core.CraftaroCoreConstants.getCoreVersion</pointCut>
|
||||
</injection>
|
||||
</injections>
|
||||
</configuration>
|
||||
|
@ -80,7 +80,7 @@
|
|||
<include>net.kyori:*</include>
|
||||
<include>com.github.cryptomorin:XSeries</include>
|
||||
<include>com.github.Revxrsal.Lamp:*</include>
|
||||
<include>com.songoda:songodacore-hooks</include>
|
||||
<include>com.craftaro:*</include>
|
||||
<include>net.wesjd:anvilgui</include>
|
||||
<include>co.aikar:*</include>
|
||||
<include>dev.triumphteam:triumph-gui</include>
|
||||
|
@ -91,81 +91,86 @@
|
|||
<include>com.h2database:h2</include>
|
||||
<include>me.carleslc.Simple-YAML:Simple-Yaml</include>
|
||||
<include>ru.vyarus:yaml-config-updater</include>
|
||||
<include>org.apache.commons:commons-text</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>com.zaxxer</pattern>
|
||||
<shadedPattern>com.songoda.core.third_party.com.zaxxer</shadedPattern>
|
||||
<shadedPattern>com.craftaro.core.third_party.com.zaxxer</shadedPattern>
|
||||
</relocation>
|
||||
|
||||
<relocation>
|
||||
<pattern>de.tr7zw.changeme.nbtapi</pattern>
|
||||
<shadedPattern>com.songoda.core.third_party.de.tr7zw.nbtapi</shadedPattern>
|
||||
<shadedPattern>com.craftaro.core.third_party.de.tr7zw.nbtapi</shadedPattern>
|
||||
</relocation>
|
||||
|
||||
<relocation>
|
||||
<pattern>net.kyori</pattern>
|
||||
<shadedPattern>com.songoda.core.third_party.net.kyori</shadedPattern>
|
||||
<shadedPattern>com.craftaro.core.third_party.net.kyori</shadedPattern>
|
||||
</relocation>
|
||||
|
||||
<relocation>
|
||||
<pattern>com.cryptomorin.xseries</pattern>
|
||||
<shadedPattern>com.songoda.core.third_party.com.cryptomorin.xseries</shadedPattern>
|
||||
<shadedPattern>com.craftaro.core.third_party.com.cryptomorin.xseries</shadedPattern>
|
||||
</relocation>
|
||||
|
||||
<relocation>
|
||||
<pattern>net.wesjd.anvilgui</pattern>
|
||||
<shadedPattern>com.songoda.core.third_party.net.wesjd.anvilgui</shadedPattern>
|
||||
<shadedPattern>com.craftaro.core.third_party.net.wesjd.anvilgui</shadedPattern>
|
||||
</relocation>
|
||||
|
||||
<relocation>
|
||||
<pattern>dev.triumphteam.gui</pattern>
|
||||
<shadedPattern>com.songoda.core.third_party.dev.triumphteam.gui</shadedPattern>
|
||||
<shadedPattern>com.craftaro.core.third_party.dev.triumphteam.gui</shadedPattern>
|
||||
</relocation>
|
||||
|
||||
<relocation>
|
||||
<pattern>revxrsal.commands</pattern>
|
||||
<shadedPattern>com.songoda.core.third_party.revxrsal.commands</shadedPattern>
|
||||
<shadedPattern>com.craftaro.core.third_party.revxrsal.commands</shadedPattern>
|
||||
</relocation>
|
||||
|
||||
<relocation>
|
||||
<pattern>org.jooq</pattern>
|
||||
<shadedPattern>com.songoda.core.third_party.org.jooq</shadedPattern>
|
||||
<shadedPattern>com.craftaro.core.third_party.org.jooq</shadedPattern>
|
||||
</relocation>
|
||||
|
||||
<relocation>
|
||||
<pattern>co.aikar.taskchain</pattern>
|
||||
<shadedPattern>com.songoda.core.third_party.co.aikar.taskchain</shadedPattern>
|
||||
<shadedPattern>com.craftaro.core.third_party.co.aikar.taskchain</shadedPattern>
|
||||
</relocation>
|
||||
|
||||
<relocation>
|
||||
<pattern>org.mariadb.jdbc</pattern>
|
||||
<shadedPattern>com.songoda.core.third_party.org.mariadb.jdbc</shadedPattern>
|
||||
<shadedPattern>com.craftaro.core.third_party.org.mariadb.jdbc</shadedPattern>
|
||||
</relocation>
|
||||
|
||||
<relocation>
|
||||
<pattern>org.h2</pattern>
|
||||
<shadedPattern>com.songoda.core.third_party.org.h2</shadedPattern>
|
||||
<shadedPattern>com.craftaro.core.third_party.org.h2</shadedPattern>
|
||||
</relocation>
|
||||
|
||||
<relocation>
|
||||
<pattern>org.reactivestreams</pattern>
|
||||
<shadedPattern>com.songoda.core.third_party.org.reactivestreams</shadedPattern>
|
||||
<shadedPattern>com.craftaro.core.third_party.org.reactivestreams</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>io.r2dbc</pattern>
|
||||
<shadedPattern>com.songoda.core.third_party.io.r2dbc</shadedPattern>
|
||||
<shadedPattern>com.craftaro.core.third_party.io.r2dbc</shadedPattern>
|
||||
</relocation>
|
||||
|
||||
<relocation>
|
||||
<pattern>me.carleslc.Simple-YAML</pattern>
|
||||
<shadedPattern>com.songoda.core.third_party.me.carleslc.Simple-YAML</shadedPattern>
|
||||
<shadedPattern>com.craftaro.core.third_party.me.carleslc.Simple-YAML</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>ru.vyarus.yaml</pattern>
|
||||
<shadedPattern>com.songoda.core.third_party.ru.vyarus.yaml</shadedPattern>
|
||||
<shadedPattern>com.craftaro.core.third_party.ru.vyarus.yaml</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.apache.commons.text</pattern>
|
||||
<shadedPattern>com.craftaro.core.third_party.org.apache.commons.text</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
|
@ -207,7 +212,7 @@
|
|||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-api</artifactId>
|
||||
<version>2.10.0</version>
|
||||
<version>2.11.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -244,13 +249,6 @@
|
|||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.cryptomorin</groupId>
|
||||
<artifactId>XSeries</artifactId>
|
||||
<version>9.1.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.Revxrsal.Lamp</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
|
@ -279,7 +277,7 @@
|
|||
<dependency>
|
||||
<groupId>dev.triumphteam</groupId>
|
||||
<artifactId>triumph-gui</artifactId>
|
||||
<version>3.1.2</version>
|
||||
<version>3.1.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -297,13 +295,6 @@
|
|||
<artifactId>h2</artifactId>
|
||||
<version>1.4.200</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>songodacore-hooks</artifactId>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>me.carleslc.Simple-YAML</groupId>
|
||||
<artifactId>Simple-Yaml</artifactId>
|
||||
|
@ -321,5 +312,29 @@
|
|||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-text</artifactId>
|
||||
<version>1.10.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.craftaro</groupId>
|
||||
<artifactId>craftarocore-hooks</artifactId>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.craftaro</groupId>
|
||||
<artifactId>craftarocore-compatibility</artifactId>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.craftaro</groupId>
|
||||
<artifactId>craftarocore-nms</artifactId>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
package com.craftaro.core;
|
||||
|
||||
import com.craftaro.core.builtin.CraftaroCoreCommand;
|
||||
import com.craftaro.core.compatibility.ServerVersion;
|
||||
import com.craftaro.core.nms.NMSGetter;
|
||||
import com.craftaro.core.plugins.PluginInfo;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import revxrsal.commands.bukkit.BukkitCommandHandler;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class CraftaroCore extends JavaPlugin {
|
||||
|
||||
private static CraftaroCore instance;
|
||||
public static CraftaroCore getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private final Set<PluginInfo> registeredPlugins = new HashSet<>();
|
||||
|
||||
private BukkitCommandHandler commandManager;
|
||||
private NMSGetter nmsGetter;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
|
||||
this.commandManager = BukkitCommandHandler.create(this);
|
||||
commandManager.register(new CraftaroCoreCommand(this));
|
||||
|
||||
try {
|
||||
this.nmsGetter = (NMSGetter)Class.forName("com.craftaro.core.nms." + ServerVersion.getServerVersionString() + ".NMSGetterImpl").getConstructors()[0].newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | ClassNotFoundException e) {
|
||||
getLogger().severe("Unable to load NMS hooks. Please update CraftaroCore. Your current server version: " + ServerVersion.getServerVersionString());
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void registerPlugin(CraftaroPlugin plugin, int pluginId, String icon) {
|
||||
plugin.getLogger().info("Hooked into " + plugin.getName() + ".");
|
||||
PluginInfo info = new PluginInfo(plugin, pluginId, icon);
|
||||
registeredPlugins.add(info);
|
||||
|
||||
// TODO: add an update checker
|
||||
}
|
||||
|
||||
public Set<PluginInfo> getRegisteredPlugins() {
|
||||
return Collections.unmodifiableSet(registeredPlugins);
|
||||
}
|
||||
|
||||
public NMSGetter getNMSGetter() {
|
||||
return nmsGetter;
|
||||
}
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
package com.songoda.core;
|
||||
package com.craftaro.core;
|
||||
|
||||
/*
|
||||
* Return values in this class are automatically replaced by a maven plugin after the project has been compiled.
|
||||
* This allows for properties to be defined at one place without relying on a text file
|
||||
* that needs to be inside the final jar (might get lost when this lib is shaded into other projects).
|
||||
*/
|
||||
public class SongodaCoreConstants {
|
||||
public class CraftaroCoreConstants {
|
||||
public static String getCoreVersion() {
|
||||
return "UNKNOWN_VERSION";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,17 +1,22 @@
|
|||
package com.songoda.core;
|
||||
package com.craftaro.core;
|
||||
|
||||
import co.aikar.taskchain.BukkitTaskChainFactory;
|
||||
import co.aikar.taskchain.TaskChain;
|
||||
import co.aikar.taskchain.TaskChainFactory;
|
||||
import com.songoda.core.actions.ActionManager;
|
||||
import com.songoda.core.builtin.SongodaCoreCommand;
|
||||
import com.songoda.core.configuration.Config;
|
||||
import com.songoda.core.database.DataManager;
|
||||
import com.songoda.core.database.DataMigration;
|
||||
import com.songoda.core.database.DatabaseType;
|
||||
import com.songoda.core.placeholder.IPlaceholderResolver;
|
||||
import com.songoda.core.placeholder.NoPluginResolver;
|
||||
import com.songoda.core.placeholder.PlaceholderAPIResolver;
|
||||
import com.craftaro.core.actions.ActionManager;
|
||||
import com.craftaro.core.configuration.Config;
|
||||
import com.craftaro.core.database.DataManager;
|
||||
import com.craftaro.core.database.DataMigration;
|
||||
import com.craftaro.core.database.DatabaseType;
|
||||
import com.craftaro.core.hooks.economy.EconomyManager;
|
||||
import com.craftaro.core.hooks.economy.IEconomy;
|
||||
import com.craftaro.core.hooks.holograms.AbstractHologram;
|
||||
import com.craftaro.core.hooks.holograms.HologramManager;
|
||||
import com.craftaro.core.hooks.protection.ProtectionManager;
|
||||
import com.craftaro.core.hooks.protection.ProtectionSet;
|
||||
import com.craftaro.core.placeholder.IPlaceholderResolver;
|
||||
import com.craftaro.core.placeholder.NoPluginResolver;
|
||||
import com.craftaro.core.placeholder.PlaceholderAPIResolver;
|
||||
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -21,13 +26,11 @@ import org.jetbrains.annotations.NotNull;
|
|||
import revxrsal.commands.bukkit.BukkitCommandHandler;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public abstract class SongodaPlugin extends JavaPlugin {
|
||||
public abstract class CraftaroPlugin extends JavaPlugin {
|
||||
|
||||
static {
|
||||
/* NBT-API */
|
||||
|
@ -44,6 +47,9 @@ public abstract class SongodaPlugin extends JavaPlugin {
|
|||
private ActionManager actionManager;
|
||||
private TaskChainFactory taskChainFactory;
|
||||
private DataManager dataManager;
|
||||
private IEconomy economyHook;
|
||||
private AbstractHologram hologramHook;
|
||||
private ProtectionSet protectionHooks;
|
||||
|
||||
public abstract void onPluginEnable();
|
||||
public abstract void onPluginDisable();
|
||||
|
@ -53,7 +59,7 @@ public abstract class SongodaPlugin extends JavaPlugin {
|
|||
|
||||
@Override
|
||||
public final void onEnable() {
|
||||
SongodaCore.getInstance().registerPlugin(this, getPluginId(), getPluginIcon());
|
||||
CraftaroCore.getInstance().registerPlugin(this, getPluginId(), getPluginIcon());
|
||||
|
||||
this.commandManager = BukkitCommandHandler.create(this);
|
||||
this.adventure = BukkitAudiences.create(this);
|
||||
|
@ -66,8 +72,14 @@ public abstract class SongodaPlugin extends JavaPlugin {
|
|||
this.placeholderResolver = new NoPluginResolver();
|
||||
}
|
||||
|
||||
Config hooksConfig = getHooksConfig();
|
||||
this.economyHook = new EconomyManager(this).getHookByName(hooksConfig.getString("Default Economy Hook"));
|
||||
this.hologramHook = new HologramManager(this).getHookByName(hooksConfig.getString("Default Hologram Hook"));
|
||||
this.protectionHooks = new ProtectionManager(this).getHooksByName(hooksConfig.getStringList("Default Protection Hook"));
|
||||
|
||||
onPluginEnable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the DataManager for this plugin.
|
||||
* Note: Make sure to call initDatabase() in onPluginEnable() before using this.
|
||||
|
@ -127,7 +139,7 @@ public abstract class SongodaPlugin extends JavaPlugin {
|
|||
}
|
||||
|
||||
/**
|
||||
* Create a configuration file that automatically updates. Requires config-version to be defined.
|
||||
* Create a configuration file that automatically updates.
|
||||
* @param file File to create.
|
||||
* @return The configuration file created.
|
||||
*/
|
||||
|
@ -139,6 +151,10 @@ public abstract class SongodaPlugin extends JavaPlugin {
|
|||
return new Config(this, new File(getDataFolder(), "database.yml"));
|
||||
}
|
||||
|
||||
public Config getHooksConfig() {
|
||||
return new Config(this, new File(getDataFolder(), "hooks.yml"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onDisable() {
|
||||
onPluginDisable();
|
||||
|
@ -148,7 +164,7 @@ public abstract class SongodaPlugin extends JavaPlugin {
|
|||
}
|
||||
|
||||
/**
|
||||
* Use {@link com.songoda.core.configuration.Config} instead.
|
||||
* Use {@link Config} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
|
@ -157,7 +173,7 @@ public abstract class SongodaPlugin extends JavaPlugin {
|
|||
}
|
||||
|
||||
/**
|
||||
* Use {@link com.songoda.core.configuration.Config} instead.
|
||||
* Use {@link Config} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
|
@ -165,7 +181,7 @@ public abstract class SongodaPlugin extends JavaPlugin {
|
|||
}
|
||||
|
||||
/**
|
||||
* Use {@link com.songoda.core.configuration.Config} instead.
|
||||
* Use {@link Config} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
|
@ -195,4 +211,16 @@ public abstract class SongodaPlugin extends JavaPlugin {
|
|||
public <T> TaskChain<T> newSharedChain(String name) {
|
||||
return taskChainFactory.newSharedChain(name);
|
||||
}
|
||||
|
||||
public IEconomy getEconomyHook() {
|
||||
return economyHook;
|
||||
}
|
||||
|
||||
public AbstractHologram getHologramHook() {
|
||||
return hologramHook;
|
||||
}
|
||||
|
||||
public ProtectionSet getProtectionHook() {
|
||||
return protectionHooks;
|
||||
}
|
||||
}
|
|
@ -1,16 +1,15 @@
|
|||
package com.songoda.core.actions;
|
||||
package com.craftaro.core.actions;
|
||||
|
||||
import com.songoda.core.SongodaPlugin;
|
||||
import com.songoda.core.actions.impl.BroadcastAction;
|
||||
import com.songoda.core.actions.impl.ConsoleCommandAction;
|
||||
import com.songoda.core.actions.impl.GiveEffectAction;
|
||||
import com.songoda.core.actions.impl.GiveFoodAction;
|
||||
import com.songoda.core.actions.impl.GiveHealthAction;
|
||||
import com.songoda.core.actions.impl.MessageAction;
|
||||
import com.songoda.core.actions.impl.PlaySoundAction;
|
||||
import com.songoda.core.actions.impl.PlayerCommandAction;
|
||||
import com.songoda.core.actions.impl.TitleAction;
|
||||
import org.bukkit.Bukkit;
|
||||
import com.craftaro.core.CraftaroPlugin;
|
||||
import com.craftaro.core.actions.impl.BroadcastAction;
|
||||
import com.craftaro.core.actions.impl.PlayerCommandAction;
|
||||
import com.craftaro.core.actions.impl.ConsoleCommandAction;
|
||||
import com.craftaro.core.actions.impl.GiveEffectAction;
|
||||
import com.craftaro.core.actions.impl.GiveFoodAction;
|
||||
import com.craftaro.core.actions.impl.GiveHealthAction;
|
||||
import com.craftaro.core.actions.impl.MessageAction;
|
||||
import com.craftaro.core.actions.impl.PlaySoundAction;
|
||||
import com.craftaro.core.actions.impl.TitleAction;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -23,10 +22,10 @@ import java.util.concurrent.ThreadLocalRandom;
|
|||
|
||||
public class ActionManager {
|
||||
|
||||
private final SongodaPlugin plugin;
|
||||
private final CraftaroPlugin plugin;
|
||||
private final Set<GameAction> globalActions = new HashSet<>();
|
||||
|
||||
public ActionManager(SongodaPlugin plugin) {
|
||||
public ActionManager(CraftaroPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
loadGlobalActions();
|
||||
}
|
||||
|
@ -46,7 +45,7 @@ public class ActionManager {
|
|||
public void executeAction(Player player, String args) {
|
||||
globalActions.stream().filter(action -> args.startsWith(action.getPrefix())).findAny().ifPresent(action -> {
|
||||
String text = args.replace("%player%", player.getName()).substring(action.getPrefix().length()).trim();
|
||||
text = plugin.getPlaceholderResolver().setPlaceholders(player, args);
|
||||
text = plugin.getPlaceholderResolver().setPlaceholders(player, text);
|
||||
|
||||
String[] availableSplits = substringsBetween(text, "{random:", "}");
|
||||
if (availableSplits != null) {
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.actions;
|
||||
package com.craftaro.core.actions;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package com.songoda.core.actions.impl;
|
||||
package com.craftaro.core.actions.impl;
|
||||
|
||||
import com.songoda.core.SongodaPlugin;
|
||||
import com.songoda.core.actions.GameAction;
|
||||
import com.craftaro.core.CraftaroPlugin;
|
||||
import com.craftaro.core.actions.GameAction;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
@ -9,8 +9,8 @@ import java.util.Map;
|
|||
|
||||
public class BroadcastAction extends GameAction {
|
||||
|
||||
private final SongodaPlugin plugin;
|
||||
public BroadcastAction(SongodaPlugin plugin) {
|
||||
private final CraftaroPlugin plugin;
|
||||
public BroadcastAction(CraftaroPlugin plugin) {
|
||||
super("[Broadcast]");
|
||||
this.plugin = plugin;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package com.songoda.core.actions.impl;
|
||||
package com.craftaro.core.actions.impl;
|
||||
|
||||
import com.songoda.core.actions.GameAction;
|
||||
import com.craftaro.core.actions.GameAction;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package com.songoda.core.actions.impl;
|
||||
package com.craftaro.core.actions.impl;
|
||||
|
||||
import com.songoda.core.actions.GameAction;
|
||||
import com.songoda.core.utils.NumberUtils;
|
||||
import com.craftaro.core.actions.GameAction;
|
||||
import com.craftaro.core.utils.NumberUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
|
@ -1,7 +1,7 @@
|
|||
package com.songoda.core.actions.impl;
|
||||
package com.craftaro.core.actions.impl;
|
||||
|
||||
import com.songoda.core.actions.GameAction;
|
||||
import com.songoda.core.utils.NumberUtils;
|
||||
import com.craftaro.core.actions.GameAction;
|
||||
import com.craftaro.core.utils.NumberUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
|
@ -1,7 +1,7 @@
|
|||
package com.songoda.core.actions.impl;
|
||||
package com.craftaro.core.actions.impl;
|
||||
|
||||
import com.songoda.core.actions.GameAction;
|
||||
import com.songoda.core.utils.NumberUtils;
|
||||
import com.craftaro.core.actions.GameAction;
|
||||
import com.craftaro.core.utils.NumberUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
|
@ -1,7 +1,7 @@
|
|||
package com.songoda.core.actions.impl;
|
||||
package com.craftaro.core.actions.impl;
|
||||
|
||||
import com.songoda.core.SongodaPlugin;
|
||||
import com.songoda.core.actions.GameAction;
|
||||
import com.craftaro.core.CraftaroPlugin;
|
||||
import com.craftaro.core.actions.GameAction;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
@ -9,8 +9,8 @@ import java.util.Map;
|
|||
|
||||
public class MessageAction extends GameAction {
|
||||
|
||||
private final SongodaPlugin plugin;
|
||||
public MessageAction(SongodaPlugin plugin) {
|
||||
private final CraftaroPlugin plugin;
|
||||
public MessageAction(CraftaroPlugin plugin) {
|
||||
super("[Message]");
|
||||
this.plugin = plugin;
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package com.songoda.core.actions.impl;
|
||||
package com.craftaro.core.actions.impl;
|
||||
|
||||
import com.songoda.core.SongodaPlugin;
|
||||
import com.songoda.core.actions.GameAction;
|
||||
import com.craftaro.core.CraftaroPlugin;
|
||||
import com.craftaro.core.actions.GameAction;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -10,8 +10,8 @@ import java.util.Map;
|
|||
|
||||
public class PlaySoundAction extends GameAction {
|
||||
|
||||
private final SongodaPlugin plugin;
|
||||
public PlaySoundAction(SongodaPlugin plugin) {
|
||||
private final CraftaroPlugin plugin;
|
||||
public PlaySoundAction(CraftaroPlugin plugin) {
|
||||
super("[PlaySound]");
|
||||
this.plugin = plugin;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package com.songoda.core.actions.impl;
|
||||
package com.craftaro.core.actions.impl;
|
||||
|
||||
import com.songoda.core.actions.GameAction;
|
||||
import com.craftaro.core.actions.GameAction;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
|
@ -1,7 +1,7 @@
|
|||
package com.songoda.core.actions.impl;
|
||||
package com.craftaro.core.actions.impl;
|
||||
|
||||
import com.songoda.core.SongodaPlugin;
|
||||
import com.songoda.core.actions.GameAction;
|
||||
import com.craftaro.core.CraftaroPlugin;
|
||||
import com.craftaro.core.actions.GameAction;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.title.Title;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -11,8 +11,8 @@ import java.util.Map;
|
|||
|
||||
public class TitleAction extends GameAction {
|
||||
|
||||
private final SongodaPlugin plugin;
|
||||
public TitleAction(SongodaPlugin plugin) {
|
||||
private final CraftaroPlugin plugin;
|
||||
public TitleAction(CraftaroPlugin plugin) {
|
||||
super("[Title]");
|
||||
this.plugin = plugin;
|
||||
}
|
|
@ -1,17 +1,14 @@
|
|||
package com.songoda.core.builtin;
|
||||
package com.craftaro.core.builtin;
|
||||
|
||||
import com.songoda.core.SongodaCore;
|
||||
import com.songoda.core.SongodaPlugin;
|
||||
import com.songoda.core.compatibility.ClassMapping;
|
||||
import com.songoda.core.compatibility.ServerProject;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import com.songoda.core.database.DataManager;
|
||||
import com.songoda.core.database.DataMigration;
|
||||
import com.songoda.core.database.DatabaseType;
|
||||
import com.songoda.core.plugins.PluginInfo;
|
||||
import com.songoda.core.utils.ColorUtils;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import com.craftaro.core.CraftaroCore;
|
||||
import com.craftaro.core.CraftaroPlugin;
|
||||
import com.craftaro.core.compatibility.ClassMapping;
|
||||
import com.craftaro.core.compatibility.ServerProject;
|
||||
import com.craftaro.core.compatibility.ServerVersion;
|
||||
import com.craftaro.core.database.DataManager;
|
||||
import com.craftaro.core.database.DataMigration;
|
||||
import com.craftaro.core.database.DatabaseType;
|
||||
import com.craftaro.core.plugins.PluginInfo;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import revxrsal.commands.annotation.Command;
|
||||
|
@ -23,17 +20,17 @@ import java.lang.reflect.Field;
|
|||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
@Command("songoda")
|
||||
@CommandPermission("songoda.admin")
|
||||
public class SongodaCoreCommand {
|
||||
@Command("craftaro")
|
||||
@CommandPermission("craftaro.admin")
|
||||
public class CraftaroCoreCommand {
|
||||
|
||||
private final SongodaCore core;
|
||||
private final CraftaroCore core;
|
||||
private final DecimalFormat format = new DecimalFormat("##.##");
|
||||
|
||||
private Object serverInstance;
|
||||
private Field tpsField;
|
||||
|
||||
public SongodaCoreCommand(SongodaCore core) {
|
||||
public CraftaroCoreCommand(CraftaroCore core) {
|
||||
this.core = core;
|
||||
|
||||
try {
|
||||
|
@ -45,7 +42,7 @@ public class SongodaCoreCommand {
|
|||
}
|
||||
}
|
||||
|
||||
@DefaultFor("songoda")
|
||||
@DefaultFor("craftaro")
|
||||
public void onDefault(CommandSender sender) {
|
||||
// TODO gui
|
||||
}
|
||||
|
@ -53,8 +50,9 @@ public class SongodaCoreCommand {
|
|||
@Subcommand("diag")
|
||||
public void onDiagnostics(CommandSender sender) {
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage("Songoda Diagnostics Information");
|
||||
sender.sendMessage("Craftaro Diagnostics Information");
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage("Core Version: " + core.getDescription().getVersion());
|
||||
sender.sendMessage("Plugins:");
|
||||
|
||||
for (PluginInfo plugin : core.getRegisteredPlugins()) {
|
||||
|
@ -90,25 +88,25 @@ public class SongodaCoreCommand {
|
|||
sender.sendMessage("Invalid database type.");
|
||||
return;
|
||||
}
|
||||
SongodaPlugin songodaPlugin = (SongodaPlugin) SongodaCore.getInstance().getRegisteredPlugins().stream()
|
||||
CraftaroPlugin craftaroPlugin = (CraftaroPlugin) CraftaroCore.getInstance().getRegisteredPlugins().stream()
|
||||
.filter(info -> info.getJavaPlugin().getName().equalsIgnoreCase(plugin))
|
||||
.findFirst().map(PluginInfo::getJavaPlugin).orElse(null);
|
||||
if (songodaPlugin == null) {
|
||||
if (craftaroPlugin == null) {
|
||||
sender.sendMessage("Invalid plugin.");
|
||||
return;
|
||||
}
|
||||
if (songodaPlugin.getDataManager().getDatabaseConnector().getType() == type) {
|
||||
if (craftaroPlugin.getDataManager().getDatabaseConnector().getType() == type) {
|
||||
sender.sendMessage("Database is already " + type.name() + ".");
|
||||
return;
|
||||
}
|
||||
|
||||
Thread t = new Thread(() -> {
|
||||
DataManager newManager = DataMigration.convert(songodaPlugin, type);
|
||||
DataManager newManager = DataMigration.convert(craftaroPlugin, type);
|
||||
if (newManager == null || !newManager.getDatabaseConnector().isInitialized()) {
|
||||
sender.sendMessage("Failed to convert database.");
|
||||
return;
|
||||
}
|
||||
songodaPlugin.setDataManager(newManager);
|
||||
craftaroPlugin.setDataManager(newManager);
|
||||
sender.sendMessage("Converted database to " + type.name() + ".");
|
||||
});
|
||||
}
|
|
@ -1,15 +1,18 @@
|
|||
package com.songoda.core.configuration;
|
||||
package com.craftaro.core.configuration;
|
||||
|
||||
import com.songoda.core.SongodaCore;
|
||||
import com.songoda.core.SongodaPlugin;
|
||||
import com.craftaro.core.CraftaroCore;
|
||||
import com.craftaro.core.CraftaroPlugin;
|
||||
import org.simpleyaml.configuration.file.YamlFile;
|
||||
import ru.vyarus.yaml.updater.YamlUpdater;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Config extends YamlFile {
|
||||
|
||||
public static final List<String> BUILT_IN_CONFIGS = Arrays.asList("database.yml", "hooks.yml");
|
||||
/**
|
||||
* Loads a config from the given file
|
||||
*
|
||||
|
@ -33,15 +36,15 @@ public class Config extends YamlFile {
|
|||
* @param plugin The plugin to load the config for
|
||||
* @param file The file to load the config from starting from the plugin's data folder
|
||||
*/
|
||||
public Config(SongodaPlugin plugin, File file) {
|
||||
public Config(CraftaroPlugin plugin, File file) {
|
||||
super(new File(plugin.getDataFolder(), file.toString().replace("plugins" + File.separator + plugin.getName() + File.separator, "")));
|
||||
String path = file.toString().replace("plugins" + File.separator + plugin.getName() + File.separator, "");
|
||||
if (!super.exists()) {
|
||||
try {
|
||||
super.createNewFile();
|
||||
final String resource = "/" + path;
|
||||
if (file.toString().endsWith("database.yml")) {
|
||||
YamlUpdater.create(super.getConfigurationFile(), Objects.requireNonNull(SongodaCore.getInstance().getClass().getResourceAsStream(resource))).update();
|
||||
if (BUILT_IN_CONFIGS.contains(file.getName())) {
|
||||
YamlUpdater.create(super.getConfigurationFile(), Objects.requireNonNull(CraftaroCore.getInstance().getClass().getResourceAsStream(resource))).update();
|
||||
} else {
|
||||
YamlUpdater.create(super.getConfigurationFile(), Objects.requireNonNull(plugin.getClass().getResourceAsStream(resource))).update();
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.database;
|
||||
package com.craftaro.core.database;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
|
@ -1,24 +1,22 @@
|
|||
package com.songoda.core.database;
|
||||
package com.craftaro.core.database;
|
||||
|
||||
import com.craftaro.core.CraftaroPlugin;
|
||||
import com.craftaro.core.configuration.Config;
|
||||
import com.craftaro.core.database.connectors.H2Connector;
|
||||
import com.craftaro.core.database.connectors.MariaDBConnector;
|
||||
import com.craftaro.core.database.connectors.MySQLConnector;
|
||||
import com.craftaro.core.database.connectors.SQLiteConnector;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import com.songoda.core.SongodaPlugin;
|
||||
import com.songoda.core.configuration.Config;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jooq.Query;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.impl.DSL;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
@ -26,7 +24,6 @@ import java.util.HashMap;
|
|||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
@ -41,7 +38,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
public class DataManager {
|
||||
protected final SongodaPlugin plugin;
|
||||
protected final CraftaroPlugin plugin;
|
||||
protected final Config databaseConfig;
|
||||
private final List<DataMigration> migrations;
|
||||
|
||||
|
@ -55,14 +52,14 @@ public class DataManager {
|
|||
@Deprecated
|
||||
private static final Map<String, LinkedList<Runnable>> queues = new HashMap<>();
|
||||
|
||||
public DataManager(SongodaPlugin plugin, List<DataMigration> migrations) {
|
||||
public DataManager(CraftaroPlugin plugin, List<DataMigration> migrations) {
|
||||
this.plugin = plugin;
|
||||
this.migrations = migrations;
|
||||
this.databaseConfig = plugin.getDatabaseConfig();
|
||||
load(null);
|
||||
}
|
||||
|
||||
public DataManager(SongodaPlugin plugin, List<DataMigration> migrations, DatabaseType forcedType) {
|
||||
public DataManager(CraftaroPlugin plugin, List<DataMigration> migrations, DatabaseType forcedType) {
|
||||
this.plugin = plugin;
|
||||
this.migrations = migrations;
|
||||
this.databaseConfig = plugin.getDatabaseConfig();
|
|
@ -1,9 +1,8 @@
|
|||
package com.songoda.core.database;
|
||||
package com.craftaro.core.database;
|
||||
|
||||
import com.songoda.core.SongodaCore;
|
||||
import com.songoda.core.SongodaPlugin;
|
||||
import com.craftaro.core.CraftaroCore;
|
||||
import com.craftaro.core.CraftaroPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
@ -33,7 +32,7 @@ public abstract class DataMigration {
|
|||
* @param toType The new database type
|
||||
* @return The new data manager instance
|
||||
*/
|
||||
public static DataManager convert(SongodaPlugin plugin, DatabaseType toType) {
|
||||
public static DataManager convert(CraftaroPlugin plugin, DatabaseType toType) {
|
||||
DataManager from = plugin.getDataManager();
|
||||
if (from.getDatabaseConnector().getType() == toType) {
|
||||
plugin.getLogger().severe("Cannot convert to the same database type!");
|
||||
|
@ -88,13 +87,13 @@ public abstract class DataMigration {
|
|||
toConnection.rollback();
|
||||
} catch (SQLException e1) {
|
||||
e1.printStackTrace();
|
||||
SongodaCore.getInstance().getLogger().severe("Failed to rollback data for the new database");
|
||||
CraftaroCore.getInstance().getLogger().severe("Failed to rollback data for the new database");
|
||||
}
|
||||
e.printStackTrace();
|
||||
SongodaCore.getInstance().getLogger().severe("Failed to migrate data from " + from.getDatabaseConnector().getType() + " to " + to.getDatabaseConnector().getType());
|
||||
CraftaroCore.getInstance().getLogger().severe("Failed to migrate data from " + from.getDatabaseConnector().getType() + " to " + to.getDatabaseConnector().getType());
|
||||
return null;
|
||||
} finally {
|
||||
SongodaCore.getInstance().getLogger().info("Successfully migrated data from " + from.getDatabaseConnector().getType() + " to " + to.getDatabaseConnector().getType());
|
||||
CraftaroCore.getInstance().getLogger().info("Successfully migrated data from " + from.getDatabaseConnector().getType() + " to " + to.getDatabaseConnector().getType());
|
||||
}
|
||||
return to;
|
||||
}
|
|
@ -1,12 +1,9 @@
|
|||
package com.songoda.core.database;
|
||||
package com.craftaro.core.database;
|
||||
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.impl.DSL;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public interface DatabaseConnector {
|
||||
/**
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.database;
|
||||
package com.craftaro.core.database;
|
||||
|
||||
import org.jooq.SQLDialect;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.database;
|
||||
package com.craftaro.core.database;
|
||||
|
||||
public class OptionalResult {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.database;
|
||||
package com.craftaro.core.database;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
|
@ -1,25 +1,27 @@
|
|||
package com.songoda.core.database;
|
||||
package com.craftaro.core.database.connectors;
|
||||
|
||||
import com.songoda.core.SongodaCore;
|
||||
import com.songoda.core.SongodaPlugin;
|
||||
import com.songoda.core.configuration.Config;
|
||||
import com.craftaro.core.CraftaroCore;
|
||||
import com.craftaro.core.CraftaroPlugin;
|
||||
import com.craftaro.core.configuration.Config;
|
||||
import com.craftaro.core.database.DatabaseConnector;
|
||||
import com.craftaro.core.database.DatabaseType;
|
||||
import com.craftaro.core.database.OptionalResult;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.impl.DSL;
|
||||
import org.simpleyaml.configuration.ConfigurationSection;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class H2Connector implements DatabaseConnector {
|
||||
|
||||
private final SongodaPlugin plugin;
|
||||
private final CraftaroPlugin plugin;
|
||||
private HikariDataSource hikari;
|
||||
private boolean initializedSuccessfully;
|
||||
|
||||
public H2Connector(SongodaPlugin plugin, Config databaseConfig) {
|
||||
public H2Connector(CraftaroPlugin plugin, Config databaseConfig) {
|
||||
this.plugin = plugin;
|
||||
|
||||
ConfigurationSection section = databaseConfig.getConfigurationSection("Connection Settings");
|
||||
|
@ -29,10 +31,10 @@ public class H2Connector implements DatabaseConnector {
|
|||
String username = section.getString("Username");
|
||||
|
||||
HikariConfig config = new HikariConfig();
|
||||
config.setDriverClassName("com.songoda.core.third_party.org.h2.Driver");
|
||||
config.setDriverClassName("com.craftaro.core.third_party.org.h2.Driver");
|
||||
config.setJdbcUrl("jdbc:h2:./" + plugin.getDataFolder().getPath().replaceAll("\\\\", "/") + "/" + plugin.getDescription().getName().toLowerCase()+ ";AUTO_RECONNECT=TRUE;MODE=MySQL;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE");
|
||||
config.setPassword(username);
|
||||
config.setUsername(password);
|
||||
config.setUsername(username);
|
||||
config.setPassword(password);
|
||||
config.setMaximumPoolSize(poolSize);
|
||||
|
||||
try {
|
||||
|
@ -69,7 +71,7 @@ public class H2Connector implements DatabaseConnector {
|
|||
try (Connection connection = getConnection()) {
|
||||
return callback.accept(connection);
|
||||
} catch (Exception ex) {
|
||||
SongodaCore.getInstance().getLogger().severe("An error occurred executing a MySQL query: " + ex.getMessage());
|
||||
CraftaroCore.getInstance().getLogger().severe("An error occurred executing a MySQL query: " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return OptionalResult.empty();
|
||||
|
@ -90,7 +92,7 @@ public class H2Connector implements DatabaseConnector {
|
|||
try (Connection connection = getConnection()) {
|
||||
return callback.accept(DSL.using(connection, SQLDialect.MYSQL));
|
||||
} catch (Exception ex) {
|
||||
SongodaCore.getInstance().getLogger().severe("An error occurred executing a MySQL query: " + ex.getMessage());
|
||||
CraftaroCore.getInstance().getLogger().severe("An error occurred executing a MySQL query: " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return OptionalResult.empty();
|
|
@ -1,26 +1,27 @@
|
|||
package com.songoda.core.database;
|
||||
package com.craftaro.core.database.connectors;
|
||||
|
||||
import com.songoda.core.SongodaCore;
|
||||
import com.songoda.core.SongodaPlugin;
|
||||
import com.songoda.core.configuration.Config;
|
||||
import com.craftaro.core.CraftaroCore;
|
||||
import com.craftaro.core.CraftaroPlugin;
|
||||
import com.craftaro.core.configuration.Config;
|
||||
import com.craftaro.core.database.DatabaseConnector;
|
||||
import com.craftaro.core.database.DatabaseType;
|
||||
import com.craftaro.core.database.OptionalResult;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.impl.DSL;
|
||||
import org.simpleyaml.configuration.ConfigurationSection;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class MariaDBConnector implements DatabaseConnector {
|
||||
|
||||
private final SongodaPlugin plugin;
|
||||
private final CraftaroPlugin plugin;
|
||||
private HikariDataSource hikari;
|
||||
private boolean initializedSuccessfully;
|
||||
|
||||
public MariaDBConnector(SongodaPlugin plugin, Config databaseConfig) {
|
||||
public MariaDBConnector(CraftaroPlugin plugin, Config databaseConfig) {
|
||||
this.plugin = plugin;
|
||||
|
||||
ConfigurationSection section = databaseConfig.getConfigurationSection("Connection Settings");
|
||||
|
@ -34,7 +35,7 @@ public class MariaDBConnector implements DatabaseConnector {
|
|||
int poolSize = section.getInt("Pool Size");
|
||||
|
||||
try {
|
||||
Class.forName("com.songoda.core.third_party.org.mariadb.jdbc.Driver");
|
||||
Class.forName("com.craftaro.core.third_party.org.mariadb.jdbc.Driver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -79,7 +80,7 @@ public class MariaDBConnector implements DatabaseConnector {
|
|||
try (Connection connection = getConnection()) {
|
||||
return callback.accept(connection);
|
||||
} catch (Exception ex) {
|
||||
SongodaCore.getInstance().getLogger().severe("An error occurred executing a MySQL query: " + ex.getMessage());
|
||||
CraftaroCore.getInstance().getLogger().severe("An error occurred executing a MySQL query: " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return OptionalResult.empty();
|
||||
|
@ -100,7 +101,7 @@ public class MariaDBConnector implements DatabaseConnector {
|
|||
try (Connection connection = getConnection()) {
|
||||
return callback.accept(DSL.using(connection, SQLDialect.MARIADB));
|
||||
} catch (Exception ex) {
|
||||
SongodaCore.getInstance().getLogger().severe("An error occurred executing a MySQL query: " + ex.getMessage());
|
||||
CraftaroCore.getInstance().getLogger().severe("An error occurred executing a MySQL query: " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return OptionalResult.empty();
|
|
@ -1,7 +1,10 @@
|
|||
package com.songoda.core.database;
|
||||
package com.craftaro.core.database.connectors;
|
||||
|
||||
import com.songoda.core.SongodaCore;
|
||||
import com.songoda.core.configuration.Config;
|
||||
import com.craftaro.core.CraftaroCore;
|
||||
import com.craftaro.core.configuration.Config;
|
||||
import com.craftaro.core.database.DatabaseConnector;
|
||||
import com.craftaro.core.database.DatabaseType;
|
||||
import com.craftaro.core.database.OptionalResult;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
@ -71,7 +74,7 @@ public class MySQLConnector implements DatabaseConnector {
|
|||
try (Connection connection = getConnection()) {
|
||||
return callback.accept(connection);
|
||||
} catch (Exception ex) {
|
||||
SongodaCore.getInstance().getLogger().severe("An error occurred executing a MySQL query: " + ex.getMessage());
|
||||
CraftaroCore.getInstance().getLogger().severe("An error occurred executing a MySQL query: " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return OptionalResult.empty();
|
||||
|
@ -92,7 +95,7 @@ public class MySQLConnector implements DatabaseConnector {
|
|||
try (Connection connection = getConnection()) {
|
||||
return callback.accept(DSL.using(connection, SQLDialect.MYSQL));
|
||||
} catch (Exception ex) {
|
||||
SongodaCore.getInstance().getLogger().severe("An error occurred executing a MySQL query: " + ex.getMessage());
|
||||
CraftaroCore.getInstance().getLogger().severe("An error occurred executing a MySQL query: " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return OptionalResult.empty();
|
|
@ -1,6 +1,9 @@
|
|||
package com.songoda.core.database;
|
||||
package com.craftaro.core.database.connectors;
|
||||
|
||||
import com.songoda.core.SongodaCore;
|
||||
import com.craftaro.core.CraftaroCore;
|
||||
import com.craftaro.core.database.DatabaseConnector;
|
||||
import com.craftaro.core.database.DatabaseType;
|
||||
import com.craftaro.core.database.OptionalResult;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.impl.DSL;
|
||||
|
@ -58,7 +61,7 @@ public class SQLiteConnector implements DatabaseConnector {
|
|||
try (Connection connection = getConnection()) {
|
||||
return callback.accept(connection);
|
||||
} catch (Exception ex) {
|
||||
SongodaCore.getInstance().getLogger().severe("An error occurred executing a MySQL query: " + ex.getMessage());
|
||||
CraftaroCore.getInstance().getLogger().severe("An error occurred executing a MySQL query: " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return OptionalResult.empty();
|
||||
|
@ -79,7 +82,7 @@ public class SQLiteConnector implements DatabaseConnector {
|
|||
try (Connection connection = getConnection()) {
|
||||
return callback.accept(DSL.using(connection, SQLDialect.SQLITE));
|
||||
} catch (Exception ex) {
|
||||
SongodaCore.getInstance().getLogger().severe("An error occurred executing a MySQL query: " + ex.getMessage());
|
||||
CraftaroCore.getInstance().getLogger().severe("An error occurred executing a MySQL query: " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return OptionalResult.empty();
|
|
@ -0,0 +1,127 @@
|
|||
package com.craftaro.core.gui;
|
||||
|
||||
import com.craftaro.core.CraftaroPlugin;
|
||||
import com.craftaro.core.configuration.Config;
|
||||
import dev.triumphteam.gui.builder.item.ItemBuilder;
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.simpleyaml.configuration.ConfigurationSection;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class BaseCustomizable {
|
||||
|
||||
protected final CraftaroPlugin plugin;
|
||||
protected final Player player;
|
||||
protected final String key;
|
||||
protected final Config config;
|
||||
|
||||
public BaseCustomizable(CraftaroPlugin plugin, Player player, String key) {
|
||||
this.plugin = plugin;
|
||||
this.player = player;
|
||||
this.key = key;
|
||||
|
||||
this.config = plugin.createUpdatingConfig(new File(plugin.getDataFolder() + File.separator + "inventories", key + ".yml"));
|
||||
}
|
||||
|
||||
public abstract void open();
|
||||
|
||||
protected abstract void fill(Player player);
|
||||
|
||||
protected void fillWithCustom(Player player) {
|
||||
if (!config.isConfigurationSection("customItems")) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (String key : config.getConfigurationSection("customItems").getKeys(false)) {
|
||||
ConfigurationSection section = config.getConfigurationSection("customItems." + key);
|
||||
List<String> actions = section.getStringList("actions");
|
||||
int slot = section.getInt("slot");
|
||||
|
||||
setCustomItem(slot, getItem(section, Collections.emptyMap(), event -> plugin.getActionManager().executeActions(player, actions)));
|
||||
}
|
||||
}
|
||||
|
||||
public List<Integer> getSlot(String route) {
|
||||
ConfigurationSection section = config.getConfigurationSection(route);
|
||||
List<Integer> slots = section.getIntegerList("slots");
|
||||
if (!slots.isEmpty()) {
|
||||
return slots;
|
||||
}
|
||||
|
||||
int slot = section.getInt("slot");
|
||||
return Collections.singletonList(slot);
|
||||
}
|
||||
|
||||
public GuiItem getItem(ConfigurationSection section, Map<String, String> placeholders, Consumer<InventoryClickEvent> consumer) {
|
||||
Material material = Material.getMaterial(section.getString("material"));
|
||||
|
||||
String nameString = section.getString("name");
|
||||
for (Map.Entry<String, String> entry : placeholders.entrySet()) {
|
||||
nameString = nameString.replace(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
Component name = MiniMessage.miniMessage().deserialize(PlaceholderAPI.setPlaceholders(player, nameString))
|
||||
.applyFallbackStyle(TextDecoration.ITALIC.withState(false));
|
||||
|
||||
|
||||
List<String> loreString = section.getStringList("lore");
|
||||
loreString.replaceAll(text -> {
|
||||
for (Map.Entry<String, String> entry : placeholders.entrySet()) {
|
||||
text = text.replace(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return text;
|
||||
});
|
||||
List<Component> lore = loreString.stream()
|
||||
.map(text -> MiniMessage.miniMessage().deserialize(PlaceholderAPI.setPlaceholders(player, text))
|
||||
.applyFallbackStyle(TextDecoration.ITALIC.withState(false)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
String texture = section.getString("texture");
|
||||
boolean glow = section.getBoolean("glow");
|
||||
int modelData = section.getInt("modelData");
|
||||
|
||||
return ItemBuilder.from(material)
|
||||
.name(name)
|
||||
.lore(lore)
|
||||
.setSkullTexture(texture)
|
||||
.glow(glow)
|
||||
.model(modelData)
|
||||
.asGuiItem(consumer::accept);
|
||||
}
|
||||
|
||||
|
||||
public void setItem(String itemKey, Map<String, String> placeholders) {
|
||||
setItem(itemKey, placeholders, event -> {});
|
||||
}
|
||||
|
||||
public void setItem(String itemKey) {
|
||||
setItem(itemKey, event -> {});
|
||||
}
|
||||
|
||||
public void setItem(String itemKey, Consumer<InventoryClickEvent> consumer) {
|
||||
setItem(itemKey, Collections.emptyMap(), consumer);
|
||||
}
|
||||
|
||||
public abstract void setItem(String itemKey, Map<String, String> placeholders, Consumer<InventoryClickEvent> consumer);
|
||||
public abstract void setCustomItem(int slot, GuiItem item);
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public Config getConfig() {
|
||||
return config;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.craftaro.core.gui;
|
||||
|
||||
import com.craftaro.core.CraftaroPlugin;
|
||||
import dev.triumphteam.gui.guis.Gui;
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.simpleyaml.configuration.ConfigurationSection;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public abstract class CustomizableInventory extends BaseCustomizable {
|
||||
|
||||
protected final Gui gui;
|
||||
public CustomizableInventory(CraftaroPlugin plugin, Player player, String key) {
|
||||
super(plugin, player, key);
|
||||
|
||||
this.gui = Gui.gui()
|
||||
.rows(config.getInt("settings.rows"))
|
||||
.title(MiniMessage.miniMessage().deserialize(config.getString("settings.title")))
|
||||
.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
gui.getGuiItems().clear();
|
||||
|
||||
fill(player);
|
||||
fillWithCustom(player);
|
||||
|
||||
gui.open(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(String itemKey, Map<String, String> placeholders, Consumer<InventoryClickEvent> consumer) {
|
||||
ConfigurationSection section = config.getConfigurationSection("items." + itemKey);
|
||||
gui.setItem(getSlot("items." + itemKey), getItem(section, placeholders, consumer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomItem(int slot, GuiItem item) {
|
||||
gui.setItem(slot, item);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.craftaro.core.gui;
|
||||
|
||||
import com.craftaro.core.CraftaroPlugin;
|
||||
import dev.triumphteam.gui.guis.Gui;
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import dev.triumphteam.gui.guis.PaginatedGui;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.simpleyaml.configuration.ConfigurationSection;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public abstract class CustomizablePagedInventory extends BaseCustomizable {
|
||||
|
||||
protected final PaginatedGui gui;
|
||||
public CustomizablePagedInventory(CraftaroPlugin plugin, Player player, String key) {
|
||||
super(plugin, player, key);
|
||||
|
||||
this.gui = Gui.paginated()
|
||||
.pageSize(config.getInt("settings.pageSize"))
|
||||
.rows(config.getInt("settings.rows"))
|
||||
.title(MiniMessage.miniMessage().deserialize(config.getString("settings.title")))
|
||||
.create();
|
||||
}
|
||||
|
||||
public void open() {
|
||||
gui.getGuiItems().clear();
|
||||
|
||||
fill(player);
|
||||
fillWithCustom(player);
|
||||
|
||||
gui.open(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(String itemKey, Map<String, String> placeholders, Consumer<InventoryClickEvent> consumer) {
|
||||
ConfigurationSection section = config.getConfigurationSection("items." + itemKey);
|
||||
gui.setItem(getSlot("items." + itemKey), getItem(section, placeholders, consumer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomItem(int slot, GuiItem item) {
|
||||
gui.setItem(slot, item);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.craftaro.core.locale;
|
||||
|
||||
import com.craftaro.core.CraftaroPlugin;
|
||||
import com.craftaro.core.configuration.Config;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class LocaleManager {
|
||||
|
||||
private final CraftaroPlugin plugin;
|
||||
private final Config langFile;
|
||||
|
||||
public LocaleManager(CraftaroPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.langFile = plugin.createUpdatingConfig(new File(plugin.getDataFolder(), "lang.yml"));
|
||||
}
|
||||
|
||||
public Message getMessage(String path) {
|
||||
return new Message(plugin.getAdventure(), MiniMessage.miniMessage().deserialize(langFile.getString(path)));
|
||||
}
|
||||
|
||||
public MessageList getMessageList(String path) {
|
||||
return new MessageList(plugin.getAdventure(), langFile.getStringList(path).stream().map(text -> MiniMessage.miniMessage().deserialize(text)).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
package com.songoda.core.locale;
|
||||
package com.craftaro.core.locale;
|
||||
|
||||
import com.songoda.core.utils.ColorUtils;
|
||||
import com.craftaro.core.utils.ColorUtils;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
@ -20,7 +22,12 @@ public class Message {
|
|||
}
|
||||
|
||||
public Message replace(String placeholder, String replacement) {
|
||||
this.component = component.replaceText(text -> text.matchLiteral("<"+placeholder+">").replacement(replacement));
|
||||
this.component = component.replaceText(text -> text.matchLiteral(placeholder).replacement(replacement));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Message replace(String placeholder, ComponentLike replacement) {
|
||||
this.component = component.replaceText(text -> text.matchLiteral(placeholder).replacement(replacement));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -43,4 +50,13 @@ public class Message {
|
|||
public void sendActionBar(Player player) {
|
||||
adventure.player(player).sendActionBar(component);
|
||||
}
|
||||
|
||||
public Component getComponent() {
|
||||
return component;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return LegacyComponentSerializer.legacySection().serialize(component);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package com.craftaro.core.locale;
|
||||
|
||||
import com.craftaro.core.utils.ColorUtils;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MessageList {
|
||||
private final BukkitAudiences adventure;
|
||||
private final List<Component> components;
|
||||
public MessageList(BukkitAudiences adventure, List<Component> components) {
|
||||
this.adventure = adventure;
|
||||
this.components = components;
|
||||
}
|
||||
|
||||
public static MessageList of(BukkitAudiences adventure, List<String> text) {
|
||||
return new MessageList(adventure, ColorUtils.formatComponent(text));
|
||||
}
|
||||
|
||||
public MessageList replace(String placeholder, String replacement) {
|
||||
this.components.replaceAll(component -> component.replaceText(text -> text.matchLiteral(placeholder).replacement(replacement)));
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessageList replace(String placeholder, ComponentLike replacement) {
|
||||
this.components.replaceAll(component -> component.replaceText(text -> text.matchLiteral(placeholder).replacement(replacement)));
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<Component> getComponents() {
|
||||
return components;
|
||||
}
|
||||
|
||||
public void broadcastMessage() {
|
||||
for (Component component : components) {
|
||||
adventure.all().sendMessage(component);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMessage(Player player) {
|
||||
for (Component component : components) {
|
||||
adventure.player(player).sendMessage(component);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMessage(CommandSender sender) {
|
||||
for (Component component : components) {
|
||||
adventure.sender(sender).sendMessage(component);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package com.songoda.core.lootables;
|
||||
package com.craftaro.core.lootables;
|
||||
|
||||
import com.songoda.core.lootables.loot.LootManager;
|
||||
import com.craftaro.core.lootables.loot.LootManager;
|
||||
|
||||
public class Lootables {
|
||||
private final String lootablesDir;
|
|
@ -0,0 +1,7 @@
|
|||
package com.craftaro.core.lootables;
|
||||
|
||||
import com.craftaro.core.lootables.loot.Loot;
|
||||
|
||||
public interface Modify {
|
||||
Loot Modify(Loot loot);
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
package com.songoda.core.lootables.gui;
|
||||
package com.craftaro.core.lootables.gui;
|
||||
|
||||
import com.craftaro.core.CraftaroCore;
|
||||
import com.craftaro.core.lootables.loot.Loot;
|
||||
import com.cryptomorin.xseries.XMaterial;
|
||||
import com.songoda.core.SongodaCore;
|
||||
import com.songoda.core.lootables.loot.Loot;
|
||||
import dev.triumphteam.gui.builder.item.ItemBuilder;
|
||||
import dev.triumphteam.gui.guis.Gui;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
@ -48,7 +48,7 @@ public abstract class AbstractGuiListEditor {
|
|||
new AnvilGUI.Builder()
|
||||
.title("Enter a new line")
|
||||
.itemLeft(XMaterial.PAPER.parseItem())
|
||||
.plugin(SongodaCore.getInstance())
|
||||
.plugin(CraftaroCore.getInstance())
|
||||
.onComplete((player, text) -> {
|
||||
String validated = validate(text);
|
||||
if (validated != null) {
|
|
@ -1,9 +1,9 @@
|
|||
package com.songoda.core.lootables.gui;
|
||||
package com.craftaro.core.lootables.gui;
|
||||
|
||||
import com.craftaro.core.lootables.loot.LootManager;
|
||||
import com.craftaro.core.lootables.loot.Lootable;
|
||||
import com.cryptomorin.xseries.XMaterial;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import com.songoda.core.lootables.loot.LootManager;
|
||||
import com.songoda.core.lootables.loot.Lootable;
|
||||
import com.craftaro.core.compatibility.ServerVersion;
|
||||
import dev.triumphteam.gui.builder.item.ItemBuilder;
|
||||
import dev.triumphteam.gui.guis.Gui;
|
||||
import dev.triumphteam.gui.guis.PaginatedGui;
|
|
@ -1,8 +1,8 @@
|
|||
package com.songoda.core.lootables.gui;
|
||||
package com.craftaro.core.lootables.gui;
|
||||
|
||||
import com.craftaro.core.CraftaroCore;
|
||||
import com.craftaro.core.lootables.loot.Loot;
|
||||
import com.cryptomorin.xseries.XMaterial;
|
||||
import com.songoda.core.SongodaCore;
|
||||
import com.songoda.core.lootables.loot.Loot;
|
||||
import dev.triumphteam.gui.builder.item.ItemBuilder;
|
||||
import dev.triumphteam.gui.guis.Gui;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
@ -43,7 +43,7 @@ public class GuiEnchantEditor {
|
|||
new AnvilGUI.Builder()
|
||||
.title("Enter an enchantment")
|
||||
.itemLeft(XMaterial.PAPER.parseItem())
|
||||
.plugin(SongodaCore.getInstance())
|
||||
.plugin(CraftaroCore.getInstance())
|
||||
.onComplete((player, text) -> {
|
||||
if (Enchantment.getByName(text.toUpperCase().trim()) == null) {
|
||||
return AnvilGUI.Response.text("Invalid enchantment");
|
||||
|
@ -55,7 +55,7 @@ public class GuiEnchantEditor {
|
|||
new AnvilGUI.Builder()
|
||||
.title("Enter a level")
|
||||
.itemLeft(XMaterial.PAPER.parseItem())
|
||||
.plugin(SongodaCore.getInstance())
|
||||
.plugin(CraftaroCore.getInstance())
|
||||
.onComplete((player, level) -> {
|
||||
lore.put(text.toUpperCase().trim(), Integer.parseInt(level.trim()));
|
||||
loot.setEnchants(lore);
|
||||
|
@ -64,7 +64,7 @@ public class GuiEnchantEditor {
|
|||
return AnvilGUI.Response.close();
|
||||
}).onClose(player -> paint());
|
||||
}
|
||||
}.runTaskLater(SongodaCore.getInstance(), 1l);
|
||||
}.runTaskLater(CraftaroCore.getInstance(), 1l);
|
||||
|
||||
return AnvilGUI.Response.close();
|
||||
}).onClose(player -> paint());
|
|
@ -1,6 +1,6 @@
|
|||
package com.songoda.core.lootables.gui;
|
||||
package com.craftaro.core.lootables.gui;
|
||||
|
||||
import com.songoda.core.lootables.loot.Loot;
|
||||
import com.craftaro.core.lootables.loot.Loot;
|
||||
import dev.triumphteam.gui.guis.Gui;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.entity.EntityType;
|
|
@ -1,11 +1,11 @@
|
|||
package com.songoda.core.lootables.gui;
|
||||
package com.craftaro.core.lootables.gui;
|
||||
|
||||
import com.craftaro.core.CraftaroCore;
|
||||
import com.craftaro.core.lootables.loot.Loot;
|
||||
import com.craftaro.core.lootables.loot.LootBuilder;
|
||||
import com.craftaro.core.lootables.loot.LootManager;
|
||||
import com.cryptomorin.xseries.XMaterial;
|
||||
import com.songoda.core.SongodaCore;
|
||||
import com.songoda.core.compatibility.CompatibleHand;
|
||||
import com.songoda.core.lootables.loot.Loot;
|
||||
import com.songoda.core.lootables.loot.LootBuilder;
|
||||
import com.songoda.core.lootables.loot.LootManager;
|
||||
import com.craftaro.core.compatibility.CompatibleHand;
|
||||
import dev.triumphteam.gui.builder.item.ItemBuilder;
|
||||
import dev.triumphteam.gui.guis.Gui;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
@ -62,7 +62,7 @@ public class GuiLootEditor {
|
|||
new AnvilGUI.Builder()
|
||||
.title("Enter a name")
|
||||
.itemLeft(XMaterial.PAPER.parseItem())
|
||||
.plugin(SongodaCore.getInstance())
|
||||
.plugin(CraftaroCore.getInstance())
|
||||
.onComplete((player, text) -> {
|
||||
loot.setName(text);
|
||||
return AnvilGUI.Response.close();
|
||||
|
@ -107,7 +107,7 @@ public class GuiLootEditor {
|
|||
new AnvilGUI.Builder()
|
||||
.title("Enter a chance")
|
||||
.itemLeft(XMaterial.PAPER.parseItem())
|
||||
.plugin(SongodaCore.getInstance())
|
||||
.plugin(CraftaroCore.getInstance())
|
||||
.onComplete((player, text) -> {
|
||||
loot.setChance(Double.parseDouble(text));
|
||||
return AnvilGUI.Response.close();
|
||||
|
@ -121,7 +121,7 @@ public class GuiLootEditor {
|
|||
new AnvilGUI.Builder()
|
||||
.title("Enter a number")
|
||||
.itemLeft(XMaterial.PAPER.parseItem())
|
||||
.plugin(SongodaCore.getInstance())
|
||||
.plugin(CraftaroCore.getInstance())
|
||||
.onComplete((player, text) -> {
|
||||
loot.setMin(Integer.parseInt(text));
|
||||
return AnvilGUI.Response.close();
|
||||
|
@ -134,7 +134,7 @@ public class GuiLootEditor {
|
|||
new AnvilGUI.Builder()
|
||||
.title("Enter a number")
|
||||
.itemLeft(XMaterial.PAPER.parseItem())
|
||||
.plugin(SongodaCore.getInstance())
|
||||
.plugin(CraftaroCore.getInstance())
|
||||
.onComplete((player, text) -> {
|
||||
loot.setMax(Integer.parseInt(text));
|
||||
return AnvilGUI.Response.close();
|
||||
|
@ -147,7 +147,7 @@ public class GuiLootEditor {
|
|||
new AnvilGUI.Builder()
|
||||
.title("Enter a number")
|
||||
.itemLeft(XMaterial.PAPER.parseItem())
|
||||
.plugin(SongodaCore.getInstance())
|
||||
.plugin(CraftaroCore.getInstance())
|
||||
.onComplete((player, text) -> {
|
||||
loot.setDamageMin(Integer.parseInt(text));
|
||||
return AnvilGUI.Response.close();
|
||||
|
@ -160,7 +160,7 @@ public class GuiLootEditor {
|
|||
new AnvilGUI.Builder()
|
||||
.title("Enter a number")
|
||||
.itemLeft(XMaterial.PAPER.parseItem())
|
||||
.plugin(SongodaCore.getInstance())
|
||||
.plugin(CraftaroCore.getInstance())
|
||||
.onComplete((player, text) -> {
|
||||
loot.setDamageMax(Integer.parseInt(text));
|
||||
return AnvilGUI.Response.close();
|
||||
|
@ -180,7 +180,7 @@ public class GuiLootEditor {
|
|||
new AnvilGUI.Builder()
|
||||
.title("Enter a number")
|
||||
.itemLeft(XMaterial.PAPER.parseItem())
|
||||
.plugin(SongodaCore.getInstance())
|
||||
.plugin(CraftaroCore.getInstance())
|
||||
.onComplete((player, text) -> {
|
||||
loot.setChildDropCountMin(Integer.parseInt(text));
|
||||
return AnvilGUI.Response.close();
|
||||
|
@ -193,7 +193,7 @@ public class GuiLootEditor {
|
|||
new AnvilGUI.Builder()
|
||||
.title("Enter a number")
|
||||
.itemLeft(XMaterial.PAPER.parseItem())
|
||||
.plugin(SongodaCore.getInstance())
|
||||
.plugin(CraftaroCore.getInstance())
|
||||
.onComplete((player, text) -> {
|
||||
loot.setChildDropCountMax(Integer.parseInt(text));
|
||||
return AnvilGUI.Response.close();
|
||||
|
@ -219,7 +219,7 @@ public class GuiLootEditor {
|
|||
new AnvilGUI.Builder()
|
||||
.title("Enter a material")
|
||||
.itemLeft(XMaterial.PAPER.parseItem())
|
||||
.plugin(SongodaCore.getInstance())
|
||||
.plugin(CraftaroCore.getInstance())
|
||||
.onComplete((player, text) -> {
|
||||
Optional<XMaterial> material = XMaterial.matchXMaterial(text.trim().toUpperCase());
|
||||
if (material.isPresent()) {
|
|
@ -1,11 +1,11 @@
|
|||
package com.songoda.core.lootables.gui;
|
||||
package com.craftaro.core.lootables.gui;
|
||||
|
||||
import com.craftaro.core.CraftaroCore;
|
||||
import com.craftaro.core.lootables.loot.Loot;
|
||||
import com.craftaro.core.lootables.loot.LootBuilder;
|
||||
import com.craftaro.core.lootables.loot.LootManager;
|
||||
import com.craftaro.core.lootables.loot.Lootable;
|
||||
import com.cryptomorin.xseries.XMaterial;
|
||||
import com.songoda.core.SongodaCore;
|
||||
import com.songoda.core.lootables.loot.Loot;
|
||||
import com.songoda.core.lootables.loot.LootBuilder;
|
||||
import com.songoda.core.lootables.loot.LootManager;
|
||||
import com.songoda.core.lootables.loot.Lootable;
|
||||
import dev.triumphteam.gui.builder.item.ItemBuilder;
|
||||
import dev.triumphteam.gui.guis.Gui;
|
||||
import dev.triumphteam.gui.guis.PaginatedGui;
|
||||
|
@ -44,7 +44,7 @@ public class GuiLootableEditor {
|
|||
new AnvilGUI.Builder()
|
||||
.title("Enter a material")
|
||||
.itemLeft(XMaterial.PAPER.parseItem())
|
||||
.plugin(SongodaCore.getInstance())
|
||||
.plugin(CraftaroCore.getInstance())
|
||||
.onComplete((player, text) -> {
|
||||
Optional<XMaterial> material = XMaterial.matchXMaterial(text.trim().toUpperCase());
|
||||
if (material.isPresent()) {
|
|
@ -1,6 +1,6 @@
|
|||
package com.songoda.core.lootables.gui;
|
||||
package com.craftaro.core.lootables.gui;
|
||||
|
||||
import com.songoda.core.lootables.loot.Loot;
|
||||
import com.craftaro.core.lootables.loot.Loot;
|
||||
import dev.triumphteam.gui.guis.Gui;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.entity.Player;
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.lootables.loot;
|
||||
package com.craftaro.core.lootables.loot;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.lootables.loot;
|
||||
package com.craftaro.core.lootables.loot;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.LivingEntity;
|
|
@ -1,8 +1,8 @@
|
|||
package com.songoda.core.lootables.loot;
|
||||
package com.craftaro.core.lootables.loot;
|
||||
|
||||
import com.cryptomorin.xseries.XMaterial;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.songoda.core.utils.ItemUtils;
|
||||
import com.craftaro.core.utils.ItemUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.enchantments.Enchantment;
|
|
@ -1,7 +1,7 @@
|
|||
package com.songoda.core.lootables.loot;
|
||||
package com.craftaro.core.lootables.loot;
|
||||
|
||||
import com.craftaro.core.lootables.loot.objects.EnchantChance;
|
||||
import com.cryptomorin.xseries.XMaterial;
|
||||
import com.songoda.core.lootables.loot.objects.EnchantChance;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.util.Arrays;
|
|
@ -1,11 +1,11 @@
|
|||
package com.songoda.core.lootables.loot;
|
||||
package com.craftaro.core.lootables.loot;
|
||||
|
||||
import com.cryptomorin.xseries.XMaterial;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.songoda.core.lootables.Lootables;
|
||||
import com.songoda.core.lootables.Modify;
|
||||
import com.craftaro.core.lootables.Lootables;
|
||||
import com.craftaro.core.lootables.Modify;
|
||||
import dev.triumphteam.gui.builder.item.ItemBuilder;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.lootables.loot;
|
||||
package com.craftaro.core.lootables.loot;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.lootables.loot.objects;
|
||||
package com.craftaro.core.lootables.loot.objects;
|
||||
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.math;
|
||||
package com.craftaro.core.math;
|
||||
|
||||
public class Eval {
|
||||
private int pos = -1, ch;
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.math;
|
||||
package com.craftaro.core.math;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -7,7 +7,7 @@ public class MathUtils {
|
|||
private static final Map<String, Double> cache = new HashMap<>();
|
||||
|
||||
public static double eval(String toParse) {
|
||||
return eval(toParse, "SongodaCore Eval Engine");
|
||||
return eval(toParse, "Craftaro Eval Engine");
|
||||
}
|
||||
|
||||
public static double eval(String toParse, String warningMessage) {
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.placeholder;
|
||||
package com.craftaro.core.placeholder;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.placeholder;
|
||||
package com.craftaro.core.placeholder;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.placeholder;
|
||||
package com.craftaro.core.placeholder;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.entity.Player;
|
|
@ -1,11 +1,11 @@
|
|||
package com.songoda.core.plugins;
|
||||
package com.craftaro.core.plugins;
|
||||
|
||||
import com.cryptomorin.xseries.XMaterial;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class PluginInfo {
|
||||
protected final JavaPlugin javaPlugin;
|
||||
protected final int songodaId;
|
||||
protected final int craftaroId;
|
||||
protected final XMaterial iconMaterial;
|
||||
|
||||
private boolean hasUpdate = false;
|
||||
|
@ -14,9 +14,9 @@ public final class PluginInfo {
|
|||
private String changeLog;
|
||||
private String marketplaceLink;
|
||||
|
||||
public PluginInfo(JavaPlugin javaPlugin, int songodaId, String icon) {
|
||||
public PluginInfo(JavaPlugin javaPlugin, int craftaroId, String icon) {
|
||||
this.javaPlugin = javaPlugin;
|
||||
this.songodaId = songodaId;
|
||||
this.craftaroId = craftaroId;
|
||||
this.iconMaterial = XMaterial.matchXMaterial(icon).orElse(XMaterial.PAPER);
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ public final class PluginInfo {
|
|||
return javaPlugin;
|
||||
}
|
||||
|
||||
public int getSongodaId() {
|
||||
return songodaId;
|
||||
public int getCraftaroId() {
|
||||
return craftaroId;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.utils;
|
||||
package com.craftaro.core.utils;
|
||||
|
||||
import com.cryptomorin.xseries.XBlock;
|
||||
import com.cryptomorin.xseries.XMaterial;
|
|
@ -1,9 +1,9 @@
|
|||
package com.songoda.core.utils;
|
||||
package com.craftaro.core.utils;
|
||||
|
||||
import com.songoda.core.SongodaCore;
|
||||
import com.songoda.core.compatibility.ClassMapping;
|
||||
import com.songoda.core.compatibility.MethodMapping;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import com.craftaro.core.CraftaroCore;
|
||||
import com.craftaro.core.compatibility.ClassMapping;
|
||||
import com.craftaro.core.compatibility.MethodMapping;
|
||||
import com.craftaro.core.compatibility.ServerVersion;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
|
@ -149,7 +149,7 @@ public class BlockUtilsModern {
|
|||
} else if (clazzPressurePlateBlock.isAssignableFrom(mblock.getClass())) {
|
||||
nmsPlate_updateNeighbours.invoke(mblock, mworld, mpos);
|
||||
} else {
|
||||
SongodaCore.getInstance().getLogger().warning("Unknown redstone: " + mblock.getClass().getName());
|
||||
CraftaroCore.getInstance().getLogger().warning("Unknown redstone: " + mblock.getClass().getName());
|
||||
}
|
||||
//
|
||||
// if(mblock instanceof net.minecraft.server.v1_15_R1.BlockLever) {
|
|
@ -1,18 +1,14 @@
|
|||
package com.songoda.core.utils;
|
||||
package com.craftaro.core.utils;
|
||||
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ColorUtils {
|
|
@ -1,7 +1,7 @@
|
|||
package com.songoda.core.utils;
|
||||
package com.craftaro.core.utils;
|
||||
|
||||
import com.craftaro.core.compatibility.ClassMapping;
|
||||
import com.cryptomorin.xseries.XMaterial;
|
||||
import com.songoda.core.compatibility.ClassMapping;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.utils;
|
||||
package com.craftaro.core.utils;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.io.BukkitObjectInputStream;
|
|
@ -1,10 +1,14 @@
|
|||
package com.songoda.core.utils;
|
||||
package com.craftaro.core.utils;
|
||||
|
||||
import com.craftaro.core.compatibility.ClassMapping;
|
||||
import com.craftaro.core.compatibility.CompatibleHand;
|
||||
import com.craftaro.core.compatibility.MethodMapping;
|
||||
import com.craftaro.core.compatibility.ServerVersion;
|
||||
import com.cryptomorin.xseries.XMaterial;
|
||||
import com.cryptomorin.xseries.XTag;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.songoda.core.compatibility.*;
|
||||
import com.craftaro.core.compatibility.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.utils;
|
||||
package com.craftaro.core.utils;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package com.songoda.core.utils;
|
||||
package com.craftaro.core.utils;
|
||||
|
||||
import com.songoda.core.compatibility.ClassMapping;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import com.craftaro.core.compatibility.ClassMapping;
|
||||
import com.craftaro.core.compatibility.ServerVersion;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.utils;
|
||||
package com.craftaro.core.utils;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.utils;
|
||||
package com.craftaro.core.utils;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.utils;
|
||||
package com.craftaro.core.utils;
|
||||
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.utils;
|
||||
package com.craftaro.core.utils;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
|
@ -0,0 +1,123 @@
|
|||
package com.craftaro.core.world;
|
||||
|
||||
import com.craftaro.core.CraftaroCore;
|
||||
import com.craftaro.core.compatibility.CompatibleHand;
|
||||
import com.craftaro.core.compatibility.ServerVersion;
|
||||
import com.cryptomorin.xseries.XSound;
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerItemBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class SItemStack {
|
||||
protected final com.craftaro.core.nms.world.SItemStack sItem;
|
||||
protected final ItemStack item;
|
||||
|
||||
public SItemStack(ItemStack item) {
|
||||
this.item = item;
|
||||
this.sItem = CraftaroCore.getInstance().getNMSGetter().getWorld().getItemStack(item);
|
||||
}
|
||||
|
||||
public SItemStack(Player player, CompatibleHand hand) {
|
||||
this.item = hand.getItem(player);
|
||||
this.sItem = CraftaroCore.getInstance().getNMSGetter().getWorld().getItemStack(item);
|
||||
}
|
||||
|
||||
public ItemStack addDamage(Player player, int damage) {
|
||||
return addDamage(player, damage, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Damage the selected item
|
||||
*
|
||||
* @param player the player whose item you want to damage
|
||||
* @param damage the amount of damage to apply to the item
|
||||
*/
|
||||
public ItemStack addDamage(Player player, int damage, boolean respectVanillaUnbreakingEnchantments) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (item.getItemMeta() == null) {
|
||||
return item;
|
||||
}
|
||||
|
||||
int maxDurability = item.getType().getMaxDurability();
|
||||
int durability;
|
||||
|
||||
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_11)
|
||||
? new NBTItem(item).hasKey("Unbreakable")
|
||||
: item.getItemMeta().isUnbreakable()) {
|
||||
return item;
|
||||
} else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
|
||||
// ItemStack.setDurability(short) still works in 1.13-1.14, but use these methods now
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta instanceof Damageable) {
|
||||
Damageable damageable = ((Damageable) meta);
|
||||
|
||||
if (respectVanillaUnbreakingEnchantments) {
|
||||
damage = shouldApplyDamage(meta.getEnchantLevel(Enchantment.DURABILITY), damage);
|
||||
}
|
||||
|
||||
damageable.setDamage(((Damageable) meta).getDamage() + damage);
|
||||
item.setItemMeta(meta);
|
||||
durability = damageable.getDamage();
|
||||
} else {
|
||||
return item;
|
||||
}
|
||||
} else {
|
||||
if (respectVanillaUnbreakingEnchantments) {
|
||||
damage = shouldApplyDamage(item.getEnchantmentLevel(Enchantment.DURABILITY), damage);
|
||||
}
|
||||
|
||||
item.setDurability((short) Math.max(0, item.getDurability() + damage));
|
||||
durability = item.getDurability();
|
||||
}
|
||||
|
||||
if (durability >= maxDurability && player != null) {
|
||||
destroy(player);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
public void destroy(Player player) {
|
||||
destroy(player, 1);
|
||||
}
|
||||
|
||||
public void destroy(Player player, int amount) {
|
||||
PlayerItemBreakEvent breakEvent = new PlayerItemBreakEvent(player, item);
|
||||
Bukkit.getServer().getPluginManager().callEvent(breakEvent);
|
||||
|
||||
sItem.breakItem(player, amount);
|
||||
XSound.ENTITY_ITEM_BREAK.play(player);
|
||||
}
|
||||
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
private static int shouldApplyDamage(int unbreakingEnchantLevel, int damageAmount) {
|
||||
int result = 0;
|
||||
|
||||
for (int i = 0; i < damageAmount; ++i) {
|
||||
if (shouldApplyDamage(unbreakingEnchantLevel)) {
|
||||
++result;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static boolean shouldApplyDamage(int unbreakingEnchantLevel) {
|
||||
if (unbreakingEnchantLevel <= 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return Math.random() <= 1.0 / (unbreakingEnchantLevel + 1);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package com.craftaro.core.world;
|
||||
|
||||
import com.craftaro.core.CraftaroCore;
|
||||
import com.craftaro.core.utils.EntityUtils;
|
||||
import com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.nms.world.SpawnedEntity;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class SSpawner {
|
||||
protected final com.craftaro.core.nms.world.SSpawner sSpawner;
|
||||
protected final Location location;
|
||||
|
||||
public SSpawner(Location location) {
|
||||
this.location = location;
|
||||
this.sSpawner = CraftaroCore.getInstance().getNMSGetter().getWorld().getSpawner(location);
|
||||
}
|
||||
|
||||
public SSpawner(CreatureSpawner spawner) {
|
||||
this(spawner.getLocation());
|
||||
}
|
||||
|
||||
public int spawn(int amountToSpawn, EntityType... types) {
|
||||
return spawn(amountToSpawn, "EXPLOSION_NORMAL", null, null, types);
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawn the spawner.
|
||||
* <p>
|
||||
* If you want support for stackers you will need to load them
|
||||
* on your plugins enable.
|
||||
*
|
||||
* @return amount of entities spawned
|
||||
*/
|
||||
public int spawn(int amountToSpawn, String particle, Set<XMaterial> canSpawnOn, SpawnedEntity spawned,
|
||||
EntityType... types) {
|
||||
if (location.getWorld() == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (canSpawnOn == null) {
|
||||
canSpawnOn = new HashSet<>();
|
||||
}
|
||||
|
||||
if (canSpawnOn.isEmpty()) {
|
||||
canSpawnOn.addAll(EntityUtils.getSpawnBlocks(types[0]));
|
||||
}
|
||||
|
||||
// TODO: Add stacker plugin support. Refer to CraftaroCore v2.
|
||||
|
||||
int spawnCountUsed = amountToSpawn;
|
||||
|
||||
int amountSpawned = 0;
|
||||
while (spawnCountUsed-- > 0) {
|
||||
EntityType type = types[ThreadLocalRandom.current().nextInt(types.length)];
|
||||
LivingEntity entity = sSpawner.spawnEntity(type, particle, spawned, canSpawnOn);
|
||||
if (entity != null) {
|
||||
amountSpawned++;
|
||||
}
|
||||
}
|
||||
|
||||
return amountSpawned;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.craftaro.core.world;
|
||||
|
||||
import com.craftaro.core.CraftaroCore;
|
||||
import com.craftaro.core.compatibility.ServerVersion;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SWorld {
|
||||
protected final com.craftaro.core.nms.world.SWorld sWorld;
|
||||
protected final World world;
|
||||
|
||||
public SWorld(World world) {
|
||||
this.world = world;
|
||||
this.sWorld = CraftaroCore.getInstance().getNMSGetter().getWorld().getWorld(world);
|
||||
}
|
||||
|
||||
public Entity[] getEntitiesFromChunk(int x, int z) {
|
||||
Location location = new Location(null, 0.0D, 0.0D, 0.0D);
|
||||
|
||||
return getLivingEntities().stream().filter((entity) -> {
|
||||
entity.getLocation(location);
|
||||
return location.getBlockX() >> 4 == x && location.getBlockZ() >> 4 == z;
|
||||
}).toArray(Entity[]::new);
|
||||
}
|
||||
|
||||
public List<LivingEntity> getLivingEntities() {
|
||||
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_17)) {
|
||||
return world.getLivingEntities();
|
||||
}
|
||||
|
||||
return sWorld.getLivingEntities();
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package com.songoda.core;
|
||||
|
||||
import com.songoda.core.builtin.SongodaCoreCommand;
|
||||
import com.songoda.core.plugins.PluginInfo;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import revxrsal.commands.bukkit.BukkitCommandHandler;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class SongodaCore extends JavaPlugin {
|
||||
|
||||
private static SongodaCore instance;
|
||||
public static SongodaCore getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private final Set<PluginInfo> registeredPlugins = new HashSet<>();
|
||||
|
||||
private BukkitCommandHandler commandManager;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
|
||||
this.commandManager = BukkitCommandHandler.create(this);
|
||||
commandManager.register(new SongodaCoreCommand(this));
|
||||
}
|
||||
|
||||
public void registerPlugin(SongodaPlugin plugin, int pluginId, String icon) {
|
||||
plugin.getLogger().info("Hooked into " + plugin.getName() + ".");
|
||||
PluginInfo info = new PluginInfo(plugin, pluginId, icon);
|
||||
registeredPlugins.add(info);
|
||||
|
||||
// TODO: add an update checker
|
||||
}
|
||||
|
||||
public Set<PluginInfo> getRegisteredPlugins() {
|
||||
return Collections.unmodifiableSet(registeredPlugins);
|
||||
}
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
package com.songoda.core.compatibility;
|
||||
|
||||
import com.songoda.core.SongodaCore;
|
||||
import com.songoda.core.locale.TextPlaceholder;
|
||||
import com.songoda.core.utils.ColorUtils;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CompatibleText {
|
||||
|
||||
private final String text;
|
||||
|
||||
public CompatibleText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public static CompatibleText of(String text) {
|
||||
return new CompatibleText(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate the legacy color codes in the text
|
||||
* @return The text with color codes translated
|
||||
*/
|
||||
public String legacy() {
|
||||
return ChatColor.translateAlternateColorCodes('&', text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace internal placeholders in the text
|
||||
* @param placeholders The internal placeholders to replace
|
||||
* @return The text with placeholders replaced
|
||||
*/
|
||||
public String legacy(TextPlaceholder... placeholders) {
|
||||
String replaced = text;
|
||||
for (TextPlaceholder placeholder : placeholders) {
|
||||
replaced = replaced.replace("<"+placeholder.getPlaceholder()+">", placeholder.getReplacement());
|
||||
}
|
||||
return ColorUtils.format(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace internal and PlaceholderAPI placeholders in the text
|
||||
* @param player The player to replace placeholders for (PlaceholderAPI)
|
||||
* @param placeholders The internal placeholders to replace
|
||||
* @return The text with placeholders replaced
|
||||
*/
|
||||
public String legacy(Player player, TextPlaceholder... placeholders) {
|
||||
String replaced = text;
|
||||
for (TextPlaceholder placeholder : placeholders) {
|
||||
replaced = replaced.replace("<"+placeholder.getPlaceholder()+">", placeholder.getReplacement());
|
||||
}
|
||||
return ColorUtils.parse(player, text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the text to a component
|
||||
* @return The component
|
||||
*/
|
||||
public Component component() {
|
||||
return ColorUtils.formatComponent(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the text to a component and replace internal placeholders
|
||||
* @param placeholders The internal placeholders to replace
|
||||
* @return The component with placeholders replaced
|
||||
*/
|
||||
public Component component(TextPlaceholder... placeholders) {
|
||||
Component component = ColorUtils.formatComponent(text);
|
||||
for (TextPlaceholder placeholder : placeholders) {
|
||||
component = component.replaceText(text -> text.matchLiteral("<"+placeholder.getPlaceholder()+">").replacement(placeholder.getReplacement()));
|
||||
}
|
||||
return component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the text to a component and replace internal and PlaceholderAPI placeholders
|
||||
* @param player The player to replace placeholders for (PlaceholderAPI)
|
||||
* @param placeholders The internal placeholders to replace
|
||||
* @return The component with placeholders replaced
|
||||
*/
|
||||
public Component component(Player player, TextPlaceholder... placeholders) {
|
||||
Component component = ColorUtils.parseComponent(player, text);
|
||||
for (TextPlaceholder placeholder : placeholders) {
|
||||
component = component.replaceText(text -> text.matchLiteral("<"+placeholder.getPlaceholder()+">").replacement(placeholder.getReplacement()));
|
||||
}
|
||||
return component;
|
||||
}
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
package com.songoda.core.compatibility;
|
||||
|
||||
import com.songoda.core.locale.TextPlaceholder;
|
||||
import com.songoda.core.utils.ColorUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CompatibleTextList {
|
||||
|
||||
private List<String> textList;
|
||||
|
||||
public CompatibleTextList(List<String> textList) {
|
||||
this.textList = textList;
|
||||
}
|
||||
|
||||
public static CompatibleTextList of(String... text) {
|
||||
return new CompatibleTextList(Arrays.asList(text));
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate the legacy color codes in the text list
|
||||
* @return The text list with color codes translated
|
||||
*/
|
||||
public List<String> legacy() {
|
||||
return ColorUtils.format(textList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace internal placeholders in the text list
|
||||
* @param placeholders The internal placeholders to replace
|
||||
* @return The text list with placeholders replaced
|
||||
*/
|
||||
public List<String> legacy(TextPlaceholder... placeholders) {
|
||||
List<String> replaced = ColorUtils.format(textList);
|
||||
for (TextPlaceholder placeholder : placeholders) {
|
||||
replaced.replaceAll(s -> s.replace("<"+placeholder.getPlaceholder()+">", placeholder.getReplacement()));
|
||||
}
|
||||
return replaced;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace internal and PlaceholderAPI placeholders in the text list
|
||||
* @param player The player to replace placeholders for (PlaceholderAPI)
|
||||
* @param placeholders The internal placeholders to replace
|
||||
* @return The text list with placeholders replaced
|
||||
*/
|
||||
public List<String> legacy(Player player, TextPlaceholder... placeholders) {
|
||||
List<String> replaced = textList;
|
||||
for (TextPlaceholder placeholder : placeholders) {
|
||||
replaced.replaceAll(s -> s.replace("<"+placeholder.getPlaceholder()+">", placeholder.getReplacement()));
|
||||
}
|
||||
return ColorUtils.parse(player, replaced);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the text list to a component list
|
||||
* @return The component list
|
||||
*/
|
||||
public List<Component> component() {
|
||||
List<Component> result = new ArrayList<>();
|
||||
for (String text : textList) {
|
||||
result.add(ColorUtils.formatComponent(text));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the text list to a component list and replace internal placeholders
|
||||
* @param placeholders The internal placeholders to replace
|
||||
* @return The component list with placeholders replaced
|
||||
*/
|
||||
public List<Component> component(TextPlaceholder... placeholders) {
|
||||
List<Component> replaced = ColorUtils.formatComponent(textList);
|
||||
Arrays.stream(placeholders).forEach(placeholder -> replaced.replaceAll(component -> component.replaceText(text -> text.matchLiteral("<"+placeholder.getPlaceholder()+">").replacement(placeholder.getReplacement()))));
|
||||
return replaced;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the text list to a component list and replace internal and PlaceholderAPI placeholders
|
||||
* @param player The player to replace placeholders for (PlaceholderAPI)
|
||||
* @param placeholders The internal placeholders to replace
|
||||
* @return The component list with placeholders replaced
|
||||
*/
|
||||
public List<Component> component(Player player, TextPlaceholder... placeholders) {
|
||||
List<Component> replaced = ColorUtils.parseComponent(player, textList);
|
||||
Arrays.stream(placeholders).forEach(placeholder -> replaced.replaceAll(component -> component.replaceText(text -> text.matchLiteral("<"+placeholder.getPlaceholder()+">").replacement(placeholder.getReplacement()))));
|
||||
return replaced;
|
||||
}
|
||||
}
|
|
@ -1,118 +0,0 @@
|
|||
package com.songoda.core.gui;
|
||||
|
||||
import com.songoda.core.SongodaPlugin;
|
||||
import com.songoda.core.configuration.Config;
|
||||
import dev.triumphteam.gui.builder.item.ItemBuilder;
|
||||
import dev.triumphteam.gui.guis.Gui;
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.simpleyaml.configuration.ConfigurationSection;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class CustomizableInventory {
|
||||
|
||||
protected final SongodaPlugin plugin;
|
||||
protected final Player player;
|
||||
private final String key;
|
||||
private final Config config;
|
||||
protected final Gui gui;
|
||||
|
||||
public CustomizableInventory(SongodaPlugin plugin, Player player, String key) {
|
||||
this.plugin = plugin;
|
||||
this.player = player;
|
||||
this.key = key;
|
||||
|
||||
this.config = plugin.createUpdatingConfig(new File(plugin.getDataFolder() + File.separator + "inventories", key + ".yml"));
|
||||
|
||||
this.gui = Gui.gui()
|
||||
.rows(config.getInt("settings.rows"))
|
||||
.disableAllInteractions()
|
||||
.title(MiniMessage.miniMessage().deserialize(config.getString("settings.title")))
|
||||
.create();
|
||||
}
|
||||
|
||||
public void open() {
|
||||
gui.getGuiItems().clear();
|
||||
|
||||
fill(player);
|
||||
fillWithCustom(player);
|
||||
|
||||
gui.open(player);
|
||||
}
|
||||
|
||||
protected abstract void fill(Player player);
|
||||
|
||||
private void fillWithCustom(Player player) {
|
||||
if (!config.isConfigurationSection("customItems")) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (String key : config.getConfigurationSection("customItems").getKeys(false)) {
|
||||
ConfigurationSection section = config.getConfigurationSection("customItems." + key);
|
||||
List<String> actions = section.getStringList("actions");
|
||||
int slot = section.getInt("slot");
|
||||
|
||||
gui.setItem(slot, getItem("customItems." + key, Collections.emptyMap(), event -> plugin.getActionManager().executeActions(player, actions)));
|
||||
}
|
||||
}
|
||||
|
||||
protected int getSlot(String route) {
|
||||
ConfigurationSection section = config.getConfigurationSection(route);
|
||||
return section.getInt("slot");
|
||||
}
|
||||
|
||||
protected GuiItem getItem(String route, Map<String, String> placeholders, Consumer<InventoryClickEvent> consumer) {
|
||||
ConfigurationSection section = config.getConfigurationSection(route);
|
||||
|
||||
Material material = Material.getMaterial(section.getString("material"));
|
||||
Component name = MiniMessage.miniMessage().deserialize(plugin.getPlaceholderResolver().setPlaceholders(player, section.getString("name")))
|
||||
.applyFallbackStyle(TextDecoration.ITALIC.withState(false));
|
||||
for (Map.Entry<String, String> entry : placeholders.entrySet()) {
|
||||
name = name.replaceText(text -> text.matchLiteral(entry.getKey()).replacement(entry.getValue()));
|
||||
}
|
||||
|
||||
List<Component> lore = section.getStringList("lore")
|
||||
.stream()
|
||||
.map(text -> MiniMessage.miniMessage().deserialize(plugin.getPlaceholderResolver().setPlaceholders(player, text))
|
||||
.applyFallbackStyle(TextDecoration.ITALIC.withState(false)))
|
||||
.collect(Collectors.toList());
|
||||
lore.replaceAll(component -> {
|
||||
for (Map.Entry<String, String> entry : placeholders.entrySet()) {
|
||||
component = component.replaceText(text -> text.matchLiteral(entry.getKey()).replacement(entry.getValue()));
|
||||
}
|
||||
return component;
|
||||
});
|
||||
|
||||
String texture = section.getString("texture");
|
||||
|
||||
return ItemBuilder.from(material).name(name).lore(lore).setSkullTexture(texture).asGuiItem(consumer::accept);
|
||||
}
|
||||
|
||||
|
||||
protected void setItem(String itemKey, Map<String, String> placeholders) {
|
||||
setItem(itemKey, placeholders, event -> {});
|
||||
}
|
||||
|
||||
protected void setItem(String itemKey) {
|
||||
setItem(itemKey, event -> {});
|
||||
}
|
||||
|
||||
protected void setItem(String itemKey, Consumer<InventoryClickEvent> consumer) {
|
||||
setItem(itemKey, Collections.emptyMap(), consumer);
|
||||
}
|
||||
|
||||
protected void setItem(String itemKey, Map<String, String> placeholders, Consumer<InventoryClickEvent> consumer) {
|
||||
gui.setItem(getSlot("items." + itemKey), getItem("items." + itemKey, placeholders, consumer));
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package com.songoda.core.locale;
|
||||
|
||||
import com.songoda.core.SongodaPlugin;
|
||||
import com.songoda.core.configuration.Config;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class LocaleManager {
|
||||
|
||||
private final SongodaPlugin plugin;
|
||||
private final Config langFile;
|
||||
|
||||
public LocaleManager(SongodaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.langFile = plugin.createUpdatingConfig(new File(plugin.getDataFolder(), "lang.yml"));
|
||||
}
|
||||
|
||||
public Message getMessage(String path) {
|
||||
return new Message(plugin.getAdventure(), MiniMessage.miniMessage().deserialize(langFile.getString(path)));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
package com.songoda.core.locale;
|
||||
|
||||
public class TextPlaceholder {
|
||||
|
||||
private final String placeholder;
|
||||
private final String replacement;
|
||||
|
||||
public TextPlaceholder(String placeholder, String replacement) {
|
||||
this.placeholder = placeholder;
|
||||
this.replacement = replacement;
|
||||
}
|
||||
|
||||
public String getPlaceholder() {
|
||||
return placeholder;
|
||||
}
|
||||
|
||||
public String getReplacement() {
|
||||
return replacement;
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package com.songoda.core.lootables;
|
||||
|
||||
import com.songoda.core.lootables.loot.Loot;
|
||||
|
||||
public interface Modify {
|
||||
Loot Modify(Loot loot);
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
## This sets the default economy hook. Available plugins:
|
||||
## - Vault
|
||||
Default Economy Hook: Vault
|
||||
|
||||
## This sets the default hologram hook. Available plugins:
|
||||
## - HolographicDisplays
|
||||
## - DecentHolograms
|
||||
Default Hologram Hook: HolographicDisplays
|
||||
|
||||
## This sets the enabled protection hook. Available plugins:
|
||||
## - WorldGuard
|
||||
## - BentoBox
|
||||
## - GriefPrevention
|
||||
Enabled Protection Hooks:
|
||||
- WorldGuard
|
|
@ -1,5 +1,5 @@
|
|||
name: SongodaCore
|
||||
author: Songoda
|
||||
main: com.songoda.core.SongodaCore
|
||||
name: CraftaroCore
|
||||
author: Craftaro
|
||||
main: com.craftaro.core.CraftaroCore
|
||||
version: ${project.version}
|
||||
api-version: 1.13
|
||||
api-version: 1.13
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>SongodaCore3</artifactId>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>CraftaroCore3</artifactId>
|
||||
<groupId>com.craftaro</groupId>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>songodacore-hooks</artifactId>
|
||||
<artifactId>craftarocore-hooks</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
|
@ -18,13 +18,6 @@
|
|||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.19.3-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Economy Hooks -->
|
||||
<dependency>
|
||||
<groupId>com.github.MilkBowl</groupId>
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.hooks;
|
||||
package com.craftaro.core.hooks;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
@ -10,7 +10,7 @@ import java.util.Map;
|
|||
public abstract class HookManager<T extends PluginHook> {
|
||||
|
||||
protected final Plugin plugin;
|
||||
private final Map<String, T> registeredHooks = new HashMap<>();
|
||||
protected final Map<String, T> registeredHooks = new HashMap<>();
|
||||
|
||||
public HookManager(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
@ -18,15 +18,23 @@ public abstract class HookManager<T extends PluginHook> {
|
|||
}
|
||||
|
||||
public T getHookByName(String name) {
|
||||
return registeredHooks.get(name);
|
||||
if (registeredHooks.containsKey(name)) {
|
||||
return registeredHooks.get(name);
|
||||
}
|
||||
|
||||
return getDummyHook();
|
||||
}
|
||||
|
||||
public Collection<T> getAllHooks() {
|
||||
return registeredHooks.values();
|
||||
}
|
||||
|
||||
public void registerHook(T hook) {
|
||||
registerHook(null, hook);
|
||||
}
|
||||
|
||||
public void registerHook(String requiredPlugin, T hook) {
|
||||
if (!Bukkit.getPluginManager().isPluginEnabled(requiredPlugin)) {
|
||||
if (requiredPlugin != null && !Bukkit.getPluginManager().isPluginEnabled(requiredPlugin)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -38,4 +46,5 @@ public abstract class HookManager<T extends PluginHook> {
|
|||
}
|
||||
|
||||
protected abstract void registerDefaultHooks();
|
||||
protected abstract T getDummyHook();
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.songoda.core.hooks;
|
||||
package com.craftaro.core.hooks;
|
||||
|
||||
public interface PluginHook {
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package com.craftaro.core.hooks.economy;
|
||||
|
||||
import com.craftaro.core.hooks.HookManager;
|
||||
import com.craftaro.core.hooks.economy.impl.DummyEconomyImplementation;
|
||||
import com.craftaro.core.hooks.economy.impl.VaultImplementation;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class EconomyManager extends HookManager<IEconomy> {
|
||||
|
||||
public EconomyManager(Plugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerDefaultHooks() {
|
||||
registerHook("Vault", new VaultImplementation());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IEconomy getDummyHook() {
|
||||
return new DummyEconomyImplementation();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package com.songoda.core.hooks.economy;
|
||||
package com.craftaro.core.hooks.economy;
|
||||
|
||||
import com.songoda.core.hooks.PluginHook;
|
||||
import com.craftaro.core.hooks.PluginHook;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
public interface IEconomy extends PluginHook {
|
|
@ -0,0 +1,36 @@
|
|||
package com.craftaro.core.hooks.economy.impl;
|
||||
|
||||
import com.craftaro.core.hooks.economy.IEconomy;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
public class DummyEconomyImplementation implements IEconomy {
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return "None";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enableHook() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBalance(OfflinePlayer player) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBalance(OfflinePlayer player, double amount) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean withdrawBalance(OfflinePlayer player, double amount) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean depositBalance(OfflinePlayer player, double amount) {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package com.songoda.core.hooks.economy.impl;
|
||||
package com.craftaro.core.hooks.economy.impl;
|
||||
|
||||
import com.songoda.core.hooks.economy.IEconomy;
|
||||
import com.craftaro.core.hooks.economy.IEconomy;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue