diff --git a/Core.iml b/Core.iml index 8a9805d..e003791 100644 --- a/Core.iml +++ b/Core.iml @@ -1,5 +1,5 @@ - + @@ -11,40 +11,33 @@ - - + + - + - - + + + + - - + - - - - - - - - - + \ No newline at end of file diff --git a/local-maven-repo/The5zigMod.jar b/local-maven-repo/The5zigMod.jar deleted file mode 100644 index 78e3450..0000000 Binary files a/local-maven-repo/The5zigMod.jar and /dev/null differ diff --git a/pom.xml b/pom.xml index 7830560..2eb77fe 100644 --- a/pom.xml +++ b/pom.xml @@ -50,34 +50,35 @@ - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + univentoEU + http://dev.joethei.de:8081/repository/public/ - org.projectlombok - lombok - 1.14.8 + com.destroystokyo.paper + paper-api + 1.11-R0.1-SNAPSHOT provided org.spigotmc spigot-api - 1.10.2-R0.1-SNAPSHOT + 1.11-R0.1-SNAPSHOT provided org.bukkit bukkit - 1.10.2-R0.1-SNAPSHOT + 1.11-R0.1-SNAPSHOT provided org.bukkit craftbukkit - 1.10.2-R0.1-SNAPSHOT + 1.11-R0.1-SNAPSHOT + provided eu.univento @@ -85,16 +86,9 @@ 1.0-SNAPSHOT - eu.univento - Commons - 1.0-SNAPSHOT - - - eu.the5zig.mod - mod - 1.0 - system - ${project.basedir}/local-maven-repo/The5zigMod.jar + org.projectlombok + lombok + 1.16.10 diff --git a/src/main/java/eu/univento/core/Core.java b/src/main/java/eu/univento/core/Core.java index b26b23f..271906c 100644 --- a/src/main/java/eu/univento/core/Core.java +++ b/src/main/java/eu/univento/core/Core.java @@ -4,7 +4,6 @@ import eu.univento.commons.Commons; import eu.univento.commons.server.TPS; import eu.univento.core.antihack.AntiHack; import eu.univento.core.api.Config; -import eu.univento.core.api.debug.DebugManager; import eu.univento.core.api.effects.Blackscreen; import eu.univento.core.api.events.MoveEventFilter; import eu.univento.core.api.items.InventoryManager; @@ -15,7 +14,6 @@ import eu.univento.core.api.utils.NettyInjection; import eu.univento.core.commands.*; import eu.univento.core.listeners.*; import io.netty.channel.Channel; -import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -86,9 +84,6 @@ public class Core extends JavaPlugin implements NettyInjection.PacketHandler { } } - @Getter - private static DebugManager debugManager; - /* @Override public void onLoad() { @@ -232,7 +227,6 @@ public class Core extends JavaPlugin implements NettyInjection.PacketHandler { }); */ Bukkit.getScheduler().runTask(this, new TPS()); - debugManager = new DebugManager(); } @Override diff --git a/src/main/java/eu/univento/core/antihack/utils/PacketReader.java b/src/main/java/eu/univento/core/antihack/utils/PacketReader.java index f3eab1b..cbf612e 100644 --- a/src/main/java/eu/univento/core/antihack/utils/PacketReader.java +++ b/src/main/java/eu/univento/core/antihack/utils/PacketReader.java @@ -4,8 +4,8 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToMessageDecoder; -import net.minecraft.server.v1_10_R1.Packet; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; +import net.minecraft.server.v1_11_R1.Packet; +import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import java.util.List; diff --git a/src/main/java/eu/univento/core/api/Hologram.java b/src/main/java/eu/univento/core/api/Hologram.java index 8a20450..93e4151 100644 --- a/src/main/java/eu/univento/core/api/Hologram.java +++ b/src/main/java/eu/univento/core/api/Hologram.java @@ -2,14 +2,14 @@ package eu.univento.core.api; import eu.univento.core.Core; import eu.univento.core.api.player.CustomPlayer; -import net.minecraft.server.v1_10_R1.EntityArmorStand; -import net.minecraft.server.v1_10_R1.EnumHand; -import net.minecraft.server.v1_10_R1.PacketPlayOutEntityDestroy; -import net.minecraft.server.v1_10_R1.PacketPlayOutSpawnEntityLiving; +import net.minecraft.server.v1_11_R1.EntityArmorStand; +import net.minecraft.server.v1_11_R1.EnumHand; +import net.minecraft.server.v1_11_R1.PacketPlayOutEntityDestroy; +import net.minecraft.server.v1_11_R1.PacketPlayOutSpawnEntityLiving; import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_10_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_11_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; diff --git a/src/main/java/eu/univento/core/api/blocks/banners/BannerColor.java b/src/main/java/eu/univento/core/api/blocks/banners/BannerColor.java index 42e602d..2756299 100644 --- a/src/main/java/eu/univento/core/api/blocks/banners/BannerColor.java +++ b/src/main/java/eu/univento/core/api/blocks/banners/BannerColor.java @@ -8,7 +8,22 @@ import org.bukkit.DyeColor; */ public enum BannerColor { - BLACK('0', DyeColor.BLACK), BLUE('1', DyeColor.BLUE), BROWN('g', DyeColor.BROWN), CYAN('3', DyeColor.CYAN), GRAY('8', DyeColor.GRAY), GREEN('2', DyeColor.GREEN), LIGHT_BLUE('b', DyeColor.LIGHT_BLUE), LIME('a', DyeColor.LIME), MAGENTA('c', DyeColor.MAGENTA), ORANGE('6', DyeColor.ORANGE), PINK('d', DyeColor.PINK), PURPLE('5', DyeColor.PURPLE), RED('4', DyeColor.RED), SILVER('7', DyeColor.SILVER), WHITE('f', DyeColor.WHITE), YELLOW('e', DyeColor.YELLOW); + BLACK('0', DyeColor.BLACK), + BLUE('1', DyeColor.BLUE), + BROWN('g', DyeColor.BROWN), + CYAN('3', DyeColor.CYAN), + GRAY('8', DyeColor.GRAY), + GREEN('2', DyeColor.GREEN), + LIGHT_BLUE('b', DyeColor.LIGHT_BLUE), + LIME('a', DyeColor.LIME), + MAGENTA('c', DyeColor.MAGENTA), + ORANGE('6', DyeColor.ORANGE), + PINK('d', DyeColor.PINK), + PURPLE('5', DyeColor.PURPLE), + RED('4', DyeColor.RED), + SILVER('7', DyeColor.SILVER), + WHITE('f', DyeColor.WHITE), + YELLOW('e', DyeColor.YELLOW); private char colorCode; private DyeColor color; diff --git a/src/main/java/eu/univento/core/api/chat/DefaultFontInfo.java b/src/main/java/eu/univento/core/api/chat/DefaultFontInfo.java new file mode 100644 index 0000000..6f82d04 --- /dev/null +++ b/src/main/java/eu/univento/core/api/chat/DefaultFontInfo.java @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2016 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.core.api.chat; + +/** + * @author SirSpoodles + * @version 1.0 + */ + +public enum DefaultFontInfo { + + A('A', 5), + a('a', 5), + B('B', 5), + b('b', 5), + C('C', 5), + c('c', 5), + D('D', 5), + d('d', 5), + E('E', 5), + e('e', 5), + F('F', 5), + f('f', 4), + G('G', 5), + g('g', 5), + H('H', 5), + h('h', 5), + I('I', 3), + i('i', 1), + J('J', 5), + j('j', 5), + K('K', 5), + k('k', 4), + L('L', 5), + l('l', 1), + M('M', 5), + m('m', 5), + N('N', 5), + n('n', 5), + O('O', 5), + o('o', 5), + P('P', 5), + p('p', 5), + Q('Q', 5), + q('q', 5), + R('R', 5), + r('r', 5), + S('S', 5), + s('s', 5), + T('T', 5), + t('t', 4), + U('U', 5), + u('u', 5), + V('V', 5), + v('v', 5), + W('W', 5), + w('w', 5), + X('X', 5), + x('x', 5), + Y('Y', 5), + y('y', 5), + Z('Z', 5), + z('z', 5), + NUM_1('1', 5), + NUM_2('2', 5), + NUM_3('3', 5), + NUM_4('4', 5), + NUM_5('5', 5), + NUM_6('6', 5), + NUM_7('7', 5), + NUM_8('8', 5), + NUM_9('9', 5), + NUM_0('0', 5), + EXCLAMATION_POINT('!', 1), + AT_SYMBOL('@', 6), + NUM_SIGN('#', 5), + DOLLAR_SIGN('$', 5), + PERCENT('%', 5), + UP_ARROW('^', 5), + AMPERSAND('&', 5), + ASTERISK('*', 5), + LEFT_PARENTHESIS('(', 4), + RIGHT_PERENTHESIS(')', 4), + MINUS('-', 5), + UNDERSCORE('_', 5), + PLUS_SIGN('+', 5), + EQUALS_SIGN('=', 5), + LEFT_CURL_BRACE('{', 4), + RIGHT_CURL_BRACE('}', 4), + LEFT_BRACKET('[', 3), + RIGHT_BRACKET(']', 3), + COLON(':', 1), + SEMI_COLON(';', 1), + DOUBLE_QUOTE('"', 3), + SINGLE_QUOTE('\'', 1), + LEFT_ARROW('<', 4), + RIGHT_ARROW('>', 4), + QUESTION_MARK('?', 5), + SLASH('/', 5), + BACK_SLASH('\\', 5), + LINE('|', 1), + TILDE('~', 5), + TICK('`', 2), + PERIOD('.', 1), + COMMA(',', 1), + SPACE(' ', 3), + DEFAULT('a', 4); + + private char character; + private int length; + + DefaultFontInfo(char character, int length) { + this.character = character; + this.length = length; + } + + public char getCharacter() { + return this.character; + } + + public int getLength() { + return this.length; + } + + public int getBoldLength() { + if (this == DefaultFontInfo.SPACE) return this.getLength(); + return this.length + 1; + } + + public static DefaultFontInfo getDefaultFontInfo(char c) { + for (DefaultFontInfo dFI : DefaultFontInfo.values()) { + if (dFI.getCharacter() == c) return dFI; + } + return DefaultFontInfo.DEFAULT; + } +} diff --git a/src/main/java/eu/univento/core/api/customitems/swords/CustomSword.java b/src/main/java/eu/univento/core/api/customitems/swords/CustomSword.java index 946423a..76c1ded 100644 --- a/src/main/java/eu/univento/core/api/customitems/swords/CustomSword.java +++ b/src/main/java/eu/univento/core/api/customitems/swords/CustomSword.java @@ -1,6 +1,5 @@ package eu.univento.core.api.customitems.swords; -import eu.univento.core.api.customitems.swords.CustomSwordManager; import eu.univento.core.api.player.CustomPlayer; import org.bukkit.inventory.ItemStack; diff --git a/src/main/java/eu/univento/core/api/debug/DebugManager.java b/src/main/java/eu/univento/core/api/debug/DebugManager.java deleted file mode 100644 index 533c702..0000000 --- a/src/main/java/eu/univento/core/api/debug/DebugManager.java +++ /dev/null @@ -1,46 +0,0 @@ -package eu.univento.core.api.debug; - -import eu.the5zig.mod.server.The5zigMod; -import eu.the5zig.mod.server.api.ModUser; -import eu.univento.commons.player.Rank; -import eu.univento.core.api.player.CustomPlayer; -import org.bukkit.Bukkit; -import org.bukkit.plugin.Plugin; - -/** - * @author joethei - * @version 0.1 - */ -public class DebugManager { - - private boolean enabled; - - public DebugManager() { - Plugin plugin = Bukkit.getPluginManager().getPlugin("The5zigMod"); - if(plugin.isEnabled()) { - this.enabled = true; - } - } - - public void sendStat(String stat, String score) { - if(enabled) { - for(ModUser user : The5zigMod.getInstance().getUserManager().getOnlineModUsers()) { - CustomPlayer player = CustomPlayer.getPlayer(user.getPlayer()); - if(player.getDatabasePlayer().isAllowed(Rank.JrDeveloper)) { - user.getStatsManager().getStat(stat).setScore(score); - } - } - } - } - - public void sendOverlay(String overlay) { - if(enabled) { - for(ModUser user : The5zigMod.getInstance().getUserManager().getOnlineModUsers()) { - CustomPlayer player = CustomPlayer.getPlayer(user.getPlayer()); - if(player.getDatabasePlayer().isAllowed(Rank.JrDeveloper)) { - user.sendOverlay(overlay); - } - } - } - } -} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/effects/Effects.java b/src/main/java/eu/univento/core/api/effects/Effects.java index 2c0beef..23477ee 100644 --- a/src/main/java/eu/univento/core/api/effects/Effects.java +++ b/src/main/java/eu/univento/core/api/effects/Effects.java @@ -1,10 +1,10 @@ package eu.univento.core.api.effects; import eu.univento.core.Core; -import net.minecraft.server.v1_10_R1.EnumParticle; -import net.minecraft.server.v1_10_R1.PacketPlayOutWorldParticles; +import net.minecraft.server.v1_11_R1.EnumParticle; +import net.minecraft.server.v1_11_R1.PacketPlayOutWorldParticles; import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer; import org.bukkit.entity.Player; /** diff --git a/src/main/java/eu/univento/core/api/entity/EntityModifier.java b/src/main/java/eu/univento/core/api/entity/EntityModifier.java index 6547773..767cb4d 100644 --- a/src/main/java/eu/univento/core/api/entity/EntityModifier.java +++ b/src/main/java/eu/univento/core/api/entity/EntityModifier.java @@ -1,13 +1,13 @@ package eu.univento.core.api.entity; import eu.univento.core.Core; -import net.minecraft.server.v1_10_R1.EntityLiving; -import net.minecraft.server.v1_10_R1.NBTTagCompound; +import net.minecraft.server.v1_11_R1.EntityLiving; +import net.minecraft.server.v1_11_R1.NBTTagCompound; import org.bukkit.Bukkit; import org.bukkit.EntityEffect; import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftCreature; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_11_R1.entity.CraftCreature; +import org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -20,7 +20,7 @@ import java.lang.reflect.Field; public class EntityModifier { private static org.bukkit.entity.Entity entity; private static CraftEntity craftentity; - private static net.minecraft.server.v1_10_R1.Entity entityS; + private static net.minecraft.server.v1_11_R1.Entity entityS; private static int scheduler; private static Plugin plugin = Core.getInstance(); private static Player player = null; @@ -100,7 +100,7 @@ public class EntityModifier { public Builder setInvulnerable(boolean invulnerable) { try { - Field invulnerableField = net.minecraft.server.v1_10_R1.Entity.class.getDeclaredField("invulnerable"); + Field invulnerableField = net.minecraft.server.v1_11_R1.Entity.class.getDeclaredField("invulnerable"); invulnerableField.setAccessible(true); invulnerableField.setBoolean(EntityModifier.entityS, invulnerable); } catch (Exception ex) { diff --git a/src/main/java/eu/univento/core/api/entity/pathfinding/AStar.java b/src/main/java/eu/univento/core/api/entity/pathfinding/AStar.java new file mode 100644 index 0000000..b4bf39c --- /dev/null +++ b/src/main/java/eu/univento/core/api/entity/pathfinding/AStar.java @@ -0,0 +1,323 @@ +/* + * Copyright (c) 2016 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.core.api.entity.pathfinding; + +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.material.Gate; + +import java.util.*; + +/** + * @author Adamk11s + * @version 1.0 + */ +public class AStar { + + private final int sx, sy, sz, ex, ey, ez; + private final World w; + + private PathingResult result; + + private HashMap open = new HashMap<>(); + private HashMap closed = new HashMap<>(); + + private void addToOpenList(Tile t, boolean modify) { + if (open.containsKey(t.getUID())) { + if (modify) { + open.put(t.getUID(), t); + } + } else { + open.put(t.getUID(), t); + } + } + + private void addToClosedList(Tile t) { + if (!closed.containsKey(t.getUID())) { + closed.put(t.getUID(), t); + } + } + + private final int range; + private final String endUID; + + public AStar(Location start, Location end, int range) throws InvalidPathException { + + boolean s = true, e = true; + + if (!(s = this.isLocationWalkable(start)) || !(e = this.isLocationWalkable(end))) { + throw new InvalidPathException(s, e); + } + + this.w = start.getWorld(); + this.sx = start.getBlockX(); + this.sy = start.getBlockY(); + this.sz = start.getBlockZ(); + this.ex = end.getBlockX(); + this.ey = end.getBlockY(); + this.ez = end.getBlockZ(); + + this.range = range; + + short sh = 0; + Tile t = new Tile(sh, sh, sh, null); + t.calculateBoth(sx, sy, sz, ex, ey, ez, true); + this.open.put(t.getUID(), t); + this.processAdjacentTiles(t); + + StringBuilder b = new StringBuilder(); + b.append(ex - sx).append(ey - sy).append(ez - sz); + this.endUID = b.toString(); + } + + public Location getEndLocation() { + return new Location(w, ex, ey, ez); + } + + public PathingResult getPathingResult() { + return this.result; + } + + boolean checkOnce = false; + + private int abs(int i) { + return (i < 0 ? -i : i); + } + + public ArrayList iterate() { + + if (!checkOnce) { + // invert the boolean flag + checkOnce ^= true; + if((abs(sx - ex) > range) || (abs(sy - ey) > range) || (abs(sz - ez) > range)){ + this.result = PathingResult.NO_PATH; + return null;//jump out + } + } + // while not at end + Tile current = null; + + while (canContinue()) { + + // get lowest F cost square on open list + current = this.getLowestFTile(); + + // process tiles + this.processAdjacentTiles(current); + } + + if (this.result != PathingResult.SUCCESS) { + return null; + } else { + // path found + LinkedList routeTrace = new LinkedList<>(); + Tile parent; + + routeTrace.add(current); + + assert current != null; + while ((parent = current.getParent()) != null) { + routeTrace.add(parent); + current = parent; + } + + Collections.reverse(routeTrace); + + return new ArrayList<>(routeTrace); + } + } + + private boolean canContinue() { + // check if open list is empty, if it is no path has been found + if (open.size() == 0) { + this.result = PathingResult.NO_PATH; + return false; + } else { + if (closed.containsKey(this.endUID)) { + this.result = PathingResult.SUCCESS; + return false; + } else { + return true; + } + } + } + + private Tile getLowestFTile() { + double f = 0; + Tile drop = null; + + // get lowest F cost square + for (Tile t : open.values()) { + if (f == 0) { + t.calculateBoth(sx, sy, sz, ex, ey, ez, true); + f = t.getF(); + drop = t; + } else { + t.calculateBoth(sx, sy, sz, ex, ey, ez, true); + double posF = t.getF(); + if (posF < f) { + f = posF; + drop = t; + } + } + } + + // drop from open list and add to closed + + assert drop != null; + this.open.remove(drop.getUID()); + this.addToClosedList(drop); + + return drop; + } + + private boolean isOnClosedList(Tile t) { + return closed.containsKey(t.getUID()); + } + + // pass in the current tile as the parent + private void processAdjacentTiles(Tile current) { + + // set of possible walk to locations adjacent to current tile + HashSet possible = new HashSet<>(26); + + for (byte x = -1; x <= 1; x++) { + for (byte y = -1; y <= 1; y++) { + for (byte z = -1; z <= 1; z++) { + + if (x == 0 && y == 0 && z == 0) { + continue;// don't check current square + } + + Tile t = new Tile((short) (current.getX() + x), (short) (current.getY() + y), (short) (current.getZ() + z), current); + + if (!t.isInRange(this.range)) { + // if block is out of bounds continue + continue; + } + + if (x != 0 && z != 0 && (y == 0 || y == 1)) { + // check to stop jumping through diagonal blocks + Tile xOff = new Tile((short) (current.getX() + x), (short) (current.getY() + y), current.getZ(), current), zOff = new Tile(current.getX(), + (short) (current.getY() + y), (short) (current.getZ() + z), current); + if (!this.isTileWalkable(xOff) && !this.isTileWalkable(zOff)) { + continue; + } + } + + if (this.isOnClosedList(t)) { + // ignore tile + continue; + } + + // only process the tile if it can be walked on + if (this.isTileWalkable(t)) { + t.calculateBoth(sx, sy, sz, ex, ey, ez, true); + possible.add(t); + } + + } + } + } + + for (Tile t : possible) { + // get the reference of the object in the array + Tile openRef; + if ((openRef = this.isOnOpenList(t)) == null) { + // not on open list, so add + this.addToOpenList(t, false); + } else { + // is on open list, check if path to that square is better using + // G cost + if (t.getG() < openRef.getG()) { + // if current path is better, change parent + openRef.setParent(current); + // force updates of F, G and H values. + openRef.calculateBoth(sx, sy, sz, ex, ey, ez, true); + } + + } + } + + } + + private Tile isOnOpenList(Tile t) { + return (open.containsKey(t.getUID()) ? open.get(t.getUID()) : null); + /* + * for (Tile o : open) { if (o.equals(t)) { return o; } } return null; + */ + } + + private boolean isTileWalkable(Tile t) { + Location l = new Location(w, (sx + t.getX()), (sy + t.getY()), (sz + t.getZ())); + Block b = l.getBlock(); + int i = b.getTypeId(); + + // lava, fire, wheat and ladders cannot be walked on, and of course air + // 85, 107 and 113 stops npcs climbing fences and fence gates + if (i != 10 && i != 11 && i != 51 && i != 59 && i != 65 && i != 0 && i != 85 && i != 107 && i != 113 && !canBlockBeWalkedThrough(i)) { + // make sure the blocks above are air + + if (b.getRelative(0, 1, 0).getTypeId() == 107) { + // fench gate check, if closed continue + Gate g = new Gate(b.getRelative(0, 1, 0).getData()); + return (g.isOpen() && (b.getRelative(0, 2, 0).getTypeId() == 0)); + } + return (canBlockBeWalkedThrough(b.getRelative(0, 1, 0).getTypeId()) && b.getRelative(0, 2, 0).getTypeId() == 0); + + } else { + return false; + } + } + + private boolean isLocationWalkable(Location l) { + Block b = l.getBlock(); + int i = b.getTypeId(); + + if (i != 10 && i != 11 && i != 51 && i != 59 && i != 65 && i != 0 && !canBlockBeWalkedThrough(i)) { + // make sure the blocks above are air or can be walked through + return (canBlockBeWalkedThrough(b.getRelative(0, 1, 0).getTypeId()) && b.getRelative(0, 2, 0).getTypeId() == 0); + } else { + return false; + } + } + + private boolean canBlockBeWalkedThrough(int id) { + return (id == 0 || id == 6 || id == 50 || id == 63 || id == 30 || id == 31 || id == 32 || id == 37 || id == 38 || id == 39 || id == 40 || id == 55 || id == 66 || id == 75 + || id == 76 || id == 78); + } + + public class InvalidPathException extends Exception { + + private final boolean s, e; + + public InvalidPathException(boolean s, boolean e) { + this.s = s; + this.e = e; + } + + public String getErrorReason() { + StringBuilder sb = new StringBuilder(); + if (!s) { + sb.append("Start Location was air. "); + } + if (!e) { + sb.append("End Location was air."); + } + return sb.toString(); + } + + public boolean isStartNotSolid() { + return (!s); + } + + public boolean isEndNotSolid() { + return (!e); + } + } + +} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/entity/pathfinding/PathingResult.java b/src/main/java/eu/univento/core/api/entity/pathfinding/PathingResult.java new file mode 100644 index 0000000..30776fb --- /dev/null +++ b/src/main/java/eu/univento/core/api/entity/pathfinding/PathingResult.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2016 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.core.api.entity.pathfinding; + +/** + * @author joethei + * @version 1.0 + */ +public enum PathingResult { + + SUCCESS(0), + NO_PATH(-1); + + private final int ec; + + PathingResult(int ec){ + this.ec = ec; + } + + public int getEndCode(){ + return this.ec; + } + +} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/entity/pathfinding/Tile.java b/src/main/java/eu/univento/core/api/entity/pathfinding/Tile.java new file mode 100644 index 0000000..ca498e5 --- /dev/null +++ b/src/main/java/eu/univento/core/api/entity/pathfinding/Tile.java @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2016 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.core.api.entity.pathfinding; + +import org.bukkit.Location; + +/** + * @author Adamk11s + * @version 1.0 + */ +public class Tile { + + // as offset from starting point + private final short x, y, z; + + private double g = -1, h = -1; + + private Tile parent = null; + + private final String uid; + + public Tile(short x, short y, short z, Tile parent) { + this.x = x; + this.y = y; + this.z = z; + this.parent = parent; + + StringBuilder b = new StringBuilder(); + b.append(x); + b.append(y); + b.append(z); + uid = b.toString(); + + } + + public boolean isInRange(int range){ + return ((range - abs(x) >= 0) && (range - abs(y) >= 0) && (range - abs(z) >= 0)); + } + + public void setParent(Tile parent) { + this.parent = parent; + } + + public Location getLocation(Location start) { + return new Location(start.getWorld(), start.getBlockX() + x, start.getBlockY() + y, start.getBlockZ() + z); + } + + public Tile getParent() { + return this.parent; + } + + public short getX() { + return x; + } + + public int getX(Location i) { + return (i.getBlockX() + x); + } + + public short getY() { + return y; + } + + public int getY(Location i) { + return (i.getBlockY() + y); + } + + public short getZ() { + return z; + } + + public int getZ(Location i) { + return (i.getBlockZ() + z); + } + + public String getUID() { + return this.uid; + } + + public boolean equals(Tile t) { + return (t.getX() == x && t.getY() == y && t.getZ() == z); + } + + public void calculateBoth(int sx, int sy, int sz, int ex, int ey, int ez, boolean update) { + this.calculateG(sx, sy, sz, update); + this.calculateH(sx, sy, sz, ex, ey, ez, update); + } + + public void calculateH(int sx, int sy, int sz, int ex, int ey, int ez, boolean update) { + // only update if h hasn't been calculated or if forced + if ((!update && h == -1) || update) { + int hx = sx + x, hy = sy + y, hz = sz + z; + this.h = this.getEuclideanDistance(hx, hy, hz, ex, ey, ez); + } + } + + // G = the movement cost to move from the starting point A to a given square + // on the grid, following the path generated to get there. + public void calculateG(int sx, int sy, int sz, boolean update) { + + if ((!update && g == -1) || update) { + + // only update if g hasn't been calculated or if forced + Tile currentParent = this.getParent(), currentTile = this; + int gCost = 0; + // follow path back to start + while ((currentParent = currentTile.getParent()) != null) { + + int dx = currentTile.getX() - currentParent.getX(), dy = currentTile.getY() - currentParent.getY(), dz = currentTile.getZ() - currentParent.getZ(); + + dx = abs(dx); + dy = abs(dy); + dz = abs(dz); + + if (dx == 1 && dy == 1 && dz == 1) { + gCost += 1.7; + } else if (((dx == 1 || dz == 1) && dy == 1) || ((dx == 1 || dz == 1) && dy == 0)) { + gCost += 1.4; + } else { + gCost += 1.0; + } + + // move backwards a tile + currentTile = currentParent; + } + this.g = gCost; + } + + } + + public double getG() { + return g; + } + + public double getH() { + return h; + } + + public double getF() { + // f = h + g + return (h + g); + } + + private double getEuclideanDistance(int sx, int sy, int sz, int ex, int ey, int ez) { + double dx = sx - ex, dy = sy - ey, dz = sz - ez; + return Math.sqrt((dx * dx) + (dy * dy) + (dz * dz)); + } + + private int abs(int i) { + return (i < 0 ? -i : i); + } + +} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/fakeplayer/FakePlayer.java b/src/main/java/eu/univento/core/api/fakeplayer/FakePlayer.java index c4aad6c..206f4b7 100644 --- a/src/main/java/eu/univento/core/api/fakeplayer/FakePlayer.java +++ b/src/main/java/eu/univento/core/api/fakeplayer/FakePlayer.java @@ -2,9 +2,9 @@ package eu.univento.core.api.fakeplayer; import com.mojang.authlib.GameProfile; import eu.univento.core.Core; -import net.minecraft.server.v1_10_R1.*; +import net.minecraft.server.v1_11_R1.*; import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; diff --git a/src/main/java/eu/univento/core/api/gui/AnvilGUI.java b/src/main/java/eu/univento/core/api/gui/AnvilGUI.java index 247a475..3374cfc 100644 --- a/src/main/java/eu/univento/core/api/gui/AnvilGUI.java +++ b/src/main/java/eu/univento/core/api/gui/AnvilGUI.java @@ -1,9 +1,9 @@ package eu.univento.core.api.gui; import eu.univento.core.Core; -import net.minecraft.server.v1_10_R1.*; +import net.minecraft.server.v1_11_R1.*; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.HandlerList; diff --git a/src/main/java/eu/univento/core/api/gui/SignInput.java b/src/main/java/eu/univento/core/api/gui/SignInput.java index 3217d51..c4e1565 100644 --- a/src/main/java/eu/univento/core/api/gui/SignInput.java +++ b/src/main/java/eu/univento/core/api/gui/SignInput.java @@ -1,9 +1,9 @@ package eu.univento.core.api.gui; import eu.univento.core.api.player.CustomPlayer; -import net.minecraft.server.v1_10_R1.BlockPosition; -import net.minecraft.server.v1_10_R1.EntityPlayer; -import net.minecraft.server.v1_10_R1.PacketPlayOutOpenSignEditor; +import net.minecraft.server.v1_11_R1.BlockPosition; +import net.minecraft.server.v1_11_R1.EntityPlayer; +import net.minecraft.server.v1_11_R1.PacketPlayOutOpenSignEditor; /** * @author joethei diff --git a/src/main/java/eu/univento/core/api/gui/SignInputHandler.java b/src/main/java/eu/univento/core/api/gui/SignInputHandler.java index 70cffc5..646e13d 100644 --- a/src/main/java/eu/univento/core/api/gui/SignInputHandler.java +++ b/src/main/java/eu/univento/core/api/gui/SignInputHandler.java @@ -3,11 +3,11 @@ package eu.univento.core.api.gui; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToMessageDecoder; -import net.minecraft.server.v1_10_R1.NetworkManager; -import net.minecraft.server.v1_10_R1.Packet; -import net.minecraft.server.v1_10_R1.PacketPlayInUpdateSign; +import net.minecraft.server.v1_11_R1.NetworkManager; +import net.minecraft.server.v1_11_R1.Packet; +import net.minecraft.server.v1_11_R1.PacketPlayInUpdateSign; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import java.lang.reflect.Field; diff --git a/src/main/java/eu/univento/core/api/items/ItemBuilder.java b/src/main/java/eu/univento/core/api/items/ItemBuilder.java index 4c9b5ca..030f923 100644 --- a/src/main/java/eu/univento/core/api/items/ItemBuilder.java +++ b/src/main/java/eu/univento/core/api/items/ItemBuilder.java @@ -34,8 +34,7 @@ public class ItemBuilder { /** * Init item chainable via given Material parameter. * - * @param itemType - * the {@link Material} to initiate the instance with. + * @param itemType the {@link Material} to initiate the instance with. * * @since 1.0 */ @@ -47,8 +46,7 @@ public class ItemBuilder { /** * Init item chainable via given ItemStack parameter. * - * @param itemStack - * the {@link ItemStack} to initialize the instance with. + * @param itemStack the {@link ItemStack} to initialize the instance with. * * @since 1.0 */ @@ -70,8 +68,7 @@ public class ItemBuilder { /** * Changes the Material type of the {@link ItemStack} * - * @param material - * the new {@link Material} to set for the ItemStack. + * @param material the new {@link Material} to set for the ItemStack. * * @return the current instance for chainable application. * @since 1.0 @@ -84,8 +81,7 @@ public class ItemBuilder { /** * Changes the {@link ItemStack}s size. * - * @param itemAmt - * the new Integer count of the ItemStack. + * @param itemAmt the new Integer count of the ItemStack. * * @return the current instance for chainable application. * @since 1.0 @@ -98,8 +94,7 @@ public class ItemBuilder { /** * Changes the {@link ItemStack}s display name. * - * @param name - * the new String for the ItemStack's display name to be set to. + * @param name the new String for the ItemStack's display name to be set to. * * @return the current instance for chainable application. * @since 1.0 @@ -113,8 +108,7 @@ public class ItemBuilder { /** * Adds a line of lore to the {@link ItemStack} * - * @param lore - * String you want to add to the ItemStack's lore. + * @param lore String you want to add to the ItemStack's lore. * * @return the current instance for chainable application. * @since 1.0 @@ -131,8 +125,7 @@ public class ItemBuilder { /** * Clears the {@link ItemStack}s lore and replaces it with the defined String array. * - * @param lores - * String array you want to set the ItemStack's lore to. + * @param lores String array you want to set the ItemStack's lore to. * * @return the current instance for chainable application. * @since 1.0 @@ -146,17 +139,6 @@ public class ItemBuilder { return this; } - /** - * Changes the durability of the current {@link ItemStack} - * - * @return the current instance for chainable application. - * @since 1.0 - */ - public ItemBuilder durability(){ - make().setDurability((short) 3); - return this; - } - public ItemBuilder durability(short durability) { make().setDurability(durability); return this; @@ -165,8 +147,7 @@ public class ItemBuilder { /** * Changes the data value of the {@link ItemStack} * - * @param data - * the new int data value (parsed as byte) to set the ItemStack's durability to. + * @param data the new int data value (parsed as byte) to set the ItemStack's durability to. * * @return the current instance for chainable application. * @since 1.0 @@ -180,11 +161,9 @@ public class ItemBuilder { /** * Adds and UnsafeEnchantment to the {@link ItemStack} with a defined level int value. * - * @param enchantment - * the {@link Enchantment} to add to the ItemStack. + * @param enchantment the {@link Enchantment} to add to the ItemStack. * - * @param level - * the int amount that the Enchantment's level will be set to. + * @param level the int amount that the Enchantment's level will be set to. * * @return the current instance for chainable application. * @since 1.0 @@ -197,8 +176,7 @@ public class ItemBuilder { /** * Adds and UnsafeEnchantment to the {@link} with a level int value of 1. * - * @param enchantment - * the {@link Enchantment} to add to the ItemStack. + * @param enchantment the {@link Enchantment} to add to the ItemStack. * * @return the current instance for chainable application. * @since 1.0 @@ -211,11 +189,9 @@ public class ItemBuilder { /** * Clears all {@link Enchantment}s from the current {@link ItemStack} then adds the defined array of Enchantments to the ItemStack. * - * @param enchantments - * the Enchantment array to replace any current enchantments applied on the ItemStack. + * @param enchantments the Enchantment array to replace any current enchantments applied on the ItemStack. * - * @param level - * the int level value for all Enchantments to be set to. + * @param level the int level value for all Enchantments to be set to. * * @return the current instance for chainable application. * @since 1.0 @@ -231,8 +207,7 @@ public class ItemBuilder { /** * Clears all {@link Enchantment}s from the current {@link ItemStack} then adds the defined array of Enchantments to the ItemStack with a level int value of 1. * - * @param enchantments - * the Enchantment array to replace any current enchantments applied on the ItemStack. + * @param enchantments the Enchantment array to replace any current enchantments applied on the ItemStack. * * @return the current instance for chainable application. * @since 1.0 @@ -248,8 +223,7 @@ public class ItemBuilder { /** * Clears the defined {@link Enchantment} from the {@link ItemStack} * - * @param enchantment - * the Enchantment to remove from the ItemStack. + * @param enchantment the Enchantment to remove from the ItemStack. * * @return the current instance for chainable application. * @since 1.0 @@ -278,8 +252,7 @@ public class ItemBuilder { /** * Clears the defined {@link String} of lore from the {@link ItemStack} * - * @param lore - * the String to be removed from the ItemStack. + * @param lore the String to be removed from the ItemStack. * * @return the current instance for chainable application. * @since 1.0 @@ -307,8 +280,7 @@ public class ItemBuilder { /** * Sets the {@link Color} of any LEATHER_ARMOR {@link Material} types of the {@link ItemStack} * - * @param color - * the Color to set the LEATHER_ARMOR ItemStack to. + * @param color the Color to set the LEATHER_ARMOR ItemStack to. * * @return the current instance for chainable application. * @since 1.0 @@ -346,8 +318,7 @@ public class ItemBuilder { /** * Sets the skullOwner {@link SkullMeta} of the current SKULL_ITEM {@link Material} type {@link ItemStack} * - * @param name - * the {@link String} value to set the SkullOwner meta to for the SKULL_ITEM Material type ItemStack. + * @param name the {@link String} value to set the SkullOwner meta to for the SKULL_ITEM Material type ItemStack. * * @return the current instance for chainable application * @since 1.0 diff --git a/src/main/java/eu/univento/core/api/npc/NPC.java b/src/main/java/eu/univento/core/api/npc/NPC.java index c3d0d6c..3475b2a 100644 --- a/src/main/java/eu/univento/core/api/npc/NPC.java +++ b/src/main/java/eu/univento/core/api/npc/NPC.java @@ -7,9 +7,9 @@ import eu.univento.core.Core; import eu.univento.core.api.player.CustomPlayer; import eu.univento.core.api.utils.GameProfileBuilder; import lombok.Data; -import net.minecraft.server.v1_10_R1.DataWatcher; -import net.minecraft.server.v1_10_R1.PacketPlayOutEntityDestroy; -import net.minecraft.server.v1_10_R1.PacketPlayOutNamedEntitySpawn; +import net.minecraft.server.v1_11_R1.DataWatcher; +import net.minecraft.server.v1_11_R1.PacketPlayOutEntityDestroy; +import net.minecraft.server.v1_11_R1.PacketPlayOutNamedEntitySpawn; import org.bukkit.Bukkit; import org.bukkit.Location; diff --git a/src/main/java/eu/univento/core/api/npc/datawatcher/EnumDataWatcher.java b/src/main/java/eu/univento/core/api/npc/datawatcher/EnumDataWatcher.java index 3a52cfc..aa2ad3d 100644 --- a/src/main/java/eu/univento/core/api/npc/datawatcher/EnumDataWatcher.java +++ b/src/main/java/eu/univento/core/api/npc/datawatcher/EnumDataWatcher.java @@ -1,10 +1,14 @@ package eu.univento.core.api.npc.datawatcher; +import lombok.Getter; + /** * @author ingrim4, joethei * @version 1.0 */ -public enum EnumDataWatcher { +enum EnumDataWatcher { + + //TODO: fix field ENTITY_BITMASK_00("Entity", "ay"),// ENTITY_AIR_01("Entity", "az"),//AIR @@ -23,8 +27,14 @@ public enum EnumDataWatcher { HUMAN_SKIN_12("EntityHuman", ""), HUMAN_HAND_13("EntityHuman", ""); - EnumDataWatcher(String owner, String field) { + @Getter + private String owner; + @Getter + private String field; + EnumDataWatcher(String owner, String field) { + this.owner = owner; + this.field = field; } public Object getObject() { diff --git a/src/main/java/eu/univento/core/api/pet/NMSHandler.java b/src/main/java/eu/univento/core/api/pet/NMSHandler.java index 0a98ca4..9108743 100644 --- a/src/main/java/eu/univento/core/api/pet/NMSHandler.java +++ b/src/main/java/eu/univento/core/api/pet/NMSHandler.java @@ -1,9 +1,9 @@ package eu.univento.core.api.pet; -import net.minecraft.server.v1_10_R1.Entity; -import net.minecraft.server.v1_10_R1.World; +import net.minecraft.server.v1_11_R1.Entity; +import net.minecraft.server.v1_11_R1.World; import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_10_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_11_R1.CraftWorld; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.event.entity.CreatureSpawnEvent; diff --git a/src/main/java/eu/univento/core/api/pet/NMSHelper.java b/src/main/java/eu/univento/core/api/pet/NMSHelper.java index d256790..36f3cb3 100644 --- a/src/main/java/eu/univento/core/api/pet/NMSHelper.java +++ b/src/main/java/eu/univento/core/api/pet/NMSHelper.java @@ -1,7 +1,7 @@ package eu.univento.core.api.pet; -import net.minecraft.server.v1_10_R1.EntityInsentient; -import net.minecraft.server.v1_10_R1.EntityTypes; +import net.minecraft.server.v1_11_R1.EntityInsentient; +import net.minecraft.server.v1_11_R1.EntityTypes; import java.lang.reflect.Field; import java.lang.reflect.Method; diff --git a/src/main/java/eu/univento/core/api/pet/PetType.java b/src/main/java/eu/univento/core/api/pet/PetType.java index c00d27d..9d37f69 100644 --- a/src/main/java/eu/univento/core/api/pet/PetType.java +++ b/src/main/java/eu/univento/core/api/pet/PetType.java @@ -2,9 +2,9 @@ package eu.univento.core.api.pet; import eu.univento.core.api.pet.custom.CustomCreeper; import eu.univento.core.api.pet.custom.CustomPig; -import net.minecraft.server.v1_10_R1.EntityCreeper; -import net.minecraft.server.v1_10_R1.EntityInsentient; -import net.minecraft.server.v1_10_R1.EntityPig; +import net.minecraft.server.v1_11_R1.EntityCreeper; +import net.minecraft.server.v1_11_R1.EntityInsentient; +import net.minecraft.server.v1_11_R1.EntityPig; import org.bukkit.entity.EntityType; import java.util.ArrayList; diff --git a/src/main/java/eu/univento/core/api/pet/custom/CustomCreeper.java b/src/main/java/eu/univento/core/api/pet/custom/CustomCreeper.java index c9ceb05..1d7c080 100644 --- a/src/main/java/eu/univento/core/api/pet/custom/CustomCreeper.java +++ b/src/main/java/eu/univento/core/api/pet/custom/CustomCreeper.java @@ -1,7 +1,7 @@ package eu.univento.core.api.pet.custom; import eu.univento.core.api.pet.PetManager; -import net.minecraft.server.v1_10_R1.*; +import net.minecraft.server.v1_11_R1.*; /** * @author joethei diff --git a/src/main/java/eu/univento/core/api/pet/custom/CustomPig.java b/src/main/java/eu/univento/core/api/pet/custom/CustomPig.java index d1c5613..ba286fe 100644 --- a/src/main/java/eu/univento/core/api/pet/custom/CustomPig.java +++ b/src/main/java/eu/univento/core/api/pet/custom/CustomPig.java @@ -1,7 +1,7 @@ package eu.univento.core.api.pet.custom; import eu.univento.core.api.pet.PetManager; -import net.minecraft.server.v1_10_R1.*; +import net.minecraft.server.v1_11_R1.*; /** * @author joethei diff --git a/src/main/java/eu/univento/core/api/player/BetterPvP.java b/src/main/java/eu/univento/core/api/player/BetterPvP.java index 4c6bfd2..e376ecb 100644 --- a/src/main/java/eu/univento/core/api/player/BetterPvP.java +++ b/src/main/java/eu/univento/core/api/player/BetterPvP.java @@ -2,10 +2,7 @@ package eu.univento.core.api.player; public class BetterPvP { - public BetterPvP() { - } - - public String getCodeString() { + public static String getCodeString() { String toReturn = "§c §r§5 §r§1 §r§f"; String code = String.valueOf(getCodeToSend()); int size = code.length(); @@ -16,7 +13,7 @@ public class BetterPvP { return toReturn; } - private int getCodeToSend() { + private static int getCodeToSend() { int code = 0; code |= 0; int armourStatusMask = 2; diff --git a/src/main/java/eu/univento/core/api/player/CustomPlayer.java b/src/main/java/eu/univento/core/api/player/CustomPlayer.java index 1237db0..1fd6bde 100644 --- a/src/main/java/eu/univento/core/api/player/CustomPlayer.java +++ b/src/main/java/eu/univento/core/api/player/CustomPlayer.java @@ -8,15 +8,15 @@ import eu.univento.commons.player.warn.WarnReason; import eu.univento.core.Core; import eu.univento.core.api.Hologram; import eu.univento.core.api.Utils; +import eu.univento.core.api.chat.DefaultFontInfo; import eu.univento.core.api.effects.Blackscreen; import eu.univento.core.api.effects.Effects; import eu.univento.core.api.languages.Messages; import eu.univento.core.api.server.ServerSettings; -import eu.univento.core.api.server.Servers; import eu.univento.core.api.shop.ShopItem; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; -import net.minecraft.server.v1_10_R1.*; +import net.minecraft.server.v1_11_R1.*; import org.bukkit.*; import org.bukkit.Material; import org.bukkit.World; @@ -27,16 +27,17 @@ import org.bukkit.boss.BarColor; import org.bukkit.boss.BarFlag; import org.bukkit.boss.BarStyle; import org.bukkit.boss.BossBar; -import org.bukkit.craftbukkit.v1_10_R1.CraftServer; -import org.bukkit.craftbukkit.v1_10_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_11_R1.CraftServer; +import org.bukkit.craftbukkit.v1_11_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Team; import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.lang.reflect.Field; @@ -139,7 +140,15 @@ public class CustomPlayer extends CraftPlayer { } public void connectToServer(String server) { - Servers.connectServer(PLAYER, server); + ByteArrayOutputStream b = new ByteArrayOutputStream(); + DataOutputStream out = new DataOutputStream(b); + try { + out.writeUTF("Connect"); + out.writeUTF(server); + } catch (IOException el) { + el.printStackTrace(); + } + sendPluginMessage(Core.getInstance(), "BungeeCord", b.toByteArray()); } public void warn(WarnReason reason, CustomPlayer warner, String proof) { @@ -321,9 +330,45 @@ public class CustomPlayer extends CraftPlayer { return new Messages(this); } + public void sendCentredMessage(Player player, String message) { + if(message == null || message.equals("")) { + player.sendMessage(""); + return; + } + message = ChatColor.translateAlternateColorCodes('&', message); + + int messagePxSize = 0; + boolean previousCode = false; + boolean isBold = false; + + for(char c : message.toCharArray()){ + if(c == '§'){ + previousCode = true; + }else if(previousCode){ + previousCode = false; + isBold = c == 'l' || c == 'L'; + }else{ + DefaultFontInfo dFI = DefaultFontInfo.getDefaultFontInfo(c); + messagePxSize += isBold ? dFI.getBoldLength() : dFI.getLength(); + messagePxSize++; + } + } + int CENTER_PX = 154; + int halvedMessageSize = messagePxSize / 2; + int toCompensate = CENTER_PX - halvedMessageSize; + int spaceLength = DefaultFontInfo.SPACE.getLength() + 1; + int compensated = 0; + StringBuilder sb = new StringBuilder(); + while(compensated < toCompensate){ + sb.append(" "); + compensated += spaceLength; + } + sendMessage(sb.toString() + message); + } + public void strikeLightning(Location loc) { World nmsWorld = (World) ((CraftWorld) loc.getWorld()).getHandle(); - EntityLightning lightning = new EntityLightning((net.minecraft.server.v1_10_R1.World) nmsWorld, loc.getX(), loc.getY(), loc.getZ(), true); + EntityLightning lightning = new EntityLightning((net.minecraft.server.v1_11_R1.World) nmsWorld, loc.getX(), loc.getY(), loc.getZ(), true); sendPacket(new PacketPlayOutSpawnEntityWeather(lightning)); playSound(loc, Sound.ENTITY_LIGHTNING_IMPACT, 20.0F, 1.0F); playSound(loc, Sound.ENTITY_LIGHTNING_THUNDER, 20.0F, 1.0F); @@ -429,7 +474,7 @@ public class CustomPlayer extends CraftPlayer { if(loc.getBlock().getType() != Material.CHEST) return; byte dataByte = (open) ? (byte) 1 : 0; BlockPosition position = new BlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); - PacketPlayOutBlockAction blockActionPacket = new PacketPlayOutBlockAction(position, net.minecraft.server.v1_10_R1.Block.getById(loc.getBlock().getTypeId()), (byte) 1, dataByte); + PacketPlayOutBlockAction blockActionPacket = new PacketPlayOutBlockAction(position, net.minecraft.server.v1_11_R1.Block.getById(loc.getBlock().getTypeId()), (byte) 1, dataByte); sendPacket(blockActionPacket); } diff --git a/src/main/java/eu/univento/core/api/player/NickName.java b/src/main/java/eu/univento/core/api/player/NickName.java index 67dcd53..bcc5a35 100644 --- a/src/main/java/eu/univento/core/api/player/NickName.java +++ b/src/main/java/eu/univento/core/api/player/NickName.java @@ -8,11 +8,16 @@ import java.util.Random; * @author joethei * @version 1.1 */ + public class NickName { - /** + + /** * gets random Nickname * @return String */ + + //FIXME: change to users from ban list + @Deprecated public static String getRandomNick() { ArrayList names = new ArrayList<>(); names.add("GommeHD"); diff --git a/src/main/java/eu/univento/core/api/schematic/Cuboid.java b/src/main/java/eu/univento/core/api/schematic/Cuboid.java index 05f2a39..2dd2a37 100644 --- a/src/main/java/eu/univento/core/api/schematic/Cuboid.java +++ b/src/main/java/eu/univento/core/api/schematic/Cuboid.java @@ -11,7 +11,7 @@ import java.util.stream.Collectors; /** * @author desht (Original code), KingFaris10 (Editor of code) - * @version 0.1 + * @version 1.0 */ public class Cuboid implements Cloneable, ConfigurationSerializable, Iterable { @@ -66,7 +66,7 @@ public class Cuboid implements Cloneable, ConfigurationSerializable, Iterable channelFuture = (List) FIELD_SERVERCONNECTION_CHANNELFUTURE.get(connection); @@ -132,7 +132,7 @@ public class NettyInjection { } } - private final void unregisterGlobalChannel() { + private void unregisterGlobalChannel() { for (Channel global : this.globalChannel) { final ChannelPipeline pipe = global.pipeline(); global.eventLoop().execute(() -> pipe.remove("NettyInjectionGlobal")); @@ -148,15 +148,15 @@ public class NettyInjection { this.handlerList.remove(name); } - public final void inject(Player player) { + private void inject(Player player) { this.injectChannel(this.getChannel(player)).player = player; } - public final void uninject(Player player) { + private void uninject(Player player) { this.uninjectChannel(this.getChannel(player)); } - private final Channel getChannel(Player player) { + private Channel getChannel(Player player) { Channel channel = this.playerChannel.get(player.getName()); if (channel == null) { channel = FIELD_NETWORKMANAGER_CHANNEL.get(FIELD_PLAYERCONNECTION_NETWORKMANAGER.get(FIELD_ENTITYPLAYER_PLAYERCONNECTION.get(FIELD_CRAFTPLAYER_ENTITY.get(player)))); @@ -165,7 +165,7 @@ public class NettyInjection { return channel; } - private final PacketInjection injectChannel(Channel channel) { + private PacketInjection injectChannel(Channel channel) { try { PacketInjection handel = (PacketInjection) channel.pipeline().get(this.handlerName); if (handel == null) { @@ -178,7 +178,7 @@ public class NettyInjection { } } - private final void uninjectChannel(Channel channel) { + private void uninjectChannel(Channel channel) { Object handel = channel.pipeline().get(this.handlerName); if (handel != null) channel.pipeline().remove(this.handlerName); @@ -196,6 +196,7 @@ public class NettyInjection { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + assert CLASS_PACKERLOGININSTART != null; if (CLASS_PACKERLOGININSTART.isInstance(msg)) NettyInjection.this.playerChannel.put(FIELD_GAMEPROFILE_NAME.get(FIELD_PACKERLOGININSTART_GAMEPROFILE.get(msg)), ctx.channel()); for (PacketHandler handel : NettyInjection.this.handlerList.values()) { diff --git a/src/main/java/eu/univento/core/api/utils/RandomCollection.java b/src/main/java/eu/univento/core/api/utils/RandomCollection.java index cd99bae..162def1 100644 --- a/src/main/java/eu/univento/core/api/utils/RandomCollection.java +++ b/src/main/java/eu/univento/core/api/utils/RandomCollection.java @@ -4,8 +4,7 @@ import java.util.NavigableMap; import java.util.Random; import java.util.TreeMap; -class RandomCollection -{ +class RandomCollection { private final NavigableMap map = new TreeMap<>(); private final Random random; private double total = 0.0D; diff --git a/src/main/java/eu/univento/core/api/utils/UUIDFetcher.java b/src/main/java/eu/univento/core/api/utils/UUIDFetcher.java index 33be615..508a060 100644 --- a/src/main/java/eu/univento/core/api/utils/UUIDFetcher.java +++ b/src/main/java/eu/univento/core/api/utils/UUIDFetcher.java @@ -1,5 +1,9 @@ package eu.univento.core.api.utils; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.mojang.util.UUIDTypeAdapter; + import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; @@ -11,12 +15,9 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.function.Consumer; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.mojang.util.UUIDTypeAdapter; - /** * @author Jofkos + * @version 1.0 */ public class UUIDFetcher{ diff --git a/src/main/java/eu/univento/core/api/utils/Vectors.java b/src/main/java/eu/univento/core/api/utils/Vectors.java index 617978c..96b3e44 100644 --- a/src/main/java/eu/univento/core/api/utils/Vectors.java +++ b/src/main/java/eu/univento/core/api/utils/Vectors.java @@ -2,44 +2,44 @@ package eu.univento.core.api.utils; import org.bukkit.util.Vector; -final class Vectors -{ - private static Vector rotateAroundAxisX(Vector v, double angle) - { - double cos = Math.cos(angle); - double sin = Math.sin(angle); - double y = v.getY() * cos - v.getZ() * sin; - double z = v.getY() * sin + v.getZ() * cos; - return v.setY(y).setZ(z); - } +/** + * @author joethei + * @version 1.0 + */ - private static Vector rotateAroundAxisY(Vector v, double angle) - { - double cos = Math.cos(angle); - double sin = Math.sin(angle); - double x = v.getX() * cos + v.getZ() * sin; - double z = v.getX() * -sin + v.getZ() * cos; - return v.setX(x).setZ(z); - } +final class Vectors { + private static Vector rotateAroundAxisX(Vector v, double angle) { + double cos = Math.cos(angle); + double sin = Math.sin(angle); + double y = v.getY() * cos - v.getZ() * sin; + double z = v.getY() * sin + v.getZ() * cos; + return v.setY(y).setZ(z); + } - private static Vector rotateAroundAxisZ(Vector v, double angle) - { - double cos = Math.cos(angle); - double sin = Math.sin(angle); - double x = v.getX() * cos - v.getY() * sin; - double y = v.getX() * sin + v.getY() * cos; - return v.setX(x).setY(y); - } + private static Vector rotateAroundAxisY(Vector v, double angle) { + double cos = Math.cos(angle); + double sin = Math.sin(angle); + double x = v.getX() * cos + v.getZ() * sin; + double z = v.getX() * -sin + v.getZ() * cos; + return v.setX(x).setZ(z); + } - public static Vector rotateVector(Vector v, double angleX, double angleY, double angleZ) - { - rotateAroundAxisX(v, angleX); - rotateAroundAxisY(v, angleY); - rotateAroundAxisZ(v, angleZ); - return v; - } + private static Vector rotateAroundAxisZ(Vector v, double angle) { + double cos = Math.cos(angle); + double sin = Math.sin(angle); + double x = v.getX() * cos - v.getY() * sin; + double y = v.getX() * sin + v.getY() * cos; + return v.setX(x).setY(y); + } - public static double angleToXAxis(Vector vector) { - return Math.atan2(vector.getX(), vector.getY()); - } + public static Vector rotateVector(Vector v, double angleX, double angleY, double angleZ) { + rotateAroundAxisX(v, angleX); + rotateAroundAxisY(v, angleY); + rotateAroundAxisZ(v, angleZ); + return v; + } + + public static double angleToXAxis(Vector vector) { + return Math.atan2(vector.getX(), vector.getY()); + } } \ No newline at end of file diff --git a/src/main/java/eu/univento/core/commands/Nick.java b/src/main/java/eu/univento/core/commands/Nick.java index a6a4fbe..30a37fb 100644 --- a/src/main/java/eu/univento/core/commands/Nick.java +++ b/src/main/java/eu/univento/core/commands/Nick.java @@ -28,7 +28,6 @@ public class Nick extends AutoCommand{ super(plugin, command, description, aliases); } - @SuppressWarnings("deprecation") @Override public boolean execute(CommandSender sender, String label, String[] args) { if(sender instanceof Player) { diff --git a/src/main/java/eu/univento/core/commands/SetRank.java b/src/main/java/eu/univento/core/commands/SetRank.java index 44836e9..a3ef373 100644 --- a/src/main/java/eu/univento/core/commands/SetRank.java +++ b/src/main/java/eu/univento/core/commands/SetRank.java @@ -17,6 +17,7 @@ import java.util.stream.Collectors; * @author joethei * @version 1.0 */ + public class SetRank extends AutoCommand{ public SetRank(Core plugin, String command, String description, String... aliases) { diff --git a/src/main/java/eu/univento/core/commands/SystemInfo.java b/src/main/java/eu/univento/core/commands/SystemInfo.java index 84705a6..ad26575 100644 --- a/src/main/java/eu/univento/core/commands/SystemInfo.java +++ b/src/main/java/eu/univento/core/commands/SystemInfo.java @@ -27,6 +27,7 @@ public class SystemInfo extends AutoCommand{ * @param description describes the commons * @param aliases aliases of commons */ + public SystemInfo(Core plugin, String command, String description, String... aliases) { super(plugin, command, description, aliases); } diff --git a/src/main/java/eu/univento/core/commands/Timeout.java b/src/main/java/eu/univento/core/commands/Timeout.java index fd88d1d..5da1663 100644 --- a/src/main/java/eu/univento/core/commands/Timeout.java +++ b/src/main/java/eu/univento/core/commands/Timeout.java @@ -16,6 +16,7 @@ import java.util.List; * @author joethei * @version 0.1 */ + public class Timeout extends AutoCommand { public Timeout(Core plugin, String command, String description, String... aliases) { diff --git a/src/main/java/eu/univento/core/commands/Vanish.java b/src/main/java/eu/univento/core/commands/Vanish.java index 01877cb..47ee37c 100644 --- a/src/main/java/eu/univento/core/commands/Vanish.java +++ b/src/main/java/eu/univento/core/commands/Vanish.java @@ -17,6 +17,7 @@ import java.util.List; * @author joethei * @version 1.0 */ + public class Vanish extends AutoCommand{ /** diff --git a/src/main/java/eu/univento/core/listeners/Blocks.java b/src/main/java/eu/univento/core/listeners/Blocks.java index b7b4af0..3fbae4d 100644 --- a/src/main/java/eu/univento/core/listeners/Blocks.java +++ b/src/main/java/eu/univento/core/listeners/Blocks.java @@ -14,6 +14,7 @@ import org.bukkit.event.block.BlockPlaceEvent; * @author joethei * @version 1.0 */ + public class Blocks implements Listener{ /** diff --git a/src/main/java/eu/univento/core/listeners/Chat.java b/src/main/java/eu/univento/core/listeners/Chat.java index 836ca8e..b3329f9 100644 --- a/src/main/java/eu/univento/core/listeners/Chat.java +++ b/src/main/java/eu/univento/core/listeners/Chat.java @@ -34,6 +34,7 @@ import java.util.Map; * @author joethei * @version 1.0 */ + public class Chat implements Listener { private List players = new LinkedList<>(); diff --git a/src/main/java/eu/univento/core/listeners/Commands.java b/src/main/java/eu/univento/core/listeners/Commands.java index 11476f4..4341ddc 100644 --- a/src/main/java/eu/univento/core/listeners/Commands.java +++ b/src/main/java/eu/univento/core/listeners/Commands.java @@ -16,6 +16,7 @@ import org.bukkit.help.HelpTopic; * @author joethei * @version 1.0 */ + public class Commands implements Listener{ diff --git a/src/main/java/eu/univento/core/listeners/Events.java b/src/main/java/eu/univento/core/listeners/Events.java index 602df17..64b5569 100644 --- a/src/main/java/eu/univento/core/listeners/Events.java +++ b/src/main/java/eu/univento/core/listeners/Events.java @@ -22,8 +22,9 @@ import org.bukkit.util.Vector; * some basic events * * @author joethei - * @version 0.2 + * @version 1.0 */ + public class Events implements Listener { @EventHandler @@ -43,6 +44,7 @@ public class Events implements Listener { if (p.getLocation().getY() <= 0) { p.setVelocity(new Vector().setY(10.0D).multiply(1.0D)); p.setGliding(true); + } } @@ -90,4 +92,5 @@ public class Events implements Listener { } } } + } \ No newline at end of file diff --git a/src/main/java/eu/univento/core/listeners/JoinQuit.java b/src/main/java/eu/univento/core/listeners/JoinQuit.java index ab48fb0..b5412e3 100644 --- a/src/main/java/eu/univento/core/listeners/JoinQuit.java +++ b/src/main/java/eu/univento/core/listeners/JoinQuit.java @@ -12,10 +12,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerKickEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.player.PlayerResourcePackStatusEvent; +import org.bukkit.event.player.*; import org.bukkit.scoreboard.Team; import java.io.ByteArrayOutputStream; @@ -34,13 +31,17 @@ public class JoinQuit implements Listener { private List firstJoin = new LinkedList<>(); private List loading = new LinkedList<>(); + @EventHandler + public void onPreLogin(AsyncPlayerPreLoginEvent e) { + if(!Core.getCommons().getSecurityHandler().isValidServer(e.getAddress().getHostAddress())) { + e.setKickMessage("Im sorry, you can only join from our official IP: play.univento.eu"); + e.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_BANNED); + } + } + @EventHandler public void onJoin(PlayerJoinEvent e) { CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); - if(!p.hasPlayedBefore()) { - - } - for (Player players : Bukkit.getOnlinePlayers()) { CustomPlayer player = CustomPlayer.getPlayer(players); if (Vanish.getPlayers().contains(player)) @@ -64,7 +65,7 @@ public class JoinQuit implements Listener { labyModFeatures.put(LabyMod.EXTRAS, false); p.setLabyModFeatures(labyModFeatures); - p.sendMessage(new BetterPvP().getCodeString()); + p.sendMessage(BetterPvP.getCodeString()); //disable code for minimap mod p.sendMessage("§A§n§t§i§M§i§n§i§m§a§p"); @@ -90,7 +91,6 @@ public class JoinQuit implements Listener { //p.setStoryResourcePack(); loading.add(p); - } @EventHandler diff --git a/src/main/java/eu/univento/core/listeners/NPCEvents.java b/src/main/java/eu/univento/core/listeners/NPCEvents.java index fe35e6d..2d337a7 100644 --- a/src/main/java/eu/univento/core/listeners/NPCEvents.java +++ b/src/main/java/eu/univento/core/listeners/NPCEvents.java @@ -6,6 +6,7 @@ import org.bukkit.event.Listener; * @author joethei * @version 0.1 */ + public class NPCEvents implements Listener { } \ No newline at end of file diff --git a/src/main/java/eu/univento/core/listeners/PluginMessenger.java b/src/main/java/eu/univento/core/listeners/PluginMessenger.java index 6597471..3656856 100644 --- a/src/main/java/eu/univento/core/listeners/PluginMessenger.java +++ b/src/main/java/eu/univento/core/listeners/PluginMessenger.java @@ -10,11 +10,27 @@ import org.bukkit.plugin.messaging.PluginMessageListener; import java.io.UnsupportedEncodingException; +/** + * @author joethei + * @version 1.0 + */ + public class PluginMessenger implements PluginMessageListener { @Override public void onPluginMessageReceived(String channel, Player player, byte[] data) { CustomPlayer p = CustomPlayer.getPlayer(player); + String string = null; + try { + string = new String (data, "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + assert string != null; + if(string.endsWith("squidhq")) { + p.warn(WarnReason.SPAM, null, "https://players.univento.eu/" + p.getUniqueId().toString() + "/hacks"); + } + if (channel.equals("WDL|INIT")) { String version = null; if(data.length == 0) version = "vor 1.8d"; @@ -27,41 +43,47 @@ public class PluginMessenger implements PluginMessageListener { p.sendMessage(p.getDatabasePlayer().getLanguage().getWord("Prefix") + p.getDatabasePlayer().getLanguage().getWord("Hack.WorldDownloader")); } if(channel.equals("WDL|CONTROL")) { - p.sendPluginMessage(Core.getInstance(), "WDL|CONTROL", createWDLPacket(0, false, false, false, false)); + ByteArrayDataOutput output = ByteStreams.newDataOutput(); + + output.writeInt(1); + + output.writeBoolean(false); + output.writeInt(0); + output.writeBoolean(false); + output.writeBoolean(false); + output.writeBoolean(false); + output.writeBoolean(false); + + p.sendPluginMessage(Core.getInstance(), "WDL|CONTROL", output.toByteArray()); } - if (channel.equals("PERMISSIONSREPL") && new String(data).contains("mod.worlddownloader")) { + if (channel.equals("PERMISSIONSREPL") && string.contains("mod.worlddownloader")) { //TODO: change to real warn reason p.warn(WarnReason.SPAM, null, "https://players.univento.eu/" + p.getUniqueId().toString() + "/hacks"); p.sendMessage(p.getDatabasePlayer().getLanguage().getWord("Prefix") + p.getDatabasePlayer().getLanguage().getWord("Hack.WorldDownloader")); } if(channel.equals("5zig_Set")) { - try { - String version = new String(data, "UTF-8"); - Core.getCommons().getLoggingHandler().getCore().info(p.getName() + " hat den 5zig Mod Version : " + version); - //https://gist.github.com/5zig/35e0854504edda418f4b shows why - ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput(); - dataOutput.writeByte(0x01 | 0x02 | 0x02 | 0x04 | 0x08 | 0x010); - p.sendPluginMessage(Core.getInstance(), "5zig_Set", dataOutput.toByteArray()); - p.sendPluginMessage(Core.getInstance(), "5zig_Set", new byte[]{0x01 | 0x02 | 0x04 | 0x08 | 0x10}); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } + //https://gist.github.com/5zig/35e0854504edda418f4b shows why its done that way + + ByteArrayDataOutput output1 = ByteStreams.newDataOutput(); + output1.write(0x01); + p.sendPluginMessage(Core.getInstance(), "5zig_Set", output1.toByteArray()); + + ByteArrayDataOutput output2 = ByteStreams.newDataOutput(); + output2.write(0x02); + p.sendPluginMessage(Core.getInstance(), "5zig_Set", output2.toByteArray()); + + ByteArrayDataOutput output3 = ByteStreams.newDataOutput(); + output3.write(0x04); + p.sendPluginMessage(Core.getInstance(), "5zig_Set", output3.toByteArray()); + + ByteArrayDataOutput output4 = ByteStreams.newDataOutput(); + output4.write(0x08); + p.sendPluginMessage(Core.getInstance(), "5zig_Set", output4.toByteArray()); + + ByteArrayDataOutput output5 = ByteStreams.newDataOutput(); + output5.write(0x10); + p.sendPluginMessage(Core.getInstance(), "5zig_Set", output5.toByteArray()); + } } - - //TODO: - private byte[] createWDLPacket(int saveRadius, boolean cacheChunks, boolean saveEntities, boolean saveTileEntities, boolean saveContainers) { - ByteArrayDataOutput output = ByteStreams.newDataOutput(); - - output.writeInt(1); - - output.writeBoolean(cacheChunks); - output.writeInt(saveRadius); - output.writeBoolean(saveEntities); - output.writeBoolean(saveTileEntities); - output.writeBoolean(saveContainers); - output.writeBoolean(false); - - return output.toByteArray(); - } } diff --git a/src/main/java/eu/univento/core/listeners/WeaponEvents.java b/src/main/java/eu/univento/core/listeners/WeaponEvents.java index 070af27..3b5aed3 100644 --- a/src/main/java/eu/univento/core/listeners/WeaponEvents.java +++ b/src/main/java/eu/univento/core/listeners/WeaponEvents.java @@ -10,7 +10,7 @@ import org.bukkit.event.player.PlayerInteractEvent; /** * @author joethei - * @version 0.1 + * @version 1.0 */ public class WeaponEvents implements Listener {