14 changed files with 355 additions and 9 deletions
@ -0,0 +1,33 @@ |
||||
package commands; |
||||
|
||||
import org.bukkit.Bukkit; |
||||
import org.bukkit.World; |
||||
import org.bukkit.command.Command; |
||||
import org.bukkit.command.CommandSender; |
||||
import org.bukkit.command.TabCompleter; |
||||
import org.bukkit.entity.Player; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class tabCompleter implements TabCompleter { |
||||
|
||||
@Override |
||||
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) { |
||||
List<String> completions = new ArrayList<>(); |
||||
|
||||
if (command.getName().equalsIgnoreCase("tpw") && commandSender.isOp()) { |
||||
if (strings.length == 1) { |
||||
for (World world : Bukkit.getWorlds()) { |
||||
completions.add(world.getName()); |
||||
} |
||||
} else if (strings.length == 2) { |
||||
for (Player player : Bukkit.getOnlinePlayers()) { |
||||
completions.add(player.getName()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
return completions; |
||||
} |
||||
} |
||||
@ -0,0 +1,62 @@ |
||||
package commands; |
||||
|
||||
import org.bukkit.Bukkit; |
||||
import org.bukkit.World; |
||||
import org.bukkit.command.Command; |
||||
import org.bukkit.command.CommandExecutor; |
||||
import org.bukkit.command.CommandSender; |
||||
import org.bukkit.entity.Player; |
||||
|
||||
public class teleportWorld implements CommandExecutor { |
||||
|
||||
// Teleports player with OP to another world.
|
||||
@Override |
||||
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { |
||||
if (commandSender instanceof Player) { |
||||
|
||||
Player player = (Player) commandSender; |
||||
|
||||
if (!player.isOp() || strings.length == 0) { |
||||
return false; |
||||
} |
||||
|
||||
World world = Bukkit.getWorld(strings[0]); |
||||
|
||||
if (world == null) { |
||||
player.sendMessage("This is not a valid world!"); |
||||
return true; |
||||
} |
||||
|
||||
if (strings.length > 1) { |
||||
try { |
||||
Player targetPlayer = Bukkit.getPlayer(strings[1]); |
||||
World targetPlayerWorld = targetPlayer.getWorld(); |
||||
|
||||
if (targetPlayerWorld.equals(world)) { |
||||
player.sendMessage(String.format("Player %s is already in this world!", strings[1])); |
||||
return true; |
||||
} |
||||
|
||||
targetPlayer.teleport(world.getSpawnLocation()); |
||||
targetPlayer.sendMessage(String.format("Successfully teleported %s from %s to %s.", strings[1], targetPlayerWorld.getName(), world.getName())); |
||||
return true; |
||||
} catch (Exception e) { |
||||
player.sendMessage("This is not a valid player!"); |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
World playerWorld = player.getWorld(); |
||||
|
||||
if (playerWorld.equals(world)) { |
||||
player.sendMessage("You are already in this world!"); |
||||
return true; |
||||
} |
||||
|
||||
player.teleport(world.getSpawnLocation()); |
||||
player.sendMessage(String.format("Successfully teleported from %s to %s.", playerWorld.getName(), world.getName())); |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
} |
||||
@ -1,12 +1,14 @@ |
||||
package xyz.soukup.mineconomiaCoreV2.core; |
||||
|
||||
import org.bukkit.Bukkit; |
||||
import org.bukkit.configuration.file.FileConfiguration; |
||||
import org.bukkit.plugin.java.JavaPlugin; |
||||
import xyz.soukup.mineconomiaCoreV2.MineconomiaCoreV2; |
||||
|
||||
import java.util.logging.Logger; |
||||
|
||||
public class sharedValues { |
||||
public static MineconomiaCoreV2 plugin = MineconomiaCoreV2.getPlugin(MineconomiaCoreV2.class); |
||||
public static MineconomiaCoreV2 plugin = MineconomiaCoreV2.getInstance(); |
||||
public static FileConfiguration config = plugin.getConfig(); |
||||
public static Logger logger = plugin.getLogger(); |
||||
} |
||||
|
||||
@ -0,0 +1,113 @@ |
||||
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()); |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,18 @@ |
||||
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; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,5 @@ |
||||
package xyz.soukup.mineconomiaCoreV2.database; |
||||
|
||||
public class PlayerInit { |
||||
public static void onJoin(){} |
||||
} |
||||
@ -1,12 +1,11 @@ |
||||
package xyz.soukup.mineconomiaCoreV2.core; |
||||
package xyz.soukup.mineconomiaCoreV2.tools; |
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration; |
||||
import org.bukkit.inventory.Inventory; |
||||
|
||||
import static xyz.soukup.mineconomiaCoreV2.core.sharedValues.config; |
||||
import static xyz.soukup.mineconomiaCoreV2.core.sharedValues.plugin; |
||||
|
||||
public class MsgRetriever { |
||||
public class LangManager { |
||||
|
||||
public static YamlConfiguration lang = null; |
||||
public static void loadLang(){ |
||||
@ -1,4 +1,4 @@ |
||||
package tools; |
||||
package xyz.soukup.mineconomiaCoreV2.tools; |
||||
|
||||
import org.bukkit.inventory.Inventory; |
||||
import org.bukkit.inventory.ItemStack; |
||||
@ -0,0 +1,61 @@ |
||||
package xyz.soukup.mineconomiaCoreV2.variables; |
||||
|
||||
import jakarta.persistence.Entity; |
||||
import jakarta.persistence.GeneratedValue; |
||||
import jakarta.persistence.GenerationType; |
||||
import jakarta.persistence.Id; |
||||
|
||||
//Definování Member classy pro databázi a další manipulace
|
||||
|
||||
@Entity |
||||
public class PlayerData { |
||||
|
||||
@Id |
||||
@GeneratedValue(strategy = GenerationType.IDENTITY) |
||||
private int id; |
||||
|
||||
private String nickname; |
||||
private String uuid; |
||||
private int online; |
||||
private float money; |
||||
|
||||
public int getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(int id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public String getNickname() { |
||||
return nickname; |
||||
} |
||||
|
||||
public void setNickname(String nickname) { |
||||
this.nickname = nickname; |
||||
} |
||||
|
||||
public String getUuid() { |
||||
return uuid; |
||||
} |
||||
|
||||
public void setUuid(String uuid) { |
||||
this.uuid = uuid; |
||||
} |
||||
|
||||
public int getOnline() { |
||||
return online; |
||||
} |
||||
|
||||
public void setOnline(int online) { |
||||
this.online = online; |
||||
} |
||||
|
||||
public float getMoney() { |
||||
return money; |
||||
} |
||||
|
||||
public void setMoney(float money) { |
||||
this.money = money; |
||||
} |
||||
} |
||||
@ -1,2 +1,8 @@ |
||||
version: 1.0 |
||||
language: "czech.yml" |
||||
language: "czech.yml" |
||||
database: |
||||
host: localhost |
||||
port: 3306 |
||||
user: mcore |
||||
password: mcore |
||||
database: mcore |
||||
Loading…
Reference in new issue