This commit is contained in:
Brianna O'Keefe 2019-02-05 23:32:15 -05:00
parent a8b3ccb907
commit ded93d2f01
87 changed files with 321 additions and 6889 deletions

View File

@ -1,11 +1,21 @@
stages:
- build
- build
variables:
name: "EpicBuckets"
path: "/builds/Songoda/$name"
version: "1.4.4"
build:
stage: build
image: maven:3.3.9-jdk-8
script: "mvn clean package"
image: maven:3.5.3-jdk-8
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
- mvn clean package
- find $path/ -depth -path '*original*' -delete
- mv -v $path/target/*.jar $path
artifacts:
name: "EpicBuckets"
name: $name-$version
paths:
- "/builds/Songoda/epicbuckets/target/*.jar"
- "$path/*.jar"

View File

@ -1,4 +1,4 @@
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@ -8,10 +8,10 @@
<version>maven-version-number</version>
</parent>
<groupId>com.songoda</groupId>
<artifactId>EpicBuckets-Hooks</artifactId>
<artifactId>EpicBuckets-Legacy-Hooks</artifactId>
<build>
<defaultGoal>clean install</defaultGoal>
<finalName>EpicBuckets-Hooks</finalName>
<finalName>EpicBuckets-Legacy-Hooks</finalName>
</build>
<repositories>
<repository>
@ -20,6 +20,12 @@
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.songoda</groupId>
<artifactId>EpicBuckets-Plugin</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldguard</artifactId>

View File

@ -1,29 +0,0 @@
package com.songoda.epicspawners.hooks.legacy;
import com.intellectualcrafters.plot.api.PlotAPI;
import com.plotsquared.bukkit.BukkitMain;
import com.songoda.epicspawners.api.utils.ProtectionPluginHook;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class HookPlotSquared implements ProtectionPluginHook {
private final PlotAPI plotSquared;
public HookPlotSquared() {
this.plotSquared = new PlotAPI();
}
@Override
public JavaPlugin getPlugin() { // BukkitMain? Really?
return JavaPlugin.getPlugin(BukkitMain.class);
}
@Override
public boolean canBuild(Player player, Location location) {
return plotSquared.getPlot(location) != null && plotSquared.isInPlot(player)
&& plotSquared.getPlot(location) == plotSquared.getPlot(player);
}
}

View File

@ -1,27 +0,0 @@
package com.songoda.epicspawners.hooks.legacy;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.songoda.epicspawners.api.utils.ProtectionPluginHook;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class HookWorldGuard implements ProtectionPluginHook {
private final WorldGuardPlugin worldGuard;
public HookWorldGuard() {
this.worldGuard = WorldGuardPlugin.inst();
}
@Override
public JavaPlugin getPlugin() {
return worldGuard;
}
@Override
public boolean canBuild(Player player, Location location) {
return worldGuard.canBuild(player, location);
}
}

View File

@ -2,6 +2,7 @@ package com.songoda.epicbuckets.hooks.legacy;
import com.intellectualcrafters.plot.api.PlotAPI;
import com.plotsquared.bukkit.BukkitMain;
import com.songoda.epicbuckets.util.hooks.ProtectionPluginHook;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

View File

@ -1,6 +1,7 @@
package com.songoda.epicbuckets.hooks.legacy;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.songoda.epicbuckets.util.hooks.ProtectionPluginHook;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

View File

@ -0,0 +1,222 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.songoda</groupId>
<artifactId>EpicBuckets-Parent</artifactId>
<version>maven-version-number</version>
</parent>
<artifactId>EpicBuckets-Plugin</artifactId>
<repositories>
<repository>
<id>private</id>
<url>http://repo.songoda.com/artifactory/private/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.gmail.filoghost.holographicdisplays</groupId>
<artifactId>holographicdisplays-api</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.songoda</groupId>
<artifactId>EpicBuckets-Legacy-Hooks</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.arcaniax</groupId>
<artifactId>liquidtanks</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>com.songoda</groupId>
<artifactId>arconix</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org</groupId>
<artifactId>kingdoms</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.milkbowl</groupId>
<artifactId>vault</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.ryanhamshire</groupId>
<artifactId>GriefPrevention</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldedit</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldguard</artifactId>
<version>6.2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com</groupId>
<artifactId>plotsquared</artifactId>
<version>3.5.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.songoda</groupId>
<artifactId>skyblockearth</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.palmergames.bukkit</groupId>
<artifactId>towny</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.wasteofplastic</groupId>
<artifactId>askyblock</artifactId>
<version>3.0.6.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>us.talabrek</groupId>
<artifactId>ultimateskyblock</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.markeh</groupId>
<artifactId>factionsframework</artifactId>
<version>1.2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>br.net.fabiozumbi12</groupId>
<artifactId>RedProtect</artifactId>
<version>7.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.gmail.nossr50</groupId>
<artifactId>mcmmo</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.gamingmesh</groupId>
<artifactId>jobs</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.botsko</groupId>
<artifactId>prism</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.diddiz</groupId>
<artifactId>logblock</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net</groupId>
<artifactId>coreprotect</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>uk.antiperson</groupId>
<artifactId>stackmob</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.sothatsit</groupId>
<artifactId>blockstore</artifactId>
<version>LATEST</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>xyz.wildseries</groupId>
<artifactId>wildstacker</artifactId>
<version>b6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.5.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>clean install</defaultGoal>
<finalName>EpicBuckets-Legacy-${project.version}</finalName>
<plugins>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>${project.build.directory}/classes/plugin.yml</file>
<file>${project.basedir}/../.gitlab-ci.yml</file>
<replacements>
<replacement>
<token>maven-version-number</token>
<value>${project.version}</value>
</replacement>
</replacements>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -5,8 +5,9 @@ import com.songoda.epicbuckets.command.CommandManager;
import com.songoda.epicbuckets.file.ConfigManager;
import com.songoda.epicbuckets.genbucket.GenbucketManager;
import com.songoda.epicbuckets.hooks.*;
import com.songoda.epicbuckets.listener.GenbucketPlaceListener;
import com.songoda.epicbuckets.listener.SourceBlockBreakListener;
import com.songoda.epicbuckets.listeners.GenbucketPlaceListener;
import com.songoda.epicbuckets.listeners.PlayerJoinListeners;
import com.songoda.epicbuckets.listeners.SourceBlockBreakListener;
import com.songoda.epicbuckets.shop.ShopManager;
import com.songoda.epicbuckets.util.ChatUtil;
import com.songoda.epicbuckets.util.ConfigWrapper;
@ -77,18 +78,27 @@ public class EpicBuckets extends JavaPlugin {
// Event registration
pluginManager.registerEvents(new GenbucketPlaceListener(this), this);
pluginManager.registerEvents(new SourceBlockBreakListener(), this);
pluginManager.registerEvents(new PlayerJoinListeners(this), this);
// Register default hooks
if (pluginManager.isPluginEnabled("ASkyBlock")) aSkyblockHook = (ClaimableProtectionPluginHook) this.register(HookASkyBlock::new);
if (pluginManager.isPluginEnabled("FactionsFramework")) factionsHook = (ClaimableProtectionPluginHook) this.register(HookFactions::new);
if (pluginManager.isPluginEnabled("GriefPrevention")) this.register(HookGriefPrevention::new);
if (pluginManager.isPluginEnabled("Kingdoms")) this.register(HookKingdoms::new);
if (pluginManager.isPluginEnabled("PlotSquared")) this.register(HookPlotSquared::new);
if (pluginManager.isPluginEnabled("RedProtect")) this.register(HookRedProtect::new);
if (pluginManager.isPluginEnabled("Towny")) townyHook = (ClaimableProtectionPluginHook) this.register(HookTowny::new);
if (pluginManager.isPluginEnabled("USkyBlock")) uSkyblockHook = (ClaimableProtectionPluginHook) this.register(HookUSkyBlock::new);
if (pluginManager.isPluginEnabled("SkyBlock")) skyBlockEarhHook = (ClaimableProtectionPluginHook) this.register(HookSkyBlockEarth::new);
if (pluginManager.isPluginEnabled("WorldGuard")) this.register(HookWorldGuard::new);
if (isServerVersionAtLeast(ServerVersion.V1_13)) {
if (pluginManager.isPluginEnabled("WorldGuard")) this.register(HookWorldGuard::new);
if (pluginManager.isPluginEnabled("PlotSquared")) this.register(HookPlotSquared::new);
} else {
if (pluginManager.isPluginEnabled("WorldGuard"))
this.register(com.songoda.epicbuckets.hooks.legacy.HookWorldGuard::new);
if (pluginManager.isPluginEnabled("PlotSquared"))
this.register(com.songoda.epicbuckets.hooks.legacy.HookPlotSquared::new);
}
console.sendMessage(ChatUtil.colorString("&a============================="));
}

View File

@ -1,4 +1,4 @@
package com.songoda.epicbuckets.listener;
package com.songoda.epicbuckets.listeners;
import com.songoda.epicbuckets.EpicBuckets;

View File

@ -1,9 +1,8 @@
package com.songoda.epicspawners.listeners;
package com.songoda.epicbuckets.listeners;
import com.songoda.epicspawners.EpicSpawnersPlugin;
import com.songoda.epicspawners.References;
import com.songoda.epicspawners.utils.Debugger;
import com.songoda.epicspawners.utils.Methods;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.References;
import com.songoda.epicbuckets.util.ChatUtil;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@ -14,31 +13,27 @@ import org.bukkit.event.player.PlayerJoinEvent;
*/
public class PlayerJoinListeners implements Listener {
private EpicSpawnersPlugin instance;
private EpicBuckets instance;
public PlayerJoinListeners(EpicSpawnersPlugin instance) {
public PlayerJoinListeners(EpicBuckets instance) {
this.instance = instance;
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
try {
Player player = event.getPlayer();
if (player.isOp() && instance.getConfig().getBoolean("Main.Display Helpful Tips For Operators")) {
if (player.isOp()) {
if (instance.getServer().getPluginManager().getPlugin("Factions") != null && instance.getServer().getPluginManager().getPlugin("FactionsFramework") == null) {
player.sendMessage("");
player.sendMessage(Methods.formatText(References.getPrefix() + "&7Here's the deal,"));
player.sendMessage(Methods.formatText("&7I cannot give you full support for Factions out of the box."));
player.sendMessage(Methods.formatText("&7Things will work without it but if you wan't a flawless"));
player.sendMessage(Methods.formatText("&7experience you need to download"));
player.sendMessage(Methods.formatText("&7&6https://www.spigotmc.org/resources/54337/&7."));
player.sendMessage(Methods.formatText("&7If you don't care and don't want to see this message again"));
player.sendMessage(Methods.formatText("&7turn &6Helpful-Tips &7off in the config."));
player.sendMessage(ChatUtil.colorString(References.getPrefix() + "&7Here's the deal,"));
player.sendMessage(ChatUtil.colorString("&7I cannot give you full support for Factions out of the box."));
player.sendMessage(ChatUtil.colorString("&7Things will work without it but if you wan't a flawless"));
player.sendMessage(ChatUtil.colorString("&7experience you need to download"));
player.sendMessage(ChatUtil.colorString("&7&6https://www.spigotmc.org/resources/54337/&7."));
player.sendMessage(ChatUtil.colorString("&7If you don't care and don't want to see this message again"));
player.sendMessage(ChatUtil.colorString("&7turn &6Helpful-Tips &7off in the config."));
player.sendMessage("");
}
}
} catch (Exception ee) {
Debugger.runReport(ee);
}
}
}

View File

@ -1,4 +1,4 @@
package com.songoda.epicbuckets.listener;
package com.songoda.epicbuckets.listeners;
import com.songoda.epicbuckets.EpicBuckets;
import org.bukkit.event.EventHandler;

View File

@ -6,7 +6,6 @@ general.nametag.prefix = "&8[&6EpicBuckets&8]"
command.reload.success = "&7You've reloaded the config"
command.admin.toggle = "&7Spy mode: %mode%"
command.general.invalidsyntax = "&7Invalid command syntax!"
command.give.genbucketnotfound = "&7A genbucket with that combination was not registered!"
#Interface Messages

View File

@ -1,7 +1,13 @@
name: EpicBuckets
version: 1.4.4
version: maven-version-number
description: Generate walls fast and efficient with beautiful guis!
author: Songoda
main: com.songoda.epicbuckets.EpicBuckets
softdepend: [WorldGuard, WorldEdit, Factions, MassiveCore, GriefPrevention]
depend: [Vault]
depend: [Vault]
commands:
EpicBuckets:
description: Main command.
default: true
aliases: [eb, genbucket, gen]
usage: /<command> [reload]

250
pom.xml
View File

@ -1,224 +1,44 @@
<project xmlns="http://maven.apache.org/POM/4.0.0">
<groupId>com.songoda</groupId>
<artifactId>EpicBuckets</artifactId>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<version>1.4.4</version>
<build>
<defaultGoal>clean package</defaultGoal>
<plugins>
<plugin>
<version>3.6.1</version>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<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.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>shaded</shadedClassifierName>
<artifactSet>
<includes>
<include>fr.minuskube.inv:smart-invs</include>
<include>co.aikar</include>
<include>me.lucko:helper</include>
<include>com.github.tr7zw.Item-NBT-API</include>
<include>net.jodah:expiringmap</include>
<include>org.jetbrains:annotations</include>
<include>com.flowpowered:flow-math</include>
<include>com.google.code.findbugs</include>
<include>com.google.guava</include>
<include>com.google.code.gson</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.intellij</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}.intellij</shadedPattern>
</relocation>
<relocation>
<pattern>javax.annotation</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}.annotation</shadedPattern>
</relocation>
<relocation>
<pattern>me.lucko.helper</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}.helper</shadedPattern>
</relocation>
<relocation>
<pattern>org.jetbrains</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}.jetbrains</shadedPattern>
</relocation>
<relocation>
<pattern>com.flowpowered</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}.flowpowered</shadedPattern>
</relocation>
<relocation>
<pattern>net.jodah</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}.jodah</shadedPattern>
</relocation>
<relocation>
<pattern>com.google</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}.google</shadedPattern>
</relocation>
<relocation>
<pattern>fr.minuskube.inv</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}.inv</shadedPattern>
</relocation>
<relocation>
<pattern>co.aikar.timings.lib</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}.acf.timings</shadedPattern>
</relocation>
<relocation>
<pattern>co.aikar.commands</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}.acf.commands</shadedPattern>
</relocation>
<relocation>
<pattern>de.tr7zw.itemnbtapi</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}.itemnbtapi</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<sourceDirectory>src/main/java</sourceDirectory>
</build>
<repositories>
<repository>
<id>11_private</id>
<url>http://repo.songoda.com/artifactory/private</url>
</repository>
<repository>
<id>22_vault</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
</repository>
<repository>
<id>33_aikar</id>
<url>https://repo.aikar.co/content/groups/aikar/</url>
</repository>
<repository>
<id>44_jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<groupId>com.songoda</groupId>
<artifactId>EpicBuckets-Parent</artifactId>
<packaging>pom</packaging>
<version>maven-version-number</version>
<modules>
<module>EpicBuckets-Legacy-Hooks</module>
<module>EpicBuckets-Plugin</module>
</modules>
<dependencies>
<dependency>
<groupId>fr.minuskube.inv</groupId>
<artifactId>smart-invs</artifactId>
<version>1.2.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>co.aikar</groupId>
<artifactId>acf-bukkit</artifactId>
<version>0.5.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>me.lucko</groupId>
<artifactId>helper</artifactId>
<version>LATEST</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.tr7zw</groupId>
<artifactId>Item-NBT-API</artifactId>
<version>master-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.13.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.songoda</groupId>
<artifactId>arconix</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.ryanhamshire</groupId>
<artifactId>GriefPrevention</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldedit</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldguard</artifactId>
<version>6.2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com</groupId>
<artifactId>plotsquared</artifactId>
<version>RELEASE</version>
<scope>provided</scope>
</dependency>
<!--The Dependencies below are for both FactionsUUID/SavageFactions/FactionsUltimate & MassiveCore Factions // By ProSavage <3 -->
<dependency>
<groupId>com.github.ProSavage</groupId>
<artifactId>SavageFactions</artifactId>
<version>1.6.x-0.1.21-gbdd5473-400</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.massivecraft.</groupId>
<artifactId>factions</artifactId>
<scope>system</scope>
<version>2.14.1-SNAPSHOT</version>
<systemPath>${project.basedir}/dependencies/Factions.jar</systemPath>
</dependency>
<dependency>
<groupId>com.massivecraft</groupId>
<artifactId>massivecore</artifactId>
<scope>system</scope>
<version>2.14.1-SNAPSHOT</version>
<systemPath>${project.basedir}/dependencies/MassiveCore.jar</systemPath>
</dependency>
<!--The Dependencies above are for both FactionsUUID/SavageFactions/FactionsUltimate & MassiveCore Factions // By ProSavage <3 -->
<!--Try not to mess it up -->
</dependencies>
</project>
<build>
<defaultGoal>clean install</defaultGoal>
<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>
</plugins>
</build>
<repositories>
<repository>
<id>private</id>
<url>http://repo.songoda.com/artifactory/private/</url>
</repository>
</repositories>
</project>

View File

@ -1,145 +0,0 @@
package com.songoda.epicbuckets;
import co.aikar.commands.BukkitCommandManager;
import com.songoda.epicbuckets.command.CommandGenbucket;
import com.songoda.epicbuckets.command.CommandTabbing;
import com.songoda.epicbuckets.file.ConfigManager;
import com.songoda.epicbuckets.genbucket.GenbucketManager;
import com.songoda.epicbuckets.listener.GenbucketPlaceListener;
import com.songoda.epicbuckets.listener.SourceBlockBreakListener;
import com.songoda.epicbuckets.shop.ShopManager;
import com.songoda.epicbuckets.util.ChatUtil;
import com.songoda.epicbuckets.util.Debugger;
import fr.minuskube.inv.InventoryManager;
import me.lucko.helper.plugin.ExtendedJavaPlugin;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.RegisteredServiceProvider;
public class EpicBuckets extends ExtendedJavaPlugin {
private static EpicBuckets instance;
private static CommandSender console = Bukkit.getConsoleSender();
private ConfigManager configManager;
private ShopManager shopManager;
private Debugger debugger;
private GenbucketManager genbucketManager;
private Economy econ;
private BukkitCommandManager commandManager;
private InventoryManager inventoryManager;
private Locale locale;
public static EpicBuckets getInstance() { return instance; }
@Override
protected void enable() {
console.sendMessage(ChatUtil.colorString("&a============================="));
console.sendMessage(ChatUtil.colorString("&7EpicBuckets " + this.getDescription().getVersion() + " by &5Songoda <3!"));
console.sendMessage(ChatUtil.colorString("&7Action: &aEnabling&7..."));
instance = this;
if (!isEnabled()) {
return;
}
saveDefaultConfig();
Locale.init(this);
Locale.saveDefaultLocale("en_US");
this.locale = Locale.getLocale(getConfig().getString("Locale", "en_US"));
debugger = new Debugger();
configManager = new ConfigManager();
shopManager = new ShopManager();
configManager.setup();
genbucketManager = new GenbucketManager();
commandManager = new BukkitCommandManager(this);
inventoryManager = new InventoryManager(this);
inventoryManager.init();
CommandTabbing.registerCommandCompletions();
commandManager.registerCommand(new CommandGenbucket());
getServer().getPluginManager().registerEvents(new GenbucketPlaceListener(), this);
getServer().getPluginManager().registerEvents(new SourceBlockBreakListener(), this);
setupEconomy();
console.sendMessage(ChatUtil.colorString("&a============================="));
}
@Override
protected void disable() {
console.sendMessage(ChatUtil.colorString("&a============================="));
console.sendMessage(ChatUtil.colorString("&7EpicBuckets " + this.getDescription().getVersion() + " by &5Songoda <3!"));
console.sendMessage(ChatUtil.colorString("&7Action: &cDisabling&7..."));
console.sendMessage(ChatUtil.colorString("&a============================="));
}
public void reload() {
this.locale.reloadMessages();
this.getConfigManager().reload();
this.getShopManager().reload();
}
public double getBalance(Player player) {
return econ.getBalance(player);
}
public void withdrawBalance(Player player, int amount, boolean sendMessage) {
if (sendMessage)
player.sendMessage(locale.getMessage("interface.withdrawl.success").replace("{amount}", String.valueOf(amount)));
econ.withdrawPlayer(player, amount);
}
private boolean setupEconomy() {
if (getServer().getPluginManager().getPlugin("Vault") == null) {
return false;
}
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
if (rsp == null) {
return false;
}
econ = rsp.getProvider();
return econ != null;
}
public ConfigManager getConfigManager() {
return configManager;
}
public ShopManager getShopManager() {
return shopManager;
}
public Debugger getDebugger() {
return debugger;
}
public GenbucketManager getGenbucketManager() {
return genbucketManager;
}
public InventoryManager getInventoryManager() {
return inventoryManager;
}
public Economy getEcon() {
return econ;
}
public Locale getLocale() {
return locale;
}
public BukkitCommandManager getCommandManager() {
return commandManager;
}
}

View File

@ -1,364 +0,0 @@
package com.songoda.epicbuckets;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.apache.commons.io.IOUtils;
import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* Assists in the creation of multiple localizations and languages,
* as well as the generation of default .lang files
*
* @author Parker Hawke - 2008Choco
*/
public class Locale {
private static JavaPlugin plugin;
private static final List<Locale> LOCALES = Lists.newArrayList();
private static final Pattern NODE_PATTERN = Pattern.compile("(\\w+(?:\\.{1}\\w+)*)\\s*=\\s*\"(.*)\"");
private static final String FILE_EXTENSION = ".lang";
private static File localeFolder;
private static String defaultLocale;
private final Map<String, String> nodes = new HashMap<>();
private final File file;
private final String name, region;
private Locale(String name, String region) {
if (plugin == null)
throw new IllegalStateException("Cannot generate locales without first initializing the class (Locale#init(JavaPlugin))");
this.name = name.toLowerCase();
this.region = region.toUpperCase();
String fileName = name + "_" + region + FILE_EXTENSION;
this.file = new File(localeFolder, fileName);
if (this.reloadMessages()) return;
plugin.getLogger().info("Loaded locale " + fileName);
}
/**
* Get the name of the language that this locale is based on.
* (i.e. "en" for English, or "fr" for French)
*
* @return the name of the language
*/
public String getName() {
return name;
}
/**
* Get the name of the region that this locale is from.
* (i.e. "US" for United States or "CA" for Canada)
*
* @return the name of the region
*/
public String getRegion() {
return region;
}
/**
* Return the entire locale tag (i.e. "en_US")
*
* @return the language tag
*/
public String getLanguageTag() {
return name + "_" + region;
}
/**
* Get the file that represents this locale
*
* @return the locale file (.lang)
*/
public File getFile() {
return file;
}
/**
* Get a message set for a specific node
*
* @param node the node to get
* @return the message for the specified node
*/
public String getMessage(String node) {
return ChatColor.translateAlternateColorCodes('&', this.getMessageOrDefault(node, node));
}
/**
* Get a message set for a specific node and replace its params with a supplied arguments.
*
* @param node the node to get
* @param args the replacement arguments
* @return the message for the specified node
*/
public String getMessage(String node, Object... args) {
String message = getMessage(node);
for (Object arg : args) {
message = message.replaceFirst("\\%.*?\\%", arg.toString());
}
return message;
}
/**
* Get a message set for a specific node
*
* @param node the node to get
* @param defaultValue the default value given that a value for the node was not found
* @return the message for the specified node. Default if none found
*/
public String getMessageOrDefault(String node, String defaultValue) {
return this.nodes.getOrDefault(node, defaultValue);
}
/**
* Get the key-value map of nodes to messages
*
* @return node-message map
*/
public Map<String, String> getMessageNodeMap() {
return ImmutableMap.copyOf(nodes);
}
/**
* Clear the previous message cache and load new messages directly from file
*
* @return reload messages from file
*/
public boolean reloadMessages() {
if (!this.file.exists()) {
plugin.getLogger().warning("Could not find file for locale " + this.name);
return false;
}
this.nodes.clear(); // Clear previous data (if any)
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
String line;
for (int lineNumber = 0; (line = reader.readLine()) != null; lineNumber++) {
if (line.isEmpty() || line.startsWith("#") /* Comment */) continue;
Matcher matcher = NODE_PATTERN.matcher(line);
if (!matcher.find()) {
System.err.println("Invalid locale syntax at (line=" + lineNumber + ")");
continue;
}
nodes.put(matcher.group(1), matcher.group(2));
}
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
/**
* Initialize the locale class to generate information and search for localizations.
* This must be called before any other methods in the Locale class can be invoked.
* Note that this will also call {@link #searchForLocales()}, so there is no need to
* invoke it for yourself after the initialization
*
* @param plugin the plugin instance
*/
public static void init(JavaPlugin plugin) {
Locale.plugin = plugin;
if (localeFolder == null) {
localeFolder = new File(plugin.getDataFolder(), "locales/");
}
localeFolder.mkdirs();
Locale.searchForLocales();
}
/**
* Find all .lang file locales under the "locales" folder
*/
public static void searchForLocales() {
if (!localeFolder.exists()) localeFolder.mkdirs();
for (File file : localeFolder.listFiles()) {
String name = file.getName();
if (!name.endsWith(".lang")) continue;
String fileName = name.substring(0, name.lastIndexOf('.'));
String[] localeValues = fileName.split("_");
if (localeValues.length != 2) continue;
if (localeExists(localeValues[0] + "_" + localeValues[1])) continue;
LOCALES.add(new Locale(localeValues[0], localeValues[1]));
plugin.getLogger().info("Found and loaded locale \"" + fileName + "\"");
}
}
/**
* Get a locale by its entire proper name (i.e. "en_US")
*
* @param name the full name of the locale
* @return locale of the specified name
*/
public static Locale getLocale(String name) {
for (Locale locale : LOCALES)
if (locale.getLanguageTag().equalsIgnoreCase(name)) return locale;
return null;
}
/**
* Get a locale from the cache by its name (i.e. "en" from "en_US")
*
* @param name the name of the language
* @return locale of the specified language. Null if not cached
*/
public static Locale getLocaleByName(String name) {
for (Locale locale : LOCALES)
if (locale.getName().equalsIgnoreCase(name)) return locale;
return null;
}
/**
* Get a locale from the cache by its region (i.e. "US" from "en_US")
*
* @param region the name of the region
* @return locale of the specified region. Null if not cached
*/
public static Locale getLocaleByRegion(String region) {
for (Locale locale : LOCALES)
if (locale.getRegion().equalsIgnoreCase(region)) return locale;
return null;
}
/**
* Check whether a locale exists and is registered or not
*
* @param name the whole language tag (i.e. "en_US")
* @return true if it exists
*/
public static boolean localeExists(String name) {
for (Locale locale : LOCALES)
if (locale.getLanguageTag().equals(name)) return true;
return false;
}
/**
* Get an immutable list of all currently loaded locales
*
* @return list of all locales
*/
public static List<Locale> getLocales() {
return ImmutableList.copyOf(LOCALES);
}
/**
* Save a default locale file from the project source directory, to the locale folder
*
* @param path the path to the file to save
* @param fileName the name of the file to save
* @return true if the operation was successful, false otherwise
*/
public static boolean saveDefaultLocale(String path, String fileName) {
if (!localeFolder.exists()) localeFolder.mkdirs();
if (!fileName.endsWith(FILE_EXTENSION))
fileName = (fileName.lastIndexOf(".") == -1 ? fileName : fileName.substring(0, fileName.lastIndexOf('.'))) + FILE_EXTENSION;
File destinationFile = new File(localeFolder, fileName);
if (destinationFile.exists()) {
return compareFiles(plugin.getResource(fileName), destinationFile);
}
try (OutputStream outputStream = new FileOutputStream(destinationFile)) {
IOUtils.copy(plugin.getResource(fileName), outputStream);
fileName = fileName.substring(0, fileName.lastIndexOf('.'));
String[] localeValues = fileName.split("_");
if (localeValues.length != 2) return false;
LOCALES.add(new Locale(localeValues[0], localeValues[1]));
if (defaultLocale == null) defaultLocale = fileName;
return true;
} catch (IOException e) {
return false;
}
}
/**
* Save a default locale file from the project source directory, to the locale folder
*
* @param fileName the name of the file to save
* @return true if the operation was successful, false otherwise
*/
public static boolean saveDefaultLocale(String fileName) {
return saveDefaultLocale("", fileName);
}
/**
* Clear all current locale data
*/
public static void clearLocaleData() {
for (Locale locale : LOCALES)
locale.nodes.clear();
LOCALES.clear();
}
// Write new changes to existing files, if any at all
private static boolean compareFiles(InputStream defaultFile, File existingFile) {
// Look for default
if (defaultFile == null) {
defaultFile = plugin.getResource(defaultLocale != null ? defaultLocale : "en_US");
if (defaultFile == null) return false; // No default at all
}
boolean changed = false;
List<String> defaultLines, existingLines;
try (BufferedReader defaultReader = new BufferedReader(new InputStreamReader(defaultFile));
BufferedReader existingReader = new BufferedReader(new FileReader(existingFile));
BufferedWriter writer = new BufferedWriter(new FileWriter(existingFile, true))) {
defaultLines = defaultReader.lines().collect(Collectors.toList());
existingLines = existingReader.lines().map(s -> s.split("\\s*=")[0]).collect(Collectors.toList());
for (String defaultValue : defaultLines) {
if (defaultValue.isEmpty() || defaultValue.startsWith("#")) continue;
String key = defaultValue.split("\\s*=")[0];
if (!existingLines.contains(key)) {
if (!changed) {
writer.newLine();
writer.newLine();
writer.write("# New messages for " + plugin.getName() + " v" + plugin.getDescription().getVersion());
}
writer.newLine();
writer.write(defaultValue);
changed = true;
}
}
} catch (IOException e) {
return false;
}
return changed;
}
}

View File

@ -1,8 +0,0 @@
package com.songoda.epicspawners;
public class References {
public static String getPrefix() {
return EpicSpawnersPlugin.getInstance().getLocale().getMessage("general.nametag.prefix") + " ";
}
}

View File

@ -1,41 +0,0 @@
package com.songoda.epicfarming.command;
import com.songoda.epicfarming.EpicFarmingPlugin;
import org.bukkit.command.CommandSender;
public abstract class AbstractCommand {
public enum ReturnType { SUCCESS, FAILURE, SYNTAX_ERROR }
private final AbstractCommand parent;
private final String command;
private final boolean noConsole;
protected AbstractCommand(String command, AbstractCommand parent, boolean noConsole) {
this.command = command;
this.parent = parent;
this.noConsole = noConsole;
}
public AbstractCommand getParent() {
return parent;
}
public String getCommand() {
return command;
}
public boolean isNoConsole() {
return noConsole;
}
protected abstract ReturnType runCommand(EpicFarmingPlugin instance, CommandSender sender, String... args);
public abstract String getPermissionNode();
public abstract String getSyntax();
public abstract String getDescription();
}

View File

@ -1,78 +0,0 @@
package com.songoda.epicfarming.command;
import com.songoda.epicfarming.EpicFarmingPlugin;
import com.songoda.epicfarming.command.commands.*;
import com.songoda.epicfarming.utils.Methods;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class CommandManager implements CommandExecutor {
private EpicFarmingPlugin instance;
private List<AbstractCommand> commands = new ArrayList<>();
public CommandManager(EpicFarmingPlugin instance) {
this.instance = instance;
instance.getCommand("EpicFarming").setExecutor(this);
AbstractCommand commandEpicFarming = addCommand(new CommandEpicFarming());
addCommand(new CommandReload(commandEpicFarming));
addCommand(new CommandSettings(commandEpicFarming));
addCommand(new CommandGiveFarmItem(commandEpicFarming));
addCommand(new CommandBoost(commandEpicFarming));
}
private AbstractCommand addCommand(AbstractCommand abstractCommand) {
commands.add(abstractCommand);
return abstractCommand;
}
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
for (AbstractCommand abstractCommand : commands) {
if (abstractCommand.getCommand().equalsIgnoreCase(command.getName())) {
if (strings.length == 0) {
processRequirements(abstractCommand, commandSender, strings);
return true;
}
} else if (strings.length != 0 && abstractCommand.getParent() != null && abstractCommand.getParent().getCommand().equalsIgnoreCase(command.getName())) {
String cmd = strings[0];
if (cmd.equalsIgnoreCase(abstractCommand.getCommand())) {
processRequirements(abstractCommand, commandSender, strings);
return true;
}
}
}
commandSender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&7The command you entered does not exist or is spelt incorrectly."));
return true;
}
private void processRequirements(AbstractCommand command, CommandSender sender, String[] strings) {
if (!(sender instanceof Player) && command.isNoConsole()) {
sender.sendMessage("You must be a player to use this command.");
return;
}
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
AbstractCommand.ReturnType returnType = command.runCommand(instance, sender, strings);
if (returnType == AbstractCommand.ReturnType.SYNTAX_ERROR) {
sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&cInvalid Syntax!"));
sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&7The valid syntax is: &6" + command.getSyntax() + "&7."));
}
return;
}
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
}
public List<AbstractCommand> getCommands() {
return Collections.unmodifiableList(commands);
}
}

View File

@ -1,36 +0,0 @@
package com.songoda.epicbuckets.command.commands;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.References;
import com.songoda.epicbuckets.command.AbstractCommand;
import com.songoda.epicbuckets.util.ChatUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class CommandAdminToggle extends AbstractCommand {
public CommandAdminToggle(AbstractCommand parent) {
super(parent, true, "admin toggle");
}
@Override
protected ReturnType runCommand(EpicBuckets instance, CommandSender sender, String... args) {
instance.getGenbucketManager().toggleAdmin((Player)sender);
return ReturnType.SUCCESS;
}
@Override
public String getPermissionNode() {
return "epicbuckets.admin";
}
@Override
public String getSyntax() {
return "/eb admin toggle";
}
@Override
public String getDescription() {
return "Toggles your admin status to receive genbucket placement notifications";
}
}

View File

@ -1,36 +0,0 @@
package com.songoda.epicbuckets.command.commands;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.References;
import com.songoda.epicbuckets.command.AbstractCommand;
import com.songoda.epicbuckets.util.ChatUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class CommandToggle extends AbstractCommand {
public CommandToggle(AbstractCommand parent) {
super(parent, true, "admin toggle");
}
@Override
protected ReturnType runCommand(EpicBuckets instance, CommandSender sender, String... args) {
instance.getGenbucketManager().toggleAdmin((Player)sender);
return ReturnType.SUCCESS;
}
@Override
public String getPermissionNode() {
return "epicbuckets.admin";
}
@Override
public String getSyntax() {
return "/eb admin toggle";
}
@Override
public String getDescription() {
return "Toggles your admin status to receive genbucket placement notifications";
}
}

View File

@ -1,43 +0,0 @@
package com.songoda.epicbuckets.command.commands;
import com.songoda.epicfarming.EpicFarmingPlugin;
import com.songoda.epicfarming.command.AbstractCommand;
import com.songoda.epicfarming.utils.Methods;
import org.bukkit.command.CommandSender;
public class CommandEpicFarming extends AbstractCommand {
public CommandEpicFarming() {
super("EpicFarming", null, false);
}
@Override
protected ReturnType runCommand(EpicFarmingPlugin instance, CommandSender sender, String... args) {
sender.sendMessage("");
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oBrianna"));
for (AbstractCommand command : instance.getCommandManager().getCommands()) {
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
sender.sendMessage(Methods.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription()));
}
}
sender.sendMessage("");
return ReturnType.SUCCESS;
}
@Override
public String getPermissionNode() {
return null;
}
@Override
public String getSyntax() {
return "/EpicFarming";
}
@Override
public String getDescription() {
return "Displays this page.";
}
}

View File

@ -1,36 +0,0 @@
package com.songoda.epicbuckets.command.commands;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.References;
import com.songoda.epicbuckets.command.AbstractCommand;
import com.songoda.epicbuckets.util.ChatUtil;
import org.bukkit.command.CommandSender;
public class CommandReload extends AbstractCommand {
public CommandReload(AbstractCommand parent) {
super(parent, false, "reload");
}
@Override
protected ReturnType runCommand(EpicBuckets instance, CommandSender sender, String... args) {
instance.reload();
sender.sendMessage(ChatUtil.colorPrefix(instance.getLocale().getMessage("command.reload.success")));
return ReturnType.SUCCESS;
}
@Override
public String getPermissionNode() {
return "epicbuckets.admin";
}
@Override
public String getSyntax() {
return "/eb reload";
}
@Override
public String getDescription() {
return "Reloads the messages & config files";
}
}

View File

@ -1,4 +0,0 @@
package com.songoda.epicbuckets.command.commands;
public class CommandHelp {
}

View File

@ -1,44 +0,0 @@
package com.songoda.epicbuckets.command.commands;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.References;
import com.songoda.epicbuckets.command.AbstractCommand;
import com.songoda.epicbuckets.util.ChatUtil;
import org.bukkit.command.CommandSender;
public class CommandHelp extends AbstractCommand {
public CommandHelp(AbstractCommand parent) {
super(parent, true, "help", "?");
}
@Override
protected ReturnType runCommand(EpicBuckets instance, CommandSender sender, String... args) {
sender.sendMessage("");
sender.sendMessage(ChatUtil.colorString(References.getPrefix() + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oBrianna"));
for (AbstractCommand command : instance.getCommandManager().getCommands()) {
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
sender.sendMessage(ChatUtil.colorString("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription()));
}
}
sender.sendMessage("");
return ReturnType.SUCCESS;
}
@Override
public String getPermissionNode() {
return null;
}
@Override
public String getSyntax() {
return "/Eb help/?";
}
@Override
public String getDescription() {
return "Displays this page.";
}
}

View File

@ -1,51 +0,0 @@
package com.songoda.epicbuckets.event;
import com.songoda.epicbuckets.genbucket.Genbucket;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class GenbucketPlaceEvent extends Event implements Cancellable {
private final Player player;
private final Genbucket genbucket;
private boolean isCancelled;
public GenbucketPlaceEvent(Player player, Genbucket genbucket) {
this.player = player;
this.genbucket = genbucket;
this.isCancelled = false;
}
public Player getPlayer() {
return this.player;
}
public Genbucket getGenbucket() {
return this.genbucket;
}
/*
Needed for the event
*/
private static final HandlerList HANDLERS = new HandlerList();
public HandlerList getHandlers() {
return HANDLERS;
}
public static HandlerList getHandlerList() {
return HANDLERS;
}
@Override
public boolean isCancelled() {
return this.isCancelled;
}
@Override
public void setCancelled(boolean b) {
this.isCancelled = b;
}
}

View File

@ -1,50 +0,0 @@
package com.songoda.epicbuckets.file;
import com.songoda.epicbuckets.EpicBuckets;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
public class Config {
private FileConfiguration handler;
private File file;
private boolean isResource;
public Config(File file, boolean resource) {
this.file = file;
this.isResource = resource;
initializeHandler();
}
private void initializeHandler() {
if (!file.exists()) {
try {
if (isResource) {
EpicBuckets.getInstance().saveResource(file.getName(), false);
} else {
file.createNewFile();
}
} catch (IOException e) {
e.printStackTrace();
}
}
handler = YamlConfiguration.loadConfiguration(file);
}
public void reloadConfig() {
try {
handler.load(file);
} catch (InvalidConfigurationException | IOException e) {
e.printStackTrace();
}
}
public FileConfiguration getConfig() {
return handler;
}
}

View File

@ -1,475 +0,0 @@
package com.songoda.epicbuckets.file;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.genbucket.GenbucketType;
import com.songoda.epicbuckets.util.InventoryHelper;
import com.songoda.epicbuckets.util.Validator;
import com.songoda.epicbuckets.util.XMaterial;
import me.lucko.helper.cooldown.Cooldown;
import me.lucko.helper.cooldown.CooldownMap;
import me.lucko.helper.item.ItemStackBuilder;
import org.bukkit.block.BlockFace;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.io.File;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.stream.Collectors;
public class ConfigManager {
private EpicBuckets epicBuckets;
private HashMap<String, Config> configDatabase;
private HashMap<String, Consumer<Boolean>> settingsGenbucketBooleans;
private HashMap<String, Consumer<Integer>> settingsGenbucketIntegers;
private HashMap<String, Consumer<Boolean>> settingsHooks;
private HashMap<String, Consumer<Boolean>> settingsShop;
private String backButtonPath = "BACK-BUTTON";
private String fillItemPath = "FILL-ITEM";
private String bulkShopIncreasePath = "BULK-SHOP-INVENTORY.increase-item";
private String bulkShopDecreasePath = "BULK-SHOP-INVENTORY.decrease-item";
private String bulkShopPurchasePath = "BULK-SHOP-INVENTORY.purchase-item";
private String menuItemsPath = "MENU-ITEMS";
private List<XMaterial> ignoredMaterials;
private List<XMaterial> psuedoMaterials;
private LinkedHashMap<String, Integer> genbucketGroups;
private HashMap<GenbucketType, List<BlockFace>> genbucketValidFaces;
private HashMap<GenbucketType, BlockFace> genbucketDefaultFace;
private HashMap<GenbucketType, List<BlockFace>> genbucketLogicalFaces;
private boolean supportFactions;
private boolean supportWorldGuard;
private boolean supportGriefPrevention;
private boolean gensInWilderness;
private boolean enchantGenbuckets;
private boolean spongeCheck;
private int spongeRadius;
private int maxGenbucketsPerPlayer;
private boolean unlimitedGenbuckets;
private boolean infiniteUse;
private boolean chargeInfiniteUse;
private HashMap<GenbucketType, HashMap<ItemStack, Double>> infiniteUseCost;
private int genbucketDelay;
private CooldownMap<Player> cooldownMap;
private int maxVerticalHeight;
private int maxHorizontalLength;
private int delay;
private boolean genbucketsDisabled;
private int inventorySize;
private String inventoryName;
private boolean fillInventory;
private ItemStack backButton;
private ItemStack fillItem;
public ConfigManager() {
this.epicBuckets = EpicBuckets.getInstance();
}
public void setup() {
configDatabase = new HashMap<>();
createConfig("shops", true);
loadData();
setupBackButton();
setupFillItem();
loadBooleanSettings();
loadIntegerSettings();
epicBuckets.getShopManager().init();
}
private void loadIntegerSettings() {
/*
Genbucket
*/
settingsGenbucketIntegers = new HashMap<>();
settingsGenbucketIntegers.put("Cooldown between placements", this::setCooldown);
settingsGenbucketIntegers.put("Sponge radius", this::setSpongeRadius);
settingsGenbucketIntegers.put("Max active gens per player", this::setMaxGenbucketsPerPlayer);
settingsGenbucketIntegers.put("Max vertical height", this::setMaxVerticalHeight);
settingsGenbucketIntegers.put("Max horizontal length", this::setMaxHorizontalLength);
settingsGenbucketIntegers.put("Genbucket Speed", this::setDelay);
}
private void loadBooleanSettings() {
/*
Genbucket
*/
settingsGenbucketBooleans = new HashMap<>();
settingsGenbucketBooleans.put("Gens in Wilderness", this::setGensInWilderness);
settingsGenbucketBooleans.put("Infinite genbucket use", this::setInfiniteUse);
settingsGenbucketBooleans.put("Charge infinite use placement", this::setChargeInfiniteUse);
settingsGenbucketBooleans.put("Sponge check", this::setSpongeCheck);
settingsGenbucketBooleans.put("Unlimited active gens", this::setUnlimitedGenbuckets);
settingsGenbucketBooleans.put("Disable genbuckets", this::setGenbucketsDisabled);
/*
Hooks
*/
settingsHooks = new HashMap<>();
settingsHooks.put("Factions Support", this::setSupportFactions);
settingsHooks.put("Worldguard Support", this::setSupportWorldGuard);
settingsHooks.put("GriefPrevention Support", this::setSupportGriefPrevention);
/*
Shop
*/
settingsShop = new HashMap<>();
settingsShop.put("Close GUI after purchase", epicBuckets.getShopManager()::setCloseAfterPurchase);
settingsShop.put("Fill bulk shop", epicBuckets.getShopManager()::setBulkFillInventory);
settingsShop.put("Fill shops", this::setFillInventory);
settingsShop.put("Use back buttons in shops", epicBuckets.getShopManager()::setUseBackButtons);
}
public void reload() {
reloadConfig("shops");
epicBuckets.reloadConfig();
loadData();
setupBackButton();
setupFillItem();
}
private void loadData() {
ignoredMaterials = new ArrayList<>();
psuedoMaterials = new ArrayList<>();
genbucketGroups = new LinkedHashMap<>();
infiniteUseCost = new HashMap<>();
loadValidFaces();
ignoredMaterials = InventoryHelper.convertMaterialList(epicBuckets.getConfig().getStringList("IGNORE-MATERIALS"), "IGNORE-MATERIALS");
psuedoMaterials = InventoryHelper.convertMaterialList(epicBuckets.getConfig().getStringList("PSUEDO-MATERIALS"), "PSUEDO-MATERIALS");
supportFactions = epicBuckets.getConfig().getBoolean("FACTIONS-SUPPORT");
supportWorldGuard = epicBuckets.getConfig().getBoolean("WORLDGUARD-SUPPORT");
supportGriefPrevention = epicBuckets.getConfig().getBoolean("GRIEFPREVENTION-SUPPORT");
gensInWilderness = epicBuckets.getConfig().getBoolean("ENABLE-GENS-IN-WILDERNESS");
enchantGenbuckets = epicBuckets.getConfig().getBoolean("ENCHANT");
spongeCheck = epicBuckets.getConfig().getBoolean("USE-SPONGE-SUPPORT");
spongeRadius = epicBuckets.getConfig().getInt("SPONGE-RADIUS");
maxGenbucketsPerPlayer = epicBuckets.getConfig().getInt("MAX-ACTIVE-GEN-PER-PLAYER");
unlimitedGenbuckets = epicBuckets.getConfig().getBoolean("PLACE-UNLIMTED-GENS");
infiniteUse = epicBuckets.getConfig().getBoolean("INFINITE-USE");
maxVerticalHeight = epicBuckets.getConfig().getInt("MAX-VERTICAL-HEIGHT");
maxHorizontalLength = epicBuckets.getConfig().getInt("MAX-HORIZONTAL-LENGTH");
delay = epicBuckets.getConfig().getInt("DELAY");
setGenbucketsDisabled(epicBuckets.getConfig().getBoolean("DISABLE-GENBUCKETS"));
inventorySize = epicBuckets.getConfig().getInt(menuItemsPath + ".size");
inventoryName = epicBuckets.getConfig().getString(menuItemsPath + ".inventory-name");
fillInventory = epicBuckets.getConfig().getBoolean(menuItemsPath + ".fill");
chargeInfiniteUse = epicBuckets.getConfig().getBoolean("CHARGE-FOR-INFINITE-USE");
epicBuckets.getConfig().getConfigurationSection("CUSTOM-ACTIVE-GEN-PER-PLAY").getKeys(false)
.forEach(s -> genbucketGroups.put(epicBuckets.getConfig().getString("CUSTOM-ACTIVE-GEN-PER-PLAY." + s).split(":")[1],
Integer.parseInt(epicBuckets.getConfig().getString("CUSTOM-ACTIVE-GEN-PER-PLAY." + s).split(":")[0])));
epicBuckets.getConfig().getConfigurationSection("COST-FOR-INFINITE-USE").getKeys(false)
.forEach(bucket -> {
HashMap<ItemStack, Double> chargingCostsPerItem = new HashMap<>();
epicBuckets.getConfig().getConfigurationSection("COST-FOR-INFINITE-USE." + bucket).getKeys(false)
.forEach(item -> chargingCostsPerItem.put(XMaterial.valueOf(item).parseItem(), epicBuckets.getConfig().getDouble("COST-FOR-INFINITE-USE." + bucket + "." + item)));
infiniteUseCost.put(GenbucketType.valueOf(bucket), chargingCostsPerItem);
});
setCooldown(epicBuckets.getConfig().getInt("GENBUCKET-DELAY"));
}
private void loadValidFaces() {
genbucketValidFaces = new HashMap<>();
genbucketDefaultFace = new HashMap<>();
genbucketLogicalFaces = new HashMap<>();
epicBuckets.getConfig().getConfigurationSection("VALID-FACES").getKeys(false).forEach(s -> {
genbucketDefaultFace.put(GenbucketType.valueOf(s), BlockFace.valueOf(epicBuckets.getConfig().getString("VALID-FACES." + s + ".DEFAULT")));
genbucketValidFaces.put(GenbucketType.valueOf(s), epicBuckets.getConfig().getStringList("VALID-FACES." + s + ".WHITELIST").stream().map(s1 -> BlockFace.valueOf(s1)).collect(Collectors.toList()));
});
genbucketLogicalFaces.put(GenbucketType.HORIZONTAL, new ArrayList<>(Arrays.asList(BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH)));
genbucketLogicalFaces.put(GenbucketType.VERTICAL, new ArrayList<>(Arrays.asList(BlockFace.UP, BlockFace.DOWN)));
genbucketLogicalFaces.put(GenbucketType.INFUSED, new ArrayList<>(Arrays.asList(BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH)));
genbucketLogicalFaces.put(GenbucketType.PSUEDO, new ArrayList<>(Arrays.asList(BlockFace.UP, BlockFace.DOWN)));
}
private void setCooldown(int genbucketDelay) {
setGenbucketDelay(genbucketDelay);
if (getGenbucketDelay() > 0) {
cooldownMap = CooldownMap.create(Cooldown.of(getGenbucketDelay() / 20, TimeUnit.SECONDS));
} else {
cooldownMap = null;
}
}
private void setupFillItem() {
boolean m = Validator.isMaterial(epicBuckets.getConfig().getString(getFillItemPath() + ".material"));
fillItem = ((!m) ? XMaterial.BLACK_STAINED_GLASS_PANE.parseItem() : XMaterial.valueOf(epicBuckets.getConfig().getString(getFillItemPath() + ".material")).parseItem());
fillItem = InventoryHelper.setDisplayName(fillItem, epicBuckets.getConfig().getString(getFillItemPath() + ".name"));
}
private void setupBackButton() {
boolean m = Validator.isMaterial(epicBuckets.getConfig().getString(getBackButtonPath() + ".material"));
backButton = ((!m) ? XMaterial.BARRIER.parseItem() : XMaterial.valueOf(epicBuckets.getConfig().getString(getBackButtonPath() + ".material")).parseItem());
backButton = InventoryHelper.setDisplayName(backButton, epicBuckets.getConfig().getString(getBackButtonPath() + ".name"));
}
public boolean isOnCooldown(Player player) {
if (cooldownMap == null) return false;
return !cooldownMap.test(player);
}
public void createConfig(String name, boolean resource) {
File f = new File(epicBuckets.getDataFolder(), name + ".yml");
configDatabase.put(name, new Config(f, resource));
}
public void reloadConfig(String name) {
if (!configDatabase.containsKey(name)) return;
configDatabase.get(name).reloadConfig();
}
public FileConfiguration getConfig(String name) {
if (!configDatabase.containsKey(name)) return null;
return configDatabase.get(name).getConfig();
}
public String getBackButtonPath() {
return backButtonPath;
}
public String getFillItemPath() {
return fillItemPath;
}
public String getBulkShopIncreasePath() {
return bulkShopIncreasePath;
}
public String getBulkShopDecreasePath() {
return bulkShopDecreasePath;
}
public String getBulkShopPurchasePath() {
return bulkShopPurchasePath;
}
public List<XMaterial> getIgnoredMaterials() {
return ignoredMaterials;
}
public List<XMaterial> getPsuedoMaterials() {
return psuedoMaterials;
}
public boolean isSupportFactions() {
return supportFactions;
}
public boolean isSupportWorldGuard() {
return supportWorldGuard;
}
public boolean isSupportGriefPrevention() {
return supportGriefPrevention;
}
public boolean isGensInWilderness() {
return gensInWilderness;
}
public boolean isEnchantGenbuckets() {
return enchantGenbuckets;
}
public boolean isSpongeCheck() {
return spongeCheck;
}
public int getSpongeRadius() {
return spongeRadius;
}
public int getMaxGenbucketsPerPlayer() {
return maxGenbucketsPerPlayer;
}
public boolean isUnlimitedGenbuckets() {
return unlimitedGenbuckets;
}
public int getMaxVerticalHeight() {
return maxVerticalHeight;
}
public int getMaxHorizontalLength() {
return maxHorizontalLength;
}
public int getDelay() {
return delay;
}
public void setGenbucketsDisabled(boolean enabled) {
this.genbucketsDisabled = enabled;
}
public boolean isGenbucketsDisabled() {
return genbucketsDisabled;
}
public ItemStack getBackButton() {
return backButton;
}
public String getMenuItemsPath() {
return menuItemsPath;
}
public int getInventorySize() {
return inventorySize;
}
public String getInventoryName() {
return inventoryName;
}
public boolean isFillInventory() {
return fillInventory;
}
public ItemStack getFillItem() {
return fillItem;
}
public LinkedHashMap<String, Integer> getGenbucketGroups() {
return genbucketGroups;
}
public List<BlockFace> getValidFacesForGenbucket(GenbucketType genbucketType) {
return genbucketValidFaces.get(genbucketType);
}
public BlockFace getDefaultFaceForGenbucket(GenbucketType genbucketType) {
return genbucketDefaultFace.get(genbucketType);
}
public List<BlockFace> getLogicalFacesForGenbucket(GenbucketType genbucketType) {
return genbucketLogicalFaces.get(genbucketType);
}
public boolean isInfiniteUse() {
return infiniteUse;
}
public boolean isChargeInfiniteUse() {
return chargeInfiniteUse;
}
public double getInfiniteUseCostForGenbucketType(GenbucketType genbucketType, ItemStack item) {
for (ItemStack itemStack : infiniteUseCost.get(genbucketType).keySet()) {
if (itemStack.getType() == item.getType() && itemStack.getData() == item.getData()) {
return infiniteUseCost.get(genbucketType).get(itemStack);
}
}
return 0;
}
public int getGenbucketDelay() {
return genbucketDelay;
}
public void setBackButtonPath(String backButtonPath) {
this.backButtonPath = backButtonPath;
}
public void setSupportFactions(boolean supportFactions) {
this.supportFactions = supportFactions;
}
public void setSupportWorldGuard(boolean supportWorldGuard) {
this.supportWorldGuard = supportWorldGuard;
}
public void setSupportGriefPrevention(boolean supportGriefPrevention) {
this.supportGriefPrevention = supportGriefPrevention;
}
public void setGensInWilderness(boolean gensInWilderness) {
this.gensInWilderness = gensInWilderness;
}
public void setSpongeCheck(boolean spongeCheck) {
this.spongeCheck = spongeCheck;
}
public void setSpongeRadius(int spongeRadius) {
this.spongeRadius = spongeRadius;
}
public void setMaxGenbucketsPerPlayer(int maxGenbucketsPerPlayer) {
this.maxGenbucketsPerPlayer = maxGenbucketsPerPlayer;
}
public void setUnlimitedGenbuckets(boolean unlimitedGenbuckets) {
this.unlimitedGenbuckets = unlimitedGenbuckets;
}
public void setInfiniteUse(boolean infiniteUse) {
this.infiniteUse = infiniteUse;
}
public void setChargeInfiniteUse(boolean chargeInfiniteUse) {
this.chargeInfiniteUse = chargeInfiniteUse;
}
public void setGenbucketDelay(int genbucketDelay) {
this.genbucketDelay = genbucketDelay;
}
public void setMaxVerticalHeight(int maxVerticalHeight) {
this.maxVerticalHeight = maxVerticalHeight;
}
public void setMaxHorizontalLength(int maxHorizontalLength) {
this.maxHorizontalLength = maxHorizontalLength;
}
public void setDelay(int delay) {
this.delay = delay;
}
public void setFillInventory(boolean fillInventory) {
this.fillInventory = fillInventory;
}
public HashMap<String, Consumer<Boolean>> getSettingsGenbucketBooleans() {
return settingsGenbucketBooleans;
}
public HashMap<String, Consumer<Integer>> getSettingsGenbucketIntegers() {
return settingsGenbucketIntegers;
}
public HashMap<String, Consumer<Boolean>> getSettingsHooks() {
return settingsHooks;
}
public HashMap<String, Consumer<Boolean>> getSettingsShop() {
return settingsShop;
}
}

View File

@ -1,170 +0,0 @@
package com.songoda.epicbuckets.genbucket;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.shop.SubShop;
import com.songoda.epicbuckets.util.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitTask;
import java.util.UUID;
public abstract class Genbucket {
protected EpicBuckets epicBuckets;
private Player owner;
private GenbucketType genbucketType;
private BlockFace blockFace;
private Block clickedBlock;
private Block sourceBlock;
private Block currentBlock;
private SubShop subShop;
private UUID genUUID;
private Location playerLocation;
private BukkitTask generation;
private boolean isGravityGen;
public Genbucket(GenbucketType genbucketType, Block clickedBlock, BlockFace blockFace, SubShop s, Player owner) {
epicBuckets = EpicBuckets.getInstance();
this.genUUID = UUID.randomUUID();
this.owner = owner;
this.genbucketType = genbucketType;
this.blockFace = blockFace;
this.clickedBlock = clickedBlock;
this.currentBlock = clickedBlock;
this.sourceBlock = clickedBlock.getRelative(blockFace);
this.subShop = s;
this.playerLocation = owner.getLocation();
isGravityGen = s.getGenItem().getType().hasGravity();
}
public abstract void generate();
public Block getSourceBlock() {
return sourceBlock;
}
public Player getOwner() {
return owner;
}
public Location getPlayerLocation() {
return playerLocation;
}
public Location getClickedLocation() {
return clickedBlock.getLocation();
}
public UUID getGenUUID() {
return genUUID;
}
public GenbucketType getGenbucketType() {
return genbucketType;
}
public boolean isValidBlockFace() {
return epicBuckets.getConfigManager().getValidFacesForGenbucket(getGenbucketType()).contains(getBlockFace());
}
public boolean calculateBlockFace() {
if (!isValidBlockFace()) return false;
if (!epicBuckets.getConfigManager().getLogicalFacesForGenbucket(getGenbucketType()).contains(getBlockFace())) {
blockFace = epicBuckets.getConfigManager().getDefaultFaceForGenbucket(genbucketType);
clickedBlock = sourceBlock.getRelative(getBlockFace().getOppositeFace());
currentBlock = clickedBlock;
}
return true;
}
public BukkitTask getGeneration() {
return generation;
}
public void setGeneration(BukkitTask task) {
generation = task;
}
protected boolean isBelowVoid(int moved) {
if (blockFace != BlockFace.DOWN) return false;
return sourceBlock.getRelative(0, -moved, 0).getLocation().getBlockY() < 0;
}
protected boolean gravityGen(int moved) {
Block b = getNextBlock();
if (isBelowVoid(moved + 1)) return false;
if (b.getRelative(getBlockFace()).getType() != Material.AIR) {
if (b.getRelative(getBlockFace()).getType() != XMaterial.COBBLESTONE.parseMaterial()) {
b.setType(getGenItem().getType());
return false;
}
}
b.getRelative(getBlockFace()).setType(XMaterial.COBBLESTONE.parseMaterial());
b.setType(getGenItem().getType());
return true;
}
protected boolean gravityGenInfused(int moved, BlockFace blockFace) {
Block b = getNextBlock(moved, blockFace);
if (isBelowVoid(moved + 1)) return false;
if (b.getRelative(BlockFace.DOWN).getType() != Material.AIR) {
if (b.getRelative(BlockFace.DOWN).getType() != XMaterial.COBBLESTONE.parseMaterial()) {
b.setType(getGenItem().getType());
return false;
}
}
b.getRelative(BlockFace.DOWN).setType(XMaterial.COBBLESTONE.parseMaterial());
b.setType(getGenItem().getType());
return true;
}
protected Block getNextBlock(int moved, BlockFace blockFace) {
return clickedBlock.getRelative(blockFace).getRelative(0, moved, 0);
}
protected Block getNextBlock() {
currentBlock = currentBlock.getRelative(getBlockFace());
return currentBlock;
}
protected void fixHole(Block block) {
if (block.getType() == XMaterial.AIR.parseMaterial()) block.setType(getGenItem().getType());
}
protected boolean spongeInRange(Block block) {
if (!epicBuckets.getConfigManager().isSpongeCheck()) return false;
int radius = (epicBuckets.getConfigManager().getSpongeRadius() - 1) / 2;
for (int x = -radius; x <= radius; x++) {
for (int z = -radius; z <= radius; z++) {
if (block.getRelative(x, 0, z).getType() == XMaterial.SPONGE.parseMaterial()) return true;
}
}
return false;
}
protected boolean placeGen(Block block) {
if (!epicBuckets.getConfigManager().getIgnoredMaterials().contains(XMaterial.requestXMaterial(block.getType().name(), block.getData()))) return false;
if (spongeInRange(block)) return false;
block.setType(getGenItem().getType());
return true;
}
public ItemStack getGenItem() {
return subShop.getGenItem();
}
protected BlockFace getBlockFace() {
return blockFace;
}
protected boolean isGravityGen() {
return isGravityGen && getBlockFace() == BlockFace.DOWN;
}
}

View File

@ -1,105 +0,0 @@
package com.songoda.epicbuckets.genbucket;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.regionhandler.*;
import com.songoda.epicbuckets.util.ChatUtil;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.*;
public class GenbucketManager {
private EpicBuckets epicBuckets;
private HashMap<UUID, List<Genbucket>> activeGens;
private List<Player> admins;
public GenbucketManager() {
this.epicBuckets = EpicBuckets.getInstance();
activeGens = new HashMap<>();
admins = new ArrayList<>();
}
public void notifyAdmins(Player user, Genbucket genbucket) {
admins.forEach(player -> player.sendMessage(ChatUtil.colorPrefix(epicBuckets.getLocale().getMessage("event.genbucket.admin").replace("%player%", user.getName()).replace("%genbucket%", StringUtils.capitalize(genbucket.getGenbucketType().name.toLowerCase()) + " genbucket"))));
}
public void toggleAdmin(Player player) {
if (admins.contains(player)) {
removeAdmin(player);
player.sendMessage(ChatUtil.colorPrefix(epicBuckets.getLocale().getMessage("command.admin.toggle").replace("%mode%", "&cdisabled")));
return;
}
addAdmin(player);
player.sendMessage(ChatUtil.colorPrefix(epicBuckets.getLocale().getMessage("command.admin.toggle").replace("%mode%", "&aenabled")));
}
private void removeAdmin(Player player) {
admins.remove(player);
}
private void addAdmin(Player player) {
admins.add(player);
}
public List<Genbucket> activeGensInOneList() {
List<Genbucket> gens = new ArrayList<>();
activeGens.forEach((uuid, genbuckets) -> gens.addAll(genbuckets));
return gens;
}
public int getTotalActiveGenbuckets(HashMap<UUID, List<Genbucket>> gens) {
int total = 0;
for (UUID uuid : gens.keySet()) {
total += gens.get(uuid).size();
}
return total;
}
public void unregisterGenbucketForPlayer(Player owner, UUID genUUID) {
List<Genbucket> genbuckets = activeGens.get(owner.getUniqueId());
List<Genbucket> newGenbuckets = new ArrayList<>();
genbuckets.stream().filter(genbucket -> genbucket.getGenUUID() != genUUID).forEach(newGenbuckets::add);
activeGens.put(owner.getUniqueId(), newGenbuckets);
}
public void registerGenbucketForPlayer(Player owner, Genbucket genbucket) {
if (!activeGens.containsKey(owner.getUniqueId())) activeGens.put(owner.getUniqueId(), new ArrayList<>(Arrays.asList(genbucket)));
List<Genbucket> genbucketItems = activeGens.get(owner.getUniqueId());
genbucketItems.add(genbucket);
activeGens.put(owner.getUniqueId(), genbucketItems);
}
public boolean canRegisterNewGenbucket(Player owner) {
if (epicBuckets.getConfigManager().isUnlimitedGenbuckets()) return true;
if (!activeGens.containsKey(owner.getUniqueId())) return true;
if (activeGens.get(owner.getUniqueId()).size() <= getMaxGenbucketsForPlayer(owner)) return true;
return false;
}
public int getMaxGenbucketsForPlayer(Player owner) {
LinkedHashMap<String, Integer> groups = epicBuckets.getConfigManager().getGenbucketGroups();
for (String perm : groups.keySet()) {
if (owner.hasPermission(perm)) return groups.get(perm);
}
return epicBuckets.getConfigManager().getMaxGenbucketsPerPlayer();
}
public boolean canPlaceGenbucket(Player player, Location location) {
boolean factionsCheck = RegionFactions.canBuild(player, location);
boolean griefPreventionCheck = RegionGriefPrevention.canBuild(player, location);
boolean worldGuardCheck = RegionWorldGuard.canBuild(player, location);
boolean worldBorderCheck = RegionWorldBorder.isOutsideOfBorder(location);
if (!factionsCheck || !griefPreventionCheck || !worldGuardCheck || worldBorderCheck) {
return false;
}
return true;
}
public HashMap<UUID, List<Genbucket>> getActiveGens() {
return activeGens;
}
}

View File

@ -1,22 +0,0 @@
package com.songoda.epicbuckets.genbucket;
public enum GenbucketType {
HORIZONTAL("HORIZONTAL"),
INFUSED("INFUSED"),
PSUEDO("PSUEDO"),
VERTICAL("VERTICAL");
public final String name;
GenbucketType(String name) {
this.name = name;
}
@Override
public String toString() {
return name;
}
}

View File

@ -1,35 +0,0 @@
package com.songoda.epicbuckets.genbucket.types;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.genbucket.Genbucket;
import com.songoda.epicbuckets.genbucket.GenbucketType;
import com.songoda.epicbuckets.shop.SubShop;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class Horizontal extends Genbucket {
private int blocksPlaced = 0;
public Horizontal(Player owner, Block clickedBlock, BlockFace blockFace, SubShop s) {
super(GenbucketType.HORIZONTAL, clickedBlock, blockFace, s, owner);
}
@Override
public void generate() {
BukkitRunnable runnable = new BukkitRunnable() {
@Override
public void run() {
if (blocksPlaced >= epicBuckets.getConfigManager().getMaxHorizontalLength() || !placeGen(getNextBlock())) {
epicBuckets.getGenbucketManager().unregisterGenbucketForPlayer(getOwner(), getGenUUID());
cancel();
return;
}
blocksPlaced++;
}
};
setGeneration(runnable.runTaskTimer(EpicBuckets.getInstance(), 0, epicBuckets.getConfigManager().getDelay()));
}
}

View File

@ -1,57 +0,0 @@
package com.songoda.epicbuckets.genbucket.types;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.genbucket.Genbucket;
import com.songoda.epicbuckets.genbucket.GenbucketType;
import com.songoda.epicbuckets.shop.SubShop;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class Infused extends Genbucket {
private int blocksPlaced = 0;
private boolean side1 = true;
private boolean side2 = true;
public Infused(Player owner, Block clickedBlock, BlockFace blockFace, SubShop s) {
super(GenbucketType.INFUSED, clickedBlock, blockFace, s, owner);
}
@Override
public void generate() {
BukkitRunnable runnable = new BukkitRunnable() {
@Override
public void run() {
// if (isGravityGen()) {
// if (!side1 && !side2) {
// epicBuckets.getGenbucketManager().unregisterGenbucketForPlayer(getOwner(), getGenUUID());
// cancel();
// return;
// }
// if (side1 && !gravityGenInfused(blocksPlaced, getBlockFace())) {
// side1 = false;
// }
// if (side2 && !gravityGenInfused(blocksPlaced, getBlockFace().getOppositeFace())) {
// side2 = false;
// }
// } else {
if ((!side1 && !side2) || blocksPlaced >= epicBuckets.getConfigManager().getMaxVerticalHeight()) {
epicBuckets.getGenbucketManager().unregisterGenbucketForPlayer(getOwner(), getGenUUID());
cancel();
return;
}
if (side1 && !placeGen(getNextBlock(blocksPlaced, getBlockFace()))) {
side1 = false;
}
if (side2 && !placeGen(getNextBlock(blocksPlaced, getBlockFace().getOppositeFace()))) {
side2 = false;
}
blocksPlaced++;
// }
}
};
setGeneration(runnable.runTaskTimer(EpicBuckets.getInstance(), 0, epicBuckets.getConfigManager().getDelay()));
}
}

View File

@ -1,36 +0,0 @@
package com.songoda.epicbuckets.genbucket.types;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.genbucket.Genbucket;
import com.songoda.epicbuckets.genbucket.GenbucketType;
import com.songoda.epicbuckets.shop.SubShop;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class PsuedoVertical extends Genbucket {
private int blocksUp = 0;
public PsuedoVertical(Player owner, Block clickedBlock, BlockFace blockFace, SubShop s) {
super(GenbucketType.PSUEDO, clickedBlock, blockFace, s, owner);
}
@Override
public void generate() {
BukkitRunnable runnable = new BukkitRunnable() {
@Override
public void run() {
if (isBelowVoid(blocksUp) || blocksUp >= epicBuckets.getConfigManager().getMaxVerticalHeight()) {
epicBuckets.getGenbucketManager().unregisterGenbucketForPlayer(getOwner(), getGenUUID());
cancel();
return;
}
fixHole(getNextBlock());
blocksUp++;
}
};
setGeneration(runnable.runTaskTimer(EpicBuckets.getInstance(), 0, epicBuckets.getConfigManager().getDelay()));
}
}

View File

@ -1,41 +0,0 @@
package com.songoda.epicbuckets.genbucket.types;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.genbucket.Genbucket;
import com.songoda.epicbuckets.genbucket.GenbucketType;
import com.songoda.epicbuckets.shop.SubShop;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class Vertical extends Genbucket {
private int blocksPlaced = 0;
public Vertical(Player owner, Block clickedBlock, BlockFace blockFace, SubShop s) {
super(GenbucketType.VERTICAL, clickedBlock, blockFace, s, owner);
}
@Override
public void generate() {
BukkitRunnable runnable = new BukkitRunnable() {
@Override
public void run() {
if (isGravityGen()) {
if (!gravityGen(blocksPlaced)) {
epicBuckets.getGenbucketManager().unregisterGenbucketForPlayer(getOwner(), getGenUUID());
cancel();
return;
}
} else if (isBelowVoid(blocksPlaced + 1) || blocksPlaced >= epicBuckets.getConfigManager().getMaxVerticalHeight() || !placeGen(getNextBlock())) {
epicBuckets.getGenbucketManager().unregisterGenbucketForPlayer(getOwner(), getGenUUID());
cancel();
return;
}
blocksPlaced++;
}
};
setGeneration(runnable.runTaskTimer(EpicBuckets.getInstance(), 0, epicBuckets.getConfigManager().getDelay()));
}
}

View File

@ -1,59 +0,0 @@
package com.songoda.epicbuckets.gui;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.file.ConfigManager;
import com.songoda.epicbuckets.shop.Shop;
import com.songoda.epicbuckets.shop.ShopManager;
import com.songoda.epicbuckets.util.gui.AbstractGUI;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class GUIMain extends AbstractGUI {
private EpicBuckets epicBuckets;
private ConfigManager configManager;
private ShopManager shopManager;
private int size;
public GUIMain(Player player) {
super(player);
this.epicBuckets = EpicBuckets.getInstance();
configManager = epicBuckets.getConfigManager();
shopManager = epicBuckets.getShopManager();
this.size = configManager.getInventorySize() * 9;
init(EpicBuckets.getInstance().getConfigManager().getInventoryName(), size);
}
@Override
protected void constructGUI() {
int num = 0;
while (num != size) {
ItemStack glass = configManager.getFillItem();
inventory.setItem(num, glass);
num++;
}
epicBuckets.getShopManager().getShops().stream().filter(Shop::isEnabled).forEach(shop -> {
inventory.setItem(shop.getSlot(), shop.getShopItem());
});
}
@Override
protected void registerClickables() {
epicBuckets.getShopManager().getShops().stream().filter(Shop::isEnabled).forEach(shop -> {
registerClickable(shop.getSlot(), ((player1, inventory1, cursor, slot, type) -> {
new GUIShop(player, shop);
}));
});
}
@Override
protected void registerOnCloses() {
}
}

View File

@ -1,4 +0,0 @@
package com.songoda.epicbuckets.gui;
public class GUIMain {
}

View File

@ -1,73 +0,0 @@
package com.songoda.epicbuckets.gui;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.file.ConfigManager;
import com.songoda.epicbuckets.shop.Shop;
import com.songoda.epicbuckets.shop.ShopManager;
import com.songoda.epicbuckets.shop.SubShop;
import com.songoda.epicbuckets.util.gui.AbstractGUI;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
public class GUIShop extends AbstractGUI {
private EpicBuckets epicBuckets;
private ConfigManager configManager;
private ShopManager shopManager;
private Shop shop;
private int size;
public GUIShop(Player player, Shop shop) {
super(player);
this.epicBuckets = EpicBuckets.getInstance();
configManager = epicBuckets.getConfigManager();
shopManager = epicBuckets.getShopManager();
this.size = shop.getInventorySize() * 9;
this.shop = shop;
init(shop.getInventoryName(), size);
}
@Override
protected void constructGUI() {
if (shop.isFillInventory()) {
int num = 0;
while (num != size) {
ItemStack glass = configManager.getFillItem();
inventory.setItem(num, glass);
num++;
}
}
if (shopManager.isUseBackButtons()) {
inventory.setItem(shop.getBackButtonSlot(), configManager.getBackButton());
}
shop.getSubShops().stream().filter(SubShop::isEnabled).forEach(subShop ->
inventory.setItem(subShop.getSlot(), subShop.getShopItem()));
}
@Override
protected void registerClickables() {
if (shopManager.isUseBackButtons()) {
registerClickable(shop.getBackButtonSlot(), ((player, inventory, cursor, slot, type) -> new GUIMain(player)));
}
shop.getSubShops().stream().filter(SubShop::isEnabled).forEach(subShop -> {
registerClickable(subShop.getSlot(), ClickType.LEFT, ((player1, inventory1, cursor, slot, type) -> {
if (shopManager.hasEnoughFunds(player1, subShop, 1) && !shopManager.inventoryFull(player)) shopManager.buyFromShop(player, subShop, 1);
if (shopManager.isCloseAfterPurchase()) new GUIMain(player);
}));
registerClickable(subShop.getSlot(), ClickType.RIGHT, ((player1, inventory1, cursor, slot, type) -> new GUIBulk(player, shop, subShop)));
});
}
@Override
protected void registerOnCloses() {
}
}

View File

@ -1,59 +0,0 @@
package com.songoda.epicbuckets.gui;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.file.ConfigManager;
import com.songoda.epicbuckets.shop.Shop;
import com.songoda.epicbuckets.shop.ShopManager;
import com.songoda.epicbuckets.util.gui.AbstractGUI;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class GUIMain extends AbstractGUI {
private EpicBuckets epicBuckets;
private ConfigManager configManager;
private ShopManager shopManager;
private int size;
public GUIMain(Player player) {
super(player);
this.epicBuckets = EpicBuckets.getInstance();
configManager = epicBuckets.getConfigManager();
shopManager = epicBuckets.getShopManager();
this.size = configManager.getInventorySize() * 9;
init(EpicBuckets.getInstance().getConfigManager().getInventoryName(), size);
}
@Override
protected void constructGUI() {
int num = 0;
while (num != size) {
ItemStack glass = configManager.getFillItem();
inventory.setItem(num, glass);
num++;
}
epicBuckets.getShopManager().getShops().stream().filter(Shop::isEnabled).forEach(shop -> {
inventory.setItem(shop.getSlot(), shop.getShopItem());
});
}
@Override
protected void registerClickables() {
epicBuckets.getShopManager().getShops().stream().filter(Shop::isEnabled).forEach(shop -> {
new GUIShop(shop, player).open();
getSlot(shop.getSlot()).bind(ClickType.LEFT, () -> handleClick(shop));
});
}
@Override
protected void registerOnCloses() {
}
}

View File

@ -1,60 +0,0 @@
package com.songoda.epicspawners.hooks;
import com.songoda.epicspawners.api.utils.ClaimableProtectionPluginHook;
import com.wasteofplastic.askyblock.ASkyBlock;
import com.wasteofplastic.askyblock.ASkyBlockAPI;
import com.wasteofplastic.askyblock.Island;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.List;
import java.util.Set;
import java.util.UUID;
public class HookASkyBlock implements ClaimableProtectionPluginHook {
private final ASkyBlockAPI skyblock;
public HookASkyBlock() {
this.skyblock = ASkyBlockAPI.getInstance();
}
@Override
public JavaPlugin getPlugin() {
return ASkyBlock.getPlugin();
}
@Override
public boolean canBuild(Player player, Location location) {
Island island = skyblock.getIslandAt(location);
if (island == null) return true;
UUID owner = island.getOwner();
UUID playerUUID = player.getUniqueId();
if (owner == null || owner.equals(playerUUID)) return true;
List<UUID> teamMembers = skyblock.getTeamMembers(owner);
if (teamMembers.contains(playerUUID)) return true;
Set<Location> coopIslands = skyblock.getCoopIslands(player);
for (Location islandLocation : coopIslands) {
if (skyblock.getIslandAt(islandLocation).getOwner().equals(playerUUID)) {
return true;
}
}
return false;
}
@Override
public boolean isInClaim(Location location, String id) {
return skyblock.getOwner(location).toString().equals(id);
}
@Override
public String getClaimID(String name) {
return null;
}
}

View File

@ -1,45 +0,0 @@
package com.songoda.epicspawners.hooks;
import com.songoda.epicspawners.api.utils.ClaimableProtectionPluginHook;
import me.markeh.factionsframework.FactionsFramework;
import me.markeh.factionsframework.entities.FPlayer;
import me.markeh.factionsframework.entities.FPlayers;
import me.markeh.factionsframework.entities.Faction;
import me.markeh.factionsframework.entities.Factions;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class HookFactions implements ClaimableProtectionPluginHook {
private final FactionsFramework factions;
public HookFactions() {
this.factions = FactionsFramework.get();
}
@Override
public JavaPlugin getPlugin() {
return factions;
}
@Override
public boolean canBuild(Player player, Location location) {
FPlayer fPlayer = FPlayers.getBySender(player);
Faction faction = Factions.getFactionAt(location);
return faction.isNone() || fPlayer.getFaction().equals(faction);
}
@Override
public boolean isInClaim(Location location, String id) {
return Factions.getFactionAt(location).getId().equals(id);
}
@Override
public String getClaimID(String name) {
Faction faction = Factions.getByName(name, "");
return (faction != null) ? faction.getId() : null;
}
}

View File

@ -1,30 +0,0 @@
package com.songoda.epicspawners.hooks;
import com.songoda.epicspawners.api.utils.ProtectionPluginHook;
import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class HookGriefPrevention implements ProtectionPluginHook {
private final GriefPrevention griefPrevention;
public HookGriefPrevention() {
this.griefPrevention = GriefPrevention.instance;
}
@Override
public JavaPlugin getPlugin() {
return griefPrevention;
}
@Override
public boolean canBuild(Player player, Location location) {
Claim claim = griefPrevention.dataStore.getClaimAt(location, false, null);
return claim != null && claim.allowBuild(player, Material.SPAWNER) == null;
}
}

View File

@ -1,38 +0,0 @@
package com.songoda.epicspawners.hooks;
import com.songoda.epicspawners.api.utils.ProtectionPluginHook;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.kingdoms.constants.land.Land;
import org.kingdoms.constants.land.SimpleChunkLocation;
import org.kingdoms.constants.player.KingdomPlayer;
import org.kingdoms.main.Kingdoms;
import org.kingdoms.manager.game.GameManagement;
public class HookKingdoms implements ProtectionPluginHook {
private final Kingdoms kingdoms;
public HookKingdoms() {
this.kingdoms = Kingdoms.getInstance();
}
@Override
public JavaPlugin getPlugin() {
return kingdoms;
}
@Override
public boolean canBuild(Player player, Location location) {
KingdomPlayer kPlayer = GameManagement.getPlayerManager().getOfflineKingdomPlayer(player).getKingdomPlayer();
if (kPlayer.getKingdom() == null) return true;
SimpleChunkLocation chunkLocation = new SimpleChunkLocation(location.getChunk());
Land land = GameManagement.getLandManager().getOrLoadLand(chunkLocation);
String owner = land.getOwner();
return owner == null || kPlayer.getKingdom().getKingdomName().equals(owner);
}
}

View File

@ -1,37 +0,0 @@
package com.songoda.epicspawners.hooks;
import com.github.intellectualsites.plotsquared.api.PlotAPI;
import com.github.intellectualsites.plotsquared.bukkit.BukkitMain;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.songoda.epicspawners.api.utils.ProtectionPluginHook;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class HookPlotSquared implements ProtectionPluginHook {
private final PlotAPI plotSquared;
public HookPlotSquared() {
this.plotSquared = new PlotAPI();
}
@Override
public JavaPlugin getPlugin() { // BukkitMain? Really?
return JavaPlugin.getPlugin(BukkitMain.class);
}
@Override
public boolean canBuild(Player player, Location location) {
com.github.intellectualsites.plotsquared.plot.object.Location plotLocation =
new com.github.intellectualsites.plotsquared.plot.object.Location(location.getWorld().getName(),
location.getBlockX(), location.getBlockY(), location.getBlockZ());
Plot plot = plotLocation.getPlot();
return plot != null
&& plot.getOwners().contains(player.getUniqueId())
&& plot.getMembers().contains(player.getUniqueId());
}
}

View File

@ -1,32 +0,0 @@
package com.songoda.epicspawners.hooks;
import br.net.fabiozumbi12.RedProtect.Bukkit.API.RedProtectAPI;
import br.net.fabiozumbi12.RedProtect.Bukkit.RedProtect;
import br.net.fabiozumbi12.RedProtect.Bukkit.Region;
import com.songoda.epicspawners.api.utils.ProtectionPluginHook;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class HookRedProtect implements ProtectionPluginHook {
private final RedProtect redProtect;
public HookRedProtect() {
this.redProtect = RedProtect.get();
}
@Override
public JavaPlugin getPlugin() {
return redProtect;
}
@Override
public boolean canBuild(Player player, Location location) {
RedProtectAPI api = redProtect.getAPI();
Region region = api.getRegion(location);
return region != null && region.canBuild(player);
}
}

View File

@ -1,59 +0,0 @@
package com.songoda.epicspawners.hooks;
import com.songoda.epicspawners.api.utils.ClaimableProtectionPluginHook;
import me.goodandevil.skyblock.SkyBlock;
import me.goodandevil.skyblock.island.Island;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.List;
import java.util.Set;
import java.util.UUID;
public class HookSkyBlockEarth implements ClaimableProtectionPluginHook {
private final SkyBlock skyblock;
public HookSkyBlockEarth() {
this.skyblock = SkyBlock.getInstance();
}
@Override
public JavaPlugin getPlugin() {
return SkyBlock.getInstance();
}
@Override
public boolean canBuild(Player player, Location location) {
Island island = skyblock.getIslandManager().getIslandAtLocation(location);
if (island == null) return true;
UUID owner = island.getOwnerUUID();
UUID playerUUID = player.getUniqueId();
if (owner == null || owner.equals(playerUUID)) return true;
Set<UUID> teamMembers = island.getCoopPlayers();
if (teamMembers.contains(playerUUID)) return true;
List<Island> coopIslands = skyblock.getIslandManager().getCoopIslands(player);
for (Island is : coopIslands) {
if (is.getOwnerUUID().equals(playerUUID)) {
return true;
}
}
return false;
}
@Override
public boolean isInClaim(Location location, String id) {
return skyblock.getIslandManager().getIslandAtLocation(location).getOwnerUUID().toString().equals(id);
}
@Override
public String getClaimID(String name) {
return null;
}
}

View File

@ -1,60 +0,0 @@
package com.songoda.epicspawners.hooks;
import com.palmergames.bukkit.towny.Towny;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.TownyUniverse;
import com.songoda.epicspawners.api.utils.ClaimableProtectionPluginHook;
import com.songoda.epicspawners.utils.Debugger;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class HookTowny implements ClaimableProtectionPluginHook {
private final Towny towny;
public HookTowny() {
this.towny = Towny.getPlugin();
}
@Override
public JavaPlugin getPlugin() {
return towny;
}
@Override
public boolean canBuild(Player player, Location location) {
if (TownyUniverse.isWilderness(location.getBlock()) || !TownyUniverse.getTownBlock(location).hasTown())
return true;
try {
Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
return resident.hasTown() && TownyUniverse.getTownName(location).equals(resident.getTown().getName());
} catch (NotRegisteredException e) {
Debugger.runReport(e);
return false;
}
}
@Override
public boolean isInClaim(Location location, String id) {
try {
return TownyUniverse.isWilderness(location.getBlock()) && TownyUniverse.getTownBlock(location).getTown().getUID().toString().equals(id);
} catch (NotRegisteredException e) {
Debugger.runReport(e);
return false;
}
}
@Override
public String getClaimID(String name) {
try {
return TownyUniverse.getDataSource().getTown(name).getUID().toString();
} catch (NotRegisteredException e) {
Debugger.runReport(e);
return null;
}
}
}

View File

@ -1,38 +0,0 @@
package com.songoda.epicspawners.hooks;
import com.songoda.epicspawners.api.utils.ClaimableProtectionPluginHook;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import us.talabrek.ultimateskyblock.api.uSkyBlockAPI;
public class HookUSkyBlock implements ClaimableProtectionPluginHook {
private final uSkyBlockAPI uSkyblock;
public HookUSkyBlock() {
this.uSkyblock = (uSkyBlockAPI) Bukkit.getPluginManager().getPlugin("USkyBlock");
}
@Override
public JavaPlugin getPlugin() { // uSkyBlockAPI is also an instance of JavaPlugin
return (JavaPlugin) uSkyblock;
}
@Override
public boolean canBuild(Player player, Location location) {
return uSkyblock.getIslandInfo(location).getOnlineMembers().contains(player) || uSkyblock.getIslandInfo(location).isLeader(player);
}
@Override
public boolean isInClaim(Location location, String id) {
return uSkyblock.getIslandInfo(location).getLeader().equals(id);
}
@Override
public String getClaimID(String name) {
return null;
}
}

View File

@ -1,34 +0,0 @@
package com.songoda.epicspawners.hooks;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import com.songoda.epicspawners.api.utils.ProtectionPluginHook;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class HookWorldGuard implements ProtectionPluginHook {
private final WorldGuard worldGuard;
public HookWorldGuard() {
this.worldGuard = WorldGuard.getInstance();
}
@Override
public JavaPlugin getPlugin() {
return WorldGuardPlugin.inst();
}
@Override
public boolean canBuild(Player player, Location location) {
RegionQuery q = worldGuard.getPlatform().getRegionContainer().createQuery();
ApplicableRegionSet ars = q.getApplicableRegions(BukkitAdapter.adapt(player.getLocation()));
return ars.testState(WorldGuardPlugin.inst().wrapPlayer(player), Flags.BUILD);
}
}

View File

@ -1,130 +0,0 @@
package com.songoda.epicbuckets.listener;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.event.GenbucketPlaceEvent;
import com.songoda.epicbuckets.genbucket.Genbucket;
import com.songoda.epicbuckets.genbucket.GenbucketType;
import com.songoda.epicbuckets.genbucket.types.Horizontal;
import com.songoda.epicbuckets.genbucket.types.Infused;
import com.songoda.epicbuckets.genbucket.types.PsuedoVertical;
import com.songoda.epicbuckets.genbucket.types.Vertical;
import com.songoda.epicbuckets.util.XMaterial;
import de.tr7zw.itemnbtapi.NBTItem;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerInteractEvent;
public class GenbucketPlaceListener implements Listener {
@EventHandler
public void emptyBucket(PlayerBucketEmptyEvent e) {
NBTItem nbtItem = new NBTItem(e.getItemStack());
if (nbtItem.hasKey("Genbucket")) {
e.setCancelled(true);
e.getBlockClicked().getRelative(e.getBlockFace()).getState().update();
e.getBlockClicked().getState().update();
}
}
@EventHandler
public void onInteract(PlayerInteractEvent e) {
if (e.getAction() != Action.RIGHT_CLICK_BLOCK || e.getItem() == null) return;
NBTItem nbtItem = new NBTItem(e.getItem());
if (!nbtItem.hasKey("Genbucket")) return;
e.setCancelled(true);
boolean isInfiniteUse = EpicBuckets.getInstance().getConfigManager().isInfiniteUse();
boolean isInfiniteUseCharge = EpicBuckets.getInstance().getConfigManager().isChargeInfiniteUse();
if (!e.getPlayer().hasPermission("epicbuckets.place")) {
e.getPlayer().sendMessage(EpicBuckets.getInstance().getLocale().getMessage("event.place.nothere"));
return;
}
if (EpicBuckets.getInstance().getConfigManager().isOnCooldown(e.getPlayer())) {
e.getPlayer().sendMessage(EpicBuckets.getInstance().getLocale().getMessage("event.place.delay"));
return;
}
if (EpicBuckets.getInstance().getConfigManager().isGenbucketsDisabled()) {
e.getPlayer().sendMessage(EpicBuckets.getInstance().getLocale().getMessage("event.genbucket.disabled"));
return;
}
if (!EpicBuckets.getInstance().getGenbucketManager().canRegisterNewGenbucket(e.getPlayer())) {
e.getPlayer().sendMessage(EpicBuckets.getInstance().getLocale().getMessage("event.place.wait"));
return;
}
if (!EpicBuckets.getInstance().getGenbucketManager().canPlaceGenbucket(e.getPlayer(), e.getClickedBlock().getLocation())) {
e.getPlayer().sendMessage(EpicBuckets.getInstance().getLocale().getMessage("event.place.nothere"));
return;
}
Genbucket genbucket = null;
switch (GenbucketType.valueOf(nbtItem.getString("Type"))) {
case PSUEDO:
genbucket = new PsuedoVertical(e.getPlayer(), e.getClickedBlock(), e.getBlockFace(), EpicBuckets.getInstance().getShopManager().getShop(nbtItem.getString("Shop")).getSubShop(nbtItem.getString("SubShop")));
break;
case INFUSED:
genbucket = new Infused(e.getPlayer(), e.getClickedBlock(), e.getBlockFace(), EpicBuckets.getInstance().getShopManager().getShop(nbtItem.getString("Shop")).getSubShop(nbtItem.getString("SubShop")));
break;
case VERTICAL:
genbucket = new Vertical(e.getPlayer(), e.getClickedBlock(), e.getBlockFace(), EpicBuckets.getInstance().getShopManager().getShop(nbtItem.getString("Shop")).getSubShop(nbtItem.getString("SubShop")));
break;
case HORIZONTAL:
genbucket = new Horizontal(e.getPlayer(), e.getClickedBlock(), e.getBlockFace(), EpicBuckets.getInstance().getShopManager().getShop(nbtItem.getString("Shop")).getSubShop(nbtItem.getString("SubShop")));
}
if (!genbucket.calculateBlockFace()) {
e.getPlayer().sendMessage(EpicBuckets.getInstance().getLocale().getMessage("event.genbucket.placedwrong").replace("%genbucket%", genbucket.getGenbucketType().name.toUpperCase() + " genbucket"));
return;
}
if (genbucket.getGenbucketType() == GenbucketType.PSUEDO && !EpicBuckets.getInstance().getConfigManager().getPsuedoMaterials().contains(XMaterial.requestXMaterial(e.getClickedBlock().getType().name(), e.getClickedBlock().getData()))) {
e.getPlayer().sendMessage(EpicBuckets.getInstance().getLocale().getMessage("event.genbucket.wrongmaterialpsuedo"));
return;
}
double infiniteUseCost = EpicBuckets.getInstance().getConfigManager().getInfiniteUseCostForGenbucketType(genbucket.getGenbucketType(), genbucket.getGenItem());
if (isInfiniteUse && isInfiniteUseCharge && EpicBuckets.getInstance().getEcon().getBalance(Bukkit.getOfflinePlayer(e.getPlayer().getUniqueId())) < infiniteUseCost) {
e.getPlayer().sendMessage(EpicBuckets.getInstance().getLocale().getMessage("event.genbucket.infiniteuse.notenough"));
return;
}
/*
Call event and check if cancelled before proceeding to start the gen and charging the player
*/
GenbucketPlaceEvent placeEvent = new GenbucketPlaceEvent(e.getPlayer(), genbucket);
Bukkit.getPluginManager().callEvent(placeEvent);
if (placeEvent.isCancelled()) return;
/*
Subtract bucket from players inventory
*/
if (e.getPlayer().getGameMode() != GameMode.CREATIVE && !isInfiniteUse) {
if (e.getItem().getAmount() > 1) {
e.getItem().setAmount(e.getItem().getAmount() - 1);
} else {
e.getPlayer().getInventory().setItem(e.getPlayer().getInventory().getHeldItemSlot(), null);
}
}
/*
Charge for infinite use placement
*/
if (isInfiniteUse && isInfiniteUseCharge && infiniteUseCost > 0) {
EpicBuckets.getInstance().getEcon().withdrawPlayer(Bukkit.getOfflinePlayer(e.getPlayer().getUniqueId()), infiniteUseCost);
e.getPlayer().sendMessage(EpicBuckets.getInstance().getLocale().getMessage("event.genbucket.infiniteuse.charge").replace("%charge%", infiniteUseCost + ""));
}
EpicBuckets.getInstance().getGenbucketManager().registerGenbucketForPlayer(e.getPlayer(), genbucket);
EpicBuckets.getInstance().getGenbucketManager().notifyAdmins(e.getPlayer(), genbucket);
genbucket.generate();
}
}

View File

@ -1,30 +0,0 @@
package com.songoda.epicbuckets.listener;
import com.songoda.epicbuckets.EpicBuckets;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
public class SourceBlockBreakListener implements Listener {
private EpicBuckets epicBuckets;
public SourceBlockBreakListener() {
epicBuckets = EpicBuckets.getInstance();
}
@EventHandler
public void onBlockBreak(BlockBreakEvent e) {
epicBuckets.getGenbucketManager().getActiveGens().forEach((uuid, genbuckets) -> {
if (genbuckets.size() > 0) {
genbuckets.forEach(genbucket -> {
if (genbucket.getSourceBlock().getLocation().equals(e.getBlock().getLocation())) {
genbucket.getGeneration().cancel();
return;
}
});
}
});
}
}

View File

@ -1,162 +0,0 @@
package com.songoda.epicbuckets.shop;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.genbucket.GenbucketType;
import com.songoda.epicbuckets.util.InventoryHelper;
import com.songoda.epicbuckets.util.Validator;
import com.songoda.epicbuckets.util.XMaterial;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.inventory.ItemStack;
import java.util.Collection;
import java.util.HashMap;
public class Shop {
private EpicBuckets epicBuckets;
private FileConfiguration shops;
private HashMap<String, SubShop> subShops;
private ItemStack shopItem;
private String menuItem;
private String shopName;
private int slot;
private String path;
private String shopPath;
private int backButtonSlot;
private GenbucketType trait;
private int inventorySize;
private boolean fillInventory;
private String inventoryName;
private boolean enabled;
public Shop(String menuItem, String name, String path) {
this.epicBuckets = EpicBuckets.getInstance();
this.shops = EpicBuckets.getInstance().getConfigManager().getConfig("shops");
this.subShops = new HashMap<>();
this.menuItem = menuItem;
this.shopName = name;
this.path = path;
this.shopPath = epicBuckets.getShopManager().getShopPath() + "." + shopName;
this.enabled = shops.getBoolean(shopPath + ".enabled");
loadData();
setupShopItem();
loadSubShops();
}
private void loadData() {
trait = Validator.genbucketType(shops.getString(shopPath + ".trait"));
backButtonSlot = Validator.slot(shops.getString(shopPath + ".goBackButton"));
inventorySize = Validator.inventorySize(shops.getString(shopPath + ".size"));
fillInventory = shops.getBoolean(shopPath + ".fill");
inventoryName = shops.getString(shopPath + ".inventory-name");
if (trait == null) {
epicBuckets.getDebugger().invalidGenbucketType(shopPath + ".trait");
setEnabled(false);
}
if (backButtonSlot == -1) {
epicBuckets.getDebugger().invalidSlot(shopPath + ".goBackButton");
setEnabled(false);
}
if (inventorySize == -1) {
epicBuckets.getDebugger().invalidInventorySize(shopPath + ".size");
setEnabled(false);
}
}
private void loadSubShops() {
for (String shop : shops.getConfigurationSection(shopPath).getKeys(false)) {
if (!shops.isConfigurationSection(shopPath + "." + shop)) {
continue;
}
subShops.put(shop, new SubShop(this, shop));
}
}
private void setupShopItem() {
String itemPath = path + ".item";
slot = Validator.slot(epicBuckets.getConfig().getString(path + ".slot"));
boolean m = Validator.isMaterial(epicBuckets.getConfig().getString(itemPath + ".material"));
if (slot == -1) {
epicBuckets.getDebugger().invalidSlot(itemPath + ".slot");
setEnabled(false);
}
shopItem = ((!m) ? XMaterial.WATER_BUCKET.parseItem() : XMaterial.valueOf(epicBuckets.getConfig().getString(itemPath + ".material")).parseItem());
shopItem = InventoryHelper.setLore(InventoryHelper.setDisplayName(shopItem, epicBuckets.getConfig().getString(itemPath + ".name")), epicBuckets.getConfig().getStringList(itemPath + ".lore"));
}
public Collection<SubShop> getSubShops() {
return subShops.values();
}
public SubShop getSubShop(String shop) {
return subShops.get(shop);
}
public SubShop getSubShop(XMaterial mat) {
for (SubShop subShop : subShops.values()) {
if (subShop.getGenItem().getType() == mat.parseMaterial() &&
subShop.getGenItem().getDurability() == mat.parseItem().getDurability()) {
return subShop;
}
}
return null;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public boolean isEnabled() {
return enabled;
}
public int getSlot() {
return slot;
}
public String getShopName() {
return shopName;
}
public String getMenuItem() {
return menuItem;
}
public ItemStack getShopItem() {
return shopItem;
}
public int getBackButtonSlot() {
return backButtonSlot;
}
public GenbucketType getTrait() {
return trait;
}
public int getInventorySize() {
return inventorySize;
}
public boolean isFillInventory() {
return fillInventory;
}
public String getInventoryName() {
return inventoryName;
}
}

View File

@ -1,220 +0,0 @@
package com.songoda.epicbuckets.shop;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.genbucket.GenbucketType;
import com.songoda.epicbuckets.util.*;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Array;
import java.util.*;
public class ShopManager {
private HashMap<String, Shop> shopDatabase;
private FileConfiguration shops;
private EpicBuckets epicBuckets;
private String shopPath = "shops";
private String bulkShopPath = "BULK-SHOP-INVENTORY";
private ItemStack increaseItem;
private ItemStack decreaseItem;
private ItemStack purchaseItem;
private List<Integer> increaseSlots;
private List<Integer> decreaseSlots;
private List<Integer> bulkAmounts = new ArrayList<>(Arrays.asList(1, 10, 64));
private int purchaseSlot;
private String bulkInventoryName;
private int bulkInventorySize;
private boolean bulkFillInventory;
private int bulkBackButtonSlot;
private int bulkMainItemSlot;
private boolean useBackButtons;
private boolean closeAfterPurchase;
public ShopManager() {
epicBuckets = EpicBuckets.getInstance();
}
public void init() {
shops = epicBuckets.getConfigManager().getConfig("shops");
shopDatabase = new HashMap<>();
increaseSlots = new ArrayList<>();
decreaseSlots = new ArrayList<>();
loadData();
loadShops();
setupBulkShop();
}
public void reload() {
init();
}
private void setupBulkShop() {
boolean i = Validator.isMaterial(epicBuckets.getConfigManager().getBulkShopIncreasePath() + ".material");
boolean d = Validator.isMaterial(epicBuckets.getConfigManager().getBulkShopDecreasePath() + ".material");
boolean p = Validator.isMaterial(epicBuckets.getConfigManager().getBulkShopPurchasePath() + ".material");
purchaseSlot = Validator.slot(epicBuckets.getConfig().getString(epicBuckets.getConfigManager().getBulkShopPurchasePath() + ".slot"));
if (purchaseSlot == -1) {
purchaseSlot = 40;
}
increaseItem = ((!i) ? XMaterial.GREEN_STAINED_GLASS_PANE.parseItem() : XMaterial.valueOf(epicBuckets.getConfig().getString(epicBuckets.getConfigManager().getBulkShopIncreasePath() + ".material")).parseItem());
decreaseItem = ((!d) ? XMaterial.RED_STAINED_GLASS_PANE.parseItem() : XMaterial.valueOf(epicBuckets.getConfig().getString(epicBuckets.getConfigManager().getBulkShopDecreasePath() + ".material")).parseItem());
purchaseItem = ((!p) ? XMaterial.YELLOW_STAINED_GLASS.parseItem() : XMaterial.valueOf(epicBuckets.getConfig().getString(epicBuckets.getConfigManager().getBulkShopPurchasePath() + ".material")).parseItem());
purchaseItem = InventoryHelper.setDisplayName(purchaseItem, epicBuckets.getConfig().getString(epicBuckets.getConfigManager().getBulkShopPurchasePath() + ".name"));
for (String s : epicBuckets.getConfig().getString(epicBuckets.getConfigManager().getBulkShopIncreasePath() + ".slots").split(",")) {
increaseSlots.add(Integer.parseInt(s));
}
for (String s : epicBuckets.getConfig().getString(epicBuckets.getConfigManager().getBulkShopDecreasePath() + ".slots").split(",")) {
decreaseSlots.add(Integer.parseInt(s));
}
}
private void loadData() {
useBackButtons = shops.getBoolean("use-back-buttons");
closeAfterPurchase = epicBuckets.getConfig().getBoolean("CLOSE-GUI-AFTER-PURCHASE");
bulkInventoryName = epicBuckets.getConfig().getString(bulkShopPath + ".inventory-name");
bulkInventorySize = epicBuckets.getConfig().getInt(bulkShopPath + ".size");
bulkBackButtonSlot = epicBuckets.getConfig().getInt(bulkShopPath + ".return-back-slot");
bulkFillInventory = epicBuckets.getConfig().getBoolean(bulkShopPath + ".fill");
bulkMainItemSlot = epicBuckets.getConfig().getInt(bulkShopPath + ".main-item-slot");
}
private void loadShops() {
System.out.println("Loading shops..");
for (String key : epicBuckets.getConfig().getConfigurationSection(epicBuckets.getConfigManager().getMenuItemsPath()).getKeys(false)) {
if (!epicBuckets.getConfig().isConfigurationSection(epicBuckets.getConfigManager().getMenuItemsPath() + "." + key)) {
continue;
}
shopDatabase.put(key, new Shop(key, epicBuckets.getConfig().getString(epicBuckets.getConfigManager().getMenuItemsPath() + "." + key + ".shop"), epicBuckets.getConfigManager().getMenuItemsPath() + "." + key));
}
System.out.println("Loaded " + shopDatabase.size() + " shop(s)");
}
public boolean inventoryFull(Player buyer) {
if (buyer.getInventory().firstEmpty() == -1) {
buyer.sendMessage(ChatUtil.colorPrefix(epicBuckets.getLocale().getMessage("event.purchase.inventoryfull")));
return true;
}
return false;
}
public boolean hasEnoughFunds(Player buyer, SubShop s, int amount) {
if (epicBuckets.getEcon().getBalance(Bukkit.getOfflinePlayer(buyer.getUniqueId())) >= (s.getPrice() * amount)) return true;
buyer.sendMessage(ChatUtil.colorPrefix(epicBuckets.getLocale().getMessage("event.purchase.notenoughmoney").replace("%money%", (s.getPrice() * amount) - epicBuckets.getBalance(buyer) + "")));
return false;
}
public void buyFromShop(Player buyer, SubShop s, int amount) {
epicBuckets.getEcon().withdrawPlayer(Bukkit.getOfflinePlayer(buyer.getUniqueId()), s.getPrice() * amount);
giveGenbucketToPlayer(buyer, s, amount);
}
public void giveGenbucketToPlayer(Player buyer, SubShop s, int amount) {
ItemStack genBucket = s.getGenShopItem();
genBucket.setAmount(amount);
buyer.getInventory().addItem(NBTHelper.addGenbucketData(genBucket, s.getParent().getTrait(), s));
}
public Collection<Shop> getShops() {
return shopDatabase.values();
}
public Shop getShop(String shop) {
return shopDatabase.get(shop);
}
public Shop getShop(GenbucketType genbucketType) {
for (Shop shop : shopDatabase.values()) {
if (shop.getTrait() == genbucketType) return shop;
}
return null;
}
public String getShopPath() {
return shopPath;
}
public ItemStack getIncreaseItem() {
return increaseItem;
}
public ItemStack getDecreaseItem() {
return decreaseItem;
}
public ItemStack getPurchaseItem() {
return purchaseItem;
}
public List<Integer> getIncreaseSlots() {
return increaseSlots;
}
public List<Integer> getDecreaseSlots() {
return decreaseSlots;
}
public int getPurchaseSlot() {
return purchaseSlot;
}
public boolean isUseBackButtons() {
return useBackButtons;
}
public boolean isCloseAfterPurchase() {
return closeAfterPurchase;
}
public String getBulkInventoryName() {
return bulkInventoryName;
}
public int getBulkInventorySize() {
return bulkInventorySize;
}
public boolean isBulkFillInventory() {
return bulkFillInventory;
}
public int getBulkBackButtonSlot() {
return bulkBackButtonSlot;
}
public int getBulkMainItemSlot() {
return bulkMainItemSlot;
}
public List<Integer> getBulkAmounts() {
return bulkAmounts;
}
public void setShopDatabase(HashMap<String, Shop> shopDatabase) {
this.shopDatabase = shopDatabase;
}
public void setBulkFillInventory(boolean bulkFillInventory) {
this.bulkFillInventory = bulkFillInventory;
}
public void setUseBackButtons(boolean useBackButtons) {
this.useBackButtons = useBackButtons;
}
public void setCloseAfterPurchase(boolean closeAfterPurchase) {
this.closeAfterPurchase = closeAfterPurchase;
}
}

View File

@ -1,139 +0,0 @@
package com.songoda.epicbuckets.shop;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.util.InventoryHelper;
import com.songoda.epicbuckets.util.Validator;
import com.songoda.epicbuckets.util.XMaterial;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
public class SubShop {
private EpicBuckets epicBuckets;
private String subShopPath;
private boolean enabled;
private ItemStack shopItem;
private ItemStack genItem;
private ItemStack genShopItem;
private XMaterial type;
private Shop parent;
private String item;
private String shopName;
private int slot;
private double price;
private List<String> description;
private List<String> genItemLore;
public SubShop(Shop parent, String item) {
this.epicBuckets = EpicBuckets.getInstance();
this.parent = parent;
this.item = item;
this.description = new ArrayList<>();
this.genItemLore = new ArrayList<>();
init();
}
private void init() {
FileConfiguration shops = EpicBuckets.getInstance().getConfigManager().getConfig("shops");
subShopPath = epicBuckets.getShopManager().getShopPath() + "." + parent.getShopName() + "." + item;
setEnabled(true);
loadData(shops);
setupShopItem(shops);
}
private void loadData(FileConfiguration shops) {
price = Validator.price(shops.getString(subShopPath + ".price"));
if (price == -1.0) {
epicBuckets.getDebugger().invalidPrice(subShopPath);
setEnabled(false);
}
this.type = XMaterial.valueOf(shops.getString(subShopPath + ".type"));
this.shopName = shops.getString(subShopPath + ".name");
this.description = shops.getStringList(subShopPath + ".description");
this.genItemLore = shops.getStringList(subShopPath + ".item-lore");
}
private void setupShopItem(FileConfiguration shops) {
slot = Validator.slot(shops.getString(subShopPath + ".slot"));
boolean m = Validator.isMaterial(shops.getString(subShopPath + ".icon"));
boolean t = Validator.isMaterial(shops.getString(subShopPath + ".type"));
if (slot == -1) {
epicBuckets.getDebugger().invalidSlot(subShopPath);
setEnabled(false);
}
shopItem = ((!m) ? XMaterial.WATER_BUCKET.parseItem() : XMaterial.valueOf(shops.getString(subShopPath + ".icon")).parseItem());
shopItem = InventoryHelper.setDisplayName(InventoryHelper.setSubShopLore(shopItem, getDescription(), this), getShopName());
genItem = ((!t) ? XMaterial.WATER_BUCKET.parseItem() : XMaterial.valueOf(shops.getString(subShopPath + ".type")).parseItem());
genShopItem = ((!m) ? XMaterial.WATER_BUCKET.parseItem() : XMaterial.valueOf(shops.getString(subShopPath + ".icon")).parseItem());
genShopItem = InventoryHelper.setDisplayName(InventoryHelper.setLore(genShopItem, getGenItemLore()), getShopName());
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public boolean isEnabled() {
return enabled;
}
public ItemStack getShopItem() {
return shopItem;
}
public ItemStack getGenItem() {
return genItem;
}
public Shop getParent() {
return parent;
}
public String getShopName() {
return shopName;
}
public int getSlot() {
return slot;
}
public double getPrice() {
return price;
}
public List<String> getDescription() {
return description;
}
public List<String> getGenItemLore() {
return genItemLore;
}
public ItemStack getGenShopItem() {
return genShopItem;
}
public String getItem() {
return item;
}
public XMaterial getType() {
return type;
}
}

View File

@ -1,93 +0,0 @@
package com.songoda.epicbuckets.util;
import com.songoda.epicbuckets.EpicBuckets;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.StringJoiner;
/**
* ChatUtil created by: SoFocused
* Date Created: oktober 02 2018
* Time created: 22:54
*/
public class ChatUtil {
public static String colorPrefix(String msg) {
return ChatColor.translateAlternateColorCodes('&', getPrefix() + msg);
}
public static String colorString(String msg) {
return ChatColor.translateAlternateColorCodes('&', msg);
}
public static List<String> colorList(List<String> list) {
List<String> newList = new ArrayList<>();
list.forEach(string -> newList.add(colorString(string)));
return newList;
}
public static List<String> colorList(List<String> list, Material material, int price) {
List<String> newList = new ArrayList<>();
list.forEach(string -> newList.add(colorString(string.replace("{material}", properMaterialName(material).toLowerCase()).replace("{price}", String.valueOf(price)))));
return newList;
}
public static String stripColor(String input) {
return ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', input));
}
public static String getPrefix() {
return EpicBuckets.getInstance().getLocale().getMessage("general.nametag.prefix").equals("none") ? "" : EpicBuckets.getInstance().getLocale().getMessage("general.nametag.prefix") + " ";
}
public static void debugMSG(Player player, Object... args) {
StringJoiner stringBuilder = new StringJoiner("§8:");
for (int i = 0; i < args.length; i++)
stringBuilder.add("§a" + args[i].toString());
player.sendMessage(stringBuilder.toString());
}
public static String getCoordinatesFromLocation(Location l) {
return "X: " + l.getBlockX() + " Y: " + l.getBlockY() + " Z: " + l.getBlockZ();
}
public static String properMaterialName(Material material) {
String materialName;
if (material.name().split("_").length > 1) {
StringJoiner stringJoiner = new StringJoiner(" ");
for (String str : material.name().split("_"))
stringJoiner.add(str);
materialName = stringJoiner.toString();
} else
materialName = material.name();
return materialName;
}
}

View File

@ -1,67 +0,0 @@
package com.songoda.epicspawners.utils;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
/**
* ConfigWrapper made by @clip
*/
public class ConfigWrapper {
private final JavaPlugin plugin;
private final String folderName, fileName;
private FileConfiguration config;
private File configFile;
public ConfigWrapper(final JavaPlugin instance, final String folderName, final String fileName) {
this.plugin = instance;
this.folderName = folderName;
this.fileName = fileName;
}
public void createNewFile(final String message, final String header) {
reloadConfig();
saveConfig();
loadConfig(header);
if (message != null) {
plugin.getLogger().info(message);
}
}
public FileConfiguration getConfig() {
if (config == null) {
reloadConfig();
}
return config;
}
public void loadConfig(final String header) {
config.options().header(header);
config.options().copyDefaults(true);
saveConfig();
}
public void reloadConfig() {
if (configFile == null) {
configFile = new File(plugin.getDataFolder() + folderName, fileName);
}
config = YamlConfiguration.loadConfiguration(configFile);
}
public void saveConfig() {
if (config == null || configFile == null) {
return;
}
try {
getConfig().save(configFile);
} catch (final IOException ex) {
plugin.getLogger().log(Level.SEVERE, "Could not save config to " + configFile, ex);
}
}
}

View File

@ -1,34 +0,0 @@
package com.songoda.epicbuckets.util;
import com.songoda.epicbuckets.EpicBuckets;
import org.bukkit.ChatColor;
public class Debugger {
private EpicBuckets epicBuckets;
public Debugger() {
epicBuckets = EpicBuckets.getInstance();
}
public void sendConsole(String message) {
epicBuckets.getLogger().info(ChatColor.translateAlternateColorCodes('&', message));
}
public void invalidInventorySize(String item) {
sendConsole(item + " has an invalid inventory size, disabling shop..");
}
public void invalidGenbucketType(String item) {
sendConsole(item + " has an invalid Genbucket type, disabling shop..");
}
public void invalidSlot(String item) {
sendConsole(item + " has an invalid slot, disabling shop..");
}
public void invalidPrice(String item) {
sendConsole(item + " has an invalid price set, disabling shop..");
}
}

View File

@ -1,63 +0,0 @@
package com.songoda.epicbuckets.util;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.shop.SubShop;
import org.bukkit.ChatColor;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;
public class InventoryHelper {
public static List<XMaterial> convertMaterialList(List<String> toConvert, String item) {
List<XMaterial> converted = new ArrayList<>();
for (String s : toConvert) {
if (!Validator.isMaterial(s.toUpperCase())) {
EpicBuckets.getInstance().getDebugger().sendConsole("Invalid material " + s.toUpperCase() + " in " + item + ", skipping..");
continue;
}
converted.add(XMaterial.valueOf(s.toUpperCase()));
}
return converted;
}
public static int[] emptySlots(int size) {
List<Integer> slots = new ArrayList<>();
IntStream.range(0, size).forEach(slots::add);
return slots.stream().mapToInt(i -> i).toArray();
}
public static ItemStack setDisplayName(ItemStack item, String s) {
ItemMeta im = item.getItemMeta();
im.setDisplayName(ChatColor.translateAlternateColorCodes('&', s));
item.setItemMeta(im);
return item;
}
public static ItemStack setLore(ItemStack item, List<String> lore) {
ItemMeta im = item.getItemMeta();
List<String> newLore = new ArrayList<>();
lore.forEach(s -> newLore.add(ChatColor.translateAlternateColorCodes('&', s)));
im.setLore(newLore);
item.setItemMeta(im);
return item;
}
public static ItemStack setSubShopLore(ItemStack item, List<String> lore, SubShop subShop) {
ItemMeta im = item.getItemMeta();
List<String> newLore = new ArrayList<>();
lore.forEach(s -> {
String line = s;
if (line.contains("%price%")) line = line.replace("%price%", subShop.getPrice() + "");
if (line.contains("%material%")) line = line.replace("%material%", subShop.getType().parseMaterial().name());
newLore.add(ChatColor.translateAlternateColorCodes('&', line));
});
im.setLore(newLore);
item.setItemMeta(im);
return item;
}
}

View File

@ -1,24 +0,0 @@
package com.songoda.epicbuckets.util;
import com.songoda.epicbuckets.genbucket.GenbucketType;
import com.songoda.epicbuckets.shop.SubShop;
import de.tr7zw.itemnbtapi.NBTItem;
import org.bukkit.inventory.ItemStack;
public class NBTHelper {
public static ItemStack addGenbucketData(ItemStack item, GenbucketType genbucketType, SubShop s) {
NBTItem nbtItem = new NBTItem(item);
nbtItem.setBoolean("Genbucket", true);
nbtItem.setString("Type", genbucketType.name);
nbtItem.setString("SubShop", s.getItem());
nbtItem.setString("Shop", s.getParent().getMenuItem());
return nbtItem.getItem();
}
public static boolean isGenbucket(ItemStack item) {
NBTItem nbtItem = new NBTItem(item);
return nbtItem.hasKey("Genbucket");
}
}

View File

@ -1,26 +0,0 @@
package com.songoda.ultimatekits.utils;
public enum ServerVersion {
UNKNOWN("unknown_server_version"),
V1_7("org.bukkit.craftbukkit.v1_7"),
V1_8("org.bukkit.craftbukkit.v1_8"),
V1_9("org.bukkit.craftbukkit.v1_9"),
V1_10("org.bukkit.craftbukkit.v1_10"),
V1_11("org.bukkit.craftbukkit.v1_11"),
V1_12("org.bukkit.craftbukkit.v1_12"),
V1_13("org.bukkit.craftbukkit.v1_13");
private final String packagePrefix;
private ServerVersion(String packagePrefix) {
this.packagePrefix = packagePrefix;
}
public static ServerVersion fromPackageName(String packageName) {
for (ServerVersion version : values())
if (packageName.startsWith(version.packagePrefix)) return version;
return ServerVersion.UNKNOWN;
}
}

View File

@ -1,61 +0,0 @@
package com.songoda.epicbuckets.util;
import com.songoda.epicbuckets.genbucket.GenbucketType;
public class Validator {
public static int inventorySize(String s) {
int i;
if (isInt(s)) {
i = Integer.parseInt(s);
if (i<=6) return i;
}
return -1;
}
public static GenbucketType genbucketType(String s) {
try {
return GenbucketType.valueOf(s);
} catch (Exception e) {
return null;
}
}
public static double price(String s) {
if (isDouble(s)) return Double.parseDouble(s);
return -1;
}
public static boolean isDouble(String s) {
try {
Double.parseDouble(s);
return true;
} catch (Exception e) {
return false;
}
}
public static boolean isInt(String s) {
try {
Integer.parseInt(s);
return true;
} catch (Exception e) {
return false;
}
}
public static boolean isMaterial(String mat) {
try {
XMaterial.valueOf(mat);
return true;
} catch (IllegalArgumentException e) {
return false;
}
}
public static int slot(String s) {
if (isInt(s)) return Integer.parseInt(s);
return -1;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,272 +0,0 @@
package com.songoda.ultimatekits.utils.gui;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.utils.ServerVersion;
import com.songoda.ultimatekits.utils.version.NMSUtil;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
public class AbstractAnvilGUI {
private static Class<?> BlockPosition;
private static Class<?> PacketPlayOutOpenWindow;
private static Class<?> ContainerAnvil;
private static Class<?> ChatMessage;
private static Class<?> EntityHuman;
private static boolean loadedClasses = false;
private Player player;
@SuppressWarnings("unused")
private AnvilClickEventHandler handler;
private Map<AnvilSlot, ItemStack> items = new HashMap<>();
private OnClose onClose = null;
private Inventory inv;
private Listener listener;
private Sound closeSound;
public AbstractAnvilGUI(final Player player, final AnvilClickEventHandler handler) {
loadClasses();
this.player = player;
this.handler = handler;
this.listener = new Listener() {
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
if (UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_9)) closeSound = Sound.ENTITY_PLAYER_LEVELUP;
if (!(event.getWhoClicked() instanceof Player) || !event.getInventory().equals(inv)) return;
event.setCancelled(true);
ItemStack item = event.getCurrentItem();
int slot = event.getRawSlot();
String name = "";
if (item != null) {
if (item.hasItemMeta()) {
ItemMeta meta = item.getItemMeta();
if (meta.hasDisplayName()) {
name = meta.getDisplayName();
}
}
}
AnvilClickEvent clickEvent = new AnvilClickEvent(AnvilSlot.bySlot(slot), name);
handler.onAnvilClick(clickEvent);
if (clickEvent.getWillClose()) {
event.getWhoClicked().closeInventory();
}
if (clickEvent.getWillDestroy()) {
destroy();
}
}
@EventHandler
public void onInventoryClose(InventoryCloseEvent event) {
if (!(event.getPlayer() instanceof Player)) return;
Inventory inv = event.getInventory();
player.setLevel(player.getLevel() - 1);
if (!inv.equals(AbstractAnvilGUI.this.inv)) return;
inv.clear();
OnClose onClose = getOnClose();
if (UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_9)) player.playSound(player.getLocation(), closeSound, 1F, 1F);
Bukkit.getScheduler().scheduleSyncDelayedTask(UltimateKits.getInstance(), () -> {
if (onClose != null) onClose.OnClose(player, inv);
destroy();
}, 1L);
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
if (!event.getPlayer().equals(getPlayer())) return;
player.setLevel(player.getLevel() - 1);
destroy();
}
};
Bukkit.getPluginManager().registerEvents(listener, UltimateKits.getInstance());
}
private void loadClasses() {
if (loadedClasses) return;
BlockPosition = NMSUtil.getNMSClass("BlockPosition");
PacketPlayOutOpenWindow = NMSUtil.getNMSClass("PacketPlayOutOpenWindow");
ContainerAnvil = NMSUtil.getNMSClass("ContainerAnvil");
EntityHuman = NMSUtil.getNMSClass("EntityHuman");
ChatMessage = NMSUtil.getNMSClass("ChatMessage");
loadedClasses = true;
}
public Player getPlayer() {
return player;
}
public void setSlot(AnvilSlot slot, ItemStack item) {
items.put(slot, item);
}
public void open() {
player.setLevel(player.getLevel() + 1);
try {
Object craftPlayer = NMSUtil.getCraftClass("entity.CraftPlayer").cast(player);
Method getHandleMethod = craftPlayer.getClass().getMethod("getHandle", new Class<?>[0]);
Object entityPlayer = getHandleMethod.invoke(craftPlayer, new Object[0]);
Object container;
if (NMSUtil.getVersionNumber() == 7) {
container = ContainerAnvil.getConstructor(new Class[]{NMSUtil.getNMSClass("PlayerInventory"), NMSUtil.getNMSClass("World"), Integer.TYPE, Integer.TYPE, Integer.TYPE, EntityHuman}).newInstance(new Object[]{NMSUtil.getFieldObject(entityPlayer, NMSUtil.getField(entityPlayer.getClass(), "inventory", false)), NMSUtil.getFieldObject(entityPlayer, NMSUtil.getField(entityPlayer.getClass(), "world", false)), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0), entityPlayer});
} else {
container = ContainerAnvil.getConstructor(NMSUtil.getNMSClass("PlayerInventory"), NMSUtil.getNMSClass("World"), BlockPosition, EntityHuman).newInstance(NMSUtil.getFieldObject(entityPlayer, NMSUtil.getField(entityPlayer.getClass(), "inventory", false)), NMSUtil.getFieldObject(entityPlayer, NMSUtil.getField(entityPlayer.getClass(), "world", false)), BlockPosition.getConstructor(int.class, int.class, int.class).newInstance(0, 0, 0), entityPlayer);
}
NMSUtil.getField(NMSUtil.getNMSClass("Container"), "checkReachable", true).set(container, false);
Method getBukkitViewMethod = container.getClass().getMethod("getBukkitView", new Class<?>[0]);
Object bukkitView = getBukkitViewMethod.invoke(container);
Method getTopInventoryMethod = bukkitView.getClass().getMethod("getTopInventory", new Class<?>[0]);
inv = (Inventory) getTopInventoryMethod.invoke(bukkitView);
for (AnvilSlot slot : items.keySet()) {
inv.setItem(slot.getSlot(), items.get(slot));
}
Method nextContainerCounterMethod = entityPlayer.getClass().getMethod("nextContainerCounter", new Class<?>[0]);
int c = (int) nextContainerCounterMethod.invoke(entityPlayer);
Constructor<?> chatMessageConstructor = ChatMessage.getConstructor(String.class, Object[].class);
Object packet;
if (NMSUtil.getVersionNumber() == 7) {
packet = PacketPlayOutOpenWindow.getConstructor(new Class[]{Integer.TYPE, Integer.TYPE, String.class, Integer.TYPE, Boolean.TYPE, Integer.TYPE}).newInstance(new Object[]{Integer.valueOf(c), Integer.valueOf(8), "Repairing", Integer.valueOf(0), Boolean.valueOf(true), Integer.valueOf(0)});
} else {
packet = PacketPlayOutOpenWindow.getConstructor(int.class, String.class, NMSUtil.getNMSClass("IChatBaseComponent"), int.class).newInstance(c, "minecraft:anvil", chatMessageConstructor.newInstance("Repairing", new Object[]{}), 0);
}
NMSUtil.sendPacket(player, packet);
Field activeContainerField = NMSUtil.getField(EntityHuman, "activeContainer", true);
if (activeContainerField != null) {
activeContainerField.set(entityPlayer, container);
NMSUtil.getField(NMSUtil.getNMSClass("Container"), "windowId", true).set(activeContainerField.get(entityPlayer), c);
Method addSlotListenerMethod = activeContainerField.get(entityPlayer).getClass().getMethod("addSlotListener", NMSUtil.getNMSClass("ICrafting"));
addSlotListenerMethod.invoke(activeContainerField.get(entityPlayer), entityPlayer);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void destroy() {
onClose = null;
player = null;
handler = null;
items = null;
HandlerList.unregisterAll(listener);
listener = null;
}
private OnClose getOnClose() {
return onClose;
}
public void setOnClose(OnClose onClose) {
this.onClose = onClose;
}
public void setCloseSound(Sound sound) {
closeSound = sound;
}
public enum AnvilSlot {
INPUT_LEFT(0),
INPUT_RIGHT(1),
OUTPUT(2);
private int slot;
private AnvilSlot(int slot) {
this.slot = slot;
}
public static AnvilSlot bySlot(int slot) {
for (AnvilSlot anvilSlot : values()) {
if (anvilSlot.getSlot() == slot) {
return anvilSlot;
}
}
return null;
}
public int getSlot() {
return slot;
}
}
public interface AnvilClickEventHandler {
void onAnvilClick(AnvilClickEvent event);
}
public class AnvilClickEvent {
private AnvilSlot slot;
private String name;
private boolean close = true;
private boolean destroy = true;
public AnvilClickEvent(AnvilSlot slot, String name) {
this.slot = slot;
this.name = name;
}
public AnvilSlot getSlot() {
return slot;
}
public String getName() {
return name;
}
public boolean getWillClose() {
return close;
}
public void setWillClose(boolean close) {
this.close = close;
}
public boolean getWillDestroy() {
return destroy;
}
public void setWillDestroy(boolean destroy) {
this.destroy = destroy;
}
}
}

View File

@ -1,226 +0,0 @@
package com.songoda.ultimatekits.utils.gui;
import com.songoda.arconix.api.methods.formatting.TextComponent;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.utils.ServerVersion;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public abstract class AbstractGUI implements Listener {
private static boolean listenersInitialized = false;
protected Player player;
protected Inventory inventory = null;
protected boolean cancelBottom = false;
private Map<Range, Clickable> clickables = new HashMap<>();
private List<OnClose> onCloses = new ArrayList<>();
private Map<Range, Boolean> draggableRanges = new HashMap<>();
public AbstractGUI(Player player) {
this.player = player;
}
public static void initializeListeners(JavaPlugin plugin) {
if (listenersInitialized) return;
Bukkit.getPluginManager().registerEvents(new Listener() {
@EventHandler
public void onClickGUI(InventoryClickEvent event) {
Inventory inventory = event.getClickedInventory();
if (inventory == null) return;
AbstractGUI gui = getGUIFromInventory(inventory);
Player player = (Player) event.getWhoClicked();
boolean bottom = false;
InventoryType type = event.getClickedInventory().getType();
if (type != InventoryType.CHEST && type != InventoryType.PLAYER) return;
if (gui == null && event.getWhoClicked().getOpenInventory().getTopInventory() != null) {
Inventory top = event.getWhoClicked().getOpenInventory().getTopInventory();
gui = getGUIFromInventory(top);
if (gui != null && gui.cancelBottom) event.setCancelled(true);
bottom = true;
}
if (gui == null) return;
if (!bottom) event.setCancelled(true);
if (!gui.draggableRanges.isEmpty() && !bottom) {
for (Map.Entry<Range, Boolean> entry : gui.draggableRanges.entrySet()) {
Range range = entry.getKey();
if (range.getMax() == range.getMin() && event.getSlot() == range.getMin()
|| event.getSlot() >= range.getMin() && event.getSlot() <= range.getMax()) {
event.setCancelled(!entry.getValue());
if (!entry.getValue()) break;
}
}
}
Map<Range, Clickable> entries = new HashMap<>(gui.clickables);
for (Map.Entry<Range, Clickable> entry : entries.entrySet()) {
Range range = entry.getKey();
if (range.isBottom() && !bottom || !range.isBottom() && bottom || range.getClickType() != null && range.getClickType() != event.getClick())
continue;
if (event.getSlot() >= range.getMin() && event.getSlot() <= range.getMax()) {
entry.getValue().Clickable(player, inventory, event.getCursor(), event.getSlot(), event.getClick());
if (UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_12))
player.playSound(player.getLocation(), entry.getKey().getOnClickSound(), 1F, 1F);
}
}
}
@EventHandler
public void onCloseGUI(InventoryCloseEvent event) {
Inventory inventory = event.getInventory();
AbstractGUI gui = getGUIFromInventory(inventory);
if (gui == null || gui.inventory == null) return;
for (OnClose onClose : gui.onCloses) {
onClose.OnClose((Player) event.getPlayer(), inventory);
}
}
private AbstractGUI getGUIFromInventory(Inventory inventory) {
if (inventory.getHolder() == null) return null;
InventoryHolder holder = inventory.getHolder();
if (!(holder instanceof GUIHolder)) return null;
return ((AbstractGUI.GUIHolder) holder).getGUI();
}
}, plugin);
listenersInitialized = true;
}
public void init(String title, int slots) {
if (inventory == null
|| inventory.getSize() != slots
|| ChatColor.translateAlternateColorCodes('&', title) != inventory.getTitle()) {
this.inventory = Bukkit.getServer().createInventory(new GUIHolder(), slots, TextComponent.formatTitle(title));
if (this.clickables.size() == 0)
registerClickables();
if (this.onCloses.size() == 0)
registerOnCloses();
}
constructGUI();
initializeListeners(UltimateKits.getInstance());
player.openInventory(inventory);
}
protected abstract void constructGUI();
protected void addDraggable(Range range, boolean option) {
this.draggableRanges.put(range, option);
}
protected void removeDraggable() {
this.draggableRanges.clear();
}
protected abstract void registerClickables();
protected abstract void registerOnCloses();
protected ItemStack createButton(int slot, Inventory inventory, ItemStack item, String name, String... lore) {
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
if (lore != null && lore.length != 0) {
List<String> newLore = new ArrayList<>();
for (String line : lore) newLore.add(ChatColor.translateAlternateColorCodes('&', line));
meta.setLore(newLore);
}
item.setItemMeta(meta);
inventory.setItem(slot, item);
return item;
}
protected ItemStack createButton(int slot, ItemStack item, String name, String... lore) {
return createButton(slot, inventory, item, name, lore);
}
protected ItemStack createButton(int slot, Inventory inventory, Material material, String name, String... lore) {
return createButton(slot, inventory, new ItemStack(material), name, lore);
}
protected ItemStack createButton(int slot, Material material, String name, String... lore) {
return createButton(slot, inventory, new ItemStack(material), name, lore);
}
protected ItemStack createButton(int slot, Material material, String name, ArrayList<String> lore) {
return createButton(slot, material, name, lore.toArray(new String[0]));
}
protected ItemStack createButton(int slot, ItemStack item, String name, ArrayList<String> lore) {
return createButton(slot, item, name, lore.toArray(new String[0]));
}
protected void registerClickable(int min, int max, ClickType clickType, boolean bottom, Clickable clickable) {
clickables.put(new Range(min, max, clickType, bottom), clickable);
}
protected void registerClickable(int min, int max, ClickType clickType, Clickable clickable) {
registerClickable(min, max, clickType, false, clickable);
}
protected void registerClickable(int slot, ClickType clickType, Clickable clickable) {
registerClickable(slot, slot, clickType, false, clickable);
}
protected void registerClickable(int min, int max, Clickable clickable) {
registerClickable(min, max, null, false, clickable);
}
protected void registerClickable(int slot, boolean bottom, Clickable clickable) {
registerClickable(slot, slot, null, bottom, clickable);
}
protected void registerClickable(int slot, Clickable clickable) {
registerClickable(slot, slot, null, false, clickable);
}
protected void resetClickables() {
clickables.clear();
}
protected void registerOnClose(OnClose onClose) {
onCloses.add(onClose);
}
public Inventory getInventory() {
return inventory;
}
public class GUIHolder implements InventoryHolder {
@Override
public Inventory getInventory() {
return inventory;
}
public AbstractGUI getGUI() {
return AbstractGUI.this;
}
}
}

View File

@ -1,11 +0,0 @@
package com.songoda.ultimatekits.utils.gui;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
public interface Clickable {
void Clickable(Player player, Inventory inventory, ItemStack cursor, int slot, ClickType type);
}

View File

@ -1,10 +0,0 @@
package com.songoda.ultimatekits.utils.gui;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
public interface OnClose {
void OnClose(Player player, Inventory inventory);
}

View File

@ -1,51 +0,0 @@
package com.songoda.ultimatekits.utils.gui;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.utils.ServerVersion;
import org.bukkit.Sound;
import org.bukkit.event.inventory.ClickType;
public class Range {
private int min;
private int max;
private ClickType clickType;
private boolean bottom;
private Sound onClickSound;
public Range(int min, int max, ClickType clickType, boolean bottom) {
this.min = min;
this.max = max;
this.clickType = clickType;
this.bottom = bottom;
if (UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_9)) onClickSound = Sound.UI_BUTTON_CLICK;
}
public Range(int min, int max, Sound onClickSound, ClickType clickType, boolean bottom) {
this.min = min;
this.max = max;
this.onClickSound = onClickSound;
this.clickType = clickType;
this.bottom = bottom;
}
public int getMin() {
return min;
}
public int getMax() {
return max;
}
public ClickType getClickType() {
return clickType;
}
public boolean isBottom() {
return bottom;
}
public Sound getOnClickSound() {
return onClickSound;
}
}

View File

@ -1,39 +0,0 @@
package com.songoda.epicspawners.api.utils;
import org.bukkit.Location;
/**
* A more specific implementation of {@link ProtectionPluginHook} used internally by
* EpicSpawners to retain more information about default hooks. Often times this
* interface is not recommended over the ProtectionPluginHook interface as its methods
* will not often be used by implementation, though they are available if more information
* is desired. It is, however, recommended to use the former
*
* @author Parker Hawke - 2008Choco
*/
public interface ClaimableProtectionPluginHook extends ProtectionPluginHook {
/**
* Check whether the provided location is in the claim with the given String ID
*
* @param location the location to check
* @param id the ID of the claim to check
*
* @return true if the location is within the claim, false otherwise or if the
* claim ID does not exist
*/
public boolean isInClaim(Location location, String id);
/**
* Get the ID of the claim with the given name. Often times this is unnecessary
* as unique IDs are not provided by a claim implementation, though for plugins
* such as factions, the passed parameter is the name of the faction and the
* returned String is its unique ID
*
* @param name the name of the claim to check
*
* @return the unique String ID. null if no claim exists
*/
public String getClaimID(String name);
}

View File

@ -1,49 +0,0 @@
package com.songoda.epicspawners.api.utils;
import com.songoda.epicspawners.api.EpicSpawners;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
/**
* Represents a hook for a protection plugin. This is used by EpicSpawners to determine
* whether a block break should be successful or not according to the current state of
* another plugin. For plugins providing claims with unique String IDs, see the
* {@link ClaimableProtectionPluginHook} for a more detailed implementation. To register
* a protection hook implementation, see
* {@link EpicSpawners#registerProtectionHook(ProtectionPluginHook)}
*/
public interface ProtectionPluginHook {
/**
* The plugin to which this plugin hook belongs. Must not be null
*
* @return the hooking plugin
*/
public JavaPlugin getPlugin();
/**
* Check whether the provided player may build at the specified location
*
* @param player the player to check
* @param location the location to check
*
* @return true if player is permitted to build, false otherwise
*/
public boolean canBuild(Player player, Location location);
/**
* Check whether the provided player may build at the specified block
*
* @param player the player to check
* @param block the block to check
*
* @return true if player is permitted to build, false otherwise
*/
public default boolean canBuild(Player player, Block block) {
return block != null && canBuild(player, block.getLocation());
}
}

View File

@ -1,39 +0,0 @@
package de.tr7zw.itemnbtapi;
import org.bukkit.Bukkit;
public enum ClassWrapper {
CRAFT_ITEMSTACK("org.bukkit.craftbukkit.", ".inventory.CraftItemStack"),
CRAFT_ENTITY("org.bukkit.craftbukkit.", ".entity.CraftEntity"),
CRAFT_WORLD("org.bukkit.craftbukkit.", ".CraftWorld"),
NMS_NBTBASE("net.minecraft.server.", ".NBTBase"),
NMS_NBTTAGSTRING("net.minecraft.server.", ".NBTTagString"),
NMS_ITEMSTACK("net.minecraft.server.", ".ItemStack"),
NMS_NBTTAGCOMPOUND("net.minecraft.server.", ".NBTTagCompound"),
NMS_NBTTAGLIST("net.minecraft.server.", ".NBTTagList"),
NMS_NBTCOMPRESSEDSTREAMTOOLS("net.minecraft.server.", ".NBTCompressedStreamTools"),
NMS_MOJANGSONPARSER("net.minecraft.server.", ".MojangsonParser"),
NMS_TILEENTITY("net.minecraft.server.", ".TileEntity"),
NMS_BLOCKPOSITION("net.minecraft.server.", ".BlockPosition"),
NMS_WORLD("net.minecraft.server.", ".WorldServer"),
NMS_ENTITY("net.minecraft.server.", ".Entity"),
;
private Class<?> clazz;
ClassWrapper(String pre, String suffix){
try{
String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
clazz = Class.forName(pre + version + suffix);
}catch(Exception ex){
ex.printStackTrace();
}
}
public Class<?> getClazz(){
return clazz;
}
}

View File

@ -1,200 +0,0 @@
package de.tr7zw.itemnbtapi;
import java.util.Set;
import de.tr7zw.itemnbtapi.utils.MinecraftVersion;
public class NBTCompound {
private String compundName;
private NBTCompound parent;
protected NBTCompound(NBTCompound owner, String name) {
this.compundName = name;
this.parent = owner;
}
public String getName() {
return compundName;
}
protected Object getCompound() {
return parent.getCompound();
}
protected void setCompound(Object compound) {
parent.setCompound(compound);
}
public NBTCompound getParent() {
return parent;
}
public void mergeCompound(NBTCompound comp){
NBTReflectionUtil.addOtherNBTCompound(this, comp);
}
public void setString(String key, String value) {
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_STRING, key, value);
}
public String getString(String key) {
return (String) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_STRING, key);
}
protected String getContent(String key) {
return NBTReflectionUtil.getContent(this, key);
}
public void setInteger(String key, Integer value) {
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_INT, key, value);
}
public Integer getInteger(String key) {
return (Integer) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_INT, key);
}
public void setDouble(String key, Double value) {
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_DOUBLE, key, value);
}
public Double getDouble(String key) {
return (Double) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_DOUBLE, key);
}
public void setByte(String key, Byte value) {
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_BYTE, key, value);
}
public Byte getByte(String key) {
return (Byte) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_BYTE, key);
}
public void setShort(String key, Short value) {
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_SHORT, key, value);
}
public Short getShort(String key) {
return (Short) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_SHORT, key);
}
public void setLong(String key, Long value) {
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_LONG, key, value);
}
public Long getLong(String key) {
return (Long) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_LONG, key);
}
public void setFloat(String key, Float value) {
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_FLOAT, key, value);
}
public Float getFloat(String key) {
return (Float) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_FLOAT, key);
}
public void setByteArray(String key, byte[] value) {
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_BYTEARRAY, key, value);
}
public byte[] getByteArray(String key) {
return (byte[]) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_BYTEARRAY, key);
}
public void setIntArray(String key, int[] value) {
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_INTARRAY, key, value);
}
public int[] getIntArray(String key) {
return (int[]) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_INTARRAY, key);
}
public void setBoolean(String key, Boolean value) {
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_BOOLEAN, key, value);
}
protected void set(String key, Object val) {
NBTReflectionUtil.set(this, key, val);
}
public Boolean getBoolean(String key) {
return (Boolean) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_BOOLEAN, key);
}
public void setObject(String key, Object value) {
NBTReflectionUtil.setObject(this, key, value);
}
public <T> T getObject(String key, Class<T> type) {
return NBTReflectionUtil.getObject(this, key, type);
}
public Boolean hasKey(String key) {
Boolean b = (Boolean) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_HAS_KEY, key);
if(b == null)return false;
return b;
}
public void removeKey(String key) {
NBTReflectionUtil.remove(this, key);
}
public Set<String> getKeys() {
return NBTReflectionUtil.getKeys(this);
}
public NBTCompound addCompound(String name) {
if(getType(name) == NBTType.NBTTagCompound)return getCompound(name);
NBTReflectionUtil.addNBTTagCompound(this, name);
return getCompound(name);
}
public NBTCompound getCompound(String name) {
NBTCompound next = new NBTCompound(this, name);
if (NBTReflectionUtil.valideCompound(next)) return next;
return null;
}
public NBTList getList(String name, NBTType type) {
return NBTReflectionUtil.getList(this, name, type);
}
public NBTType getType(String name) {
if (MinecraftVersion.getVersion() == MinecraftVersion.MC1_7_R4) return null;
Object o = NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_TYPE, name);
if(o == null)return null;
return NBTType.valueOf((byte) o);
}
@Override
public String toString() {
StringBuilder result = new StringBuilder();
for (String key : getKeys()) {
result.append(toString(key));
}
return result.toString();
}
public String toString(String key) {
StringBuilder result = new StringBuilder();
NBTCompound compound = this;
while (compound.getParent() != null) {
result.append(" ");
compound = compound.getParent();
}
if (this.getType(key) == NBTType.NBTTagCompound) {
return this.getCompound(key).toString();
} else {
return result + "-" + key + ": " + getContent(key) + System.lineSeparator();
}
}
public String asNBTString(){
Object comp = NBTReflectionUtil.gettoCompount(getCompound(), this);
if(comp == null)return "{}";
return comp.toString();
}
}

View File

@ -1,35 +0,0 @@
package de.tr7zw.itemnbtapi;
public class NBTContainer extends NBTCompound{
private Object nbt;
public NBTContainer() {
super(null, null);
nbt = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
protected NBTContainer(Object nbt){
super(null, null);
this.nbt = nbt;
}
public NBTContainer(String nbtString) throws IllegalArgumentException {
super(null, null);
try{
nbt = ReflectionMethod.PARSE_NBT.run(null, nbtString);
}catch(Exception ex){
ex.printStackTrace();
throw new IllegalArgumentException("Malformed Json: " + ex.getMessage());
}
}
protected Object getCompound() {
return nbt;
}
protected void setCompound(Object tag) {
nbt = tag;
}
}

View File

@ -1,22 +0,0 @@
package de.tr7zw.itemnbtapi;
import org.bukkit.entity.Entity;
public class NBTEntity extends NBTCompound {
private final Entity ent;
public NBTEntity(Entity entity) {
super(null, null);
ent = entity;
}
protected Object getCompound() {
return NBTReflectionUtil.getEntityNBTTagCompound(NBTReflectionUtil.getNMSEntity(ent));
}
protected void setCompound(Object compound) {
NBTReflectionUtil.setEntityNBTTag(compound, NBTReflectionUtil.getNMSEntity(ent));
}
}

View File

@ -1,46 +0,0 @@
package de.tr7zw.itemnbtapi;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class NBTFile extends NBTCompound {
private final File file;
private Object nbt;
public NBTFile(File file) throws IOException {
super(null, null);
this.file = file;
if (file.exists()) {
FileInputStream inputsteam = new FileInputStream(file);
nbt = NBTReflectionUtil.readNBTFile(inputsteam);
} else {
nbt = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
save();
}
}
public void save() throws IOException {
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
FileOutputStream outStream = new FileOutputStream(file);
NBTReflectionUtil.saveNBTFile(nbt, outStream);
}
public File getFile() {
return file;
}
protected Object getCompound() {
return nbt;
}
protected void setCompound(Object compound) {
nbt = compound;
}
}

View File

@ -1,53 +0,0 @@
package de.tr7zw.itemnbtapi;
import org.bukkit.inventory.ItemStack;
public class NBTItem extends NBTCompound {
private ItemStack bukkitItem;
public NBTItem(ItemStack item) {
super(null, null);
if(item == null){
throw new NullPointerException("ItemStack can't be null!");
}
bukkitItem = item.clone();
}
protected Object getCompound() {
return NBTReflectionUtil.getItemRootNBTTagCompound(ReflectionMethod.ITEMSTACK_NMSCOPY.run(null, bukkitItem));
}
protected void setCompound(Object compound) {
Object stack = ReflectionMethod.ITEMSTACK_NMSCOPY.run(null, bukkitItem);
ReflectionMethod.ITEMSTACK_SET_TAG.run(stack, compound);
bukkitItem = (ItemStack) ReflectionMethod.ITEMSTACK_BUKKITMIRROR.run(null, stack);
}
public ItemStack getItem() {
return bukkitItem;
}
protected void setItem(ItemStack item) {
bukkitItem = item;
}
/**
* This may return true even when the NBT is empty.
*
* @return Does the ItemStack have a NBTCompound.
*/
public boolean hasNBTData(){
return getCompound() != null;
}
public static NBTContainer convertItemtoNBT(ItemStack item){
return NBTReflectionUtil.convertNMSItemtoNBTCompound(ReflectionMethod.ITEMSTACK_NMSCOPY.run(null, item));
}
public static ItemStack convertNBTtoItem(NBTCompound comp){
return (ItemStack) ReflectionMethod.ITEMSTACK_BUKKITMIRROR.run(null, NBTReflectionUtil.convertNBTCompoundtoNMSItem(comp));
}
}

View File

@ -1,114 +0,0 @@
package de.tr7zw.itemnbtapi;
public class NBTList {
private String listName;
private NBTCompound parent;
private NBTType type;
private Object listObject;
protected NBTList(NBTCompound owner, String name, NBTType type, Object list) {
parent = owner;
listName = name;
this.type = type;
this.listObject = list;
if (!(type == NBTType.NBTTagString || type == NBTType.NBTTagCompound)) {
System.err.println("List types != String/Compound are currently not implemented!");
}
}
protected void save() {
parent.set(listName, listObject);
}
public NBTListCompound addCompound() {
if (type != NBTType.NBTTagCompound) {
new Throwable("Using Compound method on a non Compound list!").printStackTrace();
return null;
}
try {
Object compound = ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz().newInstance();
ReflectionMethod.LIST_ADD.run(listObject, compound);
return new NBTListCompound(this, compound);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public NBTListCompound getCompound(int id) {
if (type != NBTType.NBTTagCompound) {
new Throwable("Using Compound method on a non Compound list!").printStackTrace();
return null;
}
try {
Object compound = ReflectionMethod.LIST_GET.run(listObject, id);
return new NBTListCompound(this, compound);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public String getString(int i) {
if (type != NBTType.NBTTagString) {
new Throwable("Using String method on a non String list!").printStackTrace();
return null;
}
try {
return (String) ReflectionMethod.LIST_GET_STRING.run(listObject, i);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public void addString(String s) {
if (type != NBTType.NBTTagString) {
new Throwable("Using String method on a non String list!").printStackTrace();
return;
}
try {
ReflectionMethod.LIST_ADD.run(listObject, ClassWrapper.NMS_NBTTAGSTRING.getClazz().getConstructor(String.class).newInstance(s));
save();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void setString(int i, String s) {
if (type != NBTType.NBTTagString) {
new Throwable("Using String method on a non String list!").printStackTrace();
return;
}
try {
ReflectionMethod.LIST_SET.run(listObject, i, ClassWrapper.NMS_NBTTAGSTRING.getClazz().getConstructor(String.class).newInstance(s));
save();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void remove(int i) {
try {
ReflectionMethod.LIST_REMOVE_KEY.run(listObject, i);
save();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public int size() {
try {
return (int) ReflectionMethod.LIST_SIZE.run(listObject);
} catch (Exception ex) {
ex.printStackTrace();
}
return -1;
}
public NBTType getType() {
return type;
}
}

View File

@ -1,102 +0,0 @@
package de.tr7zw.itemnbtapi;
import java.util.HashSet;
import java.util.Set;
public class NBTListCompound {
private NBTList owner;
private Object compound;
protected NBTListCompound(NBTList parent, Object obj) {
owner = parent;
compound = obj;
}
public void setString(String key, String value) {
if (value == null) {
remove(key);
return;
}
try {
compound.getClass().getMethod("setString", String.class, String.class).invoke(compound, key, value);
owner.save();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void setInteger(String key, int value) {
try {
compound.getClass().getMethod("setInt", String.class, int.class).invoke(compound, key, value);
owner.save();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public int getInteger(String value) {
try {
return (int) compound.getClass().getMethod("getInt", String.class).invoke(compound, value);
} catch (Exception ex) {
ex.printStackTrace();
}
return 0;
}
public void setDouble(String key, double value) {
try {
compound.getClass().getMethod("setDouble", String.class, double.class).invoke(compound, key, value);
owner.save();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public double getDouble(String key) {
try {
return (double) compound.getClass().getMethod("getDouble", String.class).invoke(compound, key);
} catch (Exception ex) {
ex.printStackTrace();
}
return 0;
}
public String getString(String key) {
try {
return (String) compound.getClass().getMethod("getString", String.class).invoke(compound, key);
} catch (Exception ex) {
ex.printStackTrace();
}
return "";
}
public boolean hasKey(String key) {
try {
return (boolean) compound.getClass().getMethod("hasKey", String.class).invoke(compound, key);
} catch (Exception ex) {
ex.printStackTrace();
}
return false;
}
@SuppressWarnings("unchecked")
public Set<String> getKeys() {
try {
return (Set<String>) ReflectionMethod.LISTCOMPOUND_GET_KEYS.run(compound);
} catch (Exception ex) {
ex.printStackTrace();
}
return new HashSet<>();
}
public void remove(String key) {
try {
compound.getClass().getMethod("remove", String.class).invoke(compound, key);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

View File

@ -1,348 +0,0 @@
package de.tr7zw.itemnbtapi;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Set;
import java.util.Stack;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import de.tr7zw.itemnbtapi.utils.GsonWrapper;
import de.tr7zw.itemnbtapi.utils.MinecraftVersion;
public class NBTReflectionUtil {
public static Object getNMSEntity(Entity entity) {
try {
return ReflectionMethod.CRAFT_ENTITY_GET_HANDLE.run(ClassWrapper.CRAFT_ENTITY.getClazz().cast(entity));
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static Object readNBTFile(FileInputStream stream) {
try {
return ReflectionMethod.NBTFILE_READ.run(null, stream);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static Object saveNBTFile(Object nbt, FileOutputStream stream) {
try {
return ReflectionMethod.NBTFILE_WRITE.run(null, nbt, stream);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@SuppressWarnings({"unchecked"})
public static Object getItemRootNBTTagCompound(Object nmsitem) {
@SuppressWarnings("rawtypes")
Class clazz = nmsitem.getClass();
Method method;
try {
method = clazz.getMethod("getTag");
Object answer = method.invoke(nmsitem);
return answer;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@SuppressWarnings({"unchecked"})
public static Object convertNBTCompoundtoNMSItem(NBTCompound nbtcompound) {
@SuppressWarnings("rawtypes")
Class clazz = ClassWrapper.NMS_ITEMSTACK.getClazz();
try {
if(MinecraftVersion.getVersion().getVersionId() >= MinecraftVersion.MC1_12_R1.getVersionId()){
Constructor<?> constructor = clazz.getConstructor(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz());
constructor.setAccessible(true);
return constructor.newInstance(nbtcompound.getCompound());
}else{
Method method = clazz.getMethod("createStack", ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz());
method.setAccessible(true);
return method.invoke(null, nbtcompound.getCompound());
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@SuppressWarnings({"unchecked"})
public static NBTContainer convertNMSItemtoNBTCompound(Object nmsitem) {
@SuppressWarnings("rawtypes")
Class clazz = nmsitem.getClass();
Method method;
try {
method = clazz.getMethod("save", ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz());
Object answer = method.invoke(nmsitem, ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance());
return new NBTContainer(answer);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static Object getEntityNBTTagCompound(Object NMSEntity) {
try {
Object nbt = ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz().newInstance();
Object answer = ReflectionMethod.NMS_ENTITY_GET_NBT.run(NMSEntity, nbt);
if (answer == null)
answer = nbt;
return answer;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static Object setEntityNBTTag(Object NBTTag, Object NMSEntity) {
try {
ReflectionMethod.NMS_ENTITY_SET_NBT.run(NMSEntity, NBTTag);
return NMSEntity;
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static Object getTileEntityNBTTagCompound(BlockState tile) {
try {
Object pos = ObjectCreator.NMS_BLOCKPOSITION.getInstance(tile.getX(), tile.getY(), tile.getZ());
Object cworld = ClassWrapper.CRAFT_WORLD.getClazz().cast(tile.getWorld());
Object nmsworld = ReflectionMethod.CRAFT_WORLD_GET_HANDLE.run(cworld);
Object o = ReflectionMethod.NMS_WORLD_GET_TILEENTITY.run(nmsworld, pos);
Object tag = ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz().newInstance();
Object answer = ReflectionMethod.TILEENTITY_GET_NBT.run(o, tag);
if (answer == null)
answer = tag;
return answer;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static void setTileEntityNBTTagCompound(BlockState tile, Object comp) {
try {
Object pos = ObjectCreator.NMS_BLOCKPOSITION.getInstance(tile.getX(), tile.getY(), tile.getZ());
Object cworld = ClassWrapper.CRAFT_WORLD.getClazz().cast(tile.getWorld());
Object nmsworld = ReflectionMethod.CRAFT_WORLD_GET_HANDLE.run(cworld);
Object o = ReflectionMethod.NMS_WORLD_GET_TILEENTITY.run(nmsworld, pos);
ReflectionMethod.TILEENTITY_SET_NBT.run(o, comp);
} catch (Exception e) {
e.printStackTrace();
}
}
@SuppressWarnings("unchecked")
public static Object getSubNBTTagCompound(Object compound, String name) {
@SuppressWarnings("rawtypes")
Class c = compound.getClass();
Method method;
try {
method = c.getMethod("getCompound", String.class);
Object answer = method.invoke(compound, name);
return answer;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static void addNBTTagCompound(NBTCompound comp, String name) {
if (name == null) {
remove(comp, name);
return;
}
Object nbttag = comp.getCompound();
if (nbttag == null) {
nbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(nbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("set", String.class, ClassWrapper.NMS_NBTBASE.getClazz());
method.invoke(workingtag, name, ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz().newInstance());
comp.setCompound(nbttag);
return;
} catch (Exception ex) {
ex.printStackTrace();
}
return;
}
public static Boolean valideCompound(NBTCompound comp) {
Object root = comp.getCompound();
if (root == null) {
root = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
return (gettoCompount(root, comp)) != null;
}
static Object gettoCompount(Object nbttag, NBTCompound comp) {
Stack<String> structure = new Stack<>();
while (comp.getParent() != null) {
structure.add(comp.getName());
comp = comp.getParent();
}
while (!structure.isEmpty()) {
nbttag = getSubNBTTagCompound(nbttag, structure.pop());
if (nbttag == null) {
return null;
}
}
return nbttag;
}
public static void addOtherNBTCompound(NBTCompound comp, NBTCompound nbtcompound) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp);
try {
ReflectionMethod.COMPOUND_ADD.run(workingtag, nbtcompound.getCompound());
comp.setCompound(rootnbttag);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static String getContent(NBTCompound comp, String key) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("get", String.class);
return method.invoke(workingtag, key).toString();
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static void set(NBTCompound comp, String key, Object val) {
if (val == null) {
remove(comp, key);
return;
}
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
if (!valideCompound(comp)) {
new Throwable("InvalideCompound").printStackTrace();
return;
}
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("set", String.class, ClassWrapper.NMS_NBTBASE.getClazz());
method.invoke(workingtag, key, val);
comp.setCompound(rootnbttag);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static NBTList getList(NBTCompound comp, String key, NBTType type) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("getList", String.class, int.class);
return new NBTList(comp, key, type, method.invoke(workingtag, key, type.getId()));
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static void setObject(NBTCompound comp, String key, Object value) {
if (!MinecraftVersion.hasGsonSupport()) return;
try {
String json = GsonWrapper.getString(value);
setData(comp, ReflectionMethod.COMPOUND_SET_STRING, key, json);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static <T> T getObject(NBTCompound comp, String key, Class<T> type) {
if (!MinecraftVersion.hasGsonSupport()) return null;
String json = (String) getData(comp, ReflectionMethod.COMPOUND_GET_STRING, key);
if (json == null) {
return null;
}
return GsonWrapper.deserializeJson(json, type);
}
public static void remove(NBTCompound comp, String key) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp);
ReflectionMethod.COMPOUND_REMOVE_KEY.run(workingtag, key);
comp.setCompound(rootnbttag);
}
@SuppressWarnings("unchecked")
public static Set<String> getKeys(NBTCompound comp) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp);
return (Set<String>) ReflectionMethod.COMPOUND_GET_KEYS.run(workingtag);
}
public static void setData(NBTCompound comp, ReflectionMethod type, String key, Object data) {
if (data == null) {
remove(comp, key);
return;
}
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp);
type.run(workingtag, key, data);
comp.setCompound(rootnbttag);
}
public static Object getData(NBTCompound comp, ReflectionMethod type, String key) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
return null;
}
if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp);
return type.run(workingtag, key);
}
}

View File

@ -1,22 +0,0 @@
package de.tr7zw.itemnbtapi;
import org.bukkit.block.BlockState;
public class NBTTileEntity extends NBTCompound {
private final BlockState tile;
public NBTTileEntity(BlockState tile) {
super(null, null);
this.tile = tile;
}
protected Object getCompound() {
return NBTReflectionUtil.getTileEntityNBTTagCompound(tile);
}
protected void setCompound(Object compound) {
NBTReflectionUtil.setTileEntityNBTTagCompound(tile, compound);
}
}

View File

@ -1,34 +0,0 @@
package de.tr7zw.itemnbtapi;
public enum NBTType {
NBTTagEnd(0),
NBTTagByte(1),
NBTTagShort(2),
NBTTagInt(3),
NBTTagLong(4),
NBTTagFloat(5),
NBTTagDouble(6),
NBTTagByteArray(7),
NBTTagIntArray(11),
NBTTagString(8),
NBTTagList(9),
NBTTagCompound(10);
NBTType(int i) {
id = i;
}
private final int id;
public int getId() {
return id;
}
public static NBTType valueOf(int id) {
for (NBTType t : values())
if (t.getId() == id)
return t;
return NBTType.NBTTagEnd;
}
}

View File

@ -1,28 +0,0 @@
package de.tr7zw.itemnbtapi;
import java.lang.reflect.Constructor;
public enum ObjectCreator {
NMS_NBTTAGCOMPOUND(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()),
NMS_BLOCKPOSITION(ClassWrapper.NMS_BLOCKPOSITION.getClazz(), int.class, int.class, int.class);
private Constructor<?> construct;
ObjectCreator(Class<?> clazz, Class<?>... args){
try{
construct = clazz.getConstructor(args);
}catch(Exception ex){
ex.printStackTrace();
}
}
public Object getInstance(Object... args){
try{
return construct.newInstance(args);
}catch(Exception ex){
ex.printStackTrace();
}
return null;
}
}

View File

@ -1,121 +0,0 @@
package de.tr7zw.itemnbtapi;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import org.bukkit.inventory.ItemStack;
import de.tr7zw.itemnbtapi.utils.MinecraftVersion;
public enum ReflectionMethod {
COMPOUND_SET_FLOAT(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, float.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setFloat")),
COMPOUND_SET_STRING(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setString")),
COMPOUND_SET_INT(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, int.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setInt")),
COMPOUND_SET_BYTEARRAY(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, byte[].class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setByteArray")),
COMPOUND_SET_INTARRAY(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, int[].class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setIntArray")),
COMPOUND_SET_LONG(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, long.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setLong")),
COMPOUND_SET_SHORT(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, short.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setShort")),
COMPOUND_SET_BYTE(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, byte.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setByte")),
COMPOUND_SET_DOUBLE(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, double.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setDouble")),
COMPOUND_SET_BOOLEAN(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, boolean.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setBoolean")),
COMPOUND_ADD(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "a")), //FIXME: No Spigot mapping!
COMPOUND_GET_FLOAT(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getFloat")),
COMPOUND_GET_STRING(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getString")),
COMPOUND_GET_INT(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getInt")),
COMPOUND_GET_BYTEARRAY(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getByteArray")),
COMPOUND_GET_INTARRAY(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getIntArray")),
COMPOUND_GET_LONG(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getLong")),
COMPOUND_GET_SHORT(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getShort")),
COMPOUND_GET_BYTE(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getByte")),
COMPOUND_GET_DOUBLE(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getDouble")),
COMPOUND_GET_BOOLEAN(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getBoolean")),
COMPOUND_REMOVE_KEY(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "remove")),
COMPOUND_HAS_KEY(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "hasKey")),
COMPOUND_GET_TYPE(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "b"), new Since(MinecraftVersion.MC1_9_R1, "d")), //FIXME: No Spigot mapping!
COMPOUND_GET_KEYS(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "c"), new Since(MinecraftVersion.MC1_13_R1, "getKeys")),
LISTCOMPOUND_GET_KEYS(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "c"), new Since(MinecraftVersion.MC1_13_R1, "getKeys")),
LIST_REMOVE_KEY(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{int.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "a"), new Since(MinecraftVersion.MC1_9_R1, "remove")),
LIST_SIZE(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "size")),
LIST_SET(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{int.class, ClassWrapper.NMS_NBTBASE.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "a"), new Since(MinecraftVersion.MC1_13_R1, "set")),
LIST_ADD(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{ClassWrapper.NMS_NBTBASE.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "add")),
LIST_GET_STRING(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{int.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getString")),
LIST_GET(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{int.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "get")),
ITEMSTACK_SET_TAG(ClassWrapper.NMS_ITEMSTACK.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setTag")),
ITEMSTACK_NMSCOPY(ClassWrapper.CRAFT_ITEMSTACK.getClazz(), new Class[]{ItemStack.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "asNMSCopy")),
ITEMSTACK_BUKKITMIRROR(ClassWrapper.CRAFT_ITEMSTACK.getClazz(), new Class[]{ClassWrapper.NMS_ITEMSTACK.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "asCraftMirror")),
CRAFT_WORLD_GET_HANDLE(ClassWrapper.CRAFT_WORLD.getClazz(), new Class[]{}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getHandle")),
NMS_WORLD_GET_TILEENTITY(ClassWrapper.NMS_WORLD.getClazz(), new Class[]{ClassWrapper.NMS_BLOCKPOSITION.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getTileEntity")),
TILEENTITY_GET_NBT(ClassWrapper.NMS_TILEENTITY.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "b"), new Since(MinecraftVersion.MC1_9_R1, "save")),
TILEENTITY_SET_NBT(ClassWrapper.NMS_TILEENTITY.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "a"), new Since(MinecraftVersion.MC1_12_R1, "load")),
CRAFT_ENTITY_GET_HANDLE(ClassWrapper.CRAFT_ENTITY.getClazz(), new Class[]{}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getHandle")),
NMS_ENTITY_SET_NBT(ClassWrapper.NMS_ENTITY.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "f")), //FIXME: No Spigot mapping!
NMS_ENTITY_GET_NBT(ClassWrapper.NMS_ENTITY.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "e"), new Since(MinecraftVersion.MC1_12_R1, "save")),
NBTFILE_READ(ClassWrapper.NMS_NBTCOMPRESSEDSTREAMTOOLS.getClazz(), new Class[]{InputStream.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "a")), //FIXME: No Spigot mapping!
NBTFILE_WRITE(ClassWrapper.NMS_NBTCOMPRESSEDSTREAMTOOLS.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), OutputStream.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "a")), //FIXME: No Spigot mapping!
PARSE_NBT(ClassWrapper.NMS_MOJANGSONPARSER.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "parse")),
;
private Since targetVersion;
private Method method;
private boolean loaded = false;
private boolean compatible = false;
ReflectionMethod(Class<?> targetClass, Class<?>[] args, MinecraftVersion addedSince, Since... methodnames){
MinecraftVersion server = MinecraftVersion.getVersion();
if(server.compareTo(addedSince) < 0)return;
compatible = true;
Since target = methodnames[0];
for(Since s : methodnames){
if(s.version.getVersionId() <= server.getVersionId() && target.version.getVersionId() < s.version.getVersionId())
target = s;
}
targetVersion = target;
try{
method = targetClass.getMethod(targetVersion.name, args);
method.setAccessible(true);
loaded = true;
}catch(NullPointerException | NoSuchMethodException | SecurityException ex){
ex.printStackTrace();
}
}
public Object run(Object target, Object... args){
try{
return method.invoke(target, args);
}catch(Exception ex){
ex.printStackTrace();
}
return null;
}
public boolean isLoaded() {
return loaded;
}
public boolean isCompatible() {
return compatible;
}
public static class Since{
public final MinecraftVersion version;
public final String name;
public Since(MinecraftVersion version, String name) {
this.version = version;
this.name = name;
}
}
}

View File

@ -1,27 +0,0 @@
package de.tr7zw.itemnbtapi.utils;
import com.google.gson.Gson;
public class GsonWrapper {
private static final Gson gson = new Gson();
public static String getString(Object obj) {
return gson.toJson(obj);
}
public static <T> T deserializeJson(String json, Class<T> type) {
try {
if (json == null) {
return null;
}
T obj = gson.fromJson(json, type);
return type.cast(obj);
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
}

View File

@ -1,62 +0,0 @@
package de.tr7zw.itemnbtapi.utils;
import org.bukkit.Bukkit;
public enum MinecraftVersion {
Unknown(Integer.MAX_VALUE),//Use the newest known mappings
MC1_7_R4(174),
MC1_8_R3(183),
MC1_9_R1(191),
MC1_9_R2(192),
MC1_10_R1(1101),
MC1_11_R1(1111),
MC1_12_R1(1121),
MC1_13_R1(1131),
MC1_13_R2(1132);
private static MinecraftVersion version;
private static Boolean hasGsonSupport;
private final int versionId;
MinecraftVersion(int versionId) {
this.versionId = versionId;
}
public int getVersionId() {
return versionId;
}
public static MinecraftVersion getVersion() {
if (version != null) {
return version;
}
final String ver = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
System.out.println("[NBTAPI] Found Spigot: " + ver + "! Trying to find NMS support");
try {
version = MinecraftVersion.valueOf(ver.replace("v", "MC"));
} catch (IllegalArgumentException ex) {
version = MinecraftVersion.Unknown;
}
if (version != Unknown) {
System.out.println("[NBTAPI] NMS support '" + version.name() + "' loaded!");
} else {
System.out.println("[NBTAPI] Wasn't able to find NMS Support! Some functions may not work!");
}
return version;
}
public static boolean hasGsonSupport() {
if (hasGsonSupport != null) {
return hasGsonSupport;
}
try {
System.out.println("Found Gson: " + Class.forName("com.google.gson.Gson"));
hasGsonSupport = true;
} catch (Exception ex) {
hasGsonSupport = false;
}
return hasGsonSupport;
}
}

View File

@ -1,100 +0,0 @@
package com.songoda.ultimatekits.utils.version;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.lang.reflect.Field;
public class NMSUtil {
public static String getVersion() {
String name = Bukkit.getServer().getClass().getPackage().getName();
return name.substring(name.lastIndexOf('.') + 1) + ".";
}
public static int getVersionNumber() {
String name = getVersion().substring(3);
return Integer.valueOf(name.substring(0, name.length() - 4));
}
public static int getVersionReleaseNumber() {
String NMSVersion = getVersion();
return Integer.valueOf(NMSVersion.substring(NMSVersion.length() - 2).replace(".", ""));
}
public static Class<?> getNMSClass(String className) {
try {
String fullName = "net.minecraft.server." + getVersion() + className;
Class<?> clazz = Class.forName(fullName);
return clazz;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static Class<?> getCraftClass(String className) throws ClassNotFoundException {
try {
String fullName = "org.bukkit.craftbukkit." + getVersion() + className;
Class<?> clazz = Class.forName(fullName);
return clazz;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static Field getField(Class<?> clazz, String name, boolean declared) {
try {
Field field;
if (declared) {
field = clazz.getDeclaredField(name);
} else {
field = clazz.getField(name);
}
field.setAccessible(true);
return field;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static Object getFieldObject(Object object, Field field) {
try {
return field.get(object);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static void setField(Object object, String fieldName, Object fieldValue, boolean declared) {
try {
Field field;
if (declared) {
field = object.getClass().getDeclaredField(fieldName);
} else {
field = object.getClass().getField(fieldName);
}
field.setAccessible(true);
field.set(object, fieldValue);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void sendPacket(Player player, Object packet) {
try {
Object handle = player.getClass().getMethod("getHandle").invoke(player);
Object playerConnection = handle.getClass().getField("playerConnection").get(handle);
playerConnection.getClass().getMethod("sendPacket", getNMSClass("Packet")).invoke(playerConnection, packet);
} catch (Exception e) {
e.printStackTrace();
}
}
}