Initial commit
This commit is contained in:
17
Plugins/Old/Corona/src/de/craftix/corona/ActionbarAPI.java
Normal file
17
Plugins/Old/Corona/src/de/craftix/corona/ActionbarAPI.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package de.craftix.corona;
|
||||
|
||||
import net.minecraft.server.v1_8_R3.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ActionbarAPI {
|
||||
|
||||
public static void show(Player p, String content){
|
||||
IChatBaseComponent base = IChatBaseComponent.ChatSerializer.a("{\"text\": \"\"}").a(content);
|
||||
PacketPlayOutChat chat = new PacketPlayOutChat(base, (byte) 2);
|
||||
CraftPlayer cp = (CraftPlayer)p;
|
||||
cp.getHandle().playerConnection.sendPacket(chat);
|
||||
}
|
||||
|
||||
}
|
||||
82
Plugins/Old/Corona/src/de/craftix/corona/CoronaAPI.java
Normal file
82
Plugins/Old/Corona/src/de/craftix/corona/CoronaAPI.java
Normal file
@@ -0,0 +1,82 @@
|
||||
package de.craftix.corona;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
public class CoronaAPI {
|
||||
public static ArrayList<Player> coronaPlayer = new ArrayList<>();
|
||||
private static ArrayList<PotionEffectType> effects = new ArrayList<>();
|
||||
private static int timerID;
|
||||
private static int infectionTimerID;
|
||||
|
||||
public static void setup(){
|
||||
effects.add(PotionEffectType.BLINDNESS);
|
||||
effects.add(PotionEffectType.SLOW);
|
||||
effects.add(PotionEffectType.WEAKNESS);
|
||||
effects.add(PotionEffectType.CONFUSION);
|
||||
startInfectionTimer();
|
||||
}
|
||||
|
||||
public static void giveCorona(Player p){
|
||||
CoronaAPI.coronaPlayer.add(p);
|
||||
new CoronaPlayer(p);
|
||||
ActionbarAPI.show(p, "§cDu hast nun Corona!");
|
||||
}
|
||||
|
||||
public static void sendEffects(Player p){
|
||||
Random rand = new Random();
|
||||
int value = rand.nextInt(4);
|
||||
PotionEffect effect = new PotionEffect(effects.get(value), 250, 255);
|
||||
p.addPotionEffect(effect);
|
||||
}
|
||||
|
||||
public static void startTimer(){
|
||||
timerID = Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.getInstance(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player p : coronaPlayer){
|
||||
for (PotionEffect pe : p.getActivePotionEffects()){
|
||||
for (PotionEffectType corona : effects){
|
||||
if (pe.getType().equals(corona)) return;
|
||||
}
|
||||
}
|
||||
Random rand = new Random();
|
||||
if (rand.nextInt(5) < 2) continue;
|
||||
ActionbarAPI.show(p, "§cZufällige Corona attacke!");
|
||||
sendEffects(p);
|
||||
}
|
||||
}
|
||||
}, 0, 500);
|
||||
}
|
||||
|
||||
public static void stopTimer(){
|
||||
Bukkit.getScheduler().cancelTask(timerID);
|
||||
}
|
||||
|
||||
private static void startInfectionTimer(){
|
||||
infectionTimerID = Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.getInstance(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player all : Bukkit.getOnlinePlayers()){
|
||||
for (Player corona : coronaPlayer){
|
||||
if (corona == all) continue;
|
||||
if (all.getLocation().distance(corona.getLocation()) <= 2){
|
||||
CoronaAPI.coronaPlayer.add(all);
|
||||
new CoronaPlayer(all);
|
||||
ActionbarAPI.show(all, "§cDu wurdest mit Corona infiziert!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 0, 50);
|
||||
}
|
||||
|
||||
public static void stopInfectionTimer(){
|
||||
Bukkit.getScheduler().cancelTask(infectionTimerID);
|
||||
}
|
||||
}
|
||||
24
Plugins/Old/Corona/src/de/craftix/corona/CoronaPlayer.java
Normal file
24
Plugins/Old/Corona/src/de/craftix/corona/CoronaPlayer.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package de.craftix.corona;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CoronaPlayer {
|
||||
public Player p;
|
||||
private int timerID;
|
||||
public CoronaPlayer(Player p){
|
||||
this.p = p;
|
||||
startTimer();
|
||||
}
|
||||
|
||||
private void startTimer(){
|
||||
timerID = Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.getInstance(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
CoronaAPI.coronaPlayer.remove(p);
|
||||
ActionbarAPI.show(p, "§aDu hast Corona überstanden!");
|
||||
Bukkit.getScheduler().cancelTask(timerID);
|
||||
}
|
||||
}, 12000, 1);
|
||||
}
|
||||
}
|
||||
24
Plugins/Old/Corona/src/de/craftix/corona/Listener/onEat.java
Normal file
24
Plugins/Old/Corona/src/de/craftix/corona/Listener/onEat.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package de.craftix.corona.Listener;
|
||||
|
||||
import de.craftix.corona.CoronaAPI;
|
||||
import de.craftix.corona.Main;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerItemConsumeEvent;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class onEat implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onEatEvent(PlayerItemConsumeEvent event){
|
||||
if (!Main.coronaFood.contains(event.getItem().getType())) return;
|
||||
Random rand = new Random();
|
||||
if (rand.nextBoolean() && !CoronaAPI.coronaPlayer.contains(event.getPlayer())){
|
||||
Player p = event.getPlayer();
|
||||
CoronaAPI.giveCorona(p);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
46
Plugins/Old/Corona/src/de/craftix/corona/Main.java
Normal file
46
Plugins/Old/Corona/src/de/craftix/corona/Main.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package de.craftix.corona;
|
||||
|
||||
import de.craftix.corona.Listener.onEat;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Main extends JavaPlugin {
|
||||
private static Main instance;
|
||||
public static ArrayList<Material> coronaFood = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
coronaFood.add(Material.RAW_BEEF);
|
||||
coronaFood.add(Material.RAW_CHICKEN);
|
||||
coronaFood.add(Material.RAW_FISH);
|
||||
coronaFood.add(Material.PORK);
|
||||
coronaFood.add(Material.POTATO);
|
||||
coronaFood.add(Material.POISONOUS_POTATO);
|
||||
coronaFood.add(Material.RABBIT);
|
||||
coronaFood.add(Material.MUTTON);
|
||||
registerListener();
|
||||
CoronaAPI.setup();
|
||||
CoronaAPI.startTimer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
CoronaAPI.stopTimer();
|
||||
CoronaAPI.stopInfectionTimer();
|
||||
}
|
||||
|
||||
private void registerListener(){
|
||||
PluginManager pm = Bukkit.getPluginManager();
|
||||
pm.registerEvents(new onEat(), this);
|
||||
}
|
||||
|
||||
public static Main getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
4
Plugins/Old/Corona/src/plugin.yml
Normal file
4
Plugins/Old/Corona/src/plugin.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
name: Corona
|
||||
version: 1.8
|
||||
main: de.craftix.corona.Main
|
||||
author: deiner-Mudda
|
||||
Reference in New Issue
Block a user