first commit
This commit is contained in:
15
.classpath
Normal file
15
.classpath
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-13">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="lib" path="/home/spencer/Downloads/spigot-1.15.2.jar">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
||||||
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
**/bin/
|
||||||
|
.metadata/
|
||||||
|
.settings/
|
||||||
17
.project
Normal file
17
.project
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>dev.pinfosec.pin-warn</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
5
config.yml
Normal file
5
config.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# this is a comment
|
||||||
|
port: "3306"
|
||||||
|
dbuser: "user"
|
||||||
|
dbpasswd: "password"
|
||||||
|
dbaddress: "localhost"
|
||||||
10
plugin.yml
Normal file
10
plugin.yml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
main: dev.pinfosec.pinwarn.Main
|
||||||
|
name: Pin-Warn
|
||||||
|
version: 1.0
|
||||||
|
author: Pin
|
||||||
|
api-version: 1.13
|
||||||
|
commands:
|
||||||
|
warn:
|
||||||
|
alliases: [warn]
|
||||||
|
description: This is a holder desc
|
||||||
|
permission: pinwarn.warn
|
||||||
5
src/dev/pinfosec/pinwarn/.classpath
Normal file
5
src/dev/pinfosec/pinwarn/.classpath
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
||||||
17
src/dev/pinfosec/pinwarn/.project
Normal file
17
src/dev/pinfosec/pinwarn/.project
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>pinwarn</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
53
src/dev/pinfosec/pinwarn/Main.java
Normal file
53
src/dev/pinfosec/pinwarn/Main.java
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package dev.pinfosec.pinwarn;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import com.mysql.jdbc.Connection;
|
||||||
|
|
||||||
|
import dev.pinfosec.pinwarn.commands.WarnCommand;
|
||||||
|
|
||||||
|
public class Main extends JavaPlugin {
|
||||||
|
|
||||||
|
final String username = this.getConfig().getString("dbuser");
|
||||||
|
final String password = this.getConfig().getString("dbpasswd");
|
||||||
|
final String url = ("jdbc:mysql://" + this.getConfig().getString("dbaddress") + ":" + this.getConfig().getString("port") + "/pinwarn");
|
||||||
|
public static Connection connection;
|
||||||
|
|
||||||
|
public void onEnable() {
|
||||||
|
new WarnCommand(this);
|
||||||
|
this.saveDefaultConfig();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Class.forName("com.mysql.jdbc.Driver");
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
System.err.println("jdbc driver unavailable!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
connection = (Connection) DriverManager.getConnection(url, username, password);
|
||||||
|
String sql = "CREATE TABLE IF NOT EXISTS pinwarn(UUID varchar(64), "
|
||||||
|
+ "warning1 varchar(64), reason1 text, warning2 varchar(64), "
|
||||||
|
+ "reason2 text, warning3 varchar(64), reason3 text);";
|
||||||
|
PreparedStatement stmt = connection.prepareStatement(sql);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDisable() {
|
||||||
|
try {
|
||||||
|
if (connection!=null && !connection.isClosed()) {
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
114
src/dev/pinfosec/pinwarn/commands/WarnCommand.java
Normal file
114
src/dev/pinfosec/pinwarn/commands/WarnCommand.java
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
package dev.pinfosec.pinwarn.commands;
|
||||||
|
|
||||||
|
import dev.pinfosec.pinwarn.Main;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
|
||||||
|
public class WarnCommand implements CommandExecutor {
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private Main plugin;
|
||||||
|
|
||||||
|
public WarnCommand(Main plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
plugin.getCommand("warn").setExecutor(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command,
|
||||||
|
String label, String[] args) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
switch(args[0]) {
|
||||||
|
case "check":
|
||||||
|
String puuid = Bukkit.getOfflinePlayer(args[1]).getUniqueId().toString();
|
||||||
|
sender.sendMessage(puuid);
|
||||||
|
String sqlcheck = "SELECT * from pinwarn WHERE UUID=?;";
|
||||||
|
sender.sendMessage(sqlcheck);
|
||||||
|
PreparedStatement stmtcheck = dev.pinfosec.pinwarn.Main.connection.prepareStatement(sqlcheck);
|
||||||
|
stmtcheck.setString(1, Bukkit.getOfflinePlayer(args[1]).getUniqueId().toString());
|
||||||
|
sender.sendMessage(sqlcheck);
|
||||||
|
ResultSet rs = stmtcheck.executeQuery();
|
||||||
|
while (rs.next()) {
|
||||||
|
String playeruuid = rs.getString(1);
|
||||||
|
String warning1 = rs.getString(2);
|
||||||
|
String reason1 = rs.getString(3);
|
||||||
|
String warning2 = rs.getString(4);
|
||||||
|
String reason2 = rs.getString(5);
|
||||||
|
String warning3 = rs.getString(6);
|
||||||
|
String reason3 = rs.getString(7);
|
||||||
|
sender.sendMessage("User: " + args[1]);
|
||||||
|
sender.sendMessage("UUID: " + playeruuid);
|
||||||
|
sender.sendMessage("Warning 1: " + warning1);
|
||||||
|
sender.sendMessage("Reason: " + reason1);
|
||||||
|
sender.sendMessage("Warning 2: " + warning2);
|
||||||
|
sender.sendMessage("Reason: " + reason2);
|
||||||
|
sender.sendMessage("Warning 3: " + warning3);
|
||||||
|
sender.sendMessage("Reason: " + reason3);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "list":
|
||||||
|
sender.sendMessage("This is a list");
|
||||||
|
sender.sendMessage("This is arg 1 " + args[1]);
|
||||||
|
break;
|
||||||
|
case "add":
|
||||||
|
String warnedplayer = args[1];
|
||||||
|
String pexistqry = "SELECT EXISTS(SELECT * FROM pinwarn WHERE UUID=?);";
|
||||||
|
PreparedStatement pexiststm = dev.pinfosec.pinwarn.Main.connection.prepareStatement(pexistqry);
|
||||||
|
pexiststm.setString(1, Bukkit.getOfflinePlayer(args[1]).getUniqueId().toString());
|
||||||
|
ResultSet pexrs = null;
|
||||||
|
pexrs = pexiststm.executeQuery();
|
||||||
|
while (pexrs.next()) {
|
||||||
|
if(pexrs.getBoolean(1)) {
|
||||||
|
String warn2chk = "SELECT warning2 FROM pinwarn WHERE UUID=?;";
|
||||||
|
PreparedStatement warn2chkstm = dev.pinfosec.pinwarn.Main.connection.prepareStatement(warn2chk);
|
||||||
|
warn2chkstm.setString(1, Bukkit.getOfflinePlayer(args[1]).getUniqueId().toString());
|
||||||
|
ResultSet warn2rs = null;
|
||||||
|
warn2rs = warn2chkstm.executeQuery();
|
||||||
|
while (warn2rs.next()) {
|
||||||
|
if(warn2rs.getBoolean(1)) {
|
||||||
|
String sql3 = "UPDATE `pinwarn` SET warning3=?, reason3=? WHERE UUID=?;";
|
||||||
|
PreparedStatement stmt3 = dev.pinfosec.pinwarn.Main.connection.prepareStatement(sql3);
|
||||||
|
stmt3.setString(3, Bukkit.getOfflinePlayer(warnedplayer).getUniqueId().toString());
|
||||||
|
stmt3.setString(1, args[2]);
|
||||||
|
stmt3.setString(2, args[3]);
|
||||||
|
stmt3.executeUpdate();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
String sql2 = "UPDATE `pinwarn` SET warning2=?, reason2=? WHERE UUID=?;";
|
||||||
|
PreparedStatement stmt2 = dev.pinfosec.pinwarn.Main.connection.prepareStatement(sql2);
|
||||||
|
stmt2.setString(3, Bukkit.getOfflinePlayer(warnedplayer).getUniqueId().toString());
|
||||||
|
stmt2.setString(1, args[2]);
|
||||||
|
stmt2.setString(2, args[3]);
|
||||||
|
stmt2.executeUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
String sql = "INSERT INTO `pinwarn`(uuid, warning1, reason1) VALUES (?, ?, ?);";
|
||||||
|
PreparedStatement stmt = dev.pinfosec.pinwarn.Main.connection.prepareStatement(sql);
|
||||||
|
stmt.setString(1, Bukkit.getOfflinePlayer(warnedplayer).getUniqueId().toString());
|
||||||
|
stmt.setString(2, args[2]);
|
||||||
|
stmt.setString(3, args[3]);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
sender.sendMessage("Unknown");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user