mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-19 15:09:24 +00:00
鱼饵袋
This commit is contained in:
@@ -43,7 +43,7 @@ public final class CustomFishing extends JavaPlugin {
|
||||
private BonusManager bonusManager;
|
||||
private LootManager lootManager;
|
||||
private LayoutManager layoutManager;
|
||||
private DataManager dataManager;
|
||||
private BagDataManager bagDataManager;
|
||||
private TotemManager totemManager;
|
||||
private SellManager sellManager;
|
||||
|
||||
@@ -87,9 +87,9 @@ public final class CustomFishing extends JavaPlugin {
|
||||
this.bonusManager = new BonusManager();
|
||||
this.lootManager = new LootManager();
|
||||
this.layoutManager = new LayoutManager();
|
||||
this.dataManager = new DataManager();
|
||||
this.totemManager = new TotemManager();
|
||||
this.sellManager = new SellManager();
|
||||
this.bagDataManager = new BagDataManager();
|
||||
ConfigUtil.reload();
|
||||
registerCommands();
|
||||
|
||||
@@ -105,7 +105,7 @@ public final class CustomFishing extends JavaPlugin {
|
||||
this.bonusManager.unload();
|
||||
this.lootManager.unload();
|
||||
this.layoutManager.unload();
|
||||
this.dataManager.unload();
|
||||
this.bagDataManager.unload();
|
||||
this.totemManager.unload();
|
||||
this.sellManager.unload();
|
||||
if (adventure != null) {
|
||||
@@ -150,8 +150,8 @@ public final class CustomFishing extends JavaPlugin {
|
||||
return layoutManager;
|
||||
}
|
||||
|
||||
public DataManager getDataManager() {
|
||||
return dataManager;
|
||||
public BagDataManager getDataManager() {
|
||||
return bagDataManager;
|
||||
}
|
||||
|
||||
public TotemManager getTotemManager() {
|
||||
@@ -161,4 +161,8 @@ public final class CustomFishing extends JavaPlugin {
|
||||
public SellManager getSellManager() {
|
||||
return sellManager;
|
||||
}
|
||||
|
||||
public BagDataManager getBagDataManager() {
|
||||
return bagDataManager;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class BaitCommand extends AbstractSubCommand {
|
||||
else if (args.get(0).equalsIgnoreCase("get")) {
|
||||
if (sender instanceof Player player){
|
||||
if (!BonusManager.BAITITEMS.containsKey(args.get(1))){
|
||||
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.notExist);
|
||||
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.itemNotExist);
|
||||
return true;
|
||||
}
|
||||
if (args.size() == 2){
|
||||
@@ -58,7 +58,7 @@ public class BaitCommand extends AbstractSubCommand {
|
||||
return true;
|
||||
}
|
||||
if (!BonusManager.BAITITEMS.containsKey(args.get(2))){
|
||||
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.notExist);
|
||||
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.itemNotExist);
|
||||
return true;
|
||||
}
|
||||
if (args.size() == 3){
|
||||
|
||||
@@ -32,7 +32,7 @@ public class LootCommand extends AbstractSubCommand {
|
||||
else if (args.get(0).equalsIgnoreCase("get")) {
|
||||
if (sender instanceof Player player){
|
||||
if (!loots().contains(args.get(1))){
|
||||
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.notExist);
|
||||
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.itemNotExist);
|
||||
return true;
|
||||
}
|
||||
if (args.size() == 2){
|
||||
@@ -61,7 +61,7 @@ public class LootCommand extends AbstractSubCommand {
|
||||
return true;
|
||||
}
|
||||
if (!loots().contains(args.get(2))){
|
||||
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.notExist);
|
||||
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.itemNotExist);
|
||||
return true;
|
||||
}
|
||||
if (args.size() == 3){
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
package net.momirealms.customfishing.commands.subcmd;
|
||||
|
||||
import net.momirealms.customfishing.CustomFishing;
|
||||
import net.momirealms.customfishing.commands.AbstractSubCommand;
|
||||
import net.momirealms.customfishing.commands.SubCommand;
|
||||
import net.momirealms.customfishing.manager.ConfigManager;
|
||||
import net.momirealms.customfishing.manager.MessageManager;
|
||||
import net.momirealms.customfishing.util.AdventureUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class OpenCommand extends AbstractSubCommand {
|
||||
@@ -16,9 +24,45 @@ public class OpenCommand extends AbstractSubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, List<String> args) {
|
||||
if (args.size() < 1) {
|
||||
|
||||
if (!ConfigManager.enableFishingBag) return true;
|
||||
if (!(sender instanceof Player player)) {
|
||||
AdventureUtil.consoleMessage(MessageManager.prefix + MessageManager.noConsole);
|
||||
return true;
|
||||
}
|
||||
if (args.size() == 0) {
|
||||
if (!sender.hasPermission("fishingbag.open")) {
|
||||
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.noPerm);
|
||||
return true;
|
||||
}
|
||||
CustomFishing.plugin.getBagDataManager().openFishingBag(player, player);
|
||||
}
|
||||
if (args.size() == 1) {
|
||||
if (!sender.hasPermission("customfishing.admin")) {
|
||||
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.noPerm);
|
||||
return true;
|
||||
}
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayerIfCached(args.get(0));
|
||||
if (offlinePlayer == null) {
|
||||
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.playerNotExist);
|
||||
return true;
|
||||
}
|
||||
CustomFishing.plugin.getBagDataManager().openFishingBag(player, offlinePlayer);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, List<String> args) {
|
||||
if (!ConfigManager.enableFishingBag) return null;
|
||||
if (!sender.hasPermission("customfishing.admin")) return null;
|
||||
if (args.size() == 1) {
|
||||
List<String> arrayList = new ArrayList<>();
|
||||
for (String cmd : online_players()) {
|
||||
if (cmd.startsWith(args.get(0)))
|
||||
arrayList.add(cmd);
|
||||
}
|
||||
return arrayList;
|
||||
}
|
||||
return super.onTabComplete(sender, args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class RodCommand extends AbstractSubCommand {
|
||||
else if (args.get(0).equalsIgnoreCase("get")) {
|
||||
if (sender instanceof Player player){
|
||||
if (!BonusManager.RODITEMS.containsKey(args.get(1))){
|
||||
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.notExist);
|
||||
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.itemNotExist);
|
||||
return true;
|
||||
}
|
||||
if (args.size() == 2){
|
||||
@@ -58,7 +58,7 @@ public class RodCommand extends AbstractSubCommand {
|
||||
return true;
|
||||
}
|
||||
if (!BonusManager.RODITEMS.containsKey(args.get(2))){
|
||||
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.notExist);
|
||||
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.itemNotExist);
|
||||
return true;
|
||||
}
|
||||
if (args.size() == 3){
|
||||
|
||||
@@ -29,7 +29,7 @@ public class UtilCommand extends AbstractSubCommand {
|
||||
else if (args.get(0).equalsIgnoreCase("get")) {
|
||||
if (sender instanceof Player player){
|
||||
if (!BonusManager.UTILITEMS.containsKey(args.get(1))){
|
||||
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.notExist);
|
||||
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.itemNotExist);
|
||||
return true;
|
||||
}
|
||||
if (args.size() == 2){
|
||||
@@ -58,7 +58,7 @@ public class UtilCommand extends AbstractSubCommand {
|
||||
return true;
|
||||
}
|
||||
if (!BonusManager.UTILITEMS.containsKey(args.get(2))){
|
||||
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.notExist);
|
||||
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.itemNotExist);
|
||||
return true;
|
||||
}
|
||||
if (args.size() == 3){
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
package net.momirealms.customfishing.data;
|
||||
|
||||
public abstract class AbstractSQLStorage {
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package net.momirealms.customfishing.data;
|
||||
|
||||
public interface DataStorageInterface {
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package net.momirealms.customfishing.data;
|
||||
|
||||
public class FileStorageImpl {
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package net.momirealms.customfishing.data;
|
||||
|
||||
public class MongoDBStorageImpl {
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package net.momirealms.customfishing.data;
|
||||
|
||||
public class MySQLStorageImpl extends AbstractSQLStorage implements DataStorageInterface {
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package net.momirealms.customfishing.data;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public class PlayerBagData {
|
||||
|
||||
private final OfflinePlayer player;
|
||||
private Inventory inventory;
|
||||
|
||||
public PlayerBagData(OfflinePlayer player, Inventory inventory) {
|
||||
this.player = player;
|
||||
this.inventory = inventory;
|
||||
}
|
||||
|
||||
public Inventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public OfflinePlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public void setInventory(Inventory inventory) {
|
||||
this.inventory = inventory;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package net.momirealms.customfishing.data;
|
||||
|
||||
public class PlayerData {
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package net.momirealms.customfishing.data;
|
||||
|
||||
public class SQLiteStorageImpl extends AbstractSQLStorage implements DataStorageInterface {
|
||||
}
|
||||
@@ -1,201 +0,0 @@
|
||||
///*
|
||||
// * Copyright (C) <2022> <XiaoMoMi>
|
||||
// *
|
||||
// * This program is free software: you can redistribute it and/or modify
|
||||
// * it under the terms of the GNU General Public License as published by
|
||||
// * the Free Software Foundation, either version 3 of the License, or
|
||||
// * any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// * GNU General Public License for more details.
|
||||
// *
|
||||
// * You should have received a copy of the GNU General Public License
|
||||
// * along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// */
|
||||
//
|
||||
//package net.momirealms.customfishing.data;
|
||||
//
|
||||
//import com.zaxxer.hikari.HikariDataSource;
|
||||
//import net.momirealms.customfishing.CustomFishing;
|
||||
//import net.momirealms.customnameplates.ConfigManager;
|
||||
//import net.momirealms.customnameplates.CustomNameplates;
|
||||
//
|
||||
//import java.io.File;
|
||||
//import java.sql.Connection;
|
||||
//import java.sql.DriverManager;
|
||||
//import java.sql.SQLException;
|
||||
//
|
||||
//public class SqlConnection {
|
||||
//
|
||||
// private String driver = "com.mysql.jdbc.Driver";
|
||||
//
|
||||
// private final File dataFolder = CustomFishing.plugin.getDataFolder();
|
||||
//
|
||||
// private boolean secon = false;
|
||||
// private boolean isfirstry = true;
|
||||
//
|
||||
// public int waitTimeOut = 10;
|
||||
//
|
||||
// public File userdata = new File(dataFolder, "data.db");
|
||||
// private Connection connection = null;
|
||||
// private HikariDataSource hikari = null;
|
||||
//
|
||||
// /*
|
||||
// 新建Hikari配置
|
||||
// */
|
||||
// private void createNewHikariConfiguration() {
|
||||
// hikari = new HikariDataSource();
|
||||
// hikari.setPoolName("[Nameplates]");
|
||||
// hikari.setJdbcUrl(ConfigManager.Database.url);
|
||||
// hikari.setUsername(ConfigManager.Database.user);
|
||||
// hikari.setPassword(ConfigManager.Database.password);
|
||||
// hikari.setMaximumPoolSize(ConfigManager.Database.maximum_pool_size);
|
||||
// hikari.setMinimumIdle(ConfigManager.Database.minimum_idle);
|
||||
// hikari.setMaxLifetime(ConfigManager.Database.maximum_lifetime);
|
||||
// hikari.addDataSourceProperty("cachePrepStmts", "true");
|
||||
// hikari.addDataSourceProperty("prepStmtCacheSize", "250");
|
||||
// hikari.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
||||
// hikari.addDataSourceProperty("userServerPrepStmts", "true");
|
||||
// if (hikari.getMinimumIdle() < hikari.getMaximumPoolSize()) {
|
||||
// hikari.setIdleTimeout(ConfigManager.Database.idle_timeout);
|
||||
// } else {
|
||||
// hikari.setIdleTimeout(0);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /*
|
||||
// 设置驱动,区分Mysql5与8
|
||||
// */
|
||||
// private void setDriver() {
|
||||
// if(ConfigManager.Database.use_mysql){
|
||||
// try {
|
||||
// Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
// } catch (ClassNotFoundException e) {
|
||||
// driver = ("com.mysql.jdbc.Driver");
|
||||
// return;
|
||||
// }
|
||||
// driver = ("com.mysql.cj.jdbc.Driver");
|
||||
// }else {
|
||||
// driver = ("org.sqlite.JDBC");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public boolean setGlobalConnection() {
|
||||
// setDriver();
|
||||
// try {
|
||||
// if (ConfigManager.Database.enable_pool) {
|
||||
// createNewHikariConfiguration();
|
||||
// Connection connection = getConnection();
|
||||
// closeHikariConnection(connection);
|
||||
// } else {
|
||||
// Class.forName(driver);
|
||||
// if(ConfigManager.Database.use_mysql){
|
||||
// connection = DriverManager.getConnection(ConfigManager.Database.url, ConfigManager.Database.user, ConfigManager.Database.password);
|
||||
// }else {
|
||||
// connection = DriverManager.getConnection("jdbc:sqlite:" + userdata.toString());
|
||||
// }
|
||||
// }
|
||||
// if (secon) {
|
||||
// AdventureUtil.consoleMessage("<gradient:#DDE4FF:#8DA2EE>[CustomNameplates]</gradient> <color:#F5F5F5>Successfully reconnect to SQL!");
|
||||
// } else {
|
||||
// secon = true;
|
||||
// }
|
||||
// return true;
|
||||
// } catch (SQLException e) {
|
||||
// AdventureUtil.consoleMessage("<red>[CustomNameplates] Error! Failed to connect to SQL!</red>");
|
||||
// e.printStackTrace();
|
||||
// close();
|
||||
// return false;
|
||||
// } catch (ClassNotFoundException e) {
|
||||
// AdventureUtil.consoleMessage("<red>[CustomNameplates] Error! Failed to load JDBC driver</red>");
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// public Connection getConnectionAndCheck() {
|
||||
// if (!canConnect()) {
|
||||
// return null;
|
||||
// }
|
||||
// try {
|
||||
// return getConnection();
|
||||
// } catch (SQLException e) {
|
||||
// if (isfirstry) {
|
||||
// isfirstry = false;
|
||||
// close();
|
||||
// return getConnectionAndCheck();
|
||||
// } else {
|
||||
// isfirstry = true;
|
||||
// AdventureUtil.consoleMessage("<red>[CustomNameplates] Error! Failed to connect to SQL!</red>");
|
||||
// close();
|
||||
// e.printStackTrace();
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public Connection getConnection() throws SQLException {
|
||||
// if (ConfigManager.Database.enable_pool) {
|
||||
// return hikari.getConnection();
|
||||
// } else {
|
||||
// return connection;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||
// public boolean canConnect() {
|
||||
// try {
|
||||
// if (ConfigManager.Database.enable_pool) {
|
||||
// if (hikari == null) {
|
||||
// return setGlobalConnection();
|
||||
// }
|
||||
// if (hikari.isClosed()) {
|
||||
// return setGlobalConnection();
|
||||
// }
|
||||
// } else {
|
||||
// if (connection == null) {
|
||||
// return setGlobalConnection();
|
||||
// }
|
||||
// if (connection.isClosed()) {
|
||||
// return setGlobalConnection();
|
||||
// }
|
||||
// if (ConfigManager.Database.use_mysql) {
|
||||
// if (!connection.isValid(waitTimeOut)) {
|
||||
// secon = false;
|
||||
// return setGlobalConnection();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } catch (SQLException e) {
|
||||
// e.printStackTrace();
|
||||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// public void closeHikariConnection(Connection connection) {
|
||||
// if (!ConfigManager.Database.enable_pool) {
|
||||
// return;
|
||||
// }
|
||||
// try {
|
||||
// connection.close();
|
||||
// } catch (SQLException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void close() {
|
||||
// try {
|
||||
// if (connection != null) {
|
||||
// connection.close();
|
||||
// }
|
||||
// if (hikari != null) {
|
||||
// hikari.close();
|
||||
// }
|
||||
// } catch (SQLException e) {
|
||||
// AdventureUtil.consoleMessage("<red>[CustomNameplates] Error! Failed to close SQL!</red>");
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,13 @@
|
||||
package net.momirealms.customfishing.data.storage;
|
||||
|
||||
import net.momirealms.customfishing.data.PlayerBagData;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public interface DataStorageInterface {
|
||||
|
||||
Inventory load(OfflinePlayer player);
|
||||
|
||||
void save(PlayerBagData playerBagData);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package net.momirealms.customfishing.data.storage;
|
||||
|
||||
import net.momirealms.customfishing.CustomFishing;
|
||||
import net.momirealms.customfishing.data.PlayerBagData;
|
||||
import net.momirealms.customfishing.util.ConfigUtil;
|
||||
import net.momirealms.customfishing.util.InventoryUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class FileStorageImpl implements DataStorageInterface {
|
||||
|
||||
@Override
|
||||
public Inventory load(OfflinePlayer player) {
|
||||
YamlConfiguration config = ConfigUtil.readData(new File(CustomFishing.plugin.getDataFolder(), "fishingbag_data" + File.separator + player.getUniqueId() + ".yml"));
|
||||
String contents = config.getString("contents");
|
||||
int size = config.getInt("size", 9);
|
||||
ItemStack[] itemStacks = InventoryUtil.getInventoryItems(contents);
|
||||
Inventory inventory = Bukkit.createInventory(null, size, "{CustomFishing_Bag_" + player.getName() + "}");
|
||||
inventory.setContents(itemStacks);
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(PlayerBagData playerBagData) {
|
||||
YamlConfiguration data = new YamlConfiguration();
|
||||
Inventory inventory = playerBagData.getInventory();
|
||||
String contents = InventoryUtil.toBase64(inventory.getContents());
|
||||
data.set("contents", contents);
|
||||
data.set("size", inventory.getSize());
|
||||
try {
|
||||
data.save(new File(CustomFishing.plugin.getDataFolder(), "fishingbag_data" + File.separator + playerBagData.getPlayer().getUniqueId() + ".yml"));
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.momirealms.customfishing.data.storage;
|
||||
|
||||
import net.momirealms.customfishing.data.PlayerBagData;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public class MySQLStorageImpl implements DataStorageInterface {
|
||||
|
||||
@Override
|
||||
public Inventory load(OfflinePlayer player) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(PlayerBagData playerBagData) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package net.momirealms.customfishing.listener;
|
||||
|
||||
import net.momirealms.customfishing.object.Function;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
|
||||
public class InventoryListener implements Listener {
|
||||
|
||||
private final Function function;
|
||||
|
||||
public InventoryListener(Function function) {
|
||||
this.function = function;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onOpen(InventoryOpenEvent event){
|
||||
function.onOpenInventory(event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onClick(InventoryClickEvent event) {
|
||||
function.onClickInventory(event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onClose(InventoryCloseEvent event){
|
||||
function.onCloseInventory(event);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package net.momirealms.customfishing.listener;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import net.momirealms.customfishing.CustomFishing;
|
||||
import net.momirealms.customfishing.object.Function;
|
||||
|
||||
public class WindowPacketListener extends PacketAdapter {
|
||||
|
||||
private final Function function;
|
||||
|
||||
public WindowPacketListener(Function function) {
|
||||
super(CustomFishing.plugin, PacketType.Play.Server.OPEN_WINDOW);
|
||||
this.function = function;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
function.onWindowTitlePacketSend(event.getPacket(), event.getPlayer());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
package net.momirealms.customfishing.manager;
|
||||
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.momirealms.customfishing.CustomFishing;
|
||||
import net.momirealms.customfishing.data.PlayerBagData;
|
||||
import net.momirealms.customfishing.data.storage.DataStorageInterface;
|
||||
import net.momirealms.customfishing.data.storage.FileStorageImpl;
|
||||
import net.momirealms.customfishing.listener.InventoryListener;
|
||||
import net.momirealms.customfishing.listener.SimpleListener;
|
||||
import net.momirealms.customfishing.listener.WindowPacketListener;
|
||||
import net.momirealms.customfishing.object.Function;
|
||||
import net.momirealms.customfishing.util.AdventureUtil;
|
||||
import net.momirealms.customfishing.util.ItemStackUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class BagDataManager extends Function {
|
||||
|
||||
public static HashMap<UUID, PlayerBagData> dataCache;
|
||||
public static HashSet<PlayerBagData> tempCache;
|
||||
private final DataStorageInterface dataStorageInterface;
|
||||
private final InventoryListener inventoryListener;
|
||||
private final WindowPacketListener windowPacketListener;
|
||||
private final SimpleListener simpleListener;
|
||||
|
||||
public BagDataManager() {
|
||||
dataCache = new HashMap<>();
|
||||
tempCache = new HashSet<>();
|
||||
this.dataStorageInterface = new FileStorageImpl();
|
||||
this.inventoryListener = new InventoryListener(this);
|
||||
this.windowPacketListener = new WindowPacketListener(this);
|
||||
this.simpleListener = new SimpleListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
if (!ConfigManager.enableFishingBag) return;
|
||||
Bukkit.getPluginManager().registerEvents(inventoryListener, CustomFishing.plugin);
|
||||
Bukkit.getPluginManager().registerEvents(simpleListener, CustomFishing.plugin);
|
||||
CustomFishing.protocolManager.addPacketListener(windowPacketListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
HandlerList.unregisterAll(inventoryListener);
|
||||
HandlerList.unregisterAll(simpleListener);
|
||||
CustomFishing.protocolManager.removePacketListener(windowPacketListener);
|
||||
for (PlayerBagData playerBagData : dataCache.values()) {
|
||||
dataStorageInterface.save(playerBagData);
|
||||
}
|
||||
}
|
||||
|
||||
public void openFishingBag(Player viewer, OfflinePlayer ownerOffline) {
|
||||
Player owner = ownerOffline.getPlayer();
|
||||
if (owner == null) {
|
||||
Inventory inventory = dataStorageInterface.load(ownerOffline);
|
||||
PlayerBagData playerBagData = new PlayerBagData(ownerOffline, inventory);
|
||||
tempCache.add(playerBagData);
|
||||
viewer.openInventory(inventory);
|
||||
}
|
||||
else {
|
||||
PlayerBagData playerBagData = dataCache.get(owner.getUniqueId());
|
||||
if (playerBagData == null) {
|
||||
AdventureUtil.consoleMessage("<red>[CustomFishing] Unexpected data for " + owner.getName());
|
||||
tryOpen(owner, viewer, readData(owner));
|
||||
}
|
||||
else {
|
||||
tryOpen(owner, viewer, playerBagData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQuit(Player player) {
|
||||
PlayerBagData playerBagData = dataCache.remove(player.getUniqueId());
|
||||
if (playerBagData != null) {
|
||||
dataStorageInterface.save(playerBagData);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onJoin(Player player) {
|
||||
readData(player);
|
||||
}
|
||||
|
||||
public PlayerBagData readData(Player player) {
|
||||
Inventory inventory = dataStorageInterface.load(player);
|
||||
PlayerBagData playerBagData = new PlayerBagData(player, inventory);
|
||||
dataCache.put(player.getUniqueId(), playerBagData);
|
||||
return playerBagData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowTitlePacketSend(PacketContainer packet, Player receiver) {
|
||||
StructureModifier<WrappedChatComponent> wrappedChatComponentStructureModifier = packet.getChatComponents();
|
||||
WrappedChatComponent component = wrappedChatComponentStructureModifier.getValues().get(0);
|
||||
String windowTitleJson = component.getJson();
|
||||
if (windowTitleJson.startsWith("{\"text\":\"{CustomFishing_Bag_")) {
|
||||
String player = windowTitleJson.substring(28, windowTitleJson.length() - 3);
|
||||
String text = ConfigManager.fishingBagTitle.replace("{player}", player);
|
||||
wrappedChatComponentStructureModifier.write(0,
|
||||
WrappedChatComponent.fromJson(
|
||||
GsonComponentSerializer.gson().serialize(
|
||||
MiniMessage.miniMessage().deserialize(
|
||||
ItemStackUtil.replaceLegacy(text)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClickInventory(InventoryClickEvent event) {
|
||||
final Player player = (Player) event.getWhoClicked();
|
||||
PlayerBagData playerBagData = dataCache.get(player.getUniqueId());
|
||||
if (playerBagData == null) return;
|
||||
if (playerBagData.getInventory() == event.getInventory()) {
|
||||
ItemStack currentItem = event.getCurrentItem();
|
||||
if (currentItem == null || currentItem.getType() == Material.AIR) return;
|
||||
NBTItem nbtItem = new NBTItem(currentItem);
|
||||
if (!nbtItem.hasKey("CustomFishing") && !ConfigManager.bagWhiteListItems.contains(currentItem.getType())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCloseInventory(InventoryCloseEvent event) {
|
||||
final Player player = (Player) event.getPlayer();
|
||||
Inventory inventory = event.getInventory();
|
||||
PlayerBagData playerBagData = dataCache.get(player.getUniqueId());
|
||||
if (playerBagData != null) {
|
||||
if (inventory == playerBagData.getInventory()) {
|
||||
for (ItemStack itemStack : event.getInventory().getContents()) {
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR) continue;
|
||||
NBTItem nbtItem = new NBTItem(itemStack);
|
||||
if (nbtItem.hasKey("CustomFishing") || ConfigManager.bagWhiteListItems.contains(itemStack.getType())) continue;
|
||||
player.getInventory().addItem(itemStack.clone());
|
||||
itemStack.setAmount(0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (PlayerBagData temp : tempCache) {
|
||||
if (temp.getInventory() == inventory) {
|
||||
tempCache.remove(temp);
|
||||
dataStorageInterface.save(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void tryOpen(Player owner, Player viewer, PlayerBagData playerBagData) {
|
||||
Inventory inventory = playerBagData.getInventory();
|
||||
int size = 1;
|
||||
for (int i = 6; i > 1; i--) {
|
||||
if (owner.hasPermission("fishingbag.rows." + i)) {
|
||||
size = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (size * 9 != inventory.getSize()) {
|
||||
ItemStack[] itemStacks = playerBagData.getInventory().getContents();
|
||||
Inventory newInv = Bukkit.createInventory(null, size * 9, "{CustomFishing_Bag_" + owner.getName() + "}");
|
||||
newInv.setContents(itemStacks);
|
||||
playerBagData.setInventory(newInv);
|
||||
viewer.openInventory(newInv);
|
||||
}
|
||||
else {
|
||||
viewer.openInventory(inventory);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,12 @@ import net.momirealms.customfishing.util.AdventureUtil;
|
||||
import net.momirealms.customfishing.util.ConfigUtil;
|
||||
import net.momirealms.customfishing.util.JedisUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigManager {
|
||||
@@ -51,6 +53,8 @@ public class ConfigManager {
|
||||
public static boolean addTagToFish;
|
||||
public static boolean logEarning;
|
||||
public static boolean vaultHook;
|
||||
public static String fishingBagTitle;
|
||||
public static HashSet<Material> bagWhiteListItems;
|
||||
|
||||
public static void load() {
|
||||
ConfigUtil.update("config.yml");
|
||||
@@ -107,7 +111,13 @@ public class ConfigManager {
|
||||
lavaMinTime = config.getInt("mechanics.lava-fishing.min-wait-time", 100);
|
||||
lavaMaxTime = config.getInt("mechanics.lava-fishing.max-wait-time", 600) - lavaMinTime;
|
||||
|
||||
addTagToFish = config.getBoolean("mechanics.fishing-bag.can-store-fish", false);
|
||||
enableFishingBag = config.getBoolean("mechanics.fishing-bag.enable", true);
|
||||
addTagToFish = config.getBoolean("mechanics.fishing-bag.can-store-loot", false);
|
||||
fishingBagTitle = config.getString("mechanics.fishing-bag.bag-title", "Fishing Bag");
|
||||
bagWhiteListItems = new HashSet<>();
|
||||
for (String material : config.getStringList("mechanics.fishing-bag.whitelist-items")) {
|
||||
bagWhiteListItems.add(Material.valueOf(material.toUpperCase()));
|
||||
}
|
||||
|
||||
useRedis = false;
|
||||
if (enableCompetition && config.getBoolean("mechanics.fishing-competition.redis", false)) {
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
package net.momirealms.customfishing.manager;
|
||||
|
||||
import net.momirealms.customfishing.object.Function;
|
||||
import net.momirealms.customfishing.util.ConfigUtil;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public class DataManager extends Function {
|
||||
|
||||
public static String user;
|
||||
public static String password;
|
||||
public static String url;
|
||||
public static String ENCODING;
|
||||
public static String tableName;
|
||||
public static boolean enable_pool;
|
||||
public static int maximum_pool_size;
|
||||
public static int minimum_idle;
|
||||
public static int maximum_lifetime;
|
||||
public static int idle_timeout;
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
super.unload();
|
||||
}
|
||||
|
||||
public void loadConfig() {
|
||||
YamlConfiguration config = ConfigUtil.getConfig("database.yml");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.momirealms.customfishing.CustomFishing;
|
||||
import net.momirealms.customfishing.api.event.*;
|
||||
import net.momirealms.customfishing.competition.Competition;
|
||||
import net.momirealms.customfishing.data.PlayerBagData;
|
||||
import net.momirealms.customfishing.integration.AntiGriefInterface;
|
||||
import net.momirealms.customfishing.integration.MobInterface;
|
||||
import net.momirealms.customfishing.integration.item.McMMOTreasure;
|
||||
@@ -39,6 +40,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerFishEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
@@ -198,7 +200,23 @@ public class FishingManager extends Function {
|
||||
}
|
||||
|
||||
if (ConfigManager.enableFishingBag && noBait) {
|
||||
//育儿袋
|
||||
PlayerBagData playerBagData = BagDataManager.dataCache.get(player.getUniqueId());
|
||||
if (playerBagData != null) {
|
||||
Inventory baitInv = playerBagData.getInventory();
|
||||
for (int i = 0; i < baitInv.getSize(); i++) {
|
||||
ItemStack itemStack = baitInv.getItem(i);
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR) continue;
|
||||
NBTItem nbtItem = new NBTItem(itemStack);
|
||||
NBTCompound cfCompound = nbtItem.getCompound("CustomFishing");
|
||||
if (cfCompound == null) continue;
|
||||
if (!cfCompound.getString("type").equals("bait")) continue;
|
||||
Bonus baitBonus = BonusManager.BAIT.get(cfCompound.getString("id"));
|
||||
if (baitBonus != null) {
|
||||
initialBonus.addBonus(baitBonus);
|
||||
itemStack.setAmount(itemStack.getAmount() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RodCastEvent rodCastEvent = new RodCastEvent(player, initialBonus);
|
||||
@@ -388,9 +406,11 @@ public class FishingManager extends Function {
|
||||
return;
|
||||
}
|
||||
|
||||
Bonus bonus = nextBonus.remove(player);
|
||||
|
||||
if (Competition.currentCompetition != null){
|
||||
float score = (float) (droppedItem.getScore() * scoreMultiplier);
|
||||
Competition.currentCompetition.refreshData(player, score, isDouble);
|
||||
Competition.currentCompetition.refreshData(player, (float) (score * bonus.getScore()), isDouble);
|
||||
Competition.currentCompetition.getBossBarManager().tryJoin(player);
|
||||
}
|
||||
|
||||
@@ -428,6 +448,8 @@ public class FishingManager extends Function {
|
||||
return true;
|
||||
}
|
||||
|
||||
nextBonus.remove(player);
|
||||
|
||||
if (Competition.currentCompetition != null){
|
||||
Competition.currentCompetition.refreshData(player, 0, isDouble);
|
||||
Competition.currentCompetition.getBossBarManager().tryJoin(player);
|
||||
@@ -469,6 +491,8 @@ public class FishingManager extends Function {
|
||||
return;
|
||||
}
|
||||
|
||||
nextBonus.remove(player);
|
||||
|
||||
if (Competition.currentCompetition != null){
|
||||
Competition.currentCompetition.refreshData(player, 0, isDouble);
|
||||
Competition.currentCompetition.getBossBarManager().tryJoin(player);
|
||||
@@ -489,9 +513,11 @@ public class FishingManager extends Function {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Competition.currentCompetition != null){
|
||||
Bonus bonus = nextBonus.remove(player);
|
||||
|
||||
if (Competition.currentCompetition != null) {
|
||||
float score = (float) (loot.getScore() * scoreMultiplier);
|
||||
Competition.currentCompetition.refreshData(player, score, false);
|
||||
Competition.currentCompetition.refreshData(player, (float) (score * bonus.getScore()), false);
|
||||
Competition.currentCompetition.getBossBarManager().tryJoin(player);
|
||||
}
|
||||
|
||||
@@ -524,6 +550,9 @@ public class FishingManager extends Function {
|
||||
}
|
||||
|
||||
private void sendSuccessTitle(Player player, String loot) {
|
||||
|
||||
nextLoot.remove(player);
|
||||
|
||||
AdventureUtil.playerTitle(
|
||||
player,
|
||||
ConfigManager.successTitle[new Random().nextInt(ConfigManager.successTitle.length)]
|
||||
@@ -591,6 +620,9 @@ public class FishingManager extends Function {
|
||||
action.doOn(player, null);
|
||||
}
|
||||
|
||||
nextLoot.remove(player);
|
||||
nextBonus.remove(player);
|
||||
|
||||
AdventureUtil.playerTitle(
|
||||
player,
|
||||
ConfigManager.failureTitle[new Random().nextInt(ConfigManager.failureTitle.length)],
|
||||
@@ -654,31 +686,10 @@ public class FishingManager extends Function {
|
||||
}
|
||||
}
|
||||
|
||||
public List<Loot> getPossibleWaterLootList(FishingCondition fishingCondition, boolean finder) {
|
||||
public List<Loot> getPossibleLootList(FishingCondition fishingCondition, boolean finder, Collection<Loot> values) {
|
||||
List<Loot> available = new ArrayList<>();
|
||||
outer:
|
||||
for (Loot loot : LootManager.WATERLOOTS.values()) {
|
||||
if (finder && !loot.isShowInFinder()) continue;
|
||||
RequirementInterface[] requirements = loot.getRequirements();
|
||||
if (requirements == null){
|
||||
available.add(loot);
|
||||
}
|
||||
else {
|
||||
for (RequirementInterface requirement : requirements){
|
||||
if (!requirement.isConditionMet(fishingCondition)){
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
available.add(loot);
|
||||
}
|
||||
}
|
||||
return available;
|
||||
}
|
||||
|
||||
public List<Loot> getPossibleLavaLootList(FishingCondition fishingCondition, boolean finder) {
|
||||
List<Loot> available = new ArrayList<>();
|
||||
outer:
|
||||
for (Loot loot : LootManager.LAVALOOTS.values()) {
|
||||
for (Loot loot : values) {
|
||||
if (finder && !loot.isShowInFinder()) continue;
|
||||
RequirementInterface[] requirements = loot.getRequirements();
|
||||
if (requirements == null){
|
||||
@@ -756,7 +767,9 @@ public class FishingManager extends Function {
|
||||
|
||||
private void useFinder(Player player) {
|
||||
if (isCoolDown(player, 1000)) return;
|
||||
List<Loot> possibleLoots = getPossibleWaterLootList(new FishingCondition(player.getLocation(), player), true);
|
||||
FishingCondition fishingCondition = new FishingCondition(player.getLocation(), player);
|
||||
List<Loot> possibleLoots = getPossibleLootList(fishingCondition, true, LootManager.WATERLOOTS.values());
|
||||
possibleLoots.addAll(getPossibleLootList(fishingCondition, true, LootManager.LAVALOOTS.values()));
|
||||
|
||||
FishFinderEvent fishFinderEvent = new FishFinderEvent(player, possibleLoots);
|
||||
Bukkit.getPluginManager().callEvent(fishFinderEvent);
|
||||
@@ -782,7 +795,6 @@ public class FishingManager extends Function {
|
||||
layout = loot.getLayout()[new Random().nextInt(loot.getLayout().length)];
|
||||
}
|
||||
else {
|
||||
//Not null
|
||||
layout = (Layout) LayoutManager.LAYOUTS.values().stream().toArray()[new Random().nextInt(LayoutManager.LAYOUTS.values().size())];
|
||||
}
|
||||
|
||||
|
||||
@@ -48,92 +48,100 @@ public class IntegrationManager extends Function {
|
||||
this.placeholderManager = new PlaceholderManager();
|
||||
}
|
||||
|
||||
YamlConfiguration config = ConfigUtil.getConfig("config.yml");
|
||||
|
||||
this.blockInterface = new VanillaBlockImpl();
|
||||
|
||||
List<ItemInterface> itemInterfaceList = new ArrayList<>();
|
||||
itemInterfaceList.add(new CustomFishingItemImpl());
|
||||
if (pluginManager.getPlugin("ItemsAdder") != null) itemInterfaceList.add(new ItemsAdderItemImpl());
|
||||
if (pluginManager.getPlugin("Oraxen") != null) itemInterfaceList.add(new OraxenItemImpl());
|
||||
if (pluginManager.getPlugin("MMOItems") != null) itemInterfaceList.add(new MMOItemsItemImpl());
|
||||
if (pluginManager.getPlugin("MythicMobs") != null) {
|
||||
if (config.getBoolean("integrations.ItemsAdder") && pluginManager.getPlugin("ItemsAdder") != null) {
|
||||
this.blockInterface = new ItemsAdderBlockImpl();
|
||||
itemInterfaceList.add(new ItemsAdderItemImpl());
|
||||
hookMessage("ItemsAdder");
|
||||
}
|
||||
if (config.getBoolean("integrations.Oraxen") && pluginManager.getPlugin("Oraxen") != null) {
|
||||
this.blockInterface = new OraxenBlockImpl();
|
||||
itemInterfaceList.add(new OraxenItemImpl());
|
||||
hookMessage("Oraxen");
|
||||
}
|
||||
if (config.getBoolean("integrations.MMOItems") && pluginManager.getPlugin("MMOItems") != null) {
|
||||
itemInterfaceList.add(new MMOItemsItemImpl());
|
||||
hookMessage("MMOItems");
|
||||
}
|
||||
if (config.getBoolean("integrations.MythicMobs") && pluginManager.getPlugin("MythicMobs") != null) {
|
||||
itemInterfaceList.add(new MythicMobsItemImpl());
|
||||
this.mobInterface = new MythicMobsMobImpl();
|
||||
hookMessage("MythicMobs");
|
||||
}
|
||||
this.itemInterfaces = itemInterfaceList.toArray(new ItemInterface[0]);
|
||||
|
||||
if (pluginManager.getPlugin("ItemsAdder") != null) {
|
||||
this.blockInterface = new ItemsAdderBlockImpl();
|
||||
} else if (pluginManager.getPlugin("Oraxen") != null) {
|
||||
this.blockInterface = new OraxenBlockImpl();
|
||||
} else {
|
||||
this.blockInterface = new VanillaBlockImpl();
|
||||
}
|
||||
|
||||
if (pluginManager.getPlugin("eco") != null) {
|
||||
EcoItemRegister.registerItems();
|
||||
hookMessage("eco");
|
||||
}
|
||||
|
||||
YamlConfiguration config = ConfigUtil.getConfig("config.yml");
|
||||
if (config.getBoolean("integration.RealisticSeasons", false) && pluginManager.getPlugin("RealisticSeasons") != null) {
|
||||
if (config.getBoolean("integrations.RealisticSeasons", false) && pluginManager.getPlugin("RealisticSeasons") != null) {
|
||||
this.seasonInterface = new RealisticSeasonsImpl();
|
||||
hookMessage("RealisticSeasons");
|
||||
} else if (config.getBoolean("integration.CustomCrops", false) && pluginManager.getPlugin("CustomCrops") != null) {
|
||||
} else if (config.getBoolean("integrations.CustomCrops", false) && pluginManager.getPlugin("CustomCrops") != null) {
|
||||
this.seasonInterface = new CustomCropsSeasonImpl();
|
||||
hookMessage("CustomCrops");
|
||||
}
|
||||
if (config.getBoolean("integration.mcMMO", false) && Bukkit.getPluginManager().getPlugin("mcMMO") != null) {
|
||||
if (config.getBoolean("integrations.mcMMO", false) && Bukkit.getPluginManager().getPlugin("mcMMO") != null) {
|
||||
this.skillInterface = new mcMMOImpl();
|
||||
hookMessage("mcMMO");
|
||||
} else if (config.getBoolean("integration.MMOCore", false) && Bukkit.getPluginManager().getPlugin("MMOCore") != null) {
|
||||
} else if (config.getBoolean("integrations.MMOCore", false) && Bukkit.getPluginManager().getPlugin("MMOCore") != null) {
|
||||
this.skillInterface = new MMOCoreImpl();
|
||||
hookMessage("MMOCore");
|
||||
} else if (config.getBoolean("integration.AureliumSkills", false) && Bukkit.getPluginManager().getPlugin("AureliumSkills") != null) {
|
||||
} else if (config.getBoolean("integrations.AureliumSkills", false) && Bukkit.getPluginManager().getPlugin("AureliumSkills") != null) {
|
||||
this.skillInterface = new AureliumsImpl();
|
||||
hookMessage("AureliumSkills");
|
||||
} else if (config.getBoolean("integration.EcoSkills", false) && Bukkit.getPluginManager().getPlugin("EcoSkills") != null) {
|
||||
} else if (config.getBoolean("integrations.EcoSkills", false) && Bukkit.getPluginManager().getPlugin("EcoSkills") != null) {
|
||||
this.skillInterface = new EcoSkillsImpl();
|
||||
hookMessage("EcoSkills");
|
||||
} else if (config.getBoolean("integration.JobsReborn", false) && Bukkit.getPluginManager().getPlugin("Jobs") != null) {
|
||||
} else if (config.getBoolean("integrations.JobsReborn", false) && Bukkit.getPluginManager().getPlugin("Jobs") != null) {
|
||||
this.skillInterface = new JobsRebornImpl();
|
||||
hookMessage("JobsReborn");
|
||||
}
|
||||
|
||||
List<AntiGriefInterface> antiGriefsList = new ArrayList<>();
|
||||
if (config.getBoolean("integration.Residence",false)){
|
||||
if (config.getBoolean("integrations.Residence",false)){
|
||||
if (Bukkit.getPluginManager().getPlugin("Residence") == null) Log.warn("Failed to initialize Residence!");
|
||||
else {antiGriefsList.add(new net.momirealms.customfishing.integration.antigrief.ResidenceHook());hookMessage("Residence");}
|
||||
else {antiGriefsList.add(new ResidenceHook());hookMessage("Residence");}
|
||||
}
|
||||
if (config.getBoolean("integration.Kingdoms",false)){
|
||||
if (config.getBoolean("integrations.Kingdoms",false)){
|
||||
if (Bukkit.getPluginManager().getPlugin("Kingdoms") == null) Log.warn("Failed to initialize Kingdoms!");
|
||||
else {antiGriefsList.add(new KingdomsXHook());hookMessage("Kingdoms");}
|
||||
}
|
||||
if (config.getBoolean("integration.WorldGuard",false)){
|
||||
if (config.getBoolean("integrations.WorldGuard",false)){
|
||||
if (Bukkit.getPluginManager().getPlugin("WorldGuard") == null) Log.warn("Failed to initialize WorldGuard!");
|
||||
else {antiGriefsList.add(new WorldGuardHook());hookMessage("WorldGuard");}
|
||||
}
|
||||
if (config.getBoolean("integration.GriefDefender",false)){
|
||||
if (config.getBoolean("integrations.GriefDefender",false)){
|
||||
if(Bukkit.getPluginManager().getPlugin("GriefDefender") == null) Log.warn("Failed to initialize GriefDefender!");
|
||||
else {antiGriefsList.add(new GriefDefenderHook());hookMessage("GriefDefender");}
|
||||
}
|
||||
if (config.getBoolean("integration.PlotSquared",false)){
|
||||
if (config.getBoolean("integrations.PlotSquared",false)){
|
||||
if(Bukkit.getPluginManager().getPlugin("PlotSquared") == null) Log.warn("Failed to initialize PlotSquared!");
|
||||
else {antiGriefsList.add(new PlotSquaredHook());hookMessage("PlotSquared");}
|
||||
}
|
||||
if (config.getBoolean("integration.Towny",false)){
|
||||
if (config.getBoolean("integrations.Towny",false)){
|
||||
if (Bukkit.getPluginManager().getPlugin("Towny") == null) Log.warn("Failed to initialize Towny!");
|
||||
else {antiGriefsList.add(new TownyHook());hookMessage("Towny");}
|
||||
}
|
||||
if (config.getBoolean("integration.Lands",false)){
|
||||
if (config.getBoolean("integrations.Lands",false)){
|
||||
if (Bukkit.getPluginManager().getPlugin("Lands") == null) Log.warn("Failed to initialize Lands!");
|
||||
else {antiGriefsList.add(new LandsHook());hookMessage("Lands");}
|
||||
}
|
||||
if (config.getBoolean("integration.GriefPrevention",false)){
|
||||
if (config.getBoolean("integrations.GriefPrevention",false)){
|
||||
if (Bukkit.getPluginManager().getPlugin("GriefPrevention") == null) Log.warn("Failed to initialize GriefPrevention!");
|
||||
else {antiGriefsList.add(new GriefPreventionHook());hookMessage("GriefPrevention");}
|
||||
}
|
||||
if (config.getBoolean("integration.CrashClaim",false)){
|
||||
if (config.getBoolean("integrations.CrashClaim",false)){
|
||||
if (Bukkit.getPluginManager().getPlugin("CrashClaim") == null) Log.warn("Failed to initialize CrashClaim!");
|
||||
else {antiGriefsList.add(new CrashClaimHook());hookMessage("CrashClaim");}
|
||||
}
|
||||
if (config.getBoolean("integration.BentoBox",false)){
|
||||
if (config.getBoolean("integrations.BentoBox",false)){
|
||||
if (Bukkit.getPluginManager().getPlugin("BentoBox") == null) Log.warn("Failed to initialize BentoBox!");
|
||||
else {antiGriefsList.add(new BentoBoxHook());hookMessage("BentoBox");}
|
||||
}
|
||||
@@ -190,7 +198,7 @@ public class IntegrationManager extends Function {
|
||||
|
||||
@NotNull
|
||||
public ItemStack build(String key) {
|
||||
for (ItemInterface itemInterface : itemInterfaces) {
|
||||
for (ItemInterface itemInterface : getItemInterfaces()) {
|
||||
ItemStack itemStack = itemInterface.build(key);
|
||||
if (itemStack != null) {
|
||||
return itemStack;
|
||||
|
||||
@@ -13,7 +13,8 @@ public class MessageManager {
|
||||
public static String unavailableArgs;
|
||||
public static String escape;
|
||||
public static String noPerm;
|
||||
public static String notExist;
|
||||
public static String itemNotExist;
|
||||
public static String playerNotExist;
|
||||
public static String noConsole;
|
||||
public static String wrongAmount;
|
||||
public static String lackArgs;
|
||||
@@ -42,10 +43,11 @@ public class MessageManager {
|
||||
prefix = config.getString("messages.prefix", "messages.prefix is missing");
|
||||
reload = config.getString("messages.reload", "messages.reload is missing");
|
||||
nonArgs = config.getString("messages.none-args", "messages.none-args is missing");
|
||||
unavailableArgs = config.getString("messages.none-args", "messages.invalid-args is missing");
|
||||
unavailableArgs = config.getString("messages.invalid-args", "messages.invalid-args is missing");
|
||||
escape = config.getString("messages.escape", "messages.escape is missing");
|
||||
noPerm = config.getString("messages.no-perm", "messages.no-perm is missing");
|
||||
notExist = config.getString("messages.not-exist", "messages.not-exist is missing");
|
||||
itemNotExist = config.getString("messages.item-not-exist", "messages.item-not-exist is missing");
|
||||
playerNotExist = config.getString("messages.player-not-exist", "messages.player-not-exist is missing");
|
||||
noConsole = config.getString("messages.no-console", "messages.no-console is missing");
|
||||
wrongAmount = config.getString("messages.wrong-amount", "messages.wrong-amount is missing");
|
||||
lackArgs = config.getString("messages.lack-args", "messages.lack-args is missing");
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
package net.momirealms.customfishing.manager;
|
||||
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import de.tr7zw.changeme.nbtapi.NBTCompound;
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.momirealms.customfishing.CustomFishing;
|
||||
import net.momirealms.customfishing.integration.VaultHook;
|
||||
import net.momirealms.customfishing.integration.papi.PlaceholderManager;
|
||||
import net.momirealms.customfishing.listener.InventoryListener;
|
||||
import net.momirealms.customfishing.listener.WindowPacketListener;
|
||||
import net.momirealms.customfishing.object.Function;
|
||||
import net.momirealms.customfishing.object.loot.Item;
|
||||
import net.momirealms.customfishing.object.sell.ContainerPacketListener;
|
||||
import net.momirealms.customfishing.object.sell.InventoryListener;
|
||||
import net.momirealms.customfishing.util.AdventureUtil;
|
||||
import net.momirealms.customfishing.util.ConfigUtil;
|
||||
import net.momirealms.customfishing.util.ItemStackUtil;
|
||||
@@ -21,7 +27,9 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.inventory.*;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@@ -29,7 +37,7 @@ import java.util.*;
|
||||
|
||||
public class SellManager extends Function {
|
||||
|
||||
private final ContainerPacketListener containerPacketListener;
|
||||
private final WindowPacketListener windowPacketListener;
|
||||
private final InventoryListener inventoryListener;
|
||||
public static String formula;
|
||||
public static String title;
|
||||
@@ -56,7 +64,7 @@ public class SellManager extends Function {
|
||||
private final HashMap<Player, Long> coolDown;
|
||||
|
||||
public SellManager() {
|
||||
this.containerPacketListener = new ContainerPacketListener();
|
||||
this.windowPacketListener = new WindowPacketListener(this);
|
||||
this.inventoryListener = new InventoryListener(this);
|
||||
this.inventoryCache = new HashMap<>();
|
||||
this.coolDown = new HashMap<>();
|
||||
@@ -65,7 +73,7 @@ public class SellManager extends Function {
|
||||
@Override
|
||||
public void load() {
|
||||
loadConfig();
|
||||
CustomFishing.protocolManager.addPacketListener(containerPacketListener);
|
||||
CustomFishing.protocolManager.addPacketListener(windowPacketListener);
|
||||
Bukkit.getPluginManager().registerEvents(inventoryListener, CustomFishing.plugin);
|
||||
}
|
||||
|
||||
@@ -75,7 +83,7 @@ public class SellManager extends Function {
|
||||
player.closeInventory();
|
||||
}
|
||||
this.inventoryCache.clear();
|
||||
CustomFishing.protocolManager.removePacketListener(containerPacketListener);
|
||||
CustomFishing.protocolManager.removePacketListener(windowPacketListener);
|
||||
HandlerList.unregisterAll(inventoryListener);
|
||||
}
|
||||
|
||||
@@ -146,7 +154,7 @@ public class SellManager extends Function {
|
||||
|
||||
public void openGuiForPlayer(Player player) {
|
||||
player.closeInventory();
|
||||
Inventory inventory = Bukkit.createInventory(player, guiSize, "{CustomFishing}");
|
||||
Inventory inventory = Bukkit.createInventory(player, guiSize, "{CustomFishing_Sell}");
|
||||
for (Map.Entry<Integer, ItemStack> entry : guiItems.entrySet()) {
|
||||
inventory.setItem(entry.getKey(), entry.getValue());
|
||||
}
|
||||
@@ -155,7 +163,8 @@ public class SellManager extends Function {
|
||||
if (openKey != null) AdventureUtil.playerSound(player, soundSource, openKey, 1, 1);
|
||||
}
|
||||
|
||||
public void onOpen(InventoryOpenEvent event) {
|
||||
@Override
|
||||
public void onOpenInventory(InventoryOpenEvent event) {
|
||||
final Player player = (Player) event.getPlayer();
|
||||
Inventory inventory = inventoryCache.get(player);
|
||||
if (inventory == null) return;
|
||||
@@ -166,7 +175,8 @@ public class SellManager extends Function {
|
||||
}
|
||||
}
|
||||
|
||||
public void onClick(InventoryClickEvent event) {
|
||||
@Override
|
||||
public void onClickInventory(InventoryClickEvent event) {
|
||||
final Player player = (Player) event.getView().getPlayer();
|
||||
Inventory inventory = inventoryCache.get(player);
|
||||
if (inventory == null) return;
|
||||
@@ -214,7 +224,8 @@ public class SellManager extends Function {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onClose(InventoryCloseEvent event) {
|
||||
@Override
|
||||
public void onCloseInventory(InventoryCloseEvent event) {
|
||||
final Player player = (Player) event.getPlayer();
|
||||
Inventory inventory = inventoryCache.remove(player);
|
||||
if (inventory == null) return;
|
||||
@@ -301,4 +312,24 @@ public class SellManager extends Function {
|
||||
if (successKey != null) AdventureUtil.playerSound(player, soundSource, successKey, 1, 1);
|
||||
if (ConfigManager.vaultHook) VaultHook.economy.depositPlayer(player, earnings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowTitlePacketSend(PacketContainer packet, Player player) {
|
||||
StructureModifier<WrappedChatComponent> wrappedChatComponentStructureModifier = packet.getChatComponents();
|
||||
WrappedChatComponent component = wrappedChatComponentStructureModifier.getValues().get(0);
|
||||
if (component.getJson().equals("{\"text\":\"{CustomFishing_Sell}\"}")) {
|
||||
PlaceholderManager placeholderManager = CustomFishing.plugin.getIntegrationManager().getPlaceholderManager();
|
||||
String text = SellManager.title.replace("{player}", player.getName());
|
||||
if (placeholderManager != null) placeholderManager.parse(player, text);
|
||||
wrappedChatComponentStructureModifier.write(0,
|
||||
WrappedChatComponent.fromJson(
|
||||
GsonComponentSerializer.gson().serialize(
|
||||
MiniMessage.miniMessage().deserialize(
|
||||
ItemStackUtil.replaceLegacy(text)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package net.momirealms.customfishing.object;
|
||||
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.*;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
public class Function {
|
||||
@@ -24,4 +26,23 @@ public class Function {
|
||||
public void onInteract(PlayerInteractEvent event) {
|
||||
//empty
|
||||
}
|
||||
|
||||
public void onWindowTitlePacketSend(PacketContainer packet, Player receiver) {
|
||||
|
||||
}
|
||||
|
||||
public void onCloseInventory(InventoryCloseEvent event) {
|
||||
}
|
||||
|
||||
public void onClickInventory(InventoryClickEvent event) {
|
||||
}
|
||||
|
||||
public void onOpenInventory(InventoryOpenEvent event) {
|
||||
}
|
||||
|
||||
public void onDragInventory(InventoryDragEvent event) {
|
||||
}
|
||||
|
||||
public void onMoveItemInventory(InventoryMoveItemEvent event) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,6 @@ public class TextCache {
|
||||
return latestValue;
|
||||
}
|
||||
|
||||
//返回更新结果是否不一致
|
||||
public boolean update() {
|
||||
String string = originalValue;
|
||||
if (ownerPlaceholders.length != 0) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.momirealms.customfishing.object.fishing;
|
||||
import net.momirealms.customfishing.CustomFishing;
|
||||
import net.momirealms.customfishing.manager.ConfigManager;
|
||||
import net.momirealms.customfishing.manager.FishingManager;
|
||||
import net.momirealms.customfishing.manager.LootManager;
|
||||
import net.momirealms.customfishing.object.loot.Loot;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@@ -71,7 +72,7 @@ public class BobberCheckTask extends BukkitRunnable {
|
||||
}
|
||||
if (fishHook.isInWater()) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(CustomFishing.plugin, () -> {
|
||||
List<Loot> possibleLoots = fishingManager.getPossibleWaterLootList(new FishingCondition(fishHook.getLocation(), player), false);
|
||||
List<Loot> possibleLoots = fishingManager.getPossibleLootList(new FishingCondition(fishHook.getLocation(), player), false, LootManager.WATERLOOTS.values());
|
||||
fishingManager.getNextLoot(player, bonus, possibleLoots);
|
||||
});
|
||||
stop();
|
||||
@@ -108,7 +109,7 @@ public class BobberCheckTask extends BukkitRunnable {
|
||||
|
||||
private void randomTime() {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(CustomFishing.plugin, () -> {
|
||||
List<Loot> possibleLoots = fishingManager.getPossibleLavaLootList(new FishingCondition(fishHook.getLocation(), player), false);
|
||||
List<Loot> possibleLoots = fishingManager.getPossibleLootList(new FishingCondition(fishHook.getLocation(), player), false, LootManager.LAVALOOTS.values());
|
||||
fishingManager.getNextLoot(player, bonus, possibleLoots);
|
||||
});
|
||||
cancelTask();
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
package net.momirealms.customfishing.object.sell;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.momirealms.customfishing.CustomFishing;
|
||||
import net.momirealms.customfishing.integration.papi.PlaceholderManager;
|
||||
import net.momirealms.customfishing.manager.SellManager;
|
||||
import net.momirealms.customfishing.util.ItemStackUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ContainerPacketListener extends PacketAdapter {
|
||||
|
||||
public ContainerPacketListener() {
|
||||
super(CustomFishing.plugin, PacketType.Play.Server.OPEN_WINDOW);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
PacketContainer packet = event.getPacket();
|
||||
StructureModifier<WrappedChatComponent> wrappedChatComponentStructureModifier = packet.getChatComponents();
|
||||
WrappedChatComponent component = wrappedChatComponentStructureModifier.getValues().get(0);
|
||||
if (component.getJson().equals("{\"text\":\"{CustomFishing}\"}")) {
|
||||
PlaceholderManager placeholderManager = CustomFishing.plugin.getIntegrationManager().getPlaceholderManager();
|
||||
Player player = event.getPlayer();
|
||||
String text = SellManager.title.replace("{player}", player.getName());
|
||||
if (placeholderManager != null) placeholderManager.parse(player, text);
|
||||
wrappedChatComponentStructureModifier.write(0,
|
||||
WrappedChatComponent.fromJson(
|
||||
GsonComponentSerializer.gson().serialize(
|
||||
MiniMessage.miniMessage().deserialize(
|
||||
ItemStackUtil.replaceLegacy(text)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package net.momirealms.customfishing.object.sell;
|
||||
|
||||
import net.momirealms.customfishing.manager.SellManager;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.*;
|
||||
|
||||
public class InventoryListener implements Listener {
|
||||
|
||||
private final SellManager sellManager;
|
||||
|
||||
public InventoryListener(SellManager sellManager) {
|
||||
this.sellManager = sellManager;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onOpen(InventoryOpenEvent event){
|
||||
sellManager.onOpen(event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onClick(InventoryClickEvent event) {
|
||||
sellManager.onClick(event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onClose(InventoryCloseEvent event){
|
||||
sellManager.onClose(event);
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,8 @@ public class ConfigUtil {
|
||||
CustomFishing.plugin.getIntegrationManager().load();
|
||||
CustomFishing.plugin.getSellManager().unload();
|
||||
CustomFishing.plugin.getSellManager().load();
|
||||
CustomFishing.plugin.getBagDataManager().unload();
|
||||
CustomFishing.plugin.getBagDataManager().load();
|
||||
try {
|
||||
Reflection.load();
|
||||
}
|
||||
@@ -57,4 +59,17 @@ public class ConfigUtil {
|
||||
Log.warn(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static YamlConfiguration readData(File file) {
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.getParentFile().mkdirs();
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
AdventureUtil.consoleMessage("<red>[CustomFishing] Failed to generate data files!</red>");
|
||||
}
|
||||
}
|
||||
return YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package net.momirealms.customfishing.util;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.io.BukkitObjectInputStream;
|
||||
import org.bukkit.util.io.BukkitObjectOutputStream;
|
||||
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class InventoryUtil {
|
||||
|
||||
public static String toBase64(ItemStack[] contents) {
|
||||
boolean convert = false;
|
||||
|
||||
for (ItemStack item : contents) {
|
||||
if (item != null) {
|
||||
convert = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (convert) {
|
||||
try {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
|
||||
|
||||
dataOutput.writeInt(contents.length);
|
||||
|
||||
for (ItemStack stack : contents) {
|
||||
dataOutput.writeObject(stack);
|
||||
}
|
||||
dataOutput.close();
|
||||
byte[] byteArr = outputStream.toByteArray();
|
||||
return Base64Coder.encodeLines(byteArr);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Unable to save item stacks.", e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ItemStack[] getInventoryItems(String base64) {
|
||||
ItemStack[] itemStacks = null;
|
||||
try {
|
||||
itemStacks = stacksFromBase64(base64);
|
||||
} catch (IllegalArgumentException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
return itemStacks;
|
||||
}
|
||||
|
||||
private static ItemStack[] stacksFromBase64(String data) {
|
||||
if (data == null) return new ItemStack[]{};
|
||||
|
||||
ByteArrayInputStream inputStream;
|
||||
try {
|
||||
inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return new ItemStack[]{};
|
||||
}
|
||||
|
||||
BukkitObjectInputStream dataInput = null;
|
||||
ItemStack[] stacks = null;
|
||||
try {
|
||||
dataInput = new BukkitObjectInputStream(inputStream);
|
||||
stacks = new ItemStack[dataInput.readInt()];
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (stacks == null) return new ItemStack[]{};
|
||||
|
||||
for (int i = 0; i < stacks.length; i++) {
|
||||
try {
|
||||
stacks[i] = (ItemStack) dataInput.readObject();
|
||||
}
|
||||
catch (IOException | ClassNotFoundException | NullPointerException e) {
|
||||
try {
|
||||
dataInput.close();
|
||||
} catch (IOException exception) {
|
||||
AdventureUtil.consoleMessage("<red>[CustomFishing] Error! Failed to read fishing bag data");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
dataInput.close();
|
||||
} catch (IOException ignored) {
|
||||
|
||||
}
|
||||
return stacks;
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ public class NBTUtil {
|
||||
nbtCompound.getFloatList(key).add(Float.valueOf(value.substring(8)));
|
||||
} else if (value.startsWith("(Int) ")) {
|
||||
nbtCompound.getIntegerList(key).add(Integer.valueOf(value.substring(6)));
|
||||
} else if (value.startsWith("(IntArray) ")){
|
||||
} else if (value.startsWith("(IntArray) ")) {
|
||||
String[] split = value.substring(11).replace("[","").replace("]","").replaceAll("\\s", "").split(",");
|
||||
int[] array = Arrays.stream(split).mapToInt(Integer::parseInt).toArray();
|
||||
nbtCompound.getIntArrayList(key).add(array);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
# don't change
|
||||
config-version: '10'
|
||||
|
||||
# cn/en/es
|
||||
lang: en
|
||||
# chinese/english/spanish
|
||||
lang: english
|
||||
|
||||
# Plugin hooks
|
||||
integration:
|
||||
integrations:
|
||||
# Sell fish
|
||||
Vault: true
|
||||
# Skill-xp
|
||||
@@ -28,6 +28,13 @@ integration:
|
||||
GriefPrevention: false
|
||||
CrashClaim: false
|
||||
BentoBox: false
|
||||
# Mobs & Items
|
||||
MythicMobs: false
|
||||
# Items & Totem Blocks
|
||||
ItemsAdder: false
|
||||
Oraxen: false
|
||||
# Items
|
||||
MMOItems: false
|
||||
|
||||
# Worlds where fishing mechanic takes effects
|
||||
worlds:
|
||||
@@ -73,10 +80,14 @@ mechanics:
|
||||
# Fishing bag is a place where players can store their baits, utils, rods (Fish optional)
|
||||
fishing-bag:
|
||||
enable: true
|
||||
# This would add additional NBT Tags to the fish
|
||||
can-store-fish: false
|
||||
bag-title: '<blue>{player}''s Fishing Bag'
|
||||
# This would add additional NBT Tags to the loot
|
||||
can-store-loot: false
|
||||
# File/MySql
|
||||
data-storage-mode: File
|
||||
# Other whitelist-items
|
||||
whitelist-items:
|
||||
- fishing_rod
|
||||
# Lava fishing settings
|
||||
lava-fishing:
|
||||
# ticks
|
||||
|
||||
@@ -46,7 +46,7 @@ rainbow_fish:
|
||||
bonus: 0.3
|
||||
|
||||
# Custom NBT tags
|
||||
# If you are not sure about the NBT tag. You can use command '/cfishing import xxx'
|
||||
# If you are not sure about the NBT tag. You can use command '/customfishing import xxx'
|
||||
# (Int) (Byte) (String) (Float) (String) (Double) (Short) (Long) (UUID) (Boolean) (IntArray) (ByteArray)
|
||||
nbt:
|
||||
itemsadder:
|
||||
@@ -156,10 +156,6 @@ rainbow_fish:
|
||||
#Requires skill plugin
|
||||
skill-level: 10
|
||||
|
||||
#Requires WorldGuard
|
||||
region:
|
||||
- fishingpool
|
||||
|
||||
#Requires Season Plugin
|
||||
season:
|
||||
- Spring
|
||||
|
||||
@@ -5,7 +5,8 @@ messages:
|
||||
reload: '重载成功.'
|
||||
no-perm: '你没有权限!'
|
||||
not-online: '玩家 {Player} 不在线!'
|
||||
not-exist: '此物品不存在!'
|
||||
item-not-exist: '此物品不存在!'
|
||||
player-not-exist: '此玩家不存在!'
|
||||
escape: '太久没拉钩鱼儿跑走啦!'
|
||||
give-item: '成功给予玩家 {Player} {Amount}x {Item}.'
|
||||
get-item: '成功获得 {Amount}x {Item}.'
|
||||
@@ -5,7 +5,8 @@ messages:
|
||||
reload: 'Reloaded'
|
||||
no-perm: 'You don''t have permission!'
|
||||
not-online: 'That player is not online!'
|
||||
not-exist: 'That item does not exist!'
|
||||
item-not-exist: 'That item does not exist!'
|
||||
player-not-exist: 'That player does not exist!'
|
||||
escape: 'It has been too long since I pulled the hook and the fish ran away!'
|
||||
give-item: 'Successfully given players {Player} {Amount}x {Item}.'
|
||||
get-item: 'Successfully obtained {Amount}x {Item}.'
|
||||
@@ -5,7 +5,8 @@ messages:
|
||||
reload: 'Recarga con éxito.'
|
||||
no-perm: 'No tienes permiso.'
|
||||
not-online: 'Los jugadores no están en línea.'
|
||||
not-exist: 'Este artículo no existe.'
|
||||
item-not-exist: '此物品不存在!'
|
||||
player-not-exist: '此玩家不存在!'
|
||||
escape: 'Ha pasado demasiado tiempo desde que tiré del anzuelo y el pez huyó.'
|
||||
give-item: 'Se dio con éxito a los jugadores {Player} {Amount}x {Item}.'
|
||||
get-item: 'Obtenido con éxito {Amount}x {Item}.'
|
||||
@@ -31,7 +31,6 @@ commands:
|
||||
fishingbag:
|
||||
usage: /fishingbag open
|
||||
description: fishing bag command
|
||||
permission: customfishing.fishingbag
|
||||
sellfish:
|
||||
usage: /sellfish
|
||||
description: fishing bag command
|
||||
@@ -42,12 +41,24 @@ permissions:
|
||||
description: Gives access to all customfishing commands
|
||||
children:
|
||||
customfishing.admin: true
|
||||
customfishing.fishingbag: true
|
||||
customfishing.sellfish: true
|
||||
customfishing.fishingbag: true
|
||||
|
||||
customfishing.admin:
|
||||
default: op
|
||||
customfishing.fishingbag:
|
||||
default: true
|
||||
customfishing.sellfish:
|
||||
default: true
|
||||
fishingbag.rows.1:
|
||||
default: true
|
||||
fishingbag.rows.2:
|
||||
default: false
|
||||
fishingbag.rows.3:
|
||||
default: false
|
||||
fishingbag.rows.4:
|
||||
default: false
|
||||
fishingbag.rows.5:
|
||||
default: false
|
||||
fishingbag.rows.6:
|
||||
default: false
|
||||
fishingbag.open:
|
||||
default: true
|
||||
@@ -18,7 +18,6 @@ silver_fishing_rod:
|
||||
display:
|
||||
name: 'Silver Fishing Rod'
|
||||
custom-model-data: 3
|
||||
can-fish-in-lave: true
|
||||
modifier:
|
||||
weight-add:
|
||||
silver: 20
|
||||
|
||||
Reference in New Issue
Block a user