Compare commits
No commits in common. 'master' and 'napojeni-database' have entirely different histories.
master
...
napojeni-d
18 changed files with 96 additions and 710 deletions
@ -0,0 +1,49 @@ |
|||||||
|
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 { |
||||||
|
|
||||||
|
@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]); |
||||||
|
World playerWorld = player.getWorld(); |
||||||
|
|
||||||
|
if (playerWorld.equals(world)) { |
||||||
|
player.sendMessage("You are already in this world!"); // Edit
|
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
if (strings.length > 2) { |
||||||
|
try { |
||||||
|
Player targetPlayer = Bukkit.getPlayer(strings[1]); |
||||||
|
|
||||||
|
targetPlayer.teleport(world.getSpawnLocation()); |
||||||
|
targetPlayer.sendMessage(String.format("Successfully teleported %s from %s to %s.", targetPlayer, playerWorld, world)); // Edit
|
||||||
|
return true; |
||||||
|
} catch (Exception e) { |
||||||
|
player.sendMessage("This is not a valid player!"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
player.teleport(world.getSpawnLocation()); |
||||||
|
player.sendMessage(String.format("Successfully teleported from %s to %s.", playerWorld, world)); // Edit
|
||||||
|
return true; |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
@ -1,104 +0,0 @@ |
|||||||
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"); |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,21 +0,0 @@ |
|||||||
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,68 +0,0 @@ |
|||||||
package xyz.soukup.mineconomiaCoreV2.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.configuration.InvalidConfigurationException; |
|
||||||
import org.bukkit.entity.Player; |
|
||||||
import xyz.soukup.mineconomiaCoreV2.tools.LangManager; |
|
||||||
|
|
||||||
import java.io.IOException; |
|
||||||
|
|
||||||
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) { |
|
||||||
|
|
||||||
LangManager.message(commandSender, "error.command.tpw.invalid-world"); |
|
||||||
|
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
if (strings.length > 1) { |
|
||||||
try { |
|
||||||
Player targetPlayer = Bukkit.getPlayer(strings[1]); |
|
||||||
World targetPlayerWorld = targetPlayer.getWorld(); |
|
||||||
|
|
||||||
if (targetPlayerWorld.equals(world)) { |
|
||||||
LangManager.message(commandSender, "error.command.tpw.already-in-world", strings[1]); |
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
targetPlayer.teleport(world.getSpawnLocation()); |
|
||||||
LangManager.message(commandSender, "success.command.tpw.teleported", strings[1], targetPlayerWorld.getName(), world.getName()); |
|
||||||
return true; |
|
||||||
} catch (Exception e) { |
|
||||||
LangManager.message(commandSender, "error.command.invalid-player"); |
|
||||||
return true; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
World playerWorld = player.getWorld(); |
|
||||||
|
|
||||||
if (playerWorld.equals(world)) { |
|
||||||
LangManager.message(commandSender, "error.command.tpw.already-in-world-self"); |
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
player.teleport(world.getSpawnLocation()); |
|
||||||
LangManager.message(commandSender, "success.command.tpw.teleported-self", playerWorld.getName(), world.getName()); |
|
||||||
return true; |
|
||||||
} |
|
||||||
return false; |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,145 +1,16 @@ |
|||||||
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 java.io.File; |
import static xyz.soukup.mineconomiaCoreV2.core.sharedValues.config; |
||||||
import java.io.IOException; |
import static xyz.soukup.mineconomiaCoreV2.core.sharedValues.plugin; |
||||||
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; |
||||||
private static FileConfiguration langConfig; |
public static void loadLang(){ |
||||||
|
String langPath = "lang/" + config.getString("lang"); |
||||||
|
plugin.saveResource(langPath, false); |
||||||
//Replace references and colorize retrieved string
|
//lang = YamlConfiguration.loadConfiguration(plugin.getResource(langPath));
|
||||||
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); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
} |
} |
||||||
|
|||||||
@ -1,66 +0,0 @@ |
|||||||
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); |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,41 +0,0 @@ |
|||||||
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; |
|
||||||
} |
|
||||||
} |
|
||||||
Loading…
Reference in new issue