mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-11-23 18:45:34 +01:00
Merge branch 'development' into 'master'
2.1.6 See merge request Songoda/songodaupdater!13
This commit is contained in:
commit
21b3f653e5
2
.gitignore
vendored
2
.gitignore
vendored
@ -9,3 +9,5 @@ release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
nbactions.xml
|
||||
nb-configuration.xml
|
||||
|
@ -4,7 +4,7 @@ stages:
|
||||
variables:
|
||||
name: "SongodaCore"
|
||||
path: "/builds/$CI_PROJECT_PATH"
|
||||
version: "2.0.10"
|
||||
version: "2.1.6"
|
||||
|
||||
build:
|
||||
stage: build
|
||||
@ -12,9 +12,10 @@ build:
|
||||
script:
|
||||
- find $path/ -type f -name "*.xml" -print0 | xargs -0 sed -i -e s/maven-version-number/$version/g
|
||||
- find $path/ -type f -name "*.yml" -print0 | xargs -0 sed -i -e s/maven-version-number/$version/g
|
||||
- find $path/ -type f -name "*SongodaCore.java" -print0 | xargs -0 sed -i -e s/maven-version-number/$version/g
|
||||
- mvn clean package
|
||||
- find $path/ -depth -path '*original*' -delete
|
||||
- mv $path/target/*.jar $path/
|
||||
- mv $path/Core/target/*.jar $path/
|
||||
artifacts:
|
||||
name: $name-$version
|
||||
paths:
|
||||
|
300
Core/pom.xml
Normal file
300
Core/pom.xml
Normal file
@ -0,0 +1,300 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0">
|
||||
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>maven-version-number</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore</artifactId>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<finalName>SongodaCore-${project.version}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>shaded</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<shadedArtifactAttached>false</shadedArtifactAttached>
|
||||
<createDependencyReducedPom>true</createDependencyReducedPom>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>com.songoda:*</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<includes>
|
||||
<include>com/</include>
|
||||
<include>META-INF/MANIFEST.MF</include>
|
||||
<include>META-INF/maven/com.songoda/SongodaCore/</include>
|
||||
</includes>
|
||||
</filter>
|
||||
</filters>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!--
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<configuration>
|
||||
<appendAssemblyId>false</appendAssemblyId>
|
||||
<descriptors>
|
||||
<descriptor>../assembly.xml</descriptor>
|
||||
</descriptors>
|
||||
<finalName>SongodaCore-${project.version}</finalName>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>-->
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.destroystokyo.papermc</groupId>
|
||||
<artifactId>paper</artifactId>
|
||||
<version>1.14.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.14.4</version>
|
||||
</dependency-->
|
||||
<!-- Need to include all NMS modules here -->
|
||||
<!-- Note when adding a new module: include the class in NmsManager -->
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-NMS-API</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-NMS-v1_8_R1</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-NMS-v1_8_R2</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-NMS-v1_8_R3</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-NMS-v1_9_R1</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-NMS-v1_9_R2</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-NMS-v1_10_R1</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-NMS-v1_11_R1</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-NMS-v1_12_R1</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-NMS-v1_13_R1</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-NMS-v1_13_R2</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>SongodaCore-NMS-v1_14_R1</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- End NMS -->
|
||||
<dependency>
|
||||
<groupId>com.gmail.filoghost.holographicdisplays</groupId>
|
||||
<artifactId>holographicdisplays-api</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sainttx.holograms</groupId>
|
||||
<artifactId>Holograms</artifactId>
|
||||
<version>2.9.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zrips</groupId>
|
||||
<artifactId>CMI</artifactId>
|
||||
<version>8.4.0.2_1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.tnemc</groupId>
|
||||
<artifactId>Reserve</artifactId>
|
||||
<version>0.1.3.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.black_ixx</groupId>
|
||||
<artifactId>PlayerPoints</artifactId>
|
||||
<version>2.1.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.milkbowl</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.7.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>us.myles.viaversion-bukkit</groupId>
|
||||
<artifactId>ViaVersion</artifactId>
|
||||
<version>2.1.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>protocolsupport</groupId>
|
||||
<artifactId>ProtocolSupport</artifactId>
|
||||
<version>4.29</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>13.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>1.25</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.25</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-nop</artifactId>
|
||||
<version>1.7.25</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
<version>3.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.xerial</groupId>
|
||||
<artifactId>sqlite-jdbc</artifactId>
|
||||
<version>3.23.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
<artifactId>worldguard-bukkit</artifactId>
|
||||
<version>7.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldedit</groupId>
|
||||
<artifactId>worldedit-bukkit</artifactId>
|
||||
<version>7.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>UltimateStacker</artifactId>
|
||||
<version>1.9.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.bgsoftware</groupId>
|
||||
<artifactId>WildStacker</artifactId>
|
||||
<version>2-9-0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>uk.antiperson</groupId>
|
||||
<artifactId>stackmob</artifactId>
|
||||
<version>4-0-2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -7,7 +7,7 @@ import com.songoda.core.core.SongodaCoreCommand;
|
||||
import com.songoda.core.core.SongodaCoreDiagCommand;
|
||||
import com.songoda.core.commands.CommandManager;
|
||||
import com.songoda.core.compatibility.ClientVersion;
|
||||
import com.songoda.core.compatibility.LegacyMaterials;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
@ -21,6 +21,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -46,7 +47,17 @@ public class SongodaCore {
|
||||
* Whenever we make a major change to the core GUI, updater,
|
||||
* or other function used by the core, increment this number
|
||||
*/
|
||||
private final static int coreRevision = 4;
|
||||
private final static int coreRevision = 6;
|
||||
|
||||
/**
|
||||
* This has been added as of Rev 6 <br>
|
||||
* This value is automatically filled in by gitlab-ci
|
||||
*/
|
||||
private final static String coreVersion = "maven-version-number";
|
||||
|
||||
/**
|
||||
* This is specific to the website api
|
||||
*/
|
||||
private final static int updaterVersion = 1;
|
||||
|
||||
private final static Set<PluginInfo> registeredPlugins = new HashSet<>();
|
||||
@ -62,11 +73,15 @@ public class SongodaCore {
|
||||
return !SongodaCore.class.getPackage().getName().equals(new String(new char[]{'c','o','m','.','s','o','n','g','o','d','a','.','c','o','r','e'}));
|
||||
}
|
||||
|
||||
public static void registerPlugin(JavaPlugin plugin, int pluginID, LegacyMaterials icon) {
|
||||
registerPlugin(plugin, pluginID, icon == null ? "STONE" : icon.name());
|
||||
public static void registerPlugin(JavaPlugin plugin, int pluginID, CompatibleMaterial icon) {
|
||||
registerPlugin(plugin, pluginID, icon == null ? "STONE" : icon.name(), coreVersion);
|
||||
}
|
||||
|
||||
public static void registerPlugin(JavaPlugin plugin, int pluginID, String icon) {
|
||||
registerPlugin(plugin, pluginID, icon, "?");
|
||||
}
|
||||
|
||||
public static void registerPlugin(JavaPlugin plugin, int pluginID, String icon, String coreVersion) {
|
||||
if(INSTANCE == null) {
|
||||
// First: are there any other instances of SongodaCore active?
|
||||
for (Class<?> clazz : Bukkit.getServicesManager().getKnownServices()) {
|
||||
@ -76,7 +91,8 @@ public class SongodaCore {
|
||||
int otherVersion = (int) clazz.getMethod("getCoreVersion").invoke(null);
|
||||
if(otherVersion >= getCoreVersion()) {
|
||||
// use the active service
|
||||
clazz.getMethod("registerPlugin", JavaPlugin.class, int.class, String.class).invoke(null, plugin, pluginID, icon);
|
||||
// assuming that the other is greater than R6 ;)
|
||||
clazz.getMethod("registerPlugin", JavaPlugin.class, int.class, String.class, String.class).invoke(null, plugin, pluginID, icon, coreVersion);
|
||||
|
||||
if(hasShading()) {
|
||||
(INSTANCE = new SongodaCore()).piggybackedPlugin = plugin;
|
||||
@ -95,7 +111,7 @@ public class SongodaCore {
|
||||
// register ourselves as the SongodaCore service!
|
||||
INSTANCE = new SongodaCore(plugin);
|
||||
INSTANCE.init();
|
||||
INSTANCE.register(plugin, pluginID, icon);
|
||||
INSTANCE.register(plugin, pluginID, icon, coreVersion);
|
||||
Bukkit.getServicesManager().register(SongodaCore.class, INSTANCE, plugin, ServicePriority.Normal);
|
||||
// we need (JavaPlugin plugin, int pluginID, String icon) for our object
|
||||
if(!otherPlugins.isEmpty()) {
|
||||
@ -104,25 +120,28 @@ public class SongodaCore {
|
||||
Method otherPluginInfo_getJavaPlugin = otherPluginInfo.getMethod("getJavaPlugin");
|
||||
Method otherPluginInfo_getSongodaId = otherPluginInfo.getMethod("getSongodaId");
|
||||
Method otherPluginInfo_getCoreIcon = otherPluginInfo.getMethod("getCoreIcon");
|
||||
Method otherPluginInfo_getCoreLibraryVersion = otherVersion >= 6 ? otherPluginInfo.getMethod("getCoreLibraryVersion") : null;
|
||||
for(Object other : otherPlugins) {
|
||||
INSTANCE.register(
|
||||
(JavaPlugin) otherPluginInfo_getJavaPlugin.invoke(other),
|
||||
(int) otherPluginInfo_getSongodaId.invoke(other),
|
||||
(String) otherPluginInfo_getCoreIcon.invoke(other));
|
||||
(String) otherPluginInfo_getCoreIcon.invoke(other),
|
||||
otherPluginInfo_getCoreLibraryVersion != null ? (String) otherPluginInfo_getCoreLibraryVersion.invoke(other) : "?");
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ignored) {
|
||||
plugin.getLogger().log(Level.WARNING, "Error registering core service", ignored);
|
||||
}
|
||||
}
|
||||
}
|
||||
// register ourselves as the SongodaCore service!
|
||||
INSTANCE = new SongodaCore(plugin);
|
||||
INSTANCE.init();
|
||||
INSTANCE.register(plugin, pluginID, icon);
|
||||
Bukkit.getServicesManager().register(SongodaCore.class, INSTANCE, plugin, ServicePriority.Normal);
|
||||
}
|
||||
INSTANCE.register(plugin, pluginID, icon, coreVersion);
|
||||
}
|
||||
|
||||
SongodaCore() {
|
||||
@ -154,9 +173,9 @@ public class SongodaCore {
|
||||
private void destroy() {
|
||||
Bukkit.getServicesManager().unregister(SongodaCore.class, INSTANCE);
|
||||
tasks.stream().filter(task -> task != null && !task.isCancelled())
|
||||
.forEach(task -> Bukkit.getScheduler().cancelTask(task.getTaskId()));
|
||||
.forEach(task -> Bukkit.getScheduler().cancelTask(task.getTaskId()));
|
||||
HandlerList.unregisterAll(loginListener);
|
||||
if(!hasShading()) {
|
||||
if (!hasShading()) {
|
||||
HandlerList.unregisterAll(shadingListener);
|
||||
}
|
||||
registeredPlugins.clear();
|
||||
@ -172,67 +191,71 @@ public class SongodaCore {
|
||||
PluginManager pm = Bukkit.getPluginManager();
|
||||
String p;
|
||||
if (!isRegistered(p = "EpicAnchors") && pm.isPluginEnabled(p)) {
|
||||
register((JavaPlugin) pm.getPlugin(p), 31, LegacyMaterials.END_PORTAL_FRAME.name());
|
||||
register((JavaPlugin) pm.getPlugin(p), 31, CompatibleMaterial.END_PORTAL_FRAME.name());
|
||||
}
|
||||
if (!isRegistered(p = "EpicBosses") && pm.isPluginEnabled(p)) {
|
||||
register((JavaPlugin) pm.getPlugin(p), 19, LegacyMaterials.ZOMBIE_SPAWN_EGG.name());
|
||||
register((JavaPlugin) pm.getPlugin(p), 19, CompatibleMaterial.ZOMBIE_SPAWN_EGG.name());
|
||||
}
|
||||
if (!isRegistered(p = "EpicEnchants") && pm.isPluginEnabled(p)) {
|
||||
register((JavaPlugin) pm.getPlugin(p), 67, LegacyMaterials.DIAMOND_SWORD.name());
|
||||
register((JavaPlugin) pm.getPlugin(p), 67, CompatibleMaterial.DIAMOND_SWORD.name());
|
||||
}
|
||||
if (!isRegistered(p = "EpicFarming") && pm.isPluginEnabled(p)) {
|
||||
register((JavaPlugin) pm.getPlugin(p), 21, LegacyMaterials.WHEAT.name());
|
||||
register((JavaPlugin) pm.getPlugin(p), 21, CompatibleMaterial.WHEAT.name());
|
||||
}
|
||||
if (!isRegistered(p = "EpicFurnaces") && pm.isPluginEnabled(p)) {
|
||||
register((JavaPlugin) pm.getPlugin(p), 22, LegacyMaterials.FURNACE.name());
|
||||
register((JavaPlugin) pm.getPlugin(p), 22, CompatibleMaterial.FURNACE.name());
|
||||
}
|
||||
if (!isRegistered(p = "EpicHeads") && pm.isPluginEnabled(p)) {
|
||||
register((JavaPlugin) pm.getPlugin(p), 26, LegacyMaterials.PLAYER_HEAD.name());
|
||||
register((JavaPlugin) pm.getPlugin(p), 26, CompatibleMaterial.PLAYER_HEAD.name());
|
||||
}
|
||||
if (!isRegistered(p = "EpicHoppers") && pm.isPluginEnabled(p)) {
|
||||
register((JavaPlugin) pm.getPlugin(p), 15, LegacyMaterials.HOPPER.name());
|
||||
register((JavaPlugin) pm.getPlugin(p), 15, CompatibleMaterial.HOPPER.name());
|
||||
}
|
||||
if (!isRegistered(p = "EpicLevels") && pm.isPluginEnabled(p)) {
|
||||
register((JavaPlugin) pm.getPlugin(p), 44, LegacyMaterials.NETHER_STAR.name());
|
||||
register((JavaPlugin) pm.getPlugin(p), 44, CompatibleMaterial.NETHER_STAR.name());
|
||||
}
|
||||
if (!isRegistered(p = "EpicSpawners") && pm.isPluginEnabled(p)) {
|
||||
register((JavaPlugin) pm.getPlugin(p), 13, LegacyMaterials.SPAWNER.name());
|
||||
register((JavaPlugin) pm.getPlugin(p), 13, CompatibleMaterial.SPAWNER.name());
|
||||
}
|
||||
if (!isRegistered(p = "EpicVouchers") && pm.isPluginEnabled(p)) {
|
||||
register((JavaPlugin) pm.getPlugin(p), 25, LegacyMaterials.EMERALD.name());
|
||||
register((JavaPlugin) pm.getPlugin(p), 25, CompatibleMaterial.EMERALD.name());
|
||||
}
|
||||
if (!isRegistered(p = "FabledSkyBlock") && pm.isPluginEnabled(p)) {
|
||||
register((JavaPlugin) pm.getPlugin(p), 17, LegacyMaterials.GRASS_BLOCK.name());
|
||||
register((JavaPlugin) pm.getPlugin(p), 17, CompatibleMaterial.GRASS_BLOCK.name());
|
||||
}
|
||||
if (!isRegistered(p = "UltimateCatcher") && pm.isPluginEnabled(p)) {
|
||||
register((JavaPlugin) pm.getPlugin(p), 51, LegacyMaterials.EGG.name());
|
||||
register((JavaPlugin) pm.getPlugin(p), 51, CompatibleMaterial.EGG.name());
|
||||
}
|
||||
if (!isRegistered(p = "UltimateClaims") && pm.isPluginEnabled(p)) {
|
||||
register((JavaPlugin) pm.getPlugin(p), 65, LegacyMaterials.CHEST.name());
|
||||
register((JavaPlugin) pm.getPlugin(p), 65, CompatibleMaterial.CHEST.name());
|
||||
}
|
||||
if (!isRegistered(p = "UltimateFishing") && pm.isPluginEnabled(p)) {
|
||||
register((JavaPlugin) pm.getPlugin(p), 59, LegacyMaterials.COD.name());
|
||||
register((JavaPlugin) pm.getPlugin(p), 59, CompatibleMaterial.COD.name());
|
||||
}
|
||||
if (!isRegistered(p = "UltimateKits") && pm.isPluginEnabled(p)) {
|
||||
register((JavaPlugin) pm.getPlugin(p), 14, LegacyMaterials.BEACON.name());
|
||||
register((JavaPlugin) pm.getPlugin(p), 14, CompatibleMaterial.BEACON.name());
|
||||
}
|
||||
if (!isRegistered(p = "UltimateModeration") && pm.isPluginEnabled(p)) {
|
||||
register((JavaPlugin) pm.getPlugin(p), 29, LegacyMaterials.DIAMOND_CHESTPLATE.name());
|
||||
register((JavaPlugin) pm.getPlugin(p), 29, CompatibleMaterial.DIAMOND_CHESTPLATE.name());
|
||||
}
|
||||
if (!isRegistered(p = "UltimateRepairing") && pm.isPluginEnabled(p)) {
|
||||
register((JavaPlugin) pm.getPlugin(p), 20, LegacyMaterials.ANVIL.name());
|
||||
register((JavaPlugin) pm.getPlugin(p), 20, CompatibleMaterial.ANVIL.name());
|
||||
}
|
||||
if (!isRegistered(p = "UltimateStacker") && pm.isPluginEnabled(p)) {
|
||||
register((JavaPlugin) pm.getPlugin(p), 16, LegacyMaterials.IRON_INGOT.name());
|
||||
register((JavaPlugin) pm.getPlugin(p), 16, CompatibleMaterial.IRON_INGOT.name());
|
||||
}
|
||||
if (!isRegistered(p = "UltimateTimber") && pm.isPluginEnabled(p)) {
|
||||
register((JavaPlugin) pm.getPlugin(p), 18, LegacyMaterials.IRON_AXE.name());
|
||||
register((JavaPlugin) pm.getPlugin(p), 18, CompatibleMaterial.IRON_AXE.name());
|
||||
}
|
||||
}
|
||||
|
||||
private void register(JavaPlugin plugin, int pluginID, String icon) {
|
||||
register(plugin, pluginID, icon, "?");
|
||||
}
|
||||
|
||||
private void register(JavaPlugin plugin, int pluginID, String icon, String libraryVersion) {
|
||||
System.out.println(getPrefix() + "Hooked " + plugin.getName() + ".");
|
||||
PluginInfo info = new PluginInfo(plugin, pluginID, icon);
|
||||
PluginInfo info = new PluginInfo(plugin, pluginID, icon, libraryVersion);
|
||||
// don't forget to check for language pack updates ;)
|
||||
info.addModule(new LocaleModule());
|
||||
registeredPlugins.add(info);
|
||||
@ -288,6 +311,10 @@ public class SongodaCore {
|
||||
return coreRevision;
|
||||
}
|
||||
|
||||
public static String getCoreLibraryVersion() {
|
||||
return coreVersion;
|
||||
}
|
||||
|
||||
public static int getUpdaterVersion() {
|
||||
return updaterVersion;
|
||||
}
|
@ -76,6 +76,7 @@ public abstract class SongodaPlugin extends JavaPlugin {
|
||||
return;
|
||||
}
|
||||
|
||||
console.sendMessage(""); // blank line to speparate chatter
|
||||
console.sendMessage(ChatColor.GREEN + "=============================");
|
||||
console.sendMessage(String.format("%s%s %s by %sSongoda <3!", ChatColor.GRAY.toString(),
|
||||
getDescription().getName(), getDescription().getVersion(), ChatColor.DARK_PURPLE.toString()));
|
||||
@ -88,17 +89,21 @@ public abstract class SongodaPlugin extends JavaPlugin {
|
||||
onPluginEnable();
|
||||
if(emergencyStop) {
|
||||
console.sendMessage(ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
||||
console.sendMessage("");
|
||||
return;
|
||||
}
|
||||
// Start Metrics
|
||||
Metrics.start(this);
|
||||
} catch (Throwable t) {
|
||||
getLogger().log(Level.SEVERE, "Unexpected error while loading " + getDescription().getName() + ": Disabling plugin!", t);
|
||||
emergencyStop();
|
||||
console.sendMessage(ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
||||
console.sendMessage("");
|
||||
return;
|
||||
}
|
||||
|
||||
console.sendMessage(ChatColor.GREEN + "=============================");
|
||||
console.sendMessage(""); // blank line to speparate chatter
|
||||
}
|
||||
|
||||
protected void emergencyStop() {
|
||||
@ -111,6 +116,7 @@ public abstract class SongodaPlugin extends JavaPlugin {
|
||||
if (emergencyStop) {
|
||||
return;
|
||||
}
|
||||
console.sendMessage(""); // blank line to speparate chatter
|
||||
console.sendMessage(ChatColor.GREEN + "=============================");
|
||||
console.sendMessage(String.format("%s%s %s by %sSongoda <3!", ChatColor.GRAY.toString(),
|
||||
getDescription().getName(), getDescription().getVersion(), ChatColor.DARK_PURPLE.toString()));
|
||||
@ -118,6 +124,7 @@ public abstract class SongodaPlugin extends JavaPlugin {
|
||||
ChatColor.RED.toString(), "Disabling", ChatColor.GRAY.toString()));
|
||||
onPluginDisable();
|
||||
console.sendMessage(ChatColor.GREEN + "=============================");
|
||||
console.sendMessage(""); // blank line to speparate chatter
|
||||
}
|
||||
|
||||
public ConsoleCommandSender getConsole() {
|
@ -14,7 +14,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
* @since 2019-08-23
|
||||
* @author jascotty2
|
||||
*/
|
||||
public enum LegacyMaterials {
|
||||
public enum CompatibleMaterial {
|
||||
/*
|
||||
TODO: add another handler for getBlockItem() for materials and fallback materials
|
||||
|
||||
@ -31,7 +31,7 @@ public enum LegacyMaterials {
|
||||
*/
|
||||
ACACIA_BOAT("BOAT_ACACIA"),
|
||||
ACACIA_BUTTON(),
|
||||
ACACIA_DOOR("ACACIA_DOOR_ITEM"), // TODO: ACACIA_DOOR & WOODEN_DOOR are the legacy block variants
|
||||
ACACIA_DOOR("ACACIA_DOOR_ITEM"),
|
||||
ACACIA_FENCE(),
|
||||
ACACIA_FENCE_GATE(),
|
||||
ACACIA_LEAVES("LEAVES_2", (byte) 0),
|
||||
@ -133,7 +133,7 @@ public enum LegacyMaterials {
|
||||
BRAIN_CORAL_FAN,
|
||||
BRAIN_CORAL_WALL_FAN,
|
||||
BREAD,
|
||||
BREWING_STAND,
|
||||
BREWING_STAND("BREWING_STAND_ITEM"),
|
||||
/**
|
||||
* minecraft:brick (item)
|
||||
*/
|
||||
@ -175,7 +175,7 @@ public enum LegacyMaterials {
|
||||
CARTOGRAPHY_TABLE,
|
||||
CARVED_PUMPKIN("JACK_O_LANTERN"),
|
||||
CAT_SPAWN_EGG(),
|
||||
CAULDRON,
|
||||
CAULDRON("CAULDRON_ITEM"),
|
||||
CAVE_AIR(),
|
||||
CAVE_SPIDER_SPAWN_EGG("MONSTER_EGG", (byte) 59),
|
||||
CHAINMAIL_BOOTS,
|
||||
@ -462,7 +462,7 @@ public enum LegacyMaterials {
|
||||
IRON_BLOCK,
|
||||
IRON_BOOTS,
|
||||
IRON_CHESTPLATE,
|
||||
IRON_DOOR, // TODO: legacy block id is IRON_DOOR_BLOCK
|
||||
IRON_DOOR,
|
||||
IRON_HELMET,
|
||||
IRON_HOE,
|
||||
IRON_HORSE_ARMOR("IRON_BARDING"),
|
||||
@ -1008,7 +1008,8 @@ public enum LegacyMaterials {
|
||||
ZOMBIE_WALL_HEAD("SKULL", (byte) 2),;
|
||||
|
||||
private final String modern, modern2, legacy;
|
||||
private final LegacyAnalouges compatibleMaterial;
|
||||
private final LegacyMaterialAnalouge compatibleMaterial;
|
||||
private final LegacyMaterialBlockType legacyBlockMaterial;
|
||||
private final boolean legacyRequiresData;
|
||||
// some materials (I'm looking at you, GREEN_DYE) have changed ID more than once
|
||||
// minVersion is the min for modern, and minVersion2 is min to use legacyCompat1
|
||||
@ -1019,43 +1020,54 @@ public enum LegacyMaterials {
|
||||
// quick test to see if our version is < 1.13
|
||||
protected static final boolean useLegacy = ServerVersion.isServerVersionBelow(ServerVersion.V1_13);
|
||||
// map to speed up name->material lookups
|
||||
private static final Map<String, LegacyMaterials> lookupMap = new HashMap();
|
||||
private static final Map<String, CompatibleMaterial> lookupMap = new HashMap();
|
||||
|
||||
static {
|
||||
for (LegacyMaterials m : values()) {
|
||||
for (CompatibleMaterial m : values()) {
|
||||
lookupMap.put(m.name(), m);
|
||||
if (!m.usesCompatibility()) {
|
||||
lookupMap.put(m.material + ":" + (m.data == null ? "" : m.data), m);
|
||||
}
|
||||
}
|
||||
for (LegacyMaterials m : values()) {
|
||||
if (!m.usesCompatibility() && !lookupMap.containsKey(m.legacy)) {
|
||||
lookupMap.put(m.legacy, m);
|
||||
for (CompatibleMaterial m : values()) {
|
||||
if (!m.usesCompatibility()) {
|
||||
if (m.legacy != null && !lookupMap.containsKey(m.legacy)) {
|
||||
lookupMap.put(m.legacy, m);
|
||||
}
|
||||
if (m.modern2 != null && !lookupMap.containsKey(m.modern2)) {
|
||||
lookupMap.put(m.modern2, m);
|
||||
}
|
||||
if (m.legacyBlockMaterial != null && !lookupMap.containsKey(m.legacyBlockMaterial.blockMaterialName)) {
|
||||
lookupMap.put(m.legacyBlockMaterial.blockMaterialName, m);
|
||||
}
|
||||
if (m.legacyBlockMaterial != null && !lookupMap.containsKey(m.legacyBlockMaterial.alternateBlockMaterialName)) {
|
||||
lookupMap.put(m.legacyBlockMaterial.alternateBlockMaterialName, m);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LegacyMaterials() {
|
||||
CompatibleMaterial() {
|
||||
this(ServerVersion.UNKNOWN, null, null);
|
||||
}
|
||||
|
||||
LegacyMaterials(String legacy) {
|
||||
CompatibleMaterial(String legacy) {
|
||||
this(ServerVersion.V1_13, null, null, legacy, null);
|
||||
}
|
||||
|
||||
LegacyMaterials(String legacy, byte legacyData) {
|
||||
CompatibleMaterial(String legacy, byte legacyData) {
|
||||
this(ServerVersion.V1_13, null, null, legacy, legacyData);
|
||||
}
|
||||
|
||||
LegacyMaterials(ServerVersion modernMinimum, String legacy) {
|
||||
CompatibleMaterial(ServerVersion modernMinimum, String legacy) {
|
||||
this(modernMinimum, null, null, legacy, null);
|
||||
}
|
||||
|
||||
LegacyMaterials(ServerVersion modernMinimum, String legacy, Byte legacyData) {
|
||||
CompatibleMaterial(ServerVersion modernMinimum, String legacy, Byte legacyData) {
|
||||
this(modernMinimum, null, null, legacy, legacyData);
|
||||
}
|
||||
|
||||
LegacyMaterials(ServerVersion modernMinimum, String modern2, ServerVersion modern2Minimum, String legacyMaterial, Byte legacyData) {
|
||||
CompatibleMaterial(ServerVersion modernMinimum, String modern2, ServerVersion modern2Minimum, String legacyMaterial, Byte legacyData) {
|
||||
this.modern = name();
|
||||
this.modern2 = modern2;
|
||||
this.minVersion = modernMinimum;
|
||||
@ -1063,7 +1075,7 @@ public enum LegacyMaterials {
|
||||
this.legacy = legacyMaterial;
|
||||
this.legacyData = legacyData == null ? 0 : legacyData;
|
||||
this.legacyRequiresData = legacyData != null;
|
||||
this.compatibleMaterial = LegacyAnalouges.lookupAnalouge(modern);
|
||||
this.compatibleMaterial = LegacyMaterialAnalouge.lookupAnalouge(modern);
|
||||
|
||||
if (compatibleMaterial != null && ServerVersion.isServerVersionBelow(compatibleMaterial.versionLessThan)) {
|
||||
// server older than this item: use a proxy
|
||||
@ -1078,7 +1090,7 @@ public enum LegacyMaterials {
|
||||
} else if (legacyMaterial != null && (compatibleMaterial == null || ServerVersion.isServerVersionAtLeast(compatibleMaterial.versionLessThan))) {
|
||||
// we're using a server that has the legacy value available
|
||||
material = Material.getMaterial(legacyMaterial);
|
||||
data = legacyRequiresData ? legacyData : null;
|
||||
data = legacyRequiresData ? this.legacyData : null;
|
||||
} else if (compatibleMaterial != null) {
|
||||
// no match: use a proxy
|
||||
material = compatibleMaterial.material;
|
||||
@ -1087,21 +1099,30 @@ public enum LegacyMaterials {
|
||||
material = null;
|
||||
data = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (material != null && ServerVersion.isServerVersionBelow(ServerVersion.V1_13) && (compatibleMaterial == null || material != compatibleMaterial.material)) {
|
||||
legacyBlockMaterial = LegacyMaterialBlockType.getMaterial(this.modern);
|
||||
} else {
|
||||
legacyBlockMaterial = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Bukkit Material for this material
|
||||
*
|
||||
* @return
|
||||
* @return the Bukkit Material for this material
|
||||
*/
|
||||
public Material getMaterial() {
|
||||
return material;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Bukkit Material required to create a block
|
||||
*/
|
||||
public Material getBlockMaterial() {
|
||||
return legacyBlockMaterial != null ? legacyBlockMaterial.getBlockMaterial() : (isBlock() ? material : AIR.material);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item that resembles this material for the current server version
|
||||
*
|
||||
* @return
|
||||
* @return an item that resembles this material for the current server version
|
||||
*/
|
||||
public ItemStack getItem() {
|
||||
if (usesCompatibility()) {
|
||||
@ -1157,7 +1178,7 @@ public enum LegacyMaterials {
|
||||
* @param name item to lookup
|
||||
* @return LegacyMaterial or null if none found
|
||||
*/
|
||||
public static LegacyMaterials getMaterial(String name) {
|
||||
public static CompatibleMaterial getMaterial(String name) {
|
||||
return name == null ? null : lookupMap.get(name.toUpperCase());
|
||||
}
|
||||
|
||||
@ -1170,7 +1191,7 @@ public enum LegacyMaterials {
|
||||
* @param def default item if this is not a valid material
|
||||
* @return LegacyMaterial or null if none found
|
||||
*/
|
||||
public static LegacyMaterials getMaterial(String name, LegacyMaterials def) {
|
||||
public static CompatibleMaterial getMaterial(String name, CompatibleMaterial def) {
|
||||
return name == null ? def : lookupMap.getOrDefault(name.toUpperCase(), def);
|
||||
}
|
||||
|
||||
@ -1180,7 +1201,7 @@ public enum LegacyMaterials {
|
||||
* @param mat item to lookup
|
||||
* @return LegacyMaterial or null if none found
|
||||
*/
|
||||
public static LegacyMaterials getMaterial(Material mat) {
|
||||
public static CompatibleMaterial getMaterial(Material mat) {
|
||||
return mat == null ? null : lookupMap.get(mat.name());
|
||||
}
|
||||
|
||||
@ -1190,21 +1211,21 @@ public enum LegacyMaterials {
|
||||
* @param item item to lookup
|
||||
* @return LegacyMaterial or null if none found
|
||||
*/
|
||||
public static LegacyMaterials getMaterial(ItemStack item) {
|
||||
public static CompatibleMaterial getMaterial(ItemStack item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
String key = item.getType() + ":";
|
||||
LegacyMaterials m = lookupMap.get(key);
|
||||
CompatibleMaterial m = lookupMap.get(key);
|
||||
return m != null ? m : lookupMap.get(key + item.getDurability());
|
||||
}
|
||||
|
||||
static LinkedHashSet<LegacyMaterials> all = null;
|
||||
static LinkedHashSet<CompatibleMaterial> all = null;
|
||||
|
||||
public static Set<LegacyMaterials> getAllValidItemMaterials() {
|
||||
public static Set<CompatibleMaterial> getAllValidItemMaterials() {
|
||||
if (all == null) {
|
||||
all = new LinkedHashSet();
|
||||
for (LegacyMaterials mat : values()) {
|
||||
for (CompatibleMaterial mat : values()) {
|
||||
if (mat.isValidItem() && !mat.usesCompatibility()) {
|
||||
all.add(mat);
|
||||
}
|
||||
@ -1226,7 +1247,7 @@ public enum LegacyMaterials {
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
LegacyMaterials m = lookupMap.get(name.toUpperCase());
|
||||
CompatibleMaterial m = lookupMap.get(name.toUpperCase());
|
||||
if (m != null) {
|
||||
return m.getItem();
|
||||
}
|
||||
@ -1241,7 +1262,7 @@ public enum LegacyMaterials {
|
||||
* @return true if material of the ItemStack matches this item, corrected for legacy data
|
||||
*/
|
||||
public boolean matches(ItemStack item) {
|
||||
return item != null && item.getType() == material && (data == null || item.getDurability() == data); // eons ago, ItemStack.getData() would return a byte. 1.7 doesn't, though.
|
||||
return item != null && !usesCompatibility() && item.getType() == material && (data == null || item.getDurability() == data); // eons ago, ItemStack.getData() would return a byte. 1.7 doesn't, though.
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1974,8 +1995,6 @@ public enum LegacyMaterials {
|
||||
switch (this) {
|
||||
case ACACIA_WOOD:
|
||||
case BIRCH_WOOD:
|
||||
case BREWING_STAND:
|
||||
case CAULDRON:
|
||||
case DARK_OAK_WOOD:
|
||||
case JUNGLE_WOOD:
|
||||
case OAK_WOOD:
|
||||
@ -2030,14 +2049,36 @@ public enum LegacyMaterials {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static LegacyMaterials getSpawnEgg(EntityType type) {
|
||||
/**
|
||||
* @return true if this is a block that has a growth state
|
||||
*/
|
||||
public boolean isCrop() {
|
||||
switch (this) {
|
||||
case BEETROOTS:
|
||||
case CACTUS:
|
||||
case CARROTS:
|
||||
case CHORUS_FLOWER:
|
||||
// FROSTED_ICE is Ageable, but not a crop
|
||||
case KELP:
|
||||
case MELON_STEM:
|
||||
case NETHER_WART:
|
||||
case POTATOES:
|
||||
case PUMPKIN_STEM:
|
||||
case SUGAR_CANE:
|
||||
case WHEAT:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static CompatibleMaterial getSpawnEgg(EntityType type) {
|
||||
if(type == EntityType.MUSHROOM_COW) {
|
||||
return MOOSHROOM_SPAWN_EGG;
|
||||
}
|
||||
return lookupMap.get(type.name() + "_SPAWN_EGG");
|
||||
}
|
||||
|
||||
public static LegacyMaterials getGlassPaneColor(int color) {
|
||||
public static CompatibleMaterial getGlassPaneColor(int color) {
|
||||
switch (color) {
|
||||
case 0:
|
||||
return WHITE_STAINED_GLASS_PANE;
|
||||
@ -2075,7 +2116,7 @@ public enum LegacyMaterials {
|
||||
return WHITE_STAINED_GLASS_PANE;
|
||||
}
|
||||
|
||||
public static LegacyMaterials getGlassColor(int color) {
|
||||
public static CompatibleMaterial getGlassColor(int color) {
|
||||
switch (color) {
|
||||
case 0:
|
||||
return WHITE_STAINED_GLASS;
|
||||
@ -2113,7 +2154,45 @@ public enum LegacyMaterials {
|
||||
return WHITE_STAINED_GLASS;
|
||||
}
|
||||
|
||||
public static LegacyMaterials getDyeColor(int color) {
|
||||
public static CompatibleMaterial getWoolColor(int color) {
|
||||
switch (color) {
|
||||
case 0:
|
||||
return WHITE_WOOL;
|
||||
case 1:
|
||||
return ORANGE_WOOL;
|
||||
case 2:
|
||||
return MAGENTA_WOOL;
|
||||
case 3:
|
||||
return LIGHT_BLUE_WOOL;
|
||||
case 4:
|
||||
return YELLOW_WOOL;
|
||||
case 5:
|
||||
return LIME_WOOL;
|
||||
case 6:
|
||||
return PINK_WOOL;
|
||||
case 7:
|
||||
return GRAY_WOOL;
|
||||
case 8:
|
||||
return LIGHT_GRAY_WOOL;
|
||||
case 9:
|
||||
return CYAN_WOOL;
|
||||
case 10:
|
||||
return PURPLE_WOOL;
|
||||
case 11:
|
||||
return BLUE_WOOL;
|
||||
case 12:
|
||||
return BROWN_WOOL;
|
||||
case 13:
|
||||
return GREEN_WOOL;
|
||||
case 14:
|
||||
return RED_WOOL;
|
||||
case 15:
|
||||
return BLACK_WOOL;
|
||||
}
|
||||
return WHITE_WOOL;
|
||||
}
|
||||
|
||||
public static CompatibleMaterial getDyeColor(int color) {
|
||||
switch (color) {
|
||||
case 0:
|
||||
return BLACK_DYE;
|
@ -1,5 +1,7 @@
|
||||
package com.songoda.core.compatibility;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Effect;
|
||||
@ -7,7 +9,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
public class ParticleHandler {
|
||||
public class CompatibleParticleHandler {
|
||||
|
||||
public static enum ParticleType {
|
||||
EXPLOSION_NORMAL(),
|
||||
@ -83,6 +85,13 @@ public class ParticleHandler {
|
||||
final boolean compatibilityMode;
|
||||
final LegacyParticleEffects.Type compatibleEffect;
|
||||
final Object particle;
|
||||
final static Map<String, ParticleType> map = new HashMap();
|
||||
|
||||
static {
|
||||
for (ParticleType t : values()) {
|
||||
map.put(t.name(), t);
|
||||
}
|
||||
}
|
||||
|
||||
private ParticleType() {
|
||||
if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_8)) {
|
||||
@ -128,6 +137,28 @@ public class ParticleHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ParticleType getParticle(String name) {
|
||||
return map.get(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static void spawnParticles(String type, Location location) {
|
||||
spawnParticles(type, location, 0);
|
||||
}
|
||||
|
||||
public static void spawnParticles(String type, Location location, int count) {
|
||||
ParticleType pt;
|
||||
if (type != null && (pt = ParticleType.getParticle(type.toUpperCase())) != null) {
|
||||
spawnParticles(pt, location, count);
|
||||
}
|
||||
}
|
||||
|
||||
public static void spawnParticles(String type, Location location, int count, double offsetX, double offsetY, double offsetZ) {
|
||||
ParticleType pt;
|
||||
if (type != null && (pt = ParticleType.getParticle(type.toUpperCase())) != null) {
|
||||
spawnParticles(pt, location, count, offsetX, offsetY, offsetZ);
|
||||
}
|
||||
}
|
||||
|
||||
public static void spawnParticles(ParticleType type, Location location) {
|
||||
@ -140,13 +171,12 @@ public class ParticleHandler {
|
||||
|
||||
public static void spawnParticles(ParticleType type, Location location, int count) {
|
||||
if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_8)) {
|
||||
LegacyParticleEffects.createParticle(location, type.compatibleEffect);
|
||||
for (int i = 0; i < count; i++) {
|
||||
float xx = (float) (1 * (Math.random() - Math.random()));
|
||||
float yy = (float) (1 * (Math.random() - Math.random()));
|
||||
float zz = (float) (1 * (Math.random() - Math.random()));
|
||||
Location at = location.clone().add(xx, yy, zz);
|
||||
LegacyParticleEffects.createParticle(at, LegacyParticleEffects.Type.REDSTONE);
|
||||
LegacyParticleEffects.createParticle(at, type.compatibleEffect);
|
||||
}
|
||||
} else {
|
||||
location.getWorld().spawnParticle((Particle) type.particle, location, count);
|
||||
@ -155,19 +185,32 @@ public class ParticleHandler {
|
||||
|
||||
public static void spawnParticles(ParticleType type, Location location, int count, double offsetX, double offsetY, double offsetZ) {
|
||||
if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_8)) {
|
||||
LegacyParticleEffects.createParticle(location, type.compatibleEffect);
|
||||
for (int i = 0; i < count; i++) {
|
||||
float xx = (float) (offsetX * (Math.random() - Math.random()));
|
||||
float yy = (float) (offsetY * (Math.random() - Math.random()));
|
||||
float zz = (float) (offsetZ * (Math.random() - Math.random()));
|
||||
Location at = location.clone().add(xx, yy, zz);
|
||||
LegacyParticleEffects.createParticle(at, LegacyParticleEffects.Type.REDSTONE);
|
||||
LegacyParticleEffects.createParticle(at, type.compatibleEffect);
|
||||
}
|
||||
} else {
|
||||
location.getWorld().spawnParticle((Particle) type.particle, location, count, offsetX, offsetY, offsetZ);
|
||||
}
|
||||
}
|
||||
|
||||
public static void spawnParticles(ParticleType type, Location location, int count, double offsetX, double offsetY, double offsetZ, double extra) {
|
||||
if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_8)) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
float xx = (float) (offsetX * (Math.random() - Math.random()));
|
||||
float yy = (float) (offsetY * (Math.random() - Math.random()));
|
||||
float zz = (float) (offsetZ * (Math.random() - Math.random()));
|
||||
Location at = location.clone().add(xx, yy, zz);
|
||||
LegacyParticleEffects.createParticle(at, type.compatibleEffect, 0F, 0F, 0F, (float) extra, 0, null);
|
||||
}
|
||||
} else {
|
||||
location.getWorld().spawnParticle((Particle) type.particle, location, count, offsetX, offsetY, offsetZ, extra);
|
||||
}
|
||||
}
|
||||
|
||||
public static void redstoneParticles(Location location, int red, int green, int blue) {
|
||||
redstoneParticles(location, red, green, blue, 1F, 1, 0);
|
||||
}
|
@ -1,6 +1,9 @@
|
||||
package com.songoda.core.compatibility;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Sounds that are compatible with server versions 1.7+ <br>
|
||||
@ -14,7 +17,7 @@ import org.bukkit.Sound;
|
||||
* @since 2019-08-25
|
||||
* @author jascotty2
|
||||
*/
|
||||
public enum CompatibleSounds {
|
||||
public enum CompatibleSound {
|
||||
|
||||
// some of these values are missing an API value..
|
||||
// would using the raw strings be better?
|
||||
@ -820,7 +823,7 @@ public enum CompatibleSounds {
|
||||
protected /*final*/ boolean compatibilityMode;
|
||||
protected static final boolean DEBUG = false;
|
||||
|
||||
private CompatibleSounds() {
|
||||
private CompatibleSound() {
|
||||
// This could get risky, since we haven't finished this
|
||||
//sound = Sound.valueOf(name());
|
||||
Sound find = null;
|
||||
@ -838,7 +841,7 @@ public enum CompatibleSounds {
|
||||
}
|
||||
|
||||
// if the sound ony ever changed from 1.8 -> 1.9
|
||||
private CompatibleSounds(String compatibility_18) {
|
||||
private CompatibleSound(String compatibility_18) {
|
||||
try {
|
||||
compatibilityMode = false;
|
||||
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_9)) {
|
||||
@ -852,7 +855,7 @@ public enum CompatibleSounds {
|
||||
}
|
||||
}
|
||||
|
||||
private CompatibleSounds(Version... versions) {
|
||||
private CompatibleSound(Version... versions) {
|
||||
try {
|
||||
for (Version v : versions) {
|
||||
if (v.sound != null && ServerVersion.isServerVersionAtLeast(v.version)) {
|
||||
@ -880,7 +883,7 @@ public enum CompatibleSounds {
|
||||
compatibilityMode = find == null;
|
||||
}
|
||||
|
||||
private CompatibleSounds(ServerVersion minVersion, Version... versions) {
|
||||
private CompatibleSound(ServerVersion minVersion, Version... versions) {
|
||||
try {
|
||||
if (ServerVersion.isServerVersionAtLeast(minVersion)) {
|
||||
// should be good to use this sound
|
||||
@ -915,12 +918,67 @@ public enum CompatibleSounds {
|
||||
return sound != null ? sound : UI_BUTTON_CLICK.sound;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a sound to a specific player
|
||||
*
|
||||
* @param sendTo player to send the sound to
|
||||
*/
|
||||
public void play(Player sendTo) {
|
||||
sendTo.playSound(sendTo.getLocation(), getSound(), 1F, 1F);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a sound to a specific player
|
||||
*
|
||||
* @param sendTo player to send the sound to
|
||||
* @param volume the volume of the sound
|
||||
* @param pitch the pitch of the sound
|
||||
*/
|
||||
public void play(Player sendTo, float volume, float pitch) {
|
||||
sendTo.playSound(sendTo.getLocation(), getSound(), volume, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a sound to a specific player
|
||||
*
|
||||
* @param sendTo player to send the sound to
|
||||
* @param location where the sound should come from
|
||||
* @param volume the volume of the sound
|
||||
* @param pitch the pitch of the sound
|
||||
*/
|
||||
public void play(Player sendTo, Location location, float volume, float pitch) {
|
||||
sendTo.playSound(sendTo.getLocation(), getSound(), volume, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Play a sound in a world
|
||||
*
|
||||
* @param sendTo world to send the sound to
|
||||
* @param location where the sound should come from
|
||||
* @param volume the volume of the sound
|
||||
* @param pitch the pitch of the sound
|
||||
*/
|
||||
public void play(World sendTo, Location location, float volume, float pitch) {
|
||||
sendTo.playSound(location, getSound(), volume, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop a currently active sound from playing for a player
|
||||
*
|
||||
* @param sendTo player to stop the sound for
|
||||
*/
|
||||
public void stop(Player sendTo) {
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_10)) {
|
||||
sendTo.stopSound(getSound());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if this sound is available on this server.
|
||||
*
|
||||
* @return Returns false if we are using a different sound.
|
||||
*/
|
||||
public boolean isMatch() {
|
||||
public boolean usesCompatibility() {
|
||||
return !compatibilityMode;
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
* @since 2019-08-23
|
||||
* @author jascotty2
|
||||
*/
|
||||
public enum LegacyAnalouges {
|
||||
public enum LegacyMaterialAnalouge {
|
||||
|
||||
ACACIA_BOAT(ServerVersion.V1_9, "BOAT"),
|
||||
ACACIA_BUTTON(ServerVersion.V1_13, "WOOD_BUTTON"),
|
||||
@ -486,47 +486,47 @@ public enum LegacyAnalouges {
|
||||
final Byte data;
|
||||
|
||||
// map to speed up name->material lookups
|
||||
private static final Map<String, LegacyAnalouges> lookupMap = new HashMap();
|
||||
private static final Map<String, LegacyMaterialAnalouge> lookupMap = new HashMap();
|
||||
|
||||
static {
|
||||
for (LegacyAnalouges m : values()) {
|
||||
for (LegacyMaterialAnalouge m : values()) {
|
||||
lookupMap.put(m.name(), m);
|
||||
}
|
||||
}
|
||||
|
||||
public static LegacyAnalouges lookupAnalouge(String material) {
|
||||
public static LegacyMaterialAnalouge lookupAnalouge(String material) {
|
||||
return lookupMap.get(material);
|
||||
}
|
||||
|
||||
private LegacyAnalouges(ServerVersion versionLessThan, String legacyMaterial, byte legacyData) {
|
||||
private LegacyMaterialAnalouge(ServerVersion versionLessThan, String legacyMaterial, byte legacyData) {
|
||||
this(versionLessThan, null, legacyMaterial, legacyData, null, null, null);
|
||||
}
|
||||
|
||||
private LegacyAnalouges(ServerVersion versionLessThan, String legacyMaterial) {
|
||||
private LegacyMaterialAnalouge(ServerVersion versionLessThan, String legacyMaterial) {
|
||||
this(versionLessThan, null, legacyMaterial, null, null, null, null);
|
||||
}
|
||||
|
||||
private LegacyAnalouges(ServerVersion versionLessThan, String modernAnalouge, String legacyMaterial) {
|
||||
private LegacyMaterialAnalouge(ServerVersion versionLessThan, String modernAnalouge, String legacyMaterial) {
|
||||
this(versionLessThan, modernAnalouge, legacyMaterial, null, null, null, null);
|
||||
}
|
||||
|
||||
private LegacyAnalouges(ServerVersion versionLessThan, String modernAnalouge, String legacyMaterial, byte legacyData) {
|
||||
private LegacyMaterialAnalouge(ServerVersion versionLessThan, String modernAnalouge, String legacyMaterial, byte legacyData) {
|
||||
this(versionLessThan, modernAnalouge, legacyMaterial, legacyData, null, null, null);
|
||||
}
|
||||
|
||||
private LegacyAnalouges(ServerVersion versionLessThan, String legacyMaterial, byte legacyData, ServerVersion legacyMinimum, String compatMaterial, byte compatData) {
|
||||
private LegacyMaterialAnalouge(ServerVersion versionLessThan, String legacyMaterial, byte legacyData, ServerVersion legacyMinimum, String compatMaterial, byte compatData) {
|
||||
this(versionLessThan, null, legacyMaterial, legacyData, legacyMinimum, compatMaterial, compatData);
|
||||
}
|
||||
|
||||
private LegacyAnalouges(ServerVersion versionLessThan, String legacyMaterial, ServerVersion legacyMinimum, String compatMaterial, byte compatData) {
|
||||
private LegacyMaterialAnalouge(ServerVersion versionLessThan, String legacyMaterial, ServerVersion legacyMinimum, String compatMaterial, byte compatData) {
|
||||
this(versionLessThan, null, legacyMaterial, null, legacyMinimum, compatMaterial, compatData);
|
||||
}
|
||||
|
||||
private LegacyAnalouges(ServerVersion versionLessThan, String legacyMaterial, byte legacyData, ServerVersion legacyMinimum, String compatMaterial) {
|
||||
private LegacyMaterialAnalouge(ServerVersion versionLessThan, String legacyMaterial, byte legacyData, ServerVersion legacyMinimum, String compatMaterial) {
|
||||
this(versionLessThan, null, legacyMaterial, legacyData, legacyMinimum, compatMaterial, null);
|
||||
}
|
||||
|
||||
private LegacyAnalouges(ServerVersion versionLessThan, String legacyMaterial, ServerVersion legacyMinimum, String compatMaterial) {
|
||||
private LegacyMaterialAnalouge(ServerVersion versionLessThan, String legacyMaterial, ServerVersion legacyMinimum, String compatMaterial) {
|
||||
this(versionLessThan, null, legacyMaterial, null, legacyMinimum, compatMaterial, null);
|
||||
}
|
||||
|
||||
@ -537,7 +537,7 @@ public enum LegacyAnalouges {
|
||||
* @param legacyMaterial pre-1.13 material name
|
||||
* @param legacyData data for defining specific legacy items
|
||||
*/
|
||||
private LegacyAnalouges(ServerVersion versionLessThan, String modernAnalouge, String legacyMaterial, Byte legacyData, ServerVersion legacyMinimum, String compatMaterial, Byte compatData) {
|
||||
private LegacyMaterialAnalouge(ServerVersion versionLessThan, String modernAnalouge, String legacyMaterial, Byte legacyData, ServerVersion legacyMinimum, String compatMaterial, Byte compatData) {
|
||||
this.versionLessThan = versionLessThan;
|
||||
this.modernMaterial = modernAnalouge;
|
||||
this.legacyMaterial = legacyMaterial;
|
@ -0,0 +1,102 @@
|
||||
package com.songoda.core.compatibility;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Material;
|
||||
|
||||
/**
|
||||
* Starting in Minecraft 1.13, separate materials for blocks and items were
|
||||
* phased out. This provides a translation for those values.
|
||||
*
|
||||
* @since 2019-09-12
|
||||
* @author jascotty2
|
||||
*/
|
||||
public enum LegacyMaterialBlockType {
|
||||
|
||||
ACACIA_DOOR("ACACIA_DOOR", true),
|
||||
BED("BED_BLOCK", true),
|
||||
BIRCH_DOOR("BIRCH_DOOR", true),
|
||||
FURNACE("FURNACE", "BURNING_FURNACE"),
|
||||
CAKE("CAKE_BLOCK"),
|
||||
CAULDRON("CAULDRON_BLOCK"),
|
||||
COMPARATOR("REDSTONE_COMPARATOR_OFF", "REDSTONE_COMPARATOR_ON"),
|
||||
DARK_OAK_DOOR("DARK_OAK_DOOR", true),
|
||||
DAYLIGHT_DETECTOR("DAYLIGHT_DETECTOR", "DAYLIGHT_DETECTOR_INVERTED"),
|
||||
/*
|
||||
< DOUBLE_STEP,
|
||||
< DOUBLE_STONE_SLAB2,
|
||||
*/
|
||||
FLOWER_POT("FLOWER_POT"),
|
||||
IRON_DOOR("IRON_DOOR_BLOCK", true),
|
||||
JUNGLE_DOOR("JUNGLE_DOOR", true),
|
||||
NETHER_WART("NETHER_WARTS"),
|
||||
/*
|
||||
< PURPUR_DOUBLE_SLAB
|
||||
*/
|
||||
REDSTONE_LAMP("REDSTONE_LAMP_OFF", "REDSTONE_LAMP_ON"),
|
||||
REDSTONE_ORE("REDSTONE_ORE", "GLOWING_REDSTONE_ORE"),
|
||||
REDSTONE_TORCH("REDSTONE_TORCH_ON", "REDSTONE_TORCH_OFF"),
|
||||
SPRUCE_DOOR("SPRUCE_DOOR"),
|
||||
/*
|
||||
< STATIONARY_LAVA,
|
||||
< STATIONARY_WATER,
|
||||
*/
|
||||
SUGAR_CANE("SUGAR_CANE_BLOCK"),
|
||||
WHEAT("CROPS");
|
||||
final String blockMaterialName;
|
||||
final String alternateBlockMaterialName;
|
||||
final Material blockMaterial, alternateBlockMaterial;
|
||||
final boolean requiresData; // some blocks require data to render properly (double blocks)
|
||||
final static Map<String, LegacyMaterialBlockType> lookupTable = new HashMap();
|
||||
|
||||
static {
|
||||
for (LegacyMaterialBlockType t : values()) {
|
||||
lookupTable.put(t.name(), t);
|
||||
}
|
||||
}
|
||||
|
||||
private LegacyMaterialBlockType(String blockMaterial) {
|
||||
this(blockMaterial, null, false);
|
||||
}
|
||||
|
||||
private LegacyMaterialBlockType(String blockMaterial, boolean requiresData) {
|
||||
this(blockMaterial, null, requiresData);
|
||||
}
|
||||
|
||||
private LegacyMaterialBlockType(String blockMaterial, String alternateMaterial) {
|
||||
this(blockMaterial, alternateMaterial, false);
|
||||
}
|
||||
|
||||
private LegacyMaterialBlockType(String blockMaterial, String alternateMaterial, boolean requiresData) {
|
||||
this.blockMaterialName = blockMaterial;
|
||||
this.alternateBlockMaterialName = alternateMaterial;
|
||||
this.requiresData = requiresData;
|
||||
this.blockMaterial = Material.getMaterial(blockMaterialName);
|
||||
this.alternateBlockMaterial = Material.getMaterial(alternateBlockMaterialName);
|
||||
}
|
||||
|
||||
public String getBlockMaterialName() {
|
||||
return blockMaterialName;
|
||||
}
|
||||
|
||||
public String getAlternateMaterialName() {
|
||||
return alternateBlockMaterialName;
|
||||
}
|
||||
|
||||
public Material getBlockMaterial() {
|
||||
return blockMaterial;
|
||||
}
|
||||
|
||||
public Material getAlternateBlockMaterial() {
|
||||
return alternateBlockMaterial;
|
||||
}
|
||||
|
||||
public boolean requiresData() {
|
||||
return requiresData;
|
||||
}
|
||||
|
||||
public static LegacyMaterialBlockType getMaterial(String lookup) {
|
||||
return lookupTable.get(lookup);
|
||||
}
|
||||
|
||||
}
|
@ -145,11 +145,11 @@ public class LegacyParticleEffects {
|
||||
}
|
||||
|
||||
public static void createParticle(Location l, Type e) {
|
||||
createParticle(l, e, 0F, 0F, 0F, 1, 3, null);
|
||||
createParticle(l, e, 0F, 0F, 0F, 1, 0, null);
|
||||
}
|
||||
|
||||
public static void createParticle(Location l, Type e, List<Player> localOnly) {
|
||||
createParticle(l, e, 0F, 0F, 0F, 1, 3, localOnly);
|
||||
createParticle(l, e, 0F, 0F, 0F, 1, 0, localOnly);
|
||||
}
|
||||
|
||||
public static void createParticle(Location l, Type e, float effectSpeed, int amountOfParticles) {
|
@ -6,7 +6,7 @@ import org.bukkit.Bukkit;
|
||||
public enum ServerProject {
|
||||
|
||||
UNKNOWN, CRAFTBUKKIT, SPIGOT, PAPER, TACO, GLOWSTONE;
|
||||
private static ServerProject serverProject = checkProject();
|
||||
private final static ServerProject serverProject = checkProject();
|
||||
|
||||
private static ServerProject checkProject() {
|
||||
String serverPath = Bukkit.getServer().getClass().getName();
|
@ -9,26 +9,34 @@ public enum ServerVersion {
|
||||
|
||||
private final static String serverPackagePath = Bukkit.getServer().getClass().getPackage().getName();
|
||||
private final static String serverPackageVersion = serverPackagePath.substring(serverPackagePath.lastIndexOf('.') + 1);
|
||||
private static ServerVersion serverVersion = UNKNOWN;
|
||||
private static String serverReleaseVersion;
|
||||
private final static String serverReleaseVersion = serverPackageVersion.indexOf('R') != -1 ? serverPackageVersion.substring(serverPackageVersion.indexOf('R') + 1) : "";
|
||||
private final static ServerVersion serverVersion = getVersion();
|
||||
|
||||
static {
|
||||
private static ServerVersion getVersion() {
|
||||
for (ServerVersion version : values()) {
|
||||
if (serverPackageVersion.toUpperCase().startsWith(version.name())) {
|
||||
serverVersion = version;
|
||||
serverReleaseVersion = serverPackageVersion.substring(version.name().length() + 2);
|
||||
return version;
|
||||
}
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
public boolean isLessThan(ServerVersion other) {
|
||||
return this.ordinal() < other.ordinal();
|
||||
}
|
||||
|
||||
public boolean isAtOrBelow(ServerVersion other) {
|
||||
return this.ordinal() <= other.ordinal();
|
||||
}
|
||||
|
||||
public boolean isGreaterThan(ServerVersion other) {
|
||||
return this.ordinal() > other.ordinal();
|
||||
}
|
||||
|
||||
public boolean isAtLeast(ServerVersion other) {
|
||||
return this.ordinal() >= other.ordinal();
|
||||
}
|
||||
|
||||
public static String getServerVersionString() {
|
||||
return serverPackageVersion;
|
||||
}
|
@ -69,6 +69,7 @@ public class Config extends ConfigSection {
|
||||
final DumperOptions yamlOptions = new DumperOptions();
|
||||
final Representer yamlRepresenter = new YamlRepresenter();
|
||||
final Yaml yaml = new Yaml(new YamlConstructor(), yamlRepresenter, yamlOptions);
|
||||
Charset defaultCharset = StandardCharsets.UTF_8;
|
||||
SaveTask saveTask;
|
||||
Timer autosaveTimer;
|
||||
////////////// Config settings ////////////////
|
||||
@ -149,6 +150,31 @@ public class Config extends ConfigSection {
|
||||
return file;
|
||||
}
|
||||
|
||||
public Charset getDefaultCharset() {
|
||||
return defaultCharset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Charset that will be used to save this config
|
||||
*
|
||||
* @param defaultCharset Charset to use
|
||||
* @return this class
|
||||
*/
|
||||
public Config setDefaultCharset(Charset defaultCharset) {
|
||||
this.defaultCharset = defaultCharset;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default charset to use UTF-16
|
||||
*
|
||||
* @return this class
|
||||
*/
|
||||
public Config setUseUTF16() {
|
||||
this.defaultCharset = StandardCharsets.UTF_16;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean getAutosave() {
|
||||
return autosave;
|
||||
}
|
||||
@ -327,6 +353,22 @@ public class Config extends ConfigSection {
|
||||
}
|
||||
}
|
||||
|
||||
public Config clearConfig(boolean clearDefaults) {
|
||||
root.values.clear();
|
||||
root.configComments.clear();
|
||||
if (clearDefaults) {
|
||||
root.defaultComments.clear();
|
||||
root.defaults.clear();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Config clearDefaults() {
|
||||
root.defaultComments.clear();
|
||||
root.defaults.clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean load() {
|
||||
return load(getFile());
|
||||
}
|
||||
@ -336,6 +378,10 @@ public class Config extends ConfigSection {
|
||||
if (file.exists()) {
|
||||
try (BufferedInputStream stream = new BufferedInputStream(new FileInputStream(file))) {
|
||||
Charset charset = TextUtils.detectCharset(stream, StandardCharsets.UTF_8);
|
||||
// upgrade charset if file was saved in a more complex format
|
||||
if(charset == StandardCharsets.UTF_16BE || charset == StandardCharsets.UTF_16LE) {
|
||||
defaultCharset = StandardCharsets.UTF_16;
|
||||
}
|
||||
this.load(new InputStreamReader(stream, charset));
|
||||
return true;
|
||||
} catch (IOException | InvalidConfigurationException ex) {
|
||||
@ -470,7 +516,7 @@ public class Config extends ConfigSection {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
String data = this.saveToString();
|
||||
try (OutputStreamWriter writer = new OutputStreamWriter((OutputStream) new FileOutputStream(file), StandardCharsets.UTF_16);) {
|
||||
try (OutputStreamWriter writer = new OutputStreamWriter((OutputStream) new FileOutputStream(file), defaultCharset);) {
|
||||
writer.write(data);
|
||||
} catch (IOException e) {
|
||||
return false;
|
@ -1,7 +1,6 @@
|
||||
package com.songoda.core.configuration;
|
||||
|
||||
import com.songoda.core.compatibility.LegacyMaterials;
|
||||
import java.util.Arrays;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@ -257,12 +256,12 @@ public class ConfigFileConfigurationAdapter extends FileConfiguration {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public LegacyMaterials getMaterial(@NotNull String path) {
|
||||
public CompatibleMaterial getMaterial(@NotNull String path) {
|
||||
return config.getMaterial(path);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public LegacyMaterials getMaterial(@NotNull String path, @Nullable LegacyMaterials def) {
|
||||
public CompatibleMaterial getMaterial(@NotNull String path, @Nullable CompatibleMaterial def) {
|
||||
return config.getMaterial(path, def);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.core.configuration;
|
||||
|
||||
import com.songoda.core.compatibility.LegacyMaterials;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@ -126,6 +126,8 @@ public class ConfigSection extends MemoryConfiguration {
|
||||
final String node = (i != 0 ? nodePath.append(root.pathChar) : nodePath).append(pathParts[i]).toString();
|
||||
if (!(writeTo.get(node) instanceof ConfigSection)) {
|
||||
writeTo.put(node, travelNode = new ConfigSection(root, travelNode, pathParts[i], useDefault));
|
||||
} else {
|
||||
travelNode = (ConfigSection) writeTo.get(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -407,11 +409,20 @@ public class ConfigSection extends MemoryConfiguration {
|
||||
addDefault(path, value);
|
||||
} else {
|
||||
createNodePath(path, false);
|
||||
Object last = null;
|
||||
synchronized (root.lock) {
|
||||
if (value != null) {
|
||||
root.changed |= root.values.put(fullPath + path, value) != value;
|
||||
root.changed |= (last = root.values.put(fullPath + path, value)) != value;
|
||||
} else {
|
||||
root.changed |= root.values.remove(fullPath + path) != null;
|
||||
root.changed |= (last = root.values.remove(fullPath + path)) != null;
|
||||
}
|
||||
}
|
||||
if (last != value && last != null && last instanceof ConfigSection) {
|
||||
// clean up orphaned nodes
|
||||
final String trim = fullPath + path + root.pathChar;
|
||||
synchronized (root.lock) {
|
||||
root.values.keySet().stream().filter(k -> k.startsWith(trim)).collect(Collectors.toSet()).stream()
|
||||
.forEach(k -> root.values.remove(k));
|
||||
}
|
||||
}
|
||||
onChange();
|
||||
@ -620,16 +631,16 @@ public class ConfigSection extends MemoryConfiguration {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public LegacyMaterials getMaterial(@NotNull String path) {
|
||||
public CompatibleMaterial getMaterial(@NotNull String path) {
|
||||
String val = getString(path);
|
||||
LegacyMaterials mat = val != null ? LegacyMaterials.getMaterial(val) : null;
|
||||
CompatibleMaterial mat = val != null ? CompatibleMaterial.getMaterial(val) : null;
|
||||
return mat;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public LegacyMaterials getMaterial(@NotNull String path, @Nullable LegacyMaterials def) {
|
||||
public CompatibleMaterial getMaterial(@NotNull String path, @Nullable CompatibleMaterial def) {
|
||||
String val = getString(path);
|
||||
LegacyMaterials mat = val != null ? LegacyMaterials.getMaterial(val) : null;
|
||||
CompatibleMaterial mat = val != null ? CompatibleMaterial.getMaterial(val) : null;
|
||||
return mat != null ? mat : def;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.core.configuration;
|
||||
|
||||
import com.songoda.core.compatibility.LegacyMaterials;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import java.util.List;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -105,16 +105,16 @@ public class ConfigSetting {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public LegacyMaterials getMaterial() {
|
||||
LegacyMaterials m = getMaterial(null);
|
||||
return m != null ? m : LegacyMaterials.STONE;
|
||||
public CompatibleMaterial getMaterial() {
|
||||
CompatibleMaterial m = getMaterial(null);
|
||||
return m != null ? m : CompatibleMaterial.STONE;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public LegacyMaterials getMaterial(@Nullable LegacyMaterials def) {
|
||||
public CompatibleMaterial getMaterial(@Nullable CompatibleMaterial def) {
|
||||
//return config.getMaterial(key, def);
|
||||
String val = config.getString(key);
|
||||
LegacyMaterials mat = val != null ? LegacyMaterials.getMaterial(val) : null;
|
||||
CompatibleMaterial mat = val != null ? CompatibleMaterial.getMaterial(val) : null;
|
||||
|
||||
if (mat == null) {
|
||||
System.out.println(String.format("Config value \"%s\" has an invalid material name: \"%s\"", key, val));
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.core.configuration.editor;
|
||||
|
||||
import com.songoda.core.compatibility.LegacyMaterials;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.gui.Gui;
|
||||
import com.songoda.core.gui.GuiUtils;
|
||||
import com.songoda.core.gui.SimplePagedGui;
|
||||
@ -49,7 +49,7 @@ public class ConfigEditorGui extends SimplePagedGui {
|
||||
this.file = file;
|
||||
this.config = config;
|
||||
this.node = node;
|
||||
this.blankItem = GuiUtils.getBorderItem(LegacyMaterials.LIGHT_GRAY_STAINED_GLASS_PANE);
|
||||
this.blankItem = GuiUtils.getBorderItem(CompatibleMaterial.LIGHT_GRAY_STAINED_GLASS_PANE);
|
||||
|
||||
// if we have a ConfigSection, we can also grab comments
|
||||
try {
|
||||
@ -60,10 +60,10 @@ public class ConfigEditorGui extends SimplePagedGui {
|
||||
// decorate header
|
||||
this.setTitle(ChatColor.DARK_BLUE + file);
|
||||
this.setUseHeader(true);
|
||||
headerBackItem = footerBackItem = GuiUtils.getBorderItem(LegacyMaterials.GRAY_STAINED_GLASS_PANE.getItem());
|
||||
headerBackItem = footerBackItem = GuiUtils.getBorderItem(CompatibleMaterial.GRAY_STAINED_GLASS_PANE.getItem());
|
||||
final String path = node.getCurrentPath();
|
||||
this.setItem(4, configItem(LegacyMaterials.FILLED_MAP, !path.isEmpty() ? path : file , config, !path.isEmpty() ? path : null, ChatColor.BLACK.toString()));
|
||||
this.setButton(8, GuiUtils.createButtonItem(LegacyMaterials.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory());
|
||||
this.setItem(4, configItem(CompatibleMaterial.FILLED_MAP, !path.isEmpty() ? path : file , config, !path.isEmpty() ? path : null, ChatColor.BLACK.toString()));
|
||||
this.setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory());
|
||||
|
||||
// compile list of settings
|
||||
for (String key : node.getKeys(false)) {
|
||||
@ -77,7 +77,7 @@ public class ConfigEditorGui extends SimplePagedGui {
|
||||
// next we need to display the config settings
|
||||
int index = 9;
|
||||
for (final String sectionKey : sections) {
|
||||
setButton(index++, configItem(LegacyMaterials.WRITABLE_BOOK, ChatColor.YELLOW + sectionKey, node, sectionKey, "Click to open this section"),
|
||||
setButton(index++, configItem(CompatibleMaterial.WRITABLE_BOOK, ChatColor.YELLOW + sectionKey, node, sectionKey, "Click to open this section"),
|
||||
(event) -> event.manager.showGUI(event.player, new ConfigEditorGui(plugin, this, file, config, node.getConfigurationSection(sectionKey))));
|
||||
}
|
||||
|
||||
@ -87,14 +87,14 @@ public class ConfigEditorGui extends SimplePagedGui {
|
||||
if(val == null) continue;
|
||||
else if (val instanceof Boolean) {
|
||||
// toggle switch
|
||||
setButton(index, configItem(LegacyMaterials.LEVER, ChatColor.YELLOW + settingKey, node, settingKey, String.valueOf((Boolean) val), "Click to toggle this setting"),
|
||||
setButton(index, configItem(CompatibleMaterial.LEVER, ChatColor.YELLOW + settingKey, node, settingKey, String.valueOf((Boolean) val), "Click to toggle this setting"),
|
||||
(event) -> this.toggle(event.slot, settingKey));
|
||||
if ((Boolean) val) {
|
||||
highlightItem(index);
|
||||
}
|
||||
} else if (isNumber(val)) {
|
||||
// number dial
|
||||
this.setButton(index, configItem(LegacyMaterials.CLOCK, ChatColor.YELLOW + settingKey, node, settingKey, String.valueOf((Number) val), "Click to edit this setting"),
|
||||
this.setButton(index, configItem(CompatibleMaterial.CLOCK, ChatColor.YELLOW + settingKey, node, settingKey, String.valueOf((Number) val), "Click to edit this setting"),
|
||||
(event) -> {
|
||||
event.gui.exit();
|
||||
ChatPrompt.showPrompt(plugin, event.player, "Enter a new number value for " + settingKey + ":", response -> {
|
||||
@ -107,14 +107,14 @@ public class ConfigEditorGui extends SimplePagedGui {
|
||||
} else if (isMaterial(val)) {
|
||||
// changing a block
|
||||
// isMaterial is more of a guess, to be honest.
|
||||
setButton(index, configItem(LegacyMaterials.STONE, ChatColor.YELLOW + settingKey, node, settingKey, val.toString(), "Click to edit this setting"),
|
||||
setButton(index, configItem(CompatibleMaterial.STONE, ChatColor.YELLOW + settingKey, node, settingKey, val.toString(), "Click to edit this setting"),
|
||||
(event) -> {
|
||||
SimplePagedGui paged = new SimplePagedGui(this);
|
||||
paged.setTitle(ChatColor.BLUE + settingKey);
|
||||
paged.setHeaderBackItem(headerBackItem).setFooterBackItem(footerBackItem).setDefaultItem(blankItem);
|
||||
paged.setItem(4, configItem(LegacyMaterials.FILLED_MAP, settingKey, node, settingKey, "Choose an item to change this value to"));
|
||||
paged.setItem(4, configItem(CompatibleMaterial.FILLED_MAP, settingKey, node, settingKey, "Choose an item to change this value to"));
|
||||
int i = 9;
|
||||
for(LegacyMaterials mat : LegacyMaterials.getAllValidItemMaterials()) {
|
||||
for(CompatibleMaterial mat : CompatibleMaterial.getAllValidItemMaterials()) {
|
||||
paged.setButton(i++, GuiUtils.createButtonItem(mat, mat.name()), ClickType.LEFT, (matEvent) -> {
|
||||
setMaterial(event.slot, settingKey, matEvent.clickedItem);
|
||||
matEvent.player.closeInventory();
|
||||
@ -125,7 +125,7 @@ public class ConfigEditorGui extends SimplePagedGui {
|
||||
|
||||
} else if (val instanceof String) {
|
||||
// changing a "string" value (or change to a feather for writing quill)
|
||||
setButton(index, configItem(LegacyMaterials.STRING, ChatColor.YELLOW + settingKey, node, settingKey, val.toString(), "Click to edit this setting"),
|
||||
setButton(index, configItem(CompatibleMaterial.STRING, ChatColor.YELLOW + settingKey, node, settingKey, val.toString(), "Click to edit this setting"),
|
||||
(event) -> {
|
||||
event.gui.exit();
|
||||
ChatPrompt.showPrompt(plugin, event.player, "Enter a new value for " + settingKey + ":", response -> {
|
||||
@ -135,7 +135,7 @@ public class ConfigEditorGui extends SimplePagedGui {
|
||||
.setOnCancel(() -> {event.player.sendMessage(ChatColor.RED + "Edit canceled"); event.manager.showGUI(event.player, this);});
|
||||
});
|
||||
} else if (val instanceof List) {
|
||||
setButton(index, configItem(LegacyMaterials.WRITABLE_BOOK, ChatColor.YELLOW + settingKey, node, settingKey, String.format("(%d values)", ((List) val).size()), "Click to edit this setting"),
|
||||
setButton(index, configItem(CompatibleMaterial.WRITABLE_BOOK, ChatColor.YELLOW + settingKey, node, settingKey, String.format("(%d values)", ((List) val).size()), "Click to edit this setting"),
|
||||
(event) -> {
|
||||
event.manager.showGUI(event.player, (new ConfigEditorListEditorGui(this, settingKey, (List) val)).setOnClose((gui) -> {
|
||||
if(((ConfigEditorListEditorGui) gui.gui).saveChanges) {
|
||||
@ -208,9 +208,9 @@ public class ConfigEditorGui extends SimplePagedGui {
|
||||
}
|
||||
|
||||
void setMaterial(int clickCell, String path, ItemStack item) {
|
||||
LegacyMaterials mat = LegacyMaterials.getMaterial(item);
|
||||
CompatibleMaterial mat = CompatibleMaterial.getMaterial(item);
|
||||
if (mat == null) {
|
||||
node.set(path, LegacyMaterials.STONE.name());
|
||||
node.set(path, CompatibleMaterial.STONE.name());
|
||||
} else {
|
||||
node.set(path, mat.name());
|
||||
}
|
||||
@ -244,12 +244,12 @@ public class ConfigEditorGui extends SimplePagedGui {
|
||||
}
|
||||
|
||||
private boolean isMaterial(Object value) {
|
||||
LegacyMaterials m;
|
||||
CompatibleMaterial m;
|
||||
return value instanceof String && value.toString().equals(value.toString().toUpperCase())
|
||||
&& (m = LegacyMaterials.getMaterial(value.toString())) != null && m.isValidItem();
|
||||
&& (m = CompatibleMaterial.getMaterial(value.toString())) != null && m.isValidItem();
|
||||
}
|
||||
|
||||
protected ItemStack configItem(LegacyMaterials type, String name, ConfigurationSection node, String path, String def) {
|
||||
protected ItemStack configItem(CompatibleMaterial type, String name, ConfigurationSection node, String path, String def) {
|
||||
String[] info = null;
|
||||
if (configSection_getCommentString != null) {
|
||||
try {
|
||||
@ -263,7 +263,7 @@ public class ConfigEditorGui extends SimplePagedGui {
|
||||
return GuiUtils.createButtonItem(type, name, info != null ? info : (def != null ? def.split("\n") : null));
|
||||
}
|
||||
|
||||
protected ItemStack configItem(LegacyMaterials type, String name, ConfigurationSection node, String path, String value, String def) {
|
||||
protected ItemStack configItem(CompatibleMaterial type, String name, ConfigurationSection node, String path, String value, String def) {
|
||||
if(value == null) value = "";
|
||||
String[] info = null;
|
||||
if (configSection_getCommentString != null) {
|
@ -1,12 +1,11 @@
|
||||
package com.songoda.core.configuration.editor;
|
||||
|
||||
import com.songoda.core.compatibility.LegacyMaterials;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.gui.GuiUtils;
|
||||
import com.songoda.core.gui.SimplePagedGui;
|
||||
import com.songoda.core.input.ChatPrompt;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
@ -30,16 +29,16 @@ public class ConfigEditorListEditorGui extends SimplePagedGui {
|
||||
headerBackItem = footerBackItem = current.getHeaderBackItem();
|
||||
setTitle(ChatColor.DARK_BLUE + "String List Editor");
|
||||
this.setUseHeader(true);
|
||||
this.setItem(4, current.configItem(LegacyMaterials.FILLED_MAP, key, current.getCurrentNode(), key, null));
|
||||
this.setButton(8, GuiUtils.createButtonItem(LegacyMaterials.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory());
|
||||
this.setItem(4, current.configItem(CompatibleMaterial.FILLED_MAP, key, current.getCurrentNode(), key, null));
|
||||
this.setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory());
|
||||
this.values = new ArrayList(val);
|
||||
|
||||
this.setButton(8, GuiUtils.createButtonItem(LegacyMaterials.LAVA_BUCKET, ChatColor.RED + "Discard Changes"), (event) -> event.player.closeInventory());
|
||||
this.setButton(0, GuiUtils.createButtonItem(LegacyMaterials.REDSTONE, ChatColor.GREEN + "Save"), (event) -> {
|
||||
this.setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.LAVA_BUCKET, ChatColor.RED + "Discard Changes"), (event) -> event.player.closeInventory());
|
||||
this.setButton(0, GuiUtils.createButtonItem(CompatibleMaterial.REDSTONE, ChatColor.GREEN + "Save"), (event) -> {
|
||||
saveChanges = true;
|
||||
event.player.closeInventory();
|
||||
});
|
||||
this.setButton(1, GuiUtils.createButtonItem(LegacyMaterials.CHEST, ChatColor.BLUE + "Add Item"),
|
||||
this.setButton(1, GuiUtils.createButtonItem(CompatibleMaterial.CHEST, ChatColor.BLUE + "Add Item"),
|
||||
(event) -> {
|
||||
event.gui.exit();
|
||||
ChatPrompt.showPrompt(event.manager.getPlugin(), event.player, "Enter a new value to add:", response -> {
|
||||
@ -68,7 +67,7 @@ public class ConfigEditorListEditorGui extends SimplePagedGui {
|
||||
int i = 9;
|
||||
for (String item : values) {
|
||||
final int index = i - 9;
|
||||
setButton(i++, GuiUtils.createButtonItem(LegacyMaterials.PAPER, item, "Right-click to remove"), ClickType.RIGHT, (event) -> {
|
||||
setButton(i++, GuiUtils.createButtonItem(CompatibleMaterial.PAPER, item, "Right-click to remove"), ClickType.RIGHT, (event) -> {
|
||||
values.remove(index);
|
||||
redraw();
|
||||
});
|
@ -1,7 +1,7 @@
|
||||
package com.songoda.core.configuration.editor;
|
||||
|
||||
import com.songoda.core.SongodaPlugin;
|
||||
import com.songoda.core.compatibility.LegacyMaterials;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.configuration.Config;
|
||||
import com.songoda.core.gui.Gui;
|
||||
import com.songoda.core.gui.GuiUtils;
|
||||
@ -79,18 +79,18 @@ public class PluginConfigGui extends SimplePagedGui {
|
||||
}
|
||||
|
||||
private void init() {
|
||||
this.blankItem = GuiUtils.getBorderItem(LegacyMaterials.LIGHT_GRAY_STAINED_GLASS_PANE);
|
||||
this.blankItem = GuiUtils.getBorderItem(CompatibleMaterial.LIGHT_GRAY_STAINED_GLASS_PANE);
|
||||
|
||||
// decorate header
|
||||
this.setTitle(ChatColor.DARK_BLUE + plugin.getName() + " Plugin Config");
|
||||
this.setUseHeader(true);
|
||||
headerBackItem = footerBackItem = GuiUtils.getBorderItem(LegacyMaterials.GRAY_STAINED_GLASS_PANE.getItem());
|
||||
this.setButton(8, GuiUtils.createButtonItem(LegacyMaterials.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory());
|
||||
headerBackItem = footerBackItem = GuiUtils.getBorderItem(CompatibleMaterial.GRAY_STAINED_GLASS_PANE.getItem());
|
||||
this.setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory());
|
||||
|
||||
// List out all config files that this plugin has
|
||||
int i = 9;
|
||||
for (Map.Entry<String, MemoryConfiguration> config : configs.entrySet()) {
|
||||
this.setButton(i++, GuiUtils.createButtonItem(LegacyMaterials.BOOK, ChatColor.YELLOW + config.getKey(), "Click to edit this config"),
|
||||
this.setButton(i++, GuiUtils.createButtonItem(CompatibleMaterial.BOOK, ChatColor.YELLOW + config.getKey(), "Click to edit this config"),
|
||||
(event) -> event.manager.showGUI(event.player, new ConfigEditorGui(plugin, this, config.getKey(), config.getValue())));
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.core.core;
|
||||
|
||||
import com.songoda.core.compatibility.LegacyMaterials;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@ -13,7 +13,8 @@ public final class PluginInfo {
|
||||
protected final JavaPlugin javaPlugin;
|
||||
protected final int songodaId;
|
||||
protected final String coreIcon;
|
||||
protected final LegacyMaterials icon;
|
||||
protected final String coreLibraryVersion;
|
||||
protected final CompatibleMaterial icon;
|
||||
private final List<PluginInfoModule> modules = new ArrayList<>();
|
||||
private boolean hasUpdate = false;
|
||||
private String latestVersion;
|
||||
@ -22,11 +23,12 @@ public final class PluginInfo {
|
||||
private String marketplaceLink;
|
||||
private JSONObject json;
|
||||
|
||||
public PluginInfo(JavaPlugin javaPlugin, int songodaId, String icon) {
|
||||
public PluginInfo(JavaPlugin javaPlugin, int songodaId, String icon, String coreLibraryVersion) {
|
||||
this.javaPlugin = javaPlugin;
|
||||
this.songodaId = songodaId;
|
||||
this.coreIcon = icon;
|
||||
this.icon = LegacyMaterials.getMaterial(icon);
|
||||
this.icon = CompatibleMaterial.getMaterial(icon);
|
||||
this.coreLibraryVersion = coreLibraryVersion;
|
||||
}
|
||||
|
||||
public String getLatestVersion() {
|
||||
@ -98,4 +100,8 @@ public final class PluginInfo {
|
||||
public String getCoreIcon() {
|
||||
return coreIcon;
|
||||
}
|
||||
|
||||
public String getCoreLibraryVersion() {
|
||||
return coreLibraryVersion;
|
||||
}
|
||||
}
|
@ -41,7 +41,7 @@ public class SongodaCoreDiagCommand extends AbstractCommand {
|
||||
sender.sendMessage("Plugins:");
|
||||
for (PluginInfo plugin : SongodaCore.getPlugins()) {
|
||||
sender.sendMessage(plugin.getJavaPlugin().getName()
|
||||
+ " (" + plugin.getJavaPlugin().getDescription().getVersion() + ")");
|
||||
+ " (" + plugin.getJavaPlugin().getDescription().getVersion() + " Core " + plugin.getCoreLibraryVersion() + ")");
|
||||
}
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage("Server Version: " + Bukkit.getVersion());
|
@ -1,7 +1,7 @@
|
||||
package com.songoda.core.core;
|
||||
|
||||
import com.songoda.core.SongodaCore;
|
||||
import com.songoda.core.compatibility.LegacyMaterials;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.configuration.editor.PluginConfigGui;
|
||||
import com.songoda.core.gui.Gui;
|
||||
import com.songoda.core.gui.GuiUtils;
|
||||
@ -23,7 +23,7 @@ final class SongodaCoreOverviewGUI extends Gui {
|
||||
for (int i = 0; i < plugins.size(); i++) {
|
||||
final PluginInfo plugin = plugins.get(i);
|
||||
if (plugin.hasUpdate()) {
|
||||
setButton(i, GuiUtils.createButtonItem(plugin.icon != null ? plugin.icon : LegacyMaterials.STONE,
|
||||
setButton(i, GuiUtils.createButtonItem(plugin.icon != null ? plugin.icon : CompatibleMaterial.STONE,
|
||||
ChatColor.GOLD + plugin.getJavaPlugin().getName(),
|
||||
ChatColor.GRAY + "Latest Version: " + plugin.getLatestVersion(),
|
||||
ChatColor.GRAY + "Installed Version: " + plugin.getJavaPlugin().getDescription().getVersion(),
|
||||
@ -38,7 +38,7 @@ final class SongodaCoreOverviewGUI extends Gui {
|
||||
setAction(i, ClickType.RIGHT, (event) -> event.manager.showGUI(event.player, new PluginConfigGui(plugin.getJavaPlugin(), event.gui)));
|
||||
highlightItem(i);
|
||||
} else {
|
||||
setButton(i, GuiUtils.createButtonItem(plugin.icon != null ? plugin.icon : LegacyMaterials.STONE,
|
||||
setButton(i, GuiUtils.createButtonItem(plugin.icon != null ? plugin.icon : CompatibleMaterial.STONE,
|
||||
ChatColor.GOLD + plugin.getJavaPlugin().getName(),
|
||||
ChatColor.GRAY + "Installed Version: " + plugin.getJavaPlugin().getDescription().getVersion(),
|
||||
"",
|
100
Core/src/main/java/com/songoda/core/gui/AnvilGui.java
Normal file
100
Core/src/main/java/com/songoda/core/gui/AnvilGui.java
Normal file
@ -0,0 +1,100 @@
|
||||
package com.songoda.core.gui;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.gui.methods.Clickable;
|
||||
import com.songoda.core.nms.CoreNMS;
|
||||
import com.songoda.core.nms.CustomAnvil;
|
||||
import com.songoda.core.nms.NmsManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Anvil GUI for text prompts
|
||||
*
|
||||
* @since 2019-09-15
|
||||
* @author jascotty2
|
||||
*/
|
||||
public class AnvilGui extends Gui {
|
||||
|
||||
final Player player;
|
||||
CustomAnvil anvil;
|
||||
|
||||
public AnvilGui(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public AnvilGui(Player player, Gui parent) {
|
||||
super(parent);
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public AnvilGui setAction(@Nullable Clickable action) {
|
||||
return (AnvilGui) setAction(2, action);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public AnvilGui setAction(@Nullable ClickType type, @Nullable Clickable action) {
|
||||
return (AnvilGui) setAction(2, type, action);
|
||||
}
|
||||
|
||||
protected void open() {
|
||||
anvil.open();
|
||||
}
|
||||
|
||||
public AnvilGui setInput(ItemStack item) {
|
||||
return (AnvilGui) this.setItem(0, item);
|
||||
}
|
||||
|
||||
public ItemStack getInput() {
|
||||
return this.getItem(0);
|
||||
}
|
||||
|
||||
public AnvilGui setOutput(ItemStack item) {
|
||||
return (AnvilGui) this.setItem(2, item);
|
||||
}
|
||||
|
||||
public ItemStack getOutput() {
|
||||
return this.getItem(2);
|
||||
}
|
||||
|
||||
public String getInputText() {
|
||||
return anvil != null ? anvil.getRenameText() : null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Inventory generateInventory(@NotNull GuiManager manager) {
|
||||
this.guiManager = manager;
|
||||
|
||||
createInventory();
|
||||
ItemStack item;
|
||||
if ((item = cellItems.get(0)) != null) {
|
||||
inventory.setItem(0, item);
|
||||
} else if ((item = cellItems.get(1)) != null) {
|
||||
inventory.setItem(1, item);
|
||||
} else if (!acceptsItems) {
|
||||
inventory.setItem(0, GuiUtils.createButtonItem(CompatibleMaterial.PAPER, " ", " "));
|
||||
}
|
||||
if ((item = cellItems.get(2)) != null) {
|
||||
inventory.setItem(2, item);
|
||||
}
|
||||
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createInventory() {
|
||||
CoreNMS nms = NmsManager.getNMS();
|
||||
if (nms != null) {
|
||||
anvil = nms.createAnvil(player, new GuiHolder(guiManager, this));
|
||||
anvil.setCustomTitle(title);
|
||||
anvil.setLevelCost(0);
|
||||
inventory = anvil.getInventory();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.core.gui;
|
||||
|
||||
import com.songoda.core.compatibility.LegacyMaterials;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.configuration.DataStoreObject;
|
||||
import com.songoda.core.configuration.SimpleDataStore;
|
||||
import com.songoda.core.gui.methods.Clickable;
|
||||
@ -52,7 +52,7 @@ public class CustomizableGui extends Gui {
|
||||
@Override
|
||||
public CustomizableGui setDefaultItem(ItemStack item) {
|
||||
if ((blankItem = item) != null) {
|
||||
buttons.put("__DEFAULT__", (new CustomButton("__DEFAULT__")).setIcon(LegacyMaterials.getMaterial(item)));
|
||||
buttons.put("__DEFAULT__", (new CustomButton("__DEFAULT__")).setIcon(CompatibleMaterial.getMaterial(item)));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@ -72,7 +72,7 @@ public class CustomizableGui extends Gui {
|
||||
public CustomizableGui setItem(int defaultCell, @NotNull String key, @NotNull ItemStack item) {
|
||||
CustomButton btn = key == null ? null : buttons.get(key = key.toLowerCase());
|
||||
if (btn == null) {
|
||||
buttons.put(key, btn = (new CustomButton(key, defaultCell)).setIcon(LegacyMaterials.getMaterial(item)));
|
||||
buttons.put(key, btn = (new CustomButton(key, defaultCell)).setIcon(CompatibleMaterial.getMaterial(item)));
|
||||
} else {
|
||||
ItemStack btnItem = btn.icon.getItem();
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
@ -92,13 +92,13 @@ public class CustomizableGui extends Gui {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CustomizableGui setItem(int defaultRow, int defaultCol, @NotNull String key, @NotNull LegacyMaterials defaultItem, @NotNull String title, @NotNull String... lore) {
|
||||
public CustomizableGui setItem(int defaultRow, int defaultCol, @NotNull String key, @NotNull CompatibleMaterial defaultItem, @NotNull String title, @NotNull String... lore) {
|
||||
final int cell = defaultCol + defaultRow * 9;
|
||||
return setItem(cell, key, defaultItem, title, lore);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CustomizableGui setItem(int defaultCell, @NotNull String key, @NotNull LegacyMaterials defaultItem, @NotNull String title, @NotNull String... lore) {
|
||||
public CustomizableGui setItem(int defaultCell, @NotNull String key, @NotNull CompatibleMaterial defaultItem, @NotNull String title, @NotNull String... lore) {
|
||||
CustomButton btn = key == null ? null : buttons.get(key = key.toLowerCase());
|
||||
if (btn == null) {
|
||||
buttons.put(key, btn = (new CustomButton(key, defaultCell)).setIcon(defaultItem));
|
||||
@ -129,6 +129,33 @@ public class CustomizableGui extends Gui {
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui updateItemLore(@NotNull String key, @NotNull String... lore) {
|
||||
CustomButton btn = key == null ? null : buttons.get(key.toLowerCase());
|
||||
if (btn != null) {
|
||||
this.updateItemLore(btn.position, lore);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui updateItemLore(@NotNull String key, @Nullable List<String> lore) {
|
||||
CustomButton btn = key == null ? null : buttons.get(key.toLowerCase());
|
||||
if (btn != null) {
|
||||
this.updateItemLore(btn.position, lore);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui updateItemName(@NotNull String key, @Nullable String name) {
|
||||
CustomButton btn = key == null ? null : buttons.get(key.toLowerCase());
|
||||
if (btn != null) {
|
||||
this.updateItemName(btn.position, title);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CustomizableGui updateItem(@NotNull String key, @Nullable String title, @NotNull String... lore) {
|
||||
CustomButton btn = key == null ? null : buttons.get(key.toLowerCase());
|
||||
@ -148,7 +175,7 @@ public class CustomizableGui extends Gui {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CustomizableGui updateItem(@NotNull String key, @NotNull LegacyMaterials itemTo, @NotNull String title, @NotNull String... lore) {
|
||||
public CustomizableGui updateItem(@NotNull String key, @NotNull CompatibleMaterial itemTo, @NotNull String title, @NotNull String... lore) {
|
||||
CustomButton btn = key == null ? null : buttons.get(key.toLowerCase());
|
||||
if (btn != null) {
|
||||
this.updateItem(btn.position, itemTo, title, lore);
|
||||
@ -157,7 +184,7 @@ public class CustomizableGui extends Gui {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CustomizableGui updateItem(@NotNull String key, @NotNull LegacyMaterials itemTo, @NotNull String title, @Nullable List<String> lore) {
|
||||
public CustomizableGui updateItem(@NotNull String key, @NotNull CompatibleMaterial itemTo, @NotNull String title, @Nullable List<String> lore) {
|
||||
CustomButton btn = key == null ? null : buttons.get(key.toLowerCase());
|
||||
if (btn != null) {
|
||||
this.updateItem(btn.position, itemTo, title, lore);
|
||||
@ -224,7 +251,7 @@ public class CustomizableGui extends Gui {
|
||||
public CustomizableGui setNextPage(int cell, @NotNull ItemStack item) {
|
||||
CustomButton btn = buttons.get("__NEXT__");
|
||||
if (btn == null) {
|
||||
buttons.put("__NEXT__", btn = (new CustomButton("__NEXT__", cell)).setIcon(LegacyMaterials.getMaterial(item)));
|
||||
buttons.put("__NEXT__", btn = (new CustomButton("__NEXT__", cell)).setIcon(CompatibleMaterial.getMaterial(item)));
|
||||
} else {
|
||||
ItemStack btnItem = btn.icon.getItem();
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
@ -250,7 +277,7 @@ public class CustomizableGui extends Gui {
|
||||
public CustomizableGui setPrevPage(int cell, @NotNull ItemStack item) {
|
||||
CustomButton btn = buttons.get("__PREV__");
|
||||
if (btn == null) {
|
||||
buttons.put("__PREV__", btn = (new CustomButton("__PREV__", cell)).setIcon(LegacyMaterials.getMaterial(item)));
|
||||
buttons.put("__PREV__", btn = (new CustomButton("__PREV__", cell)).setIcon(CompatibleMaterial.getMaterial(item)));
|
||||
} else {
|
||||
ItemStack btnItem = btn.icon.getItem();
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
@ -278,7 +305,7 @@ public class CustomizableGui extends Gui {
|
||||
boolean _changed = false;
|
||||
final String key;
|
||||
int position = -1;
|
||||
LegacyMaterials icon = LegacyMaterials.STONE;
|
||||
CompatibleMaterial icon = CompatibleMaterial.STONE;
|
||||
|
||||
public CustomButton(String key) {
|
||||
this.key = key;
|
||||
@ -291,7 +318,7 @@ public class CustomizableGui extends Gui {
|
||||
|
||||
public static CustomButton loadFromSection(ConfigurationSection sec) {
|
||||
CustomButton dat = new CustomButton(sec.getName());
|
||||
dat.icon = sec.contains("icon") ? LegacyMaterials.getMaterial(sec.getString("icon"), LegacyMaterials.STONE) : LegacyMaterials.STONE;
|
||||
dat.icon = sec.contains("icon") ? CompatibleMaterial.getMaterial(sec.getString("icon"), CompatibleMaterial.STONE) : CompatibleMaterial.STONE;
|
||||
dat.position = sec.getInt("position");
|
||||
return dat;
|
||||
}
|
||||
@ -322,12 +349,12 @@ public class CustomizableGui extends Gui {
|
||||
_changed = isChanged;
|
||||
}
|
||||
|
||||
public LegacyMaterials getIcon() {
|
||||
public CompatibleMaterial getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public CustomButton setIcon(LegacyMaterials icon) {
|
||||
this.icon = icon != null ? icon : LegacyMaterials.STONE;
|
||||
public CustomButton setIcon(CompatibleMaterial icon) {
|
||||
this.icon = icon != null ? icon : CompatibleMaterial.STONE;
|
||||
_changed = true;
|
||||
return this;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.core.gui;
|
||||
|
||||
import com.songoda.core.compatibility.LegacyMaterials;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.gui.events.GuiClickEvent;
|
||||
import com.songoda.core.gui.events.GuiDropItemEvent;
|
||||
import com.songoda.core.gui.methods.Clickable;
|
||||
@ -378,12 +378,12 @@ public class DoubleGui extends Gui {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleGui updateItem(int row, int col, LegacyMaterials itemTo, String title, String... lore) {
|
||||
public DoubleGui updateItem(int row, int col, CompatibleMaterial itemTo, String title, String... lore) {
|
||||
return (DoubleGui) super.updateItem(col + row * 9, itemTo, title, lore);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleGui updateItem(int cell, LegacyMaterials itemTo, String title, String... lore) {
|
||||
public DoubleGui updateItem(int cell, CompatibleMaterial itemTo, String title, String... lore) {
|
||||
return (DoubleGui) super.updateItem(cell, itemTo, title, lore);
|
||||
}
|
||||
|
||||
@ -398,12 +398,12 @@ public class DoubleGui extends Gui {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleGui updateItem(int row, int col, LegacyMaterials itemTo, String title, List<String> lore) {
|
||||
public DoubleGui updateItem(int row, int col, CompatibleMaterial itemTo, String title, List<String> lore) {
|
||||
return (DoubleGui) super.updateItem(col + row * 9, itemTo, title, lore);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleGui updateItem(int cell, LegacyMaterials itemTo, String title, List<String> lore) {
|
||||
public DoubleGui updateItem(int cell, CompatibleMaterial itemTo, String title, List<String> lore) {
|
||||
return (DoubleGui) super.updateItem(cell, itemTo, title, lore);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.core.gui;
|
||||
|
||||
import com.songoda.core.compatibility.LegacyMaterials;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.gui.events.GuiClickEvent;
|
||||
import com.songoda.core.gui.events.GuiCloseEvent;
|
||||
import com.songoda.core.gui.events.GuiDropItemEvent;
|
||||
@ -330,6 +330,48 @@ public class Gui {
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui updateItemLore(int row, int col, @NotNull String... lore) {
|
||||
return updateItemLore(col + row * 9, lore);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui updateItemLore(int cell, @NotNull String... lore) {
|
||||
ItemStack item = cellItems.get(cell);
|
||||
if (item != null && item.getType() != Material.AIR) {
|
||||
setItem(cell, GuiUtils.updateItemLore(item, lore));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui updateItemLore(int row, int col, @Nullable List<String> lore) {
|
||||
return updateItemLore(col + row * 9, lore);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui updateItemLore(int cell, @Nullable List<String> lore) {
|
||||
ItemStack item = cellItems.get(cell);
|
||||
if (item != null && item.getType() != Material.AIR) {
|
||||
setItem(cell, GuiUtils.updateItemLore(item, lore));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui updateItemName(int row, int col, @Nullable String name) {
|
||||
return updateItemName(col + row * 9, name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui updateItemName(int cell, @Nullable String name) {
|
||||
ItemStack item = cellItems.get(cell);
|
||||
if (item != null && item.getType() != Material.AIR) {
|
||||
setItem(cell, GuiUtils.updateItemName(item, name));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui updateItem(int row, int col, @Nullable String name, @NotNull String... lore) {
|
||||
return updateItem(col + row * 9, name, lore);
|
||||
@ -373,12 +415,12 @@ public class Gui {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui updateItem(int row, int col, @NotNull LegacyMaterials itemTo, @Nullable String title, @NotNull String... lore) {
|
||||
public Gui updateItem(int row, int col, @NotNull CompatibleMaterial itemTo, @Nullable String title, @NotNull String... lore) {
|
||||
return updateItem(col + row * 9, itemTo, title, lore);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui updateItem(int cell, @NotNull LegacyMaterials itemTo, @Nullable String title, @Nullable String... lore) {
|
||||
public Gui updateItem(int cell, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable String... lore) {
|
||||
ItemStack item = cellItems.get(cell);
|
||||
if (item != null && item.getType() != Material.AIR) {
|
||||
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
|
||||
@ -401,12 +443,12 @@ public class Gui {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui updateItem(int row, int col, @NotNull LegacyMaterials itemTo, @Nullable String title, @Nullable List<String> lore) {
|
||||
public Gui updateItem(int row, int col, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
|
||||
return updateItem(col + row * 9, itemTo, title, lore);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui updateItem(int cell, @NotNull LegacyMaterials itemTo, @Nullable String title, @Nullable List<String> lore) {
|
||||
public Gui updateItem(int cell, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
|
||||
ItemStack item = cellItems.get(cell);
|
||||
if (item != null && item.getType() != Material.AIR) {
|
||||
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
|
||||
@ -594,7 +636,7 @@ public class Gui {
|
||||
}
|
||||
|
||||
public void setPage(int page) {
|
||||
int lastPage = page;
|
||||
int lastPage = this.page;
|
||||
this.page = Math.max(1, Math.min(pages, page));
|
||||
if(pager != null && this.page != lastPage) {
|
||||
pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page));
|
@ -1,8 +1,8 @@
|
||||
package com.songoda.core.gui;
|
||||
|
||||
import com.songoda.core.compatibility.ClientVersion;
|
||||
import com.songoda.core.compatibility.CompatibleSounds;
|
||||
import com.songoda.core.compatibility.LegacyMaterials;
|
||||
import com.songoda.core.compatibility.CompatibleSound;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -74,36 +74,55 @@ public class GuiManager {
|
||||
*/
|
||||
public void showGUI(Player player, Gui gui) {
|
||||
if (shutdown) {
|
||||
return;
|
||||
if(plugin.isEnabled()) {
|
||||
// recover if reloaded without calling init manually
|
||||
init();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else if (!initialized) {
|
||||
init();
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
if (gui instanceof AnvilGui) {
|
||||
// bukkit throws a fit now if you try to set anvil stuff asynchronously
|
||||
Gui openInv = openInventories.get(player);
|
||||
if (openInv != null) {
|
||||
openInv.open = false;
|
||||
}
|
||||
Inventory inv = gui.getOrCreateInventory(this);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
player.openInventory(inv);
|
||||
gui.onOpen(this, player);
|
||||
synchronized(lock) {
|
||||
openInventories.put(player, gui);
|
||||
gui.getOrCreateInventory(this);
|
||||
((AnvilGui) gui).open();
|
||||
gui.onOpen(this, player);
|
||||
synchronized (lock) {
|
||||
openInventories.put(player, gui);
|
||||
}
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
Gui openInv = openInventories.get(player);
|
||||
if (openInv != null) {
|
||||
openInv.open = false;
|
||||
}
|
||||
Inventory inv = gui.getOrCreateInventory(this);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
player.openInventory(inv);
|
||||
gui.onOpen(this, player);
|
||||
synchronized(lock) {
|
||||
openInventories.put(player, gui);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void showPopup(Player player, String message) {
|
||||
showPopup(player, message, LegacyMaterials.NETHER_STAR, BackgroundType.ADVENTURE);
|
||||
showPopup(player, message, CompatibleMaterial.NETHER_STAR, BackgroundType.ADVENTURE);
|
||||
}
|
||||
|
||||
public void showPopup(Player player, String message, LegacyMaterials icon) {
|
||||
public void showPopup(Player player, String message, CompatibleMaterial icon) {
|
||||
showPopup(player, message, icon, BackgroundType.ADVENTURE);
|
||||
}
|
||||
|
||||
public void showPopup(Player player, String message, LegacyMaterials icon, BackgroundType background) {
|
||||
if (ClientVersion.getClientVersion(player).isServerVersionAtLeast(ServerVersion.V1_12)) {
|
||||
public void showPopup(Player player, String message, CompatibleMaterial icon, BackgroundType background) {
|
||||
if (ClientVersion.getClientVersion(player).isAtLeast(ServerVersion.V1_12)) {
|
||||
PopupMessage popup = new PopupMessage(plugin, icon, message, background);
|
||||
popup.add();
|
||||
popup.grant(player);
|
||||
@ -176,12 +195,12 @@ public class GuiManager {
|
||||
event.setCancelled(!gui.unlockedCells.entrySet().stream().anyMatch(e -> event.getSlot() == e.getKey() && e.getValue()));
|
||||
// process button press
|
||||
if (gui.onClick(manager, player, openInv, event)) {
|
||||
player.playSound(player.getLocation(), CompatibleSounds.UI_BUTTON_CLICK.getSound(), 1F, 1F);
|
||||
player.playSound(player.getLocation(), CompatibleSound.UI_BUTTON_CLICK.getSound(), 1F, 1F);
|
||||
}
|
||||
} else {
|
||||
// Player clicked in the bottom inventory while GUI is open
|
||||
if (gui.onClickPlayerInventory(manager, player, openInv, event)) {
|
||||
player.playSound(player.getLocation(), CompatibleSounds.UI_BUTTON_CLICK.getSound(), 1F, 1F);
|
||||
player.playSound(player.getLocation(), CompatibleSound.UI_BUTTON_CLICK.getSound(), 1F, 1F);
|
||||
} else if (!gui.acceptsItems || event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@ -195,7 +214,11 @@ public class GuiManager {
|
||||
if (openInv.getHolder() != null && openInv.getHolder() instanceof GuiHolder
|
||||
&& ((GuiHolder) openInv.getHolder()).manager.uuid.equals(manager.uuid)) {
|
||||
Gui gui = ((GuiHolder) openInv.getHolder()).getGUI();
|
||||
if(!gui.open) {
|
||||
if (gui instanceof AnvilGui) {
|
||||
gui.inventory.clear();
|
||||
gui.inventory = null;
|
||||
}
|
||||
if (!gui.open) {
|
||||
return;
|
||||
}
|
||||
final Player player = (Player) event.getPlayer();
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.core.gui;
|
||||
|
||||
import com.songoda.core.compatibility.LegacyMaterials;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@ -16,7 +16,7 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
public class GuiUtils {
|
||||
|
||||
public static ItemStack getBorderGlassItem() {
|
||||
ItemStack glass = LegacyMaterials.LIGHT_BLUE_STAINED_GLASS_PANE.getItem();
|
||||
ItemStack glass = CompatibleMaterial.LIGHT_BLUE_STAINED_GLASS_PANE.getItem();
|
||||
ItemMeta glassmeta = glass.getItemMeta();
|
||||
glassmeta.setDisplayName(ChatColor.BLACK.toString());
|
||||
glass.setItemMeta(glassmeta);
|
||||
@ -30,7 +30,7 @@ public class GuiUtils {
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack getBorderItem(LegacyMaterials mat) {
|
||||
public static ItemStack getBorderItem(CompatibleMaterial mat) {
|
||||
ItemStack item = mat.getItem();
|
||||
ItemMeta glassmeta = item.getItemMeta();
|
||||
glassmeta.setDisplayName(ChatColor.BLACK.toString());
|
||||
@ -88,7 +88,7 @@ public class GuiUtils {
|
||||
return newLore;
|
||||
}
|
||||
|
||||
public static ItemStack createButtonItem(LegacyMaterials mat, String title, String... lore) {
|
||||
public static ItemStack createButtonItem(CompatibleMaterial mat, String title, String... lore) {
|
||||
ItemStack item = mat.getItem();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta != null) {
|
||||
@ -103,7 +103,7 @@ public class GuiUtils {
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack createButtonItem(LegacyMaterials mat, int amount, String title, String... lore) {
|
||||
public static ItemStack createButtonItem(CompatibleMaterial mat, int amount, String title, String... lore) {
|
||||
ItemStack item = mat.getItem();
|
||||
item.setAmount(amount);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
@ -129,12 +129,12 @@ public class GuiUtils {
|
||||
} else {
|
||||
meta.setLore(Collections.EMPTY_LIST);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack createButtonItem(LegacyMaterials mat, String title, List<String> lore) {
|
||||
public static ItemStack createButtonItem(CompatibleMaterial mat, String title, List<String> lore) {
|
||||
ItemStack item = mat.getItem();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta != null) {
|
||||
@ -144,12 +144,12 @@ public class GuiUtils {
|
||||
} else {
|
||||
meta.setLore(Collections.EMPTY_LIST);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack createButtonItem(LegacyMaterials mat, int amount, String title, List<String> lore) {
|
||||
public static ItemStack createButtonItem(CompatibleMaterial mat, int amount, String title, List<String> lore) {
|
||||
ItemStack item = mat.getItem();
|
||||
item.setAmount(amount);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
@ -160,8 +160,8 @@ public class GuiUtils {
|
||||
} else {
|
||||
meta.setLore(Collections.EMPTY_LIST);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@ -175,8 +175,8 @@ public class GuiUtils {
|
||||
} else {
|
||||
meta.setLore(Collections.EMPTY_LIST);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@ -189,12 +189,47 @@ public class GuiUtils {
|
||||
} else {
|
||||
meta.setLore(Collections.EMPTY_LIST);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack updateItem(ItemStack item, LegacyMaterials matTo, String title, String... lore) {
|
||||
public static ItemStack updateItemName(ItemStack item, String title) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta != null) {
|
||||
meta.setDisplayName(title);
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack updateItemLore(ItemStack item, String... lore) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta != null) {
|
||||
if (lore != null && lore.length != 0) {
|
||||
meta.setLore(getSafeLore(lore));
|
||||
} else {
|
||||
meta.setLore(Collections.EMPTY_LIST);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack updateItemLore(ItemStack item, List<String> lore) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta != null) {
|
||||
if (lore != null) {
|
||||
meta.setLore(getSafeLore(lore));
|
||||
} else {
|
||||
meta.setLore(Collections.EMPTY_LIST);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack updateItem(ItemStack item, CompatibleMaterial matTo, String title, String... lore) {
|
||||
if (!matTo.matches(item)) {
|
||||
item = matTo.getItem();
|
||||
}
|
||||
@ -206,13 +241,13 @@ public class GuiUtils {
|
||||
} else {
|
||||
meta.setLore(Collections.EMPTY_LIST);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack updateItem(ItemStack item, ItemStack to, String title, String... lore) {
|
||||
if (!LegacyMaterials.getMaterial(item).matches(to)) {
|
||||
if (!CompatibleMaterial.getMaterial(item).matches(to)) {
|
||||
item = to.clone();
|
||||
}
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
@ -223,8 +258,8 @@ public class GuiUtils {
|
||||
} else {
|
||||
meta.setLore(Collections.EMPTY_LIST);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@ -237,12 +272,12 @@ public class GuiUtils {
|
||||
} else {
|
||||
meta.setLore(Collections.EMPTY_LIST);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack updateItem(ItemStack item, LegacyMaterials matTo, String title, List<String> lore) {
|
||||
public static ItemStack updateItem(ItemStack item, CompatibleMaterial matTo, String title, List<String> lore) {
|
||||
if (!matTo.matches(item)) {
|
||||
item = matTo.getItem();
|
||||
}
|
||||
@ -254,13 +289,13 @@ public class GuiUtils {
|
||||
} else {
|
||||
meta.setLore(Collections.EMPTY_LIST);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack updateItem(ItemStack item, ItemStack to, String title, List<String> lore) {
|
||||
if (!LegacyMaterials.getMaterial(item).matches(to)) {
|
||||
if (!CompatibleMaterial.getMaterial(item).matches(to)) {
|
||||
item = to.clone();
|
||||
}
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
@ -271,8 +306,8 @@ public class GuiUtils {
|
||||
} else {
|
||||
meta.setLore(Collections.EMPTY_LIST);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.songoda.core.compatibility.LegacyMaterials;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
@ -30,19 +30,18 @@ class PopupMessage {
|
||||
final UUID id = UUID.randomUUID();
|
||||
private final NamespacedKey key;
|
||||
private final TextComponent title;
|
||||
LegacyMaterials icon;
|
||||
int iconAmount = 1; // experimental, untested
|
||||
CompatibleMaterial icon;
|
||||
TriggerType trigger = TriggerType.IMPOSSIBLE;
|
||||
FrameType frame = FrameType.GOAL;
|
||||
FrameType frame = FrameType.GOAL; // TASK is the default
|
||||
BackgroundType background = BackgroundType.ADVENTURE;
|
||||
|
||||
PopupMessage(Plugin source, LegacyMaterials icon, String title) {
|
||||
PopupMessage(Plugin source, CompatibleMaterial icon, String title) {
|
||||
this.key = new NamespacedKey(source, "popup/" + id);
|
||||
this.title = new TextComponent(title.length() < 74 ? title : (title.substring(0, 72) + "..."));
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
PopupMessage(Plugin source, LegacyMaterials icon, String title, BackgroundType background) {
|
||||
PopupMessage(Plugin source, CompatibleMaterial icon, String title, BackgroundType background) {
|
||||
this.key = new NamespacedKey(source, "popup/" + id);
|
||||
this.title = new TextComponent(title.length() < 74 ? title : (title.substring(0, 72) + "..."));
|
||||
this.icon = icon;
|
||||
@ -58,9 +57,6 @@ class PopupMessage {
|
||||
if (this.icon.usesData()) {
|
||||
displayIcon.addProperty("data", this.icon.getData());
|
||||
}
|
||||
if (this.iconAmount > 1) {
|
||||
displayIcon.addProperty("amount", this.iconAmount); // not entirely sure if this works
|
||||
}
|
||||
advDisplay.add("icon", displayIcon);
|
||||
}
|
||||
advDisplay.add("title", gson.fromJson(ComponentSerializer.toString(this.title), JsonElement.class));
|
@ -1,13 +1,12 @@
|
||||
package com.songoda.core.gui;
|
||||
|
||||
import com.songoda.core.compatibility.LegacyMaterials;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import static com.songoda.core.gui.Gui.trimTitle;
|
||||
import com.songoda.core.gui.events.GuiClickEvent;
|
||||
import com.songoda.core.gui.methods.Clickable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
@ -35,8 +34,8 @@ public class SimplePagedGui extends Gui {
|
||||
public SimplePagedGui(Gui parent) {
|
||||
super(parent);
|
||||
|
||||
nextPage = GuiUtils.createButtonItem(LegacyMaterials.ARROW, "Next Page");
|
||||
prevPage = GuiUtils.createButtonItem(LegacyMaterials.ARROW, "Previous Page");
|
||||
nextPage = GuiUtils.createButtonItem(CompatibleMaterial.ARROW, "Next Page");
|
||||
prevPage = GuiUtils.createButtonItem(CompatibleMaterial.ARROW, "Previous Page");
|
||||
}
|
||||
|
||||
public SimplePagedGui setUseHeader(boolean useHeader) {
|
||||
@ -134,14 +133,14 @@ public class SimplePagedGui extends Gui {
|
||||
rowsPerPage = useHeader ? 4 : 5;
|
||||
maxCellSlot = (this.cellItems.isEmpty() ? 0 : this.cellItems.keySet().stream().max(Integer::compare).get()) + 1;
|
||||
int maxRows = (int) Math.ceil(maxCellSlot / 9.);
|
||||
pages = (int) Math.ceil(maxRows / rowsPerPage);
|
||||
pages = (int) Math.max(1, Math.ceil(maxRows / (double) rowsPerPage));
|
||||
this.setRows(maxRows + (useHeader ? 1 : 0));
|
||||
|
||||
// create inventory view
|
||||
createInventory();
|
||||
|
||||
// populate and return the display inventory
|
||||
page = Math.min(page, pages);
|
||||
setPage(Math.min(page, pages));
|
||||
update();
|
||||
return inventory;
|
||||
}
|
@ -26,6 +26,16 @@ public class HologramManager {
|
||||
return manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if there is a default holograms hook loaded. <br />
|
||||
* NOTE: using a default hologram assumes that this library is shaded
|
||||
*
|
||||
* @return returns false if there are no supported hologram plugins
|
||||
*/
|
||||
public static boolean isEnabled() {
|
||||
return manager.isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab the default hologram plugin. <br />
|
||||
* NOTE: using a default hologram assumes that this library is shaded
|
@ -4,6 +4,7 @@ import com.songoda.core.hooks.economies.Economy;
|
||||
import com.songoda.core.hooks.economies.PlayerPointsEconomy;
|
||||
import com.songoda.core.hooks.economies.ReserveEconomy;
|
||||
import com.songoda.core.hooks.economies.VaultEconomy;
|
||||
import com.songoda.core.hooks.holograms.CMIHolograms;
|
||||
import com.songoda.core.hooks.stackers.StackMob;
|
||||
import com.songoda.core.hooks.stackers.Stacker;
|
||||
import com.songoda.core.hooks.stackers.UltimateStacker;
|
||||
@ -33,6 +34,7 @@ public final class PluginHook <T extends Class> {
|
||||
public static final PluginHook STACKER_STACK_MOB = new PluginHook(Stacker.class, "StackMob", StackMob.class);
|
||||
public static final PluginHook HOLO_DISPLAYS = new PluginHook(Holograms.class, "HolographicDisplays", HolographicDisplaysHolograms.class);
|
||||
public static final PluginHook HOLO_HOLOGRAMS = new PluginHook(Holograms.class, "Holograms", HologramsHolograms.class);
|
||||
public static final PluginHook HOLO_CMI = new PluginHook(Holograms.class, "CMI", CMIHolograms.class);
|
||||
|
||||
/******* Start Manager stuff *******/
|
||||
|
@ -6,19 +6,15 @@ import org.bukkit.Location;
|
||||
|
||||
public class WorldGuardHook {
|
||||
|
||||
static boolean canHook, checkedCanHook = false;
|
||||
|
||||
private static void init() {
|
||||
if(checkedCanHook) return;
|
||||
static boolean canHook = false;
|
||||
|
||||
static {
|
||||
try {
|
||||
// if this class exists, we're good to use WG classes
|
||||
Class.forName("com.sk89q.worldguard.protection.flags.Flag");
|
||||
canHook = true;
|
||||
} catch (ClassNotFoundException ex) {
|
||||
}
|
||||
|
||||
checkedCanHook = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -29,7 +25,6 @@ public class WorldGuardHook {
|
||||
* @param state default value of the flag
|
||||
*/
|
||||
public static void addHook(String flag, boolean state) {
|
||||
init();
|
||||
if(canHook) {
|
||||
WorldGuardFlagHandler.addHook(flag, state);
|
||||
}
|
||||
@ -42,7 +37,6 @@ public class WorldGuardHook {
|
||||
* called and added successfully
|
||||
*/
|
||||
public static boolean isEnabled() {
|
||||
init();
|
||||
return canHook && WorldGuardFlagHandler.isEnabled();
|
||||
}
|
||||
|
||||
@ -54,7 +48,6 @@ public class WorldGuardHook {
|
||||
* @return flag state, or null if undefined
|
||||
*/
|
||||
public static Boolean getBooleanFlag(Location l, String flag) {
|
||||
init();
|
||||
return canHook ? WorldGuardFlagHandler.getBooleanFlag(l, flag) : null;
|
||||
}
|
||||
|
||||
@ -66,7 +59,6 @@ public class WorldGuardHook {
|
||||
* @return flag state, or null if undefined
|
||||
*/
|
||||
public static Boolean getBooleanFlag(Chunk c, String flag) {
|
||||
init();
|
||||
return canHook ? WorldGuardFlagHandler.getBooleanFlag(c, flag) : null;
|
||||
}
|
||||
}
|
@ -0,0 +1,135 @@
|
||||
package com.songoda.core.hooks.holograms;
|
||||
|
||||
import com.Zrips.CMI.CMI;
|
||||
import com.Zrips.CMI.Modules.Holograms.CMIHologram;
|
||||
import com.Zrips.CMI.Modules.Holograms.HologramManager;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class CMIHolograms extends Holograms {
|
||||
|
||||
CMI cmi;
|
||||
HologramManager cmiHologramManager;
|
||||
HashSet<String> ourHolograms = new HashSet();
|
||||
Method cmi_CMIHologram_getLines;
|
||||
|
||||
{
|
||||
try {
|
||||
// test if we need to watch if the lines is an array
|
||||
if (CMIHologram.class.getDeclaredField("lines").getDeclaringClass() == String[].class) {
|
||||
cmi_CMIHologram_getLines = CMIHologram.class.getMethod("getLines");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
|
||||
public CMIHolograms(Plugin plugin) {
|
||||
super(plugin);
|
||||
cmi = (CMI) Bukkit.getPluginManager().getPlugin("CMI");
|
||||
if (cmi != null) {
|
||||
cmiHologramManager = cmi.getHologramManager();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "CMI";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return cmi != null && cmi.isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double defaultHeightOffset() {
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createHologram(Location location, List<String> lines) {
|
||||
createAt(fixLocation(location), lines);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHologram(Location location) {
|
||||
location = fixLocation(location);
|
||||
final String id = locStr(location);
|
||||
CMIHologram holo = cmiHologramManager.getByName(id);
|
||||
if (holo != null) {
|
||||
cmiHologramManager.removeHolo(holo);
|
||||
}
|
||||
ourHolograms.remove(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAllHolograms() {
|
||||
for (String id : ourHolograms) {
|
||||
CMIHologram holo = cmiHologramManager.getByName(id);
|
||||
if (holo != null) {
|
||||
cmiHologramManager.removeHolo(holo);
|
||||
}
|
||||
}
|
||||
ourHolograms.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateHologram(Location location, List<String> lines) {
|
||||
location = fixLocation(location);
|
||||
CMIHologram holo = cmiHologramManager.getByName(locStr(location));
|
||||
if (holo != null) {
|
||||
// only update if there is a change to the text
|
||||
List<String> holoLines;
|
||||
if (cmi_CMIHologram_getLines != null) {
|
||||
try {
|
||||
holoLines = Arrays.asList((String[]) cmi_CMIHologram_getLines.invoke(holo));
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(CMIHolograms.class.getName()).log(Level.SEVERE, "CMI Hologram error!", ex);
|
||||
holoLines = Collections.EMPTY_LIST;
|
||||
}
|
||||
} else {
|
||||
holoLines = holo.getLines();
|
||||
}
|
||||
boolean isChanged = lines.size() != holoLines.size();
|
||||
if (!isChanged) {
|
||||
// double-check the lines
|
||||
for (int i = 0; !isChanged && i < lines.size(); ++i) {
|
||||
isChanged = !holo.getLine(i).equals(lines.get(i));
|
||||
}
|
||||
}
|
||||
if (isChanged) {
|
||||
holo.setLines(lines);
|
||||
holo.update();
|
||||
}
|
||||
return;
|
||||
}
|
||||
createAt(location, lines);
|
||||
}
|
||||
|
||||
private String locStr(Location loc) {
|
||||
return String.format("%s-%d-%d-%d", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
}
|
||||
|
||||
private void createAt(Location location, List<String> lines) {
|
||||
|
||||
final String id = locStr(location);
|
||||
CMIHologram holo = new CMIHologram(id, location);
|
||||
holo.setLines(lines);
|
||||
|
||||
cmiHologramManager.addHologram(holo);
|
||||
holo.update();
|
||||
|
||||
if (!ourHolograms.contains(id)) {
|
||||
ourHolograms.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -5,11 +5,10 @@ import com.sainttx.holograms.api.HologramPlugin;
|
||||
import com.sainttx.holograms.api.line.HologramLine;
|
||||
import com.sainttx.holograms.api.line.TextLine;
|
||||
import java.util.HashSet;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class HologramsHolograms extends Holograms {
|
||||
|
||||
@ -70,11 +69,22 @@ public class HologramsHolograms extends Holograms {
|
||||
location = fixLocation(location);
|
||||
Hologram hologram = hologramPlugin.getHologramManager().getHologram(locStr(location));
|
||||
if (hologram != null) {
|
||||
for(HologramLine line : hologram.getLines().toArray(new HologramLine[0])) {
|
||||
hologram.removeLine(line);
|
||||
hologram.spawn();
|
||||
// only update if there is a change to the text
|
||||
boolean isChanged = lines.size() != hologram.getLines().size();
|
||||
if(!isChanged) {
|
||||
// double-check the lines
|
||||
for(int i = 0; !isChanged && i < lines.size(); ++i) {
|
||||
isChanged = !hologram.getLine(i).getRaw().equals(lines.get(i));
|
||||
}
|
||||
}
|
||||
for (String line : lines) {
|
||||
hologram.addLine(new TextLine(hologram, line));
|
||||
if(isChanged) {
|
||||
for(HologramLine line : hologram.getLines().toArray(new HologramLine[0])) {
|
||||
hologram.removeLine(line);
|
||||
}
|
||||
for (String line : lines) {
|
||||
hologram.addLine(new TextLine(hologram, line));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
@ -51,9 +51,19 @@ public class HolographicDisplaysHolograms extends Holograms {
|
||||
if (hologram.getX() != location.getX()
|
||||
|| hologram.getY() != location.getY()
|
||||
|| hologram.getZ() != location.getZ()) continue;
|
||||
hologram.clearLines();
|
||||
for (String line : lines) {
|
||||
hologram.appendTextLine(line);
|
||||
// only update if there is a change to the text
|
||||
boolean isChanged = lines.size() != hologram.size();
|
||||
if(!isChanged) {
|
||||
// double-check the lines
|
||||
for(int i = 0; !isChanged && i < lines.size(); ++i) {
|
||||
isChanged = !hologram.getLine(i).toString().equals("CraftTextLine [text=" + lines.get(i) + "]");
|
||||
}
|
||||
}
|
||||
if(isChanged) {
|
||||
hologram.clearLines();
|
||||
for (String line : lines) {
|
||||
hologram.appendTextLine(line);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
@ -33,6 +33,7 @@ public class WorldGuardFlagHandler {
|
||||
|
||||
static Boolean wgPlugin = null;
|
||||
static Object worldGuardPlugin;
|
||||
static boolean wg_v7 = false;
|
||||
static boolean legacy_v6 = false;
|
||||
static boolean legacy_v5 = false;
|
||||
static boolean hooksInstalled = false;
|
||||
@ -47,18 +48,24 @@ public class WorldGuardFlagHandler {
|
||||
*/
|
||||
public static void addHook(String flag, boolean state) {
|
||||
if (wgPlugin == null && (wgPlugin = (worldGuardPlugin = Bukkit.getPluginManager().getPlugin("WorldGuard")) != null)) {
|
||||
// a number of flags were introduced in 7.x that aren't in 5 or 6
|
||||
try {
|
||||
// if this class exists, we're on 6.0
|
||||
Class.forName("com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry");
|
||||
legacy_v6 = true;
|
||||
// if this class exists, we're on 7.x
|
||||
Class.forName("com.sk89q.worldguard.protection.flags.WeatherTypeFlag");
|
||||
wg_v7 = true;
|
||||
} catch (ClassNotFoundException ex) {
|
||||
}
|
||||
if(!legacy_v6) {
|
||||
try {
|
||||
// if this class exists, we're on 5.x
|
||||
Class.forName("com.sk89q.worldguard.protection.flags.DefaultFlag");
|
||||
legacy_v5 = true;
|
||||
} catch (ClassNotFoundException ex) {
|
||||
// if this class exists, we're on 6.0
|
||||
Class.forName("com.sk89q.worldguard.protection.flags.FlagContextCreateEvent");
|
||||
legacy_v6 = true;
|
||||
} catch (ClassNotFoundException ex2) {
|
||||
try {
|
||||
// if this class exists, we're on 5.x
|
||||
Class.forName("com.sk89q.worldguard.protection.flags.DefaultFlag");
|
||||
legacy_v5 = true;
|
||||
} catch (ClassNotFoundException ex3) {
|
||||
// ¯\_(ツ)_/¯
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -130,7 +137,7 @@ public class WorldGuardFlagHandler {
|
||||
flags.put(flag, wgFlag);
|
||||
} catch (Exception ex) {
|
||||
//Bukkit.getServer().getLogger().log(Level.WARNING, "Failed to set legacy WorldGuard Flags", ex);
|
||||
Bukkit.getServer().getLogger().log(Level.WARNING, "Could not add flag {0} to WorldGuard", flag);
|
||||
Bukkit.getServer().getLogger().log(Level.WARNING, "Could not add flag {0} to WorldGuard " + (legacy_v6 ? "6" : "5"), flag);
|
||||
Bukkit.getServer().getLogger().log(Level.WARNING, "Could not hook WorldGuard");
|
||||
wgPlugin = false;
|
||||
}
|
55
Core/src/main/java/com/songoda/core/nms/NmsManager.java
Normal file
55
Core/src/main/java/com/songoda/core/nms/NmsManager.java
Normal file
@ -0,0 +1,55 @@
|
||||
package com.songoda.core.nms;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class NmsManager {
|
||||
|
||||
private final static String serverPackagePath = Bukkit.getServer().getClass().getPackage().getName();
|
||||
private final static String serverPackageVersion = serverPackagePath.substring(serverPackagePath.lastIndexOf('.') + 1);
|
||||
private final static CoreNMS nms = _getNMS();
|
||||
|
||||
private static CoreNMS _getNMS() {
|
||||
// try {
|
||||
// return (CoreNMS) Class.forName("com.songoda.core.nms." + serverPackageVersion + ".NMS").newInstance();
|
||||
// } catch (Exception ex) {
|
||||
// Logger.getLogger(NmsManager.class.getName()).log(Level.SEVERE, "Failed to load NMS for this server version", ex);
|
||||
// }
|
||||
// this block was only added to keep minimizeJar happy
|
||||
switch (serverPackageVersion) {
|
||||
case "v1_8_R1":
|
||||
return new com.songoda.core.nms.v1_8_R1.NMS();
|
||||
case "v1_8_R2":
|
||||
return new com.songoda.core.nms.v1_8_R2.NMS();
|
||||
case "v1_8_R3":
|
||||
return new com.songoda.core.nms.v1_8_R3.NMS();
|
||||
case "v1_9_R1":
|
||||
return new com.songoda.core.nms.v1_9_R1.NMS();
|
||||
case "v1_9_R2":
|
||||
return new com.songoda.core.nms.v1_9_R2.NMS();
|
||||
case "v1_10_R1":
|
||||
return new com.songoda.core.nms.v1_10_R1.NMS();
|
||||
case "v1_11_R1":
|
||||
return new com.songoda.core.nms.v1_11_R1.NMS();
|
||||
case "v1_12_R1":
|
||||
return new com.songoda.core.nms.v1_12_R1.NMS();
|
||||
case "v1_13_R1":
|
||||
return new com.songoda.core.nms.v1_13_R1.NMS();
|
||||
case "v1_13_R2":
|
||||
return new com.songoda.core.nms.v1_13_R2.NMS();
|
||||
case "v1_14_R1":
|
||||
return new com.songoda.core.nms.v1_14_R1.NMS();
|
||||
}
|
||||
Logger.getLogger(NmsManager.class.getName()).log(Level.SEVERE, "Failed to load NMS for this server version: version {0} not found", serverPackageVersion);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static CoreNMS getNMS() {
|
||||
return nms;
|
||||
}
|
||||
|
||||
public static boolean hasNMS() {
|
||||
return nms != null;
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package com.songoda.core.utils;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.EnumSet;
|
||||
@ -7,11 +9,14 @@ import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.CropState;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.material.Crops;
|
||||
|
||||
public class BlockUtils {
|
||||
|
||||
@ -342,6 +347,136 @@ public class BlockUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a crop is at its max growth stage
|
||||
*
|
||||
* @param block The crop block to check
|
||||
* @return true if the block is a crop and at its max growth stage
|
||||
*/
|
||||
public static boolean isCropFullyGrown(Block block) {
|
||||
if (block == null) {
|
||||
return false;
|
||||
} else if (!useLegacy) {
|
||||
return BlockUtilsModern._isCropFullyGrown(block);
|
||||
}
|
||||
CompatibleMaterial mat = CompatibleMaterial.getMaterial(block.getType());
|
||||
if (mat == null || !mat.isCrop()) {
|
||||
return false;
|
||||
} else {
|
||||
return block.getData() >= (mat == CompatibleMaterial.BEETROOTS ? 3 : 7);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the max growth stage for the given block
|
||||
*
|
||||
* @param block The crop block to check
|
||||
* @return The max growth stage of the given crop type, or -1 if not a crop
|
||||
*/
|
||||
public static int getMaxGrowthStage(Block block) {
|
||||
if (block == null) {
|
||||
return -1;
|
||||
} else if (!useLegacy) {
|
||||
return BlockUtilsModern._getMaxGrowthStage(block);
|
||||
}
|
||||
CompatibleMaterial mat = CompatibleMaterial.getMaterial(block.getType());
|
||||
if (mat == null || !mat.isCrop()) {
|
||||
return -1;
|
||||
} else {
|
||||
return mat == CompatibleMaterial.BEETROOTS ? 3 : 7;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the max growth stage for the given material
|
||||
*
|
||||
* @param material The material of the crop
|
||||
* @return The max growth stage of the given crop type
|
||||
*/
|
||||
public static int getMaxGrowthStage(Material material) {
|
||||
if (material == null) {
|
||||
return -1;
|
||||
} else if (!useLegacy) {
|
||||
return BlockUtilsModern._getMaxGrowthStage(material);
|
||||
}
|
||||
CompatibleMaterial mat = CompatibleMaterial.getMaterial(material);
|
||||
if (mat == null || !mat.isCrop()) {
|
||||
return -1;
|
||||
} else {
|
||||
return mat == CompatibleMaterial.BEETROOTS ? 3 : 7;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the max growth stage for the given block
|
||||
*
|
||||
* @param block The crop block to change
|
||||
* @param stage new growth stage to use
|
||||
*/
|
||||
public static void setGrowthStage(Block block, int stage) {
|
||||
if (block == null) {
|
||||
} else if (!useLegacy) {
|
||||
BlockUtilsModern._setGrowthStage(block, stage);
|
||||
} else {
|
||||
CompatibleMaterial mat = CompatibleMaterial.getMaterial(block.getType());
|
||||
if (mat != null && mat.isCrop()) {
|
||||
try {
|
||||
legacySetBlockData.invoke(block, (byte) Math.max(0, Math.min(stage, mat == CompatibleMaterial.BEETROOTS ? 3 : 7)));
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Increments the growth stage for the given block
|
||||
*
|
||||
* @param block The crop block to grow
|
||||
*/
|
||||
public static void incrementGrowthStage(Block block) {
|
||||
if (block == null) {
|
||||
} else if (!useLegacy) {
|
||||
BlockUtilsModern._incrementGrowthStage(block);
|
||||
} else {
|
||||
CompatibleMaterial mat = CompatibleMaterial.getMaterial(block.getType());
|
||||
if (mat != null && mat.isCrop() && block.getData() < (mat == CompatibleMaterial.BEETROOTS ? 3 : 7)) {
|
||||
try {
|
||||
legacySetBlockData.invoke(block, (byte) block.getData() + 1);
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a crop's growth back to stage 0
|
||||
*
|
||||
* @param block The crop block to set
|
||||
*/
|
||||
public static void resetGrowthStage(Block block) {
|
||||
if (block == null) {
|
||||
} else if (!useLegacy) {
|
||||
BlockUtilsModern._resetGrowthStage(block);
|
||||
} else {
|
||||
CompatibleMaterial mat = CompatibleMaterial.getMaterial(block.getType());
|
||||
if (mat != null && mat.isCrop()) {
|
||||
try {
|
||||
legacySetBlockData.invoke(block, (byte) 0);
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if this material does not impede player/mob movement at all.
|
||||
*
|
||||
* @param m material to check
|
||||
* @return true if this material doesn't have a solid hitbox
|
||||
*/
|
||||
public static boolean canPassThrough(Material m) {
|
||||
|
||||
switch (m.name()) {
|
||||
@ -355,8 +490,6 @@ public class BlockUtils {
|
||||
case "ATTACHED_MELON_STEM":
|
||||
case "ATTACHED_PUMPKIN_STEM":
|
||||
case "AZURE_BLUET":
|
||||
//case "BAMBOO_SAPLING":
|
||||
//case "BARRIER": // could let robots pass through barriers
|
||||
case "BEETROOTS":
|
||||
case "BIRCH_BUTTON":
|
||||
case "BIRCH_PRESSURE_PLATE":
|
||||
@ -400,7 +533,7 @@ public class BlockUtils {
|
||||
case "DETECTOR_RAIL":
|
||||
case "END_PORTAL":
|
||||
case "FERN":
|
||||
case "FIRE": // probably should take damage
|
||||
case "FIRE":
|
||||
case "FIRE_CORAL_FAN":
|
||||
case "FIRE_CORAL_WALL_FAN":
|
||||
case "GRASS":
|
||||
@ -522,6 +655,13 @@ public class BlockUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if a player can walk into this material<br />
|
||||
* This includes blocks like slabs and stairs
|
||||
*
|
||||
* @param m material to check
|
||||
* @return true if this is a block that can be walked though or up
|
||||
*/
|
||||
public static boolean canWalkTo(Material m) {
|
||||
switch (m.name()) {
|
||||
case "ACACIA_BUTTON":
|
||||
@ -539,8 +679,6 @@ public class BlockUtils {
|
||||
case "ATTACHED_MELON_STEM":
|
||||
case "ATTACHED_PUMPKIN_STEM":
|
||||
case "AZURE_BLUET":
|
||||
//case "BAMBOO_SAPLING":
|
||||
//case "BARRIER": // could let robots pass through barriers
|
||||
case "BEETROOTS":
|
||||
case "BIRCH_BUTTON":
|
||||
case "BIRCH_DOOR":
|
||||
@ -569,7 +707,7 @@ public class BlockUtils {
|
||||
case "BUBBLE_CORAL_FAN":
|
||||
case "BUBBLE_CORAL_WALL_FAN":
|
||||
case "CAKE":
|
||||
case "CAMPFIRE": // could take damage from walking over?
|
||||
case "CAMPFIRE":
|
||||
case "CARROTS":
|
||||
case "CAVE_AIR":
|
||||
case "COBBLESTONE_SLAB":
|
||||
@ -614,7 +752,7 @@ public class BlockUtils {
|
||||
case "END_STONE_BRICK_SLAB":
|
||||
case "END_STONE_BRICK_STAIRS":
|
||||
case "FERN":
|
||||
case "FIRE": // probably should take damage
|
||||
case "FIRE":
|
||||
case "FIRE_CORAL_FAN":
|
||||
case "FIRE_CORAL_WALL_FAN":
|
||||
case "FLOWER_POT":
|
||||
@ -767,7 +905,7 @@ public class BlockUtils {
|
||||
case "SPRUCE_STAIRS":
|
||||
case "SPRUCE_TRAPDOOR":
|
||||
case "SPRUCE_WALL_SIGN":
|
||||
case "STONECUTTER": // technically can step on, so sure
|
||||
case "STONECUTTER":
|
||||
case "STONE_BRICK_SLAB":
|
||||
case "STONE_BRICK_STAIRS":
|
||||
case "STONE_BUTTON":
|
@ -1,8 +1,10 @@
|
||||
package com.songoda.core.utils;
|
||||
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.Ageable;
|
||||
import org.bukkit.block.data.Bisected;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.AnaloguePowerable;
|
||||
@ -158,4 +160,55 @@ public class BlockUtilsModern {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static boolean _isCropFullyGrown(Block block) {
|
||||
BlockData data = block.getBlockData();
|
||||
if(data instanceof Ageable) {
|
||||
return ((Ageable) data).getAge() == ((Ageable) data).getMaximumAge();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static int _getMaxGrowthStage(Block block) {
|
||||
BlockData data = block.getBlockData();
|
||||
if(data instanceof Ageable) {
|
||||
return ((Ageable) data).getMaximumAge();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
protected static int _getMaxGrowthStage(Material material) {
|
||||
BlockData data = material.createBlockData();
|
||||
if(data instanceof Ageable) {
|
||||
return ((Ageable) data).getMaximumAge();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static void _setGrowthStage(Block block, int stage) {
|
||||
BlockData data = block.getBlockData();
|
||||
if (data instanceof Ageable) {
|
||||
((Ageable) data).setAge(Math.max(0, Math.min(stage, ((Ageable) data).getMaximumAge())));
|
||||
block.setBlockData(data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void _incrementGrowthStage(Block block) {
|
||||
BlockData data = block.getBlockData();
|
||||
if (data instanceof Ageable) {
|
||||
final int max = ((Ageable) data).getMaximumAge();
|
||||
final int age = ((Ageable) data).getAge();
|
||||
if (age < max) {
|
||||
((Ageable) data).setAge(age + 1);
|
||||
block.setBlockData(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void _resetGrowthStage(Block block) {
|
||||
BlockData data = block.getBlockData();
|
||||
if (data instanceof Ageable) {
|
||||
((Ageable) data).setAge(0);
|
||||
block.setBlockData(data);
|
||||
}
|
||||
}
|
||||
}
|
@ -5,16 +5,19 @@ package com.songoda.core.utils;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.songoda.core.compatibility.LegacyMaterials;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Base64;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Stream;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
@ -243,7 +246,7 @@ public class ItemUtils {
|
||||
}
|
||||
|
||||
public static ItemStack getPlayerSkull(OfflinePlayer player) {
|
||||
ItemStack head = LegacyMaterials.PLAYER_HEAD.getItem();
|
||||
ItemStack head = CompatibleMaterial.PLAYER_HEAD.getItem();
|
||||
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) {
|
||||
return head;
|
||||
}
|
||||
@ -258,7 +261,7 @@ public class ItemUtils {
|
||||
}
|
||||
|
||||
public static void setHeadOwner(ItemStack head, OfflinePlayer player) {
|
||||
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8) || head == null || !LegacyMaterials.PLAYER_HEAD.matches(head)) {
|
||||
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8) || head == null || !CompatibleMaterial.PLAYER_HEAD.matches(head)) {
|
||||
return;
|
||||
}
|
||||
SkullMeta meta = (SkullMeta) head.getItemMeta();
|
||||
@ -270,7 +273,7 @@ public class ItemUtils {
|
||||
}
|
||||
|
||||
public static ItemStack getCustomHead(String texture) {
|
||||
ItemStack skullItem = LegacyMaterials.PLAYER_HEAD.getItem();
|
||||
ItemStack skullItem = CompatibleMaterial.PLAYER_HEAD.getItem();
|
||||
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) {
|
||||
return skullItem;
|
||||
}
|
||||
@ -297,6 +300,63 @@ public class ItemUtils {
|
||||
}
|
||||
}
|
||||
|
||||
static Class cb_CraftPlayer = NMSUtils.getCraftClass("entity.CraftPlayer");
|
||||
static Method cb_CraftPlayer_getProfile;
|
||||
|
||||
static {
|
||||
try {
|
||||
cb_CraftPlayer_getProfile = cb_CraftPlayer.getMethod("getProfile");
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getSkullTexture(Player player) {
|
||||
if (player == null || ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
|
||||
Object craftPlayer = cb_CraftPlayer.cast(player);
|
||||
|
||||
Iterator<Property> iterator = ((GameProfile) cb_CraftPlayer_getProfile.invoke(craftPlayer)).getProperties().get("textures").iterator();
|
||||
|
||||
return iterator.hasNext() ? iterator.next().getValue() : null;
|
||||
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static Field cb_SkullMeta_profile;
|
||||
|
||||
static {
|
||||
try {
|
||||
cb_SkullMeta_profile = SkullMeta.class.getDeclaredField("profile");
|
||||
cb_SkullMeta_profile.setAccessible(true);
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getSkullTexture(ItemStack item) {
|
||||
if (cb_SkullMeta_profile == null || !CompatibleMaterial.PLAYER_HEAD.matches(item) || ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
SkullMeta localSkullMeta = (SkullMeta) item.getItemMeta();
|
||||
GameProfile profile = (GameProfile) cb_SkullMeta_profile.get(localSkullMeta);
|
||||
Iterator<Property> iterator = profile.getProperties().get("textures").iterator();
|
||||
|
||||
return iterator.hasNext() ? iterator.next().getValue() : null;
|
||||
} catch (IllegalArgumentException | IllegalAccessException ex) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getDecodedTexture(String encoded) {
|
||||
return encoded != null ? StringUtils.substringBetween(new String(Base64.getDecoder().decode(encoded)), "texture/", "\"") : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use up whatever item the player is holding in their main hand
|
||||
*
|
||||
@ -332,8 +392,8 @@ public class ItemUtils {
|
||||
* @return true if both items are of the same material
|
||||
*/
|
||||
public static boolean isSimilarMaterial(ItemStack is1, ItemStack is2) {
|
||||
LegacyMaterials mat1 = LegacyMaterials.getMaterial(is1);
|
||||
return mat1 != null && mat1 == LegacyMaterials.getMaterial(is2);
|
||||
CompatibleMaterial mat1 = CompatibleMaterial.getMaterial(is1);
|
||||
return mat1 != null && mat1 == CompatibleMaterial.getMaterial(is2);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -610,7 +670,7 @@ public class ItemUtils {
|
||||
|
||||
check = new boolean[3];
|
||||
|
||||
boolean isFuel = !item.getType().name().contains("LOG") && LegacyMaterials.getMaterial(item.getType()).isFuel();
|
||||
boolean isFuel = !item.getType().name().contains("LOG") && CompatibleMaterial.getMaterial(item.getType()).isFuel();
|
||||
// fuel is 2nd slot, input is first
|
||||
if (isFuel) {
|
||||
|
||||
@ -800,7 +860,7 @@ public class ItemUtils {
|
||||
|
||||
check = new boolean[3];
|
||||
|
||||
boolean isFuel = !item.getType().name().contains("LOG") && LegacyMaterials.getMaterial(item.getType()).isFuel();
|
||||
boolean isFuel = !item.getType().name().contains("LOG") && CompatibleMaterial.getMaterial(item.getType()).isFuel();
|
||||
// fuel is 2nd slot, input is first
|
||||
if (isFuel) {
|
||||
|
@ -3,11 +3,15 @@ package com.songoda.core.utils;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class PlayerUtils {
|
||||
|
||||
@ -146,4 +150,38 @@ public class PlayerUtils {
|
||||
}
|
||||
return alli.hasNext() ? alli.next() : null;
|
||||
}
|
||||
|
||||
public static void giveItem(Player player, ItemStack item) {
|
||||
if (player == null || !player.isOnline() || item == null) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, ItemStack> leftover = player.getInventory().addItem(item);
|
||||
if (!leftover.isEmpty()) {
|
||||
leftover.values().stream().forEach(it -> player.getWorld().dropItemNaturally(player.getLocation(), it));
|
||||
}
|
||||
}
|
||||
|
||||
public static void giveItem(Player player, ItemStack... items) {
|
||||
if (player == null || !player.isOnline() || items == null || items.length == 0) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, ItemStack> leftover = player.getInventory().addItem(items);
|
||||
if (!leftover.isEmpty()) {
|
||||
final World world = player.getWorld();
|
||||
final Location location = player.getLocation();
|
||||
leftover.values().stream().forEach(it -> world.dropItemNaturally(location, it));
|
||||
}
|
||||
}
|
||||
|
||||
public static void giveItem(Player player, Collection<ItemStack> items) {
|
||||
if (player == null || !player.isOnline() || items == null || items.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, ItemStack> leftover = player.getInventory().addItem(items.toArray(new ItemStack[items.size()]));
|
||||
if (!leftover.isEmpty()) {
|
||||
final World world = player.getWorld();
|
||||
final Location location = player.getLocation();
|
||||
leftover.values().stream().forEach(it -> world.dropItemNaturally(location, it));
|
||||
}
|
||||
}
|
||||
}
|
22
NMS/NMS-API/pom.xml
Normal file
22
NMS/NMS-API/pom.xml
Normal file
@ -0,0 +1,22 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0">
|
||||
|
||||
<parent>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore-Modules</artifactId>
|
||||
<version>maven-version-number</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>SongodaCore-NMS-API</artifactId>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>13.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user