development mit master zusammengeführt
This commit is contained in:
commit
0304f59ef6
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/src/test/java" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</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" />
|
||||
</component>
|
||||
</module>
|
|
@ -0,0 +1,101 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>eu.univento</groupId>
|
||||
<artifactId>Core</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Univento.eu Core System</name>
|
||||
<url>http://univento.eu</url>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.2-beta-5</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>eu.univento.core.Core</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.mongodb</groupId>
|
||||
<artifactId>mongo-java-driver</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mongodb</groupId>
|
||||
<artifactId>mongodb-driver-async</artifactId>
|
||||
<version>3.2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
<version>4.0.31.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.9-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.9-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>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -1,159 +0,0 @@
|
|||
package eu.univento.core;
|
||||
|
||||
import eu.univento.core.api.BossBar;
|
||||
import eu.univento.core.api.Config;
|
||||
import eu.univento.core.api.SignInput;
|
||||
import eu.univento.core.api.database.MySQL;
|
||||
import eu.univento.core.api.events.MoveEventFilter;
|
||||
import eu.univento.core.api.fakeplayer.PlayerKi;
|
||||
import eu.univento.core.api.player.TeamSpeak;
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import eu.univento.core.commands.*;
|
||||
import eu.univento.core.listeners.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* main class
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Core extends JavaPlugin{
|
||||
|
||||
//TODO: rewrite time critical database functions from MySQL to MongoDB
|
||||
|
||||
/**
|
||||
* plugin instance
|
||||
*/
|
||||
public static Core instance;
|
||||
/**
|
||||
* @return plugin instance
|
||||
*/
|
||||
public static Core getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* mysql stuff
|
||||
*/
|
||||
private static MySQL sql = new MySQL(getInstance(), Config.readString("MySQL.Host"), Config.readString("MySQL.Port"), Config.readString("MySQL.DB"), Config.readString("MySQL.User"), Config.readString("MySQL.Pass"));
|
||||
/**
|
||||
* @return sql
|
||||
*/
|
||||
public static MySQL returnSQL() {
|
||||
return sql;
|
||||
}
|
||||
|
||||
private static TeamSpeak ts;
|
||||
|
||||
public static TeamSpeak getTs() {
|
||||
return ts;
|
||||
}
|
||||
/**
|
||||
* logging and stuff
|
||||
*/
|
||||
private static Logger log = Bukkit.getLogger();
|
||||
|
||||
/**
|
||||
* @param level Log level
|
||||
* @param string String
|
||||
*/
|
||||
public static void log(Level level, String string) {
|
||||
if(ServerSettings.isDebug()) {
|
||||
log.log(level, "[Core] " + string);
|
||||
}
|
||||
}
|
||||
|
||||
private SignInput signInput;
|
||||
|
||||
public SignInput getSignInput() {
|
||||
return signInput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
ServerSettings.setDebug(true);
|
||||
try {
|
||||
Config.writeDefault();
|
||||
} catch (ClassNotFoundException | SQLException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
instance = this;
|
||||
this.signInput = new SignInput(this);
|
||||
if(ServerSettings.isDebug()) log(Level.INFO, "Debug Modus aktiviert");
|
||||
PluginManager pm = Bukkit.getPluginManager();
|
||||
pm.registerEvents(new Commands(), this);
|
||||
pm.registerEvents(new JoinQuit(), this);
|
||||
pm.registerEvents(new Chat(), this);
|
||||
pm.registerEvents(new Blocks(), this);
|
||||
pm.registerEvents(new Events(), this);
|
||||
pm.registerEvents(new MoveEventFilter(getServer()), this);
|
||||
pm.registerEvents(new BossBar(), this);
|
||||
pm.registerEvents(new PlayerKi(), this);
|
||||
|
||||
log(Level.INFO, "Events registriert");
|
||||
|
||||
String[] fix = {""};
|
||||
if(ServerSettings.isGame()) new Fix(this, "fix", "Fixe dich oder andere Spieler", fix);
|
||||
|
||||
String[] runas = {""};
|
||||
new RunAs(this, "RunAs", "Sende einen Befehl als ein anderer Spieler", runas);
|
||||
|
||||
String[] systeminfo = {""};
|
||||
new SystemInfo(this, "SystemInfo", "Gibt Infos über den ServerPinger aus", systeminfo);
|
||||
|
||||
String[] vanish = {""};
|
||||
new Vanish(this, "vanish", "Lässt dich verschwinden", vanish);
|
||||
|
||||
String[] gamemode = {"gm"};
|
||||
new GameMode(this, "gamemode" , "Setzt deinen GameMode", gamemode);
|
||||
|
||||
String[] setrank = {"sr"};
|
||||
new SetRank(this, "setrank" , "Setzt den Rang eines Spielers", setrank);
|
||||
|
||||
String[] globalmute = {"globalmute"};
|
||||
new GlobalMute(this, "globalmute", "Muted den gesamten ServerPinger", globalmute);
|
||||
|
||||
String[] youtuber = {""};
|
||||
new Youtuber(this, "youtuber", "setzt Spieler in den Youtuber Rang", youtuber);
|
||||
|
||||
String[] ts = {""};
|
||||
new TS(this, "ts", "verifiziert Spieler auf dem TS", ts);
|
||||
|
||||
String[] ban = {""};
|
||||
new Ban(this, "ban", "Bannt Spieler", ban);
|
||||
|
||||
String[] build = {"b"};
|
||||
new Build(this, "build", "Setzt den Spieler in den Bau Modus", build);
|
||||
|
||||
String[] chatclear = {"cc"};
|
||||
new ChatClear(this, "chatclear", "Cleart den Chat", chatclear);
|
||||
|
||||
if(ServerSettings.isGame()) {
|
||||
String[] nick = {""};
|
||||
new Nick(this, "nick", "ändert das Verhalten des Nicksystems", nick);
|
||||
log(Level.INFO, "/nick aktiviert");
|
||||
}
|
||||
|
||||
log(Level.INFO, "Alle Befehle registriert");
|
||||
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
||||
|
||||
this.ts = new TeamSpeak();
|
||||
|
||||
log(Level.INFO, "Plugin ver. " + getDescription().getVersion() + " gestartet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
log(Level.INFO, "Plugin beendet");
|
||||
getTs().disconnect();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,301 +0,0 @@
|
|||
package eu.univento.core.api;
|
||||
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.utils.FDragon;
|
||||
import eu.univento.core.api.utils.FWither;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* Thanks for chasechocolate and BigTeddy98 for the tutorial
|
||||
* it is based on the code by them and some other tutorial
|
||||
* https://forums.bukkit.org/threads/util-set-a-players-boss-bar-nms.245073/
|
||||
* https://forums.bukkit.org/threads/tutorial-utilizing-the-boss-health-bar.158018/
|
||||
* @author Marzouki Ghofrane , mgone CraftZone.fr
|
||||
*/
|
||||
|
||||
|
||||
public class BossBar implements Listener {
|
||||
|
||||
|
||||
public static Plugin plugin;
|
||||
public static Map<Player, String> playerdragonbartask = new HashMap<>();
|
||||
public static Map<Player, Float> healthdragonbartask = new HashMap<>();
|
||||
public static Map<Player, Integer> cooldownsdragonbar= new HashMap<>();
|
||||
public static Map<Player, Integer> starttimerdragonbar= new HashMap<>();
|
||||
|
||||
public static Map<Player, String> playerwitherbartask = new HashMap<>();
|
||||
public static Map<Player, Float> healthwitherbartask = new HashMap<>();
|
||||
public static Map<Player, Integer> cooldownswitherbar= new HashMap<>();
|
||||
public static Map<Player, Integer> starttimerwitherbar= new HashMap<>();
|
||||
|
||||
public void DragonBarTask() {
|
||||
|
||||
new BukkitRunnable() {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void run() {
|
||||
for(Player p : plugin.getServer().getOnlinePlayers()){
|
||||
|
||||
if(!cooldownsdragonbar.containsKey(p)) {
|
||||
|
||||
if(playerdragonbartask.containsKey(p) && !healthdragonbartask.containsKey(p)) { setBarDragon(p, playerdragonbartask.get(p)); }
|
||||
else if(playerdragonbartask.containsKey(p) && healthdragonbartask.containsKey(p)) { setBarDragonHealth(p, playerdragonbartask.get(p), healthdragonbartask.get(p)); }
|
||||
|
||||
}
|
||||
|
||||
if(!cooldownswitherbar.containsKey(p)) {
|
||||
|
||||
if(playerwitherbartask.containsKey(p) && !healthwitherbartask.containsKey(p)) { setBarWither(p, playerwitherbartask.get(p)); }
|
||||
else if(playerwitherbartask.containsKey(p) && healthwitherbartask.containsKey(p)) { setBarWitherHealth(p, playerwitherbartask.get(p), healthwitherbartask.get(p)); }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(Core.getInstance(), 0, 40);
|
||||
|
||||
|
||||
|
||||
|
||||
new BukkitRunnable() {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void run() {
|
||||
for(Player p : plugin.getServer().getOnlinePlayers()){
|
||||
|
||||
if(cooldownsdragonbar.containsKey(p)) {
|
||||
|
||||
if(cooldownsdragonbar.get(p) > 0)
|
||||
{ cooldownsdragonbar.put(p,cooldownsdragonbar.get(p)-1); setBarDragonTimer(p, playerdragonbartask.get(p), cooldownsdragonbar.get(p)); }
|
||||
else removeBarDragon(p);
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(cooldownswitherbar.containsKey(p)) {
|
||||
|
||||
if(cooldownswitherbar.get(p) > 0)
|
||||
{ cooldownswitherbar.put(p,cooldownswitherbar.get(p)-1); setBarWitherTimer(p, playerwitherbartask.get(p), cooldownswitherbar.get(p)); }
|
||||
else removeBarWither(p);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(Core.getInstance(), 0, 20);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void PlayerQuit(PlayerQuitEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
removeBar(p);
|
||||
FDragon.removehorligneD(p);
|
||||
FWither.removehorligneW(p);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void PlayerKick(PlayerKickEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
removeBar(p);
|
||||
FDragon.removehorligneD(p);
|
||||
FWither.removehorligneW(p);
|
||||
}
|
||||
|
||||
|
||||
//dragon
|
||||
|
||||
|
||||
|
||||
public static void setBarDragon(Player p, String text) {
|
||||
playerdragonbartask.put(p, text);
|
||||
FDragon.setBossBartext(p, text);
|
||||
}
|
||||
|
||||
|
||||
public static void setBarDragonHealth(Player p, String text, float health) {
|
||||
if(health<=0 || health >100) { health = 100; text = "health must be between 1 and 100 it's a %";}
|
||||
playerdragonbartask.put(p, text);
|
||||
healthdragonbartask.put(p, (health/100)*200);
|
||||
FDragon.setBossBar(p, text, health);
|
||||
}
|
||||
|
||||
public static void setBarDragonTimer(Player p, String text, int timer) {
|
||||
playerdragonbartask.put(p, text);
|
||||
cooldownsdragonbar.put(p, timer);
|
||||
if(!starttimerdragonbar.containsKey(p)) starttimerdragonbar.put(p, timer);
|
||||
int unite = Math.round(200/starttimerdragonbar.get(p));
|
||||
FDragon.setBossBar(p, text, unite*timer);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void removeBarDragon(Player p) {
|
||||
playerdragonbartask.remove(p);
|
||||
healthdragonbartask.remove(p);
|
||||
cooldownsdragonbar.remove(p);
|
||||
starttimerdragonbar.remove(p);
|
||||
FDragon.removeBossBar(p);
|
||||
}
|
||||
|
||||
public static boolean hasBarDragon(Player p) {
|
||||
return playerdragonbartask.get(p) != null;
|
||||
}
|
||||
|
||||
|
||||
public static String getMessageDragon(Player p) {
|
||||
if(playerdragonbartask.containsKey(p)) return playerdragonbartask.get(p);
|
||||
else return " ";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//wither
|
||||
|
||||
public static void setBarWither(Player p, String text) {
|
||||
playerwitherbartask.put(p, text);
|
||||
FWither.setBossBartext(p, text);
|
||||
}
|
||||
|
||||
|
||||
public static void setBarWitherHealth(Player p, String text, float health) {
|
||||
if(health<=0 || health >100) { health = 100; text = "health must be between 1 and 100 it's a %";}
|
||||
playerwitherbartask.put(p, text);
|
||||
healthwitherbartask.put(p, (health/100)*300);
|
||||
FWither.setBossBar(p, text, health);
|
||||
}
|
||||
|
||||
public static void setBarWitherTimer(Player p, String text, int timer) {
|
||||
playerwitherbartask.put(p, text);
|
||||
cooldownswitherbar.put(p, timer);
|
||||
if(!starttimerwitherbar.containsKey(p)) starttimerwitherbar.put(p, timer);
|
||||
int unite = Math.round(300/starttimerwitherbar.get(p));
|
||||
FWither.setBossBar(p, text, unite*timer);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void removeBarWither(Player p) {
|
||||
playerwitherbartask.remove(p);
|
||||
healthwitherbartask.remove(p);
|
||||
cooldownswitherbar.remove(p);
|
||||
starttimerwitherbar.remove(p);
|
||||
FWither.removeBossBar(p);
|
||||
}
|
||||
|
||||
public static boolean hasBarWither(Player p) {
|
||||
return playerwitherbartask.get(p) != null;
|
||||
}
|
||||
|
||||
|
||||
public static String getMessageWither(Player p) {
|
||||
if(playerwitherbartask.containsKey(p)) return playerwitherbartask.get(p);
|
||||
else return " ";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//both
|
||||
|
||||
public static void setBar(Player p, String text) {
|
||||
if(McVersion(p)) {
|
||||
playerwitherbartask.put(p, text);
|
||||
FWither.setBossBartext(p, text); }
|
||||
|
||||
playerdragonbartask.put(p, text);
|
||||
FDragon.setBossBartext(p, text);
|
||||
}
|
||||
|
||||
|
||||
public static void setBarHealth(Player p, String text, float health) {
|
||||
if(health<=0 || health >100) { health = 100; text = "health must be between 1 and 100 it's a %";}
|
||||
if(McVersion(p)) {
|
||||
playerwitherbartask.put(p, text);
|
||||
healthwitherbartask.put(p, (health/100)*300);
|
||||
FWither.setBossBar(p, text, health); }
|
||||
|
||||
playerdragonbartask.put(p, text);
|
||||
healthdragonbartask.put(p, (health/100)*200);
|
||||
FDragon.setBossBar(p, text, health);
|
||||
}
|
||||
|
||||
public static void setBarTimer(Player p, String text, int timer) {
|
||||
if(McVersion(p)) {
|
||||
playerwitherbartask.put(p, text);
|
||||
cooldownswitherbar.put(p, timer);
|
||||
if(!starttimerwitherbar.containsKey(p)) starttimerwitherbar.put(p, timer);
|
||||
int unite = Math.round(300/starttimerwitherbar.get(p));
|
||||
FWither.setBossBar(p, text, unite*timer); }
|
||||
|
||||
playerdragonbartask.put(p, text);
|
||||
cooldownsdragonbar.put(p, timer);
|
||||
if(!starttimerdragonbar.containsKey(p)) starttimerdragonbar.put(p, timer);
|
||||
int unite1 = Math.round(200/starttimerdragonbar.get(p));
|
||||
FDragon.setBossBar(p, text, unite1*timer);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void removeBar(Player p) {
|
||||
if(McVersion(p)) {
|
||||
playerwitherbartask.remove(p);
|
||||
healthwitherbartask.remove(p);
|
||||
cooldownswitherbar.remove(p);
|
||||
starttimerwitherbar.remove(p);
|
||||
FWither.removeBossBar(p); }
|
||||
|
||||
playerdragonbartask.remove(p);
|
||||
healthdragonbartask.remove(p);
|
||||
cooldownsdragonbar.remove(p);
|
||||
starttimerdragonbar.remove(p);
|
||||
FDragon.removeBossBar(p);
|
||||
}
|
||||
|
||||
public static boolean hasBar(Player p) {
|
||||
|
||||
if(McVersion(p)) {
|
||||
|
||||
if(playerwitherbartask.containsKey(p) && playerdragonbartask.containsKey(p))
|
||||
return true;
|
||||
else return false; }
|
||||
|
||||
|
||||
else {
|
||||
|
||||
return playerdragonbartask.get(p) != null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String getMessage(Player p) {
|
||||
if(playerdragonbartask.containsKey(p)) return playerdragonbartask.get(p);
|
||||
else return " ";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static boolean McVersion(Player p) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,149 +0,0 @@
|
|||
package eu.univento.core.api;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
public class Hologram
|
||||
{
|
||||
private List<String> lines;
|
||||
private Location loc;
|
||||
private static final double ABS = 0.23D;
|
||||
private static String path = Bukkit.getServer().getClass().getPackage().getName();
|
||||
private static String version = path.substring(path.lastIndexOf(".") + 1, path.length());
|
||||
private static Class<?> armorStand;
|
||||
private static Class<?> worldClass;
|
||||
private static Class<?> nmsEntity;
|
||||
private static Class<?> craftWorld;
|
||||
private static Class<?> packetClass;
|
||||
private static Class<?> entityLivingClass;
|
||||
private static Constructor<?> armorStandConstructor;
|
||||
private static Class<?> nmsPacket;
|
||||
|
||||
static
|
||||
{
|
||||
try
|
||||
{
|
||||
armorStand = Class.forName("net.minecraft.server." + version +
|
||||
".EntityArmorStand");
|
||||
worldClass = Class.forName("net.minecraft.server." + version +
|
||||
".World");
|
||||
nmsEntity = Class.forName("net.minecraft.server." + version +
|
||||
".Entity");
|
||||
craftWorld = Class.forName("org.bukkit.craftbukkit." + version +
|
||||
".CraftWorld");
|
||||
packetClass = Class.forName("net.minecraft.server." + version +
|
||||
".PacketPlayOutSpawnEntityLiving");
|
||||
entityLivingClass = Class.forName("net.minecraft.server." + version +
|
||||
".EntityLiving");
|
||||
armorStandConstructor = armorStand
|
||||
.getConstructor(new Class[] { worldClass });
|
||||
|
||||
nmsPacket = Class.forName("net.minecraft.server." + version +
|
||||
".Packet");
|
||||
}
|
||||
catch (java.lang.NoSuchMethodException ex) {
|
||||
System.err.println("Error - Classes not initialized!");
|
||||
ex.printStackTrace();
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Hologram(Location loc, List<String> lines) {
|
||||
this.lines = lines;
|
||||
this.loc = loc;
|
||||
}
|
||||
|
||||
public boolean display(Player p)
|
||||
{
|
||||
Location displayLoc = this.loc.clone().add(0.0D, 0.23D * this.lines.size() - 1.97D,
|
||||
0.0D);
|
||||
for (int i = 0; i < this.lines.size(); i++) {
|
||||
Object packet = null;
|
||||
try {
|
||||
packet = getPacket(this.loc.getWorld(),
|
||||
displayLoc.getX(), displayLoc.getY(), displayLoc.getZ(),
|
||||
this.lines.get(i));
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (packet == null)
|
||||
return false;
|
||||
sendPacket(p, packet);
|
||||
displayLoc.add(0.0D, -0.23D, 0.0D);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private Object getPacket(World w, double x, double y, double z, String text) throws NoSuchMethodException {
|
||||
try {
|
||||
Object craftWorldObj = craftWorld.cast(w);
|
||||
Method getHandleMethod = craftWorldObj.getClass().getMethod(
|
||||
"getHandle", new Class[0]);
|
||||
Object entityObject = armorStandConstructor
|
||||
.newInstance(new Object[] { getHandleMethod
|
||||
.invoke(craftWorldObj, new Object[0]) });
|
||||
Method setCustomName = entityObject.getClass().getMethod(
|
||||
"setCustomName", new Class[] { String.class });
|
||||
setCustomName.invoke(entityObject, new Object[] { text });
|
||||
Method setCustomNameVisible = nmsEntity.getMethod(
|
||||
"setCustomNameVisible", new Class[] { Boolean.TYPE });
|
||||
setCustomNameVisible.invoke(entityObject, new Object[] { Boolean.valueOf(true) });
|
||||
Method setGravity = entityObject.getClass().getMethod("setGravity",
|
||||
new Class[] { Boolean.TYPE });
|
||||
setGravity.invoke(entityObject, new Object[] { Boolean.valueOf(false) });
|
||||
Method setLocation = entityObject.getClass().getMethod(
|
||||
"setLocation",
|
||||
new Class[] { Double.TYPE, Double.TYPE, Double.TYPE,
|
||||
Float.TYPE, Float.TYPE });
|
||||
setLocation.invoke(entityObject,
|
||||
new Object[] { Double.valueOf(x), Double.valueOf(y), Double.valueOf(z), Float.valueOf(0.0F), Float.valueOf(0.0F) });
|
||||
Method setInvisible = entityObject.getClass().getMethod(
|
||||
"setInvisible", new Class[] { Boolean.TYPE });
|
||||
setInvisible.invoke(entityObject, new Object[] { Boolean.valueOf(true) });
|
||||
Constructor<?> cw = packetClass
|
||||
.getConstructor(new Class[] { entityLivingClass });
|
||||
Object packetObject = cw.newInstance(new Object[] { entityObject });
|
||||
return packetObject;
|
||||
}
|
||||
catch (java.lang.SecurityException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void sendPacket(Player p, Object packet) {
|
||||
try {
|
||||
Method getHandle = p.getClass().getMethod("getHandle", new Class[0]);
|
||||
Object entityPlayer = getHandle.invoke(p, new Object[0]);
|
||||
Object pConnection = entityPlayer.getClass()
|
||||
.getField("playerConnection").get(entityPlayer);
|
||||
Method sendMethod = pConnection.getClass().getMethod("sendPacket",
|
||||
new Class[] { nmsPacket });
|
||||
sendMethod.invoke(pConnection, new Object[] { packet });
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static double getAbs() {
|
||||
return ABS;
|
||||
}
|
||||
}
|
|
@ -1,147 +0,0 @@
|
|||
package eu.univento.core.api;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
|
||||
/**
|
||||
* @author Janhektor This class in licensed under GPLv3 For more information
|
||||
* look at http://www.gnu.org/licenses/gpl-3.0
|
||||
*/
|
||||
public final class SignInput implements Listener, Runnable {
|
||||
|
||||
private final static String VERSION;
|
||||
|
||||
static {
|
||||
String path = Bukkit.getServer().getClass().getPackage().getName();
|
||||
VERSION = path.substring(path.lastIndexOf(".") + 1, path.length());
|
||||
}
|
||||
|
||||
private final Plugin plugin;
|
||||
private final Map<UUID, Consumer<String[]>> inputResults;
|
||||
|
||||
public SignInput(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.inputResults = new HashMap<UUID, Consumer<String[]>>();
|
||||
Bukkit.getScheduler().runTaskTimer(this.plugin, this, 0L, 20 * 3L);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to read the SignInput from a player The accept()-method
|
||||
* of your consumer will be called, when the player close the sign
|
||||
*
|
||||
* @return boolean successful
|
||||
* @param p
|
||||
* - The Player, who have to type an input
|
||||
* @param result
|
||||
* - The consumer (String[]) for the result; String[] contains
|
||||
* strings for 4 lines
|
||||
*/
|
||||
public boolean readInput(Player p, Consumer<String[]> result) {
|
||||
inputResults.put(p.getUniqueId(), result);
|
||||
try {
|
||||
Class<?> packetClass = Class.forName(getNMSClass("PacketPlayOutOpenSignEditor"));
|
||||
Class<?> blockPositionClass = Class.forName(getNMSClass("BlockPosition"));
|
||||
Constructor<?> blockPosCon = blockPositionClass
|
||||
.getConstructor(new Class[] { int.class, int.class, int.class });
|
||||
Object blockPosition = blockPosCon.newInstance(new Object[] { 0, 0, 0 });
|
||||
Constructor<?> packetCon = packetClass.getConstructor(new Class[] { blockPositionClass });
|
||||
Object packet = packetCon.newInstance(new Object[] { blockPosition });
|
||||
|
||||
Method getHandle = p.getClass().getMethod("getHandle");
|
||||
Object nmsPlayer = getHandle.invoke(p);
|
||||
Field pConnectionField = nmsPlayer.getClass().getField("playerConnection");
|
||||
Object pConnection = pConnectionField.get(nmsPlayer);
|
||||
Method sendMethod = pConnection.getClass().getMethod("sendPacket",
|
||||
new Class[] { Class.forName(getNMSClass("Packet")) });
|
||||
sendMethod.invoke(pConnection, new Object[] { packet });
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* Garbage Collection */
|
||||
@Override
|
||||
public void run() {
|
||||
for (UUID uuid : inputResults.keySet()) {
|
||||
if (Bukkit.getPlayer(uuid) == null)
|
||||
inputResults.remove(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
/* Events */
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
getNettyChannel(p).pipeline().addAfter("decoder", "signListener", new MessageToMessageDecoder<Object>() {
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext chc, Object packet, List<Object> packetList) throws Exception {
|
||||
if (instanceOf(packet, getNMSClass("PacketPlayInUpdateSign"))) {
|
||||
Method bMethod = packet.getClass().getMethod("b");
|
||||
Object chatBaseComponents = bMethod.invoke(packet);
|
||||
String[] lines = new String[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Object chatComponent = Array.get(chatBaseComponents, i);
|
||||
Method getText = chatComponent.getClass().getMethod("getText");
|
||||
lines[i] = (String) getText.invoke(chatComponent);
|
||||
}
|
||||
if (inputResults.containsKey(p.getUniqueId())) {
|
||||
inputResults.get(p.getUniqueId()).accept(lines);
|
||||
inputResults.remove(p.getUniqueId());
|
||||
}
|
||||
}
|
||||
packetList.add(packet);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* Util Methods */
|
||||
private Channel getNettyChannel(Player p) {
|
||||
Channel ch = null;
|
||||
try {
|
||||
Method getHandle = p.getClass().getMethod("getHandle");
|
||||
Object nmsPlayer = getHandle.invoke(p);
|
||||
Field pConnectionField = nmsPlayer.getClass().getField("playerConnection");
|
||||
Object pConnection = pConnectionField.get(nmsPlayer);
|
||||
Field networkManagerField = pConnection.getClass().getField("networkManager");
|
||||
Object networkManager = networkManagerField.get(pConnection);
|
||||
ch = (Channel) networkManager.getClass().getField("k").get(networkManager);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
|
||||
private boolean instanceOf(Object o, String className) {
|
||||
try {
|
||||
return Class.forName(className).isInstance(o);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String getNMSClass(String className) {
|
||||
return "net.minecraft.server." + VERSION + "." + className;
|
||||
}
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
package eu.univento.core.api.map;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/**
|
||||
* @author RainyCrafter
|
||||
*/
|
||||
public class Region {
|
||||
|
||||
World w;
|
||||
|
||||
int minx;
|
||||
int miny;
|
||||
int minz;
|
||||
|
||||
int maxx;
|
||||
int maxy;
|
||||
int maxz;
|
||||
|
||||
String name;
|
||||
|
||||
|
||||
|
||||
public Region(Location loc1, Location loc2, String name) {
|
||||
|
||||
w = loc1.getWorld();
|
||||
|
||||
this.name = name;
|
||||
|
||||
minx = Math.min(loc1.getBlockX(), loc2.getBlockX());
|
||||
miny = Math.min(loc1.getBlockY(), loc2.getBlockY());
|
||||
minz = Math.min(loc1.getBlockZ(), loc2.getBlockZ());
|
||||
|
||||
maxx = Math.max(loc1.getBlockX(), loc2.getBlockX());
|
||||
maxy = Math.max(loc1.getBlockY(), loc2.getBlockY());
|
||||
maxz = Math.max(loc1.getBlockZ(), loc2.getBlockZ());
|
||||
|
||||
|
||||
|
||||
}
|
||||
public void save(){
|
||||
File file = new File("plugins/Core/regions.yml");
|
||||
FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
cfg.set(name+".W", w.getName());
|
||||
|
||||
cfg.set(name+".Min.X", minx);
|
||||
cfg.set(name+".Min.Y", miny);
|
||||
cfg.set(name+".Min.Z", minz);
|
||||
|
||||
cfg.set(name+".Max.X", maxx);
|
||||
cfg.set(name+".Max.Y", maxy);
|
||||
cfg.set(name+".Max.Z", maxz);
|
||||
|
||||
try {
|
||||
cfg.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public boolean between(int w1, int zw, int w2){
|
||||
if(zw >= w1 && zw <= w2){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isInside(Location loc) {
|
||||
if (loc.getWorld() != w) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (between(minx, loc.getBlockX(), maxx) && between(miny, loc.getBlockY(), maxy) && between(minz, loc.getBlockZ(), maxz)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package eu.univento.core.api.map;
|
||||
|
||||
import ch.spacebase.opennbt.stream.NBTInputStream;
|
||||
import ch.spacebase.opennbt.tag.*;
|
||||
import eu.univento.core.api.map.Constants.MinecraftSchematicTagNames;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author James
|
||||
*/
|
||||
public class Schematic {
|
||||
|
||||
private CompoundTag _baseTag;
|
||||
private ShortTag _width;
|
||||
private ShortTag _length;
|
||||
private ShortTag _height;
|
||||
private StringTag _materials;
|
||||
private ByteArrayTag _blocks;
|
||||
private ByteArrayTag _blockData;
|
||||
private List<CompoundTag> _entities;
|
||||
private List<CompoundTag> _tileEntities;
|
||||
|
||||
public Schematic(File schematicFile) {
|
||||
_baseTag = getSchematicTagFromNBTFile(schematicFile);
|
||||
|
||||
_width = (ShortTag) _baseTag.get(MinecraftSchematicTagNames.WIDTH);
|
||||
_length = (ShortTag) _baseTag.get(MinecraftSchematicTagNames.LENGTH);
|
||||
_height = (ShortTag) _baseTag.get(MinecraftSchematicTagNames.HEIGHT);
|
||||
_blocks = (ByteArrayTag) _baseTag.get(MinecraftSchematicTagNames.BLOCKS);
|
||||
_blockData = (ByteArrayTag) _baseTag.get(MinecraftSchematicTagNames.DATA);
|
||||
|
||||
_entities = ((ListTag) _baseTag.get(MinecraftSchematicTagNames.ENTITIES)).getValue();
|
||||
_tileEntities = ((ListTag) _baseTag.get(MinecraftSchematicTagNames.TILE_ENTITIES)).getValue();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static CompoundTag getSchematicTagFromNBTFile(File schematicFile) {
|
||||
CompoundTag schematicTag = null;
|
||||
|
||||
try {
|
||||
FileInputStream stream = new FileInputStream(schematicFile);
|
||||
NBTInputStream nbtStream = new NBTInputStream(stream);
|
||||
|
||||
schematicTag = (CompoundTag) nbtStream.readTag();
|
||||
nbtStream.close();
|
||||
stream.close();
|
||||
} catch (Exception e) {
|
||||
//TODO: LOG ERROR
|
||||
}
|
||||
return schematicTag;
|
||||
}
|
||||
|
||||
public CompoundTag getBaseTag() {
|
||||
return _baseTag;
|
||||
}
|
||||
|
||||
public ShortTag getWidth() {
|
||||
return _width;
|
||||
}
|
||||
|
||||
public ShortTag getLength() {
|
||||
return _length;
|
||||
}
|
||||
|
||||
public ShortTag getHeight() {
|
||||
return _height;
|
||||
}
|
||||
|
||||
public StringTag getMaterials() {
|
||||
return _materials;
|
||||
}
|
||||
|
||||
public ByteArrayTag getBlocks() {
|
||||
return _blocks;
|
||||
}
|
||||
|
||||
public ByteArrayTag getBlockData() {
|
||||
return _blockData;
|
||||
}
|
||||
|
||||
public List<CompoundTag> getEntities() {
|
||||
return _entities;
|
||||
}
|
||||
|
||||
public List<CompoundTag> getTileEntities() {
|
||||
return _tileEntities;
|
||||
}
|
||||
}
|
|
@ -1,641 +0,0 @@
|
|||
package eu.univento.core.api.player;
|
||||
|
||||
import com.github.theholywaffle.teamspeak3.api.wrapper.ClientInfo;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.Actionbar;
|
||||
import eu.univento.core.api.Utils;
|
||||
import eu.univento.core.api.database.MySQL;
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import eu.univento.core.api.server.Servers;
|
||||
import eu.univento.core.api.utils.NameFetcher;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* custom player implementation
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class CustomPlayer extends CraftPlayer {
|
||||
|
||||
/**
|
||||
* all normal players
|
||||
*/
|
||||
private static final HashMap<String, CustomPlayer> PLAYERS = new HashMap<>();
|
||||
|
||||
/**
|
||||
* normal player
|
||||
*/
|
||||
private final Player PLAYER;
|
||||
|
||||
/**
|
||||
* custom prefix for chat
|
||||
*/
|
||||
private String customPrefix;
|
||||
/**
|
||||
* custom suffix for chat
|
||||
*/
|
||||
private String customSuffix;
|
||||
/**
|
||||
* custom color for chat
|
||||
*/
|
||||
private String customColor;
|
||||
|
||||
/**
|
||||
* player id from database
|
||||
*/
|
||||
private int id = 0;
|
||||
|
||||
/**
|
||||
* if player has open inventory
|
||||
*/
|
||||
private boolean openInventory;
|
||||
|
||||
/**
|
||||
* inits player
|
||||
* @param player Player
|
||||
*/
|
||||
private CustomPlayer(Player player) {
|
||||
super((CraftServer) Bukkit.getServer(), ((CraftPlayer) player).getHandle());
|
||||
PLAYERS.put(player.getName().toLowerCase(), this);
|
||||
PLAYER = player;
|
||||
id = getID();
|
||||
}
|
||||
|
||||
/**
|
||||
* called on player leaving
|
||||
*/
|
||||
public void onLeave() {
|
||||
if (PLAYERS.containsKey(getName().toLowerCase())) {
|
||||
PLAYERS.remove(getName().toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* init player
|
||||
* @param player Player
|
||||
* @return CustomPlayer
|
||||
*/
|
||||
public static CustomPlayer getPlayer(String player) {
|
||||
if (PLAYERS.containsKey(player.toLowerCase())) {
|
||||
return PLAYERS.get(player.toLowerCase());
|
||||
} else {
|
||||
Player p = Bukkit.getPlayer(player);
|
||||
return p == null ? null : new CustomPlayer(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets custom player from player
|
||||
* @param player Player
|
||||
* @return CustomPlayer
|
||||
*/
|
||||
public static CustomPlayer getPlayer(Player player) {
|
||||
return getPlayer(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* gets custom player from database id
|
||||
* @param id database id of player
|
||||
* @return CustomPlayer
|
||||
*/
|
||||
public static CustomPlayer getPlayer(int id) {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT ID, UUID FROM users WHERE ID='" + id + "');");
|
||||
ResultSet rs = st.executeQuery();
|
||||
String uuidString = rs.getString("UUID");
|
||||
sql.closeConnection();
|
||||
UUID uuid = UUID.fromString(uuidString);
|
||||
NameFetcher names = new NameFetcher(Arrays.asList(uuid));
|
||||
Map<UUID, String> map = null;
|
||||
try {
|
||||
map = names.call();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String name = map.toString();
|
||||
String Name = name.substring(name.indexOf('=') + 1, name.indexOf('}'));
|
||||
|
||||
return CustomPlayer.getPlayer(Name);
|
||||
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get normal player
|
||||
* @return Player
|
||||
*/
|
||||
public Player getPLAYER() {
|
||||
return PLAYER;
|
||||
}
|
||||
|
||||
/**
|
||||
* connects player to server in bungeecord
|
||||
* @param server ServerPinger to connect to
|
||||
*/
|
||||
public void connectToServer(String server) {
|
||||
Servers.connectServer(PLAYER, server);
|
||||
}
|
||||
|
||||
/**
|
||||
* if player is allowed to do stuff
|
||||
* @param rank Ranks
|
||||
* @return true/false
|
||||
*/
|
||||
public boolean isAllowed(Perms.Ranks rank) {
|
||||
try {
|
||||
return Perms.isAllowed(this, rank);
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* rank of player
|
||||
* @return Ranks
|
||||
*/
|
||||
public Perms.Ranks getRank() {
|
||||
try {
|
||||
return Perms.getRank(this);
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
return Perms.Ranks.Player;
|
||||
}
|
||||
}
|
||||
|
||||
public Perms.Ranks getFreshRank() {
|
||||
try{
|
||||
return Perms.getRankFresh(this);
|
||||
}catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
return Perms.Ranks.Player;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sets rank of this custom player
|
||||
* @param r Ranks
|
||||
*/
|
||||
public void setRank(Perms.Ranks r) {
|
||||
try {
|
||||
Perms.setRank(this, r);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* prefix of player
|
||||
* @return String
|
||||
*/
|
||||
public String getPrefix() {
|
||||
if(customPrefix != null) return customPrefix;
|
||||
if(isNicked()) return Perms.getPrefix(Perms.Ranks.Premium);
|
||||
return Perms.getPrefix(getRank());
|
||||
}
|
||||
|
||||
/**
|
||||
* suffix of player
|
||||
* @return String
|
||||
*/
|
||||
public String getSuffix() {
|
||||
if(customSuffix != null) return customSuffix;
|
||||
if(isNicked()) return Perms.getSuffix(Perms.Ranks.Premium);
|
||||
return Perms.getSuffix(getRank());
|
||||
}
|
||||
|
||||
/**
|
||||
* color of player (Ranks)
|
||||
* @return String
|
||||
*/
|
||||
public String getColor() {
|
||||
if(customColor != null) return customColor;
|
||||
if(isNicked()) return Perms.getColor(Perms.Ranks.Premium);
|
||||
return Perms.getColor(getRank());
|
||||
}
|
||||
|
||||
public Color getArmorColor() {
|
||||
return Perms.getArmorColor(getRank());
|
||||
}
|
||||
|
||||
/**
|
||||
* sets a custom prefix
|
||||
* @param prefix String
|
||||
*/
|
||||
public void setCustomPrefix(String prefix) {
|
||||
customPrefix = prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets a custom suffix
|
||||
* @param suffix String
|
||||
*/
|
||||
public void setCustomSuffix(String suffix) {
|
||||
customSuffix = suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets a custom color
|
||||
* @param color String
|
||||
*/
|
||||
public void setCustomColor(String color) {
|
||||
customColor = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets scoreboard team for player
|
||||
* @return Team
|
||||
*/
|
||||
public Team getTeam() {
|
||||
Perms.Teams teams = new Perms.Teams(this);
|
||||
if(isNicked()) {
|
||||
return teams.Premium;
|
||||
}else {
|
||||
return Perms.Teams.getTeam(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* bans player
|
||||
* @param reason why ban him ?
|
||||
* @param who who banned him ?
|
||||
* @param time ban duration
|
||||
*/
|
||||
public void ban(String reason, CustomPlayer who, Integer time) {
|
||||
try {
|
||||
BanSystem.setBanned(this, reason, who, time);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* if player is banned
|
||||
* @return true/false
|
||||
*/
|
||||
public boolean isBanned() {
|
||||
try {
|
||||
return BanSystem.isBanned(this);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get ban reason
|
||||
* @return String
|
||||
*/
|
||||
public String getBanReason() {
|
||||
try {
|
||||
return BanSystem.getBanReason(this);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* get uuid of player who banned
|
||||
* @return String
|
||||
*/
|
||||
public String getWhoBanned() {
|
||||
try {
|
||||
return BanSystem.getWhoBanned(this);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Timestamp getBanTime() {
|
||||
try {
|
||||
return BanSystem.getBanTime(this);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* unbans the player
|
||||
*/
|
||||
public void removeAllBans() {
|
||||
try {
|
||||
BanSystem.removeAllBans(this);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get nickname of player
|
||||
* @return String
|
||||
*/
|
||||
public String getNick() {
|
||||
return NickName.getNick(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* if player is nicked
|
||||
* @return true/false
|
||||
*/
|
||||
public boolean isNicked() {
|
||||
if(ServerSettings.isGame()) {
|
||||
try {
|
||||
return NickName.isNicked(this);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if player is nicked
|
||||
* @return true/false
|
||||
*/
|
||||
public boolean isNickedReal() {
|
||||
try {
|
||||
return NickName.isNicked(this);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets nickname
|
||||
* @param is boolean
|
||||
*/
|
||||
public void setNicked(boolean is) {
|
||||
try {
|
||||
NickName.setNick(this, is);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets Client Info from TeamSpeak
|
||||
* @return ClientInfo
|
||||
*/
|
||||
public ClientInfo getTSClientInfo() {
|
||||
TeamSpeak ts = Core.getTs();
|
||||
try {
|
||||
return ts.getClientInfo(ts.getTsId(this));
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* verifys player account on teamspeak
|
||||
*/
|
||||
public void verifyTs() {
|
||||
try {
|
||||
Core.getTs().verify(this);
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void checkVerifiedTs() {
|
||||
try {
|
||||
Core.getTs().checkVerifiyed(this);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasVerifiedTs() {
|
||||
try {
|
||||
return Core.getTs().hasVerified(this);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if player has played on the network before
|
||||
* @return true/false
|
||||
*/
|
||||
@Override
|
||||
public boolean hasPlayedBefore() {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
String uuid = this.getUniqueId().toString();
|
||||
ResultSet rs = sql.getConnection().createStatement().executeQuery("SELECT * FROM users WHERE UUID= '" + uuid + "';");
|
||||
if (rs.next()) {
|
||||
sql.closeConnection();
|
||||
return true;
|
||||
}else {
|
||||
sql.closeConnection();
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if inventory is empty
|
||||
* @return true/false
|
||||
*/
|
||||
public boolean hasEmptyInventory() {
|
||||
return Utils.hasEmptyInventory(PLAYER);
|
||||
}
|
||||
|
||||
/**
|
||||
* clears all potion effects from player
|
||||
*/
|
||||
public void clearPotionEffects() {
|
||||
Utils.clearPotionEffects(PLAYER);
|
||||
}
|
||||
|
||||
/**
|
||||
* gets database id of player
|
||||
* @return Integer
|
||||
*/
|
||||
public int getID() {
|
||||
if(id == 0) {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
String uuid = this.getUniqueId().toString();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT * FROM users WHERE UUID ='" + uuid + "';");
|
||||
ResultSet rs = st.executeQuery();
|
||||
if(rs.next()) {
|
||||
int id = rs.getInt("ID");
|
||||
this.id = id;
|
||||
sql.closeConnection();
|
||||
return id;
|
||||
}else {
|
||||
sql.closeConnection();
|
||||
|
||||
return 0;
|
||||
}
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}else {
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if players has a open inventory
|
||||
* @return true/false
|
||||
*/
|
||||
public boolean hasOpenInventory() {
|
||||
return openInventory;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets opened inventory
|
||||
* @param openInventory true/false
|
||||
*/
|
||||
public void setOpenInventory(boolean openInventory) {
|
||||
this.openInventory = openInventory;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets coins from player
|
||||
* @return coins as integer
|
||||
*/
|
||||
public int getCoins() {
|
||||
return Coins.getCoins(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* sets coins if player
|
||||
* @param coins coins as integer
|
||||
*/
|
||||
public void setCoins(int coins) {
|
||||
Coins.setCoins(this, coins);
|
||||
}
|
||||
|
||||
/**
|
||||
* adds coins to player coins
|
||||
* @param coins coins as integer
|
||||
*/
|
||||
public void addCoins(int coins) {
|
||||
int temp = Coins.getCoins(this);
|
||||
Coins.setCoins(this, temp + coins);
|
||||
}
|
||||
|
||||
/**
|
||||
* substracts coins from player coins
|
||||
* @param coins coins as integer
|
||||
*/
|
||||
public void substractCoins(int coins) {
|
||||
int temp = Coins.getCoins(this);
|
||||
Coins.setCoins(this, temp - coins);
|
||||
}
|
||||
|
||||
/**
|
||||
* sends message with actionbar to player
|
||||
* @param text String
|
||||
*/
|
||||
public void sendActionBar(String text) {
|
||||
Actionbar.send(PLAYER, text);
|
||||
}
|
||||
|
||||
/**
|
||||
* gets experience from player
|
||||
* @return experience experience as integer
|
||||
*/
|
||||
public int getExperience() {
|
||||
return Experience.getExperience(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* sets experience of player
|
||||
* @param experience experience to set
|
||||
*/
|
||||
public void setExperience(int experience) {
|
||||
Experience.setExperience(this, experience);
|
||||
}
|
||||
|
||||
/**
|
||||
* adds experience to player
|
||||
* @param experience experience to add
|
||||
*/
|
||||
public void addExperience(int experience) {
|
||||
int temp = Experience.getExperience(this);
|
||||
Experience.setExperience(this, temp + experience);
|
||||
setExp(0F);
|
||||
giveExp(getExperience());
|
||||
playSound(getLocation(), Sound.LEVEL_UP, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
/**
|
||||
* removes experience from player
|
||||
* @param experience experience to remove
|
||||
*/
|
||||
public void substractExperience(int experience) {
|
||||
int temp = Experience.getExperience(this);
|
||||
Experience.setExperience(this, temp - experience);
|
||||
setExp(0F);
|
||||
giveExp(getExperience());
|
||||
}
|
||||
|
||||
public void refreshExperience() {
|
||||
setLevel(0);
|
||||
setExp(0F);
|
||||
giveExp(getExperience());
|
||||
}
|
||||
//TODO: add other functions for secrets
|
||||
|
||||
public int getFoundSecrets() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getLang() {
|
||||
return PlayerSettings.get("lang", this);
|
||||
}
|
||||
|
||||
public void setLang(String lang) {
|
||||
PlayerSettings.set(lang, "lang", this);
|
||||
};
|
||||
|
||||
public boolean isSetting(String setting) {
|
||||
return PlayerSettings.isSet(setting, this);
|
||||
}
|
||||
|
||||
public String getSetting(String setting) { return PlayerSettings.get(setting, this); }
|
||||
|
||||
public void changeSetting(String setting) {
|
||||
PlayerSettings.change(setting, this);
|
||||
}
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
package eu.univento.core.api.player;
|
||||
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.database.MySQL;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* gets nick settings for players
|
||||
* @author joethei
|
||||
* @version 1.1
|
||||
*/
|
||||
public class NickName {
|
||||
|
||||
/**
|
||||
* nick names of players
|
||||
*/
|
||||
static HashMap<CustomPlayer, String> nicks = new HashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param p remove nickname from player
|
||||
*/
|
||||
public static void remove(CustomPlayer p) {
|
||||
if (nicks.containsKey(p))
|
||||
nicks.remove(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* sets nick boolean
|
||||
* @param p player
|
||||
* @param nick boolean
|
||||
* @throws ClassNotFoundException Class couldn't be found
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
*/
|
||||
static void setNick(CustomPlayer p, boolean nick) throws SQLException, ClassNotFoundException {
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
if (nick)
|
||||
sql.getConnection().createStatement().executeUpdate("UPDATE PlayerSettings SET nick = '1' WHERE ID = '" + p.getID() + "';");
|
||||
else
|
||||
sql.getConnection().createStatement().executeUpdate("UPDATE PlayerSettings SET nick = '0' WHERE ID = '" + p.getID() + "';");
|
||||
sql.closeConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* gets if player is nicked
|
||||
* @param p player
|
||||
* @return true / false
|
||||
* @throws ClassNotFoundException Class couldn't be found
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
*/
|
||||
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() + "';");
|
||||
if (rs.next()) {
|
||||
return rs.getInt("nick") == 1;
|
||||
}
|
||||
sql.closeConnection();
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets nickname of player
|
||||
* @param p player
|
||||
* @return String
|
||||
*/
|
||||
static String getNick(CustomPlayer p) {
|
||||
if (nicks.containsKey(p)) {
|
||||
return nicks.get(p);
|
||||
}else if(p.isNicked()){
|
||||
nicks.put(p, getRandomNick());
|
||||
return nicks.get(p);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets random Nickname
|
||||
* @return String
|
||||
*/
|
||||
static String getRandomNick() {
|
||||
ArrayList<String> names = new ArrayList<>();
|
||||
names.add("XXKevinXX");
|
||||
names.add("xxGamelcrafterxx");
|
||||
names.add("LiaaamDesigns");
|
||||
names.add("Firestarter88");
|
||||
names.add("MatelLucario99");
|
||||
names.add("Ghostcraft_No");
|
||||
|
||||
Random r = new Random();
|
||||
int i = r.nextInt(names.size());
|
||||
|
||||
return names.get(i);
|
||||
}
|
||||
}
|
|
@ -1,210 +0,0 @@
|
|||
package eu.univento.core.api.player;
|
||||
|
||||
import com.github.theholywaffle.teamspeak3.TS3Api;
|
||||
import com.github.theholywaffle.teamspeak3.TS3Config;
|
||||
import com.github.theholywaffle.teamspeak3.TS3Query;
|
||||
import com.github.theholywaffle.teamspeak3.api.wrapper.Client;
|
||||
import com.github.theholywaffle.teamspeak3.api.wrapper.ClientInfo;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.Config;
|
||||
import eu.univento.core.api.database.MySQL;
|
||||
import eu.univento.core.api.player.Perms.Ranks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* basic functions for teamspeak communication
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class TeamSpeak {
|
||||
|
||||
private TS3Query query;
|
||||
private TS3Api api;
|
||||
|
||||
int verified = 11;
|
||||
|
||||
/**
|
||||
* inits class
|
||||
*/
|
||||
public TeamSpeak() {
|
||||
final TS3Config config = new TS3Config();
|
||||
config.setHost(Config.readString("TS.IP"));
|
||||
config.setQueryPort(Config.readInt("TS.QueryPort"));
|
||||
config.setDebugLevel(Level.OFF);
|
||||
config.setLoginCredentials(Config.readString("TS.QueryUser"), Config.readString("TS.Query.Pass"));
|
||||
final TS3Query query = new TS3Query(config);
|
||||
query.connect();
|
||||
final TS3Api api = query.getApi();
|
||||
api.selectVirtualServerById(1);
|
||||
api.setNickname("Rechteverteiler von " + Bukkit.getServerName());
|
||||
this.api = api;
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
query.exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* gets teamspeak api
|
||||
* @return TS3Api
|
||||
*/
|
||||
TS3Api getAPI() {
|
||||
return api;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets client info for id
|
||||
* @param id database id
|
||||
* @return ClientInfo
|
||||
*/
|
||||
ClientInfo getClientInfo(int id) {
|
||||
return api.getClientInfo(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* gets database id from teamspeak for player
|
||||
* @param p CustomPlayer
|
||||
* @return Integer
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
* @throws ClassNotFoundException class couldn't be found
|
||||
*/
|
||||
public int getTsId(CustomPlayer p) throws ClassNotFoundException, SQLException {
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT TS_ID FROM users WHERE ID='" + p.getID() + "'");
|
||||
ResultSet rs = st.executeQuery();
|
||||
rs.next();
|
||||
if (rs.getInt("TS_ID") != 0) {
|
||||
int id = rs.getInt("TS_ID");
|
||||
sql.closeConnection();
|
||||
return id;
|
||||
}
|
||||
sql.closeConnection();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getUUID(int id) throws SQLException, ClassNotFoundException {
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT UUID FROM users WHERE TS_ID='" + id + "';");
|
||||
ResultSet rs = st.executeQuery();
|
||||
if(rs.next()) {
|
||||
String uuid = rs.getString("UUID");
|
||||
sql.closeConnection();
|
||||
return uuid;
|
||||
}
|
||||
sql.closeConnection();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* writes id of player to database
|
||||
* @param p CustomPlayer
|
||||
* @param id database id
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
* @throws ClassNotFoundException class couldn't be found
|
||||
*/
|
||||
void setTsId(CustomPlayer p, int id) throws ClassNotFoundException, SQLException {
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("UPDATE users SET TS_ID='" + id + "' WHERE UUID='" + p.getUniqueId().toString() + "';");
|
||||
st.execute();
|
||||
sql.closeConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* sets rank on teamspeak
|
||||
* @param p CustomPlayer
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
* @throws ClassNotFoundException class couldn't be found
|
||||
*/
|
||||
private void setRank(CustomPlayer p, Client client) throws ClassNotFoundException, SQLException {
|
||||
//for(ServerGroup groups : api.getServerGroupsByClient(client)) {
|
||||
// api.removeClientFromServerGroup(groups, client);
|
||||
//}
|
||||
api.addClientToServerGroup(getIdForRank(p.getRank()), client.getDatabaseId());
|
||||
api.addClientToServerGroup(verified, client.getDatabaseId());
|
||||
api.pokeClient(client.getId(), "Du wurdest von unserem freundlichem Bot verifiziert");
|
||||
}
|
||||
|
||||
public void verify(CustomPlayer p) throws SQLException, ClassNotFoundException {
|
||||
TS3Api api = getAPI();
|
||||
if(hasVerified(p)) {
|
||||
p.sendMessage("§cDu hast bereits einen verknüpften Account");
|
||||
}else {
|
||||
Client client = api.getClientByNameExact(p.getName(), false);
|
||||
if(client != null) {
|
||||
setRank(p, client);
|
||||
return;
|
||||
}
|
||||
p.sendMessage("§cDu bist gerade nicht im TS online oder dein Nickname entspricht nicht dem IGN");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private Client getClient(CustomPlayer p) throws SQLException, ClassNotFoundException {
|
||||
if(hasVerified(p)) {
|
||||
int id = getTsId(p);
|
||||
for (Client client : api.getClients()) {
|
||||
if (client.getDatabaseId() == id) {
|
||||
return client;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private CustomPlayer getPlayer(Client client) throws SQLException, ClassNotFoundException {
|
||||
Player player = Bukkit.getPlayer(UUID.fromString(getUUID(client.getDatabaseId())));
|
||||
return CustomPlayer.getPlayer(player);
|
||||
}
|
||||
|
||||
public void checkVerifiyed(CustomPlayer p) throws SQLException, ClassNotFoundException {
|
||||
if(hasVerified(p)) {
|
||||
Client client = getClient(p);
|
||||
if(client != null) {
|
||||
//for(ServerGroup group : api.getServerGroupsByClient(client)) {
|
||||
// if(group.getId() == getIdForRank(p.getRank())) {
|
||||
// return;
|
||||
// }
|
||||
// setRank(p, client);
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasVerified(CustomPlayer p) throws SQLException, ClassNotFoundException {
|
||||
return getTsId(p) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets group id for rank
|
||||
* @param r Ranks
|
||||
* @return Integer
|
||||
*/
|
||||
public int getIdForRank(Ranks r) {
|
||||
switch(r) {
|
||||
case Admin: return 10;
|
||||
case Developer: return 13;
|
||||
case SrModerator: return 60;
|
||||
case Moderator: return 12;
|
||||
case HeadBuilder: return 19;
|
||||
case Builder: return 20;
|
||||
case Supporter: return 14;
|
||||
case Youtuber: return 21;
|
||||
case Premium: return 22;
|
||||
case Player: return 8;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,228 +0,0 @@
|
|||
package eu.univento.core.api.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author mgone2010
|
||||
*/
|
||||
public class FDragon {
|
||||
|
||||
|
||||
private static Constructor<?> packetPlayOutSpawnEntityLiving;
|
||||
private static Constructor<?> entityEnderdragon;
|
||||
|
||||
private static Method setLocation;
|
||||
private static Method setCustomName;
|
||||
private static Method setHealth;
|
||||
private static Method setInvisible;
|
||||
|
||||
private static Method getWorldHandle;
|
||||
private static Method getPlayerHandle;
|
||||
private static Field playerConnection;
|
||||
private static Method sendPacket;
|
||||
|
||||
private static Method getDatawatcher;
|
||||
private static Method a;
|
||||
private static Field d;
|
||||
|
||||
|
||||
public static Map<String, Object> playerDragons = new HashMap<String, Object>();
|
||||
public static Map<String, String> playerTextDragon = new HashMap<String, String>();
|
||||
|
||||
static {
|
||||
try {
|
||||
|
||||
packetPlayOutSpawnEntityLiving = getMCClass("PacketPlayOutSpawnEntityLiving").getConstructor(getMCClass("EntityLiving"));
|
||||
entityEnderdragon = getMCClass("EntityEnderDragon").getConstructor(getMCClass("World"));
|
||||
|
||||
setLocation = getMCClass("EntityEnderDragon").getMethod("setLocation", double.class, double.class, double.class, float.class, float.class);
|
||||
setCustomName = getMCClass("EntityEnderDragon").getMethod("setCustomName", new Class<?>[] { String.class });
|
||||
setHealth = getMCClass("EntityEnderDragon").getMethod("setHealth", new Class<?>[] { float.class });
|
||||
setInvisible = getMCClass("EntityEnderDragon").getMethod("setInvisible", new Class<?>[] { boolean.class });
|
||||
|
||||
|
||||
getWorldHandle = getCraftClass("CraftWorld").getMethod("getHandle");
|
||||
getPlayerHandle = getCraftClass("entity.CraftPlayer").getMethod("getHandle");
|
||||
playerConnection = getMCClass("EntityPlayer").getDeclaredField("playerConnection");
|
||||
sendPacket = getMCClass("PlayerConnection").getMethod("sendPacket", getMCClass("Packet"));
|
||||
|
||||
getDatawatcher = getMCClass("EntityEnderDragon").getMethod("getDataWatcher");
|
||||
a = getMCClass("DataWatcher").getMethod("a", int.class, Object.class);
|
||||
d = getMCClass("DataWatcher").getDeclaredField("d");
|
||||
d.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Object getEnderDragon(Player p) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
|
||||
if (FDragon.playerDragons.containsKey(p.getName())) {
|
||||
return FDragon.playerDragons.get(p.getName());
|
||||
} else {
|
||||
Object nms_world = getWorldHandle.invoke(p.getWorld());
|
||||
FDragon.playerDragons.put(p.getName(), entityEnderdragon.newInstance(nms_world));
|
||||
return FDragon.getEnderDragon(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void setBossBartext(Player p, String text) {
|
||||
playerTextDragon.put(p.getName(), text);
|
||||
try {
|
||||
Object nms_dragon = getEnderDragon(p);
|
||||
//setLocation.invoke(nms_dragon, loc.getX(), 150, loc.getZ(), 0F, 0F);
|
||||
setLocation.invoke(nms_dragon, getPlayerLoc(p).getX(), getPlayerLoc(p).getY()+800, getPlayerLoc(p).getZ(), 0F, 0F);
|
||||
setCustomName.invoke(nms_dragon,text);
|
||||
setHealth.invoke(nms_dragon,200);
|
||||
setInvisible.invoke(nms_dragon,true);
|
||||
changeWatcher(nms_dragon, text);
|
||||
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(nms_dragon);
|
||||
Object nms_player = getPlayerHandle.invoke(p);
|
||||
Object nms_connection = playerConnection.get(nms_player);
|
||||
sendPacket.invoke(nms_connection, nms_packet);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void setBossBar(Player p, String text, float vie) {
|
||||
playerTextDragon.put(p.getName(), text);
|
||||
|
||||
try {
|
||||
Object nms_dragon = getEnderDragon(p);
|
||||
setLocation.invoke(nms_dragon, getPlayerLoc(p).getX(), getPlayerLoc(p).getY()+800, getPlayerLoc(p).getZ(), 0F, 0F);
|
||||
setCustomName.invoke(nms_dragon,text);
|
||||
setHealth.invoke(nms_dragon,vie);
|
||||
setInvisible.invoke(nms_dragon,true);
|
||||
changeWatcher(nms_dragon, text);
|
||||
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(nms_dragon);
|
||||
Object nms_player = getPlayerHandle.invoke(p);
|
||||
Object nms_connection = playerConnection.get(nms_player);
|
||||
sendPacket.invoke(nms_connection, nms_packet);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void removeBossBar(Player p){
|
||||
playerTextDragon.remove(p.getName());
|
||||
try {
|
||||
Object nms_dragon = getEnderDragon(p);
|
||||
setLocation.invoke(nms_dragon, p.getLocation().getX(), -5000, p.getLocation().getZ(), 0F, 0F);
|
||||
setCustomName.invoke(nms_dragon," ");
|
||||
setHealth.invoke(nms_dragon,0);
|
||||
setInvisible.invoke(nms_dragon,true);
|
||||
changeWatcher(nms_dragon, " ");
|
||||
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(nms_dragon);
|
||||
Object nms_player = getPlayerHandle.invoke(p);
|
||||
Object nms_connection = playerConnection.get(nms_player);
|
||||
sendPacket.invoke(nms_connection, nms_packet);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void removehorligneD(Player p) {
|
||||
playerDragons.remove(p.getName());
|
||||
playerTextDragon.remove(p.getName());
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static void changeWatcher(Object nms_entity, String text) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Object nms_watcher = getDatawatcher.invoke(nms_entity);
|
||||
Map<?, ?> map = (Map<?, ?>) d.get(nms_watcher);
|
||||
map.remove(10);
|
||||
a.invoke(nms_watcher, 10, text);
|
||||
}
|
||||
|
||||
private static Class<?> getMCClass(String name) throws ClassNotFoundException {
|
||||
String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3] + ".";
|
||||
String className = "net.minecraft.server." + version + name;
|
||||
return Class.forName(className);
|
||||
}
|
||||
|
||||
private static Class<?> getCraftClass(String name) throws ClassNotFoundException {
|
||||
String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3] + ".";
|
||||
String className = "org.bukkit.craftbukkit." + version + name;
|
||||
return Class.forName(className);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String getCardinalDirection(Player player) {
|
||||
double rotation = (player.getLocation().getYaw() - 180) % 360;
|
||||
if (rotation < 0) {
|
||||
rotation += 360.0;
|
||||
}
|
||||
if (0 <= rotation && rotation < 22.5) {
|
||||
return "N";
|
||||
} else if (22.5 <= rotation && rotation < 67.5) {
|
||||
return "NE";
|
||||
} else if (67.5 <= rotation && rotation < 112.5) {
|
||||
return "E";
|
||||
} else if (112.5 <= rotation && rotation < 157.5) {
|
||||
return "SE";
|
||||
} else if (157.5 <= rotation && rotation < 202.5) {
|
||||
return "S";
|
||||
} else if (202.5 <= rotation && rotation < 247.5) {
|
||||
return "SW";
|
||||
} else if (247.5 <= rotation && rotation < 292.5) {
|
||||
return "W";
|
||||
} else if (292.5 <= rotation && rotation < 337.5) {
|
||||
return "NW";
|
||||
} else if (337.5 <= rotation && rotation < 360.0) {
|
||||
return "N";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Location getPlayerLoc(Player p) {
|
||||
Location loc = p.getLocation();
|
||||
switch (getCardinalDirection(p)) {
|
||||
case ("N") :
|
||||
loc.add(0, 0, -150);
|
||||
break;
|
||||
case ("E") :
|
||||
loc.add(150, 0, 0);
|
||||
break;
|
||||
case ("S") :
|
||||
loc.add(0, 0, 150);
|
||||
break;
|
||||
case ("W") :
|
||||
loc.add(-150, 0, 0);
|
||||
break;
|
||||
case ("NE") :
|
||||
loc.add(150, 0, -150);
|
||||
break;
|
||||
case ("SE") :
|
||||
loc.add(150, 0, 150);
|
||||
break;
|
||||
case ("NW") :
|
||||
loc.add(-150, 0, -150);
|
||||
break;
|
||||
case ("SW") :
|
||||
loc.add(-150, 0, 150);
|
||||
break;
|
||||
}
|
||||
|
||||
return loc;
|
||||
|
||||
}
|
||||
}
|
|
@ -1,289 +0,0 @@
|
|||
package eu.univento.core.api.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/**
|
||||
* @author mgone2010
|
||||
*/
|
||||
public class FWither {
|
||||
|
||||
|
||||
private static Constructor<?> packetPlayOutSpawnEntityLiving;
|
||||
private static Constructor<?> entityEntityWither;
|
||||
|
||||
private static Method setLocation;
|
||||
private static Method setCustomName;
|
||||
private static Method setHealth;
|
||||
private static Method setInvisible;
|
||||
|
||||
private static Method getWorldHandle;
|
||||
private static Method getPlayerHandle;
|
||||
private static Field playerConnection;
|
||||
private static Method sendPacket;
|
||||
|
||||
private static Method getDatawatcher;
|
||||
private static Method a;
|
||||
private static Field d;
|
||||
|
||||
|
||||
private static Map<String, Object> playerWithers = new HashMap<String, Object>();
|
||||
private static Map<String, Object> playerWithers2 = new HashMap<String, Object>();
|
||||
private static Map<String, String> playerTextWither = new HashMap<String, String>();
|
||||
|
||||
static {
|
||||
try {
|
||||
|
||||
packetPlayOutSpawnEntityLiving = getMCClass("PacketPlayOutSpawnEntityLiving").getConstructor(getMCClass("EntityLiving"));
|
||||
entityEntityWither = getMCClass("EntityWither").getConstructor(getMCClass("World"));
|
||||
|
||||
|
||||
setLocation = getMCClass("EntityWither").getMethod("setLocation", double.class, double.class, double.class, float.class, float.class);
|
||||
setCustomName = getMCClass("EntityWither").getMethod("setCustomName", new Class<?>[] { String.class });
|
||||
setHealth = getMCClass("EntityWither").getMethod("setHealth", new Class<?>[] { float.class });
|
||||
setInvisible = getMCClass("EntityWither").getMethod("setInvisible", new Class<?>[] { boolean.class });
|
||||
|
||||
|
||||
getWorldHandle = getCraftClass("CraftWorld").getMethod("getHandle");
|
||||
getPlayerHandle = getCraftClass("entity.CraftPlayer").getMethod("getHandle");
|
||||
playerConnection = getMCClass("EntityPlayer").getDeclaredField("playerConnection");
|
||||
sendPacket = getMCClass("PlayerConnection").getMethod("sendPacket", getMCClass("Packet"));
|
||||
|
||||
getDatawatcher = getMCClass("EntityWither").getMethod("getDataWatcher");
|
||||
a = getMCClass("DataWatcher").getMethod("a", int.class, Object.class);
|
||||
d = getMCClass("DataWatcher").getDeclaredField("d");
|
||||
d.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Object getWither(Player p) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
|
||||
if (playerWithers.containsKey(p.getName())) {
|
||||
return playerWithers.get(p.getName());
|
||||
} else {
|
||||
Object nms_world = getWorldHandle.invoke(p.getWorld());
|
||||
playerWithers.put(p.getName(), entityEntityWither.newInstance(nms_world));
|
||||
return getWither(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Object getWither2(Player p) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
|
||||
if (playerWithers2.containsKey(p.getName())) {
|
||||
return playerWithers2.get(p.getName());
|
||||
} else {
|
||||
Object nms_world = getWorldHandle.invoke(p.getWorld());
|
||||
playerWithers2.put(p.getName(), entityEntityWither.newInstance(nms_world));
|
||||
return getWither2(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void setBossBartext(Player p, String text) {
|
||||
playerTextWither.put(p.getName(), text);
|
||||
int xr = ThreadLocalRandom.current().nextInt(-3,3);
|
||||
int xr2 = ThreadLocalRandom.current().nextInt(-3,3);
|
||||
|
||||
try {
|
||||
Object nms_wither = getWither(p);
|
||||
setLocation.invoke(nms_wither, getPlayerLoc(p).getX()+xr, getPlayerLoc(p).getY()-3, getPlayerLoc(p).getZ()+xr2, 0F, 0F);
|
||||
setCustomName.invoke(nms_wither,text);
|
||||
setHealth.invoke(nms_wither,300);
|
||||
setInvisible.invoke(nms_wither,true);
|
||||
changeWatcher(nms_wither, text);
|
||||
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(nms_wither);
|
||||
Object nms_player = getPlayerHandle.invoke(p);
|
||||
Object nms_connection = playerConnection.get(nms_player);
|
||||
sendPacket.invoke(nms_connection, nms_packet);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
/* try {
|
||||
Object nms_wither = getWither2(p);
|
||||
setLocation.invoke(nms_wither, getPlayerLoc(p).getX()+xr2, p.getLocation().getY()-10, getPlayerLoc(p).getZ()+xr, 0F, 0F);
|
||||
setCustomName.invoke(nms_wither,text);
|
||||
setHealth.invoke(nms_wither,300);
|
||||
setInvisible.invoke(nms_wither,true);
|
||||
changeWatcher(nms_wither, text);
|
||||
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(nms_wither);
|
||||
Object nms_player = getPlayerHandle.invoke(p);
|
||||
Object nms_connection = playerConnection.get(nms_player);
|
||||
sendPacket.invoke(nms_connection, nms_packet);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} */
|
||||
}
|
||||
|
||||
|
||||
public static void setBossBar(Player p, String text, float vie) {
|
||||
playerTextWither.put(p.getName(), text);
|
||||
int xr = ThreadLocalRandom.current().nextInt(0,2);
|
||||
int xr2 = ThreadLocalRandom.current().nextInt(0,2);
|
||||
|
||||
try {
|
||||
Object nms_wither = getWither(p);
|
||||
setLocation.invoke(nms_wither, getPlayerLoc(p).getX()+xr, getPlayerLoc(p).getY()-3, getPlayerLoc(p).getZ()+xr2, 0F, 0F);
|
||||
setCustomName.invoke(nms_wither,text);
|
||||
setHealth.invoke(nms_wither,vie);
|
||||
setInvisible.invoke(nms_wither,true);
|
||||
changeWatcher(nms_wither, text);
|
||||
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(nms_wither);
|
||||
Object nms_player = getPlayerHandle.invoke(p);
|
||||
Object nms_connection = playerConnection.get(nms_player);
|
||||
sendPacket.invoke(nms_connection, nms_packet);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
/* try {
|
||||
Object nms_wither = getWither2(p);
|
||||
setLocation.invoke(nms_wither, getPlayerLoc(p).getX()+xr2, p.getLocation().getY()-10, getPlayerLoc(p).getZ()+xr, 0F, 0F);
|
||||
setCustomName.invoke(nms_wither,text);
|
||||
setHealth.invoke(nms_wither,vie);
|
||||
setInvisible.invoke(nms_wither,true);
|
||||
changeWatcher(nms_wither, text);
|
||||
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(nms_wither);
|
||||
Object nms_player = getPlayerHandle.invoke(p);
|
||||
Object nms_connection = playerConnection.get(nms_player);
|
||||
sendPacket.invoke(nms_connection, nms_packet);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} */
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void removeBossBar(Player p){
|
||||
playerTextWither.remove(p.getName());
|
||||
try {
|
||||
Object nms_wither = getWither(p);
|
||||
setLocation.invoke(nms_wither, p.getLocation().getX(), -5000, p.getLocation().getZ(), 0F, 0F);
|
||||
setCustomName.invoke(nms_wither," ");
|
||||
setHealth.invoke(nms_wither,0);
|
||||
setInvisible.invoke(nms_wither,true);
|
||||
changeWatcher(nms_wither, " ");
|
||||
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(nms_wither);
|
||||
Object nms_player = getPlayerHandle.invoke(p);
|
||||
Object nms_connection = playerConnection.get(nms_player);
|
||||
sendPacket.invoke(nms_connection, nms_packet);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static void removehorligneW(Player p) {
|
||||
playerWithers.remove(p.getName());
|
||||
playerTextWither.remove(p.getName());
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static void changeWatcher(Object nms_entity, String text) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Object nms_watcher = getDatawatcher.invoke(nms_entity);
|
||||
Map<?, ?> map = (Map<?, ?>) d.get(nms_watcher);
|
||||
map.remove(10);
|
||||
a.invoke(nms_watcher, 10, text);
|
||||
|
||||
}
|
||||
|
||||
private static Class<?> getMCClass(String name) throws ClassNotFoundException {
|
||||
String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3] + ".";
|
||||
String className = "net.minecraft.server." + version + name;
|
||||
return Class.forName(className);
|
||||
}
|
||||
|
||||
private static Class<?> getCraftClass(String name) throws ClassNotFoundException {
|
||||
String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3] + ".";
|
||||
String className = "org.bukkit.craftbukkit." + version + name;
|
||||
return Class.forName(className);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String getCardinalDirection(Player player) {
|
||||
double rotation = (player.getLocation().getYaw() - 180) % 360;
|
||||
if (rotation < 0) {
|
||||
rotation += 360.0;
|
||||
}
|
||||
if (0 <= rotation && rotation < 22.5) {
|
||||
return "N";
|
||||
} else if (22.5 <= rotation && rotation < 67.5) {
|
||||
return "NE";
|
||||
} else if (67.5 <= rotation && rotation < 112.5) {
|
||||
return "E";
|
||||
} else if (112.5 <= rotation && rotation < 157.5) {
|
||||
return "SE";
|
||||
} else if (157.5 <= rotation && rotation < 202.5) {
|
||||
return "S";
|
||||
} else if (202.5 <= rotation && rotation < 247.5) {
|
||||
return "SW";
|
||||
} else if (247.5 <= rotation && rotation < 292.5) {
|
||||
return "W";
|
||||
} else if (292.5 <= rotation && rotation < 337.5) {
|
||||
return "NW";
|
||||
} else if (337.5 <= rotation && rotation <= 360.0) {
|
||||
return "N";
|
||||
} else {
|
||||
return "N";
|
||||
}
|
||||
}
|
||||
|
||||
public static Location getPlayerLoc(Player p) {
|
||||
Location loc = p.getLocation();
|
||||
switch (getCardinalDirection(p)) {
|
||||
case ("N") :
|
||||
loc.add(0, 0, -50);
|
||||
break;
|
||||
case ("E") :
|
||||
loc.add(50, 0, 0);
|
||||
break;
|
||||
case ("S") :
|
||||
loc.add(0, 0, 50);
|
||||
break;
|
||||
case ("W") :
|
||||
loc.add(-50, 0, 0);
|
||||
break;
|
||||
case ("NE") :
|
||||
loc.add(50, 0, -50);
|
||||
break;
|
||||
case ("SE") :
|
||||
loc.add(50, 0, 50);
|
||||
break;
|
||||
case ("NW") :
|
||||
loc.add(-50, 0, -50);
|
||||
break;
|
||||
case ("SW") :
|
||||
loc.add(-50, 0, 50);
|
||||
break;
|
||||
}
|
||||
|
||||
return loc;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,135 @@
|
|||
package eu.univento.core;
|
||||
|
||||
import eu.univento.core.api.Blackscreen;
|
||||
import eu.univento.core.api.Config;
|
||||
import eu.univento.core.api.database.MongoDB;
|
||||
import eu.univento.core.api.database.MySQL;
|
||||
import eu.univento.core.api.events.MoveEventFilter;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import eu.univento.core.commands.*;
|
||||
import eu.univento.core.listeners.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* main class
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Core extends JavaPlugin{
|
||||
|
||||
//TODO: rewrite time critical database functions from MySQL to MongoDB
|
||||
|
||||
/**
|
||||
* plugin instance
|
||||
*/
|
||||
public static Core instance;
|
||||
/**
|
||||
* @return plugin instance
|
||||
*/
|
||||
public static Core getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* mysql stuff
|
||||
*/
|
||||
private static MySQL sql = new MySQL(getInstance(), Config.readString("MySQL.Host"), Config.readString("MySQL.Port"), Config.readString("MySQL.DB"), Config.readString("MySQL.User"), Config.readString("MySQL.Pass"));
|
||||
/**
|
||||
* @return sql
|
||||
*/
|
||||
public static MySQL returnSQL() {
|
||||
return sql;
|
||||
}
|
||||
|
||||
private static MongoDB mongoDB;
|
||||
public static MongoDB getMongoDB() {
|
||||
return mongoDB;
|
||||
}
|
||||
|
||||
/**
|
||||
* logging and stuff
|
||||
*/
|
||||
private static Logger log = Bukkit.getLogger();
|
||||
|
||||
public static ArrayList<CustomPlayer> getOnlinePlayers() {
|
||||
ArrayList<CustomPlayer> list = new ArrayList<>();
|
||||
for(Player players : Bukkit.getOnlinePlayers()) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(players);
|
||||
list.add(p);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param level Log level
|
||||
* @param string String
|
||||
*/
|
||||
public static void log(Level level, String string) {
|
||||
if(ServerSettings.isDebug()) {
|
||||
log.log(level, "[univento Core] " + string);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
ServerSettings.setDebug(true);
|
||||
try {
|
||||
Config.writeDefault();
|
||||
} catch (ClassNotFoundException | SQLException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
instance = this;
|
||||
log(Level.INFO, "activated debug mode");
|
||||
PluginManager pm = Bukkit.getPluginManager();
|
||||
pm.registerEvents(new Commands(), this);
|
||||
pm.registerEvents(new JoinQuit(), this);
|
||||
pm.registerEvents(new Chat(), this);
|
||||
pm.registerEvents(new Events(), this);
|
||||
pm.registerEvents(new MoveEventFilter(getServer()), this);
|
||||
|
||||
if(ServerSettings.isGame()) {
|
||||
new Fix(this, "fix", "fix");
|
||||
new Stats(this, "stats", "statistics");
|
||||
new Nick(this, "nick", "nick");
|
||||
}else{
|
||||
new Build(this, "build", "build", "b");
|
||||
pm.registerEvents(new Blocks(), this);
|
||||
}
|
||||
|
||||
new RunAs(this, "RunAs", "runas");
|
||||
new SystemInfo(this, "SystemInfo", "systeminfo");
|
||||
new Vanish(this, "vanish", "vanish");
|
||||
new GameMode(this, "gamemode" , "gamemode", "gm");
|
||||
new SetRank(this, "setrank" , "setrank", "sr");
|
||||
new GlobalMute(this, "globalmute", "globalmute");
|
||||
new TS(this, "ts", "ts");
|
||||
new Ban(this, "ban", "ban");
|
||||
new ChatClear(this, "chatclear", "chatclear", "cc");
|
||||
|
||||
log(Level.INFO, "registered all commands");
|
||||
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
||||
|
||||
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"));
|
||||
|
||||
|
||||
log(Level.INFO, "Plugin ver. " + getDescription().getVersion() + " started");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
log(Level.INFO, "Plugin stoped");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,18 +1,18 @@
|
|||
package eu.univento.core.api;
|
||||
|
||||
import net.minecraft.server.v1_8_R3.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Actionbar {
|
||||
|
||||
public static void send(Player player, String message){
|
||||
CraftPlayer p = (CraftPlayer) player;
|
||||
IChatBaseComponent cbc = ChatSerializer.a("{\"text\": \"" + message + "\"}");
|
||||
PacketPlayOutChat ppoc = new PacketPlayOutChat(cbc,(byte) 2);
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(ppoc);
|
||||
}
|
||||
|
||||
}
|
||||
package eu.univento.core.api;
|
||||
|
||||
import net.minecraft.server.v1_9_R1.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_9_R1.IChatBaseComponent.ChatSerializer;
|
||||
import net.minecraft.server.v1_9_R1.PacketPlayOutChat;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Actionbar {
|
||||
|
||||
public static void send(Player player, String message){
|
||||
CraftPlayer p = (CraftPlayer) player;
|
||||
IChatBaseComponent cbc = ChatSerializer.a("{\"text\": \"" + message + "\"}");
|
||||
PacketPlayOutChat ppoc = new PacketPlayOutChat(cbc,(byte) 2);
|
||||
p.getHandle().playerConnection.sendPacket(ppoc);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,78 +1,77 @@
|
|||
package eu.univento.core.api;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author PostCrafter
|
||||
* @see href http://postcrafter.de/viewtopic.php?f=15&t=143
|
||||
* @param <P> main class
|
||||
*/
|
||||
public abstract class AutoCommand<P extends JavaPlugin> extends Command {
|
||||
|
||||
private static String VERSION;
|
||||
|
||||
static {
|
||||
String path = Bukkit.getServer().getClass().getPackage().getName();
|
||||
|
||||
AutoCommand.VERSION = path.substring(path.lastIndexOf(".") + 1, path.length());
|
||||
|
||||
System.out.println("[PostLib] AutoCommand hook for Bukkit " + AutoCommand.VERSION);
|
||||
}
|
||||
|
||||
protected final P plugin;
|
||||
protected final String command;
|
||||
|
||||
public AutoCommand(P plugin, String command, String description, String... aliases) {
|
||||
super(command);
|
||||
this.plugin = plugin;
|
||||
this.command = command;
|
||||
|
||||
super.setDescription(description);
|
||||
List<String> aliasList = new ArrayList<String>();
|
||||
for (String alias : aliases) {
|
||||
aliasList.add(alias);
|
||||
}
|
||||
super.setAliases(aliasList);
|
||||
|
||||
this.register();
|
||||
}
|
||||
|
||||
public void register() {
|
||||
try {
|
||||
Field f = Class.forName("org.bukkit.craftbukkit." + AutoCommand.VERSION + ".CraftServer").getDeclaredField("commandMap");
|
||||
f.setAccessible(true);
|
||||
|
||||
CommandMap map = (CommandMap) f.get(Bukkit.getServer());
|
||||
map.register(this.plugin.getName(), this);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract boolean execute(CommandSender sender, String label, String[] args);
|
||||
|
||||
public abstract List<String> tabComplete(CommandSender sender, String label, String[] args);
|
||||
|
||||
public String buildString(String[] args, int start) {
|
||||
String str = "";
|
||||
if (args.length > start) {
|
||||
str += args[start];
|
||||
for (int i = start + 1; i < args.length; i++) {
|
||||
str += " " + args[i];
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public P getPlugin() {
|
||||
return this.plugin;
|
||||
}
|
||||
}
|
||||
package eu.univento.core.api;
|
||||
|
||||
import eu.univento.core.Core;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* @author PostCrafter
|
||||
* @see href http://postcrafter.de/viewtopic.php?f=15&t=143
|
||||
* @param <P> main class
|
||||
*/
|
||||
public abstract class AutoCommand<P extends JavaPlugin> extends Command {
|
||||
|
||||
private static String VERSION;
|
||||
|
||||
static {
|
||||
String path = Bukkit.getServer().getClass().getPackage().getName();
|
||||
AutoCommand.VERSION = path.substring(path.lastIndexOf(".") + 1, path.length());
|
||||
Core.log(Level.INFO, "AutoCommand hook for Bukkit " + AutoCommand.VERSION);
|
||||
}
|
||||
|
||||
protected final P plugin;
|
||||
protected final String command;
|
||||
|
||||
public AutoCommand(P plugin, String command, String description, String... aliases) {
|
||||
super(command);
|
||||
this.plugin = plugin;
|
||||
this.command = command;
|
||||
|
||||
super.setDescription(description);
|
||||
List<String> aliasList = new ArrayList<>();
|
||||
for (String alias : aliases) {
|
||||
aliasList.add(alias);
|
||||
}
|
||||
super.setAliases(aliasList);
|
||||
this.register();
|
||||
}
|
||||
|
||||
private void register() {
|
||||
try {
|
||||
Field f = Class.forName("org.bukkit.craftbukkit." + AutoCommand.VERSION + ".CraftServer").getDeclaredField("commandMap");
|
||||
f.setAccessible(true);
|
||||
|
||||
CommandMap map = (CommandMap) f.get(Bukkit.getServer());
|
||||
map.register(this.plugin.getName(), this);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract boolean execute(CommandSender sender, String label, String[] args);
|
||||
|
||||
public abstract List<String> tabComplete(CommandSender sender, String label, String[] args);
|
||||
|
||||
public String buildString(String[] args, int start) {
|
||||
String str = "";
|
||||
if (args.length > start) {
|
||||
str += args[start];
|
||||
for (int i = start + 1; i < args.length; i++) {
|
||||
str += " " + args[i];
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public P getPlugin() {
|
||||
return this.plugin;
|
||||
}
|
||||
}
|
|
@ -1,85 +1,80 @@
|
|||
package eu.univento.core.api;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author janhektor
|
||||
*
|
||||
*/
|
||||
public class Blackscreen
|
||||
{
|
||||
private static Object packetObject;
|
||||
private static Class<?> packetClass;
|
||||
private static String VERSION;
|
||||
private static Map<UUID, Integer> ticksLeft = new HashMap<UUID, Integer>();
|
||||
|
||||
static { String path = Bukkit.getServer().getClass().getPackage().getName();
|
||||
VERSION = path.substring(path.lastIndexOf(".") + 1, path.length());
|
||||
try {
|
||||
packetClass = Class.forName("net.minecraft.server." + VERSION + ".Packet");
|
||||
Class<?> packetGameStateClass = Class.forName("net.minecraft.server." + VERSION + ".PacketPlayOutGameStateChange");
|
||||
packetObject = packetGameStateClass.getConstructor(new Class[] { Integer.TYPE, Float.TYPE }).newInstance(new Object[] { Integer.valueOf(4), Integer.valueOf(0) });
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setupUtil(Plugin instance)
|
||||
{
|
||||
setupUtil(instance, 2);
|
||||
}
|
||||
|
||||
public static void setupUtil(Plugin instance, int repeatingTicks)
|
||||
{
|
||||
Bukkit.getScheduler().runTaskTimer(instance, new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
for (UUID uuid : Blackscreen.ticksLeft.keySet()) {
|
||||
Player p = Bukkit.getPlayer(uuid);
|
||||
if (p == null) {
|
||||
Blackscreen.ticksLeft.remove(uuid);
|
||||
}
|
||||
else if (((Integer)Blackscreen.ticksLeft.get(uuid)).intValue() > 0) {
|
||||
Blackscreen.ticksLeft.put(uuid, Integer.valueOf(((Integer)Blackscreen.ticksLeft.get(uuid)).intValue() - 2));
|
||||
Blackscreen.access(p);
|
||||
} else {
|
||||
Blackscreen.ticksLeft.remove(uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
, 0L, repeatingTicks);
|
||||
}
|
||||
|
||||
protected static void access(Player p) {
|
||||
|
||||
}
|
||||
|
||||
private static void sendPacket(Player p) {
|
||||
try {
|
||||
Object nmsPlayer = p.getClass().getMethod("getHandle", new Class[0]).invoke(p, new Object[0]);
|
||||
Field playerConnectionField = nmsPlayer.getClass().getField("playerConnection");
|
||||
Object pConnection = playerConnectionField.get(nmsPlayer);
|
||||
Method sendPacket = pConnection.getClass().getMethod("sendPacket", new Class[] { packetClass });
|
||||
sendPacket.invoke(pConnection, new Object[] { packetObject });
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setBlack(Player p, int seconds)
|
||||
{
|
||||
ticksLeft.put(p.getUniqueId(), Integer.valueOf(seconds * 20));
|
||||
sendPacket(p);
|
||||
}
|
||||
package eu.univento.core.api;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author janhektor
|
||||
*
|
||||
*/
|
||||
public class Blackscreen {
|
||||
private static Object packetObject;
|
||||
private static Class<?> packetClass;
|
||||
private static String VERSION;
|
||||
private static Map<UUID, Integer> ticksLeft = new HashMap<UUID, Integer>();
|
||||
|
||||
static { String path = Bukkit.getServer().getClass().getPackage().getName();
|
||||
VERSION = path.substring(path.lastIndexOf(".") + 1, path.length());
|
||||
try {
|
||||
packetClass = Class.forName("net.minecraft.server." + VERSION + ".Packet");
|
||||
Class<?> packetGameStateClass = Class.forName("net.minecraft.server." + VERSION + ".PacketPlayOutGameStateChange");
|
||||
packetObject = packetGameStateClass.getConstructor(new Class[] { Integer.TYPE, Float.TYPE }).newInstance(new Object[] { Integer.valueOf(4), Integer.valueOf(0) });
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setupUtil(Plugin instance)
|
||||
{
|
||||
setupUtil(instance, 2);
|
||||
}
|
||||
|
||||
public static void setupUtil(Plugin instance, int repeatingTicks)
|
||||
{
|
||||
Bukkit.getScheduler().runTaskTimer(instance, () -> {
|
||||
for (UUID uuid : Blackscreen.ticksLeft.keySet()) {
|
||||
Player p = Bukkit.getPlayer(uuid);
|
||||
if (p == null) {
|
||||
Blackscreen.ticksLeft.remove(uuid);
|
||||
}
|
||||
else if (((Integer)Blackscreen.ticksLeft.get(uuid)).intValue() > 0) {
|
||||
Blackscreen.ticksLeft.put(uuid, Integer.valueOf((Blackscreen.ticksLeft.get(uuid)).intValue() - 2));
|
||||
Blackscreen.access(p);
|
||||
} else {
|
||||
Blackscreen.ticksLeft.remove(uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
, 0L, repeatingTicks);
|
||||
}
|
||||
|
||||
protected static void access(Player p) {
|
||||
|
||||
}
|
||||
|
||||
private static void sendPacket(Player p) {
|
||||
try {
|
||||
Object nmsPlayer = p.getClass().getMethod("getHandle", new Class[0]).invoke(p, new Object[0]);
|
||||
Field playerConnectionField = nmsPlayer.getClass().getField("playerConnection");
|
||||
Object pConnection = playerConnectionField.get(nmsPlayer);
|
||||
Method sendPacket = pConnection.getClass().getMethod("sendPacket", new Class[] { packetClass });
|
||||
sendPacket.invoke(pConnection, new Object[] { packetObject });
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setBlack(Player p, int seconds)
|
||||
{
|
||||
ticksLeft.put(p.getUniqueId(), Integer.valueOf(seconds * 20));
|
||||
sendPacket(p);
|
||||
}
|
||||
}
|
|
@ -1,172 +1,171 @@
|
|||
package eu.univento.core.api;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* gets data from config file
|
||||
* @author joethei
|
||||
* @version 1.1
|
||||
*/
|
||||
public class Config {
|
||||
|
||||
/**config file*/
|
||||
private static File file = new File("plugins/Core", "config.yml");
|
||||
/**load configuration */
|
||||
private static FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
/**
|
||||
* write default data to config
|
||||
* @throws ClassNotFoundException Class couldn't be found
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
* @throws IOException I/O failed
|
||||
*/
|
||||
public static void writeDefault() throws ClassNotFoundException, SQLException, IOException {
|
||||
//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.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.options().copyDefaults(true);
|
||||
cfg.save(file);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* write data as string to config
|
||||
* @param path path to data
|
||||
* @param obj data
|
||||
*/
|
||||
public static void write(String path, String obj) {
|
||||
cfg.set(path, obj);
|
||||
try {
|
||||
cfg.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* write data as integer to config
|
||||
* @param path path to data
|
||||
* @param obj data
|
||||
*/
|
||||
public static void write(String path, int obj) {
|
||||
cfg.set(path, obj);
|
||||
try {
|
||||
cfg.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* write data as double to config
|
||||
* @param path path to data
|
||||
* @param obj data
|
||||
*/
|
||||
public static void write(String path, double obj) {
|
||||
cfg.set(path, obj);
|
||||
try {
|
||||
cfg.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* write location to config
|
||||
* @param path path to data
|
||||
* @param loc location
|
||||
*/
|
||||
public static void write(String path, Location loc) {
|
||||
String world = loc.getWorld().getName();
|
||||
double x = loc.getX();
|
||||
double y = loc.getY();
|
||||
double z = loc.getZ();
|
||||
double yaw = (double) loc.getYaw();
|
||||
double pitch = (double) loc.getPitch();
|
||||
|
||||
cfg.set(path + ".World", world);
|
||||
cfg.set(path + ".X", x);
|
||||
cfg.set(path + ".Y", y);
|
||||
cfg.set(path + ".Z", z);
|
||||
cfg.set(path + ".Yaw", yaw);
|
||||
cfg.set(path + ".Pitch", pitch);
|
||||
|
||||
try {
|
||||
cfg.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* read integer from config
|
||||
* @param path path to data
|
||||
* @return Integer
|
||||
*/
|
||||
public static int readInt(String path) {
|
||||
return cfg.getInt(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* read double from config
|
||||
* @param path path to data
|
||||
* @return Double
|
||||
*/
|
||||
public static double readDouble(String path) {
|
||||
return cfg.getDouble(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* read string from config
|
||||
* @param path path to data
|
||||
* @return String
|
||||
*/
|
||||
public static String readString(String path) {
|
||||
return cfg.getString(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* read location from config
|
||||
* @param path path to data
|
||||
* @return Location
|
||||
*/
|
||||
public static Location readLocation(String path) {
|
||||
String world = cfg.getString(path + ".World");
|
||||
double x = cfg.getDouble(path + ".X");
|
||||
double y = cfg.getDouble(path + ".Y");
|
||||
double z = cfg.getDouble(path + ".Z");
|
||||
float yaw = (float) cfg.getDouble(path + ".Yaw");
|
||||
float pitch = (float) cfg.getDouble(path + ".Pitch");
|
||||
|
||||
Location loc = new Location(Bukkit.getWorld(world), x, y, z, yaw, pitch);
|
||||
return loc;
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if data is existing
|
||||
* @param path path do data
|
||||
* @return true / false
|
||||
*/
|
||||
public static boolean isExsisting(String path) {
|
||||
return cfg.contains(path);
|
||||
}
|
||||
|
||||
package eu.univento.core.api;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* gets data from config file
|
||||
* @author joethei
|
||||
* @version 1.1
|
||||
*/
|
||||
public class Config {
|
||||
|
||||
/**config file*/
|
||||
private static File file = new File("plugins/Core", "config.yml");
|
||||
/**load configuration */
|
||||
private static FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
/**
|
||||
* write default data to config
|
||||
* @throws ClassNotFoundException Class couldn't be found
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
* @throws IOException I/O failed
|
||||
*/
|
||||
public static void writeDefault() throws ClassNotFoundException, SQLException, IOException {
|
||||
//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.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.options().copyDefaults(true);
|
||||
cfg.save(file);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* write data as string to config
|
||||
* @param path path to data
|
||||
* @param obj data
|
||||
*/
|
||||
public static void write(String path, String obj) {
|
||||
cfg.set(path, obj);
|
||||
try {
|
||||
cfg.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* write data as integer to config
|
||||
* @param path path to data
|
||||
* @param obj data
|
||||
*/
|
||||
public static void write(String path, int obj) {
|
||||
cfg.set(path, obj);
|
||||
try {
|
||||
cfg.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* write data as double to config
|
||||
* @param path path to data
|
||||
* @param obj data
|
||||
*/
|
||||
public static void write(String path, double obj) {
|
||||
cfg.set(path, obj);
|
||||
try {
|
||||
cfg.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* write location to config
|
||||
* @param path path to data
|
||||
* @param loc location
|
||||
*/
|
||||
public static void write(String path, Location loc) {
|
||||
String world = loc.getWorld().getName();
|
||||
double x = loc.getX();
|
||||
double y = loc.getY();
|
||||
double z = loc.getZ();
|
||||
double yaw = (double) loc.getYaw();
|
||||
double pitch = (double) loc.getPitch();
|
||||
|
||||
cfg.set(path + ".World", world);
|
||||
cfg.set(path + ".X", x);
|
||||
cfg.set(path + ".Y", y);
|
||||
cfg.set(path + ".Z", z);
|
||||
cfg.set(path + ".Yaw", yaw);
|
||||
cfg.set(path + ".Pitch", pitch);
|
||||
|
||||
try {
|
||||
cfg.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* read integer from config
|
||||
* @param path path to data
|
||||
* @return Integer
|
||||
*/
|
||||
public static int readInt(String path) {
|
||||
return cfg.getInt(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* read double from config
|
||||
* @param path path to data
|
||||
* @return Double
|
||||
*/
|
||||
public static double readDouble(String path) {
|
||||
return cfg.getDouble(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* read string from config
|
||||
* @param path path to data
|
||||
* @return String
|
||||
*/
|
||||
public static String readString(String path) {
|
||||
return cfg.getString(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* read location from config
|
||||
* @param path path to data
|
||||
* @return Location
|
||||
*/
|
||||
public static Location readLocation(String path) {
|
||||
String world = cfg.getString(path + ".World");
|
||||
double x = cfg.getDouble(path + ".X");
|
||||
double y = cfg.getDouble(path + ".Y");
|
||||
double z = cfg.getDouble(path + ".Z");
|
||||
float yaw = (float) cfg.getDouble(path + ".Yaw");
|
||||
float pitch = (float) cfg.getDouble(path + ".Pitch");
|
||||
|
||||
return new Location(Bukkit.getWorld(world), x, y, z, yaw, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if data is existing
|
||||
* @param path path do data
|
||||
* @return true / false
|
||||
*/
|
||||
public static boolean isExsisting(String path) {
|
||||
return cfg.contains(path);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
package eu.univento.core.api;
|
||||
|
||||
import eu.univento.core.Core;
|
||||
import net.minecraft.server.v1_9_R1.EntityArmorStand;
|
||||
import net.minecraft.server.v1_9_R1.PacketPlayOutEntityDestroy;
|
||||
import net.minecraft.server.v1_9_R1.PacketPlayOutSpawnEntityLiving;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Hologram {
|
||||
|
||||
private List<EntityArmorStand> entitylist = new ArrayList<>();
|
||||
private String[] Text;
|
||||
private Location location;
|
||||
double DISTANCE = 0.25D;
|
||||
int count;
|
||||
|
||||
public Hologram(String[] Text, Location location) {
|
||||
this.Text = Text;
|
||||
this.location = location;
|
||||
create();
|
||||
}
|
||||
|
||||
|
||||
public void showPlayerTemp(final Player p,int Time){
|
||||
showPlayer(p);
|
||||
Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> hidePlayer(p), Time);
|
||||
}
|
||||
|
||||
|
||||
public void showAllTemp(final Player p,int Time){
|
||||
showAll();
|
||||
Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> hideAll(), Time);
|
||||
}
|
||||
|
||||
public void showPlayer(Player p) {
|
||||
for (EntityArmorStand armor : entitylist) {
|
||||
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor);
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
public void hidePlayer(Player p) {
|
||||
for (EntityArmorStand armor : entitylist) {
|
||||
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId());
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void showAll() {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
for (EntityArmorStand armor : entitylist) {
|
||||
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor);
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void hideAll() {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
for (EntityArmorStand armor : entitylist) {
|
||||
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId());
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void create() {
|
||||
for (String Text : this.Text) {
|
||||
EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(),this.location.getX(), this.location.getY(),this.location.getZ());
|
||||
entity.setCustomName(Text);
|
||||
entity.setCustomNameVisible(true);
|
||||
entity.setInvisible(true);
|
||||
entity.setGravity(false);
|
||||
entitylist.add(entity);
|
||||
this.location.subtract(0, this.DISTANCE, 0);
|
||||
count++;
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
this.location.add(0, this.DISTANCE, 0);
|
||||
}
|
||||
this.count = 0;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,99 +1,85 @@
|
|||
package eu.univento.core.api;
|
||||
|
||||
import net.minecraft.server.v1_8_R3.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerListHeaderFooter;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutTitle;
|
||||
import net.minecraft.server.v1_8_R3.PlayerConnection;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
//TODO: find real author, its not me
|
||||
/**
|
||||
* sends title to player
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Title {
|
||||
|
||||
/**
|
||||
* send title to player
|
||||
* @param player Player
|
||||
* @param fadeIn Integer
|
||||
* @param stay Integer
|
||||
* @param fadeOut Integer
|
||||
* @param title String
|
||||
* @param subtitle String
|
||||
*/
|
||||
public static void sendTitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String title, String subtitle) {
|
||||
PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||
|
||||
PacketPlayOutTitle packetPlayOutTimes = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TIMES, null, fadeIn.intValue(), stay.intValue(), fadeOut.intValue());
|
||||
connection.sendPacket(packetPlayOutTimes);
|
||||
|
||||
if (subtitle != null) {
|
||||
subtitle = subtitle.replaceAll("%player%", player.getDisplayName());
|
||||
subtitle = ChatColor.translateAlternateColorCodes('&', subtitle);
|
||||
IChatBaseComponent titleSub = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + subtitle + "\"}");
|
||||
PacketPlayOutTitle packetPlayOutSubTitle = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.SUBTITLE, titleSub);
|
||||
connection.sendPacket(packetPlayOutSubTitle);
|
||||
}
|
||||
|
||||
if (title != null) {
|
||||
title = title.replaceAll("%player%", player.getDisplayName());
|
||||
title = ChatColor.translateAlternateColorCodes('&', title);
|
||||
IChatBaseComponent titleMain = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + title + "\"}");
|
||||
PacketPlayOutTitle packetPlayOutTitle = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TITLE, titleMain);
|
||||
connection.sendPacket(packetPlayOutTitle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sends tab title to player
|
||||
* @param player Player
|
||||
* @param header String
|
||||
* @param footer String
|
||||
*/
|
||||
public static void sendTabTitle(Player player, String header, String footer) {
|
||||
if (header == null)
|
||||
header = "";
|
||||
header = ChatColor.translateAlternateColorCodes('&', header);
|
||||
|
||||
if (footer == null)
|
||||
footer = "";
|
||||
footer = ChatColor.translateAlternateColorCodes('&', footer);
|
||||
|
||||
header = header.replaceAll("%player%", player.getDisplayName());
|
||||
footer = footer.replaceAll("%player%", player.getDisplayName());
|
||||
|
||||
PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||
IChatBaseComponent tabTitle = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + header + "\"}");
|
||||
IChatBaseComponent tabFoot = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + footer + "\"}");
|
||||
PacketPlayOutPlayerListHeaderFooter headerPacket = new PacketPlayOutPlayerListHeaderFooter(tabTitle);
|
||||
try {
|
||||
Field field = headerPacket.getClass().getDeclaredField("b");
|
||||
field.setAccessible(true);
|
||||
field.set(headerPacket, tabFoot);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
connection.sendPacket(headerPacket);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if String is integer
|
||||
* @param s String
|
||||
* @return boolean
|
||||
*/
|
||||
boolean isInteger(String s) {
|
||||
try {
|
||||
Integer.parseInt(s);
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
package eu.univento.core.api;
|
||||
|
||||
import net.minecraft.server.v1_9_R1.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_9_R1.PacketPlayOutPlayerListHeaderFooter;
|
||||
import net.minecraft.server.v1_9_R1.PacketPlayOutTitle;
|
||||
import net.minecraft.server.v1_9_R1.PlayerConnection;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
//TODO: find real author, its not me
|
||||
/**
|
||||
* sends title to player
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Title {
|
||||
|
||||
/**
|
||||
* send title to player
|
||||
* @param player Player
|
||||
* @param fadeIn Integer
|
||||
* @param stay Integer
|
||||
* @param fadeOut Integer
|
||||
* @param title String
|
||||
* @param subtitle String
|
||||
*/
|
||||
public static void sendTitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String title, String subtitle) {
|
||||
PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||
|
||||
PacketPlayOutTitle packetPlayOutTimes = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut);
|
||||
connection.sendPacket(packetPlayOutTimes);
|
||||
|
||||
if (subtitle != null) {
|
||||
subtitle = subtitle.replaceAll("%player%", player.getDisplayName());
|
||||
subtitle = ChatColor.translateAlternateColorCodes('&', subtitle);
|
||||
IChatBaseComponent titleSub = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + subtitle + "\"}");
|
||||
PacketPlayOutTitle packetPlayOutSubTitle = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.SUBTITLE, titleSub);
|
||||
connection.sendPacket(packetPlayOutSubTitle);
|
||||
}
|
||||
|
||||
if (title != null) {
|
||||
title = title.replaceAll("%player%", player.getDisplayName());
|
||||
title = ChatColor.translateAlternateColorCodes('&', title);
|
||||
IChatBaseComponent titleMain = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + title + "\"}");
|
||||
PacketPlayOutTitle packetPlayOutTitle = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TITLE, titleMain);
|
||||
connection.sendPacket(packetPlayOutTitle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sends tab title to player
|
||||
* @param player Player
|
||||
* @param header String
|
||||
* @param footer String
|
||||
*/
|
||||
public static void sendTabTitle(Player player, String header, String footer) {
|
||||
if (header == null)
|
||||
header = "";
|
||||
header = ChatColor.translateAlternateColorCodes('&', header);
|
||||
|
||||
if (footer == null)
|
||||
footer = "";
|
||||
footer = ChatColor.translateAlternateColorCodes('&', footer);
|
||||
|
||||
header = header.replaceAll("%player%", player.getDisplayName());
|
||||
footer = footer.replaceAll("%player%", player.getDisplayName());
|
||||
|
||||
PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||
IChatBaseComponent tabTitle = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + header + "\"}");
|
||||
IChatBaseComponent tabFoot = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + footer + "\"}");
|
||||
PacketPlayOutPlayerListHeaderFooter headerPacket = new PacketPlayOutPlayerListHeaderFooter(tabTitle);
|
||||
try {
|
||||
Field field = headerPacket.getClass().getDeclaredField("b");
|
||||
field.setAccessible(true);
|
||||
field.set(headerPacket, tabFoot);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
connection.sendPacket(headerPacket);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,179 +1,176 @@
|
|||
package eu.univento.core.api;
|
||||
|
||||
import eu.univento.core.Core;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* some utils you may need
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Utils {
|
||||
|
||||
/**
|
||||
* plays sound for all players
|
||||
* @param s Sound
|
||||
*/
|
||||
public static void playSoundToAll(Sound s) {
|
||||
for (Player all : Bukkit.getOnlinePlayers())
|
||||
all.playSound(all.getLocation(), s, 3.0F, 3.0F);
|
||||
}
|
||||
|
||||
/**
|
||||
* plays effect for all players
|
||||
* @param e Effect
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void playEffectToAll(Effect e) {
|
||||
for (Player all : Bukkit.getOnlinePlayers())
|
||||
all.playEffect(all.getLocation(), e, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if server version is from spigot
|
||||
* @return true/false
|
||||
*/
|
||||
public static boolean isSpigot() {
|
||||
return Bukkit.getVersion().contains("Spigot");
|
||||
}
|
||||
|
||||
/**
|
||||
* deletes all folders and files in directory
|
||||
* @param file File
|
||||
*/
|
||||
public static void deleteDir(File file) {
|
||||
if (file.isDirectory()) {
|
||||
if (file.list().length == 0) {
|
||||
file.delete();
|
||||
} else {
|
||||
String[] files = file.list();
|
||||
for (String tmp : files) {
|
||||
File fileDelete = new File(file, tmp);
|
||||
deleteDir(fileDelete);
|
||||
}
|
||||
if (file.list().length == 0)
|
||||
file.delete();
|
||||
}
|
||||
} else
|
||||
file.delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a random number
|
||||
* @param low lowest possible value
|
||||
* @param high highest possible value
|
||||
* @return double
|
||||
*/
|
||||
public static double random(int low, int high) {
|
||||
return Math.random() * (high - low) + low;
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if player has empty inventory
|
||||
* @param p Player
|
||||
* @return true/false
|
||||
*/
|
||||
public static boolean hasEmptyInventory(Player p) {
|
||||
for (ItemStack item : p.getInventory().getContents()) {
|
||||
if ((item != null) && (item.getType() != Material.AIR))
|
||||
return false;
|
||||
}
|
||||
for (ItemStack item : p.getInventory().getArmorContents()) {
|
||||
if ((item != null) && (item.getType() != Material.AIR))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* removes list of entity and counts them
|
||||
* @param e List<Entity>
|
||||
* @return Integer
|
||||
*/
|
||||
public static int removeEntitys(List<Entity> e) {
|
||||
int i = 0;
|
||||
for (Entity en : e) {
|
||||
en.remove();
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* clears all potion effects from player
|
||||
* @param player Player
|
||||
*/
|
||||
public static void clearPotionEffects(Player player) {
|
||||
for (PotionEffect effect : player.getActivePotionEffects())
|
||||
player.removePotionEffect(effect.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* calculates vector from one location to another
|
||||
* @param from Location
|
||||
* @param to Location
|
||||
* @return Vector
|
||||
*/
|
||||
public static Vector calculateVector(Location from, Location to) {
|
||||
Location a = from, b = to;
|
||||
|
||||
// calculate the distance between the locations (a => from || b => to)
|
||||
double dX = a.getX() - b.getX();
|
||||
double dY = a.getY() - b.getY();
|
||||
double dZ = a.getZ() - b.getZ();
|
||||
// -------------------------
|
||||
|
||||
// calculate the yaw
|
||||
double yaw = Math.atan2(dZ, dX);
|
||||
// -------------------------
|
||||
|
||||
// calculate the pitch
|
||||
double pitch = Math.atan2(Math.sqrt(dZ * dZ + dX * dX), dY) + Math.PI;
|
||||
// -------------------------
|
||||
|
||||
// calculate and create the new vector
|
||||
double x = Math.sin(pitch) * Math.cos(yaw);
|
||||
double y = Math.sin(pitch) * Math.sin(yaw);
|
||||
double z = Math.cos(pitch);
|
||||
|
||||
Vector vector = new Vector(x, z, y);
|
||||
// -------------------------
|
||||
|
||||
return vector;
|
||||
}
|
||||
|
||||
/**
|
||||
* restarts server
|
||||
*/
|
||||
public static void restart() {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Core.getInstance(), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Bukkit.getServer().spigot().restart();
|
||||
}
|
||||
|
||||
}, 10 * 20L);
|
||||
}
|
||||
|
||||
/**
|
||||
* shots random firework at specified location
|
||||
* @param loc Location
|
||||
*/
|
||||
public static void randomFirework(Location loc) {
|
||||
FireworkEffect.Builder builder = FireworkEffect.builder();
|
||||
FireworkEffect effect = builder.flicker(false).trail(false).with(FireworkEffect.Type.BALL_LARGE).withColor(Color.RED).withFade(Color.BLUE).build();
|
||||
//TODO: make a random fireworks effect
|
||||
//TODO: remove effect.toString(), its only to remove unused warnings
|
||||
effect.toString();
|
||||
}
|
||||
package eu.univento.core.api;
|
||||
|
||||
import eu.univento.core.Core;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* some utils you may need
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Utils {
|
||||
|
||||
/**
|
||||
* plays sound for all players
|
||||
* @param s Sound
|
||||
*/
|
||||
public static void playSoundToAll(Sound s) {
|
||||
for (Player all : Bukkit.getOnlinePlayers())
|
||||
all.playSound(all.getLocation(), s, 3.0F, 3.0F);
|
||||
}
|
||||
|
||||
/**
|
||||
* plays effect for all players
|
||||
* @param e Effect
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void playEffectToAll(Effect e) {
|
||||
for (Player all : Bukkit.getOnlinePlayers())
|
||||
all.playEffect(all.getLocation(), e, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if server version is from spigot
|
||||
* @return true/false
|
||||
*/
|
||||
public static boolean isSpigot() {
|
||||
return Bukkit.getVersion().contains("Spigot");
|
||||
}
|
||||
|
||||
/**
|
||||
* deletes all folders and files in directory
|
||||
* @param file File
|
||||
*/
|
||||
public static void deleteDir(File file) {
|
||||
if (file.isDirectory()) {
|
||||
if (file.list().length == 0) {
|
||||
file.delete();
|
||||
} else {
|
||||
String[] files = file.list();
|
||||
for (String tmp : files) {
|
||||
File fileDelete = new File(file, tmp);
|
||||
deleteDir(fileDelete);
|
||||
}
|
||||
if (file.list().length == 0)
|
||||
file.delete();
|
||||
}
|
||||
} else
|
||||
file.delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a random number
|
||||
* @param low lowest possible value
|
||||
* @param high highest possible value
|
||||
* @return double
|
||||
*/
|
||||
public static double random(int low, int high) {
|
||||
return Math.random() * (high - low) + low;
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if player has empty inventory
|
||||
* @param p Player
|
||||
* @return true/false
|
||||
*/
|
||||
public static boolean hasEmptyInventory(Player p) {
|
||||
for (ItemStack item : p.getInventory().getContents()) {
|
||||
if ((item != null) && (item.getType() != Material.AIR))
|
||||
return false;
|
||||
}
|
||||
for (ItemStack item : p.getInventory().getArmorContents()) {
|
||||
if ((item != null) && (item.getType() != Material.AIR))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* removes list of entity and counts them
|
||||
* @param e List<Entity>
|
||||
* @return Integer
|
||||
*/
|
||||
public static int removeEntitys(List<Entity> e) {
|
||||
int i = 0;
|
||||
for (Entity en : e) {
|
||||
en.remove();
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* clears all potion effects from player
|
||||
* @param player Player
|
||||
*/
|
||||
public static void clearPotionEffects(Player player) {
|
||||
for (PotionEffect effect : player.getActivePotionEffects())
|
||||
player.removePotionEffect(effect.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* calculates vector from one location to another
|
||||
* @param from Location
|
||||
* @param to Location
|
||||
* @return Vector
|
||||
*/
|
||||
public static Vector calculateVector(Location from, Location to) {
|
||||
Location b = to;
|
||||
|
||||
// calculate the distance between the locations (a => from || b => to)
|
||||
double dX = from.getX() - b.getX();
|
||||
double dY = from.getY() - b.getY();
|
||||
double dZ = from.getZ() - b.getZ();
|
||||
// -------------------------
|
||||
|
||||
// calculate the yaw
|
||||
double yaw = Math.atan2(dZ, dX);
|
||||
// -------------------------
|
||||
|
||||
// calculate the pitch
|
||||
double pitch = Math.atan2(Math.sqrt(dZ * dZ + dX * dX), dY) + Math.PI;
|
||||
// -------------------------
|
||||
|
||||
// calculate and create the new vector
|
||||
double x = Math.sin(pitch) * Math.cos(yaw);
|
||||
double y = Math.sin(pitch) * Math.sin(yaw);
|
||||
double z = Math.cos(pitch);
|
||||
|
||||
// -------------------------
|
||||
|
||||
return new Vector(x, z, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* restarts server
|
||||
*/
|
||||
public static void restart() {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Core.getInstance(), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Bukkit.getServer().spigot().restart();
|
||||
}
|
||||
|
||||
}, 10 * 20L);
|
||||
}
|
||||
|
||||
/**
|
||||
* shots random firework at specified location
|
||||
* @param loc Location
|
||||
*/
|
||||
public static void randomFirework(Location loc) {
|
||||
FireworkEffect.Builder builder = FireworkEffect.builder();
|
||||
FireworkEffect effect = builder.flicker(false).trail(false).with(FireworkEffect.Type.BALL_LARGE).withColor(Color.RED).withFade(Color.BLUE).build();
|
||||
//TODO: make a random fireworks effect
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package eu.univento.core.api.database;
|
||||
|
||||
import com.mongodb.MongoClient;
|
||||
import com.mongodb.MongoCredential;
|
||||
import com.mongodb.ServerAddress;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import eu.univento.core.api.Config;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class MongoDB {
|
||||
|
||||
private MongoClient client;
|
||||
private MongoDatabase database;
|
||||
|
||||
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"));
|
||||
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));
|
||||
}
|
||||
|
||||
public MongoDatabase getDatabase() {
|
||||
if(database == null) {
|
||||
database = getClient().getDatabase(Config.readString("MongoDB.Database"));
|
||||
}return database;
|
||||
}
|
||||
|
||||
public void setDatabase(String database) {
|
||||
this.database = getClient().getDatabase(database);
|
||||
}
|
||||
|
||||
public void closeConnection() {
|
||||
if(client != null) {
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package eu.univento.core.api.effects;
|
||||
|
||||
import eu.univento.core.api.player.PlayerSettings;
|
||||
import net.minecraft.server.v1_9_R1.EnumParticle;
|
||||
import net.minecraft.server.v1_9_R1.PacketPlayOutWorldParticles;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* some better effects
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Effects {
|
||||
|
||||
/**
|
||||
* plays effects from location
|
||||
* @param loc Location
|
||||
* @param ep EnumParticle
|
||||
* @param f float of particles
|
||||
* @param count count of particles
|
||||
*/
|
||||
public static void playEffect(Location loc, EnumParticle ep, float f, int count) {
|
||||
PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(ep, true, (float) loc.getX(), (float) loc.getY(), (float) loc.getZ(), f, f, f, 0.0F, count, 0, 0);
|
||||
for(Player p : PlayerSettings.getAllPlayersWithEffectsEnabled()) {
|
||||
((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
public static void playEffectToPlayer(Player p, Location loc, EnumParticle ep, float f, int count) {
|
||||
PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(ep, true, (float) loc.getX(), (float) loc.getY(), (float) loc.getZ(), f, f, f, 0.0F, count, 0, 0);
|
||||
((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,12 +1,12 @@
|
|||
package eu.univento.core.api.entity;
|
||||
|
||||
import net.minecraft.server.v1_8_R3.EntityLiving;
|
||||
import net.minecraft.server.v1_8_R3.NBTTagCompound;
|
||||
import net.minecraft.server.v1_9_R1.EntityLiving;
|
||||
import net.minecraft.server.v1_9_R1.NBTTagCompound;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.EntityEffect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftCreature;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftCreature;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
|
@ -21,7 +21,7 @@ public class EntityModifier
|
|||
{
|
||||
static org.bukkit.entity.Entity entity;
|
||||
static CraftEntity craftentity;
|
||||
static net.minecraft.server.v1_8_R3.Entity entityS;
|
||||
static net.minecraft.server.v1_9_R1.Entity entityS;
|
||||
static int scheduler;
|
||||
static Plugin plugin;
|
||||
static Player player = null;
|
||||
|
@ -122,7 +122,7 @@ public class EntityModifier
|
|||
{
|
||||
try
|
||||
{
|
||||
Field invulnerableField = net.minecraft.server.v1_8_R3.Entity.class
|
||||
Field invulnerableField = net.minecraft.server.v1_9_R1.Entity.class
|
||||
.getDeclaredField("invulnerable");
|
||||
invulnerableField.setAccessible(true);
|
||||
invulnerableField.setBoolean(EntityModifier.entityS, invulnerable);
|
|
@ -2,9 +2,9 @@ package eu.univento.core.api.fakeplayer;
|
|||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import eu.univento.core.Core;
|
||||
import net.minecraft.server.v1_8_R3.*;
|
||||
import net.minecraft.server.v1_9_R1.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
@ -21,6 +21,8 @@ import java.util.Arrays;
|
|||
*/
|
||||
public class FakePlayer {
|
||||
|
||||
//TODO: fix parts and add some stuff
|
||||
|
||||
private static final double MOVE_SPEED = 4.3D / 20;
|
||||
|
||||
private Player player;
|
||||
|
@ -47,9 +49,9 @@ public class FakePlayer {
|
|||
|
||||
this.dataWatcher = new DataWatcher(null);
|
||||
byte status = 0;
|
||||
this.dataWatcher.a(0, status);
|
||||
this.dataWatcher.a(10, (byte) 127);
|
||||
this.dataWatcher.a(6, 20F);
|
||||
//this.dataWatcher.a(0, status);
|
||||
//this.dataWatcher.a(10, (byte) 127);
|
||||
//this.dataWatcher.a(6, 20F);
|
||||
}
|
||||
|
||||
private final BukkitRunnable tickTask = new BukkitRunnable() {
|
||||
|
@ -106,9 +108,9 @@ public class FakePlayer {
|
|||
DataWatcher dataWatcher = this.dataWatcher;
|
||||
byte status = 0;
|
||||
status = changeMask(status, data, bool);
|
||||
dataWatcher.a(0, status);
|
||||
dataWatcher.a(10, (byte) 127);
|
||||
dataWatcher.a(6, 20F);
|
||||
//dataWatcher.a(0, status);
|
||||
//dataWatcher.a(10, (byte) 127);
|
||||
//dataWatcher.a(6, 20F);
|
||||
}
|
||||
|
||||
public void followEntity(LivingEntity entity) {
|
|
@ -0,0 +1,59 @@
|
|||
package eu.univento.core.api.game;
|
||||
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
*/
|
||||
public class Team {
|
||||
|
||||
private ArrayList<CustomPlayer> players = new ArrayList<>();
|
||||
private String name;
|
||||
private String prefix;
|
||||
private org.bukkit.scoreboard.Team team;
|
||||
|
||||
public Team(String name, String prefix) {
|
||||
this.name = name;
|
||||
this.prefix = prefix;
|
||||
if(Bukkit.getScoreboardManager().getMainScoreboard().getTeam(name) == null) {
|
||||
team = Bukkit.getScoreboardManager().getMainScoreboard().registerNewTeam(name);
|
||||
}else{
|
||||
team = Bukkit.getScoreboardManager().getMainScoreboard().getTeam(name);
|
||||
}
|
||||
team.setPrefix(prefix);
|
||||
}
|
||||
|
||||
public void addPlayer(CustomPlayer p) {
|
||||
players.add(p);
|
||||
team.addEntry(p.getName());
|
||||
}
|
||||
|
||||
public void removePlayer(CustomPlayer p) {
|
||||
players.remove(p);
|
||||
team.removeEntry(p.getName());
|
||||
}
|
||||
|
||||
public boolean isPlayer(CustomPlayer p) {
|
||||
return players.contains(p);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public ArrayList<CustomPlayer> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
public org.bukkit.scoreboard.Team getScoreboardTeam() {
|
||||
return team;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package eu.univento.core.api.game;
|
||||
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
*/
|
||||
public class TeamManager {
|
||||
|
||||
private static ArrayList<Team> teams = new ArrayList<>();
|
||||
|
||||
public static ArrayList<Team> getTeams() {
|
||||
return teams;
|
||||
}
|
||||
|
||||
public static Team getTeam(String name) {
|
||||
for(Team team : teams) {
|
||||
if(team.getName().equalsIgnoreCase(name)) return team;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Team getTeam(CustomPlayer p) {
|
||||
for(Team team : teams) {
|
||||
if(team.isPlayer(p)) return team;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void addTeam(Team team) {
|
||||
teams.add(team);
|
||||
}
|
||||
|
||||
public static void removeTeam(Team team) {
|
||||
teams.remove(team);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package eu.univento.core.api.gui;
|
||||
|
||||
import eu.univento.core.Core;
|
||||
import net.minecraft.server.v1_8_R3.*;
|
||||
import net.minecraft.server.v1_9_R1.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
|
@ -0,0 +1,30 @@
|
|||
package eu.univento.core.api.gui;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
*/
|
||||
public class PlayerSignInputEvent extends PlayerEvent{
|
||||
|
||||
public static HandlerList handlerList = new HandlerList();
|
||||
public String[] lines;
|
||||
|
||||
public PlayerSignInputEvent(Player p, String[] lines) {
|
||||
super(p);
|
||||
this.lines = lines;
|
||||
SignInputHandler.ejectNetty(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlerList;
|
||||
}
|
||||
|
||||
public String[] getLines() {
|
||||
return lines;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package eu.univento.core.api.gui;
|
||||
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import net.minecraft.server.v1_9_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_9_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_9_R1.PacketPlayOutOpenSignEditor;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
*/
|
||||
public class SignInput {
|
||||
|
||||
public static void openSignInput(CustomPlayer p) {
|
||||
EntityPlayer player = p.getHandle();
|
||||
BlockPosition bp = new BlockPosition(p.getHandle());
|
||||
PacketPlayOutOpenSignEditor packet = new PacketPlayOutOpenSignEditor(bp);
|
||||
player.playerConnection.sendPacket(packet);
|
||||
SignInputHandler.injectNetty(p);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package eu.univento.core.api.gui;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||
import net.minecraft.server.v1_9_R1.NetworkManager;
|
||||
import net.minecraft.server.v1_9_R1.Packet;
|
||||
import net.minecraft.server.v1_9_R1.PacketPlayInUpdateSign;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
*/
|
||||
public class SignInputHandler {
|
||||
|
||||
private static Field channelField;
|
||||
|
||||
static{
|
||||
for(Field filed : NetworkManager.class.getDeclaredFields()) {
|
||||
if(channelField.getType().isAssignableFrom(Channel.class)) {
|
||||
channelField = filed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void injectNetty(final Player player) {
|
||||
try {
|
||||
Channel channel = (Channel) channelField.get(((CraftPlayer) player).getHandle().playerConnection.networkManager);
|
||||
if (channel != null) {
|
||||
channel.pipeline().addAfter("decoder", "update_sign", new MessageToMessageDecoder<Packet>() {
|
||||
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext chc, Packet packet, List<Object> out) throws Exception {
|
||||
if (packet instanceof PacketPlayInUpdateSign) {
|
||||
|
||||
PacketPlayInUpdateSign usePacket = (PacketPlayInUpdateSign) packet;
|
||||
Bukkit.getPluginManager().callEvent(new PlayerSignInputEvent(player, usePacket.b()));
|
||||
}
|
||||
out.add(packet);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void ejectNetty(Player player) {
|
||||
try {
|
||||
Channel channel = (Channel) channelField.get(((CraftPlayer) player).getHandle().playerConnection.networkManager);
|
||||
if (channel != null) {
|
||||
if (channel.pipeline().get("update_sign") != null) {
|
||||
channel.pipeline().remove("update_sign");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -546,7 +546,7 @@ public class Language_EN implements Languages{
|
|||
|
||||
@Override
|
||||
public String LobbyBoard_NEW() {
|
||||
return "§e§lJetzt neu:";
|
||||
return "§e§lNew:";
|
||||
}
|
||||
|
||||
@Override
|
|
@ -71,12 +71,12 @@ public class Language_IT implements Languages{
|
|||
|
||||
@Override
|
||||
public String Core_BUILD_ON() {
|
||||
return "§7Tu sei §aentrato nel §emodo di costruzione";
|
||||
return "§7Tu sei §aentrato §7nel §emodo di costruzione";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String Core_BUILD_OFF() {
|
||||
return "§7Tu sei §auscito dal §emodo di costruzione";
|
||||
return "§7Tu sei §auscito §7dal §emodo di costruzione";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -170,7 +170,7 @@ public class Language_IT implements Languages{
|
|||
|
||||
@Override
|
||||
public String Core_CHAT_CLEARED(CustomPlayer p) {
|
||||
return "§7La chat è stato §cpulito §7da " + p.getColor() + p.getDisplayName();
|
||||
return "§7La chat è stata §cpulita §7da " + p.getColor() + p.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -195,27 +195,27 @@ public class Language_IT implements Languages{
|
|||
|
||||
@Override
|
||||
public String Lobby_AUTONICK_OFF() {
|
||||
return "§7Adesso §cnon §7ti viene più dato un §esoprannome §7automatico";
|
||||
return "§7Adesso §cnon §7ti viene dato un più §esoprannome §7automatico";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String Lobby_FORCEFIELD_ON() {
|
||||
return "§7Hai §7attivato §7il §eforcefield";
|
||||
return "§7Hai §aattivato §7il §eForcefield";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String Lobby_FORCEFIELD_OFF() {
|
||||
return "§7Hai §cdisattivato §7il §eforcefield";
|
||||
return "§7Hai §cdisattivato §7il §eForcefield";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String Lobby_SILENT_LOBBY_ON() {
|
||||
return "§7Sei §aentrato §7nella §esilent-lobby";
|
||||
return "§7Sei §aentrato §7nella §eSilent-Lobby";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String Lobby_SILENT_LOBBY_OFF() {
|
||||
return "§7Sei §euscita §7della §esilent-lobby";
|
||||
return "§7Sei §cuscita §7della §eSilent-Lobby";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -435,7 +435,7 @@ public class Language_IT implements Languages{
|
|||
|
||||
@Override
|
||||
public String LobbyItems_PLAYER_MENU() {
|
||||
return " menu";
|
||||
return ": menu";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -510,17 +510,17 @@ public class Language_IT implements Languages{
|
|||
|
||||
@Override
|
||||
public String LobbyItems_SETTINGS_ON() {
|
||||
return "§aattivato";
|
||||
return "§aattivo";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String LobbyItems_SETTINGS_OFF() {
|
||||
return "§cdisattivato";
|
||||
return "§cdisattivo";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String LobbyItems_BACK() {
|
||||
return "§cindietro";
|
||||
return "§cIndietro";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -530,7 +530,7 @@ public class Language_IT implements Languages{
|
|||
|
||||
@Override
|
||||
public String LobbyBoard_COINS() {
|
||||
return "§eI tuoi Coins§7:";
|
||||
return "§eVenties§7:";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -552,4 +552,5 @@ public class Language_IT implements Languages{
|
|||
public String LobbyBoard_NEWS() {
|
||||
return "Scheibenwischer";
|
||||
}
|
||||
|
||||
}
|
|
@ -3,6 +3,7 @@ package eu.univento.core.api.languages;
|
|||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.player.Perms;
|
||||
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 2.0
|
||||
|
@ -19,14 +20,15 @@ public class Messages {
|
|||
|
||||
public Messages(CustomPlayer player) {
|
||||
this.player = player;
|
||||
if(player.getLang().equals("DE")) this.lang = de;
|
||||
if(player.getLang().equals("IT")) this.lang = it;
|
||||
if(player.getLang().equals("EN")) this.lang = en;
|
||||
if(player.getLanguage().equals("DE")) this.lang = de;
|
||||
if(player.getLanguage().equals("IT")) this.lang = it;
|
||||
if(player.getLanguage().equals("EN")) this.lang = en;
|
||||
}
|
||||
|
||||
public String PREFIX() {
|
||||
return " §7• §6univento§7.§eeu §7• ";
|
||||
return " §6univento §8» ";
|
||||
}
|
||||
public String TAB_PREFIX() { return "§8• §6U N I V E N T O §8• ";}
|
||||
|
||||
public String UNKNOWN_ERROR() {
|
||||
return lang.UNKNOWN_ERROR();
|
|
@ -0,0 +1,194 @@
|
|||
package eu.univento.core.api.map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author desht (Original code), KingFaris10 (Editor of code)
|
||||
* @version 0.1
|
||||
*/
|
||||
|
||||
public class Cuboid implements Cloneable, ConfigurationSerializable, Iterable<Block> {
|
||||
|
||||
protected String worldName;
|
||||
protected final Vector minimumPoint, maximumPoint;
|
||||
|
||||
public Cuboid(Cuboid cuboid) {
|
||||
this(cuboid.worldName, cuboid.minimumPoint.getX(), cuboid.minimumPoint.getY(), cuboid.minimumPoint.getZ(), cuboid.maximumPoint.getX(), cuboid.maximumPoint.getY(), cuboid.maximumPoint.getZ());
|
||||
}
|
||||
|
||||
public Cuboid(Location loc) {
|
||||
this(loc, loc);
|
||||
}
|
||||
|
||||
public Cuboid(Location loc1, Location loc2) {
|
||||
if (loc1 != null && loc2 != null) {
|
||||
if (loc1.getWorld() != null && loc2.getWorld() != null) {
|
||||
if (!loc1.getWorld().getUID().equals(loc2.getWorld().getUID()))
|
||||
throw new IllegalStateException("The 2 locations of the cuboid must be in the same world!");
|
||||
} else {
|
||||
throw new NullPointerException("One/both of the worlds is/are null!");
|
||||
}
|
||||
this.worldName = loc1.getWorld().getName();
|
||||
|
||||
double xPos1 = Math.min(loc1.getX(), loc2.getX());
|
||||
double yPos1 = Math.min(loc1.getY(), loc2.getY());
|
||||
double zPos1 = Math.min(loc1.getZ(), loc2.getZ());
|
||||
double xPos2 = Math.max(loc1.getX(), loc2.getX());
|
||||
double yPos2 = Math.max(loc1.getY(), loc2.getY());
|
||||
double zPos2 = Math.max(loc1.getZ(), loc2.getZ());
|
||||
this.minimumPoint = new Vector(xPos1, yPos1, zPos1);
|
||||
this.maximumPoint = new Vector(xPos2, yPos2, zPos2);
|
||||
} else {
|
||||
throw new NullPointerException("One/both of the locations is/are null!");
|
||||
}
|
||||
}
|
||||
|
||||
public Cuboid(String worldName, double x1, double y1, double z1, double x2, double y2, double z2) {
|
||||
if (worldName == null || Bukkit.getServer().getWorld(worldName) == null)
|
||||
throw new NullPointerException("One/both of the worlds is/are null!");
|
||||
this.worldName = worldName;
|
||||
|
||||
double xPos1 = Math.min(x1, x2);
|
||||
double xPos2 = Math.max(x1, x2);
|
||||
double yPos1 = Math.min(y1, y2);
|
||||
double yPos2 = Math.max(y1, y2);
|
||||
double zPos1 = Math.min(z1, z2);
|
||||
double zPos2 = Math.max(z1, z2);
|
||||
this.minimumPoint = new Vector(xPos1, yPos1, zPos1);
|
||||
this.maximumPoint = new Vector(xPos2, yPos2, zPos2);
|
||||
}
|
||||
|
||||
public boolean containsLocation(Location location) {
|
||||
return location != null && location.getWorld().getName().equals(this.worldName) && location.toVector().isInAABB(this.minimumPoint, this.maximumPoint);
|
||||
}
|
||||
|
||||
public boolean containsVector(Vector vector) {
|
||||
return vector != null && vector.isInAABB(this.minimumPoint, this.maximumPoint);
|
||||
}
|
||||
|
||||
public List<Block> getBlocks() {
|
||||
List<Block> blockList = new ArrayList<>();
|
||||
World world = this.getWorld();
|
||||
if (world != null) {
|
||||
for (int x = this.minimumPoint.getBlockX(); x <= this.maximumPoint.getBlockX(); x++) {
|
||||
for (int y = this.minimumPoint.getBlockY(); y <= this.maximumPoint.getBlockY() && y <= world.getMaxHeight(); y++) {
|
||||
for (int z = this.minimumPoint.getBlockZ(); z <= this.maximumPoint.getBlockZ(); z++) {
|
||||
blockList.add(world.getBlockAt(x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return blockList;
|
||||
}
|
||||
|
||||
public Location getLowerLocation() {
|
||||
return this.minimumPoint.toLocation(this.getWorld());
|
||||
}
|
||||
|
||||
public double getLowerX() {
|
||||
return this.minimumPoint.getX();
|
||||
}
|
||||
|
||||
public double getLowerY() {
|
||||
return this.minimumPoint.getY();
|
||||
}
|
||||
|
||||
public double getLowerZ() {
|
||||
return this.minimumPoint.getZ();
|
||||
}
|
||||
|
||||
public Location getUpperLocation() {
|
||||
return this.maximumPoint.toLocation(this.getWorld());
|
||||
}
|
||||
|
||||
public double getUpperX() {
|
||||
return this.maximumPoint.getX();
|
||||
}
|
||||
|
||||
public double getUpperY() {
|
||||
return this.maximumPoint.getY();
|
||||
}
|
||||
|
||||
public double getUpperZ() {
|
||||
return this.maximumPoint.getZ();
|
||||
}
|
||||
|
||||
public double getVolume() {
|
||||
return (this.getUpperX() - this.getLowerX() + 1) * (this.getUpperY() - this.getLowerY() + 1) * (this.getUpperZ() - this.getLowerZ() + 1);
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
World world = Bukkit.getServer().getWorld(this.worldName);
|
||||
if (world == null) throw new NullPointerException("World '" + this.worldName + "' is not loaded.");
|
||||
return world;
|
||||
}
|
||||
|
||||
public void setWorld(World world) {
|
||||
if (world != null) this.worldName = world.getName();
|
||||
else throw new NullPointerException("The world cannot be null.");
|
||||
}
|
||||
|
||||
public Location getRandomLocation() {
|
||||
Random randomX = new Random();
|
||||
Random randomY = new Random();
|
||||
double x = getLowerX() + (getUpperX() - getLowerX()) * randomX.nextDouble();
|
||||
double z = getLowerZ() + (getUpperZ() - getLowerZ()) * randomY.nextDouble();
|
||||
int y = getWorld().getHighestBlockYAt(new Location(getWorld(), x, 0, z));
|
||||
|
||||
Location loc = new Location(getWorld(), x, y, z);
|
||||
|
||||
if(loc.getBlock().getType() == Material.GRASS || loc.getBlock().getType() == Material.SNOW_BLOCK) return getRandomLocation();
|
||||
|
||||
return loc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cuboid clone() {
|
||||
return new Cuboid(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<Block> iterator() {
|
||||
return this.getBlocks().listIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, Object> serialize() {
|
||||
HashMap<String, Object> serializedCuboid = new HashMap<>();
|
||||
serializedCuboid.put("worldName", this.worldName);
|
||||
serializedCuboid.put("x1", this.minimumPoint.getX());
|
||||
serializedCuboid.put("x2", this.maximumPoint.getX());
|
||||
serializedCuboid.put("y1", this.minimumPoint.getY());
|
||||
serializedCuboid.put("y2", this.maximumPoint.getY());
|
||||
serializedCuboid.put("z1", this.minimumPoint.getZ());
|
||||
serializedCuboid.put("z2", this.maximumPoint.getZ());
|
||||
return serializedCuboid;
|
||||
}
|
||||
|
||||
public static Cuboid deserialize(HashMap<String, Object> serializedCuboid) {
|
||||
try {
|
||||
String worldName = (String) serializedCuboid.get("worldName");
|
||||
|
||||
double xPos1 = (Double) serializedCuboid.get("x1");
|
||||
double xPos2 = (Double) serializedCuboid.get("x2");
|
||||
double yPos1 = (Double) serializedCuboid.get("y1");
|
||||
double yPos2 = (Double) serializedCuboid.get("y2");
|
||||
double zPos1 = (Double) serializedCuboid.get("z1");
|
||||
double zPos2 = (Double) serializedCuboid.get("z2");
|
||||
|
||||
return new Cuboid(worldName, xPos1, yPos1, zPos1, xPos2, yPos2, zPos2);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package eu.univento.core.api.map;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
*/
|
||||
public class Map {
|
||||
|
||||
private String name;
|
||||
private String builder;
|
||||
private Material item;
|
||||
|
||||
public Map(String name, String builder, Material item) {
|
||||
this.name = name;
|
||||
this.builder = builder;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getBuilder() {
|
||||
return builder;
|
||||
}
|
||||
|
||||
public Material getItem() {
|
||||
return item;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package eu.univento.core.api.map;
|
||||
|
||||
import eu.univento.core.api.server.Game;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
*/
|
||||
public class MapDatabase {
|
||||
|
||||
//TODO: add real map database
|
||||
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));
|
||||
|
||||
return maps;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,193 @@
|
|||
package eu.univento.core.api.map;
|
||||
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.player.Perms;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
*/
|
||||
public class MapVoting implements Listener{
|
||||
|
||||
|
||||
private Map map1;
|
||||
private Map map2;
|
||||
private Map map3;
|
||||
private String invTitle;
|
||||
private ArrayList<CustomPlayer> votes1 = new ArrayList<>();
|
||||
private ArrayList<CustomPlayer> votes2 = new ArrayList<>();
|
||||
private ArrayList<CustomPlayer> votes3 = new ArrayList<>();
|
||||
private Map forcedMap;
|
||||
private ArrayList<Map> allMaps = new ArrayList<>();
|
||||
|
||||
public MapVoting(String invTitle) {
|
||||
this.invTitle = invTitle;
|
||||
}
|
||||
|
||||
public void vote(CustomPlayer p, Integer map) {
|
||||
switch (map) {
|
||||
case 1 : votes1.add(p);
|
||||
case 2 : votes2.add(p);
|
||||
case 3 : votes3.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
public int getVotes(Integer map) {
|
||||
switch (map) {
|
||||
case 1 : return votes1.size();
|
||||
case 2 : return votes2.size();
|
||||
case 3 : return votes3.size();
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public Map getForcedMap() {
|
||||
return forcedMap;
|
||||
}
|
||||
|
||||
public Map getWinningMap() {
|
||||
if(forcedMap != null) {
|
||||
return forcedMap;
|
||||
}
|
||||
ArrayList<Integer> votes = new ArrayList<>();
|
||||
votes.add(votes1.size());
|
||||
votes.add(votes2.size());
|
||||
votes.add(votes3.size());
|
||||
int max = Collections.max(votes);
|
||||
return getMap(getMapID(max));
|
||||
}
|
||||
|
||||
public Map getMap(int id) {
|
||||
switch (id) {
|
||||
case 1: return map1;
|
||||
case 2: return map2;
|
||||
case 3: return map3;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
public int getMapID(int votes) {
|
||||
if(votes == votes1.size()) {
|
||||
return 1;
|
||||
}
|
||||
if(votes == votes2.size()) {
|
||||
return 2;
|
||||
}
|
||||
if(votes == votes3.size()) {
|
||||
return 3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setVotingMaps() {
|
||||
ArrayList<Map> temp = allMaps;
|
||||
Random random = new Random();
|
||||
map1 = allMaps.get(random.nextInt(temp.size()));
|
||||
temp.remove(map1);
|
||||
map2 = allMaps.get(random.nextInt(temp.size()));
|
||||
temp.remove(map2);
|
||||
map3 = allMaps.get(random.nextInt(temp.size()));
|
||||
temp.remove(map3);
|
||||
|
||||
}
|
||||
|
||||
public void addMap(Map map) {
|
||||
allMaps.add(map);
|
||||
}
|
||||
|
||||
public Inventory getInventory(CustomPlayer p) {
|
||||
if(p.isAllowed(Perms.Ranks.Admin)) {
|
||||
Inventory inv = Bukkit.createInventory(p, 45, invTitle);
|
||||
|
||||
for(Map map : allMaps) {
|
||||
ItemStack item = new ItemStack(map.getItem());
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(map.getName());
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
lore.add("§aby " + map.getBuilder());
|
||||
meta.setLore(lore);
|
||||
|
||||
inv.addItem(item);
|
||||
}
|
||||
|
||||
return inv;
|
||||
}else{
|
||||
Inventory inv = Bukkit.createInventory(p, 9, invTitle);
|
||||
|
||||
ItemStack map1 = new ItemStack(this.map1.getItem());
|
||||
ItemMeta map1Meta = map1.getItemMeta();
|
||||
map1Meta.setDisplayName(this.map1.getName());
|
||||
ArrayList<String> map1Lore = new ArrayList<>();
|
||||
map1Lore.add("§aby " + this.map1.getBuilder());
|
||||
map1Meta.setLore(map1Lore);
|
||||
map1.setItemMeta(map1Meta);
|
||||
|
||||
ItemStack map2 = new ItemStack(this.map2.getItem());
|
||||
ItemMeta map2Meta = map2.getItemMeta();
|
||||
map2Meta.setDisplayName(this.map2.getName());
|
||||
ArrayList<String> map2Lore = new ArrayList<>();
|
||||
map2Lore.add("§aby " + this.map2.getBuilder());
|
||||
map2Meta.setLore(map2Lore);
|
||||
map2.setItemMeta(map2Meta);
|
||||
|
||||
ItemStack map3 = new ItemStack(this.map3.getItem());
|
||||
ItemMeta map3Meta = map3.getItemMeta();
|
||||
map3Meta.setDisplayName(this.map3.getName());
|
||||
ArrayList<String> map3Lore = new ArrayList<>();
|
||||
map3Lore.add("§aby " + this.map3.getBuilder());
|
||||
map3Meta.setLore(map3Lore);
|
||||
map3.setItemMeta(map3Meta);
|
||||
|
||||
inv.setItem(1, map1);
|
||||
inv.setItem(4, map2);
|
||||
inv.setItem(7, map3);
|
||||
|
||||
return inv;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent e) {
|
||||
if(e.getWhoClicked() instanceof Player) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getWhoClicked().getName());
|
||||
if(e.getInventory().getName().equals(invTitle)) {
|
||||
if(p.isAllowed(Perms.Ranks.Admin)) {
|
||||
allMaps.stream().filter(map -> e.getCurrentItem().getType() == map.getItem()).forEach(map -> {
|
||||
forcedMap = map;
|
||||
});
|
||||
}else{
|
||||
if(e.getCurrentItem().getType() == map1.getItem()) {
|
||||
vote(p, 1);
|
||||
p.closeInventory();
|
||||
}
|
||||
if(e.getCurrentItem().getType() == map2.getItem()) {
|
||||
vote(p, 2);
|
||||
p.closeInventory();
|
||||
}
|
||||
if(e.getCurrentItem().getType() == map3.getItem()) {
|
||||
vote(p, 3);
|
||||
p.closeInventory();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void registerListener(Plugin plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
}
|
|
@ -1,148 +1,148 @@
|
|||
package eu.univento.core.api.player;
|
||||
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.database.MySQL;
|
||||
import eu.univento.core.api.utils.NameFetcher;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* bans and unbans players
|
||||
* @author joethei
|
||||
* @version 1.2
|
||||
*/
|
||||
public class BanSystem{
|
||||
|
||||
/**
|
||||
* sets player banned
|
||||
* @param p player
|
||||
* @param reason reason
|
||||
* @param who who banned
|
||||
* @param time duration
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
* @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();
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
|
||||
Date date = new Date();
|
||||
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 + "');");
|
||||
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);
|
||||
sql.closeConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* unbans a player
|
||||
* @param p player
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
* @throws ClassNotFoundException class couldn't be found
|
||||
*/
|
||||
static void removeAllBans(CustomPlayer p) throws SQLException, ClassNotFoundException{
|
||||
int id = p.getID();
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("DELETE FROM bans WHERE ID ='" + id + "';");
|
||||
st.execute();
|
||||
sql.closeConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if player is banned
|
||||
* @param p player
|
||||
* @return true /false
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
* @throws ClassNotFoundException class couldn't be found
|
||||
*/
|
||||
static boolean isBanned(CustomPlayer p) throws SQLException, ClassNotFoundException {
|
||||
int id = p.getID();
|
||||
MySQL sql = Core.returnSQL();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT * FROM bans WHERE ID='" + id + "';");
|
||||
ResultSet rs = st.executeQuery();
|
||||
if(rs.next()) {
|
||||
Date date = new Date();
|
||||
Timestamp time = new Timestamp(date.getTime());
|
||||
sql.closeConnection();
|
||||
return time.before(getBanTime(p));
|
||||
}else {
|
||||
sql.closeConnection();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static Timestamp getBanTime(CustomPlayer p) throws SQLException {
|
||||
int id = p.getID();
|
||||
MySQL sql = Core.returnSQL();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT * FROM bans WHERE ID='" + id + "';");
|
||||
ResultSet rs = st.executeQuery();
|
||||
if(rs.next()) {
|
||||
Timestamp time = rs.getTimestamp("until");
|
||||
sql.closeConnection();
|
||||
return time;
|
||||
}
|
||||
sql.closeConnection();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* return reason for ban
|
||||
* @param p player
|
||||
* @return String
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
* @throws ClassNotFoundException class couldn't be found
|
||||
*/
|
||||
static String getBanReason(CustomPlayer p)throws SQLException, ClassNotFoundException {
|
||||
int id = p.getID();
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT * FROM bans WHERE ID='" + id + "';");
|
||||
ResultSet rs = st.executeQuery();
|
||||
if(rs.next()) {
|
||||
String reason = rs.getString("Reason");
|
||||
sql.closeConnection();
|
||||
return reason;
|
||||
}else {
|
||||
sql.closeConnection();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the name of the player who banned the player
|
||||
* @param p player
|
||||
* @return String
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
* @throws ClassNotFoundException class couldn't be found
|
||||
*/
|
||||
static String getWhoBanned(CustomPlayer p)throws SQLException, ClassNotFoundException {
|
||||
int id = p.getID();
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
ResultSet rs = Core.returnSQL().getConnection().createStatement().executeQuery("SELECT * FROM bans WHERE ID='" + id + "';");
|
||||
if (!rs.next()) {
|
||||
sql.closeConnection();
|
||||
return null;
|
||||
}
|
||||
String whouuid = rs.getString("who");
|
||||
UUID who = UUID.fromString(whouuid);
|
||||
List<UUID> list = new ArrayList<>();
|
||||
list.add(who);
|
||||
NameFetcher name = new NameFetcher(list);
|
||||
sql.closeConnection();
|
||||
return name.toString();
|
||||
}
|
||||
package eu.univento.core.api.player;
|
||||
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.database.MySQL;
|
||||
import eu.univento.core.api.utils.NameFetcher;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* bans and unbans players
|
||||
* @author joethei
|
||||
* @version 1.2
|
||||
*/
|
||||
public class BanSystem{
|
||||
|
||||
/**
|
||||
* sets player banned
|
||||
* @param p player
|
||||
* @param reason reason
|
||||
* @param who who banned
|
||||
* @param time duration
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
* @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();
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
|
||||
Date date = new Date();
|
||||
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 + "');");
|
||||
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);
|
||||
sql.closeConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* unbans a player
|
||||
* @param p player
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
* @throws ClassNotFoundException class couldn't be found
|
||||
*/
|
||||
static void removeAllBans(CustomPlayer p) throws SQLException, ClassNotFoundException{
|
||||
int id = p.getID();
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("DELETE FROM bans WHERE ID ='" + id + "';");
|
||||
st.execute();
|
||||
sql.closeConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if player is banned
|
||||
* @param p player
|
||||
* @return true /false
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
* @throws ClassNotFoundException class couldn't be found
|
||||
*/
|
||||
static boolean isBanned(CustomPlayer p) throws SQLException, ClassNotFoundException {
|
||||
int id = p.getID();
|
||||
MySQL sql = Core.returnSQL();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT * FROM bans WHERE BID='" + id + "';");
|
||||
ResultSet rs = st.executeQuery();
|
||||
if(rs.next()) {
|
||||
Date date = new Date();
|
||||
Timestamp time = new Timestamp(date.getTime());
|
||||
sql.closeConnection();
|
||||
return time.before(getBanTime(p));
|
||||
}else {
|
||||
sql.closeConnection();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static Timestamp getBanTime(CustomPlayer p) throws SQLException {
|
||||
int id = p.getID();
|
||||
MySQL sql = Core.returnSQL();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT * FROM bans WHERE ID='" + id + "';");
|
||||
ResultSet rs = st.executeQuery();
|
||||
if(rs.next()) {
|
||||
Timestamp time = rs.getTimestamp("until");
|
||||
sql.closeConnection();
|
||||
return time;
|
||||
}
|
||||
sql.closeConnection();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* return reason for ban
|
||||
* @param p player
|
||||
* @return String
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
* @throws ClassNotFoundException class couldn't be found
|
||||
*/
|
||||
static String getBanReason(CustomPlayer p)throws SQLException, ClassNotFoundException {
|
||||
int id = p.getID();
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT * FROM bans WHERE ID='" + id + "';");
|
||||
ResultSet rs = st.executeQuery();
|
||||
if(rs.next()) {
|
||||
String reason = rs.getString("Reason");
|
||||
sql.closeConnection();
|
||||
return reason;
|
||||
}else {
|
||||
sql.closeConnection();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the name of the player who banned the player
|
||||
* @param p player
|
||||
* @return String
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
* @throws ClassNotFoundException class couldn't be found
|
||||
*/
|
||||
static String getWhoBanned(CustomPlayer p)throws SQLException, ClassNotFoundException {
|
||||
int id = p.getID();
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
ResultSet rs = Core.returnSQL().getConnection().createStatement().executeQuery("SELECT * FROM bans WHERE ID='" + id + "';");
|
||||
if (!rs.next()) {
|
||||
sql.closeConnection();
|
||||
return null;
|
||||
}
|
||||
String whouuid = rs.getString("who");
|
||||
UUID who = UUID.fromString(whouuid);
|
||||
List<UUID> list = new ArrayList<>();
|
||||
list.add(who);
|
||||
NameFetcher name = new NameFetcher(list);
|
||||
sql.closeConnection();
|
||||
return name.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package eu.univento.core.api.player;
|
||||
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.database.MySQL;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* coins management
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Coins{
|
||||
|
||||
/**
|
||||
* gets coins from player
|
||||
* @param p CustomPlayer
|
||||
* @return coins as integer
|
||||
*/
|
||||
static int getCoins(CustomPlayer p) {
|
||||
int id = p.getID();
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT Coins FROM users WHERE ID='" + id + "';");
|
||||
ResultSet rs = st.executeQuery();
|
||||
if(rs.next()) {
|
||||
int coins = rs.getInt("Coins");
|
||||
sql.closeConnection();
|
||||
return coins;
|
||||
}
|
||||
return 0;
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sets coins of player
|
||||
* @param p CustomPlayer
|
||||
* @param coins coins to set
|
||||
*/
|
||||
static void setCoins(CustomPlayer p, int coins) {
|
||||
int id = p.getID();
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("UPDATE users SET Coins='" + coins + "' WHERE ID='" + id + "';");
|
||||
st.execute();
|
||||
sql.closeConnection();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,832 @@
|
|||
package eu.univento.core.api.player;
|
||||
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.Actionbar;
|
||||
import eu.univento.core.api.Utils;
|
||||
import eu.univento.core.api.database.MySQL;
|
||||
import eu.univento.core.api.effects.Effects;
|
||||
import eu.univento.core.api.languages.Messages;
|
||||
import eu.univento.core.api.server.Game;
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import eu.univento.core.api.server.Servers;
|
||||
import eu.univento.core.api.utils.NameFetcher;
|
||||
import net.minecraft.server.v1_9_R1.EnumParticle;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeModifier;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* custom player implementation
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class CustomPlayer extends CraftPlayer {
|
||||
|
||||
/**
|
||||
* all normal players
|
||||
*/
|
||||
private static final HashMap<String, CustomPlayer> PLAYERS = new HashMap<>();
|
||||
|
||||
/**
|
||||
* normal player
|
||||
*/
|
||||
private final Player PLAYER;
|
||||
|
||||
/**
|
||||
* custom prefix for chat
|
||||
*/
|
||||
private String customPrefix;
|
||||
/**
|
||||
* custom suffix for chat
|
||||
*/
|
||||
private String customSuffix;
|
||||
/**
|
||||
* custom color for chat
|
||||
*/
|
||||
private String customColor;
|
||||
|
||||
/**
|
||||
* player id from database
|
||||
*/
|
||||
private int id = 0;
|
||||
|
||||
/**
|
||||
* if player has open inventory
|
||||
*/
|
||||
private boolean openInventory;
|
||||
|
||||
//private MongoDB mongoDB = Core.getMongoDB();
|
||||
//private MongoCollection userCollection = mongoDB.getDatabase().getCollection("users");
|
||||
|
||||
/**
|
||||
* inits player
|
||||
*
|
||||
* @param player Player
|
||||
*/
|
||||
private CustomPlayer(Player player) {
|
||||
super((CraftServer) Bukkit.getServer(), ((CraftPlayer) player).getHandle());
|
||||
PLAYERS.put(player.getName().toLowerCase(), this);
|
||||
PLAYER = player;
|
||||
id = getID();
|
||||
}
|
||||
|
||||
/**
|
||||
* called on player leaving
|
||||
*/
|
||||
public void onLeave() {
|
||||
/**
|
||||
Date date = new Date();
|
||||
Document doc = new Document("uuid", getUniqueId());
|
||||
userCollection.updateOne(doc, new Document("$set", new Document("lastOnline", date)));
|
||||
|
||||
HashMap<String, Object> location = new HashMap<>();
|
||||
location.put("X", getLocation().getX());
|
||||
location.put("Y", getLocation().getY());
|
||||
location.put("Z", getLocation().getZ());
|
||||
location.put("Yaw", getLocation().getYaw());
|
||||
location.put("Pitch", getLocation().getPitch());
|
||||
|
||||
userCollection.updateOne(doc, new Document("$set", new Document("Pos", new Document("Loc", location))));
|
||||
|
||||
*/
|
||||
if (PLAYERS.containsKey(getName().toLowerCase())) PLAYERS.remove(getName().toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* init player
|
||||
*
|
||||
* @param player Player
|
||||
* @return CustomPlayer
|
||||
*/
|
||||
public static CustomPlayer getPlayer(String player) {
|
||||
if (PLAYERS.containsKey(player.toLowerCase())) {
|
||||
return PLAYERS.get(player.toLowerCase());
|
||||
} else {
|
||||
Player p = Bukkit.getPlayer(player);
|
||||
return p == null ? null : new CustomPlayer(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets custom player from player
|
||||
*
|
||||
* @param player Player
|
||||
* @return CustomPlayer
|
||||
*/
|
||||
public static CustomPlayer getPlayer(Player player) {
|
||||
return getPlayer(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* gets custom player from database id
|
||||
*
|
||||
* @param id database id of player
|
||||
* @return CustomPlayer
|
||||
*/
|
||||
public static CustomPlayer getPlayer(int id) {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT ID, UUID FROM users WHERE ID='" + id + "');");
|
||||
ResultSet rs = st.executeQuery();
|
||||
String uuidString = rs.getString("UUID");
|
||||
sql.closeConnection();
|
||||
UUID uuid = UUID.fromString(uuidString);
|
||||
NameFetcher names = new NameFetcher(Arrays.asList(uuid));
|
||||
Map<UUID, String> map = null;
|
||||
try {
|
||||
map = names.call();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String name = map.toString();
|
||||
String Name = name.substring(name.indexOf('=') + 1, name.indexOf('}'));
|
||||
|
||||
return CustomPlayer.getPlayer(Name);
|
||||
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets database id of player
|
||||
*
|
||||
* @return Integer
|
||||
*/
|
||||
public int getID() {
|
||||
if (id == 0) {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
String uuid = this.getUniqueId().toString();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT * FROM users WHERE UUID ='" + uuid + "';");
|
||||
ResultSet rs = st.executeQuery();
|
||||
if (rs.next()) {
|
||||
int id = rs.getInt("ID");
|
||||
this.id = id;
|
||||
sql.closeConnection();
|
||||
return id;
|
||||
} else {
|
||||
sql.closeConnection();
|
||||
|
||||
return 0;
|
||||
}
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get normal player
|
||||
*
|
||||
* @return Player
|
||||
*/
|
||||
public Player getPLAYER() {
|
||||
return PLAYER;
|
||||
}
|
||||
|
||||
/**
|
||||
public void insertToDatabase() {
|
||||
DBObject obj = new BasicDBObject("uuid", getUniqueId());
|
||||
Date date = new Date();
|
||||
|
||||
obj.put("rank", "Player");
|
||||
obj.put("firstLogin", date);
|
||||
obj.put("lastLogin", date);
|
||||
obj.put("lastOnline", date);
|
||||
obj.put("lastIP", spigot().getRawAddress().getHostName());
|
||||
obj.put("tsid", 0);
|
||||
obj.put("timesJoined", 1);
|
||||
obj.put("timePlayed", 0);
|
||||
obj.put("coins", 0);
|
||||
obj.put("experience", 0);
|
||||
obj.put("secrets", 0);
|
||||
obj.put("foundSecrets", new ArrayList<String>());
|
||||
obj.put("foundEggs", new ArrayList<String>());
|
||||
|
||||
HashMap<String, Object> settings = new HashMap<>();
|
||||
settings.put("playerVisibility", "all");
|
||||
settings.put("inventoryAnimation", true);
|
||||
settings.put("teleportAnimation", true);
|
||||
settings.put("partyRequests", true);
|
||||
settings.put("friendRequests", true);
|
||||
settings.put("friendJump", true);
|
||||
settings.put("chatSounds", true);
|
||||
settings.put("effects", true);
|
||||
settings.put("storyMode", true);
|
||||
settings.put("language", "EN");
|
||||
|
||||
obj.put("Settings", settings);
|
||||
|
||||
HashMap<String, Object> location = new HashMap<>();
|
||||
location.put("X", getLocation().getX());
|
||||
location.put("Y", getLocation().getY());
|
||||
location.put("Z", getLocation().getZ());
|
||||
location.put("Yaw", getLocation().getYaw());
|
||||
location.put("Pitch", getLocation().getPitch());
|
||||
|
||||
obj.put("Pos", location);
|
||||
userCollection.insertOne(obj);
|
||||
}
|
||||
|
||||
public void updateDatabaseEntry() {
|
||||
Date date = new Date();
|
||||
Document doc = new Document("uuid", getUniqueId());
|
||||
userCollection.updateOne(doc, new Document("$set", new Document("lastLogin", date)));
|
||||
userCollection.updateOne(doc, new Document("$set", new Document("lastIP", spigot().getRawAddress().getHostName().toString())));
|
||||
userCollection.updateOne(doc, new Document("$set", new Document("timesPlayed", getTimesJoined() + 1)));
|
||||
}
|
||||
|
||||
|
||||
public void setRank(Perms.Ranks rank) {
|
||||
userCollection.updateOne(new Document("uuid", getUniqueId()), new Document("$set", new Document("rank", rank.toString())));
|
||||
}
|
||||
|
||||
public void setTSID(int id) {
|
||||
userCollection.updateOne(new Document("uuid", getUniqueId()), new Document("$set", new Document("tsid", id)));
|
||||
}
|
||||
|
||||
public void setCoins(int coins) {
|
||||
userCollection.updateOne(new Document("uuid", getUniqueId()), new Document("$set", new Document("coins", coins)));
|
||||
}
|
||||
|
||||
public void setExperience(int experience) {
|
||||
userCollection.updateOne(new Document("uuid", getUniqueId()), new Document("$set", new Document("experience", experience)));
|
||||
}
|
||||
|
||||
public void setSecrets(int secrets) {
|
||||
userCollection.updateOne(new Document("uuid", getUniqueId()), new Document("$set", new Document("secrets", secrets)));
|
||||
}
|
||||
|
||||
|
||||
private Object getObjectFromDatbase(String name) {
|
||||
FindIterable<Document> cursor = userCollection.find(new Document("uuid", getUniqueId()));
|
||||
cursor.cursorType(CursorType.NonTailable);
|
||||
|
||||
Document doc = cursor.first();
|
||||
if (doc == null) {
|
||||
return null;
|
||||
}
|
||||
return doc.get(name);
|
||||
}
|
||||
|
||||
private int getIntegerFromDatabase(String name) {
|
||||
FindIterable<Document> cursor = userCollection.find(new Document("uuid", getUniqueId()));
|
||||
cursor.cursorType(CursorType.NonTailable);
|
||||
|
||||
Document doc = cursor.first();
|
||||
if (doc == null) {
|
||||
return 0;
|
||||
}
|
||||
return doc.getInteger(name);
|
||||
}
|
||||
|
||||
private String getStringFromDatabase(String name) {
|
||||
FindIterable<Document> cursor = userCollection.find(new Document("uuid", getUniqueId()));
|
||||
cursor.cursorType(CursorType.NonTailable);
|
||||
|
||||
Document doc = cursor.first();
|
||||
if (doc == null) {
|
||||
return null;
|
||||
}
|
||||
return doc.getString(name);
|
||||
}
|
||||
|
||||
private Date getDateFromDatabase(String name) {
|
||||
FindIterable<Document> cursor = userCollection.find(new Document("uuid", getUniqueId()));
|
||||
cursor.cursorType(CursorType.NonTailable);
|
||||
|
||||
Document doc = cursor.first();
|
||||
if (doc == null) {
|
||||
return null;
|
||||
}
|
||||
return doc.getDate(name);
|
||||
}
|
||||
|
||||
public Perms.Ranks getRank() {
|
||||
return Perms.Ranks.valueOf(getStringFromDatabase("rank"));
|
||||
}
|
||||
|
||||
public Date getFirstLogin() {
|
||||
return getDateFromDatabase("firstLogin");
|
||||
}
|
||||
|
||||
public Date getLastLogin() {
|
||||
return getDateFromDatabase("lastLogin");
|
||||
}
|
||||
|
||||
public Date getLastOnline() {
|
||||
return getDateFromDatabase("lastOnline");
|
||||
}
|
||||
|
||||
public String getLastIP() {
|
||||
return getStringFromDatabase("lastIP");
|
||||
}
|
||||
|
||||
public int getTSID() {
|
||||
return getIntegerFromDatabase("tsid");
|
||||
}
|
||||
|
||||
public int getTimesJoined() {
|
||||
return getIntegerFromDatabase("timesJoined");
|
||||
}
|
||||
|
||||
public int getCoins() {
|
||||
return getIntegerFromDatabase("coins");
|
||||
}
|
||||
|
||||
public int getExperience() {
|
||||
return getIntegerFromDatabase("experience");
|
||||
}
|
||||
|
||||
public int getSecrets() {
|
||||
return getIntegerFromDatabase("secrets");
|
||||
}
|
||||
|
||||
public ArrayList<String> getFoundSecrets() {
|
||||
return (ArrayList<String>) getObjectFromDatbase("foundSecrets");
|
||||
}
|
||||
|
||||
public ArrayList<String> getFoundEggs() {
|
||||
return (ArrayList<String>) getObjectFromDatbase("foundEggs");
|
||||
}
|
||||
|
||||
public HashMap<String, Object> getSettings() {
|
||||
return (HashMap<String, Object>) getObjectFromDatbase("settings");
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* connects player to server in bungeecord
|
||||
* @param server ServerPinger to connect to
|
||||
*/
|
||||
public void connectToServer(String server) {
|
||||
Servers.connectServer(PLAYER, server);
|
||||
}
|
||||
|
||||
/**
|
||||
* if player is allowed to do stuff
|
||||
* @param rank Ranks
|
||||
* @return true/false
|
||||
*/
|
||||
public boolean isAllowed(Perms.Ranks rank) {
|
||||
try {
|
||||
return Perms.isAllowed(this, rank);
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* rank of player
|
||||
* @return Ranks
|
||||
*/
|
||||
public Perms.Ranks getRank() {
|
||||
try {
|
||||
return Perms.getRank(this);
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
return Perms.Ranks.Player;
|
||||
}
|
||||
}
|
||||
|
||||
public Perms.Ranks getFreshRank() {
|
||||
try{
|
||||
return Perms.getRankFresh(this);
|
||||
}catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
return Perms.Ranks.Player;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sets rank of this custom player
|
||||
* @param r Ranks
|
||||
*/
|
||||
public void setRank(Perms.Ranks r) {
|
||||
try {
|
||||
Perms.setRank(this, r);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* prefix of player
|
||||
* @return String
|
||||
*/
|
||||
public String getPrefix() {
|
||||
if(customPrefix != null) return customPrefix;
|
||||
if(isNicked()) return Perms.getPrefix(Perms.Ranks.Premium);
|
||||
return Perms.getPrefix(getRank());
|
||||
}
|
||||
|
||||
/**
|
||||
* suffix of player
|
||||
* @return String
|
||||
*/
|
||||
public String getSuffix() {
|
||||
if(customSuffix != null) return customSuffix;
|
||||
if(isNicked()) return Perms.getSuffix(Perms.Ranks.Premium);
|
||||
return Perms.getSuffix(getRank());
|
||||
}
|
||||
|
||||
/**
|
||||
* color of player (Ranks)
|
||||
* @return String
|
||||
*/
|
||||
public String getColor() {
|
||||
if(customColor != null) return customColor;
|
||||
if(isNicked()) return Perms.getColor(Perms.Ranks.Premium);
|
||||
return Perms.getColor(getRank());
|
||||
}
|
||||
|
||||
public Color getArmorColor() {
|
||||
return Perms.getArmorColor(getRank());
|
||||
}
|
||||
|
||||
/**
|
||||
* sets a custom prefix
|
||||
* @param prefix String
|
||||
*/
|
||||
public void setCustomPrefix(String prefix) {
|
||||
customPrefix = prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets a custom suffix
|
||||
* @param suffix String
|
||||
*/
|
||||
public void setCustomSuffix(String suffix) {
|
||||
customSuffix = suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets a custom color
|
||||
* @param color String
|
||||
*/
|
||||
public void setCustomColor(String color) {
|
||||
customColor = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets scoreboard team for player
|
||||
* @return Team
|
||||
*/
|
||||
public Team getTeam() {
|
||||
Perms.Teams teams = new Perms.Teams(this);
|
||||
if(isNicked()) {
|
||||
return teams.Premium;
|
||||
}else {
|
||||
return Perms.Teams.getTeam(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* bans player
|
||||
* @param reason why ban him ?
|
||||
* @param who who banned him ?
|
||||
* @param time ban duration
|
||||
*/
|
||||
public void ban(String reason, CustomPlayer who, Integer time) {
|
||||
try {
|
||||
BanSystem.setBanned(this, reason, who, time);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* if player is banned
|
||||
* @return true/false
|
||||
*/
|
||||
public boolean isBanned() {
|
||||
try {
|
||||
return BanSystem.isBanned(this);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get ban reason
|
||||
* @return String
|
||||
*/
|
||||
public String getBanReason() {
|
||||
try {
|
||||
return BanSystem.getBanReason(this);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* get uuid of player who banned
|
||||
* @return String
|
||||
*/
|
||||
public String getWhoBanned() {
|
||||
try {
|
||||
return BanSystem.getWhoBanned(this);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Timestamp getBanTime() {
|
||||
try {
|
||||
return BanSystem.getBanTime(this);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* unbans the player
|
||||
*/
|
||||
public void removeAllBans() {
|
||||
try {
|
||||
BanSystem.removeAllBans(this);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get nickname of player
|
||||
* @return String
|
||||
*/
|
||||
public String getNick() {
|
||||
return NickName.getNick(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* if player is nicked
|
||||
* @return true/false
|
||||
*/
|
||||
public boolean isNicked() {
|
||||
if(ServerSettings.isGame()) {
|
||||
try {
|
||||
return NickName.isNicked(this);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if player is nicked
|
||||
* @return true/false
|
||||
*/
|
||||
public boolean isNickedReal() {
|
||||
try {
|
||||
return NickName.isNicked(this);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets nickname
|
||||
* @param is boolean
|
||||
*/
|
||||
public void setNicked(boolean is) {
|
||||
try {
|
||||
NickName.setNick(this, is);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void nick(String nick) {
|
||||
NickName.setName(this, nick);
|
||||
NickName.changeSkin(this, nick);
|
||||
}
|
||||
|
||||
public void unnick() {
|
||||
NickName.changeSkin(this, getName());
|
||||
NickName.setName(this, getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if player has played on the network before
|
||||
* @return true/false
|
||||
*/
|
||||
@Override
|
||||
public boolean hasPlayedBefore() {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
String uuid = this.getUniqueId().toString();
|
||||
ResultSet rs = sql.getConnection().createStatement().executeQuery("SELECT * FROM users WHERE UUID= '" + uuid + "';");
|
||||
if (rs.next()) {
|
||||
sql.closeConnection();
|
||||
return true;
|
||||
}else {
|
||||
sql.closeConnection();
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if inventory is empty
|
||||
* @return true/false
|
||||
*/
|
||||
public boolean hasEmptyInventory() {
|
||||
return Utils.hasEmptyInventory(PLAYER);
|
||||
}
|
||||
|
||||
/**
|
||||
* clears all potion effects from player
|
||||
*/
|
||||
public void clearPotionEffects() {
|
||||
Utils.clearPotionEffects(PLAYER);
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if players has a open inventory
|
||||
* @return true/false
|
||||
*/
|
||||
public boolean hasOpenInventory() {
|
||||
return openInventory;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets opened inventory
|
||||
* @param openInventory true/false
|
||||
*/
|
||||
public void setOpenInventory(boolean openInventory) {
|
||||
this.openInventory = openInventory;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets coins from player
|
||||
* @return coins as integer
|
||||
*/
|
||||
public int getCoins() {
|
||||
return Coins.getCoins(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* sets coins if player
|
||||
* @param coins coins as integer
|
||||
*/
|
||||
public void setCoins(int coins) {
|
||||
Coins.setCoins(this, coins);
|
||||
}
|
||||
|
||||
/**
|
||||
* adds coins to player coins
|
||||
* @param coins coins as integer
|
||||
*/
|
||||
public void addCoins(int coins) {
|
||||
int temp = Coins.getCoins(this);
|
||||
Coins.setCoins(this, temp + coins);
|
||||
}
|
||||
|
||||
/**
|
||||
* substracts coins from player coins
|
||||
* @param coins coins as integer
|
||||
*/
|
||||
public void substractCoins(int coins) {
|
||||
int temp = Coins.getCoins(this);
|
||||
Coins.setCoins(this, temp - coins);
|
||||
}
|
||||
|
||||
/**
|
||||
* sends message with actionbar to player
|
||||
* @param text String
|
||||
*/
|
||||
public void sendActionBar(String text) {
|
||||
Actionbar.send(PLAYER, text);
|
||||
}
|
||||
|
||||
/**
|
||||
* gets experience from player
|
||||
* @return experience experience as integer
|
||||
*/
|
||||
public int getExperience() {
|
||||
return Experience.getExperience(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* sets experience of player
|
||||
* @param experience experience to set
|
||||
*/
|
||||
public void setExperience(int experience) {
|
||||
Experience.setExperience(this, experience);
|
||||
}
|
||||
|
||||
/**
|
||||
* adds experience to player
|
||||
* @param experience experience to add
|
||||
*/
|
||||
public void addExperience(int experience) {
|
||||
int temp = Experience.getExperience(this);
|
||||
Experience.setExperience(this, temp + experience);
|
||||
setExp(0F);
|
||||
giveExp(getExperience());
|
||||
playSound(getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
/**
|
||||
* removes experience from player
|
||||
* @param experience experience to remove
|
||||
*/
|
||||
public void substractExperience(int experience) {
|
||||
int temp = Experience.getExperience(this);
|
||||
Experience.setExperience(this, temp - experience);
|
||||
setExp(0F);
|
||||
giveExp(getExperience());
|
||||
}
|
||||
|
||||
public void refreshExperience() {
|
||||
setLevel(0);
|
||||
setExp(0F);
|
||||
giveExp(getExperience());
|
||||
}
|
||||
|
||||
public int getFoundSecrets() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
return "DE";
|
||||
}
|
||||
|
||||
public void setLanguage(String lang) {
|
||||
PlayerSettings.set(lang, "lang", this);
|
||||
}
|
||||
|
||||
public boolean isSetting(String setting) {
|
||||
return PlayerSettings.isSet(setting, this);
|
||||
}
|
||||
|
||||
public String getSetting(String setting) { return PlayerSettings.get(setting, this); }
|
||||
|
||||
public void changeSetting(String setting) {
|
||||
PlayerSettings.change(setting, this);
|
||||
}
|
||||
|
||||
public void playParticle(Location loc, EnumParticle ep, float f, int count) {
|
||||
if(isSetting("effects"))
|
||||
Effects.playEffectToPlayer(PLAYER, loc, ep, f, count);
|
||||
}
|
||||
|
||||
public void setAttackSpeed(double speed) {
|
||||
AttributeModifier modifier = new AttributeModifier("Core", speed, AttributeModifier.Operation.ADD_NUMBER);
|
||||
getAttribute(Attribute.GENERIC_ATTACK_SPEED).addModifier(modifier);
|
||||
}
|
||||
|
||||
public double getAttackSpeed() {
|
||||
return getAttribute(Attribute.GENERIC_ATTACK_SPEED).getValue();
|
||||
}
|
||||
|
||||
public void resetAttackSpeed() {
|
||||
AttributeModifier modifier = new AttributeModifier("Core", getAttackSpeed(), AttributeModifier.Operation.ADD_NUMBER);
|
||||
getAttribute(Attribute.GENERIC_ATTACK_SPEED).removeModifier(modifier);
|
||||
}
|
||||
|
||||
public Messages getMessages() {
|
||||
return new Messages(this);
|
||||
}
|
||||
|
||||
public Statistics getStatistics(Game game) {
|
||||
return new Statistics(this, game);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package eu.univento.core.api.player;
|
||||
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.database.MySQL;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* experience management
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Experience{
|
||||
|
||||
/**
|
||||
* gets experience from player
|
||||
* @param p CustomPlayer
|
||||
* @return experience as integer
|
||||
*/
|
||||
static int getExperience(CustomPlayer p) {
|
||||
int id = p.getID();
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT Experience FROM users WHERE ID='" + id + "';");
|
||||
ResultSet rs = st.executeQuery();
|
||||
if(rs.next()) {
|
||||
int coins = rs.getInt("Experience");
|
||||
sql.closeConnection();
|
||||
return coins;
|
||||
}
|
||||
return 0;
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sets experience of player
|
||||
* @param p CustomPlayer
|
||||
* @param experience experience to set
|
||||
*/
|
||||
static void setExperience(CustomPlayer p, int experience) {
|
||||
int id = p.getID();
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("UPDATE users SET Experience='" + experience + "' WHERE ID='" + id + "';");
|
||||
st.execute();
|
||||
sql.closeConnection();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
package eu.univento.core.api.player;
|
||||
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.database.MySQL;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* api for friends
|
||||
* @author joethei
|
||||
* @version 1.1
|
||||
*/
|
||||
public class Friends {
|
||||
|
||||
/**
|
||||
* player object
|
||||
*/
|
||||
CustomPlayer player;
|
||||
|
||||
/**
|
||||
* creates the friends object
|
||||
* @param player CustomPlayer
|
||||
*/
|
||||
public Friends(CustomPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets database IDs of friends
|
||||
* @return ArrayList<Integer>
|
||||
*/
|
||||
public ArrayList<Integer> getFriends() {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
ArrayList<Integer> list = new ArrayList<Integer>();
|
||||
ResultSet rs = sql.getConnection().createStatement().executeQuery("SELECT * FROM Friends WHERE Player_ID = '" + player.getID());
|
||||
while(rs.next()) {
|
||||
list.add(rs.getInt("Friend_ID"));
|
||||
}
|
||||
sql.closeConnection();
|
||||
return list;
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add player to friends
|
||||
* @param p CustomPlayer
|
||||
*/
|
||||
public void addFriend(CustomPlayer p) {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement ps = sql.getConnection().prepareStatement("INSERT INTO Friends ('Player_ID', 'Friend_ID') VALUES ('" + player.getID() + "', '" + p.getID() + "');");
|
||||
ps.execute();
|
||||
sql.closeConnection();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* removes player from friends
|
||||
* @param p CustomPlayer
|
||||
*/
|
||||
public void removeFriend(CustomPlayer p) {
|
||||
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() + "');");
|
||||
ps.execute();
|
||||
sql.closeConnection();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if player is friend
|
||||
* @param p CustomPlayer
|
||||
* @return true/false
|
||||
*/
|
||||
public boolean isFriend(CustomPlayer p) {
|
||||
return getFriends().contains(p.getID());
|
||||
}
|
||||
|
||||
/**
|
||||
* counts friends
|
||||
* @return int
|
||||
*/
|
||||
public int countFriends() {
|
||||
return getFriends().size();
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if player has friends
|
||||
* @return true/false
|
||||
*/
|
||||
public boolean hasFriends() {
|
||||
return getFriends().size() >= 0;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,219 @@
|
|||
package eu.univento.core.api.player;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.database.MySQL;
|
||||
import net.minecraft.server.v1_9_R1.Packet;
|
||||
import net.minecraft.server.v1_9_R1.PacketPlayOutEntityDestroy;
|
||||
import net.minecraft.server.v1_9_R1.PacketPlayOutNamedEntitySpawn;
|
||||
import net.minecraft.server.v1_9_R1.PacketPlayOutPlayerInfo;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* gets nick settings for players
|
||||
* @author joethei
|
||||
* @version 1.1
|
||||
*/
|
||||
public class NickName {
|
||||
|
||||
private static HashMap<CustomPlayer, String> nicks = new HashMap<>();
|
||||
|
||||
private static Field nameField = getField(GameProfile.class, "name");
|
||||
/**
|
||||
*
|
||||
* @param p remove nickname from player
|
||||
*/
|
||||
public static void remove(CustomPlayer p) {
|
||||
if (nicks.containsKey(p))
|
||||
nicks.remove(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* sets nick boolean
|
||||
* @param p player
|
||||
* @param nick boolean
|
||||
* @throws ClassNotFoundException Class couldn't be found
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
*/
|
||||
static void setNick(CustomPlayer p, boolean nick) throws SQLException, ClassNotFoundException {
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
if (nick)
|
||||
sql.getConnection().createStatement().executeUpdate("UPDATE PlayerSettings SET nick = '1' WHERE ID = '" + p.getID() + "';");
|
||||
else
|
||||
sql.getConnection().createStatement().executeUpdate("UPDATE PlayerSettings SET nick = '0' WHERE ID = '" + p.getID() + "';");
|
||||
sql.closeConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* gets if player is nicked
|
||||
* @param p player
|
||||
* @return true / false
|
||||
* @throws ClassNotFoundException Class couldn't be found
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
*/
|
||||
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() + "';");
|
||||
if (rs.next()) {
|
||||
boolean is = rs.getInt("nick") == 1;
|
||||
sql.closeConnection();
|
||||
return is;
|
||||
}
|
||||
sql.closeConnection();
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets nickname of player
|
||||
* @param p player
|
||||
* @return String
|
||||
*/
|
||||
static String getNick(CustomPlayer p) {
|
||||
if (nicks.containsKey(p)) {
|
||||
return nicks.get(p);
|
||||
}else if(p.isNicked()){
|
||||
nicks.put(p, getRandomNick());
|
||||
return nicks.get(p);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets random Nickname
|
||||
* @return String
|
||||
*/
|
||||
private static String getRandomNick() {
|
||||
ArrayList<String> names = new ArrayList<>();
|
||||
names.add("GommeHD");
|
||||
names.add("Notch");
|
||||
names.add("12ms");
|
||||
names.add("Coriux");
|
||||
names.add("Kekse");
|
||||
names.add("AFK");
|
||||
names.add("13ms");
|
||||
names.add("Inhaltsangabe");
|
||||
names.add("LassMichEinfach");
|
||||
names.add("Inventar");
|
||||
names.add("DDoS");
|
||||
names.add("Upps");
|
||||
names.add("Hater");
|
||||
names.add("ServerOwner");
|
||||
names.add("HastDuMinecraft");
|
||||
names.add("Telekom");
|
||||
names.add("TeamBlauNurGute");
|
||||
names.add("Stats");
|
||||
names.add("Herbst");
|
||||
names.add("IchHabTwitter");
|
||||
names.add("Versager");
|
||||
names.add("ImmerAmSterben");
|
||||
names.add("Lagmolia");
|
||||
names.add("Bowspammer");
|
||||
names.add("Behindert");
|
||||
names.add("DasProgramm");
|
||||
names.add("DasPlugin");
|
||||
names.add("Staubsauger");
|
||||
names.add("Buchstabe");
|
||||
names.add("gekickt");
|
||||
names.add("Einfachpermaban");
|
||||
names.add("KeinNameWarFrei");
|
||||
names.add("KlopapierIstLeer");
|
||||
names.add("Packungsbeilage");
|
||||
names.add("HabKeinRewiPremium");
|
||||
names.add("PermaBanAufGomme");
|
||||
names.add("Vorteil");
|
||||
names.add("Nachteil");
|
||||
names.add("Oberteil");
|
||||
names.add("Einstellung");
|
||||
names.add("Verbindung");
|
||||
names.add("WarAFKWasWar");
|
||||
|
||||
Random r = new Random();
|
||||
int i = r.nextInt(names.size());
|
||||
|
||||
return names.get(i);
|
||||
}
|
||||
|
||||
static void changeSkin(CustomPlayer p, String name) {
|
||||
Skin skin = new Skin(Bukkit.getOfflinePlayer(name).getUniqueId().toString().replace("_", ""));
|
||||
if(skin.getName() != null) {
|
||||
GameProfile profile = p.getProfile();
|
||||
profile.getProperties().clear();
|
||||
profile.getProperties().put(skin.getName(), new Property(skin.getName(), skin.getValue(), skin.getSignature()));
|
||||
Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
|
||||
for(Player players : Bukkit.getOnlinePlayers()) {
|
||||
players.hidePlayer(p);
|
||||
}
|
||||
}, 1L);
|
||||
Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
|
||||
for(Player players : Bukkit.getOnlinePlayers()) {
|
||||
players.showPlayer(p);
|
||||
}
|
||||
}, 1L);
|
||||
}
|
||||
}
|
||||
|
||||
static void setName(CustomPlayer p, String name) {
|
||||
p.setDisplayName(name);
|
||||
try {
|
||||
nameField.set(p.getProfile(), name);
|
||||
PacketPlayOutEntityDestroy destroy = new PacketPlayOutEntityDestroy(p.getEntityId());
|
||||
sendPacket(destroy);
|
||||
removeFromTablist(p);
|
||||
|
||||
new BukkitRunnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
addToTablist(p);
|
||||
PacketPlayOutNamedEntitySpawn spawn = new PacketPlayOutNamedEntitySpawn(p.getHandle());
|
||||
Bukkit.getOnlinePlayers().stream().filter(players -> !players.equals(p)).forEach(players -> {
|
||||
((CraftPlayer) players).getHandle().playerConnection.sendPacket(spawn);
|
||||
});
|
||||
}
|
||||
|
||||
}.runTaskLater(Core.getInstance(), 4);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void addToTablist(CraftPlayer p) {
|
||||
PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, p.getHandle());
|
||||
sendPacket(packet);
|
||||
}
|
||||
|
||||
private static void removeFromTablist(CraftPlayer cp) {
|
||||
PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, cp.getHandle());
|
||||
sendPacket(packet);
|
||||
}
|
||||
|
||||
private static void sendPacket(Packet<?> packet) {
|
||||
for(Player players : Bukkit.getOnlinePlayers()) {
|
||||
((CraftPlayer)players).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
private static Field getField(Class<?> clazz, String name) {
|
||||
try{
|
||||
Field field = clazz.getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
}catch (NoSuchFieldException | SecurityException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,315 +1,307 @@
|
|||
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.NameTagVisibility;
|
||||
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{
|
||||
|
||||
/**
|
||||
* contains all joined players and there ranks
|
||||
*/
|
||||
private static HashMap<CustomPlayer, Ranks> ranks = new HashMap<>();
|
||||
/**
|
||||
* gets ranks
|
||||
* @return HashMap<CustomPlayer, Ranks>
|
||||
*/
|
||||
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
|
||||
*/
|
||||
public static class Teams {
|
||||
|
||||
CustomPlayer player;
|
||||
public Scoreboard board;
|
||||
|
||||
public Team Admin;
|
||||
public Team SrDeveloper;
|
||||
public Team Developer;
|
||||
public Team SrModerator;
|
||||
public Team Moderator;
|
||||
public Team HeadBuilder;
|
||||
public Team Builder;
|
||||
public Team Supporter;
|
||||
public Team Youtuber;
|
||||
public Team Premium;
|
||||
public Team Player;
|
||||
|
||||
public 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
|
||||
*/
|
||||
public 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.setNameTagVisibility(NameTagVisibility.ALWAYS);
|
||||
SrDeveloper.setNameTagVisibility(NameTagVisibility.ALWAYS);
|
||||
Developer.setNameTagVisibility(NameTagVisibility.ALWAYS);
|
||||
SrModerator.setNameTagVisibility(NameTagVisibility.ALWAYS);
|
||||
HeadBuilder.setNameTagVisibility(NameTagVisibility.ALWAYS);
|
||||
Moderator.setNameTagVisibility(NameTagVisibility.ALWAYS);
|
||||
Builder.setNameTagVisibility(NameTagVisibility.ALWAYS);
|
||||
Supporter.setNameTagVisibility(NameTagVisibility.ALWAYS);
|
||||
Youtuber.setNameTagVisibility(NameTagVisibility.ALWAYS);
|
||||
Premium.setNameTagVisibility(NameTagVisibility.ALWAYS);
|
||||
Player.setNameTagVisibility(NameTagVisibility.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 static enum Ranks{
|
||||
Admin(11),
|
||||
SrDeveloper(10),
|
||||
Developer(9),
|
||||
SrModerator(8),
|
||||
HeadBuilder(7),
|
||||
Moderator(6),
|
||||
Builder(5),
|
||||
Supporter(4),
|
||||
Youtuber(3),
|
||||
Premium(2),
|
||||
Player(1);
|
||||
|
||||
public final int value;
|
||||
|
||||
private Ranks(int n) {
|
||||
this.value = n;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package eu.univento.core.api.player;
|
||||
|
||||
import eu.univento.core.Core;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Scanner;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class Skin {
|
||||
|
||||
String uuid;
|
||||
String name;
|
||||
String value;
|
||||
String signature;
|
||||
|
||||
public Skin(final String uuid) {
|
||||
this.uuid = uuid;
|
||||
this.load();
|
||||
}
|
||||
|
||||
private void load() {
|
||||
try {
|
||||
URL url = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + this.uuid + "?unsigned=false");
|
||||
URLConnection uc = url.openConnection();
|
||||
uc.setUseCaches(false);
|
||||
uc.setDefaultUseCaches(false);
|
||||
uc.addRequestProperty("User-Agent", "Mozilla/5.0");
|
||||
uc.addRequestProperty("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
uc.addRequestProperty("Pragma", "no-cache");
|
||||
String json = new Scanner(uc.getInputStream(), "UTF-8").useDelimiter("\\A").next();
|
||||
JSONParser parser = new JSONParser();
|
||||
Object obj = parser.parse(json);
|
||||
JSONArray properties = (JSONArray)((JSONObject)obj).get("properties");
|
||||
for (int i = 0; i < properties.size(); ++i) {
|
||||
try {
|
||||
JSONObject property = (JSONObject)properties.get(i);
|
||||
String name = (String)property.get("name");
|
||||
String value = (String)property.get("value");
|
||||
String signature = property.containsKey("signature") ? ((String)property.get("signature")) : null;
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.signature = signature;
|
||||
}
|
||||
catch (Exception e) {
|
||||
Core.log(Level.WARNING, "Failed to apply auth property");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {}
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getSignature() {
|
||||
return this.signature;
|
||||
}
|
||||
}
|
|
@ -1,67 +1,67 @@
|
|||
package eu.univento.core.api.player;
|
||||
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Spectator {
|
||||
|
||||
/**
|
||||
* contains all spectators
|
||||
*/
|
||||
private static ArrayList<CustomPlayer> spectators = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* adds player to spectators
|
||||
* @param p CustomPlayer
|
||||
*/
|
||||
public static void add(CustomPlayer p) {
|
||||
for (Player on : Bukkit.getOnlinePlayers()) {
|
||||
on.hidePlayer(p);
|
||||
}
|
||||
spectators.add(p);
|
||||
p.setGameMode(GameMode.ADVENTURE);
|
||||
p.setAllowFlight(true);
|
||||
p.setFlying(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* removes player from spectator
|
||||
* @param p CustomPlayer
|
||||
*/
|
||||
public static void remove(CustomPlayer p) {
|
||||
for (Player on : Bukkit.getOnlinePlayers()) {
|
||||
on.showPlayer(p);
|
||||
}
|
||||
spectators.remove(p);
|
||||
p.setGameMode(ServerSettings.getGameMode());
|
||||
p.setAllowFlight(false);
|
||||
p.setFlying(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* gets all spectators
|
||||
* @return ArrayList<CustomPlayer>
|
||||
*/
|
||||
public static ArrayList<CustomPlayer> getSpectators() {
|
||||
return spectators;
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if players is spectator
|
||||
* @param p CustomPlayer
|
||||
* @return true/false
|
||||
*/
|
||||
public static boolean is(CustomPlayer p) {
|
||||
return spectators.contains(p);
|
||||
}
|
||||
|
||||
package eu.univento.core.api.player;
|
||||
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Spectator {
|
||||
|
||||
/**
|
||||
* contains all spectators
|
||||
*/
|
||||
private static ArrayList<CustomPlayer> spectators = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* adds player to spectators
|
||||
* @param p CustomPlayer
|
||||
*/
|
||||
public static void add(CustomPlayer p) {
|
||||
for (Player on : Bukkit.getOnlinePlayers()) {
|
||||
on.hidePlayer(p);
|
||||
}
|
||||
spectators.add(p);
|
||||
p.setGameMode(GameMode.ADVENTURE);
|
||||
p.setAllowFlight(true);
|
||||
p.setFlying(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* removes player from spectator
|
||||
* @param p CustomPlayer
|
||||
*/
|
||||
public static void remove(CustomPlayer p) {
|
||||
for (Player on : Bukkit.getOnlinePlayers()) {
|
||||
on.showPlayer(p);
|
||||
}
|
||||
spectators.remove(p);
|
||||
p.setGameMode(ServerSettings.getGameMode());
|
||||
p.setAllowFlight(false);
|
||||
p.setFlying(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* gets all spectators
|
||||
* @return ArrayList<CustomPlayer>
|
||||
*/
|
||||
public static ArrayList<CustomPlayer> getSpectators() {
|
||||
return spectators;
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if players is spectator
|
||||
* @param p CustomPlayer
|
||||
* @return true/false
|
||||
*/
|
||||
public static boolean is(CustomPlayer p) {
|
||||
return spectators.contains(p);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,217 @@
|
|||
package eu.univento.core.api.player;
|
||||
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.database.MySQL;
|
||||
import eu.univento.core.api.server.Game;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* statistics management
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Statistics {
|
||||
|
||||
CustomPlayer player;
|
||||
Game game;
|
||||
|
||||
/**
|
||||
* @param player CustomPlayer
|
||||
* @param game Game
|
||||
*/
|
||||
public Statistics(CustomPlayer player, Game game) {
|
||||
this.player = player;
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* gets deaths of player for game
|
||||
* @return Integer
|
||||
*/
|
||||
public int getDeaths() {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT Deaths FROM " + game.toString() + "Stats WHERE ID='" + player.getID() + "');");
|
||||
ResultSet rs = st.executeQuery();
|
||||
int deaths = rs.getInt("Deaths");
|
||||
sql.closeConnection();
|
||||
return deaths;
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sets deaths of player for game
|
||||
* @param deaths Integer
|
||||
*/
|
||||
public void setDeaths(int deaths) {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("UPDATE " + game.toString() + "Stats WHERE ID='" + player.getID() + "' SET Deaths='" + deaths +"');");
|
||||
st.execute();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void addDeath() {
|
||||
setDeaths(getDeaths() + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* gets kills of player for game
|
||||
* @return Integer
|
||||
*/
|
||||
public int getKills() {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT Kills FROM " + game.toString() + "Stats WHERE ID='" + player.getID() + "');");
|
||||
ResultSet rs = st.executeQuery();
|
||||
int kills = rs.getInt("Kills");
|
||||
sql.closeConnection();
|
||||
return kills;
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sets kills of player for game
|
||||
* @param kills Integer
|
||||
*/
|
||||
public void setKills(int kills) {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("UPDATE " + game.toString() + "Stats WHERE ID='" + player.getID() + "' SET Kills='" + kills +"');");
|
||||
st.execute();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void addKill() {
|
||||
setKills(getKills() + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* gets played rounds of player for game
|
||||
* @return Integer
|
||||
*/
|
||||
public int getPlayedRounds() {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT PlayedRounds FROM " + game.toString() + "Stats WHERE ID='" + player.getID() + "');");
|
||||
ResultSet rs = st.executeQuery();
|
||||
int rounds = rs.getInt("PlayedRounds");
|
||||
sql.closeConnection();
|
||||
return rounds;
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sets played rounds of player for game
|
||||
* @param rounds Integer
|
||||
*/
|
||||
public void setPlayedRounds(int rounds) {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("UPDATE " + game.toString() + "Stats WHERE ID='" + player.getID() + "' SET PlayedRounds='" + rounds +"');");
|
||||
st.execute();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void addPlayedRound() {
|
||||
setPlayedRounds(getPlayedRounds() + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* gets playtime of player for game
|
||||
* @return Integer
|
||||
*/
|
||||
public int getPlaytime() {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT Playtime FROM " + game.toString() + "Stats WHERE ID='" + player.getID() + "');");
|
||||
ResultSet rs = st.executeQuery();
|
||||
int time = rs.getInt("Playtime");
|
||||
sql.closeConnection();
|
||||
return time;
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sets playtime of player for game
|
||||
* @param time Integer
|
||||
*/
|
||||
public void setPlaytime(int time) {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("UPDATE " + game.toString() + "Stats WHERE ID='" + player.getID() + "' SET Playtime='" + time +"');");
|
||||
st.execute();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets wins of player for game
|
||||
* @return Integer
|
||||
*/
|
||||
public int getWins() {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT Wins FROM " + game.toString() + "Stats WHERE ID='" + player.getID() + "');");
|
||||
ResultSet rs = st.executeQuery();
|
||||
int wins = rs.getInt("Wins");
|
||||
sql.closeConnection();
|
||||
return wins;
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sets wins of player for game
|
||||
* @param wins Integer
|
||||
*/
|
||||
public void setWins(int wins) {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("UPDATE " + game.toString() + "Stats WHERE ID='" + player.getID() + "' SET Wins='" + wins +"');");
|
||||
st.execute();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void addWin() {
|
||||
setWins(getWins() + 1);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package eu.univento.core.api.server;
|
||||
|
||||
/**
|
||||
* all minigames with description
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public enum Game {
|
||||
|
||||
//TODO: lookout for some TODOs in this file
|
||||
WoolGet,
|
||||
FlagAttack,
|
||||
Free4All,
|
||||
TrashGames,
|
||||
HulkFight,
|
||||
Maya,
|
||||
FallingAttack,
|
||||
Worms
|
||||
}
|
|
@ -13,7 +13,7 @@ import java.sql.SQLException;
|
|||
*/
|
||||
public class ServerDatabase {
|
||||
|
||||
public static String getIP(String name) {
|
||||
static String getIP(String name) {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
|
@ -31,7 +31,7 @@ public class ServerDatabase {
|
|||
}
|
||||
}
|
||||
|
||||
public static int getPort(String name) {
|
||||
static int getPort(String name) {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
|
@ -48,4 +48,22 @@ public class ServerDatabase {
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static String getMotd(String name) {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
PreparedStatement st = sql.getConnection().prepareStatement("SELECT motd FROM Servers WHERE name='" + name + "'");
|
||||
ResultSet rs = st.executeQuery();
|
||||
if(rs.next()) {
|
||||
String motd = rs.getString("motd");
|
||||
sql.closeConnection();
|
||||
return motd;
|
||||
}
|
||||
return null;
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,6 +31,10 @@ public class ServerInfo {
|
|||
return parts[1];
|
||||
}
|
||||
|
||||
public boolean isOnline() {
|
||||
return pinger.isOnline();
|
||||
}
|
||||
|
||||
public int getOnlinePlayers() {
|
||||
return pinger.getPlayerCount();
|
||||
}
|
||||
|
@ -40,7 +44,7 @@ public class ServerInfo {
|
|||
}
|
||||
|
||||
public String getMotd() {
|
||||
return pinger.getMotd();
|
||||
return ServerDatabase.getMotd(name);
|
||||
}
|
||||
|
||||
}
|
|
@ -140,12 +140,14 @@ public class ServerPinger {
|
|||
if(string.startsWith("§")){
|
||||
String[] data = string.split("\0");
|
||||
this.setMotd(data[3]);
|
||||
this.setOnline(true);
|
||||
this.setPlayerCount(Integer.parseInt(data[4]));
|
||||
this.setMaxPlayers(Integer.parseInt(data[5]));
|
||||
}
|
||||
else{
|
||||
String[] data = string.split("§");
|
||||
this.setMotd(data[0]);
|
||||
this.setOnline(true);
|
||||
this.setPlayerCount(Integer.parseInt(data[1]));
|
||||
this.setMaxPlayers(Integer.parseInt(data[2]));
|
||||
}
|
|
@ -15,8 +15,9 @@ public class ServerSettings {
|
|||
private static boolean game;
|
||||
private static Game playedGame;
|
||||
private static GameMode gameMode;
|
||||
private static String gameState;
|
||||
|
||||
public static Game getPlayedGameGame() {
|
||||
public static Game getPlayedGame() {
|
||||
return playedGame;
|
||||
}
|
||||
|
||||
|
@ -71,4 +72,12 @@ public class ServerSettings {
|
|||
public static void setMute(boolean mute) {
|
||||
ServerSettings.mute = mute;
|
||||
}
|
||||
|
||||
public static String getGameState() {
|
||||
return gameState;
|
||||
}
|
||||
|
||||
public static void setGameState(String gameState) {
|
||||
ServerSettings.gameState = gameState;
|
||||
}
|
||||
}
|
|
@ -1,25 +1,25 @@
|
|||
package eu.univento.core.api.twitch;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
|
||||
public class API {
|
||||
public static String readJsonFromUrl(String urlString) throws Exception {
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
URL url = new URL(urlString);
|
||||
reader = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
int read;
|
||||
char[] chars = new char[1024];
|
||||
while ((read = reader.read(chars)) != -1)
|
||||
buffer.append(chars, 0, read);
|
||||
|
||||
return buffer.toString();
|
||||
} finally {
|
||||
if (reader != null)
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
package eu.univento.core.api.twitch;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
|
||||
public class API {
|
||||
public static String readJsonFromUrl(String urlString) throws Exception {
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
URL url = new URL(urlString);
|
||||
reader = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
int read;
|
||||
char[] chars = new char[1024];
|
||||
while ((read = reader.read(chars)) != -1)
|
||||
buffer.append(chars, 0, read);
|
||||
|
||||
return buffer.toString();
|
||||
} finally {
|
||||
if (reader != null)
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,43 +1,43 @@
|
|||
package eu.univento.core.api.twitch;
|
||||
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
|
||||
public class Twitch_API {
|
||||
public static Gson gson = new Gson();
|
||||
|
||||
|
||||
|
||||
|
||||
public static Twitch_Stream getStream(String channelname){
|
||||
try{
|
||||
String json = API.readJsonFromUrl("http://api.justin.tv/api/stream/list.json?channel="+channelname);
|
||||
|
||||
|
||||
Twitch_Stream stream = new Twitch_Stream();
|
||||
if(json.equalsIgnoreCase("[]")){
|
||||
stream.setOnline(false);
|
||||
return stream;
|
||||
}
|
||||
JsonArray jb = gson.fromJson(json, JsonArray.class);
|
||||
JsonObject jo = (JsonObject) jb.get(0);
|
||||
stream.setOnline(true);
|
||||
stream.load(jo);
|
||||
return stream;
|
||||
} catch (Exception error){
|
||||
error.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
package eu.univento.core.api.twitch;
|
||||
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
|
||||
public class Twitch_API {
|
||||
public static Gson gson = new Gson();
|
||||
|
||||
|
||||
|
||||
|
||||
public static Twitch_Stream getStream(String channelname){
|
||||
try{
|
||||
String json = API.readJsonFromUrl("http://api.justin.tv/api/stream/list.json?channel="+channelname);
|
||||
|
||||
|
||||
Twitch_Stream stream = new Twitch_Stream();
|
||||
if(json.equalsIgnoreCase("[]")){
|
||||
stream.setOnline(false);
|
||||
return stream;
|
||||
}
|
||||
JsonArray jb = gson.fromJson(json, JsonArray.class);
|
||||
JsonObject jo = (JsonObject) jb.get(0);
|
||||
stream.setOnline(true);
|
||||
stream.load(jo);
|
||||
return stream;
|
||||
} catch (Exception error){
|
||||
error.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -1,380 +1,380 @@
|
|||
package eu.univento.core.api.twitch;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class Twitch_Stream {
|
||||
boolean online;
|
||||
int broadcast_part;
|
||||
boolean featured;
|
||||
boolean channel_subscription;
|
||||
String id;
|
||||
String category;
|
||||
String title;
|
||||
int channel_count;
|
||||
int video_height;
|
||||
int site_count;
|
||||
boolean embed_enabled;
|
||||
String up_time;
|
||||
String meta_game;
|
||||
String format;
|
||||
int embed_count;
|
||||
String stream_type;
|
||||
boolean abuse_reported;
|
||||
int video_width;
|
||||
String geo;
|
||||
String name;
|
||||
String language;
|
||||
int stream_count;
|
||||
double video_bitrate;
|
||||
String broadcaster;
|
||||
int channel_view_count;
|
||||
String username;
|
||||
String status;
|
||||
String channel_url;
|
||||
boolean producer;
|
||||
String subcategory_title;
|
||||
String screen_cap_url_large;
|
||||
String screen_cap_url_small;
|
||||
String screen_cap_url_medium;
|
||||
String screen_cap_url_huge;
|
||||
String timezone;
|
||||
String category_title;
|
||||
int views_count;
|
||||
|
||||
public void load(JsonObject job) {
|
||||
setBroadcast_part(job.get("broadcast_part").getAsInt());
|
||||
setFeatured(job.get("featured").getAsBoolean());
|
||||
setChannel_subscription(job.get("channel_subscription").getAsBoolean());
|
||||
setId(job.get("id").getAsString());
|
||||
setCategory(job.get("category").getAsString());
|
||||
setTitle(job.get("title").getAsString());
|
||||
setChannel_count(job.get("channel_count").getAsInt());
|
||||
setVideo_height(job.get("video_height").getAsInt());
|
||||
setSite_count(job.get("site_count").getAsInt());
|
||||
setEmbed_enabled(job.get("embed_enabled").getAsBoolean());
|
||||
setUp_time(job.get("up_time").getAsString());
|
||||
setMeta_game(job.get("meta_game").getAsString());
|
||||
setFormat(job.get("format").getAsString());
|
||||
setEmbed_count(job.get("embed_count").getAsInt());
|
||||
setStream_type(job.get("stream_type").getAsString());
|
||||
setAbuse_reported(job.get("abuse_reported").getAsBoolean());
|
||||
setVideo_width(job.get("video_width").getAsInt());
|
||||
setGeo(job.get("geo").getAsString());
|
||||
setName(job.get("name").getAsString());
|
||||
setLanguage(job.get("language").getAsString());
|
||||
setStream_count(job.get("stream_count").getAsInt());
|
||||
setVideo_bitrate(job.get("video_bitrate").getAsDouble());
|
||||
setBroadcaster(job.get("broadcaster").getAsString());
|
||||
setChannel_view_count(job.get("channel_view_count").getAsInt());
|
||||
|
||||
setUsername(job.get("channel").getAsJsonObject().get("login").getAsString());
|
||||
setTitle(job.get("channel").getAsJsonObject().get("status").getAsString());
|
||||
setChannel_url(job.get("channel").getAsJsonObject().get("channel_url").getAsString());
|
||||
setProducer(job.get("channel").getAsJsonObject().get("producer").getAsBoolean());
|
||||
|
||||
setSubcategory_title(job.get("channel").getAsJsonObject().get("subcategory_title").getAsString());
|
||||
setScreen_cap_url_large(job.get("channel").getAsJsonObject().get("screen_cap_url_large").getAsString());
|
||||
setScreen_cap_url_small(job.get("channel").getAsJsonObject().get("screen_cap_url_small").getAsString());
|
||||
setScreen_cap_url_medium(job.get("channel").getAsJsonObject().get("screen_cap_url_medium").getAsString());
|
||||
setScreen_cap_url_huge(job.get("channel").getAsJsonObject().get("screen_cap_url_huge").getAsString());
|
||||
setTimezone(job.get("channel").getAsJsonObject().get("timezone").getAsString());
|
||||
setCategory_title(job.get("channel").getAsJsonObject().get("category_title").getAsString());
|
||||
setViews_count(job.get("channel").getAsJsonObject().get("views_count").getAsInt());
|
||||
}
|
||||
|
||||
public boolean isOnline() {
|
||||
return this.online;
|
||||
}
|
||||
|
||||
public void setOnline(boolean online) {
|
||||
this.online = online;
|
||||
}
|
||||
|
||||
public int getBroadcast_part() {
|
||||
return this.broadcast_part;
|
||||
}
|
||||
|
||||
public void setBroadcast_part(int broadcast_part) {
|
||||
this.broadcast_part = broadcast_part;
|
||||
}
|
||||
|
||||
public boolean isFeatured() {
|
||||
return this.featured;
|
||||
}
|
||||
|
||||
public void setFeatured(boolean featured) {
|
||||
this.featured = featured;
|
||||
}
|
||||
|
||||
public boolean isChannel_subscription() {
|
||||
return this.channel_subscription;
|
||||
}
|
||||
|
||||
public void setChannel_subscription(boolean channel_subscription) {
|
||||
this.channel_subscription = channel_subscription;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return this.category;
|
||||
}
|
||||
|
||||
public void setCategory(String category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public int getChannel_count() {
|
||||
return this.channel_count;
|
||||
}
|
||||
|
||||
public void setChannel_count(int channel_count) {
|
||||
this.channel_count = channel_count;
|
||||
}
|
||||
|
||||
public int getVideo_height() {
|
||||
return this.video_height;
|
||||
}
|
||||
|
||||
public void setVideo_height(int video_height) {
|
||||
this.video_height = video_height;
|
||||
}
|
||||
|
||||
public int getSite_count() {
|
||||
return this.site_count;
|
||||
}
|
||||
|
||||
public void setSite_count(int site_count) {
|
||||
this.site_count = site_count;
|
||||
}
|
||||
|
||||
public boolean isEmbed_enabled() {
|
||||
return this.embed_enabled;
|
||||
}
|
||||
|
||||
public void setEmbed_enabled(boolean embed_enabled) {
|
||||
this.embed_enabled = embed_enabled;
|
||||
}
|
||||
|
||||
public String getUp_time() {
|
||||
return this.up_time;
|
||||
}
|
||||
|
||||
public void setUp_time(String up_time) {
|
||||
this.up_time = up_time;
|
||||
}
|
||||
|
||||
public String getMeta_game() {
|
||||
return this.meta_game;
|
||||
}
|
||||
|
||||
public void setMeta_game(String meta_game) {
|
||||
this.meta_game = meta_game;
|
||||
}
|
||||
|
||||
public String getFormat() {
|
||||
return this.format;
|
||||
}
|
||||
|
||||
public void setFormat(String format) {
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
public int getEmbed_count() {
|
||||
return this.embed_count;
|
||||
}
|
||||
|
||||
public void setEmbed_count(int embed_count) {
|
||||
this.embed_count = embed_count;
|
||||
}
|
||||
|
||||
public String getStream_type() {
|
||||
return this.stream_type;
|
||||
}
|
||||
|
||||
public void setStream_type(String stream_type) {
|
||||
this.stream_type = stream_type;
|
||||
}
|
||||
|
||||
public boolean isAbuse_reported() {
|
||||
return this.abuse_reported;
|
||||
}
|
||||
|
||||
public void setAbuse_reported(boolean abuse_reported) {
|
||||
this.abuse_reported = abuse_reported;
|
||||
}
|
||||
|
||||
public int getVideo_width() {
|
||||
return this.video_width;
|
||||
}
|
||||
|
||||
public void setVideo_width(int video_width) {
|
||||
this.video_width = video_width;
|
||||
}
|
||||
|
||||
public String getGeo() {
|
||||
return this.geo;
|
||||
}
|
||||
|
||||
public void setGeo(String geo) {
|
||||
this.geo = geo;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
return this.language;
|
||||
}
|
||||
|
||||
public void setLanguage(String language) {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
public int getStream_count() {
|
||||
return this.stream_count;
|
||||
}
|
||||
|
||||
public void setStream_count(int stream_count) {
|
||||
this.stream_count = stream_count;
|
||||
}
|
||||
|
||||
public double getVideo_bitrate() {
|
||||
return this.video_bitrate;
|
||||
}
|
||||
|
||||
public void setVideo_bitrate(double video_bitrate) {
|
||||
this.video_bitrate = video_bitrate;
|
||||
}
|
||||
|
||||
public String getBroadcaster() {
|
||||
return this.broadcaster;
|
||||
}
|
||||
|
||||
public void setBroadcaster(String broadcaster) {
|
||||
this.broadcaster = broadcaster;
|
||||
}
|
||||
|
||||
public int getChannel_view_count() {
|
||||
return this.channel_view_count;
|
||||
}
|
||||
|
||||
public void setChannel_view_count(int channel_view_count) {
|
||||
this.channel_view_count = channel_view_count;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getChannel_url() {
|
||||
return this.channel_url;
|
||||
}
|
||||
|
||||
public void setChannel_url(String channel_url) {
|
||||
this.channel_url = channel_url;
|
||||
}
|
||||
|
||||
public boolean isProducer() {
|
||||
return this.producer;
|
||||
}
|
||||
|
||||
public void setProducer(boolean producer) {
|
||||
this.producer = producer;
|
||||
}
|
||||
|
||||
public String getSubcategory_title() {
|
||||
return this.subcategory_title;
|
||||
}
|
||||
|
||||
public void setSubcategory_title(String subcategory_title) {
|
||||
this.subcategory_title = subcategory_title;
|
||||
}
|
||||
|
||||
public String getScreen_cap_url_large() {
|
||||
return this.screen_cap_url_large;
|
||||
}
|
||||
|
||||
public void setScreen_cap_url_large(String screen_cap_url_large) {
|
||||
this.screen_cap_url_large = screen_cap_url_large;
|
||||
}
|
||||
|
||||
public String getScreen_cap_url_small() {
|
||||
return this.screen_cap_url_small;
|
||||
}
|
||||
|
||||
public void setScreen_cap_url_small(String screen_cap_url_small) {
|
||||
this.screen_cap_url_small = screen_cap_url_small;
|
||||
}
|
||||
|
||||
public String getScreen_cap_url_medium() {
|
||||
return this.screen_cap_url_medium;
|
||||
}
|
||||
|
||||
public void setScreen_cap_url_medium(String screen_cap_url_medium) {
|
||||
this.screen_cap_url_medium = screen_cap_url_medium;
|
||||
}
|
||||
|
||||
public String getScreen_cap_url_huge() {
|
||||
return this.screen_cap_url_huge;
|
||||
}
|
||||
|
||||
public void setScreen_cap_url_huge(String screen_cap_url_huge) {
|
||||
this.screen_cap_url_huge = screen_cap_url_huge;
|
||||
}
|
||||
|
||||
public String getTimezone() {
|
||||
return this.timezone;
|
||||
}
|
||||
|
||||
public void setTimezone(String timezone) {
|
||||
this.timezone = timezone;
|
||||
}
|
||||
|
||||
public String getCategory_title() {
|
||||
return this.category_title;
|
||||
}
|
||||
|
||||
public void setCategory_title(String category_title) {
|
||||
this.category_title = category_title;
|
||||
}
|
||||
|
||||
public int getViews_count() {
|
||||
return this.views_count;
|
||||
}
|
||||
|
||||
public void setViews_count(int views_count) {
|
||||
this.views_count = views_count;
|
||||
}
|
||||
package eu.univento.core.api.twitch;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class Twitch_Stream {
|
||||
boolean online;
|
||||
int broadcast_part;
|
||||
boolean featured;
|
||||
boolean channel_subscription;
|
||||
String id;
|
||||
String category;
|
||||
String title;
|
||||
int channel_count;
|
||||
int video_height;
|
||||
int site_count;
|
||||
boolean embed_enabled;
|
||||
String up_time;
|
||||
String meta_game;
|
||||
String format;
|
||||
int embed_count;
|
||||
String stream_type;
|
||||
boolean abuse_reported;
|
||||
int video_width;
|
||||
String geo;
|
||||
String name;
|
||||
String language;
|
||||
int stream_count;
|
||||
double video_bitrate;
|
||||
String broadcaster;
|
||||
int channel_view_count;
|
||||
String username;
|
||||
String status;
|
||||
String channel_url;
|
||||
boolean producer;
|
||||
String subcategory_title;
|
||||
String screen_cap_url_large;
|
||||
String screen_cap_url_small;
|
||||
String screen_cap_url_medium;
|
||||
String screen_cap_url_huge;
|
||||
String timezone;
|
||||
String category_title;
|
||||
int views_count;
|
||||
|
||||
public void load(JsonObject job) {
|
||||
setBroadcast_part(job.get("broadcast_part").getAsInt());
|
||||
setFeatured(job.get("featured").getAsBoolean());
|
||||
setChannel_subscription(job.get("channel_subscription").getAsBoolean());
|
||||
setId(job.get("id").getAsString());
|
||||
setCategory(job.get("category").getAsString());
|
||||
setTitle(job.get("title").getAsString());
|
||||
setChannel_count(job.get("channel_count").getAsInt());
|
||||
setVideo_height(job.get("video_height").getAsInt());
|
||||
setSite_count(job.get("site_count").getAsInt());
|
||||
setEmbed_enabled(job.get("embed_enabled").getAsBoolean());
|
||||
setUp_time(job.get("up_time").getAsString());
|
||||
setMeta_game(job.get("meta_game").getAsString());
|
||||
setFormat(job.get("format").getAsString());
|
||||
setEmbed_count(job.get("embed_count").getAsInt());
|
||||
setStream_type(job.get("stream_type").getAsString());
|
||||
setAbuse_reported(job.get("abuse_reported").getAsBoolean());
|
||||
setVideo_width(job.get("video_width").getAsInt());
|
||||
setGeo(job.get("geo").getAsString());
|
||||
setName(job.get("name").getAsString());
|
||||
setLanguage(job.get("language").getAsString());
|
||||
setStream_count(job.get("stream_count").getAsInt());
|
||||
setVideo_bitrate(job.get("video_bitrate").getAsDouble());
|
||||
setBroadcaster(job.get("broadcaster").getAsString());
|
||||
setChannel_view_count(job.get("channel_view_count").getAsInt());
|
||||
|
||||
setUsername(job.get("channel").getAsJsonObject().get("login").getAsString());
|
||||
setTitle(job.get("channel").getAsJsonObject().get("status").getAsString());
|
||||
setChannel_url(job.get("channel").getAsJsonObject().get("channel_url").getAsString());
|
||||
setProducer(job.get("channel").getAsJsonObject().get("producer").getAsBoolean());
|
||||
|
||||
setSubcategory_title(job.get("channel").getAsJsonObject().get("subcategory_title").getAsString());
|
||||
setScreen_cap_url_large(job.get("channel").getAsJsonObject().get("screen_cap_url_large").getAsString());
|
||||
setScreen_cap_url_small(job.get("channel").getAsJsonObject().get("screen_cap_url_small").getAsString());
|
||||
setScreen_cap_url_medium(job.get("channel").getAsJsonObject().get("screen_cap_url_medium").getAsString());
|
||||
setScreen_cap_url_huge(job.get("channel").getAsJsonObject().get("screen_cap_url_huge").getAsString());
|
||||
setTimezone(job.get("channel").getAsJsonObject().get("timezone").getAsString());
|
||||
setCategory_title(job.get("channel").getAsJsonObject().get("category_title").getAsString());
|
||||
setViews_count(job.get("channel").getAsJsonObject().get("views_count").getAsInt());
|
||||
}
|
||||
|
||||
public boolean isOnline() {
|
||||
return this.online;
|
||||
}
|
||||
|
||||
public void setOnline(boolean online) {
|
||||
this.online = online;
|
||||
}
|
||||
|
||||
public int getBroadcast_part() {
|
||||
return this.broadcast_part;
|
||||
}
|
||||
|
||||
public void setBroadcast_part(int broadcast_part) {
|
||||
this.broadcast_part = broadcast_part;
|
||||
}
|
||||
|
||||
public boolean isFeatured() {
|
||||
return this.featured;
|
||||
}
|
||||
|
||||
public void setFeatured(boolean featured) {
|
||||
this.featured = featured;
|
||||
}
|
||||
|
||||
public boolean isChannel_subscription() {
|
||||
return this.channel_subscription;
|
||||
}
|
||||
|
||||
public void setChannel_subscription(boolean channel_subscription) {
|
||||
this.channel_subscription = channel_subscription;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return this.category;
|
||||
}
|
||||
|
||||
public void setCategory(String category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public int getChannel_count() {
|
||||
return this.channel_count;
|
||||
}
|
||||
|
||||
public void setChannel_count(int channel_count) {
|
||||
this.channel_count = channel_count;
|
||||
}
|
||||
|
||||
public int getVideo_height() {
|
||||
return this.video_height;
|
||||
}
|
||||
|
||||
public void setVideo_height(int video_height) {
|
||||
this.video_height = video_height;
|
||||
}
|
||||
|
||||
public int getSite_count() {
|
||||
return this.site_count;
|
||||
}
|
||||
|
||||
public void setSite_count(int site_count) {
|
||||
this.site_count = site_count;
|
||||
}
|
||||
|
||||
public boolean isEmbed_enabled() {
|
||||
return this.embed_enabled;
|
||||
}
|
||||
|
||||
public void setEmbed_enabled(boolean embed_enabled) {
|
||||
this.embed_enabled = embed_enabled;
|
||||
}
|
||||
|
||||
public String getUp_time() {
|
||||
return this.up_time;
|
||||
}
|
||||
|
||||
public void setUp_time(String up_time) {
|
||||
this.up_time = up_time;
|
||||
}
|
||||
|
||||
public String getMeta_game() {
|
||||
return this.meta_game;
|
||||
}
|
||||
|
||||
public void setMeta_game(String meta_game) {
|
||||
this.meta_game = meta_game;
|
||||
}
|
||||
|
||||
public String getFormat() {
|
||||
return this.format;
|
||||
}
|
||||
|
||||
public void setFormat(String format) {
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
public int getEmbed_count() {
|
||||
return this.embed_count;
|
||||
}
|
||||
|
||||
public void setEmbed_count(int embed_count) {
|
||||
this.embed_count = embed_count;
|
||||
}
|
||||
|
||||
public String getStream_type() {
|
||||
return this.stream_type;
|
||||
}
|
||||
|
||||
public void setStream_type(String stream_type) {
|
||||
this.stream_type = stream_type;
|
||||
}
|
||||
|
||||
public boolean isAbuse_reported() {
|
||||
return this.abuse_reported;
|
||||
}
|
||||
|
||||
public void setAbuse_reported(boolean abuse_reported) {
|
||||
this.abuse_reported = abuse_reported;
|
||||
}
|
||||
|
||||
public int getVideo_width() {
|
||||
return this.video_width;
|
||||
}
|
||||
|
||||
public void setVideo_width(int video_width) {
|
||||
this.video_width = video_width;
|
||||
}
|
||||
|
||||
public String getGeo() {
|
||||
return this.geo;
|
||||
}
|
||||
|
||||
public void setGeo(String geo) {
|
||||
this.geo = geo;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
return this.language;
|
||||
}
|
||||
|
||||
public void setLanguage(String language) {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
public int getStream_count() {
|
||||
return this.stream_count;
|
||||
}
|
||||
|
||||
public void setStream_count(int stream_count) {
|
||||
this.stream_count = stream_count;
|
||||
}
|
||||
|
||||
public double getVideo_bitrate() {
|
||||
return this.video_bitrate;
|
||||
}
|
||||
|
||||
public void setVideo_bitrate(double video_bitrate) {
|
||||
this.video_bitrate = video_bitrate;
|
||||
}
|
||||
|
||||
public String getBroadcaster() {
|
||||
return this.broadcaster;
|
||||
}
|
||||
|
||||
public void setBroadcaster(String broadcaster) {
|
||||
this.broadcaster = broadcaster;
|
||||
}
|
||||
|
||||
public int getChannel_view_count() {
|
||||
return this.channel_view_count;
|
||||
}
|
||||
|
||||
public void setChannel_view_count(int channel_view_count) {
|
||||
this.channel_view_count = channel_view_count;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getChannel_url() {
|
||||
return this.channel_url;
|
||||
}
|
||||
|
||||
public void setChannel_url(String channel_url) {
|
||||
this.channel_url = channel_url;
|
||||
}
|
||||
|
||||
public boolean isProducer() {
|
||||
return this.producer;
|
||||
}
|
||||
|
||||
public void setProducer(boolean producer) {
|
||||
this.producer = producer;
|
||||
}
|
||||
|
||||
public String getSubcategory_title() {
|
||||
return this.subcategory_title;
|
||||
}
|
||||
|
||||
public void setSubcategory_title(String subcategory_title) {
|
||||
this.subcategory_title = subcategory_title;
|
||||
}
|
||||
|
||||
public String getScreen_cap_url_large() {
|
||||
return this.screen_cap_url_large;
|
||||
}
|
||||
|
||||
public void setScreen_cap_url_large(String screen_cap_url_large) {
|
||||
this.screen_cap_url_large = screen_cap_url_large;
|
||||
}
|
||||
|
||||
public String getScreen_cap_url_small() {
|
||||
return this.screen_cap_url_small;
|
||||
}
|
||||
|
||||
public void setScreen_cap_url_small(String screen_cap_url_small) {
|
||||
this.screen_cap_url_small = screen_cap_url_small;
|
||||
}
|
||||
|
||||
public String getScreen_cap_url_medium() {
|
||||
return this.screen_cap_url_medium;
|
||||
}
|
||||
|
||||
public void setScreen_cap_url_medium(String screen_cap_url_medium) {
|
||||
this.screen_cap_url_medium = screen_cap_url_medium;
|
||||
}
|
||||
|
||||
public String getScreen_cap_url_huge() {
|
||||
return this.screen_cap_url_huge;
|
||||
}
|
||||
|
||||
public void setScreen_cap_url_huge(String screen_cap_url_huge) {
|
||||
this.screen_cap_url_huge = screen_cap_url_huge;
|
||||
}
|
||||
|
||||
public String getTimezone() {
|
||||
return this.timezone;
|
||||
}
|
||||
|
||||
public void setTimezone(String timezone) {
|
||||
this.timezone = timezone;
|
||||
}
|
||||
|
||||
public String getCategory_title() {
|
||||
return this.category_title;
|
||||
}
|
||||
|
||||
public void setCategory_title(String category_title) {
|
||||
this.category_title = category_title;
|
||||
}
|
||||
|
||||
public int getViews_count() {
|
||||
return this.views_count;
|
||||
}
|
||||
|
||||
public void setViews_count(int views_count) {
|
||||
this.views_count = views_count;
|
||||
}
|
||||
}
|
|
@ -1,37 +1,37 @@
|
|||
package eu.univento.core.api.utils;
|
||||
|
||||
public enum Direction
|
||||
{
|
||||
NORTH(1, 0),
|
||||
SOUTH(-1, 0),
|
||||
EAST(0, 1),
|
||||
WEST(0, -1),
|
||||
NORTHEAST(1, 1),
|
||||
SOUTHEAST(-1, 1),
|
||||
NORTHWEST(1, -1),
|
||||
SOUTHWEST(-1, -1);
|
||||
|
||||
private int x;
|
||||
private int z;
|
||||
|
||||
private Direction(int x, int z) { this.x = x;
|
||||
this.z = z; }
|
||||
|
||||
public int getX()
|
||||
{
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
public static Direction getDirection(String direction) {
|
||||
for (Direction dir : values())
|
||||
{
|
||||
if (dir.name().equalsIgnoreCase(direction))
|
||||
return dir;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
package eu.univento.core.api.utils;
|
||||
|
||||
public enum Direction
|
||||
{
|
||||
NORTH(1, 0),
|
||||
SOUTH(-1, 0),
|
||||
EAST(0, 1),
|
||||
WEST(0, -1),
|
||||
NORTHEAST(1, 1),
|
||||
SOUTHEAST(-1, 1),
|
||||
NORTHWEST(1, -1),
|
||||
SOUTHWEST(-1, -1);
|
||||
|
||||
private int x;
|
||||
private int z;
|
||||
|
||||
private Direction(int x, int z) { this.x = x;
|
||||
this.z = z; }
|
||||
|
||||
public int getX()
|
||||
{
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
public static Direction getDirection(String direction) {
|
||||
for (Direction dir : values())
|
||||
{
|
||||
if (dir.name().equalsIgnoreCase(direction))
|
||||
return dir;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,171 +1,171 @@
|
|||
package eu.univento.core.api.utils;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import com.mojang.util.UUIDTypeAdapter;
|
||||
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Jofkos
|
||||
*/
|
||||
public class GameProfileBuilder {
|
||||
|
||||
private static final String SERVICE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/%s?unsigned=false";
|
||||
private static final String JSON_SKIN = "{\"timestamp\":%d,\"profileId\":\"%s\",\"profileName\":\"%s\",\"isPublic\":true,\"textures\":{\"SKIN\":{\"url\":\"%s\"}}}";
|
||||
private static final String JSON_CAPE = "{\"timestamp\":%d,\"profileId\":\"%s\",\"profileName\":\"%s\",\"isPublic\":true,\"textures\":{\"SKIN\":{\"url\":\"%s\"},\"CAPE\":{\"url\":\"%s\"}}}";
|
||||
|
||||
private static Gson gson = new GsonBuilder().disableHtmlEscaping().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).registerTypeAdapter(GameProfile.class, new GameProfileSerializer()).registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()).create();
|
||||
|
||||
private static HashMap<UUID, CachedProfile> cache = new HashMap<>();
|
||||
|
||||
private static long cacheTime = -1;
|
||||
|
||||
/**
|
||||
* Don't run in main thread!
|
||||
*
|
||||
* Fetches the GameProfile from the Mojang servers
|
||||
*
|
||||
* @param uuid The player uuid
|
||||
* @return The GameProfile
|
||||
* @throws IOException If something wents wrong while fetching
|
||||
* @see GameProfile
|
||||
*/
|
||||
public static GameProfile fetch(UUID uuid) throws IOException {
|
||||
return fetch(uuid, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't run in main thread!
|
||||
*
|
||||
* Fetches the GameProfile from the Mojang servers
|
||||
* @param uuid The player uuid
|
||||
* @param forceNew If true the cache is ignored
|
||||
* @return The GameProfile
|
||||
* @throws IOException If something wents wrong while fetching
|
||||
* @see GameProfile
|
||||
*/
|
||||
public static GameProfile fetch(UUID uuid, boolean forceNew) throws IOException {
|
||||
if (!forceNew && cache.containsKey(uuid) && cache.get(uuid).isValid()) {
|
||||
return cache.get(uuid).profile;
|
||||
} else {
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(String.format(SERVICE_URL, UUIDTypeAdapter.fromUUID(uuid))).openConnection();
|
||||
connection.setReadTimeout(5000);
|
||||
|
||||
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
||||
String json = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine();
|
||||
|
||||
GameProfile result = gson.fromJson(json, GameProfile.class);
|
||||
cache.put(uuid, new CachedProfile(result));
|
||||
return result;
|
||||
} else {
|
||||
if (!forceNew && cache.containsKey(uuid)) {
|
||||
return cache.get(uuid).profile;
|
||||
}
|
||||
JsonObject error = (JsonObject) new JsonParser().parse(new BufferedReader(new InputStreamReader(connection.getErrorStream())).readLine());
|
||||
throw new IOException(error.get("error").getAsString() + ": " + error.get("errorMessage").getAsString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a GameProfile for the specified args
|
||||
*
|
||||
* @param uuid The uuid
|
||||
* @param name The name
|
||||
* @param skin The url from the skin image
|
||||
* @return A GameProfile built from the arguments
|
||||
* @see GameProfile
|
||||
*/
|
||||
public static GameProfile getProfile(UUID uuid, String name, String skin) {
|
||||
return getProfile(uuid, name, skin, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a GameProfile for the specified args
|
||||
*
|
||||
* @param uuid The uuid
|
||||
* @param name The name
|
||||
* @param skinUrl Url from the skin image
|
||||
* @param capeUrl Url from the cape image
|
||||
* @return A GameProfile built from the arguments
|
||||
* @see GameProfile
|
||||
*/
|
||||
public static GameProfile getProfile(UUID uuid, String name, String skinUrl, String capeUrl) {
|
||||
GameProfile profile = new GameProfile(uuid, name);
|
||||
boolean cape = capeUrl != null && !capeUrl.isEmpty();
|
||||
|
||||
List<Object> args = new ArrayList<Object>();
|
||||
args.add(System.currentTimeMillis());
|
||||
args.add(UUIDTypeAdapter.fromUUID(uuid));
|
||||
args.add(name);
|
||||
args.add(skinUrl);
|
||||
if (cape) args.add(capeUrl);
|
||||
|
||||
profile.getProperties().put("textures", new Property("textures", Base64Coder.encodeString(String.format(cape ? JSON_CAPE : JSON_SKIN, args.toArray(new Object[args.size()])))));
|
||||
return profile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the time as long as you want to keep the gameprofiles in cache (-1 = never remove it)
|
||||
* @param time cache time (default = -1)
|
||||
*/
|
||||
public static void setCacheTime(long time) {
|
||||
cacheTime = time;
|
||||
}
|
||||
|
||||
private static class GameProfileSerializer implements JsonSerializer<GameProfile>, JsonDeserializer<GameProfile> {
|
||||
|
||||
public GameProfile deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||
JsonObject object = (JsonObject) json;
|
||||
UUID id = object.has("id") ? (UUID) context.deserialize(object.get("id"), UUID.class) : null;
|
||||
String name = object.has("name") ? object.getAsJsonPrimitive("name").getAsString() : null;
|
||||
GameProfile profile = new GameProfile(id, name);
|
||||
|
||||
if (object.has("properties")) {
|
||||
for (Entry<String, Property> prop : ((PropertyMap) context.deserialize(object.get("properties"), PropertyMap.class)).entries()) {
|
||||
profile.getProperties().put(prop.getKey(), prop.getValue());
|
||||
}
|
||||
}
|
||||
return profile;
|
||||
}
|
||||
|
||||
public JsonElement serialize(GameProfile profile, Type type, JsonSerializationContext context) {
|
||||
JsonObject result = new JsonObject();
|
||||
if (profile.getId() != null)
|
||||
result.add("id", context.serialize(profile.getId()));
|
||||
if (profile.getName() != null)
|
||||
result.addProperty("name", profile.getName());
|
||||
if (!profile.getProperties().isEmpty())
|
||||
result.add("properties", context.serialize(profile.getProperties()));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private static class CachedProfile {
|
||||
|
||||
private long timestamp = System.currentTimeMillis();
|
||||
private GameProfile profile;
|
||||
|
||||
public CachedProfile(GameProfile profile) {
|
||||
this.profile = profile;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return cacheTime < 0 ? true : (System.currentTimeMillis() - timestamp) < cacheTime;
|
||||
}
|
||||
}
|
||||
package eu.univento.core.api.utils;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import com.mojang.util.UUIDTypeAdapter;
|
||||
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Jofkos
|
||||
*/
|
||||
public class GameProfileBuilder {
|
||||
|
||||
private static final String SERVICE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/%s?unsigned=false";
|
||||
private static final String JSON_SKIN = "{\"timestamp\":%d,\"profileId\":\"%s\",\"profileName\":\"%s\",\"isPublic\":true,\"textures\":{\"SKIN\":{\"url\":\"%s\"}}}";
|
||||
private static final String JSON_CAPE = "{\"timestamp\":%d,\"profileId\":\"%s\",\"profileName\":\"%s\",\"isPublic\":true,\"textures\":{\"SKIN\":{\"url\":\"%s\"},\"CAPE\":{\"url\":\"%s\"}}}";
|
||||
|
||||
private static Gson gson = new GsonBuilder().disableHtmlEscaping().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).registerTypeAdapter(GameProfile.class, new GameProfileSerializer()).registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()).create();
|
||||
|
||||
private static HashMap<UUID, CachedProfile> cache = new HashMap<>();
|
||||
|
||||
private static long cacheTime = -1;
|
||||
|
||||
/**
|
||||
* Don't run in main thread!
|
||||
*
|
||||
* Fetches the GameProfile from the Mojang servers
|
||||
*
|
||||
* @param uuid The player uuid
|
||||
* @return The GameProfile
|
||||
* @throws IOException If something wents wrong while fetching
|
||||
* @see GameProfile
|
||||
*/
|
||||
public static GameProfile fetch(UUID uuid) throws IOException {
|
||||
return fetch(uuid, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't run in main thread!
|
||||
*
|
||||
* Fetches the GameProfile from the Mojang servers
|
||||
* @param uuid The player uuid
|
||||
* @param forceNew If true the cache is ignored
|
||||
* @return The GameProfile
|
||||
* @throws IOException If something wents wrong while fetching
|
||||
* @see GameProfile
|
||||
*/
|
||||
public static GameProfile fetch(UUID uuid, boolean forceNew) throws IOException {
|
||||
if (!forceNew && cache.containsKey(uuid) && cache.get(uuid).isValid()) {
|
||||
return cache.get(uuid).profile;
|
||||
} else {
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(String.format(SERVICE_URL, UUIDTypeAdapter.fromUUID(uuid))).openConnection();
|
||||
connection.setReadTimeout(5000);
|
||||
|
||||
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
||||
String json = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine();
|
||||
|
||||
GameProfile result = gson.fromJson(json, GameProfile.class);
|
||||
cache.put(uuid, new CachedProfile(result));
|
||||
return result;
|
||||
} else {
|
||||
if (!forceNew && cache.containsKey(uuid)) {
|
||||
return cache.get(uuid).profile;
|
||||
}
|
||||
JsonObject error = (JsonObject) new JsonParser().parse(new BufferedReader(new InputStreamReader(connection.getErrorStream())).readLine());
|
||||
throw new IOException(error.get("error").getAsString() + ": " + error.get("errorMessage").getAsString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a GameProfile for the specified args
|
||||
*
|
||||
* @param uuid The uuid
|
||||
* @param name The name
|
||||
* @param skin The url from the skin image
|
||||
* @return A GameProfile built from the arguments
|
||||
* @see GameProfile
|
||||
*/
|
||||
public static GameProfile getProfile(UUID uuid, String name, String skin) {
|
||||
return getProfile(uuid, name, skin, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a GameProfile for the specified args
|
||||
*
|
||||
* @param uuid The uuid
|
||||
* @param name The name
|
||||
* @param skinUrl Url from the skin image
|
||||
* @param capeUrl Url from the cape image
|
||||
* @return A GameProfile built from the arguments
|
||||
* @see GameProfile
|
||||
*/
|
||||
public static GameProfile getProfile(UUID uuid, String name, String skinUrl, String capeUrl) {
|
||||
GameProfile profile = new GameProfile(uuid, name);
|
||||
boolean cape = capeUrl != null && !capeUrl.isEmpty();
|
||||
|
||||
List<Object> args = new ArrayList<Object>();
|
||||
args.add(System.currentTimeMillis());
|
||||
args.add(UUIDTypeAdapter.fromUUID(uuid));
|
||||
args.add(name);
|
||||
args.add(skinUrl);
|
||||
if (cape) args.add(capeUrl);
|
||||
|
||||
profile.getProperties().put("textures", new Property("textures", Base64Coder.encodeString(String.format(cape ? JSON_CAPE : JSON_SKIN, args.toArray(new Object[args.size()])))));
|
||||
return profile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the time as long as you want to keep the gameprofiles in cache (-1 = never remove it)
|
||||
* @param time cache time (default = -1)
|
||||
*/
|
||||
public static void setCacheTime(long time) {
|
||||
cacheTime = time;
|
||||
}
|
||||
|
||||
private static class GameProfileSerializer implements JsonSerializer<GameProfile>, JsonDeserializer<GameProfile> {
|
||||
|
||||
public GameProfile deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||
JsonObject object = (JsonObject) json;
|
||||
UUID id = object.has("id") ? (UUID) context.deserialize(object.get("id"), UUID.class) : null;
|
||||
String name = object.has("name") ? object.getAsJsonPrimitive("name").getAsString() : null;
|
||||
GameProfile profile = new GameProfile(id, name);
|
||||
|
||||
if (object.has("properties")) {
|
||||
for (Entry<String, Property> prop : ((PropertyMap) context.deserialize(object.get("properties"), PropertyMap.class)).entries()) {
|
||||
profile.getProperties().put(prop.getKey(), prop.getValue());
|
||||
}
|
||||
}
|
||||
return profile;
|
||||
}
|
||||
|
||||
public JsonElement serialize(GameProfile profile, Type type, JsonSerializationContext context) {
|
||||
JsonObject result = new JsonObject();
|
||||
if (profile.getId() != null)
|
||||
result.add("id", context.serialize(profile.getId()));
|
||||
if (profile.getName() != null)
|
||||
result.addProperty("name", profile.getName());
|
||||
if (!profile.getProperties().isEmpty())
|
||||
result.add("properties", context.serialize(profile.getProperties()));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private static class CachedProfile {
|
||||
|
||||
private long timestamp = System.currentTimeMillis();
|
||||
private GameProfile profile;
|
||||
|
||||
public CachedProfile(GameProfile profile) {
|
||||
this.profile = profile;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return cacheTime < 0 ? true : (System.currentTimeMillis() - timestamp) < cacheTime;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,281 +1,281 @@
|
|||
package eu.univento.core.api.utils;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Random;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class Maths
|
||||
{
|
||||
public static final float nanoToSec = 1.0E-009F;
|
||||
public static final float FLOAT_ROUNDING_ERROR = 1.0E-006F;
|
||||
public static final float PI = 3.141593F;
|
||||
public static final float PI2 = 6.283186F;
|
||||
public static final float SQRT_3 = 1.73205F;
|
||||
public static final float E = 2.718282F;
|
||||
public static final float radiansToDegrees = 57.295776F;
|
||||
public static final float radDeg = 57.295776F;
|
||||
public static final float degreesToRadians = 0.01745329F;
|
||||
public static final float degRad = 0.01745329F;
|
||||
static final int ATAN2_DIM = (int)Math.sqrt(16384.0D);
|
||||
private static final float INV_ATAN2_DIM_MINUS_1 = 1.0F / (ATAN2_DIM - 1);
|
||||
|
||||
public static Random random = new Random();
|
||||
|
||||
public static final float sin(float radians) {
|
||||
return Sin.table[((int)(radians * 2607.5945F) & 0x3FFF)];
|
||||
}
|
||||
|
||||
public static final float cos(float radians)
|
||||
{
|
||||
return Sin.table[((int)((radians + 1.570796F) * 2607.5945F) & 0x3FFF)];
|
||||
}
|
||||
|
||||
public static final float sinDeg(float degrees)
|
||||
{
|
||||
return Sin.table[((int)(degrees * 45.511112F) & 0x3FFF)];
|
||||
}
|
||||
|
||||
public static final float cosDeg(float degrees)
|
||||
{
|
||||
return Sin.table[((int)((degrees + 90.0F) * 45.511112F) & 0x3FFF)];
|
||||
}
|
||||
|
||||
public static final float atan2(float y, float x)
|
||||
{
|
||||
float mul;
|
||||
float add;
|
||||
if (x < 0.0F)
|
||||
{
|
||||
if (y < 0.0F) {
|
||||
y = -y;
|
||||
mul = 1.0F;
|
||||
} else {
|
||||
mul = -1.0F;
|
||||
}x = -x;
|
||||
add = -3.141593F;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (y < 0.0F) {
|
||||
y = -y;
|
||||
mul = -1.0F;
|
||||
} else {
|
||||
mul = 1.0F;
|
||||
}add = 0.0F;
|
||||
}
|
||||
float invDiv = 1.0F / ((x < y ? y : x) * INV_ATAN2_DIM_MINUS_1);
|
||||
|
||||
if (invDiv == 1.0F) return ((float)Math.atan2(y, x) + add) * mul;
|
||||
|
||||
int xi = (int)(x * invDiv);
|
||||
int yi = (int)(y * invDiv);
|
||||
return (Atan2.table[(yi * ATAN2_DIM + xi)] + add) * mul;
|
||||
}
|
||||
|
||||
public static final int random(int range)
|
||||
{
|
||||
return random.nextInt(range + 1);
|
||||
}
|
||||
|
||||
public static final int random(int start, int end)
|
||||
{
|
||||
return start + random.nextInt(end - start + 1);
|
||||
}
|
||||
|
||||
public static final boolean randomBoolean()
|
||||
{
|
||||
return random.nextBoolean();
|
||||
}
|
||||
|
||||
public static final boolean randomBoolean(float chance)
|
||||
{
|
||||
return random() < chance;
|
||||
}
|
||||
|
||||
public static final float random()
|
||||
{
|
||||
return random.nextFloat();
|
||||
}
|
||||
|
||||
public static final float random(float range)
|
||||
{
|
||||
return random.nextFloat() * range;
|
||||
}
|
||||
|
||||
public static final float random(float start, float end)
|
||||
{
|
||||
return start + random.nextFloat() * (end - start);
|
||||
}
|
||||
|
||||
public static int nextPowerOfTwo(int value)
|
||||
{
|
||||
if (value == 0) return 1;
|
||||
value--;
|
||||
value |= value >> 1;
|
||||
value |= value >> 2;
|
||||
value |= value >> 4;
|
||||
value |= value >> 8;
|
||||
value |= value >> 16;
|
||||
return value + 1;
|
||||
}
|
||||
|
||||
public static boolean isPowerOfTwo(int value) {
|
||||
return (value != 0) && ((value & value - 1) == 0);
|
||||
}
|
||||
|
||||
public static int clamp(int value, int min, int max)
|
||||
{
|
||||
if (value < min) return min;
|
||||
if (value > max) return max;
|
||||
return value;
|
||||
}
|
||||
|
||||
public static short clamp(short value, short min, short max) {
|
||||
if (value < min) return min;
|
||||
if (value > max) return max;
|
||||
return value;
|
||||
}
|
||||
|
||||
public static float clamp(float value, float min, float max) {
|
||||
if (value < min) return min;
|
||||
if (value > max) return max;
|
||||
return value;
|
||||
}
|
||||
|
||||
public static int floor(float x)
|
||||
{
|
||||
return (int)(x + 16384.0D) - 16384;
|
||||
}
|
||||
|
||||
public static int floorPositive(float x)
|
||||
{
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
public static int ceil(float x)
|
||||
{
|
||||
return (int)(x + 16384.999999999996D) - 16384;
|
||||
}
|
||||
|
||||
public static int ceilPositive(float x)
|
||||
{
|
||||
return (int)(x + 0.9999999000000001D);
|
||||
}
|
||||
|
||||
public static int round(float x)
|
||||
{
|
||||
return (int)(x + 16384.5D) - 16384;
|
||||
}
|
||||
|
||||
public static int roundPositive(float x)
|
||||
{
|
||||
return (int)(x + 0.5F);
|
||||
}
|
||||
|
||||
public static boolean isZero(float value)
|
||||
{
|
||||
return Math.abs(value) <= 1.0E-006F;
|
||||
}
|
||||
|
||||
public static boolean isZero(float value, float tolerance)
|
||||
{
|
||||
return Math.abs(value) <= tolerance;
|
||||
}
|
||||
|
||||
public static boolean isEqual(float a, float b)
|
||||
{
|
||||
return Math.abs(a - b) <= 1.0E-006F;
|
||||
}
|
||||
|
||||
public static boolean isEqual(float a, float b, float tolerance)
|
||||
{
|
||||
return Math.abs(a - b) <= tolerance;
|
||||
}
|
||||
|
||||
public static long parseDateDiff(String time, boolean future)
|
||||
throws Exception
|
||||
{
|
||||
Pattern timePattern = Pattern.compile("(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?(?:([0-9]+)\\s*(?:s[a-z]*)?)?", 2);
|
||||
Matcher m = timePattern.matcher(time);
|
||||
int years = 0;
|
||||
int months = 0;
|
||||
int weeks = 0;
|
||||
int days = 0;
|
||||
int hours = 0;
|
||||
int minutes = 0;
|
||||
int seconds = 0;
|
||||
boolean found = false;
|
||||
while (m.find()) {
|
||||
if ((m.group() == null) || (m.group().isEmpty())) {
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < m.groupCount(); i++) {
|
||||
if ((m.group(i) != null) && (!m.group(i).isEmpty())) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
if ((m.group(1) != null) && (!m.group(1).isEmpty()))
|
||||
years = Integer.parseInt(m.group(1));
|
||||
if ((m.group(2) != null) && (!m.group(2).isEmpty()))
|
||||
months = Integer.parseInt(m.group(2));
|
||||
if ((m.group(3) != null) && (!m.group(3).isEmpty()))
|
||||
weeks = Integer.parseInt(m.group(3));
|
||||
if ((m.group(4) != null) && (!m.group(4).isEmpty()))
|
||||
days = Integer.parseInt(m.group(4));
|
||||
if ((m.group(5) != null) && (!m.group(5).isEmpty()))
|
||||
hours = Integer.parseInt(m.group(5));
|
||||
if ((m.group(6) != null) && (!m.group(6).isEmpty()))
|
||||
minutes = Integer.parseInt(m.group(6));
|
||||
if ((m.group(7) == null) || (m.group(7).isEmpty())) break;
|
||||
seconds = Integer.parseInt(m.group(7));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
throw new Exception("Illegal Date");
|
||||
Calendar c = new GregorianCalendar();
|
||||
if (years > 0)
|
||||
c.add(1, years * (future ? 1 : -1));
|
||||
if (months > 0)
|
||||
c.add(2, months * (future ? 1 : -1));
|
||||
if (weeks > 0)
|
||||
c.add(3, weeks * (future ? 1 : -1));
|
||||
if (days > 0)
|
||||
c.add(5, days * (future ? 1 : -1));
|
||||
if (hours > 0)
|
||||
c.add(11, hours * (future ? 1 : -1));
|
||||
if (minutes > 0)
|
||||
c.add(12, minutes * (future ? 1 : -1));
|
||||
if (seconds > 0)
|
||||
c.add(13, seconds * (future ? 1 : -1));
|
||||
return c.getTimeInMillis();
|
||||
}
|
||||
|
||||
private static class Atan2
|
||||
{
|
||||
static final float[] table = new float[16384];
|
||||
|
||||
static { for (int i = 0; i < Maths.ATAN2_DIM; i++)
|
||||
for (int j = 0; j < Maths.ATAN2_DIM; j++) {
|
||||
float x0 = i / Maths.ATAN2_DIM;
|
||||
float y0 = j / Maths.ATAN2_DIM;
|
||||
table[(j * Maths.ATAN2_DIM + i)] = (float)Math.atan2(y0, x0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class Sin
|
||||
{
|
||||
static final float[] table = new float[16384];
|
||||
|
||||
static { for (int i = 0; i < 16384; i++)
|
||||
table[i] = (float)Math.sin((i + 0.5F) / 16384.0F * 6.283186F);
|
||||
for (int i = 0; i < 360; i += 90)
|
||||
table[((int)(i * 45.511112F) & 0x3FFF)] = (float)Math.sin(i * 0.01745329F);
|
||||
}
|
||||
}
|
||||
package eu.univento.core.api.utils;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Random;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class Maths
|
||||
{
|
||||
public static final float nanoToSec = 1.0E-009F;
|
||||
public static final float FLOAT_ROUNDING_ERROR = 1.0E-006F;
|
||||
public static final float PI = 3.141593F;
|
||||
public static final float PI2 = 6.283186F;
|
||||
public static final float SQRT_3 = 1.73205F;
|
||||
public static final float E = 2.718282F;
|
||||
public static final float radiansToDegrees = 57.295776F;
|
||||
public static final float radDeg = 57.295776F;
|
||||
public static final float degreesToRadians = 0.01745329F;
|
||||
public static final float degRad = 0.01745329F;
|
||||
static final int ATAN2_DIM = (int)Math.sqrt(16384.0D);
|
||||
private static final float INV_ATAN2_DIM_MINUS_1 = 1.0F / (ATAN2_DIM - 1);
|
||||
|
||||
public static Random random = new Random();
|
||||
|
||||
public static final float sin(float radians) {
|
||||
return Sin.table[((int)(radians * 2607.5945F) & 0x3FFF)];
|
||||
}
|
||||
|
||||
public static final float cos(float radians)
|
||||
{
|
||||
return Sin.table[((int)((radians + 1.570796F) * 2607.5945F) & 0x3FFF)];
|
||||
}
|
||||
|
||||
public static final float sinDeg(float degrees)
|
||||
{
|
||||
return Sin.table[((int)(degrees * 45.511112F) & 0x3FFF)];
|
||||
}
|
||||
|
||||
public static final float cosDeg(float degrees)
|
||||
{
|
||||
return Sin.table[((int)((degrees + 90.0F) * 45.511112F) & 0x3FFF)];
|
||||
}
|
||||
|
||||
public static final float atan2(float y, float x)
|
||||
{
|
||||
float mul;
|
||||
float add;
|
||||
if (x < 0.0F)
|
||||
{
|
||||
if (y < 0.0F) {
|
||||
y = -y;
|
||||
mul = 1.0F;
|
||||
} else {
|
||||
mul = -1.0F;
|
||||
}x = -x;
|
||||
add = -3.141593F;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (y < 0.0F) {
|
||||
y = -y;
|
||||
mul = -1.0F;
|
||||
} else {
|
||||
mul = 1.0F;
|
||||
}add = 0.0F;
|
||||
}
|
||||
float invDiv = 1.0F / ((x < y ? y : x) * INV_ATAN2_DIM_MINUS_1);
|
||||
|
||||
if (invDiv == 1.0F) return ((float)Math.atan2(y, x) + add) * mul;
|
||||
|
||||
int xi = (int)(x * invDiv);
|
||||
int yi = (int)(y * invDiv);
|
||||
return (Atan2.table[(yi * ATAN2_DIM + xi)] + add) * mul;
|
||||
}
|
||||
|
||||
public static final int random(int range)
|
||||
{
|
||||
return random.nextInt(range + 1);
|
||||
}
|
||||
|
||||
public static final int random(int start, int end)
|
||||
{
|
||||
return start + random.nextInt(end - start + 1);
|
||||
}
|
||||
|
||||
public static final boolean randomBoolean()
|
||||
{
|
||||
return random.nextBoolean();
|
||||
}
|
||||
|
||||
public static final boolean randomBoolean(float chance)
|
||||
{
|
||||
return random() < chance;
|
||||
}
|
||||
|
||||
public static final float random()
|
||||
{
|
||||
return random.nextFloat();
|
||||
}
|
||||
|
||||
public static final float random(float range)
|
||||
{
|
||||
return random.nextFloat() * range;
|
||||
}
|
||||
|
||||
public static final float random(float start, float end)
|
||||
{
|
||||
return start + random.nextFloat() * (end - start);
|
||||
}
|
||||
|
||||
public static int nextPowerOfTwo(int value)
|
||||
{
|
||||
if (value == 0) return 1;
|
||||
value--;
|
||||
value |= value >> 1;
|
||||
value |= value >> 2;
|
||||
value |= value >> 4;
|
||||
value |= value >> 8;
|
||||
value |= value >> 16;
|
||||
return value + 1;
|
||||
}
|
||||
|
||||
public static boolean isPowerOfTwo(int value) {
|
||||
return (value != 0) && ((value & value - 1) == 0);
|
||||
}
|
||||
|
||||
public static int clamp(int value, int min, int max)
|
||||
{
|
||||
if (value < min) return min;
|
||||
if (value > max) return max;
|
||||
return value;
|
||||
}
|
||||
|
||||
public static short clamp(short value, short min, short max) {
|
||||
if (value < min) return min;
|
||||
if (value > max) return max;
|
||||
return value;
|
||||
}
|
||||
|
||||
public static float clamp(float value, float min, float max) {
|
||||
if (value < min) return min;
|
||||
if (value > max) return max;
|
||||
return value;
|
||||
}
|
||||
|
||||
public static int floor(float x)
|
||||
{
|
||||
return (int)(x + 16384.0D) - 16384;
|
||||
}
|
||||
|
||||
public static int floorPositive(float x)
|
||||
{
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
public static int ceil(float x)
|
||||
{
|
||||
return (int)(x + 16384.999999999996D) - 16384;
|
||||
}
|
||||
|
||||
public static int ceilPositive(float x)
|
||||
{
|
||||
return (int)(x + 0.9999999000000001D);
|
||||
}
|
||||
|
||||
public static int round(float x)
|
||||
{
|
||||
return (int)(x + 16384.5D) - 16384;
|
||||
}
|
||||
|
||||
public static int roundPositive(float x)
|
||||
{
|
||||
return (int)(x + 0.5F);
|
||||
}
|
||||
|
||||
public static boolean isZero(float value)
|
||||
{
|
||||
return Math.abs(value) <= 1.0E-006F;
|
||||
}
|
||||
|
||||
public static boolean isZero(float value, float tolerance)
|
||||
{
|
||||
return Math.abs(value) <= tolerance;
|
||||
}
|
||||
|
||||
public static boolean isEqual(float a, float b)
|
||||
{
|
||||
return Math.abs(a - b) <= 1.0E-006F;
|
||||
}
|
||||
|
||||
public static boolean isEqual(float a, float b, float tolerance)
|
||||
{
|
||||
return Math.abs(a - b) <= tolerance;
|
||||
}
|
||||
|
||||
public static long parseDateDiff(String time, boolean future)
|
||||
throws Exception
|
||||
{
|
||||
Pattern timePattern = Pattern.compile("(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?(?:([0-9]+)\\s*(?:s[a-z]*)?)?", 2);
|
||||
Matcher m = timePattern.matcher(time);
|
||||
int years = 0;
|
||||
int months = 0;
|
||||
int weeks = 0;
|
||||
int days = 0;
|
||||
int hours = 0;
|
||||
int minutes = 0;
|
||||
int seconds = 0;
|
||||
boolean found = false;
|
||||
while (m.find()) {
|
||||
if ((m.group() == null) || (m.group().isEmpty())) {
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < m.groupCount(); i++) {
|
||||
if ((m.group(i) != null) && (!m.group(i).isEmpty())) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
if ((m.group(1) != null) && (!m.group(1).isEmpty()))
|
||||
years = Integer.parseInt(m.group(1));
|
||||
if ((m.group(2) != null) && (!m.group(2).isEmpty()))
|
||||
months = Integer.parseInt(m.group(2));
|
||||
if ((m.group(3) != null) && (!m.group(3).isEmpty()))
|
||||
weeks = Integer.parseInt(m.group(3));
|
||||
if ((m.group(4) != null) && (!m.group(4).isEmpty()))
|
||||
days = Integer.parseInt(m.group(4));
|
||||
if ((m.group(5) != null) && (!m.group(5).isEmpty()))
|
||||
hours = Integer.parseInt(m.group(5));
|
||||
if ((m.group(6) != null) && (!m.group(6).isEmpty()))
|
||||
minutes = Integer.parseInt(m.group(6));
|
||||
if ((m.group(7) == null) || (m.group(7).isEmpty())) break;
|
||||
seconds = Integer.parseInt(m.group(7));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
throw new Exception("Illegal Date");
|
||||
Calendar c = new GregorianCalendar();
|
||||
if (years > 0)
|
||||
c.add(1, years * (future ? 1 : -1));
|
||||
if (months > 0)
|
||||
c.add(2, months * (future ? 1 : -1));
|
||||
if (weeks > 0)
|
||||
c.add(3, weeks * (future ? 1 : -1));
|
||||
if (days > 0)
|
||||
c.add(5, days * (future ? 1 : -1));
|
||||
if (hours > 0)
|
||||
c.add(11, hours * (future ? 1 : -1));
|
||||
if (minutes > 0)
|
||||
c.add(12, minutes * (future ? 1 : -1));
|
||||
if (seconds > 0)
|
||||
c.add(13, seconds * (future ? 1 : -1));
|
||||
return c.getTimeInMillis();
|
||||
}
|
||||
|
||||
private static class Atan2
|
||||
{
|
||||
static final float[] table = new float[16384];
|
||||
|
||||
static { for (int i = 0; i < Maths.ATAN2_DIM; i++)
|
||||
for (int j = 0; j < Maths.ATAN2_DIM; j++) {
|
||||
float x0 = i / Maths.ATAN2_DIM;
|
||||
float y0 = j / Maths.ATAN2_DIM;
|
||||
table[(j * Maths.ATAN2_DIM + i)] = (float)Math.atan2(y0, x0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class Sin
|
||||
{
|
||||
static final float[] table = new float[16384];
|
||||
|
||||
static { for (int i = 0; i < 16384; i++)
|
||||
table[i] = (float)Math.sin((i + 0.5F) / 16384.0F * 6.283186F);
|
||||
for (int i = 0; i < 360; i += 90)
|
||||
table[((int)(i * 45.511112F) & 0x3FFF)] = (float)Math.sin(i * 0.01745329F);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,49 +1,49 @@
|
|||
package eu.univento.core.api.utils;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class NameFetcher implements Callable<Map<UUID, String>>{
|
||||
private static final String PROFILE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/";
|
||||
private final JSONParser jsonParser = new JSONParser();
|
||||
private final List<UUID> uuids;
|
||||
|
||||
public NameFetcher(List<UUID> uuids)
|
||||
{
|
||||
this.uuids = ImmutableList.copyOf(uuids);
|
||||
}
|
||||
|
||||
public Map<UUID, String> call() throws Exception
|
||||
{
|
||||
Map<UUID, String> uuidStringMap = new HashMap<UUID, String>();
|
||||
for (UUID uuid : this.uuids) {
|
||||
HttpURLConnection connection = (HttpURLConnection)new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid.toString().replace("-", "")).openConnection();
|
||||
JSONObject response = (JSONObject)this.jsonParser.parse(new InputStreamReader(connection.getInputStream()));
|
||||
String name = (String)response.get("name");
|
||||
if (name == null) {
|
||||
continue;
|
||||
}
|
||||
String cause = (String)response.get("cause");
|
||||
String errorMessage = (String)response.get("errorMessage");
|
||||
if ((cause != null) && (cause.length() > 0)) {
|
||||
throw new IllegalStateException(errorMessage);
|
||||
}
|
||||
uuidStringMap.put(uuid, name);
|
||||
}
|
||||
return uuidStringMap;
|
||||
}
|
||||
|
||||
public static String getProfileUrl() {
|
||||
return PROFILE_URL;
|
||||
}
|
||||
package eu.univento.core.api.utils;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class NameFetcher implements Callable<Map<UUID, String>>{
|
||||
private static final String PROFILE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/";
|
||||
private final JSONParser jsonParser = new JSONParser();
|
||||
private final List<UUID> uuids;
|
||||
|
||||
public NameFetcher(List<UUID> uuids)
|
||||
{
|
||||
this.uuids = ImmutableList.copyOf(uuids);
|
||||
}
|
||||
|
||||
public Map<UUID, String> call() throws Exception
|
||||
{
|
||||
Map<UUID, String> uuidStringMap = new HashMap<UUID, String>();
|
||||
for (UUID uuid : this.uuids) {
|
||||
HttpURLConnection connection = (HttpURLConnection)new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid.toString().replace("-", "")).openConnection();
|
||||
JSONObject response = (JSONObject)this.jsonParser.parse(new InputStreamReader(connection.getInputStream()));
|
||||
String name = (String)response.get("name");
|
||||
if (name == null) {
|
||||
continue;
|
||||
}
|
||||
String cause = (String)response.get("cause");
|
||||
String errorMessage = (String)response.get("errorMessage");
|
||||
if ((cause != null) && (cause.length() > 0)) {
|
||||
throw new IllegalStateException(errorMessage);
|
||||
}
|
||||
uuidStringMap.put(uuid, name);
|
||||
}
|
||||
return uuidStringMap;
|
||||
}
|
||||
|
||||
public static String getProfileUrl() {
|
||||
return PROFILE_URL;
|
||||
}
|
||||
}
|
|
@ -1,41 +1,41 @@
|
|||
package eu.univento.core.api.utils;
|
||||
|
||||
import java.util.NavigableMap;
|
||||
import java.util.Random;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class RandomCollection<E>
|
||||
{
|
||||
private final NavigableMap<Double, E> map = new TreeMap<Double, E>();
|
||||
private final Random random;
|
||||
private double total = 0.0D;
|
||||
|
||||
public RandomCollection() {
|
||||
this(new Random());
|
||||
}
|
||||
|
||||
public RandomCollection(Random random) {
|
||||
this.random = random;
|
||||
}
|
||||
|
||||
public void add(double weight, E result) {
|
||||
if (weight <= 0.0D) return;
|
||||
this.total += weight;
|
||||
this.map.put(Double.valueOf(this.total), result);
|
||||
}
|
||||
|
||||
public E next() {
|
||||
double value = this.random.nextDouble() * this.total;
|
||||
return this.map.ceilingEntry(Double.valueOf(value)).getValue();
|
||||
}
|
||||
|
||||
public E random() {
|
||||
double value = this.random.nextDouble() * this.total;
|
||||
|
||||
while (this.random.nextBoolean()) {
|
||||
value = this.random.nextDouble() * this.total;
|
||||
}
|
||||
|
||||
return this.map.ceilingEntry(Double.valueOf(value)).getValue();
|
||||
}
|
||||
package eu.univento.core.api.utils;
|
||||
|
||||
import java.util.NavigableMap;
|
||||
import java.util.Random;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class RandomCollection<E>
|
||||
{
|
||||
private final NavigableMap<Double, E> map = new TreeMap<Double, E>();
|
||||
private final Random random;
|
||||
private double total = 0.0D;
|
||||
|
||||
public RandomCollection() {
|
||||
this(new Random());
|
||||
}
|
||||
|
||||
public RandomCollection(Random random) {
|
||||
this.random = random;
|
||||
}
|
||||
|
||||
public void add(double weight, E result) {
|
||||
if (weight <= 0.0D) return;
|
||||
this.total += weight;
|
||||
this.map.put(Double.valueOf(this.total), result);
|
||||
}
|
||||
|
||||
public E next() {
|
||||
double value = this.random.nextDouble() * this.total;
|
||||
return this.map.ceilingEntry(Double.valueOf(value)).getValue();
|
||||
}
|
||||
|
||||
public E random() {
|
||||
double value = this.random.nextDouble() * this.total;
|
||||
|
||||
while (this.random.nextBoolean()) {
|
||||
value = this.random.nextDouble() * this.total;
|
||||
}
|
||||
|
||||
return this.map.ceilingEntry(Double.valueOf(value)).getValue();
|
||||
}
|
||||
}
|
|
@ -1,45 +1,45 @@
|
|||
package eu.univento.core.api.utils;
|
||||
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public final class Vectors
|
||||
{
|
||||
public static final Vector rotateAroundAxisX(Vector v, double angle)
|
||||
{
|
||||
double cos = Math.cos(angle);
|
||||
double sin = Math.sin(angle);
|
||||
double y = v.getY() * cos - v.getZ() * sin;
|
||||
double z = v.getY() * sin + v.getZ() * cos;
|
||||
return v.setY(y).setZ(z);
|
||||
}
|
||||
|
||||
public static final Vector rotateAroundAxisY(Vector v, double angle)
|
||||
{
|
||||
double cos = Math.cos(angle);
|
||||
double sin = Math.sin(angle);
|
||||
double x = v.getX() * cos + v.getZ() * sin;
|
||||
double z = v.getX() * -sin + v.getZ() * cos;
|
||||
return v.setX(x).setZ(z);
|
||||
}
|
||||
|
||||
public static final Vector rotateAroundAxisZ(Vector v, double angle)
|
||||
{
|
||||
double cos = Math.cos(angle);
|
||||
double sin = Math.sin(angle);
|
||||
double x = v.getX() * cos - v.getY() * sin;
|
||||
double y = v.getX() * sin + v.getY() * cos;
|
||||
return v.setX(x).setY(y);
|
||||
}
|
||||
|
||||
public static final Vector rotateVector(Vector v, double angleX, double angleY, double angleZ)
|
||||
{
|
||||
rotateAroundAxisX(v, angleX);
|
||||
rotateAroundAxisY(v, angleY);
|
||||
rotateAroundAxisZ(v, angleZ);
|
||||
return v;
|
||||
}
|
||||
|
||||
public static final double angleToXAxis(Vector vector) {
|
||||
return Math.atan2(vector.getX(), vector.getY());
|
||||
}
|
||||
package eu.univento.core.api.utils;
|
||||
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public final class Vectors
|
||||
{
|
||||
public static final Vector rotateAroundAxisX(Vector v, double angle)
|
||||
{
|
||||
double cos = Math.cos(angle);
|
||||
double sin = Math.sin(angle);
|
||||
double y = v.getY() * cos - v.getZ() * sin;
|
||||
double z = v.getY() * sin + v.getZ() * cos;
|
||||
return v.setY(y).setZ(z);
|
||||
}
|
||||
|
||||
public static final Vector rotateAroundAxisY(Vector v, double angle)
|
||||
{
|
||||
double cos = Math.cos(angle);
|
||||
double sin = Math.sin(angle);
|
||||
double x = v.getX() * cos + v.getZ() * sin;
|
||||
double z = v.getX() * -sin + v.getZ() * cos;
|
||||
return v.setX(x).setZ(z);
|
||||
}
|
||||
|
||||
public static final Vector rotateAroundAxisZ(Vector v, double angle)
|
||||
{
|
||||
double cos = Math.cos(angle);
|
||||
double sin = Math.sin(angle);
|
||||
double x = v.getX() * cos - v.getY() * sin;
|
||||
double y = v.getX() * sin + v.getY() * cos;
|
||||
return v.setX(x).setY(y);
|
||||
}
|
||||
|
||||
public static final Vector rotateVector(Vector v, double angleX, double angleY, double angleZ)
|
||||
{
|
||||
rotateAroundAxisX(v, angleX);
|
||||
rotateAroundAxisY(v, angleY);
|
||||
rotateAroundAxisZ(v, angleZ);
|
||||
return v;
|
||||
}
|
||||
|
||||
public static final double angleToXAxis(Vector vector) {
|
||||
return Math.atan2(vector.getX(), vector.getY());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,606 @@
|
|||
package eu.univento.core.api.utils.reflection;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <b>ReflectionUtils</b>
|
||||
* <p>
|
||||
* This class provides useful methods which makes dealing with reflection much easier, especially when working with Bukkit
|
||||
* <p>
|
||||
* You are welcome to use it, modify it and redistribute it under the following conditions:
|
||||
* <ul>
|
||||
* <li>Don't claim this class as your own
|
||||
* <li>Don't remove this disclaimer
|
||||
* </ul>
|
||||
* <p>
|
||||
* <i>It would be nice if you provide credit to me if you use this class in a published project</i>
|
||||
*
|
||||
* @author DarkBlade12
|
||||
* @version 1.1
|
||||
*/
|
||||
public final class ReflectionUtils {
|
||||
// Prevent accidental construction
|
||||
private ReflectionUtils() {}
|
||||
|
||||
/**
|
||||
* Returns the constructor of a given class with the given parameter types
|
||||
*
|
||||
* @param clazz Target class
|
||||
* @param parameterTypes Parameter types of the desired constructor
|
||||
* @return The constructor of the target class with the specified parameter types
|
||||
* @throws NoSuchMethodException If the desired constructor with the specified parameter types cannot be found
|
||||
* @see DataType
|
||||
* @see DataType#getPrimitive(Class[])
|
||||
* @see DataType#compare(Class[], Class[])
|
||||
*/
|
||||
public static Constructor<?> getConstructor(Class<?> clazz, Class<?>... parameterTypes) throws NoSuchMethodException {
|
||||
Class<?>[] primitiveTypes = DataType.getPrimitive(parameterTypes);
|
||||
for (Constructor<?> constructor : clazz.getConstructors()) {
|
||||
if (!DataType.compare(DataType.getPrimitive(constructor.getParameterTypes()), primitiveTypes)) {
|
||||
continue;
|
||||
}
|
||||
return constructor;
|
||||
}
|
||||
throw new NoSuchMethodException("There is no such constructor in this class with the specified parameter types");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the constructor of a desired class with the given parameter types
|
||||
*
|
||||
* @param className Name of the desired target class
|
||||
* @param packageType Package where the desired target class is located
|
||||
* @param parameterTypes Parameter types of the desired constructor
|
||||
* @return The constructor of the desired target class with the specified parameter types
|
||||
* @throws NoSuchMethodException If the desired constructor with the specified parameter types cannot be found
|
||||
* @throws ClassNotFoundException ClassNotFoundException If the desired target class with the specified name and package cannot be found
|
||||
* @see #getClass(String, PackageType)
|
||||
* @see #getConstructor(Class, Class...)
|
||||
*/
|
||||
public static Constructor<?> getConstructor(String className, PackageType packageType, Class<?>... parameterTypes) throws NoSuchMethodException, ClassNotFoundException {
|
||||
return getConstructor(packageType.getClass(className), parameterTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of a class with the given arguments
|
||||
*
|
||||
* @param clazz Target class
|
||||
* @param arguments Arguments which are used to construct an object of the target class
|
||||
* @return The instance of the target class with the specified arguments
|
||||
* @throws InstantiationException If you cannot create an instance of the target class due to certain circumstances
|
||||
* @throws IllegalAccessException If the desired constructor cannot be accessed due to certain circumstances
|
||||
* @throws IllegalArgumentException If the types of the arguments do not match the parameter types of the constructor (this should not occur since it searches for a constructor with the types of the arguments)
|
||||
* @throws InvocationTargetException If the desired constructor cannot be invoked
|
||||
* @throws NoSuchMethodException If the desired constructor with the specified arguments cannot be found
|
||||
*/
|
||||
public static Object instantiateObject(Class<?> clazz, Object... arguments) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException {
|
||||
return getConstructor(clazz, DataType.getPrimitive(arguments)).newInstance(arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of a desired class with the given arguments
|
||||
*
|
||||
* @param className Name of the desired target class
|
||||
* @param packageType Package where the desired target class is located
|
||||
* @param arguments Arguments which are used to construct an object of the desired target class
|
||||
* @return The instance of the desired target class with the specified arguments
|
||||
* @throws InstantiationException If you cannot create an instance of the desired target class due to certain circumstances
|
||||
* @throws IllegalAccessException If the desired constructor cannot be accessed due to certain circumstances
|
||||
* @throws IllegalArgumentException If the types of the arguments do not match the parameter types of the constructor (this should not occur since it searches for a constructor with the types of the arguments)
|
||||
* @throws InvocationTargetException If the desired constructor cannot be invoked
|
||||
* @throws NoSuchMethodException If the desired constructor with the specified arguments cannot be found
|
||||
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
|
||||
* @see #getClass(String, PackageType)
|
||||
* @see #instantiateObject(Class, Object...)
|
||||
*/
|
||||
public static Object instantiateObject(String className, PackageType packageType, Object... arguments) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
|
||||
return instantiateObject(packageType.getClass(className), arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a method of a class with the given parameter types
|
||||
*
|
||||
* @param clazz Target class
|
||||
* @param methodName Name of the desired method
|
||||
* @param parameterTypes Parameter types of the desired method
|
||||
* @return The method of the target class with the specified name and parameter types
|
||||
* @throws NoSuchMethodException If the desired method of the target class with the specified name and parameter types cannot be found
|
||||
* @see DataType#getPrimitive(Class[])
|
||||
* @see DataType#compare(Class[], Class[])
|
||||
*/
|
||||
public static Method getMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException {
|
||||
Class<?>[] primitiveTypes = DataType.getPrimitive(parameterTypes);
|
||||
for (Method method : clazz.getMethods()) {
|
||||
if (!method.getName().equals(methodName) || !DataType.compare(DataType.getPrimitive(method.getParameterTypes()), primitiveTypes)) {
|
||||
continue;
|
||||
}
|
||||
return method;
|
||||
}
|
||||
throw new NoSuchMethodException("There is no such method in this class with the specified name and parameter types");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a method of a desired class with the given parameter types
|
||||
*
|
||||
* @param className Name of the desired target class
|
||||
* @param packageType Package where the desired target class is located
|
||||
* @param methodName Name of the desired method
|
||||
* @param parameterTypes Parameter types of the desired method
|
||||
* @return The method of the desired target class with the specified name and parameter types
|
||||
* @throws NoSuchMethodException If the desired method of the desired target class with the specified name and parameter types cannot be found
|
||||
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
|
||||
* @see #getClass(String, PackageType)
|
||||
* @see #getMethod(Class, String, Class...)
|
||||
*/
|
||||
public static Method getMethod(String className, PackageType packageType, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException, ClassNotFoundException {
|
||||
return getMethod(packageType.getClass(className), methodName, parameterTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes a method on an object with the given arguments
|
||||
*
|
||||
* @param instance Target object
|
||||
* @param methodName Name of the desired method
|
||||
* @param arguments Arguments which are used to invoke the desired method
|
||||
* @return The result of invoking the desired method on the target object
|
||||
* @throws IllegalAccessException If the desired method cannot be accessed due to certain circumstances
|
||||
* @throws IllegalArgumentException If the types of the arguments do not match the parameter types of the method (this should not occur since it searches for a method with the types of the arguments)
|
||||
* @throws InvocationTargetException If the desired method cannot be invoked on the target object
|
||||
* @throws NoSuchMethodException If the desired method of the class of the target object with the specified name and arguments cannot be found
|
||||
* @see #getMethod(Class, String, Class...)
|
||||
* @see DataType#getPrimitive(Object[])
|
||||
*/
|
||||
public static Object invokeMethod(Object instance, String methodName, Object... arguments) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException {
|
||||
return getMethod(instance.getClass(), methodName, DataType.getPrimitive(arguments)).invoke(instance, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes a method of the target class on an object with the given arguments
|
||||
*
|
||||
* @param instance Target object
|
||||
* @param clazz Target class
|
||||
* @param methodName Name of the desired method
|
||||
* @param arguments Arguments which are used to invoke the desired method
|
||||
* @return The result of invoking the desired method on the target object
|
||||
* @throws IllegalAccessException If the desired method cannot be accessed due to certain circumstances
|
||||
* @throws IllegalArgumentException If the types of the arguments do not match the parameter types of the method (this should not occur since it searches for a method with the types of the arguments)
|
||||
* @throws InvocationTargetException If the desired method cannot be invoked on the target object
|
||||
* @throws NoSuchMethodException If the desired method of the target class with the specified name and arguments cannot be found
|
||||
* @see #getMethod(Class, String, Class...)
|
||||
* @see DataType#getPrimitive(Object[])
|
||||
*/
|
||||
public static Object invokeMethod(Object instance, Class<?> clazz, String methodName, Object... arguments) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException {
|
||||
return getMethod(clazz, methodName, DataType.getPrimitive(arguments)).invoke(instance, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes a method of a desired class on an object with the given arguments
|
||||
*
|
||||
* @param instance Target object
|
||||
* @param className Name of the desired target class
|
||||
* @param packageType Package where the desired target class is located
|
||||
* @param methodName Name of the desired method
|
||||
* @param arguments Arguments which are used to invoke the desired method
|
||||
* @return The result of invoking the desired method on the target object
|
||||
* @throws IllegalAccessException If the desired method cannot be accessed due to certain circumstances
|
||||
* @throws IllegalArgumentException If the types of the arguments do not match the parameter types of the method (this should not occur since it searches for a method with the types of the arguments)
|
||||
* @throws InvocationTargetException If the desired method cannot be invoked on the target object
|
||||
* @throws NoSuchMethodException If the desired method of the desired target class with the specified name and arguments cannot be found
|
||||
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
|
||||
* @see #getClass(String, PackageType)
|
||||
* @see #invokeMethod(Object, Class, String, Object...)
|
||||
*/
|
||||
public static Object invokeMethod(Object instance, String className, PackageType packageType, String methodName, Object... arguments) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
|
||||
return invokeMethod(instance, packageType.getClass(className), methodName, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a field of the target class with the given name
|
||||
*
|
||||
* @param clazz Target class
|
||||
* @param declared Whether the desired field is declared or not
|
||||
* @param fieldName Name of the desired field
|
||||
* @return The field of the target class with the specified name
|
||||
* @throws NoSuchFieldException If the desired field of the given class cannot be found
|
||||
* @throws SecurityException If the desired field cannot be made accessible
|
||||
*/
|
||||
public static Field getField(Class<?> clazz, boolean declared, String fieldName) throws NoSuchFieldException, SecurityException {
|
||||
Field field = declared ? clazz.getDeclaredField(fieldName) : clazz.getField(fieldName);
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a field of a desired class with the given name
|
||||
*
|
||||
* @param className Name of the desired target class
|
||||
* @param packageType Package where the desired target class is located
|
||||
* @param declared Whether the desired field is declared or not
|
||||
* @param fieldName Name of the desired field
|
||||
* @return The field of the desired target class with the specified name
|
||||
* @throws NoSuchFieldException If the desired field of the desired class cannot be found
|
||||
* @throws SecurityException If the desired field cannot be made accessible
|
||||
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
|
||||
* @see #getField(Class, boolean, String)
|
||||
*/
|
||||
public static Field getField(String className, PackageType packageType, boolean declared, String fieldName) throws NoSuchFieldException, SecurityException, ClassNotFoundException {
|
||||
return getField(packageType.getClass(className), declared, fieldName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of a field of the given class of an object
|
||||
*
|
||||
* @param instance Target object
|
||||
* @param clazz Target class
|
||||
* @param declared Whether the desired field is declared or not
|
||||
* @param fieldName Name of the desired field
|
||||
* @return The value of field of the target object
|
||||
* @throws IllegalArgumentException If the target object does not feature the desired field
|
||||
* @throws IllegalAccessException If the desired field cannot be accessed
|
||||
* @throws NoSuchFieldException If the desired field of the target class cannot be found
|
||||
* @throws SecurityException If the desired field cannot be made accessible
|
||||
* @see #getField(Class, boolean, String)
|
||||
*/
|
||||
public static Object getValue(Object instance, Class<?> clazz, boolean declared, String fieldName) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
|
||||
return getField(clazz, declared, fieldName).get(instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of a field of a desired class of an object
|
||||
*
|
||||
* @param instance Target object
|
||||
* @param className Name of the desired target class
|
||||
* @param packageType Package where the desired target class is located
|
||||
* @param declared Whether the desired field is declared or not
|
||||
* @param fieldName Name of the desired field
|
||||
* @return The value of field of the target object
|
||||
* @throws IllegalArgumentException If the target object does not feature the desired field
|
||||
* @throws IllegalAccessException If the desired field cannot be accessed
|
||||
* @throws NoSuchFieldException If the desired field of the desired class cannot be found
|
||||
* @throws SecurityException If the desired field cannot be made accessible
|
||||
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
|
||||
* @see #getValue(Object, Class, boolean, String)
|
||||
*/
|
||||
public static Object getValue(Object instance, String className, PackageType packageType, boolean declared, String fieldName) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException, ClassNotFoundException {
|
||||
return getValue(instance, packageType.getClass(className), declared, fieldName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of a field with the given name of an object
|
||||
*
|
||||
* @param instance Target object
|
||||
* @param declared Whether the desired field is declared or not
|
||||
* @param fieldName Name of the desired field
|
||||
* @return The value of field of the target object
|
||||
* @throws IllegalArgumentException If the target object does not feature the desired field (should not occur since it searches for a field with the given name in the class of the object)
|
||||
* @throws IllegalAccessException If the desired field cannot be accessed
|
||||
* @throws NoSuchFieldException If the desired field of the target object cannot be found
|
||||
* @throws SecurityException If the desired field cannot be made accessible
|
||||
* @see #getValue(Object, Class, boolean, String)
|
||||
*/
|
||||
public static Object getValue(Object instance, boolean declared, String fieldName) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
|
||||
return getValue(instance, instance.getClass(), declared, fieldName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a field of the given class of an object
|
||||
*
|
||||
* @param instance Target object
|
||||
* @param clazz Target class
|
||||
* @param declared Whether the desired field is declared or not
|
||||
* @param fieldName Name of the desired field
|
||||
* @param value New value
|
||||
* @throws IllegalArgumentException If the type of the value does not match the type of the desired field
|
||||
* @throws IllegalAccessException If the desired field cannot be accessed
|
||||
* @throws NoSuchFieldException If the desired field of the target class cannot be found
|
||||
* @throws SecurityException If the desired field cannot be made accessible
|
||||
* @see #getField(Class, boolean, String)
|
||||
*/
|
||||
public static void setValue(Object instance, Class<?> clazz, boolean declared, String fieldName, Object value) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
|
||||
getField(clazz, declared, fieldName).set(instance, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a field of a desired class of an object
|
||||
*
|
||||
* @param instance Target object
|
||||
* @param className Name of the desired target class
|
||||
* @param packageType Package where the desired target class is located
|
||||
* @param declared Whether the desired field is declared or not
|
||||
* @param fieldName Name of the desired field
|
||||
* @param value New value
|
||||
* @throws IllegalArgumentException If the type of the value does not match the type of the desired field
|
||||
* @throws IllegalAccessException If the desired field cannot be accessed
|
||||
* @throws NoSuchFieldException If the desired field of the desired class cannot be found
|
||||
* @throws SecurityException If the desired field cannot be made accessible
|
||||
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
|
||||
* @see #setValue(Object, Class, boolean, String, Object)
|
||||
*/
|
||||
public static void setValue(Object instance, String className, PackageType packageType, boolean declared, String fieldName, Object value) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException, ClassNotFoundException {
|
||||
setValue(instance, packageType.getClass(className), declared, fieldName, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a field with the given name of an object
|
||||
*
|
||||
* @param instance Target object
|
||||
* @param declared Whether the desired field is declared or not
|
||||
* @param fieldName Name of the desired field
|
||||
* @param value New value
|
||||
* @throws IllegalArgumentException If the type of the value does not match the type of the desired field
|
||||
* @throws IllegalAccessException If the desired field cannot be accessed
|
||||
* @throws NoSuchFieldException If the desired field of the target object cannot be found
|
||||
* @throws SecurityException If the desired field cannot be made accessible
|
||||
* @see #setValue(Object, Class, boolean, String, Object)
|
||||
*/
|
||||
public static void setValue(Object instance, boolean declared, String fieldName, Object value) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
|
||||
setValue(instance, instance.getClass(), declared, fieldName, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an enumeration of dynamic packages of NMS and CraftBukkit
|
||||
* <p>
|
||||
* This class is part of the <b>ReflectionUtils</b> and follows the same usage conditions
|
||||
*
|
||||
* @author DarkBlade12
|
||||
* @since 1.0
|
||||
*/
|
||||
public enum PackageType {
|
||||
MINECRAFT_SERVER("net.minecraft.server." + getServerVersion()),
|
||||
CRAFTBUKKIT("org.bukkit.craftbukkit." + getServerVersion()),
|
||||
CRAFTBUKKIT_BLOCK(CRAFTBUKKIT, "block"),
|
||||
CRAFTBUKKIT_CHUNKIO(CRAFTBUKKIT, "chunkio"),
|
||||
CRAFTBUKKIT_COMMAND(CRAFTBUKKIT, "command"),
|
||||
CRAFTBUKKIT_CONVERSATIONS(CRAFTBUKKIT, "conversations"),
|
||||
CRAFTBUKKIT_ENCHANTMENS(CRAFTBUKKIT, "enchantments"),
|
||||
CRAFTBUKKIT_ENTITY(CRAFTBUKKIT, "entity"),
|
||||
CRAFTBUKKIT_EVENT(CRAFTBUKKIT, "event"),
|
||||
CRAFTBUKKIT_GENERATOR(CRAFTBUKKIT, "generator"),
|
||||
CRAFTBUKKIT_HELP(CRAFTBUKKIT, "help"),
|
||||
CRAFTBUKKIT_INVENTORY(CRAFTBUKKIT, "inventory"),
|
||||
CRAFTBUKKIT_MAP(CRAFTBUKKIT, "map"),
|
||||
CRAFTBUKKIT_METADATA(CRAFTBUKKIT, "metadata"),
|
||||
CRAFTBUKKIT_POTION(CRAFTBUKKIT, "potion"),
|
||||
CRAFTBUKKIT_PROJECTILES(CRAFTBUKKIT, "projectiles"),
|
||||
CRAFTBUKKIT_SCHEDULER(CRAFTBUKKIT, "scheduler"),
|
||||
CRAFTBUKKIT_SCOREBOARD(CRAFTBUKKIT, "scoreboard"),
|
||||
CRAFTBUKKIT_UPDATER(CRAFTBUKKIT, "updater"),
|
||||
CRAFTBUKKIT_UTIL(CRAFTBUKKIT, "util");
|
||||
|
||||
private final String path;
|
||||
|
||||
/**
|
||||
* Construct a new package type
|
||||
*
|
||||
* @param path Path of the package
|
||||
*/
|
||||
private PackageType(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new package type
|
||||
*
|
||||
* @param parent Parent package of the package
|
||||
* @param path Path of the package
|
||||
*/
|
||||
private PackageType(PackageType parent, String path) {
|
||||
this(parent + "." + path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path of this package type
|
||||
*
|
||||
* @return The path
|
||||
*/
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class with the given name
|
||||
*
|
||||
* @param className Name of the desired class
|
||||
* @return The class with the specified name
|
||||
* @throws ClassNotFoundException If the desired class with the specified name and package cannot be found
|
||||
*/
|
||||
public Class<?> getClass(String className) throws ClassNotFoundException {
|
||||
return Class.forName(this + "." + className);
|
||||
}
|
||||
|
||||
// Override for convenience
|
||||
@Override
|
||||
public String toString() {
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the version of your server
|
||||
*
|
||||
* @return The server version
|
||||
*/
|
||||
public static String getServerVersion() {
|
||||
return Bukkit.getServer().getClass().getPackage().getName().substring(23);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an enumeration of Java data types with corresponding classes
|
||||
* <p>
|
||||
* This class is part of the <b>ReflectionUtils</b> and follows the same usage conditions
|
||||
*
|
||||
* @author DarkBlade12
|
||||
* @since 1.0
|
||||
*/
|
||||
public enum DataType {
|
||||
BYTE(byte.class, Byte.class),
|
||||
SHORT(short.class, Short.class),
|
||||
INTEGER(int.class, Integer.class),
|
||||
LONG(long.class, Long.class),
|
||||
CHARACTER(char.class, Character.class),
|
||||
FLOAT(float.class, Float.class),
|
||||
DOUBLE(double.class, Double.class),
|
||||
BOOLEAN(boolean.class, Boolean.class);
|
||||
|
||||
private static final Map<Class<?>, DataType> CLASS_MAP = new HashMap<Class<?>, DataType>();
|
||||
private final Class<?> primitive;
|
||||
private final Class<?> reference;
|
||||
|
||||
// Initialize map for quick class lookup
|
||||
static {
|
||||
for (DataType type : values()) {
|
||||
CLASS_MAP.put(type.primitive, type);
|
||||
CLASS_MAP.put(type.reference, type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new data type
|
||||
*
|
||||
* @param primitive Primitive class of this data type
|
||||
* @param reference Reference class of this data type
|
||||
*/
|
||||
private DataType(Class<?> primitive, Class<?> reference) {
|
||||
this.primitive = primitive;
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the primitive class of this data type
|
||||
*
|
||||
* @return The primitive class
|
||||
*/
|
||||
public Class<?> getPrimitive() {
|
||||
return primitive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the reference class of this data type
|
||||
*
|
||||
* @return The reference class
|
||||
*/
|
||||
public Class<?> getReference() {
|
||||
return reference;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data type with the given primitive/reference class
|
||||
*
|
||||
* @param clazz Primitive/Reference class of the data type
|
||||
* @return The data type
|
||||
*/
|
||||
public static DataType fromClass(Class<?> clazz) {
|
||||
return CLASS_MAP.get(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the primitive class of the data type with the given reference class
|
||||
*
|
||||
* @param clazz Reference class of the data type
|
||||
* @return The primitive class
|
||||
*/
|
||||
public static Class<?> getPrimitive(Class<?> clazz) {
|
||||
DataType type = fromClass(clazz);
|
||||
return type == null ? clazz : type.getPrimitive();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the reference class of the data type with the given primitive class
|
||||
*
|
||||
* @param clazz Primitive class of the data type
|
||||
* @return The reference class
|
||||
*/
|
||||
public static Class<?> getReference(Class<?> clazz) {
|
||||
DataType type = fromClass(clazz);
|
||||
return type == null ? clazz : type.getReference();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the primitive class array of the given class array
|
||||
*
|
||||
* @param classes Given class array
|
||||
* @return The primitive class array
|
||||
*/
|
||||
public static Class<?>[] getPrimitive(Class<?>[] classes) {
|
||||
int length = classes == null ? 0 : classes.length;
|
||||
Class<?>[] types = new Class<?>[length];
|
||||
for (int index = 0; index < length; index++) {
|
||||
types[index] = getPrimitive(classes[index]);
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the reference class array of the given class array
|
||||
*
|
||||
* @param classes Given class array
|
||||
* @return The reference class array
|
||||
*/
|
||||
public static Class<?>[] getReference(Class<?>[] classes) {
|
||||
int length = classes == null ? 0 : classes.length;
|
||||
Class<?>[] types = new Class<?>[length];
|
||||
for (int index = 0; index < length; index++) {
|
||||
types[index] = getReference(classes[index]);
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the primitive class array of the given object array
|
||||
*
|
||||
* @param object Given object array
|
||||
* @return The primitive class array
|
||||
*/
|
||||
public static Class<?>[] getPrimitive(Object[] objects) {
|
||||
int length = objects == null ? 0 : objects.length;
|
||||
Class<?>[] types = new Class<?>[length];
|
||||
for (int index = 0; index < length; index++) {
|
||||
types[index] = getPrimitive(objects[index].getClass());
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the reference class array of the given object array
|
||||
*
|
||||
* @param object Given object array
|
||||
* @return The reference class array
|
||||
*/
|
||||
public static Class<?>[] getReference(Object[] objects) {
|
||||
int length = objects == null ? 0 : objects.length;
|
||||
Class<?>[] types = new Class<?>[length];
|
||||
for (int index = 0; index < length; index++) {
|
||||
types[index] = getReference(objects[index].getClass());
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two class arrays on equivalence
|
||||
*
|
||||
* @param primary Primary class array
|
||||
* @param secondary Class array which is compared to the primary array
|
||||
* @return Whether these arrays are equal or not
|
||||
*/
|
||||
public static boolean compare(Class<?>[] primary, Class<?>[] secondary) {
|
||||
if (primary == null || secondary == null || primary.length != secondary.length) {
|
||||
return false;
|
||||
}
|
||||
for (int index = 0; index < primary.length; index++) {
|
||||
Class<?> primaryClass = primary[index];
|
||||
Class<?> secondaryClass = secondary[index];
|
||||
if (primaryClass.equals(secondaryClass) || primaryClass.isAssignableFrom(secondaryClass)) {
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,119 +1,119 @@
|
|||
package eu.univento.core.api.youtube;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
|
||||
public class YTAPI {
|
||||
|
||||
public static Gson gson = new Gson();
|
||||
|
||||
public static String readJsonFromUrl(String urlString) throws Exception {
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
URL url = new URL(urlString);
|
||||
reader = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
int read;
|
||||
char[] chars = new char[1024];
|
||||
while ((read = reader.read(chars)) != -1)
|
||||
buffer.append(chars, 0, read);
|
||||
|
||||
return buffer.toString();
|
||||
} finally {
|
||||
if (reader != null)
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getGooglePlusId(String uri) throws Exception {
|
||||
String endid = uri.split("/")[uri.split("/").length - 1];
|
||||
String json = YTAPI.readJsonFromUrl("http://gdata.youtube.com/feeds/api/users/" + endid + "?alt=json");
|
||||
JsonObject jo = gson.fromJson(json, JsonObject.class);
|
||||
String gplusid = jo.get("entry").getAsJsonObject().get("yt$googlePlusUserId").getAsJsonObject().get("$t")
|
||||
.getAsString();
|
||||
return gplusid;
|
||||
}
|
||||
|
||||
public static String getChannelFromGPlusId(String plusid, String uri, String developerkey) throws Exception {
|
||||
|
||||
String endid = uri;
|
||||
|
||||
try {
|
||||
String json = YTAPI
|
||||
.readJsonFromUrl("https://www.googleapis.com/plus/v1/people/" + plusid + "?key=" + developerkey);
|
||||
JsonObject jb = gson.fromJson(json, JsonObject.class);
|
||||
JsonObject jo = jb;
|
||||
JsonArray ja = jo.get("urls").getAsJsonArray();
|
||||
for (int i = 0; i < ja.size(); i++) {
|
||||
JsonObject jsob = (JsonObject) ja.get(i);
|
||||
if (jsob.get("value").getAsString().toLowerCase().contains("youtube")) {
|
||||
return jsob.get("value").getAsString();
|
||||
}
|
||||
}
|
||||
return "No Google Plus Data To Find The Channel";
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
return "No Google Plus Data To Find The Channel";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static YoutubeChannel getYTChannelFromUri(String uri) {
|
||||
try {
|
||||
System.out.println(uri);
|
||||
YoutubeChannel ch;
|
||||
String json = YTAPI.readJsonFromUrl(uri + "?alt=json");
|
||||
JsonObject jb = gson.fromJson(json, JsonObject.class);
|
||||
String username = jb.get("entry").getAsJsonObject().get("yt$username").getAsJsonObject().get("$t")
|
||||
.getAsString();
|
||||
String about_us = jb.get("entry").getAsJsonObject().get("content").getAsJsonObject().get("$t")
|
||||
.getAsString();
|
||||
String title = jb.get("entry").getAsJsonObject().get("title").getAsJsonObject().get("$t").getAsString();
|
||||
String subscribers = jb.get("entry").getAsJsonObject().get("yt$statistics").getAsJsonObject()
|
||||
.get("subscriberCount").getAsString();
|
||||
String gplusid = jb.get("entry").getAsJsonObject().get("yt$googlePlusUserId").getAsJsonObject().get("$t")
|
||||
.getAsString();
|
||||
String firstname = "";
|
||||
String lastname = "";
|
||||
if (jb.get("entry").getAsJsonObject().get("yt$firstName") != null) {
|
||||
firstname = jb.get("entry").getAsJsonObject().get("yt$firstName").getAsJsonObject().get("$t")
|
||||
.getAsString();
|
||||
}
|
||||
if (jb.get("entry").getAsJsonObject().get("yt$lastName") != null) {
|
||||
|
||||
lastname = jb.get("entry").getAsJsonObject().get("yt$lastName").getAsJsonObject().get("$t")
|
||||
.getAsString();
|
||||
;
|
||||
}
|
||||
String location = jb.get("entry").getAsJsonObject().get("yt$location").getAsJsonObject().get("$t")
|
||||
.getAsString();
|
||||
;
|
||||
String lastwebaccess = jb.get("entry").getAsJsonObject().get("yt$statistics").getAsJsonObject()
|
||||
.get("lastWebAccess").getAsString();
|
||||
int videowatchcount = jb.get("entry").getAsJsonObject().get("yt$statistics").getAsJsonObject()
|
||||
.get("videoWatchCount").getAsInt();
|
||||
int viewcount = jb.get("entry").getAsJsonObject().get("yt$statistics").getAsJsonObject().get("viewCount")
|
||||
.getAsInt();
|
||||
String totaluploadviews = jb.get("entry").getAsJsonObject().get("yt$statistics").getAsJsonObject()
|
||||
.get("totalUploadViews").getAsString();
|
||||
String avatar = jb.get("entry").getAsJsonObject().get("media$thumbnail").getAsJsonObject().get("url")
|
||||
.getAsString();
|
||||
ch = new YoutubeChannel(about_us, title, username, subscribers, gplusid, firstname, lastname, location,
|
||||
lastwebaccess, videowatchcount, viewcount, totaluploadviews, avatar);
|
||||
return ch;
|
||||
} catch (Exception err) {
|
||||
err.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static YoutubeChannel getYTChannelFromName(String channel) {
|
||||
return getYTChannelFromUri("http://gdata.youtube.com/feeds/api/users/" + channel);
|
||||
}
|
||||
|
||||
package eu.univento.core.api.youtube;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
|
||||
public class YTAPI {
|
||||
|
||||
public static Gson gson = new Gson();
|
||||
|
||||
public static String readJsonFromUrl(String urlString) throws Exception {
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
URL url = new URL(urlString);
|
||||
reader = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
int read;
|
||||
char[] chars = new char[1024];
|
||||
while ((read = reader.read(chars)) != -1)
|
||||
buffer.append(chars, 0, read);
|
||||
|
||||
return buffer.toString();
|
||||
} finally {
|
||||
if (reader != null)
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getGooglePlusId(String uri) throws Exception {
|
||||
String endid = uri.split("/")[uri.split("/").length - 1];
|
||||
String json = YTAPI.readJsonFromUrl("http://gdata.youtube.com/feeds/api/users/" + endid + "?alt=json");
|
||||
JsonObject jo = gson.fromJson(json, JsonObject.class);
|
||||
String gplusid = jo.get("entry").getAsJsonObject().get("yt$googlePlusUserId").getAsJsonObject().get("$t")
|
||||
.getAsString();
|
||||
return gplusid;
|
||||
}
|
||||
|
||||
public static String getChannelFromGPlusId(String plusid, String uri, String developerkey) throws Exception {
|
||||
|
||||
String endid = uri;
|
||||
|
||||
try {
|
||||
String json = YTAPI
|
||||
.readJsonFromUrl("https://www.googleapis.com/plus/v1/people/" + plusid + "?key=" + developerkey);
|
||||
JsonObject jb = gson.fromJson(json, JsonObject.class);
|
||||
JsonObject jo = jb;
|
||||
JsonArray ja = jo.get("urls").getAsJsonArray();
|
||||
for (int i = 0; i < ja.size(); i++) {
|
||||
JsonObject jsob = (JsonObject) ja.get(i);
|
||||
if (jsob.get("value").getAsString().toLowerCase().contains("youtube")) {
|
||||
return jsob.get("value").getAsString();
|
||||
}
|
||||
}
|
||||
return "No Google Plus Data To Find The Channel";
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
return "No Google Plus Data To Find The Channel";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static YoutubeChannel getYTChannelFromUri(String uri) {
|
||||
try {
|
||||
System.out.println(uri);
|
||||
YoutubeChannel ch;
|
||||
String json = YTAPI.readJsonFromUrl(uri + "?alt=json");
|
||||
JsonObject jb = gson.fromJson(json, JsonObject.class);
|
||||
String username = jb.get("entry").getAsJsonObject().get("yt$username").getAsJsonObject().get("$t")
|
||||
.getAsString();
|
||||
String about_us = jb.get("entry").getAsJsonObject().get("content").getAsJsonObject().get("$t")
|
||||
.getAsString();
|
||||
String title = jb.get("entry").getAsJsonObject().get("title").getAsJsonObject().get("$t").getAsString();
|
||||
String subscribers = jb.get("entry").getAsJsonObject().get("yt$statistics").getAsJsonObject()
|
||||
.get("subscriberCount").getAsString();
|
||||
String gplusid = jb.get("entry").getAsJsonObject().get("yt$googlePlusUserId").getAsJsonObject().get("$t")
|
||||
.getAsString();
|
||||
String firstname = "";
|
||||
String lastname = "";
|
||||
if (jb.get("entry").getAsJsonObject().get("yt$firstName") != null) {
|
||||
firstname = jb.get("entry").getAsJsonObject().get("yt$firstName").getAsJsonObject().get("$t")
|
||||
.getAsString();
|
||||
}
|
||||
if (jb.get("entry").getAsJsonObject().get("yt$lastName") != null) {
|
||||
|
||||
lastname = jb.get("entry").getAsJsonObject().get("yt$lastName").getAsJsonObject().get("$t")
|
||||
.getAsString();
|
||||
|
||||
}
|
||||
String location = jb.get("entry").getAsJsonObject().get("yt$location").getAsJsonObject().get("$t")
|
||||
.getAsString();
|
||||
|
||||
String lastwebaccess = jb.get("entry").getAsJsonObject().get("yt$statistics").getAsJsonObject()
|
||||
.get("lastWebAccess").getAsString();
|
||||
int videowatchcount = jb.get("entry").getAsJsonObject().get("yt$statistics").getAsJsonObject()
|
||||
.get("videoWatchCount").getAsInt();
|
||||
int viewcount = jb.get("entry").getAsJsonObject().get("yt$statistics").getAsJsonObject().get("viewCount")
|
||||
.getAsInt();
|
||||
String totaluploadviews = jb.get("entry").getAsJsonObject().get("yt$statistics").getAsJsonObject()
|
||||
.get("totalUploadViews").getAsString();
|
||||
String avatar = jb.get("entry").getAsJsonObject().get("media$thumbnail").getAsJsonObject().get("url")
|
||||
.getAsString();
|
||||
ch = new YoutubeChannel(about_us, title, username, subscribers, gplusid, firstname, lastname, location,
|
||||
lastwebaccess, videowatchcount, viewcount, totaluploadviews, avatar);
|
||||
return ch;
|
||||
} catch (Exception err) {
|
||||
err.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static YoutubeChannel getYTChannelFromName(String channel) {
|
||||
return getYTChannelFromUri("http://gdata.youtube.com/feeds/api/users/" + channel);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,242 +1,242 @@
|
|||
package eu.univento.core.api.youtube;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
public class YoutubeChannel {
|
||||
String about_us;
|
||||
String title;
|
||||
String username;
|
||||
String subscribers;
|
||||
String googleplusid;
|
||||
String firstname = "";
|
||||
String lastname = "";
|
||||
String location;
|
||||
String lastwebaccess;
|
||||
int videoWatchCount;
|
||||
int viewcount;
|
||||
String totaluploadViews;
|
||||
String avatar;
|
||||
|
||||
@ConstructorProperties({ "about_us", "title", "username", "subscribers", "googleplusid", "firstname", "lastname",
|
||||
"location", "lastwebaccess", "videoWatchCount", "viewcount", "totaluploadViews", "avatar" })
|
||||
public YoutubeChannel(String about_us, String title, String username, String subscribers, String googleplusid,
|
||||
String firstname, String lastname, String location, String lastwebaccess, int videoWatchCount,
|
||||
int viewcount, String totaluploadViews, String avatar) {
|
||||
this.about_us = about_us;
|
||||
this.title = title;
|
||||
this.username = username;
|
||||
this.subscribers = subscribers;
|
||||
this.googleplusid = googleplusid;
|
||||
this.firstname = firstname;
|
||||
this.lastname = lastname;
|
||||
this.location = location;
|
||||
this.lastwebaccess = lastwebaccess;
|
||||
this.videoWatchCount = videoWatchCount;
|
||||
this.viewcount = viewcount;
|
||||
this.totaluploadViews = totaluploadViews;
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
public String getAbout_us() {
|
||||
return this.about_us;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
public String getSubscribers() {
|
||||
return this.subscribers;
|
||||
}
|
||||
|
||||
public String getGoogleplusid() {
|
||||
return this.googleplusid;
|
||||
}
|
||||
|
||||
public String getFirstname() {
|
||||
return this.firstname;
|
||||
}
|
||||
|
||||
public String getLastname() {
|
||||
return this.lastname;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
public String getLastwebaccess() {
|
||||
return this.lastwebaccess;
|
||||
}
|
||||
|
||||
public int getVideoWatchCount() {
|
||||
return this.videoWatchCount;
|
||||
}
|
||||
|
||||
public int getViewcount() {
|
||||
return this.viewcount;
|
||||
}
|
||||
|
||||
public String getTotaluploadViews() {
|
||||
return this.totaluploadViews;
|
||||
}
|
||||
|
||||
public String getAvatar() {
|
||||
return this.avatar;
|
||||
}
|
||||
|
||||
public void setAbout_us(String about_us) {
|
||||
this.about_us = about_us;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public void setSubscribers(String subscribers) {
|
||||
this.subscribers = subscribers;
|
||||
}
|
||||
|
||||
public void setGoogleplusid(String googleplusid) {
|
||||
this.googleplusid = googleplusid;
|
||||
}
|
||||
|
||||
public void setFirstname(String firstname) {
|
||||
this.firstname = firstname;
|
||||
}
|
||||
|
||||
public void setLastname(String lastname) {
|
||||
this.lastname = lastname;
|
||||
}
|
||||
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public void setLastwebaccess(String lastwebaccess) {
|
||||
this.lastwebaccess = lastwebaccess;
|
||||
}
|
||||
|
||||
public void setVideoWatchCount(int videoWatchCount) {
|
||||
this.videoWatchCount = videoWatchCount;
|
||||
}
|
||||
|
||||
public void setViewcount(int viewcount) {
|
||||
this.viewcount = viewcount;
|
||||
}
|
||||
|
||||
public void setTotaluploadViews(String totaluploadViews) {
|
||||
this.totaluploadViews = totaluploadViews;
|
||||
}
|
||||
|
||||
public void setAvatar(String avatar) {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o == this)
|
||||
return true;
|
||||
if (!(o instanceof YoutubeChannel))
|
||||
return false;
|
||||
YoutubeChannel other = (YoutubeChannel) o;
|
||||
if (!other.canEqual(this))
|
||||
return false;
|
||||
Object this$about_us = getAbout_us();
|
||||
Object other$about_us = other.getAbout_us();
|
||||
if (this$about_us == null ? other$about_us != null : !this$about_us.equals(other$about_us))
|
||||
return false;
|
||||
Object this$title = getTitle();
|
||||
Object other$title = other.getTitle();
|
||||
if (this$title == null ? other$title != null : !this$title.equals(other$title))
|
||||
return false;
|
||||
Object this$username = getUsername();
|
||||
Object other$username = other.getUsername();
|
||||
if (this$username == null ? other$username != null : !this$username.equals(other$username))
|
||||
return false;
|
||||
Object this$subscribers = getSubscribers();
|
||||
Object other$subscribers = other.getSubscribers();
|
||||
if (this$subscribers == null ? other$subscribers != null : !this$subscribers.equals(other$subscribers))
|
||||
return false;
|
||||
Object this$googleplusid = getGoogleplusid();
|
||||
Object other$googleplusid = other.getGoogleplusid();
|
||||
if (this$googleplusid == null ? other$googleplusid != null : !this$googleplusid.equals(other$googleplusid))
|
||||
return false;
|
||||
Object this$firstname = getFirstname();
|
||||
Object other$firstname = other.getFirstname();
|
||||
if (this$firstname == null ? other$firstname != null : !this$firstname.equals(other$firstname))
|
||||
return false;
|
||||
Object this$lastname = getLastname();
|
||||
Object other$lastname = other.getLastname();
|
||||
if (this$lastname == null ? other$lastname != null : !this$lastname.equals(other$lastname))
|
||||
return false;
|
||||
Object this$location = getLocation();
|
||||
Object other$location = other.getLocation();
|
||||
if (this$location == null ? other$location != null : !this$location.equals(other$location))
|
||||
return false;
|
||||
Object this$lastwebaccess = getLastwebaccess();
|
||||
Object other$lastwebaccess = other.getLastwebaccess();
|
||||
if (this$lastwebaccess == null ? other$lastwebaccess != null : !this$lastwebaccess.equals(other$lastwebaccess))
|
||||
return false;
|
||||
if (getVideoWatchCount() != other.getVideoWatchCount())
|
||||
return false;
|
||||
if (getViewcount() != other.getViewcount())
|
||||
return false;
|
||||
Object this$totaluploadViews = getTotaluploadViews();
|
||||
Object other$totaluploadViews = other.getTotaluploadViews();
|
||||
if (this$totaluploadViews == null ? other$totaluploadViews != null
|
||||
: !this$totaluploadViews.equals(other$totaluploadViews))
|
||||
return false;
|
||||
Object this$avatar = getAvatar();
|
||||
Object other$avatar = other.getAvatar();
|
||||
return this$avatar == null ? other$avatar == null : this$avatar.equals(other$avatar);
|
||||
}
|
||||
|
||||
public boolean canEqual(Object other) {
|
||||
return other instanceof YoutubeChannel;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int PRIME = 31;
|
||||
int result = 1;
|
||||
Object $about_us = getAbout_us();
|
||||
result = result * 31 + ($about_us == null ? 0 : $about_us.hashCode());
|
||||
Object $title = getTitle();
|
||||
result = result * 31 + ($title == null ? 0 : $title.hashCode());
|
||||
Object $username = getUsername();
|
||||
result = result * 31 + ($username == null ? 0 : $username.hashCode());
|
||||
Object $subscribers = getSubscribers();
|
||||
result = result * 31 + ($subscribers == null ? 0 : $subscribers.hashCode());
|
||||
Object $googleplusid = getGoogleplusid();
|
||||
result = result * 31 + ($googleplusid == null ? 0 : $googleplusid.hashCode());
|
||||
Object $firstname = getFirstname();
|
||||
result = result * 31 + ($firstname == null ? 0 : $firstname.hashCode());
|
||||
Object $lastname = getLastname();
|
||||
result = result * 31 + ($lastname == null ? 0 : $lastname.hashCode());
|
||||
Object $location = getLocation();
|
||||
result = result * 31 + ($location == null ? 0 : $location.hashCode());
|
||||
Object $lastwebaccess = getLastwebaccess();
|
||||
result = result * 31 + ($lastwebaccess == null ? 0 : $lastwebaccess.hashCode());
|
||||
result = result * 31 + getVideoWatchCount();
|
||||
result = result * 31 + getViewcount();
|
||||
Object $totaluploadViews = getTotaluploadViews();
|
||||
result = result * 31 + ($totaluploadViews == null ? 0 : $totaluploadViews.hashCode());
|
||||
Object $avatar = getAvatar();
|
||||
return result * 31 + ($avatar == null ? 0 : $avatar.hashCode());
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "YoutubeChannel(about_us=" + getAbout_us() + ", title=" + getTitle() + ", username=" + getUsername()
|
||||
+ ", subscribers=" + getSubscribers() + ", googleplusid=" + getGoogleplusid() + ", firstname="
|
||||
+ getFirstname() + ", lastname=" + getLastname() + ", location=" + getLocation() + ", lastwebaccess="
|
||||
+ getLastwebaccess() + ", videoWatchCount=" + getVideoWatchCount() + ", viewcount=" + getViewcount()
|
||||
+ ", totaluploadViews=" + getTotaluploadViews() + ", avatar=" + getAvatar() + ")";
|
||||
}
|
||||
package eu.univento.core.api.youtube;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
public class YoutubeChannel {
|
||||
String about_us;
|
||||
String title;
|
||||
String username;
|
||||
String subscribers;
|
||||
String googleplusid;
|
||||
String firstname = "";
|
||||
String lastname = "";
|
||||
String location;
|
||||
String lastwebaccess;
|
||||
int videoWatchCount;
|
||||
int viewcount;
|
||||
String totaluploadViews;
|
||||
String avatar;
|
||||
|
||||
@ConstructorProperties({ "about_us", "title", "username", "subscribers", "googleplusid", "firstname", "lastname",
|
||||
"location", "lastwebaccess", "videoWatchCount", "viewcount", "totaluploadViews", "avatar" })
|
||||
public YoutubeChannel(String about_us, String title, String username, String subscribers, String googleplusid,
|
||||
String firstname, String lastname, String location, String lastwebaccess, int videoWatchCount,
|
||||
int viewcount, String totaluploadViews, String avatar) {
|
||||
this.about_us = about_us;
|
||||
this.title = title;
|
||||
this.username = username;
|
||||
this.subscribers = subscribers;
|
||||
this.googleplusid = googleplusid;
|
||||
this.firstname = firstname;
|
||||
this.lastname = lastname;
|
||||
this.location = location;
|
||||
this.lastwebaccess = lastwebaccess;
|
||||
this.videoWatchCount = videoWatchCount;
|
||||
this.viewcount = viewcount;
|
||||
this.totaluploadViews = totaluploadViews;
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
public String getAbout_us() {
|
||||
return this.about_us;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
public String getSubscribers() {
|
||||
return this.subscribers;
|
||||
}
|
||||
|
||||
public String getGoogleplusid() {
|
||||
return this.googleplusid;
|
||||
}
|
||||
|
||||
public String getFirstname() {
|
||||
return this.firstname;
|
||||
}
|
||||
|
||||
public String getLastname() {
|
||||
return this.lastname;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
public String getLastwebaccess() {
|
||||
return this.lastwebaccess;
|
||||
}
|
||||
|
||||
public int getVideoWatchCount() {
|
||||
return this.videoWatchCount;
|
||||
}
|
||||
|
||||
public int getViewcount() {
|
||||
return this.viewcount;
|
||||
}
|
||||
|
||||
public String getTotaluploadViews() {
|
||||
return this.totaluploadViews;
|
||||
}
|
||||
|
||||
public String getAvatar() {
|
||||
return this.avatar;
|
||||
}
|
||||
|
||||
public void setAbout_us(String about_us) {
|
||||
this.about_us = about_us;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public void setSubscribers(String subscribers) {
|
||||
this.subscribers = subscribers;
|
||||
}
|
||||
|
||||
public void setGoogleplusid(String googleplusid) {
|
||||
this.googleplusid = googleplusid;
|
||||
}
|
||||
|
||||
public void setFirstname(String firstname) {
|
||||
this.firstname = firstname;
|
||||
}
|
||||
|
||||
public void setLastname(String lastname) {
|
||||
this.lastname = lastname;
|
||||
}
|
||||
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public void setLastwebaccess(String lastwebaccess) {
|
||||
this.lastwebaccess = lastwebaccess;
|
||||
}
|
||||
|
||||
public void setVideoWatchCount(int videoWatchCount) {
|
||||
this.videoWatchCount = videoWatchCount;
|
||||
}
|
||||
|
||||
public void setViewcount(int viewcount) {
|
||||
this.viewcount = viewcount;
|
||||
}
|
||||
|
||||
public void setTotaluploadViews(String totaluploadViews) {
|
||||
this.totaluploadViews = totaluploadViews;
|
||||
}
|
||||
|
||||
public void setAvatar(String avatar) {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o == this)
|
||||
return true;
|
||||
if (!(o instanceof YoutubeChannel))
|
||||
return false;
|
||||
YoutubeChannel other = (YoutubeChannel) o;
|
||||
if (!other.canEqual(this))
|
||||
return false;
|
||||
Object this$about_us = getAbout_us();
|
||||
Object other$about_us = other.getAbout_us();
|
||||
if (this$about_us == null ? other$about_us != null : !this$about_us.equals(other$about_us))
|
||||
return false;
|
||||
Object this$title = getTitle();
|
||||
Object other$title = other.getTitle();
|
||||
if (this$title == null ? other$title != null : !this$title.equals(other$title))
|
||||
return false;
|
||||
Object this$username = getUsername();
|
||||
Object other$username = other.getUsername();
|
||||
if (this$username == null ? other$username != null : !this$username.equals(other$username))
|
||||
return false;
|
||||
Object this$subscribers = getSubscribers();
|
||||
Object other$subscribers = other.getSubscribers();
|
||||
if (this$subscribers == null ? other$subscribers != null : !this$subscribers.equals(other$subscribers))
|
||||
return false;
|
||||
Object this$googleplusid = getGoogleplusid();
|
||||
Object other$googleplusid = other.getGoogleplusid();
|
||||
if (this$googleplusid == null ? other$googleplusid != null : !this$googleplusid.equals(other$googleplusid))
|
||||
return false;
|
||||
Object this$firstname = getFirstname();
|
||||
Object other$firstname = other.getFirstname();
|
||||
if (this$firstname == null ? other$firstname != null : !this$firstname.equals(other$firstname))
|
||||
return false;
|
||||
Object this$lastname = getLastname();
|
||||
Object other$lastname = other.getLastname();
|
||||
if (this$lastname == null ? other$lastname != null : !this$lastname.equals(other$lastname))
|
||||
return false;
|
||||
Object this$location = getLocation();
|
||||
Object other$location = other.getLocation();
|
||||
if (this$location == null ? other$location != null : !this$location.equals(other$location))
|
||||
return false;
|
||||
Object this$lastwebaccess = getLastwebaccess();
|
||||
Object other$lastwebaccess = other.getLastwebaccess();
|
||||
if (this$lastwebaccess == null ? other$lastwebaccess != null : !this$lastwebaccess.equals(other$lastwebaccess))
|
||||
return false;
|
||||
if (getVideoWatchCount() != other.getVideoWatchCount())
|
||||
return false;
|
||||
if (getViewcount() != other.getViewcount())
|
||||
return false;
|
||||
Object this$totaluploadViews = getTotaluploadViews();
|
||||
Object other$totaluploadViews = other.getTotaluploadViews();
|
||||
if (this$totaluploadViews == null ? other$totaluploadViews != null
|
||||
: !this$totaluploadViews.equals(other$totaluploadViews))
|
||||
return false;
|
||||
Object this$avatar = getAvatar();
|
||||
Object other$avatar = other.getAvatar();
|
||||
return this$avatar == null ? other$avatar == null : this$avatar.equals(other$avatar);
|
||||
}
|
||||
|
||||
public boolean canEqual(Object other) {
|
||||
return other instanceof YoutubeChannel;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int PRIME = 31;
|
||||
int result = 1;
|
||||
Object $about_us = getAbout_us();
|
||||
result = result * 31 + ($about_us == null ? 0 : $about_us.hashCode());
|
||||
Object $title = getTitle();
|
||||
result = result * 31 + ($title == null ? 0 : $title.hashCode());
|
||||
Object $username = getUsername();
|
||||
result = result * 31 + ($username == null ? 0 : $username.hashCode());
|
||||
Object $subscribers = getSubscribers();
|
||||
result = result * 31 + ($subscribers == null ? 0 : $subscribers.hashCode());
|
||||
Object $googleplusid = getGoogleplusid();
|
||||
result = result * 31 + ($googleplusid == null ? 0 : $googleplusid.hashCode());
|
||||
Object $firstname = getFirstname();
|
||||
result = result * 31 + ($firstname == null ? 0 : $firstname.hashCode());
|
||||
Object $lastname = getLastname();
|
||||
result = result * 31 + ($lastname == null ? 0 : $lastname.hashCode());
|
||||
Object $location = getLocation();
|
||||
result = result * 31 + ($location == null ? 0 : $location.hashCode());
|
||||
Object $lastwebaccess = getLastwebaccess();
|
||||
result = result * 31 + ($lastwebaccess == null ? 0 : $lastwebaccess.hashCode());
|
||||
result = result * 31 + getVideoWatchCount();
|
||||
result = result * 31 + getViewcount();
|
||||
Object $totaluploadViews = getTotaluploadViews();
|
||||
result = result * 31 + ($totaluploadViews == null ? 0 : $totaluploadViews.hashCode());
|
||||
Object $avatar = getAvatar();
|
||||
return result * 31 + ($avatar == null ? 0 : $avatar.hashCode());
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "YoutubeChannel(about_us=" + getAbout_us() + ", title=" + getTitle() + ", username=" + getUsername()
|
||||
+ ", subscribers=" + getSubscribers() + ", googleplusid=" + getGoogleplusid() + ", firstname="
|
||||
+ getFirstname() + ", lastname=" + getLastname() + ", location=" + getLocation() + ", lastwebaccess="
|
||||
+ getLastwebaccess() + ", videoWatchCount=" + getVideoWatchCount() + ", viewcount=" + getViewcount()
|
||||
+ ", totaluploadViews=" + getTotaluploadViews() + ", avatar=" + getAvatar() + ")";
|
||||
}
|
||||
}
|
|
@ -1,116 +1,116 @@
|
|||
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.player.Perms.Ranks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* command to ban players
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Ban extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command command to execute
|
||||
* @param description describes the command
|
||||
* @param aliases aliases of command
|
||||
*/
|
||||
public Ban(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(p.isAllowed(Ranks.Moderator)) {
|
||||
if(args.length == 2) {
|
||||
if(Bukkit.getPlayer(args[0]) != null) {
|
||||
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());
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(msgs.PREFIX() + msgs.NOT_ONLINE(args[0]));
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(msgs.PREFIX() + msgs.Core_BAN_USAGE());
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
List<String> list = new ArrayList<>();
|
||||
for(int i = 0; i >= getReasons().size(); i++) {
|
||||
list.add(getReasons().get(i));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all possible ban reasons
|
||||
*/
|
||||
private HashMap<Integer, String> getReasons() {
|
||||
HashMap<Integer, String> map = new HashMap<>();
|
||||
|
||||
map.put(1, "Hacking");
|
||||
map.put(2, "Griefing");
|
||||
map.put(3, "Bugusing");
|
||||
map.put(4, "Insult");
|
||||
map.put(5, "Spam");
|
||||
map.put(6, "Banumgehung");
|
||||
map.put(7, "Advertising");
|
||||
map.put(8, "Trolling");
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ban durations to reason
|
||||
*/
|
||||
private HashMap<Integer, Integer> getBanDurations() {
|
||||
HashMap<Integer, Integer> map = new HashMap<>();
|
||||
|
||||
map.put(1, 60);
|
||||
map.put(2, 30);
|
||||
map.put(3, 20);
|
||||
map.put(4, 10);
|
||||
map.put(5, 5);
|
||||
map.put(6, 120);
|
||||
map.put(7, 15);
|
||||
map.put(8, 25);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
private Integer getKey(String value) {
|
||||
for(int key : getReasons().keySet()) {
|
||||
if(getReasons().get(key).equals(value)) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
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.player.Perms.Ranks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* command to ban players
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Ban extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command command to execute
|
||||
* @param description describes the command
|
||||
* @param aliases aliases of command
|
||||
*/
|
||||
public Ban(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(p.isAllowed(Ranks.Moderator)) {
|
||||
if(args.length == 2) {
|
||||
if(Bukkit.getPlayer(args[0]) != null) {
|
||||
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());
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(msgs.PREFIX() + msgs.NOT_ONLINE(args[0]));
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(msgs.PREFIX() + msgs.Core_BAN_USAGE());
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
List<String> list = new ArrayList<>();
|
||||
for(int i = 0; i >= getReasons().size(); i++) {
|
||||
list.add(getReasons().get(i));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all possible ban reasons
|
||||
*/
|
||||
private HashMap<Integer, String> getReasons() {
|
||||
HashMap<Integer, String> map = new HashMap<>();
|
||||
|
||||
map.put(1, "Hacking");
|
||||
map.put(2, "Griefing");
|
||||
map.put(3, "Bugusing");
|
||||
map.put(4, "Insult");
|
||||
map.put(5, "Spam");
|
||||
map.put(6, "Banumgehung");
|
||||
map.put(7, "Advertising");
|
||||
map.put(8, "Trolling");
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ban durations to reason
|
||||
*/
|
||||
private HashMap<Integer, Integer> getBanDurations() {
|
||||
HashMap<Integer, Integer> map = new HashMap<>();
|
||||
|
||||
map.put(1, 60);
|
||||
map.put(2, 30);
|
||||
map.put(3, 20);
|
||||
map.put(4, 10);
|
||||
map.put(5, 5);
|
||||
map.put(6, 120);
|
||||
map.put(7, 15);
|
||||
map.put(8, 25);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
private Integer getKey(String value) {
|
||||
for(int key : getReasons().keySet()) {
|
||||
if(getReasons().get(key).equals(value)) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,82 +1,82 @@
|
|||
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.player.Perms.Ranks;
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* lets player build
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Build extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* player who can build
|
||||
*/
|
||||
private static HashMap<CustomPlayer, ItemStack[]> players = new HashMap<>();
|
||||
|
||||
/**
|
||||
* @return player that can build
|
||||
*/
|
||||
public static HashMap<CustomPlayer, ItemStack[]> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command command to execute
|
||||
* @param description describes the command
|
||||
* @param aliases aliases of command
|
||||
*/
|
||||
public Build(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(p.isAllowed(Ranks.Builder)) {
|
||||
if(players.containsKey(p)) {
|
||||
p.sendMessage(msgs.PREFIX() + msgs.Core_BUILD_OFF());
|
||||
|
||||
ItemStack[] content = players.get(p);
|
||||
p.getInventory().setContents(content);
|
||||
players.remove(p);
|
||||
p.setGameMode(ServerSettings.getGameMode());
|
||||
|
||||
}else {
|
||||
players.put(p, p.getInventory().getContents());
|
||||
p.sendMessage(msgs.PREFIX() + msgs.Core_BUILD_ON());
|
||||
p.getInventory().clear();
|
||||
p.setGameMode(GameMode.CREATIVE);
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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.player.Perms.Ranks;
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* lets player build
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Build extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* player who can build
|
||||
*/
|
||||
private static HashMap<CustomPlayer, ItemStack[]> players = new HashMap<>();
|
||||
|
||||
/**
|
||||
* @return player that can build
|
||||
*/
|
||||
public static HashMap<CustomPlayer, ItemStack[]> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command command to execute
|
||||
* @param description describes the command
|
||||
* @param aliases aliases of command
|
||||
*/
|
||||
public Build(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(p.isAllowed(Ranks.Builder)) {
|
||||
if(players.containsKey(p)) {
|
||||
p.sendMessage(msgs.PREFIX() + msgs.Core_BUILD_OFF());
|
||||
|
||||
ItemStack[] content = players.get(p);
|
||||
p.getInventory().setContents(content);
|
||||
players.remove(p);
|
||||
p.setGameMode(ServerSettings.getGameMode());
|
||||
|
||||
}else {
|
||||
players.put(p, p.getInventory().getContents());
|
||||
p.sendMessage(msgs.PREFIX() + msgs.Core_BUILD_ON());
|
||||
p.getInventory().clear();
|
||||
p.setGameMode(GameMode.CREATIVE);
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,73 +1,71 @@
|
|||
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 org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* fixes players
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Fix extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command command to execute
|
||||
* @param description describes the command
|
||||
* @param aliases aliases of command
|
||||
*/
|
||||
public Fix(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 == 0) {
|
||||
for(Player player : Bukkit.getOnlinePlayers()) {
|
||||
player.hidePlayer(p);
|
||||
player.showPlayer(p);
|
||||
}
|
||||
p.teleport(p.getLocation());
|
||||
p.sendMessage(msgs.PREFIX() + msgs.Core_FIX_OWN());
|
||||
}
|
||||
if(args.length == 1) {
|
||||
if(Bukkit.getPlayer(args[0]) != null) {
|
||||
CustomPlayer t = CustomPlayer.getPlayer(Bukkit.getPlayer(args[0]).getName());
|
||||
Messages tMsgs = new Messages(t);
|
||||
if(t != p) {
|
||||
p.hidePlayer(t);
|
||||
p.showPlayer(t);
|
||||
p.teleport(p.getLocation());
|
||||
p.sendMessage(msgs.Core_FIX_OTHER(t));
|
||||
t.sendMessage(tMsgs.Core_FIX_BY_OTHER(p));
|
||||
}else {
|
||||
p.chat("/fix");
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(msgs.NOT_ONLINE(args[0]));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
List<String> list = Bukkit.getOnlinePlayers().stream().map(Player::getDisplayName).collect(Collectors.toList());
|
||||
|
||||
return list;
|
||||
}
|
||||
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 org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* fixes players
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Fix extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command command to execute
|
||||
* @param description describes the command
|
||||
* @param aliases aliases of command
|
||||
*/
|
||||
public Fix(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 == 0) {
|
||||
for(Player player : Bukkit.getOnlinePlayers()) {
|
||||
player.hidePlayer(p);
|
||||
player.showPlayer(p);
|
||||
}
|
||||
p.teleport(p.getLocation());
|
||||
p.sendMessage(msgs.PREFIX() + msgs.Core_FIX_OWN());
|
||||
}
|
||||
if(args.length == 1) {
|
||||
if(Bukkit.getPlayer(args[0]) != null) {
|
||||
CustomPlayer t = CustomPlayer.getPlayer(Bukkit.getPlayer(args[0]).getName());
|
||||
Messages tMsgs = new Messages(t);
|
||||
if(t != p) {
|
||||
p.hidePlayer(t);
|
||||
p.showPlayer(t);
|
||||
p.teleport(p.getLocation());
|
||||
p.sendMessage(msgs.Core_FIX_OTHER(t));
|
||||
t.sendMessage(tMsgs.Core_FIX_BY_OTHER(p));
|
||||
}else {
|
||||
p.chat("/fix");
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(msgs.NOT_ONLINE(args[0]));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return Bukkit.getOnlinePlayers().stream().map(Player::getDisplayName).collect(Collectors.toList());
|
||||
}
|
||||
}
|
|
@ -1,87 +1,87 @@
|
|||
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.player.Perms.Ranks;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* changes game modes
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class GameMode extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command command to execute
|
||||
* @param description describes the command
|
||||
* @param aliases aliases of command
|
||||
*/
|
||||
public GameMode(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(p.isAllowed(Ranks.Builder)) {
|
||||
if(args.length == 1) {
|
||||
String mode = args[0];
|
||||
p.setGameMode(getModeFromString(mode));
|
||||
p.sendMessage(msgs.Core_GM_CHANGED());
|
||||
}if(args.length == 0){
|
||||
p.sendMessage(msgs.Core_GM_USAGE());
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
List<String> list = new ArrayList<>();
|
||||
|
||||
list.add("0");
|
||||
list.add("1");
|
||||
list.add("2");
|
||||
list.add("3");
|
||||
list.add("Survival");
|
||||
list.add("Creative");
|
||||
list.add("Adventure");
|
||||
list.add("Spectator");
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string Mode
|
||||
* @return GameMode
|
||||
*/
|
||||
private org.bukkit.GameMode getModeFromString(String string) {
|
||||
switch(string) {
|
||||
case "0" : return org.bukkit.GameMode.SURVIVAL;
|
||||
case "1" : return org.bukkit.GameMode.CREATIVE;
|
||||
case "2": return org.bukkit.GameMode.ADVENTURE;
|
||||
case "3" : return org.bukkit.GameMode.SPECTATOR;
|
||||
case "Survial" : return org.bukkit.GameMode.SURVIVAL;
|
||||
case "Creative" : return org.bukkit.GameMode.CREATIVE;
|
||||
case "Adventure" : return org.bukkit.GameMode.ADVENTURE;
|
||||
case "Spectator" : return org.bukkit.GameMode.SPECTATOR;
|
||||
default: return org.bukkit.GameMode.SPECTATOR;
|
||||
}
|
||||
}
|
||||
|
||||
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.player.Perms.Ranks;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* changes game modes
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class GameMode extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command command to execute
|
||||
* @param description describes the command
|
||||
* @param aliases aliases of command
|
||||
*/
|
||||
public GameMode(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(p.isAllowed(Ranks.Builder)) {
|
||||
if(args.length == 1) {
|
||||
String mode = args[0];
|
||||
p.setGameMode(getModeFromString(mode));
|
||||
p.sendMessage(msgs.Core_GM_CHANGED());
|
||||
}if(args.length == 0){
|
||||
p.sendMessage(msgs.Core_GM_USAGE());
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
List<String> list = new ArrayList<>();
|
||||
|
||||
list.add("0");
|
||||
list.add("1");
|
||||
list.add("2");
|
||||
list.add("3");
|
||||
list.add("Survival");
|
||||
list.add("Creative");
|
||||
list.add("Adventure");
|
||||
list.add("Spectator");
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string Mode
|
||||
* @return GameMode
|
||||
*/
|
||||
private org.bukkit.GameMode getModeFromString(String string) {
|
||||
switch(string) {
|
||||
case "0" : return org.bukkit.GameMode.SURVIVAL;
|
||||
case "1" : return org.bukkit.GameMode.CREATIVE;
|
||||
case "2": return org.bukkit.GameMode.ADVENTURE;
|
||||
case "3" : return org.bukkit.GameMode.SPECTATOR;
|
||||
case "Survial" : return org.bukkit.GameMode.SURVIVAL;
|
||||
case "Creative" : return org.bukkit.GameMode.CREATIVE;
|
||||
case "Adventure" : return org.bukkit.GameMode.ADVENTURE;
|
||||
case "Spectator" : return org.bukkit.GameMode.SPECTATOR;
|
||||
default: return org.bukkit.GameMode.SPECTATOR;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,58 +1,58 @@
|
|||
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.player.Perms.Ranks;
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* mutes the whole server
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class GlobalMute extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command command to execute
|
||||
* @param description describes the command
|
||||
* @param aliases aliases of command
|
||||
*/
|
||||
public GlobalMute(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(p.isAllowed(Ranks.Moderator)) {
|
||||
if(ServerSettings.isMute()) {
|
||||
ServerSettings.setMute(false);
|
||||
p.sendMessage(msgs.Core_GLOBALMUTE_OFF());
|
||||
}else {
|
||||
ServerSettings.setMute(true);
|
||||
p.sendMessage(msgs.Core_GLOBALMUTE_ON());
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
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.player.Perms.Ranks;
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* mutes the whole server
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class GlobalMute extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command command to execute
|
||||
* @param description describes the command
|
||||
* @param aliases aliases of command
|
||||
*/
|
||||
public GlobalMute(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(p.isAllowed(Ranks.Moderator)) {
|
||||
if(ServerSettings.isMute()) {
|
||||
ServerSettings.setMute(false);
|
||||
p.sendMessage(msgs.Core_GLOBALMUTE_OFF());
|
||||
}else {
|
||||
ServerSettings.setMute(true);
|
||||
p.sendMessage(msgs.Core_GLOBALMUTE_ON());
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,63 +1,67 @@
|
|||
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.youtube.YTAPI;
|
||||
import eu.univento.core.api.youtube.YoutubeChannel;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* sets player to youtube rank
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Youtuber extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command command to execute
|
||||
* @param description describes the command
|
||||
* @param aliases aliases of command
|
||||
*/
|
||||
public Youtuber(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) {
|
||||
YoutubeChannel yt = YTAPI.getYTChannelFromName(args[0]);
|
||||
if(yt != null) {
|
||||
p.sendMessage("§aBenutzername: " + yt.getUsername());
|
||||
p.sendMessage("§aGooglePlus ID: " + yt.getGoogleplusid());
|
||||
p.sendMessage("§aZuletzt online: " + yt.getLastwebaccess());
|
||||
p.sendMessage("§aVon: " + yt.getLocation());
|
||||
p.sendMessage("§aAbos: " + yt.getSubscribers());
|
||||
p.sendMessage("§aVideo Watch Count: " + yt.getVideoWatchCount());
|
||||
p.sendMessage("§aViewcount: " + yt.getViewcount());
|
||||
}else {
|
||||
p.sendMessage(msgs.PREFIX() + "§cDer Youtube Kanal exsistiert nicht");
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(msgs.PREFIX() + "§cBenutze doch /youtuber <Channel Name>");
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
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.player.Perms.Ranks;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* nick command
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Nick extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command command to execute
|
||||
* @param description describes the command
|
||||
* @param aliases aliases of command
|
||||
*/
|
||||
public Nick(Core plugin, String command, String description, String... aliases) {
|
||||
super(plugin, command, description, aliases);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@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(p.isAllowed(Ranks.Youtuber)) {
|
||||
if(p.isNicked()) {
|
||||
p.getTeam().removeEntry(p.getDisplayName());
|
||||
p.setNicked(false);
|
||||
p.setDisplayName(p.getName());
|
||||
p.getTeam().addEntry(p.getDisplayName());
|
||||
p.sendMessage(msgs.PREFIX() + msgs.Core_NICK_OFF());
|
||||
p.unnick();
|
||||
}else {
|
||||
p.getTeam().removeEntry(p.getDisplayName());
|
||||
p.setNicked(true);
|
||||
p.setDisplayName(p.getNick());
|
||||
p.getTeam().addEntry(p.getDisplayName());
|
||||
p.sendMessage(msgs.PREFIX() + msgs.Core_NICK_ON());
|
||||
p.nick(p.getNick());
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,70 +1,70 @@
|
|||
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.player.Perms.Ranks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* lets other player run commands
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class RunAs extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command command to execute
|
||||
* @param description describes the command
|
||||
* @param aliases aliases of command
|
||||
*/
|
||||
public RunAs(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(p.isAllowed(Ranks.Admin)) {
|
||||
if(args.length >= 2) {
|
||||
CustomPlayer t = CustomPlayer.getPlayer(Bukkit.getPlayer(args[0]).getName());
|
||||
if(t != null) {
|
||||
String msg = "";
|
||||
for(int i = 1; i < args.length; i++) {
|
||||
msg = msg + args[i] + " ";
|
||||
}
|
||||
t.chat(msg);
|
||||
p.sendMessage(msgs.Core_RUNAS_RUN(t));
|
||||
return true;
|
||||
}else {
|
||||
p.sendMessage(msgs.NOT_ONLINE(args[0]));
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(msgs.Core_RUNAS_USAGE());
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return Bukkit.getOnlinePlayers().stream().map(Player::getDisplayName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
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.player.Perms.Ranks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* lets other player run commands
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class RunAs extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command command to execute
|
||||
* @param description describes the command
|
||||
* @param aliases aliases of command
|
||||
*/
|
||||
public RunAs(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(p.isAllowed(Ranks.Admin)) {
|
||||
if(args.length >= 2) {
|
||||
CustomPlayer t = CustomPlayer.getPlayer(Bukkit.getPlayer(args[0]).getName());
|
||||
if(t != null) {
|
||||
String msg = "";
|
||||
for(int i = 1; i < args.length; i++) {
|
||||
msg = msg + args[i] + " ";
|
||||
}
|
||||
t.chat(msg);
|
||||
p.sendMessage(msgs.Core_RUNAS_RUN(t));
|
||||
return true;
|
||||
}else {
|
||||
p.sendMessage(msgs.NOT_ONLINE(args[0]));
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(msgs.Core_RUNAS_USAGE());
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return Bukkit.getOnlinePlayers().stream().map(Player::getDisplayName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,103 +1,102 @@
|
|||
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.player.Perms.Ranks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* sets ranks for players
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class SetRank extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command command to execute
|
||||
* @param description describes the command
|
||||
* @param aliases aliases of command
|
||||
*/
|
||||
public SetRank(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(p.isAllowed(Ranks.HeadBuilder)) {
|
||||
if(args.length == 2) {
|
||||
Ranks rank = Ranks.valueOf(args[1]);
|
||||
if(rank != null) {
|
||||
if(Bukkit.getPlayer(args[0]) != null) {
|
||||
CustomPlayer player = CustomPlayer.getPlayer(Bukkit.getPlayer(args[0]).getName());
|
||||
if(p.isAllowed(Ranks.HeadBuilder) && rank == Ranks.Builder) {
|
||||
player.setRank(rank);
|
||||
p.sendMessage(msgs.PREFIX() + msgs.Core_SETRANK_SET(player, player.getRank()));
|
||||
player.kickPlayer(msgs.Core_SETRANK_KICK());
|
||||
}if(p.isAllowed(Ranks.SrModerator) && rank == Ranks.Moderator) {
|
||||
player.setRank(rank);
|
||||
p.sendMessage(msgs.PREFIX() + msgs.Core_SETRANK_SET(player, player.getRank()));
|
||||
player.kickPlayer(msgs.Core_SETRANK_KICK());
|
||||
}if(p.isAllowed(Ranks.SrModerator) && rank == Ranks.Supporter) {
|
||||
player.setRank(rank);
|
||||
p.sendMessage(msgs.PREFIX() + msgs.Core_SETRANK_SET(player, player.getRank()));
|
||||
player.kickPlayer(msgs.Core_SETRANK_KICK());
|
||||
}if(p.isAllowed(Ranks.SrDeveloper) && rank == Ranks.Developer) {
|
||||
player.setRank(rank);
|
||||
p.sendMessage(msgs.PREFIX() + msgs.Core_SETRANK_SET(player, player.getRank()));
|
||||
player.kickPlayer(msgs.Core_SETRANK_KICK());
|
||||
}
|
||||
if(p.isAllowed(Ranks.Admin)) {
|
||||
player.setRank(rank);
|
||||
p.sendMessage(msgs.PREFIX() + msgs.Core_SETRANK_SET(player, player.getRank()));
|
||||
player.kickPlayer(msgs.Core_SETRANK_KICK());
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(msgs.NOT_ONLINE(args[0]));
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(msgs.Core_SETRANK_NO_RANK());
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(msgs.Core_SETRANK_NO_RANK());
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
List<String> list = Bukkit.getOnlinePlayers().stream().map(Player::getDisplayName).collect(Collectors.toList());
|
||||
|
||||
list.add("Admin");
|
||||
list.add("Developer");
|
||||
list.add("SrModerator");
|
||||
list.add("Moderator");
|
||||
list.add("HeadBuilder");
|
||||
list.add("Builder");
|
||||
list.add("Supporter");
|
||||
list.add("Youtuber");
|
||||
list.add("Premium");
|
||||
list.add("Player");
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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.player.Perms.Ranks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* sets ranks for players
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class SetRank extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command command to execute
|
||||
* @param description describes the command
|
||||
* @param aliases aliases of command
|
||||
*/
|
||||
public SetRank(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());
|
||||
if(p.isAllowed(Ranks.HeadBuilder)) {
|
||||
if(args.length == 2) {
|
||||
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());
|
||||
}
|
||||
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());
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(p.getMessages().NOT_ONLINE(args[0]));
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(p.getMessages().Core_SETRANK_NO_RANK());
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(p.getMessages().Core_SETRANK_NO_RANK());
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(p.getMessages().NO_PERMS());
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
List<String> list = Bukkit.getOnlinePlayers().stream().map(Player::getDisplayName).collect(Collectors.toList());
|
||||
|
||||
list.add("Admin");
|
||||
list.add("Developer");
|
||||
list.add("SrModerator");
|
||||
list.add("Moderator");
|
||||
list.add("HeadBuilder");
|
||||
list.add("Builder");
|
||||
list.add("Supporter");
|
||||
list.add("Youtuber");
|
||||
list.add("Premium");
|
||||
list.add("Player");
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) univento.eu 2016. Any attempt to use these program(s) without permission may result in a penalty of up to 1.000€
|
||||
*/
|
||||
|
||||
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.server.Game;
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
*/
|
||||
public class Stats extends AutoCommand<Core> {
|
||||
|
||||
public Stats(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());
|
||||
Game game = ServerSettings.getPlayedGame();
|
||||
if(args.length == 0) {
|
||||
p.sendMessage("§aDeine " + game.toString() + " Statistiken");
|
||||
p.sendMessage("Tötungen: " + p.getStatistics(game).getKills());
|
||||
p.sendMessage("Tode: " + p.getStatistics(game).getDeaths());
|
||||
p.sendMessage("Gewinne: " + p.getStatistics(game).getWins());
|
||||
p.sendMessage("Gespielte Runden: " + p.getStatistics(game).getPlayedRounds());
|
||||
p.sendMessage("Spielzeit: " + p.getStatistics(game).getPlaytime());
|
||||
}
|
||||
if(args.length == 1) {
|
||||
if(ServerSettings.getGameState().equals("Lobby") || ServerSettings.getGameState().equals("Restart")) {
|
||||
if(Bukkit.getPlayer(args[0]) != null) {
|
||||
CustomPlayer t = CustomPlayer.getPlayer(args[0]);
|
||||
p.sendMessage("§a" + game.toString() + " Statistiken von " + t.getDisplayName());
|
||||
p.sendMessage("Tötungen: " + t.getStatistics(game).getKills());
|
||||
p.sendMessage("Tode: " + t.getStatistics(game).getDeaths());
|
||||
p.sendMessage("Gewinne: " + t.getStatistics(game).getWins());
|
||||
p.sendMessage("Gespielte Runden: " + t.getStatistics(game).getPlayedRounds());
|
||||
p.sendMessage("Spielzeit: " + t.getStatistics(game).getPlaytime());
|
||||
}else{
|
||||
p.sendMessage(p.getMessages().PREFIX() + p.getMessages().NOT_ONLINE(args[0]));
|
||||
}
|
||||
}else{
|
||||
p.sendMessage(p.getMessages().PREFIX() + " §cDu kannst dir im Moment keine Statistiken von anderen Spielern anschauen");
|
||||
}
|
||||
}else{
|
||||
|
||||
}
|
||||
}else{
|
||||
sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,61 +1,61 @@
|
|||
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.player.Perms.Ranks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* prints infos about the server
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class SystemInfo extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command command to execute
|
||||
* @param description describes the command
|
||||
* @param aliases aliases of command
|
||||
*/
|
||||
public SystemInfo(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(p.isAllowed(Ranks.SrModerator)) {
|
||||
Runtime run = Runtime.getRuntime();
|
||||
p.sendMessage("§6§l===SystemInfo <SpigotServer>===");
|
||||
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");
|
||||
p.sendMessage("§6avaiable cores: " + run.availableProcessors());
|
||||
p.sendMessage("§6OS: " + System.getProperty("os.name"));
|
||||
p.sendMessage("§6OS version: " + System.getProperty("os.version"));
|
||||
p.sendMessage("§6OS architecture: " + System.getProperty("os.arch"));
|
||||
}else {
|
||||
p.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
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.player.Perms.Ranks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* prints infos about the server
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class SystemInfo extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command command to execute
|
||||
* @param description describes the command
|
||||
* @param aliases aliases of command
|
||||
*/
|
||||
public SystemInfo(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(p.isAllowed(Ranks.SrModerator)) {
|
||||
Runtime run = Runtime.getRuntime();
|
||||
p.sendMessage("§6§l===SystemInfo <SpigotServer>===");
|
||||
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");
|
||||
p.sendMessage("§6avaiable cores: " + run.availableProcessors());
|
||||
p.sendMessage("§6OS: " + System.getProperty("os.name"));
|
||||
p.sendMessage("§6OS version: " + System.getProperty("os.version"));
|
||||
p.sendMessage("§6OS architecture: " + System.getProperty("os.arch"));
|
||||
}else {
|
||||
p.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,42 +1,42 @@
|
|||
package eu.univento.core.commands;
|
||||
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.AutoCommand;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* sets ts groups according to player rank
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class TS extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command command to execute
|
||||
* @param description describes the command
|
||||
* @param aliases aliases of command
|
||||
*/
|
||||
public TS(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());
|
||||
p.verifyTs();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
package eu.univento.core.commands;
|
||||
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.AutoCommand;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* sets ts groups according to player rank
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class TS extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command command to execute
|
||||
* @param description describes the command
|
||||
* @param aliases aliases of command
|
||||
*/
|
||||
public TS(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());
|
||||
p.sendMessage("Der TS Befehl ist momentan deaktivert");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,65 +1,65 @@
|
|||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,77 +1,77 @@
|
|||
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.player.Perms.Ranks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* vanish players
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Vanish extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* contains vanished players
|
||||
*/
|
||||
private static ArrayList<CustomPlayer> players = new ArrayList<CustomPlayer>();
|
||||
/**
|
||||
* @return vanished players
|
||||
*/
|
||||
public static ArrayList<CustomPlayer> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command command to execute
|
||||
* @param description describes the command
|
||||
* @param aliases aliases of command
|
||||
*/
|
||||
public Vanish(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(p.isAllowed(Ranks.Moderator)) {
|
||||
if(players.contains(p)) {
|
||||
for(Player players : Bukkit.getOnlinePlayers()) {
|
||||
players.showPlayer(p);
|
||||
}
|
||||
players.remove(p);
|
||||
p.sendMessage(msgs.PREFIX() + msgs.Core_VANISH_OFF());
|
||||
}else {
|
||||
for(Player players : Bukkit.getOnlinePlayers()) {
|
||||
players.hidePlayer(p);
|
||||
}
|
||||
players.add(p);
|
||||
p.sendMessage(msgs.PREFIX() + msgs.Core_VANISH_ON());
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
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.player.Perms.Ranks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* vanish players
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Vanish extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* contains vanished players
|
||||
*/
|
||||
private static ArrayList<CustomPlayer> players = new ArrayList<CustomPlayer>();
|
||||
/**
|
||||
* @return vanished players
|
||||
*/
|
||||
public static ArrayList<CustomPlayer> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command command to execute
|
||||
* @param description describes the command
|
||||
* @param aliases aliases of command
|
||||
*/
|
||||
public Vanish(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(p.isAllowed(Ranks.Moderator)) {
|
||||
if(players.contains(p)) {
|
||||
for(Player players : Bukkit.getOnlinePlayers()) {
|
||||
players.showPlayer(p);
|
||||
}
|
||||
players.remove(p);
|
||||
p.sendMessage(msgs.PREFIX() + msgs.Core_VANISH_OFF());
|
||||
}else {
|
||||
for(Player players : Bukkit.getOnlinePlayers()) {
|
||||
players.hidePlayer(p);
|
||||
}
|
||||
players.add(p);
|
||||
p.sendMessage(msgs.PREFIX() + msgs.Core_VANISH_ON());
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,53 +1,53 @@
|
|||
package eu.univento.core.listeners;
|
||||
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.commands.Build;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockCanBuildEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
/**
|
||||
* some stuff with blocks
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Blocks implements Listener{
|
||||
|
||||
/**
|
||||
* cancels block placement if player is not in build mode
|
||||
* @param e BlockPlaceEvent
|
||||
*/
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
||||
if(!Build.getPlayers().containsKey(p)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* cancels block breaking if player is not in build mode
|
||||
* @param e BlockBreakEvent
|
||||
*/
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
||||
if(!Build.getPlayers().containsKey(p)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* sets buildable true so players can place blocks, even if vanished player is standing there
|
||||
* @param e BlockCanBuildEvent
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onBlockCanBuildEvent(BlockCanBuildEvent e){
|
||||
e.setBuildable(true);
|
||||
}
|
||||
|
||||
package eu.univento.core.listeners;
|
||||
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.commands.Build;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockCanBuildEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
/**
|
||||
* some stuff with blocks
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Blocks implements Listener{
|
||||
|
||||
/**
|
||||
* cancels block placement if player is not in build mode
|
||||
* @param e BlockPlaceEvent
|
||||
*/
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
||||
if(!Build.getPlayers().containsKey(p)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* cancels block breaking if player is not in build mode
|
||||
* @param e BlockBreakEvent
|
||||
*/
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
||||
if(!Build.getPlayers().containsKey(p)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* sets buildable true so players can place blocks, even if vanished player is standing there
|
||||
* @param e BlockCanBuildEvent
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onBlockCanBuildEvent(BlockCanBuildEvent e){
|
||||
e.setBuildable(true);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,46 +1,47 @@
|
|||
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.server.ServerSettings;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
/**
|
||||
* manages chat
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Chat implements Listener{
|
||||
|
||||
/**
|
||||
* @param e AsyncPlayerChatEvent
|
||||
*/
|
||||
@EventHandler
|
||||
public void onChat(AsyncPlayerChatEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer().getName());
|
||||
Messages msgs = new Messages(p);
|
||||
if(ServerSettings.isMute()) {
|
||||
if(!p.isAllowed(Ranks.Supporter)) {
|
||||
e.setCancelled(true);
|
||||
p.sendMessage(msgs.PREFIX() + msgs.Core_SERVER_MUTED());
|
||||
}
|
||||
}
|
||||
String format;
|
||||
if(p.isAllowed(Ranks.Youtuber)) {
|
||||
if(p.isNicked() && !ServerSettings.isLobby()) {
|
||||
format = p.getPrefix() + p.getDisplayName() + p.getSuffix() + ChatColor.translateAlternateColorCodes('&', e.getMessage());
|
||||
}else {
|
||||
format = p.getPrefix() + p.getDisplayName() + p.getSuffix() + ChatColor.translateAlternateColorCodes('&', e.getMessage());
|
||||
}
|
||||
}else {
|
||||
format = p.getPrefix() + p.getDisplayName() + p.getSuffix() + e.getMessage();
|
||||
}
|
||||
e.setFormat(format);
|
||||
|
||||
}
|
||||
|
||||
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.server.ServerSettings;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
/**
|
||||
* manages chat
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Chat implements Listener{
|
||||
|
||||
/**
|
||||
* @param e AsyncPlayerChatEvent
|
||||
*/
|
||||
@EventHandler
|
||||
public void onChat(AsyncPlayerChatEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer().getName());
|
||||
Messages msgs = new Messages(p);
|
||||
if(ServerSettings.isMute()) {
|
||||
if(!p.isAllowed(Ranks.Supporter)) {
|
||||
e.setCancelled(true);
|
||||
p.sendMessage(msgs.PREFIX() + msgs.Core_SERVER_MUTED());
|
||||
}
|
||||
}
|
||||
String format;
|
||||
if(p.isAllowed(Ranks.Youtuber)) {
|
||||
if(p.isNicked() && !ServerSettings.isLobby()) {
|
||||
format = p.getPrefix() + p.getDisplayName() + p.getSuffix() + ChatColor.translateAlternateColorCodes('&', e.getMessage());
|
||||
}else {
|
||||
format = p.getPrefix() + p.getDisplayName() + p.getSuffix() + ChatColor.translateAlternateColorCodes('&', e.getMessage());
|
||||
}
|
||||
}else {
|
||||
format = p.getPrefix() + p.getDisplayName() + p.getSuffix() + e.getMessage();
|
||||
}
|
||||
if(format.contains("%")) format = format.replace("%", "%%");
|
||||
e.setFormat(format);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,61 +1,61 @@
|
|||
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 org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.help.HelpTopic;
|
||||
|
||||
/**
|
||||
* commands
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Commands implements Listener{
|
||||
|
||||
|
||||
/**
|
||||
* prints unknown command message
|
||||
* @param e PlayerCommandPreprocessEvent
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
||||
Messages msgs = new Messages(p);
|
||||
if (!e.isCancelled()) {
|
||||
String cmd = e.getMessage().split(" ")[0];
|
||||
HelpTopic topic = Bukkit.getServer().getHelpMap().getHelpTopic(cmd);
|
||||
if (topic == null) {
|
||||
p.sendMessage(msgs.COMMAND_NOT_FOUND());
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
String cmd = e.getMessage();
|
||||
if(cmd.equalsIgnoreCase("/rl") || cmd.equalsIgnoreCase("/reload")) {
|
||||
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);
|
||||
}else {
|
||||
p.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.help.HelpTopic;
|
||||
|
||||
/**
|
||||
* commands
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Commands implements Listener{
|
||||
|
||||
|
||||
/**
|
||||
* prints unknown command message
|
||||
* @param e PlayerCommandPreprocessEvent
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
||||
Messages msgs = new Messages(p);
|
||||
if (!e.isCancelled()) {
|
||||
String cmd = e.getMessage().split(" ")[0];
|
||||
HelpTopic topic = Bukkit.getServer().getHelpMap().getHelpTopic(cmd);
|
||||
if (topic == null) {
|
||||
p.sendMessage(msgs.COMMAND_NOT_FOUND());
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
String cmd = e.getMessage();
|
||||
if(cmd.equalsIgnoreCase("/rl") || cmd.equalsIgnoreCase("/reload")) {
|
||||
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);
|
||||
}else {
|
||||
p.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue