mirror of
https://github.com/songoda/EpicHoppers.git
synced 2024-11-22 10:15:43 +01:00
Massive rewrite to code base.
Added an animated timer to the autosell feature. Cleaned up timer appearance for autosell. Redid GUI structure. Cleaned up code. Updated to match Songoda Standards. Made Updating hoppers more responsive. Fixed right-click to desync on filter. Removed brewingstand from Fix for complete mess up with filter linking. You are now shown through lore the amount of currently linked hoppers. Designed and implemented a better system for filter overflow. Fixed hopper info dupe.
This commit is contained in:
parent
7d7e46d116
commit
147731a8cf
@ -4,7 +4,7 @@ stages:
|
||||
variables:
|
||||
name: "EpicHoppers"
|
||||
path: "/builds/Songoda/$name"
|
||||
version: "3.4.1"
|
||||
version: "3.4.2"
|
||||
|
||||
build:
|
||||
stage: build
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.songoda.epichoppers.api;
|
||||
|
||||
/**
|
||||
* Represents a cost type when making a purchase from EpicSpawners
|
||||
*/
|
||||
public enum CostType {
|
||||
|
||||
/**
|
||||
* A purchase made with an economy balance (generally an implementation of Vault)
|
||||
*/
|
||||
ECONOMY,
|
||||
|
||||
/**
|
||||
* A purchase made with a player's experience levels
|
||||
*/
|
||||
EXPERIENCE
|
||||
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
<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">
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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>EpicHoppers-Parent</artifactId>
|
||||
<version>maven-version-number</version>
|
||||
</parent>
|
||||
|
||||
|
||||
<artifactId>EpicHoppers-Plugin</artifactId>
|
||||
|
||||
<repositories>
|
||||
@ -165,7 +165,7 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<finalName>EpicHoppers-${project.version}</finalName>
|
||||
|
@ -115,7 +115,7 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
EpicHoppersAPI.setImplementation(this);
|
||||
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
console.sendMessage(Methods.formatText("&7EpicHoppers " + this.getDescription().getVersion() + " by &5Brianna <3&7!"));
|
||||
console.sendMessage(Methods.formatText("&7EpicHoppers " + this.getDescription().getVersion() + " by &5Songoda <3&7!"));
|
||||
console.sendMessage(Methods.formatText("&7Action: &aEnabling&7..."));
|
||||
|
||||
settingsManager = new SettingsManager(this);
|
||||
@ -211,7 +211,7 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
new HopHandler(this);
|
||||
teleportHandler = new TeleportHandler(this);
|
||||
|
||||
int timeout = getConfig().getInt("Main.Auto Save Interval In Seconds")* 60 * 20;
|
||||
int timeout = getConfig().getInt("Main.Auto Save Interval In Seconds") * 60 * 20;
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(this, this::saveToFile, timeout, timeout);
|
||||
|
||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
@ -233,9 +233,12 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
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("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);
|
||||
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
@ -246,7 +249,7 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
this.storage.closeConnection();
|
||||
this.protectionHooks.clear();
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
console.sendMessage(Methods.formatText("&7EpicHoppers " + this.getDescription().getVersion() + " by &5Brianna <3!"));
|
||||
console.sendMessage(Methods.formatText("&7EpicHoppers " + this.getDescription().getVersion() + " by &5Songoda <3!"));
|
||||
console.sendMessage(Methods.formatText("&7Action: &cDisabling&7..."));
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
}
|
||||
@ -271,7 +274,7 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
for (Object o : files) {
|
||||
JSONObject file = (JSONObject) o;
|
||||
|
||||
switch ((String)file.get("type")) {
|
||||
switch ((String) file.get("type")) {
|
||||
case "locale":
|
||||
InputStream in = new URL((String) file.get("link")).openStream();
|
||||
Locale.saveDefaultLocale(in, (String) file.get("name"));
|
||||
@ -292,6 +295,7 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
this.storage = new StorageYaml(this);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Saves registered hopper to file.
|
||||
*/
|
||||
|
@ -150,8 +150,8 @@ public class Locale {
|
||||
/**
|
||||
* Save a default locale file from the project source directory, to the locale folder
|
||||
*
|
||||
* @param in file to save
|
||||
* @param fileName the name of the file to save
|
||||
* @param in 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(InputStream in, String fileName) {
|
||||
|
@ -5,12 +5,8 @@ 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) {
|
||||
@ -38,4 +34,6 @@ public abstract class AbstractCommand {
|
||||
public abstract String getSyntax();
|
||||
|
||||
public abstract String getDescription();
|
||||
|
||||
public enum ReturnType {SUCCESS, FAILURE, SYNTAX_ERROR}
|
||||
}
|
||||
|
@ -63,11 +63,11 @@ public class CommandManager implements CommandExecutor {
|
||||
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.references.getPrefix() + Methods.formatText("&cInvalid Syntax!"));
|
||||
sender.sendMessage(instance.references.getPrefix() + Methods.formatText("&7The valid syntax is: &6" + command.getSyntax() + "&7."));
|
||||
}
|
||||
AbstractCommand.ReturnType returnType = command.runCommand(instance, sender, strings);
|
||||
if (returnType == AbstractCommand.ReturnType.SYNTAX_ERROR) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Methods.formatText("&cInvalid Syntax!"));
|
||||
sender.sendMessage(instance.references.getPrefix() + Methods.formatText("&7The valid syntax is: &6" + command.getSyntax() + "&7."));
|
||||
}
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
|
||||
|
@ -21,48 +21,48 @@ public class CommandBoost extends AbstractCommand {
|
||||
if (args.length < 3) {
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
if (Bukkit.getPlayer(args[1]) == null) {
|
||||
sender.sendMessage(Methods.formatText(instance.references.getPrefix() + "&cThat player does not exist..."));
|
||||
return ReturnType.FAILURE;
|
||||
} else if (!Methods.isInt(args[2])) {
|
||||
sender.sendMessage(Methods.formatText(instance.references.getPrefix() + "&6" + args[2] + " &7is not a number..."));
|
||||
return ReturnType.FAILURE;
|
||||
} else {
|
||||
Calendar c = Calendar.getInstance();
|
||||
Date currentDate = new Date();
|
||||
c.setTime(currentDate);
|
||||
if (Bukkit.getPlayer(args[1]) == null) {
|
||||
sender.sendMessage(Methods.formatText(instance.references.getPrefix() + "&cThat player does not exist..."));
|
||||
return ReturnType.FAILURE;
|
||||
} else if (!Methods.isInt(args[2])) {
|
||||
sender.sendMessage(Methods.formatText(instance.references.getPrefix() + "&6" + args[2] + " &7is not a number..."));
|
||||
return ReturnType.FAILURE;
|
||||
} else {
|
||||
Calendar c = Calendar.getInstance();
|
||||
Date currentDate = new Date();
|
||||
c.setTime(currentDate);
|
||||
|
||||
String time = "&7.";
|
||||
String time = "&7.";
|
||||
|
||||
if (args.length > 3) {
|
||||
if (args[3].contains("m:")) {
|
||||
String[] arr2 = (args[3]).split(":");
|
||||
c.add(Calendar.MINUTE, Integer.parseInt(arr2[1]));
|
||||
time = " &7for &6" + arr2[1] + " minutes&7.";
|
||||
} else if (args[3].contains("h:")) {
|
||||
String[] arr2 = (args[3]).split(":");
|
||||
c.add(Calendar.HOUR, Integer.parseInt(arr2[1]));
|
||||
time = " &7for &6" + arr2[1] + " hours&7.";
|
||||
} else if (args[3].contains("d:")) {
|
||||
String[] arr2 = (args[3]).split(":");
|
||||
c.add(Calendar.HOUR, Integer.parseInt(arr2[1]) * 24);
|
||||
time = " &7for &6" + arr2[1] + " days&7.";
|
||||
} else if (args[3].contains("y:")) {
|
||||
String[] arr2 = (args[3]).split(":");
|
||||
c.add(Calendar.YEAR, Integer.parseInt(arr2[1]));
|
||||
time = " &7for &6" + arr2[1] + " years&7.";
|
||||
} else {
|
||||
sender.sendMessage(Methods.formatText(instance.references.getPrefix() + "&7" + args[3] + " &7is invalid."));
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
if (args.length > 3) {
|
||||
if (args[3].contains("m:")) {
|
||||
String[] arr2 = (args[3]).split(":");
|
||||
c.add(Calendar.MINUTE, Integer.parseInt(arr2[1]));
|
||||
time = " &7for &6" + arr2[1] + " minutes&7.";
|
||||
} else if (args[3].contains("h:")) {
|
||||
String[] arr2 = (args[3]).split(":");
|
||||
c.add(Calendar.HOUR, Integer.parseInt(arr2[1]));
|
||||
time = " &7for &6" + arr2[1] + " hours&7.";
|
||||
} else if (args[3].contains("d:")) {
|
||||
String[] arr2 = (args[3]).split(":");
|
||||
c.add(Calendar.HOUR, Integer.parseInt(arr2[1]) * 24);
|
||||
time = " &7for &6" + arr2[1] + " days&7.";
|
||||
} else if (args[3].contains("y:")) {
|
||||
String[] arr2 = (args[3]).split(":");
|
||||
c.add(Calendar.YEAR, Integer.parseInt(arr2[1]));
|
||||
time = " &7for &6" + arr2[1] + " years&7.";
|
||||
} else {
|
||||
c.add(Calendar.YEAR, 10);
|
||||
sender.sendMessage(Methods.formatText(instance.references.getPrefix() + "&7" + args[3] + " &7is invalid."));
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
BoostData boostData = new BoostData(Integer.parseInt(args[2]), c.getTime().getTime(), Bukkit.getPlayer(args[1]).getUniqueId());
|
||||
instance.getBoostManager().addBoostToPlayer(boostData);
|
||||
sender.sendMessage(Methods.formatText(instance.references.getPrefix() + "&7Successfully boosted &6" + Bukkit.getPlayer(args[1]).getName() + "'s &7hoppers transfer rates by &6" + args[2] + "x" + time));
|
||||
} else {
|
||||
c.add(Calendar.YEAR, 10);
|
||||
}
|
||||
|
||||
BoostData boostData = new BoostData(Integer.parseInt(args[2]), c.getTime().getTime(), Bukkit.getPlayer(args[1]).getUniqueId());
|
||||
instance.getBoostManager().addBoostToPlayer(boostData);
|
||||
sender.sendMessage(Methods.formatText(instance.references.getPrefix() + "&7Successfully boosted &6" + Bukkit.getPlayer(args[1]).getName() + "'s &7hoppers transfer rates by &6" + args[2] + "x" + time));
|
||||
}
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ public class CommandEpicHoppers extends AbstractCommand {
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicHoppersPlugin instance, CommandSender sender, String... args) {
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage(Methods.formatText(instance.references.getPrefix() + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oBrianna"));
|
||||
sender.sendMessage(Methods.formatText(instance.references.getPrefix() + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oSongoda"));
|
||||
|
||||
for (AbstractCommand command : instance.getCommandManager().getCommands()) {
|
||||
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
|
||||
|
@ -24,30 +24,30 @@ public class CommandGive extends AbstractCommand {
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
Level level = instance.getLevelManager().getLowestLevel();
|
||||
Player player;
|
||||
if (args.length != 1 && Bukkit.getPlayer(args[1]) == null) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Methods.formatText("&cThat player does not exist or is currently offline."));
|
||||
Level level = instance.getLevelManager().getLowestLevel();
|
||||
Player player;
|
||||
if (args.length != 1 && Bukkit.getPlayer(args[1]) == null) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Methods.formatText("&cThat player does not exist or is currently offline."));
|
||||
return ReturnType.FAILURE;
|
||||
} else if (args.length == 1) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Methods.formatText("&cYou need to be a player to give a hopper to yourself."));
|
||||
return ReturnType.FAILURE;
|
||||
} else if (args.length == 1) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Methods.formatText("&cYou need to be a player to give a hopper to yourself."));
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
player = (Player) sender;
|
||||
} else {
|
||||
player = Bukkit.getPlayer(args[1]);
|
||||
}
|
||||
player = (Player) sender;
|
||||
} else {
|
||||
player = Bukkit.getPlayer(args[1]);
|
||||
}
|
||||
|
||||
|
||||
if (args.length >= 3 && !instance.getLevelManager().isLevel(Integer.parseInt(args[2]))) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Methods.formatText("&cNot a valid level... The current valid levels are: &4" + instance.getLevelManager().getLowestLevel().getLevel() + "-" + instance.getLevelManager().getHighestLevel().getLevel() + "&c."));
|
||||
return ReturnType.FAILURE;
|
||||
} else if (args.length != 1) {
|
||||
level = instance.getLevelManager().getLevel(Integer.parseInt(args[2]));
|
||||
}
|
||||
player.getInventory().addItem(instance.newHopperItem(level));
|
||||
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("command.give.success", level.getLevel()));
|
||||
if (args.length >= 3 && !instance.getLevelManager().isLevel(Integer.parseInt(args[2]))) {
|
||||
sender.sendMessage(instance.references.getPrefix() + Methods.formatText("&cNot a valid level... The current valid levels are: &4" + instance.getLevelManager().getLowestLevel().getLevel() + "-" + instance.getLevelManager().getHighestLevel().getLevel() + "&c."));
|
||||
return ReturnType.FAILURE;
|
||||
} else if (args.length != 1) {
|
||||
level = instance.getLevelManager().getLevel(Integer.parseInt(args[2]));
|
||||
}
|
||||
player.getInventory().addItem(instance.newHopperItem(level));
|
||||
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("command.give.success", level.getLevel()));
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
@ -0,0 +1,72 @@
|
||||
package com.songoda.epichoppers.gui;
|
||||
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.api.hopper.Hopper;
|
||||
import com.songoda.epichoppers.hopper.EHopper;
|
||||
import com.songoda.epichoppers.utils.Methods;
|
||||
import com.songoda.epichoppers.utils.gui.AbstractGUI;
|
||||
import com.songoda.epichoppers.utils.gui.Range;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class GUICrafting extends AbstractGUI {
|
||||
|
||||
private final EpicHoppersPlugin plugin;
|
||||
private final EHopper hopper;
|
||||
private final Player player;
|
||||
|
||||
public GUICrafting(EpicHoppersPlugin plugin, EHopper hopper, Player player) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.hopper = hopper;
|
||||
this.player = player;
|
||||
|
||||
init(Methods.formatText(Methods.formatName(hopper.getLevel().getLevel(), false) + " &8-&f Crafting"), 27);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void constructGUI() {
|
||||
int nu = 0;
|
||||
while (nu != 27) {
|
||||
inventory.setItem(nu, Methods.getGlass());
|
||||
nu++;
|
||||
}
|
||||
|
||||
inventory.setItem(0, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(1, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(2, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(6, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(7, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(8, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(9, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(10, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(16, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(17, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(18, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(19, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(20, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(24, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(25, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(26, Methods.getBackgroundGlass(true));
|
||||
|
||||
inventory.setItem(13, new ItemStack(hopper.getAutoCrafting() == null ? Material.AIR : hopper.getAutoCrafting()));
|
||||
|
||||
addDraggable(new Range(13, 13, null, false), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerClickables() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerOnCloses() {
|
||||
registerOnClose(((player, inventory) -> {
|
||||
Hopper hopper = plugin.getHopperManager().getHopperFromPlayer(player);
|
||||
ItemStack item = inventory.getItem(13);
|
||||
hopper.setAutoCrafting(item == null ? Material.AIR : item.getType());
|
||||
}));
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,224 @@
|
||||
package com.songoda.epichoppers.gui;
|
||||
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.api.hopper.Filter;
|
||||
import com.songoda.epichoppers.hopper.EHopper;
|
||||
import com.songoda.epichoppers.player.SyncType;
|
||||
import com.songoda.epichoppers.utils.Debugger;
|
||||
import com.songoda.epichoppers.utils.Methods;
|
||||
import com.songoda.epichoppers.utils.gui.AbstractGUI;
|
||||
import com.songoda.epichoppers.utils.gui.Range;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GUIFilter extends AbstractGUI {
|
||||
|
||||
private final EpicHoppersPlugin plugin;
|
||||
private final EHopper hopper;
|
||||
private final Player player;
|
||||
|
||||
public GUIFilter(EpicHoppersPlugin plugin, EHopper hopper, Player player) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.hopper = hopper;
|
||||
this.player = player;
|
||||
|
||||
init(Methods.formatText(Methods.formatName(hopper.getLevel().getLevel(), false) + " &8-&f Filter"), 54);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void constructGUI() {
|
||||
|
||||
Filter filter = hopper.getFilter();
|
||||
|
||||
inventory.setItem(6, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(7, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(8, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(15, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(17, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(24, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(25, Methods.getGlass());
|
||||
inventory.setItem(26, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(33, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(34, Methods.getGlass());
|
||||
inventory.setItem(35, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(42, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(44, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(51, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(52, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(53, Methods.getBackgroundGlass(true));
|
||||
|
||||
ItemStack it = new ItemStack(Material.WHITE_STAINED_GLASS_PANE, 1);
|
||||
ItemMeta itm = it.getItemMeta();
|
||||
itm.setDisplayName(plugin.getLocale().getMessage("interface.filter.whitelist"));
|
||||
it.setItemMeta(itm);
|
||||
|
||||
int[] whiteSlots = {0, 1, 45, 46};
|
||||
for (int nu : whiteSlots) {
|
||||
inventory.setItem(nu, it);
|
||||
}
|
||||
|
||||
int[] awhite = {9, 10, 18, 19, 27, 28, 36, 37};
|
||||
int num = 0;
|
||||
for (ItemStack m : filter.getWhiteList()) {
|
||||
if (num >= filter.getWhiteList().size()) break;
|
||||
inventory.setItem(awhite[num], new ItemStack(m));
|
||||
num++;
|
||||
}
|
||||
|
||||
it = new ItemStack(Material.BLACK_STAINED_GLASS_PANE, 1);
|
||||
itm = it.getItemMeta();
|
||||
itm.setDisplayName(plugin.getLocale().getMessage("interface.filter.blacklist"));
|
||||
it.setItemMeta(itm);
|
||||
|
||||
int[] blackSlots = {2, 3, 47, 48};
|
||||
for (int nu : blackSlots) {
|
||||
inventory.setItem(nu, it);
|
||||
}
|
||||
|
||||
int[] ablack = {11, 12, 20, 21, 29, 30, 38, 39};
|
||||
num = 0;
|
||||
for (ItemStack m : filter.getBlackList()) {
|
||||
if (num >= filter.getBlackList().size()) break;
|
||||
inventory.setItem(ablack[num], new ItemStack(m));
|
||||
num++;
|
||||
}
|
||||
|
||||
it = new ItemStack(Material.BARRIER);
|
||||
itm = it.getItemMeta();
|
||||
itm.setDisplayName(plugin.getLocale().getMessage("interface.filter.void"));
|
||||
it.setItemMeta(itm);
|
||||
|
||||
int[] avoid = {4, 5, 49, 50};
|
||||
for (int nu : avoid) {
|
||||
inventory.setItem(nu, it);
|
||||
}
|
||||
|
||||
int[] voidSlots = {13, 14, 22, 23, 31, 32, 40, 41};
|
||||
num = 0;
|
||||
for (ItemStack m : filter.getVoidList()) {
|
||||
if (num >= filter.getVoidList().size()) break;
|
||||
inventory.setItem(voidSlots[num], new ItemStack(m));
|
||||
num++;
|
||||
}
|
||||
|
||||
ItemStack itemInfo = new ItemStack(Material.PAPER, 1);
|
||||
ItemMeta itemmetaInfo = itemInfo.getItemMeta();
|
||||
itemmetaInfo.setDisplayName(plugin.getLocale().getMessage("interface.filter.infotitle"));
|
||||
ArrayList<String> loreInfo = new ArrayList<>();
|
||||
String[] parts = plugin.getLocale().getMessage("interface.filter.infolore").split("\\|");
|
||||
for (String line : parts) {
|
||||
loreInfo.add(Methods.formatText(line));
|
||||
}
|
||||
itemmetaInfo.setLore(loreInfo);
|
||||
itemInfo.setItemMeta(itemmetaInfo);
|
||||
|
||||
inventory.setItem(16, itemInfo);
|
||||
|
||||
|
||||
ItemStack hook = new ItemStack(Material.TRIPWIRE_HOOK, 1);
|
||||
ItemMeta hookmeta = hook.getItemMeta();
|
||||
hookmeta.setDisplayName(plugin.getLocale().getMessage("interface.hopper.rejectsync"));
|
||||
ArrayList<String> lorehook = new ArrayList<>();
|
||||
parts = plugin.getLocale().getMessage("interface.hopper.synclore", filter.getEndPoint() != null ? 1 : 0).split("\\|");
|
||||
for (String line : parts) {
|
||||
lorehook.add(Methods.formatText(line));
|
||||
}
|
||||
hookmeta.setLore(lorehook);
|
||||
hook.setItemMeta(hookmeta);
|
||||
inventory.setItem(43, hook);
|
||||
|
||||
addDraggable(new Range(9, 14, null, false), true);
|
||||
addDraggable(new Range(18, 23, null, false), true);
|
||||
addDraggable(new Range(27, 32, null, false), true);
|
||||
addDraggable(new Range(36, 41, null, false), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerClickables() {
|
||||
registerClickable(43, ((player, inventory, cursor, slot, type) -> {
|
||||
if (type == ClickType.RIGHT) {
|
||||
player.sendMessage(plugin.references.getPrefix() + plugin.getLocale().getMessage("event.hopper.desync"));
|
||||
hopper.getFilter().setEndPoint(null);
|
||||
} else {
|
||||
plugin.getPlayerDataManager().getPlayerData(player).setSyncType(SyncType.FILTERED);
|
||||
player.sendMessage(plugin.references.getPrefix() + plugin.getLocale().getMessage("event.hopper.syncnext"));
|
||||
hopper.timeout(player);
|
||||
}
|
||||
player.closeInventory();
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
private void compile(Player p) {
|
||||
try {
|
||||
ItemStack[] items = p.getOpenInventory().getTopInventory().getContents();
|
||||
|
||||
Filter filter = hopper.getFilter();
|
||||
|
||||
List<ItemStack> owhite = new ArrayList<>();
|
||||
List<ItemStack> oblack = new ArrayList<>();
|
||||
List<ItemStack> ovoid = new ArrayList<>();
|
||||
|
||||
int[] awhite = {9, 10, 18, 19, 27, 28, 36, 37};
|
||||
int[] ablack = {11, 12, 20, 21, 29, 30, 38, 39};
|
||||
int[] avoid = {13, 14, 22, 23, 31, 32, 40, 41};
|
||||
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
for (int aa : awhite) {
|
||||
if (aa != i) continue;
|
||||
if (items[i] != null && items[i].getType() != Material.AIR) {
|
||||
ItemStack item = items[i];
|
||||
if (item.getAmount() != 1) {
|
||||
item.setAmount(item.getAmount() - 1);
|
||||
Bukkit.getPlayer(hopper.getLastPlayer()).getInventory().addItem(item);
|
||||
item.setAmount(1);
|
||||
}
|
||||
owhite.add(item);
|
||||
}
|
||||
}
|
||||
for (int aa : ablack) {
|
||||
if (aa != i) continue;
|
||||
if (items[i] != null && items[i].getType() != Material.AIR) {
|
||||
ItemStack item = items[i];
|
||||
if (item.getAmount() != 1) {
|
||||
item.setAmount(item.getAmount() - 1);
|
||||
Bukkit.getPlayer(hopper.getLastPlayer()).getInventory().addItem(item);
|
||||
item.setAmount(1);
|
||||
}
|
||||
oblack.add(item);
|
||||
}
|
||||
}
|
||||
for (int aa : avoid) {
|
||||
if (aa != i) continue;
|
||||
if (items[i] != null && items[i].getType() != Material.AIR) {
|
||||
ItemStack item = items[i];
|
||||
if (item.getAmount() != 1) {
|
||||
item.setAmount(item.getAmount() - 1);
|
||||
Bukkit.getPlayer(hopper.getLastPlayer()).getInventory().addItem(item);
|
||||
item.setAmount(1);
|
||||
}
|
||||
ovoid.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
filter.setWhiteList(owhite);
|
||||
filter.setBlackList(oblack);
|
||||
filter.setVoidList(ovoid);
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerOnCloses() {
|
||||
registerOnClose(((player, inventory) -> compile(player)));
|
||||
}
|
||||
}
|
@ -0,0 +1,304 @@
|
||||
package com.songoda.epichoppers.gui;
|
||||
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.api.CostType;
|
||||
import com.songoda.epichoppers.api.hopper.TeleportTrigger;
|
||||
import com.songoda.epichoppers.api.hopper.levels.Level;
|
||||
import com.songoda.epichoppers.boost.BoostData;
|
||||
import com.songoda.epichoppers.hopper.EHopper;
|
||||
import com.songoda.epichoppers.player.SyncType;
|
||||
import com.songoda.epichoppers.utils.Methods;
|
||||
import com.songoda.epichoppers.utils.gui.AbstractGUI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class GUIHoppperOverview extends AbstractGUI {
|
||||
|
||||
private final EpicHoppersPlugin plugin;
|
||||
private final EHopper hopper;
|
||||
private final Player player;
|
||||
|
||||
private int task;
|
||||
|
||||
public GUIHoppperOverview(EpicHoppersPlugin plugin, EHopper hopper, Player player) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.player = player;
|
||||
this.hopper = hopper;
|
||||
|
||||
init(Methods.formatName(hopper.getLevel().getLevel(), false), 27);
|
||||
runTask();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void constructGUI() {
|
||||
plugin.getPlayerDataManager().getPlayerData(player).setLastHopper(hopper);
|
||||
|
||||
Level level = hopper.getLevel();
|
||||
|
||||
Level nextLevel = plugin.getLevelManager().getHighestLevel().getLevel() > level.getLevel() ? plugin.getLevelManager().getLevel(level.getLevel() + 1) : null;
|
||||
|
||||
ItemStack perl = new ItemStack(Material.ENDER_PEARL, 1);
|
||||
ItemMeta perlmeta = perl.getItemMeta();
|
||||
perlmeta.setDisplayName(plugin.getLocale().getMessage("interface.hopper.perltitle"));
|
||||
ArrayList<String> loreperl = new ArrayList<>();
|
||||
String[] parts = plugin.getLocale().getMessage("interface.hopper.perllore2", hopper.getTeleportTrigger() == TeleportTrigger.DISABLED ? plugin.getLocale().getMessage("general.word.disabled") : hopper.getTeleportTrigger().name()).split("\\|");
|
||||
for (String line : parts) {
|
||||
loreperl.add(Methods.formatText(line));
|
||||
}
|
||||
perlmeta.setLore(loreperl);
|
||||
perl.setItemMeta(perlmeta);
|
||||
|
||||
ItemStack filter = new ItemStack(Material.COMPARATOR, 1);
|
||||
ItemMeta filtermeta = filter.getItemMeta();
|
||||
filtermeta.setDisplayName(plugin.getLocale().getMessage("interface.hopper.filtertitle"));
|
||||
ArrayList<String> lorefilter = new ArrayList<>();
|
||||
parts = plugin.getLocale().getMessage("interface.hopper.filterlore").split("\\|");
|
||||
for (String line : parts) {
|
||||
lorefilter.add(Methods.formatText(line));
|
||||
}
|
||||
filtermeta.setLore(lorefilter);
|
||||
filter.setItemMeta(filtermeta);
|
||||
|
||||
ItemStack crafting = new ItemStack(Material.CRAFTING_TABLE, 1);
|
||||
ItemMeta craftingmeta = crafting.getItemMeta();
|
||||
craftingmeta.setDisplayName(plugin.getLocale().getMessage("interface.hopper.craftingtitle"));
|
||||
ArrayList<String> lorecrafting = new ArrayList<>();
|
||||
parts = plugin.getLocale().getMessage("interface.hopper.craftinglore").split("\\|");
|
||||
for (String line : parts) {
|
||||
lorecrafting.add(Methods.formatText(line));
|
||||
}
|
||||
craftingmeta.setLore(lorecrafting);
|
||||
crafting.setItemMeta(craftingmeta);
|
||||
|
||||
ItemStack sell = new ItemStack(Material.SUNFLOWER, 1);
|
||||
ItemMeta sellmeta = sell.getItemMeta();
|
||||
sellmeta.setDisplayName(plugin.getLocale().getMessage("interface.hopper.selltitle"));
|
||||
ArrayList<String> loresell = new ArrayList<>();
|
||||
parts = plugin.getLocale().getMessage("interface.hopper.selllore", hopper.getAutoSellTimer() == -9999 ? "\u221E" : (int) Math.floor(hopper.getAutoSellTimer() / 20)).split("\\|");
|
||||
for (String line : parts) {
|
||||
loresell.add(Methods.formatText(line));
|
||||
}
|
||||
sellmeta.setLore(loresell);
|
||||
sell.setItemMeta(sellmeta);
|
||||
|
||||
|
||||
ItemStack item = new ItemStack(Material.HOPPER, 1);
|
||||
ItemMeta itemmeta = item.getItemMeta();
|
||||
itemmeta.setDisplayName(plugin.getLocale().getMessage("interface.hopper.currentlevel", level.getLevel()));
|
||||
List<String> lore = level.getDescription();
|
||||
if (plugin.getConfig().getBoolean("Main.Allow hopper Upgrading")) {
|
||||
lore.add("");
|
||||
if (nextLevel == null) lore.add(plugin.getLocale().getMessage("interface.hopper.alreadymaxed"));
|
||||
else {
|
||||
lore.add(plugin.getLocale().getMessage("interface.hopper.nextlevel", nextLevel.getLevel()));
|
||||
lore.addAll(nextLevel.getDescription());
|
||||
}
|
||||
}
|
||||
|
||||
BoostData boostData = plugin.getBoostManager().getBoost(hopper.getPlacedBy());
|
||||
if (boostData != null) {
|
||||
parts = plugin.getLocale().getMessage("interface.hopper.boostedstats", Integer.toString(boostData.getMultiplier()), Methods.makeReadable(boostData.getEndTime() - System.currentTimeMillis())).split("\\|");
|
||||
lore.add("");
|
||||
for (String line : parts)
|
||||
lore.add(Methods.formatText(line));
|
||||
}
|
||||
|
||||
itemmeta.setLore(lore);
|
||||
item.setItemMeta(itemmeta);
|
||||
|
||||
ItemStack hook = new ItemStack(Material.TRIPWIRE_HOOK, 1);
|
||||
ItemMeta hookmeta = hook.getItemMeta();
|
||||
hookmeta.setDisplayName(plugin.getLocale().getMessage("interface.hopper.synchopper"));
|
||||
ArrayList<String> lorehook = new ArrayList<>();
|
||||
parts = plugin.getLocale().getMessage("interface.hopper.synclore", hopper.getLinkedBlocks().size()).split("\\|");
|
||||
for (String line : parts) {
|
||||
lorehook.add(Methods.formatText(line));
|
||||
}
|
||||
hookmeta.setLore(lorehook);
|
||||
hook.setItemMeta(hookmeta);
|
||||
|
||||
ItemStack itemXP = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.XP Icon")), 1);
|
||||
ItemMeta itemmetaXP = itemXP.getItemMeta();
|
||||
itemmetaXP.setDisplayName(plugin.getLocale().getMessage("interface.hopper.upgradewithxp"));
|
||||
ArrayList<String> loreXP = new ArrayList<>();
|
||||
if (nextLevel != null)
|
||||
loreXP.add(plugin.getLocale().getMessage("interface.hopper.upgradewithxplore", nextLevel.getCostExperience()));
|
||||
else
|
||||
loreXP.add(plugin.getLocale().getMessage("interface.hopper.alreadymaxed"));
|
||||
itemmetaXP.setLore(loreXP);
|
||||
itemXP.setItemMeta(itemmetaXP);
|
||||
|
||||
ItemStack itemECO = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.Economy Icon")), 1);
|
||||
ItemMeta itemmetaECO = itemECO.getItemMeta();
|
||||
itemmetaECO.setDisplayName(plugin.getLocale().getMessage("interface.hopper.upgradewitheconomy"));
|
||||
ArrayList<String> loreECO = new ArrayList<>();
|
||||
if (nextLevel != null)
|
||||
loreECO.add(plugin.getLocale().getMessage("interface.hopper.upgradewitheconomylore", Methods.formatEconomy(nextLevel.getCostEconomy())));
|
||||
else
|
||||
loreECO.add(plugin.getLocale().getMessage("interface.hopper.alreadymaxed"));
|
||||
itemmetaECO.setLore(loreECO);
|
||||
itemECO.setItemMeta(itemmetaECO);
|
||||
|
||||
int nu = 0;
|
||||
while (nu != 27) {
|
||||
inventory.setItem(nu, Methods.getGlass());
|
||||
nu++;
|
||||
}
|
||||
|
||||
Map<Integer, Integer[]> layouts = new HashMap<>();
|
||||
layouts.put(1, new Integer[]{22});
|
||||
layouts.put(2, new Integer[]{22, 4});
|
||||
layouts.put(3, new Integer[]{22, 3, 5});
|
||||
layouts.put(4, new Integer[]{23, 3, 5, 21});
|
||||
layouts.put(5, new Integer[]{23, 3, 5, 21, 22});
|
||||
|
||||
int amount = 1;
|
||||
|
||||
boolean canFilter = level.isFilter() || player.hasPermission("EpicHoppers.Filter");
|
||||
boolean canTeleport = level.isTeleport() || player.hasPermission("EpicHoppers.Teleport");
|
||||
boolean canCraft = level.getRegisteredModules().removeIf(e -> e.getName().equals("AutoCrafting"));
|
||||
boolean canAutoSell = level.getAutoSell() != 0;
|
||||
if (canFilter) amount++;
|
||||
if (canTeleport) amount++;
|
||||
if (canAutoSell) amount++;
|
||||
if (canCraft) amount++;
|
||||
|
||||
Integer[] layout = layouts.get(amount);
|
||||
|
||||
for (int ii = 0; ii < amount; ii++) {
|
||||
int slot = layout[ii];
|
||||
|
||||
if (ii == 0) {
|
||||
inventory.setItem(slot, hook);
|
||||
} else if (canTeleport) {
|
||||
inventory.setItem(slot, perl);
|
||||
canTeleport = false;
|
||||
} else if (canFilter) {
|
||||
inventory.setItem(slot, filter);
|
||||
canFilter = false;
|
||||
} else if (canCraft) {
|
||||
inventory.setItem(slot, crafting);
|
||||
canCraft = false;
|
||||
} else if (canAutoSell) {
|
||||
inventory.setItem(slot, sell);
|
||||
canAutoSell = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (plugin.getConfig().getBoolean("Main.Upgrade With XP") && player.hasPermission("EpicHoppers.Upgrade.XP") && level.getCostExperience() != -1) {
|
||||
inventory.setItem(11, itemXP);
|
||||
}
|
||||
|
||||
inventory.setItem(13, item);
|
||||
|
||||
if (plugin.getConfig().getBoolean("Main.Upgrade With Economy") && player.hasPermission("EpicHoppers.Upgrade.ECO") && level.getCostEconomy() != -1) {
|
||||
inventory.setItem(15, itemECO);
|
||||
}
|
||||
|
||||
inventory.setItem(0, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(1, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(2, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(6, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(7, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(8, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(9, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(10, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(16, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(17, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(18, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(19, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(20, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(24, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(25, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(26, Methods.getBackgroundGlass(true));
|
||||
|
||||
hopper.setLastPlayer(player.getUniqueId());
|
||||
}
|
||||
|
||||
private void runTask() {
|
||||
task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, this::constructGUI, 10L, 10L);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerClickables() {
|
||||
registerClickable(11, ((player, inventory, cursor, slot, type) -> {
|
||||
if (!player.hasPermission("EpicHoppers.Upgrade.XP")
|
||||
|| hopper.getLevel().getCostExperience() == -1) return;
|
||||
hopper.upgrade(player, CostType.EXPERIENCE);
|
||||
this.hopper.overview(player);
|
||||
}));
|
||||
|
||||
registerClickable(15, ((player, inventory, cursor, slot, type) -> {
|
||||
if (!player.hasPermission("EpicHoppers.Upgrade.ECO")
|
||||
|| hopper.getLevel().getCostExperience() == -1) return;
|
||||
hopper.upgrade(player, CostType.ECONOMY);
|
||||
this.hopper.overview(player);
|
||||
}));
|
||||
|
||||
registerClickable(3, 23, ((player, inventory, cursor, slot, type) -> {
|
||||
if (inventory.getItem(slot).getItemMeta()
|
||||
.getDisplayName().equals(plugin.getLocale().getMessage("interface.hopper.selltitle"))) {
|
||||
if (hopper.getAutoSellTimer() == -9999) {
|
||||
hopper.setAutoSellTimer(0);
|
||||
} else {
|
||||
hopper.setAutoSellTimer(-9999);
|
||||
}
|
||||
} else if (inventory.getItem(slot).getItemMeta()
|
||||
.getDisplayName().equals(plugin.getLocale().getMessage("interface.hopper.craftingtitle"))) {
|
||||
new GUICrafting(plugin, hopper, player);
|
||||
} else if (inventory.getItem(slot).getItemMeta()
|
||||
.getDisplayName().equals(plugin.getLocale().getMessage("interface.hopper.filtertitle"))) {
|
||||
new GUIFilter(plugin, hopper, player);
|
||||
} else if (inventory.getItem(slot).getItemMeta()
|
||||
.getDisplayName().equals(plugin.getLocale().getMessage("interface.hopper.perltitle"))) {
|
||||
if (type == ClickType.LEFT) {
|
||||
if (hopper.getLinkedBlocks() != null) {
|
||||
plugin.getTeleportHandler().tpPlayer(player, hopper);
|
||||
player.closeInventory();
|
||||
}
|
||||
} else {
|
||||
if (hopper.getTeleportTrigger() == TeleportTrigger.DISABLED) {
|
||||
hopper.setTeleportTrigger(TeleportTrigger.SNEAK);
|
||||
} else if (hopper.getTeleportTrigger() == TeleportTrigger.SNEAK) {
|
||||
hopper.setTeleportTrigger(TeleportTrigger.WALK_ON);
|
||||
} else if (hopper.getTeleportTrigger() == TeleportTrigger.WALK_ON) {
|
||||
hopper.setTeleportTrigger(TeleportTrigger.DISABLED);
|
||||
}
|
||||
constructGUI();
|
||||
}
|
||||
} else if (inventory.getItem(slot).getItemMeta()
|
||||
.getDisplayName().equals(plugin.getLocale().getMessage("interface.hopper.synchopper"))) {
|
||||
if (type == ClickType.RIGHT) {
|
||||
player.sendMessage(plugin.references.getPrefix() + plugin.getLocale().getMessage("event.hopper.desync"));
|
||||
hopper.clearLinkedBlocks();
|
||||
} else {
|
||||
if (hopper.getLastPlayer() != null && !hopper.getLastPlayer().equals(player.getUniqueId())) {
|
||||
player.sendMessage(plugin.references.getPrefix() + plugin.getLocale().getMessage("event.hopper.syncdidnotplace"));
|
||||
return;
|
||||
}
|
||||
plugin.getPlayerDataManager().getPlayerData(player).setSyncType(SyncType.REGULAR);
|
||||
hopper.clearLinkedBlocks();
|
||||
player.sendMessage(plugin.references.getPrefix() + plugin.getLocale().getMessage("event.hopper.syncnext"));
|
||||
hopper.timeout(player);
|
||||
}
|
||||
player.closeInventory();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerOnCloses() {
|
||||
registerOnClose(((player1, inventory1) -> Bukkit.getScheduler().cancelTask(task)));
|
||||
}
|
||||
}
|
@ -86,9 +86,9 @@ public class HopHandler {
|
||||
|
||||
for (Entity entity : nearbyEntite) {
|
||||
if (entity.getType() == EntityType.MINECART_HOPPER)
|
||||
override = ((HopperMinecart)entity).getInventory();
|
||||
override = ((HopperMinecart) entity).getInventory();
|
||||
else if (entity.getType() == EntityType.MINECART_CHEST)
|
||||
override = ((StorageMinecart)entity).getInventory();
|
||||
override = ((StorageMinecart) entity).getInventory();
|
||||
}
|
||||
|
||||
if (linked.isEmpty()) continue;
|
||||
@ -110,7 +110,7 @@ public class HopHandler {
|
||||
hopper.clearLinkedBlocks();
|
||||
continue;
|
||||
}
|
||||
destinationInventory = ((InventoryHolder)state).getInventory();
|
||||
destinationInventory = ((InventoryHolder) state).getInventory();
|
||||
}
|
||||
|
||||
BoostData boostData = instance.getBoostManager().getBoost(hopper.getPlacedBy());
|
||||
@ -170,7 +170,7 @@ public class HopHandler {
|
||||
hopper.getFilter().setEndPoint(null);
|
||||
return;
|
||||
}
|
||||
Inventory destinationInventory = ((InventoryHolder)state).getInventory();
|
||||
Inventory destinationInventory = ((InventoryHolder) state).getInventory();
|
||||
|
||||
addItem(hopperState, hopper, destinationInventory, destinationBlock, item, amt, place);
|
||||
} catch (Exception e) {
|
||||
|
@ -8,9 +8,7 @@ import com.songoda.epichoppers.utils.Debugger;
|
||||
import com.songoda.epichoppers.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
@ -71,7 +69,7 @@ public class TeleportHandler {
|
||||
|
||||
EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance();
|
||||
Hopper lastHopper = hopper;
|
||||
for (int i = 0; i < 15; i ++) {
|
||||
for (int i = 0; i < 15; i++) {
|
||||
boolean empty = lastHopper.getLinkedBlocks().isEmpty();
|
||||
if (empty && i == 0) {
|
||||
if (teleportFrom.containsKey(hopper.getLocation()))
|
||||
@ -101,6 +99,6 @@ public class TeleportHandler {
|
||||
player.teleport(location);
|
||||
|
||||
if (instance.getConfig().getBoolean("Main.Sounds Enabled"))
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 10,10);
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 10, 10);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package com.songoda.epichoppers.hopper;
|
||||
|
||||
import com.songoda.epichoppers.api.hopper.Filter;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -1,12 +1,12 @@
|
||||
package com.songoda.epichoppers.hopper;
|
||||
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.api.CostType;
|
||||
import com.songoda.epichoppers.api.hopper.Filter;
|
||||
import com.songoda.epichoppers.api.hopper.Hopper;
|
||||
import com.songoda.epichoppers.api.hopper.TeleportTrigger;
|
||||
import com.songoda.epichoppers.api.hopper.levels.Level;
|
||||
import com.songoda.epichoppers.boost.BoostData;
|
||||
import com.songoda.epichoppers.player.MenuType;
|
||||
import com.songoda.epichoppers.gui.GUIHoppperOverview;
|
||||
import com.songoda.epichoppers.player.PlayerData;
|
||||
import com.songoda.epichoppers.utils.Debugger;
|
||||
import com.songoda.epichoppers.utils.Methods;
|
||||
@ -14,12 +14,11 @@ import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/14/2017.
|
||||
@ -60,428 +59,28 @@ public class EHopper implements Hopper {
|
||||
|
||||
public void overview(Player player) {
|
||||
try {
|
||||
EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance();
|
||||
if (!player.hasPermission("epichoppers.overview")) return;
|
||||
|
||||
if (lastPlayer != null && lastPlayer != player.getUniqueId()) {
|
||||
Bukkit.getPlayer(lastPlayer).closeInventory();
|
||||
}
|
||||
|
||||
if (placedBy == null) placedBy = player.getUniqueId();
|
||||
|
||||
instance.getPlayerDataManager().getPlayerData(player).setLastHopper(this);
|
||||
|
||||
Level nextLevel = instance.getLevelManager().getHighestLevel().getLevel() > level.getLevel() ? instance.getLevelManager().getLevel(level.getLevel() + 1) : null;
|
||||
|
||||
Inventory i = Bukkit.createInventory(null, 27, Methods.formatName(level.getLevel(), false));
|
||||
|
||||
ItemStack perl = new ItemStack(Material.ENDER_PEARL, 1);
|
||||
ItemMeta perlmeta = perl.getItemMeta();
|
||||
perlmeta.setDisplayName(instance.getLocale().getMessage("interface.hopper.perltitle"));
|
||||
ArrayList<String> loreperl = new ArrayList<>();
|
||||
String[] parts = instance.getLocale().getMessage("interface.hopper.perllore2", teleportTrigger == TeleportTrigger.DISABLED ? instance.getLocale().getMessage("general.word.disabled") : teleportTrigger.name()).split("\\|");
|
||||
for (String line : parts) {
|
||||
loreperl.add(Methods.formatText(line));
|
||||
}
|
||||
perlmeta.setLore(loreperl);
|
||||
perl.setItemMeta(perlmeta);
|
||||
|
||||
ItemStack filter = new ItemStack(Material.COMPARATOR, 1);
|
||||
ItemMeta filtermeta = filter.getItemMeta();
|
||||
filtermeta.setDisplayName(instance.getLocale().getMessage("interface.hopper.filtertitle"));
|
||||
ArrayList<String> lorefilter = new ArrayList<>();
|
||||
parts = instance.getLocale().getMessage("interface.hopper.filterlore").split("\\|");
|
||||
for (String line : parts) {
|
||||
lorefilter.add(Methods.formatText(line));
|
||||
}
|
||||
filtermeta.setLore(lorefilter);
|
||||
filter.setItemMeta(filtermeta);
|
||||
|
||||
ItemStack crafting = new ItemStack(Material.CRAFTING_TABLE, 1);
|
||||
ItemMeta craftingmeta = crafting.getItemMeta();
|
||||
craftingmeta.setDisplayName(instance.getLocale().getMessage("interface.hopper.craftingtitle"));
|
||||
ArrayList<String> lorecrafting = new ArrayList<>();
|
||||
parts = instance.getLocale().getMessage("interface.hopper.craftinglore").split("\\|");
|
||||
for (String line : parts) {
|
||||
lorecrafting.add(Methods.formatText(line));
|
||||
}
|
||||
craftingmeta.setLore(lorecrafting);
|
||||
crafting.setItemMeta(craftingmeta);
|
||||
|
||||
ItemStack sell = new ItemStack(Material.SUNFLOWER, 1);
|
||||
ItemMeta sellmeta = sell.getItemMeta();
|
||||
sellmeta.setDisplayName(instance.getLocale().getMessage("interface.hopper.selltitle"));
|
||||
ArrayList<String> loresell = new ArrayList<>();
|
||||
parts = instance.getLocale().getMessage("interface.hopper.selllore", autoSellTimer == -9999 ? "\u221E" : Math.floor(autoSellTimer / 20)).split("\\|");
|
||||
for (String line : parts) {
|
||||
loresell.add(Methods.formatText(line));
|
||||
}
|
||||
sellmeta.setLore(loresell);
|
||||
sell.setItemMeta(sellmeta);
|
||||
|
||||
|
||||
ItemStack item = new ItemStack(Material.HOPPER, 1);
|
||||
ItemMeta itemmeta = item.getItemMeta();
|
||||
itemmeta.setDisplayName(instance.getLocale().getMessage("interface.hopper.currentlevel", level.getLevel()));
|
||||
List<String> lore = this.level.getDescription();
|
||||
if (instance.getConfig().getBoolean("Main.Allow hopper Upgrading")) {
|
||||
lore.add("");
|
||||
if (nextLevel == null) lore.add(instance.getLocale().getMessage("interface.hopper.alreadymaxed"));
|
||||
else {
|
||||
lore.add(instance.getLocale().getMessage("interface.hopper.nextlevel", nextLevel.getLevel()));
|
||||
lore.addAll(nextLevel.getDescription());
|
||||
}
|
||||
}
|
||||
|
||||
BoostData boostData = instance.getBoostManager().getBoost(placedBy);
|
||||
if (boostData != null) {
|
||||
parts = instance.getLocale().getMessage("interface.hopper.boostedstats", Integer.toString(boostData.getMultiplier()), Methods.makeReadable(boostData.getEndTime() - System.currentTimeMillis())).split("\\|");
|
||||
lore.add("");
|
||||
for (String line : parts)
|
||||
lore.add(Methods.formatText(line));
|
||||
}
|
||||
|
||||
itemmeta.setLore(lore);
|
||||
item.setItemMeta(itemmeta);
|
||||
|
||||
ItemStack hook = new ItemStack(Material.TRIPWIRE_HOOK, 1);
|
||||
ItemMeta hookmeta = hook.getItemMeta();
|
||||
hookmeta.setDisplayName(instance.getLocale().getMessage("interface.hopper.synchopper"));
|
||||
ArrayList<String> lorehook = new ArrayList<>();
|
||||
parts = instance.getLocale().getMessage("interface.hopper.synclore").split("\\|");
|
||||
for (String line : parts) {
|
||||
lorehook.add(Methods.formatText(line));
|
||||
}
|
||||
hookmeta.setLore(lorehook);
|
||||
hook.setItemMeta(hookmeta);
|
||||
|
||||
ItemStack itemXP = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.XP Icon")), 1);
|
||||
ItemMeta itemmetaXP = itemXP.getItemMeta();
|
||||
itemmetaXP.setDisplayName(instance.getLocale().getMessage("interface.hopper.upgradewithxp"));
|
||||
ArrayList<String> loreXP = new ArrayList<>();
|
||||
if (nextLevel != null)
|
||||
loreXP.add(instance.getLocale().getMessage("interface.hopper.upgradewithxplore", nextLevel.getCostExperience()));
|
||||
else
|
||||
loreXP.add(instance.getLocale().getMessage("interface.hopper.alreadymaxed"));
|
||||
itemmetaXP.setLore(loreXP);
|
||||
itemXP.setItemMeta(itemmetaXP);
|
||||
|
||||
ItemStack itemECO = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.Economy Icon")), 1);
|
||||
ItemMeta itemmetaECO = itemECO.getItemMeta();
|
||||
itemmetaECO.setDisplayName(instance.getLocale().getMessage("interface.hopper.upgradewitheconomy"));
|
||||
ArrayList<String> loreECO = new ArrayList<>();
|
||||
if (nextLevel != null)
|
||||
loreECO.add(instance.getLocale().getMessage("interface.hopper.upgradewitheconomylore", Methods.formatEconomy(nextLevel.getCostEconomy())));
|
||||
else
|
||||
loreECO.add(instance.getLocale().getMessage("interface.hopper.alreadymaxed"));
|
||||
itemmetaECO.setLore(loreECO);
|
||||
itemECO.setItemMeta(itemmetaECO);
|
||||
|
||||
int nu = 0;
|
||||
while (nu != 27) {
|
||||
i.setItem(nu, Methods.getGlass());
|
||||
nu++;
|
||||
}
|
||||
|
||||
Map<Integer, Integer[]> layouts = new HashMap<>();
|
||||
layouts.put(1, new Integer[]{22});
|
||||
layouts.put(2, new Integer[]{22, 4});
|
||||
layouts.put(3, new Integer[]{22, 3, 5});
|
||||
layouts.put(4, new Integer[]{23, 3, 5, 21});
|
||||
layouts.put(5, new Integer[]{23, 3, 5, 21, 22});
|
||||
|
||||
int amount = 1;
|
||||
|
||||
boolean canFilter = level.isFilter() || player.hasPermission("EpicHoppers.Filter");
|
||||
boolean canTeleport = level.isTeleport() || player.hasPermission("EpicHoppers.Teleport");
|
||||
boolean canCraft = level.getRegisteredModules().removeIf(e -> e.getName().equals("AutoCrafting"));
|
||||
boolean canAutoSell = level.getAutoSell() != 0;
|
||||
if (canFilter) amount ++;
|
||||
if (canTeleport) amount ++;
|
||||
if (canAutoSell) amount ++;
|
||||
if (canCraft) amount ++;
|
||||
|
||||
Integer[] layout = layouts.get(amount);
|
||||
|
||||
for (int ii = 0; ii < amount; ii ++) {
|
||||
int slot = layout[ii];
|
||||
|
||||
if (ii == 0) {
|
||||
i.setItem(slot, hook);
|
||||
} else if (canTeleport) {
|
||||
i.setItem(slot, perl);
|
||||
canTeleport = false;
|
||||
} else if (canFilter) {
|
||||
i.setItem(slot, filter);
|
||||
canFilter = false;
|
||||
} else if (canCraft) {
|
||||
i.setItem(slot, crafting);
|
||||
canCraft = false;
|
||||
} else if (canAutoSell) {
|
||||
i.setItem(slot, sell);
|
||||
canAutoSell = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (instance.getConfig().getBoolean("Main.Upgrade With XP") && player.hasPermission("EpicHoppers.Upgrade.XP") && level.getCostExperience() != -1) {
|
||||
i.setItem(11, itemXP);
|
||||
}
|
||||
|
||||
i.setItem(13, item);
|
||||
|
||||
if (instance.getConfig().getBoolean("Main.Upgrade With Economy") && player.hasPermission("EpicHoppers.Upgrade.ECO") && level.getCostEconomy() != -1) {
|
||||
i.setItem(15, itemECO);
|
||||
}
|
||||
|
||||
i.setItem(0, Methods.getBackgroundGlass(true));
|
||||
i.setItem(1, Methods.getBackgroundGlass(true));
|
||||
i.setItem(2, Methods.getBackgroundGlass(false));
|
||||
i.setItem(6, Methods.getBackgroundGlass(false));
|
||||
i.setItem(7, Methods.getBackgroundGlass(true));
|
||||
i.setItem(8, Methods.getBackgroundGlass(true));
|
||||
i.setItem(9, Methods.getBackgroundGlass(true));
|
||||
i.setItem(10, Methods.getBackgroundGlass(false));
|
||||
i.setItem(16, Methods.getBackgroundGlass(false));
|
||||
i.setItem(17, Methods.getBackgroundGlass(true));
|
||||
i.setItem(18, Methods.getBackgroundGlass(true));
|
||||
i.setItem(19, Methods.getBackgroundGlass(true));
|
||||
i.setItem(20, Methods.getBackgroundGlass(false));
|
||||
i.setItem(24, Methods.getBackgroundGlass(false));
|
||||
i.setItem(25, Methods.getBackgroundGlass(true));
|
||||
i.setItem(26, Methods.getBackgroundGlass(true));
|
||||
|
||||
player.openInventory(i);
|
||||
instance.getPlayerDataManager().getPlayerData(player).setInMenu(MenuType.OVERVIEW);
|
||||
lastPlayer = player.getUniqueId();
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void crafting(Player player) {
|
||||
try {
|
||||
EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance();
|
||||
instance.getPlayerDataManager().getPlayerData(player).setLastHopper(this);
|
||||
|
||||
Inventory i = Bukkit.createInventory(null, 27, Methods.formatText(Methods.formatName(level.getLevel(), false) + " &8-&f Crafting"));
|
||||
|
||||
int nu = 0;
|
||||
while (nu != 27) {
|
||||
i.setItem(nu, Methods.getGlass());
|
||||
nu++;
|
||||
}
|
||||
|
||||
i.setItem(0, Methods.getBackgroundGlass(true));
|
||||
i.setItem(1, Methods.getBackgroundGlass(true));
|
||||
i.setItem(2, Methods.getBackgroundGlass(false));
|
||||
i.setItem(6, Methods.getBackgroundGlass(false));
|
||||
i.setItem(7, Methods.getBackgroundGlass(true));
|
||||
i.setItem(8, Methods.getBackgroundGlass(true));
|
||||
i.setItem(9, Methods.getBackgroundGlass(true));
|
||||
i.setItem(10, Methods.getBackgroundGlass(false));
|
||||
i.setItem(16, Methods.getBackgroundGlass(false));
|
||||
i.setItem(17, Methods.getBackgroundGlass(true));
|
||||
i.setItem(18, Methods.getBackgroundGlass(true));
|
||||
i.setItem(19, Methods.getBackgroundGlass(true));
|
||||
i.setItem(20, Methods.getBackgroundGlass(false));
|
||||
i.setItem(24, Methods.getBackgroundGlass(false));
|
||||
i.setItem(25, Methods.getBackgroundGlass(true));
|
||||
i.setItem(26, Methods.getBackgroundGlass(true));
|
||||
|
||||
i.setItem(13, new ItemStack(autoCrafting == null ? Material.AIR : autoCrafting));
|
||||
|
||||
player.openInventory(i);
|
||||
instance.getPlayerDataManager().getPlayerData(player).setInMenu(MenuType.CRAFTING);
|
||||
lastPlayer = player.getUniqueId();
|
||||
if (!player.hasPermission("epichoppers.overview")) return;
|
||||
new GUIHoppperOverview(instance, this, player);
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void filter(Player player) {
|
||||
try {
|
||||
EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance();
|
||||
|
||||
Inventory i = Bukkit.createInventory(null, 54, Methods.formatText(Methods.formatName(level.getLevel(), false) + " &8-&f Filter"));
|
||||
|
||||
i.setItem(2, Methods.getBackgroundGlass(true));
|
||||
i.setItem(3, Methods.getBackgroundGlass(true));
|
||||
i.setItem(4, Methods.getBackgroundGlass(true));
|
||||
i.setItem(5, Methods.getBackgroundGlass(false));
|
||||
i.setItem(6, Methods.getBackgroundGlass(false));
|
||||
|
||||
i.setItem(11, Methods.getBackgroundGlass(true));
|
||||
i.setItem(15, Methods.getBackgroundGlass(false));
|
||||
|
||||
i.setItem(20, Methods.getBackgroundGlass(true));
|
||||
i.setItem(24, Methods.getBackgroundGlass(true));
|
||||
|
||||
i.setItem(29, Methods.getBackgroundGlass(true));
|
||||
i.setItem(33, Methods.getBackgroundGlass(true));
|
||||
|
||||
i.setItem(38, Methods.getBackgroundGlass(false));
|
||||
i.setItem(42, Methods.getBackgroundGlass(true));
|
||||
|
||||
i.setItem(47, Methods.getBackgroundGlass(false));
|
||||
i.setItem(48, Methods.getBackgroundGlass(false));
|
||||
i.setItem(49, Methods.getBackgroundGlass(true));
|
||||
i.setItem(50, Methods.getBackgroundGlass(true));
|
||||
i.setItem(51, Methods.getBackgroundGlass(true));
|
||||
|
||||
i.setItem(12, Methods.getGlass());
|
||||
i.setItem(14, Methods.getGlass());
|
||||
i.setItem(21, Methods.getGlass());
|
||||
i.setItem(22, Methods.getGlass());
|
||||
i.setItem(23, Methods.getGlass());
|
||||
i.setItem(30, Methods.getGlass());
|
||||
i.setItem(31, Methods.getGlass());
|
||||
i.setItem(32, Methods.getGlass());
|
||||
i.setItem(39, Methods.getGlass());
|
||||
i.setItem(41, Methods.getGlass());
|
||||
|
||||
ItemStack it = new ItemStack(Material.WHITE_STAINED_GLASS_PANE, 1);
|
||||
ItemMeta itm = it.getItemMeta();
|
||||
itm.setDisplayName(instance.getLocale().getMessage("interface.filter.whitelist"));
|
||||
it.setItemMeta(itm);
|
||||
int[] whiteSlots = {0, 1, 9, 10, 18, 19};
|
||||
for (int nu : whiteSlots) {
|
||||
i.setItem(nu, it);
|
||||
}
|
||||
|
||||
int num = 0;
|
||||
for (ItemStack m : filter.getWhiteList()) {
|
||||
if (m != null) {
|
||||
i.setItem(whiteSlots[num], new ItemStack(m));
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
it = new ItemStack(Material.BLACK_STAINED_GLASS_PANE, 1);
|
||||
itm = it.getItemMeta();
|
||||
itm.setDisplayName(instance.getLocale().getMessage("interface.filter.blacklist"));
|
||||
it.setItemMeta(itm);
|
||||
int[] blackSlots = {27, 28, 36, 37, 45, 46};
|
||||
for (int nu : blackSlots) {
|
||||
i.setItem(nu, it);
|
||||
}
|
||||
|
||||
num = 0;
|
||||
for (ItemStack m : filter.getBlackList()) {
|
||||
if (m != null) {
|
||||
i.setItem(blackSlots[num], new ItemStack(m));
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
it = new ItemStack(Material.BARRIER);
|
||||
itm = it.getItemMeta();
|
||||
itm.setDisplayName(instance.getLocale().getMessage("interface.filter.void"));
|
||||
it.setItemMeta(itm);
|
||||
int[] avoid = {7, 8, 16, 17, 25, 26, 34, 35, 43, 44, 52, 53};
|
||||
for (int nu : avoid) {
|
||||
i.setItem(nu, it);
|
||||
}
|
||||
|
||||
num = 0;
|
||||
for (ItemStack m : filter.getVoidList()) {
|
||||
if (m != null) {
|
||||
i.setItem(avoid[num], new ItemStack(m));
|
||||
num++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ItemStack itemInfo = new ItemStack(Material.PAPER, 1);
|
||||
ItemMeta itemmetaInfo = itemInfo.getItemMeta();
|
||||
itemmetaInfo.setDisplayName(instance.getLocale().getMessage("interface.filter.infotitle"));
|
||||
ArrayList<String> loreInfo = new ArrayList<>();
|
||||
String[] parts = instance.getLocale().getMessage("interface.filter.infolore").split("\\|");
|
||||
for (String line : parts) {
|
||||
loreInfo.add(Methods.formatText(line));
|
||||
}
|
||||
itemmetaInfo.setLore(loreInfo);
|
||||
itemInfo.setItemMeta(itemmetaInfo);
|
||||
|
||||
i.setItem(13, itemInfo);
|
||||
|
||||
|
||||
ItemStack hook = new ItemStack(Material.TRIPWIRE_HOOK, 1);
|
||||
ItemMeta hookmeta = hook.getItemMeta();
|
||||
hookmeta.setDisplayName(instance.getLocale().getMessage("interface.hopper.rejectsync"));
|
||||
ArrayList<String> lorehook = new ArrayList<>();
|
||||
parts = instance.getLocale().getMessage("interface.hopper.synclore").split("\\|");
|
||||
for (String line : parts) {
|
||||
lorehook.add(Methods.formatText(line));
|
||||
}
|
||||
hookmeta.setLore(lorehook);
|
||||
hook.setItemMeta(hookmeta);
|
||||
i.setItem(40, hook);
|
||||
|
||||
player.openInventory(i);
|
||||
instance.getPlayerDataManager().getPlayerData(player).setInMenu(MenuType.FILTER);
|
||||
lastPlayer = player.getUniqueId();
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void compile(Player p) {
|
||||
try {
|
||||
ItemStack[] items2 = p.getOpenInventory().getTopInventory().getContents();
|
||||
|
||||
List<ItemStack> owhite = new ArrayList<>();
|
||||
List<ItemStack> oblack = new ArrayList<>();
|
||||
List<ItemStack> ovoid = new ArrayList<>();
|
||||
|
||||
int[] awhite = {0, 1, 9, 10, 18, 19};
|
||||
int[] ablack = {27, 28, 36, 37, 45, 46};
|
||||
int[] avoid = {7, 8, 16, 17, 25, 26, 34, 35, 43, 44, 52, 53};
|
||||
|
||||
int num = 0;
|
||||
for (ItemStack item : items2) {
|
||||
for (int aa : awhite) {
|
||||
if (aa == num) {
|
||||
if (items2[num] != null && !items2[num].getType().name().contains("STAINED_GLASS") && items2[num].getType() != Material.AIR)
|
||||
owhite.add(items2[num]);
|
||||
}
|
||||
}
|
||||
for (int aa : ablack) {
|
||||
if (aa == num) {
|
||||
if (items2[num] != null && !items2[num].getType().name().contains("STAINED_GLASS") && items2[num].getType() != Material.AIR)
|
||||
oblack.add(items2[num]);
|
||||
}
|
||||
}
|
||||
for (int aa : avoid) {
|
||||
if (aa == num) {
|
||||
if (items2[num] != null && !items2[num].getType().equals(Material.BARRIER) && items2[num].getType() != Material.AIR)
|
||||
ovoid.add(items2[num]);
|
||||
}
|
||||
}
|
||||
num++;
|
||||
}
|
||||
filter.setWhiteList(owhite);
|
||||
filter.setBlackList(oblack);
|
||||
filter.setVoidList(ovoid);
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void upgrade(String type, Player player) {
|
||||
public void upgrade(Player player, CostType type) {
|
||||
try {
|
||||
EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance();
|
||||
if (instance.getLevelManager().getLevels().containsKey(this.level.getLevel() + 1)) {
|
||||
|
||||
Level level = instance.getLevelManager().getLevel(this.level.getLevel() + 1);
|
||||
int cost;
|
||||
if (type.equals("XP")) {
|
||||
cost = level.getCostExperience();
|
||||
} else {
|
||||
cost = level.getCostEconomy();
|
||||
}
|
||||
int cost = type == CostType.ECONOMY ? level.getCostEconomy() : level.getCostExperience();
|
||||
|
||||
if (type.equals("ECO")) {
|
||||
if (type == CostType.ECONOMY) {
|
||||
if (instance.getServer().getPluginManager().getPlugin("Vault") != null) {
|
||||
RegisteredServiceProvider<Economy> rsp = instance.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
net.milkbowl.vault.economy.Economy econ = rsp.getProvider();
|
||||
@ -494,7 +93,7 @@ public class EHopper implements Hopper {
|
||||
} else {
|
||||
player.sendMessage("Vault is not installed.");
|
||||
}
|
||||
} else if (type.equals("XP")) {
|
||||
} else if (type == CostType.EXPERIENCE) {
|
||||
if (player.getLevel() >= cost || player.getGameMode() == GameMode.CREATIVE) {
|
||||
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||
player.setLevel(player.getLevel() - cost);
|
||||
@ -589,8 +188,12 @@ public class EHopper implements Hopper {
|
||||
|
||||
if (!filtered)
|
||||
this.linkedBlocks.add(toLink.getLocation());
|
||||
else
|
||||
else {
|
||||
this.filter.setEndPoint(toLink.getLocation());
|
||||
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.hopper.syncsuccess"));
|
||||
instance.getPlayerDataManager().getPlayerData(player).setSyncType(null);
|
||||
return;
|
||||
}
|
||||
this.lastPlayer = player.getUniqueId();
|
||||
|
||||
if (level.getLinkAmount() > 1) {
|
||||
@ -602,6 +205,7 @@ public class EHopper implements Hopper {
|
||||
return;
|
||||
}
|
||||
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.hopper.syncsuccess"));
|
||||
instance.getPlayerDataManager().getPlayerData(player).setSyncType(null);
|
||||
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
@ -668,6 +272,11 @@ public class EHopper implements Hopper {
|
||||
return teleportTrigger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTeleportTrigger(TeleportTrigger teleportTrigger) {
|
||||
this.teleportTrigger = teleportTrigger;
|
||||
}
|
||||
|
||||
public int getAutoSellTimer() {
|
||||
return autoSellTimer;
|
||||
}
|
||||
@ -676,11 +285,6 @@ public class EHopper implements Hopper {
|
||||
this.autoSellTimer = autoSellTimer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTeleportTrigger(TeleportTrigger teleportTrigger) {
|
||||
this.teleportTrigger = teleportTrigger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Location> getLinkedBlocks() {
|
||||
return new ArrayList<>(linkedBlocks);
|
||||
|
@ -10,12 +10,9 @@ import java.util.List;
|
||||
public class ELevel implements Level {
|
||||
|
||||
private final ArrayList<Module> registeredModules;
|
||||
|
||||
private int level, costExperience, costEconomy, range, amount, linkAmount, autoSell;
|
||||
|
||||
private boolean filter, teleport;
|
||||
|
||||
private final List<String> description = new ArrayList<>();
|
||||
private int level, costExperience, costEconomy, range, amount, linkAmount, autoSell;
|
||||
private boolean filter, teleport;
|
||||
|
||||
ELevel(int level, int costExperience, int costEconomy, int range, int amount, boolean filter, boolean teleport, int linkAmount, int autoSell, ArrayList<Module> registeredModules) {
|
||||
this.level = level;
|
||||
@ -33,10 +30,10 @@ public class ELevel implements Level {
|
||||
|
||||
description.add(instance.getLocale().getMessage("interface.hopper.range", range));
|
||||
description.add(instance.getLocale().getMessage("interface.hopper.amount", amount));
|
||||
if (linkAmount != 1) description.add(instance.getLocale().getMessage("interface.hopper.linkamount", linkAmount));
|
||||
if (linkAmount != 1)
|
||||
description.add(instance.getLocale().getMessage("interface.hopper.linkamount", linkAmount));
|
||||
if (filter) description.add(instance.getLocale().getMessage("interface.hopper.filter", true));
|
||||
if (teleport) description.add(instance.getLocale().getMessage("interface.hopper.teleport", true));
|
||||
if (autoSell != 0) description.add(instance.getLocale().getMessage("interface.hopper.autosell", autoSell));
|
||||
|
||||
for (Module module : registeredModules) {
|
||||
description.add(module.getDescription());
|
||||
|
@ -4,7 +4,6 @@ import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.api.hopper.Hopper;
|
||||
import com.songoda.epichoppers.api.hopper.levels.modules.Module;
|
||||
import com.songoda.epichoppers.utils.Debugger;
|
||||
import jdk.nashorn.internal.ir.Block;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.*;
|
||||
@ -45,55 +44,55 @@ public class ModuleAutoCrafting implements Module {
|
||||
if (hopper.getAutoCrafting() != null && canMove(hopperBlock.getInventory(), new ItemStack(hopper.getAutoCrafting()))) {
|
||||
|
||||
Recipe recipe = cachedRecipes.get(hopper.getAutoCrafting());
|
||||
if (!(recipe instanceof ShapedRecipe) && !(recipe instanceof ShapelessRecipe)) return;
|
||||
List<ItemStack> ingredientMap = null;
|
||||
if (recipe instanceof ShapelessRecipe) ingredientMap = ((ShapelessRecipe) recipe).getIngredientList();
|
||||
if (recipe instanceof ShapedRecipe)
|
||||
ingredientMap = new ArrayList<>(((ShapedRecipe) recipe).getIngredientMap().values());
|
||||
if (hopperBlock.getInventory().getSize() == 0) return;
|
||||
if (!(recipe instanceof ShapedRecipe) && !(recipe instanceof ShapelessRecipe)) return;
|
||||
List<ItemStack> ingredientMap = null;
|
||||
if (recipe instanceof ShapelessRecipe) ingredientMap = ((ShapelessRecipe) recipe).getIngredientList();
|
||||
if (recipe instanceof ShapedRecipe)
|
||||
ingredientMap = new ArrayList<>(((ShapedRecipe) recipe).getIngredientMap().values());
|
||||
if (hopperBlock.getInventory().getSize() == 0) return;
|
||||
|
||||
Map<Material, Integer> items = new HashMap<>();
|
||||
for (ItemStack item : ingredientMap) {
|
||||
if (item == null) continue;
|
||||
if (!items.containsKey(item.getType())) {
|
||||
items.put(item.getType(), item.getAmount());
|
||||
} else {
|
||||
items.put(item.getType(), items.get(item.getType()) + 1);
|
||||
}
|
||||
Map<Material, Integer> items = new HashMap<>();
|
||||
for (ItemStack item : ingredientMap) {
|
||||
if (item == null) continue;
|
||||
if (!items.containsKey(item.getType())) {
|
||||
items.put(item.getType(), item.getAmount());
|
||||
} else {
|
||||
items.put(item.getType(), items.get(item.getType()) + 1);
|
||||
}
|
||||
|
||||
for (Material material : items.keySet()) {
|
||||
int amt = 0;
|
||||
ItemStack item = new ItemStack(material, items.get(material));
|
||||
for (ItemStack i : hopperBlock.getInventory().getContents()) {
|
||||
if (i == null) continue;
|
||||
if (i.getType() != material) continue;
|
||||
amt += i.getAmount();
|
||||
}
|
||||
|
||||
if (amt < item.getAmount()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
main2:
|
||||
for (Material material : items.keySet()) {
|
||||
int amtRemoved = 0;
|
||||
ItemStack toRemove = new ItemStack(material, items.get(material));
|
||||
for (ItemStack i : hopperBlock.getInventory().getContents()) {
|
||||
if (i == null || i.getType() != material) continue;
|
||||
if (toRemove.getAmount() - amtRemoved <= i.getAmount()) {
|
||||
toRemove.setAmount(toRemove.getAmount() - amtRemoved);
|
||||
hopperBlock.getInventory().removeItem(toRemove);
|
||||
continue main2;
|
||||
} else {
|
||||
amtRemoved += i.getAmount();
|
||||
hopperBlock.getInventory().removeItem(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
hopperBlock.getInventory().addItem(recipe.getResult());
|
||||
}
|
||||
|
||||
for (Material material : items.keySet()) {
|
||||
int amt = 0;
|
||||
ItemStack item = new ItemStack(material, items.get(material));
|
||||
for (ItemStack i : hopperBlock.getInventory().getContents()) {
|
||||
if (i == null) continue;
|
||||
if (i.getType() != material) continue;
|
||||
amt += i.getAmount();
|
||||
}
|
||||
|
||||
if (amt < item.getAmount()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
main2:
|
||||
for (Material material : items.keySet()) {
|
||||
int amtRemoved = 0;
|
||||
ItemStack toRemove = new ItemStack(material, items.get(material));
|
||||
for (ItemStack i : hopperBlock.getInventory().getContents()) {
|
||||
if (i == null || i.getType() != material) continue;
|
||||
if (toRemove.getAmount() - amtRemoved <= i.getAmount()) {
|
||||
toRemove.setAmount(toRemove.getAmount() - amtRemoved);
|
||||
hopperBlock.getInventory().removeItem(toRemove);
|
||||
continue main2;
|
||||
} else {
|
||||
amtRemoved += i.getAmount();
|
||||
hopperBlock.getInventory().removeItem(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
hopperBlock.getInventory().addItem(recipe.getResult());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<Material> getBlockedItems(Hopper hopper) {
|
||||
|
@ -1,20 +1,16 @@
|
||||
package com.songoda.epichoppers.hopper.levels.modules;
|
||||
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.api.EpicHoppers;
|
||||
import com.songoda.epichoppers.api.hopper.Hopper;
|
||||
import com.songoda.epichoppers.api.hopper.levels.modules.Module;
|
||||
import com.songoda.epichoppers.hopper.EHopper;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ModuleAutoSell implements Module {
|
||||
|
||||
@ -24,7 +20,7 @@ public class ModuleAutoSell implements Module {
|
||||
public ModuleAutoSell(int timeOut) {
|
||||
EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance();
|
||||
this.timeOut = timeOut * 20;
|
||||
this.hopperTickRate = (int)instance.getConfig().getLong("Main.Amount of Ticks Between Hops");
|
||||
this.hopperTickRate = (int) instance.getConfig().getLong("Main.Amount of Ticks Between Hops");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -37,16 +33,16 @@ public class ModuleAutoSell implements Module {
|
||||
org.bukkit.block.Hopper hopperBlock = hopper.getHopper();
|
||||
if (hopperBlock == null || hopperBlock.getInventory() == null) return;
|
||||
|
||||
if (((EHopper)hopper).getAutoSellTimer() == -9999) return;
|
||||
if (((EHopper) hopper).getAutoSellTimer() == -9999) return;
|
||||
|
||||
if (((EHopper)hopper).getAutoSellTimer() <= 0) {
|
||||
if (((EHopper) hopper).getAutoSellTimer() <= 0) {
|
||||
EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance();
|
||||
|
||||
if (instance.getServer().getPluginManager().getPlugin("Vault") == null) return;
|
||||
RegisteredServiceProvider<Economy> rsp = instance.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
net.milkbowl.vault.economy.Economy econ = rsp.getProvider();
|
||||
|
||||
List<String> list = (List<String>)EpicHoppersPlugin.getInstance().getConfig().getList("Main.AutoSell Prices");
|
||||
List<String> list = (List<String>) EpicHoppersPlugin.getInstance().getConfig().getList("Main.AutoSell Prices");
|
||||
|
||||
for (String line : list) {
|
||||
try {
|
||||
@ -61,11 +57,12 @@ public class ModuleAutoSell implements Module {
|
||||
hopperBlock.getInventory().removeItem(itemStack);
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
((EHopper)hopper).setAutoSellTimer(timeOut);
|
||||
((EHopper) hopper).setAutoSellTimer(timeOut);
|
||||
}
|
||||
((EHopper)hopper).setAutoSellTimer(((EHopper)hopper).getAutoSellTimer() - hopperTickRate);
|
||||
((EHopper) hopper).setAutoSellTimer(((EHopper) hopper).getAutoSellTimer() - hopperTickRate);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -75,6 +72,6 @@ public class ModuleAutoSell implements Module {
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return EpicHoppersPlugin.getInstance().getLocale().getMessage("interface.hopper.autosell", timeOut);
|
||||
return EpicHoppersPlugin.getInstance().getLocale().getMessage("interface.hopper.autosell", (int) Math.floor(timeOut / 20));
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,8 @@ import java.util.Map;
|
||||
|
||||
public class ModuleBlockBreak implements Module {
|
||||
|
||||
private Map<Block, Integer> blockTick = new HashMap<>();
|
||||
|
||||
private final int amount;
|
||||
private Map<Block, Integer> blockTick = new HashMap<>();
|
||||
|
||||
public ModuleBlockBreak(int amount) {
|
||||
this.amount = amount;
|
||||
@ -42,16 +41,16 @@ public class ModuleBlockBreak implements Module {
|
||||
if (tick < amount) return;
|
||||
Block above = block.getRelative(0, 1, 0);
|
||||
if (above.getType() == Material.WATER || above.getType() == Material.LAVA) return;
|
||||
|
||||
|
||||
if (above.getType() != Material.AIR && above.getType() != Material.HOPPER && !EpicHoppersPlugin.getInstance().getConfig().getStringList("Main.BlockBreak Blacklisted Blocks").contains(above.getType().name())) {
|
||||
above.getWorld().playSound(above.getLocation(), Sound.BLOCK_STONE_BREAK, 1F, 1F);
|
||||
Location locationAbove = above.getLocation();
|
||||
locationAbove.add(.5, .5, .5);
|
||||
|
||||
float xx = (float) (0 + (Math.random() * .5));
|
||||
float yy = (float) (0 + (Math.random() * .5));
|
||||
float zz = (float) (0 + (Math.random() * .5));
|
||||
above.getWorld().spawnParticle(Particle.valueOf(EpicHoppersPlugin.getInstance().getConfig().getString("Main.BlockBreak Particle Type")), locationAbove, 15, xx, yy, zz);
|
||||
float xx = (float) (0 + (Math.random() * .5));
|
||||
float yy = (float) (0 + (Math.random() * .5));
|
||||
float zz = (float) (0 + (Math.random() * .5));
|
||||
above.getWorld().spawnParticle(Particle.valueOf(EpicHoppersPlugin.getInstance().getConfig().getString("Main.BlockBreak Particle Type")), locationAbove, 15, xx, yy, zz);
|
||||
|
||||
above.breakNaturally();
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import com.songoda.epichoppers.api.hopper.levels.modules.Module;
|
||||
import com.songoda.epichoppers.utils.Debugger;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -20,11 +19,11 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class ModuleSuction implements Module {
|
||||
|
||||
|
||||
private final int amount;
|
||||
|
||||
private boolean wildStacker = Bukkit.getPluginManager().isPluginEnabled("WildStacker");
|
||||
|
||||
|
||||
public ModuleSuction(int amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
@ -59,7 +58,7 @@ public class ModuleSuction implements Module {
|
||||
continue;
|
||||
|
||||
if (wildStacker)
|
||||
hopItem.setAmount(WildStackerAPI.getItemAmount((Item)entity));
|
||||
hopItem.setAmount(WildStackerAPI.getItemAmount((Item) entity));
|
||||
|
||||
ItemStack item = ((Item) entity).getItemStack();
|
||||
if (item == null) continue;
|
||||
@ -68,10 +67,10 @@ public class ModuleSuction implements Module {
|
||||
}
|
||||
((Item) entity).setPickupDelay(10);
|
||||
entity.setMetadata("grabbed", new FixedMetadataValue(EpicHoppersPlugin.getInstance(), ""));
|
||||
float xx = (float) (0 + (Math.random() * .1));
|
||||
float yy = (float) (0 + (Math.random() * .1));
|
||||
float zz = (float) (0 + (Math.random() * .1));
|
||||
entity.getLocation().getWorld().spawnParticle(Particle.FLAME, entity.getLocation(), 5, xx, yy, zz, 0);
|
||||
float xx = (float) (0 + (Math.random() * .1));
|
||||
float yy = (float) (0 + (Math.random() * .1));
|
||||
float zz = (float) (0 + (Math.random() * .1));
|
||||
entity.getLocation().getWorld().spawnParticle(Particle.FLAME, entity.getLocation(), 5, xx, yy, zz, 0);
|
||||
|
||||
for (ItemStack itemStack : hopperBlock.getInventory().addItem(hopItem).values()) {
|
||||
entity.getWorld().dropItemNaturally(entity.getLocation(), itemStack);
|
||||
|
@ -124,7 +124,7 @@ public class BlockListeners implements Listener {
|
||||
|
||||
for (ItemStack m : hopper.getFilter().getWhiteList()) {
|
||||
if (m != null)
|
||||
event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(),m);
|
||||
event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(), m);
|
||||
}
|
||||
|
||||
for (ItemStack m : hopper.getFilter().getBlackList()) {
|
||||
@ -133,7 +133,7 @@ public class BlockListeners implements Listener {
|
||||
}
|
||||
for (ItemStack m : hopper.getFilter().getVoidList()) {
|
||||
if (m != null)
|
||||
event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(),m);
|
||||
event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(), m);
|
||||
}
|
||||
instance.getHopperManager().removeHopper(block.getLocation());
|
||||
|
||||
|
@ -3,7 +3,6 @@ package com.songoda.epichoppers.listeners;
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.api.hopper.Hopper;
|
||||
import com.songoda.epichoppers.utils.Debugger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
@ -72,7 +72,7 @@ public class InteractListeners implements Listener {
|
||||
int z = location.getBlockZ() >> 4;
|
||||
|
||||
if (location.getWorld().getChunkAt(x, z) == to) {
|
||||
((EHopper)hopper).reloadHopper();
|
||||
((EHopper) hopper).reloadHopper();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -121,8 +121,6 @@ public class InteractListeners implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.getClickedBlock().getType() == Material.BREWING_STAND) return;
|
||||
|
||||
if (e.getClickedBlock().getState() instanceof InventoryHolder || e.getClickedBlock().getType().equals(Material.ENDER_CHEST) && instance.getConfig().getBoolean("Main.Support Enderchests")) {
|
||||
Hopper hopper = playerData.getLastHopper();
|
||||
if (playerData.getSyncType() != null && e.getClickedBlock().getLocation().equals(playerData.getLastHopper().getLocation())) {
|
||||
|
@ -1,21 +1,14 @@
|
||||
package com.songoda.epichoppers.listeners;
|
||||
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.api.hopper.Hopper;
|
||||
import com.songoda.epichoppers.api.hopper.TeleportTrigger;
|
||||
import com.songoda.epichoppers.hopper.EHopper;
|
||||
import com.songoda.epichoppers.player.MenuType;
|
||||
import com.songoda.epichoppers.player.PlayerData;
|
||||
import com.songoda.epichoppers.player.SyncType;
|
||||
import com.songoda.epichoppers.utils.Debugger;
|
||||
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.*;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -55,8 +48,6 @@ public class InventoryListeners implements Listener {
|
||||
|
||||
if (!event.getCurrentItem().hasItemMeta()) return;
|
||||
|
||||
if (doFilter(event)) return;
|
||||
|
||||
if (event.getSlot() != 64537
|
||||
&& event.getInventory().getType() == InventoryType.ANVIL
|
||||
&& event.getAction() != InventoryAction.NOTHING
|
||||
@ -66,183 +57,8 @@ public class InventoryListeners implements Listener {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
PlayerData playerData = instance.getPlayerDataManager().getPlayerData(player);
|
||||
|
||||
if (playerData.getInMenu() == MenuType.CRAFTING) {
|
||||
if (event.getSlot() == 13) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (playerData.getInMenu() != MenuType.OVERVIEW) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
Hopper hopper = playerData.getLastHopper();
|
||||
if (event.getCurrentItem().getItemMeta().hasDisplayName()
|
||||
&& event.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("interface.hopper.perltitle"))
|
||||
&& (hopper.getLevel().isTeleport() || player.hasPermission("EpicHoppers.Teleport"))) {
|
||||
if (event.isLeftClick()) {
|
||||
if (hopper.getLinkedBlocks() != null) {
|
||||
instance.getTeleportHandler().tpPlayer(player, hopper);
|
||||
}
|
||||
} else {
|
||||
if (hopper.getTeleportTrigger() == TeleportTrigger.DISABLED) {
|
||||
hopper.setTeleportTrigger(TeleportTrigger.SNEAK);
|
||||
} else if (hopper.getTeleportTrigger() == TeleportTrigger.SNEAK) {
|
||||
hopper.setTeleportTrigger(TeleportTrigger.WALK_ON);
|
||||
} else if (hopper.getTeleportTrigger() == TeleportTrigger.WALK_ON) {
|
||||
hopper.setTeleportTrigger(TeleportTrigger.DISABLED);
|
||||
}
|
||||
((EHopper) hopper).overview(player);
|
||||
return;
|
||||
}
|
||||
player.closeInventory();
|
||||
} else if (event.getCurrentItem().getItemMeta().hasDisplayName() && event.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("interface.hopper.filtertitle")) && (hopper.getLevel().isFilter() || player.hasPermission("EpicHoppers.Filter"))) {
|
||||
if (!event.getCurrentItem().getItemMeta().getDisplayName().equals("§l")) {
|
||||
((EHopper) hopper).filter(player);
|
||||
}
|
||||
} else if (event.getSlot() == 11 && player.hasPermission("EpicHoppers.Upgrade.XP") && hopper.getLevel().getCostExperience() != -1) {
|
||||
if (!event.getCurrentItem().getItemMeta().getDisplayName().equals("§l")) {
|
||||
((EHopper) hopper).upgrade("XP", player);
|
||||
player.closeInventory();
|
||||
}
|
||||
} else if (event.getSlot() == 15 && player.hasPermission("EpicHoppers.Upgrade.ECO") && hopper.getLevel().getCostEconomy() != -1) {
|
||||
if (!event.getCurrentItem().getItemMeta().getDisplayName().equals("§l")) {
|
||||
((EHopper) hopper).upgrade("ECO", player);
|
||||
player.closeInventory();
|
||||
}
|
||||
} else if (event.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("interface.hopper.craftingtitle"))) {
|
||||
((EHopper) hopper).crafting(player);
|
||||
} else if (event.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("interface.hopper.selltitle"))) {
|
||||
if (((EHopper)hopper).getAutoSellTimer() == -9999) {
|
||||
((EHopper)hopper).setAutoSellTimer(0);
|
||||
} else {
|
||||
((EHopper)hopper).setAutoSellTimer(-9999);
|
||||
}
|
||||
((EHopper) hopper).overview(player);
|
||||
} else if (event.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("interface.hopper.synchopper"))) {
|
||||
if (event.isRightClick()) {
|
||||
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.hopper.desync"));
|
||||
hopper.clearLinkedBlocks();
|
||||
} else {
|
||||
boolean can = true;
|
||||
if (hopper.getLastPlayer() != null) {
|
||||
if (!hopper.getLastPlayer().equals(player.getUniqueId())) {
|
||||
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.hopper.syncdidnotplace"));
|
||||
can = false;
|
||||
}
|
||||
}
|
||||
if (can) {
|
||||
playerData.setSyncType(SyncType.REGULAR);
|
||||
hopper.clearLinkedBlocks();
|
||||
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.hopper.syncnext"));
|
||||
((EHopper) hopper).timeout(player);
|
||||
}
|
||||
}
|
||||
player.closeInventory();
|
||||
}
|
||||
} catch (Exception ee) {
|
||||
Debugger.runReport(ee);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean doFilter(InventoryClickEvent e) {
|
||||
Player player = (Player) e.getWhoClicked();
|
||||
PlayerData playerData = instance.getPlayerDataManager().getPlayerData(player);
|
||||
if (playerData.getInMenu() != MenuType.FILTER
|
||||
|| e.getInventory() == null
|
||||
|| !e.getInventory().equals(player.getOpenInventory().getTopInventory())) {
|
||||
return false;
|
||||
}
|
||||
if (e.getClick().equals(ClickType.SHIFT_LEFT)) {
|
||||
e.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
Hopper hopper = playerData.getLastHopper();
|
||||
if (e.getSlot() == 40) {
|
||||
playerData.setSyncType(SyncType.FILTERED);
|
||||
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.hopper.syncnext"));
|
||||
((EHopper) hopper).timeout(player);
|
||||
player.closeInventory();
|
||||
return true;
|
||||
}
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> ((EHopper) hopper).compile(player), 1);
|
||||
|
||||
int[] a = {0, 1, 9, 10, 18, 19, 27, 28, 36, 37, 45, 46, 7, 8, 16, 17, 25, 26, 34, 35, 43, 44, 52, 53};
|
||||
e.setCancelled(true);
|
||||
for (int aa : a) {
|
||||
if (aa != e.getSlot()) continue;
|
||||
String name = "";
|
||||
if (e.getCurrentItem().hasItemMeta() && e.getCurrentItem().getItemMeta().hasDisplayName())
|
||||
name = e.getCurrentItem().getItemMeta().getDisplayName();
|
||||
|
||||
if (!ChatColor.stripColor(name).equals(ChatColor.stripColor(instance.getLocale().getMessage("interface.filter.whitelist"))) &&
|
||||
!name.equals(instance.getLocale().getMessage("interface.filter.blacklist")) &&
|
||||
!name.equals(instance.getLocale().getMessage("interface.filter.void"))) {
|
||||
e.setCancelled(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (e.getCursor().getType().equals(Material.AIR)) return true;
|
||||
if (e.getCursor().getAmount() != 1) {
|
||||
e.setCancelled(true);
|
||||
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.hopper.onlyone"));
|
||||
return true;
|
||||
}
|
||||
|
||||
e.setCancelled(false);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> player.setItemOnCursor(new ItemStack(Material.AIR)), 1L);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDrop(PlayerDropItemEvent e) {
|
||||
|
||||
ItemStack item = e.getItemDrop().getItemStack();
|
||||
|
||||
if (!item.hasItemMeta() || !item.getItemMeta().hasDisplayName()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String name = item.getItemMeta().getDisplayName();
|
||||
|
||||
if (!name.equals(instance.getLocale().getMessage("interface.filter.whitelist")) &&
|
||||
!name.equals(instance.getLocale().getMessage("interface.filter.blacklist")) &&
|
||||
!name.equals(instance.getLocale().getMessage("interface.filter.void"))) {
|
||||
return;
|
||||
}
|
||||
e.getItemDrop().remove();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onClose(InventoryCloseEvent event) {
|
||||
try {
|
||||
Player player = (Player) event.getPlayer();
|
||||
PlayerData playerData = instance.getPlayerDataManager().getPlayerData(player);
|
||||
if (playerData.getInMenu() == MenuType.CRAFTING) {
|
||||
Hopper hopper = instance.getHopperManager().getHopperFromPlayer(player);
|
||||
ItemStack item = event.getInventory().getItem(13);
|
||||
hopper.setAutoCrafting(item == null ? Material.AIR : item.getType());
|
||||
}
|
||||
if (playerData.getInMenu() == MenuType.FILTER) {
|
||||
Hopper hopper = instance.getHopperManager().getHopperFromPlayer(player);
|
||||
((EHopper) hopper).compile(player);
|
||||
}
|
||||
if (playerData.getInMenu() != MenuType.NOT_IN) {
|
||||
Hopper hopper = instance.getHopperManager().getHopperFromPlayer(player);
|
||||
if (hopper != null)
|
||||
hopper.setLastPlayer(null);
|
||||
}
|
||||
playerData.setInMenu(MenuType.NOT_IN);
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package com.songoda.epichoppers.player;
|
||||
|
||||
public enum MenuType {
|
||||
|
||||
NOT_IN,
|
||||
OVERVIEW,
|
||||
FILTER,
|
||||
CRAFTING
|
||||
|
||||
}
|
@ -11,8 +11,6 @@ public class PlayerData {
|
||||
|
||||
private Hopper lastHopper = null;
|
||||
|
||||
private MenuType inMenu = MenuType.NOT_IN;
|
||||
|
||||
private SyncType syncType = null; // Null means off.
|
||||
|
||||
private Date lastTeleport = null; // Null means off.
|
||||
@ -21,10 +19,6 @@ public class PlayerData {
|
||||
this.playerUUID = playerUUID;
|
||||
}
|
||||
|
||||
public UUID getPlayerUUID() {
|
||||
return playerUUID;
|
||||
}
|
||||
|
||||
public Hopper getLastHopper() {
|
||||
return lastHopper;
|
||||
}
|
||||
@ -33,14 +27,6 @@ public class PlayerData {
|
||||
this.lastHopper = lastHopper;
|
||||
}
|
||||
|
||||
public MenuType getInMenu() {
|
||||
return inMenu;
|
||||
}
|
||||
|
||||
public void setInMenu(MenuType inMenu) {
|
||||
this.inMenu = inMenu;
|
||||
}
|
||||
|
||||
public SyncType getSyncType() {
|
||||
return syncType;
|
||||
}
|
||||
|
@ -3,17 +3,16 @@ package com.songoda.epichoppers.storage;
|
||||
import com.songoda.epichoppers.utils.Methods;
|
||||
import com.songoda.epichoppers.utils.Serializers;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class StorageItem {
|
||||
|
||||
private String key = null;
|
||||
|
||||
private final Object object;
|
||||
private String key = null;
|
||||
|
||||
public StorageItem(Object object) {
|
||||
this.object = object;
|
||||
@ -50,17 +49,17 @@ public class StorageItem {
|
||||
|
||||
public String asString() {
|
||||
if (object == null) return null;
|
||||
return (String)object;
|
||||
return (String) object;
|
||||
}
|
||||
|
||||
public boolean asBoolean() {
|
||||
if (object == null) return false;
|
||||
return (boolean)object;
|
||||
return (boolean) object;
|
||||
}
|
||||
|
||||
public int asInt() {
|
||||
if (object == null) return 0;
|
||||
return (int)object;
|
||||
return (int) object;
|
||||
}
|
||||
|
||||
public Object asObject() {
|
||||
@ -71,7 +70,7 @@ public class StorageItem {
|
||||
List<ItemStack> list = new ArrayList<>();
|
||||
if (object == null) return list;
|
||||
String obj = (String) object;
|
||||
if (obj.equals("[]"))return list;
|
||||
if (obj.equals("[]")) return list;
|
||||
List<String> sers = new ArrayList<>(Arrays.asList(obj.split(";;")));
|
||||
for (String ser : sers) {
|
||||
list.add(Serializers.deserialize(ser));
|
||||
|
@ -17,8 +17,8 @@ import java.util.Map;
|
||||
|
||||
public class StorageMysql extends Storage {
|
||||
|
||||
private MySQLDatabase database;
|
||||
private static List<String> toSave = new ArrayList<>();
|
||||
private MySQLDatabase database;
|
||||
|
||||
public StorageMysql(EpicHoppersPlugin instance) {
|
||||
super(instance);
|
||||
|
@ -19,6 +19,8 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
public class Methods {
|
||||
|
||||
private static Map<String, Location> serializeCache = new HashMap<>();
|
||||
|
||||
public static boolean isSync(Player p) {
|
||||
try {
|
||||
if (p.getItemInHand().hasItemMeta()
|
||||
@ -97,14 +99,12 @@ public class Methods {
|
||||
location.setX(location.getX() + .5);
|
||||
location.setY(location.getY() + .5);
|
||||
location.setZ(location.getZ() + .5);
|
||||
p.getWorld().spawnParticle(org.bukkit.Particle.valueOf(instance.getConfig().getString("Main.Upgrade Particle Type")), location, 200, .5, .5, .5);
|
||||
p.getWorld().spawnParticle(org.bukkit.Particle.valueOf(instance.getConfig().getString("Main.Upgrade Particle Type")), location, 200, .5, .5, .5);
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Serializes the location of the block specified.
|
||||
*
|
||||
@ -135,8 +135,6 @@ public class Methods {
|
||||
return str;
|
||||
}
|
||||
|
||||
private static Map<String, Location> serializeCache = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Deserializes a location from the string.
|
||||
*
|
||||
|
@ -23,18 +23,18 @@ public class MySQLDatabase {
|
||||
//ToDo: This is sloppy
|
||||
connection.createStatement().execute(
|
||||
"CREATE TABLE IF NOT EXISTS `" + instance.getConfig().getString("Database.Prefix") + "sync` (\n" +
|
||||
"\t`location` TEXT NULL,\n" +
|
||||
"\t`level` INT NULL,\n" +
|
||||
"\t`block` TEXT NULL,\n" +
|
||||
"\t`placedby` TEXT NULL,\n" +
|
||||
"\t`player` TEXT NULL,\n" +
|
||||
"\t`teleporttrigger` TEXT NULL,\n" +
|
||||
"\t`autocrafting` TEXT NULL,\n" +
|
||||
"\t`whitelist` TEXT NULL,\n" +
|
||||
"\t`blacklist` TEXT NULL,\n" +
|
||||
"\t`void` TEXT NULL,\n" +
|
||||
"\t`black` TEXT NULL\n" +
|
||||
")");
|
||||
"\t`location` TEXT NULL,\n" +
|
||||
"\t`level` INT NULL,\n" +
|
||||
"\t`block` TEXT NULL,\n" +
|
||||
"\t`placedby` TEXT NULL,\n" +
|
||||
"\t`player` TEXT NULL,\n" +
|
||||
"\t`teleporttrigger` TEXT NULL,\n" +
|
||||
"\t`autocrafting` TEXT NULL,\n" +
|
||||
"\t`whitelist` TEXT NULL,\n" +
|
||||
"\t`blacklist` TEXT NULL,\n" +
|
||||
"\t`void` TEXT NULL,\n" +
|
||||
"\t`black` TEXT NULL\n" +
|
||||
")");
|
||||
|
||||
connection.createStatement().execute("CREATE TABLE IF NOT EXISTS `" + instance.getConfig().getString("Database.Prefix") + "boosts` (\n" +
|
||||
"\t`endtime` TEXT NULL,\n" +
|
||||
|
@ -10,41 +10,40 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Serializers {
|
||||
public static String serialize(ItemStack item){
|
||||
public static String serialize(ItemStack item) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(item.getType().toString());
|
||||
if(item.getDurability() != 0) builder.append(":" + item.getDurability());
|
||||
if (item.getDurability() != 0) builder.append(":" + item.getDurability());
|
||||
builder.append(" " + item.getAmount());
|
||||
for(Enchantment enchant:item.getEnchantments().keySet())
|
||||
for (Enchantment enchant : item.getEnchantments().keySet())
|
||||
builder.append(" " + enchant.getName() + ":" + item.getEnchantments().get(enchant));
|
||||
String name = getName(item);
|
||||
if(name != null) builder.append(" name:" + name);
|
||||
if (name != null) builder.append(" name:" + name);
|
||||
String lore = getLore(item);
|
||||
if(lore != null) builder.append(" lore:" + lore);
|
||||
if (lore != null) builder.append(" lore:" + lore);
|
||||
Color color = getArmorColor(item);
|
||||
if(color != null) builder.append(" rgb:" + color.getRed() + "|" + color.getGreen() + "|" + color.getBlue());
|
||||
if (color != null) builder.append(" rgb:" + color.getRed() + "|" + color.getGreen() + "|" + color.getBlue());
|
||||
String owner = getOwner(item);
|
||||
if(owner != null) builder.append(" owner:" + owner);
|
||||
if (owner != null) builder.append(" owner:" + owner);
|
||||
return builder.toString();
|
||||
}
|
||||
public static ItemStack deserialize(String serializedItem){
|
||||
|
||||
public static ItemStack deserialize(String serializedItem) {
|
||||
String[] strings = serializedItem.split(" ");
|
||||
Map<Enchantment, Integer> enchants = new HashMap<Enchantment, Integer>();
|
||||
String[] args;
|
||||
ItemStack item = new ItemStack(Material.AIR);
|
||||
for (String str: strings) {
|
||||
for (String str : strings) {
|
||||
args = str.split(":");
|
||||
if(Material.matchMaterial(args[0]) != null && item.getType() == Material.AIR){
|
||||
if (Material.matchMaterial(args[0]) != null && item.getType() == Material.AIR) {
|
||||
item.setType(Material.matchMaterial(args[0]));
|
||||
if(args.length == 2) item.setDurability(Short.parseShort(args[1]));
|
||||
if (args.length == 2) item.setDurability(Short.parseShort(args[1]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -52,27 +51,27 @@ public class Serializers {
|
||||
Bukkit.getLogger().info("Could not find a valid material for the item in \"" + serializedItem + "\"");
|
||||
return null;
|
||||
}
|
||||
for(String str:strings){
|
||||
for (String str : strings) {
|
||||
args = str.split(":", 2);
|
||||
if(isNumber(args[0])) item.setAmount(Integer.parseInt(args[0]));
|
||||
if(args.length == 1) continue;
|
||||
if(args[0].equalsIgnoreCase("name:")){
|
||||
if (isNumber(args[0])) item.setAmount(Integer.parseInt(args[0]));
|
||||
if (args.length == 1) continue;
|
||||
if (args[0].equalsIgnoreCase("name:")) {
|
||||
setName(item, ChatColor.translateAlternateColorCodes('&', args[1]));
|
||||
continue;
|
||||
}
|
||||
if(args[0].equalsIgnoreCase("lore:")){
|
||||
if (args[0].equalsIgnoreCase("lore:")) {
|
||||
setLore(item, ChatColor.translateAlternateColorCodes('&', args[1]));
|
||||
continue;
|
||||
}
|
||||
if(args[0].equalsIgnoreCase("rgb:")){
|
||||
if (args[0].equalsIgnoreCase("rgb:")) {
|
||||
setArmorColor(item, args[1]);
|
||||
continue;
|
||||
}
|
||||
if(args[0].equalsIgnoreCase("owner:")){
|
||||
if (args[0].equalsIgnoreCase("owner:")) {
|
||||
setOwner(item, args[1]);
|
||||
continue;
|
||||
}
|
||||
if(Enchantment.getByName(args[0].toUpperCase()) != null){
|
||||
if (Enchantment.getByName(args[0].toUpperCase()) != null) {
|
||||
enchants.put(Enchantment.getByName(args[0].toUpperCase()), Integer.parseInt(args[1]));
|
||||
continue;
|
||||
}
|
||||
@ -80,52 +79,60 @@ public class Serializers {
|
||||
item.addUnsafeEnchantments(enchants);
|
||||
return item.getType().equals(Material.AIR) ? null : item;
|
||||
}
|
||||
private static String getOwner(ItemStack item){
|
||||
if(!(item.getItemMeta() instanceof SkullMeta)) return null;
|
||||
return ((SkullMeta)item.getItemMeta()).getOwner();
|
||||
|
||||
private static String getOwner(ItemStack item) {
|
||||
if (!(item.getItemMeta() instanceof SkullMeta)) return null;
|
||||
return ((SkullMeta) item.getItemMeta()).getOwner();
|
||||
}
|
||||
private static void setOwner(ItemStack item, String owner){
|
||||
try{
|
||||
|
||||
private static void setOwner(ItemStack item, String owner) {
|
||||
try {
|
||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
||||
meta.setOwner(owner);
|
||||
item.setItemMeta(meta);
|
||||
}catch(Exception exception){
|
||||
} catch (Exception exception) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
private static String getName(ItemStack item){
|
||||
if(!item.hasItemMeta()) return null;
|
||||
if(!item.getItemMeta().hasDisplayName()) return null;
|
||||
|
||||
private static String getName(ItemStack item) {
|
||||
if (!item.hasItemMeta()) return null;
|
||||
if (!item.getItemMeta().hasDisplayName()) return null;
|
||||
return item.getItemMeta().getDisplayName().replace(" ", "_").replace(ChatColor.COLOR_CHAR, '&');
|
||||
}
|
||||
private static void setName(ItemStack item, String name){
|
||||
|
||||
private static void setName(ItemStack item, String name) {
|
||||
name = name.replace("_", " ");
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(name);
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
private static String getLore(ItemStack item){
|
||||
if(!item.hasItemMeta()) return null;
|
||||
if(!item.getItemMeta().hasLore()) return null;
|
||||
|
||||
private static String getLore(ItemStack item) {
|
||||
if (!item.hasItemMeta()) return null;
|
||||
if (!item.getItemMeta().hasLore()) return null;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
List<String> lore = item.getItemMeta().getLore();
|
||||
for(int ind = 0;ind<lore.size();ind++){
|
||||
for (int ind = 0; ind < lore.size(); ind++) {
|
||||
builder.append((ind > 0 ? "|" : "") + lore.get(ind).replace(" ", "_").replace(ChatColor.COLOR_CHAR, '&'));
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
private static void setLore(ItemStack item, String lore){
|
||||
|
||||
private static void setLore(ItemStack item, String lore) {
|
||||
lore = lore.replace("_", " ");
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setLore(Arrays.asList(lore.split("\\|")));
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
private static Color getArmorColor(ItemStack item){
|
||||
if(!(item.getItemMeta() instanceof LeatherArmorMeta)) return null;
|
||||
return ((LeatherArmorMeta)item.getItemMeta()).getColor();
|
||||
|
||||
private static Color getArmorColor(ItemStack item) {
|
||||
if (!(item.getItemMeta() instanceof LeatherArmorMeta)) return null;
|
||||
return ((LeatherArmorMeta) item.getItemMeta()).getColor();
|
||||
}
|
||||
private static void setArmorColor(ItemStack item, String str){
|
||||
try{
|
||||
|
||||
private static void setArmorColor(ItemStack item, String str) {
|
||||
try {
|
||||
String[] colors = str.split("\\|");
|
||||
int red = Integer.parseInt(colors[0]);
|
||||
int green = Integer.parseInt(colors[1]);
|
||||
@ -133,14 +140,15 @@ public class Serializers {
|
||||
LeatherArmorMeta meta = (LeatherArmorMeta) item.getItemMeta();
|
||||
meta.setColor(Color.fromRGB(red, green, blue));
|
||||
item.setItemMeta(meta);
|
||||
}catch(Exception exception){
|
||||
} catch (Exception exception) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
private static boolean isNumber(String str){
|
||||
try{
|
||||
|
||||
private static boolean isNumber(String str) {
|
||||
try {
|
||||
Integer.parseInt(str);
|
||||
}catch(NumberFormatException exception){
|
||||
} catch (NumberFormatException exception) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -15,7 +15,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
@ -23,22 +22,17 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public class SettingsManager implements Listener {
|
||||
|
||||
private String pluginName = "EpicHoppers";
|
||||
|
||||
private static final Pattern SETTINGS_PATTERN = Pattern.compile("(.{1,28}(?:\\s|$))|(.{0,28})", Pattern.DOTALL);
|
||||
|
||||
|
||||
private Map<Player, String> cat = new HashMap<>();
|
||||
|
||||
private final EpicHoppersPlugin instance;
|
||||
private String pluginName = "EpicHoppers";
|
||||
private Map<Player, String> cat = new HashMap<>();
|
||||
private Map<Player, String> current = new HashMap<>();
|
||||
|
||||
public SettingsManager(EpicHoppersPlugin plugin) {
|
||||
this.instance = plugin;
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
private Map<Player, String> current = new HashMap<>();
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
ItemStack clickedItem = event.getCurrentItem();
|
||||
|
@ -0,0 +1,270 @@
|
||||
package com.songoda.epichoppers.utils.gui;
|
||||
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.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 = Sound.ENTITY_PLAYER_LEVELUP;
|
||||
|
||||
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 (!(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();
|
||||
player.playSound(player.getLocation(), closeSound, 1F, 1F);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(EpicHoppersPlugin.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, EpicHoppersPlugin.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;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,217 @@
|
||||
package com.songoda.epichoppers.utils.gui;
|
||||
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
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());
|
||||
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;
|
||||
}
|
||||
|
||||
protected 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, ChatColor.translateAlternateColorCodes('&', title));
|
||||
registerClickables();
|
||||
registerOnCloses();
|
||||
}
|
||||
constructGUI();
|
||||
initializeListeners(EpicHoppersPlugin.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 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.songoda.epichoppers.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);
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.songoda.epichoppers.utils.gui;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public interface OnClose {
|
||||
|
||||
void OnClose(Player player, Inventory inventory);
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.songoda.epichoppers.utils.gui;
|
||||
|
||||
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 = Sound.UI_BUTTON_CLICK;
|
||||
|
||||
public Range(int min, int max, ClickType clickType, boolean bottom) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.clickType = clickType;
|
||||
this.bottom = bottom;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
package com.songoda.epichoppers.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();
|
||||
}
|
||||
}
|
||||
}
|
@ -26,7 +26,7 @@ interface.hopper.autosell = "&7AutoSell: Every &6%seconds%s"
|
||||
interface.hopper.linkamount = "&7Link Overflow: &6%amount%"
|
||||
interface.hopper.blockbreak = "&7Block Break: &6Every %ticks% ticks"
|
||||
interface.hopper.alreadymaxed = "&7This hopper is already maxed out!"
|
||||
interface.hopper.synclore = "|&7Left-Click then click a another|&7hopper or chest to link!||&7Right-Click to unlink."
|
||||
interface.hopper.synclore = "|&7Left-Click then click a another|&7hopper or chest to link!||&7Right-Click to unlink.|&7Currently linked to &6%amount% hopper(s)&7."
|
||||
interface.hopper.perltitle = "&6Click to Teleport"
|
||||
interface.hopper.perllore2 = "|&7Left-Click to teleport to|&7the end of the chain.||&7Right-Click to switch the|&7teleport trigger mode.|&7Currently set to: &a%type%&7."
|
||||
interface.hopper.filtertitle = "&cClick to Filter"
|
||||
@ -38,7 +38,7 @@ interface.hopper.selllore = "|&7Selling in &6%timeleft%s&7."
|
||||
interface.hopper.synchopper = "&6Click to Link This hopper"
|
||||
interface.hopper.rejectsync = "&6Click to Link Rejected Items"
|
||||
interface.filter.infotitle = "&aFilter Guide"
|
||||
interface.filter.infolore = "&7Items placed in the top left|&7space will be whitelisted.||&7Items placed in the right|&7will be void.||&7Items placed in the bottom left|&7will be blacklisted.||&cUsing the whitelist will disable|&cboth the blacklist and the void."
|
||||
interface.filter.infolore = "&7Items placed in the right most colmun|&7space will be whitelisted.||&7Items placed in the right most column|&7will be void.||&7Items placed in the middle column|&7will be blacklisted.||&cUsing the whitelist will disable|&cboth the blacklist and the void."
|
||||
interface.filter.whitelist = "&f&lWhite List"
|
||||
interface.filter.blacklist = "&8&lBlack List"
|
||||
interface.filter.void = "&c&lVoid"
|
||||
|
Loading…
Reference in New Issue
Block a user