Rework + Removing MoneySystem
Dieser Commit ist enthalten in:
Ursprung
0ec1dd4a8c
Commit
6585a33b1e
@ -1,10 +1,12 @@
|
||||
package de.warking.hunjy.manager;
|
||||
package de.steamwar.core;
|
||||
|
||||
import de.warking.hunjy.Core;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import de.warking.hunjy.Core;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
||||
public class FileManager {
|
||||
@ -29,20 +31,12 @@ public class FileManager {
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (IOException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Could not save MySQL Config", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public YamlConfiguration getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package de.warking.hunjy.PlayerManager.events;
|
||||
package de.steamwar.core.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -12,14 +12,4 @@ public class ChattingEvent implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
event.setFormat("§eLokal §r"+ player.getDisplayName() + "§8» §7" + event.getMessage());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
private void onGroupChange(PlayerChangeTeamEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
|
||||
player.kickPlayer("<EFBFBD>7Du hast einen neuen Rang erhalten\n\n" + event.getOldGroup() + " <20>8<EFBFBD> " + event.getNewGroup() + "\n\n<EFBFBD>7Bitte Joine neu auf <20>9Diamant-ix.de");
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package de.warking.hunjy.PlayerManager.events;
|
||||
package de.steamwar.core.events;
|
||||
|
||||
import de.warking.hunjy.MySQL.WarkingUser;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -8,7 +8,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
|
||||
public class PlayerJoin implements Listener{
|
||||
public class PlayerJoinedEvent implements Listener{
|
||||
|
||||
@EventHandler
|
||||
private void onJoin(PlayerJoinEvent event) {
|
||||
@ -52,5 +52,4 @@ public class PlayerJoin implements Listener{
|
||||
|
||||
event.setQuitMessage("§c§l« §r" + player.getDisplayName());
|
||||
}
|
||||
|
||||
}
|
@ -19,7 +19,7 @@ import java.util.*;
|
||||
|
||||
public class SWInventory implements Listener, Inventory {
|
||||
|
||||
protected Player player;
|
||||
Player player;
|
||||
private Map<Integer, InvCallback> callbacks;
|
||||
private int inventorySize;
|
||||
private ItemStack[] contents;
|
||||
@ -97,11 +97,17 @@ public class SWInventory implements Listener, Inventory {
|
||||
|
||||
|
||||
@Override
|
||||
public int getSize() {return inventorySize;}
|
||||
public int getSize() {
|
||||
return inventorySize;
|
||||
}
|
||||
@Override
|
||||
public int getMaxStackSize() {return 999;}
|
||||
public int getMaxStackSize() {
|
||||
return 999;
|
||||
}
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {}
|
||||
public void setMaxStackSize(int size) {
|
||||
//Unused
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
@ -114,21 +120,35 @@ public class SWInventory implements Listener, Inventory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int index, ItemStack item) {}
|
||||
public void setItem(int index, ItemStack item) {
|
||||
//Unused
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ItemStack> addItem(ItemStack... items) throws IllegalArgumentException {return null;}
|
||||
public HashMap<Integer, ItemStack> addItem(ItemStack... items) throws IllegalArgumentException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ItemStack> removeItem(ItemStack... items) throws IllegalArgumentException {return null;}
|
||||
public HashMap<Integer, ItemStack> removeItem(ItemStack... items) throws IllegalArgumentException {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public ItemStack[] getContents() {return contents;}
|
||||
public ItemStack[] getContents() {
|
||||
return contents;
|
||||
}
|
||||
@Override
|
||||
public void setContents(ItemStack[] items) throws IllegalArgumentException {}
|
||||
public void setContents(ItemStack[] items) throws IllegalArgumentException {
|
||||
//Unused
|
||||
}
|
||||
@Override
|
||||
public ItemStack[] getStorageContents() {return contents;}
|
||||
public ItemStack[] getStorageContents() {
|
||||
return contents;
|
||||
}
|
||||
@Override
|
||||
public void setStorageContents(ItemStack[] items) throws IllegalArgumentException {}
|
||||
public void setStorageContents(ItemStack[] items) throws IllegalArgumentException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(int materialId) {
|
||||
|
@ -1,18 +0,0 @@
|
||||
package de.warking.hunjy.CoinSystem;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.warking.hunjy.CoinSystem.manager.CoinsManager;
|
||||
|
||||
public class CoinSystem {
|
||||
|
||||
public static String prefix = "§6Bank §8<C2A7> ";
|
||||
|
||||
public CoinSystem() {
|
||||
}
|
||||
|
||||
public static CoinsManager getCoinsManager(Player player) {
|
||||
return new CoinsManager(player);
|
||||
}
|
||||
|
||||
}
|
@ -1,179 +0,0 @@
|
||||
package de.warking.hunjy.CoinSystem.command;
|
||||
|
||||
/**
|
||||
* @author hunjy
|
||||
*
|
||||
*/
|
||||
|
||||
import de.warking.hunjy.CoinSystem.CoinSystem;
|
||||
import de.warking.hunjy.CoinSystem.events.PlayerCoinsChangeEvent;
|
||||
import de.warking.hunjy.CoinSystem.events.PlayerPayPlayerEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class CoinCommand implements CommandExecutor{
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player))
|
||||
return false;
|
||||
|
||||
Player player = (Player)sender;
|
||||
|
||||
if(command.getName().equals("coins")) {
|
||||
if(args.length == 0) {
|
||||
int coins = CoinSystem.getCoinsManager(player).getCoins();
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>aDu hast <20>6" + coins + " M<>nzen<65>a.");
|
||||
}else if(args.length == 1) {
|
||||
|
||||
if(player.hasPermission("admin.coins.seecoins")) {
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
if(target == null) {
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>cDer Spieler ist nicht Online!");
|
||||
return false;
|
||||
}
|
||||
int coins = CoinSystem.getCoinsManager(target).getCoins();
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>7" + target.getName() + " <20>ahat <20>6" + coins + " M<>nzen<65>a.");
|
||||
}
|
||||
}
|
||||
}else if(command.getName().equals("addcoins")) {
|
||||
if(player.hasPermission("admin.coins.addcoins")) {
|
||||
if(args.length == 2) {
|
||||
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
if(target == null) {
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>cDer Spieler ist nicht Online!");
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
int coins = Integer.valueOf(args[1]);
|
||||
|
||||
if(coins == 0) {
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>cBitte gebe einen g<>ltigen Wert ein!");
|
||||
return false;
|
||||
}
|
||||
CoinSystem.getCoinsManager(target).addCoins(coins);
|
||||
|
||||
target.sendMessage(CoinSystem.prefix + "<EFBFBD>aDu hast <20>6"+ coins + " M<>nzen <20>avon <20>7" + player.getDisplayName() + " <20>aerhalten");
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>aDu hast dem Spieler <20>7" + target.getDisplayName() + " <20>aerfolgreich <20>6" + coins + " M<>nzen <20>agegeben.");
|
||||
Bukkit.getPluginManager().callEvent(new PlayerCoinsChangeEvent(player, target, "add",coins));
|
||||
}catch (NumberFormatException e) {
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>cBitte gebe einen g<>ltigen Wert ein!");
|
||||
return false;
|
||||
}
|
||||
}else {
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>cBenutze: /addcoins [Spieler] [Anzahl]");
|
||||
}
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}else if(command.getName().equals("removecoins")) {
|
||||
if(player.hasPermission("admin.coins.removecoins")) {
|
||||
if(args.length == 2) {
|
||||
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
if(target == null) {
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>cDer Spieler ist nicht Online!");
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
int coins = Integer.valueOf(args[1]);
|
||||
|
||||
if(coins == 0) {
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>cBitte gebe einen g<>ltigen Wert ein!");
|
||||
return false;
|
||||
}
|
||||
if(CoinSystem.getCoinsManager(target).getCoins() < coins) {
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>cDer Spieler hat nicht so viele <20>6M<36>nzen<65>c.");
|
||||
return false;
|
||||
}
|
||||
CoinSystem.getCoinsManager(target).removeCoins(coins);
|
||||
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>aDu hast dem Spieler <20>7" + target.getDisplayName() + " <20>aerfolgreich <20>6" + coins + " M<>nzen <20>aweggenommen.");
|
||||
Bukkit.getPluginManager().callEvent(new PlayerCoinsChangeEvent(player, target, "remove",coins));
|
||||
}catch (NumberFormatException e) {
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>cBitte gebe einen g<>ltigen Wert ein!");
|
||||
return false;
|
||||
}
|
||||
}else {
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>cBenutze: /removecoins [Spieler] [Anzahl]");
|
||||
}
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}else if(command.getName().equals("setcoins")) {
|
||||
if(player.hasPermission("admin.coins.setcoins")) {
|
||||
if(args.length == 2) {
|
||||
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
if(target == null) {
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>cDer Spieler ist nicht Online!");
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
int coins = Integer.valueOf(args[1]);
|
||||
if(coins < 0) {
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>cBitte gebe einen g<>ltigen Wert ein!");
|
||||
return false;
|
||||
}
|
||||
CoinSystem.getCoinsManager(target).setCoins(coins);
|
||||
|
||||
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>aDu hast den Kontostand von <20>7" + target.getDisplayName() + " <20>aauf <20>6" + coins + " M<>nzen <20>agesetzt.");
|
||||
Bukkit.getPluginManager().callEvent(new PlayerCoinsChangeEvent(player, target, "set",coins));
|
||||
}catch (NumberFormatException e) {
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>cBitte gebe einen g<>ltigen Wert ein!");
|
||||
return false;
|
||||
}
|
||||
}else {
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>cBenutze: /setcoins [Spieler] [Anzahl]");
|
||||
}
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}else if(command.getName().equals("pay")) {
|
||||
if(args.length != 2) {
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>cBenutze: /pay [Spieler] [Anzahl]");
|
||||
}else {
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
if(target == null) {
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>cDer Spieler ist nicht Online!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(target == player || target.getAddress().getHostName() == player.getAddress().getHostName()){
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>cDu kannst dir kein Geld <20>berweisen!");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
int coins = Integer.valueOf(args[1]);
|
||||
|
||||
if(CoinSystem.getCoinsManager(player).getCoins() < coins) {
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>cDu hast nicht gen<65>gend <20>6M<36>nzen<65>c.");
|
||||
return false;
|
||||
}
|
||||
if(coins == 0) {
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>cBitte gebe einen g<>ltigen Wert ein!");
|
||||
return false;
|
||||
}
|
||||
CoinSystem.getCoinsManager(player).removeCoins(coins);
|
||||
CoinSystem.getCoinsManager(target).addCoins(coins);
|
||||
|
||||
target.sendMessage(CoinSystem.prefix + "<EFBFBD>aDu hast <20>6"+ coins + " M<>nzen <20>avon <20>7" + player.getDisplayName() + " <20>aerhalten");
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>aDu hast dem Spieler <20>7" + target.getDisplayName() + " <20>aerfolgreich <20>6" + coins + " M<>nzen <20>agegeben");
|
||||
Bukkit.getPluginManager().callEvent(new PlayerPayPlayerEvent(player, target, coins));
|
||||
}catch (NumberFormatException e) {
|
||||
player.sendMessage(CoinSystem.prefix + "<EFBFBD>cBitte gebe einen g<>ltigen Wert ein!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
package de.warking.hunjy.CoinSystem.events;
|
||||
|
||||
|
||||
import de.warking.hunjy.Core;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
|
||||
public class PlayerCoinsChangeEvent extends Event implements Cancellable{
|
||||
|
||||
public static HandlerList handlers = new HandlerList();
|
||||
public boolean cancelled = false;
|
||||
|
||||
Player player;
|
||||
String msg;
|
||||
|
||||
public PlayerCoinsChangeEvent(Player player, Player target, String option, int Coins) {
|
||||
this.player = player;
|
||||
switch (option) {
|
||||
case "add":
|
||||
this.msg = "<EFBFBD>8[<5B>c"+ player.getName() + "<EFBFBD>8] <20>7Gibt " + target.getName() + " <20>6" + Coins + "<EFBFBD>6 M<>nze/n" ;
|
||||
break;
|
||||
case "set":
|
||||
this.msg = "<EFBFBD>8[<5B>c"+ player.getName() + "<EFBFBD>8] <20>7Setzt den Kontostand von " + target.getName() + " <20>7auf <20>6" + Coins + "<EFBFBD>6 M<>nze/n" ;
|
||||
break;
|
||||
case "remove":
|
||||
this.msg = "<EFBFBD>8[<5B>c"+ player.getName() + "<EFBFBD>8] <20>7Entfernt " + target.getName() + " <20>6" + Coins + "<EFBFBD>6 M<>nze/n" ;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Core.getInstance().getCacheManager().addCache(this.msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public String getLog() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package de.warking.hunjy.CoinSystem.events;
|
||||
|
||||
import de.warking.hunjy.Core;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class PlayerPayPlayerEvent extends Event implements Cancellable{
|
||||
|
||||
public static HandlerList handlers = new HandlerList();
|
||||
public boolean cancelled = false;
|
||||
|
||||
Player player;
|
||||
String msg;
|
||||
|
||||
public PlayerPayPlayerEvent(Player player, Player target, int coins) {
|
||||
this.player = player;
|
||||
this.msg = "<EFBFBD>7" + player.getName() + " <20>8-> <20>7" + target.getName() + " <20>8[<5B>6" + coins + " M<>nzen<65>8]";
|
||||
|
||||
Core.getInstance().getCacheManager().addCache(this.msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
package de.warking.hunjy.CoinSystem.manager;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import de.warking.hunjy.Core;
|
||||
import de.warking.hunjy.MySQL.MySQL;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author hunjy
|
||||
*
|
||||
*/
|
||||
public class CoinsManager {
|
||||
|
||||
private MySQL mySQL;
|
||||
Player player;
|
||||
|
||||
public CoinsManager(Player player) {
|
||||
mySQL = Core.getInstance().getMySQL();
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public boolean playerExist() {
|
||||
try {
|
||||
PreparedStatement st = mySQL.getCon().prepareStatement("SELECT * FROM Coins WHERE UUID=?");
|
||||
st.setString(1, player.getUniqueId().toString());
|
||||
ResultSet rs = st.executeQuery();
|
||||
return rs.next();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void createPlayer() {
|
||||
mySQL.update("INSERT INTO Coins(UUID, Coins) VALUES ('"+ player.getUniqueId().toString() +"','0')");
|
||||
}
|
||||
|
||||
public int getCoins() {
|
||||
if(!playerExist())
|
||||
createPlayer();
|
||||
int coins = 0;
|
||||
|
||||
ResultSet rs = mySQL.select("SELECT * FROM Coins WHERE UUID='"+ player.getUniqueId().toString() +"'");
|
||||
try {
|
||||
if(rs.next() && Integer.valueOf(rs.getInt("Coins")) != null) {
|
||||
coins = rs.getInt("Coins");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return coins;
|
||||
}
|
||||
|
||||
public void setCoins(int amount) {
|
||||
if(!playerExist())
|
||||
createPlayer();
|
||||
mySQL.update("UPDATE Coins Set Coins='" + amount + "' WHERE UUID='" + player.getUniqueId().toString() + "'");
|
||||
}
|
||||
|
||||
public void addCoins( int amount) {
|
||||
if(!playerExist())
|
||||
createPlayer();
|
||||
int coins = getCoins();
|
||||
coins += amount;
|
||||
mySQL.update("UPDATE Coins Set Coins='" + coins + "' WHERE UUID='" + player.getUniqueId().toString() + "'");
|
||||
}
|
||||
|
||||
public void removeCoins( int amount) {
|
||||
if(!playerExist())
|
||||
createPlayer();
|
||||
int coins = getCoins();
|
||||
coins -= amount;
|
||||
if(coins >= 0)
|
||||
mySQL.update("UPDATE Coins Set Coins='" + coins + "' WHERE UUID='" + player.getUniqueId().toString() + "'");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,52 +1,32 @@
|
||||
package de.warking.hunjy;
|
||||
|
||||
import de.warking.hunjy.CoinSystem.CoinSystem;
|
||||
import de.warking.hunjy.CoinSystem.command.CoinCommand;
|
||||
import de.steamwar.core.events.ChattingEvent;
|
||||
import de.steamwar.core.events.PlayerJoinedEvent;
|
||||
import de.warking.hunjy.MySQL.MySQL;
|
||||
import de.warking.hunjy.MySQL.WarkingUser;
|
||||
import de.warking.hunjy.PlayerManager.PlayerManager;
|
||||
import de.warking.hunjy.PlayerManager.events.ChattingEvent;
|
||||
import de.warking.hunjy.PlayerManager.events.PlayerJoin;
|
||||
import de.warking.hunjy.manager.CacheManager;
|
||||
import de.warking.hunjy.manager.FileManager;
|
||||
import de.steamwar.core.FileManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
public class Core extends JavaPlugin{
|
||||
|
||||
public static MySQL sql;
|
||||
|
||||
|
||||
public static final String chatPrefix = "§6War§7King» §r";
|
||||
private static Core instance;
|
||||
private CacheManager cacheManager;
|
||||
private FileManager fileManager;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
instance = this;
|
||||
cacheManager = new CacheManager();
|
||||
setInstance(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
fileManager = new FileManager();
|
||||
|
||||
sql = new MySQL();
|
||||
new CoinSystem();
|
||||
|
||||
instance.getCommand("coins").setExecutor(new CoinCommand());
|
||||
instance.getCommand("pay").setExecutor(new CoinCommand());
|
||||
instance.getCommand("addcoins").setExecutor(new CoinCommand());
|
||||
instance.getCommand("setcoins").setExecutor(new CoinCommand());
|
||||
instance.getCommand("removecoins").setExecutor(new CoinCommand());
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerJoin(), this);
|
||||
setSql(new MySQL());
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerJoinedEvent(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ChattingEvent(), this);
|
||||
|
||||
Bukkit.getScheduler().runTaskTimer(this, WarkingUser::clearCache, 72000, 72000);
|
||||
@ -55,25 +35,14 @@ public class Core extends JavaPlugin{
|
||||
public static Core getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public MySQL getMySQL() {
|
||||
return sql;
|
||||
}
|
||||
|
||||
public CacheManager getCacheManager() {
|
||||
return cacheManager;
|
||||
}
|
||||
|
||||
public PlayerManager getPlayerManager(Player player) {
|
||||
return new PlayerManager(player);
|
||||
}
|
||||
|
||||
public PlayerManager getPlayerManager(UUID uuid) {
|
||||
return new PlayerManager(uuid);
|
||||
}
|
||||
|
||||
public FileManager getFileManager() {
|
||||
return fileManager;
|
||||
}
|
||||
|
||||
private static void setInstance(Core instance) {
|
||||
Core.instance = instance;
|
||||
}
|
||||
private static void setSql(MySQL sql) {
|
||||
Core.sql = sql;
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,16 @@
|
||||
package de.warking.hunjy.MySQL;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import de.warking.hunjy.Core;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
|
||||
public class MySQL {
|
||||
private String HOST;
|
||||
private String PORT;
|
||||
private String DATABASE;
|
||||
private String USER;
|
||||
private String PASSWORD = "";
|
||||
private String host;
|
||||
private String port;
|
||||
private String database;
|
||||
private String user;
|
||||
private String password;
|
||||
private Connection con;
|
||||
|
||||
public static Integer booleanToInt(boolean b){
|
||||
@ -25,21 +21,18 @@ public class MySQL {
|
||||
}
|
||||
|
||||
public MySQL() {
|
||||
this.HOST = Core.getInstance().getFileManager().getConfig().getString("HOST");
|
||||
this.PORT = Core.getInstance().getFileManager().getConfig().getString("PORT");
|
||||
this.DATABASE = Core.getInstance().getFileManager().getConfig().getString("DATABASE");
|
||||
this.USER = Core.getInstance().getFileManager().getConfig().getString("USER");
|
||||
|
||||
if(!Core.getInstance().getFileManager().getConfig().getString("PASSWORD").equals("")) {
|
||||
this.PASSWORD = Core.getInstance().getFileManager().getConfig().getString("PASSWORD");
|
||||
}
|
||||
this.host = Core.getInstance().getFileManager().getConfig().getString("HOST");
|
||||
this.port = Core.getInstance().getFileManager().getConfig().getString("PORT");
|
||||
this.database = Core.getInstance().getFileManager().getConfig().getString("DATABASE");
|
||||
this.user = Core.getInstance().getFileManager().getConfig().getString("USER");
|
||||
this.password = Core.getInstance().getFileManager().getConfig().getString("PASSWORD");
|
||||
|
||||
connect();
|
||||
}
|
||||
|
||||
public void connect() {
|
||||
try {
|
||||
con = DriverManager.getConnection("jdbc:mysql://" + HOST + ":" + PORT + "/" + DATABASE + "?autoreconnect=true", USER, PASSWORD);
|
||||
con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?autoreconnect=true", user, password);
|
||||
if(con == null)
|
||||
System.err.println("Fatal ERROR: Could not connect to database!");
|
||||
}catch (SQLException e) {
|
||||
@ -102,8 +95,4 @@ public class MySQL {
|
||||
public static String disarmString(String s){
|
||||
return s.replace("'", "");
|
||||
}
|
||||
|
||||
public Connection getCon() {
|
||||
return con;
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ public class WarkingUser {
|
||||
private UUID UUID;
|
||||
private String UserName;
|
||||
private UserGroup UserGroup;
|
||||
private int Team;
|
||||
|
||||
public WarkingUser(UUID uuid){
|
||||
ResultSet dbplayer = sql.select("SELECT * FROM UserData WHERE UUID = '" + uuid.toString() + "'");
|
||||
@ -40,6 +41,7 @@ public class WarkingUser {
|
||||
this.UUID = java.util.UUID.fromString(dbplayer.getString("UUID"));
|
||||
UserName = dbplayer.getString("UserName");
|
||||
UserGroup = de.warking.hunjy.MySQL.UserGroup.valueOf(dbplayer.getString("UserGroup"));
|
||||
Team = dbplayer.getInt("Team");
|
||||
allUsers.add(this);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
@ -62,6 +64,10 @@ public class WarkingUser {
|
||||
return UserGroup;
|
||||
}
|
||||
|
||||
public int getTeam(){
|
||||
return Team;
|
||||
}
|
||||
|
||||
public static WarkingUser get(String userName){
|
||||
userName = MySQL.disarmString(userName);
|
||||
for(WarkingUser user : allUsers)
|
||||
|
@ -1,57 +0,0 @@
|
||||
package de.warking.hunjy.PlayerManager;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.warking.hunjy.Core;
|
||||
import de.warking.hunjy.MySQL.MySQL;
|
||||
|
||||
public class PlayerManager {
|
||||
|
||||
UUID uuid;
|
||||
private MySQL mySQL;
|
||||
|
||||
public PlayerManager(Player player) {
|
||||
mySQL = Core.getInstance().getMySQL();
|
||||
this.uuid = player.getUniqueId();
|
||||
}
|
||||
|
||||
public PlayerManager(UUID uuid) {
|
||||
mySQL = Core.getInstance().getMySQL();
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public boolean playerExist() {
|
||||
try {
|
||||
PreparedStatement st = mySQL.getCon().prepareStatement("SELECT * FROM UserData WHERE UUID=?");
|
||||
st.setString(1, uuid.toString());
|
||||
ResultSet rs = st.executeQuery();
|
||||
return rs.next();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getGroupName() {
|
||||
try {
|
||||
PreparedStatement st = mySQL.getCon().prepareStatement("SELECT * FROM UserData WHERE UUID=?");
|
||||
st.setString(1, uuid.toString());
|
||||
ResultSet rs = st.executeQuery();
|
||||
while(rs.next()) {
|
||||
return rs.getString("UserGroup");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setGroup(String group) {
|
||||
mySQL.update("UPDATE UserData Set UserGroup='" + group + "' WHERE UUID='" + uuid.toString() + "'");
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
package de.warking.hunjy.PlayerManager.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class PlayerChangeTeamEvent extends Event implements Cancellable{
|
||||
|
||||
public static HandlerList handlers = new HandlerList();
|
||||
public boolean cancelled = false;
|
||||
|
||||
Player player;
|
||||
String oldGroup;
|
||||
String newGroup;
|
||||
|
||||
|
||||
public PlayerChangeTeamEvent(Player player, String oldGroup, String newGroup) {
|
||||
this.player = player;
|
||||
this.oldGroup = oldGroup;
|
||||
this.newGroup = newGroup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public String getOldGroup() {
|
||||
return oldGroup;
|
||||
}
|
||||
|
||||
public String getNewGroup() {
|
||||
return newGroup;
|
||||
}
|
||||
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package de.warking.hunjy.manager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Time;
|
||||
|
||||
import de.warking.hunjy.Core;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
|
||||
public class CacheManager {
|
||||
|
||||
private File file;
|
||||
private YamlConfiguration config;
|
||||
|
||||
public CacheManager() {
|
||||
file = new File(Core.getInstance().getDataFolder(), "cache.yml");
|
||||
config = YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void addCache(String qry) {
|
||||
|
||||
long millis = System.currentTimeMillis();
|
||||
Time time = new Time(millis);
|
||||
|
||||
config.set(time.toLocaleString(), qry);
|
||||
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -6,8 +6,3 @@ author: hunjy, Lixfel
|
||||
main: de.warking.hunjy.Core
|
||||
|
||||
commands:
|
||||
coins:
|
||||
pay:
|
||||
addcoins:
|
||||
removecoins:
|
||||
setcoins:
|
In neuem Issue referenzieren
Einen Benutzer sperren