first commit
This commit is contained in:
commit
8369f7ffc9
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="lib" path="F:/DevServer/Spigot/spigot.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
|
@ -0,0 +1 @@
|
|||
/bin/
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Core</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,11 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
|
@ -0,0 +1,162 @@
|
|||
package de.joethei.core;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import de.joethei.core.api.Messages;
|
||||
import de.joethei.core.api.Config;
|
||||
import de.joethei.core.api.CustomPlayer;
|
||||
import de.joethei.core.api.MySQL;
|
||||
import de.joethei.core.api.Settings;
|
||||
import de.joethei.core.commands.Ban;
|
||||
import de.joethei.core.commands.Build;
|
||||
import de.joethei.core.commands.Fix;
|
||||
import de.joethei.core.commands.GameMode;
|
||||
import de.joethei.core.commands.GlobalMute;
|
||||
import de.joethei.core.commands.RunAs;
|
||||
import de.joethei.core.commands.SetRank;
|
||||
import de.joethei.core.commands.SystemInfo;
|
||||
import de.joethei.core.commands.Vanish;
|
||||
import de.joethei.core.commands.Youtuber;
|
||||
import de.joethei.core.listeners.Blocks;
|
||||
import de.joethei.core.listeners.Chat;
|
||||
import de.joethei.core.listeners.Commands;
|
||||
import de.joethei.core.listeners.JoinQuit;
|
||||
|
||||
/**
|
||||
* main class
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Core extends JavaPlugin{
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* nick names of players
|
||||
*/
|
||||
public static HashMap<CustomPlayer, String> nicks = new HashMap<CustomPlayer, String>();
|
||||
|
||||
/**
|
||||
* logging and stuff
|
||||
*/
|
||||
private static Logger log = Bukkit.getLogger();
|
||||
|
||||
/**
|
||||
* @param level Log level
|
||||
* @param string String
|
||||
*/
|
||||
public static void log(Level level, String string) {
|
||||
log.log(level, "[" + Messages.CONSOLE_PREFIX + Core.getInstance().getDescription().getName() + "] " + string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Settings.setDebug(true);
|
||||
Settings.setBuild(true);
|
||||
instance = this;
|
||||
if(Settings.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);
|
||||
|
||||
if(Settings.isDebug()) log(Level.INFO, "Events registriert");
|
||||
|
||||
String[] fix = {""};
|
||||
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 Server 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 Server", globalmute);
|
||||
|
||||
String[] youtuber = {""};
|
||||
new Youtuber(this, "youtuber", "setzt Spieler in den Youtuber Rang", youtuber);
|
||||
|
||||
String[] ban = {""};
|
||||
new Ban(this, "ban", "Bannt Spieler", ban);
|
||||
|
||||
if(Settings.isBuild()) {
|
||||
String[] build = {"b"};
|
||||
new Build(this, "build", "Setzt den Spieler in den Bau Modus", build);
|
||||
|
||||
if(Settings.isDebug()) log(Level.INFO, "Build Modus aktiviert");
|
||||
}
|
||||
if(Settings.isDebug()) log(Level.INFO, "Alle Befehle registriert");
|
||||
|
||||
try
|
||||
{
|
||||
MySQL tempSQL = sql;
|
||||
tempSQL.openConnection();
|
||||
|
||||
tempSQL.getConnection().createStatement().execute("CREATE TABLE IF NOT EXISTS PlayerData(ID bigint PRIMARY KEY auto_increment, player_uuid varchar(50), FirstJoin TIMESTAMP default now(), Coins bigint, mute boolean, Rank varchar(10), nick boolean, FastMenu boolean, teleport boolean);");
|
||||
if(Settings.isDebug()) log(Level.INFO, "MySQL PlayerData ausgeführt");
|
||||
|
||||
tempSQL.getConnection().createStatement().execute("CREATE TABLE IF NOT EXISTS bans(ID bigint PRIMARY KEY auto_increment, player_uuid varchar(50), Reason varchar(50), who varchar(50));");
|
||||
if(Settings.isDebug()) log(Level.INFO, "MySQL Bans erstellt");
|
||||
|
||||
tempSQL.getConnection().createStatement().execute("CREATE TABLE IF NOT EXISTS bugs(ID bigint PRIMARY KEY auto_increment, player_uuid varchar(50), time timestamp, msg varchar(250));");
|
||||
if(Settings.isDebug()) log(Level.INFO, "MySQL Bugs erstellt");
|
||||
|
||||
tempSQL.getConnection().createStatement().execute("CREATE TABLE IF NOT EXISTS Friends(ID bigint PRIMARY KEY auto_increment, player_uuid VARCHAR(64), Friends VARCHAR(2500));");
|
||||
if(Settings.isDebug()) log(Level.INFO, "MySQL Friends erstellt");
|
||||
|
||||
tempSQL.getConnection().createStatement().execute("CREATE TABLE IF NOT EXISTS Messages(ID bigint PRIMARY KEY auto_increment,Ident varchar(25), Message varchar(250));");
|
||||
if(Settings.isDebug()) log(Level.INFO, "MySQL Messages erstellt");
|
||||
|
||||
tempSQL.closeConnection();
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
||||
log(Level.INFO, "Plugin ver. " + getDescription().getVersion() + " gestartet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
Core.log(Level.INFO, "Plugin beendet");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
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;
|
||||
|
||||
public class Actionbar {
|
||||
|
||||
|
||||
public static void send(Player p, String text) {
|
||||
|
||||
CraftPlayer cp = (CraftPlayer)p;
|
||||
|
||||
IChatBaseComponent textC = ChatSerializer.a("{\"text\": \"" + text + "\"}");
|
||||
|
||||
PacketPlayOutChat actionbar = new PacketPlayOutChat(textC);
|
||||
|
||||
try {
|
||||
Field field = actionbar.getClass().getDeclaredField("a");
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
field.set(actionbar, (byte)2);
|
||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (NoSuchFieldException | SecurityException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
cp.getHandle().playerConnection.sendPacket(actionbar);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
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;
|
||||
|
||||
public abstract class AutoCommand<P extends JavaPlugin> extends Command {
|
||||
|
||||
/**
|
||||
* @author PostCrafter
|
||||
* @see http://postcrafter.de/viewtopic.php?f=15&t=143
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import de.joethei.core.Core;
|
||||
import de.joethei.core.api.utils.NameFetcher;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public static void setBanned(Player p, String reason, Player who, int time)throws SQLException, ClassNotFoundException {
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
String uuid = p.getUniqueId().toString();
|
||||
String whouuid = who.getUniqueId().toString();
|
||||
|
||||
Date date = new Date();
|
||||
date.setTime(date.getTime() + (time + 24));
|
||||
|
||||
Core.returnSQL().getConnection().createStatement().execute("INSERT INTO bans (player_uuid, Reason, who, time) VALUES ('" + uuid + "', '" + reason + "', '" + whouuid + "', '" + date.getTime() + "');");
|
||||
p.kickPlayer("§cDu wurdest gebannt. §6Grund: " + reason + "\nDauer: " + time);
|
||||
who.sendMessage("§cDu hast den Spieler " + p.getName() + " für " + time + " Tage gebannt");
|
||||
sql.closeConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* unbans a player
|
||||
* @param p player
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
* @throws ClassNotFoundException class couldn't be found
|
||||
*/
|
||||
public static void unban(OfflinePlayer p)throws SQLException, ClassNotFoundException{
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
String uuid = p.getUniqueId().toString();
|
||||
Core.returnSQL().getConnection().createStatement().executeUpdate("DELETE FROM bans WHERE player_uuid ='" + uuid + "';");
|
||||
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
|
||||
*/
|
||||
public static boolean isBanned(OfflinePlayer p)throws SQLException, ClassNotFoundException {
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
String uuid = p.getUniqueId().toString();
|
||||
ResultSet rs = Core.returnSQL().getConnection().createStatement().executeQuery("SELECT * FROM bans WHERE player_uuid='" + uuid + "';");
|
||||
sql.closeConnection();
|
||||
return rs.next();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public static String getBanReason(OfflinePlayer p)throws SQLException, ClassNotFoundException {
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
String uuid = p.getUniqueId().toString();
|
||||
ResultSet rs = Core.returnSQL().getConnection().createStatement().executeQuery("SELECT * FROM bans WHERE player_uuid='" + uuid + "';");
|
||||
if (!rs.next()) {
|
||||
sql.closeConnection();
|
||||
return null;
|
||||
}
|
||||
sql.closeConnection();
|
||||
return rs.getString("Reason");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public static String getWhoBanned(OfflinePlayer p)throws SQLException, ClassNotFoundException {
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
String uuid = p.getUniqueId().toString();
|
||||
ResultSet rs = Core.returnSQL().getConnection().createStatement().executeQuery("SELECT * FROM bans WHERE player_uuid='" + uuid + "';");
|
||||
if (!rs.next()) {
|
||||
sql.closeConnection();
|
||||
return null;
|
||||
}
|
||||
String whouuid = rs.getString("who");
|
||||
UUID who = UUID.fromString(whouuid);
|
||||
List<UUID> list = new ArrayList<UUID>();
|
||||
list.add(who);
|
||||
NameFetcher name = new NameFetcher(list);
|
||||
sql.closeConnection();
|
||||
return name.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import de.joethei.core.api.utils.FakeDragon;
|
||||
import de.joethei.core.api.utils.FakeWither;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class BossBar
|
||||
{
|
||||
public static Map<Player, String> playerdragonbartask = new HashMap<Player, String>();
|
||||
public static Map<Player, Float> healthdragonbartask = new HashMap<Player, Float>();
|
||||
public static Map<Player, Integer> cooldownsdragonbar = new HashMap<Player, Integer>();
|
||||
public static Map<Player, Integer> starttimerdragonbar = new HashMap<Player, Integer>();
|
||||
|
||||
public static Map<Player, String> playerwitherbartask = new HashMap<Player, String>();
|
||||
public static Map<Player, Float> healthwitherbartask = new HashMap<Player, Float>();
|
||||
public static Map<Player, Integer> cooldownswitherbar = new HashMap<Player, Integer>();
|
||||
public static Map<Player, Integer> starttimerwitherbar = new HashMap<Player, Integer>();
|
||||
|
||||
public static void setBarDragon(Player p, String text) {
|
||||
playerdragonbartask.put(p, text);
|
||||
FakeDragon.setBossBartext(p, text);
|
||||
}
|
||||
|
||||
public static void setBarDragonHealth(Player p, String text, float health)
|
||||
{
|
||||
if ((health <= 0.0F) || (health > 100.0F)) { health = 100.0F; text = "health must be between 1 and 100 it's a %"; }
|
||||
playerdragonbartask.put(p, text);
|
||||
healthdragonbartask.put(p, Float.valueOf(health / 100.0F * 200.0F));
|
||||
FakeDragon.setBossBar(p, text, health);
|
||||
}
|
||||
|
||||
public static void setBarDragonTimer(Player p, String text, int timer) {
|
||||
playerdragonbartask.put(p, text);
|
||||
cooldownsdragonbar.put(p, Integer.valueOf(timer));
|
||||
if (!starttimerdragonbar.containsKey(p)) starttimerdragonbar.put(p, Integer.valueOf(timer));
|
||||
int unite = Math.round(200 / starttimerdragonbar.get(p).intValue());
|
||||
FakeDragon.setBossBar(p, text, unite * timer);
|
||||
}
|
||||
|
||||
public static void removeBarDragon(Player p)
|
||||
{
|
||||
playerdragonbartask.remove(p);
|
||||
healthdragonbartask.remove(p);
|
||||
cooldownsdragonbar.remove(p);
|
||||
starttimerdragonbar.remove(p);
|
||||
FakeDragon.removeBossBar(p);
|
||||
}
|
||||
|
||||
public static boolean hasBarDragon(Player p) {
|
||||
return playerdragonbartask.get(p) != null;
|
||||
}
|
||||
|
||||
public static void setBarWither(Player p, String text)
|
||||
{
|
||||
playerwitherbartask.put(p, text);
|
||||
FakeWither.setBossBartext(p, text);
|
||||
}
|
||||
|
||||
public static void setBarWitherHealth(Player p, String text, float health)
|
||||
{
|
||||
if ((health <= 0.0F) || (health > 100.0F)) { health = 100.0F; text = "health must be between 1 and 100 it's a %"; }
|
||||
playerwitherbartask.put(p, text);
|
||||
healthwitherbartask.put(p, Float.valueOf(health / 100.0F * 300.0F));
|
||||
FakeWither.setBossBar(p, text, health);
|
||||
}
|
||||
|
||||
public static void setBarWitherTimer(Player p, String text, int timer) {
|
||||
playerwitherbartask.put(p, text);
|
||||
cooldownswitherbar.put(p, Integer.valueOf(timer));
|
||||
if (!starttimerwitherbar.containsKey(p)) starttimerwitherbar.put(p, Integer.valueOf(timer));
|
||||
int unite = Math.round(300 / starttimerwitherbar.get(p).intValue());
|
||||
FakeWither.setBossBar(p, text, unite * timer);
|
||||
}
|
||||
|
||||
public static void removeBarWither(Player p)
|
||||
{
|
||||
playerwitherbartask.remove(p);
|
||||
healthwitherbartask.remove(p);
|
||||
cooldownswitherbar.remove(p);
|
||||
starttimerwitherbar.remove(p);
|
||||
FakeWither.removeBossBar(p);
|
||||
}
|
||||
|
||||
public static boolean hasBarWither(Player p) {
|
||||
return playerwitherbartask.get(p) != null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,165 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
/**
|
||||
* gets data from config file
|
||||
* @author joethei
|
||||
* @version 1.1
|
||||
*/
|
||||
public class Config {
|
||||
|
||||
private static File file = new File("plugins/Core", "config.yml");
|
||||
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.set("MySQL.Host", "192.168.0.101");
|
||||
cfg.set("MySQL.Port", "3306");
|
||||
cfg.set("MySQL.DB", "core");
|
||||
cfg.set("MySQL.User", "root");//best user name
|
||||
cfg.set("MySQL.Pass", "");//best password
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,295 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.joethei.core.api.Perms.Ranks;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* inits player
|
||||
* @param player Player
|
||||
*/
|
||||
private CustomPlayer(Player player) {
|
||||
super((CraftServer) Bukkit.getServer(), ((CraftPlayer) player).getHandle());
|
||||
PLAYERS.put(player.getName().toLowerCase(), this);
|
||||
PLAYER = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get normal player
|
||||
* @return Player
|
||||
*/
|
||||
public Player getPLAYER() {
|
||||
return PLAYER;
|
||||
}
|
||||
|
||||
/**
|
||||
* connects player to server in bungeecord
|
||||
* @param server Server 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(Ranks rank) {
|
||||
try {
|
||||
return Perms.isAllowed(this, rank);
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets fresh rank of player
|
||||
* @return Ranks
|
||||
*/
|
||||
public Ranks getRankFresh() {
|
||||
try {
|
||||
return Perms.getRankFresh(this);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* rank of player
|
||||
* @return Ranks
|
||||
*/
|
||||
public Ranks getRank() {
|
||||
return Perms.getRank(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* prefix of player
|
||||
* @return String
|
||||
*/
|
||||
public String getPrefix() {
|
||||
if(customPrefix != null) {
|
||||
return customPrefix;
|
||||
}else {
|
||||
return Perms.getPrefix(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* suffix of player
|
||||
* @return String
|
||||
*/
|
||||
public String getSuffix() {
|
||||
if(customSuffix != null) {
|
||||
return customSuffix;
|
||||
}
|
||||
return Perms.getSuffix(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* color of player (Ranks)
|
||||
* @return String
|
||||
*/
|
||||
public String getColor() {
|
||||
if(customColor != null) {
|
||||
return customColor;
|
||||
}
|
||||
return Perms.getColor(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* if player is muted
|
||||
* @return true/false
|
||||
*/
|
||||
public boolean isMuted() {
|
||||
try {
|
||||
return MuteSystem.isMuted(PLAYER);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(PLAYER, reason, who.getPLAYER(), time);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* if player is banned
|
||||
* @return true/false
|
||||
*/
|
||||
public boolean isBanned() {
|
||||
try {
|
||||
return BanSystem.isBanned(PLAYER);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get ban reason
|
||||
* @return String
|
||||
*/
|
||||
public String getBanReason() {
|
||||
try {
|
||||
return BanSystem.getBanReason(PLAYER);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* get uuid of player who banned
|
||||
* @return String
|
||||
*/
|
||||
public String getWhoBanned() {
|
||||
try {
|
||||
return BanSystem.getWhoBanned(PLAYER);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* unbans the player
|
||||
*/
|
||||
public void unban() {
|
||||
try {
|
||||
BanSystem.unban(PLAYER);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get nickname of player
|
||||
* @return String
|
||||
*/
|
||||
public String getNick() {
|
||||
return NickName.getNick(PLAYER);
|
||||
}
|
||||
|
||||
/**
|
||||
* if player is nicked
|
||||
* @return true/false
|
||||
*/
|
||||
public boolean isNicked() {
|
||||
try {
|
||||
return NickName.isNicked(PLAYER);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sets nickname
|
||||
* @param is boolean
|
||||
*/
|
||||
public void setNick(boolean is) {
|
||||
try {
|
||||
NickName.setNick(PLAYER, is);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public abstract class Database
|
||||
{
|
||||
protected Connection connection;
|
||||
protected Plugin plugin;
|
||||
|
||||
protected Database(Plugin plugin)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.connection = null;
|
||||
}
|
||||
|
||||
public abstract Connection openConnection()
|
||||
throws SQLException, ClassNotFoundException;
|
||||
|
||||
public boolean checkConnection()
|
||||
throws SQLException
|
||||
{
|
||||
return (this.connection != null) && (!this.connection.isClosed());
|
||||
}
|
||||
|
||||
public Connection getConnection()
|
||||
{
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
public boolean closeConnection()
|
||||
throws SQLException
|
||||
{
|
||||
if (this.connection == null) {
|
||||
return false;
|
||||
}
|
||||
this.connection.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
public ResultSet querySQL(String query)
|
||||
throws SQLException, ClassNotFoundException
|
||||
{
|
||||
if (!checkConnection()) {
|
||||
openConnection();
|
||||
}
|
||||
|
||||
Statement statement = this.connection.createStatement();
|
||||
|
||||
ResultSet result = statement.executeQuery(query);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public int updateSQL(String query)
|
||||
throws SQLException, ClassNotFoundException
|
||||
{
|
||||
if (!checkConnection()) {
|
||||
openConnection();
|
||||
}
|
||||
|
||||
Statement statement = this.connection.createStatement();
|
||||
|
||||
int result = statement.executeUpdate(query);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,233 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import net.minecraft.server.v1_8_R3.EntityLiving;
|
||||
import net.minecraft.server.v1_8_R3.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.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class EntityModifier
|
||||
{
|
||||
static org.bukkit.entity.Entity entity;
|
||||
static CraftEntity craftentity;
|
||||
static net.minecraft.server.v1_8_R3.Entity entityS;
|
||||
static int scheduler;
|
||||
static Plugin plugin;
|
||||
static Player player = null;
|
||||
static float Speed;
|
||||
|
||||
public EntityModifier(org.bukkit.entity.Entity entity, Plugin plugin)
|
||||
{
|
||||
EntityModifier.entity = entity;
|
||||
craftentity = (CraftEntity)entity;
|
||||
entityS = craftentity.getHandle();
|
||||
EntityModifier.plugin = plugin;
|
||||
}
|
||||
|
||||
public static Builder modify()
|
||||
{
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static final class Builder
|
||||
{
|
||||
public Builder setDisplayName(String display)
|
||||
{
|
||||
EntityModifier.entity.setCustomName(display);
|
||||
EntityModifier.entity.setCustomNameVisible(true);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setDisplayNameVisible(Boolean visible)
|
||||
{
|
||||
EntityModifier.entity.setCustomNameVisible(visible.booleanValue());
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder playEffekt(EntityEffect entityeffect)
|
||||
{
|
||||
EntityModifier.entity.playEffect(entityeffect);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder remove()
|
||||
{
|
||||
EntityModifier.entity.remove();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setPassenger(org.bukkit.entity.Entity passenger)
|
||||
{
|
||||
EntityModifier.entity.setPassenger(passenger);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setFireTicks(int ticks)
|
||||
{
|
||||
EntityModifier.entity.setFireTicks(ticks);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setLocation(Location location)
|
||||
{
|
||||
teleport(location);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setYawPitch(float yaw, float pitch)
|
||||
{
|
||||
Location loc = EntityModifier.entity.getLocation().clone();
|
||||
teleport(
|
||||
new Location(loc.getWorld(), loc.getX(), loc.getY(),
|
||||
loc.getZ(), yaw, pitch));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder teleport(Location location)
|
||||
{
|
||||
EntityModifier.entity.teleport(location);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder die()
|
||||
{
|
||||
EntityModifier.entityS.die();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setInvisible(boolean invisible)
|
||||
{
|
||||
EntityModifier.entityS.setInvisible(invisible);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder noClip(boolean noClip)
|
||||
{
|
||||
EntityModifier.entityS.noclip = noClip;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setInvulnerable(boolean invulnerable)
|
||||
{
|
||||
try
|
||||
{
|
||||
Field invulnerableField = net.minecraft.server.v1_8_R3.Entity.class
|
||||
.getDeclaredField("invulnerable");
|
||||
invulnerableField.setAccessible(true);
|
||||
invulnerableField.setBoolean(EntityModifier.entityS, invulnerable);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setNoAI(boolean noAI)
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
EntityModifier.entityS.c(tag);
|
||||
tag.setBoolean("NoAI", noAI);
|
||||
EntityLiving el = (EntityLiving)EntityModifier.entityS;
|
||||
el.a(tag);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSilent(boolean silent)
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
EntityModifier.entityS.c(tag);
|
||||
tag.setBoolean("Silent", silent);
|
||||
EntityLiving el = (EntityLiving)EntityModifier.entityS;
|
||||
el.a(tag);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setCanPickUpLoot(boolean canpickuploot)
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
EntityModifier.entityS.c(tag);
|
||||
tag.setBoolean("CanPickUpLoot", canpickuploot);
|
||||
EntityLiving el = (EntityLiving)EntityModifier.entityS;
|
||||
el.a(tag);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setHealth(float health)
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
EntityModifier.entityS.c(tag);
|
||||
tag.setFloat("HealF", health);
|
||||
EntityLiving el = (EntityLiving)EntityModifier.entityS;
|
||||
el.a(tag);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setCanDespawn(boolean candespawn)
|
||||
{
|
||||
candespawn = !candespawn;
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
EntityModifier.entityS.c(tag);
|
||||
tag.setBoolean("PersistenceRequired", candespawn);
|
||||
EntityLiving el = (EntityLiving)EntityModifier.entityS;
|
||||
el.a(tag);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder walkToLocation(Location location, float speed)
|
||||
{
|
||||
((CraftCreature)EntityModifier.entity)
|
||||
.getHandle()
|
||||
.getNavigation()
|
||||
.a(location.getX(), location.getY(), location.getZ(), speed);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder followPlayer(Player target, float speed)
|
||||
{
|
||||
EntityModifier.player = target;
|
||||
EntityModifier.Speed = speed;
|
||||
EntityModifier.scheduler = Bukkit.getScheduler().scheduleSyncRepeatingTask(EntityModifier.plugin,
|
||||
new Runnable()
|
||||
{
|
||||
@SuppressWarnings("deprecation")
|
||||
public void run() {
|
||||
double distance = EntityModifier.entity.getLocation().distance(
|
||||
EntityModifier.player.getLocation());
|
||||
if (distance < 11.0D) {
|
||||
float speed = EntityModifier.Speed;
|
||||
if (distance < 3.0D) {
|
||||
speed = 0.0F;
|
||||
}
|
||||
((CraftCreature)EntityModifier.entity)
|
||||
.getHandle()
|
||||
.getNavigation()
|
||||
.a(EntityModifier.player.getLocation().getX(),
|
||||
EntityModifier.player.getLocation().getY(),
|
||||
EntityModifier.player.getLocation().getZ(),
|
||||
speed);
|
||||
}
|
||||
else if (EntityModifier.player.isOnGround()) {
|
||||
EntityModifier.entity.teleport(EntityModifier.player);
|
||||
}
|
||||
}
|
||||
}
|
||||
, 0L, 1L);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder stopFollowingPlayer()
|
||||
{
|
||||
Bukkit.getScheduler().cancelTask(EntityModifier.scheduler);
|
||||
return this;
|
||||
}
|
||||
|
||||
public org.bukkit.entity.Entity build()
|
||||
{
|
||||
return EntityModifier.entity;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,148 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Base64;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
public class ItemSkulls
|
||||
{
|
||||
private static Class<?> skullMetaClass;
|
||||
private static Class<?> tileEntityClass;
|
||||
private static Class<?> blockPositionClass;
|
||||
private static int mcVersion;
|
||||
|
||||
static
|
||||
{
|
||||
String version = org.bukkit.Bukkit.getServer().getClass().getPackage().getName()
|
||||
.split("\\.")[3];
|
||||
mcVersion = Integer.parseInt(version.replaceAll("[^0-9]", ""));
|
||||
try {
|
||||
skullMetaClass = Class.forName("org.bukkit.craftbukkit." + version +
|
||||
".inventory.CraftMetaSkull");
|
||||
tileEntityClass = Class.forName("net.minecraft.server." + version +
|
||||
".TileEntitySkull");
|
||||
if (mcVersion > 174)
|
||||
blockPositionClass = Class.forName("net.minecraft.server." +
|
||||
version + ".BlockPosition");
|
||||
else
|
||||
blockPositionClass = null;
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack getSkull(String skinURL)
|
||||
{
|
||||
return getSkull(skinURL, 1);
|
||||
}
|
||||
|
||||
public static ItemStack getSkull(String skinURL, int amount)
|
||||
{
|
||||
ItemStack skull = new ItemStack(Material.SKULL_ITEM, amount, (short) 3);
|
||||
SkullMeta meta = (SkullMeta)skull.getItemMeta();
|
||||
try {
|
||||
Field profileField = skullMetaClass.getDeclaredField("profile");
|
||||
profileField.setAccessible(true);
|
||||
profileField.set(meta, getProfile(skinURL));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
skull.setItemMeta(meta);
|
||||
return skull;
|
||||
}
|
||||
|
||||
public static boolean setBlock(Location loc, String skinURL)
|
||||
{
|
||||
return setBlock(loc.getBlock(), skinURL);
|
||||
}
|
||||
|
||||
public static boolean setBlock(Block block, String skinURL)
|
||||
{
|
||||
boolean flag = block.getType() == Material.SKULL;
|
||||
if (!flag)
|
||||
block.setType(Material.SKULL);
|
||||
try
|
||||
{
|
||||
Object nmsWorld = block.getWorld().getClass()
|
||||
.getMethod("getHandle", new Class[0]).invoke(block.getWorld(), new Object[0]);
|
||||
Object tileEntity = null;
|
||||
|
||||
if (mcVersion <= 174) {
|
||||
Method getTileEntity = nmsWorld.getClass().getMethod(
|
||||
"getTileEntity", new Class[] { Integer.TYPE, Integer.TYPE, Integer.TYPE });
|
||||
tileEntity = tileEntityClass.cast(getTileEntity.invoke(
|
||||
nmsWorld, new Object[] { Integer.valueOf(block.getX()), Integer.valueOf(block.getY()), Integer.valueOf(block.getZ()) }));
|
||||
} else {
|
||||
Method getTileEntity = nmsWorld.getClass().getMethod(
|
||||
"getTileEntity", new Class[] { blockPositionClass });
|
||||
tileEntity = tileEntityClass.cast(getTileEntity.invoke(
|
||||
nmsWorld, new Object[] {
|
||||
getBlockPositionFor(block.getX(), block.getY(),
|
||||
block.getZ()) }));
|
||||
}
|
||||
|
||||
tileEntityClass.getMethod("setGameProfile", new Class[] { GameProfile.class })
|
||||
.invoke(tileEntity, new Object[] { getProfile(skinURL) });
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return !flag;
|
||||
}
|
||||
|
||||
private static GameProfile getProfile(String skinURL) {
|
||||
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
|
||||
String base64encoded = Base64.getEncoder().encodeToString(
|
||||
new String("{textures:{SKIN:{url:\"" + skinURL + "\"}}}")
|
||||
.getBytes());
|
||||
Property property = new Property("textures", base64encoded);
|
||||
profile.getProperties().put("textures", property);
|
||||
return profile;
|
||||
}
|
||||
|
||||
private static Object getBlockPositionFor(int x, int y, int z) {
|
||||
Object blockPosition = null;
|
||||
try {
|
||||
Constructor<?> cons = blockPositionClass.getConstructor(new Class[] { Integer.TYPE,
|
||||
Integer.TYPE, Integer.TYPE });
|
||||
blockPosition = cons.newInstance(new Object[] { Integer.valueOf(x), Integer.valueOf(y), Integer.valueOf(z) });
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return blockPosition;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,577 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import de.joethei.core.api.utils.Direction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
public enum Letters
|
||||
{
|
||||
LETTER_A('a',
|
||||
new boolean[][] {
|
||||
{ false, true },
|
||||
{ true, false, true },
|
||||
{ true, false, true },
|
||||
{ true, true, true },
|
||||
{ true, false, true } }),
|
||||
|
||||
LETTER_B('b',
|
||||
new boolean[][] {
|
||||
{ true, true },
|
||||
{ true, false, true },
|
||||
{ true, true, true },
|
||||
{ true, false, true },
|
||||
{ true, true } }),
|
||||
|
||||
LETTER_C('c',
|
||||
new boolean[][] {
|
||||
{ false, true, true },
|
||||
{ true },
|
||||
{ true },
|
||||
{ true },
|
||||
{ false, true, true } }),
|
||||
|
||||
LETTER_D('d',
|
||||
new boolean[][] {
|
||||
{ true, true },
|
||||
{ true, false, true },
|
||||
{ true, false, true },
|
||||
{ true, false, true },
|
||||
{ true, true } }),
|
||||
|
||||
LETTER_E('e',
|
||||
new boolean[][] {
|
||||
{ true, true, true },
|
||||
{ true },
|
||||
{ true, true },
|
||||
{ true },
|
||||
{ true, true, true } }),
|
||||
|
||||
LETTER_F('f',
|
||||
new boolean[][] {
|
||||
{ true, true, true },
|
||||
{ true },
|
||||
{ true, true },
|
||||
{ true },
|
||||
{ true } }),
|
||||
|
||||
LETTER_G('g',
|
||||
new boolean[][] {
|
||||
{ false, true, true },
|
||||
{ true },
|
||||
{ true, false, true, true },
|
||||
{ true, false, false, true },
|
||||
{ false, true, true, true } }),
|
||||
|
||||
LETTER_H('h',
|
||||
new boolean[][] {
|
||||
{ true, false, true },
|
||||
{ true, false, true },
|
||||
{ true, true, true },
|
||||
{ true, false, true },
|
||||
{ true, false, true } }),
|
||||
|
||||
LETTER_I('i',
|
||||
new boolean[][] {
|
||||
{ true },
|
||||
{ true },
|
||||
{ true },
|
||||
{ true },
|
||||
{ true } }),
|
||||
|
||||
LETTER_J('j',
|
||||
new boolean[][] {
|
||||
{ false, false, true },
|
||||
{ false, false, true },
|
||||
{ false, false, true },
|
||||
{ true, false, true },
|
||||
{ true, true, true } }),
|
||||
|
||||
LETTER_K('k',
|
||||
new boolean[][] {
|
||||
{ true, false, false, true },
|
||||
{ true, false, true },
|
||||
{ true, true },
|
||||
{ true, false, true },
|
||||
{ true, false, false, true } }),
|
||||
|
||||
LETTER_L('l',
|
||||
new boolean[][] {
|
||||
{ true },
|
||||
{ true },
|
||||
{ true },
|
||||
{ true },
|
||||
{ true, true, true } }),
|
||||
|
||||
LETTER_M('m',
|
||||
new boolean[][] {
|
||||
{ true, true, true, true, true },
|
||||
{ true, false, true, false, true },
|
||||
{ true, false, true, false, true },
|
||||
{ true, false, false, false, true },
|
||||
{ true, false, false, false, true } }),
|
||||
|
||||
LETTER_N('n',
|
||||
new boolean[][] {
|
||||
{ true, false, false, true },
|
||||
{ true, true, false, true },
|
||||
{ true, false, true, true },
|
||||
{ true, false, false, true },
|
||||
{ true, false, false, true } }),
|
||||
|
||||
LETTER_O('o',
|
||||
new boolean[][] {
|
||||
{ false, true },
|
||||
{ true, false, true },
|
||||
{ true, false, true },
|
||||
{ true, false, true },
|
||||
{ false, true } }),
|
||||
|
||||
LETTER_P('p',
|
||||
new boolean[][] {
|
||||
{ true, true },
|
||||
{ true, false, true },
|
||||
{ true, true },
|
||||
{ true },
|
||||
{ true } }),
|
||||
|
||||
LETTER_Q('q',
|
||||
new boolean[][] {
|
||||
{ false, true, true },
|
||||
{ true, false, false, true },
|
||||
{ true, false, false, true },
|
||||
{ true, false, true, true },
|
||||
{ false, true, true } }),
|
||||
|
||||
LETTER_R('r',
|
||||
new boolean[][] {
|
||||
{ true, true },
|
||||
{ true, false, true },
|
||||
{ true, false, true },
|
||||
{ true, true },
|
||||
{ true, false, true } }),
|
||||
|
||||
LETTER_S('s',
|
||||
new boolean[][] {
|
||||
{ false, true, true },
|
||||
{ true },
|
||||
{ false, true },
|
||||
{ false, false, true },
|
||||
{ true, true } }),
|
||||
|
||||
LETTER_T('t',
|
||||
new boolean[][] {
|
||||
{ true, true, true },
|
||||
{ false, true },
|
||||
{ false, true },
|
||||
{ false, true },
|
||||
{ false, true } }),
|
||||
|
||||
LETTER_U('u',
|
||||
new boolean[][] {
|
||||
{ true, false, true },
|
||||
{ true, false, true },
|
||||
{ true, false, true },
|
||||
{ true, false, true },
|
||||
{ false, true } }),
|
||||
|
||||
LETTER_V('v',
|
||||
new boolean[][] {
|
||||
{ true, false, false, false, true },
|
||||
{ true, false, false, false, true },
|
||||
{ false, true, false, true },
|
||||
{ false, true, false, true },
|
||||
{ false, false, true } }),
|
||||
|
||||
LETTER_W('w',
|
||||
new boolean[][] {
|
||||
{ true, false, false, false, true },
|
||||
{ true, false, false, false, true },
|
||||
{ true, false, false, false, true },
|
||||
{ true, false, true, false, true },
|
||||
{ true, true, true, true, true } }),
|
||||
|
||||
LETTER_X('x',
|
||||
new boolean[][] {
|
||||
{ true, false, false, false, true },
|
||||
{ false, true, false, true },
|
||||
{ false, false, true },
|
||||
{ false, true, false, true },
|
||||
{ true, false, false, false, true } }),
|
||||
|
||||
LETTER_Y('y',
|
||||
new boolean[][] {
|
||||
{ true, false, false, true },
|
||||
{ false, true, true },
|
||||
{ false, false, true },
|
||||
{ false, true },
|
||||
{ true } }),
|
||||
|
||||
LETTER_Z('z',
|
||||
new boolean[][] {
|
||||
{ true, true, true, true, true },
|
||||
{ false, false, false, true },
|
||||
{ false, false, true },
|
||||
{ false, true },
|
||||
{ true, true, true, true, true } }),
|
||||
|
||||
LETTER_0('0',
|
||||
new boolean[][] {
|
||||
{ true, true, true },
|
||||
{ true, false, true },
|
||||
{ true, false, true },
|
||||
{ true, false, true },
|
||||
{ true, true, true } }),
|
||||
|
||||
LETTER_1('1',
|
||||
new boolean[][] {
|
||||
{ true, true },
|
||||
{ false, true },
|
||||
{ false, true },
|
||||
{ false, true },
|
||||
{ true, true, true } }),
|
||||
|
||||
LETTER_2('2',
|
||||
new boolean[][] {
|
||||
{ true, true },
|
||||
{ false, false, true },
|
||||
{ false, true },
|
||||
{ true },
|
||||
{ true, true, true } }),
|
||||
|
||||
LETTER_3('3',
|
||||
new boolean[][] {
|
||||
{ true, true },
|
||||
{ false, false, true },
|
||||
{ true, true },
|
||||
{ false, false, true },
|
||||
{ true, true } }),
|
||||
|
||||
LETTER_4('4',
|
||||
new boolean[][] {
|
||||
{ true, false, true },
|
||||
{ true, false, true },
|
||||
{ true, true, true },
|
||||
{ false, false, true },
|
||||
{ false, false, true } }),
|
||||
|
||||
LETTER_5('5',
|
||||
new boolean[][] {
|
||||
{ true, true, true },
|
||||
{ true },
|
||||
{ true, true, true },
|
||||
{ false, false, true },
|
||||
{ true, true, true } }),
|
||||
|
||||
LETTER_6('6',
|
||||
new boolean[][] {
|
||||
{ true, true, true },
|
||||
{ true },
|
||||
{ true, true, true },
|
||||
{ true, false, true },
|
||||
{ true, true, true } }),
|
||||
|
||||
LETTER_7('7',
|
||||
new boolean[][] {
|
||||
{ true, true, true },
|
||||
{ false, false, true },
|
||||
{ false, false, true },
|
||||
{ false, false, true },
|
||||
{ false, false, true } }),
|
||||
|
||||
LETTER_8('8',
|
||||
new boolean[][] {
|
||||
{ true, true, true },
|
||||
{ true, false, true },
|
||||
{ true, true, true },
|
||||
{ true, false, true },
|
||||
{ true, true, true } }),
|
||||
|
||||
LETTER_9('9',
|
||||
new boolean[][] {
|
||||
{ true, true, true },
|
||||
{ true, false, true },
|
||||
{ true, true, true },
|
||||
{ false, false, true },
|
||||
{ true, true, true } }),
|
||||
|
||||
LETTER_DOT('.',
|
||||
new boolean[][] {
|
||||
{ true } }),
|
||||
|
||||
LETTER_UNDERSCORE('_',
|
||||
new boolean[][] {
|
||||
{ true, true, true } }),
|
||||
|
||||
LETTER_SPACE(' ',
|
||||
new boolean[][] {
|
||||
new boolean[3] }),
|
||||
|
||||
LETTER_PERCENT('%',
|
||||
new boolean[][] {
|
||||
{ true, false, false, false, true },
|
||||
{ false, false, false, true },
|
||||
{ false, false, true },
|
||||
{ false, true },
|
||||
{ true, false, false, false, true } }),
|
||||
|
||||
LETTER_UP_ARROW('^',
|
||||
new boolean[][] {
|
||||
{ false, false, true },
|
||||
{ false, true, false, true },
|
||||
{ true, false, false, false, true },
|
||||
new boolean[5],
|
||||
new boolean[5] }),
|
||||
|
||||
LETTER_LEFT_ARROW('<',
|
||||
new boolean[][] {
|
||||
{ false, false, true },
|
||||
{ false, true },
|
||||
{ true },
|
||||
{ false, true },
|
||||
{ false, false, true } }),
|
||||
|
||||
LETTER_RIGHT_ARROW('>',
|
||||
new boolean[][] {
|
||||
{ true },
|
||||
{ false, true },
|
||||
{ false, false, true },
|
||||
{ false, true },
|
||||
{ true } }),
|
||||
|
||||
LETTER_AMPERSAND('*',
|
||||
new boolean[][] {
|
||||
{ true, false, true, false, true },
|
||||
{ false, true, true, true },
|
||||
{ true, true, true, true, true },
|
||||
{ false, true, true, true },
|
||||
{ true, false, true, false, true } }),
|
||||
|
||||
LETTER_HASHTAG('#',
|
||||
new boolean[][] {
|
||||
{ false, true, false, true },
|
||||
{ true, true, true, true, true },
|
||||
{ false, true, false, true },
|
||||
{ true, true, true, true, true },
|
||||
{ false, true, false, true } }),
|
||||
|
||||
LETTER_COMMA(',',
|
||||
new boolean[][] {
|
||||
{ true },
|
||||
{ true } }),
|
||||
|
||||
LETTER_COLON(':',
|
||||
new boolean[][] {
|
||||
{ true },
|
||||
new boolean[1],
|
||||
new boolean[1],
|
||||
new boolean[1],
|
||||
{ true } }),
|
||||
|
||||
LETTER_DASH('-',
|
||||
new boolean[][] {
|
||||
{ true, true, true },
|
||||
new boolean[3],
|
||||
new boolean[3] }),
|
||||
|
||||
LETTER_PLUS('+',
|
||||
new boolean[][] {
|
||||
{ false, false, true },
|
||||
{ false, false, true },
|
||||
{ true, true, true, true, true },
|
||||
{ false, false, true },
|
||||
{ false, false, true } }),
|
||||
|
||||
LETTER_MINUS('-',
|
||||
new boolean[][] {
|
||||
{ true, true, true, true, true },
|
||||
new boolean[5],
|
||||
new boolean[5] }),
|
||||
|
||||
LETTER_EQUAL('=',
|
||||
new boolean[][] {
|
||||
{ true, true, true, true, true },
|
||||
new boolean[5],
|
||||
{ true, true, true, true, true },
|
||||
new boolean[5] }),
|
||||
|
||||
LETTER_LEFT_ROUND_BRACKET('(',
|
||||
new boolean[][] {
|
||||
{ false, true },
|
||||
{ true },
|
||||
{ true },
|
||||
{ true },
|
||||
{ false, true } }),
|
||||
|
||||
LETTER_RIGHT_ROUND_BRACKET(')',
|
||||
new boolean[][] {
|
||||
{ true },
|
||||
{ false, true },
|
||||
{ false, true },
|
||||
{ false, true },
|
||||
{ true } }),
|
||||
|
||||
LETTER_LEFT_SQUARE_BRACKET('[',
|
||||
new boolean[][] {
|
||||
{ true, true },
|
||||
{ true },
|
||||
{ true },
|
||||
{ true },
|
||||
{ true, true } }),
|
||||
|
||||
LETTER_RIGHT_SQUARE_BRACKET(']',
|
||||
new boolean[][] {
|
||||
{ true, true },
|
||||
{ false, true },
|
||||
{ false, true },
|
||||
{ false, true },
|
||||
{ true, true } }),
|
||||
|
||||
LETTER_QUESTION('?',
|
||||
new boolean[][] {
|
||||
{ true, true, true },
|
||||
{ false, false, true },
|
||||
{ false, true, true },
|
||||
new boolean[3],
|
||||
{ false, true } });
|
||||
|
||||
private char character;
|
||||
private int height;
|
||||
private int width;
|
||||
private boolean[][] blocks;
|
||||
|
||||
private Letters(char character, boolean[][] blocks) {
|
||||
this.character = character;
|
||||
this.blocks = blocks;
|
||||
this.height = blocks.length;
|
||||
this.width = blocks[0].length;
|
||||
boolean[][] reversed = new boolean[this.height][this.width];
|
||||
for (int i = 0; i < this.height; i++)
|
||||
{
|
||||
reversed[(this.height - i - 1)] = blocks[i];
|
||||
}
|
||||
this.blocks = reversed;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return this.width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return this.height;
|
||||
}
|
||||
|
||||
public char getCharacter() {
|
||||
return this.character;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void draw(Material type, byte data, Location loc, Direction dir)
|
||||
{
|
||||
for (int y = 0; y < this.height; y++)
|
||||
{
|
||||
for (int x = 0; x < this.width; x++)
|
||||
{
|
||||
Location l = loc.clone().add(x * dir.getX(), y, x * dir.getZ());
|
||||
if ((l.getBlock() == null) || (this.blocks[y][x] == 0))
|
||||
continue;
|
||||
l.getBlock().setType(type);
|
||||
l.getBlock().setData(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int strHeight()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
public static int strHeight(String[] str) {
|
||||
return (strHeight() + 1) * str.length - 1;
|
||||
}
|
||||
|
||||
public static int strWidth(String str) {
|
||||
int w = 0;
|
||||
List letters = fromString(str);
|
||||
for (Letters l : letters)
|
||||
{
|
||||
w += l.getWidth() + 1;
|
||||
}
|
||||
return w > 0 ? w - 1 : w;
|
||||
}
|
||||
|
||||
public static int strWidth(String[] str) {
|
||||
int width = 0;
|
||||
String[] arrayOfString = str; int j = str.length; for (int i = 0; i < j; i++) { String s = arrayOfString[i];
|
||||
|
||||
if (strWidth(s) > width)
|
||||
width = strWidth(s);
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
public static void centreString(String text, Material type, byte data, Location centre, Direction dir)
|
||||
{
|
||||
int width = strWidth(text);
|
||||
Location start = centre.subtract(width / 2 * dir.getX(), 0.0D, width / 2 *
|
||||
dir.getZ());
|
||||
drawString(text, type, data, start, dir);
|
||||
}
|
||||
|
||||
public static void centreString(String[] text, Material type, byte data, Location centre, Direction dir)
|
||||
{
|
||||
int height = 0;
|
||||
String[] arrayOfString = text; int j = text.length; for (int i = 0; i < j; i++) { String s = arrayOfString[i];
|
||||
|
||||
height++;
|
||||
height += strHeight();
|
||||
centreString(s, type, data, centre.clone().subtract(0.0D, height, 0.0D), dir); }
|
||||
}
|
||||
|
||||
public static void drawString(String str, Material type, byte data, Location loc, Direction dir)
|
||||
{
|
||||
List letters = fromString(str);
|
||||
for (Letters l : letters)
|
||||
{
|
||||
l.draw(type, data, loc.clone(), dir);
|
||||
loc = loc.add((l.getWidth() + 1) * dir.getX(), 0.0D, (l.getWidth() + 1) *
|
||||
dir.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawString(String[] text, Material type, byte data, Location loc, Direction dir) {
|
||||
int height = 0;
|
||||
String[] arrayOfString = text; int j = text.length; for (int i = 0; i < j; i++) { String s = arrayOfString[i];
|
||||
|
||||
height++;
|
||||
height += strHeight();
|
||||
centreString(s, type, data, loc.clone().subtract(0.0D, height, 0.0D), dir); }
|
||||
}
|
||||
|
||||
public static Letters fromCharacter(char character)
|
||||
{
|
||||
for (Letters l : values())
|
||||
{
|
||||
if (l.character.equalsIgnoreCase(character))
|
||||
{
|
||||
return l;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<Letters> fromString(String string) {
|
||||
List letters = new ArrayList();
|
||||
for (char character : string.toCharArray())
|
||||
{
|
||||
Letters l = fromCharacter(character);
|
||||
if (l == null)
|
||||
continue;
|
||||
letters.add(l);
|
||||
}
|
||||
|
||||
return letters;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import de.joethei.core.Core;
|
||||
|
||||
/**
|
||||
* messages from database
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Messages {
|
||||
|
||||
public static String PREFIX;
|
||||
public static String CONSOLE_PREFIX;
|
||||
public static String UNKNOWN_ERROR;
|
||||
public static String NOT_A_PLAYER;
|
||||
public static String NO_PERMS;
|
||||
public static String ERROR;
|
||||
public static String NOT_ONLINE;
|
||||
public static String KICK_RESTART;
|
||||
public static String KICK_FULL;
|
||||
|
||||
/**
|
||||
* write default data
|
||||
* @throws ClassNotFoundException Class couldn't be found
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
*/
|
||||
public static void writeDefault() throws ClassNotFoundException, SQLException {
|
||||
//editable messages will be set here, but do not edit this messages.
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
sql.getConnection().createStatement().execute("INSERT INTO MESSAGES(Ident, Message) values ('Prefix', '§aunivento §8»');");
|
||||
sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('ConsolePrefix', '[univento Core]');");
|
||||
sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('UnknownError', '§cEs ist leider ein unbekannter Fehler aufgetreten');");
|
||||
sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('Commands.NoPlayer', '§cDu bist leider kein Spieler');");
|
||||
sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('Commands.NoPerms', '§cDu hast keine Berechtigungen diesen Befehl auszuführen')");
|
||||
sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('Commands.Error', '§cBeim ausführen dieses Befehls ist ein Fehler aufgetreten');");
|
||||
sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('Commands.NotOnline', '§cDer Spieler $player ist nicht online');");
|
||||
sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('Commands.Unknown', '§6Der Befehl $cmd konnte leider nicht gefunden werden');");
|
||||
sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('Kick.Restart', '§cDer Server startet gerade neu');");
|
||||
sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('Kick.Full', '§cDer Server ist leider schon voll')");
|
||||
|
||||
sql.closeConnection();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* reads all string to variables
|
||||
* @throws ClassNotFoundException Class couldn't be found
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
*/
|
||||
public static void readStrings() throws ClassNotFoundException, SQLException {
|
||||
PREFIX = readString("Prefix") + " ";
|
||||
CONSOLE_PREFIX = readString("ConsolePrefix") + " ";
|
||||
UNKNOWN_ERROR = readString("UnknownError") + " ";
|
||||
NOT_A_PLAYER = readString("Commands.NoPlayer") + " ";
|
||||
NO_PERMS = readString("Commands.NoPerms") + " ";
|
||||
ERROR = readString("Commands.Error") + " ";
|
||||
NOT_ONLINE = readString("Commands.NotOnline") + " ";
|
||||
KICK_RESTART = readString("Kick.Restart") + " ";
|
||||
KICK_FULL = readString("Kick.Full") + " ";
|
||||
}
|
||||
|
||||
/**
|
||||
* reads single message from database
|
||||
* @param path path
|
||||
* @return String
|
||||
*/
|
||||
public static String readString(String path) {
|
||||
MySQL sql = Core.returnSQL();
|
||||
try {
|
||||
sql.openConnection();
|
||||
ResultSet rs = sql.getConnection().createStatement().executeQuery("SELECT * FROM Messages WHERE Ident='" + path + "';");
|
||||
if (!rs.next()) {
|
||||
sql.closeConnection();
|
||||
return null;
|
||||
}
|
||||
sql.closeConnection();
|
||||
return rs.getString("Message");
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
|
||||
public class MojangService
|
||||
{
|
||||
private static JSONParser parser = new JSONParser();
|
||||
|
||||
public static ServiceStatus getStatus(MinecraftServer service)
|
||||
{
|
||||
String status = null;
|
||||
try
|
||||
{
|
||||
URL url = new URL("http://status.mojang.com/check?service=" + service.getURL());
|
||||
BufferedReader input = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||
|
||||
Object object = parser.parse(input);
|
||||
JSONObject jsonObject = (JSONObject)object;
|
||||
|
||||
status = (String)jsonObject.get(service.getURL());
|
||||
} catch (Exception e) {
|
||||
return ServiceStatus.UNKNOWN;
|
||||
}
|
||||
|
||||
return status(status);
|
||||
}
|
||||
|
||||
public static ServiceStatus getStatus(MojangServer service) {
|
||||
String status = null;
|
||||
try
|
||||
{
|
||||
URL url = new URL("http://status.mojang.com/check?service=" + service.getURL());
|
||||
BufferedReader input = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||
|
||||
Object object = parser.parse(input);
|
||||
JSONObject jsonObject = (JSONObject)object;
|
||||
|
||||
status = (String)jsonObject.get(service.getURL());
|
||||
} catch (Exception e) {
|
||||
return ServiceStatus.UNKNOWN;
|
||||
}
|
||||
|
||||
return status(status);
|
||||
}
|
||||
|
||||
private static ServiceStatus status(String status)
|
||||
{
|
||||
String str;
|
||||
switch ((str = status.toLowerCase()).hashCode()) { case -734239628:
|
||||
if (str.equals("yellow")) break; break;
|
||||
case 112785:
|
||||
if (str.equals("red"));
|
||||
case 98619139:
|
||||
if ((goto 92) && (str.equals("green")))
|
||||
{
|
||||
return ServiceStatus.ONLINE;
|
||||
|
||||
return ServiceStatus.EXPERIENCE;
|
||||
|
||||
return ServiceStatus.OFFLINE;
|
||||
}
|
||||
}
|
||||
return ServiceStatus.UNKNOWN;
|
||||
}
|
||||
|
||||
public static enum MinecraftServer
|
||||
{
|
||||
WEBSITE("minecraft.net"),
|
||||
LOGIN("login.minecraft.net"),
|
||||
SKIN("skins.minecraft.net"),
|
||||
SESSION("session.minecraft.net");
|
||||
|
||||
private String url;
|
||||
|
||||
private MinecraftServer(String url) { this.url = url; }
|
||||
|
||||
private String getURL()
|
||||
{
|
||||
return this.url;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum MojangServer
|
||||
{
|
||||
ACCOUNT("account.mojang.com"),
|
||||
AUTH("auth.mojang.com"),
|
||||
AUTHSERVER("authserver.mojang.com"),
|
||||
SESSION("sessionserver.mojang.com");
|
||||
|
||||
private String url;
|
||||
|
||||
private MojangServer(String url) { this.url = url; }
|
||||
|
||||
private String getURL()
|
||||
{
|
||||
return this.url;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum ServiceStatus
|
||||
{
|
||||
ONLINE("No problems detected!"),
|
||||
EXPERIENCE("May be experiencing issues"),
|
||||
OFFLINE("Experiencing problems!"),
|
||||
UNKNOWN("Couldn't connect to Mojang!");
|
||||
|
||||
private String description;
|
||||
|
||||
private ServiceStatus(String description) { this.description = description; }
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return this.description;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.joethei.core.Core;
|
||||
|
||||
/**
|
||||
* querys database for muted players
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class MuteSystem {
|
||||
|
||||
|
||||
/**
|
||||
* checks if player is muted
|
||||
* @param p player
|
||||
* @return true /false
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
* @throws ClassNotFoundException class couldn't be found
|
||||
*/
|
||||
public static boolean isMuted(Player p) throws SQLException, ClassNotFoundException {
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
String uuid = p.getUniqueId().toString();
|
||||
ResultSet rs = sql.getConnection().createStatement().executeQuery("SELECT mute FROM PlayerData WHERE player_uuid='" + uuid + "';");
|
||||
if (rs.next()) {
|
||||
return rs.getInt("mute") == 1;
|
||||
}
|
||||
sql.closeConnection();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* sets / unsets mute
|
||||
* @param p player
|
||||
* @param mute boolean
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
* @throws ClassNotFoundException class couldn't be found
|
||||
*/
|
||||
public static void setUser(Player p, boolean mute) throws SQLException, ClassNotFoundException {
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
String uuid = p.getUniqueId().toString();
|
||||
sql.getConnection().createStatement().executeUpdate("UPDATE PlayerData SET mute = " + mute + " WHERE player_uuid='" + uuid + "';");
|
||||
sql.closeConnection();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class MySQL extends Database
|
||||
{
|
||||
private final String user;
|
||||
private final String database;
|
||||
private final String password;
|
||||
private final String port;
|
||||
private final String hostname;
|
||||
|
||||
public MySQL(Plugin plugin, String hostname, String port, String database, String username, String password) {
|
||||
super(plugin);
|
||||
this.hostname = hostname;
|
||||
this.port = port;
|
||||
this.database = database;
|
||||
this.user = username;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public Connection openConnection()
|
||||
throws SQLException, ClassNotFoundException
|
||||
{
|
||||
if (checkConnection()) {
|
||||
return this.connection;
|
||||
}
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
this.connection = DriverManager.getConnection("jdbc:mysql://" +
|
||||
this.hostname + ":" + this.port + "/" + this.database,
|
||||
this.user, this.password);
|
||||
return this.connection;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,785 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import com.mojang.authlib.properties.PropertyMap.Serializer;
|
||||
import com.mojang.util.UUIDTypeAdapter;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.minecraft.server.v1_8_R3.DataWatcher;
|
||||
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_8_R3.NetworkManager;
|
||||
import net.minecraft.server.v1_8_R3.Packet;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity.EnumEntityUseAction;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityEquipment;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityTeleport;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutNamedEntitySpawn;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo.EnumPlayerInfoAction;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo.PlayerInfoData;
|
||||
import net.minecraft.server.v1_8_R3.PlayerConnection;
|
||||
import net.minecraft.server.v1_8_R3.WorldSettings;
|
||||
import net.minecraft.server.v1_8_R3.WorldSettings.EnumGamemode;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.util.CraftChatMessage;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
|
||||
|
||||
public class NPC
|
||||
{
|
||||
private static Map<Integer, NPC> npcs = new HashMap<Integer, NPC>();
|
||||
private static Field channelField;
|
||||
private static Field idField;
|
||||
private DataWatcher watcher;
|
||||
private GameProfile profile;
|
||||
private Material chestplate;
|
||||
private boolean hideTablist;
|
||||
private Material leggings;
|
||||
private Location location;
|
||||
private String skinName;
|
||||
private Material inHand;
|
||||
private Material helmet;
|
||||
private Material boots;
|
||||
private String tablist;
|
||||
private int entityID;
|
||||
private String name;
|
||||
|
||||
static
|
||||
{
|
||||
try
|
||||
{
|
||||
idField = PacketPlayInUseEntity.class.getDeclaredField("a");
|
||||
idField.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
for (Field field : NetworkManager.class.getDeclaredFields())
|
||||
if (field.getType().isAssignableFrom(Channel.class)) {
|
||||
channelField = field;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public NPC(String skinName, String name, String tablist, int entityID, Location location, Material inHand, boolean hideTablist)
|
||||
{
|
||||
this.location = location;
|
||||
this.tablist = ChatColor.translateAlternateColorCodes('&', tablist);
|
||||
this.name = ChatColor.translateAlternateColorCodes('&', name);
|
||||
this.entityID = entityID;
|
||||
this.inHand = inHand;
|
||||
this.skinName = skinName;
|
||||
this.watcher = new DataWatcher(null);
|
||||
this.hideTablist = hideTablist;
|
||||
this.watcher.a(6, Float.valueOf(20.0F));
|
||||
}
|
||||
|
||||
public NPC(String name, Location location, boolean hideTablist)
|
||||
{
|
||||
this(null, name, name, new Random().nextInt(10000), location,
|
||||
Material.AIR, hideTablist);
|
||||
}
|
||||
|
||||
public NPC(String skinName, String name, Location location, boolean hideTablist)
|
||||
{
|
||||
this(skinName, name, name, new Random().nextInt(10000), location,
|
||||
Material.AIR, hideTablist);
|
||||
}
|
||||
|
||||
public NPC(String name, Location location, Material inHand, boolean hideTablist)
|
||||
{
|
||||
this(null, name, name, new Random().nextInt(10000), location, inHand,
|
||||
hideTablist);
|
||||
}
|
||||
|
||||
public NPC(String name, String tablist, Location location, Material inHand, boolean hideTablist)
|
||||
{
|
||||
this(null, name, tablist, new Random().nextInt(10000), location,
|
||||
inHand, hideTablist);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void spawn()
|
||||
{
|
||||
try {
|
||||
PacketPlayOutNamedEntitySpawn packet = new PacketPlayOutNamedEntitySpawn();
|
||||
addToTablist();
|
||||
setValue(packet, "a", Integer.valueOf(this.entityID));
|
||||
setValue(packet, "b", this.profile.getId());
|
||||
setValue(packet, "c", Integer.valueOf(toFixedPoint(this.location.getX())));
|
||||
setValue(packet, "d", Integer.valueOf(toFixedPoint(this.location.getY())));
|
||||
setValue(packet, "e", Integer.valueOf(toFixedPoint(this.location.getZ())));
|
||||
setValue(packet, "f", Byte.valueOf(toPackedByte(this.location.getYaw())));
|
||||
setValue(packet, "g", Byte.valueOf(toPackedByte(this.location.getPitch())));
|
||||
setValue(packet, "h", Integer.valueOf(this.inHand == null ? 0 : this.inHand.getId()));
|
||||
setValue(packet, "i", this.watcher);
|
||||
for (Player online : Bukkit.getOnlinePlayers()) {
|
||||
((CraftPlayer)online).getHandle().playerConnection
|
||||
.sendPacket(packet);
|
||||
}
|
||||
npcs.put(Integer.valueOf(this.entityID), this);
|
||||
if (this.hideTablist)
|
||||
removeFromTablist();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void despawn() {
|
||||
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(new int[] {
|
||||
this.entityID });
|
||||
removeFromTablist();
|
||||
for (Player online : Bukkit.getOnlinePlayers()) {
|
||||
((CraftPlayer)online).getHandle().playerConnection
|
||||
.sendPacket(packet);
|
||||
}
|
||||
npcs.remove(Integer.valueOf(this.entityID));
|
||||
}
|
||||
|
||||
public void changePlayerlistName(String name) {
|
||||
try {
|
||||
PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo(
|
||||
PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_DISPLAY_NAME, new EntityPlayer[0]);
|
||||
PacketPlayOutPlayerInfo tmp20_19 = packet; tmp20_19.getClass(); PacketPlayOutPlayerInfo.PlayerInfoData data = new PacketPlayOutPlayerInfo.PlayerInfoData(tmp20_19,
|
||||
this.profile, 0, WorldSettings.EnumGamemode.NOT_SET,
|
||||
CraftChatMessage.fromString(name)[0]);
|
||||
|
||||
List players = (List)
|
||||
getValue(packet, "b");
|
||||
players.add(data);
|
||||
setValue(packet, "b", players);
|
||||
this.tablist = name;
|
||||
for (Player online : Bukkit.getOnlinePlayers())
|
||||
((CraftPlayer)online).getHandle().playerConnection
|
||||
.sendPacket(packet);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void addToTablist() {
|
||||
try {
|
||||
PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo();
|
||||
GameProfile profile = this.profile = getProfile();
|
||||
PacketPlayOutPlayerInfo tmp23_22 = packet; tmp23_22.getClass(); PacketPlayOutPlayerInfo.PlayerInfoData data = new PacketPlayOutPlayerInfo.PlayerInfoData(tmp23_22,
|
||||
profile, 1, WorldSettings.EnumGamemode.NOT_SET,
|
||||
org.bukkit.craftbukkit.v1_8_R3.util.CraftChatMessage.fromString(this.tablist)[0]);
|
||||
|
||||
List players = (List)getValue(
|
||||
packet, "b");
|
||||
players.add(data);
|
||||
setValue(packet, "a",
|
||||
PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER);
|
||||
setValue(packet, "b", players);
|
||||
for (Player online : Bukkit.getOnlinePlayers())
|
||||
((CraftPlayer)online).getHandle().playerConnection
|
||||
.sendPacket(packet);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void removeFromTablist() {
|
||||
try {
|
||||
PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo(
|
||||
PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, new EntityPlayer[0]);
|
||||
PacketPlayOutPlayerInfo tmp20_19 = packet; tmp20_19.getClass(); PacketPlayOutPlayerInfo.PlayerInfoData data = new PacketPlayOutPlayerInfo.PlayerInfoData(tmp20_19,
|
||||
this.profile, -1, null, null);
|
||||
|
||||
List players = (List)
|
||||
getValue(packet, "b");
|
||||
players.add(data);
|
||||
setValue(packet, "b", players);
|
||||
for (Player online : Bukkit.getOnlinePlayers())
|
||||
((CraftPlayer)online).getHandle().playerConnection
|
||||
.sendPacket(packet);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void teleport(Location location) {
|
||||
try {
|
||||
PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport();
|
||||
setValue(packet, "a", Integer.valueOf(this.entityID));
|
||||
setValue(packet, "b", Integer.valueOf(toFixedPoint(location.getX())));
|
||||
setValue(packet, "c", Integer.valueOf(toFixedPoint(location.getY())));
|
||||
setValue(packet, "d", Integer.valueOf(toFixedPoint(location.getZ())));
|
||||
setValue(packet, "e", Byte.valueOf(toPackedByte(location.getYaw())));
|
||||
setValue(packet, "f", Byte.valueOf(toPackedByte(location.getPitch())));
|
||||
setValue(packet, "g",
|
||||
Boolean.valueOf(this.location.getBlock().getType() != Material.AIR));
|
||||
this.location = location;
|
||||
for (Player online : Bukkit.getOnlinePlayers())
|
||||
((CraftPlayer)online).getHandle().playerConnection
|
||||
.sendPacket(packet);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setItemInHand(Material material) {
|
||||
try {
|
||||
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment();
|
||||
setValue(packet, "a", Integer.valueOf(this.entityID));
|
||||
setValue(packet, "b", Integer.valueOf(0));
|
||||
setValue(
|
||||
packet,
|
||||
"c",
|
||||
(material == Material.AIR) || (material == null) ?
|
||||
CraftItemStack.asNMSCopy(new ItemStack(Material.AIR)) :
|
||||
CraftItemStack.asNMSCopy(new ItemStack(material)));
|
||||
this.inHand = material;
|
||||
for (Player online : Bukkit.getOnlinePlayers())
|
||||
((CraftPlayer)online).getHandle().playerConnection
|
||||
.sendPacket(packet);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Material getItemInHand() {
|
||||
return this.inHand;
|
||||
}
|
||||
|
||||
public void setHelmet(Material material) {
|
||||
try {
|
||||
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment();
|
||||
setValue(packet, "a", Integer.valueOf(this.entityID));
|
||||
setValue(packet, "b", Integer.valueOf(4));
|
||||
setValue(
|
||||
packet,
|
||||
"c",
|
||||
(material == Material.AIR) || (material == null) ?
|
||||
CraftItemStack.asNMSCopy(new ItemStack(Material.AIR)) :
|
||||
CraftItemStack.asNMSCopy(new ItemStack(material)));
|
||||
this.helmet = material;
|
||||
for (Player online : Bukkit.getOnlinePlayers())
|
||||
((CraftPlayer)online).getHandle().playerConnection
|
||||
.sendPacket(packet);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Material getHelmet() {
|
||||
return this.helmet;
|
||||
}
|
||||
|
||||
public void setChestplate(Material material) {
|
||||
try {
|
||||
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment();
|
||||
setValue(packet, "a", Integer.valueOf(this.entityID));
|
||||
setValue(packet, "b", Integer.valueOf(3));
|
||||
setValue(
|
||||
packet,
|
||||
"c",
|
||||
(material == Material.AIR) || (material == null) ?
|
||||
CraftItemStack.asNMSCopy(new ItemStack(Material.AIR)) :
|
||||
CraftItemStack.asNMSCopy(new ItemStack(material)));
|
||||
this.chestplate = material;
|
||||
for (Player online : Bukkit.getOnlinePlayers())
|
||||
((CraftPlayer)online).getHandle().playerConnection
|
||||
.sendPacket(packet);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Material getChestplate() {
|
||||
return this.chestplate;
|
||||
}
|
||||
|
||||
public void setLeggings(Material material) {
|
||||
try {
|
||||
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment();
|
||||
setValue(packet, "a", Integer.valueOf(this.entityID));
|
||||
setValue(packet, "b", Integer.valueOf(2));
|
||||
setValue(
|
||||
packet,
|
||||
"c",
|
||||
(material == Material.AIR) || (material == null) ?
|
||||
CraftItemStack.asNMSCopy(new ItemStack(Material.AIR)) :
|
||||
CraftItemStack.asNMSCopy(new ItemStack(material)));
|
||||
this.leggings = material;
|
||||
for (Player online : Bukkit.getOnlinePlayers())
|
||||
((CraftPlayer)online).getHandle().playerConnection
|
||||
.sendPacket(packet);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Material getLeggings() {
|
||||
return this.leggings;
|
||||
}
|
||||
|
||||
public void setBoots(Material material) {
|
||||
try {
|
||||
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment();
|
||||
setValue(packet, "a", Integer.valueOf(this.entityID));
|
||||
setValue(packet, "b", Integer.valueOf(1));
|
||||
setValue(
|
||||
packet,
|
||||
"c",
|
||||
(material == Material.AIR) || (material == null) ?
|
||||
CraftItemStack.asNMSCopy(new ItemStack(Material.AIR)) :
|
||||
CraftItemStack.asNMSCopy(new ItemStack(material)));
|
||||
this.boots = material;
|
||||
for (Player online : Bukkit.getOnlinePlayers())
|
||||
((CraftPlayer)online).getHandle().playerConnection
|
||||
.sendPacket(packet);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Material getBoots() {
|
||||
return this.boots;
|
||||
}
|
||||
|
||||
public int getEntityID() {
|
||||
return this.entityID;
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return this.profile.getId();
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getPlayerlistName() {
|
||||
return this.tablist;
|
||||
}
|
||||
|
||||
private void setValue(Object instance, String field, Object value) throws Exception
|
||||
{
|
||||
Field f = instance.getClass().getDeclaredField(field);
|
||||
f.setAccessible(true);
|
||||
f.set(instance, value);
|
||||
}
|
||||
|
||||
private Object getValue(Object instance, String field) throws Exception {
|
||||
Field f = instance.getClass().getDeclaredField(field);
|
||||
f.setAccessible(true);
|
||||
return f.get(instance);
|
||||
}
|
||||
|
||||
private int toFixedPoint(double d) {
|
||||
return (int)(d * 32.0D);
|
||||
}
|
||||
|
||||
private byte toPackedByte(float f) {
|
||||
return (byte)(int)(f * 256.0F / 360.0F);
|
||||
}
|
||||
|
||||
private GameProfile getProfile() {
|
||||
try {
|
||||
GameProfile profile = GameProfileBuilder.fetch(
|
||||
UUIDFetcher.getUUID(ChatColor.stripColor(this.name)));
|
||||
Field name = profile.getClass().getDeclaredField("name");
|
||||
name.setAccessible(true);
|
||||
name.set(profile, this.name);
|
||||
return profile; } catch (Exception e) {
|
||||
}
|
||||
return getFakeProfile();
|
||||
}
|
||||
|
||||
private GameProfile getFakeProfile()
|
||||
{
|
||||
try {
|
||||
GameProfile profile = GameProfileBuilder.fetch(
|
||||
UUIDFetcher.getUUID(ChatColor.stripColor(this.skinName)));
|
||||
Field name = profile.getClass().getDeclaredField("name");
|
||||
name.setAccessible(true);
|
||||
name.set(profile, this.name);
|
||||
return profile; } catch (Exception e) {
|
||||
}
|
||||
return new GameProfile(UUID.randomUUID(), this.name);
|
||||
}
|
||||
|
||||
public static void injectNetty(Player player)
|
||||
{
|
||||
try
|
||||
{
|
||||
Channel channel = (Channel)channelField.get(((CraftPlayer)player)
|
||||
.getHandle().playerConnection.networkManager);
|
||||
if (channel != null)
|
||||
channel.pipeline().addAfter("decoder", "npc_interact",
|
||||
new MessageToMessageDecoder(player)
|
||||
{
|
||||
protected void decode(ChannelHandlerContext chc, Packet packet, List<Object> out)
|
||||
throws Exception
|
||||
{
|
||||
if ((packet instanceof PacketPlayInUseEntity)) {
|
||||
PacketPlayInUseEntity usePacket = (PacketPlayInUseEntity)packet;
|
||||
if (usePacket.a() == PacketPlayInUseEntity.EnumEntityUseAction.INTERACT) {
|
||||
int entityId =
|
||||
((Integer)NPC.idField
|
||||
.get(usePacket)).intValue();
|
||||
if (NPC.npcs.containsKey(Integer.valueOf(entityId))) {
|
||||
Bukkit.getPluginManager()
|
||||
.callEvent(
|
||||
new NPC.PlayerInteractNPCEvent(
|
||||
NPC.this,
|
||||
(NPC)NPC.npcs.get(Integer.valueOf(entityId))));
|
||||
}
|
||||
}
|
||||
}
|
||||
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) &&
|
||||
(channel.pipeline().get("npc_interact") != null))
|
||||
channel.pipeline().remove("npc_interact");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static 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(null))
|
||||
.registerTypeAdapter(PropertyMap.class,
|
||||
new PropertyMap.Serializer()).create();
|
||||
private static HashMap<UUID, CachedProfile> cache = new HashMap();
|
||||
private static long cacheTime = -1L;
|
||||
|
||||
public static GameProfile fetch(UUID uuid)
|
||||
throws IOException
|
||||
{
|
||||
return fetch(uuid, false);
|
||||
}
|
||||
|
||||
public static GameProfile fetch(UUID uuid, boolean forceNew)
|
||||
throws IOException
|
||||
{
|
||||
if ((!forceNew) && (cache.containsKey(uuid)) &&
|
||||
(((CachedProfile)cache.get(uuid)).isValid())) {
|
||||
return ((CachedProfile)cache.get(uuid)).profile;
|
||||
}
|
||||
HttpURLConnection connection = (HttpURLConnection)new URL(
|
||||
String.format("https://sessionserver.mojang.com/session/minecraft/profile/%s?unsigned=false", new Object[] {
|
||||
UUIDTypeAdapter.fromUUID(uuid) }))
|
||||
.openConnection();
|
||||
connection.setReadTimeout(5000);
|
||||
if (connection.getResponseCode() == 200) {
|
||||
String json = new BufferedReader(
|
||||
new InputStreamReader(connection.getInputStream())).readLine();
|
||||
GameProfile result = (GameProfile)gson.fromJson(json, GameProfile.class);
|
||||
cache.put(uuid, new CachedProfile(result));
|
||||
return result;
|
||||
}
|
||||
if ((!forceNew) && (cache.containsKey(uuid))) {
|
||||
return ((CachedProfile)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());
|
||||
}
|
||||
|
||||
public static GameProfile getProfile(UUID uuid, String name, String skin)
|
||||
{
|
||||
return getProfile(uuid, name, skin, null);
|
||||
}
|
||||
|
||||
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 args = new ArrayList();
|
||||
args.add(Long.valueOf(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 ? "{\"timestamp\":%d,\"profileId\":\"%s\",\"profileName\":\"%s\",\"isPublic\":true,\"textures\":{\"SKIN\":{\"url\":\"%s\"},\"CAPE\":{\"url\":\"%s\"}}}" : "{\"timestamp\":%d,\"profileId\":\"%s\",\"profileName\":\"%s\",\"isPublic\":true,\"textures\":{\"SKIN\":{\"url\":\"%s\"}}}",
|
||||
args.toArray(new Object[args.size()])))));
|
||||
return profile;
|
||||
}
|
||||
|
||||
public static void setCacheTime(long time)
|
||||
{
|
||||
cacheTime = time;
|
||||
}
|
||||
private static class CachedProfile {
|
||||
private long timestamp = System.currentTimeMillis();
|
||||
private GameProfile profile;
|
||||
|
||||
public CachedProfile(GameProfile profile) {
|
||||
this.profile = profile;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return (NPC.GameProfileBuilder.cacheTime < 0L) || (
|
||||
System.currentTimeMillis() - this.timestamp < NPC.GameProfileBuilder.cacheTime);
|
||||
}
|
||||
}
|
||||
|
||||
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"))
|
||||
{
|
||||
Iterator localIterator = ((PropertyMap)context
|
||||
.deserialize(object.get("properties"),
|
||||
PropertyMap.class)).entries().iterator();
|
||||
|
||||
while (localIterator.hasNext())
|
||||
{
|
||||
Map.Entry prop = (Map.Entry)localIterator.next();
|
||||
profile.getProperties().put((String)prop.getKey(),
|
||||
(Property)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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class PlayerInteractNPCEvent extends PlayerEvent
|
||||
{
|
||||
public static HandlerList handlers = new HandlerList();
|
||||
private NPC npc;
|
||||
|
||||
public PlayerInteractNPCEvent(Player who, NPC npc)
|
||||
{
|
||||
super();
|
||||
this.npc = npc;
|
||||
}
|
||||
|
||||
public NPC getNpc() {
|
||||
return this.npc;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
||||
private static class UUIDFetcher
|
||||
{
|
||||
public static final long FEBRUARY_2015 = 1422748800000L;
|
||||
private static Gson gson = new GsonBuilder().registerTypeAdapter(
|
||||
UUID.class, new UUIDTypeAdapter()).create();
|
||||
private static final String UUID_URL = "https://api.mojang.com/users/profiles/minecraft/%s?at=%d";
|
||||
private static final String NAME_URL = "https://api.mojang.com/user/profiles/%s/names";
|
||||
private static Map<String, UUID> uuidCache = new HashMap();
|
||||
private static Map<UUID, String> nameCache = new HashMap();
|
||||
private static ExecutorService pool = Executors.newCachedThreadPool();
|
||||
private String name;
|
||||
private UUID id;
|
||||
|
||||
public static void getUUID(String name, Consumer<UUID> action)
|
||||
{
|
||||
pool.execute(new Acceptor(action, name)
|
||||
{
|
||||
public UUID getValue() {
|
||||
return NPC.UUIDFetcher.getUUID(this.val$name);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static UUID getUUID(String name)
|
||||
{
|
||||
return getUUIDAt(name, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public static void getUUIDAt(String name, long timestamp, Consumer<UUID> action)
|
||||
{
|
||||
pool.execute(new Acceptor(action, name, timestamp)
|
||||
{
|
||||
public UUID getValue() {
|
||||
return NPC.UUIDFetcher.getUUIDAt(this.val$name, this.val$timestamp);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static UUID getUUIDAt(String name, long timestamp)
|
||||
{
|
||||
name = name.toLowerCase();
|
||||
if (uuidCache.containsKey(name))
|
||||
return (UUID)uuidCache.get(name);
|
||||
try
|
||||
{
|
||||
HttpURLConnection connection = (HttpURLConnection)new URL(
|
||||
String.format("https://api.mojang.com/users/profiles/minecraft/%s?at=%d", new Object[] { name, Long.valueOf(timestamp / 1000L) }))
|
||||
.openConnection();
|
||||
connection.setReadTimeout(5000);
|
||||
UUIDFetcher data = (UUIDFetcher)gson.fromJson(
|
||||
new BufferedReader(new InputStreamReader(connection.getInputStream())),
|
||||
UUIDFetcher.class);
|
||||
uuidCache.put(name, data.id);
|
||||
nameCache.put(data.id, data.name);
|
||||
return data.id;
|
||||
} catch (Exception localException) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void getName(UUID uuid, Consumer<String> action)
|
||||
{
|
||||
pool.execute(new Acceptor(action, uuid)
|
||||
{
|
||||
public String getValue() {
|
||||
return NPC.UUIDFetcher.getName(this.val$uuid);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static String getName(UUID uuid)
|
||||
{
|
||||
if (nameCache.containsKey(uuid))
|
||||
return (String)nameCache.get(uuid);
|
||||
try
|
||||
{
|
||||
HttpURLConnection connection = (HttpURLConnection)new URL(
|
||||
String.format("https://api.mojang.com/user/profiles/%s/names", new Object[] { UUIDTypeAdapter.fromUUID(uuid) }))
|
||||
.openConnection();
|
||||
connection.setReadTimeout(5000);
|
||||
UUIDFetcher[] nameHistory = (UUIDFetcher[])gson.fromJson(
|
||||
new BufferedReader(new InputStreamReader(connection.getInputStream())),
|
||||
[Lde.joethei.core.api.NPC.UUIDFetcher.class);
|
||||
UUIDFetcher currentNameData = nameHistory[(nameHistory.length - 1)];
|
||||
uuidCache.put(currentNameData.name.toLowerCase(), uuid);
|
||||
nameCache.put(uuid, currentNameData.name);
|
||||
return currentNameData.name;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static abstract class Acceptor<T>
|
||||
implements Runnable
|
||||
{
|
||||
private NPC.UUIDFetcher.Consumer<T> consumer;
|
||||
|
||||
public Acceptor(NPC.UUIDFetcher.Consumer<T> consumer)
|
||||
{
|
||||
this.consumer = consumer;
|
||||
}
|
||||
|
||||
public abstract T getValue();
|
||||
|
||||
public void run() {
|
||||
this.consumer.accept(getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract interface Consumer<T>
|
||||
{
|
||||
public abstract void accept(T paramT);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.joethei.core.Core;
|
||||
|
||||
/**
|
||||
* gets nick settings for players
|
||||
* @author joethei
|
||||
* @version 1.1
|
||||
*/
|
||||
public class NickName {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param p remove nickname from player
|
||||
*/
|
||||
public static void remove(Player p) {
|
||||
if (Core.nicks.containsKey(p))
|
||||
Core.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
|
||||
*/
|
||||
public static void setNick(Player p, boolean nick) throws SQLException, ClassNotFoundException {
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
String uuid = p.getUniqueId().toString();
|
||||
if (nick)
|
||||
sql.getConnection().createStatement().executeUpdate("UPDATE PlayerData SET nick = '1' WHERE player_uuid = '" + uuid + "';");
|
||||
else
|
||||
sql.getConnection().createStatement().executeUpdate("UPDATE PlayerData SET nick = '0' WHERE player_uuid = '" + uuid + "';");
|
||||
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
|
||||
*/
|
||||
public static boolean isNicked(Player p) throws SQLException, ClassNotFoundException {
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
String uuid = p.getUniqueId().toString();
|
||||
ResultSet rs = sql.getConnection().createStatement().executeQuery("SELECT nick FROM PlayerData WHERE player_uuid = '" + uuid + "';");
|
||||
if (rs.next()) {
|
||||
return rs.getInt("nick") == 1;
|
||||
}
|
||||
sql.closeConnection();
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets nickname of player
|
||||
* @param p player
|
||||
* @return String
|
||||
*/
|
||||
public static String getNick(Player p) {
|
||||
if (Core.nicks.containsKey(p)) {
|
||||
String nick = (String) Core.nicks.get(p);
|
||||
return nick;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets random Nickname
|
||||
* @return String
|
||||
* @throws SQLException SQL server not available or throwing error
|
||||
*/
|
||||
public static String getNicks() throws SQLException {
|
||||
ArrayList<String> names = new ArrayList<String>();
|
||||
names.add("XXKevinXX");
|
||||
names.add("xxGamelcrafterxx");
|
||||
names.add("LiaaamDesigns");
|
||||
|
||||
Random r = new Random();
|
||||
int i = r.nextInt(names.size());
|
||||
|
||||
return (String) names.get(i);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/***************************
|
||||
* Pagifier by leNic *
|
||||
***************************/
|
||||
/**
|
||||
* @author leNic
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Pagifier<T> {
|
||||
// Properties
|
||||
private int pageSize;
|
||||
// List of pages
|
||||
private List<List<T>> pages;
|
||||
// Constructor
|
||||
public Pagifier(int pageSize){
|
||||
this.pageSize = pageSize;
|
||||
this.pages = new ArrayList<>();
|
||||
// Create first page
|
||||
this.pages.add(new ArrayList<>());
|
||||
}
|
||||
/**
|
||||
* Add item to pages
|
||||
* (Creates a new page if the previous page is not existing or full)
|
||||
* @param item The item you want to add
|
||||
*/
|
||||
public void addItem(T item){
|
||||
int pageNum = pages.size() - 1;
|
||||
List<T> currentPage = this.pages.get(pageNum);
|
||||
// Add page if full
|
||||
if(currentPage.size() >= this.pageSize) {
|
||||
currentPage = new ArrayList<>();
|
||||
this.pages.add(currentPage);
|
||||
pageNum++;
|
||||
}
|
||||
currentPage.add(item);
|
||||
}
|
||||
/**
|
||||
* Get the items of a page
|
||||
* @param pageNum Number of the page (beginning at 0)
|
||||
* @return Optional with a list of the page's items
|
||||
*/
|
||||
public Optional<List<T>> getPage(int pageNum){
|
||||
if(this.pages.size() == 0)
|
||||
return Optional.empty();
|
||||
return Optional.of(this.pages.get(pageNum));
|
||||
}
|
||||
/**
|
||||
* Get all pages
|
||||
* @return List containing all pages
|
||||
*/
|
||||
public List<List<T>> getPages(){
|
||||
return this.pages;
|
||||
}
|
||||
/**
|
||||
* Get the current set page size
|
||||
* @return The current page size
|
||||
*/
|
||||
public int getPageSize(){
|
||||
return this.pageSize;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,161 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import de.joethei.core.Core;
|
||||
|
||||
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<CustomPlayer, Ranks>();
|
||||
public static HashMap<CustomPlayer, Ranks> getRanks() {
|
||||
return ranks;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the prefix of a player
|
||||
* @param p player
|
||||
* @return String
|
||||
*/
|
||||
public static String getPrefix(CustomPlayer p) {
|
||||
switch(p.getRank()) {
|
||||
case Admin: return "§7[§4Admin§7]§4 ";
|
||||
case Developer: return "§7[§3Developer§7] §3 ";
|
||||
case HeadBuild: return "§7[§aHead-Builder§7]§a ";
|
||||
case Builder: return "§7[§2Builder§7]§2 ";
|
||||
case Moderator: return "§7[§cModerator§7]§c ";
|
||||
case Supporter: return "§7[§bSupporter§7]§b ";
|
||||
case Youtuber: return "§5";
|
||||
case Premium: return "§6";
|
||||
case Spieler: return "§7";
|
||||
default: return "§cFehler ";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the suffix of a player
|
||||
* @param p Player
|
||||
* @return String
|
||||
*/
|
||||
public static String getSuffix(CustomPlayer p) {
|
||||
switch(p.getRank()) {
|
||||
case Admin: return " §8» §f§l";
|
||||
case Developer: return " §8» §f§l";
|
||||
case HeadBuild: return " §8» §f§l";
|
||||
case Builder: return " §8» §f§l";
|
||||
case Moderator: return " §8» §f§l";
|
||||
case Supporter: return " §8» §f§l";
|
||||
case Youtuber: return " §8» §f§l";
|
||||
case Premium: return " §8» §f§l";
|
||||
case Spieler: return " §8» §f§l";
|
||||
default: return "§cFehler";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets color of a player
|
||||
* @param p Player
|
||||
* @return String
|
||||
*/
|
||||
public static String getColor(CustomPlayer p) {
|
||||
switch(p.getRank()) {
|
||||
case Admin: return "§4";
|
||||
case Developer: return "§3";
|
||||
case HeadBuild: return "§a";
|
||||
case Builder: return "§2";
|
||||
case Moderator: return "§c";
|
||||
case Supporter: return "§b";
|
||||
case Youtuber: return "§5";
|
||||
case Premium: return "§6";
|
||||
case Spieler: return "§7";
|
||||
default: return "§cFehler";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets Rank of player
|
||||
* @param p Player
|
||||
* @return Ranks
|
||||
*/
|
||||
public static Ranks getRank(CustomPlayer p) {
|
||||
return getRanks().get(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
|
||||
*/
|
||||
public static Ranks getRankFresh(CustomPlayer p) throws SQLException, ClassNotFoundException {
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
ResultSet rs = sql.getConnection().createStatement().executeQuery("SELECT * FROM PlayerData WHERE player_uuid='" + p.getUniqueId() + "'");
|
||||
rs.next();
|
||||
if (rs.getString("player_uuid") != null) {
|
||||
String rank = rs.getString("Rank");
|
||||
Ranks Rank = Ranks.valueOf(rank);
|
||||
sql.closeConnection();
|
||||
return Rank;
|
||||
}
|
||||
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
|
||||
*/
|
||||
public static void setRank(CustomPlayer p, Ranks r) throws ClassNotFoundException, SQLException {
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
sql.getConnection().createStatement().execute("UPDATE PlayerData SET Rank='" + r.toString() + "' WHERE player_uuid='" + p.getUniqueId() + "';");
|
||||
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
|
||||
*/
|
||||
public 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;
|
||||
}
|
||||
|
||||
public static enum Ranks{
|
||||
Admin(9),
|
||||
Developer(8),
|
||||
HeadBuild(7),
|
||||
Builder(6),
|
||||
Moderator(5),
|
||||
Supporter(4),
|
||||
Youtuber(3),
|
||||
Premium(2),
|
||||
Spieler(1);
|
||||
|
||||
public final int value;
|
||||
|
||||
private Ranks(int n) {
|
||||
this.value = n;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class SQLite extends Database
|
||||
{
|
||||
private final String dbLocation;
|
||||
|
||||
public SQLite(Plugin plugin, String dbLocation)
|
||||
{
|
||||
super(plugin);
|
||||
this.dbLocation = dbLocation;
|
||||
}
|
||||
|
||||
public Connection openConnection()
|
||||
throws SQLException, ClassNotFoundException
|
||||
{
|
||||
if (checkConnection()) {
|
||||
return this.connection;
|
||||
}
|
||||
if (!this.plugin.getDataFolder().exists()) {
|
||||
this.plugin.getDataFolder().mkdirs();
|
||||
}
|
||||
File file = new File(this.plugin.getDataFolder(), this.dbLocation);
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
this.plugin.getLogger().log(Level.SEVERE,
|
||||
"Unable to create database!");
|
||||
}
|
||||
}
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
this.connection =
|
||||
DriverManager.getConnection("jdbc:sqlite:" +
|
||||
this.plugin.getDataFolder().toPath().toString() + "/" +
|
||||
this.dbLocation);
|
||||
return this.connection;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
public class ServerPinger
|
||||
{
|
||||
private String host;
|
||||
private int port;
|
||||
|
||||
public ServerPinger(String host, int port)
|
||||
{
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public ServerPinger(String host) {
|
||||
this.host = host;
|
||||
this.port = 25565;
|
||||
}
|
||||
|
||||
public ServerPinger() {
|
||||
this.host = "127.0.0.1";
|
||||
this.port = 25565;
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
public String parseData(Connection connection)
|
||||
{
|
||||
try
|
||||
{
|
||||
Socket socket = new Socket();
|
||||
|
||||
socket.setSoTimeout(2500);
|
||||
socket.connect(new InetSocketAddress(this.host, this.port));
|
||||
|
||||
OutputStream os = socket.getOutputStream();
|
||||
DataOutputStream dos = new DataOutputStream(os);
|
||||
|
||||
InputStream is = socket.getInputStream();
|
||||
InputStreamReader isr = new InputStreamReader(is, Charset.forName("UTF-16BE"));
|
||||
|
||||
dos.write(new byte[] { -2, 1 });
|
||||
|
||||
int packetID = is.read();
|
||||
|
||||
if (packetID == -1) {
|
||||
System.out.println("Invalid Packet ID! (End Of Stream)");
|
||||
}
|
||||
if (packetID != 255) {
|
||||
System.out.println("Invalid Packet Id! " + packetID);
|
||||
}
|
||||
|
||||
int length = isr.read();
|
||||
|
||||
if (length == -1) {
|
||||
System.out.println("End Of Stream");
|
||||
}
|
||||
|
||||
if (length == 0) {
|
||||
System.out.println("Invalid length");
|
||||
}
|
||||
|
||||
char[] chars = new char[length];
|
||||
|
||||
if (isr.read(chars, 0, length) != length) {
|
||||
System.out.println("End Of Stream");
|
||||
}
|
||||
|
||||
String string = new String(chars);
|
||||
String[] data = string.split("");
|
||||
|
||||
if (connection == Connection.ONLINE_PLAYERS)
|
||||
return data[4];
|
||||
if (connection == Connection.MOTD)
|
||||
return data[3];
|
||||
if (connection == Connection.MAX_PLAYERS) {
|
||||
return data[5];
|
||||
}
|
||||
System.out.println("Connection value not handled!");
|
||||
}
|
||||
catch (Exception localException)
|
||||
{
|
||||
localException.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static enum Connection {
|
||||
ONLINE_PLAYERS, MAX_PLAYERS, MOTD;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import de.joethei.core.Core;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* sends player to other bungeecord servers
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Servers {
|
||||
|
||||
|
||||
/**
|
||||
* sends player to server
|
||||
* @param p player
|
||||
* @param server name of server
|
||||
*/
|
||||
public static void connectServer(Player p, String server) {
|
||||
if ((p instanceof Player)) {
|
||||
ByteArrayOutputStream b = new ByteArrayOutputStream();
|
||||
DataOutputStream out = new DataOutputStream(b);
|
||||
try {
|
||||
out.writeUTF("Connect");
|
||||
out.writeUTF(server);
|
||||
} catch (IOException el) {
|
||||
el.printStackTrace();
|
||||
}
|
||||
p.sendPluginMessage(Core.getInstance(), "BungeeCord", b.toByteArray());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* connects all player to server
|
||||
* @param server name of server
|
||||
*/
|
||||
public static void connectAllToServer(String server) {
|
||||
for (Player all : Bukkit.getOnlinePlayers())
|
||||
connectServer(all, server);
|
||||
}
|
||||
|
||||
/**
|
||||
* gets player count of server
|
||||
* @param server name of server
|
||||
* @return player count
|
||||
*/
|
||||
public static int getOnlinePlayers(String server) {
|
||||
int online = 0;
|
||||
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
|
||||
out.writeUTF("PlayerCount");
|
||||
out.writeUTF(server);
|
||||
|
||||
Player player = (Player) Iterables.getFirst(Bukkit.getOnlinePlayers(), null);
|
||||
player.sendPluginMessage(Core.getInstance(), "BungeeCord", out.toByteArray());
|
||||
|
||||
return online;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets ip of server from bungeecord
|
||||
* @param server server name
|
||||
* @return server ip
|
||||
*/
|
||||
public static String getServerIP(String server) {
|
||||
String ip = null;
|
||||
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
|
||||
out.writeUTF("ServerInfo");
|
||||
out.writeUTF(server);
|
||||
|
||||
Player player = (Player) Iterables.getFirst(Bukkit.getOnlinePlayers(), null);
|
||||
player.sendPluginMessage(Core.getInstance(), "BungeeCord", out.toByteArray());
|
||||
|
||||
return ip;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* gets port of server from bungeecord
|
||||
* @param server server name
|
||||
* @return server port
|
||||
*/
|
||||
public static int getServerPort(String server) {
|
||||
int port = 0;
|
||||
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
|
||||
out.writeUTF("ServerInfo");
|
||||
out.writeUTF(server);
|
||||
|
||||
Player player = (Player) Iterables.getFirst(Bukkit.getOnlinePlayers(), null);
|
||||
player.sendPluginMessage(Core.getInstance(), "BungeeCord", out.toByteArray());
|
||||
|
||||
return port;
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
/**
|
||||
* server-wide settings
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
*/
|
||||
|
||||
public class Settings {
|
||||
|
||||
private static boolean build;
|
||||
private static boolean lobby;
|
||||
private static boolean debug;
|
||||
private static boolean mute;
|
||||
/**
|
||||
* @return is build
|
||||
*/
|
||||
public static boolean isBuild() {
|
||||
return build;
|
||||
}
|
||||
/**
|
||||
* @param build the build to set
|
||||
*/
|
||||
public static void setBuild(boolean build) {
|
||||
Settings.build = build;
|
||||
}
|
||||
/**
|
||||
* @return is lobby
|
||||
*/
|
||||
public static boolean isLobby() {
|
||||
return lobby;
|
||||
}
|
||||
/**
|
||||
* @param lobby the lobby to set
|
||||
*/
|
||||
public static void setLobby(boolean lobby) {
|
||||
Settings.lobby = lobby;
|
||||
}
|
||||
/**
|
||||
* @return is debug
|
||||
*/
|
||||
public static boolean isDebug() {
|
||||
return debug;
|
||||
}
|
||||
/**
|
||||
* @param debug the debug to set
|
||||
*/
|
||||
public static void setDebug(boolean debug) {
|
||||
Settings.debug = debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return is mute
|
||||
*/
|
||||
public static boolean isMute() {
|
||||
return mute;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param mute the mute to set
|
||||
*/
|
||||
public static void setMute(boolean mute) {
|
||||
Settings.mute = mute;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,145 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||
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;
|
||||
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 org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
public final class SignInput
|
||||
implements Listener, Runnable
|
||||
{
|
||||
private static final String VERSION;
|
||||
private final Plugin plugin;
|
||||
private final Map<UUID, Consumer<String[]>> inputResults;
|
||||
|
||||
static
|
||||
{
|
||||
String path = Bukkit.getServer().getClass().getPackage().getName();
|
||||
VERSION = path.substring(path.lastIndexOf(".") + 1, path.length());
|
||||
}
|
||||
|
||||
public SignInput(Plugin plugin)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.inputResults = new HashMap();
|
||||
Bukkit.getScheduler().runTaskTimer(this.plugin, this, 0L, 60L);
|
||||
}
|
||||
|
||||
public boolean readInput(Player p, Consumer<String[]> result)
|
||||
{
|
||||
this.inputResults.put(p.getUniqueId(), result);
|
||||
try {
|
||||
Class packetClass =
|
||||
Class.forName(getNMSClass("PacketPlayOutOpenSignEditor"));
|
||||
Class blockPositionClass =
|
||||
Class.forName(getNMSClass("BlockPosition"));
|
||||
Constructor blockPosCon = blockPositionClass
|
||||
.getConstructor(new Class[] { Integer.TYPE, Integer.TYPE,
|
||||
Integer.TYPE });
|
||||
Object blockPosition = blockPosCon.newInstance(new Object[] { Integer.valueOf(0), Integer.valueOf(0),
|
||||
Integer.valueOf(0) });
|
||||
Constructor packetCon = packetClass
|
||||
.getConstructor(new Class[] { blockPositionClass });
|
||||
Object packet = packetCon
|
||||
.newInstance(new Object[] { blockPosition });
|
||||
|
||||
Method getHandle = p.getClass().getMethod("getHandle", new Class[0]);
|
||||
Object nmsPlayer = getHandle.invoke(p, new Object[0]);
|
||||
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;
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
for (UUID uuid : this.inputResults.keySet())
|
||||
if (Bukkit.getPlayer(uuid) == null)
|
||||
this.inputResults.remove(uuid);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e)
|
||||
{
|
||||
Player p = e.getPlayer();
|
||||
getNettyChannel(p).pipeline().addAfter("decoder", "signListener",
|
||||
new MessageToMessageDecoder() {
|
||||
protected void decode(ChannelHandlerContext chc, Object packet, List<Object> packetList) throws Exception {
|
||||
if (SignInput.this.instanceOf(packet,
|
||||
SignInput.access(SignInput.this, "PacketPlayInUpdateSign"))) {
|
||||
Method bMethod = packet.getClass().getMethod("b", new Class[0]);
|
||||
Object chatBaseComponents = bMethod.invoke(packet, new Object[0]);
|
||||
String[] lines = new String[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Object chatComponent = Array.get(
|
||||
chatBaseComponents, i);
|
||||
Method getText = chatComponent.getClass()
|
||||
.getMethod("getText", new Class[0]);
|
||||
lines[i] =
|
||||
((String)getText
|
||||
.invoke(chatComponent, new Object[0]));
|
||||
}
|
||||
if (SignInput.this.inputResults.containsKey(p.getUniqueId())) {
|
||||
((Consumer)SignInput.this.inputResults.get(p.getUniqueId())).accept(lines);
|
||||
SignInput.this.inputResults.remove(p.getUniqueId());
|
||||
}
|
||||
}
|
||||
packetList.add(packet);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Channel getNettyChannel(Player p) {
|
||||
Channel ch = null;
|
||||
try {
|
||||
Method getHandle = p.getClass().getMethod("getHandle", new Class[0]);
|
||||
Object nmsPlayer = getHandle.invoke(p, new Object[0]);
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
public class SimpleScoreboard
|
||||
{
|
||||
private Scoreboard scoreboard;
|
||||
private String title;
|
||||
private Map<String, Integer> scores;
|
||||
private List<Team> teams;
|
||||
|
||||
public SimpleScoreboard(String title)
|
||||
{
|
||||
this.scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
|
||||
this.title = title;
|
||||
this.scores = Maps.newLinkedHashMap();
|
||||
this.teams = Lists.newArrayList();
|
||||
}
|
||||
|
||||
public void add(String text) {
|
||||
add(text, null);
|
||||
}
|
||||
|
||||
public void add(String text, Integer score) {
|
||||
Preconditions.checkArgument(text.length() < 48, "text cannot be over 48 characters in length");
|
||||
text = fixDuplicates(text);
|
||||
this.scores.put(text, score);
|
||||
}
|
||||
|
||||
private String fixDuplicates(String text) {
|
||||
while (this.scores.containsKey(text))
|
||||
text = text + "§r";
|
||||
if (text.length() > 48)
|
||||
text = text.substring(0, 47);
|
||||
return text;
|
||||
}
|
||||
|
||||
private Map.Entry<Team, String> createTeam(String text)
|
||||
{
|
||||
String result = "";
|
||||
if (text.length() <= 16)
|
||||
return new AbstractMap.SimpleEntry<Team, String>(null, text);
|
||||
Team team = this.scoreboard.registerNewTeam("text-" + this.scoreboard.getTeams().size());
|
||||
Iterator<String> iterator = Splitter.fixedLength(16).split(text).iterator();
|
||||
team.setPrefix((String)iterator.next());
|
||||
result = (String)iterator.next();
|
||||
if (text.length() > 32)
|
||||
team.setSuffix((String)iterator.next());
|
||||
this.teams.add(team);
|
||||
return new AbstractMap.SimpleEntry<Team, String>(team, result);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "deprecation", "rawtypes" })
|
||||
public void build()
|
||||
{
|
||||
Objective obj = this.scoreboard.registerNewObjective(this.title.length() > 16 ? this.title.substring(0, 15) : this.title, "dummy");
|
||||
obj.setDisplayName(this.title);
|
||||
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
|
||||
int index = this.scores.size();
|
||||
|
||||
for (Map.Entry text : this.scores.entrySet()) {
|
||||
Map.Entry team = createTeam((String)text.getKey());
|
||||
Integer score = Integer.valueOf(text.getValue() != null ? ((Integer)text.getValue()).intValue() : index);
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer((String)team.getValue());
|
||||
if (team.getKey() != null)
|
||||
((Team)team.getKey()).addPlayer(player);
|
||||
obj.getScore(player.getName()).setScore(score.intValue());
|
||||
index--;
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.title = null;
|
||||
this.scores.clear();
|
||||
for (Team t : this.teams)
|
||||
t.unregister();
|
||||
this.teams.clear();
|
||||
}
|
||||
|
||||
public Scoreboard getScoreboard() {
|
||||
return this.scoreboard;
|
||||
}
|
||||
|
||||
public void send(Player[] players) {
|
||||
for (Player p : players)
|
||||
p.setScoreboard(this.scoreboard);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Spectator {
|
||||
|
||||
private static ArrayList<CustomPlayer> spectators = new ArrayList<CustomPlayer>();
|
||||
|
||||
public Spectator() {
|
||||
}
|
||||
|
||||
public static void add(Player p) {
|
||||
for(Player on : Bukkit.getOnlinePlayers()) {
|
||||
on.hidePlayer(p);
|
||||
}
|
||||
spectators.add(CustomPlayer.getPlayer(p.getName()));
|
||||
p.setGameMode(GameMode.CREATIVE);
|
||||
p.setAllowFlight(true);
|
||||
p.setFlying(true);
|
||||
}
|
||||
|
||||
public static void remove(Player p) {
|
||||
for(Player on : Bukkit.getOnlinePlayers()) {
|
||||
on.showPlayer(p);
|
||||
}
|
||||
spectators.remove(CustomPlayer.getPlayer(p.getName()));
|
||||
p.setGameMode(GameMode.SURVIVAL);
|
||||
p.setAllowFlight(false);
|
||||
p.setFlying(false);
|
||||
}
|
||||
|
||||
public static ArrayList<CustomPlayer> getSpectators() {
|
||||
return spectators;
|
||||
}
|
||||
|
||||
public static boolean is(CustomPlayer p) {
|
||||
return spectators.contains(p.getName());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
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;
|
||||
|
||||
public class Title
|
||||
{
|
||||
@Deprecated
|
||||
public static void sendTitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String message)
|
||||
{
|
||||
sendTitle(player, fadeIn, stay, fadeOut, message, null);
|
||||
}
|
||||
@Deprecated
|
||||
public static void sendSubtitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String message) {
|
||||
sendTitle(player, fadeIn, stay, fadeOut, null, message);
|
||||
}
|
||||
@Deprecated
|
||||
public static void sendFullTitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String title, String subtitle) {
|
||||
sendTitle(player, fadeIn, stay, fadeOut, title, subtitle);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
boolean isInteger(String s)
|
||||
{
|
||||
try {
|
||||
Integer.parseInt(s);
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,179 @@
|
|||
package de.joethei.core.api;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import net.minecraft.server.v1_8_R3.EnumParticle;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutWorldParticles;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.FireworkEffect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Firework;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.FireworkMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class Utils
|
||||
{
|
||||
|
||||
public static void deleteFolder(File folder)
|
||||
{
|
||||
File[] files = folder.listFiles();
|
||||
if (files != null) {
|
||||
for (File f : files) {
|
||||
if (f.isDirectory())
|
||||
deleteFolder(f);
|
||||
else {
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
folder.delete();
|
||||
}
|
||||
|
||||
public static void PlaySoundToAll(Sound s) {
|
||||
for (Player all : Bukkit.getOnlinePlayers())
|
||||
all.playSound(all.getLocation(), s, 3.0F, 3.0F);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void PlayEffectToAll(Effect s)
|
||||
{
|
||||
for (Player all : Bukkit.getOnlinePlayers())
|
||||
all.playEffect(all.getLocation(), s, 3);
|
||||
}
|
||||
|
||||
public static boolean isSpigot() {
|
||||
return Bukkit.getVersion().contains("Spigot");
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
public static double random(int low, int high) {
|
||||
return Math.random() * (high - low) + low;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static ItemStack createItemStack(int id, int anzahl, int sh, String name) {
|
||||
ItemStack item = new ItemStack(id, anzahl, (short)sh);
|
||||
ItemMeta im = item.getItemMeta();
|
||||
im.setDisplayName(name);
|
||||
item.setItemMeta(im);
|
||||
return item;
|
||||
}
|
||||
public static boolean emptyInventory(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;
|
||||
}
|
||||
public static void randomFirework(Location loc) {
|
||||
Firework fw = (Firework)loc.getWorld().spawnEntity(loc, EntityType.FIREWORK);
|
||||
FireworkMeta fwm = fw.getFireworkMeta();
|
||||
Random r = new Random();
|
||||
int rt = r.nextInt(5) + 1;
|
||||
FireworkEffect.Type type = FireworkEffect.Type.BALL;
|
||||
if (rt == 1) type = FireworkEffect.Type.BALL;
|
||||
if (rt == 2) type = FireworkEffect.Type.BALL_LARGE;
|
||||
if (rt == 3) type = FireworkEffect.Type.BURST;
|
||||
if (rt == 4) type = FireworkEffect.Type.CREEPER;
|
||||
if (rt == 5) type = FireworkEffect.Type.STAR;
|
||||
|
||||
int red = r.nextInt(256);
|
||||
int b = r.nextInt(256);
|
||||
int g = r.nextInt(256);
|
||||
|
||||
Color c1 = Color.fromRGB(red, g, b);
|
||||
|
||||
red = r.nextInt(256);
|
||||
b = r.nextInt(256);
|
||||
g = r.nextInt(256);
|
||||
Color c2 = Color.fromRGB(red, g, b);
|
||||
|
||||
FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type).trail(r.nextBoolean()).build();
|
||||
fwm.addEffect(effect);
|
||||
int rp = r.nextInt(2) + 1;
|
||||
fwm.setPower(rp);
|
||||
fw.setFireworkMeta(fwm);
|
||||
}
|
||||
|
||||
public static int removeEntitys(List<Entity> e) {
|
||||
int i = 0;
|
||||
for (Entity en : e) {
|
||||
en.remove();
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public static void clearPotionEffects(Player player) {
|
||||
for (PotionEffect effect : player.getActivePotionEffects())
|
||||
player.removePotionEffect(effect.getType());
|
||||
}
|
||||
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, new int[] { 0, 0 });
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package de.joethei.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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package de.joethei.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;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,381 @@
|
|||
package de.joethei.core.api.twitch;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package de.joethei.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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,227 @@
|
|||
package de.joethei.core.api.utils;
|
||||
|
||||
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 org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class FakeDragon
|
||||
{
|
||||
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(new Class[] { getMCClass("EntityLiving") });
|
||||
entityEnderdragon = getMCClass("EntityEnderDragon").getConstructor(new Class[] { getMCClass("World") });
|
||||
|
||||
setLocation = getMCClass("EntityEnderDragon").getMethod("setLocation", new Class[] { Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE });
|
||||
setCustomName = getMCClass("EntityEnderDragon").getMethod("setCustomName", new Class[] { String.class });
|
||||
setHealth = getMCClass("EntityEnderDragon").getMethod("setHealth", new Class[] { Float.TYPE });
|
||||
setInvisible = getMCClass("EntityEnderDragon").getMethod("setInvisible", new Class[] { Boolean.TYPE });
|
||||
|
||||
getWorldHandle = getCraftClass("CraftWorld").getMethod("getHandle", new Class[0]);
|
||||
getPlayerHandle = getCraftClass("entity.CraftPlayer").getMethod("getHandle", new Class[0]);
|
||||
playerConnection = getMCClass("EntityPlayer").getDeclaredField("playerConnection");
|
||||
sendPacket = getMCClass("PlayerConnection").getMethod("sendPacket", new Class[] { getMCClass("Packet") });
|
||||
|
||||
getDatawatcher = getMCClass("EntityEnderDragon").getMethod("getDataWatcher", new Class[0]);
|
||||
a = getMCClass("DataWatcher").getMethod("a", new Class[] { Integer.TYPE, 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 (playerDragons.containsKey(p.getName())) {
|
||||
return playerDragons.get(p.getName());
|
||||
}
|
||||
Object nms_world = getWorldHandle.invoke(p.getWorld(), new Object[0]);
|
||||
playerDragons.put(p.getName(), entityEnderdragon.newInstance(new Object[] { nms_world }));
|
||||
return 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, new Object[] { Double.valueOf(getPlayerLoc(p).getX()), Double.valueOf(getPlayerLoc(p).getY() + 800.0D), Double.valueOf(getPlayerLoc(p).getZ()), Float.valueOf(0.0F), Float.valueOf(0.0F) });
|
||||
setCustomName.invoke(nms_dragon, new Object[] { text });
|
||||
setHealth.invoke(nms_dragon, new Object[] { Integer.valueOf(200) });
|
||||
setInvisible.invoke(nms_dragon, new Object[] { Boolean.valueOf(true) });
|
||||
changeWatcher(nms_dragon, text);
|
||||
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(new Object[] { nms_dragon });
|
||||
Object nms_player = getPlayerHandle.invoke(p, new Object[0]);
|
||||
Object nms_connection = playerConnection.get(nms_player);
|
||||
sendPacket.invoke(nms_connection, new Object[] { 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, new Object[] { Double.valueOf(getPlayerLoc(p).getX()), Double.valueOf(getPlayerLoc(p).getY() + 800.0D), Double.valueOf(getPlayerLoc(p).getZ()), Float.valueOf(0.0F), Float.valueOf(0.0F) });
|
||||
setCustomName.invoke(nms_dragon, new Object[] { text });
|
||||
setHealth.invoke(nms_dragon, new Object[] { Float.valueOf(vie) });
|
||||
setInvisible.invoke(nms_dragon, new Object[] { Boolean.valueOf(true) });
|
||||
changeWatcher(nms_dragon, text);
|
||||
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(new Object[] { nms_dragon });
|
||||
Object nms_player = getPlayerHandle.invoke(p, new Object[0]);
|
||||
Object nms_connection = playerConnection.get(nms_player);
|
||||
sendPacket.invoke(nms_connection, new Object[] { 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, new Object[] { Double.valueOf(p.getLocation().getX()), Integer.valueOf(-5000), Double.valueOf(p.getLocation().getZ()), Float.valueOf(0.0F), Float.valueOf(0.0F) });
|
||||
setCustomName.invoke(nms_dragon, new Object[] { " " });
|
||||
setHealth.invoke(nms_dragon, new Object[] { Integer.valueOf(0) });
|
||||
setInvisible.invoke(nms_dragon, new Object[] { Boolean.valueOf(true) });
|
||||
changeWatcher(nms_dragon, " ");
|
||||
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(new Object[] { nms_dragon });
|
||||
Object nms_player = getPlayerHandle.invoke(p, new Object[0]);
|
||||
Object nms_connection = playerConnection.get(nms_player);
|
||||
sendPacket.invoke(nms_connection, new Object[] { nms_packet });
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public 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, new Object[0]);
|
||||
Map map = (Map)d.get(nms_watcher);
|
||||
map.remove(Integer.valueOf(10));
|
||||
a.invoke(nms_watcher, new Object[] { Integer.valueOf(10), text });
|
||||
}
|
||||
|
||||
private static Class<?> getMCClass(String name) throws ClassNotFoundException {
|
||||
String version = org.bukkit.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 = org.bukkit.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.0F) % 360.0F;
|
||||
if (rotation < 0.0D) {
|
||||
rotation += 360.0D;
|
||||
}
|
||||
if ((0.0D <= rotation) && (rotation < 22.5D))
|
||||
return "N";
|
||||
if ((22.5D <= rotation) && (rotation < 67.5D))
|
||||
return "NE";
|
||||
if ((67.5D <= rotation) && (rotation < 112.5D))
|
||||
return "E";
|
||||
if ((112.5D <= rotation) && (rotation < 157.5D))
|
||||
return "SE";
|
||||
if ((157.5D <= rotation) && (rotation < 202.5D))
|
||||
return "S";
|
||||
if ((202.5D <= rotation) && (rotation < 247.5D))
|
||||
return "SW";
|
||||
if ((247.5D <= rotation) && (rotation < 292.5D))
|
||||
return "W";
|
||||
if ((292.5D <= rotation) && (rotation < 337.5D))
|
||||
return "NW";
|
||||
if ((337.5D <= rotation) && (rotation < 360.0D)) {
|
||||
return "N";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Location getPlayerLoc(Player p)
|
||||
{
|
||||
Location loc = p.getLocation();
|
||||
String str;
|
||||
switch ((str = getCardinalDirection(p)).hashCode()) { case 69:
|
||||
if (!str.equals("E")) break;
|
||||
break;
|
||||
case 78:
|
||||
case 83:
|
||||
if ((!str.equals("N")) || (goto 284) ||
|
||||
(!str.equals("S"))) break;
|
||||
break;
|
||||
case 87:
|
||||
case 2487:
|
||||
if ((!str.equals("W")) ||
|
||||
(goto 284) ||
|
||||
(!str.equals("NE"))) break;
|
||||
break;
|
||||
case 2505:
|
||||
case 2642:
|
||||
if ((!str.equals("NW")) ||
|
||||
(goto 284) ||
|
||||
(!str.equals("SE"))) break;
|
||||
break;
|
||||
case 2660:
|
||||
if (!str.equals("SW"))
|
||||
{
|
||||
loc.add(0.0D, 0.0D, -150.0D);
|
||||
|
||||
loc.add(150.0D, 0.0D, 0.0D);
|
||||
|
||||
loc.add(0.0D, 0.0D, 150.0D);
|
||||
|
||||
loc.add(-150.0D, 0.0D, 0.0D);
|
||||
|
||||
loc.add(150.0D, 0.0D, -150.0D);
|
||||
|
||||
loc.add(150.0D, 0.0D, 150.0D);
|
||||
|
||||
loc.add(-150.0D, 0.0D, -150.0D);
|
||||
}
|
||||
else {
|
||||
loc.add(-150.0D, 0.0D, 150.0D);
|
||||
}
|
||||
}
|
||||
|
||||
return loc;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,277 @@
|
|||
package de.joethei.core.api.utils;
|
||||
|
||||
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;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class FakeWither
|
||||
{
|
||||
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();
|
||||
private static Map<String, Object> playerWithers2 = new HashMap();
|
||||
private static Map<String, String> playerTextWither = new HashMap();
|
||||
|
||||
static
|
||||
{
|
||||
try {
|
||||
packetPlayOutSpawnEntityLiving = getMCClass("PacketPlayOutSpawnEntityLiving").getConstructor(new Class[] { getMCClass("EntityLiving") });
|
||||
entityEntityWither = getMCClass("EntityWither").getConstructor(new Class[] { getMCClass("World") });
|
||||
|
||||
setLocation = getMCClass("EntityWither").getMethod("setLocation", new Class[] { Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE });
|
||||
setCustomName = getMCClass("EntityWither").getMethod("setCustomName", new Class[] { String.class });
|
||||
setHealth = getMCClass("EntityWither").getMethod("setHealth", new Class[] { Float.TYPE });
|
||||
setInvisible = getMCClass("EntityWither").getMethod("setInvisible", new Class[] { Boolean.TYPE });
|
||||
|
||||
getWorldHandle = getCraftClass("CraftWorld").getMethod("getHandle", new Class[0]);
|
||||
getPlayerHandle = getCraftClass("entity.CraftPlayer").getMethod("getHandle", new Class[0]);
|
||||
playerConnection = getMCClass("EntityPlayer").getDeclaredField("playerConnection");
|
||||
sendPacket = getMCClass("PlayerConnection").getMethod("sendPacket", new Class[] { getMCClass("Packet") });
|
||||
|
||||
getDatawatcher = getMCClass("EntityWither").getMethod("getDataWatcher", new Class[0]);
|
||||
a = getMCClass("DataWatcher").getMethod("a", new Class[] { Integer.TYPE, 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());
|
||||
}
|
||||
Object nms_world = getWorldHandle.invoke(p.getWorld(), new Object[0]);
|
||||
playerWithers.put(p.getName(), entityEntityWither.newInstance(new Object[] { 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());
|
||||
}
|
||||
Object nms_world = getWorldHandle.invoke(p.getWorld(), new Object[0]);
|
||||
playerWithers2.put(p.getName(), entityEntityWither.newInstance(new Object[] { 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, new Object[] { Double.valueOf(getPlayerLoc(p).getX() + xr), Double.valueOf(getPlayerLoc(p).getY()), Double.valueOf(getPlayerLoc(p).getZ() + xr2), Float.valueOf(0.0F), Float.valueOf(0.0F) });
|
||||
setCustomName.invoke(nms_wither, new Object[] { text });
|
||||
setHealth.invoke(nms_wither, new Object[] { Integer.valueOf(300) });
|
||||
setInvisible.invoke(nms_wither, new Object[] { Boolean.valueOf(true) });
|
||||
changeWatcher(nms_wither, text);
|
||||
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(new Object[] { nms_wither });
|
||||
Object nms_player = getPlayerHandle.invoke(p, new Object[0]);
|
||||
Object nms_connection = playerConnection.get(nms_player);
|
||||
sendPacket.invoke(nms_connection, new Object[] { nms_packet });
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Object nms_wither = getWither2(p);
|
||||
setLocation.invoke(nms_wither, new Object[] { Double.valueOf(getPlayerLoc(p).getX() + xr2), Double.valueOf(p.getLocation().getY() - 10.0D), Double.valueOf(getPlayerLoc(p).getZ() + xr), Float.valueOf(0.0F), Float.valueOf(0.0F) });
|
||||
setCustomName.invoke(nms_wither, new Object[] { text });
|
||||
setHealth.invoke(nms_wither, new Object[] { Integer.valueOf(300) });
|
||||
setInvisible.invoke(nms_wither, new Object[] { Boolean.valueOf(true) });
|
||||
changeWatcher(nms_wither, text);
|
||||
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(new Object[] { nms_wither });
|
||||
Object nms_player = getPlayerHandle.invoke(p, new Object[0]);
|
||||
Object nms_connection = playerConnection.get(nms_player);
|
||||
sendPacket.invoke(nms_connection, new Object[] { 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, new Object[] { Double.valueOf(getPlayerLoc(p).getX() + xr), Double.valueOf(getPlayerLoc(p).getY()), Double.valueOf(getPlayerLoc(p).getZ() + xr2), Float.valueOf(0.0F), Float.valueOf(0.0F) });
|
||||
setCustomName.invoke(nms_wither, new Object[] { text });
|
||||
setHealth.invoke(nms_wither, new Object[] { Float.valueOf(vie) });
|
||||
setInvisible.invoke(nms_wither, new Object[] { Boolean.valueOf(true) });
|
||||
changeWatcher(nms_wither, text);
|
||||
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(new Object[] { nms_wither });
|
||||
Object nms_player = getPlayerHandle.invoke(p, new Object[0]);
|
||||
Object nms_connection = playerConnection.get(nms_player);
|
||||
sendPacket.invoke(nms_connection, new Object[] { nms_packet });
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Object nms_wither = getWither2(p);
|
||||
setLocation.invoke(nms_wither, new Object[] { Double.valueOf(getPlayerLoc(p).getX() + xr2), Double.valueOf(p.getLocation().getY() - 10.0D), Double.valueOf(getPlayerLoc(p).getZ() + xr), Float.valueOf(0.0F), Float.valueOf(0.0F) });
|
||||
setCustomName.invoke(nms_wither, new Object[] { text });
|
||||
setHealth.invoke(nms_wither, new Object[] { Float.valueOf(vie) });
|
||||
setInvisible.invoke(nms_wither, new Object[] { Boolean.valueOf(true) });
|
||||
changeWatcher(nms_wither, text);
|
||||
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(new Object[] { nms_wither });
|
||||
Object nms_player = getPlayerHandle.invoke(p, new Object[0]);
|
||||
Object nms_connection = playerConnection.get(nms_player);
|
||||
sendPacket.invoke(nms_connection, new Object[] { 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, new Object[] { Double.valueOf(p.getLocation().getX()), Integer.valueOf(-5000), Double.valueOf(p.getLocation().getZ()), Float.valueOf(0.0F), Float.valueOf(0.0F) });
|
||||
setCustomName.invoke(nms_wither, new Object[] { " " });
|
||||
setHealth.invoke(nms_wither, new Object[] { Integer.valueOf(0) });
|
||||
setInvisible.invoke(nms_wither, new Object[] { Boolean.valueOf(true) });
|
||||
changeWatcher(nms_wither, " ");
|
||||
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(new Object[] { nms_wither });
|
||||
Object nms_player = getPlayerHandle.invoke(p, new Object[0]);
|
||||
Object nms_connection = playerConnection.get(nms_player);
|
||||
sendPacket.invoke(nms_connection, new Object[] { nms_packet });
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public 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, new Object[0]);
|
||||
Map map = (Map)d.get(nms_watcher);
|
||||
map.remove(Integer.valueOf(10));
|
||||
a.invoke(nms_watcher, new Object[] { Integer.valueOf(10), text });
|
||||
}
|
||||
|
||||
private static Class<?> getMCClass(String name) throws ClassNotFoundException
|
||||
{
|
||||
String version = org.bukkit.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 = org.bukkit.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.0F) % 360.0F;
|
||||
if (rotation < 0.0D) {
|
||||
rotation += 360.0D;
|
||||
}
|
||||
if ((0.0D <= rotation) && (rotation < 22.5D))
|
||||
return "N";
|
||||
if ((22.5D <= rotation) && (rotation < 67.5D))
|
||||
return "NE";
|
||||
if ((67.5D <= rotation) && (rotation < 112.5D))
|
||||
return "E";
|
||||
if ((112.5D <= rotation) && (rotation < 157.5D))
|
||||
return "SE";
|
||||
if ((157.5D <= rotation) && (rotation < 202.5D))
|
||||
return "S";
|
||||
if ((202.5D <= rotation) && (rotation < 247.5D))
|
||||
return "SW";
|
||||
if ((247.5D <= rotation) && (rotation < 292.5D))
|
||||
return "W";
|
||||
if ((292.5D <= rotation) && (rotation < 337.5D))
|
||||
return "NW";
|
||||
if ((337.5D <= rotation) && (rotation <= 360.0D)) {
|
||||
return "N";
|
||||
}
|
||||
return "N";
|
||||
}
|
||||
|
||||
public static Location getPlayerLoc(Player p)
|
||||
{
|
||||
Location loc = p.getLocation();
|
||||
String str;
|
||||
switch ((str = getCardinalDirection(p)).hashCode()) { case 69:
|
||||
if (!str.equals("E")) break;
|
||||
break;
|
||||
case 78:
|
||||
case 83:
|
||||
if ((!str.equals("N")) || (goto 284) ||
|
||||
(!str.equals("S"))) break;
|
||||
break;
|
||||
case 87:
|
||||
case 2487:
|
||||
if ((!str.equals("W")) ||
|
||||
(goto 284) ||
|
||||
(!str.equals("NE"))) break;
|
||||
break;
|
||||
case 2505:
|
||||
case 2642:
|
||||
if ((!str.equals("NW")) ||
|
||||
(goto 284) ||
|
||||
(!str.equals("SE"))) break;
|
||||
break;
|
||||
case 2660:
|
||||
if (!str.equals("SW"))
|
||||
{
|
||||
loc.add(0.0D, 0.0D, -50.0D);
|
||||
|
||||
loc.add(50.0D, 0.0D, 0.0D);
|
||||
|
||||
loc.add(0.0D, 0.0D, 50.0D);
|
||||
|
||||
loc.add(-50.0D, 0.0D, 0.0D);
|
||||
|
||||
loc.add(50.0D, 0.0D, -50.0D);
|
||||
|
||||
loc.add(50.0D, 0.0D, 50.0D);
|
||||
|
||||
loc.add(-50.0D, 0.0D, -50.0D);
|
||||
}
|
||||
else {
|
||||
loc.add(-50.0D, 0.0D, 50.0D);
|
||||
}
|
||||
}
|
||||
|
||||
return loc;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,145 @@
|
|||
package de.joethei.core.api.utils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import com.mojang.util.UUIDTypeAdapter;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
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;
|
||||
import java.util.UUID;
|
||||
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
|
||||
|
||||
public class GameProfileBuilder
|
||||
{
|
||||
private HashMap<UUID, CachedProfile> cache = new HashMap<UUID, CachedProfile>();
|
||||
private Gson gson;
|
||||
|
||||
public GameProfileBuilder()
|
||||
{
|
||||
GsonBuilder builder = new GsonBuilder().disableHtmlEscaping();
|
||||
|
||||
builder.registerTypeAdapter(UUID.class, new UUIDTypeAdapter());
|
||||
builder.registerTypeAdapter(GameProfile.class, new GameProfileSerializer());
|
||||
builder.registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer());
|
||||
|
||||
this.gson = builder.create();
|
||||
}
|
||||
|
||||
public GameProfile fetch(UUID uuid) throws Exception {
|
||||
return fetch(uuid, false);
|
||||
}
|
||||
|
||||
public GameProfile fetch(UUID uuid, boolean forceNew) throws Exception {
|
||||
if ((!forceNew) && (this.cache.containsKey(uuid)) && (this.cache.get(uuid).isValid())) {
|
||||
return this.cache.get(uuid).profile;
|
||||
}
|
||||
HttpURLConnection connection = (HttpURLConnection)new URL(String.format("https://sessionserver.mojang.com/session/minecraft/profile/%s?unsigned=false", new Object[] { UUIDTypeAdapter.fromUUID(uuid) })).openConnection();
|
||||
connection.setReadTimeout(5000);
|
||||
|
||||
if (connection.getResponseCode() == 200) {
|
||||
String json = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine();
|
||||
|
||||
GameProfile result = this.gson.fromJson(json, GameProfile.class);
|
||||
this.cache.put(uuid, new CachedProfile(result));
|
||||
return result;
|
||||
}
|
||||
if ((!forceNew) && (this.cache.containsKey(uuid))) {
|
||||
return this.cache.get(uuid).profile;
|
||||
}
|
||||
JsonObject error = (JsonObject)new JsonParser().parse(new BufferedReader(new InputStreamReader(connection.getErrorStream())).readLine());
|
||||
throw new Exception(error.get("error").getAsString() + ": " + error.get("errorMessage").getAsString());
|
||||
}
|
||||
|
||||
public GameProfile getProfile(UUID uuid, String name, String skinUrl)
|
||||
{
|
||||
return getProfile(uuid, name, skinUrl, null);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
public GameProfile getProfile(UUID uuid, String name, String skinUrl, String capeUrl) {
|
||||
GameProfile profile = new GameProfile(uuid, name);
|
||||
boolean cape = (capeUrl != null) && (!capeUrl.isEmpty());
|
||||
|
||||
List<Comparable> args = new ArrayList<Comparable>();
|
||||
args.add(Long.valueOf(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 ? "{\"timestamp\":%d,\"profileId\":\"%s\",\"profileName\":\"%s\",\"isPublic\":true,\"textures\":{\"SKIN\":{\"url\":\"%s\"},\"CAPE\":{\"url\":\"%s\"}}}" : "{\"timestamp\":%d,\"profileId\":\"%s\",\"profileName\":\"%s\",\"isPublic\":true,\"textures\":{\"SKIN\":{\"url\":\"%s\"}}}", args.toArray(new Object[args.size()])))));
|
||||
return profile;
|
||||
}
|
||||
|
||||
private class CachedProfile
|
||||
{
|
||||
private GameProfile profile;
|
||||
private long timestamp;
|
||||
|
||||
public CachedProfile(GameProfile profile)
|
||||
{
|
||||
this.profile = profile;
|
||||
this.timestamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return System.currentTimeMillis() - this.timestamp < 150000L;
|
||||
}
|
||||
}
|
||||
|
||||
private class GameProfileSerializer
|
||||
implements JsonSerializer<GameProfile>, JsonDeserializer<GameProfile>
|
||||
{
|
||||
private GameProfileSerializer()
|
||||
{
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
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);
|
||||
|
||||
PropertyMap properties = object.has("properties") ? (PropertyMap)context.deserialize(object.get("properties"), PropertyMap.class) : null;
|
||||
|
||||
if (properties != null) {
|
||||
for (Map.Entry prop : properties.entries()) {
|
||||
profile.getProperties().put((String)prop.getKey(), (Property)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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,281 @@
|
|||
package de.joethei.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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package de.joethei.core.api.utils;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
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;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package de.joethei.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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,140 @@
|
|||
package de.joethei.core.api.utils;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class Reflection
|
||||
{
|
||||
public static final Class<?> CLASS_CRAFTITEMSTACK = getCraftBukkitClass("inventory.CraftItemStack");
|
||||
public static final Method METHOD_ASNMSCOPY = getMethod(CLASS_CRAFTITEMSTACK, "asNMSCopy");
|
||||
|
||||
public static void sendPacket(Player p, Object packet) {
|
||||
try {
|
||||
Object nmsPlayer = getNMSPlayer(p);
|
||||
Object connection = nmsPlayer.getClass()
|
||||
.getField("playerConnection").get(nmsPlayer);
|
||||
connection.getClass()
|
||||
.getMethod("sendPacket", new Class[] { getNMSClass("Packet") })
|
||||
.invoke(connection, new Object[] { packet });
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static Field getField(Class<?> clazz, String field) {
|
||||
Field re = null;
|
||||
try {
|
||||
re = clazz.getDeclaredField(field);
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return re;
|
||||
}
|
||||
|
||||
public static void sendPacket(Player p, String packetName, Class<?>[] parameterclass, Object[] parameters) {
|
||||
try {
|
||||
Object nmsPlayer = getNMSPlayer(p);
|
||||
Object connection = nmsPlayer.getClass()
|
||||
.getField("playerConnection").get(nmsPlayer);
|
||||
Object packet =
|
||||
Class.forName(
|
||||
nmsPlayer.getClass().getPackage().getName() + "." +
|
||||
packetName)
|
||||
.getConstructor(parameterclass).newInstance(parameters);
|
||||
connection.getClass()
|
||||
.getMethod("sendPacket", new Class[] { getNMSClass("Packet") })
|
||||
.invoke(connection, new Object[] { packet });
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getVersion() {
|
||||
String name = Bukkit.getServer().getClass().getPackage().getName();
|
||||
String version = name.substring(name.lastIndexOf('.') + 1) + ".";
|
||||
return version;
|
||||
}
|
||||
|
||||
public static Class<?> getNMSClass(String className) {
|
||||
String fullName = "net.minecraft.server." + getVersion() + className;
|
||||
Class<?> clazz = null;
|
||||
try {
|
||||
clazz = Class.forName(fullName);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
public static Class<?> getCraftBukkitClass(String className) {
|
||||
String fullName = "org.bukkit.craftbukkit." + getVersion() + className;
|
||||
Class<?> clazz = null;
|
||||
try {
|
||||
clazz = Class.forName(fullName);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public static Object asNMSCopy(ItemStack i) throws IllegalAccessException, InvocationTargetException {
|
||||
Object re = null;
|
||||
try
|
||||
{
|
||||
METHOD_ASNMSCOPY.invoke(null, new Object[] { i });
|
||||
}
|
||||
catch (java.lang.IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return re;
|
||||
}
|
||||
|
||||
public static Field getField(Field f) {
|
||||
f.setAccessible(true);
|
||||
return f;
|
||||
}
|
||||
public static Constructor<?> getConstructor(Class<?> clazz, Class<?>[] param) {
|
||||
Constructor<?> re = null;
|
||||
try {
|
||||
re = clazz.getConstructor(param);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return re;
|
||||
}
|
||||
public static Object getHandle(Entity entity) {
|
||||
Object object = null;
|
||||
try
|
||||
{
|
||||
object = getMethod(entity.getClass(), "getHandle").invoke(entity, new Object[0]);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
public static Object getNMSPlayer(Player player) {
|
||||
return getHandle(player);
|
||||
}
|
||||
|
||||
public static Method getMethod(Class<?> c, String methodName) {
|
||||
Method returnMethod = null;
|
||||
|
||||
for (Method m : c.getDeclaredMethods()) {
|
||||
if (m.getName().equals(methodName)) {
|
||||
returnMethod = m;
|
||||
}
|
||||
}
|
||||
|
||||
return returnMethod;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package de.joethei.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,119 @@
|
|||
package de.joethei.core.api.youtube;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,242 @@
|
|||
package de.joethei.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() + ")";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
package de.joethei.core.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.joethei.core.Core;
|
||||
import de.joethei.core.api.AutoCommand;
|
||||
import de.joethei.core.api.CustomPlayer;
|
||||
import de.joethei.core.api.Messages;
|
||||
import de.joethei.core.api.Perms.Ranks;
|
||||
|
||||
/**
|
||||
* 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());
|
||||
if(p.isAllowed(Ranks.Moderator)) {
|
||||
if(args.length >= 3) {
|
||||
if(Bukkit.getPlayer(args[0]) != null) {
|
||||
CustomPlayer t = CustomPlayer.getPlayer(args[0]);
|
||||
if(getReasons().containsKey(args[1])) {
|
||||
String string = getReasons().get(args[1]);
|
||||
int id = Integer.parseInt(string);
|
||||
|
||||
t.ban(getReasons().get(id), p, getBanDurations().get(id));
|
||||
}else {
|
||||
p.sendMessage(Messages.PREFIX + "§cDieser Grund exsistiert nicht");
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(Messages.PREFIX + "§cDer Spieler " + args[0] + " exsistiert nicht, oder ist nicht online.");
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(Messages.PREFIX + "§cNutze /ban <Spieler> <Grund>");
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.NO_PERMS);
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.NOT_A_PLAYER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
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<Integer, String>();
|
||||
|
||||
map.put(1, "Hacking");
|
||||
map.put(2, "Griefing");
|
||||
map.put(3, "Bugusing");
|
||||
map.put(4, "Beleidigung");
|
||||
map.put(5, "Spam");
|
||||
map.put(6, "Banumgehung");
|
||||
map.put(7, "Werbung");
|
||||
map.put(8, "Trolling");
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ban durations to reason
|
||||
*/
|
||||
private HashMap<Integer, Integer> getBanDurations() {
|
||||
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
|
||||
|
||||
map.put(1, 60);
|
||||
map.put(2, 30);
|
||||
map.put(3, 20);
|
||||
map.put(4, 10);
|
||||
map.put(5, 5);
|
||||
map.put(6, 50);
|
||||
map.put(7, 15);
|
||||
map.put(8, 25);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package de.joethei.core.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.joethei.core.Core;
|
||||
import de.joethei.core.api.AutoCommand;
|
||||
import de.joethei.core.api.Messages;
|
||||
import de.joethei.core.api.CustomPlayer;
|
||||
import de.joethei.core.api.Perms.Ranks;
|
||||
|
||||
/**
|
||||
* lets player build
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Build extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* player who can build
|
||||
*/
|
||||
private static ArrayList<CustomPlayer> players = new ArrayList<CustomPlayer>();
|
||||
|
||||
/**
|
||||
* @return player that can build
|
||||
*/
|
||||
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 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());
|
||||
if(p.isAllowed(Ranks.Builder)) {
|
||||
if(players.contains(p)) {
|
||||
players.remove(p);
|
||||
p.sendMessage("§cDu kannst nun nicht mehr bauen");
|
||||
}else {
|
||||
players.add(p);
|
||||
p.sendMessage("§aDu kannst nun bauen");
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.NO_PERMS);
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.NOT_A_PLAYER);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package de.joethei.core.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.joethei.core.Core;
|
||||
import de.joethei.core.api.AutoCommand;
|
||||
import de.joethei.core.api.Messages;
|
||||
import de.joethei.core.api.CustomPlayer;
|
||||
|
||||
/**
|
||||
* 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());
|
||||
if(args.length == 0) {
|
||||
for(Player player : Bukkit.getOnlinePlayers()) {
|
||||
player.hidePlayer(p);
|
||||
player.showPlayer(p);
|
||||
}
|
||||
p.teleport(p.getLocation());
|
||||
p.sendMessage("§6Du hast dich gefixt");
|
||||
}
|
||||
if(args.length == 1) {
|
||||
if(Bukkit.getPlayer(args[0]) != null) {
|
||||
CustomPlayer t = CustomPlayer.getPlayer(Bukkit.getPlayer(args[0]).getName());
|
||||
if(t != p) {
|
||||
p.hidePlayer(t);
|
||||
p.showPlayer(t);
|
||||
p.teleport(p.getLocation());
|
||||
p.sendMessage("§6Du hast den Spieler " + t.getDisplayName() + " gefixt");
|
||||
t.sendMessage("§6Du wurdest von " + p.getDisplayName() + " gefixt");
|
||||
}else {
|
||||
p.chat("/fix");
|
||||
}
|
||||
}else {
|
||||
p.sendMessage("§cDieser Spieler ist nicht online");
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.NOT_A_PLAYER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
|
||||
for(Player players : Bukkit.getOnlinePlayers()) {
|
||||
list.add(players.getDisplayName());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
package de.joethei.core.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.joethei.core.Core;
|
||||
import de.joethei.core.api.AutoCommand;
|
||||
import de.joethei.core.api.Messages;
|
||||
import de.joethei.core.api.CustomPlayer;
|
||||
import de.joethei.core.api.Perms.Ranks;
|
||||
|
||||
/**
|
||||
* 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());
|
||||
if(p.isAllowed(Ranks.Builder)) {
|
||||
if(args.length == 1) {
|
||||
String mode = args[0];
|
||||
p.setGameMode(getModeFromString(mode));
|
||||
p.sendMessage("§aDein Spielmodus wurde geändert");
|
||||
}else {
|
||||
p.sendMessage("§cNutze /gm <0 | 1 | 2 | 3>");
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(Messages.NO_PERMS);
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.NOT_A_PLAYER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package de.joethei.core.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.joethei.core.Core;
|
||||
import de.joethei.core.api.AutoCommand;
|
||||
import de.joethei.core.api.Messages;
|
||||
import de.joethei.core.api.CustomPlayer;
|
||||
import de.joethei.core.api.Perms.Ranks;
|
||||
import de.joethei.core.api.Settings;
|
||||
|
||||
/**
|
||||
* 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());
|
||||
if(p.isAllowed(Ranks.Moderator)) {
|
||||
if(Settings.isMute()) {
|
||||
Settings.setMute(false);
|
||||
p.sendMessage("§cGlobal Mute deaktiviert");
|
||||
}else {
|
||||
Settings.setMute(true);
|
||||
p.sendMessage("§aGlobal Mute aktiviert");
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(Messages.NO_PERMS);
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.NOT_A_PLAYER);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package de.joethei.core.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.joethei.core.Core;
|
||||
import de.joethei.core.api.AutoCommand;
|
||||
import de.joethei.core.api.Messages;
|
||||
import de.joethei.core.api.CustomPlayer;
|
||||
import de.joethei.core.api.Perms.Ranks;
|
||||
|
||||
/**
|
||||
* 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());
|
||||
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("§2Erfolgreich ausgeführt");
|
||||
return true;
|
||||
}else {
|
||||
String msg = Messages.readString("Messages.Player.NotOnline");
|
||||
msg = msg.replace("$player", args[0]);
|
||||
p.sendMessage(msg);
|
||||
}
|
||||
}else {
|
||||
p.sendMessage("§cDu musst §6/RunAs <Spieler> <Command/Nachricht> §causführen");
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(Messages.NO_PERMS);
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.NOT_A_PLAYER);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
|
||||
for(Player players : Bukkit.getOnlinePlayers()) {
|
||||
list.add(players.getDisplayName());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
package de.joethei.core.commands;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.joethei.core.Core;
|
||||
import de.joethei.core.api.AutoCommand;
|
||||
import de.joethei.core.api.Messages;
|
||||
import de.joethei.core.api.CustomPlayer;
|
||||
import de.joethei.core.api.Perms;
|
||||
import de.joethei.core.api.Perms.Ranks;
|
||||
|
||||
/**
|
||||
* 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.Admin)) {
|
||||
if(args.length == 2) {
|
||||
Ranks rank = Ranks.valueOf(args[1]);
|
||||
if(Bukkit.getPlayer(args[0]) != null) {
|
||||
CustomPlayer player = CustomPlayer.getPlayer(Bukkit.getPlayer(args[0]).getName());
|
||||
if(rank != null) {
|
||||
try {
|
||||
Perms.setRank(player, rank);
|
||||
p.sendMessage("§aDer Rang wurde erfolgreich gesetzt");
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(Messages.readString("Messages.UnknownError"));
|
||||
}
|
||||
}else {
|
||||
p.sendMessage("§cDen Rang gibt es nicht");
|
||||
}
|
||||
}else {
|
||||
String msg = Messages.readString("Messages.Player.NotOnline");
|
||||
msg = msg.replace("$player", args[0]);
|
||||
p.sendMessage(msg);
|
||||
}
|
||||
}else {
|
||||
p.sendMessage("§cNutze §6/setRank <Spieler> <Rang>");
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(Messages.NO_PERMS);
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.NOT_A_PLAYER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
|
||||
for(Player players : Bukkit.getOnlinePlayers()) {
|
||||
list.add(players.getDisplayName());
|
||||
}
|
||||
|
||||
list.add("Admin");
|
||||
list.add("Developer");
|
||||
list.add("HeadBuild");
|
||||
list.add("Builder");
|
||||
list.add("Moderator");
|
||||
list.add("Supporter");
|
||||
list.add("Youtuber");
|
||||
list.add("Premium");
|
||||
list.add("Spieler");
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package de.joethei.core.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.joethei.core.Core;
|
||||
import de.joethei.core.api.AutoCommand;
|
||||
import de.joethei.core.api.Messages;
|
||||
import de.joethei.core.api.CustomPlayer;
|
||||
import de.joethei.core.api.Perms.Ranks;
|
||||
|
||||
/**
|
||||
* 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());
|
||||
if(p.isAllowed(Ranks.Admin)) {
|
||||
Runtime run = Runtime.getRuntime();
|
||||
p.sendMessage("§6§l===SystemInfo <SpigotServer>===");
|
||||
p.sendMessage("§6Spigot Version: " + Bukkit.getVersion());
|
||||
p.sendMessage("§6Genutzter Arbeitsspeicher: " + (run.totalMemory() - run.freeMemory() / 1048576L) + " MB");
|
||||
p.sendMessage("§6Freier Arbeitsspeicher: " + run.freeMemory() / 1048576L + " MB");
|
||||
p.sendMessage("§6Gesamter Arbeitsspeicher: " + run.maxMemory() / 1048576L + " MB");
|
||||
p.sendMessage("§6Verfügbare Prozessoren: " + run.availableProcessors());
|
||||
p.sendMessage("§6Betriebssystem: " + System.getProperty("os.name"));
|
||||
p.sendMessage("§6Betriebsystem Version: " + System.getProperty("os.version"));
|
||||
p.sendMessage("§6Betriebssystem Architektur: " + System.getProperty("os.arch"));
|
||||
}else {
|
||||
p.sendMessage(Messages.NO_PERMS);
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.NOT_A_PLAYER);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package de.joethei.core.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.joethei.core.Core;
|
||||
import de.joethei.core.api.AutoCommand;
|
||||
import de.joethei.core.api.CustomPlayer;
|
||||
import de.joethei.core.api.Messages;
|
||||
import de.joethei.core.api.twitch.Twitch_API;
|
||||
import de.joethei.core.api.twitch.Twitch_Stream;
|
||||
|
||||
/**
|
||||
* 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());
|
||||
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(Messages.PREFIX + "§aDen Benutzer gibt es nicht");
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(Messages.PREFIX + "§cNutze /twitch <Name>");
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.NOT_A_PLAYER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package de.joethei.core.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.joethei.core.Core;
|
||||
import de.joethei.core.api.AutoCommand;
|
||||
import de.joethei.core.api.Messages;
|
||||
import de.joethei.core.api.CustomPlayer;
|
||||
import de.joethei.core.api.Perms.Ranks;
|
||||
|
||||
/**
|
||||
* 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());
|
||||
if(p.isAllowed(Ranks.Moderator)) {
|
||||
if(players.contains(p)) {
|
||||
for(Player players : Bukkit.getOnlinePlayers()) {
|
||||
players.showPlayer(p);
|
||||
}
|
||||
players.remove(p);
|
||||
p.sendMessage("§cDu bist nun wieder sichtbar");
|
||||
}else {
|
||||
for(Player players : Bukkit.getOnlinePlayers()) {
|
||||
players.hidePlayer(p);
|
||||
}
|
||||
players.add(p);
|
||||
p.sendMessage("Du bist nun unsichtbar");
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(Messages.NO_PERMS);
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.NOT_A_PLAYER);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package de.joethei.core.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.joethei.core.Core;
|
||||
import de.joethei.core.api.AutoCommand;
|
||||
import de.joethei.core.api.CustomPlayer;
|
||||
import de.joethei.core.api.Messages;
|
||||
import de.joethei.core.api.youtube.YTAPI;
|
||||
import de.joethei.core.api.youtube.YoutubeChannel;
|
||||
|
||||
/**
|
||||
* 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());
|
||||
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(Messages.PREFIX + "§cDer Youtube Kanal exsistiert nicht");
|
||||
}
|
||||
}else {
|
||||
p.sendMessage(Messages.PREFIX + "§cBenutze doch /youtuber <Channel Name>");
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Messages.NOT_A_PLAYER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package de.joethei.core.listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
import de.joethei.core.api.CustomPlayer;
|
||||
import de.joethei.core.api.Settings;
|
||||
import de.joethei.core.commands.Build;
|
||||
|
||||
/**
|
||||
* cancels building
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Blocks implements Listener{
|
||||
|
||||
/**
|
||||
* @param e BlockPlaceEvent
|
||||
*/
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer().getName());
|
||||
if(Settings.isBuild()) {
|
||||
if(!Build.getPlayers().contains(p)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param e BlockBreakEvent
|
||||
*/
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer().getName());
|
||||
if(Settings.isBuild()) {
|
||||
if(!Build.getPlayers().contains(p)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package de.joethei.core.listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
import de.joethei.core.api.CustomPlayer;
|
||||
import de.joethei.core.api.Settings;
|
||||
import de.joethei.core.api.Perms.Ranks;
|
||||
|
||||
/**
|
||||
* 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());
|
||||
if(Settings.isMute()) {
|
||||
if(!p.isAllowed(Ranks.Supporter)) {
|
||||
e.setCancelled(true);
|
||||
p.sendMessage("§cMomentan ist dieser Server gemutet");
|
||||
}
|
||||
}
|
||||
if(!p.isMuted()) {
|
||||
String msg = p.getPrefix() + p.getDisplayName() + p.getSuffix() + e.getMessage();
|
||||
e.setFormat(msg);
|
||||
}else {
|
||||
p.sendMessage("§cDu wurdest leider vom Chat ausgeschlossen");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
package de.joethei.core.listeners;
|
||||
|
||||
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;
|
||||
|
||||
import de.joethei.core.Core;
|
||||
import de.joethei.core.api.Messages;
|
||||
import de.joethei.core.api.CustomPlayer;
|
||||
import de.joethei.core.api.Perms.Ranks;
|
||||
|
||||
/**
|
||||
* commands
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Commands implements Listener{
|
||||
|
||||
|
||||
/**
|
||||
* prints unknown command message
|
||||
* @param e PlayerCommandPreprocessEvent
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerPreprocess(PlayerCommandPreprocessEvent e) {
|
||||
if(!(e.isCancelled())) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer().getName());
|
||||
String cmd = e.getMessage().split(" ")[0];
|
||||
HelpTopic topic = Bukkit.getServer().getHelpMap().getHelpTopic(cmd);
|
||||
if(topic == null) {
|
||||
String msg = Messages.readString("Commands.Unknown");
|
||||
msg = msg.replace("$cmd", cmd);
|
||||
p.sendMessage(msg);
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* custom reload
|
||||
* @param e PlayerPreprocessEvent
|
||||
*/
|
||||
@EventHandler
|
||||
public void onReload(PlayerCommandPreprocessEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer().getName());
|
||||
String cmd = e.getMessage();
|
||||
if(cmd.equalsIgnoreCase("/rl") || cmd.equalsIgnoreCase("/reload")) {
|
||||
if(p.isAllowed(Ranks.Admin)) {
|
||||
e.setCancelled(true);
|
||||
Bukkit.broadcastMessage("§cAchtung der Server wird gleich neu geladen");
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Core.getInstance(), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for(Player players : Bukkit.getOnlinePlayers()) {
|
||||
players.kickPlayer("§cServer wurde neu geladen \n §6Bitte joine doch neu unter \n §bplay§5.§6univento§5.§aeu");
|
||||
}
|
||||
Bukkit.reload();
|
||||
}
|
||||
|
||||
}, 100L);
|
||||
}else {
|
||||
p.sendMessage(Messages.NO_PERMS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
package de.joethei.core.listeners;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
||||
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.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import de.joethei.core.Core;
|
||||
import de.joethei.core.api.CustomPlayer;
|
||||
import de.joethei.core.api.MySQL;
|
||||
import de.joethei.core.api.NickName;
|
||||
import de.joethei.core.api.Perms;
|
||||
import de.joethei.core.api.Perms.Ranks;
|
||||
import de.joethei.core.commands.Vanish;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class JoinQuit implements Listener{
|
||||
|
||||
/**
|
||||
* Handles JoinMessage and vanished players
|
||||
* @param e event
|
||||
*/
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer().getName());
|
||||
e.setJoinMessage(null);
|
||||
createPlayer(p);
|
||||
Perms.getRanks().put(p, p.getRankFresh());
|
||||
try {
|
||||
setup(p, p.getRank());
|
||||
} catch (SQLException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
for(Player players : Bukkit.getOnlinePlayers()) {
|
||||
if(Vanish.getPlayers().contains(players)) {
|
||||
p.hidePlayer(players);
|
||||
}
|
||||
}
|
||||
if(p.isNicked()) {
|
||||
p.setDisplayName(p.getNick());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles QuitMessage and other needed stuff
|
||||
* @param e event
|
||||
*/
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer().getName());
|
||||
NickName.remove(p);
|
||||
Perms.getRanks().remove(p);
|
||||
p.onLeave();
|
||||
e.setQuitMessage(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* creates player in database
|
||||
* @param p CustomPlayer
|
||||
*/
|
||||
private static void createPlayer(CustomPlayer p) {
|
||||
Date date = new Date();
|
||||
Timestamp time = new Timestamp(date.getTime());
|
||||
String uuid = p.getUniqueId().toString();
|
||||
try {
|
||||
MySQL sql = Core.returnSQL();
|
||||
sql.openConnection();
|
||||
ResultSet res = Core.returnSQL().getConnection().createStatement().executeQuery("SELECT player_uuid FROM PlayerData WHERE player_uuid ='" + uuid + "';");
|
||||
if (!res.next())
|
||||
Core.returnSQL().getConnection().createStatement().execute("INSERT INTO PlayerData (player_uuid, FirstJoin, Coins, mute, Rank, nick, FastMenu, teleport) VALUES ('" + uuid + "','" + time + "', '0', '0', '" + Perms.Ranks.Spieler.toString() + "', '0', '0', '1');");
|
||||
sql.closeConnection();
|
||||
}
|
||||
catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sets up the player
|
||||
* @param p CustomPlayer
|
||||
* @param r Ranks
|
||||
* @throws SQLException Database not available
|
||||
*/
|
||||
private void setup(CustomPlayer p, Ranks r) throws SQLException {
|
||||
if (p.isNicked()) {
|
||||
Core.nicks.put(p, NickName.getNicks());
|
||||
setName(p, Core.nicks.get(p));
|
||||
} else {
|
||||
setName(p, p.getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sets DisplayName of Player
|
||||
* @param p CustomPlayer
|
||||
* @param name name to set
|
||||
*/
|
||||
private void setName(CustomPlayer p, String name) {
|
||||
p.setDisplayName(name);
|
||||
p.setPlayerListName(p.getColor() + name);
|
||||
}
|
||||
/**
|
||||
* Handles KickMessage
|
||||
* @param e event
|
||||
*/
|
||||
@EventHandler(priority=EventPriority.HIGHEST)
|
||||
public void onKick(PlayerKickEvent e) {
|
||||
e.setLeaveMessage(null);
|
||||
NickName.remove(e.getPlayer());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
main: de.joethei.core.Core
|
||||
name: Core
|
||||
description: univento Core
|
||||
author: joethei
|
||||
version: 0.1
|
||||
website: http://univento.eu
|
Loading…
Reference in New Issue