Initial commit
This commit is contained in:
8
Plugins/Old/CoinAPI/.idea/workspace.xml
generated
Normal file
8
Plugins/Old/CoinAPI/.idea/workspace.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showExcludedFiles" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
</project>
|
||||
0
Plugins/Old/CoinAPI/README.md
Normal file
0
Plugins/Old/CoinAPI/README.md
Normal file
3
Plugins/Old/CoinAPI/coinapi/.idea/.gitignore
generated
vendored
Normal file
3
Plugins/Old/CoinAPI/coinapi/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
1
Plugins/Old/CoinAPI/coinapi/.idea/.name
generated
Normal file
1
Plugins/Old/CoinAPI/coinapi/.idea/.name
generated
Normal file
@@ -0,0 +1 @@
|
||||
CoinAPI
|
||||
8
Plugins/Old/CoinAPI/coinapi/.idea/artifacts/CoinAPI.xml
generated
Normal file
8
Plugins/Old/CoinAPI/coinapi/.idea/artifacts/CoinAPI.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<component name="ArtifactManager">
|
||||
<artifact type="jar" name="CoinAPI">
|
||||
<output-path>$USER_HOME$/Desktop/Localhost/plugins</output-path>
|
||||
<root id="archive" name="CoinAPI.jar">
|
||||
<element id="module-output" name="CoinAPI" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
||||
11
Plugins/Old/CoinAPI/coinapi/.idea/libraries/spigot_1_8_8.xml
generated
Normal file
11
Plugins/Old/CoinAPI/coinapi/.idea/libraries/spigot_1_8_8.xml
generated
Normal file
@@ -0,0 +1,11 @@
|
||||
<component name="libraryTable">
|
||||
<library name="spigot 1.8.8">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/../../Spigot Versions/spigot 1.8.8.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$PROJECT_DIR$/../../Spigot Versions/spigot 1.8.8.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
11
Plugins/Old/CoinAPI/coinapi/.idea/misc.xml
generated
Normal file
11
Plugins/Old/CoinAPI/coinapi/.idea/misc.xml
generated
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<list size="1">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.bukkit.event.EventHandler" />
|
||||
</list>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
8
Plugins/Old/CoinAPI/coinapi/.idea/modules.xml
generated
Normal file
8
Plugins/Old/CoinAPI/coinapi/.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/CoinAPI.iml" filepath="$PROJECT_DIR$/CoinAPI.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
6
Plugins/Old/CoinAPI/coinapi/.idea/vcs.xml
generated
Normal file
6
Plugins/Old/CoinAPI/coinapi/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
21
Plugins/Old/CoinAPI/coinapi/CoinAPI.iml
Normal file
21
Plugins/Old/CoinAPI/coinapi/CoinAPI.iml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>SPIGOT</platformType>
|
||||
</autoDetectTypes>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="spigot 1.8.8" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,6 @@
|
||||
main: de.craftix.coinapi.CoinAPI
|
||||
name: CoinAPI
|
||||
version: 1.8.8
|
||||
|
||||
commands:
|
||||
coins:
|
||||
@@ -0,0 +1,86 @@
|
||||
package de.craftix.coinapi;
|
||||
|
||||
import de.craftix.coinapi.commands.Coins;
|
||||
import de.craftix.coinapi.listener.onJoin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class CoinAPI extends JavaPlugin {
|
||||
private static CoinAPI instance;
|
||||
|
||||
public static int startCoins = 1000;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
MySQL.connect();
|
||||
MySQL.update("CREATE TABLE IF NOT EXISTS coins (UUID VARCHAR(100), Coins INT(100))");
|
||||
getCommand("coins").setExecutor(new Coins());
|
||||
Bukkit.getPluginManager().registerEvents(new onJoin(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
MySQL.disconnect();
|
||||
}
|
||||
|
||||
public static CoinAPI getInstance(){ return instance; }
|
||||
|
||||
public static void setCoins(Player p, int coins){
|
||||
if (isUserRegistrated(p)){
|
||||
MySQL.update("INSERT INTO coins(UUID, Coins) VALUES (" + p.getUniqueId().toString() + ", " + coins + ")");
|
||||
}else {
|
||||
MySQL.update("UPDATE coins SET Coins = " + coins + " WHERE UUID = " + p.getUniqueId().toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static void addCoins(Player p, int coins){
|
||||
setCoins(p, (getCoins(p) + coins));
|
||||
}
|
||||
|
||||
public static void removeCoins(Player p, int coins){
|
||||
int i = getCoins(p);
|
||||
if (i - coins > 0) setCoins(p, getCoins(p) - coins);
|
||||
else setCoins(p, 0);
|
||||
}
|
||||
|
||||
public static int getCoins(Player p){
|
||||
Integer i = 0;
|
||||
if (isUserRegistrated(p)) {
|
||||
try {
|
||||
final ResultSet rs = MySQL.get("SELECT * FROM coins WHERE UUID= '" + p.getUniqueId().toString() + "'");
|
||||
if (!rs.next() || Integer.valueOf(rs.getInt("Coins")) == null) {}
|
||||
i = rs.getInt("Coins");
|
||||
}
|
||||
catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else {
|
||||
setCoins(p, startCoins);
|
||||
getCoins(p);
|
||||
}
|
||||
return i;
|
||||
|
||||
}
|
||||
|
||||
public static boolean checkCoins(Player p, int coins){
|
||||
if (getCoins(p) - coins > 0) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isUserRegistrated(Player p){
|
||||
try{
|
||||
ResultSet rs = MySQL.get("SELECT * FROM coins WHERE UUID = " + p.getUniqueId().toString());
|
||||
return rs.next() && rs.getString("UUID") != null;
|
||||
}catch (SQLException throwables){
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package de.craftix.coinapi;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class MySQL {
|
||||
|
||||
private static String host = "localhost";
|
||||
private static String port = "3306";
|
||||
private static String database = "coins";
|
||||
private static String username = "Coins";
|
||||
private static String password = "1234";
|
||||
private static Connection con = null;
|
||||
|
||||
public static void connect(){
|
||||
try {
|
||||
con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
|
||||
System.out.println("[MySQL] Connected");
|
||||
} catch (SQLException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void disconnect(){
|
||||
if (con == null) return;
|
||||
try {
|
||||
con.close();
|
||||
System.out.println("[MySQL] Disconnected");
|
||||
}catch (SQLException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void update(String qry){
|
||||
try {
|
||||
con.createStatement().executeUpdate(qry);
|
||||
}
|
||||
catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static ResultSet get(String qry){
|
||||
try {
|
||||
return con.createStatement().executeQuery(qry);
|
||||
}
|
||||
catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package de.craftix.coinapi.commands;
|
||||
|
||||
import de.craftix.coinapi.CoinAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Coins implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
|
||||
if (!(sender instanceof Player)) return true;
|
||||
Player p = (Player)sender;
|
||||
if (args.length == 0){
|
||||
p.sendMessage("§aDu hast §6" + CoinAPI.getCoins(p) + " §aCoins!");
|
||||
}else if (args.length == 1){
|
||||
if (!p.hasPermission("coins.ohter")) return true;
|
||||
if (Bukkit.getPlayer(args[0]) == null) return true;
|
||||
Player t = Bukkit.getPlayer(args[0]);
|
||||
p.sendMessage("§aDer spieler §6" + t.getDisplayName() + " §a hat §6" + CoinAPI.getCoins(t) + " §aCoins");
|
||||
}else if (args.length == 2){
|
||||
if (!p.hasPermission("coins.admin")) return true;
|
||||
if (args[0].equalsIgnoreCase("add")){
|
||||
CoinAPI.addCoins(p, Integer.parseInt(args[1]));
|
||||
p.sendMessage("§aDu hast nun §6" + CoinAPI.getCoins(p) + " §aCoins");
|
||||
}else if (args[0].equalsIgnoreCase("set")){
|
||||
CoinAPI.setCoins(p, Integer.parseInt(args[1]));
|
||||
p.sendMessage("§aDu hast nun §6" + CoinAPI.getCoins(p) + " §aCoins");
|
||||
}else if (args[0].equalsIgnoreCase("remove")){
|
||||
CoinAPI.removeCoins(p, Integer.parseInt(args[1]));
|
||||
p.sendMessage("§aDu hast nun §6" + CoinAPI.getCoins(p) + " §aCoins");
|
||||
}
|
||||
}else if (args.length == 3){
|
||||
if (!p.hasPermission("coins.admin")) return true;
|
||||
if (Bukkit.getPlayer(args[2]) == null) return true;
|
||||
Player t = Bukkit.getPlayer(args[0]);
|
||||
if (args[0].equalsIgnoreCase("add")){
|
||||
CoinAPI.addCoins(t, Integer.parseInt(args[1]));
|
||||
p.sendMessage("§aDer spieler §6" + t.getDisplayName() + " §ahat nun §6" + CoinAPI.getCoins(t) + " §aCoins");
|
||||
}else if (args[0].equalsIgnoreCase("set")){
|
||||
CoinAPI.setCoins(t, Integer.parseInt(args[1]));
|
||||
p.sendMessage("§aDer spieler §6" + t.getDisplayName() + " §ahat nun §6" + CoinAPI.getCoins(t) + " §aCoins");
|
||||
}else if (args[0].equalsIgnoreCase("remove")){
|
||||
CoinAPI.removeCoins(t, Integer.parseInt(args[1]));
|
||||
p.sendMessage("§aDer spieler §6" + t.getDisplayName() + " §ahat nun §6" + CoinAPI.getCoins(t) + " §aCoins");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package de.craftix.coinapi.listener;
|
||||
|
||||
import de.craftix.coinapi.CoinAPI;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class onJoin implements Listener {
|
||||
|
||||
public void onJoinEvent(PlayerJoinEvent event){
|
||||
Player p = event.getPlayer();
|
||||
if (!CoinAPI.isUserRegistrated(p)) CoinAPI.setCoins(p, CoinAPI.startCoins);
|
||||
}
|
||||
|
||||
}
|
||||
6
Plugins/Old/CoinAPI/coinapi/src/plugin.yml
Normal file
6
Plugins/Old/CoinAPI/coinapi/src/plugin.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
main: de.craftix.coinapi.CoinAPI
|
||||
name: CoinAPI
|
||||
version: 1.8.8
|
||||
|
||||
commands:
|
||||
coins:
|
||||
Reference in New Issue
Block a user