diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..92a9a94 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +Effekte Challenge V2/target/* +.DS_Store \ No newline at end of file diff --git a/Effekte Challenge V2/src/main/java/com/xonics/ef/classes/Challenge.java b/Effekte Challenge V2/src/main/java/com/xonics/ef/classes/Challenge.java new file mode 100644 index 0000000..ec6bac7 --- /dev/null +++ b/Effekte Challenge V2/src/main/java/com/xonics/ef/classes/Challenge.java @@ -0,0 +1,94 @@ +package com.xonics.ef.classes; + +import java.util.List; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.potion.PotionEffect; +import org.bukkit.boss.BossBar; +import org.bukkit.Bukkit; +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarStyle; +import com.xonics.ef.main; + +public class Challenge { + + private boolean isRunning; + private List players; + private BukkitRunnable task; + private TimeManager tm; + + public Challenge(List participants, int timer) { + this.players = participants; + this.isRunning = false; + this.tm.setTime(timer); + } + + public Challenge(List participants) { + this(participants, 20); + } + + public void start() { + if (!isRunning) { + isRunning = true; + BossBar infoBar = Bukkit.createBossBar("Finger an der Gapling Gan", BarColor.RED, BarStyle.SEGMENTED_10); + for (Player p : players) { + infoBar.addPlayer(p); + infoBar.setVisible(true); + } + Timer.start(); + EffektRevolver revolver = new EffektRevolver(6); + revolver.loadRevolver(); + this.task = new BukkitRunnable() { + @Override + public void run() { + + infoBar.setTitle( + "Finger an der Gapling Gan in " + tm.getTime() + "s " + revolver.getChamberIndicator()); + infoBar.setProgress((double) (tm.getInitTime() - tm.getTime()) / tm.getInitTime()); + + if (tm.getTime() == 0) { + if (!revolver.isEmpty()) { + setEffekt(revolver.shoot()); + } else { + revolver.loadRevolver(); + } + tm.resetTime(); + } + + tm.decreaseTime(); + } + }; + task.runTaskTimer(main.getInstance(), 0L, 20L); + } + } + + public void stop() { + this.task.cancel(); + this.isRunning = false; + Timer.stop(); + } + + public void sendMessageToParticipants(String msg) { + for (Player p : players) { + p.sendMessage(msg); + } + } + + public void setEffekt(Effekt e) { + for (Player p : players) { + p.addPotionEffect(new PotionEffect(e.getEffect(), tm.getInitTime(), 1)); + switch (e.getEffektTyp()) { + case GOOD: + p.sendTitle("§a" + e.getName(), "", 10, 20, 10); + break; + case BAD: + p.sendTitle("§c" + e.getName(), "", 10, 20, 10); + break; + case NEUTRAL: + p.sendTitle("§7" + e.getName(), "", 10, 20, 10); + break; + } + } + } + +} diff --git a/Effekte Challenge V2/src/main/java/com/xonics/ef/classes/Effekt.java b/Effekte Challenge V2/src/main/java/com/xonics/ef/classes/Effekt.java index 0e66e02..7f9d012 100644 --- a/Effekte Challenge V2/src/main/java/com/xonics/ef/classes/Effekt.java +++ b/Effekte Challenge V2/src/main/java/com/xonics/ef/classes/Effekt.java @@ -4,14 +4,20 @@ import org.bukkit.potion.PotionEffectType; public class Effekt { + private String eName; private PotionEffectType ieffect; private EffektTyp ieTyp; - public Effekt(PotionEffectType effect, EffektTyp eTyp) { + public Effekt(String name, PotionEffectType effect, EffektTyp eTyp) { + this.eName = name; this.ieffect = effect; this.ieTyp = eTyp; } + public String getName() { + return this.eName; + } + public PotionEffectType getEffect() { return this.ieffect; } diff --git a/Effekte Challenge V2/src/main/java/com/xonics/ef/classes/EffektLibrary.java b/Effekte Challenge V2/src/main/java/com/xonics/ef/classes/EffektLibrary.java index 00d0586..e7c758d 100644 --- a/Effekte Challenge V2/src/main/java/com/xonics/ef/classes/EffektLibrary.java +++ b/Effekte Challenge V2/src/main/java/com/xonics/ef/classes/EffektLibrary.java @@ -6,43 +6,43 @@ import org.bukkit.potion.PotionEffectType; public abstract class EffektLibrary { private static List effects = List.of( - new Effekt(PotionEffectType.SPEED, EffektTyp.GOOD), - new Effekt(PotionEffectType.SLOWNESS, EffektTyp.BAD), - new Effekt(PotionEffectType.JUMP_BOOST, EffektTyp.GOOD), - new Effekt(PotionEffectType.OOZING, EffektTyp.NEUTRAL), - new Effekt(PotionEffectType.FIRE_RESISTANCE, EffektTyp.GOOD), - new Effekt(PotionEffectType.INSTANT_DAMAGE, EffektTyp.BAD), - new Effekt(PotionEffectType.INSTANT_HEALTH, EffektTyp.GOOD), - new Effekt(PotionEffectType.HUNGER, EffektTyp.BAD), - new Effekt(PotionEffectType.INVISIBILITY, EffektTyp.GOOD), - new Effekt(PotionEffectType.LEVITATION, EffektTyp.BAD), - new Effekt(PotionEffectType.NIGHT_VISION, EffektTyp.GOOD), - new Effekt(PotionEffectType.POISON, EffektTyp.BAD), - new Effekt(PotionEffectType.REGENERATION, EffektTyp.GOOD), - new Effekt(PotionEffectType.STRENGTH, EffektTyp.GOOD), - new Effekt(PotionEffectType.WEAKNESS, EffektTyp.BAD), - new Effekt(PotionEffectType.WITHER, EffektTyp.BAD), - new Effekt(PotionEffectType.INFESTED, EffektTyp.NEUTRAL), - new Effekt(PotionEffectType.HASTE, EffektTyp.GOOD), - new Effekt(PotionEffectType.MINING_FATIGUE, EffektTyp.BAD), - new Effekt(PotionEffectType.STRENGTH, EffektTyp.GOOD), - new Effekt(PotionEffectType.NAUSEA, EffektTyp.BAD), - new Effekt(PotionEffectType.RESISTANCE, EffektTyp.GOOD), - new Effekt(PotionEffectType.WATER_BREATHING, EffektTyp.GOOD), - new Effekt(PotionEffectType.INVISIBILITY, EffektTyp.NEUTRAL), - new Effekt(PotionEffectType.BLINDNESS, EffektTyp.BAD), - new Effekt(PotionEffectType.NIGHT_VISION, EffektTyp.NEUTRAL), - new Effekt(PotionEffectType.HUNGER, EffektTyp.BAD), - new Effekt(PotionEffectType.HEALTH_BOOST, EffektTyp.GOOD), - new Effekt(PotionEffectType.ABSORPTION, EffektTyp.GOOD), - new Effekt(PotionEffectType.SATURATION, EffektTyp.GOOD), - new Effekt(PotionEffectType.GLOWING, EffektTyp.NEUTRAL), - new Effekt(PotionEffectType.LUCK, EffektTyp.NEUTRAL), - new Effekt(PotionEffectType.UNLUCK, EffektTyp.NEUTRAL), - new Effekt(PotionEffectType.CONDUIT_POWER, EffektTyp.GOOD), - new Effekt(PotionEffectType.DOLPHINS_GRACE, EffektTyp.GOOD), - new Effekt(PotionEffectType.BAD_OMEN, EffektTyp.BAD), - new Effekt(PotionEffectType.HERO_OF_THE_VILLAGE, EffektTyp.GOOD)); + new Effekt("Speed", PotionEffectType.SPEED, EffektTyp.GOOD), + new Effekt("Slowness", PotionEffectType.SLOWNESS, EffektTyp.BAD), + new Effekt("Jump Boost", PotionEffectType.JUMP_BOOST, EffektTyp.GOOD), + new Effekt("Oozing", PotionEffectType.OOZING, EffektTyp.NEUTRAL), + new Effekt("Fire Resistance", PotionEffectType.FIRE_RESISTANCE, EffektTyp.GOOD), + new Effekt("Instant Damage", PotionEffectType.INSTANT_DAMAGE, EffektTyp.BAD), + new Effekt("Instant Health", PotionEffectType.INSTANT_HEALTH, EffektTyp.GOOD), + new Effekt("Hunger", PotionEffectType.HUNGER, EffektTyp.BAD), + new Effekt("Invisibility", PotionEffectType.INVISIBILITY, EffektTyp.GOOD), + new Effekt("Levitation", PotionEffectType.LEVITATION, EffektTyp.BAD), + new Effekt("Night Vision", PotionEffectType.NIGHT_VISION, EffektTyp.GOOD), + new Effekt("Poison", PotionEffectType.POISON, EffektTyp.BAD), + new Effekt("Regeneration", PotionEffectType.REGENERATION, EffektTyp.GOOD), + new Effekt("Strength", PotionEffectType.STRENGTH, EffektTyp.GOOD), + new Effekt("Weakness", PotionEffectType.WEAKNESS, EffektTyp.BAD), + new Effekt("Wither", PotionEffectType.WITHER, EffektTyp.BAD), + new Effekt("Infested", PotionEffectType.INFESTED, EffektTyp.NEUTRAL), + new Effekt("Haste", PotionEffectType.HASTE, EffektTyp.GOOD), + new Effekt("Mining Fatigue", PotionEffectType.MINING_FATIGUE, EffektTyp.BAD), + new Effekt("Strength", PotionEffectType.STRENGTH, EffektTyp.GOOD), + new Effekt("Nausea", PotionEffectType.NAUSEA, EffektTyp.BAD), + new Effekt("Resistance", PotionEffectType.RESISTANCE, EffektTyp.GOOD), + new Effekt("Water Breathing", PotionEffectType.WATER_BREATHING, EffektTyp.GOOD), + new Effekt("Invisibility", PotionEffectType.INVISIBILITY, EffektTyp.NEUTRAL), + new Effekt("Blindness", PotionEffectType.BLINDNESS, EffektTyp.BAD), + new Effekt("Night Vision", PotionEffectType.NIGHT_VISION, EffektTyp.NEUTRAL), + new Effekt("Hunger", PotionEffectType.HUNGER, EffektTyp.BAD), + new Effekt("Health Boost", PotionEffectType.HEALTH_BOOST, EffektTyp.GOOD), + new Effekt("Absorption", PotionEffectType.ABSORPTION, EffektTyp.GOOD), + new Effekt("Saturation", PotionEffectType.SATURATION, EffektTyp.GOOD), + new Effekt("Glowing", PotionEffectType.GLOWING, EffektTyp.NEUTRAL), + new Effekt("Luck", PotionEffectType.LUCK, EffektTyp.NEUTRAL), + new Effekt("Unluck", PotionEffectType.UNLUCK, EffektTyp.NEUTRAL), + new Effekt("Conduit Power", PotionEffectType.CONDUIT_POWER, EffektTyp.GOOD), + new Effekt("Dolphins Grace", PotionEffectType.DOLPHINS_GRACE, EffektTyp.GOOD), + new Effekt("Bad Omen", PotionEffectType.BAD_OMEN, EffektTyp.BAD), + new Effekt("Hero of the Village", PotionEffectType.HERO_OF_THE_VILLAGE, EffektTyp.GOOD)); public static List getEffects() { return effects; @@ -55,5 +55,4 @@ public abstract class EffektLibrary { public static int getEffectCount() { return effects.size(); } - } \ No newline at end of file diff --git a/Effekte Challenge V2/src/main/java/com/xonics/ef/classes/EffektRevolver.java b/Effekte Challenge V2/src/main/java/com/xonics/ef/classes/EffektRevolver.java index d350c59..eca8271 100644 --- a/Effekte Challenge V2/src/main/java/com/xonics/ef/classes/EffektRevolver.java +++ b/Effekte Challenge V2/src/main/java/com/xonics/ef/classes/EffektRevolver.java @@ -9,11 +9,13 @@ public class EffektRevolver { private int roundsShot; private boolean isEmpty; private ArrayList chamber = new ArrayList(); + private String chamberIndicator; public EffektRevolver(int roundSlots) { this.roundSlots = roundSlots; this.roundsShot = 0; this.isEmpty = true; + this.chamberIndicator = ""; } public void loadRevolver() { @@ -25,6 +27,7 @@ public class EffektRevolver { for (int i = 0; i < EffektLibrary.getEffectCount(); i++) { randomZahlen.add(i); + this.chamberIndicator += "§7| "; } Collections.shuffle(randomZahlen); @@ -34,15 +37,24 @@ public class EffektRevolver { } this.isEmpty = false; } - } public Effekt shoot() { - if (!this.isEmpty && this.roundsShot < this.roundSlots) { + if (this.roundsShot <= this.roundSlots) { int chamberNumber = this.roundsShot; this.roundsShot++; + this.chamberIndicator = this.chamberIndicator.substring(0, this.chamberIndicator.length() - 4); return this.chamber.get(chamberNumber); } + this.isEmpty = true; return null; } -} + + public boolean isEmpty() { + return this.isEmpty; + } + + public String getChamberIndicator() { + return this.chamberIndicator; + } +} \ No newline at end of file diff --git a/Effekte Challenge V2/src/main/java/com/xonics/ef/classes/TimeManager.java b/Effekte Challenge V2/src/main/java/com/xonics/ef/classes/TimeManager.java new file mode 100644 index 0000000..983fd88 --- /dev/null +++ b/Effekte Challenge V2/src/main/java/com/xonics/ef/classes/TimeManager.java @@ -0,0 +1,31 @@ +package com.xonics.ef.classes; + +public class TimeManager { + private int time; + private int timeClone; + + public void setTime(int time) { + this.time = time; + this.timeClone = time; + } + + public void decreaseTime() { + this.time--; + } + + public void increaseTime() { + this.time++; + } + + public int getTime() { + return this.time; + } + + public int getInitTime() { + return this.timeClone; + } + + public void resetTime() { + this.time = this.timeClone; + } +} diff --git a/Effekte Challenge V2/src/main/java/com/xonics/ef/classes/Timer.java b/Effekte Challenge V2/src/main/java/com/xonics/ef/classes/Timer.java index cf5a681..76ece2b 100644 --- a/Effekte Challenge V2/src/main/java/com/xonics/ef/classes/Timer.java +++ b/Effekte Challenge V2/src/main/java/com/xonics/ef/classes/Timer.java @@ -7,16 +7,18 @@ import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -public class Timer { +public abstract class Timer { private static int time; private static BukkitRunnable task; private static boolean paused = false; + private static boolean running = false; public static void start() { if (task != null) return; time = 0; + running = true; task = new BukkitRunnable() { @Override @@ -53,6 +55,7 @@ public class Timer { task = null; time = 0; paused = false; + running = false; } public static String getTime() { @@ -61,4 +64,12 @@ public class Timer { int sekunden = time % 60; return String.format("%02d:%02d:%02d", stunden, minuten, sekunden); } + + public static boolean isPaused() { + return paused; + } + + public static boolean isRunning() { + return running; + } } diff --git a/Effekte Challenge V2/src/main/java/com/xonics/ef/commands/TimerCommands.java b/Effekte Challenge V2/src/main/java/com/xonics/ef/commands/TimerCommands.java new file mode 100644 index 0000000..aa85f46 --- /dev/null +++ b/Effekte Challenge V2/src/main/java/com/xonics/ef/commands/TimerCommands.java @@ -0,0 +1,33 @@ +package com.xonics.ef.commands; + +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.Command; +import org.bukkit.entity.Player; +import com.xonics.ef.classes.Timer; + +public class TimerCommands implements CommandExecutor { + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Player p = (Player) sender; + + switch (command.getName().toLowerCase()) { + case "pause": + if (Timer.isPaused()) { + p.sendMessage("Der Timer ist bereits pausiert."); + } else { + Timer.pause(); + } + break; + + case "resume": + if (!Timer.isPaused()) { + p.sendMessage("Der Timer läuft bereits."); + } else { + Timer.resume(); + } + break; + } + return true; + } +} diff --git a/Effekte Challenge V2/src/main/java/com/xonics/ef/listeners/PlayerListener.java b/Effekte Challenge V2/src/main/java/com/xonics/ef/listeners/PlayerListener.java index b663978..d627bc6 100644 --- a/Effekte Challenge V2/src/main/java/com/xonics/ef/listeners/PlayerListener.java +++ b/Effekte Challenge V2/src/main/java/com/xonics/ef/listeners/PlayerListener.java @@ -3,12 +3,19 @@ package com.xonics.ef.listeners; import org.bukkit.event.Listener; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; public class PlayerListener implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { String pName = event.getPlayer().getName(); - event.setJoinMessage("§a" + pName + " §7ist dem Spiel beigetreten!"); + event.setJoinMessage("§a+ §8| §7" + pName); } -} \ No newline at end of file + + @EventHandler + public void OnPlayerLeave(PlayerQuitEvent event) { + String pName = event.getPlayer().getName(); + event.setQuitMessage("§c- §8| §7" + pName); + } +} diff --git a/Effekte Challenge V2/src/main/java/com/xonics/ef/main.java b/Effekte Challenge V2/src/main/java/com/xonics/ef/main.java index c6e069e..3d5baa3 100644 --- a/Effekte Challenge V2/src/main/java/com/xonics/ef/main.java +++ b/Effekte Challenge V2/src/main/java/com/xonics/ef/main.java @@ -3,6 +3,7 @@ package com.xonics.ef; import org.bukkit.plugin.java.JavaPlugin; import com.xonics.ef.managers.PluginManager; import com.xonics.ef.listeners.PlayerListener; +import com.xonics.ef.commands.TimerCommands; public class main extends JavaPlugin { @@ -23,6 +24,10 @@ public class main extends JavaPlugin { // Register listeners getServer().getPluginManager().registerEvents(new PlayerListener(), this); + // Register commands + getCommand("pause").setExecutor(new TimerCommands()); + getCommand("resume").setExecutor(new TimerCommands()); + getLogger().info("Effekte Challenge V2 has been enabled!"); } diff --git a/Effekte Challenge V2/src/main/java/com/xonics/ef/utils/Utils.java b/Effekte Challenge V2/src/main/java/com/xonics/ef/utils/Utils.java index 5b44d1e..0c9035a 100644 --- a/Effekte Challenge V2/src/main/java/com/xonics/ef/utils/Utils.java +++ b/Effekte Challenge V2/src/main/java/com/xonics/ef/utils/Utils.java @@ -15,6 +15,4 @@ public class Utils { } return ChatColor.translateAlternateColorCodes('&', msg); } - - // Add more utility methods here } \ No newline at end of file diff --git a/Effekte Challenge V2/src/main/resources/plugin.yml b/Effekte Challenge V2/src/main/resources/plugin.yml index 0125035..7c8ca16 100644 --- a/Effekte Challenge V2/src/main/resources/plugin.yml +++ b/Effekte Challenge V2/src/main/resources/plugin.yml @@ -1,5 +1,14 @@ main: com.xonics.ef.main -version: 1.0.0-SNAPSHOT +version: 12.0.1 name: Effekte author: xonics -api-version: 1.13 \ No newline at end of file +api-version: 1.13 +commands: + pause: + description: Pauses the timer + usage: /pause + permission: timer.pause + resume: + description: Resumes the timer + usage: /resume + permission: timer.resume \ No newline at end of file