changed database from MySQL to MongoDB mainly
This commit is contained in:
parent
234dec0439
commit
5f05f95ee8
27
Core.iml
27
Core.iml
@ -12,25 +12,24 @@
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="spigot-1.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:3.2.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mongodb:mongodb-driver-async:3.2.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mongodb:mongodb-driver-core:3.2.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mongodb:bson:3.2.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.netty:netty-all:4.0.31.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.projectlombok:lombok:1.16.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.bukkit:craftbukkit:1.9-R0.1-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.9-R0.1-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.6" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: junit:junit:4.10" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:17.0" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.2.4" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.avaje:ebean:2.8.1" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.persistence:persistence-api:1.0" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.15" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot-api:1.9-R0.1-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: net.md-5:bungeecord-chat:1.9-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:craftbukkit:1.9.2-R0.1-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.9.2-R0.1-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: junit:junit:4.10" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.guava:guava:17.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.2.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.avaje:ebean:2.8.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.persistence:persistence-api:1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.15" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.spigotmc:spigot-api:1.9.2-R0.1-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" name="Maven: net.md-5:bungeecord-chat:1.9-SNAPSHOT" level="project" />
|
||||
</component>
|
||||
</module>
|
9
pom.xml
9
pom.xml
@ -17,6 +17,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
@ -82,19 +83,19 @@
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.9-R0.1-SNAPSHOT</version>
|
||||
<version>1.9.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.9-R0.1-SNAPSHOT</version>
|
||||
<version>1.9.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.9-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<version>1.9.2-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -101,7 +101,8 @@ public class Core extends JavaPlugin{
|
||||
new Fix(this, "fix", "fix");
|
||||
new Stats(this, "stats", "statistics");
|
||||
new Nick(this, "nick", "nick");
|
||||
}else{
|
||||
}
|
||||
if(!ServerSettings.isBuild()) {
|
||||
new Build(this, "build", "build", "b");
|
||||
pm.registerEvents(new Blocks(), this);
|
||||
}
|
||||
@ -119,16 +120,17 @@ public class Core extends JavaPlugin{
|
||||
log(Level.INFO, "registered all commands");
|
||||
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "LABYMOD");
|
||||
|
||||
Blackscreen.setupUtil(getInstance());
|
||||
//mongoDB = new MongoDB(Config.readString("MongoDB.Host"), Config.readInt("MongoDB.Port"), Config.readString("MongoDB.Username"), Config.readString("MongoDB.Password"), Config.readString("MongoDB.Database"));
|
||||
|
||||
mongoDB = new MongoDB(Config.readString("MongoDB.Host"), Config.readInt("MongoDB.Port"), Config.readString("MongoDB.User"), Config.readString("MongoDB.Password"), Config.readString("MongoDB.Database"));
|
||||
|
||||
log(Level.INFO, "Plugin ver. " + getDescription().getVersion() + " started");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
mongoDB.getClient().close();
|
||||
log(Level.INFO, "Plugin stoped");
|
||||
}
|
||||
|
||||
|
@ -31,15 +31,16 @@ public class Config {
|
||||
//editable messages will be set here, but do not edit this messages.
|
||||
|
||||
//seting the default MySQL config.
|
||||
cfg.addDefault("MySQL.Host", "192.168.0.101");
|
||||
cfg.addDefault("MySQL.Host", "hostname");
|
||||
cfg.addDefault("MySQL.Port", "3306");
|
||||
cfg.addDefault("MySQL.DB", "core");
|
||||
cfg.addDefault("MySQL.User", "root");//best user name
|
||||
cfg.addDefault("MySQL.Pass", "");//best password
|
||||
cfg.addDefault("TS.IP", "ts.univento.eu");
|
||||
cfg.addDefault("TS.QueryPort", 0);
|
||||
cfg.addDefault("TS.QueryUser", "ServerQuery");
|
||||
cfg.addDefault("TS.QueryPass", "password");
|
||||
cfg.addDefault("MySQL.User", "root");
|
||||
cfg.addDefault("MySQL.Pass", "");
|
||||
cfg.addDefault("MongoDB.Host", "Hostname");
|
||||
cfg.addDefault("MongoDB.Port", 27017);
|
||||
cfg.addDefault("MongoDB.User", "univento");
|
||||
cfg.addDefault("MongoDB.Password", "1234");
|
||||
cfg.addDefault("MongoDB.Database", "univento");
|
||||
|
||||
cfg.options().copyDefaults(true);
|
||||
cfg.save(file);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package eu.univento.core.api;
|
||||
|
||||
|
||||
import eu.univento.core.Core;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -154,14 +155,7 @@ public class Utils {
|
||||
* restarts server
|
||||
*/
|
||||
public static void restart() {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Core.getInstance(), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Bukkit.getServer().spigot().restart();
|
||||
}
|
||||
|
||||
}, 10 * 20L);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Core.getInstance(), () -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "/restart"), 10 * 20L);
|
||||
}
|
||||
|
||||
/**
|
||||
|
153
src/main/java/eu/univento/core/api/database/AsyncMySQL.java
Normal file
153
src/main/java/eu/univento/core/api/database/AsyncMySQL.java
Normal file
@ -0,0 +1,153 @@
|
||||
package eu.univento.core.api.database;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
*/
|
||||
public class AsyncMySQL {
|
||||
private ExecutorService executor;
|
||||
private Plugin plugin;
|
||||
private MySQL sql;
|
||||
|
||||
public AsyncMySQL(Plugin owner, String host, int port, String user, String password, String database) {
|
||||
try {
|
||||
sql = new MySQL(host, port, user, password, database);
|
||||
executor = Executors.newCachedThreadPool();
|
||||
plugin = owner;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void update(PreparedStatement statement) {
|
||||
executor.execute(() -> sql.queryUpdate(statement));
|
||||
}
|
||||
|
||||
public void update(String statement) {
|
||||
executor.execute(() -> sql.queryUpdate(statement));
|
||||
}
|
||||
|
||||
public void query(PreparedStatement statement, Consumer<ResultSet> consumer) {
|
||||
executor.execute(() -> {
|
||||
ResultSet result = sql.query(statement);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> consumer.accept(result));
|
||||
});
|
||||
}
|
||||
|
||||
public void query(String statement, Consumer<ResultSet> consumer) {
|
||||
executor.execute(() -> {
|
||||
ResultSet result = sql.query(statement);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> consumer.accept(result));
|
||||
});
|
||||
}
|
||||
|
||||
public PreparedStatement prepare(String query) {
|
||||
try {
|
||||
return sql.getConnection().prepareStatement(query);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public MySQL getMySQL() {
|
||||
return sql;
|
||||
}
|
||||
|
||||
public static class MySQL {
|
||||
|
||||
private String host, user, password, database;
|
||||
private int port;
|
||||
|
||||
private Connection conn;
|
||||
|
||||
public MySQL(String host, int port, String user, String password, String database) throws Exception {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.user = user;
|
||||
this.password = password;
|
||||
this.database = database;
|
||||
|
||||
this.openConnection();
|
||||
}
|
||||
|
||||
public void queryUpdate(String query) {
|
||||
checkConnection();
|
||||
try (PreparedStatement statement = conn.prepareStatement(query)) {
|
||||
queryUpdate(statement);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void queryUpdate(PreparedStatement statement) {
|
||||
checkConnection();
|
||||
try {
|
||||
statement.executeUpdate();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
statement.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ResultSet query(String query) {
|
||||
checkConnection();
|
||||
try {
|
||||
return query(conn.prepareStatement(query));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ResultSet query(PreparedStatement statement) {
|
||||
checkConnection();
|
||||
try {
|
||||
return statement.executeQuery();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Connection getConnection() {
|
||||
return this.conn;
|
||||
}
|
||||
|
||||
private void checkConnection() {
|
||||
try {
|
||||
if (this.conn == null || !this.conn.isValid(10) || this.conn.isClosed()) openConnection();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Connection openConnection() throws Exception {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
return this.conn = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.user, this.password);
|
||||
}
|
||||
|
||||
public void closeConnection() {
|
||||
try {
|
||||
this.conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
this.conn = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -7,66 +7,59 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public abstract class Database
|
||||
{
|
||||
protected Connection connection;
|
||||
protected Plugin plugin;
|
||||
public abstract class Database {
|
||||
protected Connection connection;
|
||||
protected Plugin plugin;
|
||||
|
||||
protected Database(Plugin plugin)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.connection = null;
|
||||
}
|
||||
|
||||
public abstract Connection openConnection()
|
||||
throws SQLException, ClassNotFoundException;
|
||||
|
||||
public boolean checkConnection()
|
||||
throws SQLException
|
||||
{
|
||||
return (this.connection != null) && (!this.connection.isClosed());
|
||||
}
|
||||
|
||||
public Connection getConnection()
|
||||
{
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
public boolean closeConnection()
|
||||
throws SQLException
|
||||
{
|
||||
if (this.connection == null) {
|
||||
return false;
|
||||
}
|
||||
this.connection.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
public ResultSet querySQL(String query)
|
||||
throws SQLException, ClassNotFoundException
|
||||
{
|
||||
if (!checkConnection()) {
|
||||
openConnection();
|
||||
protected Database(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.connection = null;
|
||||
}
|
||||
|
||||
Statement statement = this.connection.createStatement();
|
||||
public abstract Connection openConnection()
|
||||
throws SQLException, ClassNotFoundException;
|
||||
|
||||
ResultSet result = statement.executeQuery(query);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public int updateSQL(String query)
|
||||
throws SQLException, ClassNotFoundException
|
||||
{
|
||||
if (!checkConnection()) {
|
||||
openConnection();
|
||||
public boolean checkConnection()
|
||||
throws SQLException {
|
||||
return (this.connection != null) && (!this.connection.isClosed());
|
||||
}
|
||||
|
||||
Statement statement = this.connection.createStatement();
|
||||
public Connection getConnection() {
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
int result = statement.executeUpdate(query);
|
||||
public boolean closeConnection()
|
||||
throws SQLException {
|
||||
if (this.connection == null) {
|
||||
return false;
|
||||
}
|
||||
this.connection.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
public ResultSet querySQL(String query)
|
||||
throws SQLException, ClassNotFoundException {
|
||||
if (!checkConnection()) {
|
||||
openConnection();
|
||||
}
|
||||
|
||||
Statement statement = this.connection.createStatement();
|
||||
|
||||
ResultSet result = statement.executeQuery(query);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public int updateSQL(String query)
|
||||
throws SQLException, ClassNotFoundException {
|
||||
if (!checkConnection()) {
|
||||
openConnection();
|
||||
}
|
||||
|
||||
Statement statement = this.connection.createStatement();
|
||||
|
||||
int result = statement.executeUpdate(query);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ import com.mongodb.ServerAddress;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import eu.univento.core.api.Config;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
public class MongoDB {
|
||||
|
||||
@ -15,19 +15,19 @@ public class MongoDB {
|
||||
|
||||
public MongoClient getClient() {
|
||||
if(client == null)
|
||||
new MongoDB(Config.readString("MongoDB.Host"), Config.readInt("MongoDB.Port"), Config.readString("MongoDB.Username"), Config.readString("MongoDB.Password"), Config.readString("MongoDB.Database"));
|
||||
new MongoDB(Config.readString("MongoDB.Host"), Config.readInt("MongoDB.Port"), Config.readString("MongoDB.User"), Config.readString("MongoDB.Password"), Config.readString("MongoDB.Database"));
|
||||
return client;
|
||||
}
|
||||
|
||||
public MongoDB(String host, int port, String username, String password, String database) {
|
||||
MongoCredential credential = MongoCredential.createCredential(username, database, password.toCharArray());
|
||||
client = new MongoClient(new ServerAddress(host, port), Arrays.asList(credential));
|
||||
client = new MongoClient(new ServerAddress(host, port), Collections.singletonList(credential));
|
||||
}
|
||||
|
||||
public MongoDatabase getDatabase() {
|
||||
if(database == null) {
|
||||
if(database == null)
|
||||
database = getClient().getDatabase(Config.readString("MongoDB.Database"));
|
||||
}return database;
|
||||
return database;
|
||||
}
|
||||
|
||||
public void setDatabase(String database) {
|
||||
@ -35,9 +35,8 @@ public class MongoDB {
|
||||
}
|
||||
|
||||
public void closeConnection() {
|
||||
if(client != null) {
|
||||
if(client != null)
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -13,227 +13,197 @@ import org.bukkit.plugin.Plugin;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author GerVorbis
|
||||
* @version 1.0
|
||||
*/
|
||||
public class EntityModifier
|
||||
{
|
||||
static org.bukkit.entity.Entity entity;
|
||||
static CraftEntity craftentity;
|
||||
static net.minecraft.server.v1_9_R1.Entity entityS;
|
||||
static int scheduler;
|
||||
static Plugin plugin;
|
||||
static Player player = null;
|
||||
static float Speed;
|
||||
public class EntityModifier {
|
||||
static org.bukkit.entity.Entity entity;
|
||||
static CraftEntity craftentity;
|
||||
static net.minecraft.server.v1_9_R1.Entity entityS;
|
||||
static int scheduler;
|
||||
static Plugin plugin;
|
||||
static Player player = null;
|
||||
static float Speed;
|
||||
|
||||
public EntityModifier(org.bukkit.entity.Entity entity, Plugin plugin)
|
||||
{
|
||||
EntityModifier.entity = entity;
|
||||
craftentity = (CraftEntity)entity;
|
||||
entityS = craftentity.getHandle();
|
||||
EntityModifier.plugin = plugin;
|
||||
}
|
||||
|
||||
public static Builder modify()
|
||||
{
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static final class Builder
|
||||
{
|
||||
public Builder setDisplayName(String display)
|
||||
{
|
||||
EntityModifier.entity.setCustomName(display);
|
||||
EntityModifier.entity.setCustomNameVisible(true);
|
||||
return this;
|
||||
public EntityModifier(org.bukkit.entity.Entity entity, Plugin plugin) {
|
||||
EntityModifier.entity = entity;
|
||||
craftentity = (CraftEntity) entity;
|
||||
entityS = craftentity.getHandle();
|
||||
EntityModifier.plugin = plugin;
|
||||
}
|
||||
|
||||
public Builder setDisplayNameVisible(Boolean visible)
|
||||
{
|
||||
EntityModifier.entity.setCustomNameVisible(visible.booleanValue());
|
||||
return this;
|
||||
public static Builder modify() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder playEffekt(EntityEffect entityeffect)
|
||||
{
|
||||
EntityModifier.entity.playEffect(entityeffect);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder remove()
|
||||
{
|
||||
EntityModifier.entity.remove();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setPassenger(org.bukkit.entity.Entity passenger)
|
||||
{
|
||||
EntityModifier.entity.setPassenger(passenger);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setFireTicks(int ticks)
|
||||
{
|
||||
EntityModifier.entity.setFireTicks(ticks);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setLocation(Location location)
|
||||
{
|
||||
teleport(location);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setYawPitch(float yaw, float pitch)
|
||||
{
|
||||
Location loc = EntityModifier.entity.getLocation().clone();
|
||||
teleport(
|
||||
new Location(loc.getWorld(), loc.getX(), loc.getY(),
|
||||
loc.getZ(), yaw, pitch));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder teleport(Location location)
|
||||
{
|
||||
EntityModifier.entity.teleport(location);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder die()
|
||||
{
|
||||
EntityModifier.entityS.die();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setInvisible(boolean invisible)
|
||||
{
|
||||
EntityModifier.entityS.setInvisible(invisible);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder noClip(boolean noClip)
|
||||
{
|
||||
EntityModifier.entityS.noclip = noClip;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setInvulnerable(boolean invulnerable)
|
||||
{
|
||||
try
|
||||
{
|
||||
Field invulnerableField = net.minecraft.server.v1_9_R1.Entity.class
|
||||
.getDeclaredField("invulnerable");
|
||||
invulnerableField.setAccessible(true);
|
||||
invulnerableField.setBoolean(EntityModifier.entityS, invulnerable);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setNoAI(boolean noAI)
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
EntityModifier.entityS.c(tag);
|
||||
tag.setBoolean("NoAI", noAI);
|
||||
EntityLiving el = (EntityLiving)EntityModifier.entityS;
|
||||
el.a(tag);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSilent(boolean silent)
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
EntityModifier.entityS.c(tag);
|
||||
tag.setBoolean("Silent", silent);
|
||||
EntityLiving el = (EntityLiving)EntityModifier.entityS;
|
||||
el.a(tag);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setCanPickUpLoot(boolean canpickuploot)
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
EntityModifier.entityS.c(tag);
|
||||
tag.setBoolean("CanPickUpLoot", canpickuploot);
|
||||
EntityLiving el = (EntityLiving)EntityModifier.entityS;
|
||||
el.a(tag);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setHealth(float health)
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
EntityModifier.entityS.c(tag);
|
||||
tag.setFloat("HealF", health);
|
||||
EntityLiving el = (EntityLiving)EntityModifier.entityS;
|
||||
el.a(tag);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setCanDespawn(boolean candespawn)
|
||||
{
|
||||
candespawn = !candespawn;
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
EntityModifier.entityS.c(tag);
|
||||
tag.setBoolean("PersistenceRequired", candespawn);
|
||||
EntityLiving el = (EntityLiving)EntityModifier.entityS;
|
||||
el.a(tag);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder walkToLocation(Location location, float speed)
|
||||
{
|
||||
((CraftCreature)EntityModifier.entity)
|
||||
.getHandle()
|
||||
.getNavigation()
|
||||
.a(location.getX(), location.getY(), location.getZ(), speed);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder followPlayer(Player target, float speed)
|
||||
{
|
||||
EntityModifier.player = target;
|
||||
EntityModifier.Speed = speed;
|
||||
EntityModifier.scheduler = Bukkit.getScheduler().scheduleSyncRepeatingTask(EntityModifier.plugin,
|
||||
new Runnable()
|
||||
{
|
||||
@SuppressWarnings("deprecation")
|
||||
public void run() {
|
||||
double distance = EntityModifier.entity.getLocation().distance(
|
||||
EntityModifier.player.getLocation());
|
||||
if (distance < 11.0D) {
|
||||
float speed = EntityModifier.Speed;
|
||||
if (distance < 3.0D) {
|
||||
speed = 0.0F;
|
||||
}
|
||||
((CraftCreature)EntityModifier.entity)
|
||||
.getHandle()
|
||||
.getNavigation()
|
||||
.a(EntityModifier.player.getLocation().getX(),
|
||||
EntityModifier.player.getLocation().getY(),
|
||||
EntityModifier.player.getLocation().getZ(),
|
||||
speed);
|
||||
}
|
||||
else if (EntityModifier.player.isOnGround()) {
|
||||
EntityModifier.entity.teleport(EntityModifier.player);
|
||||
}
|
||||
public static final class Builder {
|
||||
public Builder setDisplayName(String display) {
|
||||
EntityModifier.entity.setCustomName(display);
|
||||
EntityModifier.entity.setCustomNameVisible(true);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
, 0L, 1L);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder stopFollowingPlayer()
|
||||
{
|
||||
Bukkit.getScheduler().cancelTask(EntityModifier.scheduler);
|
||||
return this;
|
||||
}
|
||||
public Builder setDisplayNameVisible(Boolean visible) {
|
||||
EntityModifier.entity.setCustomNameVisible(visible.booleanValue());
|
||||
return this;
|
||||
}
|
||||
|
||||
public org.bukkit.entity.Entity build()
|
||||
{
|
||||
return EntityModifier.entity;
|
||||
public Builder playEffekt(EntityEffect entityeffect) {
|
||||
EntityModifier.entity.playEffect(entityeffect);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder remove() {
|
||||
EntityModifier.entity.remove();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setPassenger(org.bukkit.entity.Entity passenger) {
|
||||
EntityModifier.entity.setPassenger(passenger);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setFireTicks(int ticks) {
|
||||
EntityModifier.entity.setFireTicks(ticks);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setLocation(Location location) {
|
||||
teleport(location);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setYawPitch(float yaw, float pitch) {
|
||||
Location loc = EntityModifier.entity.getLocation().clone();
|
||||
teleport(
|
||||
new Location(loc.getWorld(), loc.getX(), loc.getY(),
|
||||
loc.getZ(), yaw, pitch));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder teleport(Location location) {
|
||||
EntityModifier.entity.teleport(location);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder die() {
|
||||
EntityModifier.entityS.die();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setInvisible(boolean invisible) {
|
||||
EntityModifier.entityS.setInvisible(invisible);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder noClip(boolean noClip) {
|
||||
EntityModifier.entityS.noclip = noClip;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setInvulnerable(boolean invulnerable) {
|
||||
try {
|
||||
Field invulnerableField = net.minecraft.server.v1_9_R1.Entity.class
|
||||
.getDeclaredField("invulnerable");
|
||||
invulnerableField.setAccessible(true);
|
||||
invulnerableField.setBoolean(EntityModifier.entityS, invulnerable);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setNoAI(boolean noAI) {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
EntityModifier.entityS.c(tag);
|
||||
tag.setBoolean("NoAI", noAI);
|
||||
EntityLiving el = (EntityLiving) EntityModifier.entityS;
|
||||
el.a(tag);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSilent(boolean silent) {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
EntityModifier.entityS.c(tag);
|
||||
tag.setBoolean("Silent", silent);
|
||||
EntityLiving el = (EntityLiving) EntityModifier.entityS;
|
||||
el.a(tag);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setCanPickUpLoot(boolean canpickuploot) {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
EntityModifier.entityS.c(tag);
|
||||
tag.setBoolean("CanPickUpLoot", canpickuploot);
|
||||
EntityLiving el = (EntityLiving) EntityModifier.entityS;
|
||||
el.a(tag);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setHealth(float health) {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
EntityModifier.entityS.c(tag);
|
||||
tag.setFloat("HealF", health);
|
||||
EntityLiving el = (EntityLiving) EntityModifier.entityS;
|
||||
el.a(tag);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setCanDespawn(boolean candespawn) {
|
||||
candespawn = !candespawn;
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
EntityModifier.entityS.c(tag);
|
||||
tag.setBoolean("PersistenceRequired", candespawn);
|
||||
EntityLiving el = (EntityLiving) EntityModifier.entityS;
|
||||
el.a(tag);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder walkToLocation(Location location, float speed) {
|
||||
((CraftCreature) EntityModifier.entity)
|
||||
.getHandle()
|
||||
.getNavigation()
|
||||
.a(location.getX(), location.getY(), location.getZ(), speed);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder followPlayer(Player target, float speed) {
|
||||
EntityModifier.player = target;
|
||||
EntityModifier.Speed = speed;
|
||||
EntityModifier.scheduler = Bukkit.getScheduler().scheduleSyncRepeatingTask(EntityModifier.plugin,
|
||||
new Runnable() {
|
||||
@SuppressWarnings("deprecation")
|
||||
public void run() {
|
||||
double distance = EntityModifier.entity.getLocation().distance(
|
||||
EntityModifier.player.getLocation());
|
||||
if (distance < 11.0D) {
|
||||
float speed = EntityModifier.Speed;
|
||||
if (distance < 3.0D) {
|
||||
speed = 0.0F;
|
||||
}
|
||||
((CraftCreature) EntityModifier.entity)
|
||||
.getHandle()
|
||||
.getNavigation()
|
||||
.a(EntityModifier.player.getLocation().getX(),
|
||||
EntityModifier.player.getLocation().getY(),
|
||||
EntityModifier.player.getLocation().getZ(),
|
||||
speed);
|
||||
} else if (EntityModifier.player.isOnGround()) {
|
||||
EntityModifier.entity.teleport(EntityModifier.player);
|
||||
}
|
||||
}
|
||||
}
|
||||
, 0L, 1L);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder stopFollowingPlayer() {
|
||||
Bukkit.getScheduler().cancelTask(EntityModifier.scheduler);
|
||||
return this;
|
||||
}
|
||||
|
||||
public org.bukkit.entity.Entity build() {
|
||||
return EntityModifier.entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -13,18 +13,14 @@ import java.util.WeakHashMap;
|
||||
/**
|
||||
* @author Crislibaer
|
||||
*/
|
||||
public class MoveEventFilter implements Listener
|
||||
{
|
||||
public static class PlayerBlockMoveEvent extends PlayerMoveEvent
|
||||
{
|
||||
public PlayerBlockMoveEvent(PlayerMoveEvent pEvent)
|
||||
{
|
||||
public class MoveEventFilter implements Listener {
|
||||
public static class PlayerBlockMoveEvent extends PlayerMoveEvent {
|
||||
public PlayerBlockMoveEvent(PlayerMoveEvent pEvent) {
|
||||
super(pEvent.getPlayer(), pEvent.getFrom(), pEvent.getTo());
|
||||
}
|
||||
}
|
||||
|
||||
private static class BlockPosition
|
||||
{
|
||||
private static class BlockPosition {
|
||||
public int x;
|
||||
public int y;
|
||||
public int z;
|
||||
@ -34,16 +30,13 @@ public class MoveEventFilter implements Listener
|
||||
private Server mServer;
|
||||
private WeakHashMap<Player, BlockPosition> mLastPosition = new WeakHashMap<>();
|
||||
|
||||
public MoveEventFilter(Server pServer)
|
||||
{
|
||||
public MoveEventFilter(Server pServer) {
|
||||
mServer = pServer;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent pEvent)
|
||||
{
|
||||
if(pEvent.isCancelled() || pEvent instanceof PlayerBlockMoveEvent)
|
||||
{
|
||||
public void onPlayerMove(PlayerMoveEvent pEvent) {
|
||||
if (pEvent.isCancelled() || pEvent instanceof PlayerBlockMoveEvent) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -51,23 +44,17 @@ public class MoveEventFilter implements Listener
|
||||
Location currentPos = pEvent.getTo();
|
||||
boolean fireEvent = false;
|
||||
|
||||
if(lastPos == null)
|
||||
{
|
||||
if (lastPos == null) {
|
||||
lastPos = new BlockPosition();
|
||||
mLastPosition.put(pEvent.getPlayer(), lastPos);
|
||||
fireEvent = true;
|
||||
}
|
||||
else if(lastPos.x != currentPos.getBlockX() || lastPos.z != currentPos.getBlockZ() || lastPos.y != currentPos.getBlockY())
|
||||
{
|
||||
} else if (lastPos.x != currentPos.getBlockX() || lastPos.z != currentPos.getBlockZ() || lastPos.y != currentPos.getBlockY()) {
|
||||
fireEvent = true;
|
||||
}
|
||||
else if(lastPos.world != currentPos.getWorld())
|
||||
{
|
||||
} else if (lastPos.world != currentPos.getWorld()) {
|
||||
fireEvent = true;
|
||||
}
|
||||
|
||||
if(fireEvent)
|
||||
{
|
||||
if (fireEvent) {
|
||||
// make sure that our event is synchronous
|
||||
assert !pEvent.isAsynchronous();
|
||||
|
||||
@ -76,8 +63,7 @@ public class MoveEventFilter implements Listener
|
||||
mServer.getPluginManager().callEvent(event);
|
||||
|
||||
// check event state and only update new position if event does not gets canceled
|
||||
if(!event.isCancelled())
|
||||
{
|
||||
if (!event.isCancelled()) {
|
||||
// update new position
|
||||
lastPos.world = currentPos.getWorld();
|
||||
lastPos.x = currentPos.getBlockX();
|
||||
|
@ -14,111 +14,92 @@ import java.lang.reflect.Method;
|
||||
import java.util.Base64;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ItemSkulls
|
||||
{
|
||||
private static Class<?> skullMetaClass;
|
||||
private static Class<?> tileEntityClass;
|
||||
private static Class<?> blockPositionClass;
|
||||
private static int mcVersion;
|
||||
public class ItemSkulls {
|
||||
private static Class<?> skullMetaClass;
|
||||
private static Class<?> tileEntityClass;
|
||||
private static Class<?> blockPositionClass;
|
||||
private static int mcVersion;
|
||||
|
||||
static
|
||||
{
|
||||
String version = org.bukkit.Bukkit.getServer().getClass().getPackage().getName()
|
||||
.split("\\.")[3];
|
||||
mcVersion = Integer.parseInt(version.replaceAll("[^0-9]", ""));
|
||||
try {
|
||||
skullMetaClass = Class.forName("org.bukkit.craftbukkit." + version +
|
||||
".inventory.CraftMetaSkull");
|
||||
tileEntityClass = Class.forName("net.minecraft.server." + version +
|
||||
".TileEntitySkull");
|
||||
if (mcVersion > 174)
|
||||
blockPositionClass = Class.forName("net.minecraft.server." +
|
||||
version + ".BlockPosition");
|
||||
else
|
||||
blockPositionClass = null;
|
||||
static {
|
||||
String version = org.bukkit.Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
mcVersion = Integer.parseInt(version.replaceAll("[^0-9]", ""));
|
||||
try {
|
||||
skullMetaClass = Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftMetaSkull");
|
||||
tileEntityClass = Class.forName("net.minecraft.server." + version + ".TileEntitySkull");
|
||||
if (mcVersion > 174)
|
||||
blockPositionClass = Class.forName("net.minecraft.server." + version + ".BlockPosition");
|
||||
else
|
||||
blockPositionClass = null;
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
public static ItemStack getSkull(String skinURL) {
|
||||
return getSkull(skinURL, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack getSkull(String skinURL)
|
||||
{
|
||||
return getSkull(skinURL, 1);
|
||||
}
|
||||
|
||||
public static ItemStack getSkull(String skinURL, int amount)
|
||||
{
|
||||
ItemStack skull = new ItemStack(Material.SKULL_ITEM, amount, (short) 3);
|
||||
SkullMeta meta = (SkullMeta)skull.getItemMeta();
|
||||
try {
|
||||
Field profileField = skullMetaClass.getDeclaredField("profile");
|
||||
profileField.setAccessible(true);
|
||||
profileField.set(meta, getProfile(skinURL));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
public static ItemStack getSkull(String skinURL, int amount) {
|
||||
ItemStack skull = new ItemStack(Material.SKULL_ITEM, amount, (short) 3);
|
||||
SkullMeta meta = (SkullMeta) skull.getItemMeta();
|
||||
try {
|
||||
Field profileField = skullMetaClass.getDeclaredField("profile");
|
||||
profileField.setAccessible(true);
|
||||
profileField.set(meta, getProfile(skinURL));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
skull.setItemMeta(meta);
|
||||
return skull;
|
||||
}
|
||||
skull.setItemMeta(meta);
|
||||
return skull;
|
||||
}
|
||||
|
||||
public static boolean setBlock(Location loc, String skinURL)
|
||||
{
|
||||
return setBlock(loc.getBlock(), skinURL);
|
||||
}
|
||||
|
||||
public static boolean setBlock(Block block, String skinURL)
|
||||
{
|
||||
boolean flag = block.getType() == Material.SKULL;
|
||||
if (!flag)
|
||||
block.setType(Material.SKULL);
|
||||
try
|
||||
{
|
||||
Object nmsWorld = block.getWorld().getClass()
|
||||
.getMethod("getHandle", new Class[0]).invoke(block.getWorld(), new Object[0]);
|
||||
Object tileEntity = null;
|
||||
|
||||
if (mcVersion <= 174) {
|
||||
Method getTileEntity = nmsWorld.getClass().getMethod(
|
||||
"getTileEntity", new Class[] { Integer.TYPE, Integer.TYPE, Integer.TYPE });
|
||||
tileEntity = tileEntityClass.cast(getTileEntity.invoke(
|
||||
nmsWorld, new Object[] { Integer.valueOf(block.getX()), Integer.valueOf(block.getY()), Integer.valueOf(block.getZ()) }));
|
||||
} else {
|
||||
Method getTileEntity = nmsWorld.getClass().getMethod(
|
||||
"getTileEntity", new Class[] { blockPositionClass });
|
||||
tileEntity = tileEntityClass.cast(getTileEntity.invoke(
|
||||
nmsWorld, new Object[] {
|
||||
getBlockPositionFor(block.getX(), block.getY(),
|
||||
block.getZ()) }));
|
||||
}
|
||||
|
||||
tileEntityClass.getMethod("setGameProfile", new Class[] { GameProfile.class })
|
||||
.invoke(tileEntity, new Object[] { getProfile(skinURL) });
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
public static boolean setBlock(Location loc, String skinURL) {
|
||||
return setBlock(loc.getBlock(), skinURL);
|
||||
}
|
||||
return !flag;
|
||||
}
|
||||
|
||||
private static GameProfile getProfile(String skinURL) {
|
||||
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
|
||||
String base64encoded = Base64.getEncoder().encodeToString(
|
||||
new String("{textures:{SKIN:{url:\"" + skinURL + "\"}}}")
|
||||
.getBytes());
|
||||
Property property = new Property("textures", base64encoded);
|
||||
profile.getProperties().put("textures", property);
|
||||
return profile;
|
||||
}
|
||||
public static boolean setBlock(Block block, String skinURL) {
|
||||
boolean flag = block.getType() == Material.SKULL;
|
||||
if (!flag)
|
||||
block.setType(Material.SKULL);
|
||||
try {
|
||||
Object nmsWorld = block.getWorld().getClass().getMethod("getHandle", new Class[0]).invoke(block.getWorld());
|
||||
Object tileEntity = null;
|
||||
|
||||
private static Object getBlockPositionFor(int x, int y, int z) {
|
||||
Object blockPosition = null;
|
||||
try {
|
||||
Constructor<?> cons = blockPositionClass.getConstructor(new Class[] { Integer.TYPE,
|
||||
Integer.TYPE, Integer.TYPE });
|
||||
blockPosition = cons.newInstance(new Object[] { Integer.valueOf(x), Integer.valueOf(y), Integer.valueOf(z) });
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
if (mcVersion <= 174) {
|
||||
Method getTileEntity = nmsWorld.getClass().getMethod("getTileEntity", Integer.TYPE, Integer.TYPE, Integer.TYPE);
|
||||
tileEntity = tileEntityClass.cast(getTileEntity.invoke(nmsWorld, block.getX(), block.getY(), block.getZ()));
|
||||
} else {
|
||||
Method getTileEntity = nmsWorld.getClass().getMethod("getTileEntity", blockPositionClass);
|
||||
tileEntity = tileEntityClass.cast(getTileEntity.invoke(
|
||||
nmsWorld, getBlockPositionFor(block.getX(), block.getY(),
|
||||
block.getZ())));
|
||||
}
|
||||
|
||||
tileEntityClass.getMethod("setGameProfile", new Class[]{GameProfile.class})
|
||||
.invoke(tileEntity, getProfile(skinURL));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return !flag;
|
||||
}
|
||||
|
||||
private static GameProfile getProfile(String skinURL) {
|
||||
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
|
||||
String base64encoded = Base64.getEncoder().encodeToString(
|
||||
("{textures:{SKIN:{url:\"" + skinURL + "\"}}}").getBytes());
|
||||
Property property = new Property("textures", base64encoded);
|
||||
profile.getProperties().put("textures", property);
|
||||
return profile;
|
||||
}
|
||||
|
||||
private static Object getBlockPositionFor(int x, int y, int z) {
|
||||
Object blockPosition = null;
|
||||
try {
|
||||
Constructor<?> cons = blockPositionClass.getConstructor(Integer.TYPE, Integer.TYPE, Integer.TYPE);
|
||||
blockPosition = cons.newInstance(x, y, z);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return blockPosition;
|
||||
}
|
||||
return blockPosition;
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package eu.univento.core.api.languages;
|
||||
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.player.Perms;
|
||||
import eu.univento.core.api.player.Ranks;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
@ -141,7 +141,7 @@ public class Language_DE implements Languages{
|
||||
}
|
||||
|
||||
@Override
|
||||
public String Core_SETRANK_SET(CustomPlayer p, Perms.Ranks rank) {
|
||||
public String Core_SETRANK_SET(CustomPlayer p, Ranks rank) {
|
||||
return "§7Du hast dem Spieler " + p.getDisplayName() + " auf §e" + rank.toString() + " §7gesetzt";
|
||||
}
|
||||
@Override
|
||||
|
@ -1,7 +1,7 @@
|
||||
package eu.univento.core.api.languages;
|
||||
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.player.Perms;
|
||||
import eu.univento.core.api.player.Ranks;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
@ -140,7 +140,7 @@ public class Language_EN implements Languages{
|
||||
}
|
||||
|
||||
@Override
|
||||
public String Core_SETRANK_SET(CustomPlayer p, Perms.Ranks rank) {
|
||||
public String Core_SETRANK_SET(CustomPlayer p, Ranks rank) {
|
||||
return "§7You gave " + p.getDisplayName() + " the rank §e" + rank.toString();
|
||||
}
|
||||
|
||||
@ -356,7 +356,7 @@ public class Language_EN implements Languages{
|
||||
|
||||
@Override
|
||||
public String LobbyItems_BUILDSERVER() {
|
||||
return "§aBuilding-Server";
|
||||
return "§aBuilding-server";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -406,7 +406,7 @@ public class Language_EN implements Languages{
|
||||
|
||||
@Override
|
||||
public String LobbyItems_PETS_REMOVE() {
|
||||
return "§6ride pet";
|
||||
return "§6remove pet";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,7 +1,7 @@
|
||||
package eu.univento.core.api.languages;
|
||||
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.player.Perms;
|
||||
import eu.univento.core.api.player.Ranks;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
@ -140,7 +140,7 @@ public class Language_IT implements Languages{
|
||||
}
|
||||
|
||||
@Override
|
||||
public String Core_SETRANK_SET(CustomPlayer p, Perms.Ranks rank) {
|
||||
public String Core_SETRANK_SET(CustomPlayer p, Ranks rank) {
|
||||
return "§7Hai dato " + p.getDisplayName() + " il gruppo §e" + rank.toString();
|
||||
}
|
||||
@Override
|
||||
|
@ -1,7 +1,7 @@
|
||||
package eu.univento.core.api.languages;
|
||||
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.player.Perms;
|
||||
import eu.univento.core.api.player.Ranks;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
@ -36,7 +36,7 @@ public interface Languages{
|
||||
String Core_SETRANK_USAGE();
|
||||
String Core_SETRANK_KICK();
|
||||
String Core_SETRANK_NO_RANK();
|
||||
String Core_SETRANK_SET(CustomPlayer p, Perms.Ranks rank);
|
||||
String Core_SETRANK_SET(CustomPlayer p, Ranks rank);
|
||||
String Core_TS_ALLREADY_VERIFIED();
|
||||
String Core_TS_VERIFIED();
|
||||
String Core_VANISH_ON();
|
||||
|
@ -1,7 +1,7 @@
|
||||
package eu.univento.core.api.languages;
|
||||
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.player.Perms;
|
||||
import eu.univento.core.api.player.Ranks;
|
||||
|
||||
|
||||
/**
|
||||
@ -109,7 +109,7 @@ public class Messages {
|
||||
public String Core_SETRANK_NO_RANK() {
|
||||
return lang.Core_SETRANK_NO_RANK();
|
||||
}
|
||||
public String Core_SETRANK_SET(CustomPlayer p, Perms.Ranks rank) {
|
||||
public String Core_SETRANK_SET(CustomPlayer p, Ranks rank) {
|
||||
return lang.Core_SETRANK_SET(p, rank);
|
||||
}
|
||||
public String Core_TS_ALLREADY_VERIFIED() {
|
||||
|
@ -11,11 +11,13 @@ public class Map {
|
||||
private String name;
|
||||
private String builder;
|
||||
private Material item;
|
||||
private String download;
|
||||
|
||||
public Map(String name, String builder, Material item) {
|
||||
public Map(String name, String builder, Material item, String download) {
|
||||
this.name = name;
|
||||
this.builder = builder;
|
||||
this.item = item;
|
||||
this.download = download;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@ -29,4 +31,8 @@ public class Map {
|
||||
public Material getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public String getDownloadLink() {
|
||||
return download;
|
||||
}
|
||||
}
|
@ -15,9 +15,9 @@ public class MapDatabase {
|
||||
public static ArrayList<Map> getAllMaps(Game game) {
|
||||
ArrayList<Map> maps = new ArrayList<>();
|
||||
|
||||
maps.add(new Map("Map1", "TeamVento", Material.GRASS));
|
||||
maps.add(new Map("Map2", "TeamVento", Material.STONE));
|
||||
maps.add(new Map("Map3", "TeamVento", Material.APPLE));
|
||||
maps.add(new Map("Map1", "TeamVento", Material.GRASS, "http://creppy.univento.eu/maps/Strive/Map1"));
|
||||
maps.add(new Map("Map2", "TeamVento", Material.STONE, "http://creppy.univento.eu/maps/Strive/Map2"));
|
||||
maps.add(new Map("Map3", "TeamVento", Material.APPLE, "http://creppy.univento.eu/maps/Strive/Map3"));
|
||||
|
||||
return maps;
|
||||
}
|
||||
|
37
src/main/java/eu/univento/core/api/map/MapDownloader.java
Normal file
37
src/main/java/eu/univento/core/api/map/MapDownloader.java
Normal file
@ -0,0 +1,37 @@
|
||||
package eu.univento.core.api.map;
|
||||
|
||||
import eu.univento.core.Core;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URL;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
*/
|
||||
public class MapDownloader {
|
||||
|
||||
public static void download(URL file, File dest) {
|
||||
try {
|
||||
InputStream is = file.openStream();
|
||||
File finaldest = new File(dest + "/" + file.getFile());
|
||||
if(!finaldest.getParentFile().mkdirs()) Core.log(Level.SEVERE, "Map Ordner konnte nicht erstellt werden");
|
||||
finaldest.createNewFile();
|
||||
OutputStream os = new FileOutputStream(finaldest);
|
||||
byte data[] = new byte[1024];
|
||||
int count;
|
||||
while ((count = is.read(data, 0, 1024)) != -1) {
|
||||
os.write(data, 0, count);
|
||||
}
|
||||
os.flush();
|
||||
is.close();
|
||||
os.close();
|
||||
} catch (Exception ec) {
|
||||
ec.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package eu.univento.core.api.map;
|
||||
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.player.Perms;
|
||||
import eu.univento.core.api.player.Ranks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -109,7 +109,7 @@ public class MapVoting implements Listener{
|
||||
}
|
||||
|
||||
public Inventory getInventory(CustomPlayer p) {
|
||||
if(p.isAllowed(Perms.Ranks.Admin)) {
|
||||
if(p.isAllowed(Ranks.Admin)) {
|
||||
Inventory inv = Bukkit.createInventory(p, 45, invTitle);
|
||||
|
||||
for(Map map : allMaps) {
|
||||
@ -164,7 +164,7 @@ public class MapVoting implements Listener{
|
||||
if(e.getWhoClicked() instanceof Player) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getWhoClicked().getName());
|
||||
if(e.getInventory().getName().equals(invTitle)) {
|
||||
if(p.isAllowed(Perms.Ranks.Admin)) {
|
||||
if(p.isAllowed(Ranks.Admin)) {
|
||||
allMaps.stream().filter(map -> e.getCurrentItem().getType() == map.getItem()).forEach(map -> {
|
||||
forcedMap = map;
|
||||
});
|
||||
|
@ -30,7 +30,7 @@ public class BanSystem{
|
||||
* @throws ClassNotFoundException class couldn't be found
|
||||
*/
|
||||
static void setBanned(CustomPlayer p, String reason, CustomPlayer who, int time)throws SQLException, ClassNotFoundException {
|
||||
int id = p.getID();
|
||||
int id = 0;
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
|
||||
@ -38,7 +38,7 @@ static void setBanned(CustomPlayer p, String reason, CustomPlayer who, int time)
|
||||
date.setTime(date.getTime() + (time * 24));
|
||||
Timestamp timestamp = new Timestamp(date.getTime());
|
||||
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("INSERT INTO bans (BID, Reason, until, BannerID) VALUES ('" + id + "', '" + reason + "', '" + who.getID() + "', '" + timestamp + "');");
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("INSERT INTO bans (BID, Reason, until, BannerID) VALUES ('" + id + "', '" + reason + "', '" + 0 + "', '" + timestamp + "');");
|
||||
st.execute();
|
||||
p.kickPlayer("§cYou have been banned. §6Reason: " + reason + "\nUntil: " + timestamp);
|
||||
who.sendMessage("§cDu hast den Spieler " + p.getColor() + p.getName() + "§c für " + time + " Tage gebannt wegen " + reason);
|
||||
@ -52,7 +52,7 @@ static void setBanned(CustomPlayer p, String reason, CustomPlayer who, int time)
|
||||
* @throws ClassNotFoundException class couldn't be found
|
||||
*/
|
||||
static void removeAllBans(CustomPlayer p) throws SQLException, ClassNotFoundException{
|
||||
int id = p.getID();
|
||||
int id = 0;
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("DELETE FROM bans WHERE ID ='" + id + "';");
|
||||
@ -68,7 +68,7 @@ static void removeAllBans(CustomPlayer p) throws SQLException, ClassNotFoundExce
|
||||
* @throws ClassNotFoundException class couldn't be found
|
||||
*/
|
||||
static boolean isBanned(CustomPlayer p) throws SQLException, ClassNotFoundException {
|
||||
int id = p.getID();
|
||||
int id = 0;
|
||||
MySQL sql = Core.returnSQL();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT * FROM bans WHERE BID='" + id + "';");
|
||||
ResultSet rs = st.executeQuery();
|
||||
@ -85,7 +85,7 @@ static boolean isBanned(CustomPlayer p) throws SQLException, ClassNotFoundExcept
|
||||
}
|
||||
|
||||
static Timestamp getBanTime(CustomPlayer p) throws SQLException {
|
||||
int id = p.getID();
|
||||
int id = 0;
|
||||
MySQL sql = Core.returnSQL();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT * FROM bans WHERE ID='" + id + "';");
|
||||
ResultSet rs = st.executeQuery();
|
||||
@ -106,7 +106,7 @@ static boolean isBanned(CustomPlayer p) throws SQLException, ClassNotFoundExcept
|
||||
* @throws ClassNotFoundException class couldn't be found
|
||||
*/
|
||||
static String getBanReason(CustomPlayer p)throws SQLException, ClassNotFoundException {
|
||||
int id = p.getID();
|
||||
int id = 0;
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT * FROM bans WHERE ID='" + id + "';");
|
||||
@ -129,7 +129,7 @@ static String getBanReason(CustomPlayer p)throws SQLException, ClassNotFoundExce
|
||||
* @throws ClassNotFoundException class couldn't be found
|
||||
*/
|
||||
static String getWhoBanned(CustomPlayer p)throws SQLException, ClassNotFoundException {
|
||||
int id = p.getID();
|
||||
int id = 0;
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
ResultSet rs = Core.returnSQL().getConnection().createStatement().executeQuery("SELECT * FROM bans WHERE ID='" + id + "';");
|
||||
|
@ -20,7 +20,7 @@ public class Coins{
|
||||
* @return coins as integer
|
||||
*/
|
||||
static int getCoins(CustomPlayer p) {
|
||||
int id = p.getID();
|
||||
int id = 0;
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
@ -44,7 +44,7 @@ public class Coins{
|
||||
* @param coins coins to set
|
||||
*/
|
||||
static void setCoins(CustomPlayer p, int coins) {
|
||||
int id = p.getID();
|
||||
int id = 0;
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -20,7 +20,7 @@ public class Experience{
|
||||
* @return experience as integer
|
||||
*/
|
||||
static int getExperience(CustomPlayer p) {
|
||||
int id = p.getID();
|
||||
int id = 0;
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
@ -44,7 +44,7 @@ public class Experience{
|
||||
* @param experience experience to set
|
||||
*/
|
||||
static void setExperience(CustomPlayer p, int experience) {
|
||||
int id = p.getID();
|
||||
int id = 0;
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
|
@ -37,7 +37,7 @@ public class Friends {
|
||||
try {
|
||||
sql.openConnection();
|
||||
ArrayList<Integer> list = new ArrayList<Integer>();
|
||||
ResultSet rs = sql.getConnection().createStatement().executeQuery("SELECT * FROM Friends WHERE Player_ID = '" + player.getID());
|
||||
ResultSet rs = sql.getConnection().createStatement().executeQuery("SELECT * FROM Friends WHERE Player_ID = '" + 0 + "';");
|
||||
while(rs.next()) {
|
||||
list.add(rs.getInt("Friend_ID"));
|
||||
}
|
||||
@ -57,7 +57,7 @@ public class Friends {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement ps = sql.getConnection().prepareStatement("INSERT INTO Friends ('Player_ID', 'Friend_ID') VALUES ('" + player.getID() + "', '" + p.getID() + "');");
|
||||
PreparedStatement ps = sql.getConnection().prepareStatement("INSERT INTO Friends ('Player_ID', 'Friend_ID') VALUES ('" + 0 + "', '" + 0 + "');");
|
||||
ps.execute();
|
||||
sql.closeConnection();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
@ -73,7 +73,7 @@ public class Friends {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement ps = sql.getConnection().prepareStatement("DELETE FROM Friends WHERE Player_ID='" + player.getID() + "' AND Friend_ID='" + p.getID() + "');");
|
||||
PreparedStatement ps = sql.getConnection().prepareStatement("DELETE FROM Friends WHERE Player_ID='" + 0 + "' AND Friend_ID='" + 0 + "');");
|
||||
ps.execute();
|
||||
sql.closeConnection();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
@ -87,7 +87,7 @@ public class Friends {
|
||||
* @return true/false
|
||||
*/
|
||||
public boolean isFriend(CustomPlayer p) {
|
||||
return getFriends().contains(p.getID());
|
||||
return getFriends().contains(0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,9 +50,9 @@ public class NickName {
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
if (nick)
|
||||
sql.getConnection().createStatement().executeUpdate("UPDATE PlayerSettings SET nick = '1' WHERE ID = '" + p.getID() + "';");
|
||||
sql.getConnection().createStatement().executeUpdate("UPDATE PlayerSettings SET nick = '1' WHERE ID = '" + 0 + "';");
|
||||
else
|
||||
sql.getConnection().createStatement().executeUpdate("UPDATE PlayerSettings SET nick = '0' WHERE ID = '" + p.getID() + "';");
|
||||
sql.getConnection().createStatement().executeUpdate("UPDATE PlayerSettings SET nick = '0' WHERE ID = '" + 0 + "';");
|
||||
sql.closeConnection();
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ public class NickName {
|
||||
static boolean isNicked(CustomPlayer p) throws SQLException, ClassNotFoundException {
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
ResultSet rs = sql.getConnection().createStatement().executeQuery("SELECT nick FROM PlayerSettings WHERE ID = '" + p.getID() + "';");
|
||||
ResultSet rs = sql.getConnection().createStatement().executeQuery("SELECT nick FROM PlayerSettings WHERE ID = '" + 0 + "';");
|
||||
if (rs.next()) {
|
||||
boolean is = rs.getInt("nick") == 1;
|
||||
sql.closeConnection();
|
||||
|
@ -1,307 +0,0 @@
|
||||
package eu.univento.core.api.player;
|
||||
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.database.MySQL;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* some permission management
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Perms{
|
||||
|
||||
private static HashMap<CustomPlayer, Ranks> ranks = new HashMap<>();
|
||||
public static HashMap<CustomPlayer, Ranks> getRanks() {
|
||||
return ranks;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the prefix of a player
|
||||
* @param r Ranks
|
||||
* @return String
|
||||
*/
|
||||
static String getPrefix(Ranks r) {
|
||||
switch(r) {
|
||||
case Admin: return "§8[§4Admin§8]§4 ";
|
||||
case SrDeveloper: return "§8[§3Dev+§8]§3 ";
|
||||
case Developer: return "§8[§3Dev§8]§3 ";
|
||||
case SrModerator: return "§8[§cSrMod§8]§c ";
|
||||
case HeadBuilder: return "§8[§aHead-Builder§8]§a ";
|
||||
case Moderator: return "§8[§cMod§8]§c ";
|
||||
case Builder: return "§8[§2Builder§8]§2 ";
|
||||
case Supporter: return "§8[§9Supporter§8]§9 ";
|
||||
case Youtuber: return "§5";
|
||||
case Premium: return "§6";
|
||||
case Player: return "§e";
|
||||
default: return "§cFehler ";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the suffix of a player
|
||||
* @param r Ranks
|
||||
* @return String
|
||||
*/
|
||||
static String getSuffix(Ranks r) {
|
||||
switch(r) {
|
||||
case Admin: return "§8 »§7 ";
|
||||
case SrDeveloper: return "§8 »§7";
|
||||
case Developer: return "§8 »§7 ";
|
||||
case SrModerator: return "§8 »§7 ";
|
||||
case HeadBuilder: return "§8 »§7 ";
|
||||
case Moderator: return "§8 »§7 ";
|
||||
case Builder: return "§8 »§7 ";
|
||||
case Supporter: return "§8 »§7 ";
|
||||
case Youtuber: return "§8 »§7 ";
|
||||
case Premium: return "§8 »§7 ";
|
||||
case Player: return "§8 »§7 ";
|
||||
default: return "§cFehler";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets color of a player
|
||||
* @param r Ranks
|
||||
* @return String
|
||||
*/
|
||||
static String getColor(Ranks r) {
|
||||
switch(r) {
|
||||
case Admin: return "§4";
|
||||
case SrDeveloper: return "§3";
|
||||
case Developer: return "§3";
|
||||
case SrModerator: return "§c";
|
||||
case HeadBuilder: return "§a";
|
||||
case Moderator: return "§c";
|
||||
case Builder: return "§2";
|
||||
case Supporter: return "§9";
|
||||
case Youtuber: return "§5";
|
||||
case Premium: return "§6";
|
||||
case Player: return "§e";
|
||||
default: return "§cFehler";
|
||||
}
|
||||
}
|
||||
|
||||
static Color getArmorColor(Ranks r) {
|
||||
switch (r) {
|
||||
case Admin: return Color.MAROON;
|
||||
case SrDeveloper: return Color.TEAL;
|
||||
case Developer: return Color.TEAL;
|
||||
case SrModerator: return Color.RED;
|
||||
case HeadBuilder: return Color.LIME;
|
||||
case Moderator: return Color.RED;
|
||||
case Builder: return Color.GREEN;
|
||||
case Supporter: return Color.PURPLE;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* contains all scoreboard ranks
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
static class Teams {
|
||||
|
||||
CustomPlayer player;
|
||||
Scoreboard board;
|
||||
|
||||
Team Admin;
|
||||
Team SrDeveloper;
|
||||
Team Developer;
|
||||
Team SrModerator;
|
||||
Team Moderator;
|
||||
Team HeadBuilder;
|
||||
Team Builder;
|
||||
Team Supporter;
|
||||
Team Youtuber;
|
||||
Team Premium;
|
||||
Team Player;
|
||||
|
||||
Teams(CustomPlayer player) {
|
||||
this.player = player;
|
||||
board = player.getScoreboard();
|
||||
Admin = board.getTeam("a");
|
||||
SrDeveloper = board.getTeam("b");
|
||||
Developer = board.getTeam("c");
|
||||
SrModerator = board.getTeam("d");
|
||||
HeadBuilder = board.getTeam("e");
|
||||
Moderator = board.getTeam("f");
|
||||
Builder = board.getTeam("g");
|
||||
Supporter = board.getTeam("h");
|
||||
Youtuber = board.getTeam("i");
|
||||
Premium = board.getTeam("j");
|
||||
Player = board.getTeam("k");
|
||||
}
|
||||
|
||||
/**
|
||||
* returns scoreboard team for rank
|
||||
* @param p CustomPlayer
|
||||
* @return Team
|
||||
*/
|
||||
static Team getTeam(CustomPlayer p) {
|
||||
Teams teams = new Teams(p);
|
||||
switch(p.getRank()) {
|
||||
case Admin: return teams.Admin;
|
||||
case SrDeveloper: return teams.SrDeveloper;
|
||||
case Developer: return teams.Developer;
|
||||
case SrModerator: return teams.SrModerator;
|
||||
case HeadBuilder: return teams.HeadBuilder;
|
||||
case Moderator: return teams.Moderator;
|
||||
case Builder: return teams.Builder;
|
||||
case Supporter: return teams.Supporter;
|
||||
case Youtuber: return teams.Youtuber;
|
||||
case Premium: return teams.Premium;
|
||||
case Player: return teams.Player;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* setup scoreboards
|
||||
*/
|
||||
public static void initScoreboard(CustomPlayer p) {
|
||||
Scoreboard board = p.getScoreboard();
|
||||
board.getTeams().forEach(Team::unregister);
|
||||
|
||||
Team Admin = board.registerNewTeam("a");
|
||||
Team SrDeveloper = board.registerNewTeam("b");
|
||||
Team Developer = board.registerNewTeam("c");
|
||||
Team SrModerator = board.registerNewTeam("d");
|
||||
Team HeadBuilder = board.registerNewTeam("e");
|
||||
Team Moderator = board.registerNewTeam("f");
|
||||
Team Builder = board.registerNewTeam("g");
|
||||
Team Supporter = board.registerNewTeam("h");
|
||||
Team Youtuber = board.registerNewTeam("i");
|
||||
Team Premium = board.registerNewTeam("j");
|
||||
Team Player = board.registerNewTeam("k");
|
||||
|
||||
Admin.setPrefix(getColor(Ranks.Admin));
|
||||
SrDeveloper.setPrefix(getColor(Ranks.SrDeveloper));
|
||||
Developer.setPrefix(getColor(Ranks.Developer));
|
||||
SrModerator.setPrefix(getColor(Ranks.SrModerator));
|
||||
HeadBuilder.setPrefix(getColor(Ranks.HeadBuilder));
|
||||
Moderator.setPrefix(getColor(Ranks.Moderator));
|
||||
Builder.setPrefix(getColor(Ranks.Builder));
|
||||
Supporter.setPrefix(getColor(Ranks.Supporter));
|
||||
Youtuber.setPrefix(getColor(Ranks.Youtuber));
|
||||
Premium.setPrefix(getColor(Ranks.Premium));
|
||||
Player.setPrefix(getColor(Ranks.Player));
|
||||
|
||||
Admin.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS);
|
||||
SrDeveloper.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS);
|
||||
Developer.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS);
|
||||
SrModerator.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS);
|
||||
HeadBuilder.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS);
|
||||
Moderator.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS);
|
||||
Builder.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS);
|
||||
Supporter.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS);
|
||||
Youtuber.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS);
|
||||
Premium.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS);
|
||||
Player.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS);
|
||||
}
|
||||
/**
|
||||
* gets Rank of player
|
||||
* @param p Player
|
||||
* @return Ranks
|
||||
* @throws ClassNotFoundException Class couldn't be found
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
*/
|
||||
static Ranks getRank(CustomPlayer p) throws ClassNotFoundException, SQLException {
|
||||
if(getRanks().get(p) != null) {
|
||||
return getRanks().get(p);
|
||||
}else {
|
||||
return getRankFresh(p);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* gets Rank of player fresh from database
|
||||
* @param p Player
|
||||
* @return Ranks
|
||||
* @throws ClassNotFoundException Class couldn't be found
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
*/
|
||||
static Ranks getRankFresh(CustomPlayer p) throws SQLException, ClassNotFoundException {
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
String uuid = p.getUniqueId().toString();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT * FROM users WHERE UUID= '" + uuid + "';");
|
||||
ResultSet rs = st.executeQuery();
|
||||
if(rs.next()) {
|
||||
String rank = rs.getString("Rank");
|
||||
sql.closeConnection();
|
||||
return Ranks.valueOf(rank);
|
||||
}else {
|
||||
sql.closeConnection();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sets rank for player
|
||||
* @param p Player
|
||||
* @param r Ranks
|
||||
* @throws ClassNotFoundException Class couldn't be found
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
*/
|
||||
static void setRank(CustomPlayer p, Ranks r) throws ClassNotFoundException, SQLException {
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("UPDATE users SET Rank='" + r.toString() + "' WHERE ID='" + p.getID() + "';");
|
||||
st.execute();
|
||||
sql.closeConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* if player is allowed to do
|
||||
* @param p Player
|
||||
* @param r Ranks
|
||||
* @return true / false
|
||||
* @throws ClassNotFoundException Class couldn't be found
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
*/
|
||||
static boolean isAllowed(CustomPlayer p, Ranks r) throws ClassNotFoundException, SQLException{
|
||||
Ranks rank;
|
||||
if(getRank(p) == null) {
|
||||
rank = getRankFresh(p);
|
||||
}else {
|
||||
rank = getRank(p);
|
||||
}
|
||||
return rank.value >= r.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* contains all ranks
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public enum Ranks{
|
||||
Admin(11),
|
||||
SrDeveloper(10),
|
||||
Developer(9),
|
||||
SrModerator(8),
|
||||
HeadBuilder(7),
|
||||
Moderator(6),
|
||||
Builder(5),
|
||||
Supporter(4),
|
||||
Youtuber(3),
|
||||
Premium(2),
|
||||
Player(1);
|
||||
|
||||
final int value;
|
||||
|
||||
Ranks(int n) {
|
||||
this.value = n;
|
||||
}
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ public class PlayerSettings {
|
||||
* @return boolean
|
||||
*/
|
||||
static boolean isSet(String what, CustomPlayer p) {
|
||||
int id = p.getID();
|
||||
int id = 0;
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
@ -53,7 +53,7 @@ public class PlayerSettings {
|
||||
* @throws SQLException SQL ServerPinger not available or throwing error
|
||||
*/
|
||||
static void set(boolean bool, String what, CustomPlayer p) throws SQLException, ClassNotFoundException {
|
||||
int id = p.getID();
|
||||
int id = 0;
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
if (bool) {
|
||||
@ -73,7 +73,7 @@ public class PlayerSettings {
|
||||
* @return String
|
||||
*/
|
||||
static String get(String what, CustomPlayer p) {
|
||||
int id = p.getID();
|
||||
int id = 0;
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
@ -98,7 +98,7 @@ public class PlayerSettings {
|
||||
* @param p CustomPlayer
|
||||
*/
|
||||
static void set(String set, String what, CustomPlayer p) {
|
||||
int id = p.getID();
|
||||
int id = 0;
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
|
21
src/main/java/eu/univento/core/api/player/Ranks.java
Normal file
21
src/main/java/eu/univento/core/api/player/Ranks.java
Normal file
@ -0,0 +1,21 @@
|
||||
package eu.univento.core.api.player;
|
||||
|
||||
public enum Ranks {
|
||||
Admin(11),
|
||||
SrDeveloper(10),
|
||||
Developer(9),
|
||||
SrModerator(8),
|
||||
HeadBuilder(7),
|
||||
Moderator(6),
|
||||
Builder(5),
|
||||
Supporter(4),
|
||||
Youtuber(3),
|
||||
Premium(2),
|
||||
Player(1);
|
||||
|
||||
final int value;
|
||||
|
||||
Ranks(int n) {
|
||||
this.value = n;
|
||||
}
|
||||
}
|
@ -36,7 +36,7 @@ public class Statistics {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT Deaths FROM " + game.toString() + "Stats WHERE ID='" + player.getID() + "');");
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT Deaths FROM " + game.toString() + "Stats WHERE ID='" + 0 + "');");
|
||||
ResultSet rs = st.executeQuery();
|
||||
int deaths = rs.getInt("Deaths");
|
||||
sql.closeConnection();
|
||||
@ -55,7 +55,7 @@ public class Statistics {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("UPDATE " + game.toString() + "Stats WHERE ID='" + player.getID() + "' SET Deaths='" + deaths +"');");
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("UPDATE " + game.toString() + "Stats WHERE ID='" + 0 + "' SET Deaths='" + deaths +"');");
|
||||
st.execute();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
@ -74,7 +74,7 @@ public class Statistics {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT Kills FROM " + game.toString() + "Stats WHERE ID='" + player.getID() + "');");
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT Kills FROM " + game.toString() + "Stats WHERE ID='" + 0 + "');");
|
||||
ResultSet rs = st.executeQuery();
|
||||
int kills = rs.getInt("Kills");
|
||||
sql.closeConnection();
|
||||
@ -93,7 +93,7 @@ public class Statistics {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("UPDATE " + game.toString() + "Stats WHERE ID='" + player.getID() + "' SET Kills='" + kills +"');");
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("UPDATE " + game.toString() + "Stats WHERE ID='" + 0 + "' SET Kills='" + kills +"');");
|
||||
st.execute();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
@ -112,7 +112,7 @@ public class Statistics {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT PlayedRounds FROM " + game.toString() + "Stats WHERE ID='" + player.getID() + "');");
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT PlayedRounds FROM " + game.toString() + "Stats WHERE ID='" + 0 + "');");
|
||||
ResultSet rs = st.executeQuery();
|
||||
int rounds = rs.getInt("PlayedRounds");
|
||||
sql.closeConnection();
|
||||
@ -131,7 +131,7 @@ public class Statistics {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("UPDATE " + game.toString() + "Stats WHERE ID='" + player.getID() + "' SET PlayedRounds='" + rounds +"');");
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("UPDATE " + game.toString() + "Stats WHERE ID='" + 0 + "' SET PlayedRounds='" + rounds +"');");
|
||||
st.execute();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
@ -150,7 +150,7 @@ public class Statistics {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT Playtime FROM " + game.toString() + "Stats WHERE ID='" + player.getID() + "');");
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT Playtime FROM " + game.toString() + "Stats WHERE ID='" + 0 + "');");
|
||||
ResultSet rs = st.executeQuery();
|
||||
int time = rs.getInt("Playtime");
|
||||
sql.closeConnection();
|
||||
@ -169,7 +169,7 @@ public class Statistics {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("UPDATE " + game.toString() + "Stats WHERE ID='" + player.getID() + "' SET Playtime='" + time +"');");
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("UPDATE " + game.toString() + "Stats WHERE ID='" + 0 + "' SET Playtime='" + time +"');");
|
||||
st.execute();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
@ -184,7 +184,7 @@ public class Statistics {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT Wins FROM " + game.toString() + "Stats WHERE ID='" + player.getID() + "');");
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT Wins FROM " + game.toString() + "Stats WHERE ID='" + 0 + "');");
|
||||
ResultSet rs = st.executeQuery();
|
||||
int wins = rs.getInt("Wins");
|
||||
sql.closeConnection();
|
||||
@ -203,7 +203,7 @@ public class Statistics {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("UPDATE " + game.toString() + "Stats WHERE ID='" + player.getID() + "' SET Wins='" + wins +"');");
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("UPDATE " + game.toString() + "Stats WHERE ID='" + 0 + "' SET Wins='" + wins +"');");
|
||||
st.execute();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -4,7 +4,7 @@ import eu.univento.core.Core;
|
||||
import eu.univento.core.api.AutoCommand;
|
||||
import eu.univento.core.api.languages.Messages;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.player.Perms.Ranks;
|
||||
import eu.univento.core.api.player.Ranks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -41,7 +41,6 @@ public class Ban extends AutoCommand<Core>{
|
||||
CustomPlayer t = CustomPlayer.getPlayer(args[0]);
|
||||
if(getReasons().containsValue(args[1])) {
|
||||
int id = getKey(args[1]);
|
||||
t.ban(getReasons().get(id), p, getBanDurations().get(id));
|
||||
}else {
|
||||
p.sendMessage(msgs.PREFIX() + msgs.Core_BAN_NO_REASON());
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import eu.univento.core.Core;
|
||||
import eu.univento.core.api.AutoCommand;
|
||||
import eu.univento.core.api.languages.Messages;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.player.Perms.Ranks;
|
||||
import eu.univento.core.api.player.Ranks;
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@ -4,7 +4,7 @@ import eu.univento.core.Core;
|
||||
import eu.univento.core.api.AutoCommand;
|
||||
import eu.univento.core.api.languages.Messages;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.player.Perms.Ranks;
|
||||
import eu.univento.core.api.player.Ranks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -4,7 +4,7 @@ import eu.univento.core.Core;
|
||||
import eu.univento.core.api.AutoCommand;
|
||||
import eu.univento.core.api.languages.Messages;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.player.Perms.Ranks;
|
||||
import eu.univento.core.api.player.Ranks;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
@ -4,7 +4,7 @@ import eu.univento.core.Core;
|
||||
import eu.univento.core.api.AutoCommand;
|
||||
import eu.univento.core.api.languages.Messages;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.player.Perms.Ranks;
|
||||
import eu.univento.core.api.player.Ranks;
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -4,7 +4,7 @@ import eu.univento.core.Core;
|
||||
import eu.univento.core.api.AutoCommand;
|
||||
import eu.univento.core.api.languages.Messages;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.player.Perms.Ranks;
|
||||
import eu.univento.core.api.player.Ranks;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -40,14 +40,14 @@ public class Nick extends AutoCommand<Core>{
|
||||
p.setDisplayName(p.getName());
|
||||
p.getTeam().addEntry(p.getDisplayName());
|
||||
p.sendMessage(msgs.PREFIX() + msgs.Core_NICK_OFF());
|
||||
p.unnick();
|
||||
//p.unnick();
|
||||
}else {
|
||||
p.getTeam().removeEntry(p.getDisplayName());
|
||||
p.setNicked(true);
|
||||
p.setDisplayName(p.getNick());
|
||||
//p.setDisplayName(p.getNick());
|
||||
p.getTeam().addEntry(p.getDisplayName());
|
||||
p.sendMessage(msgs.PREFIX() + msgs.Core_NICK_ON());
|
||||
p.nick(p.getNick());
|
||||
//p.nick(p.getNick());
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(msgs.NO_PERMS());
|
||||
|
@ -4,7 +4,7 @@ import eu.univento.core.Core;
|
||||
import eu.univento.core.api.AutoCommand;
|
||||
import eu.univento.core.api.languages.Messages;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.player.Perms.Ranks;
|
||||
import eu.univento.core.api.player.Ranks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -35,7 +35,7 @@ public class RunAs extends AutoCommand<Core>{
|
||||
if(sender instanceof Player) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(sender.getName());
|
||||
Messages msgs = new Messages(p);
|
||||
if(p.isAllowed(Ranks.Admin)) {
|
||||
if(p.isAllowed(Ranks.SrDeveloper)) {
|
||||
if(args.length >= 2) {
|
||||
CustomPlayer t = CustomPlayer.getPlayer(Bukkit.getPlayer(args[0]).getName());
|
||||
if(t != null) {
|
||||
|
@ -4,7 +4,7 @@ import eu.univento.core.Core;
|
||||
import eu.univento.core.api.AutoCommand;
|
||||
import eu.univento.core.api.languages.Messages;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.player.Perms.Ranks;
|
||||
import eu.univento.core.api.player.Ranks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -38,28 +38,35 @@ public class SetRank extends AutoCommand<Core>{
|
||||
Ranks rank = Ranks.valueOf(args[1]);
|
||||
if(rank != null) {
|
||||
if(Bukkit.getPlayer(args[0]) != null) {
|
||||
CustomPlayer player = CustomPlayer.getPlayer(Bukkit.getPlayer(args[0]));
|
||||
if(p.isAllowed(Ranks.HeadBuilder) && rank.equals(Ranks.Builder)) {
|
||||
player.setRank(rank);
|
||||
p.sendMessage(p.getMessages().PREFIX() + p.getMessages().Core_SETRANK_SET(player, player.getRank()));
|
||||
player.kickPlayer(player.getMessages().Core_SETRANK_KICK());
|
||||
}if(p.isAllowed(Ranks.SrModerator) && rank.equals(Ranks.Moderator)) {
|
||||
player.setRank(rank);
|
||||
p.sendMessage(p.getMessages().PREFIX() + p.getMessages().Core_SETRANK_SET(player, player.getRank()));
|
||||
player.kickPlayer(player.getMessages().Core_SETRANK_KICK());
|
||||
}if(p.isAllowed(Ranks.SrModerator) && rank.equals(Ranks.Supporter)) {
|
||||
player.setRank(rank);
|
||||
p.sendMessage(p.getMessages().PREFIX() + p.getMessages().Core_SETRANK_SET(player, player.getRank()));
|
||||
player.kickPlayer(player.getMessages().Core_SETRANK_KICK());
|
||||
}if(p.isAllowed(Ranks.SrDeveloper) && rank.equals(Ranks.Developer)) {
|
||||
player.setRank(rank);
|
||||
p.sendMessage(p.getMessages().PREFIX() + p.getMessages().Core_SETRANK_SET(player, player.getRank()));
|
||||
player.kickPlayer(player.getMessages().Core_SETRANK_KICK());
|
||||
CustomPlayer player = CustomPlayer.getPlayer(args[0]);
|
||||
if(player.isAllowed(rank)) {
|
||||
p.sendMessage(p.getMessages().PREFIX() + "§cDer Spieler hat den Rang schon oder ist besser.");
|
||||
p.sendMessage(p.getMessages().PREFIX() + "§cÄnderungen müssen in der Datenbank stattfinden.");
|
||||
return true;
|
||||
}
|
||||
if(p.isAllowed(Ranks.Admin)) {
|
||||
player.setRank(rank);
|
||||
p.sendMessage(p.getMessages().PREFIX() + p.getMessages().Core_SETRANK_SET(player, player.getRank()));
|
||||
player.kickPlayer(player.getMessages().Core_SETRANK_KICK());
|
||||
}
|
||||
if(p.isAllowed(Ranks.SrDeveloper) && rank.equals(Ranks.Developer)) {
|
||||
player.setRank(Ranks.Developer);
|
||||
p.sendMessage(p.getMessages().PREFIX() + p.getMessages().Core_SETRANK_SET(player, Ranks.Developer));
|
||||
player.kickPlayer(player.getMessages().Core_SETRANK_KICK());
|
||||
}
|
||||
if(p.isAllowed(Ranks.SrModerator) && rank.equals(Ranks.Moderator)) {
|
||||
player.setRank(Ranks.Moderator);
|
||||
p.sendMessage(p.getMessages().PREFIX() + p.getMessages().Core_SETRANK_SET(player, Ranks.Moderator));
|
||||
player.kickPlayer(player.getMessages().Core_SETRANK_KICK());
|
||||
}if(p.isAllowed(Ranks.SrModerator) && rank.equals(Ranks.Supporter)) {
|
||||
player.setRank(Ranks.Supporter);
|
||||
p.sendMessage(p.getMessages().PREFIX() + p.getMessages().Core_SETRANK_SET(player, Ranks.Supporter));
|
||||
player.kickPlayer(player.getMessages().Core_SETRANK_KICK());
|
||||
}
|
||||
if(p.isAllowed(Ranks.HeadBuilder) && rank.equals(Ranks.Builder)) {
|
||||
player.setRank(Ranks.Builder);
|
||||
p.sendMessage(p.getMessages().PREFIX() + p.getMessages().Core_SETRANK_SET(player, Ranks.Builder));
|
||||
player.kickPlayer(player.getMessages().Core_SETRANK_KICK());
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(p.getMessages().NOT_ONLINE(args[0]));
|
||||
|
@ -4,11 +4,13 @@ import eu.univento.core.Core;
|
||||
import eu.univento.core.api.AutoCommand;
|
||||
import eu.univento.core.api.languages.Messages;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.player.Perms.Ranks;
|
||||
import eu.univento.core.api.player.Ranks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -35,8 +37,13 @@ public class SystemInfo extends AutoCommand<Core>{
|
||||
Messages msgs = new Messages(p);
|
||||
if(p.isAllowed(Ranks.SrModerator)) {
|
||||
Runtime run = Runtime.getRuntime();
|
||||
p.sendMessage("§6§l===SystemInfo <SpigotServer>===");
|
||||
p.sendMessage("§6Spigot version: " + Bukkit.getVersion());
|
||||
p.sendMessage("§6§l===SystemInfo <" + Bukkit.getServerName() + ">===");
|
||||
try {
|
||||
p.sendMessage("§6Server: " + InetAddress.getLocalHost().getHostName());
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
p.sendMessage("§6Spigot version: " + Bukkit.getVersion());
|
||||
p.sendMessage("§6used memory: " + (run.totalMemory() - run.freeMemory() / 1048576L) + " MB");
|
||||
p.sendMessage("§6free memory: " + run.freeMemory() / 1048576L + " MB");
|
||||
p.sendMessage("§6total memory: " + run.maxMemory() / 1048576L + " MB");
|
||||
|
@ -1,65 +0,0 @@
|
||||
package eu.univento.core.commands;
|
||||
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.AutoCommand;
|
||||
import eu.univento.core.api.languages.Messages;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.twitch.Twitch_API;
|
||||
import eu.univento.core.api.twitch.Twitch_Stream;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* send info about twitch streams
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Twitch extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command command to execute
|
||||
* @param description describes the command
|
||||
* @param aliases aliases of command
|
||||
*/
|
||||
public Twitch(Core plugin, String command, String description, String... aliases) {
|
||||
super(plugin, command, description, aliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||
if(sender instanceof Player) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(sender.getName());
|
||||
Messages msgs = new Messages(p);
|
||||
if(args.length == 1) {
|
||||
Twitch_Stream stream = Twitch_API.getStream(args[0]);
|
||||
if(stream != null) {
|
||||
p.sendMessage("§a" + stream.getBroadcaster());
|
||||
p.sendMessage("§aBenutzername: " + stream.getUsername());
|
||||
p.sendMessage("§aSpiel: " + stream.getMeta_game());
|
||||
p.sendMessage("§aKategorie: " + stream.getCategory());
|
||||
p.sendMessage("§aTitel: " + stream.getTitle());
|
||||
p.sendMessage("§aStatus: " + stream.getStatus());
|
||||
p.sendMessage("§aZuschauer:" + stream.getChannel_view_count());
|
||||
p.sendMessage("§aSprachen: " + stream.getGeo());
|
||||
p.sendMessage("§aOnline seit: " + stream.getUp_time());
|
||||
}else {
|
||||
p.sendMessage(msgs.PREFIX() + "§aDen Benutzer gibt es nicht");
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(msgs.PREFIX() + "§cNutze /twitch <Name>");
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -4,7 +4,7 @@ import eu.univento.core.Core;
|
||||
import eu.univento.core.api.AutoCommand;
|
||||
import eu.univento.core.api.languages.Messages;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.player.Perms.Ranks;
|
||||
import eu.univento.core.api.player.Ranks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -2,7 +2,7 @@ package eu.univento.core.listeners;
|
||||
|
||||
import eu.univento.core.api.languages.Messages;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.player.Perms.Ranks;
|
||||
import eu.univento.core.api.player.Ranks;
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
@ -3,7 +3,7 @@ package eu.univento.core.listeners;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.languages.Messages;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.player.Perms.Ranks;
|
||||
import eu.univento.core.api.player.Ranks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -41,17 +41,12 @@ public class Commands implements Listener{
|
||||
if(p.isAllowed(Ranks.Admin)) {
|
||||
e.setCancelled(true);
|
||||
Bukkit.broadcastMessage(msgs.PREFIX() + "§cWarning ! Server will be restarted");
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Core.getInstance(), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for(Player players : Bukkit.getOnlinePlayers()) {
|
||||
players.kickPlayer("§cServer has been restarted \n §6Please join again at: \n §bplay§5.§6univento§5.§aeu");
|
||||
}
|
||||
Bukkit.getServer().spigot().restart();
|
||||
}
|
||||
|
||||
}, 100L);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Core.getInstance(), () -> {
|
||||
for(Player players : Bukkit.getOnlinePlayers()) {
|
||||
players.kickPlayer("§cServer has been restarted \n §6Please join again at: \n §bplay§5.§6univento§5.§aeu");
|
||||
}
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "/restart");
|
||||
}, 100L);
|
||||
}else {
|
||||
p.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public class Events implements Listener{
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onInventoryClick(InventoryClickEvent e) {
|
||||
Inventory inv = e.getClickedInventory();
|
||||
Inventory inv = e.getInventory();
|
||||
if(e.getWhoClicked() instanceof Player) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getWhoClicked().getName());
|
||||
if(inv.getName().equals(JoinQuit.getLanguageChooser(p).getName())) {
|
||||
|
@ -3,11 +3,8 @@ package eu.univento.core.listeners;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.Title;
|
||||
import eu.univento.core.api.Utils;
|
||||
import eu.univento.core.api.database.MySQL;
|
||||
import eu.univento.core.api.languages.Messages;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.player.NickName;
|
||||
import eu.univento.core.api.player.Perms;
|
||||
import eu.univento.core.api.player.Spectator;
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import eu.univento.core.commands.Build;
|
||||
@ -27,12 +24,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
@ -46,7 +37,6 @@ public class JoinQuit implements Listener{
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
||||
Messages msgs = new Messages(p);
|
||||
|
||||
for(Player players : Bukkit.getOnlinePlayers()) {
|
||||
CustomPlayer player = CustomPlayer.getPlayer(players);
|
||||
@ -59,24 +49,20 @@ public class JoinQuit implements Listener{
|
||||
}
|
||||
|
||||
if(!p.hasPlayedBefore()) {
|
||||
//p.insertToDatabase();
|
||||
Perms.getRanks().put(p, p.getFreshRank());
|
||||
p.insertToDatabase();
|
||||
for(int i = 0; i <= 15; i++) {
|
||||
Utils.randomFirework(p.getEyeLocation());
|
||||
}
|
||||
Title.sendTitle(p, 0, 100, 0, "§6Welcome", "§aPlease choose a language");
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Core.getInstance(), () -> p.openInventory(getLanguageChooser(p)), 100L);
|
||||
return;
|
||||
}
|
||||
//p.updateDatabaseEntry();
|
||||
Perms.getRanks().put(p, p.getFreshRank());
|
||||
Title.sendTabTitle(p, msgs.Core_TAB_TITLE() + Bukkit.getServerName() , msgs.TAB_PREFIX());
|
||||
p.updateDatabaseEntry();
|
||||
Title.sendTabTitle(p, p.getMessages().Core_TAB_TITLE() + Bukkit.getServerName() , p.getMessages().TAB_PREFIX());
|
||||
p.setGameMode(ServerSettings.getGameMode());
|
||||
p.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
|
||||
Perms.initScoreboard(p);
|
||||
|
||||
p.initScoreboard();
|
||||
if(p.isNicked()) {
|
||||
p.nick(p.getNick());
|
||||
//TODO: add nicking back in
|
||||
}
|
||||
|
||||
for(Player players : Bukkit.getOnlinePlayers()){
|
||||
@ -108,53 +94,15 @@ public class JoinQuit implements Listener{
|
||||
if(Build.getPlayers().containsKey(p))
|
||||
Build.getPlayers().remove(p);
|
||||
if(ServerSettings.isGame()) {
|
||||
p.setNicked(false);
|
||||
p.setDisplayName(p.getName());
|
||||
p.unnick();
|
||||
NickName.remove(p);
|
||||
}
|
||||
for(Team team : p.getScoreboard().getTeams()) {
|
||||
team.removeEntry(p.getDisplayName());
|
||||
}
|
||||
Perms.getRanks().remove(p);
|
||||
p.onLeave();
|
||||
}
|
||||
|
||||
/**
|
||||
* creates player in database
|
||||
* @param p CustomPlayer
|
||||
*/
|
||||
void createPlayer(CustomPlayer p) {
|
||||
MySQL sql = Core.returnSQL();
|
||||
Date date = new Date();
|
||||
Timestamp time = new Timestamp(date.getTime());
|
||||
String uuid = p.getUniqueId().toString();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT UUID FROM users WHERE UUID ='" + uuid + "'");
|
||||
ResultSet res = st.executeQuery();
|
||||
if (!res.next()){
|
||||
PreparedStatement st2 = sql.getConnection().prepareStatement("INSERT INTO users (UUID, FirstJoin, Rank, Coins) VALUES ('" + uuid + "','" + time + "', '" + Perms.Ranks.Player.toString() + "', 0);");
|
||||
st2.execute();
|
||||
|
||||
int id = p.getID();
|
||||
|
||||
PreparedStatement st3 = sql.getConnection().prepareStatement("INSERT INTO PlayerSettings (ID, teleport, FastMenu, requestsParty, requestsFriend, joined, nick) VALUES ('" + id +"', '1', '0', '1', '1', '0', '0',);");
|
||||
st3.execute();
|
||||
|
||||
PreparedStatement st4 = sql.getConnection().prepareStatement("INSERT INTO FoundItems(ID, music_3, sugar, feather, hearts) VALUES ('" + id + "',0, 0, 0, 0);");
|
||||
st4.execute();
|
||||
|
||||
sql.closeConnection();
|
||||
return;
|
||||
}
|
||||
sql.closeConnection();
|
||||
}
|
||||
catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Handles KickMessage
|
||||
@ -162,9 +110,7 @@ public class JoinQuit implements Listener{
|
||||
*/
|
||||
@EventHandler(priority=EventPriority.HIGHEST)
|
||||
public void onKick(PlayerKickEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
||||
e.setLeaveMessage(null);
|
||||
p.setNicked(false);
|
||||
}
|
||||
|
||||
static Inventory getLanguageChooser(CustomPlayer p) {
|
||||
|
Loading…
Reference in New Issue
Block a user