From e1d93cf1b619525b731336007d4765cad69a1057 Mon Sep 17 00:00:00 2001 From: joethei Date: Wed, 3 Aug 2016 00:03:09 +0200 Subject: [PATCH] first commit --- .gitignore | 2 + pom.xml | 96 +++++++++++++ .../java/eu/univento/free4all/Free4All.java | 46 ++++++ .../eu/univento/free4all/commands/Setloc.java | 50 +++++++ .../free4all/listeners/PlayerEvents.java | 133 ++++++++++++++++++ .../free4all/utils/RespawnHelper.java | 73 ++++++++++ src/main/resources/plugin.yml | 6 + 7 files changed, 406 insertions(+) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/main/java/eu/univento/free4all/Free4All.java create mode 100644 src/main/java/eu/univento/free4all/commands/Setloc.java create mode 100644 src/main/java/eu/univento/free4all/listeners/PlayerEvents.java create mode 100644 src/main/java/eu/univento/free4all/utils/RespawnHelper.java create mode 100644 src/main/resources/plugin.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..32c4b59 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +Free4All.iml \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..7ed5471 --- /dev/null +++ b/pom.xml @@ -0,0 +1,96 @@ + + + 4.0.0 + + eu.univento + ffa + 1.0-SNAPSHOT + univento.eu Free4All Secret Minigame + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.2-beta-5 + + + + eu.univento.teamvento.TeamVento + + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + org.bukkit + bukkit + 1.10-R0.1-SNAPSHOT + provided + + + org.mongodb + mongo-java-driver + 3.2.2 + + + org.mongodb + mongodb-driver-async + 3.2.2 + + + io.netty + netty-all + 4.0.36.Final + + + org.spigotmc + spigot-api + 1.10-R0.1-SNAPSHOT + provided + + + com.google.code.gson + gson + 2.3.1 + + + eu.univento + Core + 1.0-SNAPSHOT + + + \ No newline at end of file diff --git a/src/main/java/eu/univento/free4all/Free4All.java b/src/main/java/eu/univento/free4all/Free4All.java new file mode 100644 index 0000000..3a665f3 --- /dev/null +++ b/src/main/java/eu/univento/free4all/Free4All.java @@ -0,0 +1,46 @@ +package eu.univento.free4all; + +import eu.univento.core.Core; +import eu.univento.free4all.commands.Setloc; +import eu.univento.free4all.listeners.PlayerEvents; +import org.bukkit.Bukkit; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * @author joethei + * @version 0.1 + */ +public class Free4All extends JavaPlugin { + + public static String prefix = " Free4All"; + + private static Free4All instance; + public static Free4All getInstance() { + return instance; + } + + private static Logger logger; + public static void log(Level level, String msg) { + logger.log(level, msg); + } + + @Override + public void onEnable() { + Core.getInstance().registerPlugin(this); + instance = this; + logger = Bukkit.getLogger(); + PluginManager pm = Bukkit.getPluginManager(); + pm.registerEvents(new PlayerEvents(), this); + + new Setloc(this, "setloc", "sets locations"); + } + + @Override + public void onDisable() { + Core.getInstance().unregisterPlugin(this); + } +} \ No newline at end of file diff --git a/src/main/java/eu/univento/free4all/commands/Setloc.java b/src/main/java/eu/univento/free4all/commands/Setloc.java new file mode 100644 index 0000000..6a0a5d6 --- /dev/null +++ b/src/main/java/eu/univento/free4all/commands/Setloc.java @@ -0,0 +1,50 @@ +package eu.univento.free4all.commands; + +import eu.univento.commons.player.Rank; +import eu.univento.core.api.AutoCommand; +import eu.univento.core.api.Config; +import eu.univento.core.api.languages.Messages; +import eu.univento.core.api.player.CustomPlayer; +import eu.univento.free4all.Free4All; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.List; + +/** + * @author joethei + * @version 1.0 + */ +public class Setloc extends AutoCommand{ + + public Setloc(Free4All plugin, String command, String description, String... aliases) { + super(plugin, command, description, aliases); + } + + @Override + public boolean execute(CommandSender sender, String label, String[] args) { + if(sender instanceof Player) { + CustomPlayer p = CustomPlayer.getPlayer(sender.getName()); + Messages msgs = new Messages(p); + assert p != null; + if(p.getDatabasePlayer().isAllowed(Rank.SrDeveloper)) { + if(args.length == 1) { + Config.write("FFA.Spawn." + args[0], p.getLocation()); + p.sendMessage(msgs.PREFIX() + msgs.Lobby_SET_LOCATION()); + }else { + p.sendMessage(msgs.PREFIX() + msgs.Lobby_SET_LOCATION_USAGE()); + } + }else { + p.sendMessage(msgs.NO_PERMS()); + } + }else { + sender.sendMessage(Messages.Console.NOT_A_PLAYER); + } + return false; + } + + @Override + public List tabComplete(CommandSender sender, String label, String[] args) { + return null; + } +} diff --git a/src/main/java/eu/univento/free4all/listeners/PlayerEvents.java b/src/main/java/eu/univento/free4all/listeners/PlayerEvents.java new file mode 100644 index 0000000..c98c6ea --- /dev/null +++ b/src/main/java/eu/univento/free4all/listeners/PlayerEvents.java @@ -0,0 +1,133 @@ +package eu.univento.free4all.listeners; + +import eu.univento.core.Core; +import eu.univento.core.api.Hologram; +import eu.univento.core.api.effects.Effects; +import eu.univento.core.api.player.CustomPlayer; +import eu.univento.free4all.Free4All; +import eu.univento.free4all.utils.RespawnHelper; +import net.minecraft.server.v1_10_R1.EnumParticle; +import org.bukkit.Effect; +import org.bukkit.Material; +import org.bukkit.block.BlockFace; +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; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; + +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * @author joethei + * @version 0.1 + */ +public class PlayerEvents implements Listener{ + private Map> lastDamage = new LinkedHashMap<>(); + + @EventHandler + public void onPlayerDeath(PlayerDeathEvent e) { + CustomPlayer p = CustomPlayer.getPlayer(e.getEntity()); + if(p.getKiller() != null) { + CustomPlayer killer = CustomPlayer.getPlayer(p.getKiller()); + e.setDeathMessage(p.getDatabasePlayer().getRank().getColor() + p.getDisplayName() + " §awurde von " + killer.getDatabasePlayer().getRank().getColor() + killer.getDisplayName() + " §agetötet."); + Hologram holo = new Hologram(new String[]{"§6+1 Coins"}, p.getEyeLocation()); + killer.getDatabasePlayer().addCoins(1); + holo.showPlayerTemp(killer, 50); + for(CustomPlayer players : Core.getOnlinePlayers()) { + players.playEffect(killer.getLocation(), Effect.CHORUS_FLOWER_DEATH, 5, 2, 0.5F, 0.0F, 0.5F, 0.1F, 20, 5); + } + }else if(lastDamage.containsKey(p)){ + for(Map.Entry entry : lastDamage.get(p).entrySet()) { + CustomPlayer killer = entry.getKey(); + e.setDeathMessage(p.getDatabasePlayer().getRank().getColor() + p.getDisplayName() + " §a wurde von " + killer.getDatabasePlayer().getRank().getColor() + killer.getDisplayName() + " §cgetötet."); + Effects.playEffect(killer.getLocation(), EnumParticle.DRIP_LAVA, 10); + killer.getDatabasePlayer().addCoins(1); + } + }else { + e.setDeathMessage(p.getDatabasePlayer().getRank().getColor() + p.getDisplayName() + " §cist nun tot."); + } + } + + @EventHandler + public void onPlayerRespawn(PlayerRespawnEvent e) { + CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); + RespawnHelper helper = new RespawnHelper(p); + e.setRespawnLocation(helper.getRespawnLocation()); + helper.setRespawnInventory(); + Effects.playEffect(e.getRespawnLocation(), EnumParticle.HEART, 5); + } + + @EventHandler + public void onEntityDamageByEntity(EntityDamageByEntityEvent e) { + + if(e.getEntity() instanceof Player) { + CustomPlayer p = CustomPlayer.getPlayer((Player) e.getEntity()); + if(e.getDamager() instanceof Player) { + CustomPlayer damager = CustomPlayer.getPlayer((Player) e.getEntity()); + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + if(lastDamage.containsKey(p)) lastDamage.remove(p); + } + }.runTaskLater(Free4All.getInstance(), 10 * 20L); + LinkedHashMap map = new LinkedHashMap<>(); + map.put(damager, task); + lastDamage.put(p, map); + } + if(e.getDamager() instanceof Projectile) { + CustomPlayer damager = CustomPlayer.getPlayer((Player) ((Projectile) e.getDamager()).getShooter()); + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + if(lastDamage.containsKey(p)) lastDamage.remove(p); + } + }.runTaskLater(Free4All.getInstance(), 10 * 20L); + LinkedHashMap map = new LinkedHashMap<>(); + map.put(damager, task); + lastDamage.put(p, map); + } + } + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent e) { + CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); + e.setJoinMessage(p.getDatabasePlayer().getRank().getColor() + p.getDisplayName() + " §aist dem Spiel beigetreten."); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent e) { + CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); + for(Map.Entry> entry : lastDamage.entrySet()) { + entry.getValue().entrySet().stream().filter(mapEntry -> mapEntry.equals(p)).forEach(mapEntry -> lastDamage.remove(entry.getKey())); + } + if(lastDamage.containsKey(p)) { + for(Map.Entry entry : lastDamage.get(p).entrySet()) { + CustomPlayer killer = entry.getKey(); + killer.getDatabasePlayer().addCoins(1); + Effects.playEffect(p.getLocation(), EnumParticle.FLAME, 10); + } + e.setQuitMessage(Free4All.prefix + "§cDer Spieler " + p.getDatabasePlayer().getRank().getColor() + p.getDisplayName() + " §chat sich während eines Kampfes ausgeloggt."); + lastDamage.remove(p); + } + e.setQuitMessage(Free4All.prefix + "§cDer Spieler " + p.getDatabasePlayer().getRank().getColor() + p.getDisplayName() + " §c hat das Spiel verlassen."); + } + + @EventHandler + public void onPlayerMove(PlayerMoveEvent e) { + CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); + if(e.getTo().getBlock().getRelative(BlockFace.UP).getType() == Material.STATIONARY_WATER) { + p.damage(0.5D); + } + } + +} \ No newline at end of file diff --git a/src/main/java/eu/univento/free4all/utils/RespawnHelper.java b/src/main/java/eu/univento/free4all/utils/RespawnHelper.java new file mode 100644 index 0000000..1f8353a --- /dev/null +++ b/src/main/java/eu/univento/free4all/utils/RespawnHelper.java @@ -0,0 +1,73 @@ +package eu.univento.free4all.utils; + +import eu.univento.core.api.Config; +import eu.univento.core.api.items.ItemBuilder; +import eu.univento.core.api.player.CustomPlayer; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.PlayerInventory; + +import java.util.Random; + +/** + * @author joethei + * @version 0.1 + */ +public class RespawnHelper { + + private CustomPlayer player; + + public RespawnHelper(CustomPlayer player) { + this.player = player; + } + + public Location getRespawnLocation() { + int spawn = new Random().nextInt(10); + return Config.readLocation("FFA.Spawn." + spawn); + } + + public void setRespawnInventory() { + int inventory = new Random().nextInt(5); + PlayerInventory inv = player.getInventory(); + inv.clear(); + + if(inventory == 0) { + inv.setItem(0, new ItemBuilder(Material.WOOD_SWORD).name("§cEinfaches Schwert").make()); + inv.setItem(1, new ItemBuilder(Material.BOW).name("§cEinfacher Bogen").make()); + inv.setItem(8, new ItemBuilder(Material.ARROW).name("§cEinfacher Pfeil").amount(10).make()); + inv.setBoots(new ItemBuilder(Material.DIAMOND_BOOTS).name("§cStarke Schuhe").make()); + inv.setLeggings(new ItemBuilder(Material.DIAMOND_LEGGINGS).name("§cStarke Hose").make()); + inv.setChestplate(new ItemBuilder(Material.DIAMOND_CHESTPLATE).name("§cStarke Brustplatte").enchantment(Enchantment.THORNS).make()); + inv.setHelmet(new ItemBuilder(Material.DIAMOND_HELMET).name("§cStarker Helm").make()); + } + if(inventory == 1) { + inv.setItem(0, new ItemBuilder(Material.WOOD_SWORD).name("§cFliegendes Schwert").enchantment(Enchantment.KNOCKBACK).make()); + inv.setItem(1, new ItemBuilder(Material.BOW).name("§cFliegender Bogen").enchantment(Enchantment.ARROW_KNOCKBACK).make()); + inv.setItem(8, new ItemBuilder(Material.ARROW).name("§cFliegende Pfeil").amount(10).make()); + inv.setBoots(new ItemBuilder(Material.DIAMOND_BOOTS).name("§cStarke Schuhe").make()); + inv.setLeggings(new ItemBuilder(Material.DIAMOND_LEGGINGS).name("§cStarke Hose").make()); + inv.setChestplate(new ItemBuilder(Material.DIAMOND_CHESTPLATE).name("§cStarke Brustplatte").make()); + inv.setHelmet(new ItemBuilder(Material.DIAMOND_HELMET).name("§cStarke Helm").make()); + } + if(inventory == 2) { + inv.setItem(0, new ItemBuilder(Material.WOOD_SWORD).name("§cFeuriges Schwert").enchantment(Enchantment.FIRE_ASPECT).make()); + inv.setItem(1, new ItemBuilder(Material.BOW).name("§cFeuriger Bogen").enchantment(Enchantment.ARROW_FIRE).make()); + inv.setItem(8, new ItemBuilder(Material.ARROW).name("§cFeuriger Pfeil").amount(10).make()); + inv.setBoots(new ItemBuilder(Material.DIAMOND_BOOTS).name("§cStarke Schuhe").make()); + inv.setLeggings(new ItemBuilder(Material.DIAMOND_LEGGINGS).name("§cStarke Hose").make()); + inv.setChestplate(new ItemBuilder(Material.DIAMOND_CHESTPLATE).name("§cStarke Brustplatte").enchantment(Enchantment.PROTECTION_FIRE).make()); + inv.setHelmet(new ItemBuilder(Material.DIAMOND_HELMET).name("§cStarke Helm").make()); + } + if(inventory == 3) { + inv.setItem(0, new ItemBuilder(Material.STONE_SWORD).name("§cEin Schwert").make()); + inv.setItem(1, new ItemBuilder(Material.BOW).name("§cEin Bogen").enchantment(Enchantment.ARROW_DAMAGE).make()); + inv.setItem(8, new ItemBuilder(Material.ARROW).amount(20).make()); + } + if(inventory == 4) { + inv.setItem(0, new ItemBuilder(Material.STONE_SWORD).name("§cStarkes Schwert").enchantment(Enchantment.DAMAGE_ALL).make()); + inv.setItem(1, new ItemBuilder(Material.BOW).name("§cUnendlicher Bogen").enchantment(Enchantment.ARROW_INFINITE).make()); + inv.setItem(8, new ItemBuilder(Material.SPECTRAL_ARROW).name("§cLeuchtender Pfeil").make()); + } + } +} \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..94a9fa4 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,6 @@ +name: Free4All +main: eu.univento.free4All.Free4All +author: joethei +version: 0.1 +description: univento.eu Secret Minigame +website: https://univento.eu \ No newline at end of file