Compare commits
13 Commits
tpwCommand
...
master
| Author | SHA1 | Date |
|---|---|---|
|
|
8f8d7b576b | 1 year ago |
|
|
db73025bfb | 1 year ago |
|
|
886a17621e | 1 year ago |
|
|
71ee856925 | 1 year ago |
|
|
c322e47706 | 1 year ago |
|
|
d34b7892fe | 1 year ago |
|
|
55566b5e2e | 1 year ago |
|
|
c71ff3f6e8 | 1 year ago |
|
|
a33be13ab2 | 1 year ago |
|
|
b7745c4a90 | 1 year ago |
|
|
5f28885b1a | 1 year ago |
|
|
44820ee592 | 1 year ago |
|
|
394a0cbcae | 1 year ago |
21 changed files with 971 additions and 197 deletions
@ -0,0 +1,104 @@ |
|||||||
|
package xyz.soukup.mineconomiaCoreV2.commands; |
||||||
|
|
||||||
|
import org.bukkit.Bukkit; |
||||||
|
import org.bukkit.Material; |
||||||
|
import org.bukkit.command.Command; |
||||||
|
import org.bukkit.command.CommandSender; |
||||||
|
import org.bukkit.command.TabExecutor; |
||||||
|
import org.bukkit.entity.Player; |
||||||
|
import org.bukkit.inventory.ItemStack; |
||||||
|
import org.bukkit.inventory.meta.ItemMeta; |
||||||
|
import org.bukkit.persistence.PersistentDataType; |
||||||
|
import org.jetbrains.annotations.NotNull; |
||||||
|
import org.jetbrains.annotations.Nullable; |
||||||
|
import xyz.soukup.mineconomiaCoreV2.tools.LangManager; |
||||||
|
import xyz.soukup.mineconomiaCoreV2.tools.PDC; |
||||||
|
import xyz.soukup.mineconomiaCoreV2.variables.Transaction; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.sql.SQLException; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
import static xyz.soukup.mineconomiaCoreV2.core.sharedValues.config; |
||||||
|
|
||||||
|
public class admin implements TabExecutor { |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) { |
||||||
|
|
||||||
|
|
||||||
|
if (!commandSender.isOp()) { |
||||||
|
LangManager.message(commandSender, "error.command.no-permissions"); |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
if (strings.length == 0){ |
||||||
|
LangManager.message(commandSender, "error.command.not-enough-arguments"); |
||||||
|
} |
||||||
|
|
||||||
|
switch (strings[0].toLowerCase()){ |
||||||
|
case "setruleritem": |
||||||
|
setRulerItem(commandSender); |
||||||
|
return true; |
||||||
|
case "givemoney": |
||||||
|
try { |
||||||
|
giveMoney(commandSender, strings); |
||||||
|
} catch (SQLException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
return true; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) { |
||||||
|
|
||||||
|
if (strings.length == 1 && commandSender.isOp()) { |
||||||
|
return List.of("setRulerItem", "giveMoney"); |
||||||
|
} |
||||||
|
|
||||||
|
return List.of(); |
||||||
|
} |
||||||
|
|
||||||
|
private void giveMoney(CommandSender commandSender, String[] strings) throws SQLException { |
||||||
|
if (strings.length < 3){ |
||||||
|
LangManager.message(commandSender, "error.command.not-enough-arguments"); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
Float amount = Float.valueOf(strings[2]); |
||||||
|
|
||||||
|
Transaction.prepareTransaction("server", "server", strings[1], "player", amount, "admin").process(); |
||||||
|
LangManager.message(commandSender, "success.command.admin.give-money"); |
||||||
|
} |
||||||
|
|
||||||
|
private void setRulerItem(CommandSender commandSender){ |
||||||
|
Player player = (Player) commandSender; |
||||||
|
|
||||||
|
ItemStack playerHand = player.getInventory().getItemInMainHand(); |
||||||
|
|
||||||
|
if (playerHand.getType() == Material.AIR) { |
||||||
|
LangManager.message(commandSender, "error.command.admin.setruleritem.invalid-item"); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
ItemMeta meta = playerHand.getItemMeta(); |
||||||
|
assert meta != null; |
||||||
|
PDC.WriteItemMetaPDC(meta, "ruler", PersistentDataType.INTEGER, 1); |
||||||
|
playerHand.setItemMeta(meta); |
||||||
|
|
||||||
|
config.set("special-items.ruler", playerHand); |
||||||
|
|
||||||
|
try { |
||||||
|
config.save("config.yml"); |
||||||
|
} catch (IOException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
|
||||||
|
LangManager.message(commandSender, "success.command.admin.setruleritem"); |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,21 @@ |
|||||||
|
package xyz.soukup.mineconomiaCoreV2.commands; |
||||||
|
|
||||||
|
import org.bukkit.command.Command; |
||||||
|
import org.bukkit.command.CommandSender; |
||||||
|
import org.bukkit.command.TabExecutor; |
||||||
|
import org.jetbrains.annotations.NotNull; |
||||||
|
import org.jetbrains.annotations.Nullable; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
public class money implements TabExecutor { |
||||||
|
@Override |
||||||
|
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) { |
||||||
|
return List.of(); |
||||||
|
} |
||||||
|
} |
||||||
@ -1,4 +1,4 @@ |
|||||||
package commands; |
package xyz.soukup.mineconomiaCoreV2.commands; |
||||||
|
|
||||||
import org.bukkit.Bukkit; |
import org.bukkit.Bukkit; |
||||||
import org.bukkit.World; |
import org.bukkit.World; |
||||||
@ -0,0 +1,61 @@ |
|||||||
|
package xyz.soukup.mineconomiaCoreV2.database; |
||||||
|
|
||||||
|
import com.google.protobuf.TypeRegistry; |
||||||
|
import com.j256.ormlite.dao.Dao; |
||||||
|
import com.j256.ormlite.dao.DaoManager; |
||||||
|
import com.j256.ormlite.jdbc.JdbcConnectionSource; |
||||||
|
import com.j256.ormlite.support.ConnectionSource; |
||||||
|
import com.j256.ormlite.table.TableUtils; |
||||||
|
import xyz.soukup.mineconomiaCoreV2.variables.*; |
||||||
|
|
||||||
|
import java.sql.SQLException; |
||||||
|
|
||||||
|
import static xyz.soukup.mineconomiaCoreV2.core.sharedValues.config; |
||||||
|
import static xyz.soukup.mineconomiaCoreV2.core.sharedValues.logger; |
||||||
|
|
||||||
|
public class DatabaseUtil { |
||||||
|
public static Dao<PlayerData, Integer> playerDataDao; |
||||||
|
public static Dao<Island, Integer> islandDao; |
||||||
|
public static Dao<Shop, Integer> shopDao; |
||||||
|
public static Dao<Transaction, Integer> transactionDao; |
||||||
|
public static Dao<Group, Integer> groupDao; |
||||||
|
public static Dao<GroupMembership, Integer> groupMembershipDao; |
||||||
|
|
||||||
|
public static ConnectionSource getConnectionSource() throws SQLException { |
||||||
|
String host = config.getString("database.host"); |
||||||
|
String port = config.getString("database.port"); |
||||||
|
String user = config.getString("database.user"); |
||||||
|
String password = config.getString("database.password"); |
||||||
|
String database = config.getString("database.database"); |
||||||
|
|
||||||
|
String url = "jdbc:mysql://" + host + ":" + port + "/" + database; |
||||||
|
|
||||||
|
return new JdbcConnectionSource(url, user, password); |
||||||
|
} |
||||||
|
|
||||||
|
public static void createTables(ConnectionSource connectionSource) throws SQLException { |
||||||
|
TableUtils.createTableIfNotExists(connectionSource, PlayerData.class); |
||||||
|
TableUtils.createTableIfNotExists(connectionSource, Transaction.class); |
||||||
|
TableUtils.createTableIfNotExists(connectionSource, Island.class); |
||||||
|
TableUtils.createTableIfNotExists(connectionSource, Shop.class); |
||||||
|
TableUtils.createTableIfNotExists(connectionSource, Group.class); |
||||||
|
TableUtils.createTableIfNotExists(connectionSource, GroupMembership.class); |
||||||
|
} |
||||||
|
|
||||||
|
public static void daoInit(ConnectionSource connectionSource) throws SQLException { |
||||||
|
islandDao = DaoManager.createDao(connectionSource, Island.class); |
||||||
|
playerDataDao = DaoManager.createDao(connectionSource, PlayerData.class); |
||||||
|
shopDao = DaoManager.createDao(connectionSource, Shop.class); |
||||||
|
transactionDao = DaoManager.createDao(connectionSource, Transaction.class); |
||||||
|
groupDao = DaoManager.createDao(connectionSource, Group.class); |
||||||
|
groupMembershipDao = DaoManager.createDao(connectionSource, GroupMembership.class); |
||||||
|
} |
||||||
|
|
||||||
|
public static void databaseInit() throws SQLException { |
||||||
|
ConnectionSource connectionSource = getConnectionSource(); |
||||||
|
|
||||||
|
createTables(connectionSource); |
||||||
|
daoInit(connectionSource); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -1,113 +0,0 @@ |
|||||||
package xyz.soukup.mineconomiaCoreV2.database; |
|
||||||
|
|
||||||
import jakarta.persistence.Query; |
|
||||||
import jakarta.persistence.criteria.CriteriaBuilder; |
|
||||||
import jakarta.persistence.criteria.CriteriaQuery; |
|
||||||
import org.bukkit.scoreboard.Criteria; |
|
||||||
import org.hibernate.Session; |
|
||||||
import org.hibernate.SessionFactory; |
|
||||||
import org.hibernate.Transaction; |
|
||||||
import org.hibernate.boot.MetadataSources; |
|
||||||
import org.hibernate.boot.model.internal.QueryBinder; |
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistry; |
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; |
|
||||||
import xyz.soukup.mineconomiaCoreV2.core.sharedValues; |
|
||||||
import xyz.soukup.mineconomiaCoreV2.variables.PlayerData; |
|
||||||
|
|
||||||
import java.util.List; |
|
||||||
import java.util.Objects; |
|
||||||
import java.util.Properties; |
|
||||||
|
|
||||||
import static xyz.soukup.mineconomiaCoreV2.core.sharedValues.config; |
|
||||||
import static xyz.soukup.mineconomiaCoreV2.core.sharedValues.logger; |
|
||||||
|
|
||||||
public class HibernateUtil { |
|
||||||
private static SessionFactory sessionFactory; |
|
||||||
|
|
||||||
static { |
|
||||||
|
|
||||||
try { |
|
||||||
|
|
||||||
StandardServiceRegistry registry = new StandardServiceRegistryBuilder() |
|
||||||
.applySettings(getHibernateProperties()) |
|
||||||
.build(); |
|
||||||
|
|
||||||
sessionFactory = new MetadataSources(registry) |
|
||||||
.addAnnotatedClass(PlayerData.class) |
|
||||||
.buildMetadata() |
|
||||||
.buildSessionFactory(); |
|
||||||
|
|
||||||
} catch (Exception e) { |
|
||||||
|
|
||||||
sharedValues.logger.warning(e.toString()); |
|
||||||
|
|
||||||
if (sessionFactory != null) { |
|
||||||
sessionFactory.close(); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
private static Properties getHibernateProperties() { |
|
||||||
|
|
||||||
String host = config.getString("database.host"); |
|
||||||
String port = config.getString("database.port"); |
|
||||||
String user = config.getString("database.user"); |
|
||||||
String password = config.getString("database.password"); |
|
||||||
String database = config.getString("database.database"); |
|
||||||
|
|
||||||
String jdbcString = "jdbc:mysql://" + host + ":" + port + "/" + database; |
|
||||||
|
|
||||||
Properties properties = new Properties(); |
|
||||||
properties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect"); |
|
||||||
properties.put("hibernate.connection.driver_class", "com.mysql.cj.jdbc.Driver"); |
|
||||||
properties.put("hibernate.connection.url", jdbcString); |
|
||||||
properties.put("hibernate.connection.username", user); |
|
||||||
properties.put("hibernate.connection.password", password); |
|
||||||
properties.put("hibernate.hbm2ddl.auto", "update"); |
|
||||||
properties.put("hibernate.show_sql", "true"); |
|
||||||
return properties; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public static SessionFactory getSessionFactory() { |
|
||||||
return sessionFactory; |
|
||||||
} |
|
||||||
|
|
||||||
public static Session newSession(){ |
|
||||||
return getSessionFactory().openSession(); |
|
||||||
} |
|
||||||
|
|
||||||
public static void shutdown() { |
|
||||||
if (sessionFactory != null) { |
|
||||||
sessionFactory.close(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public static void saveToDatabase(Object object){ |
|
||||||
|
|
||||||
Session session = HibernateUtil.newSession(); |
|
||||||
Transaction transaction = null; |
|
||||||
|
|
||||||
try { |
|
||||||
|
|
||||||
transaction = session.beginTransaction(); |
|
||||||
session.persist(object); |
|
||||||
transaction.commit(); |
|
||||||
session.close(); |
|
||||||
|
|
||||||
}catch (Exception e){ |
|
||||||
|
|
||||||
if (transaction != null) { |
|
||||||
transaction.rollback(); // Rollback if something goes wrong
|
|
||||||
} |
|
||||||
|
|
||||||
logger.warning(e.toString()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} |
|
||||||
@ -1,18 +0,0 @@ |
|||||||
package xyz.soukup.mineconomiaCoreV2.database; |
|
||||||
|
|
||||||
import jakarta.persistence.criteria.CriteriaBuilder; |
|
||||||
import xyz.soukup.mineconomiaCoreV2.variables.PlayerData; |
|
||||||
|
|
||||||
|
|
||||||
public class PlayerDataDatabase { |
|
||||||
|
|
||||||
public static void savePlayerDataToDatabase(PlayerData playerData){ |
|
||||||
HibernateUtil.saveToDatabase(playerData); |
|
||||||
} |
|
||||||
|
|
||||||
public static PlayerData getPlayerDataFromDatabase(String nickname){ |
|
||||||
CriteriaBuilder criteriaBuilder = HibernateUtil.newSession().getCriteriaBuilder(); |
|
||||||
return null; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,5 +0,0 @@ |
|||||||
package xyz.soukup.mineconomiaCoreV2.database; |
|
||||||
|
|
||||||
public class PlayerInit { |
|
||||||
public static void onJoin(){} |
|
||||||
} |
|
||||||
@ -0,0 +1,53 @@ |
|||||||
|
package xyz.soukup.mineconomiaCoreV2.events; |
||||||
|
|
||||||
|
import com.j256.ormlite.stmt.QueryBuilder; |
||||||
|
import org.bukkit.entity.Player; |
||||||
|
import org.bukkit.event.EventHandler; |
||||||
|
import org.bukkit.event.Listener; |
||||||
|
import org.bukkit.event.player.PlayerJoinEvent; |
||||||
|
import org.bukkit.event.player.PlayerQuitEvent; |
||||||
|
import xyz.soukup.mineconomiaCoreV2.variables.PlayerData; |
||||||
|
|
||||||
|
import java.sql.SQLException; |
||||||
|
|
||||||
|
import static xyz.soukup.mineconomiaCoreV2.database.DatabaseUtil.playerDataDao; |
||||||
|
import static xyz.soukup.mineconomiaCoreV2.variables.PlayerData.playersData; |
||||||
|
|
||||||
|
public class PlayerInit implements Listener { |
||||||
|
|
||||||
|
@EventHandler |
||||||
|
public static void onJoin(PlayerJoinEvent event) throws SQLException { |
||||||
|
|
||||||
|
Player player = event.getPlayer(); |
||||||
|
String name = player.getDisplayName(); |
||||||
|
PlayerData playerData = PlayerData.generateFromPlayer(player);; |
||||||
|
|
||||||
|
QueryBuilder<PlayerData, Integer> queryBuilder = playerDataDao.queryBuilder(); |
||||||
|
queryBuilder.where().eq("nickname", name); |
||||||
|
|
||||||
|
if (queryBuilder.countOf() > 0){ |
||||||
|
playerData = queryBuilder.queryForFirst(); |
||||||
|
}else { |
||||||
|
playerDataDao.create(playerData); |
||||||
|
} |
||||||
|
|
||||||
|
playerData.setOnline(1); |
||||||
|
playerDataDao.update(playerData); |
||||||
|
|
||||||
|
playersData.put(player, playerData); |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@EventHandler |
||||||
|
public static void onLeave(PlayerQuitEvent event) throws SQLException { |
||||||
|
|
||||||
|
Player player = event.getPlayer(); |
||||||
|
PlayerData playerData = playersData.get(player); |
||||||
|
|
||||||
|
playerData.setOnline(0); |
||||||
|
playerDataDao.update(playerData); |
||||||
|
|
||||||
|
playersData.remove(player); |
||||||
|
} |
||||||
|
} |
||||||
@ -1,16 +1,145 @@ |
|||||||
package xyz.soukup.mineconomiaCoreV2.tools; |
package xyz.soukup.mineconomiaCoreV2.tools; |
||||||
|
|
||||||
|
import net.matrixcreations.libraries.MatrixColorAPI; |
||||||
|
import org.bukkit.ChatColor; |
||||||
|
import org.bukkit.command.CommandSender; |
||||||
|
import org.bukkit.configuration.InvalidConfigurationException; |
||||||
|
import org.bukkit.configuration.file.FileConfiguration; |
||||||
import org.bukkit.configuration.file.YamlConfiguration; |
import org.bukkit.configuration.file.YamlConfiguration; |
||||||
|
import org.bukkit.entity.Player; |
||||||
|
|
||||||
import static xyz.soukup.mineconomiaCoreV2.core.sharedValues.config; |
import java.io.File; |
||||||
import static xyz.soukup.mineconomiaCoreV2.core.sharedValues.plugin; |
import java.io.IOException; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
import static xyz.soukup.mineconomiaCoreV2.core.sharedValues.*; |
||||||
|
|
||||||
public class LangManager { |
public class LangManager { |
||||||
|
|
||||||
public static YamlConfiguration lang = null; |
public static YamlConfiguration lang = null; |
||||||
public static void loadLang(){ |
private static FileConfiguration langConfig; |
||||||
String langPath = "lang/" + config.getString("lang"); |
|
||||||
plugin.saveResource(langPath, false); |
|
||||||
//lang = YamlConfiguration.loadConfiguration(plugin.getResource(langPath));
|
//Replace references and colorize retrieved string
|
||||||
|
public static String get(String key){ |
||||||
|
return MatrixColorAPI.process(retrieveString(key)); |
||||||
|
} |
||||||
|
|
||||||
|
public static String get(String key, String s1){ |
||||||
|
return MatrixColorAPI.process(retrieveString(key).replace("%s1", s1)); |
||||||
|
} |
||||||
|
|
||||||
|
public static String get(String key, String s1, String s2) { |
||||||
|
return MatrixColorAPI.process(retrieveString(key).replace("%s1", s1).replace("%s2", s2)); |
||||||
|
} |
||||||
|
|
||||||
|
public static String get(String key, String s1, String s2, String s3) { |
||||||
|
return MatrixColorAPI.process(retrieveString(key).replace("%s1", s1).replace("%s2", s2).replace("%s3", s3)); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
//Info into server console
|
||||||
|
public static void info(String key){ |
||||||
|
logger.info(ChatColor.stripColor(get(key))); |
||||||
|
} |
||||||
|
|
||||||
|
public static void info(String key, String s1){ |
||||||
|
logger.info(ChatColor.stripColor(get(key, s1))); |
||||||
|
} |
||||||
|
public static void info(String key, String s1, String s2){ |
||||||
|
logger.info(ChatColor.stripColor(get(key, s1, s2))); |
||||||
|
} |
||||||
|
public static void info(String key, String s1, String s2, String s3){ |
||||||
|
logger.info(ChatColor.stripColor(get(key, s1, s2, s3))); |
||||||
|
} |
||||||
|
|
||||||
|
//Warning into server console
|
||||||
|
public static void warning(String key){ |
||||||
|
logger.warning(ChatColor.stripColor(get(key))); |
||||||
|
} |
||||||
|
|
||||||
|
public static void warning(String key, String s1){ |
||||||
|
logger.warning(ChatColor.stripColor(get(key, s1))); |
||||||
|
} |
||||||
|
public static void warning(String key, String s1, String s2){ |
||||||
|
logger.warning(ChatColor.stripColor(get(key, s1, s2))); |
||||||
|
} |
||||||
|
public static void warning(String key, String s1, String s2, String s3){ |
||||||
|
logger.warning(ChatColor.stripColor(get(key, s1, s2, s3))); |
||||||
|
} |
||||||
|
|
||||||
|
//Message to player
|
||||||
|
public static void message(CommandSender commandSender, String key){ |
||||||
|
commandSender.sendMessage(get(key)); |
||||||
|
} |
||||||
|
|
||||||
|
public static void message(CommandSender commandSender, String key, String s1){ |
||||||
|
commandSender.sendMessage(get(key, s1)); |
||||||
|
} |
||||||
|
|
||||||
|
public static void message(CommandSender commandSender, String key, String s1, String s2) { |
||||||
|
commandSender.sendMessage(get(key, s1, s2)); |
||||||
|
} |
||||||
|
|
||||||
|
public static void message(CommandSender commandSender, String key, String s1, String s2, String s3) { |
||||||
|
commandSender.sendMessage(get(key, s1, s2, s3)); |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
|
private static String retrieveString(String key) { |
||||||
|
|
||||||
|
Object value = langConfig.get(key); |
||||||
|
|
||||||
|
if (value == null){ |
||||||
|
return key; |
||||||
|
} |
||||||
|
|
||||||
|
if(value instanceof String){ |
||||||
|
return (String) value; |
||||||
|
} |
||||||
|
|
||||||
|
if (value instanceof List){ |
||||||
|
List<String> stringList = (List<String>) value; |
||||||
|
|
||||||
|
StringBuilder result = new StringBuilder(); |
||||||
|
boolean isFirst = true; |
||||||
|
|
||||||
|
for (String s : stringList){ |
||||||
|
|
||||||
|
if(!isFirst){ |
||||||
|
result.append("\n"); |
||||||
|
} |
||||||
|
|
||||||
|
result.append(s); |
||||||
|
isFirst = false; |
||||||
|
} |
||||||
|
|
||||||
|
return result.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
return key; |
||||||
|
} |
||||||
|
|
||||||
|
public static void initLangManager() throws IOException, InvalidConfigurationException { |
||||||
|
|
||||||
|
if (langConfig != null){ |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
String selectedLang = config.getString("language"); |
||||||
|
|
||||||
|
File langFile = new File(plugin.getDataFolder(), "lang/" + selectedLang); |
||||||
|
|
||||||
|
if (!langFile.exists()) { |
||||||
|
langFile.getParentFile().mkdirs(); |
||||||
|
plugin.saveResource("lang/" + selectedLang, false); |
||||||
|
} |
||||||
|
|
||||||
|
langConfig = new YamlConfiguration(); |
||||||
|
|
||||||
|
langConfig.load(langFile); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
} |
} |
||||||
|
|||||||
@ -0,0 +1,66 @@ |
|||||||
|
package xyz.soukup.mineconomiaCoreV2.variables; |
||||||
|
|
||||||
|
import com.j256.ormlite.field.DatabaseField; |
||||||
|
import com.j256.ormlite.stmt.QueryBuilder; |
||||||
|
import com.j256.ormlite.table.DatabaseTable; |
||||||
|
|
||||||
|
import java.sql.SQLException; |
||||||
|
|
||||||
|
import static xyz.soukup.mineconomiaCoreV2.database.DatabaseUtil.groupDao; |
||||||
|
|
||||||
|
@DatabaseTable(tableName = "groups") |
||||||
|
public class Group { |
||||||
|
|
||||||
|
@DatabaseField(generatedId = true) |
||||||
|
private int id; |
||||||
|
|
||||||
|
@DatabaseField(unique = true) |
||||||
|
private String name; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private String owner; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private float money; |
||||||
|
|
||||||
|
public int getId() { |
||||||
|
return id; |
||||||
|
} |
||||||
|
|
||||||
|
public void setId(int id) { |
||||||
|
this.id = id; |
||||||
|
} |
||||||
|
|
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
public void setName(String name) { |
||||||
|
this.name = name; |
||||||
|
} |
||||||
|
|
||||||
|
public String getOwner() { |
||||||
|
return owner; |
||||||
|
} |
||||||
|
|
||||||
|
public void setOwner(String owner) { |
||||||
|
this.owner = owner; |
||||||
|
} |
||||||
|
|
||||||
|
public float getMoney() { |
||||||
|
return money; |
||||||
|
} |
||||||
|
|
||||||
|
public void setMoney(float money) { |
||||||
|
this.money = money; |
||||||
|
} |
||||||
|
|
||||||
|
public static Group getGroup(String name) throws SQLException { |
||||||
|
QueryBuilder<Group, Integer> queryBuilder = groupDao.queryBuilder(); |
||||||
|
return queryBuilder.where().eq("name", name).queryForFirst(); |
||||||
|
} |
||||||
|
|
||||||
|
public void save() throws SQLException { |
||||||
|
groupDao.update(this); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,41 @@ |
|||||||
|
package xyz.soukup.mineconomiaCoreV2.variables; |
||||||
|
|
||||||
|
import com.j256.ormlite.field.DatabaseField; |
||||||
|
import com.j256.ormlite.table.DatabaseTable; |
||||||
|
|
||||||
|
@DatabaseTable(tableName = "group_memberships") |
||||||
|
public class GroupMembership { |
||||||
|
|
||||||
|
@DatabaseField(generatedId = true) |
||||||
|
private int id; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private String group; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private String member; |
||||||
|
|
||||||
|
public String getGroup() { |
||||||
|
return group; |
||||||
|
} |
||||||
|
|
||||||
|
public void setGroup(String group) { |
||||||
|
this.group = group; |
||||||
|
} |
||||||
|
|
||||||
|
public String getMember() { |
||||||
|
return member; |
||||||
|
} |
||||||
|
|
||||||
|
public void setMember(String member) { |
||||||
|
this.member = member; |
||||||
|
} |
||||||
|
|
||||||
|
public int getId() { |
||||||
|
return id; |
||||||
|
} |
||||||
|
|
||||||
|
public void setId(int id) { |
||||||
|
this.id = id; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,29 @@ |
|||||||
|
package xyz.soukup.mineconomiaCoreV2.variables; |
||||||
|
|
||||||
|
import com.j256.ormlite.field.DatabaseField; |
||||||
|
import com.j256.ormlite.table.DatabaseTable; |
||||||
|
|
||||||
|
@DatabaseTable(tableName = "islands") |
||||||
|
public class Island { |
||||||
|
|
||||||
|
@DatabaseField(generatedId = true) |
||||||
|
private int id; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private String server; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private String name; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private String owner; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private String world; |
||||||
|
|
||||||
|
@DatabaseField(columnName = "size_x") |
||||||
|
private int sizeX; |
||||||
|
|
||||||
|
@DatabaseField(columnName = "size_y") |
||||||
|
private int sizeY; |
||||||
|
} |
||||||
@ -0,0 +1,54 @@ |
|||||||
|
package xyz.soukup.mineconomiaCoreV2.variables; |
||||||
|
|
||||||
|
import com.j256.ormlite.field.DatabaseField; |
||||||
|
import com.j256.ormlite.table.DatabaseTable; |
||||||
|
|
||||||
|
@DatabaseTable(tableName = "shops") |
||||||
|
public class Shop { |
||||||
|
@DatabaseField(generatedId = true) |
||||||
|
private int id; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private String server; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private String owner; |
||||||
|
|
||||||
|
@DatabaseField(columnName = "owner_type", canBeNull = false) |
||||||
|
private String ownerType; |
||||||
|
|
||||||
|
@DatabaseField(columnName = "price_sell", canBeNull = false) |
||||||
|
private String priceSell; |
||||||
|
|
||||||
|
@DatabaseField(columnName = "price_buy", canBeNull = false) |
||||||
|
private float priceBuy; |
||||||
|
|
||||||
|
@DatabaseField |
||||||
|
private int stock; |
||||||
|
|
||||||
|
@DatabaseField |
||||||
|
private int space; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private int x; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private int y; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private int z; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private int world; |
||||||
|
|
||||||
|
@DatabaseField(columnName = "storage_x", canBeNull = false) |
||||||
|
private int storageX; |
||||||
|
|
||||||
|
@DatabaseField(columnName = "storage_y", canBeNull = false) |
||||||
|
private int storageY; |
||||||
|
|
||||||
|
@DatabaseField(columnName = "storage_z", canBeNull = false) |
||||||
|
private int storageZ; |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,236 @@ |
|||||||
|
package xyz.soukup.mineconomiaCoreV2.variables; |
||||||
|
|
||||||
|
import com.j256.ormlite.field.DatabaseField; |
||||||
|
import com.j256.ormlite.table.DatabaseTable; |
||||||
|
import org.bukkit.entity.Player; |
||||||
|
|
||||||
|
import java.sql.SQLException; |
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
import static xyz.soukup.mineconomiaCoreV2.database.DatabaseUtil.transactionDao; |
||||||
|
|
||||||
|
@DatabaseTable(tableName = "transactions") |
||||||
|
public class Transaction { |
||||||
|
|
||||||
|
@DatabaseField(generatedId = true) |
||||||
|
private int id; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private Date date; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private String type; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private float amount; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private String sender; |
||||||
|
|
||||||
|
@DatabaseField(columnName = "sender_type", canBeNull = false) |
||||||
|
private String senderType; |
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false) |
||||||
|
private String receiver; |
||||||
|
|
||||||
|
@DatabaseField(columnName = "receiver_type", canBeNull = false) |
||||||
|
private String receiverType; |
||||||
|
|
||||||
|
@DatabaseField |
||||||
|
private String s1; |
||||||
|
|
||||||
|
@DatabaseField |
||||||
|
private String s2; |
||||||
|
|
||||||
|
public int getId() { |
||||||
|
return id; |
||||||
|
} |
||||||
|
|
||||||
|
public void setId(int id) { |
||||||
|
this.id = id; |
||||||
|
} |
||||||
|
|
||||||
|
public Date getDate() { |
||||||
|
return date; |
||||||
|
} |
||||||
|
|
||||||
|
public void setDate(Date date) { |
||||||
|
this.date = date; |
||||||
|
} |
||||||
|
|
||||||
|
public String getType() { |
||||||
|
return type; |
||||||
|
} |
||||||
|
|
||||||
|
public void setType(String type) { |
||||||
|
this.type = type; |
||||||
|
} |
||||||
|
|
||||||
|
public float getAmount() { |
||||||
|
return amount; |
||||||
|
} |
||||||
|
|
||||||
|
public void setAmount(float amount) { |
||||||
|
this.amount = amount; |
||||||
|
} |
||||||
|
|
||||||
|
public String getSender() { |
||||||
|
return sender; |
||||||
|
} |
||||||
|
|
||||||
|
public void setSender(String sender) { |
||||||
|
this.sender = sender; |
||||||
|
} |
||||||
|
|
||||||
|
public String getSenderType() { |
||||||
|
return senderType; |
||||||
|
} |
||||||
|
|
||||||
|
public void setSenderType(String senderType) { |
||||||
|
this.senderType = senderType; |
||||||
|
} |
||||||
|
|
||||||
|
public String getReceiver() { |
||||||
|
return receiver; |
||||||
|
} |
||||||
|
|
||||||
|
public void setReceiver(String receiver) { |
||||||
|
this.receiver = receiver; |
||||||
|
} |
||||||
|
|
||||||
|
public String getReceiverType() { |
||||||
|
return receiverType; |
||||||
|
} |
||||||
|
|
||||||
|
public void setReceiverType(String receiverType) { |
||||||
|
this.receiverType = receiverType; |
||||||
|
} |
||||||
|
|
||||||
|
public String getS1(){ |
||||||
|
return s1; |
||||||
|
} |
||||||
|
|
||||||
|
public void setS1(String s1){ |
||||||
|
this.s1 = s1; |
||||||
|
} |
||||||
|
|
||||||
|
public String getS2(){ |
||||||
|
return s2; |
||||||
|
} |
||||||
|
|
||||||
|
public void setS2(String s2){ |
||||||
|
this.s2 = s2; |
||||||
|
} |
||||||
|
|
||||||
|
public Boolean senderHasEnough() throws SQLException { |
||||||
|
switch (this.senderType){ |
||||||
|
case "server": |
||||||
|
return true; |
||||||
|
case "group": |
||||||
|
Group group = Group.getGroup(this.sender); |
||||||
|
|
||||||
|
if (group == null){ |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
return group.getMoney() >= this.amount; |
||||||
|
|
||||||
|
case "player": |
||||||
|
PlayerData playerData = PlayerData.getPlayerData(this.sender); |
||||||
|
|
||||||
|
if (playerData == null){ |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
return playerData.getMoney() >= this.amount; |
||||||
|
|
||||||
|
default: |
||||||
|
return false; |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void process() throws SQLException { |
||||||
|
|
||||||
|
float money; |
||||||
|
|
||||||
|
switch (this.senderType){ |
||||||
|
case "server": |
||||||
|
break; |
||||||
|
case "player": |
||||||
|
PlayerData playerData = PlayerData.getPlayerData(this.sender); |
||||||
|
money = playerData.getMoney(); |
||||||
|
playerData.setMoney(money - amount); |
||||||
|
playerData.save(); |
||||||
|
break; |
||||||
|
case "group": |
||||||
|
Group group = Group.getGroup(this.sender); |
||||||
|
money = group.getMoney(); |
||||||
|
group.setMoney(money - amount); |
||||||
|
group.save(); |
||||||
|
} |
||||||
|
|
||||||
|
switch (this.receiverType){ |
||||||
|
case "server": |
||||||
|
break; |
||||||
|
case "player": |
||||||
|
PlayerData playerData = PlayerData.getPlayerData(this.receiver); |
||||||
|
money = playerData.getMoney(); |
||||||
|
playerData.setMoney(money + amount); |
||||||
|
playerData.save(); |
||||||
|
break; |
||||||
|
case "group": |
||||||
|
Group group = Group.getGroup(this.receiver); |
||||||
|
money = group.getMoney(); |
||||||
|
group.setMoney(money + amount); |
||||||
|
group.save(); |
||||||
|
} |
||||||
|
|
||||||
|
this.setDate(new Date()); |
||||||
|
|
||||||
|
transactionDao.create(this); |
||||||
|
} |
||||||
|
|
||||||
|
public Boolean processIfSenderHasEnough() throws SQLException { |
||||||
|
if (this.senderHasEnough()){ |
||||||
|
this.process(); |
||||||
|
return true; |
||||||
|
} |
||||||
|
return false; |
||||||
|
}; |
||||||
|
|
||||||
|
public static Transaction prepareTransaction(String sender, String senderType, String receiver, String receiverType, Float amount, String type){ |
||||||
|
Transaction transaction = new Transaction(); |
||||||
|
|
||||||
|
transaction.setSender(sender); |
||||||
|
transaction.setSenderType(senderType); |
||||||
|
transaction.setReceiver(receiver); |
||||||
|
transaction.setReceiverType(receiverType); |
||||||
|
transaction.setAmount(amount); |
||||||
|
transaction.setType(type); |
||||||
|
|
||||||
|
return transaction; |
||||||
|
} |
||||||
|
|
||||||
|
public static Transaction prepareTransaction(String sender, String senderType, String receiver, String receiverType, Float amount, String type, String s1){ |
||||||
|
Transaction transaction = prepareTransaction(sender, senderType, receiver, receiverType, amount, type); |
||||||
|
transaction.setS1(s1); |
||||||
|
return transaction; |
||||||
|
} |
||||||
|
public static Transaction prepareTransaction(String sender, String senderType, String receiver, String receiverType, Float amount, String type, String s1, String s2){ |
||||||
|
Transaction transaction = prepareTransaction(sender, senderType, receiver, receiverType, amount, type, s1); |
||||||
|
transaction.setS2(s2); |
||||||
|
return transaction; |
||||||
|
} |
||||||
|
|
||||||
|
public static Transaction prepareTransaction(Player senderPlayer, Player receiverPlayer, Float amount){ |
||||||
|
String sender = senderPlayer.getDisplayName(); |
||||||
|
String receiver = receiverPlayer.getDisplayName(); |
||||||
|
|
||||||
|
return prepareTransaction(sender, "player", receiver, "player", amount, "playertoplayer"); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
@ -1,7 +1,7 @@ |
|||||||
version: 1.0 |
version: 1.0 |
||||||
language: "czech.yml" |
language: "czech.yml" |
||||||
database: |
database: |
||||||
host: localhost |
host: uceni.soukup.xyz |
||||||
port: 3306 |
port: 3306 |
||||||
user: mcore |
user: mcore |
||||||
password: mcore |
password: mcore |
||||||
|
|||||||
Loading…
Reference in new issue