mirror of
https://github.com/songoda/EpicHoppers.git
synced 2024-11-22 10:15:43 +01:00
Release v5.0.0-SNAPSHOT-b5. Updates to new db system, updates UltimateStacker compatiblility.
This commit is contained in:
parent
332a058077
commit
7a612f7ff5
@ -7,10 +7,11 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.craftaro</groupId>
|
<groupId>com.craftaro</groupId>
|
||||||
<artifactId>EpicHoppers-Parent</artifactId>
|
<artifactId>EpicHoppers-Parent</artifactId>
|
||||||
<version>5.0.0-SNAPSHOT</version>
|
<version>5.0.0-SNAPSHOT-b5</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>EpicHoppers-API</artifactId>
|
<artifactId>EpicHoppers-API</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package com.craftaro.epichoppers;
|
package com.craftaro.epichoppers;
|
||||||
|
|
||||||
|
import com.craftaro.core.database.DataManager;
|
||||||
import com.craftaro.epichoppers.boost.BoostManager;
|
import com.craftaro.epichoppers.boost.BoostManager;
|
||||||
import com.craftaro.epichoppers.containers.ContainerManager;
|
import com.craftaro.epichoppers.containers.ContainerManager;
|
||||||
import com.craftaro.epichoppers.database.DataManager;
|
|
||||||
import com.craftaro.epichoppers.hopper.teleport.TeleportHandler;
|
import com.craftaro.epichoppers.hopper.teleport.TeleportHandler;
|
||||||
import com.craftaro.epichoppers.player.PlayerDataManager;
|
import com.craftaro.epichoppers.player.PlayerDataManager;
|
||||||
import com.craftaro.epichoppers.hopper.levels.LevelManager;
|
import com.craftaro.epichoppers.hopper.levels.LevelManager;
|
||||||
@ -16,20 +16,16 @@ public class EpicHoppersApi {
|
|||||||
private final ContainerManager containerManager;
|
private final ContainerManager containerManager;
|
||||||
private final TeleportHandler teleportHandler;
|
private final TeleportHandler teleportHandler;
|
||||||
private final PlayerDataManager playerDataManager;
|
private final PlayerDataManager playerDataManager;
|
||||||
private final DataManager dataManager;
|
|
||||||
|
|
||||||
private EpicHoppersApi(LevelManager levelManager,
|
private EpicHoppersApi(LevelManager levelManager,
|
||||||
BoostManager boostManager,
|
BoostManager boostManager,
|
||||||
ContainerManager containerManager,
|
ContainerManager containerManager,
|
||||||
TeleportHandler teleportHandler,
|
TeleportHandler teleportHandler,
|
||||||
PlayerDataManager playerDataManager,
|
PlayerDataManager playerDataManager) {
|
||||||
DataManager dataManager) {
|
|
||||||
this.levelManager = levelManager;
|
this.levelManager = levelManager;
|
||||||
this.boostManager = boostManager;
|
this.boostManager = boostManager;
|
||||||
this.containerManager = containerManager;
|
this.containerManager = containerManager;
|
||||||
this.teleportHandler = teleportHandler;
|
this.teleportHandler = teleportHandler;
|
||||||
this.playerDataManager = playerDataManager;
|
this.playerDataManager = playerDataManager;
|
||||||
this.dataManager = dataManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public LevelManager getLevelManager() {
|
public LevelManager getLevelManager() {
|
||||||
@ -52,22 +48,14 @@ public class EpicHoppersApi {
|
|||||||
return this.playerDataManager;
|
return this.playerDataManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO: The DataManager probably shouldn't be exposed to the API.
|
|
||||||
*/
|
|
||||||
@ApiStatus.Internal
|
|
||||||
public DataManager getDataManager() {
|
|
||||||
return this.dataManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EpicHoppersApi getApi() {
|
public static EpicHoppersApi getApi() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void initApi(LevelManager levelManager, BoostManager boostManager, ContainerManager containerManager, TeleportHandler teleportHandler, PlayerDataManager playerDataManager, DataManager dataManager) {
|
static void initApi(LevelManager levelManager, BoostManager boostManager, ContainerManager containerManager, TeleportHandler teleportHandler, PlayerDataManager playerDataManager) {
|
||||||
if (instance != null) {
|
if (instance != null) {
|
||||||
throw new IllegalStateException(EpicHoppersApi.class.getSimpleName() + " already initialized");
|
throw new IllegalStateException(EpicHoppersApi.class.getSimpleName() + " already initialized");
|
||||||
}
|
}
|
||||||
instance = new EpicHoppersApi(levelManager, boostManager, containerManager, teleportHandler, playerDataManager, dataManager);
|
instance = new EpicHoppersApi(levelManager, boostManager, containerManager, teleportHandler, playerDataManager);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,52 +3,23 @@ package com.craftaro.epichoppers.boost;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class BoostData {
|
public interface BoostData {
|
||||||
private final int multiplier;
|
|
||||||
private final long endTime;
|
|
||||||
private final UUID player;
|
|
||||||
|
|
||||||
public BoostData(int multiplier, long endTime, UUID player) {
|
/**
|
||||||
this.multiplier = multiplier;
|
* Gets the multiplier of the boost
|
||||||
this.endTime = endTime;
|
* @return The multiplier
|
||||||
this.player = player;
|
*/
|
||||||
}
|
int getMultiplier();
|
||||||
|
|
||||||
public int getMultiplier() {
|
/**
|
||||||
return this.multiplier;
|
* Gets the player's uuid who has the boost
|
||||||
}
|
* @return The player's uuid
|
||||||
|
*/
|
||||||
public UUID getPlayer() {
|
public UUID getPlayer();
|
||||||
return this.player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getEndTime() {
|
|
||||||
return this.endTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
int result = 31 * this.multiplier;
|
|
||||||
|
|
||||||
result = 31 * result + (this.player == null ? 0 : this.player.hashCode());
|
|
||||||
result = 31 * result + (int) (this.endTime ^ (this.endTime >>> 32));
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!(obj instanceof BoostData)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
BoostData other = (BoostData) obj;
|
|
||||||
return this.multiplier == other.multiplier &&
|
|
||||||
this.endTime == other.endTime &&
|
|
||||||
Objects.equals(this.player, other.player);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the end time of the boost
|
||||||
|
* @return The end time
|
||||||
|
*/
|
||||||
|
public long getEndTime();
|
||||||
}
|
}
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
package com.craftaro.epichoppers.database;
|
|
||||||
|
|
||||||
import com.craftaro.epichoppers.boost.BoostData;
|
|
||||||
import com.craftaro.epichoppers.hopper.Hopper;
|
|
||||||
import com.craftaro.epichoppers.hopper.ItemType;
|
|
||||||
import com.craftaro.epichoppers.hopper.LinkType;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public interface DataManager {
|
|
||||||
void createBoost(BoostData boostData);
|
|
||||||
|
|
||||||
void getBoosts(Consumer<List<BoostData>> callback);
|
|
||||||
|
|
||||||
void deleteBoost(BoostData boostData);
|
|
||||||
|
|
||||||
void createLink(Hopper hopper, Location location, LinkType type);
|
|
||||||
|
|
||||||
void updateItems(Hopper hopper, ItemType type, List<ItemStack> items);
|
|
||||||
|
|
||||||
void deleteLink(Hopper hopper, Location location);
|
|
||||||
|
|
||||||
void deleteLinks(Hopper hopper);
|
|
||||||
|
|
||||||
void createHoppers(List<Hopper> hoppers);
|
|
||||||
|
|
||||||
void createHopper(Hopper hopper);
|
|
||||||
|
|
||||||
void updateHopper(Hopper hopper);
|
|
||||||
|
|
||||||
void deleteHopper(Hopper hopper);
|
|
||||||
|
|
||||||
void getHoppers(Consumer<Map<Integer, Hopper>> callback);
|
|
||||||
}
|
|
@ -1,410 +1,57 @@
|
|||||||
package com.craftaro.epichoppers.hopper;
|
package com.craftaro.epichoppers.hopper;
|
||||||
|
|
||||||
import com.craftaro.core.SongodaPlugin;
|
import com.craftaro.core.database.Data;
|
||||||
import com.craftaro.core.compatibility.CompatibleParticleHandler;
|
|
||||||
import com.craftaro.core.compatibility.ServerVersion;
|
|
||||||
import com.craftaro.core.hooks.EconomyManager;
|
|
||||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XSound;
|
|
||||||
import com.craftaro.epichoppers.EpicHoppersApi;
|
|
||||||
import com.craftaro.epichoppers.api.events.HopperAccessEvent;
|
|
||||||
import com.craftaro.epichoppers.database.DataManager;
|
|
||||||
import com.craftaro.epichoppers.hopper.levels.Level;
|
import com.craftaro.epichoppers.hopper.levels.Level;
|
||||||
import com.craftaro.epichoppers.hopper.levels.LevelManager;
|
|
||||||
import com.craftaro.epichoppers.player.PlayerData;
|
|
||||||
import com.craftaro.epichoppers.player.PlayerDataManager;
|
|
||||||
import com.craftaro.epichoppers.utils.CostType;
|
|
||||||
import com.craftaro.epichoppers.utils.Methods;
|
|
||||||
import com.craftaro.epichoppers.hopper.teleport.TeleportTrigger;
|
import com.craftaro.epichoppers.hopper.teleport.TeleportTrigger;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.GameMode;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
public interface Hopper extends Data {
|
||||||
* FIXME: Needs heavy refactoring to only have one responsibility.
|
|
||||||
*/
|
|
||||||
public class Hopper {
|
|
||||||
// Id for database use.
|
|
||||||
private int id;
|
|
||||||
|
|
||||||
private final Location location;
|
Location getLocation();
|
||||||
private Level level = getLevelManager().getLowestLevel();
|
|
||||||
private UUID lastPlayerOpened = null;
|
|
||||||
private UUID placedBy = null;
|
|
||||||
private final List<Location> linkedBlocks = new ArrayList<>();
|
|
||||||
private Filter filter = new Filter();
|
|
||||||
private TeleportTrigger teleportTrigger = TeleportTrigger.DISABLED;
|
|
||||||
private int transferTick = 0;
|
|
||||||
|
|
||||||
private int syncId = -1;
|
Block getBlock();
|
||||||
|
|
||||||
private Player activePlayer;
|
Level getLevel();
|
||||||
|
|
||||||
private final Map<String, Object> moduleCache = new HashMap<>();
|
void setLevel(Level level);
|
||||||
|
|
||||||
public Hopper(Location location) {
|
@Nullable UUID getLastPlayerOpened();
|
||||||
this.location = location;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiStatus.Internal
|
@Nullable UUID getPlacedBy();
|
||||||
public boolean prepareForOpeningOverviewGui(Player player) {
|
|
||||||
if (this.lastPlayerOpened != null &&
|
|
||||||
this.lastPlayerOpened != player.getUniqueId() &&
|
|
||||||
Bukkit.getPlayer(this.lastPlayerOpened) != null) {
|
|
||||||
Bukkit.getPlayer(this.lastPlayerOpened).closeInventory();
|
|
||||||
}
|
|
||||||
|
|
||||||
HopperAccessEvent accessEvent = new HopperAccessEvent(player, this);
|
void setPlacedBy(UUID placedBy);
|
||||||
Bukkit.getPluginManager().callEvent(accessEvent);
|
|
||||||
if (accessEvent.isCancelled()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.placedBy == null) {
|
void setLastPlayerOpened(UUID lastPlayerOpened);
|
||||||
this.placedBy = player.getUniqueId();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!player.hasPermission("epichoppers.overview")) {
|
TeleportTrigger getTeleportTrigger();
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
setActivePlayer(player);
|
void setTeleportTrigger(TeleportTrigger teleportTrigger);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiStatus.Internal
|
List<Location> getLinkedBlocks();
|
||||||
public void forceClose() {
|
|
||||||
if (this.activePlayer != null) {
|
|
||||||
this.activePlayer.closeInventory();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void dropItems() {
|
void addLinkedBlock(Location location, LinkType type);
|
||||||
Inventory inventory = ((InventoryHolder) this.location.getBlock().getState()).getInventory();
|
|
||||||
World world = this.location.getWorld();
|
|
||||||
|
|
||||||
for (ItemStack itemStack : inventory.getContents()) {
|
void removeLinkedBlock(Location location);
|
||||||
if (itemStack == null || itemStack.getType() == Material.AIR) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
world.dropItemNaturally(this.location, itemStack);
|
void clearLinkedBlocks();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void upgrade(Player player, CostType type) {
|
Filter getFilter();
|
||||||
if (!getLevelManager().getLevels().containsKey(this.level.getLevel() + 1)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Level level = getLevelManager().getLevel(this.level.getLevel() + 1);
|
void setActivePlayer(Player activePlayer);
|
||||||
int cost = type == CostType.ECONOMY ? level.getCostEconomy() : level.getCostExperience();
|
|
||||||
|
|
||||||
if (type == CostType.ECONOMY) {
|
void timeout(Player player);
|
||||||
if (!EconomyManager.isEnabled()) {
|
|
||||||
player.sendMessage("Economy not enabled.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!EconomyManager.hasBalance(player, cost)) {
|
|
||||||
getPlugin().getLocale().getMessage("event.upgrade.cannotafford").sendPrefixedMessage(player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
EconomyManager.withdrawBalance(player, cost);
|
|
||||||
upgradeFinal(level, player);
|
|
||||||
} else if (type == CostType.EXPERIENCE) {
|
|
||||||
if (player.getLevel() >= cost || player.getGameMode() == GameMode.CREATIVE) {
|
|
||||||
if (player.getGameMode() != GameMode.CREATIVE) {
|
|
||||||
player.setLevel(player.getLevel() - cost);
|
|
||||||
}
|
|
||||||
upgradeFinal(level, player);
|
|
||||||
} else {
|
|
||||||
getPlugin().getLocale().getMessage("event.upgrade.cannotafford").sendPrefixedMessage(player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void upgradeFinal(Level level, Player player) {
|
void addDataToModuleCache(String s, Object value);
|
||||||
this.level = level;
|
|
||||||
getDataManager().updateHopper(this);
|
|
||||||
syncName();
|
|
||||||
if (getLevelManager().getHighestLevel() != level) {
|
|
||||||
getPlugin().getLocale().getMessage("event.upgrade.success")
|
|
||||||
.processPlaceholder("level", level.getLevel()).sendPrefixedMessage(player);
|
|
||||||
} else {
|
|
||||||
getPlugin().getLocale().getMessage("event.upgrade.maxed")
|
|
||||||
.processPlaceholder("level", level.getLevel()).sendPrefixedMessage(player);
|
|
||||||
}
|
|
||||||
Location loc = this.location.clone().add(.5, .5, .5);
|
|
||||||
|
|
||||||
if (!getUpgradeParticleType().trim().isEmpty()) {
|
boolean isDataCachedInModuleCache(String cacheStr);
|
||||||
CompatibleParticleHandler.spawnParticles(
|
|
||||||
CompatibleParticleHandler.ParticleType.getParticle(getUpgradeParticleType()),
|
|
||||||
loc, 100, .5, .5, .5);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getLevelManager().getHighestLevel() != level) {
|
Object getDataFromModuleCache(String cacheStr);
|
||||||
XSound.ENTITY_PLAYER_LEVELUP.play(player, .6f, 15);
|
|
||||||
} else {
|
|
||||||
XSound.ENTITY_PLAYER_LEVELUP.play(player, 2, 25);
|
|
||||||
XSound.BLOCK_NOTE_BLOCK_CHIME.play(player, 2, 25);
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), () -> XSound.BLOCK_NOTE_BLOCK_CHIME.play(player, 1.2f, 35), 5);
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), () -> XSound.BLOCK_NOTE_BLOCK_CHIME.play(player, 1.8f, 35), 10);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void syncName() {
|
void clearModuleCache();
|
||||||
org.bukkit.block.Hopper hopper = (org.bukkit.block.Hopper) this.location.getBlock().getState();
|
|
||||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_10)) {
|
|
||||||
hopper.setCustomName(Methods.formatName(this.level.getLevel()));
|
|
||||||
}
|
|
||||||
hopper.update(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void timeout(Player player) {
|
|
||||||
this.syncId = Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), () -> {
|
|
||||||
PlayerData playerData = getPlayerDataManager().getPlayerData(player);
|
|
||||||
if (playerData.getSyncType() != null && playerData.getLastHopper() == this) {
|
|
||||||
getPlugin().getLocale().getMessage("event.hopper.synctimeout").sendPrefixedMessage(player);
|
|
||||||
playerData.setSyncType(null);
|
|
||||||
}
|
|
||||||
}, getLinkTimeoutFromPluginConfig() * this.level.getLinkAmount());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void link(Block toLink, boolean filtered, Player player) {
|
|
||||||
if (this.location.getWorld().equals(toLink.getLocation().getWorld())
|
|
||||||
&& !player.hasPermission("EpicHoppers.Override")
|
|
||||||
&& !player.hasPermission("EpicHoppers.Admin")
|
|
||||||
&& this.location.distance(toLink.getLocation()) > this.level.getRange()) {
|
|
||||||
getPlugin().getLocale().getMessage("event.hopper.syncoutofrange").sendPrefixedMessage(player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.linkedBlocks.contains(toLink.getLocation())) {
|
|
||||||
getPlugin().getLocale().getMessage("event.hopper.already").sendPrefixedMessage(player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!filtered) {
|
|
||||||
this.linkedBlocks.add(toLink.getLocation());
|
|
||||||
getDataManager().createLink(this, toLink.getLocation(), LinkType.REGULAR);
|
|
||||||
} else {
|
|
||||||
this.filter.setEndPoint(toLink.getLocation());
|
|
||||||
getDataManager().createLink(this, toLink.getLocation(), LinkType.REJECT);
|
|
||||||
getPlugin().getLocale().getMessage("event.hopper.syncsuccess").sendPrefixedMessage(player);
|
|
||||||
getPlayerDataManager().getPlayerData(player).setSyncType(null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.lastPlayerOpened = player.getUniqueId();
|
|
||||||
|
|
||||||
if (this.level.getLinkAmount() > 1) {
|
|
||||||
if (this.linkedBlocks.size() >= this.level.getLinkAmount()) {
|
|
||||||
getPlugin().getLocale().getMessage("event.hopper.syncdone").sendPrefixedMessage(player);
|
|
||||||
cancelSync(player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
getPlugin().getLocale().getMessage("event.hopper.syncsuccessmore")
|
|
||||||
.processPlaceholder("amount", this.level.getLinkAmount() - this.linkedBlocks.size())
|
|
||||||
.sendPrefixedMessage(player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
getPlugin().getLocale().getMessage("event.hopper.syncsuccess").sendPrefixedMessage(player);
|
|
||||||
cancelSync(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ticks a hopper to determine when it can transfer items next
|
|
||||||
*
|
|
||||||
* @param maxTick The maximum amount the hopper can be ticked before next transferring items
|
|
||||||
* @param allowLooping If true, the hopper is allowed to transfer items if the tick is also valid
|
|
||||||
* @return true if the hopper should transfer an item, otherwise false
|
|
||||||
*/
|
|
||||||
public boolean tryTick(int maxTick, boolean allowLooping) {
|
|
||||||
this.transferTick++;
|
|
||||||
if (this.transferTick >= maxTick) {
|
|
||||||
if (allowLooping) {
|
|
||||||
this.transferTick = 0;
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
this.transferTick = maxTick;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Location getLocation() {
|
|
||||||
return this.location.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Block getBlock() {
|
|
||||||
return this.location.getBlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
public World getWorld() {
|
|
||||||
return this.location.getWorld();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getX() {
|
|
||||||
return this.location.getBlockX();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getY() {
|
|
||||||
return this.location.getBlockY();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getZ() {
|
|
||||||
return this.location.getBlockZ();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Level getLevel() {
|
|
||||||
return this.level;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLevel(Level level) {
|
|
||||||
this.level = level;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getPlacedBy() {
|
|
||||||
return this.placedBy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPlacedBy(UUID placedBy) {
|
|
||||||
this.placedBy = placedBy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getLastPlayerOpened() {
|
|
||||||
return this.lastPlayerOpened;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastPlayerOpened(UUID uuid) {
|
|
||||||
this.lastPlayerOpened = uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TeleportTrigger getTeleportTrigger() {
|
|
||||||
return this.teleportTrigger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTeleportTrigger(TeleportTrigger teleportTrigger) {
|
|
||||||
this.teleportTrigger = teleportTrigger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Location> getLinkedBlocks() {
|
|
||||||
return new ArrayList<>(this.linkedBlocks);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addLinkedBlock(Location location, LinkType type) {
|
|
||||||
if (type == LinkType.REGULAR) {
|
|
||||||
this.linkedBlocks.add(location);
|
|
||||||
} else {
|
|
||||||
this.filter.setEndPoint(location);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeLinkedBlock(Location location) {
|
|
||||||
this.linkedBlocks.remove(location);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearLinkedBlocks() {
|
|
||||||
this.linkedBlocks.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Filter getFilter() {
|
|
||||||
return this.filter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFilter(Filter filter) {
|
|
||||||
this.filter = filter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getDataFromModuleCache(String key) {
|
|
||||||
return this.moduleCache.getOrDefault(key, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addDataToModuleCache(String key, Object data) {
|
|
||||||
this.moduleCache.put(key, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDataCachedInModuleCache(String key) {
|
|
||||||
return this.moduleCache.containsKey(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeDataFromModuleCache(String key) {
|
|
||||||
this.moduleCache.remove(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearModuleCache() {
|
|
||||||
this.moduleCache.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cancelSync(Player player) {
|
|
||||||
Bukkit.getScheduler().cancelTask(this.syncId);
|
|
||||||
getPlayerDataManager().getPlayerData(player).setSyncType(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return this.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Player getActivePlayer() {
|
|
||||||
return this.activePlayer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setActivePlayer(Player activePlayer) {
|
|
||||||
this.activePlayer = activePlayer;
|
|
||||||
}
|
|
||||||
|
|
||||||
private LevelManager getLevelManager() {
|
|
||||||
return EpicHoppersApi.getApi().getLevelManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
private PlayerDataManager getPlayerDataManager() {
|
|
||||||
return EpicHoppersApi.getApi().getPlayerDataManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
private DataManager getDataManager() {
|
|
||||||
return EpicHoppersApi.getApi().getDataManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated The class needs refactoring to not even need the plugin.
|
|
||||||
* This is just a temporary workaround to get a Minecraft 1.20-beta build ready
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private long getLinkTimeoutFromPluginConfig() {
|
|
||||||
return getPlugin().getConfig().getLong("Main.Timeout When Syncing Hoppers");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated The class needs refactoring to not even need the plugin.
|
|
||||||
* This is just a temporary workaround to get a Minecraft 1.20-beta build ready
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private String getUpgradeParticleType() {
|
|
||||||
return getPlugin().getConfig().getString("Main.Upgrade Particle Type");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated The class needs refactoring to not even need the plugin.
|
|
||||||
* This is just a temporary workaround to get a Minecraft 1.20-beta build ready
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private SongodaPlugin getPlugin() {
|
|
||||||
return (SongodaPlugin) Bukkit.getPluginManager().getPlugin("EpicHoppers");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.craftaro.epichoppers.player;
|
package com.craftaro.epichoppers.player;
|
||||||
|
|
||||||
|
|
||||||
import com.craftaro.epichoppers.hopper.Hopper;
|
import com.craftaro.epichoppers.hopper.Hopper;
|
||||||
|
|
||||||
public class PlayerData {
|
public class PlayerData {
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.craftaro</groupId>
|
<groupId>com.craftaro</groupId>
|
||||||
<artifactId>EpicHoppers-Parent</artifactId>
|
<artifactId>EpicHoppers-Parent</artifactId>
|
||||||
<version>5.0.0-SNAPSHOT</version>
|
<version>5.0.0-SNAPSHOT-b5</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>EpicHoppers-Plugin</artifactId>
|
<artifactId>EpicHoppers-Plugin</artifactId>
|
||||||
@ -56,6 +56,7 @@
|
|||||||
<excludeDefaults>false</excludeDefaults>
|
<excludeDefaults>false</excludeDefaults>
|
||||||
<includes>
|
<includes>
|
||||||
<include>**/nms/v*/**</include>
|
<include>**/nms/v*/**</include>
|
||||||
|
<include>**/third_party/**</include>
|
||||||
</includes>
|
</includes>
|
||||||
</filter>
|
</filter>
|
||||||
</filters>
|
</filters>
|
||||||
@ -89,7 +90,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.craftaro</groupId>
|
<groupId>com.craftaro</groupId>
|
||||||
<artifactId>EpicHoppers-API</artifactId>
|
<artifactId>EpicHoppers-API</artifactId>
|
||||||
<version>5.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@ -136,9 +137,9 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.songoda</groupId>
|
<groupId>com.craftaro</groupId>
|
||||||
<artifactId>UltimateStacker</artifactId>
|
<artifactId>UltimateStacker-API</artifactId>
|
||||||
<version>2.1.6</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -4,17 +4,14 @@ import com.craftaro.core.SongodaCore;
|
|||||||
import com.craftaro.core.SongodaPlugin;
|
import com.craftaro.core.SongodaPlugin;
|
||||||
import com.craftaro.core.commands.CommandManager;
|
import com.craftaro.core.commands.CommandManager;
|
||||||
import com.craftaro.core.configuration.Config;
|
import com.craftaro.core.configuration.Config;
|
||||||
import com.craftaro.core.database.DataManagerAbstract;
|
|
||||||
import com.craftaro.core.database.DataMigrationManager;
|
|
||||||
import com.craftaro.core.database.DatabaseConnector;
|
import com.craftaro.core.database.DatabaseConnector;
|
||||||
import com.craftaro.core.database.MySQLConnector;
|
|
||||||
import com.craftaro.core.database.SQLiteConnector;
|
|
||||||
import com.craftaro.core.gui.GuiManager;
|
import com.craftaro.core.gui.GuiManager;
|
||||||
import com.craftaro.core.hooks.EconomyManager;
|
import com.craftaro.core.hooks.EconomyManager;
|
||||||
import com.craftaro.core.hooks.ProtectionManager;
|
import com.craftaro.core.hooks.ProtectionManager;
|
||||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||||
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
|
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
|
||||||
import com.craftaro.core.utils.TextUtils;
|
import com.craftaro.core.utils.TextUtils;
|
||||||
|
import com.craftaro.epichoppers.boost.BoostDataImpl;
|
||||||
import com.craftaro.epichoppers.boost.BoostManager;
|
import com.craftaro.epichoppers.boost.BoostManager;
|
||||||
import com.craftaro.epichoppers.boost.BoostManagerImpl;
|
import com.craftaro.epichoppers.boost.BoostManagerImpl;
|
||||||
import com.craftaro.epichoppers.commands.CommandBoost;
|
import com.craftaro.epichoppers.commands.CommandBoost;
|
||||||
@ -23,9 +20,8 @@ import com.craftaro.epichoppers.commands.CommandReload;
|
|||||||
import com.craftaro.epichoppers.commands.CommandSettings;
|
import com.craftaro.epichoppers.commands.CommandSettings;
|
||||||
import com.craftaro.epichoppers.containers.ContainerManager;
|
import com.craftaro.epichoppers.containers.ContainerManager;
|
||||||
import com.craftaro.epichoppers.containers.ContainerManagerImpl;
|
import com.craftaro.epichoppers.containers.ContainerManagerImpl;
|
||||||
import com.craftaro.epichoppers.database.DataManager;
|
|
||||||
import com.craftaro.epichoppers.database.DataManagerImpl;
|
|
||||||
import com.craftaro.epichoppers.database.migrations._1_InitialMigration;
|
import com.craftaro.epichoppers.database.migrations._1_InitialMigration;
|
||||||
|
import com.craftaro.epichoppers.hopper.HopperImpl;
|
||||||
import com.craftaro.epichoppers.hopper.HopperManager;
|
import com.craftaro.epichoppers.hopper.HopperManager;
|
||||||
import com.craftaro.epichoppers.hopper.levels.Level;
|
import com.craftaro.epichoppers.hopper.levels.Level;
|
||||||
import com.craftaro.epichoppers.hopper.levels.LevelManager;
|
import com.craftaro.epichoppers.hopper.levels.LevelManager;
|
||||||
@ -76,8 +72,6 @@ public class EpicHoppers extends SongodaPlugin {
|
|||||||
private TeleportHandler teleportHandler;
|
private TeleportHandler teleportHandler;
|
||||||
|
|
||||||
private DatabaseConnector databaseConnector;
|
private DatabaseConnector databaseConnector;
|
||||||
private DataManager dataManager;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPluginLoad() {
|
public void onPluginLoad() {
|
||||||
}
|
}
|
||||||
@ -120,33 +114,8 @@ public class EpicHoppers extends SongodaPlugin {
|
|||||||
this.containerManager = new ContainerManagerImpl();
|
this.containerManager = new ContainerManagerImpl();
|
||||||
this.boostManager = new BoostManagerImpl();
|
this.boostManager = new BoostManagerImpl();
|
||||||
|
|
||||||
// Database stuff, go!
|
|
||||||
try {
|
|
||||||
if (Settings.MYSQL_ENABLED.getBoolean()) {
|
|
||||||
String hostname = Settings.MYSQL_HOSTNAME.getString();
|
|
||||||
int port = Settings.MYSQL_PORT.getInt();
|
|
||||||
String database = Settings.MYSQL_DATABASE.getString();
|
|
||||||
String username = Settings.MYSQL_USERNAME.getString();
|
|
||||||
String password = Settings.MYSQL_PASSWORD.getString();
|
|
||||||
boolean useSSL = Settings.MYSQL_USE_SSL.getBoolean();
|
|
||||||
int poolSize = Settings.MYSQL_POOL_SIZE.getInt();
|
|
||||||
|
|
||||||
this.databaseConnector = new MySQLConnector(this, hostname, port, database, username, password, useSSL, poolSize);
|
initDatabase(Collections.singletonList(new _1_InitialMigration(this)));
|
||||||
this.getLogger().info("Data handler connected using MySQL.");
|
|
||||||
} else {
|
|
||||||
this.databaseConnector = new SQLiteConnector(this);
|
|
||||||
this.getLogger().info("Data handler connected using SQLite.");
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
this.getLogger().severe("Fatal error trying to connect to database. Please make sure all your connection settings are correct and try again. Plugin has been disabled.");
|
|
||||||
this.emergencyStop();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.dataManager = new DataManagerImpl(this.databaseConnector, this);
|
|
||||||
DataMigrationManager dataMigrationManager = new DataMigrationManager(this.databaseConnector, (DataManagerAbstract) this.dataManager, new _1_InitialMigration(this));
|
|
||||||
dataMigrationManager.runMigrations();
|
|
||||||
|
|
||||||
EpicHoppersApi.initApi(this.levelManager, this.boostManager, this.containerManager, this.teleportHandler, this.playerDataManager, this.dataManager);
|
|
||||||
|
|
||||||
this.loadLevelManager();
|
this.loadLevelManager();
|
||||||
|
|
||||||
@ -162,6 +131,8 @@ public class EpicHoppers extends SongodaPlugin {
|
|||||||
pluginManager.registerEvents(new InteractListeners(this), this);
|
pluginManager.registerEvents(new InteractListeners(this), this);
|
||||||
pluginManager.registerEvents(new InventoryListeners(), this);
|
pluginManager.registerEvents(new InventoryListeners(), this);
|
||||||
|
|
||||||
|
EpicHoppersApi.initApi(this.levelManager, this.boostManager, this.containerManager, this.teleportHandler, this.playerDataManager);
|
||||||
|
|
||||||
// Start auto save
|
// Start auto save
|
||||||
int saveInterval = Settings.AUTOSAVE.getInt() * 60 * 20;
|
int saveInterval = Settings.AUTOSAVE.getInt() * 60 * 20;
|
||||||
Bukkit.getScheduler().runTaskTimerAsynchronously(this, this::saveModules, saveInterval, saveInterval);
|
Bukkit.getScheduler().runTaskTimerAsynchronously(this, this::saveModules, saveInterval, saveInterval);
|
||||||
@ -182,10 +153,9 @@ public class EpicHoppers extends SongodaPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public void onDataLoad() {
|
public void onDataLoad() {
|
||||||
// Load data from DB
|
// Load data from DB
|
||||||
this.dataManager.getHoppers((hoppers) -> {
|
this.dataManager.getAsyncPool().execute(() -> {
|
||||||
this.hopperManager.addHoppers(hoppers.values());
|
this.hopperManager.addHoppers(this.dataManager.loadBatch(HopperImpl.class, "placed_hoppers"));
|
||||||
this.dataManager.getBoosts((boosts) -> this.boostManager.addBoosts(boosts));
|
this.boostManager.loadBoosts(this.dataManager.loadBatch(BoostDataImpl.class, "boosted_players"));
|
||||||
|
|
||||||
this.hopperManager.setReady();
|
this.hopperManager.setReady();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -302,10 +272,6 @@ public class EpicHoppers extends SongodaPlugin {
|
|||||||
return this.guiManager;
|
return this.guiManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataManager getDataManager() {
|
|
||||||
return this.dataManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DatabaseConnector getDatabaseConnector() {
|
public DatabaseConnector getDatabaseConnector() {
|
||||||
return this.databaseConnector;
|
return this.databaseConnector;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,92 @@
|
|||||||
|
package com.craftaro.epichoppers.boost;
|
||||||
|
|
||||||
|
import com.craftaro.core.database.Data;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class BoostDataImpl implements BoostData, Data {
|
||||||
|
private final int multiplier;
|
||||||
|
private final long endTime;
|
||||||
|
private final UUID player;
|
||||||
|
|
||||||
|
public BoostDataImpl() {
|
||||||
|
this.multiplier = 0;
|
||||||
|
this.endTime = 0;
|
||||||
|
this.player = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BoostDataImpl(Map<String, Object> map) {
|
||||||
|
this.multiplier = (int) map.get("multiplier");
|
||||||
|
this.endTime = (long) map.get("end_time");
|
||||||
|
this.player = UUID.fromString((String) map.get("player"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public BoostDataImpl(int multiplier, long endTime, UUID player) {
|
||||||
|
this.multiplier = multiplier;
|
||||||
|
this.endTime = endTime;
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMultiplier() {
|
||||||
|
return this.multiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getPlayer() {
|
||||||
|
return this.player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getEndTime() {
|
||||||
|
return this.endTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = 31 * this.multiplier;
|
||||||
|
|
||||||
|
result = 31 * result + (this.player == null ? 0 : this.player.hashCode());
|
||||||
|
result = 31 * result + (int) (this.endTime ^ (this.endTime >>> 32));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!(obj instanceof BoostDataImpl)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
BoostDataImpl other = (BoostDataImpl) obj;
|
||||||
|
return this.multiplier == other.multiplier &&
|
||||||
|
this.endTime == other.endTime &&
|
||||||
|
Objects.equals(this.player, other.player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UUID getUniqueId() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> serialize() {
|
||||||
|
Map<String, Object> map = new java.util.HashMap<>();
|
||||||
|
map.put("player", player.toString());
|
||||||
|
map.put("multiplier", multiplier);
|
||||||
|
map.put("end_time", endTime);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Data deserialize(Map<String, Object> map) {
|
||||||
|
return new BoostDataImpl(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTableName() {
|
||||||
|
return "player_boosts";
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,8 @@
|
|||||||
package com.craftaro.epichoppers.boost;
|
package com.craftaro.epichoppers.boost;
|
||||||
|
|
||||||
|
import com.craftaro.core.database.Data;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -24,6 +27,10 @@ public class BoostManagerImpl implements BoostManager {
|
|||||||
this.registeredBoosts.addAll(boosts);
|
this.registeredBoosts.addAll(boosts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void loadBoosts(Collection<BoostDataImpl> boosts) {
|
||||||
|
this.registeredBoosts.addAll(boosts);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<BoostData> getBoosts() {
|
public Set<BoostData> getBoosts() {
|
||||||
return Collections.unmodifiableSet(this.registeredBoosts);
|
return Collections.unmodifiableSet(this.registeredBoosts);
|
||||||
|
@ -3,7 +3,7 @@ package com.craftaro.epichoppers.commands;
|
|||||||
import com.craftaro.core.commands.AbstractCommand;
|
import com.craftaro.core.commands.AbstractCommand;
|
||||||
import com.craftaro.core.utils.NumberUtils;
|
import com.craftaro.core.utils.NumberUtils;
|
||||||
import com.craftaro.core.utils.TimeUtils;
|
import com.craftaro.core.utils.TimeUtils;
|
||||||
import com.craftaro.epichoppers.boost.BoostData;
|
import com.craftaro.epichoppers.boost.BoostDataImpl;
|
||||||
import com.craftaro.epichoppers.EpicHoppers;
|
import com.craftaro.epichoppers.EpicHoppers;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -49,7 +49,7 @@ public class CommandBoost extends AbstractCommand {
|
|||||||
return ReturnType.FAILURE;
|
return ReturnType.FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
BoostData boostData = new BoostData(Integer.parseInt(args[1]), duration == 0L ? Long.MAX_VALUE : System.currentTimeMillis() + duration, player.getUniqueId());
|
BoostDataImpl boostData = new BoostDataImpl(Integer.parseInt(args[1]), duration == 0L ? Long.MAX_VALUE : System.currentTimeMillis() + duration, player.getUniqueId());
|
||||||
this.plugin.getBoostManager().addBoostToPlayer(boostData);
|
this.plugin.getBoostManager().addBoostToPlayer(boostData);
|
||||||
this.plugin.getLocale().newMessage("&7Successfully boosted &6" + Bukkit.getPlayer(args[0]).getName()
|
this.plugin.getLocale().newMessage("&7Successfully boosted &6" + Bukkit.getPlayer(args[0]).getName()
|
||||||
+ "'s &7hopper transfer rates by &6" + args[1] + "x" + (duration == 0L ? "" : (" for " + TimeUtils.makeReadable(duration))) + "&7.").sendPrefixedMessage(sender);
|
+ "'s &7hopper transfer rates by &6" + args[1] + "x" + (duration == 0L ? "" : (" for " + TimeUtils.makeReadable(duration))) + "&7.").sendPrefixedMessage(sender);
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package com.craftaro.epichoppers.database;
|
package com.craftaro.epichoppers.database;
|
||||||
|
|
||||||
import com.craftaro.core.database.DataManagerAbstract;
|
|
||||||
import com.craftaro.core.database.DatabaseConnector;
|
import com.craftaro.core.database.DatabaseConnector;
|
||||||
import com.craftaro.epichoppers.boost.BoostData;
|
import com.craftaro.epichoppers.boost.BoostData;
|
||||||
|
import com.craftaro.epichoppers.boost.BoostDataImpl;
|
||||||
import com.craftaro.epichoppers.EpicHoppers;
|
import com.craftaro.epichoppers.EpicHoppers;
|
||||||
import com.craftaro.epichoppers.hopper.Filter;
|
import com.craftaro.epichoppers.hopper.Filter;
|
||||||
import com.craftaro.epichoppers.hopper.Hopper;
|
import com.craftaro.epichoppers.hopper.HopperImpl;
|
||||||
import com.craftaro.epichoppers.hopper.HopperBuilder;
|
import com.craftaro.epichoppers.hopper.HopperBuilder;
|
||||||
import com.craftaro.epichoppers.hopper.ItemType;
|
import com.craftaro.epichoppers.hopper.ItemType;
|
||||||
import com.craftaro.epichoppers.hopper.LinkType;
|
import com.craftaro.epichoppers.hopper.LinkType;
|
||||||
@ -33,401 +33,346 @@ import java.util.Map;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class DataManagerImpl extends DataManagerAbstract implements DataManager {
|
public class DataManagerImpl {
|
||||||
public DataManagerImpl(DatabaseConnector databaseConnector, Plugin plugin) {
|
// public DataManagerImpl(DatabaseConnector databaseConnector, Plugin plugin) {
|
||||||
super(databaseConnector, plugin);
|
// super(databaseConnector, plugin);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void createBoost(BoostData boostData) {
|
// public void createBoost(BoostDataImpl boostData) {
|
||||||
this.runAsync(() -> {
|
// this.runAsync(() -> {
|
||||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
// try (Connection connection = this.databaseConnector.getConnection()) {
|
||||||
String createBoostedPlayer = "INSERT INTO " + this.getTablePrefix() + "boosted_players (player, multiplier, end_time) VALUES (?, ?, ?)";
|
// String createBoostedPlayer = "INSERT INTO " + this.getTablePrefix() + "boosted_players (player, multiplier, end_time) VALUES (?, ?, ?)";
|
||||||
PreparedStatement statement = connection.prepareStatement(createBoostedPlayer);
|
// PreparedStatement statement = connection.prepareStatement(createBoostedPlayer);
|
||||||
statement.setString(1, boostData.getPlayer().toString());
|
// statement.setString(1, boostData.getPlayer().toString());
|
||||||
statement.setInt(2, boostData.getMultiplier());
|
// statement.setInt(2, boostData.getMultiplier());
|
||||||
statement.setLong(3, boostData.getEndTime());
|
// statement.setLong(3, boostData.getEndTime());
|
||||||
statement.executeUpdate();
|
// statement.executeUpdate();
|
||||||
} catch (Exception ex) {
|
// } catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
// ex.printStackTrace();
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void getBoosts(Consumer<List<BoostData>> callback) {
|
// public void getBoosts(Consumer<List<BoostData>> callback) {
|
||||||
List<BoostData> boosts = new ArrayList<>();
|
// List<BoostDataImpl> boosts = new ArrayList<>();
|
||||||
this.runAsync(() -> {
|
// this.runAsync(() -> {
|
||||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
// try (Connection connection = this.databaseConnector.getConnection()) {
|
||||||
Statement statement = connection.createStatement();
|
// Statement statement = connection.createStatement();
|
||||||
String selectBoostedPlayers = "SELECT * FROM " + this.getTablePrefix() + "boosted_players";
|
// String selectBoostedPlayers = "SELECT * FROM " + this.getTablePrefix() + "boosted_players";
|
||||||
ResultSet result = statement.executeQuery(selectBoostedPlayers);
|
// ResultSet result = statement.executeQuery(selectBoostedPlayers);
|
||||||
while (result.next()) {
|
// while (result.next()) {
|
||||||
UUID player = UUID.fromString(result.getString("player"));
|
// UUID player = UUID.fromString(result.getString("player"));
|
||||||
int multiplier = result.getInt("multiplier");
|
// int multiplier = result.getInt("multiplier");
|
||||||
long endTime = result.getLong("end_time");
|
// long endTime = result.getLong("end_time");
|
||||||
boosts.add(new BoostData(multiplier, endTime, player));
|
// boosts.add(new BoostDataImpl(multiplier, endTime, player));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
this.sync(() -> callback.accept(boosts));
|
// this.sync(() -> callback.accept(boosts));
|
||||||
} catch (Exception ex) {
|
// } catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
// ex.printStackTrace();
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void deleteBoost(BoostData boostData) {
|
// public void deleteBoost(BoostDataImpl boostData) {
|
||||||
this.runAsync(() -> {
|
// this.runAsync(() -> {
|
||||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
// try (Connection connection = this.databaseConnector.getConnection()) {
|
||||||
String deleteBoost = "DELETE FROM " + this.getTablePrefix() + "boosted_players WHERE end_time = ?";
|
// String deleteBoost = "DELETE FROM " + this.getTablePrefix() + "boosted_players WHERE end_time = ?";
|
||||||
PreparedStatement statement = connection.prepareStatement(deleteBoost);
|
// PreparedStatement statement = connection.prepareStatement(deleteBoost);
|
||||||
statement.setLong(1, boostData.getEndTime());
|
// statement.setLong(1, boostData.getEndTime());
|
||||||
statement.executeUpdate();
|
// statement.executeUpdate();
|
||||||
} catch (Exception ex) {
|
// } catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
// ex.printStackTrace();
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void createLink(Hopper hopper, Location location, LinkType type) {
|
// public void deleteLink(HopperImpl hopper, Location location) {
|
||||||
this.runAsync(() -> {
|
// this.runAsync(() -> {
|
||||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
// try (Connection connection = this.databaseConnector.getConnection()) {
|
||||||
String createLink = "INSERT INTO " + this.getTablePrefix() + "links (hopper_id, link_type, world, x, y, z) VALUES (?, ?, ?, ?, ?, ?)";
|
// String deleteLink = "DELETE FROM " + this.getTablePrefix() + "links WHERE hopper_id = ? AND world = ? AND x = ? AND y = ? AND z = ?";
|
||||||
PreparedStatement statement = connection.prepareStatement(createLink);
|
// PreparedStatement statement = connection.prepareStatement(deleteLink);
|
||||||
statement.setInt(1, hopper.getId());
|
// statement.setInt(1, hopper.getId());
|
||||||
|
// statement.setString(2, location.getWorld().getName());
|
||||||
statement.setString(2, type.name());
|
// statement.setInt(3, location.getBlockX());
|
||||||
|
// statement.setInt(4, location.getBlockY());
|
||||||
statement.setString(3, location.getWorld().getName());
|
// statement.setInt(5, location.getBlockZ());
|
||||||
statement.setInt(4, location.getBlockX());
|
// statement.executeUpdate();
|
||||||
statement.setInt(5, location.getBlockY());
|
// } catch (Exception ex) {
|
||||||
statement.setInt(6, location.getBlockZ());
|
// ex.printStackTrace();
|
||||||
statement.executeUpdate();
|
// }
|
||||||
} catch (Exception ex) {
|
// });
|
||||||
ex.printStackTrace();
|
// }
|
||||||
}
|
//
|
||||||
});
|
// @Override
|
||||||
}
|
// public void deleteLinks(HopperImpl hopper) {
|
||||||
|
// this.runAsync(() -> {
|
||||||
@Override
|
// try (Connection connection = this.databaseConnector.getConnection()) {
|
||||||
public void updateItems(Hopper hopper, ItemType type, List<ItemStack> items) {
|
// String deleteHopperLinks = "DELETE FROM " + this.getTablePrefix() + "links WHERE hopper_id = ?";
|
||||||
this.runAsync(() -> {
|
// PreparedStatement statement = connection.prepareStatement(deleteHopperLinks);
|
||||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
// statement.setInt(1, hopper.getId());
|
||||||
String clearItems = "DELETE FROM " + this.getTablePrefix() + "items WHERE hopper_id = ? AND item_type = ?";
|
// statement.executeUpdate();
|
||||||
try (PreparedStatement statement = connection.prepareStatement(clearItems)) {
|
// } catch (Exception ex) {
|
||||||
statement.setInt(1, hopper.getId());
|
// ex.printStackTrace();
|
||||||
statement.setString(2, type.name());
|
// }
|
||||||
statement.executeUpdate();
|
// });
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
String createItem = "INSERT INTO " + this.getTablePrefix() + "items (hopper_id, item_type, item) VALUES (?, ?, ?)";
|
// @Override
|
||||||
try (PreparedStatement statement = connection.prepareStatement(createItem)) {
|
// public void createHoppers(List<HopperImpl> hoppers) {
|
||||||
for (ItemStack item : items) {
|
// for (HopperImpl hopper : hoppers) {
|
||||||
statement.setInt(1, hopper.getId());
|
// createHopper(hopper);
|
||||||
statement.setString(2, type.name());
|
// }
|
||||||
|
// }
|
||||||
try (ByteArrayOutputStream stream = new ByteArrayOutputStream(); BukkitObjectOutputStream bukkitStream = new BukkitObjectOutputStream(stream)) {
|
//
|
||||||
bukkitStream.writeObject(item);
|
// @Override
|
||||||
statement.setString(3, Base64.getEncoder().encodeToString(stream.toByteArray()));
|
// public void createHopper(HopperImpl hopper) {
|
||||||
} catch (IOException e) {
|
// this.runAsync(() -> {
|
||||||
e.printStackTrace();
|
// try (Connection connection = this.databaseConnector.getConnection()) {
|
||||||
continue;
|
// String createHopper = "INSERT INTO " + this.getTablePrefix() + "placed_hoppers (level, placed_by, last_opened_by, teleport_trigger, world, x, y, z) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
}
|
// try (PreparedStatement statement = connection.prepareStatement(createHopper)) {
|
||||||
statement.addBatch();
|
// statement.setInt(1, hopper.getLevel().getLevel());
|
||||||
}
|
//
|
||||||
statement.executeBatch();
|
// statement.setString(2,
|
||||||
}
|
// hopper.getPlacedBy() == null ? null : hopper.getPlacedBy().toString());
|
||||||
} catch (Exception ex) {
|
//
|
||||||
ex.printStackTrace();
|
// statement.setString(3,
|
||||||
}
|
// hopper.getLastPlayerOpened() == null ? null : hopper.getLastPlayerOpened().toString());
|
||||||
});
|
//
|
||||||
}
|
// statement.setString(4, hopper.getTeleportTrigger().name());
|
||||||
|
//
|
||||||
@Override
|
// statement.setString(5, hopper.getWorld().getName());
|
||||||
public void deleteLink(Hopper hopper, Location location) {
|
// statement.setInt(6, hopper.getX());
|
||||||
this.runAsync(() -> {
|
// statement.setInt(7, hopper.getY());
|
||||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
// statement.setInt(8, hopper.getZ());
|
||||||
String deleteLink = "DELETE FROM " + this.getTablePrefix() + "links WHERE hopper_id = ? AND world = ? AND x = ? AND y = ? AND z = ?";
|
// statement.executeUpdate();
|
||||||
PreparedStatement statement = connection.prepareStatement(deleteLink);
|
// }
|
||||||
statement.setInt(1, hopper.getId());
|
//
|
||||||
statement.setString(2, location.getWorld().getName());
|
// int hopperId = this.lastInsertedId(connection, "placed_hoppers");
|
||||||
statement.setInt(3, location.getBlockX());
|
// hopper.setId(hopperId);
|
||||||
statement.setInt(4, location.getBlockY());
|
//
|
||||||
statement.setInt(5, location.getBlockZ());
|
// Map<ItemStack, ItemType> items = new HashMap<>();
|
||||||
statement.executeUpdate();
|
// Filter filter = hopper.getFilter();
|
||||||
} catch (Exception ex) {
|
//
|
||||||
ex.printStackTrace();
|
// for (ItemStack item : filter.getWhiteList()) {
|
||||||
}
|
// items.put(item, ItemType.WHITELIST);
|
||||||
});
|
// }
|
||||||
}
|
//
|
||||||
|
// for (ItemStack item : filter.getBlackList()) {
|
||||||
@Override
|
// items.put(item, ItemType.BLACKLIST);
|
||||||
public void deleteLinks(Hopper hopper) {
|
// }
|
||||||
this.runAsync(() -> {
|
//
|
||||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
// for (ItemStack item : filter.getVoidList()) {
|
||||||
String deleteHopperLinks = "DELETE FROM " + this.getTablePrefix() + "links WHERE hopper_id = ?";
|
// items.put(item, ItemType.VOID);
|
||||||
PreparedStatement statement = connection.prepareStatement(deleteHopperLinks);
|
// }
|
||||||
statement.setInt(1, hopper.getId());
|
//
|
||||||
statement.executeUpdate();
|
// for (ItemStack item : filter.getAutoSellWhiteList()) {
|
||||||
} catch (Exception ex) {
|
// items.put(item, ItemType.AUTO_SELL_WHITELIST);
|
||||||
ex.printStackTrace();
|
// }
|
||||||
}
|
//
|
||||||
});
|
// for (ItemStack item : filter.getAutoSellBlackList()) {
|
||||||
}
|
// items.put(item, ItemType.AUTO_SELL_BLACKLIST);
|
||||||
|
// }
|
||||||
@Override
|
//
|
||||||
public void createHoppers(List<Hopper> hoppers) {
|
// String createItem = "INSERT INTO " + this.getTablePrefix() + "items (hopper_id, item_type, item) VALUES (?, ?, ?)";
|
||||||
for (Hopper hopper : hoppers) {
|
// try (PreparedStatement statement = connection.prepareStatement(createItem)) {
|
||||||
createHopper(hopper);
|
// for (Map.Entry<ItemStack, ItemType> entry : items.entrySet()) {
|
||||||
}
|
// statement.setInt(1, hopper.getId());
|
||||||
}
|
// statement.setString(2, entry.getValue().name());
|
||||||
|
//
|
||||||
@Override
|
// try (ByteArrayOutputStream stream = new ByteArrayOutputStream(); BukkitObjectOutputStream bukkitStream = new BukkitObjectOutputStream(stream)) {
|
||||||
public void createHopper(Hopper hopper) {
|
// bukkitStream.writeObject(entry.getKey());
|
||||||
this.runAsync(() -> {
|
// statement.setString(3, Base64.getEncoder().encodeToString(stream.toByteArray()));
|
||||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
// } catch (IOException e) {
|
||||||
String createHopper = "INSERT INTO " + this.getTablePrefix() + "placed_hoppers (level, placed_by, last_opened_by, teleport_trigger, world, x, y, z) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
// e.printStackTrace();
|
||||||
try (PreparedStatement statement = connection.prepareStatement(createHopper)) {
|
// continue;
|
||||||
statement.setInt(1, hopper.getLevel().getLevel());
|
// }
|
||||||
|
// statement.addBatch();
|
||||||
statement.setString(2,
|
// }
|
||||||
hopper.getPlacedBy() == null ? null : hopper.getPlacedBy().toString());
|
// statement.executeBatch();
|
||||||
|
// }
|
||||||
statement.setString(3,
|
//
|
||||||
hopper.getLastPlayerOpened() == null ? null : hopper.getLastPlayerOpened().toString());
|
// Map<Location, LinkType> links = new HashMap<>();
|
||||||
|
//
|
||||||
statement.setString(4, hopper.getTeleportTrigger().name());
|
// for (Location location : hopper.getLinkedBlocks()) {
|
||||||
|
// links.put(location, LinkType.REGULAR);
|
||||||
statement.setString(5, hopper.getWorld().getName());
|
// }
|
||||||
statement.setInt(6, hopper.getX());
|
//
|
||||||
statement.setInt(7, hopper.getY());
|
// if (filter.getEndPoint() != null) {
|
||||||
statement.setInt(8, hopper.getZ());
|
// links.put(filter.getEndPoint(), LinkType.REJECT);
|
||||||
statement.executeUpdate();
|
// }
|
||||||
}
|
//
|
||||||
|
// String createLink = "INSERT INTO " + this.getTablePrefix() + "links (hopper_id, link_type, world, x, y, z) VALUES (?, ?, ?, ?, ?, ?)";
|
||||||
int hopperId = this.lastInsertedId(connection, "placed_hoppers");
|
// try (PreparedStatement statement = connection.prepareStatement(createLink)) {
|
||||||
hopper.setId(hopperId);
|
// for (Map.Entry<Location, LinkType> entry : links.entrySet()) {
|
||||||
|
// statement.setInt(1, hopper.getId());
|
||||||
Map<ItemStack, ItemType> items = new HashMap<>();
|
//
|
||||||
Filter filter = hopper.getFilter();
|
// statement.setString(2, entry.getValue().name());
|
||||||
|
//
|
||||||
for (ItemStack item : filter.getWhiteList()) {
|
// Location location = entry.getKey();
|
||||||
items.put(item, ItemType.WHITELIST);
|
// statement.setString(3, location.getWorld().getName());
|
||||||
}
|
// statement.setInt(4, location.getBlockX());
|
||||||
|
// statement.setInt(5, location.getBlockY());
|
||||||
for (ItemStack item : filter.getBlackList()) {
|
// statement.setInt(6, location.getBlockZ());
|
||||||
items.put(item, ItemType.BLACKLIST);
|
// statement.addBatch();
|
||||||
}
|
// }
|
||||||
|
// statement.executeBatch();
|
||||||
for (ItemStack item : filter.getVoidList()) {
|
// }
|
||||||
items.put(item, ItemType.VOID);
|
// } catch (Exception ex) {
|
||||||
}
|
// ex.printStackTrace();
|
||||||
|
// }
|
||||||
for (ItemStack item : filter.getAutoSellWhiteList()) {
|
// });
|
||||||
items.put(item, ItemType.AUTO_SELL_WHITELIST);
|
// }
|
||||||
}
|
//
|
||||||
|
// @Override
|
||||||
for (ItemStack item : filter.getAutoSellBlackList()) {
|
// public void updateHopper(HopperImpl hopper) {
|
||||||
items.put(item, ItemType.AUTO_SELL_BLACKLIST);
|
// this.runAsync(() -> {
|
||||||
}
|
// try (Connection connection = this.databaseConnector.getConnection()) {
|
||||||
|
// String updateHopper = "UPDATE " + this.getTablePrefix() + "placed_hoppers SET level = ?, placed_by = ?, last_opened_by = ?, teleport_trigger = ? WHERE id = ?";
|
||||||
String createItem = "INSERT INTO " + this.getTablePrefix() + "items (hopper_id, item_type, item) VALUES (?, ?, ?)";
|
// PreparedStatement statement = connection.prepareStatement(updateHopper);
|
||||||
try (PreparedStatement statement = connection.prepareStatement(createItem)) {
|
// statement.setInt(1, hopper.getLevel().getLevel());
|
||||||
for (Map.Entry<ItemStack, ItemType> entry : items.entrySet()) {
|
// statement.setString(2, hopper.getPlacedBy().toString());
|
||||||
statement.setInt(1, hopper.getId());
|
// statement.setString(3, hopper.getLastPlayerOpened().toString());
|
||||||
statement.setString(2, entry.getValue().name());
|
// statement.setString(4, hopper.getTeleportTrigger().name());
|
||||||
|
// statement.setInt(5, hopper.getId());
|
||||||
try (ByteArrayOutputStream stream = new ByteArrayOutputStream(); BukkitObjectOutputStream bukkitStream = new BukkitObjectOutputStream(stream)) {
|
// statement.executeUpdate();
|
||||||
bukkitStream.writeObject(entry.getKey());
|
// } catch (Exception ex) {
|
||||||
statement.setString(3, Base64.getEncoder().encodeToString(stream.toByteArray()));
|
// ex.printStackTrace();
|
||||||
} catch (IOException e) {
|
// }
|
||||||
e.printStackTrace();
|
// });
|
||||||
continue;
|
// }
|
||||||
}
|
//
|
||||||
statement.addBatch();
|
// @Override
|
||||||
}
|
// public void deleteHopper(HopperImpl hopper) {
|
||||||
statement.executeBatch();
|
// this.runAsync(() -> {
|
||||||
}
|
// try (Connection connection = this.databaseConnector.getConnection()) {
|
||||||
|
// String deleteHopper = "DELETE FROM " + this.getTablePrefix() + "placed_hoppers WHERE id = ?";
|
||||||
Map<Location, LinkType> links = new HashMap<>();
|
// try (PreparedStatement statement = connection.prepareStatement(deleteHopper)) {
|
||||||
|
// statement.setInt(1, hopper.getId());
|
||||||
for (Location location : hopper.getLinkedBlocks()) {
|
// statement.executeUpdate();
|
||||||
links.put(location, LinkType.REGULAR);
|
// }
|
||||||
}
|
//
|
||||||
|
// String deleteHopperLinks = "DELETE FROM " + this.getTablePrefix() + "links WHERE hopper_id = ?";
|
||||||
if (filter.getEndPoint() != null) {
|
// try (PreparedStatement statement = connection.prepareStatement(deleteHopperLinks)) {
|
||||||
links.put(filter.getEndPoint(), LinkType.REJECT);
|
// statement.setInt(1, hopper.getId());
|
||||||
}
|
// statement.executeUpdate();
|
||||||
|
// }
|
||||||
String createLink = "INSERT INTO " + this.getTablePrefix() + "links (hopper_id, link_type, world, x, y, z) VALUES (?, ?, ?, ?, ?, ?)";
|
//
|
||||||
try (PreparedStatement statement = connection.prepareStatement(createLink)) {
|
// String deleteItems = "DELETE FROM " + this.getTablePrefix() + "items WHERE hopper_id = ?";
|
||||||
for (Map.Entry<Location, LinkType> entry : links.entrySet()) {
|
// try (PreparedStatement statement = connection.prepareStatement(deleteItems)) {
|
||||||
statement.setInt(1, hopper.getId());
|
// statement.setInt(1, hopper.getId());
|
||||||
|
// statement.executeUpdate();
|
||||||
statement.setString(2, entry.getValue().name());
|
// }
|
||||||
|
// } catch (Exception ex) {
|
||||||
Location location = entry.getKey();
|
// ex.printStackTrace();
|
||||||
statement.setString(3, location.getWorld().getName());
|
// }
|
||||||
statement.setInt(4, location.getBlockX());
|
// });
|
||||||
statement.setInt(5, location.getBlockY());
|
// }
|
||||||
statement.setInt(6, location.getBlockZ());
|
//
|
||||||
statement.addBatch();
|
// @Override
|
||||||
}
|
// public void getHoppers(Consumer<Map<Integer, HopperImpl>> callback) {
|
||||||
statement.executeBatch();
|
// this.runAsync(() -> {
|
||||||
}
|
// try (Connection connection = this.databaseConnector.getConnection()) {
|
||||||
} catch (Exception ex) {
|
// Map<Integer, HopperImpl> hoppers = new HashMap<>();
|
||||||
ex.printStackTrace();
|
//
|
||||||
}
|
// try (Statement statement = connection.createStatement()) {
|
||||||
});
|
// String selectHoppers = "SELECT * FROM " + this.getTablePrefix() + "placed_hoppers";
|
||||||
}
|
// ResultSet result = statement.executeQuery(selectHoppers);
|
||||||
|
// while (result.next()) {
|
||||||
@Override
|
// World world = Bukkit.getWorld(result.getString("world"));
|
||||||
public void updateHopper(Hopper hopper) {
|
//
|
||||||
this.runAsync(() -> {
|
// if (world == null) {
|
||||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
// continue;
|
||||||
String updateHopper = "UPDATE " + this.getTablePrefix() + "placed_hoppers SET level = ?, placed_by = ?, last_opened_by = ?, teleport_trigger = ? WHERE id = ?";
|
// }
|
||||||
PreparedStatement statement = connection.prepareStatement(updateHopper);
|
//
|
||||||
statement.setInt(1, hopper.getLevel().getLevel());
|
// int id = result.getInt("id");
|
||||||
statement.setString(2, hopper.getPlacedBy().toString());
|
// int level = result.getInt("level");
|
||||||
statement.setString(3, hopper.getLastPlayerOpened().toString());
|
//
|
||||||
statement.setString(4, hopper.getTeleportTrigger().name());
|
// String placedByStr = result.getString("placed_by");
|
||||||
statement.setInt(5, hopper.getId());
|
// UUID placedBy = placedByStr == null ? null : UUID.fromString(result.getString("placed_by"));
|
||||||
statement.executeUpdate();
|
//
|
||||||
} catch (Exception ex) {
|
// String lastOpenedByStr = result.getString("last_opened_by");
|
||||||
ex.printStackTrace();
|
// UUID lastOpenedBy = lastOpenedByStr == null ? null : UUID.fromString(result.getString("last_opened_by"));
|
||||||
}
|
//
|
||||||
});
|
// TeleportTrigger teleportTrigger = TeleportTrigger.valueOf(result.getString("teleport_trigger"));
|
||||||
}
|
//
|
||||||
|
// int x = result.getInt("x");
|
||||||
@Override
|
// int y = result.getInt("y");
|
||||||
public void deleteHopper(Hopper hopper) {
|
// int z = result.getInt("z");
|
||||||
this.runAsync(() -> {
|
// Location location = new Location(world, x, y, z);
|
||||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
//
|
||||||
String deleteHopper = "DELETE FROM " + this.getTablePrefix() + "placed_hoppers WHERE id = ?";
|
// HopperImpl hopper = new HopperBuilder(location)
|
||||||
try (PreparedStatement statement = connection.prepareStatement(deleteHopper)) {
|
// .setId(id)
|
||||||
statement.setInt(1, hopper.getId());
|
// .setLevel(((EpicHoppers) this.plugin).getLevelManager().getLevel(level))
|
||||||
statement.executeUpdate();
|
// .setPlacedBy(placedBy)
|
||||||
}
|
// .setLastPlayerOpened(lastOpenedBy)
|
||||||
|
// .setTeleportTrigger(teleportTrigger)
|
||||||
String deleteHopperLinks = "DELETE FROM " + this.getTablePrefix() + "links WHERE hopper_id = ?";
|
// .build();
|
||||||
try (PreparedStatement statement = connection.prepareStatement(deleteHopperLinks)) {
|
//
|
||||||
statement.setInt(1, hopper.getId());
|
// hoppers.put(id, hopper);
|
||||||
statement.executeUpdate();
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
String deleteItems = "DELETE FROM " + this.getTablePrefix() + "items WHERE hopper_id = ?";
|
// try (Statement statement = connection.createStatement()) {
|
||||||
try (PreparedStatement statement = connection.prepareStatement(deleteItems)) {
|
// String selectLinks = "SELECT * FROM " + this.getTablePrefix() + "links";
|
||||||
statement.setInt(1, hopper.getId());
|
// ResultSet result = statement.executeQuery(selectLinks);
|
||||||
statement.executeUpdate();
|
// while (result.next()) {
|
||||||
}
|
// World world = Bukkit.getWorld(result.getString("world"));
|
||||||
} catch (Exception ex) {
|
//
|
||||||
ex.printStackTrace();
|
// if (world == null) {
|
||||||
}
|
// continue;
|
||||||
});
|
// }
|
||||||
}
|
//
|
||||||
|
// int id = result.getInt("hopper_id");
|
||||||
@Override
|
// LinkType type = LinkType.valueOf(result.getString("link_type"));
|
||||||
public void getHoppers(Consumer<Map<Integer, Hopper>> callback) {
|
//
|
||||||
this.runAsync(() -> {
|
// int x = result.getInt("x");
|
||||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
// int y = result.getInt("y");
|
||||||
Map<Integer, Hopper> hoppers = new HashMap<>();
|
// int z = result.getInt("z");
|
||||||
|
// Location location = new Location(world, x, y, z);
|
||||||
try (Statement statement = connection.createStatement()) {
|
//
|
||||||
String selectHoppers = "SELECT * FROM " + this.getTablePrefix() + "placed_hoppers";
|
// HopperImpl hopper = hoppers.get(id);
|
||||||
ResultSet result = statement.executeQuery(selectHoppers);
|
// if (hopper == null) {
|
||||||
while (result.next()) {
|
// break;
|
||||||
World world = Bukkit.getWorld(result.getString("world"));
|
// }
|
||||||
|
//
|
||||||
if (world == null) {
|
// hopper.addLinkedBlock(location, type);
|
||||||
continue;
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
int id = result.getInt("id");
|
// try (Statement statement = connection.createStatement()) {
|
||||||
int level = result.getInt("level");
|
// String selectItems = "SELECT * FROM " + this.getTablePrefix() + "items";
|
||||||
|
// ResultSet result = statement.executeQuery(selectItems);
|
||||||
String placedByStr = result.getString("placed_by");
|
// while (result.next()) {
|
||||||
UUID placedBy = placedByStr == null ? null : UUID.fromString(result.getString("placed_by"));
|
// int id = result.getInt("hopper_id");
|
||||||
|
// ItemType type = ItemType.valueOf(result.getString("item_type"));
|
||||||
String lastOpenedByStr = result.getString("last_opened_by");
|
//
|
||||||
UUID lastOpenedBy = lastOpenedByStr == null ? null : UUID.fromString(result.getString("last_opened_by"));
|
// ItemStack item = null;
|
||||||
|
// try (BukkitObjectInputStream stream = new BukkitObjectInputStream(
|
||||||
TeleportTrigger teleportTrigger = TeleportTrigger.valueOf(result.getString("teleport_trigger"));
|
// new ByteArrayInputStream(Base64.getDecoder().decode(result.getString("item"))))) {
|
||||||
|
// item = (ItemStack) stream.readObject();
|
||||||
int x = result.getInt("x");
|
// } catch (IOException | ClassNotFoundException e) {
|
||||||
int y = result.getInt("y");
|
// e.printStackTrace();
|
||||||
int z = result.getInt("z");
|
// }
|
||||||
Location location = new Location(world, x, y, z);
|
//
|
||||||
|
// HopperImpl hopper = hoppers.get(id);
|
||||||
Hopper hopper = new HopperBuilder(location)
|
// if (hopper == null) {
|
||||||
.setId(id)
|
// break;
|
||||||
.setLevel(((EpicHoppers) this.plugin).getLevelManager().getLevel(level))
|
// }
|
||||||
.setPlacedBy(placedBy)
|
//
|
||||||
.setLastPlayerOpened(lastOpenedBy)
|
// if (item != null) {
|
||||||
.setTeleportTrigger(teleportTrigger)
|
// hopper.getFilter().addItem(item, type);
|
||||||
.build();
|
// }
|
||||||
|
// }
|
||||||
hoppers.put(id, hopper);
|
// }
|
||||||
}
|
// this.sync(() -> callback.accept(hoppers));
|
||||||
}
|
// } catch (Exception ex) {
|
||||||
|
// ex.printStackTrace();
|
||||||
try (Statement statement = connection.createStatement()) {
|
// }
|
||||||
String selectLinks = "SELECT * FROM " + this.getTablePrefix() + "links";
|
// });
|
||||||
ResultSet result = statement.executeQuery(selectLinks);
|
// }
|
||||||
while (result.next()) {
|
|
||||||
World world = Bukkit.getWorld(result.getString("world"));
|
|
||||||
|
|
||||||
if (world == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = result.getInt("hopper_id");
|
|
||||||
LinkType type = LinkType.valueOf(result.getString("link_type"));
|
|
||||||
|
|
||||||
int x = result.getInt("x");
|
|
||||||
int y = result.getInt("y");
|
|
||||||
int z = result.getInt("z");
|
|
||||||
Location location = new Location(world, x, y, z);
|
|
||||||
|
|
||||||
Hopper hopper = hoppers.get(id);
|
|
||||||
if (hopper == null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
hopper.addLinkedBlock(location, type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try (Statement statement = connection.createStatement()) {
|
|
||||||
String selectItems = "SELECT * FROM " + this.getTablePrefix() + "items";
|
|
||||||
ResultSet result = statement.executeQuery(selectItems);
|
|
||||||
while (result.next()) {
|
|
||||||
int id = result.getInt("hopper_id");
|
|
||||||
ItemType type = ItemType.valueOf(result.getString("item_type"));
|
|
||||||
|
|
||||||
ItemStack item = null;
|
|
||||||
try (BukkitObjectInputStream stream = new BukkitObjectInputStream(
|
|
||||||
new ByteArrayInputStream(Base64.getDecoder().decode(result.getString("item"))))) {
|
|
||||||
item = (ItemStack) stream.readObject();
|
|
||||||
} catch (IOException | ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
Hopper hopper = hoppers.get(id);
|
|
||||||
if (hopper == null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item != null) {
|
|
||||||
hopper.getFilter().addItem(item, type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.sync(() -> callback.accept(hoppers));
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.craftaro.epichoppers.database.migrations;
|
package com.craftaro.epichoppers.database.migrations;
|
||||||
|
|
||||||
import com.craftaro.core.database.DataMigration;
|
import com.craftaro.core.database.DataMigration;
|
||||||
|
import com.craftaro.core.database.DatabaseConnector;
|
||||||
import com.craftaro.core.database.MySQLConnector;
|
import com.craftaro.core.database.MySQLConnector;
|
||||||
import com.craftaro.epichoppers.EpicHoppers;
|
import com.craftaro.epichoppers.EpicHoppers;
|
||||||
|
|
||||||
@ -17,13 +18,12 @@ public class _1_InitialMigration extends DataMigration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void migrate(Connection connection, String tablePrefix) throws SQLException {
|
public void migrate(DatabaseConnector databaseConnector, String tablePrefix) throws SQLException {
|
||||||
String autoIncrement = this.plugin.getDatabaseConnector() instanceof MySQLConnector ? " AUTO_INCREMENT" : "";
|
|
||||||
|
|
||||||
// Create hoppers table
|
// Create hoppers table
|
||||||
try (Statement statement = connection.createStatement()) {
|
try (Statement statement = databaseConnector.getConnection().createStatement()) {
|
||||||
statement.execute("CREATE TABLE " + tablePrefix + "placed_hoppers (" +
|
statement.execute("CREATE TABLE " + tablePrefix + "placed_hoppers (" +
|
||||||
"id INTEGER PRIMARY KEY" + autoIncrement + ", " +
|
"id INTEGER PRIMARY KEY AUTO_INCREMENT" + ", " +
|
||||||
"level INTEGER NOT NULL, " +
|
"level INTEGER NOT NULL, " +
|
||||||
"placed_by VARCHAR(36), " +
|
"placed_by VARCHAR(36), " +
|
||||||
"last_opened_by VARCHAR(36), " +
|
"last_opened_by VARCHAR(36), " +
|
||||||
@ -36,7 +36,7 @@ public class _1_InitialMigration extends DataMigration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create hopper links
|
// Create hopper links
|
||||||
try (Statement statement = connection.createStatement()) {
|
try (Statement statement = databaseConnector.getConnection().createStatement()) {
|
||||||
statement.execute("CREATE TABLE " + tablePrefix + "links (" +
|
statement.execute("CREATE TABLE " + tablePrefix + "links (" +
|
||||||
"hopper_id INTEGER NOT NULL, " +
|
"hopper_id INTEGER NOT NULL, " +
|
||||||
"link_type TEXT NOT NULL," +
|
"link_type TEXT NOT NULL," +
|
||||||
@ -49,7 +49,7 @@ public class _1_InitialMigration extends DataMigration {
|
|||||||
|
|
||||||
// Create items
|
// Create items
|
||||||
// Items are base64.
|
// Items are base64.
|
||||||
try (Statement statement = connection.createStatement()) {
|
try (Statement statement = databaseConnector.getConnection().createStatement()) {
|
||||||
statement.execute("CREATE TABLE " + tablePrefix + "items (" +
|
statement.execute("CREATE TABLE " + tablePrefix + "items (" +
|
||||||
"hopper_id INTEGER NOT NULL, " +
|
"hopper_id INTEGER NOT NULL, " +
|
||||||
"item_type BIT NOT NULL," +
|
"item_type BIT NOT NULL," +
|
||||||
@ -58,7 +58,7 @@ public class _1_InitialMigration extends DataMigration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create player boosts
|
// Create player boosts
|
||||||
try (Statement statement = connection.createStatement()) {
|
try (Statement statement = databaseConnector.getConnection().createStatement()) {
|
||||||
statement.execute("CREATE TABLE " + tablePrefix + "boosted_players (" +
|
statement.execute("CREATE TABLE " + tablePrefix + "boosted_players (" +
|
||||||
"player VARCHAR(36) NOT NULL, " +
|
"player VARCHAR(36) NOT NULL, " +
|
||||||
"multiplier INTEGER NOT NULL," +
|
"multiplier INTEGER NOT NULL," +
|
||||||
|
@ -5,11 +5,12 @@ import com.craftaro.core.gui.CustomizableGui;
|
|||||||
import com.craftaro.core.gui.GuiUtils;
|
import com.craftaro.core.gui.GuiUtils;
|
||||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||||
import com.craftaro.core.utils.TextUtils;
|
import com.craftaro.core.utils.TextUtils;
|
||||||
import com.craftaro.epichoppers.EpicHoppersApi;
|
|
||||||
import com.craftaro.epichoppers.hopper.Filter;
|
import com.craftaro.epichoppers.hopper.Filter;
|
||||||
import com.craftaro.epichoppers.hopper.Hopper;
|
import com.craftaro.epichoppers.hopper.Hopper;
|
||||||
|
import com.craftaro.epichoppers.hopper.HopperImpl;
|
||||||
import com.craftaro.epichoppers.hopper.ItemType;
|
import com.craftaro.epichoppers.hopper.ItemType;
|
||||||
import com.craftaro.epichoppers.settings.Settings;
|
import com.craftaro.epichoppers.settings.Settings;
|
||||||
|
import com.craftaro.epichoppers.utils.DataHelper;
|
||||||
import com.craftaro.epichoppers.utils.Methods;
|
import com.craftaro.epichoppers.utils.Methods;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -21,14 +22,14 @@ import java.util.List;
|
|||||||
public class GUIAutoSellFilter extends CustomizableGui {
|
public class GUIAutoSellFilter extends CustomizableGui {
|
||||||
private static final List<GUIAutoSellFilter> OPEN_INVENTORIES = new ArrayList<>();
|
private static final List<GUIAutoSellFilter> OPEN_INVENTORIES = new ArrayList<>();
|
||||||
|
|
||||||
private final Hopper hopper;
|
private final HopperImpl hopper;
|
||||||
|
|
||||||
private final int[] whiteListSlots = {9, 10, 11, 18, 19, 20, 27, 28, 29, 36, 37, 38};
|
private final int[] whiteListSlots = {9, 10, 11, 18, 19, 20, 27, 28, 29, 36, 37, 38};
|
||||||
private final int[] blackListSlots = {12, 13, 14, 21, 22, 23, 30, 31, 32, 39, 40, 41};
|
private final int[] blackListSlots = {12, 13, 14, 21, 22, 23, 30, 31, 32, 39, 40, 41};
|
||||||
|
|
||||||
public GUIAutoSellFilter(SongodaPlugin plugin, Hopper hopper) {
|
public GUIAutoSellFilter(SongodaPlugin plugin, Hopper hopper) {
|
||||||
super(plugin, "autosell");
|
super(plugin, "autosell");
|
||||||
this.hopper = hopper;
|
this.hopper = (HopperImpl) hopper;
|
||||||
|
|
||||||
setRows(6);
|
setRows(6);
|
||||||
setTitle(TextUtils.formatText(Methods.formatName(hopper.getLevel().getLevel()) + " &8-&f AutoSell Filter"));
|
setTitle(TextUtils.formatText(Methods.formatName(hopper.getLevel().getLevel()) + " &8-&f AutoSell Filter"));
|
||||||
@ -62,7 +63,7 @@ public class GUIAutoSellFilter extends CustomizableGui {
|
|||||||
setButton("back", 8, GuiUtils.createButtonItem(XMaterial.ARROW.parseItem(),
|
setButton("back", 8, GuiUtils.createButtonItem(XMaterial.ARROW.parseItem(),
|
||||||
plugin.getLocale().getMessage("general.nametag.back").getMessage()),
|
plugin.getLocale().getMessage("general.nametag.back").getMessage()),
|
||||||
(event) -> {
|
(event) -> {
|
||||||
if (hopper.prepareForOpeningOverviewGui(event.player)) {
|
if (this.hopper.prepareForOpeningOverviewGui(event.player)) {
|
||||||
this.guiManager.showGUI(event.player, new GUIOverview(plugin, hopper, event.player));
|
this.guiManager.showGUI(event.player, new GUIOverview(plugin, hopper, event.player));
|
||||||
}
|
}
|
||||||
compile();
|
compile();
|
||||||
@ -180,11 +181,11 @@ public class GUIAutoSellFilter extends CustomizableGui {
|
|||||||
|
|
||||||
filter.setAutoSellWhiteList(whiteListItems);
|
filter.setAutoSellWhiteList(whiteListItems);
|
||||||
filter.setAutoSellBlackList(blackListItems);
|
filter.setAutoSellBlackList(blackListItems);
|
||||||
EpicHoppersApi.getApi().getDataManager().updateItems(this.hopper, ItemType.AUTO_SELL_WHITELIST, whiteListItems);
|
DataHelper.updateItems(this.hopper, ItemType.AUTO_SELL_WHITELIST, whiteListItems);
|
||||||
EpicHoppersApi.getApi().getDataManager().updateItems(this.hopper, ItemType.AUTO_SELL_BLACKLIST, blackListItems);
|
DataHelper.updateItems(this.hopper, ItemType.AUTO_SELL_BLACKLIST, blackListItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void compileOpenAutoSellFilter(Hopper hopper) {
|
public static void compileOpenAutoSellFilter(HopperImpl hopper) {
|
||||||
for (GUIAutoSellFilter autoSellFilter : OPEN_INVENTORIES) {
|
for (GUIAutoSellFilter autoSellFilter : OPEN_INVENTORIES) {
|
||||||
if (autoSellFilter.hopper == hopper) {
|
if (autoSellFilter.hopper == hopper) {
|
||||||
autoSellFilter.compile();
|
autoSellFilter.compile();
|
||||||
|
@ -5,10 +5,11 @@ import com.craftaro.core.gui.CustomizableGui;
|
|||||||
import com.craftaro.core.gui.GuiUtils;
|
import com.craftaro.core.gui.GuiUtils;
|
||||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||||
import com.craftaro.core.utils.TextUtils;
|
import com.craftaro.core.utils.TextUtils;
|
||||||
|
import com.craftaro.epichoppers.hopper.Hopper;
|
||||||
|
import com.craftaro.epichoppers.hopper.HopperImpl;
|
||||||
import com.craftaro.epichoppers.hopper.levels.modules.ModuleAutoCrafting;
|
import com.craftaro.epichoppers.hopper.levels.modules.ModuleAutoCrafting;
|
||||||
import com.craftaro.epichoppers.settings.Settings;
|
import com.craftaro.epichoppers.settings.Settings;
|
||||||
import com.craftaro.epichoppers.utils.Methods;
|
import com.craftaro.epichoppers.utils.Methods;
|
||||||
import com.craftaro.epichoppers.hopper.Hopper;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
@ -38,7 +39,7 @@ public class GUICrafting extends CustomizableGui {
|
|||||||
setButton("back", 8, GuiUtils.createButtonItem(XMaterial.ARROW.parseItem(),
|
setButton("back", 8, GuiUtils.createButtonItem(XMaterial.ARROW.parseItem(),
|
||||||
plugin.getLocale().getMessage("general.nametag.back").getMessage()),
|
plugin.getLocale().getMessage("general.nametag.back").getMessage()),
|
||||||
(event) -> {
|
(event) -> {
|
||||||
if (hopper.prepareForOpeningOverviewGui(event.player)) {
|
if (((HopperImpl)hopper).prepareForOpeningOverviewGui(event.player)) {
|
||||||
this.guiManager.showGUI(event.player, new GUIOverview(plugin, hopper, event.player));
|
this.guiManager.showGUI(event.player, new GUIOverview(plugin, hopper, event.player));
|
||||||
}
|
}
|
||||||
setItem(module, hopper, player);
|
setItem(module, hopper, player);
|
||||||
|
@ -6,12 +6,14 @@ import com.craftaro.core.gui.GuiUtils;
|
|||||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||||
import com.craftaro.core.utils.TextUtils;
|
import com.craftaro.core.utils.TextUtils;
|
||||||
import com.craftaro.epichoppers.EpicHoppersApi;
|
import com.craftaro.epichoppers.EpicHoppersApi;
|
||||||
|
import com.craftaro.epichoppers.hopper.Hopper;
|
||||||
import com.craftaro.epichoppers.hopper.ItemType;
|
import com.craftaro.epichoppers.hopper.ItemType;
|
||||||
import com.craftaro.epichoppers.player.SyncType;
|
import com.craftaro.epichoppers.player.SyncType;
|
||||||
import com.craftaro.epichoppers.settings.Settings;
|
import com.craftaro.epichoppers.settings.Settings;
|
||||||
|
import com.craftaro.epichoppers.utils.DataHelper;
|
||||||
import com.craftaro.epichoppers.utils.Methods;
|
import com.craftaro.epichoppers.utils.Methods;
|
||||||
import com.craftaro.epichoppers.hopper.Filter;
|
import com.craftaro.epichoppers.hopper.Filter;
|
||||||
import com.craftaro.epichoppers.hopper.Hopper;
|
import com.craftaro.epichoppers.hopper.HopperImpl;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -26,12 +28,12 @@ public class GUIFilter extends CustomizableGui {
|
|||||||
private static final List<GUIFilter> OPEN_INVENTORIES = new ArrayList<>();
|
private static final List<GUIFilter> OPEN_INVENTORIES = new ArrayList<>();
|
||||||
|
|
||||||
private final SongodaPlugin plugin;
|
private final SongodaPlugin plugin;
|
||||||
private final Hopper hopper;
|
private final HopperImpl hopper;
|
||||||
|
|
||||||
public GUIFilter(SongodaPlugin plugin, Hopper hopper, Player player) {
|
public GUIFilter(SongodaPlugin plugin, Hopper hopper, Player player) {
|
||||||
super(plugin, "filter");
|
super(plugin, "filter");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.hopper = hopper;
|
this.hopper = (HopperImpl) hopper;
|
||||||
|
|
||||||
setRows(6);
|
setRows(6);
|
||||||
setTitle(TextUtils.formatText(Methods.formatName(hopper.getLevel().getLevel()) + " &8-&f Filter"));
|
setTitle(TextUtils.formatText(Methods.formatName(hopper.getLevel().getLevel()) + " &8-&f Filter"));
|
||||||
@ -68,7 +70,7 @@ public class GUIFilter extends CustomizableGui {
|
|||||||
setButton("back", 8, GuiUtils.createButtonItem(XMaterial.ARROW.parseItem(),
|
setButton("back", 8, GuiUtils.createButtonItem(XMaterial.ARROW.parseItem(),
|
||||||
plugin.getLocale().getMessage("general.nametag.back").getMessage()),
|
plugin.getLocale().getMessage("general.nametag.back").getMessage()),
|
||||||
(event) -> {
|
(event) -> {
|
||||||
if (hopper.prepareForOpeningOverviewGui(event.player)) {
|
if (this.hopper.prepareForOpeningOverviewGui(event.player)) {
|
||||||
this.guiManager.showGUI(event.player, new GUIOverview(plugin, hopper, event.player));
|
this.guiManager.showGUI(event.player, new GUIOverview(plugin, hopper, event.player));
|
||||||
}
|
}
|
||||||
compile();
|
compile();
|
||||||
@ -235,12 +237,12 @@ public class GUIFilter extends CustomizableGui {
|
|||||||
filter.setWhiteList(owhite);
|
filter.setWhiteList(owhite);
|
||||||
filter.setBlackList(oblack);
|
filter.setBlackList(oblack);
|
||||||
filter.setVoidList(ovoid);
|
filter.setVoidList(ovoid);
|
||||||
EpicHoppersApi.getApi().getDataManager().updateItems(this.hopper, ItemType.WHITELIST, owhite);
|
DataHelper.updateItems(this.hopper, ItemType.WHITELIST, owhite);
|
||||||
EpicHoppersApi.getApi().getDataManager().updateItems(this.hopper, ItemType.BLACKLIST, oblack);
|
DataHelper.updateItems(this.hopper, ItemType.BLACKLIST, oblack);
|
||||||
EpicHoppersApi.getApi().getDataManager().updateItems(this.hopper, ItemType.VOID, ovoid);
|
DataHelper.updateItems(this.hopper, ItemType.VOID, ovoid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void compileOpenGuiFilter(Hopper hopper) {
|
public static void compileOpenGuiFilter(HopperImpl hopper) {
|
||||||
for (GUIFilter guiFilter : OPEN_INVENTORIES) {
|
for (GUIFilter guiFilter : OPEN_INVENTORIES) {
|
||||||
if (guiFilter.hopper == hopper) {
|
if (guiFilter.hopper == hopper) {
|
||||||
guiFilter.compile();
|
guiFilter.compile();
|
||||||
|
@ -8,15 +8,19 @@ import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
|||||||
import com.craftaro.core.utils.NumberUtils;
|
import com.craftaro.core.utils.NumberUtils;
|
||||||
import com.craftaro.core.utils.TextUtils;
|
import com.craftaro.core.utils.TextUtils;
|
||||||
import com.craftaro.core.utils.TimeUtils;
|
import com.craftaro.core.utils.TimeUtils;
|
||||||
|
import com.craftaro.epichoppers.EpicHoppers;
|
||||||
import com.craftaro.epichoppers.EpicHoppersApi;
|
import com.craftaro.epichoppers.EpicHoppersApi;
|
||||||
import com.craftaro.epichoppers.boost.BoostData;
|
import com.craftaro.epichoppers.boost.BoostData;
|
||||||
|
import com.craftaro.epichoppers.boost.BoostDataImpl;
|
||||||
import com.craftaro.epichoppers.hopper.Hopper;
|
import com.craftaro.epichoppers.hopper.Hopper;
|
||||||
|
import com.craftaro.epichoppers.hopper.HopperImpl;
|
||||||
import com.craftaro.epichoppers.hopper.levels.Level;
|
import com.craftaro.epichoppers.hopper.levels.Level;
|
||||||
import com.craftaro.epichoppers.hopper.levels.modules.Module;
|
import com.craftaro.epichoppers.hopper.levels.modules.Module;
|
||||||
import com.craftaro.epichoppers.hopper.teleport.TeleportTrigger;
|
import com.craftaro.epichoppers.hopper.teleport.TeleportTrigger;
|
||||||
import com.craftaro.epichoppers.player.SyncType;
|
import com.craftaro.epichoppers.player.SyncType;
|
||||||
import com.craftaro.epichoppers.settings.Settings;
|
import com.craftaro.epichoppers.settings.Settings;
|
||||||
import com.craftaro.epichoppers.utils.CostType;
|
import com.craftaro.epichoppers.utils.CostType;
|
||||||
|
import com.craftaro.epichoppers.utils.DataHelper;
|
||||||
import com.craftaro.epichoppers.utils.Methods;
|
import com.craftaro.epichoppers.utils.Methods;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -33,7 +37,7 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public class GUIOverview extends CustomizableGui {
|
public class GUIOverview extends CustomizableGui {
|
||||||
private final SongodaPlugin plugin;
|
private final SongodaPlugin plugin;
|
||||||
private final Hopper hopper;
|
private final HopperImpl hopper;
|
||||||
private final Player player;
|
private final Player player;
|
||||||
|
|
||||||
private int task;
|
private int task;
|
||||||
@ -41,7 +45,7 @@ public class GUIOverview extends CustomizableGui {
|
|||||||
public GUIOverview(SongodaPlugin plugin, Hopper hopper, Player player) {
|
public GUIOverview(SongodaPlugin plugin, Hopper hopper, Player player) {
|
||||||
super(plugin, "overview");
|
super(plugin, "overview");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.hopper = hopper;
|
this.hopper = (HopperImpl) hopper;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
|
||||||
setRows(3);
|
setRows(3);
|
||||||
@ -189,7 +193,7 @@ public class GUIOverview extends CustomizableGui {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.hopper.clearLinkedBlocks();
|
this.hopper.clearLinkedBlocks();
|
||||||
EpicHoppersApi.getApi().getDataManager().deleteLinks(this.hopper);
|
DataHelper.deleteLinks(this.hopper);
|
||||||
if (event.clickType == ClickType.RIGHT) {
|
if (event.clickType == ClickType.RIGHT) {
|
||||||
this.plugin.getLocale().getMessage("event.hopper.desync").sendPrefixedMessage(this.player);
|
this.plugin.getLocale().getMessage("event.hopper.desync").sendPrefixedMessage(this.player);
|
||||||
constructGUI();
|
constructGUI();
|
||||||
@ -224,7 +228,7 @@ public class GUIOverview extends CustomizableGui {
|
|||||||
} else if (this.hopper.getTeleportTrigger() == TeleportTrigger.WALK_ON) {
|
} else if (this.hopper.getTeleportTrigger() == TeleportTrigger.WALK_ON) {
|
||||||
this.hopper.setTeleportTrigger(TeleportTrigger.DISABLED);
|
this.hopper.setTeleportTrigger(TeleportTrigger.DISABLED);
|
||||||
}
|
}
|
||||||
EpicHoppersApi.getApi().getDataManager().updateHopper(this.hopper);
|
EpicHoppers.getPlugin(EpicHoppers.class).getDataManager().save(this.hopper);
|
||||||
constructGUI();
|
constructGUI();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -6,10 +6,11 @@ import com.craftaro.core.gui.CustomizableGui;
|
|||||||
import com.craftaro.core.gui.GuiUtils;
|
import com.craftaro.core.gui.GuiUtils;
|
||||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||||
import com.craftaro.core.utils.TextUtils;
|
import com.craftaro.core.utils.TextUtils;
|
||||||
|
import com.craftaro.epichoppers.hopper.Hopper;
|
||||||
|
import com.craftaro.epichoppers.hopper.HopperImpl;
|
||||||
import com.craftaro.epichoppers.hopper.levels.modules.ModuleAutoSmelter;
|
import com.craftaro.epichoppers.hopper.levels.modules.ModuleAutoSmelter;
|
||||||
import com.craftaro.epichoppers.settings.Settings;
|
import com.craftaro.epichoppers.settings.Settings;
|
||||||
import com.craftaro.epichoppers.utils.Methods;
|
import com.craftaro.epichoppers.utils.Methods;
|
||||||
import com.craftaro.epichoppers.hopper.Hopper;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
@ -19,7 +20,7 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public class GUISmeltable extends CustomizableGui {
|
public class GUISmeltable extends CustomizableGui {
|
||||||
private final SongodaPlugin plugin;
|
private final SongodaPlugin plugin;
|
||||||
private final Hopper hopper;
|
private final HopperImpl hopper;
|
||||||
private final int maxPages;
|
private final int maxPages;
|
||||||
private final ModuleAutoSmelter moduleAutoSmelter;
|
private final ModuleAutoSmelter moduleAutoSmelter;
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ public class GUISmeltable extends CustomizableGui {
|
|||||||
public GUISmeltable(ModuleAutoSmelter moduleAutoSmelter, SongodaPlugin plugin, Hopper hopper) {
|
public GUISmeltable(ModuleAutoSmelter moduleAutoSmelter, SongodaPlugin plugin, Hopper hopper) {
|
||||||
super(plugin, "smeltable");
|
super(plugin, "smeltable");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.hopper = hopper;
|
this.hopper = (HopperImpl) hopper;
|
||||||
this.moduleAutoSmelter = moduleAutoSmelter;
|
this.moduleAutoSmelter = moduleAutoSmelter;
|
||||||
|
|
||||||
int smeltables = BURNABLES.size();
|
int smeltables = BURNABLES.size();
|
||||||
|
@ -9,10 +9,10 @@ import org.bukkit.block.Block;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class HopperBuilder {
|
public class HopperBuilder {
|
||||||
private final Hopper hopper;
|
private final HopperImpl hopper;
|
||||||
|
|
||||||
public HopperBuilder(Location location) {
|
public HopperBuilder(Location location) {
|
||||||
this.hopper = new Hopper(location);
|
this.hopper = new HopperImpl(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HopperBuilder(Block block) {
|
public HopperBuilder(Block block) {
|
||||||
@ -65,7 +65,7 @@ public class HopperBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Hopper build() {
|
public HopperImpl build() {
|
||||||
return this.hopper;
|
return this.hopper;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,474 @@
|
|||||||
|
package com.craftaro.epichoppers.hopper;
|
||||||
|
|
||||||
|
import com.craftaro.core.SongodaPlugin;
|
||||||
|
import com.craftaro.core.compatibility.CompatibleParticleHandler;
|
||||||
|
import com.craftaro.core.compatibility.ServerVersion;
|
||||||
|
import com.craftaro.core.database.Data;
|
||||||
|
import com.craftaro.core.database.DataManager;
|
||||||
|
import com.craftaro.core.database.SerializedLocation;
|
||||||
|
import com.craftaro.core.hooks.EconomyManager;
|
||||||
|
import com.craftaro.core.third_party.com.cryptomorin.xseries.XSound;
|
||||||
|
import com.craftaro.core.third_party.org.jooq.impl.DSL;
|
||||||
|
import com.craftaro.epichoppers.EpicHoppers;
|
||||||
|
import com.craftaro.epichoppers.EpicHoppersApi;
|
||||||
|
import com.craftaro.epichoppers.api.events.HopperAccessEvent;
|
||||||
|
import com.craftaro.epichoppers.hopper.levels.Level;
|
||||||
|
import com.craftaro.epichoppers.hopper.levels.LevelManager;
|
||||||
|
import com.craftaro.epichoppers.player.PlayerData;
|
||||||
|
import com.craftaro.epichoppers.player.PlayerDataManager;
|
||||||
|
import com.craftaro.epichoppers.utils.CostType;
|
||||||
|
import com.craftaro.epichoppers.utils.DataHelper;
|
||||||
|
import com.craftaro.epichoppers.utils.Methods;
|
||||||
|
import com.craftaro.epichoppers.hopper.teleport.TeleportTrigger;
|
||||||
|
import com.songoda.skyblock.core.utils.ItemUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FIXME: Needs heavy refactoring to only have one responsibility.
|
||||||
|
*/
|
||||||
|
public class HopperImpl implements Hopper {
|
||||||
|
// Id for database use.
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
private final Location location;
|
||||||
|
private Level level = getLevelManager().getLowestLevel();
|
||||||
|
private UUID lastPlayerOpened = null;
|
||||||
|
private UUID placedBy = null;
|
||||||
|
private final List<Location> linkedBlocks = new ArrayList<>();
|
||||||
|
private Filter filter = new Filter();
|
||||||
|
private TeleportTrigger teleportTrigger = TeleportTrigger.DISABLED;
|
||||||
|
private int transferTick = 0;
|
||||||
|
|
||||||
|
private int syncId = -1;
|
||||||
|
|
||||||
|
private Player activePlayer;
|
||||||
|
|
||||||
|
private final Map<String, Object> moduleCache = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor for database use.
|
||||||
|
*/
|
||||||
|
public HopperImpl() {
|
||||||
|
this.location = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HopperImpl(Location location) {
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for database use.
|
||||||
|
*/
|
||||||
|
public HopperImpl(Map<String, Object> map) {
|
||||||
|
this.id = (int) map.get("id");
|
||||||
|
this.location = SerializedLocation.of(map);
|
||||||
|
this.level = getLevelManager().getLevel((int) map.get("level"));
|
||||||
|
this.lastPlayerOpened = map.get("lastPlayerOpened") == null ? null : UUID.fromString((String) map.get("lastPlayerOpened"));
|
||||||
|
|
||||||
|
DataManager dataManager = EpicHoppers.getPlugin(EpicHoppers.class).getDataManager();
|
||||||
|
dataManager.getDatabaseConnector().connectDSL(dslContext -> {
|
||||||
|
|
||||||
|
//Load links
|
||||||
|
dslContext.select().from(DSL.table(dataManager.getTablePrefix() + "links")).where(DSL.field("hopper_id").eq(id)).fetch().forEach(record -> {
|
||||||
|
this.linkedBlocks.add(new Location(Bukkit.getWorld(record.get("world", String.class)),
|
||||||
|
record.get("x", Double.class),
|
||||||
|
record.get("y", Double.class),
|
||||||
|
record.get("z", Double.class)));
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
//Load filtered items
|
||||||
|
dslContext.select().from(DSL.table(dataManager.getTablePrefix() + "items")).where(DSL.field("hopper_id").eq(id)).fetch().forEach(record -> {
|
||||||
|
ItemStack itemStack = ItemUtils.itemStackArrayFromBase64(record.get("item", String.class))[0];
|
||||||
|
ItemType type = ItemType.valueOf(record.get("item_type", String.class));
|
||||||
|
filter.addItem(itemStack, type);
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiStatus.Internal
|
||||||
|
public boolean prepareForOpeningOverviewGui(Player player) {
|
||||||
|
if (this.lastPlayerOpened != null &&
|
||||||
|
this.lastPlayerOpened != player.getUniqueId() &&
|
||||||
|
Bukkit.getPlayer(this.lastPlayerOpened) != null) {
|
||||||
|
Bukkit.getPlayer(this.lastPlayerOpened).closeInventory();
|
||||||
|
}
|
||||||
|
|
||||||
|
HopperAccessEvent accessEvent = new HopperAccessEvent(player, this);
|
||||||
|
Bukkit.getPluginManager().callEvent(accessEvent);
|
||||||
|
if (accessEvent.isCancelled()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.placedBy == null) {
|
||||||
|
this.placedBy = player.getUniqueId();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!player.hasPermission("epichoppers.overview")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
setActivePlayer(player);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiStatus.Internal
|
||||||
|
public void forceClose() {
|
||||||
|
if (this.activePlayer != null) {
|
||||||
|
this.activePlayer.closeInventory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dropItems() {
|
||||||
|
Inventory inventory = ((InventoryHolder) this.location.getBlock().getState()).getInventory();
|
||||||
|
World world = this.location.getWorld();
|
||||||
|
|
||||||
|
for (ItemStack itemStack : inventory.getContents()) {
|
||||||
|
if (itemStack == null || itemStack.getType() == Material.AIR) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
world.dropItemNaturally(this.location, itemStack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void upgrade(Player player, CostType type) {
|
||||||
|
if (!getLevelManager().getLevels().containsKey(this.level.getLevel() + 1)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Level level = getLevelManager().getLevel(this.level.getLevel() + 1);
|
||||||
|
int cost = type == CostType.ECONOMY ? level.getCostEconomy() : level.getCostExperience();
|
||||||
|
|
||||||
|
if (type == CostType.ECONOMY) {
|
||||||
|
if (!EconomyManager.isEnabled()) {
|
||||||
|
player.sendMessage("Economy not enabled.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!EconomyManager.hasBalance(player, cost)) {
|
||||||
|
getPlugin().getLocale().getMessage("event.upgrade.cannotafford").sendPrefixedMessage(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
EconomyManager.withdrawBalance(player, cost);
|
||||||
|
upgradeFinal(level, player);
|
||||||
|
} else if (type == CostType.EXPERIENCE) {
|
||||||
|
if (player.getLevel() >= cost || player.getGameMode() == GameMode.CREATIVE) {
|
||||||
|
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||||
|
player.setLevel(player.getLevel() - cost);
|
||||||
|
}
|
||||||
|
upgradeFinal(level, player);
|
||||||
|
} else {
|
||||||
|
getPlugin().getLocale().getMessage("event.upgrade.cannotafford").sendPrefixedMessage(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void upgradeFinal(Level level, Player player) {
|
||||||
|
this.level = level;
|
||||||
|
EpicHoppers.getPlugin(EpicHoppers.class).getDataManager().save(this);
|
||||||
|
//TODO save items/links
|
||||||
|
syncName();
|
||||||
|
if (getLevelManager().getHighestLevel() != level) {
|
||||||
|
getPlugin().getLocale().getMessage("event.upgrade.success")
|
||||||
|
.processPlaceholder("level", level.getLevel()).sendPrefixedMessage(player);
|
||||||
|
} else {
|
||||||
|
getPlugin().getLocale().getMessage("event.upgrade.maxed")
|
||||||
|
.processPlaceholder("level", level.getLevel()).sendPrefixedMessage(player);
|
||||||
|
}
|
||||||
|
Location loc = this.location.clone().add(.5, .5, .5);
|
||||||
|
|
||||||
|
if (!getUpgradeParticleType().trim().isEmpty()) {
|
||||||
|
CompatibleParticleHandler.spawnParticles(
|
||||||
|
CompatibleParticleHandler.ParticleType.getParticle(getUpgradeParticleType()),
|
||||||
|
loc, 100, .5, .5, .5);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getLevelManager().getHighestLevel() != level) {
|
||||||
|
XSound.ENTITY_PLAYER_LEVELUP.play(player, .6f, 15);
|
||||||
|
} else {
|
||||||
|
XSound.ENTITY_PLAYER_LEVELUP.play(player, 2, 25);
|
||||||
|
XSound.BLOCK_NOTE_BLOCK_CHIME.play(player, 2, 25);
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), () -> XSound.BLOCK_NOTE_BLOCK_CHIME.play(player, 1.2f, 35), 5);
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), () -> XSound.BLOCK_NOTE_BLOCK_CHIME.play(player, 1.8f, 35), 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void syncName() {
|
||||||
|
org.bukkit.block.Hopper hopper = (org.bukkit.block.Hopper) this.location.getBlock().getState();
|
||||||
|
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_10)) {
|
||||||
|
hopper.setCustomName(Methods.formatName(this.level.getLevel()));
|
||||||
|
}
|
||||||
|
hopper.update(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void timeout(Player player) {
|
||||||
|
this.syncId = Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), () -> {
|
||||||
|
PlayerData playerData = getPlayerDataManager().getPlayerData(player);
|
||||||
|
if (playerData.getSyncType() != null && playerData.getLastHopper() == this) {
|
||||||
|
getPlugin().getLocale().getMessage("event.hopper.synctimeout").sendPrefixedMessage(player);
|
||||||
|
playerData.setSyncType(null);
|
||||||
|
}
|
||||||
|
}, getLinkTimeoutFromPluginConfig() * this.level.getLinkAmount());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void link(Block toLink, boolean filtered, Player player) {
|
||||||
|
if (this.location.getWorld().equals(toLink.getLocation().getWorld())
|
||||||
|
&& !player.hasPermission("EpicHoppers.Override")
|
||||||
|
&& !player.hasPermission("EpicHoppers.Admin")
|
||||||
|
&& this.location.distance(toLink.getLocation()) > this.level.getRange()) {
|
||||||
|
getPlugin().getLocale().getMessage("event.hopper.syncoutofrange").sendPrefixedMessage(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.linkedBlocks.contains(toLink.getLocation())) {
|
||||||
|
getPlugin().getLocale().getMessage("event.hopper.already").sendPrefixedMessage(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!filtered) {
|
||||||
|
this.linkedBlocks.add(toLink.getLocation());
|
||||||
|
DataHelper.createLink(this, toLink.getLocation(), LinkType.REGULAR);
|
||||||
|
} else {
|
||||||
|
this.filter.setEndPoint(toLink.getLocation());
|
||||||
|
DataHelper.createLink(this, toLink.getLocation(), LinkType.REJECT);
|
||||||
|
getPlugin().getLocale().getMessage("event.hopper.syncsuccess").sendPrefixedMessage(player);
|
||||||
|
getPlayerDataManager().getPlayerData(player).setSyncType(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.lastPlayerOpened = player.getUniqueId();
|
||||||
|
|
||||||
|
if (this.level.getLinkAmount() > 1) {
|
||||||
|
if (this.linkedBlocks.size() >= this.level.getLinkAmount()) {
|
||||||
|
getPlugin().getLocale().getMessage("event.hopper.syncdone").sendPrefixedMessage(player);
|
||||||
|
cancelSync(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
getPlugin().getLocale().getMessage("event.hopper.syncsuccessmore")
|
||||||
|
.processPlaceholder("amount", this.level.getLinkAmount() - this.linkedBlocks.size())
|
||||||
|
.sendPrefixedMessage(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
getPlugin().getLocale().getMessage("event.hopper.syncsuccess").sendPrefixedMessage(player);
|
||||||
|
cancelSync(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ticks a hopper to determine when it can transfer items next
|
||||||
|
*
|
||||||
|
* @param maxTick The maximum amount the hopper can be ticked before next transferring items
|
||||||
|
* @param allowLooping If true, the hopper is allowed to transfer items if the tick is also valid
|
||||||
|
* @return true if the hopper should transfer an item, otherwise false
|
||||||
|
*/
|
||||||
|
public boolean tryTick(int maxTick, boolean allowLooping) {
|
||||||
|
this.transferTick++;
|
||||||
|
if (this.transferTick >= maxTick) {
|
||||||
|
if (allowLooping) {
|
||||||
|
this.transferTick = 0;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
this.transferTick = maxTick;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getLocation() {
|
||||||
|
return this.location.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Block getBlock() {
|
||||||
|
return this.location.getBlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
public World getWorld() {
|
||||||
|
return this.location.getWorld();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getX() {
|
||||||
|
return this.location.getBlockX();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getY() {
|
||||||
|
return this.location.getBlockY();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getZ() {
|
||||||
|
return this.location.getBlockZ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Level getLevel() {
|
||||||
|
return this.level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLevel(Level level) {
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getPlacedBy() {
|
||||||
|
return this.placedBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlacedBy(UUID placedBy) {
|
||||||
|
this.placedBy = placedBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getLastPlayerOpened() {
|
||||||
|
return this.lastPlayerOpened;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastPlayerOpened(UUID uuid) {
|
||||||
|
this.lastPlayerOpened = uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TeleportTrigger getTeleportTrigger() {
|
||||||
|
return this.teleportTrigger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTeleportTrigger(TeleportTrigger teleportTrigger) {
|
||||||
|
this.teleportTrigger = teleportTrigger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Location> getLinkedBlocks() {
|
||||||
|
return new ArrayList<>(this.linkedBlocks);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addLinkedBlock(Location location, LinkType type) {
|
||||||
|
if (type == LinkType.REGULAR) {
|
||||||
|
this.linkedBlocks.add(location);
|
||||||
|
} else {
|
||||||
|
this.filter.setEndPoint(location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeLinkedBlock(Location location) {
|
||||||
|
this.linkedBlocks.remove(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearLinkedBlocks() {
|
||||||
|
this.linkedBlocks.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Filter getFilter() {
|
||||||
|
return this.filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFilter(Filter filter) {
|
||||||
|
this.filter = filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getDataFromModuleCache(String key) {
|
||||||
|
return this.moduleCache.getOrDefault(key, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDataToModuleCache(String key, Object data) {
|
||||||
|
this.moduleCache.put(key, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDataCachedInModuleCache(String key) {
|
||||||
|
return this.moduleCache.containsKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeDataFromModuleCache(String key) {
|
||||||
|
this.moduleCache.remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearModuleCache() {
|
||||||
|
this.moduleCache.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancelSync(Player player) {
|
||||||
|
Bukkit.getScheduler().cancelTask(this.syncId);
|
||||||
|
getPlayerDataManager().getPlayerData(player).setSyncType(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> serialize() {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("id", this.id);
|
||||||
|
map.put("level", this.level.getLevel());
|
||||||
|
map.put("placed_by", this.placedBy.toString());
|
||||||
|
map.put("last_opened_by", this.lastPlayerOpened.toString());
|
||||||
|
map.put("teleport_trigger", this.teleportTrigger.name());
|
||||||
|
map.putAll(SerializedLocation.of(this.location));
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Data deserialize(Map<String, Object> map) {
|
||||||
|
return new HopperImpl(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTableName() {
|
||||||
|
return "placed_hoppers";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getActivePlayer() {
|
||||||
|
return this.activePlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActivePlayer(Player activePlayer) {
|
||||||
|
this.activePlayer = activePlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
private LevelManager getLevelManager() {
|
||||||
|
return EpicHoppersApi.getApi().getLevelManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
private PlayerDataManager getPlayerDataManager() {
|
||||||
|
return EpicHoppersApi.getApi().getPlayerDataManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated The class needs refactoring to not even need the plugin.
|
||||||
|
* This is just a temporary workaround to get a Minecraft 1.20-beta build ready
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
private long getLinkTimeoutFromPluginConfig() {
|
||||||
|
return getPlugin().getConfig().getLong("Main.Timeout When Syncing Hoppers");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated The class needs refactoring to not even need the plugin.
|
||||||
|
* This is just a temporary workaround to get a Minecraft 1.20-beta build ready
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
private String getUpgradeParticleType() {
|
||||||
|
return getPlugin().getConfig().getString("Main.Upgrade Particle Type");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated The class needs refactoring to not even need the plugin.
|
||||||
|
* This is just a temporary workaround to get a Minecraft 1.20-beta build ready
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
private SongodaPlugin getPlugin() {
|
||||||
|
return (SongodaPlugin) Bukkit.getPluginManager().getPlugin("EpicHoppers");
|
||||||
|
}
|
||||||
|
}
|
@ -13,7 +13,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class HopperManager {
|
public class HopperManager {
|
||||||
private final Map<Location, Hopper> registeredHoppers = new HashMap<>();
|
private final Map<Location, HopperImpl> registeredHoppers = new HashMap<>();
|
||||||
private final EpicHoppers plugin;
|
private final EpicHoppers plugin;
|
||||||
|
|
||||||
protected boolean ready;
|
protected boolean ready;
|
||||||
@ -37,18 +37,18 @@ public class HopperManager {
|
|||||||
return this.ready;
|
return this.ready;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Hopper addHopper(Hopper hopper) {
|
public HopperImpl addHopper(HopperImpl hopper) {
|
||||||
this.registeredHoppers.put(roundLocation(hopper.getLocation()), hopper);
|
this.registeredHoppers.put(roundLocation(hopper.getLocation()), hopper);
|
||||||
return hopper;
|
return hopper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void addHopper(Location location, Hopper hopper) {
|
public void addHopper(Location location, HopperImpl hopper) {
|
||||||
this.registeredHoppers.put(roundLocation(location), hopper);
|
this.registeredHoppers.put(roundLocation(location), hopper);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addHoppers(Collection<Hopper> hoppers) {
|
public void addHoppers(Collection<HopperImpl> hoppers) {
|
||||||
for (Hopper hopper : hoppers) {
|
for (HopperImpl hopper : hoppers) {
|
||||||
this.registeredHoppers.put(hopper.getLocation(), hopper);
|
this.registeredHoppers.put(hopper.getLocation(), hopper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,10 +59,10 @@ public class HopperManager {
|
|||||||
* @param location The location of the hopper to remove
|
* @param location The location of the hopper to remove
|
||||||
* @return The removed hopper, or null if none was removed
|
* @return The removed hopper, or null if none was removed
|
||||||
*/
|
*/
|
||||||
public Hopper removeHopper(Location location) {
|
public HopperImpl removeHopper(Location location) {
|
||||||
Hopper removed = this.registeredHoppers.remove(location);
|
HopperImpl removed = this.registeredHoppers.remove(location);
|
||||||
|
|
||||||
for (Hopper hopper : this.registeredHoppers.values()) {
|
for (HopperImpl hopper : this.registeredHoppers.values()) {
|
||||||
hopper.removeLinkedBlock(location);
|
hopper.removeLinkedBlock(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,19 +75,19 @@ public class HopperManager {
|
|||||||
return removed;
|
return removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Hopper getHopper(Location location) {
|
public HopperImpl getHopper(Location location) {
|
||||||
if (!this.registeredHoppers.containsKey(location = roundLocation(location))) {
|
if (!this.registeredHoppers.containsKey(location = roundLocation(location))) {
|
||||||
if (!this.ready) {
|
if (!this.ready) {
|
||||||
throw new IllegalStateException("Hoppers are still being loaded");
|
throw new IllegalStateException("Hoppers are still being loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
Hopper hopper = addHopper(new Hopper(location));
|
HopperImpl hopper = addHopper(new HopperImpl(location));
|
||||||
this.plugin.getDataManager().createHopper(hopper);
|
this.plugin.getDataManager().delete(hopper);
|
||||||
}
|
}
|
||||||
return this.registeredHoppers.get(location);
|
return this.registeredHoppers.get(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Hopper getHopper(Block block) {
|
public HopperImpl getHopper(Block block) {
|
||||||
return getHopper(block.getLocation());
|
return getHopper(block.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,16 +98,16 @@ public class HopperManager {
|
|||||||
return this.registeredHoppers.containsKey(roundLocation(location));
|
return this.registeredHoppers.containsKey(roundLocation(location));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Location, Hopper> getHoppers() {
|
public Map<Location, HopperImpl> getHoppers() {
|
||||||
return Collections.unmodifiableMap(this.registeredHoppers);
|
return Collections.unmodifiableMap(this.registeredHoppers);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Hopper getHopperFromPlayer(Player player) {
|
public HopperImpl getHopperFromPlayer(Player player) {
|
||||||
if (!this.ready) {
|
if (!this.ready) {
|
||||||
throw new IllegalStateException("Hoppers are still being loaded");
|
throw new IllegalStateException("Hoppers are still being loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Hopper hopper : this.registeredHoppers.values()) {
|
for (HopperImpl hopper : this.registeredHoppers.values()) {
|
||||||
if (hopper.getLastPlayerOpened() == player.getUniqueId()) {
|
if (hopper.getLastPlayerOpened() == player.getUniqueId()) {
|
||||||
return hopper;
|
return hopper;
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,11 @@ import com.craftaro.core.SongodaPlugin;
|
|||||||
import com.craftaro.core.gui.GuiManager;
|
import com.craftaro.core.gui.GuiManager;
|
||||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||||
import com.craftaro.core.utils.TextUtils;
|
import com.craftaro.core.utils.TextUtils;
|
||||||
|
import com.craftaro.epichoppers.hopper.Hopper;
|
||||||
|
import com.craftaro.epichoppers.hopper.HopperImpl;
|
||||||
import com.craftaro.epichoppers.settings.Settings;
|
import com.craftaro.epichoppers.settings.Settings;
|
||||||
import com.craftaro.epichoppers.utils.Methods;
|
import com.craftaro.epichoppers.utils.Methods;
|
||||||
import com.craftaro.epichoppers.gui.GUICrafting;
|
import com.craftaro.epichoppers.gui.GUICrafting;
|
||||||
import com.craftaro.epichoppers.hopper.Hopper;
|
|
||||||
import com.craftaro.epichoppers.utils.StorageContainerCache;
|
import com.craftaro.epichoppers.utils.StorageContainerCache;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -122,7 +123,7 @@ public class ModuleAutoCrafting extends Module {
|
|||||||
for (int i = 0; i < items.length; i++) {
|
for (int i = 0; i < items.length; i++) {
|
||||||
if (!slotsToAlter.containsKey(i)) {
|
if (!slotsToAlter.containsKey(i)) {
|
||||||
// and yeet into space!
|
// and yeet into space!
|
||||||
hopper.getWorld().dropItemNaturally(hopper.getLocation(), items[i]);
|
hopper.getLocation().getWorld().dropItemNaturally(hopper.getLocation(), items[i]);
|
||||||
items[i] = null;
|
items[i] = null;
|
||||||
|
|
||||||
freeSlotAfterRemovingIngredients = true;
|
freeSlotAfterRemovingIngredients = true;
|
||||||
|
@ -6,11 +6,12 @@ import com.craftaro.core.hooks.EconomyManager;
|
|||||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||||
import com.craftaro.core.utils.NumberUtils;
|
import com.craftaro.core.utils.NumberUtils;
|
||||||
import com.craftaro.core.utils.TextUtils;
|
import com.craftaro.core.utils.TextUtils;
|
||||||
|
import com.craftaro.epichoppers.hopper.Hopper;
|
||||||
|
import com.craftaro.epichoppers.hopper.HopperImpl;
|
||||||
import com.craftaro.epichoppers.settings.Settings;
|
import com.craftaro.epichoppers.settings.Settings;
|
||||||
import com.craftaro.epichoppers.utils.Methods;
|
import com.craftaro.epichoppers.utils.Methods;
|
||||||
import com.craftaro.epichoppers.gui.GUIAutoSellFilter;
|
import com.craftaro.epichoppers.gui.GUIAutoSellFilter;
|
||||||
import com.craftaro.epichoppers.hopper.Filter;
|
import com.craftaro.epichoppers.hopper.Filter;
|
||||||
import com.craftaro.epichoppers.hopper.Hopper;
|
|
||||||
import com.craftaro.epichoppers.utils.StorageContainerCache;
|
import com.craftaro.epichoppers.utils.StorageContainerCache;
|
||||||
import me.gypopo.economyshopgui.api.EconomyShopGUIHook;
|
import me.gypopo.economyshopgui.api.EconomyShopGUIHook;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
@ -5,9 +5,10 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
|
|||||||
import com.craftaro.core.gui.GuiManager;
|
import com.craftaro.core.gui.GuiManager;
|
||||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||||
import com.craftaro.core.utils.TextUtils;
|
import com.craftaro.core.utils.TextUtils;
|
||||||
|
import com.craftaro.epichoppers.hopper.Hopper;
|
||||||
|
import com.craftaro.epichoppers.hopper.HopperImpl;
|
||||||
import com.craftaro.epichoppers.settings.Settings;
|
import com.craftaro.epichoppers.settings.Settings;
|
||||||
import com.craftaro.epichoppers.gui.GUISmeltable;
|
import com.craftaro.epichoppers.gui.GUISmeltable;
|
||||||
import com.craftaro.epichoppers.hopper.Hopper;
|
|
||||||
import com.craftaro.epichoppers.utils.StorageContainerCache;
|
import com.craftaro.epichoppers.utils.StorageContainerCache;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -4,9 +4,10 @@ import com.craftaro.core.SongodaPlugin;
|
|||||||
import com.craftaro.core.compatibility.ServerVersion;
|
import com.craftaro.core.compatibility.ServerVersion;
|
||||||
import com.craftaro.core.gui.GuiManager;
|
import com.craftaro.core.gui.GuiManager;
|
||||||
import com.craftaro.core.utils.TextUtils;
|
import com.craftaro.core.utils.TextUtils;
|
||||||
|
import com.craftaro.epichoppers.hopper.Hopper;
|
||||||
|
import com.craftaro.epichoppers.hopper.HopperImpl;
|
||||||
import com.craftaro.epichoppers.settings.Settings;
|
import com.craftaro.epichoppers.settings.Settings;
|
||||||
import com.craftaro.epichoppers.EpicHoppersApi;
|
import com.craftaro.epichoppers.EpicHoppersApi;
|
||||||
import com.craftaro.epichoppers.hopper.Hopper;
|
|
||||||
import com.craftaro.epichoppers.utils.StorageContainerCache;
|
import com.craftaro.epichoppers.utils.StorageContainerCache;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
@ -4,6 +4,7 @@ import com.craftaro.core.SongodaPlugin;
|
|||||||
import com.craftaro.core.gui.GuiManager;
|
import com.craftaro.core.gui.GuiManager;
|
||||||
import com.craftaro.core.utils.TextUtils;
|
import com.craftaro.core.utils.TextUtils;
|
||||||
import com.craftaro.epichoppers.hopper.Hopper;
|
import com.craftaro.epichoppers.hopper.Hopper;
|
||||||
|
import com.craftaro.epichoppers.hopper.HopperImpl;
|
||||||
import com.craftaro.epichoppers.utils.StorageContainerCache;
|
import com.craftaro.epichoppers.utils.StorageContainerCache;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -49,7 +50,7 @@ public class ModuleMobHopper extends Module {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
hopper.getWorld().getNearbyEntities(hopper.getLocation(), 5, 5, 5).stream()
|
hopper.getLocation().getWorld().getNearbyEntities(hopper.getLocation(), 5, 5, 5).stream()
|
||||||
.filter(entity -> entity instanceof LivingEntity && !(entity instanceof Player) &&
|
.filter(entity -> entity instanceof LivingEntity && !(entity instanceof Player) &&
|
||||||
!(entity instanceof ArmorStand)).limit(1).forEach(entity -> {
|
!(entity instanceof ArmorStand)).limit(1).forEach(entity -> {
|
||||||
Location location = hopper.getLocation().add(.5, 1, .5);
|
Location location = hopper.getLocation().add(.5, 1, .5);
|
||||||
|
@ -7,11 +7,12 @@ import com.craftaro.core.gui.GuiManager;
|
|||||||
import com.craftaro.core.locale.Locale;
|
import com.craftaro.core.locale.Locale;
|
||||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||||
import com.craftaro.core.utils.TextUtils;
|
import com.craftaro.core.utils.TextUtils;
|
||||||
|
import com.craftaro.epichoppers.hopper.Hopper;
|
||||||
|
import com.craftaro.epichoppers.hopper.HopperImpl;
|
||||||
import com.craftaro.epichoppers.settings.Settings;
|
import com.craftaro.epichoppers.settings.Settings;
|
||||||
import com.craftaro.epichoppers.utils.Methods;
|
import com.craftaro.epichoppers.utils.Methods;
|
||||||
import com.craftaro.epichoppers.hopper.Hopper;
|
|
||||||
import com.craftaro.epichoppers.utils.StorageContainerCache;
|
import com.craftaro.epichoppers.utils.StorageContainerCache;
|
||||||
import com.songoda.ultimatestacker.UltimateStacker;
|
import com.craftaro.ultimatestacker.api.UltimateStackerApi;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
@ -157,7 +158,7 @@ public class ModuleSuction extends Module {
|
|||||||
|
|
||||||
private int getActualItemAmount(Item item) {
|
private int getActualItemAmount(Item item) {
|
||||||
if (ULTIMATE_STACKER) {
|
if (ULTIMATE_STACKER) {
|
||||||
return UltimateStacker.getActualItemAmount(item);
|
return UltimateStackerApi.getStackedItemManager().getActualItemAmount(item);
|
||||||
} else if (WILD_STACKER) {
|
} else if (WILD_STACKER) {
|
||||||
return WildStackerAPI.getItemAmount(item);
|
return WildStackerAPI.getItemAmount(item);
|
||||||
} else {
|
} else {
|
||||||
@ -168,7 +169,7 @@ public class ModuleSuction extends Module {
|
|||||||
|
|
||||||
private void updateAmount(Item item, int amount) {
|
private void updateAmount(Item item, int amount) {
|
||||||
if (ULTIMATE_STACKER) {
|
if (ULTIMATE_STACKER) {
|
||||||
UltimateStacker.updateItemAmount(item, item.getItemStack(), amount);
|
UltimateStackerApi.getStackedItemManager().updateStack(item, amount);
|
||||||
} else if (WILD_STACKER) {
|
} else if (WILD_STACKER) {
|
||||||
WildStackerAPI.getStackedItem(item).setStackAmount(amount, true);
|
WildStackerAPI.getStackedItem(item).setStackAmount(amount, true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.ServerVersion;
|
|||||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XSound;
|
import com.craftaro.core.third_party.com.cryptomorin.xseries.XSound;
|
||||||
import com.craftaro.epichoppers.EpicHoppers;
|
import com.craftaro.epichoppers.EpicHoppers;
|
||||||
import com.craftaro.epichoppers.hopper.Hopper;
|
import com.craftaro.epichoppers.hopper.Hopper;
|
||||||
|
import com.craftaro.epichoppers.hopper.HopperImpl;
|
||||||
import com.craftaro.epichoppers.settings.Settings;
|
import com.craftaro.epichoppers.settings.Settings;
|
||||||
import com.craftaro.epichoppers.utils.Methods;
|
import com.craftaro.epichoppers.utils.Methods;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -64,7 +65,7 @@ public class TeleportHandlerImpl implements TeleportHandler {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Hopper hopper = this.plugin.getHopperManager().getHopper(location);
|
HopperImpl hopper = this.plugin.getHopperManager().getHopper(location);
|
||||||
|
|
||||||
if (hopper.getTeleportTrigger() != TeleportTrigger.WALK_ON) {
|
if (hopper.getTeleportTrigger() != TeleportTrigger.WALK_ON) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -6,7 +6,7 @@ import com.craftaro.epichoppers.api.events.HopperBreakEvent;
|
|||||||
import com.craftaro.epichoppers.api.events.HopperPlaceEvent;
|
import com.craftaro.epichoppers.api.events.HopperPlaceEvent;
|
||||||
import com.craftaro.epichoppers.gui.GUIAutoSellFilter;
|
import com.craftaro.epichoppers.gui.GUIAutoSellFilter;
|
||||||
import com.craftaro.epichoppers.gui.GUIFilter;
|
import com.craftaro.epichoppers.gui.GUIFilter;
|
||||||
import com.craftaro.epichoppers.hopper.Hopper;
|
import com.craftaro.epichoppers.hopper.HopperImpl;
|
||||||
import com.craftaro.epichoppers.hopper.HopperBuilder;
|
import com.craftaro.epichoppers.hopper.HopperBuilder;
|
||||||
import com.craftaro.epichoppers.hopper.levels.Level;
|
import com.craftaro.epichoppers.hopper.levels.Level;
|
||||||
import com.craftaro.epichoppers.settings.Settings;
|
import com.craftaro.epichoppers.settings.Settings;
|
||||||
@ -68,7 +68,7 @@ public class BlockListeners implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Hopper hopper = this.plugin.getHopperManager().addHopper(
|
HopperImpl hopper = this.plugin.getHopperManager().addHopper(
|
||||||
new HopperBuilder(e.getBlock())
|
new HopperBuilder(e.getBlock())
|
||||||
.setLevel(this.plugin.getLevelManager().getLevel(item))
|
.setLevel(this.plugin.getLevelManager().getLevel(item))
|
||||||
.setPlacedBy(player)
|
.setPlacedBy(player)
|
||||||
@ -77,7 +77,7 @@ public class BlockListeners implements Listener {
|
|||||||
HopperPlaceEvent hopperPlaceEvent = new HopperPlaceEvent(player, hopper);
|
HopperPlaceEvent hopperPlaceEvent = new HopperPlaceEvent(player, hopper);
|
||||||
Bukkit.getPluginManager().callEvent(hopperPlaceEvent);
|
Bukkit.getPluginManager().callEvent(hopperPlaceEvent);
|
||||||
|
|
||||||
this.plugin.getDataManager().createHopper(hopper);
|
this.plugin.getDataManager().save(hopper);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int maxHoppers(Player player) {
|
private int maxHoppers(Player player) {
|
||||||
@ -130,7 +130,7 @@ public class BlockListeners implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Hopper hopper = this.plugin.getHopperManager().getHopper(block);
|
HopperImpl hopper = this.plugin.getHopperManager().getHopper(block);
|
||||||
|
|
||||||
GUIFilter.compileOpenGuiFilter(hopper);
|
GUIFilter.compileOpenGuiFilter(hopper);
|
||||||
GUIAutoSellFilter.compileOpenAutoSellFilter(hopper);
|
GUIAutoSellFilter.compileOpenAutoSellFilter(hopper);
|
||||||
@ -175,7 +175,7 @@ public class BlockListeners implements Listener {
|
|||||||
.forEach(item -> event.getBlock().getWorld().dropItemNaturally(event.getBlock().getLocation(), item));
|
.forEach(item -> event.getBlock().getWorld().dropItemNaturally(event.getBlock().getLocation(), item));
|
||||||
|
|
||||||
this.plugin.getHopperManager().removeHopper(block.getLocation());
|
this.plugin.getHopperManager().removeHopper(block.getLocation());
|
||||||
this.plugin.getDataManager().deleteHopper(hopper);
|
this.plugin.getDataManager().delete(hopper);
|
||||||
|
|
||||||
this.plugin.getPlayerDataManager().getPlayerData(player).setSyncType(null);
|
this.plugin.getPlayerDataManager().getPlayerData(player).setSyncType(null);
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,9 @@ package com.craftaro.epichoppers.listeners;
|
|||||||
|
|
||||||
import com.craftaro.core.compatibility.ServerVersion;
|
import com.craftaro.core.compatibility.ServerVersion;
|
||||||
import com.craftaro.core.nms.NmsManager;
|
import com.craftaro.core.nms.NmsManager;
|
||||||
|
import com.craftaro.epichoppers.hopper.HopperImpl;
|
||||||
import com.craftaro.epichoppers.settings.Settings;
|
import com.craftaro.epichoppers.settings.Settings;
|
||||||
import com.craftaro.epichoppers.EpicHoppers;
|
import com.craftaro.epichoppers.EpicHoppers;
|
||||||
import com.craftaro.epichoppers.hopper.Hopper;
|
|
||||||
import com.craftaro.epichoppers.hopper.levels.modules.Module;
|
import com.craftaro.epichoppers.hopper.levels.modules.Module;
|
||||||
import com.craftaro.epichoppers.hopper.levels.modules.ModuleAutoCrafting;
|
import com.craftaro.epichoppers.hopper.levels.modules.ModuleAutoCrafting;
|
||||||
import com.craftaro.epichoppers.utils.HopperDirection;
|
import com.craftaro.epichoppers.utils.HopperDirection;
|
||||||
@ -40,7 +40,7 @@ public class HopperListeners implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hopper minecarts should be able to take care of themselves
|
// HopperImpl minecarts should be able to take care of themselves
|
||||||
// Let EpicHoppers take over if the hopper is pointing down though
|
// Let EpicHoppers take over if the hopper is pointing down though
|
||||||
if (destination.getHolder() instanceof HopperMinecart
|
if (destination.getHolder() instanceof HopperMinecart
|
||||||
&& source.getHolder() instanceof org.bukkit.block.Hopper
|
&& source.getHolder() instanceof org.bukkit.block.Hopper
|
||||||
@ -56,7 +56,7 @@ public class HopperListeners implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hopper going into minecarts
|
// HopperImpl going into minecarts
|
||||||
if (destination.getHolder() instanceof Minecart && source.getHolder() instanceof org.bukkit.block.Hopper) {
|
if (destination.getHolder() instanceof Minecart && source.getHolder() instanceof org.bukkit.block.Hopper) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
@ -68,12 +68,12 @@ public class HopperListeners implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calling HopperManager#getHopper() automatically creates a new Hopper and we don't need to iterate over default-valued hoppers
|
// Calling HopperManager#getHopper() automatically creates a new HopperImpl and we don't need to iterate over default-valued hoppers
|
||||||
if (!this.plugin.getHopperManager().isHopper(destinationLocation)) {
|
if (!this.plugin.getHopperManager().isHopper(destinationLocation)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Hopper toHopper = this.plugin.getHopperManager().getHopper(destinationLocation);
|
HopperImpl toHopper = this.plugin.getHopperManager().getHopper(destinationLocation);
|
||||||
// minecraft 1.8 doesn't have a method to get the hopper's location from the inventory, so we use the holder instead
|
// minecraft 1.8 doesn't have a method to get the hopper's location from the inventory, so we use the holder instead
|
||||||
final ItemStack toMove = event.getItem();
|
final ItemStack toMove = event.getItem();
|
||||||
|
|
||||||
|
@ -2,10 +2,11 @@ package com.craftaro.epichoppers.listeners;
|
|||||||
|
|
||||||
import com.craftaro.core.hooks.ProtectionManager;
|
import com.craftaro.core.hooks.ProtectionManager;
|
||||||
import com.craftaro.core.hooks.WorldGuardHook;
|
import com.craftaro.core.hooks.WorldGuardHook;
|
||||||
|
import com.craftaro.epichoppers.hopper.Hopper;
|
||||||
import com.craftaro.epichoppers.settings.Settings;
|
import com.craftaro.epichoppers.settings.Settings;
|
||||||
import com.craftaro.epichoppers.EpicHoppers;
|
import com.craftaro.epichoppers.EpicHoppers;
|
||||||
import com.craftaro.epichoppers.gui.GUIOverview;
|
import com.craftaro.epichoppers.gui.GUIOverview;
|
||||||
import com.craftaro.epichoppers.hopper.Hopper;
|
import com.craftaro.epichoppers.hopper.HopperImpl;
|
||||||
import com.craftaro.epichoppers.hopper.teleport.TeleportTrigger;
|
import com.craftaro.epichoppers.hopper.teleport.TeleportTrigger;
|
||||||
import com.craftaro.epichoppers.player.PlayerData;
|
import com.craftaro.epichoppers.player.PlayerData;
|
||||||
import com.craftaro.epichoppers.player.SyncType;
|
import com.craftaro.epichoppers.player.SyncType;
|
||||||
@ -37,12 +38,12 @@ public class InteractListeners implements Listener {
|
|||||||
Location location = player.getLocation().getBlock().getRelative(BlockFace.SELF).getLocation();
|
Location location = player.getLocation().getBlock().getRelative(BlockFace.SELF).getLocation();
|
||||||
Location down = location.getBlock().getRelative(BlockFace.DOWN).getLocation();
|
Location down = location.getBlock().getRelative(BlockFace.DOWN).getLocation();
|
||||||
if (this.plugin.getHopperManager().isHopper(down)) {
|
if (this.plugin.getHopperManager().isHopper(down)) {
|
||||||
Hopper hopper = this.plugin.getHopperManager().getHopper(down);
|
HopperImpl hopper = this.plugin.getHopperManager().getHopper(down);
|
||||||
if (hopper.getTeleportTrigger() == TeleportTrigger.SNEAK) {
|
if (hopper.getTeleportTrigger() == TeleportTrigger.SNEAK) {
|
||||||
this.plugin.getTeleportHandler().tpEntity(player, hopper);
|
this.plugin.getTeleportHandler().tpEntity(player, hopper);
|
||||||
}
|
}
|
||||||
} else if (this.plugin.getHopperManager().isHopper(location)) {
|
} else if (this.plugin.getHopperManager().isHopper(location)) {
|
||||||
Hopper hopper = this.plugin.getHopperManager().getHopper(location);
|
HopperImpl hopper = this.plugin.getHopperManager().getHopper(location);
|
||||||
if (hopper.getTeleportTrigger() == TeleportTrigger.SNEAK) {
|
if (hopper.getTeleportTrigger() == TeleportTrigger.SNEAK) {
|
||||||
this.plugin.getTeleportHandler().tpEntity(player, hopper);
|
this.plugin.getTeleportHandler().tpEntity(player, hopper);
|
||||||
}
|
}
|
||||||
@ -89,7 +90,7 @@ public class InteractListeners implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Hopper hopper = this.plugin.getHopperManager().getHopper(event.getClickedBlock());
|
HopperImpl hopper = this.plugin.getHopperManager().getHopper(event.getClickedBlock());
|
||||||
if (!player.getInventory().getItemInHand().getType().name().contains("PICKAXE")) {
|
if (!player.getInventory().getItemInHand().getType().name().contains("PICKAXE")) {
|
||||||
if (hopper.prepareForOpeningOverviewGui(player)) {
|
if (hopper.prepareForOpeningOverviewGui(player)) {
|
||||||
this.plugin.getGuiManager().showGUI(player, new GUIOverview(this.plugin, hopper, player));
|
this.plugin.getGuiManager().showGUI(player, new GUIOverview(this.plugin, hopper, player));
|
||||||
@ -103,7 +104,7 @@ public class InteractListeners implements Listener {
|
|||||||
|
|
||||||
if (event.getClickedBlock().getState() instanceof InventoryHolder ||
|
if (event.getClickedBlock().getState() instanceof InventoryHolder ||
|
||||||
(event.getClickedBlock().getType() == Material.ENDER_CHEST && Settings.ENDERCHESTS.getBoolean())) {
|
(event.getClickedBlock().getType() == Material.ENDER_CHEST && Settings.ENDERCHESTS.getBoolean())) {
|
||||||
Hopper hopper = playerData.getLastHopper();
|
HopperImpl hopper = (HopperImpl) playerData.getLastHopper();
|
||||||
if (event.getClickedBlock().getLocation().equals(playerData.getLastHopper().getLocation())) {
|
if (event.getClickedBlock().getLocation().equals(playerData.getLastHopper().getLocation())) {
|
||||||
if (!hopper.getLinkedBlocks().isEmpty()) {
|
if (!hopper.getLinkedBlocks().isEmpty()) {
|
||||||
this.plugin.getLocale().getMessage("event.hopper.syncfinish").sendPrefixedMessage(player);
|
this.plugin.getLocale().getMessage("event.hopper.syncfinish").sendPrefixedMessage(player);
|
||||||
|
@ -27,7 +27,7 @@ public class Settings {
|
|||||||
public static final ConfigSetting DISABLED_WORLDS = new ConfigSetting(CONFIG, "Main.Disabled Worlds",
|
public static final ConfigSetting DISABLED_WORLDS = new ConfigSetting(CONFIG, "Main.Disabled Worlds",
|
||||||
Arrays.asList("example1", "example2"),
|
Arrays.asList("example1", "example2"),
|
||||||
"Worlds where epic hoppers cannot be placed.",
|
"Worlds where epic hoppers cannot be placed.",
|
||||||
"Any placed Epic Hopper will just be converted to a normal one.");
|
"Any placed Epic HopperImpl will just be converted to a normal one.");
|
||||||
|
|
||||||
public static final ConfigSetting TELEPORT = new ConfigSetting(CONFIG, "Main.Allow Players To Teleport Through Hoppers", true,
|
public static final ConfigSetting TELEPORT = new ConfigSetting(CONFIG, "Main.Allow Players To Teleport Through Hoppers", true,
|
||||||
"Should players be able to teleport through hoppers?");
|
"Should players be able to teleport through hoppers?");
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package com.craftaro.epichoppers.tasks;
|
package com.craftaro.epichoppers.tasks;
|
||||||
|
|
||||||
import com.craftaro.epichoppers.boost.BoostData;
|
import com.craftaro.epichoppers.boost.BoostData;
|
||||||
|
import com.craftaro.epichoppers.boost.BoostDataImpl;
|
||||||
import com.craftaro.epichoppers.containers.CustomContainer;
|
import com.craftaro.epichoppers.containers.CustomContainer;
|
||||||
|
import com.craftaro.epichoppers.hopper.HopperImpl;
|
||||||
import com.craftaro.epichoppers.hopper.levels.modules.ModuleAutoCrafting;
|
import com.craftaro.epichoppers.hopper.levels.modules.ModuleAutoCrafting;
|
||||||
import com.craftaro.epichoppers.settings.Settings;
|
import com.craftaro.epichoppers.settings.Settings;
|
||||||
import com.craftaro.epichoppers.utils.HopperDirection;
|
import com.craftaro.epichoppers.utils.HopperDirection;
|
||||||
@ -45,7 +47,7 @@ public class HopTask extends BukkitRunnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
for (final com.craftaro.epichoppers.hopper.Hopper hopper : this.plugin.getHopperManager().getHoppers().values()) {
|
for (final HopperImpl hopper : this.plugin.getHopperManager().getHoppers().values()) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Get this hopper's location.
|
// Get this hopper's location.
|
||||||
@ -56,7 +58,7 @@ public class HopTask extends BukkitRunnable {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Hopper Block.
|
// Get HopperImpl Block.
|
||||||
Block block = location.getBlock();
|
Block block = location.getBlock();
|
||||||
|
|
||||||
// If block is not a hopper continue.
|
// If block is not a hopper continue.
|
||||||
@ -173,7 +175,7 @@ public class HopTask extends BukkitRunnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private StorageContainerCache.Cache getFilterEndpoint(com.craftaro.epichoppers.hopper.Hopper hopper) {
|
private StorageContainerCache.Cache getFilterEndpoint(HopperImpl hopper) {
|
||||||
// Get endpoint location.
|
// Get endpoint location.
|
||||||
Location endPoint = hopper.getFilter().getEndPoint();
|
Location endPoint = hopper.getFilter().getEndPoint();
|
||||||
|
|
||||||
@ -199,7 +201,7 @@ public class HopTask extends BukkitRunnable {
|
|||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pullItemsFromContainers(com.craftaro.epichoppers.hopper.Hopper toHopper, StorageContainerCache.Cache hopperCache, int maxToMove) {
|
private void pullItemsFromContainers(HopperImpl toHopper, StorageContainerCache.Cache hopperCache, int maxToMove) {
|
||||||
// Grab items from the container above (includes storage/hopper minecarts, EpicFarming farm items and AdvancedChests chest)
|
// Grab items from the container above (includes storage/hopper minecarts, EpicFarming farm items and AdvancedChests chest)
|
||||||
// If the container above is a hopper, ignore it if it's pointing down
|
// If the container above is a hopper, ignore it if it's pointing down
|
||||||
Block above = toHopper.getBlock().getRelative(BlockFace.UP);
|
Block above = toHopper.getBlock().getRelative(BlockFace.UP);
|
||||||
@ -305,7 +307,7 @@ public class HopTask extends BukkitRunnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pushItemsIntoContainers(com.craftaro.epichoppers.hopper.Hopper hopper, StorageContainerCache.Cache hopperCache, int maxToMove, Collection<Material> blockedMaterials, HopperDirection hopperDirection) {
|
private void pushItemsIntoContainers(HopperImpl hopper, StorageContainerCache.Cache hopperCache, int maxToMove, Collection<Material> blockedMaterials, HopperDirection hopperDirection) {
|
||||||
|
|
||||||
// Filter target, if any
|
// Filter target, if any
|
||||||
StorageContainerCache.Cache filterCache = getFilterEndpoint(hopper);
|
StorageContainerCache.Cache filterCache = getFilterEndpoint(hopper);
|
||||||
@ -395,7 +397,7 @@ public class HopTask extends BukkitRunnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean tryPushCustomContainer(com.craftaro.epichoppers.hopper.Hopper hopper,
|
private boolean tryPushCustomContainer(HopperImpl hopper,
|
||||||
StorageContainerCache.Cache hopperCache,
|
StorageContainerCache.Cache hopperCache,
|
||||||
CustomContainer container,
|
CustomContainer container,
|
||||||
StorageContainerCache.Cache filterCache,
|
StorageContainerCache.Cache filterCache,
|
||||||
@ -442,7 +444,7 @@ public class HopTask extends BukkitRunnable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean tryPush(com.craftaro.epichoppers.hopper.Hopper hopper,
|
private boolean tryPush(HopperImpl hopper,
|
||||||
StorageContainerCache.Cache hopperCache,
|
StorageContainerCache.Cache hopperCache,
|
||||||
StorageContainerCache.Cache targetCache,
|
StorageContainerCache.Cache targetCache,
|
||||||
StorageContainerCache.Cache filterCache,
|
StorageContainerCache.Cache filterCache,
|
||||||
@ -491,7 +493,7 @@ public class HopTask extends BukkitRunnable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processVoidFilter(com.craftaro.epichoppers.hopper.Hopper hopper, StorageContainerCache.Cache hopperCache, int maxToMove) {
|
private void processVoidFilter(HopperImpl hopper, StorageContainerCache.Cache hopperCache, int maxToMove) {
|
||||||
// Loop over hopper inventory to process void filtering.
|
// Loop over hopper inventory to process void filtering.
|
||||||
if (!hopper.getFilter().getVoidList().isEmpty()) {
|
if (!hopper.getFilter().getVoidList().isEmpty()) {
|
||||||
ItemStack[] hopperContents = hopperCache.cachedInventory;
|
ItemStack[] hopperContents = hopperCache.cachedInventory;
|
||||||
|
@ -0,0 +1,101 @@
|
|||||||
|
package com.craftaro.epichoppers.utils;
|
||||||
|
|
||||||
|
import com.craftaro.core.third_party.org.jooq.Query;
|
||||||
|
import com.craftaro.core.third_party.org.jooq.impl.DSL;
|
||||||
|
import com.craftaro.core.utils.ItemSerializer;
|
||||||
|
import com.craftaro.epichoppers.EpicHoppers;
|
||||||
|
import com.craftaro.epichoppers.hopper.Hopper;
|
||||||
|
import com.craftaro.epichoppers.hopper.HopperImpl;
|
||||||
|
import com.craftaro.epichoppers.hopper.ItemType;
|
||||||
|
import com.craftaro.epichoppers.hopper.LinkType;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DataHelper {
|
||||||
|
|
||||||
|
public static void createLink(HopperImpl hopper, Location location, LinkType type) {
|
||||||
|
EpicHoppers.getPlugin(EpicHoppers.class).getDataManager().getDatabaseConnector().connectDSL(dslContext -> {
|
||||||
|
dslContext.insertInto(DSL.table(EpicHoppers.getPlugin(EpicHoppers.class).getDataManager().getTablePrefix() + "links"))
|
||||||
|
.columns(
|
||||||
|
DSL.field("hopper_id"),
|
||||||
|
DSL.field("link_type"),
|
||||||
|
DSL.field("world"),
|
||||||
|
DSL.field("x"),
|
||||||
|
DSL.field("y"),
|
||||||
|
DSL.field("z"))
|
||||||
|
.values(
|
||||||
|
hopper.getId(),
|
||||||
|
type.name(),
|
||||||
|
location.getWorld().getName(),
|
||||||
|
location.getBlockX(),
|
||||||
|
location.getBlockY(),
|
||||||
|
location.getBlockZ())
|
||||||
|
.execute();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateItems(HopperImpl hopper, ItemType type, List<ItemStack> items) {
|
||||||
|
// try (Connection connection = this.databaseConnector.getConnection()) {
|
||||||
|
// String clearItems = "DELETE FROM " + this.getTablePrefix() + "items WHERE hopper_id = ? AND item_type = ?";
|
||||||
|
// try (PreparedStatement statement = connection.prepareStatement(clearItems)) {
|
||||||
|
// statement.setInt(1, hopper.getId());
|
||||||
|
// statement.setString(2, type.name());
|
||||||
|
// statement.executeUpdate();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// String createItem = "INSERT INTO " + this.getTablePrefix() + "items (hopper_id, item_type, item) VALUES (?, ?, ?)";
|
||||||
|
// try (PreparedStatement statement = connection.prepareStatement(createItem)) {
|
||||||
|
// for (ItemStack item : items) {
|
||||||
|
// statement.setInt(1, hopper.getId());
|
||||||
|
// statement.setString(2, type.name());
|
||||||
|
//
|
||||||
|
// try (ByteArrayOutputStream stream = new ByteArrayOutputStream(); BukkitObjectOutputStream bukkitStream = new BukkitObjectOutputStream(stream)) {
|
||||||
|
// bukkitStream.writeObject(item);
|
||||||
|
// statement.setString(3, Base64.getEncoder().encodeToString(stream.toByteArray()));
|
||||||
|
// } catch (IOException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// statement.addBatch();
|
||||||
|
// }
|
||||||
|
// statement.executeBatch();
|
||||||
|
// }
|
||||||
|
// } catch (Exception ex) {
|
||||||
|
// ex.printStackTrace();
|
||||||
|
// }
|
||||||
|
|
||||||
|
//Recreate with jooq
|
||||||
|
EpicHoppers.getPlugin(EpicHoppers.class).getDataManager().getDatabaseConnector().connectDSL(dslContext -> {
|
||||||
|
dslContext.deleteFrom(DSL.table(EpicHoppers.getPlugin(EpicHoppers.class).getDataManager().getTablePrefix() + "items"))
|
||||||
|
.where(DSL.field("hopper_id").eq(hopper.getId()))
|
||||||
|
.and(DSL.field("item_type").eq(type.name()))
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
dslContext.batch(
|
||||||
|
items.stream().map(item -> dslContext.insertInto(DSL.table(EpicHoppers.getPlugin(EpicHoppers.class).getDataManager().getTablePrefix() + "items"))
|
||||||
|
.columns(
|
||||||
|
DSL.field("hopper_id"),
|
||||||
|
DSL.field("item_type"),
|
||||||
|
DSL.field("item"))
|
||||||
|
.values(
|
||||||
|
hopper.getId(),
|
||||||
|
type.name(),
|
||||||
|
Base64.getEncoder().encodeToString(ItemSerializer.serializeItem(item)))
|
||||||
|
).toArray(Query[]::new)
|
||||||
|
).execute();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void deleteLinks(Hopper hopper) {
|
||||||
|
EpicHoppers.getPlugin(EpicHoppers.class).getDataManager().getDatabaseConnector().connectDSL(dslContext -> {
|
||||||
|
dslContext.deleteFrom(DSL.table(EpicHoppers.getPlugin(EpicHoppers.class).getDataManager().getTablePrefix() + "links"))
|
||||||
|
.where(DSL.field("hopper_id").eq(hopper.getId()))
|
||||||
|
.execute();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
2
pom.xml
2
pom.xml
@ -7,7 +7,7 @@
|
|||||||
<groupId>com.craftaro</groupId>
|
<groupId>com.craftaro</groupId>
|
||||||
<artifactId>EpicHoppers-Parent</artifactId>
|
<artifactId>EpicHoppers-Parent</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>5.0.0-SNAPSHOT</version>
|
<version>5.0.0-SNAPSHOT-b5</version>
|
||||||
<!-- Run 'mvn versions:set -DgenerateBackupPoms=false -DnewVersion=X.Y.Z-DEV' to update version recursively -->
|
<!-- Run 'mvn versions:set -DgenerateBackupPoms=false -DnewVersion=X.Y.Z-DEV' to update version recursively -->
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
|
Loading…
Reference in New Issue
Block a user