commit 900983dcb21548970c8011347a5e5a79604f4f87 Author: joethei Date: Sat Sep 17 12:04:34 2016 +0200 first commit diff --git a/Maya.iml b/Maya.iml new file mode 100644 index 0000000..8a03d9e --- /dev/null +++ b/Maya.iml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..3ed69f4 --- /dev/null +++ b/pom.xml @@ -0,0 +1,80 @@ + + + 4.0.0 + + groupId + Maya + 1.0-SNAPSHOT + + Univento.eu Maya Minigame + http://univento.eu + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.2-beta-5 + + + + eu.univento.maya.Maya + + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + org.spigotmc + spigot-api + 1.10-R0.1-SNAPSHOT + provided + + + eu.univento + Core + LATEST + + + eu.univento + Core + 1.0-SNAPSHOT + + + + + \ No newline at end of file diff --git a/src/main/Maya.iml b/src/main/Maya.iml new file mode 100644 index 0000000..4ab866e --- /dev/null +++ b/src/main/Maya.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/eu/univento/maya/Maya.java b/src/main/java/eu/univento/maya/Maya.java new file mode 100644 index 0000000..77dd549 --- /dev/null +++ b/src/main/java/eu/univento/maya/Maya.java @@ -0,0 +1,109 @@ +package eu.univento.maya; + +import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; + +import eu.univento.core.api.server.Game; +import eu.univento.core.api.server.ServerSettings; +import eu.univento.maya.game.GameStage; +import eu.univento.maya.game.LobbyCounter; +import eu.univento.maya.listener.PlayerEvents; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.entity.Player; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; + +/** + * main class + * @author joethei + * @version 0.1 + */ +public class Maya extends JavaPlugin{ + + /** + * instance + */ + private static Maya instance; + /** + * @return plugin instance + */ + public static Maya getInstance() { + return instance; + } + + /** + * logging and stuff + */ + private static Logger logger = Bukkit.getLogger(); + + /** + * game stage + */ + private static GameStage stage; + + /** + * @return GameStage + */ + public static GameStage getStage() { + return stage; + } + + /** + * sets gamestage + * @param stage GameStage + */ + public static void setStage(GameStage stage) { + Maya.stage = stage; + } + + public static int getMinPlayers() { + return 1; + } + + public static int getMaxPlayers() { + return 12; + } + + private static ArrayList players = new ArrayList<>(); + public static ArrayList getPlayers() { + return players; + } + + public static int lobbyID; + public static int warmupID; + public static int gameID; + public static int buyID; + public static int deathmatchID; + public static int restartID; + /** + * @param level Log level + * @param string String + */ + public static void log(Level level, String string) { + logger.log(level, "[" + getInstance().getDescription().getName() + "] " + string); + } + + @SuppressWarnings("deprecation") + @Override + public void onEnable() { + instance = this; + PluginManager pm = Bukkit.getPluginManager(); + pm.registerEvents(new PlayerEvents(), this); + + ServerSettings.setGame(true); + ServerSettings.setPlayedGame(Game.Maya); + ServerSettings.setGameMode(GameMode.ADVENTURE); + log(Level.INFO, "Plugin Version: " + getDescription().getVersion() + " gestartet"); + stage = GameStage.Lobby; + lobbyID = getServer().getScheduler().scheduleSyncRepeatingTask(getInstance(), new LobbyCounter(), 20L, 20L); + + } + + @Override + public void onDisable() { + log(Level.INFO, "Plugin beendet"); + } + +} \ No newline at end of file diff --git a/src/main/java/eu/univento/maya/Utils.java b/src/main/java/eu/univento/maya/Utils.java new file mode 100644 index 0000000..b81029f --- /dev/null +++ b/src/main/java/eu/univento/maya/Utils.java @@ -0,0 +1,30 @@ +package eu.univento.maya; + +import eu.univento.maya.game.GameStage; +import eu.univento.maya.game.RestartCounter; +import org.bukkit.Bukkit; + +/** + * @author joethei + * @version 0.1 + */ +public class Utils { + + public static void endGame(GameStage stage) { + Maya.setStage(GameStage.Restart); + Maya.restartID = Maya.getInstance().getServer().getScheduler().scheduleSyncRepeatingTask(Maya.getInstance(), new RestartCounter(), 20L, 20L); + Bukkit.getScheduler().cancelTask(getSchedulerId(stage)); + } + + static int getSchedulerId(GameStage stage) { + switch (stage) { + case Lobby: return Maya.lobbyID; + case Warmup: return Maya.warmupID; + case InGame: return Maya.gameID; + case Buy: return Maya.buyID; + case DeathMatch: return Maya.deathmatchID; + case Restart: return Maya.restartID; + default: return 0; + } + } +} \ No newline at end of file diff --git a/src/main/java/eu/univento/maya/game/BuyCounter.java b/src/main/java/eu/univento/maya/game/BuyCounter.java new file mode 100644 index 0000000..bb81b0a --- /dev/null +++ b/src/main/java/eu/univento/maya/game/BuyCounter.java @@ -0,0 +1,33 @@ +package eu.univento.maya.game; + +import eu.univento.core.api.Title; +import eu.univento.maya.Maya; +import org.bukkit.Bukkit; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +/** + * @author joethei + * @version 0.1 + */ +public class BuyCounter extends BukkitRunnable{ + + int time = 60; + + public void run() { + if(Maya.getStage() == GameStage.Buy) { + for(Player players : Bukkit.getOnlinePlayers()) { + Title.sendTitle(players, 1, 1, 1, "§6" + time, ""); + players.playSound(players.getEyeLocation(), Sound.ENTITY_ARROW_HIT, 1.0F, 1.0F); + } + if(time == 0) { + Maya.setStage(GameStage.DeathMatch); + Maya.deathmatchID = Maya.getInstance().getServer().getScheduler().scheduleSyncRepeatingTask(Maya.getInstance(), new DeathmatchCounter(), 20L, 20L); + Bukkit.getScheduler().cancelTask(Maya.buyID); + } + time--; + } + return; + } +} \ No newline at end of file diff --git a/src/main/java/eu/univento/maya/game/DeathmatchCounter.java b/src/main/java/eu/univento/maya/game/DeathmatchCounter.java new file mode 100644 index 0000000..109ec7b --- /dev/null +++ b/src/main/java/eu/univento/maya/game/DeathmatchCounter.java @@ -0,0 +1,33 @@ +package eu.univento.maya.game; + +import eu.univento.core.api.Title; +import eu.univento.maya.Maya; +import org.bukkit.Bukkit; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +/** + * @author joethei + * @version 0.1 + */ +public class DeathmatchCounter extends BukkitRunnable{ + + int time = 20; + + public void run() { + if(Maya.getStage() == GameStage.DeathMatch) { + for(Player players : Bukkit.getOnlinePlayers()) { + Title.sendTitle(players, 1, 1, 1, "§6" + time, ""); + players.playSound(players.getEyeLocation(), Sound.ENTITY_ARROW_HIT, 1.0F, 1.0F); + } + if(time == 0) { + Maya.setStage(GameStage.Restart); + Bukkit.getScheduler().cancelTask(Maya.deathmatchID); + Maya.restartID = Bukkit.getScheduler().scheduleSyncRepeatingTask(Maya.getInstance(), new RestartCounter(), 20L, 20L); + } + time--; + } + return; + } +} \ No newline at end of file diff --git a/src/main/java/eu/univento/maya/game/GameCounter.java b/src/main/java/eu/univento/maya/game/GameCounter.java new file mode 100644 index 0000000..a4eb843 --- /dev/null +++ b/src/main/java/eu/univento/maya/game/GameCounter.java @@ -0,0 +1,57 @@ +package eu.univento.maya.game; + +import eu.univento.maya.Maya; +import eu.univento.maya.Utils; +import org.bukkit.Bukkit; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Score; +import org.bukkit.scoreboard.Scoreboard; + + +/** + * runnable for game counter + * @author joethei + * @version 0.2 + */ +public class GameCounter extends BukkitRunnable{ + + int time = 0; + int maxTime = 80; + + public void run() { + if(Maya.getStage() == GameStage.InGame) { + updateScoreboard(); + if(Maya.getPlayers().size() <= 1) { + Utils.endGame(Maya.getStage()); + } + if(time == maxTime) { + Maya.setStage(GameStage.Buy); + Maya.buyID = Maya.getInstance().getServer().getScheduler().scheduleSyncRepeatingTask(Maya.getInstance(), new BuyCounter(), 20L, 20L); + Bukkit.getScheduler().cancelTask(Maya.gameID); + } + time++; + } + return; + } + + void updateScoreboard() { + Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard(); + + Objective obj = board.getObjective("maya"); + if(obj == null) { + obj = board.registerNewObjective("maya", "dummy"); + } + + obj.setDisplayName("§6Maya"); + obj.setDisplaySlot(DisplaySlot.SIDEBAR); + + Score time = obj.getScore("§6Zeit:"); + time.setScore(this.time); + + if(this.time == maxTime) { + obj.unregister(); + } + } +} \ No newline at end of file diff --git a/src/main/java/eu/univento/maya/game/GameStage.java b/src/main/java/eu/univento/maya/game/GameStage.java new file mode 100644 index 0000000..8d17f04 --- /dev/null +++ b/src/main/java/eu/univento/maya/game/GameStage.java @@ -0,0 +1,59 @@ +package eu.univento.maya.game; + +/** + * enum for gamestages + * @author joethei + * @version 1.0 + */ +public enum GameStage { + /** + * players are waiting in the lobby until min player count is reached + */ + Lobby(1), + /** + * players waiting while map is being loaded + */ + Warmup(2), + /** + * game has been started, teams are hiding there block + */ + InGame(3), + /** + * players can buy items + */ + Buy(4), + /** + * players can fight + */ + DeathMatch(5), + /** + * server is reseting map and restarts + */ + Restart(6); + + /** + * id of stage + */ + private int id; + /** + * gets gamestage for id + * @param id Integer + */ + private GameStage(int id) { + this.setId(id); + } + /** + * gets id of gamestage + * @return Integer + */ + public int getId() { + return id; + } + /** + * sets id + * @param id Integer + */ + public void setId(int id) { + this.id = id; + } +} \ No newline at end of file diff --git a/src/main/java/eu/univento/maya/game/LobbyCounter.java b/src/main/java/eu/univento/maya/game/LobbyCounter.java new file mode 100644 index 0000000..b001a77 --- /dev/null +++ b/src/main/java/eu/univento/maya/game/LobbyCounter.java @@ -0,0 +1,40 @@ +package eu.univento.maya.game; + +import eu.univento.maya.Maya; +import eu.univento.maya.modules.Modules; +import org.bukkit.Bukkit; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +/** + * runnable for lobby counter + * @author joethei + * @version 0.2 + */ +public class LobbyCounter extends BukkitRunnable{ + + int time = 60; + + public void run() { + if(Maya.getStage() == GameStage.Lobby && Bukkit.getOnlinePlayers().size() >= Maya.getMinPlayers()) { + for(Player players : Bukkit.getOnlinePlayers()) { + players.setLevel(time); + if(time == 30) { + Modules.generate(); + } + if(time <= 10) { + players.playSound(players.getEyeLocation(), Sound.ENTITY_ARROW_HIT, 1.0F, 1.0F); + } + } + + if(time == 0) { + Maya.setStage(GameStage.Warmup); + Maya.warmupID = Maya.getInstance().getServer().getScheduler().scheduleSyncRepeatingTask(Maya.getInstance(), new WarmupCounter(), 20L, 20L); + Bukkit.getScheduler().cancelTask(Maya.lobbyID); + } + time--; + } + return; + } +} \ No newline at end of file diff --git a/src/main/java/eu/univento/maya/game/RestartCounter.java b/src/main/java/eu/univento/maya/game/RestartCounter.java new file mode 100644 index 0000000..a7ed517 --- /dev/null +++ b/src/main/java/eu/univento/maya/game/RestartCounter.java @@ -0,0 +1,33 @@ +package eu.univento.maya.game; + +import eu.univento.core.api.server.Servers; +import eu.univento.core.api.Utils; +import eu.univento.core.api.server.ServerSettings; +import eu.univento.maya.Maya; +import org.bukkit.Bukkit; +import org.bukkit.scheduler.BukkitRunnable; + +/** + * @author joethei + * @version 0.1 + */ +public class RestartCounter extends BukkitRunnable{ + + int time = 10; + + public void run() { + if(Maya.getStage() == GameStage.Restart) { + + Bukkit.broadcastMessage("§6Server startet neu in " + time + " Sekunden"); + + if(time == 0) { + Bukkit.getScheduler().cancelTask(Maya.restartID); + Utils.restart(); + ServerSettings.setPlayedGame(null); + Servers.connectAllToServer("Lobby01"); + Bukkit.broadcastMessage("Alle würden jetzt auf die Lobby01 kommen"); + } + time--; + } + } +} \ No newline at end of file diff --git a/src/main/java/eu/univento/maya/game/WarmupCounter.java b/src/main/java/eu/univento/maya/game/WarmupCounter.java new file mode 100644 index 0000000..44cf8e0 --- /dev/null +++ b/src/main/java/eu/univento/maya/game/WarmupCounter.java @@ -0,0 +1,34 @@ +package eu.univento.maya.game; + +import eu.univento.core.api.Title; +import eu.univento.maya.Maya; +import org.bukkit.Bukkit; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +/** + * @author joethei + * @version 0.1 + */ +public class WarmupCounter extends BukkitRunnable{ + + int time = 10; + + public void run() { + if(Maya.getStage() == GameStage.Warmup) { + for(Player players : Bukkit.getOnlinePlayers()) { + Title.sendTitle(players, 1, 10, 1, "§6" + time, ""); + players.playSound(players.getEyeLocation(), Sound.ENTITY_ARROW_HIT, 1.0F, 1.0F); + } + if(time == 0) { + Maya.setStage(GameStage.InGame); + Maya.gameID = Maya.getInstance().getServer().getScheduler().scheduleSyncRepeatingTask(Maya.getInstance(), new GameCounter(), 20L, 20L); + Bukkit.getScheduler().cancelTask(Maya.warmupID); + } + time--; + } + return; + } + +} diff --git a/src/main/java/eu/univento/maya/listener/PlayerEvents.java b/src/main/java/eu/univento/maya/listener/PlayerEvents.java new file mode 100644 index 0000000..f06ee9f --- /dev/null +++ b/src/main/java/eu/univento/maya/listener/PlayerEvents.java @@ -0,0 +1,60 @@ +package eu.univento.maya.listener; + +import eu.univento.core.api.Config; +import eu.univento.core.api.player.CustomPlayer; +import eu.univento.core.api.player.Spectator; +import eu.univento.maya.Maya; +import eu.univento.maya.game.GameStage; +import org.bukkit.GameMode; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +/** + * @author joethei + * @version 0.1 + */ +public class PlayerEvents implements Listener{ + + @EventHandler + public void onJoin(PlayerJoinEvent e) { + CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); + if(Maya.getStage() == GameStage.Lobby) { + if(Maya.getPlayers().size() >= Maya.getMaxPlayers()) { + Spectator.add(p); + p.teleport(Config.readLocation("Maya.Spawn.Spectator")); + p.sendMessage("§cDu bist nun Zuschauer"); + e.setJoinMessage(null); + return; + } + p.teleport(Config.readLocation("Maya.Spawn.Lobby")); + p.sendMessage("§cDu bist dem Spiel beigetreten"); + e.setJoinMessage("§6Maya: " + p.getColor() + p.getDisplayName() + " §6ist dem Spiel beigetreten"); + p.setGameMode(GameMode.ADVENTURE); + + + }else { + e.setJoinMessage(null); + Spectator.add(p); + p.teleport(Config.readLocation("Maya.Spawn.Spectator")); + p.sendMessage("§cDu bist nun Zuschauer"); + + } + } + + @EventHandler + public void onQuit(PlayerQuitEvent e) { + CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); + if(Spectator.is(p)) { + Spectator.remove(p); + e.setQuitMessage(null); + } + if(Maya.getPlayers().contains(p)) { + Maya.getPlayers().remove(p); + e.setQuitMessage("§6Maya: " + p.getColor() + p.getDisplayName() + " §6hat das Spiel verlassen"); + } + + } + +} \ No newline at end of file diff --git a/src/main/java/eu/univento/maya/modules/Modules.java b/src/main/java/eu/univento/maya/modules/Modules.java new file mode 100644 index 0000000..ae82d18 --- /dev/null +++ b/src/main/java/eu/univento/maya/modules/Modules.java @@ -0,0 +1,29 @@ +package eu.univento.maya.modules; + +import eu.univento.core.api.map.MinecraftSchematic; +import eu.univento.maya.Maya; +import org.bukkit.Bukkit; +import org.bukkit.Location; + +import java.io.File; +import java.util.logging.Level; + +/** + * @author joethei + * @version 0.1 + */ +public class Modules { + +private static void loadModule(Location loc, String name) { + File file = new File("plugins/Core/Maya/modules/", name + ".schematic"); + MinecraftSchematic schematic = new MinecraftSchematic(file); + schematic.placeInWorld(loc); +} + + public static void generate() { + int playercount = Maya.getPlayers().size(); + loadModule(Bukkit.getWorld("world").getSpawnLocation(), "test"); + Maya.log(Level.INFO, "Modul test wird generiert"); + } + +} \ No newline at end of file diff --git a/src/main/java/plugin.yml b/src/main/java/plugin.yml new file mode 100644 index 0000000..f0189f2 --- /dev/null +++ b/src/main/java/plugin.yml @@ -0,0 +1,6 @@ +main: eu.univento.maya.Maya +name: Maya +author: joethei +version: 0.1 +description: Maya Minigame from univento.eu +website: http://univento.eu/games/maya \ No newline at end of file