first commit

This commit is contained in:
Johannes Theiner 2016-02-27 09:08:17 +01:00
parent 99564aaa64
commit db66d45170
81 changed files with 6365 additions and 2916 deletions

View File

@ -1,8 +0,0 @@
<?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="lib" path="F:/Sources/Jars/teamspeak3-api-1.0.12.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -1,10 +0,0 @@
stages:
- build
- test
- deploy
job1:
stage: build
script:
- find -name "*.java" > sources.txt
- javac bin @sources.txt

View File

@ -1,17 +0,0 @@
<?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>

View File

@ -2,4 +2,4 @@ Core Plugin for univento.eu
Written by joethei
API Doku at: http://joethei.de/javadocs/Core
API Doku can be found at: http://dev.univento.eu/docs/Core

View File

@ -0,0 +1,33 @@
package eu.univento.cloud.client;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
/**
* @author joethei
* @version 0.1
*/
public class CloudClient {
public CloudClient() throws Exception{
NioEventLoopGroup child = new NioEventLoopGroup();
try{
Bootstrap bootstrap = new Bootstrap();
bootstrap.channel(NioSocketChannel.class);
bootstrap.group(child);
bootstrap.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel channel) throws Exception {
}
});
bootstrap.connect("master.univento.eu", 8000).sync().channel().closeFuture().sync();
}finally {
child.shutdownGracefully();
}
}
}

View File

@ -1,36 +1,23 @@
package eu.univento.core;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import eu.univento.core.api.BossBar;
import eu.univento.core.api.Config;
import eu.univento.core.api.SignInput;
import eu.univento.core.api.database.MySQL;
import eu.univento.core.api.events.MoveEventFilter;
import eu.univento.core.api.fakeplayer.PlayerKi;
import eu.univento.core.api.player.TeamSpeak;
import eu.univento.core.api.server.ServerSettings;
import eu.univento.core.commands.*;
import eu.univento.core.listeners.*;
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import eu.univento.core.api.Config;
import eu.univento.core.api.Messages;
import eu.univento.core.api.MySQL;
import eu.univento.core.api.Settings;
import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.player.Perms;
import eu.univento.core.commands.Ban;
import eu.univento.core.commands.Build;
import eu.univento.core.commands.Fix;
import eu.univento.core.commands.GameMode;
import eu.univento.core.commands.GlobalMute;
import eu.univento.core.commands.RunAs;
import eu.univento.core.commands.SetRank;
import eu.univento.core.commands.SystemInfo;
import eu.univento.core.commands.TS;
import eu.univento.core.commands.Vanish;
import eu.univento.core.commands.Youtuber;
import eu.univento.core.listeners.Blocks;
import eu.univento.core.listeners.Chat;
import eu.univento.core.listeners.Commands;
import eu.univento.core.listeners.JoinQuit;
import java.io.IOException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* main class
@ -38,6 +25,8 @@ import eu.univento.core.listeners.JoinQuit;
* @version 1.0
*/
public class Core extends JavaPlugin{
//TODO: rewrite time critical database functions from MySQL to MongoDB
/**
* plugin instance
@ -60,12 +49,12 @@ public class Core extends JavaPlugin{
public static MySQL returnSQL() {
return sql;
}
/**
* nick names of players
*/
public static HashMap<CustomPlayer, String> nicks = new HashMap<CustomPlayer, String>();
private static TeamSpeak ts;
public static TeamSpeak getTs() {
return ts;
}
/**
* logging and stuff
*/
@ -76,40 +65,51 @@ public class Core extends JavaPlugin{
* @param string String
*/
public static void log(Level level, String string) {
log.log(level, "[" + Messages.CONSOLE_PREFIX + Core.getInstance().getDescription().getName() + "] " + string);
if(ServerSettings.isDebug()) {
log.log(level, "[Core] " + string);
}
}
private SignInput signInput;
public SignInput getSignInput() {
return signInput;
}
@Override
public void onEnable() {
Settings.setDebug(true);
Settings.setBuild(true);
ServerSettings.setDebug(true);
try {
Config.writeDefault();
} catch (ClassNotFoundException | SQLException | IOException e) {
e.printStackTrace();
}
instance = this;
if(Settings.isDebug()) log(Level.INFO, "Debug Modus aktiviert");
Perms.initScoreboard();
this.signInput = new SignInput(this);
if(ServerSettings.isDebug()) log(Level.INFO, "Debug Modus aktiviert");
PluginManager pm = Bukkit.getPluginManager();
pm.registerEvents(new Commands(), this);
pm.registerEvents(new JoinQuit(), this);
pm.registerEvents(new Chat(), this);
pm.registerEvents(new Blocks(), this);
pm.registerEvents(new Events(), this);
pm.registerEvents(new MoveEventFilter(getServer()), this);
pm.registerEvents(new BossBar(), this);
pm.registerEvents(new PlayerKi(), this);
if(Settings.isDebug()) log(Level.INFO, "Events registriert");
log(Level.INFO, "Events registriert");
String[] fix = {""};
new Fix(this, "fix", "Fixe dich oder andere Spieler", fix);
if(ServerSettings.isGame()) new Fix(this, "fix", "Fixe dich oder andere Spieler", fix);
String[] runas = {""};
new RunAs(this, "RunAs", "Sende einen Befehl als ein anderer Spieler", runas);
String[] systeminfo = {""};
new SystemInfo(this, "SystemInfo", "Gibt Infos über den Server aus", systeminfo);
new SystemInfo(this, "SystemInfo", "Gibt Infos über den ServerPinger aus", systeminfo);
String[] vanish = {""};
new Vanish(this, "vanish", "Lässt dich verschwinden", vanish);
new Vanish(this, "vanish", "Lässt dich verschwinden", vanish);
String[] gamemode = {"gm"};
new GameMode(this, "gamemode" , "Setzt deinen GameMode", gamemode);
@ -118,7 +118,7 @@ public class Core extends JavaPlugin{
new SetRank(this, "setrank" , "Setzt den Rang eines Spielers", setrank);
String[] globalmute = {"globalmute"};
new GlobalMute(this, "globalmute", "Muted den gesamten Server", globalmute);
new GlobalMute(this, "globalmute", "Muted den gesamten ServerPinger", globalmute);
String[] youtuber = {""};
new Youtuber(this, "youtuber", "setzt Spieler in den Youtuber Rang", youtuber);
@ -129,51 +129,31 @@ public class Core extends JavaPlugin{
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");
String[] build = {"b"};
new Build(this, "build", "Setzt den Spieler in den Bau Modus", build);
String[] chatclear = {"cc"};
new ChatClear(this, "chatclear", "Cleart den Chat", chatclear);
if(ServerSettings.isGame()) {
String[] nick = {""};
new Nick(this, "nick", "ändert das Verhalten des Nicksystems", nick);
log(Level.INFO, "/nick aktiviert");
}
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(15),TS_ID bigint, Friends varchar(2500), nick 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();
}
log(Level.INFO, "Alle Befehle registriert");
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
try {
Messages.writeDefault();
Messages.readStrings();
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
this.ts = new TeamSpeak();
log(Level.INFO, "Plugin ver. " + getDescription().getVersion() + " gestartet");
}
@Override
public void onDisable() {
Core.log(Level.INFO, "Plugin beendet");
log(Level.INFO, "Plugin beendet");
getTs().disconnect();
}
}

View File

@ -1,38 +1,18 @@
package eu.univento.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;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
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);
}
}
public static void send(Player player, String message){
CraftPlayer p = (CraftPlayer) player;
IChatBaseComponent cbc = ChatSerializer.a("{\"text\": \"" + message + "\"}");
PacketPlayOutChat ppoc = new PacketPlayOutChat(cbc,(byte) 2);
((CraftPlayer) p).getHandle().playerConnection.sendPacket(ppoc);
}
}

View File

@ -1,21 +1,22 @@
package eu.univento.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;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
/**
* @author PostCrafter
* @see href http://postcrafter.de/viewtopic.php?f=15&t=143
* @param <P> main class
*/
public abstract class AutoCommand<P extends JavaPlugin> extends Command {
/**
* @author PostCrafter
* @see http://postcrafter.de/viewtopic.php?f=15&t=143
*/
private static String VERSION;
static {

View File

@ -1,14 +1,20 @@
package eu.univento.core.api;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
/**
*
* @author janhektor
*
*/
public class Blackscreen
{
private static Object packetObject;

View File

@ -1,8 +1,8 @@
package eu.univento.core.api;
import java.util.HashMap;
import java.util.Map;
import eu.univento.core.Core;
import eu.univento.core.api.utils.FDragon;
import eu.univento.core.api.utils.FWither;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -12,9 +12,8 @@ import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import eu.univento.core.Core;
import eu.univento.core.api.utils.FDragon;
import eu.univento.core.api.utils.FWither;
import java.util.HashMap;
import java.util.Map;
/**
@ -30,15 +29,15 @@ public class BossBar implements Listener {
public static Plugin plugin;
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> playerdragonbartask = new HashMap<>();
public static Map<Player, Float> healthdragonbartask = new HashMap<>();
public static Map<Player, Integer> cooldownsdragonbar= new HashMap<>();
public static Map<Player, Integer> starttimerdragonbar= new HashMap<>();
public static Map<Player, String> playerwitherbartask = new HashMap<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 Map<Player, String> playerwitherbartask = new HashMap<>();
public static Map<Player, Float> healthwitherbartask = new HashMap<>();
public static Map<Player, Integer> cooldownswitherbar= new HashMap<>();
public static Map<Player, Integer> starttimerwitherbar= new HashMap<>();
public void DragonBarTask() {
@ -65,7 +64,7 @@ public class BossBar implements Listener {
}
}
}.runTaskTimer(Core.getInstance(), 0, 40);
}.runTaskTimer(Core.getInstance(), 0, 40);

View File

@ -1,14 +1,14 @@
package eu.univento.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;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
/**
* gets data from config file
* @author joethei
@ -16,7 +16,9 @@ import org.bukkit.configuration.file.YamlConfiguration;
*/
public class Config {
/**config file*/
private static File file = new File("plugins/Core", "config.yml");
/**load configuration */
private static FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
/**

View File

@ -1,13 +1,14 @@
package eu.univento.core.api;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
public class Hologram
{

View File

@ -1,123 +0,0 @@
package eu.univento.core.api;
import java.sql.ResultSet;
import java.sql.SQLException;
import eu.univento.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;
public static String COMMAND_NOT_FOUND;
/**
* 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();
if(!isInDatabase("Prefix")) writeData("INSERT INTO Messages(Ident, Message) values ('Prefix', '§aunivento §8»');");
if(!isInDatabase("ConsolePrefix")) writeData("INSERT INTO Messages(Ident, Message) values ('ConsolePrefix', '[univento Core]');");
if(!isInDatabase("UnknownError")) writeData("INSERT INTO Messages(Ident, Message) values ('UnknownError', '§cEs ist leider ein unbekannter Fehler aufgetreten');");
if(!isInDatabase("Commands.NoPlayer")) writeData("INSERT INTO Messages(Ident, Message) values ('Commands.NoPlayer', '§cDu bist leider kein Spieler');");
if(!isInDatabase("Commands.NoPerms")) writeData("INSERT INTO Messages(Ident, Message) values ('Commands.NoPerms', '§cDu hast keine Berechtigungen diesen Befehl auszuführen')");
if(!isInDatabase("Commands.Error")) writeData("INSERT INTO Messages(Ident, Message) values ('Commands.Error', '§cBeim ausführen dieses Befehls ist ein Fehler aufgetreten');");
if(!isInDatabase("Commands.NotOnline")) writeData("INSERT INTO Messages(Ident, Message) values ('Commands.NotOnline', '§cDer Spieler $player ist nicht online');");
if(!isInDatabase("Commands.Unknown")) writeData("INSERT INTO Messages(Ident, Message) values ('Commands.Unknown', '§6Dieser Befehl konnte leider nicht gefunden werden');");
if(!isInDatabase("Kick.Restart")) writeData("INSERT INTO Messages(Ident, Message) values ('Kick.Restart', '§cDer Server startet gerade neu');");
if(!isInDatabase("Kick.Full")) writeData("INSERT INTO Messages(Ident, Message) values ('Kick.Full', '§cDer Server ist leider schon voll')");
sql.closeConnection();
}
private static void writeData(String data) {
MySQL sql = Core.returnSQL();
try {
sql.openConnection();
sql.getConnection().createStatement().execute(data);
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
}
/**
* checks if message is in database
* @param ident identifier of message
* @return true/false
*/
private static boolean isInDatabase(String ident) {
MySQL sql = Core.returnSQL();
try {
sql.openConnection();
ResultSet rs = sql.getConnection().createStatement().executeQuery("SELECT * FROM Messages WHERE Ident='" + ident + "';");
if (!rs.next()) {
sql.closeConnection();
return false;
}
sql.closeConnection();
return true;
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
return false;
}
}
/**
* 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 = PREFIX + readString("UnknownError");
NOT_A_PLAYER = readString("Commands.NoPlayer") ;
NO_PERMS = PREFIX + readString("Commands.NoPerms");
ERROR = PREFIX + readString("Commands.Error");
NOT_ONLINE = PREFIX + readString("Commands.NotOnline");
KICK_RESTART = readString("Kick.Restart");
KICK_FULL = readString("Kick.Full");
COMMAND_NOT_FOUND = PREFIX + readString("Commands.Unkown");
}
/**
* 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;
}
String message = rs.getString("Message");
sql.closeConnection();
return message;
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
return null;
}
}
}

View File

@ -1,364 +0,0 @@
package eu.univento.core.api;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.*;
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.inventory.ItemStack;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.v1_8_R3.*;
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.WorldSettings.EnumGamemode;
/**
* @author Summerfeeling
*/
public class NPC {
private DataWatcher watcher;
private Material chestplate;
private Material leggings;
private Location location;
private Material inHand;
private Material helmet;
private Material boots;
private String tablist;
private int entityID;
private String name;
private UUID uuid;
/*
* NPC, a class for spawning fake players in the 1.8 Copyright (C)
* [Summerfeeling] Dieses Programm ist freie Software. Sie können es unter
* den Bedingungen der GNU General Public License, wie von der Free Software
* Foundation veröffentlicht, weitergeben und/oder modifizieren, entweder
* gemäß Version 3 der Lizenz oder (nach Ihrer Option) jeder späteren
* Version. Die Veröffentlichung dieses Programms erfolgt in der Hoffnung,
* daß es Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE, sogar
* ohne die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR
* EINEN BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public
* License. Sie sollten ein Exemplar der GNU General Public License zusammen
* mit diesem Programm erhalten haben. Falls nicht, siehe
* <http://www.gnu.org/licenses/>.
*/
public NPC(String name, String tablist, UUID uuid, int entityID, Location location, Material inHand) {
this.location = location;
this.tablist = tablist;
this.name = name;
this.uuid = uuid;
this.entityID = entityID;
this.inHand = inHand;
this.watcher = new DataWatcher(null);
watcher.a(6, (float) 20);
}
public NPC(String name, Location location) {
this(name, name, UUID.randomUUID(), new Random().nextInt(10000), location, Material.AIR);
}
public NPC(String name, Location location, Material inHand) {
this(name, name, UUID.randomUUID(), new Random().nextInt(10000), location, inHand);
}
public NPC(String name, String tablist, Location location) {
this(name, tablist, UUID.randomUUID(), new Random().nextInt(10000), location, Material.AIR);
}
public NPC(String name, String tablist, Location location, Material inHand) {
this(name, tablist, UUID.randomUUID(), new Random().nextInt(10000), location, inHand);
}
@SuppressWarnings("deprecation")
public void spawn() {
try {
PacketPlayOutNamedEntitySpawn packet = new PacketPlayOutNamedEntitySpawn();
this.addToTablist();
this.setValue(packet, "a", this.entityID);
this.setValue(packet, "b", this.uuid);
this.setValue(packet, "c", this.toFixedPoint(this.location.getX()));
this.setValue(packet, "d", this.toFixedPoint(this.location.getY()));
this.setValue(packet, "e", this.toFixedPoint(this.location.getZ()));
this.setValue(packet, "f", this.toPackedByte(this.location.getYaw()));
this.setValue(packet, "g", this.toPackedByte(this.location.getPitch()));
this.setValue(packet, "h", this.inHand == null ? 0 : this.inHand.getId());
this.setValue(packet, "i", this.watcher);
for (Player online : Bukkit.getOnlinePlayers()) {
((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@SuppressWarnings("deprecation")
public void despawn() {
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(new int[] { this.entityID });
this.removeFromTablist();
for (Player online : Bukkit.getOnlinePlayers()) {
((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet);
}
}
@SuppressWarnings("deprecation")
public void changePlayerlistName(String name) {
try {
PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo();
PlayerInfoData data = new PlayerInfoData(packet, new GameProfile(this.uuid, this.name), 0,
EnumGamemode.NOT_SET, CraftChatMessage.fromString(name)[0]);
@SuppressWarnings("unchecked")
List<PlayerInfoData> players = (List<PlayerInfoData>) this.getValue(packet, "b");
players.add(data);
this.setValue(packet, "a", EnumPlayerInfoAction.UPDATE_DISPLAY_NAME);
this.setValue(packet, "b", players);
this.tablist = name;
for (Player online : Bukkit.getOnlinePlayers()) {
((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@SuppressWarnings("deprecation")
private void addToTablist() {
try {
PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo();
PlayerInfoData data = new PlayerInfoData(packet, new GameProfile(this.uuid, this.name), 0,
EnumGamemode.NOT_SET, CraftChatMessage.fromString(this.tablist)[0]);
@SuppressWarnings("unchecked")
List<PlayerInfoData> players = (List<PlayerInfoData>) this.getValue(packet, "b");
players.add(data);
this.setValue(packet, "a", EnumPlayerInfoAction.ADD_PLAYER);
this.setValue(packet, "b", players);
for (Player online : Bukkit.getOnlinePlayers()) {
((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@SuppressWarnings("deprecation")
private void removeFromTablist() {
try {
PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo();
PlayerInfoData data = new PlayerInfoData(packet, new GameProfile(this.uuid, this.name), 0,
EnumGamemode.NOT_SET, CraftChatMessage.fromString(this.tablist)[0]);
@SuppressWarnings("unchecked")
List<PlayerInfoData> players = (List<PlayerInfoData>) this.getValue(packet, "b");
players.add(data);
this.setValue(packet, "a", EnumPlayerInfoAction.REMOVE_PLAYER);
this.setValue(packet, "b", players);
for (Player online : Bukkit.getOnlinePlayers()) {
((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@SuppressWarnings("deprecation")
public void teleport(Location location) {
try {
PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport();
this.setValue(packet, "a", this.entityID);
this.setValue(packet, "b", this.toFixedPoint(location.getX()));
this.setValue(packet, "c", this.toFixedPoint(location.getY()));
this.setValue(packet, "d", this.toFixedPoint(location.getZ()));
this.setValue(packet, "e", this.toPackedByte(location.getYaw()));
this.setValue(packet, "f", this.toPackedByte(location.getPitch()));
this.setValue(packet, "g", this.location.getBlock().getType() == Material.AIR ? false : true);
this.location = location;
for (Player online : Bukkit.getOnlinePlayers()) {
((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@SuppressWarnings("deprecation")
public void setItemInHand(Material material) {
try {
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment();
this.setValue(packet, "a", this.entityID);
this.setValue(packet, "b", 0);
this.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;
}
@SuppressWarnings("deprecation")
public void setHelmet(Material material) {
try {
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment();
this.setValue(packet, "a", this.entityID);
this.setValue(packet, "b", 4);
this.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;
}
@SuppressWarnings("deprecation")
public void setChestplate(Material material) {
try {
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment();
this.setValue(packet, "a", this.entityID);
this.setValue(packet, "b", 3);
this.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;
}
@SuppressWarnings("deprecation")
public void setLeggings(Material material) {
try {
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment();
this.setValue(packet, "a", this.entityID);
this.setValue(packet, "b", 2);
this.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;
}
@SuppressWarnings("deprecation")
public void setBoots(Material material) {
try {
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment();
this.setValue(packet, "a", this.entityID);
this.setValue(packet, "b", 1);
this.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.uuid;
}
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.0);
}
private byte toPackedByte(float f) {
return (byte) ((int) (f * 256.0F / 360.0F));
}
}

View File

@ -1,98 +0,0 @@
package eu.univento.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;
}
}

View File

@ -1,109 +0,0 @@
package eu.univento.core.api;
import com.google.common.collect.Iterables;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import eu.univento.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;
}
}

View File

@ -1,67 +0,0 @@
package eu.univento.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;
}
}