From b53720692fd4c80570f85df87e01bff99faaf07e Mon Sep 17 00:00:00 2001 From: BuildTools Date: Thu, 7 Sep 2017 22:36:54 +0200 Subject: [PATCH] + custom advancements + camera movements + custom items + attribute modification + easy gui creation - cleanup --- .gitignore | 3 +- .gitlab-ci.yml | 8 - .gitlab/settings.xml | 18 - Core.iml | 50 +- pom.xml | 58 ++- src/main/java/eu/univento/core/Core.java | 103 ++++- .../eu/univento/core/antihack/AntiHack.java | 5 + .../java/eu/univento/core/antihack/Hack.java | 5 + .../core/antihack/modules/AutoClicker.java | 5 + .../core/antihack/modules/AutoRespawn.java | 5 + .../core/antihack/modules/AutoSoup.java | 5 + .../core/antihack/modules/BowAimbot.java | 5 + .../core/antihack/modules/Criticals.java | 5 + .../core/antihack/modules/FastPlace.java | 5 + .../core/antihack/modules/Movement.java | 5 + .../univento/core/antihack/modules/Nuker.java | 5 + .../core/antihack/modules/Packets.java | 5 + .../univento/core/antihack/modules/Reach.java | 5 + .../univento/core/antihack/modules/Regen.java | 5 + .../core/antihack/modules/SelfHit.java | 14 + .../eu/univento/core/api/AutoCommand.java | 5 + .../java/eu/univento/core/api/Config.java | 6 + .../java/eu/univento/core/api/Hologram.java | 17 +- src/main/java/eu/univento/core/api/Utils.java | 177 -------- .../core/api/advancement/Advancement.java | 179 ++++++++ .../api/advancement/CustomAdvancement.java | 49 ++ .../univento/core/api/blocks/MiniBlock.java | 5 + .../core/api/blocks/banners/BannerColor.java | 5 + .../core/api/blocks/banners/BannerString.java | 5 + .../core/api/blocks/banners/FloatingText.java | 5 + .../core/api/blocks/banners/Shape.java | 5 + .../api/blocks/banners/ShapeRegistry.java | 5 + .../Camera.java => camera/CameraUtil.java} | 68 +-- .../univento/core/api/camera/Traveller.java | 141 ++++++ .../core/api/chat/DefaultFontInfo.java | 2 +- .../core/api/cloud/CloudApiWrapper.java | 54 +++ .../core/api/command/BukkitCommand.java | 5 + .../core/api/command/BukkitCompleter.java | 5 + .../eu/univento/core/api/command/Command.java | 23 +- .../core/api/command/CommandArgs.java | 22 +- .../core/api/command/CommandFramework.java | 7 +- .../univento/core/api/command/Completer.java | 5 + .../core/api/customitems/CustomArmor.java | 5 + .../core/api/customitems/CustomItem.java | 24 + .../api/customitems/CustomItemActions.java | 26 ++ .../api/customitems/CustomItemManager.java | 5 + .../core/api/customitems/CustomItems.java | 44 ++ .../univento/core/api/customitems/Rarity.java | 29 ++ .../actions/InteractBlockAction.java | 20 + .../actions/InteractPlayerAction.java | 17 + .../customitems/actions/PlayerHitAction.java | 18 + .../api/customitems/swords/CustomSword.java | 35 +- .../swords/CustomSwordManager.java | 25 +- .../core/api/effects/Blackscreen.java | 43 +- .../eu/univento/core/api/effects/Effects.java | 11 +- .../core/api/effects/ParticleEffect.java | 5 + .../api/effects/ParticleWorldBoarder.java | 11 +- .../core/api/entity/ArmorStandAnimator.java | 32 +- .../core/api/entity/EntityModifier.java | 17 +- .../core/api/entity/pathfinding/AStar.java | 2 +- .../api/entity/pathfinding/PathingResult.java | 4 +- .../core/api/entity/pathfinding/Tile.java | 2 +- .../core/api/events/BorderLeaveEvent.java | 5 + .../core/api/events/HologramClickEvent.java | 4 +- .../core/api/events/MoveEventFilter.java | 5 + .../univento/core/api/game/PlayerManager.java | 7 +- .../java/eu/univento/core/api/game/Team.java | 40 +- .../univento/core/api/game/TeamManager.java | 7 +- .../java/eu/univento/core/api/gui/Action.java | 17 + .../eu/univento/core/api/gui/AnvilGUI.java | 9 +- .../univento/core/api/gui/InventoryGUI.java | 58 +++ .../eu/univento/core/api/gui/SignInput.java | 21 - .../core/api/gui/hologram/HologramData.java | 2 +- .../core/api/gui/hologram/HologramGUI.java | 2 +- .../components/ComponentPosition.java | 2 +- .../components/ComponentProperties.java | 2 +- .../gui/hologram/components/GUIComponent.java | 2 +- .../api/gui/hologram/components/GUIPage.java | 2 +- .../gui/hologram/components/GUIPageModel.java | 2 +- .../gui/hologram/components/IValueHolder.java | 2 +- .../components/PlayerGUIComponent.java | 2 +- .../hologram/components/PlayerGUIPage.java | 2 +- .../components/PlayerGUIPageModel.java | 2 +- .../components/PlayerGUITextBoxComponent.java | 2 +- .../PlayerGUIValueBoxComponent.java | 2 +- .../components/StationaryPlayerGUIPage.java | 2 +- .../gui/{ => sign}/PlayerSignInputEvent.java | 8 +- .../univento/core/api/gui/sign/SignInput.java | 67 +++ .../api/gui/{ => sign}/SignInputHandler.java | 23 +- .../univento/core/api/hologram/Hologram.java | 10 +- .../core/api/hologram/HologramManager.java | 4 +- .../core/api/items/ClickInventory.java | 238 ---------- .../core/api/items/InventoryManager.java | 94 ---- .../univento/core/api/items/ItemBuilder.java | 201 +++++---- .../core/api/items/NamedInventory.java | 205 --------- .../java/eu/univento/core/api/items/Page.java | 59 --- .../core/api/items/PageInventory.java | 328 -------------- .../univento/core/api/items/PageLayout.java | 58 --- .../eu/univento/core/api/items/Pagifier.java | 5 + .../core/api/items/ScrollingInventory.java | 120 ----- .../core/api/items/attribute/Attribute.java | 33 ++ .../items/attribute/AttributeModifier.java | 57 +++ .../api/items/attribute/ItemAttributes.java | 66 +++ .../core/api/items/attribute/ItemSlot.java | 29 ++ .../core/api/items/events/ItemClickEvent.java | 60 --- .../api/items/events/NamedCloseEvent.java | 40 -- .../api/items/events/NamedPageClickEvent.java | 56 --- .../core/api/items/events/PageCloseEvent.java | 40 -- .../api/items/events/PagesClickEvent.java | 49 -- .../core/api/items/events/PagesTurnEvent.java | 55 --- .../java/eu/univento/core/api/map/Map.java | 5 + .../eu/univento/core/api/map/MapDatabase.java | 5 + .../univento/core/api/map/MapDownloader.java | 5 + .../eu/univento/core/api/map/MapVoting.java | 13 +- .../java/eu/univento/core/api/npc/NPC.java | 16 +- .../eu/univento/core/api/npc/NPCChannel.java | 5 + .../core/api/npc/NPCNetworkManager.java | 9 +- .../core/api/npc/NPCPlayerConnection.java | 13 +- .../eu/univento/core/api/pet/NMSHandler.java | 41 -- .../eu/univento/core/api/pet/NMSHelper.java | 40 -- .../eu/univento/core/api/pet/PetManager.java | 12 - .../eu/univento/core/api/pet/PetType.java | 86 ---- .../core/api/pet/custom/CustomCreeper.java | 67 --- .../core/api/pet/custom/CustomPig.java | 66 --- .../univento/core/api/player/BetterPvP.java | 13 +- .../core/api/player/CustomPlayer.java | 426 ++++++++++-------- .../eu/univento/core/api/player/LabyMod.java | 7 +- .../eu/univento/core/api/player/NickName.java | 5 + .../core/api/player/NickedPlayer.java | 5 + .../eu/univento/core/api/player/Skin.java | 5 + .../core/api/player/SpectateManager.java | 5 + .../univento/core/api/player/Spectator.java | 36 +- .../univento/core/api/schematic/Cuboid.java | 18 +- .../core/api/schematic/Schematic.java | 5 + .../core/api/schematic/SchematicManager.java | 5 + .../eu/univento/core/api/server/GameInfo.java | 34 -- .../core/api/server/MojangService.java | 5 + .../univento/core/api/server/NetworkData.java | 56 --- .../core/api/server/ServerDatabase.java | 55 --- .../core/api/server/ServerPinger.java | 164 ------- .../core/api/server/ServerSettings.java | 15 +- .../eu/univento/core/api/shop/PayType.java | 21 - .../univento/core/api/shop/ShopCategory.java | 16 +- .../eu/univento/core/api/shop/ShopItem.java | 36 +- .../eu/univento/core/api/shop/ShopMenu.java | 24 +- .../core/api/shop/entity/ShopEntity.java | 7 +- .../core/api/shop/entity/ShopIronGolem.java | 5 + .../core/api/shop/entity/ShopVillager.java | 5 + .../univento/core/api/story/StoryMission.java | 5 + .../core/api/story/StoryMissionStatus.java | 5 + .../core/api/story/StoryMissions.java | 5 + .../core/api/update/PluginUpdater.java | 55 --- .../eu/univento/core/api/utils/Direction.java | 5 + .../core/api/utils/GameProfileBuilder.java | 5 + .../eu/univento/core/api/utils/Lamps.java | 5 + .../eu/univento/core/api/utils/Maths.java | 5 + .../core/api/utils/NettyInjection.java | 5 + .../core/api/utils/RandomCollection.java | 5 + .../univento/core/api/utils/UUIDFetcher.java | 5 + .../eu/univento/core/api/utils/Vectors.java | 5 + .../api/utils/reflection/ArrayWrapper.java | 5 + .../api/utils/reflection/IReflection.java | 5 + .../api/utils/reflection/ReflectionUtils.java | 5 + .../univento/core/api/world/WorldReset.java | 2 +- .../univento/core/commands/AdminCommands.java | 60 +++ .../core/commands/BuilderCommands.java | 5 + .../univento/core/commands/DevCommands.java | 7 +- .../core/commands/HologramCommands.java | 5 + .../univento/core/commands/ModCommands.java | 33 ++ .../core/commands/PlayerCommands.java | 5 + .../eu/univento/core/commands/SetRank.java | 5 + .../univento/core/commands/VIPCommands.java | 5 + .../closecombat/CloseCombatEvents.java | 101 +++++ .../weapons/closecombat/ThiefsDagger.java} | 29 +- .../eu/univento/core/listeners/Blocks.java | 5 + .../java/eu/univento/core/listeners/Chat.java | 5 + .../eu/univento/core/listeners/Commands.java | 5 + .../eu/univento/core/listeners/Events.java | 7 +- .../eu/univento/core/listeners/JoinQuit.java | 26 +- .../eu/univento/core/listeners/NPCEvents.java | 20 +- .../core/listeners/PluginMessenger.java | 7 +- .../core/listeners/SpectatorEvents.java | 38 +- .../univento/core/listeners/WeaponEvents.java | 5 + .../core/listeners/WorkbenchEvents.java | 19 +- .../core/listeners/cloud/CloudNet.java | 16 + .../core/listeners/cloud/Servers.java | 34 ++ 186 files changed, 2491 insertions(+), 3029 deletions(-) delete mode 100644 .gitlab-ci.yml delete mode 100644 .gitlab/settings.xml delete mode 100644 src/main/java/eu/univento/core/api/Utils.java create mode 100644 src/main/java/eu/univento/core/api/advancement/Advancement.java create mode 100644 src/main/java/eu/univento/core/api/advancement/CustomAdvancement.java rename src/main/java/eu/univento/core/api/{utils/Camera.java => camera/CameraUtil.java} (59%) create mode 100644 src/main/java/eu/univento/core/api/camera/Traveller.java create mode 100644 src/main/java/eu/univento/core/api/cloud/CloudApiWrapper.java create mode 100644 src/main/java/eu/univento/core/api/customitems/CustomItem.java create mode 100644 src/main/java/eu/univento/core/api/customitems/CustomItemActions.java create mode 100644 src/main/java/eu/univento/core/api/customitems/CustomItems.java create mode 100644 src/main/java/eu/univento/core/api/customitems/Rarity.java create mode 100644 src/main/java/eu/univento/core/api/customitems/actions/InteractBlockAction.java create mode 100644 src/main/java/eu/univento/core/api/customitems/actions/InteractPlayerAction.java create mode 100644 src/main/java/eu/univento/core/api/customitems/actions/PlayerHitAction.java create mode 100644 src/main/java/eu/univento/core/api/gui/Action.java create mode 100644 src/main/java/eu/univento/core/api/gui/InventoryGUI.java delete mode 100644 src/main/java/eu/univento/core/api/gui/SignInput.java rename src/main/java/eu/univento/core/api/gui/{ => sign}/PlayerSignInputEvent.java (77%) create mode 100644 src/main/java/eu/univento/core/api/gui/sign/SignInput.java rename src/main/java/eu/univento/core/api/gui/{ => sign}/SignInputHandler.java (76%) delete mode 100644 src/main/java/eu/univento/core/api/items/ClickInventory.java delete mode 100644 src/main/java/eu/univento/core/api/items/InventoryManager.java delete mode 100644 src/main/java/eu/univento/core/api/items/NamedInventory.java delete mode 100644 src/main/java/eu/univento/core/api/items/Page.java delete mode 100644 src/main/java/eu/univento/core/api/items/PageInventory.java delete mode 100644 src/main/java/eu/univento/core/api/items/PageLayout.java delete mode 100644 src/main/java/eu/univento/core/api/items/ScrollingInventory.java create mode 100644 src/main/java/eu/univento/core/api/items/attribute/Attribute.java create mode 100644 src/main/java/eu/univento/core/api/items/attribute/AttributeModifier.java create mode 100644 src/main/java/eu/univento/core/api/items/attribute/ItemAttributes.java create mode 100644 src/main/java/eu/univento/core/api/items/attribute/ItemSlot.java delete mode 100644 src/main/java/eu/univento/core/api/items/events/ItemClickEvent.java delete mode 100644 src/main/java/eu/univento/core/api/items/events/NamedCloseEvent.java delete mode 100644 src/main/java/eu/univento/core/api/items/events/NamedPageClickEvent.java delete mode 100644 src/main/java/eu/univento/core/api/items/events/PageCloseEvent.java delete mode 100644 src/main/java/eu/univento/core/api/items/events/PagesClickEvent.java delete mode 100644 src/main/java/eu/univento/core/api/items/events/PagesTurnEvent.java delete mode 100644 src/main/java/eu/univento/core/api/pet/NMSHandler.java delete mode 100644 src/main/java/eu/univento/core/api/pet/NMSHelper.java delete mode 100644 src/main/java/eu/univento/core/api/pet/PetManager.java delete mode 100644 src/main/java/eu/univento/core/api/pet/PetType.java delete mode 100644 src/main/java/eu/univento/core/api/pet/custom/CustomCreeper.java delete mode 100644 src/main/java/eu/univento/core/api/pet/custom/CustomPig.java delete mode 100644 src/main/java/eu/univento/core/api/server/GameInfo.java delete mode 100644 src/main/java/eu/univento/core/api/server/NetworkData.java delete mode 100644 src/main/java/eu/univento/core/api/server/ServerDatabase.java delete mode 100644 src/main/java/eu/univento/core/api/server/ServerPinger.java delete mode 100644 src/main/java/eu/univento/core/api/shop/PayType.java delete mode 100644 src/main/java/eu/univento/core/api/update/PluginUpdater.java create mode 100644 src/main/java/eu/univento/core/commands/AdminCommands.java create mode 100644 src/main/java/eu/univento/core/customitems/weapons/closecombat/CloseCombatEvents.java rename src/main/java/eu/univento/core/{api/customitems/swords/BestSwordEver.java => customitems/weapons/closecombat/ThiefsDagger.java} (57%) create mode 100644 src/main/java/eu/univento/core/listeners/cloud/CloudNet.java diff --git a/.gitignore b/.gitignore index 9a9e56b..465e7ae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /target /server /build -Core.iml \ No newline at end of file +Core.iml +run-server.sh \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index a99baa2..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,8 +0,0 @@ -image: maven:3-jdk-8 - -build: - script: "mvn clean --settings .gitlab/settings.xml" - artifacts: - name: "Core" - paths: - - "target/*.jar" \ No newline at end of file diff --git a/.gitlab/settings.xml b/.gitlab/settings.xml deleted file mode 100644 index 8093b52..0000000 --- a/.gitlab/settings.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - univentoEU - download - ${env.password} - - - - - - univentoEU - univentoEU Mirror Repo - http://play.univento.eu:8081/repository/public/ - * - - - \ No newline at end of file diff --git a/Core.iml b/Core.iml index 3bed099..31d1fd1 100644 --- a/Core.iml +++ b/Core.iml @@ -20,25 +20,35 @@ - + + + + + + + + + + + + - - - - - - + + + + - - - - - - + + + + + + + @@ -64,6 +74,7 @@ + @@ -73,17 +84,18 @@ - - - - - + + + + + + - + \ No newline at end of file diff --git a/pom.xml b/pom.xml index f1ebe52..8a4d6b9 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ 1.0-SNAPSHOT jar - Univento.eu Core System + univento.eu Core System @@ -53,61 +53,69 @@ - - - univentoEU - http://play.univento.eu:8081/repository/univento/ - - - com.destroystokyo.paper paper-api - 1.11.2-R0.1-SNAPSHOT - provided - - - org.spigotmc - spigot-api - 1.11.2-R0.1-SNAPSHOT - provided - - - org.bukkit - bukkit - 1.11.2-R0.1-SNAPSHOT + 1.12.1-R0.1-SNAPSHOT provided org.bukkit craftbukkit - 1.11.2-R0.1-SNAPSHOT + 1.12.1-R0.1-SNAPSHOT provided org.projectlombok lombok - 1.16.10 + 1.16.16 co.aikar taskchain-bukkit - 3.4.3 + 3.6.0 + + pl.kacperduras + tasket-core + 1.1.0 + compile + + + pl.kacperduras + tasket-bukkit + 1.1.0 + + io.github.lordakkarin nbt 1.0 + + eu.univento - Commons + commons 1.0-SNAPSHOT + + + de.dytanic.cloudnet + cloudnet-api + 2.0 + provided + \ No newline at end of file diff --git a/src/main/java/eu/univento/core/Core.java b/src/main/java/eu/univento/core/Core.java index 483b474..c2b0e02 100644 --- a/src/main/java/eu/univento/core/Core.java +++ b/src/main/java/eu/univento/core/Core.java @@ -1,26 +1,43 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core; +import co.aikar.taskchain.BukkitTaskChainFactory; +import co.aikar.taskchain.TaskChainFactory; 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.advancement.CustomAdvancement; +import eu.univento.core.api.cloud.CloudApiWrapper; import eu.univento.core.api.command.CommandFramework; import eu.univento.core.api.effects.Blackscreen; import eu.univento.core.api.events.MoveEventFilter; -import eu.univento.core.api.items.InventoryManager; import eu.univento.core.api.player.CustomPlayer; import eu.univento.core.commands.*; +import eu.univento.core.customitems.weapons.closecombat.CloseCombatEvents; import eu.univento.core.listeners.*; import eu.univento.core.listeners.cloud.Servers; +import io.sentry.Sentry; +import io.sentry.SentryClient; +import io.sentry.jul.SentryHandler; import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.inventory.Recipe; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; +import pl.kacperduras.tasket.Tasket; +import pl.kacperduras.tasket.bukkit.BukkitTasket; import java.io.IOException; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.Collection; +import java.util.Iterator; import java.util.LinkedList; +import java.util.logging.Level; /** * main class @@ -33,6 +50,9 @@ public class Core extends JavaPlugin{ @Getter private static Core instance; @Getter private static Commons commons; @Getter private static CommandFramework commandFramework; + @Getter private static TaskChainFactory taskChainFactory; + @Getter private static Tasket tasket; + @Getter private static CloudApiWrapper cloudAPI; public static String getNMSVersion() { final String packageName = Bukkit.getServer().getClass().getPackage().getName(); @@ -52,7 +72,21 @@ public class Core extends JavaPlugin{ public void onEnable() { commons = new Commons(); - System.out.println("\n" + + SentryClient sentryClient = Sentry.init(commons.getConfigurationHandler().getString("Sentry.DSN.Core")); + try { + sentryClient.setServerName(InetAddress.getLocalHost().getHostName()); + sentryClient.setEnvironment(""); + sentryClient.setDist("Core"); + sentryClient.setRelease("1.0.0"); + } catch (UnknownHostException e) { + e.printStackTrace(); + } + + SentryHandler logHandler = new SentryHandler(); + logHandler.setLevel(Level.INFO); + getLogger().addHandler(logHandler); + + getLogger().info("\n" + "\n" + " \n" + " \n" + @@ -85,20 +119,14 @@ public class Core extends JavaPlugin{ e.printStackTrace(); } instance = this; - PluginManager pm = Bukkit.getPluginManager(); - pm.registerEvents(new Commands(), this); - pm.registerEvents(new JoinQuit(), this); - pm.registerEvents(new Chat(), this); - pm.registerEvents(new Events(), this); - pm.registerEvents(new WeaponEvents(), this); - pm.registerEvents(new SpectatorEvents(), this); - pm.registerEvents(new MoveEventFilter(getServer()), this); - pm.registerEvents(new InventoryManager(), this); - pm.registerEvents(new WorkbenchEvents(), this); - pm.registerEvents(new NPCEvents(), this); + + taskChainFactory = BukkitTaskChainFactory.create(this); + tasket = new BukkitTasket(this); + cloudAPI = new CloudApiWrapper(); commandFramework = new CommandFramework(this); + commandFramework.registerCommands(new AdminCommands()); commandFramework.registerCommands(new DevCommands()); commandFramework.registerCommands(new ModCommands()); commandFramework.registerCommands(new BuilderCommands()); @@ -107,11 +135,25 @@ public class Core extends JavaPlugin{ commandFramework.registerCommands(new HologramCommands()); - new AntiHack().registerListeners(); + + PluginManager pm = Bukkit.getPluginManager(); + pm.registerEvents(new Commands(), this); + pm.registerEvents(new JoinQuit(), this); + pm.registerEvents(new Chat(), this); + pm.registerEvents(new Events(), this); + pm.registerEvents(new WeaponEvents(), this); + pm.registerEvents(new SpectatorEvents(), this); + pm.registerEvents(new MoveEventFilter(getServer()), this); + pm.registerEvents(new WorkbenchEvents(), this); + pm.registerEvents(new NPCEvents(), this); + + pm.registerEvents(new CloseCombatEvents(), this); new SetRank(this, "setrank", "sets the rank for other players", "sr"); PluginMessenger pluginMessenger = new PluginMessenger(); + Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); + Bukkit.getMessenger().registerIncomingPluginChannel(this, "BungeeCord", pluginMessenger); Bukkit.getMessenger().registerOutgoingPluginChannel(this, "5zig_Set"); Bukkit.getMessenger().registerIncomingPluginChannel(this, "5zig_Set", pluginMessenger); Bukkit.getMessenger().registerOutgoingPluginChannel(this, "LABYMOD"); @@ -124,7 +166,21 @@ public class Core extends JavaPlugin{ Servers.register(); Blackscreen.setupUtil(getInstance()); - Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> System.out.println("\n" + + + for(CustomAdvancement advancement : CustomAdvancement.values()) advancement.load(); + + Iterator iterator = Bukkit.recipeIterator(); + while(iterator.hasNext()) { + Recipe recipe = iterator.next(); + //TODO: remove unwanted recipes and add own recipies + /* + if() { + iterator.remove(); + } + */ + } + + Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> getLogger().info("\n" + "\n" + "\n" + " _ _ \n" + @@ -137,7 +193,15 @@ public class Core extends JavaPlugin{ " \n" + "\n"), 0L); - Bukkit.getScheduler().runTask(this, new TPS()); + /* + Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> { + + String[] args = new SimpleDateFormat("HH:mm").format(new Date()).split(":"); + long time = (Integer.parseInt(args[0])*1000) + (Integer.parseInt(args[1])*100/60) + 18000; + + for(World world : Bukkit.getWorlds()) world.setTime(time); + }, 20L, 1L); + */ } @Override @@ -145,7 +209,7 @@ public class Core extends JavaPlugin{ Bukkit.getMessenger().unregisterIncomingPluginChannel(this); Bukkit.getMessenger().unregisterOutgoingPluginChannel(this); - System.out.println("\n" + + getLogger().info("\n" + "\n" + " \n" + " \n" + @@ -172,7 +236,6 @@ public class Core extends JavaPlugin{ " \n" + " \n" + "\n"); - //new PluginUpdater("Core").update(); commons.shutdown(); } diff --git a/src/main/java/eu/univento/core/antihack/AntiHack.java b/src/main/java/eu/univento/core/antihack/AntiHack.java index 20e07bb..4ba0405 100644 --- a/src/main/java/eu/univento/core/antihack/AntiHack.java +++ b/src/main/java/eu/univento/core/antihack/AntiHack.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.antihack; import eu.univento.commons.player.warn.WarnReason; diff --git a/src/main/java/eu/univento/core/antihack/Hack.java b/src/main/java/eu/univento/core/antihack/Hack.java index f1dfc15..5a71816 100644 --- a/src/main/java/eu/univento/core/antihack/Hack.java +++ b/src/main/java/eu/univento/core/antihack/Hack.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.antihack; public enum Hack { diff --git a/src/main/java/eu/univento/core/antihack/modules/AutoClicker.java b/src/main/java/eu/univento/core/antihack/modules/AutoClicker.java index fba81ee..aac81eb 100644 --- a/src/main/java/eu/univento/core/antihack/modules/AutoClicker.java +++ b/src/main/java/eu/univento/core/antihack/modules/AutoClicker.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.antihack.modules; import eu.univento.core.api.player.CustomPlayer; diff --git a/src/main/java/eu/univento/core/antihack/modules/AutoRespawn.java b/src/main/java/eu/univento/core/antihack/modules/AutoRespawn.java index 00c3a59..d1439ba 100644 --- a/src/main/java/eu/univento/core/antihack/modules/AutoRespawn.java +++ b/src/main/java/eu/univento/core/antihack/modules/AutoRespawn.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.antihack.modules; import eu.univento.commons.player.warn.WarnReason; diff --git a/src/main/java/eu/univento/core/antihack/modules/AutoSoup.java b/src/main/java/eu/univento/core/antihack/modules/AutoSoup.java index 921c974..4571d09 100644 --- a/src/main/java/eu/univento/core/antihack/modules/AutoSoup.java +++ b/src/main/java/eu/univento/core/antihack/modules/AutoSoup.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.antihack.modules; import eu.univento.commons.player.warn.WarnReason; diff --git a/src/main/java/eu/univento/core/antihack/modules/BowAimbot.java b/src/main/java/eu/univento/core/antihack/modules/BowAimbot.java index 07bc709..e95f1ef 100644 --- a/src/main/java/eu/univento/core/antihack/modules/BowAimbot.java +++ b/src/main/java/eu/univento/core/antihack/modules/BowAimbot.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.antihack.modules; import eu.univento.core.api.player.CustomPlayer; diff --git a/src/main/java/eu/univento/core/antihack/modules/Criticals.java b/src/main/java/eu/univento/core/antihack/modules/Criticals.java index 35139c3..be71b61 100644 --- a/src/main/java/eu/univento/core/antihack/modules/Criticals.java +++ b/src/main/java/eu/univento/core/antihack/modules/Criticals.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.antihack.modules; import eu.univento.commons.player.warn.WarnReason; diff --git a/src/main/java/eu/univento/core/antihack/modules/FastPlace.java b/src/main/java/eu/univento/core/antihack/modules/FastPlace.java index d16e19f..df719e3 100644 --- a/src/main/java/eu/univento/core/antihack/modules/FastPlace.java +++ b/src/main/java/eu/univento/core/antihack/modules/FastPlace.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.antihack.modules; import eu.univento.commons.player.warn.WarnReason; diff --git a/src/main/java/eu/univento/core/antihack/modules/Movement.java b/src/main/java/eu/univento/core/antihack/modules/Movement.java index f7ef778..c453cbd 100644 --- a/src/main/java/eu/univento/core/antihack/modules/Movement.java +++ b/src/main/java/eu/univento/core/antihack/modules/Movement.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.antihack.modules; import eu.univento.core.api.events.MoveEventFilter; diff --git a/src/main/java/eu/univento/core/antihack/modules/Nuker.java b/src/main/java/eu/univento/core/antihack/modules/Nuker.java index 304bc34..dec7ebe 100644 --- a/src/main/java/eu/univento/core/antihack/modules/Nuker.java +++ b/src/main/java/eu/univento/core/antihack/modules/Nuker.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.antihack.modules; import eu.univento.commons.player.warn.WarnReason; diff --git a/src/main/java/eu/univento/core/antihack/modules/Packets.java b/src/main/java/eu/univento/core/antihack/modules/Packets.java index 8b0827a..3364359 100644 --- a/src/main/java/eu/univento/core/antihack/modules/Packets.java +++ b/src/main/java/eu/univento/core/antihack/modules/Packets.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.antihack.modules; import com.destroystokyo.paper.event.player.IllegalPacketEvent; diff --git a/src/main/java/eu/univento/core/antihack/modules/Reach.java b/src/main/java/eu/univento/core/antihack/modules/Reach.java index 2b288d2..ef24c1f 100644 --- a/src/main/java/eu/univento/core/antihack/modules/Reach.java +++ b/src/main/java/eu/univento/core/antihack/modules/Reach.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.antihack.modules; import eu.univento.core.api.player.CustomPlayer; diff --git a/src/main/java/eu/univento/core/antihack/modules/Regen.java b/src/main/java/eu/univento/core/antihack/modules/Regen.java index f3d56bb..1f9fe5b 100644 --- a/src/main/java/eu/univento/core/antihack/modules/Regen.java +++ b/src/main/java/eu/univento/core/antihack/modules/Regen.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.antihack.modules; import eu.univento.commons.player.warn.WarnReason; diff --git a/src/main/java/eu/univento/core/antihack/modules/SelfHit.java b/src/main/java/eu/univento/core/antihack/modules/SelfHit.java index cee43e5..ce96479 100644 --- a/src/main/java/eu/univento/core/antihack/modules/SelfHit.java +++ b/src/main/java/eu/univento/core/antihack/modules/SelfHit.java @@ -1,7 +1,13 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.antihack.modules; import eu.univento.core.api.player.CustomPlayer; import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageByEntityEvent; @@ -22,5 +28,13 @@ public class SelfHit implements Listener { e.setDamage(0.0D); } } + if(!e.isCancelled() && e.getEntity() instanceof Player && e.getDamager() instanceof Projectile) { + CustomPlayer p = (CustomPlayer) e.getEntity(); + Projectile projectile = (Projectile) e.getDamager(); + if(projectile.getShooter().equals(p)) { + e.setCancelled(true); + e.setDamage(0.0D); + } + } } } \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/AutoCommand.java b/src/main/java/eu/univento/core/api/AutoCommand.java index b31248f..4f41ccb 100644 --- a/src/main/java/eu/univento/core/api/AutoCommand.java +++ b/src/main/java/eu/univento/core/api/AutoCommand.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api; import org.bukkit.Bukkit; diff --git a/src/main/java/eu/univento/core/api/Config.java b/src/main/java/eu/univento/core/api/Config.java index fcc346b..f40d23c 100644 --- a/src/main/java/eu/univento/core/api/Config.java +++ b/src/main/java/eu/univento/core/api/Config.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api; import org.bukkit.Bukkit; @@ -14,6 +19,7 @@ import java.sql.SQLException; * @author joethei * @version 1.1 */ +@Deprecated public class Config { /**config file*/ diff --git a/src/main/java/eu/univento/core/api/Hologram.java b/src/main/java/eu/univento/core/api/Hologram.java index 86a6e86..47c65bf 100644 --- a/src/main/java/eu/univento/core/api/Hologram.java +++ b/src/main/java/eu/univento/core/api/Hologram.java @@ -1,15 +1,20 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api; import eu.univento.core.Core; import eu.univento.core.api.player.CustomPlayer; -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 net.minecraft.server.v1_12_R1.EntityArmorStand; +import net.minecraft.server.v1_12_R1.EnumHand; +import net.minecraft.server.v1_12_R1.PacketPlayOutEntityDestroy; +import net.minecraft.server.v1_12_R1.PacketPlayOutSpawnEntityLiving; import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_11_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; diff --git a/src/main/java/eu/univento/core/api/Utils.java b/src/main/java/eu/univento/core/api/Utils.java deleted file mode 100644 index 794a1be..0000000 --- a/src/main/java/eu/univento/core/api/Utils.java +++ /dev/null @@ -1,177 +0,0 @@ -package eu.univento.core.api; - - -import eu.univento.core.Core; -import eu.univento.core.api.player.CustomPlayer; -import org.bukkit.*; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffect; -import org.bukkit.util.Vector; - -import java.io.File; -import java.util.List; - -/** - * some utils you may need - * - * @author joethei - * @version 1.0 - */ -public class Utils { - - /** - * plays sound for all players - * - * @param s Sound - */ - public static void playSoundToAll(Sound s) { - for (Player all : Bukkit.getOnlinePlayers()) - all.playSound(all.getLocation(), s, 3.0F, 3.0F); - } - - /** - * plays effect for all players - * - * @param e Effect - */ - 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 - */ - private static void deleteDir(File file) { - if (file.isDirectory()) { - if (file.list().length == 0) { - file.delete(); - } else { - String[] files = file.list(); - for (String tmp : files) { - File fileDelete = new File(file, tmp); - deleteDir(fileDelete); - } - if (file.list().length == 0) - file.delete(); - } - } else - file.delete(); - } - - /** - * creates a random number - * - * @param low lowest possible value - * @param high highest possible value - * @return double - */ - public static double random(int low, int high) { - return Math.random() * (high - low) + low; - } - - /** - * checks if player has empty inventory - * - * @param p Player - * @return true/false - */ - public static boolean hasEmptyInventory(Player p) { - for (ItemStack item : p.getInventory().getContents()) { - if ((item != null) && (item.getType() != Material.AIR)) - return false; - } - for (ItemStack item : p.getInventory().getArmorContents()) { - if ((item != null) && (item.getType() != Material.AIR)) - return false; - } - return true; - } - - - /** - * removes list of entity and counts them - * - * @param e Entity list - * @return Integer - */ - public static int removeEntitys(List e) { - int i = 0; - for (Entity en : e) { - en.remove(); - i++; - } - return i; - } - - /** - * clears all potion effects from player - * - * @param player Player - */ - public static void clearPotionEffects(Player player) { - for (PotionEffect effect : player.getActivePotionEffects()) - player.removePotionEffect(effect.getType()); - } - - /** - * calculates vector from one location to another - * - * @param from Location - * @param to Location - * @return Vector - */ - public static Vector calculateVector(Location from, Location to) { - Location b = to; - - // calculate the distance between the locations (a => from || b => to) - double dX = from.getX() - b.getX(); - double dY = from.getY() - b.getY(); - double dZ = from.getZ() - b.getZ(); - // ------------------------- - - // calculate the yaw - double yaw = Math.atan2(dZ, dX); - // ------------------------- - - // calculate the pitch - double pitch = Math.atan2(Math.sqrt(dZ * dZ + dX * dX), dY) + Math.PI; - // ------------------------- - - // calculate and create the new vector - double x = Math.sin(pitch) * Math.cos(yaw); - double y = Math.sin(pitch) * Math.sin(yaw); - double z = Math.cos(pitch); - - // ------------------------- - - return new Vector(x, z, y); - } - - /** - * restarts server - */ - public static void restart() { - Bukkit.getScheduler().scheduleSyncDelayedTask(Core.getInstance(), () -> { - if(Core.getOnlinePlayers().size() != 0) { - for(CustomPlayer players : Core.getOnlinePlayers()) - //TODO: add connect to optimal lobby server here - players.connectToServer("Lobby01"); - } - Bukkit.spigot().restart(); - }, 10 * 20L); - } -} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/advancement/Advancement.java b/src/main/java/eu/univento/core/api/advancement/Advancement.java new file mode 100644 index 0000000..03febab --- /dev/null +++ b/src/main/java/eu/univento/core/api/advancement/Advancement.java @@ -0,0 +1,179 @@ +package eu.univento.core.api.advancement; + +import com.google.common.collect.Lists; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import lombok.Getter; +import org.bukkit.NamespacedKey; +import org.bukkit.inventory.ItemStack; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; + +import java.util.List; + +/** + * Created by charliej on 14/05/2017. + * Last modification DiscowZombie on 5/06/2017. + */ + +@Getter +public class Advancement { + + private NamespacedKey id; + private String title, parent, trigger, icon, description, background; + private boolean announce, toast; + private FrameType frame; + private List items; + + public Advancement(NamespacedKey id) { + this.id = id; + this.items = Lists.newArrayList(); + this.announce = true; + this.toast = true; + } + + + public Advancement withIcon(String icon) { + this.icon = icon; + return this; + } + + public String getDescription() { + return description; + } + + public Advancement withDescription(String description) { + this.description = description; + return this; + } + + public Advancement withBackground(String url) { + this.background = url; + return this; + } + + public Advancement withBackground(AdvancementBackground background) { + this.background = background.getUrl(); + return this; + } + + public Advancement withTitle(String title) { + this.title = title; + return this; + } + + public Advancement withParent(String parent) { + this.parent = parent; + return this; + } + + public Advancement withTrigger(String trigger) { + this.trigger = trigger; + return this; + } + + public Advancement withItem(ItemStack is) { + items.add(is); + return this; + } + + public Advancement withFrame(FrameType frame) { + this.frame = frame; + return this; + } + + public Advancement withAnnouncement(boolean announce){ + this.announce = announce; + return this; + } + + public Advancement withToast(boolean toast){ + this.toast = toast; + return this; + } + + public String getJSON() { + JSONObject json = new JSONObject(); + + JSONObject icon = new JSONObject(); + icon.put("item", getIcon()); + + JSONObject display = new JSONObject(); + display.put("icon", icon); + display.put("title", getTitle()); + display.put("description", getDescription()); + display.put("background", getBackground()); + display.put("frame", getFrame().toString()); + display.put("announce_to_chat", isAnnounce()); + display.put("show_toast", isToast()); + + json.put("parent", getParent()); + + JSONObject criteria = new JSONObject(); + JSONObject conditions = new JSONObject(); + JSONObject elytra = new JSONObject(); + + JSONArray itemArray = new JSONArray(); + JSONObject itemJSON = new JSONObject(); + + for(ItemStack i : getItems()) { + itemJSON.put("item", "minecraft:"+ i.getType().name().toLowerCase()); + itemJSON.put("amount", i.getAmount()); + itemArray.add(itemJSON); + } + + /** + * Define each criteria, for each criteria in list, + * add items, trigger and conditions + */ + + conditions.put("items", itemArray); + elytra.put("trigger", getTrigger()); + elytra.put("conditions", conditions); + + criteria.put("elytra", elytra); + + json.put("criteria", criteria); + json.put("display", display); + + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + + return gson.toJson(json); + } + + public enum FrameType { + TASK("task"), + GOAL("goal"), + CHALLENGE("challenge"); + + private String name = "task"; + + FrameType(String name){ + this.name = name; + } + + public String toString(){ + return name; + } + } + + public enum AdvancementBackground{ + ADVENTURE("minecraft:textures/gui/advancements/backgrounds/adventure.png"), + END("minecraft:textures/gui/advancements/backgrounds/end.png"), + HUSBANDRY("minecraft:textures/gui/advancements/backgrounds/husbandry.png"), + NETHER("minecraft:textures/gui/advancements/backgrounds/nether.png"), + STONE("minecraft:textures/gui/advancements/backgrounds/stone.png"), + fromNamespace(null); + + @Getter private String url; + + AdvancementBackground(String url){ + this.url = url; + } + + public void fromNamespace(String string) { + url = string; + } + } + +} diff --git a/src/main/java/eu/univento/core/api/advancement/CustomAdvancement.java b/src/main/java/eu/univento/core/api/advancement/CustomAdvancement.java new file mode 100644 index 0000000..5656936 --- /dev/null +++ b/src/main/java/eu/univento/core/api/advancement/CustomAdvancement.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.core.api.advancement; + +import eu.univento.core.Core; +import eu.univento.core.api.player.CustomPlayer; +import lombok.Getter; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.inventory.ItemStack; + +/** + * @author joethei + * @version 1.0 + */ + +@Getter +public enum CustomAdvancement { + CHAT_T(new Advancement(new NamespacedKey(Core.getInstance(), "chat_t")).withTrigger("minecraft:impossible").withIcon("minecraft:apple") + .withBackground(Advancement.AdvancementBackground.ADVENTURE).withFrame(Advancement.FrameType.GOAL).withTitle("Chatten").withDescription("Schreibe etwas in den Chat").withItem(new ItemStack(Material.TNT)).withAnnouncement(false).withToast(true)); + + private Advancement advancement; + + CustomAdvancement(Advancement advancement) { + this.advancement = advancement; + } + + public void load() { + if(Bukkit.getAdvancement(advancement.getId()) == null) + Bukkit.getUnsafe().loadAdvancement(advancement.getId(), advancement.getJSON()); + } + + public void award(CustomPlayer p, String criteria) { + if(!p.getAdvancementProgress(Bukkit.getAdvancement(advancement.getId())).isDone()) { + p.getAdvancementProgress(Bukkit.getAdvancement(advancement.getId())).awardCriteria(criteria); + } + } + + public void revoke(CustomPlayer p, String criteria) { + if(p.getAdvancementProgress(Bukkit.getAdvancement(advancement.getId())).isDone()) { + p.getAdvancementProgress(Bukkit.getAdvancement(advancement.getId())).revokeCriteria(criteria); + } + } + +} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/blocks/MiniBlock.java b/src/main/java/eu/univento/core/api/blocks/MiniBlock.java index 8356d72..cfee5d9 100644 --- a/src/main/java/eu/univento/core/api/blocks/MiniBlock.java +++ b/src/main/java/eu/univento/core/api/blocks/MiniBlock.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.blocks; import org.bukkit.*; 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 2756299..a989034 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 @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.blocks.banners; import org.bukkit.DyeColor; diff --git a/src/main/java/eu/univento/core/api/blocks/banners/BannerString.java b/src/main/java/eu/univento/core/api/blocks/banners/BannerString.java index 27f3ffa..43470ef 100644 --- a/src/main/java/eu/univento/core/api/blocks/banners/BannerString.java +++ b/src/main/java/eu/univento/core/api/blocks/banners/BannerString.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.blocks.banners; import org.bukkit.block.Banner; diff --git a/src/main/java/eu/univento/core/api/blocks/banners/FloatingText.java b/src/main/java/eu/univento/core/api/blocks/banners/FloatingText.java index 8bfd2b3..e6d0e10 100644 --- a/src/main/java/eu/univento/core/api/blocks/banners/FloatingText.java +++ b/src/main/java/eu/univento/core/api/blocks/banners/FloatingText.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.blocks.banners; /** diff --git a/src/main/java/eu/univento/core/api/blocks/banners/Shape.java b/src/main/java/eu/univento/core/api/blocks/banners/Shape.java index 860e018..01885ee 100644 --- a/src/main/java/eu/univento/core/api/blocks/banners/Shape.java +++ b/src/main/java/eu/univento/core/api/blocks/banners/Shape.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.blocks.banners; import org.bukkit.DyeColor; diff --git a/src/main/java/eu/univento/core/api/blocks/banners/ShapeRegistry.java b/src/main/java/eu/univento/core/api/blocks/banners/ShapeRegistry.java index 797ae33..db8f3e7 100644 --- a/src/main/java/eu/univento/core/api/blocks/banners/ShapeRegistry.java +++ b/src/main/java/eu/univento/core/api/blocks/banners/ShapeRegistry.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.blocks.banners; import org.bukkit.DyeColor; diff --git a/src/main/java/eu/univento/core/api/utils/Camera.java b/src/main/java/eu/univento/core/api/camera/CameraUtil.java similarity index 59% rename from src/main/java/eu/univento/core/api/utils/Camera.java rename to src/main/java/eu/univento/core/api/camera/CameraUtil.java index 6dc3a8b..599b4c9 100644 --- a/src/main/java/eu/univento/core/api/utils/Camera.java +++ b/src/main/java/eu/univento/core/api/camera/CameraUtil.java @@ -1,50 +1,29 @@ -package eu.univento.core.api.utils; +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ -import eu.univento.core.api.player.CustomPlayer; -import org.bukkit.Location; +package eu.univento.core.api.camera; import java.math.BigDecimal; -import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.*; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; -class Camera { +/** + * @author CrushedPixel + * @version 1.0 + */ +public class CameraUtil { - //TODO: add full functionality - - private int time; - private ArrayList players = new ArrayList<>(); - private ArrayList locations = new ArrayList<>(); - - private double round(double unrounded, int precision) { - BigDecimal bigDecimal = new BigDecimal(unrounded); - BigDecimal rounded = bigDecimal.setScale(precision, 4); + public static double round(double unrounded, int precision) { + BigDecimal bd = new BigDecimal(unrounded); + BigDecimal rounded = bd.setScale(precision, 4); return rounded.doubleValue(); } - private double positionDifference(Location loc1, Location loc2) { - double x1 = loc1.getX(); - double y1 = loc1.getY(); - double z1 = loc1.getZ(); - - double x2 = loc2.getX(); - double y2 = loc2.getY(); - double z2 = loc2.getZ(); - - double x = x2 - x1; - if (x < 0.0D) - x = -x; - double z = z2 - z1; - if (z < 0.0D) - z = -z; - double xz = Math.hypot(x, z); - double y = y2 - y1; - if (y < 0.0D) - y = -y; - return Math.hypot(xz, y); - } - - private Date parseTimeString(String timeString) throws ParseException { + public static int parseTimeString(String timeString) throws java.text.ParseException { Date length; try { SimpleDateFormat formatter = new SimpleDateFormat("mm'm'ss's'"); @@ -83,18 +62,11 @@ class Camera { } } } - return length; - } - private void load() { + Calendar cal = GregorianCalendar.getInstance(); + cal.setTime(length); - } - - public Camera(String name) { - load(); - } - - public void start(CustomPlayer p) { + return (cal.get(Calendar.MINUTE) * 60 + cal.get(Calendar.SECOND)) * 20; } } \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/camera/Traveller.java b/src/main/java/eu/univento/core/api/camera/Traveller.java new file mode 100644 index 0000000..30c91c0 --- /dev/null +++ b/src/main/java/eu/univento/core/api/camera/Traveller.java @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.core.api.camera; + +import eu.univento.core.Core; +import eu.univento.core.api.player.CustomPlayer; +import io.vertx.core.json.JsonArray; +import io.vertx.core.json.JsonObject; +import lombok.Getter; +import org.bukkit.Bukkit; +import org.bukkit.Location; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +/** + * @author Redstoneore, joethei + * @version 1.0 + */ +public class Traveller { + + private CustomPlayer player; + @Getter private List points = new ArrayList<>(); + @Getter private int time; + private boolean traveling = false; + private String finished; + private String failed; + + public Traveller(CustomPlayer player, String route) { + this.player = player; + + Core.getCommons().getDatabaseManager().getMongoDB().getClient().findOne("routes", new JsonObject().put("route", route), null, event -> { + finished = event.result().getString("finished"); + failed = event.result().getString("failed"); + time = event.result().getInteger("time"); + JsonArray locations = event.result().getJsonArray("locations"); + for(int i = 0; i > locations.size(); i++) { + JsonObject json = locations.getJsonObject(i); + points.add(new Location(Bukkit.getWorld(json.getString("world")), json.getDouble("X"), json.getDouble("Y"), json.getDouble("Z"), json.getFloat("Yaw"), json.getFloat("Pitch"))); + } + }); + } + + public void travel() { + if(points.size() == 0) { + player.sendMessage(failed); + return; + } + List diffs = new ArrayList<>(); + List travelTimes = new ArrayList<>(); + + Double totalDiff = 0.0D; + + for (int i = 0; i < points.size() - 1; i++) { + Location start = points.get(i); + Location next = points.get(i + 1); + + Double diff = start.distance(next); + totalDiff += diff; + diffs.add(diff); + } + + for (Double d : diffs) { + travelTimes.add((int) (d / totalDiff * time)); + } + + final List tps = new ArrayList<>(); + + UUID world = player.getLocation().getWorld().getUID(); + + for (int i = 0; i < points.size() - 1; i++) { + Location thisPoint = points.get(i); + Location nextPoint = points.get(i + 1); + int travelPoint = travelTimes.get(i); + + double moveX = nextPoint.getX() - thisPoint.getX(); + double moveY = nextPoint.getY() - thisPoint.getY(); + double moveZ = nextPoint.getZ() - thisPoint.getZ(); + double movePitch = nextPoint.getPitch() - thisPoint.getPitch(); + + double yawDiff = Math.abs(nextPoint.getYaw() - thisPoint.getYaw()); + double c; + + if (yawDiff <= 180.0) { + if (thisPoint.getYaw() < nextPoint.getYaw()) { + c = yawDiff; + } else { + c = -yawDiff; + } + } else if (thisPoint.getYaw() < nextPoint.getYaw()) { + c = -(360.0 - yawDiff); + } else { + c = 360.0 - yawDiff; + } + + double d = c / travelPoint; + + for (int x = 0; x < travelPoint; x++) { + Location l = new Location(Bukkit.getWorld(world), thisPoint.getX() + moveX / travelPoint * x, thisPoint.getY() + moveY / travelPoint * x, thisPoint.getZ() + moveZ / travelPoint * x, (float) (thisPoint.getYaw() + d * x), (float) (thisPoint.getPitch() + movePitch / travelPoint * x)); + + tps.add(l); + } + + } + + try { + + player.teleport(tps.get(0)); + + Bukkit.getScheduler().runTaskLater(Core.getInstance(), new Runnable() { + private int ticks = 0; + + public void run() { + if (this.ticks < tps.size()) { + + player.teleport(tps.get(this.ticks)); + + // check if they cancelled + if (traveling) { + Bukkit.getScheduler().runTaskLater(Core.getInstance(), this, 1L); + } + this.ticks += 1; + } else { + traveling = false; + player.sendMessage(finished); + } + } + }, 1L); + } catch (Exception e) { + player.sendMessage(failed); + e.printStackTrace(); + } + } + + //TODO: GitHub repo to code after: https://github.com/redstone/RCameraStudio + +} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/chat/DefaultFontInfo.java b/src/main/java/eu/univento/core/api/chat/DefaultFontInfo.java index 6f82d04..59d6c3e 100644 --- a/src/main/java/eu/univento/core/api/chat/DefaultFontInfo.java +++ b/src/main/java/eu/univento/core/api/chat/DefaultFontInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 univento.eu - All rights reserved + * Copyright (c) 2017 univento.eu - All rights reserved * You are not allowed to use, distribute or modify this code */ diff --git a/src/main/java/eu/univento/core/api/cloud/CloudApiWrapper.java b/src/main/java/eu/univento/core/api/cloud/CloudApiWrapper.java new file mode 100644 index 0000000..c93e86f --- /dev/null +++ b/src/main/java/eu/univento/core/api/cloud/CloudApiWrapper.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.core.api.cloud; + +import de.dytanic.cloudnet.api.CloudAPI; +import de.dytanic.cloudnet.lib.server.ServerState; +import de.dytanic.cloudnet.lib.server.info.ServerInfo; +import eu.univento.commons.server.ServerType; +import eu.univento.core.Core; +import eu.univento.core.api.player.CustomPlayer; +import lombok.Getter; + +import java.util.Collection; +import java.util.concurrent.CompletableFuture; + +/** + * @author joethei + * @version 1.0 + */ +public class CloudApiWrapper { + + @Getter private CloudAPI cloudAPI; + + public CloudApiWrapper() { + cloudAPI = CloudAPI.getInstance(); + } + + public CompletableFuture getOptimalServer(CustomPlayer player, ServerType type) { + CompletableFuture future = new CompletableFuture<>(); + Collection servers = cloudAPI.getServers(type.getName()); + + Core.getCommons().getPartyManager().isInParty(player.getDatabasePlayer()).whenComplete(((bool, throwable) -> servers.forEach(serverInfo -> { + if (serverInfo.isOnline() && serverInfo.getServerState() == ServerState.LOBBY) { + if (bool) { + Core.getCommons().getPartyManager().getParty(player.getDatabasePlayer()).whenComplete((party, throwable1) -> { + if (serverInfo.getOnlineCount() < serverInfo.getMaxPlayers() - party.getMembers().size()) { + future.complete(serverInfo.getServiceId().getServerId()); + } + }); + } else { + if (serverInfo.getOnlineCount() < serverInfo.getMaxPlayers() - 1) { + future.complete(serverInfo.getServiceId().getServerId()); + } + } + } + }))); + + return future; + } + +} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/command/BukkitCommand.java b/src/main/java/eu/univento/core/api/command/BukkitCommand.java index fb1b2f9..be1a443 100644 --- a/src/main/java/eu/univento/core/api/command/BukkitCommand.java +++ b/src/main/java/eu/univento/core/api/command/BukkitCommand.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.command; import org.apache.commons.lang3.Validate; diff --git a/src/main/java/eu/univento/core/api/command/BukkitCompleter.java b/src/main/java/eu/univento/core/api/command/BukkitCompleter.java index 847d77f..1a687e2 100644 --- a/src/main/java/eu/univento/core/api/command/BukkitCompleter.java +++ b/src/main/java/eu/univento/core/api/command/BukkitCompleter.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.command; import org.bukkit.command.CommandSender; diff --git a/src/main/java/eu/univento/core/api/command/Command.java b/src/main/java/eu/univento/core/api/command/Command.java index 9661ce7..e49dddc 100644 --- a/src/main/java/eu/univento/core/api/command/Command.java +++ b/src/main/java/eu/univento/core/api/command/Command.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.command; import eu.univento.commons.player.rank.Group; @@ -28,17 +33,17 @@ public @interface Command { * * @return */ - public String name(); + String name(); /** * Gets the required permission of the command * * @return */ - public Rank rank() default Rank.Player; - public Group group() default Group.None; + Rank rank() default Rank.Player; + Group group() default Group.None; - public ServerType serverType() default ServerType.NONE; + ServerType serverType() default ServerType.NONE; /** * The message sent to the player when they do not have permission to @@ -46,7 +51,7 @@ public @interface Command { * * @return */ - public String notAllowed() default "§cYou do not have permission to perform that action"; + String notAllowed() default "§cYou do not have permission to perform that action"; /** * A list of alternate names that the command is executed under. See @@ -54,26 +59,26 @@ public @interface Command { * * @return */ - public String[] aliases() default {}; + String[] aliases() default {}; /** * The description that will appear in /help of the command * * @return */ - public String description() default ""; + String description() default ""; /** * The usage that will appear in /help (commandname) * * @return */ - public String usage() default ""; + String usage() default ""; /** * Whether or not the command is available to players only * * @return */ - public boolean inGameOnly() default false; + boolean inGameOnly() default false; } \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/command/CommandArgs.java b/src/main/java/eu/univento/core/api/command/CommandArgs.java index a0dd75f..d5ccc68 100644 --- a/src/main/java/eu/univento/core/api/command/CommandArgs.java +++ b/src/main/java/eu/univento/core/api/command/CommandArgs.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.command; import eu.univento.core.api.player.CustomPlayer; @@ -19,17 +24,14 @@ public class CommandArgs { private String label; private String[] args; - protected CommandArgs(CommandSender sender, org.bukkit.command.Command command, String label, String[] args, - int subCommand) { + protected CommandArgs(CommandSender sender, org.bukkit.command.Command command, String label, String[] args, int subCommand) { String[] modArgs = new String[args.length - subCommand]; - for (int i = 0; i < args.length - subCommand; i++) { - modArgs[i] = args[i + subCommand]; - } + System.arraycopy(args, subCommand, modArgs, 0, args.length - subCommand); - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); buffer.append(label); for (int x = 0; x < subCommand; x++) { - buffer.append("." + args[x]); + buffer.append(".").append(args[x]); } String cmdLabel = buffer.toString(); this.sender = sender; @@ -41,7 +43,7 @@ public class CommandArgs { /** * Gets the command sender * - * @return + * @return CommandSender */ public CommandSender getSender() { return sender; @@ -50,7 +52,7 @@ public class CommandArgs { /** * Gets the original command object * - * @return + * @return Command */ public org.bukkit.command.Command getCommand() { return command; @@ -70,7 +72,7 @@ public class CommandArgs { * label was test.subcommand and the arguments were subcommand foo foo, it * would only return 'foo foo' because 'subcommand' is part of the command * - * @return + * @return String[] */ public String[] getArgs() { return args; diff --git a/src/main/java/eu/univento/core/api/command/CommandFramework.java b/src/main/java/eu/univento/core/api/command/CommandFramework.java index 857a3cd..e0178cb 100644 --- a/src/main/java/eu/univento/core/api/command/CommandFramework.java +++ b/src/main/java/eu/univento/core/api/command/CommandFramework.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.command; import eu.univento.commons.player.rank.Group; @@ -26,7 +31,7 @@ import java.util.*; * Command Framework - CommandFramework
* The main command framework class used for controlling the framework. * - * @author minnymin3 + * @author minnymin3, joethei */ public class CommandFramework implements CommandExecutor { diff --git a/src/main/java/eu/univento/core/api/command/Completer.java b/src/main/java/eu/univento/core/api/command/Completer.java index 78bcacb..6e11deb 100644 --- a/src/main/java/eu/univento/core/api/command/Completer.java +++ b/src/main/java/eu/univento/core/api/command/Completer.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.command; import java.lang.annotation.ElementType; diff --git a/src/main/java/eu/univento/core/api/customitems/CustomArmor.java b/src/main/java/eu/univento/core/api/customitems/CustomArmor.java index 43d61d0..a7636ea 100644 --- a/src/main/java/eu/univento/core/api/customitems/CustomArmor.java +++ b/src/main/java/eu/univento/core/api/customitems/CustomArmor.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.customitems; /** diff --git a/src/main/java/eu/univento/core/api/customitems/CustomItem.java b/src/main/java/eu/univento/core/api/customitems/CustomItem.java new file mode 100644 index 0000000..4f79ffd --- /dev/null +++ b/src/main/java/eu/univento/core/api/customitems/CustomItem.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.core.api.customitems; + +import lombok.Builder; +import lombok.Getter; +import org.bukkit.inventory.ItemStack; + +/** + * @author joethei + * @version 1.0 + */ +@Getter +@Builder +public class CustomItem { + + private ItemStack itemStack; + private Rarity rarity; + private CustomItemActions actions; + +} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/customitems/CustomItemActions.java b/src/main/java/eu/univento/core/api/customitems/CustomItemActions.java new file mode 100644 index 0000000..4bfd2a4 --- /dev/null +++ b/src/main/java/eu/univento/core/api/customitems/CustomItemActions.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.core.api.customitems; + +import eu.univento.core.api.customitems.actions.InteractBlockAction; +import eu.univento.core.api.customitems.actions.InteractPlayerAction; +import eu.univento.core.api.customitems.actions.PlayerHitAction; +import lombok.Builder; +import lombok.Getter; + +/** + * @author joethei + * @version 1.0 + */ + +@Getter +@Builder +public class CustomItemActions { + + private PlayerHitAction playerHitAction; + private InteractBlockAction interactBlockAction; + private InteractPlayerAction interactPlayerAction; +} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/customitems/CustomItemManager.java b/src/main/java/eu/univento/core/api/customitems/CustomItemManager.java index 8ce9010..f222502 100644 --- a/src/main/java/eu/univento/core/api/customitems/CustomItemManager.java +++ b/src/main/java/eu/univento/core/api/customitems/CustomItemManager.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.customitems; /** diff --git a/src/main/java/eu/univento/core/api/customitems/CustomItems.java b/src/main/java/eu/univento/core/api/customitems/CustomItems.java new file mode 100644 index 0000000..4c64f33 --- /dev/null +++ b/src/main/java/eu/univento/core/api/customitems/CustomItems.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.core.api.customitems; + +import eu.univento.core.api.items.ItemBuilder; +import eu.univento.core.api.items.attribute.Attribute; +import eu.univento.core.api.items.attribute.ItemSlot; +import lombok.Getter; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +/** + * @author joethei + * @version 1.0 + */ +@Getter +public enum CustomItems { + + Thiefs_Dagger(CustomItem.builder().itemStack(new ItemBuilder(Material.DIAMOND_SWORD).attribute(Attribute.ATTACK_SPEED, "ThiefsDaggerSpeed", ItemSlot.MAIN_HAND, 0, 0.0D) + .name(Rarity.Epic.getColor() + "Dolch des Diebes").build()).rarity(Rarity.Epic).actions(CustomItemActions.builder() + .playerHitAction((player, hitPlayer, damage, cause) -> player.sendMessage("Du hast " + hitPlayer.getDisplayName() + " geschlagen")) + .interactBlockAction((player, action, block, blockFace) -> player.sendMessage("Du hast auf einen " + block.getType().name() + " geklickt")) + .interactPlayerAction((player, interactPlayer) -> player.sendMessage("Du hast auf den Spieler " + interactPlayer.getDisplayName() + " geklickt")) + .build()).build()); + + private CustomItem item; + + CustomItems(CustomItem item) { + this.item = item; + } + + public static CustomItem valueOf(ItemStack item) { + return null; + /* + for (CustomItems customItems : values()) { + if (item.equals(customItems.getItem().getItemStack())) return customItems.getItem(); + } + return null; + */ + } +} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/customitems/Rarity.java b/src/main/java/eu/univento/core/api/customitems/Rarity.java new file mode 100644 index 0000000..eb0d05d --- /dev/null +++ b/src/main/java/eu/univento/core/api/customitems/Rarity.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.core.api.customitems; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * @author joethei + * @version 1.0 + */ + +@AllArgsConstructor +public enum Rarity { + + Normal("§7", "Normal"), + Rare("§6", "Selten"), + Epic("§5", "Episch"), + Legendary("§f", "Legendär"), + Secret("§8", "Geheim"), + Unique("§c", "Einzigartig"); + + @Getter private String color; + @Getter private String name; + +} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/customitems/actions/InteractBlockAction.java b/src/main/java/eu/univento/core/api/customitems/actions/InteractBlockAction.java new file mode 100644 index 0000000..352c5f9 --- /dev/null +++ b/src/main/java/eu/univento/core/api/customitems/actions/InteractBlockAction.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.core.api.customitems.actions; + +import eu.univento.core.api.player.CustomPlayer; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.event.block.Action; + +/** + * @author joethei + * @version 1.0 + */ +public interface InteractBlockAction { + + void onInteract(CustomPlayer player, Action action, Block block, BlockFace blockFace); +} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/customitems/actions/InteractPlayerAction.java b/src/main/java/eu/univento/core/api/customitems/actions/InteractPlayerAction.java new file mode 100644 index 0000000..f5f847b --- /dev/null +++ b/src/main/java/eu/univento/core/api/customitems/actions/InteractPlayerAction.java @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.core.api.customitems.actions; + +import eu.univento.core.api.player.CustomPlayer; + +/** + * @author joethei + * @version 1.0 + */ +public interface InteractPlayerAction { + + void onInteract(CustomPlayer player, CustomPlayer interactPlayer); +} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/customitems/actions/PlayerHitAction.java b/src/main/java/eu/univento/core/api/customitems/actions/PlayerHitAction.java new file mode 100644 index 0000000..b6238a0 --- /dev/null +++ b/src/main/java/eu/univento/core/api/customitems/actions/PlayerHitAction.java @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.core.api.customitems.actions; + +import eu.univento.core.api.player.CustomPlayer; +import org.bukkit.event.entity.EntityDamageEvent; + +/** + * @author joethei + * @version 0.1 + */ +public interface PlayerHitAction { + + void onHit(CustomPlayer player, CustomPlayer hitPlayer, double damage, EntityDamageEvent.DamageCause cause); +} \ No newline at end of file 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 76c1ded..82b5740 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,38 +1,25 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.customitems.swords; -import eu.univento.core.api.player.CustomPlayer; import org.bukkit.inventory.ItemStack; /** * @author joethei * @version 0.1 */ -public class CustomSword{ +public interface CustomSword{ - public CustomPlayer player; + void primaryAttack(); - public CustomSword(CustomPlayer player) { - this.player = player; - CustomSwordManager.add(this); - } + void secondaryAttack(); - public void primaryAttack() { + void sneakingAttack(); - } + ItemStack getItem(); - public void secondaryAttack() { - - } - - public void sneakingAttack() { - - } - - public ItemStack getItem() { - return null; - } - - public void addItem() { - player.getInventory().addItem(getItem()); - } + void addItem(); } \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/customitems/swords/CustomSwordManager.java b/src/main/java/eu/univento/core/api/customitems/swords/CustomSwordManager.java index bdec69c..8e43bf2 100644 --- a/src/main/java/eu/univento/core/api/customitems/swords/CustomSwordManager.java +++ b/src/main/java/eu/univento/core/api/customitems/swords/CustomSwordManager.java @@ -1,9 +1,15 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.customitems.swords; +import eu.univento.core.api.player.CustomPlayer; import org.bukkit.inventory.ItemStack; -import java.util.LinkedList; -import java.util.List; +import java.util.LinkedHashMap; +import java.util.Map; /** * @author joethei @@ -11,23 +17,24 @@ import java.util.List; */ public class CustomSwordManager { - private static List swords = new LinkedList<>(); + private static Map swords = new LinkedHashMap<>(); public static CustomSword valueOf(ItemStack item) { - for(CustomSword sword : swords) + for(CustomSword sword : swords.values()) if(sword.getItem().equals(item)) return sword; return null; } - public static void add(CustomSword sword) { - swords.add(sword); + public static void add(CustomPlayer p, CustomSword sword) { + swords.put(p, sword); } - public static void remove(CustomSword sword) { - swords.remove(sword); + public static void remove(CustomPlayer p, CustomSword sword) { + if(swords.get(p).equals(sword)) + swords.remove(p); } public static boolean contains(CustomSword sword) { - return swords.contains(sword); + return swords.containsValue(sword); } } \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/effects/Blackscreen.java b/src/main/java/eu/univento/core/api/effects/Blackscreen.java index ad4bf9c..92f580a 100644 --- a/src/main/java/eu/univento/core/api/effects/Blackscreen.java +++ b/src/main/java/eu/univento/core/api/effects/Blackscreen.java @@ -1,35 +1,26 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.effects; +import eu.univento.core.api.player.CustomPlayer; +import net.minecraft.server.v1_12_R1.PacketPlayOutGameStateChange; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; -import java.lang.reflect.Field; -import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; import java.util.UUID; /** - * @author janhektor + * @author janhektor, joethei */ public class Blackscreen { - private static Object packetObject; - private static Class packetClass; private static Map ticksLeft = new HashMap<>(); - static { - String path = Bukkit.getServer().getClass().getPackage().getName(); - String VERSION = path.substring(path.lastIndexOf(".") + 1, path.length()); - try { - packetClass = Class.forName("net.minecraft.server." + VERSION + ".Packet"); - Class packetGameStateClass = Class.forName("net.minecraft.server." + VERSION + ".PacketPlayOutGameStateChange"); - packetObject = packetGameStateClass.getConstructor(new Class[]{Integer.TYPE, Float.TYPE}).newInstance(4, 0); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - public static void setupUtil(Plugin instance) { Bukkit.getScheduler().runTaskTimer(instance, () -> { for (UUID uuid : Blackscreen.ticksLeft.keySet()) { @@ -46,20 +37,10 @@ public class Blackscreen { , 0L, 2); } - private static void sendPacket(Player p) { - try { - Object nmsPlayer = p.getClass().getMethod("getHandle", new Class[0]).invoke(p); - Field playerConnectionField = nmsPlayer.getClass().getField("playerConnection"); - Object pConnection = playerConnectionField.get(nmsPlayer); - Method sendPacket = pConnection.getClass().getMethod("sendPacket", packetClass); - sendPacket.invoke(pConnection, packetObject); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - public static void setBlack(Player p, int seconds) { + public static void setBlack(CustomPlayer p, int seconds) { ticksLeft.put(p.getUniqueId(), seconds * 20); - sendPacket(p); + PacketPlayOutGameStateChange packet = new PacketPlayOutGameStateChange(4, 0); + p.sendPacket(packet); + } } \ 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 23477ee..860905b 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,15 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.effects; import eu.univento.core.Core; -import net.minecraft.server.v1_11_R1.EnumParticle; -import net.minecraft.server.v1_11_R1.PacketPlayOutWorldParticles; +import net.minecraft.server.v1_12_R1.EnumParticle; +import net.minecraft.server.v1_12_R1.PacketPlayOutWorldParticles; import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; import org.bukkit.entity.Player; /** diff --git a/src/main/java/eu/univento/core/api/effects/ParticleEffect.java b/src/main/java/eu/univento/core/api/effects/ParticleEffect.java index 96cbf22..156595b 100644 --- a/src/main/java/eu/univento/core/api/effects/ParticleEffect.java +++ b/src/main/java/eu/univento/core/api/effects/ParticleEffect.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.effects; import eu.univento.core.api.utils.reflection.ReflectionUtils; diff --git a/src/main/java/eu/univento/core/api/effects/ParticleWorldBoarder.java b/src/main/java/eu/univento/core/api/effects/ParticleWorldBoarder.java index 843c7cd..db0542c 100644 --- a/src/main/java/eu/univento/core/api/effects/ParticleWorldBoarder.java +++ b/src/main/java/eu/univento/core/api/effects/ParticleWorldBoarder.java @@ -1,7 +1,9 @@ -package eu.univento.core.api.effects; +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ -import java.util.ArrayList; -import java.util.List; +package eu.univento.core.api.effects; import eu.univento.core.api.events.BorderLeaveEvent; import org.bukkit.Bukkit; @@ -12,6 +14,9 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.plugin.Plugin; +import java.util.ArrayList; +import java.util.List; + /** * @author Janhektor * @version 1.0 diff --git a/src/main/java/eu/univento/core/api/entity/ArmorStandAnimator.java b/src/main/java/eu/univento/core/api/entity/ArmorStandAnimator.java index 90feac1..82f127c 100644 --- a/src/main/java/eu/univento/core/api/entity/ArmorStandAnimator.java +++ b/src/main/java/eu/univento/core/api/entity/ArmorStandAnimator.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.entity; import org.bukkit.Location; @@ -12,33 +17,6 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; -/** - * The original thread that this code belongs to can be found here: - * https://www.spigotmc.org/threads/armor-stand-animator-class.152863/ - * MIT License - - Copyright (c) 2016 Bram Stout - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. - * @author Bram - * - */ public class ArmorStandAnimator { /** 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 767cb4d..330efda 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,18 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.entity; import eu.univento.core.Core; -import net.minecraft.server.v1_11_R1.EntityLiving; -import net.minecraft.server.v1_11_R1.NBTTagCompound; +import net.minecraft.server.v1_12_R1.EntityLiving; +import net.minecraft.server.v1_12_R1.NBTTagCompound; import org.bukkit.Bukkit; import org.bukkit.EntityEffect; import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_11_R1.entity.CraftCreature; -import org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_12_R1.entity.CraftCreature; +import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -20,7 +25,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_11_R1.Entity entityS; + private static net.minecraft.server.v1_12_R1.Entity entityS; private static int scheduler; private static Plugin plugin = Core.getInstance(); private static Player player = null; @@ -100,7 +105,7 @@ public class EntityModifier { public Builder setInvulnerable(boolean invulnerable) { try { - Field invulnerableField = net.minecraft.server.v1_11_R1.Entity.class.getDeclaredField("invulnerable"); + Field invulnerableField = net.minecraft.server.v1_12_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 index b4bf39c..3c7580e 100644 --- a/src/main/java/eu/univento/core/api/entity/pathfinding/AStar.java +++ b/src/main/java/eu/univento/core/api/entity/pathfinding/AStar.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 univento.eu - All rights reserved + * Copyright (c) 2017 univento.eu - All rights reserved * You are not allowed to use, distribute or modify this code */ 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 index 30776fb..6d7fa73 100644 --- a/src/main/java/eu/univento/core/api/entity/pathfinding/PathingResult.java +++ b/src/main/java/eu/univento/core/api/entity/pathfinding/PathingResult.java @@ -1,12 +1,12 @@ /* - * Copyright (c) 2016 univento.eu - All rights reserved + * Copyright (c) 2017 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 + * @author Adamk11s * @version 1.0 */ public enum PathingResult { 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 index ca498e5..4923842 100644 --- a/src/main/java/eu/univento/core/api/entity/pathfinding/Tile.java +++ b/src/main/java/eu/univento/core/api/entity/pathfinding/Tile.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 univento.eu - All rights reserved + * Copyright (c) 2017 univento.eu - All rights reserved * You are not allowed to use, distribute or modify this code */ diff --git a/src/main/java/eu/univento/core/api/events/BorderLeaveEvent.java b/src/main/java/eu/univento/core/api/events/BorderLeaveEvent.java index 3f1e453..96bd28a 100644 --- a/src/main/java/eu/univento/core/api/events/BorderLeaveEvent.java +++ b/src/main/java/eu/univento/core/api/events/BorderLeaveEvent.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.events; import org.bukkit.entity.Player; diff --git a/src/main/java/eu/univento/core/api/events/HologramClickEvent.java b/src/main/java/eu/univento/core/api/events/HologramClickEvent.java index 7154416..3876e0e 100644 --- a/src/main/java/eu/univento/core/api/events/HologramClickEvent.java +++ b/src/main/java/eu/univento/core/api/events/HologramClickEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 univento.eu - All rights reserved + * Copyright (c) 2017 univento.eu - All rights reserved * You are not allowed to use, distribute or modify this code */ @@ -12,7 +12,7 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; /** * @author joethei - * @version 0.1 + * @version 1.0 */ public class HologramClickEvent extends PlayerInteractEntityEvent{ diff --git a/src/main/java/eu/univento/core/api/events/MoveEventFilter.java b/src/main/java/eu/univento/core/api/events/MoveEventFilter.java index 3f9a00d..5feb792 100644 --- a/src/main/java/eu/univento/core/api/events/MoveEventFilter.java +++ b/src/main/java/eu/univento/core/api/events/MoveEventFilter.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.events; import org.bukkit.Location; diff --git a/src/main/java/eu/univento/core/api/game/PlayerManager.java b/src/main/java/eu/univento/core/api/game/PlayerManager.java index cb10e09..481f79e 100644 --- a/src/main/java/eu/univento/core/api/game/PlayerManager.java +++ b/src/main/java/eu/univento/core/api/game/PlayerManager.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.game; import eu.univento.core.api.player.CustomPlayer; @@ -7,7 +12,7 @@ import java.util.List; /** * @author joethei - * @version 0.1 + * @version 1.0 */ public class PlayerManager { diff --git a/src/main/java/eu/univento/core/api/game/Team.java b/src/main/java/eu/univento/core/api/game/Team.java index c0e1bc6..5af387c 100644 --- a/src/main/java/eu/univento/core/api/game/Team.java +++ b/src/main/java/eu/univento/core/api/game/Team.java @@ -1,59 +1,51 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.game; import eu.univento.core.api.player.CustomPlayer; +import lombok.Getter; import org.bukkit.Bukkit; import java.util.ArrayList; /** * @author joethei - * @version 0.1 + * @version 1.0 */ + +@Getter public class Team { - private final ArrayList players = new ArrayList<>(); + private ArrayList players = new ArrayList<>(); private final String name; private final String prefix; - private final org.bukkit.scoreboard.Team team; + private final org.bukkit.scoreboard.Team scoreboardTeam; public Team(String name, String prefix) { this.name = name; this.prefix = prefix; if(Bukkit.getScoreboardManager().getMainScoreboard().getTeam(name) == null) { - team = Bukkit.getScoreboardManager().getMainScoreboard().registerNewTeam(name); + scoreboardTeam = Bukkit.getScoreboardManager().getMainScoreboard().registerNewTeam(name); }else{ - team = Bukkit.getScoreboardManager().getMainScoreboard().getTeam(name); + scoreboardTeam = Bukkit.getScoreboardManager().getMainScoreboard().getTeam(name); } - team.setPrefix(prefix); + scoreboardTeam.setPrefix(prefix); } public void addPlayer(CustomPlayer p) { players.add(p); - team.addEntry(p.getName()); + scoreboardTeam.addEntry(p.getName()); } public void removePlayer(CustomPlayer p) { players.remove(p); - team.removeEntry(p.getName()); + scoreboardTeam.removeEntry(p.getName()); } public boolean isPlayer(CustomPlayer p) { return players.contains(p); } - - public String getName() { - return name; - } - - public String getPrefix() { - return prefix; - } - - public ArrayList getPlayers() { - return players; - } - - public org.bukkit.scoreboard.Team getScoreboardTeam() { - return team; - } } \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/game/TeamManager.java b/src/main/java/eu/univento/core/api/game/TeamManager.java index 7601f54..c96dde0 100644 --- a/src/main/java/eu/univento/core/api/game/TeamManager.java +++ b/src/main/java/eu/univento/core/api/game/TeamManager.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.game; import eu.univento.core.api.player.CustomPlayer; @@ -6,7 +11,7 @@ import java.util.ArrayList; /** * @author joethei - * @version 0.1 + * @version 1.0 */ public class TeamManager { diff --git a/src/main/java/eu/univento/core/api/gui/Action.java b/src/main/java/eu/univento/core/api/gui/Action.java new file mode 100644 index 0000000..1f001aa --- /dev/null +++ b/src/main/java/eu/univento/core/api/gui/Action.java @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.core.api.gui; + +import eu.univento.core.api.player.CustomPlayer; + +/** + * @author joethei + * @version 1.0 + */ + +public interface Action { + void onClick(CustomPlayer player); +} 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 3374cfc..399cd94 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,14 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.gui; import eu.univento.core.Core; -import net.minecraft.server.v1_11_R1.*; +import net.minecraft.server.v1_12_R1.*; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_12_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/InventoryGUI.java b/src/main/java/eu/univento/core/api/gui/InventoryGUI.java new file mode 100644 index 0000000..aae1db6 --- /dev/null +++ b/src/main/java/eu/univento/core/api/gui/InventoryGUI.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.core.api.gui; + +import eu.univento.core.Core; +import eu.univento.core.api.player.CustomPlayer; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author joethei + * @version 1.0 + */ +public class InventoryGUI implements Listener{ + + private CustomPlayer player; + private Inventory inventory; + private Map actions; + + public InventoryGUI(CustomPlayer player, int size, String title) { + this.player = player; + inventory = Bukkit.createInventory(player, size, title); + actions = new HashMap<>(); + Bukkit.getPluginManager().registerEvents(this, Core.getInstance()); + } + + public void addItem(int slot, ItemStack item, Action action) { + inventory.setItem(slot, item); + actions.put(slot, action); + } + + public void open() { + player.openInventory(inventory); + } + + @EventHandler + private void onClick(InventoryClickEvent e) { + CustomPlayer p = CustomPlayer.getPlayer((Player) e.getWhoClicked()); + if(e.getInventory().getTitle().equals(inventory.getTitle())) { + if(actions.get(e.getSlot()) != null) { + actions.get(e.getSlot()).onClick(p); + } + } + } +} + + diff --git a/src/main/java/eu/univento/core/api/gui/SignInput.java b/src/main/java/eu/univento/core/api/gui/SignInput.java deleted file mode 100644 index c4e1565..0000000 --- a/src/main/java/eu/univento/core/api/gui/SignInput.java +++ /dev/null @@ -1,21 +0,0 @@ -package eu.univento.core.api.gui; - -import eu.univento.core.api.player.CustomPlayer; -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 - * @version 0.1 - */ -class SignInput { - - public static void openSignInput(CustomPlayer p) { - EntityPlayer player = p.getHandle(); - BlockPosition bp = new BlockPosition(p.getHandle()); - PacketPlayOutOpenSignEditor packet = new PacketPlayOutOpenSignEditor(bp); - player.playerConnection.sendPacket(packet); - SignInputHandler.injectNetty(p); - } -} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/gui/hologram/HologramData.java b/src/main/java/eu/univento/core/api/gui/hologram/HologramData.java index 0baa14e..88e4532 100644 --- a/src/main/java/eu/univento/core/api/gui/hologram/HologramData.java +++ b/src/main/java/eu/univento/core/api/gui/hologram/HologramData.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 univento.eu - All rights reserved + * Copyright (c) 2017 univento.eu - All rights reserved * You are not allowed to use, distribute or modify this code */ diff --git a/src/main/java/eu/univento/core/api/gui/hologram/HologramGUI.java b/src/main/java/eu/univento/core/api/gui/hologram/HologramGUI.java index 4d39879..d5d828e 100644 --- a/src/main/java/eu/univento/core/api/gui/hologram/HologramGUI.java +++ b/src/main/java/eu/univento/core/api/gui/hologram/HologramGUI.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 univento.eu - All rights reserved + * Copyright (c) 2017 univento.eu - All rights reserved * You are not allowed to use, distribute or modify this code */ diff --git a/src/main/java/eu/univento/core/api/gui/hologram/components/ComponentPosition.java b/src/main/java/eu/univento/core/api/gui/hologram/components/ComponentPosition.java index c0a06d5..998d2b0 100644 --- a/src/main/java/eu/univento/core/api/gui/hologram/components/ComponentPosition.java +++ b/src/main/java/eu/univento/core/api/gui/hologram/components/ComponentPosition.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 univento.eu - All rights reserved + * Copyright (c) 2017 univento.eu - All rights reserved * You are not allowed to use, distribute or modify this code */ diff --git a/src/main/java/eu/univento/core/api/gui/hologram/components/ComponentProperties.java b/src/main/java/eu/univento/core/api/gui/hologram/components/ComponentProperties.java index 1008100..7ae149d 100644 --- a/src/main/java/eu/univento/core/api/gui/hologram/components/ComponentProperties.java +++ b/src/main/java/eu/univento/core/api/gui/hologram/components/ComponentProperties.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 univento.eu - All rights reserved + * Copyright (c) 2017 univento.eu - All rights reserved * You are not allowed to use, distribute or modify this code */ diff --git a/src/main/java/eu/univento/core/api/gui/hologram/components/GUIComponent.java b/src/main/java/eu/univento/core/api/gui/hologram/components/GUIComponent.java index ec1cf09..d3ece9b 100644 --- a/src/main/java/eu/univento/core/api/gui/hologram/components/GUIComponent.java +++ b/src/main/java/eu/univento/core/api/gui/hologram/components/GUIComponent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 univento.eu - All rights reserved + * Copyright (c) 2017 univento.eu - All rights reserved * You are not allowed to use, distribute or modify this code */ diff --git a/src/main/java/eu/univento/core/api/gui/hologram/components/GUIPage.java b/src/main/java/eu/univento/core/api/gui/hologram/components/GUIPage.java index 626cf0c..7be0651 100644 --- a/src/main/java/eu/univento/core/api/gui/hologram/components/GUIPage.java +++ b/src/main/java/eu/univento/core/api/gui/hologram/components/GUIPage.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 univento.eu - All rights reserved + * Copyright (c) 2017 univento.eu - All rights reserved * You are not allowed to use, distribute or modify this code */ diff --git a/src/main/java/eu/univento/core/api/gui/hologram/components/GUIPageModel.java b/src/main/java/eu/univento/core/api/gui/hologram/components/GUIPageModel.java index d0d41ca..3ae4246 100644 --- a/src/main/java/eu/univento/core/api/gui/hologram/components/GUIPageModel.java +++ b/src/main/java/eu/univento/core/api/gui/hologram/components/GUIPageModel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 univento.eu - All rights reserved + * Copyright (c) 2017 univento.eu - All rights reserved * You are not allowed to use, distribute or modify this code */ diff --git a/src/main/java/eu/univento/core/api/gui/hologram/components/IValueHolder.java b/src/main/java/eu/univento/core/api/gui/hologram/components/IValueHolder.java index 61ba726..d83817a 100644 --- a/src/main/java/eu/univento/core/api/gui/hologram/components/IValueHolder.java +++ b/src/main/java/eu/univento/core/api/gui/hologram/components/IValueHolder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 univento.eu - All rights reserved + * Copyright (c) 2017 univento.eu - All rights reserved * You are not allowed to use, distribute or modify this code */ diff --git a/src/main/java/eu/univento/core/api/gui/hologram/components/PlayerGUIComponent.java b/src/main/java/eu/univento/core/api/gui/hologram/components/PlayerGUIComponent.java index 8f6cf00..826cbee 100644 --- a/src/main/java/eu/univento/core/api/gui/hologram/components/PlayerGUIComponent.java +++ b/src/main/java/eu/univento/core/api/gui/hologram/components/PlayerGUIComponent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 univento.eu - All rights reserved + * Copyright (c) 2017 univento.eu - All rights reserved * You are not allowed to use, distribute or modify this code */ diff --git a/src/main/java/eu/univento/core/api/gui/hologram/components/PlayerGUIPage.java b/src/main/java/eu/univento/core/api/gui/hologram/components/PlayerGUIPage.java index e593873..059077f 100644 --- a/src/main/java/eu/univento/core/api/gui/hologram/components/PlayerGUIPage.java +++ b/src/main/java/eu/univento/core/api/gui/hologram/components/PlayerGUIPage.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 univento.eu - All rights reserved + * Copyright (c) 2017 univento.eu - All rights reserved * You are not allowed to use, distribute or modify this code */ diff --git a/src/main/java/eu/univento/core/api/gui/hologram/components/PlayerGUIPageModel.java b/src/main/java/eu/univento/core/api/gui/hologram/components/PlayerGUIPageModel.java index f6fec98..7613684 100644 --- a/src/main/java/eu/univento/core/api/gui/hologram/components/PlayerGUIPageModel.java +++ b/src/main/java/eu/univento/core/api/gui/hologram/components/PlayerGUIPageModel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 univento.eu - All rights reserved + * Copyright (c) 2017 univento.eu - All rights reserved * You are not allowed to use, distribute or modify this code */ diff --git a/src/main/java/eu/univento/core/api/gui/hologram/components/PlayerGUITextBoxComponent.java b/src/main/java/eu/univento/core/api/gui/hologram/components/PlayerGUITextBoxComponent.java index 70a7466..cde7305 100644 --- a/src/main/java/eu/univento/core/api/gui/hologram/components/PlayerGUITextBoxComponent.java +++ b/src/main/java/eu/univento/core/api/gui/hologram/components/PlayerGUITextBoxComponent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 univento.eu - All rights reserved + * Copyright (c) 2017 univento.eu - All rights reserved * You are not allowed to use, distribute or modify this code */ diff --git a/src/main/java/eu/univento/core/api/gui/hologram/components/PlayerGUIValueBoxComponent.java b/src/main/java/eu/univento/core/api/gui/hologram/components/PlayerGUIValueBoxComponent.java index 731a0cd..1c7a338 100644 --- a/src/main/java/eu/univento/core/api/gui/hologram/components/PlayerGUIValueBoxComponent.java +++ b/src/main/java/eu/univento/core/api/gui/hologram/components/PlayerGUIValueBoxComponent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 univento.eu - All rights reserved + * Copyright (c) 2017 univento.eu - All rights reserved * You are not allowed to use, distribute or modify this code */ diff --git a/src/main/java/eu/univento/core/api/gui/hologram/components/StationaryPlayerGUIPage.java b/src/main/java/eu/univento/core/api/gui/hologram/components/StationaryPlayerGUIPage.java index 022edff..f2af365 100644 --- a/src/main/java/eu/univento/core/api/gui/hologram/components/StationaryPlayerGUIPage.java +++ b/src/main/java/eu/univento/core/api/gui/hologram/components/StationaryPlayerGUIPage.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 univento.eu - All rights reserved + * Copyright (c) 2017 univento.eu - All rights reserved * You are not allowed to use, distribute or modify this code */ diff --git a/src/main/java/eu/univento/core/api/gui/PlayerSignInputEvent.java b/src/main/java/eu/univento/core/api/gui/sign/PlayerSignInputEvent.java similarity index 77% rename from src/main/java/eu/univento/core/api/gui/PlayerSignInputEvent.java rename to src/main/java/eu/univento/core/api/gui/sign/PlayerSignInputEvent.java index a79e9b3..7129719 100644 --- a/src/main/java/eu/univento/core/api/gui/PlayerSignInputEvent.java +++ b/src/main/java/eu/univento/core/api/gui/sign/PlayerSignInputEvent.java @@ -1,4 +1,9 @@ -package eu.univento.core.api.gui; +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.core.api.gui.sign; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; @@ -16,7 +21,6 @@ class PlayerSignInputEvent extends PlayerEvent{ public PlayerSignInputEvent(Player p, String[] lines) { super(p); this.lines = lines; - SignInputHandler.ejectNetty(p); } @Override diff --git a/src/main/java/eu/univento/core/api/gui/sign/SignInput.java b/src/main/java/eu/univento/core/api/gui/sign/SignInput.java new file mode 100644 index 0000000..0e3a50a --- /dev/null +++ b/src/main/java/eu/univento/core/api/gui/sign/SignInput.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.core.api.gui.sign; + +import eu.univento.core.api.player.CustomPlayer; +import lombok.Getter; +import net.minecraft.server.v1_12_R1.BlockPosition; +import net.minecraft.server.v1_12_R1.PacketPlayOutOpenSignEditor; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; + +/** + * @author joethei + * @version 1.0 + */ + +class SignInput implements Listener{ + + @Getter private CustomPlayer player; + @Getter private String[] lines; + + public SignInput(CustomPlayer player, String[] lines) { + this.player = player; + this.lines = lines; + } + + private static Map> futures = new HashMap<>(); + + + public static CompletableFuture openSignInput(CustomPlayer p) { + CompletableFuture future = new CompletableFuture<>(); + p.sendPacket(new PacketPlayOutOpenSignEditor(new BlockPosition(p.getHandle()))); + SignInputHandler.injectNetty(p); + futures.put(p.getUniqueId(), future); + return future; + } + + @EventHandler + public void onSignInput(PlayerSignInputEvent e) { + if(futures.get(e.getPlayer().getUniqueId()) != null) { + futures.get(e.getPlayer().getUniqueId()).complete(new SignInput(CustomPlayer.getPlayer(e.getPlayer()), e.getLines())); + SignInputHandler.ejectNetty(e.getPlayer()); + } + } + + + + /* + + public static void openSignInput(CustomPlayer p) { + EntityPlayer player = p.getHandle(); + BlockPosition bp = new BlockPosition(p.getHandle()); + PacketPlayOutOpenSignEditor packet = new PacketPlayOutOpenSignEditor(bp); + player.playerConnection.sendPacket(packet); + SignInputHandler.injectNetty(p); + } + */ + +} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/gui/SignInputHandler.java b/src/main/java/eu/univento/core/api/gui/sign/SignInputHandler.java similarity index 76% rename from src/main/java/eu/univento/core/api/gui/SignInputHandler.java rename to src/main/java/eu/univento/core/api/gui/sign/SignInputHandler.java index 646e13d..49585c4 100644 --- a/src/main/java/eu/univento/core/api/gui/SignInputHandler.java +++ b/src/main/java/eu/univento/core/api/gui/sign/SignInputHandler.java @@ -1,13 +1,18 @@ -package eu.univento.core.api.gui; +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.core.api.gui.sign; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToMessageDecoder; -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 net.minecraft.server.v1_12_R1.NetworkManager; +import net.minecraft.server.v1_12_R1.Packet; +import net.minecraft.server.v1_12_R1.PacketPlayInUpdateSign; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import java.lang.reflect.Field; @@ -22,15 +27,15 @@ class SignInputHandler { private static Field channelField = null; static{ - for(Field filed : NetworkManager.class.getDeclaredFields()) { + for(Field field : NetworkManager.class.getDeclaredFields()) { if(channelField.getType().isAssignableFrom(Channel.class)) { - channelField = filed; + channelField = field; break; } } } - public static void injectNetty(final Player player) { + static void injectNetty(final Player player) { try { Channel channel = (Channel) channelField.get(((CraftPlayer) player).getHandle().playerConnection.networkManager); if (channel != null) { @@ -52,7 +57,7 @@ class SignInputHandler { } } - public static void ejectNetty(Player player) { + static void ejectNetty(Player player) { try { Channel channel = (Channel) channelField.get(((CraftPlayer) player).getHandle().playerConnection.networkManager); if (channel != null) { diff --git a/src/main/java/eu/univento/core/api/hologram/Hologram.java b/src/main/java/eu/univento/core/api/hologram/Hologram.java index bbec925..eb2a44a 100644 --- a/src/main/java/eu/univento/core/api/hologram/Hologram.java +++ b/src/main/java/eu/univento/core/api/hologram/Hologram.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 univento.eu - All rights reserved + * Copyright (c) 2017 univento.eu - All rights reserved * You are not allowed to use, distribute or modify this code */ @@ -9,13 +9,13 @@ import eu.univento.core.Core; import eu.univento.core.api.events.HologramClickEvent; import eu.univento.core.api.player.CustomPlayer; import lombok.Getter; -import net.minecraft.server.v1_11_R1.EntityArmorStand; -import net.minecraft.server.v1_11_R1.PacketPlayOutEntityDestroy; -import net.minecraft.server.v1_11_R1.PacketPlayOutSpawnEntityLiving; +import net.minecraft.server.v1_12_R1.EntityArmorStand; +import net.minecraft.server.v1_12_R1.PacketPlayOutEntityDestroy; +import net.minecraft.server.v1_12_R1.PacketPlayOutSpawnEntityLiving; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_11_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; import org.bukkit.entity.ArmorStand; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; diff --git a/src/main/java/eu/univento/core/api/hologram/HologramManager.java b/src/main/java/eu/univento/core/api/hologram/HologramManager.java index 4d865e8..8f017d4 100644 --- a/src/main/java/eu/univento/core/api/hologram/HologramManager.java +++ b/src/main/java/eu/univento/core/api/hologram/HologramManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 univento.eu - All rights reserved + * Copyright (c) 2017 univento.eu - All rights reserved * You are not allowed to use, distribute or modify this code */ @@ -11,7 +11,7 @@ import java.util.HashMap; /** * @author joethei - * @version 0.1 + * @version 1.0 */ public class HologramManager { diff --git a/src/main/java/eu/univento/core/api/items/ClickInventory.java b/src/main/java/eu/univento/core/api/items/ClickInventory.java deleted file mode 100644 index e995d65..0000000 --- a/src/main/java/eu/univento/core/api/items/ClickInventory.java +++ /dev/null @@ -1,238 +0,0 @@ -package eu.univento.core.api.items; - -import eu.univento.core.api.items.events.NamedCloseEvent; -import eu.univento.core.api.items.events.PageCloseEvent; -import eu.univento.core.api.player.CustomPlayer; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryDragEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.metadata.FixedMetadataValue; -import org.bukkit.plugin.java.JavaPlugin; - -import java.lang.reflect.Array; -import java.util.HashMap; - -/** - * @author joethei - * @version 0.1 - */ -public abstract class ClickInventory{ - - protected static JavaPlugin plugin; - protected Inventory currentInventory; - protected boolean inventoryInUse; - private boolean modifiable; - private CustomPlayer player; - private boolean playerInventoryUsed; - private ItemStack[] previousContents; - private String inventoryName; - private HashMap savedData; - - protected void saveContents() { - this.previousContents = this.getPlayer().getInventory().getContents().clone(); - } - - public Object getData(final Object key) { - return this.savedData.get(key); - } - - public ClickInventory setData(final Object key, final Object obj) { - if (obj == null) { - this.savedData.remove(key); - } - else { - this.savedData.put(key, obj); - } - return this; - } - - public ClickInventory(String inventoryName, final CustomPlayer player) { - this.savedData = new HashMap<>(); - this.player = player; - if (inventoryName == null) { - inventoryName = this.getClass().getSimpleName(); - } - this.inventoryName = inventoryName; - } - - public String getName() { - return this.inventoryName; - } - - public ClickInventory setPlayerInventory() { - if (!this.isInUse()) { - this.playerInventoryUsed = true; - } - return this; - } - - public void closeInventory() { - this.closeInventory(true); - } - - protected void onInventoryDrag(final InventoryDragEvent event) { - if (!this.isModifiable()) { - event.getRawSlots().stream().filter(this::checkInMenu).forEachOrdered(slot -> event.setCancelled(true)); - } - } - - protected boolean checkInMenu(int rawSlot) { - if (this.isPlayerInventory()) { - if (this.getPlayer().getOpenInventory().getTopInventory().getHolder() != this.getPlayer()) { - rawSlot -= this.getPlayer().getOpenInventory().getTopInventory().getSize(); - } - return rawSlot >= 0 && rawSlot < this.currentInventory.getSize(); - } - return rawSlot < this.currentInventory.getSize(); - } - - public boolean isPlayerInventory() { - return this.playerInventoryUsed; - } - - protected abstract void onInventoryClick(final InventoryClickEvent e); - - private void closeInventory(final boolean forceClose, final boolean restoreInventory) { - InventoryManager.removeInventory(this); - this.inventoryInUse = false; - if (this.getPlayer().hasMetadata(this.getClass().getSimpleName())) { - final E[] invs = (E[])this.getPlayer().getMetadata(this.getClass().getSimpleName()).get(0).value(); - if (invs[isPlayerInventory() ? 1 : 0] == this) - invs[isPlayerInventory() ? 1 : 0] = null; - } - if (this instanceof NamedInventory) { - Bukkit.getPluginManager().callEvent(new NamedCloseEvent((NamedInventory) this)); - } - if (this instanceof PageInventory) { - Bukkit.getPluginManager().callEvent(new PageCloseEvent((PageInventory) this)); - } - if (forceClose && (!this.isPlayerInventory() || this.getPlayer().getOpenInventory().getTopInventory().equals(this.currentInventory))) { - this.getPlayer().closeInventory(); - } - if (this.isPlayerInventory() && restoreInventory) { - this.getPlayer().getInventory().clear(); - this.getPlayer().getInventory().setContents(this.previousContents); - Bukkit.getScheduler().scheduleSyncDelayedTask(ClickInventory.plugin, () -> ClickInventory.this.getPlayer().updateInventory()); - } - } - - public void closeInventory(final boolean forceClose) { - this.closeInventory(forceClose, true); - } - - public ItemStack getItem(int slot) { - if (this.isPlayerInventory()) { - slot += 9; - if (slot >= 36) { - slot -= 36; - } - } - if (this.currentInventory != null && this.currentInventory.getSize() > slot) { - return this.currentInventory.getItem(slot); - } - return null; - } - - protected void setItems(final ItemStack[] items) { - if (this.isPlayerInventory()) { - for (int i = 0; i < items.length; ++i) { - this.setItem(i, items[i]); - } - } - else { - this.currentInventory.setContents(items); - } - } - - protected void setItem(int slot, final ItemStack item) { - if (this.isPlayerInventory()) { - slot += 9; - if (slot >= 36) { - slot -= 36; - } - } - this.currentInventory.setItem(slot, item); - } - - public CustomPlayer getPlayer() { - return this.player; - } - - public boolean isInUse() { - return this.inventoryInUse; - } - - public boolean isModifiable() { - return this.modifiable; - } - - protected void openInventory() { - final boolean isSwitchingInventory = this.isInUse(); - ItemStack heldItem = null; - final ClickInventory[] invs = new ClickInventory[2]; - for (final String inv : new String[] { "PageInventory", "NamedInventory", "AnvilInventory" }) { - if (this.getPlayer().hasMetadata(inv)) { - final E[] invss = (E[])(this.getPlayer().hasMetadata(inv) ? this.getPlayer().getMetadata(inv).get(0).value() : null); - if (invss != null) { - for (int i = 0; i < 2; ++i) { - if (invss[i] != null) { - invs[i] = (ClickInventory)invss[i]; - } - } - } - } - } - if (!this.isPlayerInventory()) { - this.inventoryInUse = false; - boolean previous = false; - if (invs[1] != null) { - previous = invs[1].inventoryInUse; - invs[1].inventoryInUse = false; - } - if (isSwitchingInventory) { - heldItem = this.getPlayer().getItemOnCursor(); - this.getPlayer().setItemOnCursor(new ItemStack(Material.AIR)); - } - if (invs[1] != null) { - invs[1].inventoryInUse = previous; - } - } - else { - this.getPlayer().updateInventory(); - if (!isSwitchingInventory && this.getPlayer().getOpenInventory().getTopInventory().getHolder() == this.getPlayer()) { - this.getPlayer().openInventory(Bukkit.createInventory(null, 0, this.getTitle())); - } - } - if (!isSwitchingInventory) { - InventoryManager.addInventory(this); - final int slot = this.isPlayerInventory() ? 1 : 0; - if (invs[slot] != null) { - if (invs[slot].inventoryInUse) { - invs[slot].closeInventory(false, false); - } - if (this.isPlayerInventory()) { - this.previousContents = invs[1].previousContents; - } - } - final E[] inv2 = (E[])(this.getPlayer().hasMetadata(this.getClass().getSimpleName()) ? this.getPlayer().getMetadata(this.getClass().getSimpleName()).get(0).value() : ((Object[]) Array.newInstance(this.getClass(), 2))); - inv2[slot] = (E)this; - this.getPlayer().setMetadata(this.getClass().getSimpleName(), new FixedMetadataValue(ClickInventory.plugin, inv2)); - } - else if (heldItem != null && heldItem.getType() != Material.AIR) { - this.getPlayer().setItemOnCursor(heldItem); - this.getPlayer().updateInventory(); - } - this.inventoryInUse = true; - } - - public abstract String getTitle(); - - public void setModifiable(final boolean modifiable) { - this.modifiable = modifiable; - } - - public abstract void setTitle(final String p0); -} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/items/InventoryManager.java b/src/main/java/eu/univento/core/api/items/InventoryManager.java deleted file mode 100644 index a4c2b5f..0000000 --- a/src/main/java/eu/univento/core/api/items/InventoryManager.java +++ /dev/null @@ -1,94 +0,0 @@ -package eu.univento.core.api.items; - -import eu.univento.core.api.player.CustomPlayer; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryDragEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.inventory.ItemStack; - -import java.util.List; - -/** - * @author joethei - * @version 0.1 - */ -public class InventoryManager implements Listener{ - - private static List inventoryList; - - public static List getInventoryList() { - return inventoryList; - } - - public static void addInventory(ClickInventory inventory) { - inventoryList.add(inventory); - } - - public static void removeInventory(ClickInventory inventory) { - inventoryList.remove(inventory); - } - - public static NamedInventory[] getNamedInventories(final CustomPlayer p) { - if(!p.hasMetadata("NamedInventory")) return new NamedInventory[2]; - return ((NamedInventory[])p.getMetadata("NamedInventory").get(0).value()).clone(); - } - - public static NamedInventory getNamedInventory(final CustomPlayer p) { - return getNamedInventories(p)[0]; - } - - public static PageInventory[] getPageInventories(final CustomPlayer p) { - if(!p.hasMetadata("PageInventory")) return new PageInventory[2]; - return ((PageInventory[])p.getMetadata("PageInventory").get(0).value()).clone(); - } - - public static PageInventory getPageInventory(CustomPlayer p) { - return getPageInventories(p)[0]; - } - - public static ItemStack[] generateEmptyPage(int size) { - size = (int) (Math.ceil(size / 9.0) * 9); - return new ItemStack[Math.min(54, size)]; - } - - @EventHandler - public void onInventoryClick(InventoryClickEvent e) { - int i = 0; - CustomPlayer p = CustomPlayer.getPlayer((Player) e.getWhoClicked()); - if(e.getInventory() instanceof ClickInventory) { - for(ClickInventory inventory : inventoryList) { - if(inventory.getPlayer() == p) - inventory.onInventoryClick(e); - if(i++ == 1) break; - } - } - } - - @EventHandler - public void onInventoryDrag(InventoryDragEvent e) { - int i = 0; - CustomPlayer p = CustomPlayer.getPlayer((Player) e.getWhoClicked()); - for(ClickInventory inventory : inventoryList) { - if(inventory.getPlayer() == p) { - inventory.onInventoryDrag(e); - if(i++ == 1) break; - } - } - } - - @EventHandler - public void onQuit(PlayerQuitEvent e) { - int i = 0; - CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); - if(inventoryList == null) return; - for(ClickInventory inventory : inventoryList) { - if(inventory.getPlayer() == p) { - if(inventory.isInUse()) inventory.closeInventory(false); - if(i ++ == 1) break; - } - } - } -} \ No newline at end of file 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 c72a5e2..b0bd34d 100644 --- a/src/main/java/eu/univento/core/api/items/ItemBuilder.java +++ b/src/main/java/eu/univento/core/api/items/ItemBuilder.java @@ -1,5 +1,19 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.items; +import com.mojang.authlib.GameProfile; +import eu.univento.commons.player.language.MessageConstant; +import eu.univento.commons.player.user.UserInformation; +import eu.univento.core.api.items.attribute.Attribute; +import eu.univento.core.api.items.attribute.AttributeModifier; +import eu.univento.core.api.items.attribute.ItemAttributes; +import eu.univento.core.api.items.attribute.ItemSlot; +import eu.univento.core.api.player.CustomPlayer; +import eu.univento.core.api.utils.GameProfileBuilder; import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; @@ -10,6 +24,8 @@ import org.bukkit.inventory.meta.LeatherArmorMeta; import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.material.MaterialData; +import java.io.IOException; +import java.lang.reflect.Field; import java.util.*; /** @@ -28,8 +44,9 @@ import java.util.*; public class ItemBuilder { - private final ItemStack item; - private final ItemMeta itemM; + private CustomPlayer player; + private ItemStack item; + private ItemMeta meta; /** * Init item chainable via given Material parameter. @@ -38,31 +55,22 @@ public class ItemBuilder { * * @since 1.0 */ - public ItemBuilder(final Material itemType){ + public ItemBuilder(final Material itemType) { item = new ItemStack(itemType); - itemM = item.getItemMeta(); + meta = item.getItemMeta(); } /** - * Init item chainable via given ItemStack parameter. + * Init item chainable via given Material parameter. * - * @param itemStack the {@link ItemStack} to initialize the instance with. + * @param itemType the {@link Material} to initiate the instance with. * * @since 1.0 */ - public ItemBuilder(final ItemStack itemStack){ - item = itemStack; - itemM = item.getItemMeta(); - } - - /** - * Init the item chainable with no defined Material/ItemStack - * - * @since 1.0 - */ - public ItemBuilder(){ - item = new ItemStack(Material.AIR); - itemM = item.getItemMeta(); + public ItemBuilder(final CustomPlayer player, final Material itemType) { + this.player = player; + item = new ItemStack(itemType); + meta = item.getItemMeta(); } /** @@ -73,8 +81,8 @@ public class ItemBuilder { * @return the current instance for chainable application. * @since 1.0 */ - public ItemBuilder type(final Material material){ - make().setType(material); + public ItemBuilder type(final Material material) { + item.setType(material); return this; } @@ -86,8 +94,8 @@ public class ItemBuilder { * @return the current instance for chainable application. * @since 1.0 */ - public ItemBuilder amount(final Integer itemAmt){ - make().setAmount(itemAmt); + public ItemBuilder amount(final Integer itemAmt) { + item.setAmount(itemAmt); return this; } @@ -99,9 +107,16 @@ public class ItemBuilder { * @return the current instance for chainable application. * @since 1.0 */ - public ItemBuilder name(final String name){ - meta().setDisplayName(name); - make().setItemMeta(meta()); + public ItemBuilder name(final String name) { + meta.setDisplayName(name); + item.setItemMeta(meta); + return this; + } + + public ItemBuilder name(final MessageConstant messageConstant) { + if(player == null) return this; + meta.setDisplayName(player.getDatabasePlayer().getLanguage().getMessage(messageConstant)); + item.setItemMeta(meta); return this; } @@ -113,12 +128,12 @@ public class ItemBuilder { * @return the current instance for chainable application. * @since 1.0 */ - public ItemBuilder lore(final String lore){ - List lores = meta().getLore(); + public ItemBuilder lore(final String lore) { + List lores = meta.getLore(); if(lores == null){lores = new ArrayList<>();} lores.add(lore); - meta().setLore(lores); - make().setItemMeta(meta()); + meta.setLore(lores); + item.setItemMeta(meta); return this; } @@ -130,17 +145,17 @@ public class ItemBuilder { * @return the current instance for chainable application. * @since 1.0 */ - public ItemBuilder lores(final String[] lores){ - List loresList = meta().getLore(); - if(loresList == null){loresList = new ArrayList<>();} + public ItemBuilder lores(final String[] lores) { + List loresList = meta.getLore(); + if(loresList == null) loresList = new ArrayList<>(); else{loresList.clear();} Collections.addAll(loresList, lores); - meta().setLore(loresList); + meta.setLore(loresList); return this; } public ItemBuilder durability(short durability) { - make().setDurability(durability); + item.setDurability(durability); return this; } @@ -153,8 +168,8 @@ public class ItemBuilder { * @since 1.0 */ @SuppressWarnings("deprecation") - public ItemBuilder data(final int data){ - make().setData(new MaterialData(make().getType(), (byte)data)); + public ItemBuilder data(final int data) { + item.setData(new MaterialData(build().getType(), (byte)data)); return this; } @@ -168,8 +183,8 @@ public class ItemBuilder { * @return the current instance for chainable application. * @since 1.0 */ - public ItemBuilder enchantment(final Enchantment enchantment, final int level){ - make().addUnsafeEnchantment(enchantment, level); + public ItemBuilder enchantment(final Enchantment enchantment, final int level) { + item.addUnsafeEnchantment(enchantment, level); return this; } @@ -181,8 +196,8 @@ public class ItemBuilder { * @return the current instance for chainable application. * @since 1.0 */ - public ItemBuilder enchantment(final Enchantment enchantment){ - make().addUnsafeEnchantment(enchantment, 1); + public ItemBuilder enchantment(final Enchantment enchantment) { + item.addUnsafeEnchantment(enchantment, 1); return this; } @@ -196,10 +211,10 @@ public class ItemBuilder { * @return the current instance for chainable application. * @since 1.0 */ - public ItemBuilder enchantments(final Enchantment[] enchantments, final int level){ - make().getEnchantments().clear(); + public ItemBuilder enchantments(final Enchantment[] enchantments, final int level) { + item.getEnchantments().clear(); for(Enchantment enchantment : enchantments){ - make().addUnsafeEnchantment(enchantment, level); + item.addUnsafeEnchantment(enchantment, level); } return this; } @@ -212,10 +227,10 @@ public class ItemBuilder { * @return the current instance for chainable application. * @since 1.0 */ - public ItemBuilder enchantments(final Enchantment[] enchantments){ - make().getEnchantments().clear(); + public ItemBuilder enchantments(final Enchantment[] enchantments) { + item.getEnchantments().clear(); for(Enchantment enchantment : enchantments){ - make().addUnsafeEnchantment(enchantment, 1); + item.addUnsafeEnchantment(enchantment, 1); } return this; } @@ -228,8 +243,8 @@ public class ItemBuilder { * @return the current instance for chainable application. * @since 1.0 */ - public ItemBuilder clearEnchantment(final Enchantment enchantment){ - Map itemEnchantments = make().getEnchantments(); + public ItemBuilder clearEnchantment(final Enchantment enchantment) { + Map itemEnchantments = item.getEnchantments(); itemEnchantments.keySet().stream().filter(enchantmentC -> enchantment == enchantmentC).forEach(itemEnchantments::remove); return this; } @@ -240,13 +255,20 @@ public class ItemBuilder { * @return the current instance for chainable application. * @since 1.0 */ - public ItemBuilder clearEnchantments(){ - make().getEnchantments().clear(); + public ItemBuilder clearEnchantments() { + item.getEnchantments().clear(); + return this; + } + + public ItemBuilder attribute(Attribute attribute, String name, ItemSlot slot, int operation, double amount) { + ItemAttributes attributes = new ItemAttributes(); + attributes.addModifier(new AttributeModifier(attribute, name, slot, operation, amount, UUID.randomUUID())); + this.item = attributes.apply(this.item); return this; } public ItemBuilder glow() { - meta().addEnchant(Enchantment.ARROW_DAMAGE, 10, false); + meta.addEnchant(Enchantment.ARROW_DAMAGE, 10, false); return this; } @@ -258,11 +280,11 @@ public class ItemBuilder { * @return the current instance for chainable application. * @since 1.0 */ - public ItemBuilder clearLore(final String lore){ - if(meta().getLore().contains(lore)){ - meta().getLore().remove(lore); + public ItemBuilder clearLore(final String lore) { + if(meta.getLore().contains(lore)){ + meta.getLore().remove(lore); } - make().setItemMeta(meta()); + item.setItemMeta(meta); return this; } @@ -272,9 +294,9 @@ public class ItemBuilder { * @return the current instance for chainable application. * @since 1.0 */ - public ItemBuilder clearLores(){ - meta().getLore().clear(); - make().setItemMeta(meta()); + public ItemBuilder clearLores() { + meta.getLore().clear(); + item.setItemMeta(meta); return this; } @@ -286,14 +308,14 @@ public class ItemBuilder { * @return the current instance for chainable application. * @since 1.0 */ - public ItemBuilder color(final Color color){ - if(make().getType() == Material.LEATHER_HELMET - || make().getType() == Material.LEATHER_CHESTPLATE - || make().getType() == Material.LEATHER_LEGGINGS - || make().getType() == Material.LEATHER_BOOTS ){ - LeatherArmorMeta meta = (LeatherArmorMeta) meta(); + public ItemBuilder color(final Color color) { + if(item.getType() == Material.LEATHER_HELMET + || item.getType() == Material.LEATHER_CHESTPLATE + || item.getType() == Material.LEATHER_LEGGINGS + || item.getType() == Material.LEATHER_BOOTS ){ + LeatherArmorMeta meta = (LeatherArmorMeta) this.meta; meta.setColor(color); - make().setItemMeta(meta); + item.setItemMeta(meta); } return this; } @@ -304,14 +326,14 @@ public class ItemBuilder { * @return the current instance for chainable application. * @since 1.0 */ - public ItemBuilder clearColor(){ - if(make().getType() == Material.LEATHER_HELMET - || make().getType() == Material.LEATHER_CHESTPLATE - || make().getType() == Material.LEATHER_LEGGINGS - || make().getType() == Material.LEATHER_BOOTS ){ - LeatherArmorMeta meta = (LeatherArmorMeta) meta(); + public ItemBuilder clearColor() { + if(item.getType() == Material.LEATHER_HELMET + || item.getType() == Material.LEATHER_CHESTPLATE + || item.getType() == Material.LEATHER_LEGGINGS + || item.getType() == Material.LEATHER_BOOTS ){ + LeatherArmorMeta meta = (LeatherArmorMeta) this.meta; meta.setColor(null); - make().setItemMeta(meta); + item.setItemMeta(meta); } return this; } @@ -319,27 +341,42 @@ 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 uuid 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 */ - public ItemBuilder skullOwner(final String name){ - if(make().getType() == Material.SKULL_ITEM && make().getDurability() == (byte) 3){ - SkullMeta skullMeta = (SkullMeta) meta(); - skullMeta.setOwner(name); - make().setItemMeta(meta()); + public ItemBuilder skullOwner(final UUID uuid) { + if(item.getType() == Material.SKULL_ITEM && item.getDurability() == (byte) 3){ + SkullMeta skullMeta = (SkullMeta) meta; + + try { + GameProfile profile = GameProfileBuilder.fetch(uuid); + Field field = skullMeta.getClass().getDeclaredField("profile"); + field.setAccessible(true); + field.set(skullMeta, profile); + + item.setItemMeta(meta); + } catch (IOException | NoSuchFieldException | IllegalAccessException e) { + e.printStackTrace(); + } + } return this; } + public ItemBuilder skullOwner(final String name) { + UserInformation.get(name).whenComplete((userInformation, throwable) -> skullOwner(userInformation.getUuid())); + return this; + } + /** * Returns the {@link ItemMeta} of the {@link ItemStack} * * @return the ItemMeta of the ItemStack. */ - private ItemMeta meta(){ - return itemM; + private ItemMeta meta() { + return meta; } /** @@ -347,7 +384,7 @@ public class ItemBuilder { * * @return the ItemStack of the ItemBuilder instance. */ - public ItemStack make(){ + public ItemStack build() { item.getItemMeta().addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_DESTROYS, ItemFlag.HIDE_UNBREAKABLE, ItemFlag.HIDE_ENCHANTS); return item; } diff --git a/src/main/java/eu/univento/core/api/items/NamedInventory.java b/src/main/java/eu/univento/core/api/items/NamedInventory.java deleted file mode 100644 index b4c9ba1..0000000 --- a/src/main/java/eu/univento/core/api/items/NamedInventory.java +++ /dev/null @@ -1,205 +0,0 @@ -package eu.univento.core.api.items; - -import eu.univento.core.api.items.events.NamedPageClickEvent; -import eu.univento.core.api.player.CustomPlayer; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemStack; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; - -/** - * @author joethei - * @version 0.1 - */ -public class NamedInventory extends ClickInventory{ - - protected Page currentPage; - protected HashMap pageDirectors; - protected HashMap pages; - - public NamedInventory(final CustomPlayer player) { - this(null, player); - } - - public NamedInventory(final CustomPlayer player, final boolean dymanicInventory) { - this(player); - } - - public NamedInventory(final String inventoryName, final CustomPlayer player) { - super(inventoryName, player); - this.pageDirectors = new HashMap<>(); - this.pages = new HashMap<>(); - } - - public Page getCurrentPage() { - return this.currentPage; - } - - public ItemStack[] getPage(final Page page) { - return this.pages.get(page); - } - - public Page getPage(final String pageName) { - for (final Page page : this.pages.keySet()) { - if (page.getPageName().equals(pageName)) { - return page; - } - } - return null; - } - - public Page getPageLink(final ItemStack item) { - return this.pageDirectors.get(item); - } - - public HashMap getPages() { - return this.pages; - } - - @Override - public String getTitle() { - return this.currentPage.getPageDisplayTitle(); - } - - public void linkPage(final ItemStack item, final Page page) { - this.pageDirectors.put(item, page); - } - - public void linkPage(final ItemStack item, final String pageName) { - final Page page = this.getPage(pageName); - if (page != null) { - this.linkPage(item, page); - } - } - - @Override - protected void onInventoryClick(final InventoryClickEvent event) { - final ItemStack item = event.getCurrentItem(); - if (this.checkInMenu(event.getRawSlot())) { - if (item != null && this.pageDirectors.containsKey(item)) { - event.setCancelled(true); - this.setPage(this.pageDirectors.get(item)); - return; - } - int slot = event.getSlot(); - if (this.isPlayerInventory()) { - slot -= 9; - if (slot < 0) { - slot += 36; - } - } - final NamedPageClickEvent itemClickEvent = new NamedPageClickEvent(this, this.currentPage, slot, event); - if (!this.isModifiable()) { - itemClickEvent.setCancelled(true); - } - Bukkit.getPluginManager().callEvent(itemClickEvent); - if (itemClickEvent.isCancelled()) { - event.setCancelled(true); - } - } - else if (!this.isModifiable() && event.isShiftClick() && item != null && item.getType() != Material.AIR) { - for (int slot = 0; slot < this.currentInventory.getSize(); ++slot) { - final ItemStack invItem = this.currentInventory.getItem(slot); - if (invItem == null || invItem.getType() == Material.AIR || (invItem.isSimilar(item) && invItem.getAmount() < invItem.getMaxStackSize())) { - event.setCancelled(true); - break; - } - } - } - } - - public void openInventory() { - if (this.isInUse()) { - return; - } - if (this.isPlayerInventory()) { - this.saveContents(); - } - if (this.currentPage == null) { - if (this.pages.isEmpty()) { - this.pages.put(new Page("Inventory"), new ItemStack[0]); - } - this.currentPage = this.pages.keySet().iterator().next(); - } - if (this.currentInventory == null) { - final ItemStack[] pageItems = this.getPage(this.currentPage); - if (this.isPlayerInventory()) { - this.currentInventory = this.getPlayer().getInventory(); - } - else { - this.currentInventory = Bukkit.createInventory(null, pageItems.length, this.getTitle()); - } - this.setItems(pageItems); - } - this.openInventory(); - } - - public void removePage(final Page page) { - this.pages.remove(page); - } - - public void setPage(final Page newPage) { - if (this.pages.containsKey(newPage)) { - final Page oldPage = this.currentPage; - this.currentPage = newPage; - if (this.isInUse()) { - final ItemStack[] pageItems = this.pages.get(this.currentPage); - if (!this.isPlayerInventory() && (pageItems.length != this.currentInventory.getSize() || !oldPage.getPageDisplayTitle().equals(this.getTitle()))) { - (this.currentInventory = Bukkit.createInventory(null, pageItems.length, this.getTitle())).setContents(pageItems); - this.openInventory(); - } - else { - this.setItems(pageItems); - } - } - } - } - - public void setPage(final Page page, ItemStack... items) { - if (items.length % 9 != 0) { - items = Arrays.copyOf(items, (int)(Math.ceil(items.length / 9.0) * 9.0)); - } - if (items.length > (this.isPlayerInventory() ? 36 : 54)) { - throw new RuntimeException("A inventory size of " + items.length + " was passed when the max is " + (this.isPlayerInventory() ? 36 : 54)); - } - this.pages.put(page, items); - if (this.currentPage == null) { - this.currentPage = page; - } - else if (this.currentPage.equals(page)) { - this.setPage(page); - } - } - - public void setPage(final Page page, final List items) { - this.setPage(page, (ItemStack[])items.toArray(new ItemStack[items.size()])); - } - - public void setPage(final String pageName) { - final Page page = this.getPage(pageName); - if (page != null) { - this.setPage(page); - } - } - - @Override - public NamedInventory setPlayerInventory() { - super.setPlayerInventory(); - return this; - } - - @Override - public void setTitle(final String newTitle) { - if (newTitle != null && this.getCurrentPage() != null && !this.getCurrentPage().getPageDisplayTitle().equals(newTitle)) { - this.setPage(new Page(this.getCurrentPage().getPageName(), newTitle), this.getPage(this.getCurrentPage())); - } - } - - public void unlinkPage(final ItemStack item) { - this.pageDirectors.remove(item); - } -} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/items/Page.java b/src/main/java/eu/univento/core/api/items/Page.java deleted file mode 100644 index 9fd56db..0000000 --- a/src/main/java/eu/univento/core/api/items/Page.java +++ /dev/null @@ -1,59 +0,0 @@ -package eu.univento.core.api.items; - -/** - * @author joethei - * @version 0.1 - */ -public class Page { - private String pageName; - private String pageTitle; - - public Page(final String pageName) { - this(pageName, pageName); - } - - public Page(final String pageName, final String pageDisplayTitle) { - this.pageTitle = pageDisplayTitle; - this.pageName = pageName; - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (this.getClass() != obj.getClass()) { - return false; - } - final Page other = (Page)obj; - return this.getPageName().equals(other.getPageName()); - } - - public String getPageDisplayTitle() { - return this.pageTitle; - } - - public String getPageName() { - return this.pageName; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = 31 * result + this.getPageName().hashCode(); - return result; - } - - public void setDisplayTitle(final String newTitle) { - this.pageTitle = newTitle; - } - - @Override - public String toString() { - return "Page[Name=" + this.getPageName() + ", Title=" + this.getPageDisplayTitle() + "]"; - } -} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/items/PageInventory.java b/src/main/java/eu/univento/core/api/items/PageInventory.java deleted file mode 100644 index 3618ea5..0000000 --- a/src/main/java/eu/univento/core/api/items/PageInventory.java +++ /dev/null @@ -1,328 +0,0 @@ -package eu.univento.core.api.items; - -import eu.univento.core.api.items.events.PagesClickEvent; -import eu.univento.core.api.items.events.PagesTurnEvent; -import eu.univento.core.api.player.CustomPlayer; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemStack; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; - -/** - * @author joethei - * @version 0.1 - */ -public class PageInventory extends ClickInventory{ - - protected ItemStack backAPage; - protected ItemStack forwardsAPage; - protected ItemStack exitInventory; - protected int currentPage; - protected boolean dynamicInventorySize; - private int inventorySize; - protected boolean pageDisplayedInTitle; - protected HashMap pages; - protected String title; - private String titleFormat; - - public PageInventory(final CustomPlayer player) { - this(null, player); - } - - public PageInventory(final CustomPlayer player, final boolean dynamicInventory) { - this(null, player, dynamicInventory); - } - - public PageInventory(final CustomPlayer player, final int inventorySize) { - this(null, player, inventorySize); - } - - public PageInventory(final String inventoryName, final CustomPlayer player) { - super(inventoryName, player); - this.dynamicInventorySize = true; - this.inventorySize = 54; - this.pages = new HashMap<>(); - this.title = "Inventory"; - this.titleFormat = "%Title% - Page %Page%"; - } - - public PageInventory(final String inventoryName, final CustomPlayer player, final boolean dynamicInventorySize) { - super(inventoryName, player); - this.dynamicInventorySize = true; - this.inventorySize = 54; - this.pages = new HashMap<>(); - this.title = "Inventory"; - this.titleFormat = "%Title% - Page %Page%"; - this.dynamicInventorySize = dynamicInventorySize; - } - - public PageInventory(final String inventoryName, final CustomPlayer player, final int inventorySize) { - super(inventoryName, player); - this.dynamicInventorySize = true; - this.inventorySize = 54; - this.pages = new HashMap<>(); - this.title = "Inventory"; - this.titleFormat = "%Title% - Page %Page%"; - this.inventorySize = Math.min(54, (int)Math.ceil(inventorySize / 9.0) * 9); - this.dynamicInventorySize = false; - this.pages.put(0, new ItemStack[0]); - } - - public ItemStack getExitInventory() { - return this.exitInventory; - } - - public void setExitInventory(final ItemStack item) { - this.exitInventory = item; - } - - public ItemStack getBackPage() { - if (this.backAPage == null) { - this.backAPage = new ItemBuilder(Material.SIGN).name("Zurück").make(); - } - return this.backAPage; - } - - public int getCurrentPage() { - return this.currentPage; - } - - public ItemStack getForwardsPage() { - if (this.forwardsAPage == null) { - this.forwardsAPage = new ItemBuilder(Material.SIGN).name("Vorwärts").make(); - } - return this.forwardsAPage; - } - - @Override - public String getTitle() { - return this.getPageTitle(); - } - - public ItemStack[] getPage(final int pageNumber) { - if (this.pages.containsKey(pageNumber)) { - return this.pages.get(pageNumber); - } - return null; - } - - public HashMap getPages() { - return this.pages; - } - - protected String getPageTitle() { - return this.isPageDisplayedInTitle() ? this.titleFormat.replace("%Title%", this.title).replace("%Page%", this.getCurrentPage() + 1 + "") : this.title; - } - - public boolean isPageDisplayedInTitle() { - return this.pageDisplayedInTitle; - } - - @Override - protected void onInventoryClick(final InventoryClickEvent event) { - final ItemStack item = event.getCurrentItem(); - if (this.checkInMenu(event.getRawSlot())) { - if (item != null) { - int newPage = 0; - if (item.equals(this.getBackPage())) { - newPage = -1; - } - else if (item.equals(this.getForwardsPage())) { - newPage = 1; - } - if (newPage != 0) { - final PagesTurnEvent newEvent = new PagesTurnEvent(this, event.getSlot(), event, this.getCurrentPage() + newPage); - Bukkit.getPluginManager().callEvent(newEvent); - if (!newEvent.isCancelled()) { - this.setPage(this.getCurrentPage() + newPage); - } - event.setCancelled(true); - return; - } - } - int slot = event.getSlot(); - if (this.isPlayerInventory()) { - slot -= 9; - if (slot < 0) { - slot += 36; - } - } - final PagesClickEvent itemClickEvent = new PagesClickEvent(this, slot, event); - if (!this.isModifiable()) { - itemClickEvent.setCancelled(true); - } - Bukkit.getPluginManager().callEvent(itemClickEvent); - if (itemClickEvent.isCancelled()) { - event.setCancelled(true); - } - } - else if (!this.isModifiable() && event.isShiftClick() && item != null && item.getType() != Material.AIR) { - for (int slot = 0; slot < this.currentInventory.getSize(); ++slot) { - final ItemStack invItem = this.currentInventory.getItem(slot); - if (invItem == null || invItem.getType() == Material.AIR || (invItem.isSimilar(item) && item.getAmount() < item.getMaxStackSize())) { - event.setCancelled(true); - break; - } - } - } - } - - public void openInventory() { - if (this.isInUse()) { - return; - } - this.saveContents(); - final ItemStack[] pageItems = this.getItemsForPage(); - if (this.currentInventory == null) { - if (this.isPlayerInventory()) { - this.currentInventory = this.getPlayer().getInventory(); - } - else { - this.currentInventory = Bukkit.createInventory(null, pageItems.length, this.getPageTitle()); - } - } - this.setItems(pageItems); - this.openInventory(); - } - - private ItemStack[] getItemsForPage() { - ItemStack[] pageItems = this.pages.get(Math.max(this.getCurrentPage(), 0)); - int pageSize = pageItems.length; - if (this.pages.size() > 1 || this.getExitInventory() != null) { - pageSize += 9; - } - if (!this.dynamicInventorySize || this.isPlayerInventory()) { - pageSize = (this.isPlayerInventory() ? 36 : this.inventorySize); - } - else { - pageSize = (pageSize + 8) / 9 * 9; - } - pageItems = Arrays.copyOf(pageItems, pageSize); - if (this.getCurrentPage() > 0 || this.getExitInventory() != null) { - pageItems[pageItems.length - 9] = ((this.getCurrentPage() == 0) ? this.getExitInventory() : this.getBackPage()); - } - if (this.pages.size() - 1 > this.getCurrentPage()) { - pageItems[pageItems.length - 1] = this.getForwardsPage(); - } - return pageItems; - } - - public void setBackPage(final ItemStack newBack) { - this.backAPage = newBack; - } - - public void setForwardsPage(final ItemStack newForwards) { - this.forwardsAPage = newForwards; - } - - public ArrayList getItems() { - final ArrayList items = new ArrayList<>(); - for (int i = 0; i < this.pages.size(); ++i) { - final ItemStack[] itemArray = this.pages.get(i); - for (int a = 0; a < itemArray.length - ((this.pages.size() > 1) ? 9 : 0); ++a) { - items.add(itemArray[a]); - } - } - return items; - } - - public void setPage(final int newPage) { - if (this.pages.containsKey(newPage)) { - this.currentPage = newPage; - if (this.isInUse()) { - final ItemStack[] pageItems = this.getItemsForPage(); - if (!this.isPlayerInventory() && (pageItems.length != this.currentInventory.getSize() || !this.currentInventory.getTitle().equalsIgnoreCase(this.getPageTitle()))) { - (this.currentInventory = Bukkit.createInventory(null, pageItems.length, this.getPageTitle())).setContents(pageItems); - this.openInventory(); - } - else { - this.setItems(pageItems); - } - } - } - } - - public void setPageDisplayedInTitle(final boolean displayPage) { - if (this.isPageDisplayedInTitle() != displayPage) { - this.pageDisplayedInTitle = displayPage; - if (this.isInUse()) { - this.setPage(this.getCurrentPage()); - } - } - } - - public void setPageDisplayTitleFormat(final String titleFormat) { - this.titleFormat = titleFormat; - if (this.isInUse()) { - this.setPage(this.getCurrentPage()); - } - } - - public void setPages(final ArrayList allItems) { - this.setPages((ItemStack[])allItems.toArray(new ItemStack[allItems.size()])); - } - - public void setPages(final ItemStack... allItems) { - this.pages.clear(); - int invPage = 0; - final boolean usePages = this.getExitInventory() != null || allItems.length > this.inventorySize; - ItemStack[] items = null; - int currentSlot = 0; - final int baseSize = this.isPlayerInventory() ? 36 : this.inventorySize; - for (int currentItem = 0; currentItem < allItems.length; ++currentItem) { - if (items == null) { - int newSize = allItems.length - currentItem; - if (usePages && newSize + 9 > baseSize) { - newSize = baseSize - 9; - } - else if (newSize > baseSize) { - newSize = baseSize; - } - items = new ItemStack[newSize]; - } - final ItemStack item = allItems[currentItem]; - items[currentSlot++] = item; - if (currentSlot == items.length) { - this.pages.put(invPage, items); - ++invPage; - currentSlot = 0; - items = null; - } - } - if (this.pages.keySet().size() < this.getCurrentPage()) { - this.currentPage = this.pages.keySet().size() - 1; - } - if (allItems.length == 0) { - int size = this.isPlayerInventory() ? 36 : this.inventorySize; - if (!this.isPlayerInventory() && this.dynamicInventorySize) { - size = 9; - } - items = InventoryManager.generateEmptyPage(size); - if (this.getExitInventory() != null) { - items[0] = this.getExitInventory(); - } - this.pages.put(0, items); - } - this.setPage(this.getCurrentPage()); - } - - @Override - public PageInventory setPlayerInventory() { - super.setPlayerInventory(); - return this; - } - - @Override - public void setTitle(final String newTitle) { - if (!this.getTitle().equals(newTitle)) { - this.title = newTitle; - if (this.isInUse()) { - this.setPage(this.getCurrentPage()); - } - } - } -} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/items/PageLayout.java b/src/main/java/eu/univento/core/api/items/PageLayout.java deleted file mode 100644 index baf8eb1..0000000 --- a/src/main/java/eu/univento/core/api/items/PageLayout.java +++ /dev/null @@ -1,58 +0,0 @@ -package eu.univento.core.api.items; - -import org.bukkit.inventory.ItemStack; - -import java.util.ArrayList; - -/** - * @author joethei - * @version 0.1 - */ -public class PageLayout { - private static String empty = "X"; - private static String full = "O"; - private int invSize; - private ArrayList size; - - public static void setStringFormat(final String noItem, final String aItem) { - PageLayout.empty = noItem; - PageLayout.full = aItem; - } - - public PageLayout(final String... strings) { - this.invSize = 0; - this.size = new ArrayList(); - this.invSize = strings.length * 9; - for (int slot = 0; slot < strings.length * 9; ++slot) { - final String string = strings[(int)Math.floor(slot / 9.0)]; - if (string.length() != 9) { - throw new RuntimeException("String is not a length of 9. String is a length of " + string.length() + ". " + string); - } - final String letter = string.substring(slot % 9, slot % 9 + 1); - if (!letter.equalsIgnoreCase(PageLayout.empty)) { - if (!letter.equalsIgnoreCase(PageLayout.full)) { - throw new RuntimeException("Unrecognised value " + letter); - } - this.size.add(slot); - } - } - } - - public ItemStack[] generate(final ArrayList items) { - return this.generate((ItemStack[])items.toArray(new ItemStack[items.size()])); - } - - public ItemStack[] generate(final ItemStack... items) { - final ItemStack[] itemArray = new ItemStack[this.invSize]; - for (int i = 0; i < this.size.size(); ++i) { - if (i < items.length) { - final ItemStack itemToInsert = items[i]; - if (itemToInsert != null) { - itemArray[this.size.get(i)] = itemToInsert.clone(); - } - } - } - return itemArray; - } - -} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/items/Pagifier.java b/src/main/java/eu/univento/core/api/items/Pagifier.java index f7b5243..0e2fde6 100644 --- a/src/main/java/eu/univento/core/api/items/Pagifier.java +++ b/src/main/java/eu/univento/core/api/items/Pagifier.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.items; import java.util.ArrayList; diff --git a/src/main/java/eu/univento/core/api/items/ScrollingInventory.java b/src/main/java/eu/univento/core/api/items/ScrollingInventory.java deleted file mode 100644 index db7a8bf..0000000 --- a/src/main/java/eu/univento/core/api/items/ScrollingInventory.java +++ /dev/null @@ -1,120 +0,0 @@ -package eu.univento.core.api.items; - -import eu.univento.core.Core; -import eu.univento.core.api.player.CustomPlayer; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.event.EventHandler; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryCloseEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; - -import java.util.ArrayList; - -public class ScrollingInventory implements Listener{ - - private final Inventory inv; - private final ArrayList items = new ArrayList<>(); - private ItemStack next; - private ItemStack back; - private int side = 0; - private int rows = 4; - private final CustomPlayer player; - public ScrollingInventory(CustomPlayer player, String name){ - this.player = player; - int var = 1; - for(int i = 0; i > 27 * 9; i = i + 9) - var++; - inv = Bukkit.createInventory(player, var * 9 + 9, name); - Bukkit.getPluginManager().registerEvents(this, Core.getInstance()); - this.rows = 27; - side = 0; - } - public void addItem(ItemStack item){ - items.add(item); - } - public void removeItem(ItemStack item){ - items.remove(item); - } - private void clearItems(){ - for(ItemStack is : inv.getContents()){ - inv.remove(is); - } - } - - @EventHandler - public void onInventoryClose(InventoryCloseEvent e){ - if(e.getInventory().equals(inv)){ - if(inv.getViewers().size() == 0) - HandlerList.unregisterAll(this); - } - } - - @EventHandler - public void onInventoryClick(InventoryClickEvent e){ - if(e.getInventory().equals(inv)){ - e.setCancelled(true); - if(e.getCurrentItem() != null){ - if(e.getCurrentItem().equals(back)) { - setDisplaySide(side - 1); - } - else if(e.getCurrentItem().equals(next)) { - setDisplaySide(side + 1); - } - } - } - } - - private void setDisplaySide(int i) { - clearItems(); - if(items.size() - side * rows > (side + 1) * rows) - setNext(); - if(side > 0) - setBack(); - int from = side * rows; - int to = (side + 1) * rows; - int a = 0; - for(ItemStack is : items.subList(from, (to > items.size() ? items.size() : to))){ - inv.setItem(a, is); - a++; - } - } - private void setNext(){ - if(next == null){ - next = new ItemStack(Material.TIPPED_ARROW); - PotionMeta nextMeta = (PotionMeta) next.getItemMeta(); - nextMeta.addCustomEffect(new PotionEffect(PotionEffectType.LUCK, 5 * 20, 1), true); - nextMeta.setDisplayName("§aVor"); - next.setItemMeta(nextMeta); - } - inv.setItem(inv.getSize()-2, next); - } - private void setBack(){ - if(back == null){ - back = new ItemStack(Material.TIPPED_ARROW); - PotionMeta backMeta = (PotionMeta) back.getItemMeta(); - backMeta.addCustomEffect(new PotionEffect(PotionEffectType.HEAL, 5 * 20, 1), true); - backMeta.setDisplayName("§cZurück"); - back.setItemMeta(backMeta); - } - inv.setItem(inv.getSize()-8, next); - } - public void openInventory(){ - setDisplaySide(0); - player.openInventory(inv); - } - public void setNextItem(ItemStack item){ - next = item; - setNext(); - } - public void setBackItem(ItemStack item){ - back = item; - setBack(); - } -} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/items/attribute/Attribute.java b/src/main/java/eu/univento/core/api/items/attribute/Attribute.java new file mode 100644 index 0000000..554d32b --- /dev/null +++ b/src/main/java/eu/univento/core/api/items/attribute/Attribute.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.core.api.items.attribute; + +import lombok.Getter; + +/** + * @author joethei + * @version 1.0 + */ +public enum Attribute { + + MAX_HEALTH("generic.maxHealth"), + FOLLOW_RANGE("generic.followRange"), + KNOCKBACK_RESISTANCE("generic.knockbackResistance"), + MOVEMENT_SPEED("generic.movementSpeed"), + ATTACK_DAMAGE("generic.attackDamage"), + ATTACK_SPEED("generic.attackSpeed"), + ARMOR("generic.armor"), + ARMOR_TOUGHNESS("generic.armorToughness"), + LUCK("generic.luck"), + JUMP_STRENGTH("horse.jumpStrength"), + SPAWN_REINFORCEMENTS("zombie.spawnReinforcements"); + + @Getter private String name; + + Attribute(String name) { + this.name = name; + } +} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/items/attribute/AttributeModifier.java b/src/main/java/eu/univento/core/api/items/attribute/AttributeModifier.java new file mode 100644 index 0000000..9305b6d --- /dev/null +++ b/src/main/java/eu/univento/core/api/items/attribute/AttributeModifier.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.core.api.items.attribute; + +import lombok.AllArgsConstructor; +import net.minecraft.server.v1_12_R1.NBTTagCompound; + +import java.util.UUID; + +/** + * @author joethei + * @version 1.0 + */ + +@AllArgsConstructor +public class AttributeModifier { + + private Attribute attribute; + private String name; + private ItemSlot slot; + private int operation; + private double amount; + private UUID uuid; + + /** + * generates a new attribute modifier from an existing nbt tag + * @param nbt NBTTagCompound of the item + */ + public AttributeModifier(NBTTagCompound nbt) { + this.attribute = Attribute.valueOf(nbt.getString("AttributeName")); + this.name = nbt.getString("Name"); + this.slot = ItemSlot.valueOf("Slot"); + this.operation = nbt.getInt("Operation"); + this.amount = nbt.getDouble("Amount"); + this.uuid = new UUID(nbt.getLong("UUIDMost"), nbt.getLong("UUIDLeast")); + } + + /** + * generates a NBT Tag Compound + * @return NBTTagCompound to be set on items + */ + public NBTTagCompound getNBT() { + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setString("AttributeName", attribute.getName()); + nbt.setString("Name", name); + nbt.setString("Slot", slot.getName()); + nbt.setInt("Operation", operation); + nbt.setDouble("Amount", amount); + nbt.setLong("UUIDMost", uuid.getMostSignificantBits()); + nbt.setLong("UUIDLeast", uuid.getLeastSignificantBits()); + + return nbt; + } +} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/items/attribute/ItemAttributes.java b/src/main/java/eu/univento/core/api/items/attribute/ItemAttributes.java new file mode 100644 index 0000000..a5a602a --- /dev/null +++ b/src/main/java/eu/univento/core/api/items/attribute/ItemAttributes.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.core.api.items.attribute; + +import net.minecraft.server.v1_12_R1.NBTTagList; +import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack; +import org.bukkit.inventory.ItemStack; + +import java.util.LinkedList; +import java.util.List; + +/** + * @author joethei + * @version 1.0 + */ +public class ItemAttributes { + + private NBTTagList modifiers; + + public ItemAttributes() { + modifiers = new NBTTagList(); + } + + public void addModifier(AttributeModifier modifier) { + if(modifiers != null) { + modifiers.add(modifier.getNBT()); + } + } + + public void removeModifier(AttributeModifier modifier) { + if(modifiers != null) { + for(int i = 0; i < modifiers.size(); i++) { + if(modifiers.get(i).equals(modifier.getNBT())) { + modifiers.a(i, modifier.getNBT()); + } + } + } + } + + public List getModifiers() { + if(modifiers != null) { + List modifiers = new LinkedList<>(); + for(int i= 0; i < this.modifiers.size(); i++) { + modifiers.add(new AttributeModifier(this.modifiers.get(i))); + } + return modifiers; + } + return null; + } + + public ItemStack apply(ItemStack item) { + net.minecraft.server.v1_12_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + nmsItem.a("AttributeModifiers", this.modifiers); + return CraftItemStack.asBukkitCopy(nmsItem); + } + + public void getFromStack(ItemStack item) { + net.minecraft.server.v1_12_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + assert nmsItem.getTag() != null; + this.modifiers = nmsItem.getTag().getList("AttributeModifiers", 10); + if(this.modifiers == null) this.modifiers = new NBTTagList(); + } +} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/items/attribute/ItemSlot.java b/src/main/java/eu/univento/core/api/items/attribute/ItemSlot.java new file mode 100644 index 0000000..d282d5e --- /dev/null +++ b/src/main/java/eu/univento/core/api/items/attribute/ItemSlot.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.core.api.items.attribute; + +import lombok.Getter; + +/** + * @author joethei + * @version 1.0 + */ + +public enum ItemSlot { + + MAIN_HAND("mainhand"), + OFF_HAND("offhand"), + FEET("feet"), + LEGS("legs"), + CHEST("chest"), + HEAD("head"); + + @Getter private String name; + + ItemSlot(String name) { + this.name = name; + } +} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/items/events/ItemClickEvent.java b/src/main/java/eu/univento/core/api/items/events/ItemClickEvent.java deleted file mode 100644 index 3a63002..0000000 --- a/src/main/java/eu/univento/core/api/items/events/ItemClickEvent.java +++ /dev/null @@ -1,60 +0,0 @@ -package eu.univento.core.api.items.events; - -import eu.univento.core.api.items.ClickInventory; -import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemStack; - -/** - * @author joethei - * @version 0.1 - */ -public abstract class ItemClickEvent extends Event implements Cancellable{ - - private static final HandlerList handlers = new HandlerList(); - private boolean cancelled; - private InventoryClickEvent invEvent; - protected int slot; - - public static HandlerList getHandlerList() { - return ItemClickEvent.handlers; - } - - public ItemClickEvent(final int slot, final InventoryClickEvent invEvent) { - this.slot = slot; - this.invEvent = invEvent; - } - - public InventoryClickEvent getEvent() { - return this.invEvent; - } - - public HandlerList getHandlers() { - return ItemClickEvent.handlers; - } - - public abstract ClickInventory getInventory(); - - public abstract ItemStack getItemStack(); - - public String getName() { - return this.getInventory().getName(); - } - - public abstract Player getPlayer(); - - public int getSlot() { - return this.slot; - } - - public boolean isCancelled() { - return this.cancelled; - } - - public void setCancelled(final boolean cancel) { - this.cancelled = cancel; - } -} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/items/events/NamedCloseEvent.java b/src/main/java/eu/univento/core/api/items/events/NamedCloseEvent.java deleted file mode 100644 index 09500ad..0000000 --- a/src/main/java/eu/univento/core/api/items/events/NamedCloseEvent.java +++ /dev/null @@ -1,40 +0,0 @@ -package eu.univento.core.api.items.events; - -import eu.univento.core.api.items.NamedInventory; -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; - -/** - * @author joethei - * @version 0.1 - */ -public class NamedCloseEvent extends Event { - - private static final HandlerList handlers = new HandlerList(); - private NamedInventory inv; - - public static HandlerList getHandlerList() { - return NamedCloseEvent.handlers; - } - - public NamedCloseEvent(final NamedInventory inventory) { - this.inv = inventory; - } - - public HandlerList getHandlers() { - return NamedCloseEvent.handlers; - } - - public NamedInventory getInventory() { - return this.inv; - } - - public Player getPlayer() { - return this.inv.getPlayer(); - } - - public String getName() { - return this.getInventory().getName(); - } -} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/items/events/NamedPageClickEvent.java b/src/main/java/eu/univento/core/api/items/events/NamedPageClickEvent.java deleted file mode 100644 index a0724b6..0000000 --- a/src/main/java/eu/univento/core/api/items/events/NamedPageClickEvent.java +++ /dev/null @@ -1,56 +0,0 @@ -package eu.univento.core.api.items.events; - -import eu.univento.core.api.items.NamedInventory; -import eu.univento.core.api.items.Page; -import org.bukkit.entity.Player; -import org.bukkit.event.HandlerList; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemStack; - -/** - * @author joethei - * @version 0.1 - */ -public class NamedPageClickEvent extends ItemClickEvent{ - - private static final HandlerList handlers = new HandlerList(); - private NamedInventory inv; - private Page page; - - public static HandlerList getHandlerList() { - return NamedPageClickEvent.handlers; - } - - public NamedPageClickEvent(final NamedInventory inventory, final Page page, final int slot, final InventoryClickEvent invEvent) { - super(slot, invEvent); - this.inv = inventory; - this.page = page; - } - - @Override - public HandlerList getHandlers() { - return NamedPageClickEvent.handlers; - } - - @Override - public NamedInventory getInventory() { - return this.inv; - } - - @Override - public ItemStack getItemStack() { - if (this.slot >= 0) { - return this.inv.getItem(this.slot); - } - return null; - } - - public Page getPage() { - return this.page; - } - - @Override - public Player getPlayer() { - return this.inv.getPlayer(); - } -} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/items/events/PageCloseEvent.java b/src/main/java/eu/univento/core/api/items/events/PageCloseEvent.java deleted file mode 100644 index 3da693b..0000000 --- a/src/main/java/eu/univento/core/api/items/events/PageCloseEvent.java +++ /dev/null @@ -1,40 +0,0 @@ -package eu.univento.core.api.items.events; - -import eu.univento.core.api.items.PageInventory; -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; - -/** - * @author joethei - * @version 0.1 - */ -public class PageCloseEvent extends Event{ - - private static final HandlerList handlers = new HandlerList(); - private PageInventory inv; - - public static HandlerList getHandlerList() { - return PageCloseEvent.handlers; - } - - public PageCloseEvent(final PageInventory inventory) { - this.inv = inventory; - } - - public HandlerList getHandlers() { - return PageCloseEvent.handlers; - } - - public PageInventory getInventory() { - return this.inv; - } - - public Player getPlayer() { - return this.inv.getPlayer(); - } - - public String getName() { - return this.getInventory().getName(); - } -} diff --git a/src/main/java/eu/univento/core/api/items/events/PagesClickEvent.java b/src/main/java/eu/univento/core/api/items/events/PagesClickEvent.java deleted file mode 100644 index 14e8bf9..0000000 --- a/src/main/java/eu/univento/core/api/items/events/PagesClickEvent.java +++ /dev/null @@ -1,49 +0,0 @@ -package eu.univento.core.api.items.events; - -import eu.univento.core.api.items.PageInventory; -import org.bukkit.entity.Player; -import org.bukkit.event.HandlerList; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemStack; - -/** - * @author joethei - * @version 0.1 - */ -public class PagesClickEvent extends ItemClickEvent{ - - private static final HandlerList handlers = new HandlerList(); - private PageInventory inv; - - public static HandlerList getHandlerList() { - return PagesClickEvent.handlers; - } - - public PagesClickEvent(final PageInventory inventory, final int slot, final InventoryClickEvent invEvent) { - super(slot, invEvent); - this.inv = inventory; - } - - @Override - public HandlerList getHandlers() { - return PagesClickEvent.handlers; - } - - @Override - public PageInventory getInventory() { - return this.inv; - } - - @Override - public ItemStack getItemStack() { - if (this.slot >= 0) { - return this.inv.getItem(this.slot); - } - return null; - } - - @Override - public Player getPlayer() { - return this.inv.getPlayer(); - } -} diff --git a/src/main/java/eu/univento/core/api/items/events/PagesTurnEvent.java b/src/main/java/eu/univento/core/api/items/events/PagesTurnEvent.java deleted file mode 100644 index 45980e2..0000000 --- a/src/main/java/eu/univento/core/api/items/events/PagesTurnEvent.java +++ /dev/null @@ -1,55 +0,0 @@ -package eu.univento.core.api.items.events; - -import eu.univento.core.api.items.PageInventory; -import org.bukkit.entity.Player; -import org.bukkit.event.HandlerList; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemStack; - -/** - * @author joethei - * @version 0.1 - */ -public class PagesTurnEvent extends ItemClickEvent{ - - private static final HandlerList handlers = new HandlerList(); - private PageInventory inv; - private int newPage; - - public static HandlerList getHandlerList() { - return PagesTurnEvent.handlers; - } - - public PagesTurnEvent(final PageInventory inventory, final int slot, final InventoryClickEvent invEvent, final int newPage) { - super(slot, invEvent); - this.inv = inventory; - this.newPage = newPage; - } - - public int getNewPage() { - return this.newPage; - } - - @Override - public HandlerList getHandlers() { - return PagesTurnEvent.handlers; - } - - @Override - public PageInventory getInventory() { - return this.inv; - } - - @Override - public ItemStack getItemStack() { - if (this.slot >= 0) { - return this.inv.getItem(this.slot); - } - return null; - } - - @Override - public Player getPlayer() { - return this.inv.getPlayer(); - } -} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/map/Map.java b/src/main/java/eu/univento/core/api/map/Map.java index fec43ac..a0ba921 100644 --- a/src/main/java/eu/univento/core/api/map/Map.java +++ b/src/main/java/eu/univento/core/api/map/Map.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.map; import org.bukkit.Material; diff --git a/src/main/java/eu/univento/core/api/map/MapDatabase.java b/src/main/java/eu/univento/core/api/map/MapDatabase.java index 0eff9c4..e027c26 100644 --- a/src/main/java/eu/univento/core/api/map/MapDatabase.java +++ b/src/main/java/eu/univento/core/api/map/MapDatabase.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.map; /** diff --git a/src/main/java/eu/univento/core/api/map/MapDownloader.java b/src/main/java/eu/univento/core/api/map/MapDownloader.java index 4e43852..3f0f535 100644 --- a/src/main/java/eu/univento/core/api/map/MapDownloader.java +++ b/src/main/java/eu/univento/core/api/map/MapDownloader.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.map; import org.apache.commons.io.FileUtils; diff --git a/src/main/java/eu/univento/core/api/map/MapVoting.java b/src/main/java/eu/univento/core/api/map/MapVoting.java index f55b8f3..fd58391 100644 --- a/src/main/java/eu/univento/core/api/map/MapVoting.java +++ b/src/main/java/eu/univento/core/api/map/MapVoting.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.map; import eu.univento.commons.player.rank.Rank; @@ -106,15 +111,15 @@ public class MapVoting implements Listener{ Inventory inv = Bukkit.createInventory(p, 45, invTitle); for(Map map : allMaps) - inv.addItem(new ItemBuilder(map.getItem()).name(map.getName()).lore("§aby " + map.getBuilder()).make()); + inv.addItem(new ItemBuilder(p, map.getItem()).name(map.getName()).lore("§aby " + map.getBuilder()).build()); return inv; }else{ Inventory inv = Bukkit.createInventory(p, 9, invTitle); - inv.setItem(1, new ItemBuilder(this.map1.getItem()).name(this.map1.getName()).lore("§aby " + this.map1.getBuilder()).make()); - inv.setItem(4, new ItemBuilder(this.map2.getItem()).name(this.map2.getName()).lore("§aby " + this.map2.getBuilder()).make()); - inv.setItem(7, new ItemBuilder(this.map3.getItem()).name(this.map3.getName()).lore("§aby " + this.map3.getBuilder()).make()); + inv.setItem(1, new ItemBuilder(p, this.map1.getItem()).name(this.map1.getName()).lore("§aby " + this.map1.getBuilder()).build()); + inv.setItem(4, new ItemBuilder(p, this.map2.getItem()).name(this.map2.getName()).lore("§aby " + this.map2.getBuilder()).build()); + inv.setItem(7, new ItemBuilder(p, this.map3.getItem()).name(this.map3.getName()).lore("§aby " + this.map3.getBuilder()).build()); return inv; } 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 5a654b8..e7c954a 100644 --- a/src/main/java/eu/univento/core/api/npc/NPC.java +++ b/src/main/java/eu/univento/core/api/npc/NPC.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.npc; import com.mojang.authlib.GameProfile; @@ -5,15 +10,15 @@ import com.mojang.authlib.properties.Property; import eu.univento.core.Core; import eu.univento.core.api.player.CustomPlayer; import lombok.Getter; -import net.minecraft.server.v1_11_R1.*; +import net.minecraft.server.v1_12_R1.*; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.BlockFace; -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.craftbukkit.v1_12_R1.CraftServer; +import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack; import org.bukkit.entity.*; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; @@ -22,7 +27,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; -import eu.univento.core.api.npc.NPC; /** * @author Ploxh4D, joethei diff --git a/src/main/java/eu/univento/core/api/npc/NPCChannel.java b/src/main/java/eu/univento/core/api/npc/NPCChannel.java index 448cc66..3d64d31 100644 --- a/src/main/java/eu/univento/core/api/npc/NPCChannel.java +++ b/src/main/java/eu/univento/core/api/npc/NPCChannel.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.npc; import io.netty.channel.*; diff --git a/src/main/java/eu/univento/core/api/npc/NPCNetworkManager.java b/src/main/java/eu/univento/core/api/npc/NPCNetworkManager.java index fd0c933..3325925 100644 --- a/src/main/java/eu/univento/core/api/npc/NPCNetworkManager.java +++ b/src/main/java/eu/univento/core/api/npc/NPCNetworkManager.java @@ -1,7 +1,12 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.npc; -import net.minecraft.server.v1_11_R1.EnumProtocolDirection; -import net.minecraft.server.v1_11_R1.NetworkManager; +import net.minecraft.server.v1_12_R1.EnumProtocolDirection; +import net.minecraft.server.v1_12_R1.NetworkManager; /** * @author Ploxh4D diff --git a/src/main/java/eu/univento/core/api/npc/NPCPlayerConnection.java b/src/main/java/eu/univento/core/api/npc/NPCPlayerConnection.java index 8b64387..2f2389e 100644 --- a/src/main/java/eu/univento/core/api/npc/NPCPlayerConnection.java +++ b/src/main/java/eu/univento/core/api/npc/NPCPlayerConnection.java @@ -1,9 +1,14 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.npc; -import net.minecraft.server.v1_11_R1.EntityPlayer; -import net.minecraft.server.v1_11_R1.MinecraftServer; -import net.minecraft.server.v1_11_R1.NetworkManager; -import net.minecraft.server.v1_11_R1.PlayerConnection; +import net.minecraft.server.v1_12_R1.EntityPlayer; +import net.minecraft.server.v1_12_R1.MinecraftServer; +import net.minecraft.server.v1_12_R1.NetworkManager; +import net.minecraft.server.v1_12_R1.PlayerConnection; /** * @author joethei diff --git a/src/main/java/eu/univento/core/api/pet/NMSHandler.java b/src/main/java/eu/univento/core/api/pet/NMSHandler.java deleted file mode 100644 index 9108743..0000000 --- a/src/main/java/eu/univento/core/api/pet/NMSHandler.java +++ /dev/null @@ -1,41 +0,0 @@ -package eu.univento.core.api.pet; - -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_11_R1.CraftWorld; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.LivingEntity; -import org.bukkit.event.entity.CreatureSpawnEvent; - -import java.lang.reflect.InvocationTargetException; - -/** - * @author joethei - * @version 0.1 - */ -public class NMSHandler { - - public static LivingEntity spawn(EntityType type, Location loc) { - World nmsWorld = ((CraftWorld) loc.getWorld()).getHandle(); - PetType petType = PetType.valueOf(type); - Entity entity; - try { - entity = (Entity) petType.getCustomClass().getConstructors()[0].newInstance(nmsWorld); - } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - return null; - } - entity.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getPitch(), loc.getYaw()); - nmsWorld.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM); - return (LivingEntity) entity.getBukkitEntity(); - } - - public static void registerEnties() { - PetType.registerEntities(); - } - - public static EntityType[] getRegisteredTypes() { - return PetType.getRegisteredTypes(); - } -} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/pet/NMSHelper.java b/src/main/java/eu/univento/core/api/pet/NMSHelper.java deleted file mode 100644 index 36f3cb3..0000000 --- a/src/main/java/eu/univento/core/api/pet/NMSHelper.java +++ /dev/null @@ -1,40 +0,0 @@ -package eu.univento.core.api.pet; - -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; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -/** - * @author joethei - * @version 0.1 - */ -class NMSHelper { - - static void registerEntity(String name, int id, Class nmsClass, Class customClass) { - try { - final List> dataMaps = new ArrayList<>(); - for (final Field f : EntityTypes.class.getDeclaredFields()) { - if (f.getType().getSimpleName().equals(Map.class.getSimpleName())) { - f.setAccessible(true); - dataMaps.add((Map) f.get(null)); - } - } - if (dataMaps.get(2).containsKey(id)) { - dataMaps.get(0).remove(name); - dataMaps.get(2).remove(id); - } - - final Method method = EntityTypes.class.getDeclaredMethod("a", Class.class, String.class, int.class); - method.setAccessible(true); - method.invoke(null, customClass, name, id); - - } catch (final Exception e) { - e.printStackTrace(); - } - } -} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/pet/PetManager.java b/src/main/java/eu/univento/core/api/pet/PetManager.java deleted file mode 100644 index 1899886..0000000 --- a/src/main/java/eu/univento/core/api/pet/PetManager.java +++ /dev/null @@ -1,12 +0,0 @@ -package eu.univento.core.api.pet; - -/** - * @author joethei - * @version 0.1 - */ -public class PetManager { - - public static int getUpdateValue() { - return 1; - } -} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/pet/PetType.java b/src/main/java/eu/univento/core/api/pet/PetType.java deleted file mode 100644 index 9d37f69..0000000 --- a/src/main/java/eu/univento/core/api/pet/PetType.java +++ /dev/null @@ -1,86 +0,0 @@ -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_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; -import java.util.List; - -/** - * this class overrides all most of the normal minecraft entities - * - * @author joethei - * @version 0.1 - */ -public enum PetType { - CREEPER("Creeper", 50, EntityType.CREEPER, EntityCreeper.class, CustomCreeper.class), - PIG("Pig", 90, EntityType.PIG, EntityPig.class, CustomPig.class); - - private final String name; - private final int id; - private final EntityType type; - private final Class nmsClass; - private final Class customClass; - - PetType(String name, int id, EntityType type, Class nmsClass, Class customClass) { - this.name = name; - this.id = id; - this.type = type; - this.nmsClass = nmsClass; - this.customClass = customClass; - } - - private String getName() { - return name; - } - - private int getID() { - return id; - } - - private EntityType getType() { - return type; - } - - private Class getNmsClass() { - return nmsClass; - } - - public Class getCustomClass() { - return customClass; - } - - private static EntityType[] registeredTypes; - - static void registerEntities() { - for (PetType pet : values()) { - NMSHelper.registerEntity(pet.getName(), pet.getID(), pet.getNmsClass(), pet.getCustomClass()); - } - } - - static EntityType[] getRegisteredTypes() { - if (registeredTypes == null) { - List list = new ArrayList<>(); - for (final PetType pet : values()) { - list.add(pet.getType()); - } - - registeredTypes = list.toArray(new EntityType[list.size()]); - } - - return registeredTypes; - } - - static PetType valueOf(EntityType type) { - for (final PetType pet : values()) { - if (pet.getType().equals(type)) { - return pet; - } - } - return null; - } -} 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 deleted file mode 100644 index 1d7c080..0000000 --- a/src/main/java/eu/univento/core/api/pet/custom/CustomCreeper.java +++ /dev/null @@ -1,67 +0,0 @@ -package eu.univento.core.api.pet.custom; - -import eu.univento.core.api.pet.PetManager; -import net.minecraft.server.v1_11_R1.*; - -/** - * @author joethei - * @version 0.1 - */ -public class CustomCreeper extends EntityCreeper{ - - private double rideSpeed; - private double sideways; - private double backwards; - private double stepHeight; - private int updateValue = 0; - - public CustomCreeper(World world) { - super(world); - update(); - } - - private void update() { - rideSpeed = 0.2; - sideways = 0.5; - backwards = 0.25; - stepHeight = 1.0; - } - - @Override - public void g(float f, float f1) { - EntityLiving entity = (EntityLiving) bw(); - if(entity == null) { - for(final Entity e : passengers) { - if(e instanceof EntityHuman) { - entity = (EntityLiving) e; - break; - } - } - if(entity == null) { - super.g(f, f1); - return; - } - } - if(PetManager.getUpdateValue() > updateValue) { - updateValue = PetManager.getUpdateValue(); - update(); - } - - this.lastPitch = this.yaw = entity.yaw; - this.pitch = entity.pitch = 0.5F; - this.setYawPitch(this.yaw, this.pitch); - this.aQ = this.aO = this.yaw; - - f = (float) (entity.bf * sideways); - - f1 = entity.bg; - if(f1 <= 0.0F) { - f1 *= backwards; - } - - this.l((float) rideSpeed); - super.g(f, f1); - - P = (float) stepHeight; - } -} 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 deleted file mode 100644 index ba286fe..0000000 --- a/src/main/java/eu/univento/core/api/pet/custom/CustomPig.java +++ /dev/null @@ -1,66 +0,0 @@ -package eu.univento.core.api.pet.custom; - -import eu.univento.core.api.pet.PetManager; -import net.minecraft.server.v1_11_R1.*; - -/** - * @author joethei - * @version 0.1 - */ -public class CustomPig extends EntityPig{ - private double rideSpeed; - private double sideways; - private double backwards; - private double stepHeight; - private int updateValue = 0; - - public CustomPig(World world) { - super(world); - update(); - } - - private void update() { - rideSpeed = 0.5; - sideways = 0.5; - backwards = 0.25; - stepHeight = 2.0; - } - - @Override - public void g(float f, float f1) { - EntityLiving entity = (EntityLiving) bw(); - if(entity == null) { - for(final Entity e : passengers) { - if(e instanceof EntityHuman) { - entity = (EntityLiving) e; - break; - } - } - if(entity == null) { - super.g(f, f1); - return; - } - } - if(PetManager.getUpdateValue() > updateValue) { - updateValue = PetManager.getUpdateValue(); - update(); - } - - this.lastPitch = this.yaw = entity.yaw; - this.pitch = entity.pitch = 0.5F; - this.setYawPitch(this.yaw, this.pitch); - this.aQ = this.aO = this.yaw; - - f = (float) (entity.bf * sideways); - - f1 = entity.bg; - if(f1 <= 0.0F) { - f1 *= backwards; - } - - this.l((float) rideSpeed); - super.g(f, f1); - - P = (float) stepHeight; - } -} \ No newline at end of file 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 e376ecb..734269b 100644 --- a/src/main/java/eu/univento/core/api/player/BetterPvP.java +++ b/src/main/java/eu/univento/core/api/player/BetterPvP.java @@ -1,16 +1,21 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.player; public class BetterPvP { public static String getCodeString() { - String toReturn = "§c §r§5 §r§1 §r§f"; + StringBuilder toReturn = new StringBuilder("§c §r§5 §r§1 §r§f"); String code = String.valueOf(getCodeToSend()); int size = code.length(); for (int i = 0; i < size; i++) - toReturn = toReturn + " " + "§r§" + code.substring(i, i + 1); - toReturn = toReturn + " "; + toReturn.append(" " + "§r§").append(code.substring(i, i + 1)); + toReturn.append(" "); - return toReturn; + return toReturn.toString(); } private static int getCodeToSend() { 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 ae8b784..e1ba7ac 100644 --- a/src/main/java/eu/univento/core/api/player/CustomPlayer.java +++ b/src/main/java/eu/univento/core/api/player/CustomPlayer.java @@ -1,12 +1,20 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.player; +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; import com.mojang.authlib.GameProfile; import eu.univento.commons.player.DatabasePlayer; +import eu.univento.commons.player.language.MessageConstant; import eu.univento.commons.player.rank.Rank; import eu.univento.commons.player.warn.WarnReason; +import eu.univento.commons.server.ServerType; 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; @@ -14,29 +22,34 @@ import eu.univento.core.api.gui.hologram.HologramData; import eu.univento.core.api.server.ServerSettings; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; +import io.vertx.core.json.JsonObject; import lombok.Getter; -import net.minecraft.server.v1_11_R1.*; +import lombok.Setter; +import net.md_5.bungee.api.chat.TextComponent; +import net.minecraft.server.v1_12_R1.*; import org.bukkit.*; -import org.bukkit.Material; -import org.bukkit.World; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; import org.bukkit.attribute.AttributeModifier; +import org.bukkit.block.Chest; +import org.bukkit.block.DoubleChest; +import org.bukkit.block.EnderChest; +import org.bukkit.block.ShulkerBox; 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_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.craftbukkit.v1_12_R1.CraftServer; +import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; 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; @@ -55,15 +68,16 @@ public class CustomPlayer extends CraftPlayer { private final Player PLAYER; private final DatabasePlayer DATABASE_PLAYER; - private boolean openInventory; + @Getter @Setter private boolean openInventory; private final GameProfile gameProfile; - @Getter private HologramData hologramData; + @Getter + private HologramData hologramData; private CustomPlayer(Player player) { super((CraftServer) Bukkit.getServer(), ((CraftPlayer) player).getHandle()); - DATABASE_PLAYER = new DatabasePlayer(player.getUniqueId(), player.getName()); + DATABASE_PLAYER = new DatabasePlayer(player.getUniqueId()); PLAYERS.put(player.getUniqueId(), this); PLAYER = player; gameProfile = ((CraftPlayer) player).getProfile(); @@ -83,10 +97,11 @@ public class CustomPlayer extends CraftPlayer { if (ServerSettings.isLobby()) DATABASE_PLAYER.setInDatabase("Pos", location); if (PLAYERS.containsKey(getUniqueId())) PLAYERS.remove(getUniqueId()); + getDatabasePlayer().save(); } public static CustomPlayer getPlayer(String player) { - if(Bukkit.getPlayer(player) == null) return null; + if (Bukkit.getPlayer(player) == null) return null; Player p = Bukkit.getPlayer(player); if (PLAYERS.containsKey(p.getUniqueId())) { return PLAYERS.get(p.getUniqueId()); @@ -96,10 +111,9 @@ public class CustomPlayer extends CraftPlayer { } public static CustomPlayer getPlayer(UUID player) { - if(PLAYERS.containsKey(player)) { + if (PLAYERS.containsKey(player)) { return PLAYERS.get(player); - } - else { + } else { Player p = Bukkit.getPlayer(player); return p == null ? null : new CustomPlayer(p); } @@ -117,49 +131,57 @@ public class CustomPlayer extends CraftPlayer { return DATABASE_PLAYER; } - public CompletableFuture getLastLocation() { - CompletableFuture future = new CompletableFuture<>(); - DATABASE_PLAYER.getObjectFromDatabase("POS").whenComplete((entries, throwable) -> - future.complete(new Location(Bukkit.getWorld("world"), entries.getDouble("X"), entries.getDouble("Y"), entries.getDouble("Z"), - Float.parseFloat(entries.getString("Yaw")), Float.parseFloat(entries.getString("Pitch"))))); - return future; + /* + Chat + */ + + public void sendMessage(MessageConstant constant) { + sendMessage(ChatColor.translateAlternateColorCodes('&', getDatabasePlayer().getLanguage().getMessage(constant))); } - public void connectToServer(String server) { - ByteArrayOutputStream b = new ByteArrayOutputStream(); - DataOutputStream out = new DataOutputStream(b); - try { - out.writeUTF("Connect"); - out.writeUTF(server); - } catch (IOException el) { - el.printStackTrace(); + public void sendCentredMessage(String message) { + if (message == null || message.equals("")) { + sendMessage(""); + return; } - sendPluginMessage(Core.getInstance(), "BungeeCord", b.toByteArray()); + 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 warn(WarnReason reason, CustomPlayer warner, String proof) { - DATABASE_PLAYER.warn(reason, warner.getUniqueId().toString(), proof); - } - - public boolean hasEmptyInventory() { - return Utils.hasEmptyInventory(PLAYER); - } - - public void clearPotionEffects() { - Utils.clearPotionEffects(PLAYER); - } - - public boolean hasOpenInventory() { - return openInventory; - } - - public void setOpenInventory(boolean openInventory) { - this.openInventory = openInventory; - } + /* + Graphical User Interface + */ public void sendActionBar(String text) { IChatBaseComponent cbc = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + text + "\"}"); - PacketPlayOutChat ppoc = new PacketPlayOutChat(cbc, (byte) 2); + PacketPlayOutChat ppoc = new PacketPlayOutChat(cbc, ChatMessageType.a((byte) 2)); sendPacket(ppoc); } @@ -206,32 +228,94 @@ public class CustomPlayer extends CraftPlayer { header = header.replaceAll("%player%", getDisplayName()); footer = footer.replaceAll("%player%", getDisplayName()); + PLAYER.setPlayerListHeaderFooter(new TextComponent(header), new TextComponent(footer)); - IChatBaseComponent tabTitle = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + header + "\"}"); - IChatBaseComponent tabFoot = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + footer + "\"}"); - PacketPlayOutPlayerListHeaderFooter headerPacket = new PacketPlayOutPlayerListHeaderFooter(tabTitle); - try { - Field field = headerPacket.getClass().getDeclaredField("b"); - field.setAccessible(true); - field.set(headerPacket, tabFoot); - } catch (Exception e) { - e.printStackTrace(); - } finally { - sendPacket(headerPacket); + } + + /* + Cloud + */ + + public void connectToServer(String server) { + ByteArrayDataOutput out = ByteStreams.newDataOutput(); + out.writeUTF("Connect"); + out.writeUTF(server); + sendPluginMessage(Core.getInstance(), "BungeeCord", out.toByteArray()); + } + + public void connectToServer(ServerType type) { + Core.getCloudAPI().getOptimalServer(this, type).whenComplete((s, throwable) -> connectToServer(s)); + } + + /* + Inventory + */ + + public boolean hasEmptyInventory() { + return getInventory().firstEmpty() != -1; + } + + /* + Effects + */ + + /** + * @param location location for effect + * @param effect particle effect + * @param id the id + * @param data the data + * @param offsetX offset in x direction + * @param offsetY offset in y direction + * @param offsetZ offset in z direction + * @param speed particle speed + * @param particleCount count of showed particles + * @param radius effect radius + */ + public void playEffect(Location location, Effect effect, int id, int data, float offsetX, float offsetY, float offsetZ, float speed, int particleCount, int radius) { + if (DATABASE_PLAYER.getSettings().hasEffectsEnabled()) { + PLAYER.spigot().playEffect(location, effect, id, data, offsetX, offsetY, offsetZ, speed, particleCount, radius); } } + @Deprecated + public void playParticle(Location loc, EnumParticle ep, float f, int count) { + if (DATABASE_PLAYER.getSettings().hasEffectsEnabled()) Effects.playEffectToPlayer(PLAYER, loc, ep, f, count); + } + + /* + Combat + */ + public void setAttackSpeed(double speed) { + AttributeModifier modifier = new AttributeModifier(Core.getInstance().getName(), speed, AttributeModifier.Operation.ADD_NUMBER); + getAttribute(Attribute.GENERIC_ATTACK_SPEED).addModifier(modifier); + } + + private double getAttackSpeed() { + return getAttribute(Attribute.GENERIC_ATTACK_SPEED).getValue(); + } + + public void resetAttackSpeed() { + AttributeModifier modifier = new AttributeModifier(Core.getInstance().getName(), getAttackSpeed(), AttributeModifier.Operation.ADD_NUMBER); + getAttribute(Attribute.GENERIC_ATTACK_SPEED).removeModifier(modifier); + AttributeInstance instance = getAttribute(Attribute.GENERIC_ATTACK_SPEED); + instance.setBaseValue(16.0D); + } + + /* + Nick + */ + public void setNickName(String name) { - if(name.length() > 16) { + if (name.length() > 16) { sendMessage("Disguised name can only be less the 16 characters."); return; } - if(isNicked()) { + if (isNicked()) { sendMessage("You are already disguised!"); return; } - if(Bukkit.getOnlinePlayers().stream().filter(p -> p.getName().equals(name)).count() != 0) { - sendMessage("The name you chose is online."); + if (Bukkit.getOnlinePlayers().stream().filter(p -> p.getName().equals(name)).count() != 0) { + sendMessage("The name you chose is already online."); return; } nickedPlayers.put(getUniqueId(), new NickedPlayer(this, name)); @@ -253,10 +337,10 @@ public class CustomPlayer extends CraftPlayer { return; } Core.getOnlinePlayers().stream().filter(p -> p.getUniqueId() != getUniqueId()).forEach(p -> { - if(p.getDatabasePlayer().isAllowed(Rank.Admin)) return; + if (p.getDatabasePlayer().isAllowed(Rank.Admin)) return; p.sendPacket(new PacketPlayOutEntityDestroy(getEntityId())); p.sendPacket(new PacketPlayOutNamedEntitySpawn(getHandle())); - if(p.canSee(this)) { + if (p.canSee(this)) { p.hidePlayer(this); p.showPlayer(this); } @@ -271,16 +355,17 @@ public class CustomPlayer extends CraftPlayer { updateScaledHealth(); sendPacket(new PacketPlayOutHeldItemSlot(getHandle().inventory.itemInHandIndex)); getHandle().updateAbilities(); - for(MobEffect effect : getHandle().getEffects()) sendPacket(new PacketPlayOutEntityEffect(getHandle().getId(), effect)); + for (MobEffect effect : getHandle().getEffects()) + sendPacket(new PacketPlayOutEntityEffect(getHandle().getId(), effect)); - if(this.gameProfile != profile) { - for(CustomPlayer player : Core.getOnlinePlayers()) { - if(player.getDatabasePlayer().isAllowed(Rank.Admin)) return; + if (this.gameProfile != profile) { + for (CustomPlayer player : Core.getOnlinePlayers()) { + if (player.getDatabasePlayer().isAllowed(Rank.Admin)) return; player.initScoreboard(); player.getDatabasePlayer().getRankAsync().whenComplete((rank, throwable) -> getScoreboard().getTeam(rank.getTeam()).addEntry(player.getDisplayName())); player.getScoreboard().getTeam(Rank.Premium.getTeam()).addEntry(getDisplayName()); } - }else { + } else { for (CustomPlayer player : Core.getOnlinePlayers()) { player.initScoreboard(); getDatabasePlayer().getRankAsync().whenComplete((rank, throwable) -> player.getScoreboard().getTeam(rank.getTeam()).addEntry(getDisplayName())); @@ -290,7 +375,7 @@ public class CustomPlayer extends CraftPlayer { } public void removeNickName() { - if(isNicked()) { + if (isNicked()) { nickedPlayers.remove(getUniqueId()); setGameProfile(getName(), gameProfile); } @@ -300,90 +385,69 @@ public class CustomPlayer extends CraftPlayer { return nickedPlayers.containsKey(getUniqueId()); } - public void addExperience(int experience) { - DATABASE_PLAYER.getExperience().whenComplete((integer, throwable) -> { - DATABASE_PLAYER.setExperience(integer + experience); - setExp(0F); - giveExp(integer + experience); - playSound(getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0F, 1.0F); - }); - } + /* + Miscellaneous + */ - public void substractExperience(int experience) { - DATABASE_PLAYER.getExperience().whenComplete((integer, throwable) -> { - DATABASE_PLAYER.setExperience(integer - experience); - setExp(0F); - giveExp(integer - experience); - }); - } - - @Deprecated - public void playParticle(Location loc, EnumParticle ep, float f, int count) { - if (DATABASE_PLAYER.getSettings().hasEffectsEnabled()) Effects.playEffectToPlayer(PLAYER, loc, ep, f, count); - } - - public void setAttackSpeed(double speed) { - AttributeModifier modifier = new AttributeModifier("Core", speed, AttributeModifier.Operation.ADD_NUMBER); - getAttribute(Attribute.GENERIC_ATTACK_SPEED).addModifier(modifier); - } - - private double getAttackSpeed() { - return getAttribute(Attribute.GENERIC_ATTACK_SPEED).getValue(); - } - - public void resetAttackSpeed() { - AttributeModifier modifier = new AttributeModifier("Core", getAttackSpeed(), AttributeModifier.Operation.ADD_NUMBER); - getAttribute(Attribute.GENERIC_ATTACK_SPEED).removeModifier(modifier); - AttributeInstance instance = getAttribute(Attribute.GENERIC_ATTACK_SPEED); - instance.setBaseValue(16.0D); - } - - public void sendCentredMessage(Player player, String message) { - if(message == null || message.equals("")) { - player.sendMessage(""); + /** + * open or close chests for player + * + * @param loc location, block at location must be a type of chest + * @param open open or close the chest + */ + public void changeChestState(Location loc, boolean open) { + if (!(loc.getBlock() instanceof Chest) && !(loc.getBlock() instanceof ShulkerBox) && !(loc.getBlock() instanceof EnderChest) && !(loc.getBlock() instanceof DoubleChest)) return; - } - message = ChatColor.translateAlternateColorCodes('&', message); + BlockPosition position = new BlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); + PacketPlayOutBlockAction blockActionPacket = new PacketPlayOutBlockAction(position, Block.getById(loc.getBlock().getTypeId()), 1, (open) ? 1 : 0); + sendPacket(blockActionPacket); + } - int messagePxSize = 0; - boolean previousCode = false; - boolean isBold = false; + /** + * sets the amount of arrows that are in the body of the player + * + * @param count arrow count + */ + public void setArrowsInBody(int count) { + getHandle().getDataWatcher().set(new DataWatcherObject<>(10, DataWatcherRegistry.b), count); + } - 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++; - } + public int getArrowsInBody() { + return getHandle().getDataWatcher().get(new DataWatcherObject<>(10, DataWatcherRegistry.b)); + } + + /** + * sends packets for item cooldown, items won't be disabled + * + * @param item item to have a cooldown + * @param time time in seconds + */ + public void setItemCooldown(ItemStack item, int time) { + sendPacket(new PacketPlayOutSetCooldown(CraftItemStack.asNMSCopy(item).getItem(), time)); + } + + public void hideToAll() { + for (CustomPlayer p : Core.getOnlinePlayers()) { + p.hidePlayer(this); } - 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; + } + + public void showToAll() { + for (CustomPlayer p : Core.getOnlinePlayers()) { + p.showPlayer(this); } - sendMessage(sb.toString() + message); } public void strikeLightning(Location loc) { - World nmsWorld = (World) ((CraftWorld) loc.getWorld()).getHandle(); - EntityLightning lightning = new EntityLightning((net.minecraft.server.v1_11_R1.World) nmsWorld, loc.getX(), loc.getY(), loc.getZ(), true); + net.minecraft.server.v1_12_R1.World nmsWorld = ((CraftWorld) loc.getWorld()).getHandle(); + EntityLightning lightning = new EntityLightning(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); } public void setBlackScreen(int seconds) { - Blackscreen.setBlack(PLAYER, seconds); + Blackscreen.setBlack(this, seconds); } public void setStoryResourcePack() { @@ -421,7 +485,7 @@ public class CustomPlayer extends CraftPlayer { } /** - * crash's the players client + * crashes the players client */ public void crashClient() { sendPacket(new PacketPlayOutExplosion(9999999999D, @@ -430,11 +494,14 @@ public class CustomPlayer extends CraftPlayer { 9999999999D, 9999999999D))); } + /* + Packets + */ + public void sendPacket(Packet packet) { getHandle().playerConnection.sendPacket(packet); } - private Field getField(Class clazz, String name) { try { Field field = clazz.getDeclaredField(name); @@ -446,57 +513,28 @@ public class CustomPlayer extends CraftPlayer { return null; } - /** - * - * @param location location for effect - * @param effect particle effect - * @param id the id - * @param data the data - * @param offsetX offset in x direction - * @param offsetY offset in y direction - * @param offsetZ offset in z direction - * @param speed particle speed - * @param particleCount count of showed particles - * @param radius effect radius + /* + Other */ - public void playEffect(Location location, Effect effect, int id, int data, float offsetX, float offsetY, float offsetZ, float speed, int particleCount, int radius) { - if(DATABASE_PLAYER.getSettings().hasEffectsEnabled()) { - PLAYER.spigot().playEffect(location, effect, id, data, offsetX, offsetY, offsetZ, speed, particleCount, radius); + + public CompletableFuture getLastLocation() { + CompletableFuture future = new CompletableFuture<>(); + DATABASE_PLAYER.getObjectFromDatabase().whenComplete((entries, throwable) -> { + JsonObject json = entries.getJsonObject("Pos"); + future.complete(new Location(Bukkit.getWorld("world"), json.getDouble("X"), json.getDouble("Y"), json.getDouble("Z"), + Float.parseFloat(json.getString("Yaw")), Float.parseFloat(json.getString("Pitch")))); + }); + return future; + } + + public void warn(WarnReason reason, CustomPlayer warner, String proof) { + DATABASE_PLAYER.warn(reason, warner.getUniqueId().toString(), proof); + } + + public void clearPotionEffects() { + for(PotionEffect potion : getActivePotionEffects()) { + removePotionEffect(potion.getType()); } } - /** - * open or close chests for player - * @param loc location, block at location must be a type of chest - * @param open open or close the chest - */ - public void changeChestState(Location loc, boolean open) { - 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_11_R1.Block.getById(loc.getBlock().getTypeId()), (byte) 1, dataByte); - sendPacket(blockActionPacket); - } - - /** - * sets the amount of arrows that are in the body of the player - * @param count arrow count - */ - public void setArrowsInBody(int count) { - getHandle().getDataWatcher().set(new DataWatcherObject<>(10, DataWatcherRegistry.b), count); - } - - public int getArrowsInBody() { - return getHandle().getDataWatcher().get(new DataWatcherObject<>(10, DataWatcherRegistry.b)); - } - - /** - * sends packets for item cooldown, items won't be disabled - * @param item item to have a cooldown - * @param time time in seconds - */ - public void setItemCooldown(ItemStack item, int time) { - sendPacket(new PacketPlayOutSetCooldown(CraftItemStack.asNMSCopy(item).getItem(), time)); - } - } \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/player/LabyMod.java b/src/main/java/eu/univento/core/api/player/LabyMod.java index 5194fc7..4966649 100644 --- a/src/main/java/eu/univento/core/api/player/LabyMod.java +++ b/src/main/java/eu/univento/core/api/player/LabyMod.java @@ -1,8 +1,13 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.player; public enum LabyMod { FOOD("FOOD", 0), - GUI("GUI", 1), + GUI("InventoryGUI", 1), NICK("NICK", 2), BLOCKBUILD("BLOCKBUILD", 3), CHAT("CHAT", 4), 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 bcc5a35..5ff1301 100644 --- a/src/main/java/eu/univento/core/api/player/NickName.java +++ b/src/main/java/eu/univento/core/api/player/NickName.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.player; import java.util.ArrayList; diff --git a/src/main/java/eu/univento/core/api/player/NickedPlayer.java b/src/main/java/eu/univento/core/api/player/NickedPlayer.java index 3b2d057..44f16f7 100644 --- a/src/main/java/eu/univento/core/api/player/NickedPlayer.java +++ b/src/main/java/eu/univento/core/api/player/NickedPlayer.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.player; import com.mojang.authlib.GameProfile; diff --git a/src/main/java/eu/univento/core/api/player/Skin.java b/src/main/java/eu/univento/core/api/player/Skin.java index dd4a356..c6a64ca 100644 --- a/src/main/java/eu/univento/core/api/player/Skin.java +++ b/src/main/java/eu/univento/core/api/player/Skin.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.player; import lombok.Getter; diff --git a/src/main/java/eu/univento/core/api/player/SpectateManager.java b/src/main/java/eu/univento/core/api/player/SpectateManager.java index 672df84..738621b 100644 --- a/src/main/java/eu/univento/core/api/player/SpectateManager.java +++ b/src/main/java/eu/univento/core/api/player/SpectateManager.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.player; import java.util.LinkedList; diff --git a/src/main/java/eu/univento/core/api/player/Spectator.java b/src/main/java/eu/univento/core/api/player/Spectator.java index 487b89a..53246a4 100644 --- a/src/main/java/eu/univento/core/api/player/Spectator.java +++ b/src/main/java/eu/univento/core/api/player/Spectator.java @@ -1,10 +1,14 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.player; -import eu.univento.commons.player.language.MessageConstant; import eu.univento.core.Core; import eu.univento.core.api.game.PlayerManager; +import eu.univento.core.api.gui.InventoryGUI; import eu.univento.core.api.items.ItemBuilder; -import eu.univento.core.api.items.ScrollingInventory; import eu.univento.core.api.server.ServerSettings; import org.bukkit.GameMode; import org.bukkit.Material; @@ -25,6 +29,9 @@ public class Spectator { player.setGameMode(GameMode.ADVENTURE); player.setAllowFlight(true); player.setFlying(true); + + player.getInventory().setItem(7, new ItemBuilder(Material.PAPER).name("Weiterspielen").build()); + player.getInventory().setItem(8, new ItemBuilder(Material.BED).name("Zur Lobby").build()); } public CustomPlayer getPlayer() { @@ -41,10 +48,16 @@ public class Spectator { if(player.getSpectatorTarget() != null) player.setSpectatorTarget(null); } - public void spectate(CustomPlayer p) throws NullPointerException { - if(!SpectateManager.contains(p)) throw new NullPointerException("The player " + player.getName() + " is not an spectator"); - if(!p.isOnline()) throw new NullPointerException("The player " + p.getName() + " is not online"); - player.setSpectatorTarget(p); + public void spectate(CustomPlayer p) { + if(SpectateManager.contains(p)) { + player.sendMessage("Dieser Spieler ist schon tot"); + return; + } + if(!p.isOnline()) { + player.sendMessage("Dieser Spieler ist nicht mehr online"); + return; + } + player.setSpectatorTarget(p); } public void resetSpectateTarget() { @@ -52,10 +65,11 @@ public class Spectator { } public void openPlayerListInventory() { - ScrollingInventory inventory = new ScrollingInventory(player, player.getDatabasePlayer().getLanguage().getMessage(MessageConstant.GAME_SPECTATE_MENU)); - for(CustomPlayer players : PlayerManager.getPlayers()) { - inventory.addItem(new ItemBuilder(Material.SKULL_ITEM).durability((short) 3).skullOwner(players.getDisplayName()).name(players.getDisplayName()).make()); - } - inventory.openInventory(); + InventoryGUI gui = new InventoryGUI(player, (int) (Math.ceil(PlayerManager.getPlayers().size() / 9.0D) * 9), "Spieler"); + int i = 0; + for(CustomPlayer players : PlayerManager.getPlayers()) { + gui.addItem(i, new ItemBuilder(Material.SKULL_ITEM).durability((short) 3).skullOwner(players.getUniqueId()).build(), player -> spectate(players)); + i++; + } } } \ No newline at end of file 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 2dd2a37..0be445b 100644 --- a/src/main/java/eu/univento/core/api/schematic/Cuboid.java +++ b/src/main/java/eu/univento/core/api/schematic/Cuboid.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.schematic; import org.bukkit.*; @@ -66,7 +71,7 @@ public class Cuboid implements Cloneable, ConfigurationSerializable, Iterable getEntities() { @@ -194,4 +195,9 @@ public class Cuboid implements Cloneable, ConfigurationSerializable, Iterable items; + private List items = new LinkedList<>(); public ShopMenu(Plugin plugin, String name, ShopItem... items) { @@ -32,8 +38,7 @@ public class ShopMenu implements Listener{ public Inventory getInventory() { Inventory inv = Bukkit.createInventory(null, 18, name); - for(ShopItem item : items) - inv.addItem(item.getItem()); + for(ShopItem item : items) inv.addItem(item.getItem()); return inv; } @@ -41,7 +46,18 @@ public class ShopMenu implements Listener{ @EventHandler public void onInventoryClick(InventoryClickEvent e) { CustomPlayer p = CustomPlayer.getPlayer((Player) e.getWhoClicked()); - //items.stream().filter(shopItem -> shopItem.getItem().equals(e.getCurrentItem())).forEach(p::buy); + for(ShopItem item : items) { + if(item.getItem().equals(e.getCurrentItem())) { + e.setCancelled(true); + p.getDatabasePlayer().getCurrency(item.getCurrencyType()).whenComplete((integer, throwable) -> { + if(integer >= item.getPrice()) { + p.getDatabasePlayer().buy(item.getCurrencyType(), item.getPrice()); + }else { + p.sendMessage("Das ist zu teuer für dich"); + } + }); + } + } } } \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/shop/entity/ShopEntity.java b/src/main/java/eu/univento/core/api/shop/entity/ShopEntity.java index 374baac..711e4dd 100644 --- a/src/main/java/eu/univento/core/api/shop/entity/ShopEntity.java +++ b/src/main/java/eu/univento/core/api/shop/entity/ShopEntity.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.shop.entity; import eu.univento.core.api.player.CustomPlayer; @@ -34,7 +39,7 @@ class ShopEntity implements Listener{ spawn(); } - public void spawn() { + private void spawn() { if(entity == null) { LivingEntity entity = (LivingEntity) location.getWorld().spawnEntity(location, type); entity.setCustomName(name); diff --git a/src/main/java/eu/univento/core/api/shop/entity/ShopIronGolem.java b/src/main/java/eu/univento/core/api/shop/entity/ShopIronGolem.java index d4a990d..8904b10 100644 --- a/src/main/java/eu/univento/core/api/shop/entity/ShopIronGolem.java +++ b/src/main/java/eu/univento/core/api/shop/entity/ShopIronGolem.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.shop.entity; import eu.univento.core.api.shop.ShopMenu; diff --git a/src/main/java/eu/univento/core/api/shop/entity/ShopVillager.java b/src/main/java/eu/univento/core/api/shop/entity/ShopVillager.java index 4b974fb..6ede3ed 100644 --- a/src/main/java/eu/univento/core/api/shop/entity/ShopVillager.java +++ b/src/main/java/eu/univento/core/api/shop/entity/ShopVillager.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.shop.entity; import eu.univento.core.api.shop.ShopMenu; diff --git a/src/main/java/eu/univento/core/api/story/StoryMission.java b/src/main/java/eu/univento/core/api/story/StoryMission.java index 5ed8f4c..3301328 100644 --- a/src/main/java/eu/univento/core/api/story/StoryMission.java +++ b/src/main/java/eu/univento/core/api/story/StoryMission.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.story; import eu.univento.core.Core; diff --git a/src/main/java/eu/univento/core/api/story/StoryMissionStatus.java b/src/main/java/eu/univento/core/api/story/StoryMissionStatus.java index 6aa0709..c05c6ff 100644 --- a/src/main/java/eu/univento/core/api/story/StoryMissionStatus.java +++ b/src/main/java/eu/univento/core/api/story/StoryMissionStatus.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.story; /** diff --git a/src/main/java/eu/univento/core/api/story/StoryMissions.java b/src/main/java/eu/univento/core/api/story/StoryMissions.java index a80a3e0..56cd2d2 100644 --- a/src/main/java/eu/univento/core/api/story/StoryMissions.java +++ b/src/main/java/eu/univento/core/api/story/StoryMissions.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.story; import lombok.Getter; diff --git a/src/main/java/eu/univento/core/api/update/PluginUpdater.java b/src/main/java/eu/univento/core/api/update/PluginUpdater.java deleted file mode 100644 index 1c39a58..0000000 --- a/src/main/java/eu/univento/core/api/update/PluginUpdater.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2017 univento.eu - All rights reserved - * You are not allowed to use, distribute or modify this code - */ - -package eu.univento.core.api.update; - -import eu.univento.core.Core; -import eu.univento.core.api.server.ServerSettings; -import org.apache.commons.io.FileUtils; -import org.gitlab.api.GitlabAPI; -import org.gitlab.api.TokenType; -import org.gitlab.api.models.GitlabBuild; -import org.gitlab.api.models.GitlabProject; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.StandardCopyOption; -import java.util.List; - -/** - * @author joethei - * @version 1.0 - */ -public class PluginUpdater { - - private String name; - - public PluginUpdater(String name) { - this.name = name; - } - - public void update() { - GitlabAPI api = GitlabAPI.connect(Core.getCommons().getConfigurationHandler().getString("Gitlab.Host"), Core.getCommons().getConfigurationHandler().getString("Gitlab.token"), TokenType.PRIVATE_TOKEN); - try { - GitlabProject project = api.getProject(name); - List builds = api.getProjectBuilds(project); - - File zip = new File("update", name + ".zip"); - File output = new File("update", name); - - FileUtils.copyURLToFile(new URL(builds.get(0).getDownloadUrl()), zip); - eu.univento.commons.utils.Files.unzip(zip, output); - Files.copy(new FileInputStream(new File(output, "target/" + name +".jar")), new File("update", name + ".jar").toPath(), StandardCopyOption.REPLACE_EXISTING); - FileUtils.deleteQuietly(zip); - FileUtils.deleteDirectory(output); - } catch (IOException e) { - Core.getCommons().getLoggingHandler().log(ServerSettings.getServerType(), "Failed while trying to update plugin: " + name); - e.printStackTrace(); - } - } -} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/utils/Direction.java b/src/main/java/eu/univento/core/api/utils/Direction.java index dbfc247..845b520 100644 --- a/src/main/java/eu/univento/core/api/utils/Direction.java +++ b/src/main/java/eu/univento/core/api/utils/Direction.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.utils; public enum Direction { diff --git a/src/main/java/eu/univento/core/api/utils/GameProfileBuilder.java b/src/main/java/eu/univento/core/api/utils/GameProfileBuilder.java index 2b1ee0b..b85e22f 100644 --- a/src/main/java/eu/univento/core/api/utils/GameProfileBuilder.java +++ b/src/main/java/eu/univento/core/api/utils/GameProfileBuilder.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.utils; import com.google.gson.*; diff --git a/src/main/java/eu/univento/core/api/utils/Lamps.java b/src/main/java/eu/univento/core/api/utils/Lamps.java index 10bca93..22adfe7 100644 --- a/src/main/java/eu/univento/core/api/utils/Lamps.java +++ b/src/main/java/eu/univento/core/api/utils/Lamps.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.utils; import eu.univento.core.Core; diff --git a/src/main/java/eu/univento/core/api/utils/Maths.java b/src/main/java/eu/univento/core/api/utils/Maths.java index c084a40..8bef95e 100644 --- a/src/main/java/eu/univento/core/api/utils/Maths.java +++ b/src/main/java/eu/univento/core/api/utils/Maths.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.utils; import java.util.Calendar; diff --git a/src/main/java/eu/univento/core/api/utils/NettyInjection.java b/src/main/java/eu/univento/core/api/utils/NettyInjection.java index e4254b9..7ac87c3 100644 --- a/src/main/java/eu/univento/core/api/utils/NettyInjection.java +++ b/src/main/java/eu/univento/core/api/utils/NettyInjection.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.utils; import eu.univento.core.api.utils.reflection.IReflection; 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 162def1..4c538fd 100644 --- a/src/main/java/eu/univento/core/api/utils/RandomCollection.java +++ b/src/main/java/eu/univento/core/api/utils/RandomCollection.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.utils; import java.util.NavigableMap; 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 508a060..3b064ff 100644 --- a/src/main/java/eu/univento/core/api/utils/UUIDFetcher.java +++ b/src/main/java/eu/univento/core/api/utils/UUIDFetcher.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.utils; import com.google.gson.Gson; 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 96b3e44..a11c8c3 100644 --- a/src/main/java/eu/univento/core/api/utils/Vectors.java +++ b/src/main/java/eu/univento/core/api/utils/Vectors.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.utils; import org.bukkit.util.Vector; diff --git a/src/main/java/eu/univento/core/api/utils/reflection/ArrayWrapper.java b/src/main/java/eu/univento/core/api/utils/reflection/ArrayWrapper.java index 912a363..9286955 100644 --- a/src/main/java/eu/univento/core/api/utils/reflection/ArrayWrapper.java +++ b/src/main/java/eu/univento/core/api/utils/reflection/ArrayWrapper.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.utils.reflection; import org.apache.commons.lang.Validate; diff --git a/src/main/java/eu/univento/core/api/utils/reflection/IReflection.java b/src/main/java/eu/univento/core/api/utils/reflection/IReflection.java index c205e0b..89cebbc 100644 --- a/src/main/java/eu/univento/core/api/utils/reflection/IReflection.java +++ b/src/main/java/eu/univento/core/api/utils/reflection/IReflection.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.utils.reflection; import org.bukkit.Bukkit; diff --git a/src/main/java/eu/univento/core/api/utils/reflection/ReflectionUtils.java b/src/main/java/eu/univento/core/api/utils/reflection/ReflectionUtils.java index 3845ab9..3d6bd6c 100644 --- a/src/main/java/eu/univento/core/api/utils/reflection/ReflectionUtils.java +++ b/src/main/java/eu/univento/core/api/utils/reflection/ReflectionUtils.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + package eu.univento.core.api.utils.reflection; import org.bukkit.Bukkit; diff --git a/src/main/java/eu/univento/core/api/world/WorldReset.java b/src/main/java/eu/univento/core/api/world/WorldReset.java index 2f9da05..8b1dcb5 100644 --- a/src/main/java/eu/univento/core/api/world/WorldReset.java +++ b/src/main/java/eu/univento/core/api/world/WorldReset.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 univento.eu - All rights reserved + * Copyright (c) 2017 univento.eu - All rights reserved * You are not allowed to use, distribute or modify this code */ diff --git a/src/main/java/eu/univento/core/commands/AdminCommands.java b/src/main/java/eu/univento/core/commands/AdminCommands.java new file mode 100644 index 0000000..65605a3 --- /dev/null +++ b/src/main/java/eu/univento/core/commands/AdminCommands.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.core.commands; + +import eu.univento.commons.player.rank.Rank; +import eu.univento.core.Core; +import eu.univento.core.api.camera.Traveller; +import eu.univento.core.api.command.Command; +import eu.univento.core.api.command.CommandArgs; +import io.vertx.core.json.JsonObject; +import org.bukkit.Location; + +public class AdminCommands { + + @Command(name = "camera", description = "control the camera", rank = Rank.Admin, inGameOnly = true) + public void camera(CommandArgs args) { + args.getPlayer().sendMessage("/camera add | add a new location to the route"); + args.getPlayer().sendMessage("/camera create