bugfixes, added more functions to CustomPlayer

This commit is contained in:
Johannes Theiner 2015-12-06 20:23:13 +01:00
parent 007d1a7671
commit 99564aaa64
34 changed files with 1607 additions and 2269 deletions

View File

@ -11,11 +11,11 @@ import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import eu.univento.core.api.Config; import eu.univento.core.api.Config;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.MySQL; import eu.univento.core.api.MySQL;
import eu.univento.core.api.Perms;
import eu.univento.core.api.Settings; 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.Ban;
import eu.univento.core.commands.Build; import eu.univento.core.commands.Build;
import eu.univento.core.commands.Fix; import eu.univento.core.commands.Fix;
@ -142,7 +142,7 @@ public class Core extends JavaPlugin{
MySQL tempSQL = sql; MySQL tempSQL = sql;
tempSQL.openConnection(); 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, FastMenu boolean, teleport boolean);"); 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"); 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));"); 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));");

View File

@ -2,89 +2,301 @@ package eu.univento.core.api;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import eu.univento.core.api.utils.FakeDragon; import eu.univento.core.Core;
import eu.univento.core.api.utils.FakeWither; import eu.univento.core.api.utils.FDragon;
import eu.univento.core.api.utils.FWither;
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>(); * Thanks for chasechocolate and BigTeddy98 for the tutorial
public static Map<Player, Integer> cooldownswitherbar = new HashMap<Player, Integer>(); * it is based on the code by them and some other tutorial
public static Map<Player, Integer> starttimerwitherbar = new HashMap<Player, Integer>(); * https://forums.bukkit.org/threads/util-set-a-players-boss-bar-nms.245073/
* https://forums.bukkit.org/threads/tutorial-utilizing-the-boss-health-bar.158018/
* @author Marzouki Ghofrane , mgone CraftZone.fr
*/
public static void setBarDragon(Player p, String text) {
playerdragonbartask.put(p, text); public class BossBar implements Listener {
FakeDragon.setBossBartext(p, text);
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> 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 void DragonBarTask() {
new BukkitRunnable() {
@SuppressWarnings("deprecation")
@Override
public void run() {
for(Player p : plugin.getServer().getOnlinePlayers()){
if(!cooldownsdragonbar.containsKey(p)) {
if(playerdragonbartask.containsKey(p) && !healthdragonbartask.containsKey(p)) { setBarDragon(p, playerdragonbartask.get(p)); }
else if(playerdragonbartask.containsKey(p) && healthdragonbartask.containsKey(p)) { setBarDragonHealth(p, playerdragonbartask.get(p), healthdragonbartask.get(p)); }
}
if(!cooldownswitherbar.containsKey(p)) {
if(playerwitherbartask.containsKey(p) && !healthwitherbartask.containsKey(p)) { setBarWither(p, playerwitherbartask.get(p)); }
else if(playerwitherbartask.containsKey(p) && healthwitherbartask.containsKey(p)) { setBarWitherHealth(p, playerwitherbartask.get(p), healthwitherbartask.get(p)); }
}
}
}
}.runTaskTimer(Core.getInstance(), 0, 40);
new BukkitRunnable() {
@SuppressWarnings("deprecation")
@Override
public void run() {
for(Player p : plugin.getServer().getOnlinePlayers()){
if(cooldownsdragonbar.containsKey(p)) {
if(cooldownsdragonbar.get(p) > 0)
{ cooldownsdragonbar.put(p,cooldownsdragonbar.get(p)-1); setBarDragonTimer(p, playerdragonbartask.get(p), cooldownsdragonbar.get(p)); }
else removeBarDragon(p);
}
if(cooldownswitherbar.containsKey(p)) {
if(cooldownswitherbar.get(p) > 0)
{ cooldownswitherbar.put(p,cooldownswitherbar.get(p)-1); setBarWitherTimer(p, playerwitherbartask.get(p), cooldownswitherbar.get(p)); }
else removeBarWither(p);
}
}
}
}.runTaskTimer(Core.getInstance(), 0, 20);
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void PlayerQuit(PlayerQuitEvent event) {
Player p = event.getPlayer();
removeBar(p);
FDragon.removehorligneD(p);
FWither.removehorligneW(p);
}
public static void setBarDragonHealth(Player p, String text, float health) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
{ public void PlayerKick(PlayerKickEvent event) {
if ((health <= 0.0F) || (health > 100.0F)) { health = 100.0F; text = "health must be between 1 and 100 it's a %"; } Player p = event.getPlayer();
playerdragonbartask.put(p, text); removeBar(p);
healthdragonbartask.put(p, Float.valueOf(health / 100.0F * 200.0F)); FDragon.removehorligneD(p);
FakeDragon.setBossBar(p, text, health); FWither.removehorligneW(p);
} }
public static void setBarDragonTimer(Player p, String text, int timer) {
playerdragonbartask.put(p, text); //dragon
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 setBarDragon(Player p, String text) {
} playerdragonbartask.put(p, text);
FDragon.setBossBartext(p, text);
}
public static void setBarDragonHealth(Player p, String text, float health) {
if(health<=0 || health >100) { health = 100; text = "health must be between 1 and 100 it's a %";}
playerdragonbartask.put(p, text);
healthdragonbartask.put(p, (health/100)*200);
FDragon.setBossBar(p, text, health);
}
public static void setBarDragonTimer(Player p, String text, int timer) {
playerdragonbartask.put(p, text);
cooldownsdragonbar.put(p, timer);
if(!starttimerdragonbar.containsKey(p)) starttimerdragonbar.put(p, timer);
int unite = Math.round(200/starttimerdragonbar.get(p));
FDragon.setBossBar(p, text, unite*timer);
}
public static void removeBarDragon(Player p) {
playerdragonbartask.remove(p);
healthdragonbartask.remove(p);
cooldownsdragonbar.remove(p);
starttimerdragonbar.remove(p);
FDragon.removeBossBar(p);
}
public static boolean hasBarDragon(Player p) {
return playerdragonbartask.get(p) != null;
}
public static String getMessageDragon(Player p) {
if(playerdragonbartask.containsKey(p)) return playerdragonbartask.get(p);
else return " ";
}
//wither
public static void setBarWither(Player p, String text) {
playerwitherbartask.put(p, text);
FWither.setBossBartext(p, text);
}
public static void setBarWitherHealth(Player p, String text, float health) {
if(health<=0 || health >100) { health = 100; text = "health must be between 1 and 100 it's a %";}
playerwitherbartask.put(p, text);
healthwitherbartask.put(p, (health/100)*300);
FWither.setBossBar(p, text, health);
}
public static void setBarWitherTimer(Player p, String text, int timer) {
playerwitherbartask.put(p, text);
cooldownswitherbar.put(p, timer);
if(!starttimerwitherbar.containsKey(p)) starttimerwitherbar.put(p, timer);
int unite = Math.round(300/starttimerwitherbar.get(p));
FWither.setBossBar(p, text, unite*timer);
}
public static void removeBarWither(Player p) {
playerwitherbartask.remove(p);
healthwitherbartask.remove(p);
cooldownswitherbar.remove(p);
starttimerwitherbar.remove(p);
FWither.removeBossBar(p);
}
public static boolean hasBarWither(Player p) {
return playerwitherbartask.get(p) != null;
}
public static String getMessageWither(Player p) {
if(playerwitherbartask.containsKey(p)) return playerwitherbartask.get(p);
else return " ";
}
//both
public static void setBar(Player p, String text) {
if(McVersion(p)) {
playerwitherbartask.put(p, text);
FWither.setBossBartext(p, text); }
playerdragonbartask.put(p, text);
FDragon.setBossBartext(p, text);
}
public static void setBarHealth(Player p, String text, float health) {
if(health<=0 || health >100) { health = 100; text = "health must be between 1 and 100 it's a %";}
if(McVersion(p)) {
playerwitherbartask.put(p, text);
healthwitherbartask.put(p, (health/100)*300);
FWither.setBossBar(p, text, health); }
playerdragonbartask.put(p, text);
healthdragonbartask.put(p, (health/100)*200);
FDragon.setBossBar(p, text, health);
}
public static void setBarTimer(Player p, String text, int timer) {
if(McVersion(p)) {
playerwitherbartask.put(p, text);
cooldownswitherbar.put(p, timer);
if(!starttimerwitherbar.containsKey(p)) starttimerwitherbar.put(p, timer);
int unite = Math.round(300/starttimerwitherbar.get(p));
FWither.setBossBar(p, text, unite*timer); }
playerdragonbartask.put(p, text);
cooldownsdragonbar.put(p, timer);
if(!starttimerdragonbar.containsKey(p)) starttimerdragonbar.put(p, timer);
int unite1 = Math.round(200/starttimerdragonbar.get(p));
FDragon.setBossBar(p, text, unite1*timer);
}
public static void removeBar(Player p) {
if(McVersion(p)) {
playerwitherbartask.remove(p);
healthwitherbartask.remove(p);
cooldownswitherbar.remove(p);
starttimerwitherbar.remove(p);
FWither.removeBossBar(p); }
playerdragonbartask.remove(p);
healthdragonbartask.remove(p);
cooldownsdragonbar.remove(p);
starttimerdragonbar.remove(p);
FDragon.removeBossBar(p);
}
public static boolean hasBar(Player p) {
if(McVersion(p)) {
if(playerwitherbartask.containsKey(p) && playerdragonbartask.containsKey(p))
return true;
else return false; }
else {
return playerdragonbartask.get(p) != null;
}
}
public static String getMessage(Player p) {
if(playerdragonbartask.containsKey(p)) return playerdragonbartask.get(p);
else return " ";
}
public static boolean McVersion(Player p) {
return true;
}
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;
}
}

View File

@ -1,578 +0,0 @@
package eu.univento.core.api;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import eu.univento.core.api.utils.Direction;
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;
}
}

View File

@ -32,21 +32,31 @@ public class Messages {
//editable messages will be set here, but do not edit this messages. //editable messages will be set here, but do not edit this messages.
MySQL sql = Core.returnSQL(); MySQL sql = Core.returnSQL();
sql.openConnection(); sql.openConnection();
if(!isInDatabase("Prefix")) sql.getConnection().createStatement().execute("INSERT INTO MESSAGES(Ident, Message) values ('Prefix', '§aunivento §8»');"); if(!isInDatabase("Prefix")) writeData("INSERT INTO Messages(Ident, Message) values ('Prefix', '§aunivento §8»');");
if(!isInDatabase("ConsolePrefix")) sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('ConsolePrefix', '[univento Core]');"); if(!isInDatabase("ConsolePrefix")) writeData("INSERT INTO Messages(Ident, Message) values ('ConsolePrefix', '[univento Core]');");
if(!isInDatabase("UnknownError")) sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('UnknownError', '§cEs ist leider ein unbekannter Fehler aufgetreten');"); if(!isInDatabase("UnknownError")) writeData("INSERT INTO Messages(Ident, Message) values ('UnknownError', '§cEs ist leider ein unbekannter Fehler aufgetreten');");
if(!isInDatabase("Commands.NoPlayer")) sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('Commands.NoPlayer', '§cDu bist leider kein Spieler');"); if(!isInDatabase("Commands.NoPlayer")) writeData("INSERT INTO Messages(Ident, Message) values ('Commands.NoPlayer', '§cDu bist leider kein Spieler');");
if(!isInDatabase("Commands.NoPerms")) sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('Commands.NoPerms', '§cDu hast keine Berechtigungen diesen Befehl auszuführen')"); 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")) sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('Commands.Error', '§cBeim ausführen dieses Befehls ist ein Fehler aufgetreten');"); 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")) sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('Commands.NotOnline', '§cDer Spieler $player ist nicht online');"); if(!isInDatabase("Commands.NotOnline")) writeData("INSERT INTO Messages(Ident, Message) values ('Commands.NotOnline', '§cDer Spieler $player ist nicht online');");
if(!isInDatabase("Commands.Unknown")) sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('Commands.Unknown', '§6Dieser Befehl konnte leider nicht gefunden werden');"); if(!isInDatabase("Commands.Unknown")) writeData("INSERT INTO Messages(Ident, Message) values ('Commands.Unknown', '§6Dieser Befehl konnte leider nicht gefunden werden');");
if(!isInDatabase("Kick.Restart")) sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('Kick.Restart', '§cDer Server startet gerade neu');"); if(!isInDatabase("Kick.Restart")) writeData("INSERT INTO Messages(Ident, Message) values ('Kick.Restart', '§cDer Server startet gerade neu');");
if(!isInDatabase("Kick.Full")) sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('Kick.Full', '§cDer Server ist leider schon voll')"); if(!isInDatabase("Kick.Full")) writeData("INSERT INTO Messages(Ident, Message) values ('Kick.Full', '§cDer Server ist leider schon voll')");
sql.closeConnection(); 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 * checks if message is in database
* @param ident identifier of message * @param ident identifier of message
@ -77,14 +87,14 @@ public class Messages {
public static void readStrings() throws ClassNotFoundException, SQLException { public static void readStrings() throws ClassNotFoundException, SQLException {
PREFIX = readString("Prefix") + " "; PREFIX = readString("Prefix") + " ";
CONSOLE_PREFIX = readString("ConsolePrefix") + " "; CONSOLE_PREFIX = readString("ConsolePrefix") + " ";
UNKNOWN_ERROR = readString("UnknownError"); UNKNOWN_ERROR = PREFIX + readString("UnknownError");
NOT_A_PLAYER = readString("Commands.NoPlayer") ; NOT_A_PLAYER = readString("Commands.NoPlayer") ;
NO_PERMS = readString("Commands.NoPerms"); NO_PERMS = PREFIX + readString("Commands.NoPerms");
ERROR = readString("Commands.Error"); ERROR = PREFIX + readString("Commands.Error");
NOT_ONLINE = readString("Commands.NotOnline"); NOT_ONLINE = PREFIX + readString("Commands.NotOnline");
KICK_RESTART = readString("Kick.Restart"); KICK_RESTART = readString("Kick.Restart");
KICK_FULL = readString("Kick.Full"); KICK_FULL = readString("Kick.Full");
COMMAND_NOT_FOUND = readString("Commands.Unkown"); COMMAND_NOT_FOUND = PREFIX + readString("Commands.Unkown");
} }
/** /**
@ -101,8 +111,9 @@ public class Messages {
sql.closeConnection(); sql.closeConnection();
return null; return null;
} }
String message = rs.getString("Message");
sql.closeConnection(); sql.closeConnection();
return rs.getString("Message"); return message;
} catch (ClassNotFoundException | SQLException e) { } catch (ClassNotFoundException | SQLException e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,6 @@ package eu.univento.core.api;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.MessageToMessageDecoder; import io.netty.handler.codec.MessageToMessageDecoder;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
@ -19,127 +18,129 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.Plugin; 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 /**
{ * @author Janhektor This class in licensed under GPLv3 For more information
String path = Bukkit.getServer().getClass().getPackage().getName(); * look at http://www.gnu.org/licenses/gpl-3.0
VERSION = path.substring(path.lastIndexOf(".") + 1, path.length()); */
} public final class SignInput implements Listener, Runnable {
public SignInput(Plugin plugin) private final static String VERSION;
{
this.plugin = plugin;
this.inputResults = new HashMap();
Bukkit.getScheduler().runTaskTimer(this.plugin, this, 0L, 60L);
}
public boolean readInput(Player p, Consumer<String[]> result) static {
{ String path = Bukkit.getServer().getClass().getPackage().getName();
this.inputResults.put(p.getUniqueId(), result); VERSION = path.substring(path.lastIndexOf(".") + 1, path.length());
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]); private final Plugin plugin;
Object nmsPlayer = getHandle.invoke(p, new Object[0]); private final Map<UUID, Consumer<String[]>> inputResults;
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() public SignInput(Plugin plugin) {
{ this.plugin = plugin;
for (UUID uuid : this.inputResults.keySet()) this.inputResults = new HashMap<UUID, Consumer<String[]>>();
if (Bukkit.getPlayer(uuid) == null) Bukkit.getScheduler().runTaskTimer(this.plugin, this, 0L, 20 * 3L);
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; * Use this method to read the SignInput from a player The accept()-method
try { * of your consumer will be called, when the player close the sign
Method getHandle = p.getClass().getMethod("getHandle", new Class[0]); *
Object nmsPlayer = getHandle.invoke(p, new Object[0]); * @return boolean successful
Field pConnectionField = nmsPlayer.getClass().getField( * @param p
"playerConnection"); * - The Player, who have to type an input
Object pConnection = pConnectionField.get(nmsPlayer); * @param result
Field networkManagerField = pConnection.getClass().getField( * - The consumer (String[]) for the result; String[] contains
"networkManager"); * strings for 4 lines
Object networkManager = networkManagerField.get(pConnection); */
ch = (Channel)networkManager.getClass().getField("k") public boolean readInput(Player p, Consumer<String[]> result) {
.get(networkManager); inputResults.put(p.getUniqueId(), result);
} catch (Exception ex) { try {
ex.printStackTrace(); Class<?> packetClass = Class.forName(getNMSClass("PacketPlayOutOpenSignEditor"));
} Class<?> blockPositionClass = Class.forName(getNMSClass("BlockPosition"));
return ch; Constructor<?> blockPosCon = blockPositionClass
} .getConstructor(new Class[] { int.class, int.class, int.class });
Object blockPosition = blockPosCon.newInstance(new Object[] { 0, 0, 0 });
Constructor<?> packetCon = packetClass.getConstructor(new Class[] { blockPositionClass });
Object packet = packetCon.newInstance(new Object[] { blockPosition });
private boolean instanceOf(Object o, String className) { Method getHandle = p.getClass().getMethod("getHandle");
try { Object nmsPlayer = getHandle.invoke(p);
return Class.forName(className).isInstance(o); Field pConnectionField = nmsPlayer.getClass().getField("playerConnection");
} catch (ClassNotFoundException e) { Object pConnection = pConnectionField.get(nmsPlayer);
e.printStackTrace(); Method sendMethod = pConnection.getClass().getMethod("sendPacket",
} new Class[] { Class.forName(getNMSClass("Packet")) });
return false; sendMethod.invoke(pConnection, new Object[] { packet });
} return true;
} catch (Exception ex) {
ex.printStackTrace();
return false;
}
}
private String getNMSClass(String className) { /* Garbage Collection */
return "net.minecraft.server." + VERSION + "." + className; @Override
} public void run() {
} for (UUID uuid : inputResults.keySet()) {
if (Bukkit.getPlayer(uuid) == null)
inputResults.remove(uuid);
}
}
/* Events */
@EventHandler
public void onJoin(PlayerJoinEvent e) {
Player p = e.getPlayer();
getNettyChannel(p).pipeline().addAfter("decoder", "signListener", new MessageToMessageDecoder<Object>() {
@Override
protected void decode(ChannelHandlerContext chc, Object packet, List<Object> packetList) throws Exception {
if (instanceOf(packet, getNMSClass("PacketPlayInUpdateSign"))) {
Method bMethod = packet.getClass().getMethod("b");
Object chatBaseComponents = bMethod.invoke(packet);
String[] lines = new String[4];
for (int i = 0; i < 4; i++) {
Object chatComponent = Array.get(chatBaseComponents, i);
Method getText = chatComponent.getClass().getMethod("getText");
lines[i] = (String) getText.invoke(chatComponent);
}
if (inputResults.containsKey(p.getUniqueId())) {
inputResults.get(p.getUniqueId()).accept(lines);
inputResults.remove(p.getUniqueId());
}
}
packetList.add(packet);
}
});
}
/* Util Methods */
private Channel getNettyChannel(Player p) {
Channel ch = null;
try {
Method getHandle = p.getClass().getMethod("getHandle");
Object nmsPlayer = getHandle.invoke(p);
Field pConnectionField = nmsPlayer.getClass().getField("playerConnection");
Object pConnection = pConnectionField.get(nmsPlayer);
Field networkManagerField = pConnection.getClass().getField("networkManager");
Object networkManager = networkManagerField.get(pConnection);
ch = (Channel) networkManager.getClass().getField("k").get(networkManager);
} catch (Exception ex) {
ex.printStackTrace();
}
return ch;
}
private boolean instanceOf(Object o, String className) {
try {
return Class.forName(className).isInstance(o);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return false;
}
private String getNMSClass(String className) {
return "net.minecraft.server." + VERSION + "." + className;
}
}

View File

@ -19,161 +19,199 @@ import org.bukkit.entity.Firework;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkMeta; import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
public class Utils /**
{ * some utils you may need
* @author joethei
* @version 1.0
*/
public class Utils {
/**
* plays sound for all players
* @param s Sound
*/
public static void playSoundToAll(Sound s) {
for (Player all : Bukkit.getOnlinePlayers())
all.playSound(all.getLocation(), s, 3.0F, 3.0F);
}
/**
* plays effect for all players
* @param e Effect
*/
@SuppressWarnings("deprecation")
public static void playEffectToAll(Effect e) {
for (Player all : Bukkit.getOnlinePlayers())
all.playEffect(all.getLocation(), e, 3);
}
/**
* checks if server version is from spigot
* @return true/false
*/
public static boolean isSpigot() {
return Bukkit.getVersion().contains("Spigot");
}
/**
* deletes all folders and files in directory
* @param file File
*/
public static void deleteDir(File file) {
if (file.isDirectory()) {
if (file.list().length == 0) {
file.delete();
} else {
String[] files = file.list();
for (String tmp : files) {
File fileDelete = new File(file, tmp);
deleteDir(fileDelete);
}
if (file.list().length == 0)
file.delete();
}
} else
file.delete();
}
public static void deleteFolder(File folder) /**
{ * creates a random number
File[] files = folder.listFiles(); * @param low lowest possible value
if (files != null) { * @param high highest possible value
for (File f : files) { * @return double
if (f.isDirectory()) */
deleteFolder(f); public static double random(int low, int high) {
else { return Math.random() * (high - low) + low;
f.delete(); }
}
}
}
folder.delete(); /**
} * checks if player has empty inventory
* @param p Player
* @return true/false
*/
public static boolean hasEmptyInventory(Player p) {
for (ItemStack item : p.getInventory().getContents()) {
if ((item != null) && (item.getType() != Material.AIR))
return false;
}
for (ItemStack item : p.getInventory().getArmorContents()) {
if ((item != null) && (item.getType() != Material.AIR))
return false;
}
return true;
}
public static void PlaySoundToAll(Sound s) { /**
for (Player all : Bukkit.getOnlinePlayers()) * shoots random fireworks at defined location
all.playSound(all.getLocation(), s, 3.0F, 3.0F); * @param loc Location
} */
public static void randomFireworks(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;
@SuppressWarnings("deprecation") int red = r.nextInt(256);
public static void PlayEffectToAll(Effect s) int b = r.nextInt(256);
{ int g = r.nextInt(256);
for (Player all : Bukkit.getOnlinePlayers())
all.playEffect(all.getLocation(), s, 3);
}
public static boolean isSpigot() { Color c1 = Color.fromRGB(red, g, b);
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) { red = r.nextInt(256);
return Math.random() * (high - low) + low; b = r.nextInt(256);
} g = r.nextInt(256);
Color c2 = Color.fromRGB(red, g, b);
@SuppressWarnings("deprecation") FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type)
public static ItemStack createItemStack(int id, int anzahl, int sh, String name) { .trail(r.nextBoolean()).build();
ItemStack item = new ItemStack(id, anzahl, (short)sh); fwm.addEffect(effect);
ItemMeta im = item.getItemMeta(); int rp = r.nextInt(2) + 1;
im.setDisplayName(name); fwm.setPower(rp);
item.setItemMeta(im); fw.setFireworkMeta(fwm);
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); * removes list of entity and counts them
int g = r.nextInt(256); * @param e List<Entity>
* @return Integer
*/
public static int removeEntitys(List<Entity> e) {
int i = 0;
for (Entity en : e) {
en.remove();
i++;
}
return i;
}
Color c1 = Color.fromRGB(red, g, b); /**
* clears all potion effects from player
* @param player Player
*/
public static void clearPotionEffects(Player player) {
for (PotionEffect effect : player.getActivePotionEffects())
player.removePotionEffect(effect.getType());
}
red = r.nextInt(256); /**
b = r.nextInt(256); * plays effect at defined location for all players
g = r.nextInt(256); * @param loc Location
Color c2 = Color.fromRGB(red, g, b); * @param ep EnumParticle
* @param f random placement of particles
* @param count count of particles
*/
public static void playEffect(Location loc, EnumParticle ep, float f, int count) {
PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(ep, true, (float) loc.getX(),
(float) loc.getY(), (float) loc.getZ(), f, f, f, 0.0F, count, new int[] { 0, 0 });
for (Player p : Bukkit.getOnlinePlayers())
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
}
FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type).trail(r.nextBoolean()).build(); /**
fwm.addEffect(effect); * calculates vector from one location to another
int rp = r.nextInt(2) + 1; * @param from Location
fwm.setPower(rp); * @param to Location
fw.setFireworkMeta(fwm); * @return Vector
} */
public static Vector calculateVector(Location from, Location to) {
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; Location a = from, b = to;
//calculate the distance between the locations (a => from || b => to) // calculate the distance between the locations (a => from || b => to)
double dX = a.getX() - b.getX(); double dX = a.getX() - b.getX();
double dY = a.getY() - b.getY(); double dY = a.getY() - b.getY();
double dZ = a.getZ() - b.getZ(); double dZ = a.getZ() - b.getZ();
// ------------------------- // -------------------------
//calculate the yaw // calculate the yaw
double yaw = Math.atan2(dZ, dX); double yaw = Math.atan2(dZ, dX);
// ------------------------- // -------------------------
//calculate the pitch // calculate the pitch
double pitch = Math.atan2(Math.sqrt(dZ * dZ + dX * dX), dY) + Math.PI; double pitch = Math.atan2(Math.sqrt(dZ * dZ + dX * dX), dY) + Math.PI;
// ------------------------- // -------------------------
//calculate and create the new vector // calculate and create the new vector
double x = Math.sin(pitch) * Math.cos(yaw); double x = Math.sin(pitch) * Math.cos(yaw);
double y = Math.sin(pitch) * Math.sin(yaw); double y = Math.sin(pitch) * Math.sin(yaw);
double z = Math.cos(pitch); double z = Math.cos(pitch);
Vector vector = new Vector(x, z, y); Vector vector = new Vector(x, z, y);
// ------------------------- // -------------------------
return vector; return vector;
} }
} }

View File

@ -1,6 +1,7 @@
package eu.univento.core.api; package eu.univento.core.api.player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.MySQL;
import eu.univento.core.api.utils.NameFetcher; import eu.univento.core.api.utils.NameFetcher;
import java.sql.ResultSet; import java.sql.ResultSet;

View File

@ -1,5 +1,6 @@
package eu.univento.core.api; package eu.univento.core.api.player;
import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
@ -11,7 +12,11 @@ import org.bukkit.scoreboard.Team;
import com.github.theholywaffle.teamspeak3.api.wrapper.ClientInfo; import com.github.theholywaffle.teamspeak3.api.wrapper.ClientInfo;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.Core;
import eu.univento.core.api.MySQL;
import eu.univento.core.api.Servers;
import eu.univento.core.api.Utils;
import eu.univento.core.api.player.Perms.Ranks;
/** /**
* custom player implementation * custom player implementation
@ -329,5 +334,43 @@ public class CustomPlayer extends CraftPlayer {
} }
} }
/**
* checks if player has played on the network before
* @return true/false
*/
@Override
public boolean hasPlayedBefore() {
MySQL sql = Core.returnSQL();
boolean bool;
try {
sql.openConnection();
String uuid = this.getUniqueId().toString();
ResultSet rs = sql.getConnection().createStatement().executeQuery("SELECT * FROM PlayerData WHERE player_uuid='" + uuid + "';");
if (rs.next())
bool = true;
bool = false;
sql.closeConnection();
return bool;
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
return false;
}
}
/**
* checks if inventory is empty
* @return true/false
*/
public boolean hasEmptyInventory() {
return Utils.hasEmptyInventory(PLAYER);
}
/**
* clears all potion effects from player
*/
public void clearPotionEffects() {
Utils.clearPotionEffects(PLAYER);
}
} }

View File

@ -1,10 +1,11 @@
package eu.univento.core.api; package eu.univento.core.api.player;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.MySQL;
/** /**
* querys database for muted players * querys database for muted players

View File

@ -1,4 +1,4 @@
package eu.univento.core.api; package eu.univento.core.api.player;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@ -7,6 +7,7 @@ import java.util.Random;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.MySQL;
/** /**
* gets nick settings for players * gets nick settings for players

View File

@ -1,4 +1,4 @@
package eu.univento.core.api; package eu.univento.core.api.player;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@ -10,6 +10,7 @@ import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team; import org.bukkit.scoreboard.Team;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.MySQL;
/** /**
* some permission management * some permission management
@ -31,9 +32,9 @@ public class Perms{
public static String getPrefix(Ranks r) { public static String getPrefix(Ranks r) {
switch(r) { switch(r) {
case Admin: return "§7[§4Admin§7]§4 "; case Admin: return "§7[§4Admin§7]§4 ";
case Developer: return "§7[§aDeveloper§7]§3 "; case Developer: return "§7[§3Developer§7]§3 ";
case Moderator: return "§7[§cModerator§7]§c "; case Moderator: return "§7[§cModerator§7]§c ";
case HeadBuilder: return "§7[§2Head-Builder§7]§a "; case HeadBuilder: return "§7[§aHead-Builder§7]§a ";
case Builder: return "§7[§2Builder§7]§2 "; case Builder: return "§7[§2Builder§7]§2 ";
case Supporter: return "§7[§bSupporter§7]§b "; case Supporter: return "§7[§bSupporter§7]§b ";
case Youtuber: return "§5"; case Youtuber: return "§5";
@ -50,7 +51,7 @@ public static String getPrefix(Ranks r) {
*/ */
public static String getSuffix(Ranks r) { public static String getSuffix(Ranks r) {
switch(r) { switch(r) {
case Admin: return " §8» §6"; case Admin: return " §8» §f§l";
case Developer: return " §8» §f"; case Developer: return " §8» §f";
case Moderator: return " §8» §f"; case Moderator: return " §8» §f";
case HeadBuilder: return " §8» §f"; case HeadBuilder: return " §8» §f";
@ -83,6 +84,11 @@ public static String getColor(Ranks r) {
} }
} }
/**
* returns scoreboard team for rank
* @param r Ranks
* @return Team
*/
public static Team getTeam(Ranks r) { public static Team getTeam(Ranks r) {
switch(r) { switch(r) {
case Admin: return Teams.Admin; case Admin: return Teams.Admin;
@ -98,6 +104,10 @@ public static Team getTeam(Ranks r) {
} }
} }
/**
* @author joethei
* @version 1.0
*/
public static class Teams { public static class Teams {
private static Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard(); private static Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard();
public static Team Admin = board.getTeam("a"); public static Team Admin = board.getTeam("a");
@ -111,7 +121,9 @@ public static class Teams {
public static Team Spieler = board.getTeam("i"); public static Team Spieler = board.getTeam("i");
} }
/**
* setsup scoreboards
*/
public static void initScoreboard() { public static void initScoreboard() {
Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard(); Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard();
Teams.Admin.unregister(); Teams.Admin.unregister();
@ -143,16 +155,6 @@ public static void initScoreboard() {
Teams.Youtuber.setPrefix(getColor(Ranks.Youtuber)); Teams.Youtuber.setPrefix(getColor(Ranks.Youtuber));
Teams.Premium.setPrefix(getColor(Ranks.Premium)); Teams.Premium.setPrefix(getColor(Ranks.Premium));
Teams.Spieler.setPrefix(getColor(Ranks.Spieler)); Teams.Spieler.setPrefix(getColor(Ranks.Spieler));
Teams.Admin.setNameTagVisibility(NameTagVisibility.ALWAYS);
Teams.Developer.setNameTagVisibility(NameTagVisibility.ALWAYS);
Teams.Moderator.setNameTagVisibility(NameTagVisibility.ALWAYS);
Teams.HeadBuilder.setNameTagVisibility(NameTagVisibility.ALWAYS);
Teams.Builder.setNameTagVisibility(NameTagVisibility.ALWAYS);
Teams.Supporter.setNameTagVisibility(NameTagVisibility.ALWAYS);
Teams.Youtuber.setNameTagVisibility(NameTagVisibility.ALWAYS);
Teams.Premium.setNameTagVisibility(NameTagVisibility.ALWAYS);
Teams.Spieler.setNameTagVisibility(NameTagVisibility.ALWAYS);
} }
/** /**
* gets Rank of player * gets Rank of player

View File

@ -1,4 +1,4 @@
package eu.univento.core.api; package eu.univento.core.api.player;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -1,4 +1,4 @@
package eu.univento.core.api; package eu.univento.core.api.player;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@ -11,7 +11,9 @@ import com.github.theholywaffle.teamspeak3.api.wrapper.Client;
import com.github.theholywaffle.teamspeak3.api.wrapper.ClientInfo; import com.github.theholywaffle.teamspeak3.api.wrapper.ClientInfo;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.api.Config;
import eu.univento.core.api.MySQL;
import eu.univento.core.api.player.Perms.Ranks;
/** /**
* basic functions for teamspeak communication * basic functions for teamspeak communication
@ -74,8 +76,8 @@ public class TeamSpeak {
sql.openConnection(); sql.openConnection();
ResultSet rs = sql.getConnection().createStatement().executeQuery("SELECT * FROM PlayerData WHERE player_uuid='" + p.getUniqueId() + "'"); ResultSet rs = sql.getConnection().createStatement().executeQuery("SELECT * FROM PlayerData WHERE player_uuid='" + p.getUniqueId() + "'");
rs.next(); rs.next();
if (rs.getInt("TS-ID") != 0) { if (rs.getInt("TS_ID") != 0) {
int id = rs.getInt("TS-ID"); int id = rs.getInt("TS_ID");
sql.closeConnection(); sql.closeConnection();
return id; return id;
} }
@ -93,7 +95,7 @@ public class TeamSpeak {
private void setTsId(CustomPlayer p, int id) throws ClassNotFoundException, SQLException { private void setTsId(CustomPlayer p, int id) throws ClassNotFoundException, SQLException {
MySQL sql = Core.returnSQL(); MySQL sql = Core.returnSQL();
sql.openConnection(); sql.openConnection();
sql.getConnection().createStatement().execute("UPDATE PlayerData SET TS-ID='" + id + "' WHERE player_uuid='" + p.getUniqueId() + "';"); sql.getConnection().createStatement().execute("UPDATE PlayerData SET TS_ID='" + id + "' WHERE player_uuid='" + p.getUniqueId() + "';");
sql.closeConnection(); sql.closeConnection();
} }

View File

@ -0,0 +1,228 @@
package eu.univento.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.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* @author mgone2010
*/
public class FDragon {
private static Constructor<?> packetPlayOutSpawnEntityLiving;
private static Constructor<?> entityEnderdragon;
private static Method setLocation;
private static Method setCustomName;
private static Method setHealth;
private static Method setInvisible;
private static Method getWorldHandle;
private static Method getPlayerHandle;
private static Field playerConnection;
private static Method sendPacket;
private static Method getDatawatcher;
private static Method a;
private static Field d;
public static Map<String, Object> playerDragons = new HashMap<String, Object>();
public static Map<String, String> playerTextDragon = new HashMap<String, String>();
static {
try {
packetPlayOutSpawnEntityLiving = getMCClass("PacketPlayOutSpawnEntityLiving").getConstructor(getMCClass("EntityLiving"));
entityEnderdragon = getMCClass("EntityEnderDragon").getConstructor(getMCClass("World"));
setLocation = getMCClass("EntityEnderDragon").getMethod("setLocation", double.class, double.class, double.class, float.class, float.class);
setCustomName = getMCClass("EntityEnderDragon").getMethod("setCustomName", new Class<?>[] { String.class });
setHealth = getMCClass("EntityEnderDragon").getMethod("setHealth", new Class<?>[] { float.class });
setInvisible = getMCClass("EntityEnderDragon").getMethod("setInvisible", new Class<?>[] { boolean.class });
getWorldHandle = getCraftClass("CraftWorld").getMethod("getHandle");
getPlayerHandle = getCraftClass("entity.CraftPlayer").getMethod("getHandle");
playerConnection = getMCClass("EntityPlayer").getDeclaredField("playerConnection");
sendPacket = getMCClass("PlayerConnection").getMethod("sendPacket", getMCClass("Packet"));
getDatawatcher = getMCClass("EntityEnderDragon").getMethod("getDataWatcher");
a = getMCClass("DataWatcher").getMethod("a", int.class, Object.class);
d = getMCClass("DataWatcher").getDeclaredField("d");
d.setAccessible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
public static Object getEnderDragon(Player p) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
if (FDragon.playerDragons.containsKey(p.getName())) {
return FDragon.playerDragons.get(p.getName());
} else {
Object nms_world = getWorldHandle.invoke(p.getWorld());
FDragon.playerDragons.put(p.getName(), entityEnderdragon.newInstance(nms_world));
return FDragon.getEnderDragon(p);
}
}
public static void setBossBartext(Player p, String text) {
playerTextDragon.put(p.getName(), text);
try {
Object nms_dragon = getEnderDragon(p);
//setLocation.invoke(nms_dragon, loc.getX(), 150, loc.getZ(), 0F, 0F);
setLocation.invoke(nms_dragon, getPlayerLoc(p).getX(), getPlayerLoc(p).getY()+800, getPlayerLoc(p).getZ(), 0F, 0F);
setCustomName.invoke(nms_dragon,text);
setHealth.invoke(nms_dragon,200);
setInvisible.invoke(nms_dragon,true);
changeWatcher(nms_dragon, text);
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(nms_dragon);
Object nms_player = getPlayerHandle.invoke(p);
Object nms_connection = playerConnection.get(nms_player);
sendPacket.invoke(nms_connection, nms_packet);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void setBossBar(Player p, String text, float vie) {
playerTextDragon.put(p.getName(), text);
try {
Object nms_dragon = getEnderDragon(p);
setLocation.invoke(nms_dragon, getPlayerLoc(p).getX(), getPlayerLoc(p).getY()+800, getPlayerLoc(p).getZ(), 0F, 0F);
setCustomName.invoke(nms_dragon,text);
setHealth.invoke(nms_dragon,vie);
setInvisible.invoke(nms_dragon,true);
changeWatcher(nms_dragon, text);
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(nms_dragon);
Object nms_player = getPlayerHandle.invoke(p);
Object nms_connection = playerConnection.get(nms_player);
sendPacket.invoke(nms_connection, nms_packet);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void removeBossBar(Player p){
playerTextDragon.remove(p.getName());
try {
Object nms_dragon = getEnderDragon(p);
setLocation.invoke(nms_dragon, p.getLocation().getX(), -5000, p.getLocation().getZ(), 0F, 0F);
setCustomName.invoke(nms_dragon," ");
setHealth.invoke(nms_dragon,0);
setInvisible.invoke(nms_dragon,true);
changeWatcher(nms_dragon, " ");
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(nms_dragon);
Object nms_player = getPlayerHandle.invoke(p);
Object nms_connection = playerConnection.get(nms_player);
sendPacket.invoke(nms_connection, nms_packet);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void removehorligneD(Player p) {
playerDragons.remove(p.getName());
playerTextDragon.remove(p.getName());
}
private static void changeWatcher(Object nms_entity, String text) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Object nms_watcher = getDatawatcher.invoke(nms_entity);
Map<?, ?> map = (Map<?, ?>) d.get(nms_watcher);
map.remove(10);
a.invoke(nms_watcher, 10, text);
}
private static Class<?> getMCClass(String name) throws ClassNotFoundException {
String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3] + ".";
String className = "net.minecraft.server." + version + name;
return Class.forName(className);
}
private static Class<?> getCraftClass(String name) throws ClassNotFoundException {
String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3] + ".";
String className = "org.bukkit.craftbukkit." + version + name;
return Class.forName(className);
}
public static String getCardinalDirection(Player player) {
double rotation = (player.getLocation().getYaw() - 180) % 360;
if (rotation < 0) {
rotation += 360.0;
}
if (0 <= rotation && rotation < 22.5) {
return "N";
} else if (22.5 <= rotation && rotation < 67.5) {
return "NE";
} else if (67.5 <= rotation && rotation < 112.5) {
return "E";
} else if (112.5 <= rotation && rotation < 157.5) {
return "SE";
} else if (157.5 <= rotation && rotation < 202.5) {
return "S";
} else if (202.5 <= rotation && rotation < 247.5) {
return "SW";
} else if (247.5 <= rotation && rotation < 292.5) {
return "W";
} else if (292.5 <= rotation && rotation < 337.5) {
return "NW";
} else if (337.5 <= rotation && rotation < 360.0) {
return "N";
} else {
return null;
}
}
public static Location getPlayerLoc(Player p) {
Location loc = p.getLocation();
switch (getCardinalDirection(p)) {
case ("N") :
loc.add(0, 0, -150);
break;
case ("E") :
loc.add(150, 0, 0);
break;
case ("S") :
loc.add(0, 0, 150);
break;
case ("W") :
loc.add(-150, 0, 0);
break;
case ("NE") :
loc.add(150, 0, -150);
break;
case ("SE") :
loc.add(150, 0, 150);
break;
case ("NW") :
loc.add(-150, 0, -150);
break;
case ("SW") :
loc.add(-150, 0, 150);
break;
}
return loc;
}
}

View File

@ -0,0 +1,289 @@
package eu.univento.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.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* @author mgone2010
*/
public class FWither {
private static Constructor<?> packetPlayOutSpawnEntityLiving;
private static Constructor<?> entityEntityWither;
private static Method setLocation;
private static Method setCustomName;
private static Method setHealth;
private static Method setInvisible;
private static Method getWorldHandle;
private static Method getPlayerHandle;
private static Field playerConnection;
private static Method sendPacket;
private static Method getDatawatcher;
private static Method a;
private static Field d;
private static Map<String, Object> playerWithers = new HashMap<String, Object>();
private static Map<String, Object> playerWithers2 = new HashMap<String, Object>();
private static Map<String, String> playerTextWither = new HashMap<String, String>();
static {
try {
packetPlayOutSpawnEntityLiving = getMCClass("PacketPlayOutSpawnEntityLiving").getConstructor(getMCClass("EntityLiving"));
entityEntityWither = getMCClass("EntityWither").getConstructor(getMCClass("World"));
setLocation = getMCClass("EntityWither").getMethod("setLocation", double.class, double.class, double.class, float.class, float.class);
setCustomName = getMCClass("EntityWither").getMethod("setCustomName", new Class<?>[] { String.class });
setHealth = getMCClass("EntityWither").getMethod("setHealth", new Class<?>[] { float.class });
setInvisible = getMCClass("EntityWither").getMethod("setInvisible", new Class<?>[] { boolean.class });
getWorldHandle = getCraftClass("CraftWorld").getMethod("getHandle");
getPlayerHandle = getCraftClass("entity.CraftPlayer").getMethod("getHandle");
playerConnection = getMCClass("EntityPlayer").getDeclaredField("playerConnection");
sendPacket = getMCClass("PlayerConnection").getMethod("sendPacket", getMCClass("Packet"));
getDatawatcher = getMCClass("EntityWither").getMethod("getDataWatcher");
a = getMCClass("DataWatcher").getMethod("a", int.class, Object.class);
d = getMCClass("DataWatcher").getDeclaredField("d");
d.setAccessible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
public static Object getWither(Player p) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
if (playerWithers.containsKey(p.getName())) {
return playerWithers.get(p.getName());
} else {
Object nms_world = getWorldHandle.invoke(p.getWorld());
playerWithers.put(p.getName(), entityEntityWither.newInstance(nms_world));
return getWither(p);
}
}
public static Object getWither2(Player p) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
if (playerWithers2.containsKey(p.getName())) {
return playerWithers2.get(p.getName());
} else {
Object nms_world = getWorldHandle.invoke(p.getWorld());
playerWithers2.put(p.getName(), entityEntityWither.newInstance(nms_world));
return getWither2(p);
}
}
public static void setBossBartext(Player p, String text) {
playerTextWither.put(p.getName(), text);
int xr = ThreadLocalRandom.current().nextInt(-3,3);
int xr2 = ThreadLocalRandom.current().nextInt(-3,3);
try {
Object nms_wither = getWither(p);
setLocation.invoke(nms_wither, getPlayerLoc(p).getX()+xr, getPlayerLoc(p).getY()-3, getPlayerLoc(p).getZ()+xr2, 0F, 0F);
setCustomName.invoke(nms_wither,text);
setHealth.invoke(nms_wither,300);
setInvisible.invoke(nms_wither,true);
changeWatcher(nms_wither, text);
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(nms_wither);
Object nms_player = getPlayerHandle.invoke(p);
Object nms_connection = playerConnection.get(nms_player);
sendPacket.invoke(nms_connection, nms_packet);
} catch (Exception e) {
e.printStackTrace();
}
/* try {
Object nms_wither = getWither2(p);
setLocation.invoke(nms_wither, getPlayerLoc(p).getX()+xr2, p.getLocation().getY()-10, getPlayerLoc(p).getZ()+xr, 0F, 0F);
setCustomName.invoke(nms_wither,text);
setHealth.invoke(nms_wither,300);
setInvisible.invoke(nms_wither,true);
changeWatcher(nms_wither, text);
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(nms_wither);
Object nms_player = getPlayerHandle.invoke(p);
Object nms_connection = playerConnection.get(nms_player);
sendPacket.invoke(nms_connection, nms_packet);
} catch (Exception e) {
e.printStackTrace();
} */
}
public static void setBossBar(Player p, String text, float vie) {
playerTextWither.put(p.getName(), text);
int xr = ThreadLocalRandom.current().nextInt(0,2);
int xr2 = ThreadLocalRandom.current().nextInt(0,2);
try {
Object nms_wither = getWither(p);
setLocation.invoke(nms_wither, getPlayerLoc(p).getX()+xr, getPlayerLoc(p).getY()-3, getPlayerLoc(p).getZ()+xr2, 0F, 0F);
setCustomName.invoke(nms_wither,text);
setHealth.invoke(nms_wither,vie);
setInvisible.invoke(nms_wither,true);
changeWatcher(nms_wither, text);
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(nms_wither);
Object nms_player = getPlayerHandle.invoke(p);
Object nms_connection = playerConnection.get(nms_player);
sendPacket.invoke(nms_connection, nms_packet);
} catch (Exception e) {
e.printStackTrace();
}
/* try {
Object nms_wither = getWither2(p);
setLocation.invoke(nms_wither, getPlayerLoc(p).getX()+xr2, p.getLocation().getY()-10, getPlayerLoc(p).getZ()+xr, 0F, 0F);
setCustomName.invoke(nms_wither,text);
setHealth.invoke(nms_wither,vie);
setInvisible.invoke(nms_wither,true);
changeWatcher(nms_wither, text);
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(nms_wither);
Object nms_player = getPlayerHandle.invoke(p);
Object nms_connection = playerConnection.get(nms_player);
sendPacket.invoke(nms_connection, nms_packet);
} catch (Exception e) {
e.printStackTrace();
} */
}
public static void removeBossBar(Player p){
playerTextWither.remove(p.getName());
try {
Object nms_wither = getWither(p);
setLocation.invoke(nms_wither, p.getLocation().getX(), -5000, p.getLocation().getZ(), 0F, 0F);
setCustomName.invoke(nms_wither," ");
setHealth.invoke(nms_wither,0);
setInvisible.invoke(nms_wither,true);
changeWatcher(nms_wither, " ");
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(nms_wither);
Object nms_player = getPlayerHandle.invoke(p);
Object nms_connection = playerConnection.get(nms_player);
sendPacket.invoke(nms_connection, nms_packet);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void removehorligneW(Player p) {
playerWithers.remove(p.getName());
playerTextWither.remove(p.getName());
}
private static void changeWatcher(Object nms_entity, String text) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Object nms_watcher = getDatawatcher.invoke(nms_entity);
Map<?, ?> map = (Map<?, ?>) d.get(nms_watcher);
map.remove(10);
a.invoke(nms_watcher, 10, text);
}
private static Class<?> getMCClass(String name) throws ClassNotFoundException {
String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3] + ".";
String className = "net.minecraft.server." + version + name;
return Class.forName(className);
}
private static Class<?> getCraftClass(String name) throws ClassNotFoundException {
String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3] + ".";
String className = "org.bukkit.craftbukkit." + version + name;
return Class.forName(className);
}
public static String getCardinalDirection(Player player) {
double rotation = (player.getLocation().getYaw() - 180) % 360;
if (rotation < 0) {
rotation += 360.0;
}
if (0 <= rotation && rotation < 22.5) {
return "N";
} else if (22.5 <= rotation && rotation < 67.5) {
return "NE";
} else if (67.5 <= rotation && rotation < 112.5) {
return "E";
} else if (112.5 <= rotation && rotation < 157.5) {
return "SE";
} else if (157.5 <= rotation && rotation < 202.5) {
return "S";
} else if (202.5 <= rotation && rotation < 247.5) {
return "SW";
} else if (247.5 <= rotation && rotation < 292.5) {
return "W";
} else if (292.5 <= rotation && rotation < 337.5) {
return "NW";
} else if (337.5 <= rotation && rotation <= 360.0) {
return "N";
} else {
return "N";
}
}
public static Location getPlayerLoc(Player p) {
Location loc = p.getLocation();
switch (getCardinalDirection(p)) {
case ("N") :
loc.add(0, 0, -50);
break;
case ("E") :
loc.add(50, 0, 0);
break;
case ("S") :
loc.add(0, 0, 50);
break;
case ("W") :
loc.add(-50, 0, 0);
break;
case ("NE") :
loc.add(50, 0, -50);
break;
case ("SE") :
loc.add(50, 0, 50);
break;
case ("NW") :
loc.add(-50, 0, -50);
break;
case ("SW") :
loc.add(-50, 0, 50);
break;
}
return loc;
}
}

View File

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

View File

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

View File

@ -10,9 +10,9 @@ import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.AutoCommand; import eu.univento.core.api.AutoCommand;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.player.Perms.Ranks;
/** /**
* command to ban players * command to ban players

View File

@ -8,9 +8,9 @@ import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.AutoCommand; import eu.univento.core.api.AutoCommand;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.player.Perms.Ranks;
/** /**
* lets player build * lets player build

View File

@ -9,8 +9,8 @@ import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.AutoCommand; import eu.univento.core.api.AutoCommand;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.player.CustomPlayer;
/** /**
* fixes players * fixes players

View File

@ -8,9 +8,9 @@ import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.AutoCommand; import eu.univento.core.api.AutoCommand;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.player.Perms.Ranks;
/** /**
* changes game modes * changes game modes

View File

@ -7,10 +7,10 @@ import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.AutoCommand; import eu.univento.core.api.AutoCommand;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.Settings; import eu.univento.core.api.Settings;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.player.Perms.Ranks;
/** /**
* mutes the whole server * mutes the whole server

View File

@ -9,9 +9,9 @@ import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.AutoCommand; import eu.univento.core.api.AutoCommand;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.player.Perms.Ranks;
/** /**
* lets other player run commands * lets other player run commands

View File

@ -10,10 +10,10 @@ import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.AutoCommand; import eu.univento.core.api.AutoCommand;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.Perms; import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.api.player.Perms;
import eu.univento.core.api.player.Perms.Ranks;
/** /**
* sets ranks for players * sets ranks for players
@ -39,23 +39,21 @@ public class SetRank extends AutoCommand<Core>{
if(p.isAllowed(Ranks.Admin)) { if(p.isAllowed(Ranks.Admin)) {
if(args.length == 2) { if(args.length == 2) {
Ranks rank = Ranks.valueOf(args[1]); Ranks rank = Ranks.valueOf(args[1]);
if(Bukkit.getPlayer(args[0]) != null) { if(rank != null) {
CustomPlayer player = CustomPlayer.getPlayer(Bukkit.getPlayer(args[0]).getName()); if(Bukkit.getPlayer(args[0]) != null) {
if(rank != null) { CustomPlayer player = CustomPlayer.getPlayer(Bukkit.getPlayer(args[0]).getName());
try { try {
Perms.setRank(player, rank); Perms.setRank(player, rank);
p.sendMessage("§aDer Rang wurde erfolgreich gesetzt"); p.sendMessage("§aDer Rang wurde erfolgreich gesetzt");
} catch (ClassNotFoundException | SQLException e) { } catch (ClassNotFoundException | SQLException e) {
e.printStackTrace(); e.printStackTrace();
p.sendMessage(Messages.readString("Messages.UnknownError")); p.sendMessage(Messages.readString("Messages.UnknownError"));
} }
}else { }else {
p.sendMessage("§cDen Rang gibt es nicht"); p.sendMessage(Messages.NOT_ONLINE);
} }
}else { }else {
String msg = Messages.readString("Messages.Player.NotOnline"); p.sendMessage("§cDen Rang gibt es nicht");
msg = msg.replace("$player", args[0]);
p.sendMessage(msg);
} }
}else { }else {
p.sendMessage("§cNutze §6/setRank <Spieler> <Rang>"); p.sendMessage("§cNutze §6/setRank <Spieler> <Rang>");

View File

@ -8,9 +8,9 @@ import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.AutoCommand; import eu.univento.core.api.AutoCommand;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.player.Perms.Ranks;
/** /**
* prints infos about the server * prints infos about the server

View File

@ -7,9 +7,9 @@ import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.AutoCommand; import eu.univento.core.api.AutoCommand;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.TeamSpeak; import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.player.TeamSpeak;
/** /**
* sets ts groups according to player rank * sets ts groups according to player rank

View File

@ -7,8 +7,8 @@ import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.AutoCommand; import eu.univento.core.api.AutoCommand;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.twitch.Twitch_API; import eu.univento.core.api.twitch.Twitch_API;
import eu.univento.core.api.twitch.Twitch_Stream; import eu.univento.core.api.twitch.Twitch_Stream;

View File

@ -9,9 +9,9 @@ import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.AutoCommand; import eu.univento.core.api.AutoCommand;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.player.Perms.Ranks;
/** /**
* vanish players * vanish players
@ -51,13 +51,13 @@ public class Vanish extends AutoCommand<Core>{
players.showPlayer(p); players.showPlayer(p);
} }
players.remove(p); players.remove(p);
p.sendMessage("§cDu bist nun wieder sichtbar"); p.sendMessage(Messages.PREFIX + "§eDu bist nun wieder §csichtbar");
}else { }else {
for(Player players : Bukkit.getOnlinePlayers()) { for(Player players : Bukkit.getOnlinePlayers()) {
players.hidePlayer(p); players.hidePlayer(p);
} }
players.add(p); players.add(p);
p.sendMessage("Du bist nun unsichtbar"); p.sendMessage(Messages.PREFIX + "§eDu bist nun §aunsichtbar");
} }
}else { }else {
p.sendMessage(Messages.NO_PERMS); p.sendMessage(Messages.NO_PERMS);

View File

@ -7,8 +7,8 @@ import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.AutoCommand; import eu.univento.core.api.AutoCommand;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.youtube.YTAPI; import eu.univento.core.api.youtube.YTAPI;
import eu.univento.core.api.youtube.YoutubeChannel; import eu.univento.core.api.youtube.YoutubeChannel;

View File

@ -5,8 +5,8 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Settings; import eu.univento.core.api.Settings;
import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.commands.Build; import eu.univento.core.commands.Build;
/** /**

View File

@ -4,9 +4,10 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import eu.univento.core.api.CustomPlayer; import eu.univento.core.api.Messages;
import eu.univento.core.api.Settings; import eu.univento.core.api.Settings;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.player.Perms.Ranks;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
/** /**
@ -25,7 +26,7 @@ public class Chat implements Listener{
if(Settings.isMute()) { if(Settings.isMute()) {
if(!p.isAllowed(Ranks.Supporter)) { if(!p.isAllowed(Ranks.Supporter)) {
e.setCancelled(true); e.setCancelled(true);
p.sendMessage("§cMomentan ist dieser Server gemutet"); p.sendMessage(Messages.PREFIX + "§cMomentan ist dieser Server gemutet");
} }
} }
if(!p.isMuted()) { if(!p.isMuted()) {
@ -37,7 +38,7 @@ public class Chat implements Listener{
} }
e.setFormat(format); e.setFormat(format);
}else { }else {
p.sendMessage("§cDu wurdest leider vom Chat ausgeschlossen"); p.sendMessage(Messages.PREFIX + "§cDu wurdest leider vom Chat ausgeschlossen");
} }
} }

View File

@ -9,9 +9,9 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.help.HelpTopic; import org.bukkit.help.HelpTopic;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.player.Perms.Ranks;
/** /**
* commands * commands
@ -50,7 +50,7 @@ public class Commands implements Listener{
if(cmd.equalsIgnoreCase("/rl") || cmd.equalsIgnoreCase("/reload")) { if(cmd.equalsIgnoreCase("/rl") || cmd.equalsIgnoreCase("/reload")) {
if(p.isAllowed(Ranks.Admin)) { if(p.isAllowed(Ranks.Admin)) {
e.setCancelled(true); e.setCancelled(true);
Bukkit.broadcastMessage("§cAchtung der Server wird gleich neu geladen"); Bukkit.broadcastMessage(Messages.PREFIX + "§cAchtung der Server wird gleich neu geladen");
Bukkit.getScheduler().scheduleSyncDelayedTask(Core.getInstance(), new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(Core.getInstance(), new Runnable() {
@Override @Override

View File

@ -15,11 +15,13 @@ import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.CustomPlayer; import eu.univento.core.api.Messages;
import eu.univento.core.api.MySQL; import eu.univento.core.api.MySQL;
import eu.univento.core.api.NickName; import eu.univento.core.api.Utils;
import eu.univento.core.api.Perms; import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.api.player.NickName;
import eu.univento.core.api.player.Perms;
import eu.univento.core.api.player.Perms.Ranks;
import eu.univento.core.commands.Vanish; import eu.univento.core.commands.Vanish;
/** /**
@ -36,10 +38,19 @@ public class JoinQuit implements Listener{
@EventHandler @EventHandler
public void onJoin(PlayerJoinEvent e) { public void onJoin(PlayerJoinEvent e) {
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer().getName()); CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer().getName());
if(!p.hasPlayedBefore()) {
createPlayer(p);
p.sendMessage(Messages.PREFIX + "§aHerzlich willkommen auf univento.eu");
p.sendMessage(Messages.PREFIX + "§6Dem Netzwerk mit Style");
for(int i = 0; i >= 15; i++) {
Utils.randomFireworks(p.getEyeLocation());
}
}
e.setJoinMessage(null); e.setJoinMessage(null);
createPlayer(p);
Perms.getRanks().put(p, p.getRankFresh()); Perms.getRanks().put(p, p.getRankFresh());
p.getTeam().addPlayer(p); p.getTeam().addPlayer(p);
p.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
try { try {
setup(p, p.getRank()); setup(p, p.getRank());
} catch (SQLException e1) { } catch (SQLException e1) {
@ -60,11 +71,13 @@ public class JoinQuit implements Listener{
* Handles QuitMessage and other needed stuff * Handles QuitMessage and other needed stuff
* @param e event * @param e event
*/ */
@SuppressWarnings("deprecation")
@EventHandler @EventHandler
public void onQuit(PlayerQuitEvent e) { public void onQuit(PlayerQuitEvent e) {
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer().getName()); CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer().getName());
NickName.remove(p); NickName.remove(p);
Perms.getRanks().remove(p); Perms.getRanks().remove(p);
p.getTeam().removePlayer(p);
p.onLeave(); p.onLeave();
e.setQuitMessage(null); e.setQuitMessage(null);
} }