diff --git a/.idea/.gitignore b/.idea/.gitignore
index 0e40fe8..5c98b42 100644
--- a/.idea/.gitignore
+++ b/.idea/.gitignore
@@ -1,3 +1,2 @@
-
# Default ignored files
/workspace.xml
\ No newline at end of file
diff --git a/.idea/.name b/.idea/.name
new file mode 100644
index 0000000..2483ffb
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+MinecraftButPlugin
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..e99fddb
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..b26911b
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 84da703..4b661a5 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,6 +1,14 @@
+
+
+
+
-
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index 869ab1f..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/MinecraftBut.iml b/MinecraftBut.iml
index f58d13a..eadd327 100644
--- a/MinecraftBut.iml
+++ b/MinecraftBut.iml
@@ -1,5 +1,5 @@
-
+
@@ -9,17 +9,29 @@
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/games/bevs/minecraftbut/MinecraftButPlugin.java b/src/main/java/games/bevs/minecraftbut/MinecraftButPlugin.java
index 1b7677f..c56f9e6 100644
--- a/src/main/java/games/bevs/minecraftbut/MinecraftButPlugin.java
+++ b/src/main/java/games/bevs/minecraftbut/MinecraftButPlugin.java
@@ -2,6 +2,7 @@
import java.lang.reflect.Field;
+import games.bevs.minecraftbut.senerario.senerarios.mathorstop.MathOrStop;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandMap;
import org.bukkit.plugin.java.JavaPlugin;
@@ -86,10 +87,12 @@ private void populateScenerarios(ButWorld butWorld)
this.scenerarioManager.registerSenerario(new LinkedHealth(butWorld));
this.scenerarioManager.registerSenerario(new ShrinkingInventory(butWorld));
this.scenerarioManager.registerSenerario(new MobsMultiple(butWorld));
+
if(minecraft18)
{
+ this.scenerarioManager.registerSenerario(new MathOrStop(butWorld));
this.scenerarioManager.registerSenerario(new AnvilRain(butWorld));
this.scenerarioManager.registerSenerario(new LinkedInventories(butWorld));
}
diff --git a/src/main/java/games/bevs/minecraftbut/senerario/senerarios/mathorstop/MathOrStop.java b/src/main/java/games/bevs/minecraftbut/senerario/senerarios/mathorstop/MathOrStop.java
new file mode 100644
index 0000000..763dc36
--- /dev/null
+++ b/src/main/java/games/bevs/minecraftbut/senerario/senerarios/mathorstop/MathOrStop.java
@@ -0,0 +1,291 @@
+package games.bevs.minecraftbut.senerario.senerarios.mathorstop;
+
+import com.google.common.collect.Lists;
+import games.bevs.minecraftbut.commons.utils.CC;
+import games.bevs.minecraftbut.commons.utils.MathUtils;
+import games.bevs.minecraftbut.senerario.Senerario;
+import games.bevs.minecraftbut.senerario.options.Optional;
+import games.bevs.minecraftbut.world.ButWorld;
+import lombok.AllArgsConstructor;
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.Sound;
+import org.bukkit.entity.Creeper;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.player.AsyncPlayerChatEvent;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.util.Vector;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+
+public class MathOrStop extends Senerario
+{
+ /**
+ * Time before question has to be answered
+ */
+ @Optional
+ private long mathSprintSeconds = 30l;
+ @Optional
+ private long secondsLeft = 0;
+
+ private int grade = 0;
+ private int questionIndex = 0;
+
+ //Grade, Questions
+ private HashMap> questions;
+
+ public MathOrStop(ButWorld butWorld)
+ {
+ super("Math or Stop", butWorld, Material.BARRIER, new String[] {"Answer the math questions or rip"}, "Sprock");
+
+ populateQuestions();
+ }
+
+ public void populateQuestions()
+ {
+ this.questions = new HashMap<>();
+
+ //generate baby grade questions
+ this.addQuestion(0, new Question("How many lines are there: ////", "4"));
+ this.addQuestion(0, new Question("How many lines are there: //////", "6"));
+ this.addQuestion(0, new Question("How many lines are there: // + ///", "5"));
+ this.addQuestion(0, new Question("How many lines are there: // - /", "1"));
+
+ //generate first grade questions
+ for(int i = 0; i < 10; i++)
+ {
+ int value1 = MathUtils.getRandom().nextInt(10);
+ int value2 = MathUtils.getRandom().nextInt(10);
+ this.addQuestion(1, new Question(value1 + " + " + value2, (value1 + value2) + ""));
+ }
+
+ //generate second grade questions
+ for(int i = 0; i < 10; i++)
+ {
+ int value1 = MathUtils.getRandom().nextInt(10);
+ int value2 = MathUtils.getRandom().nextInt(10);
+ this.addQuestion(2, new Question(value1 + " - " + value2, (value1 - value2) + ""));
+ }
+
+ //generate third grade questions
+ for(int i = 0; i < 10; i++)
+ {
+ int value1 = MathUtils.getRandom().nextInt(100);
+ int value2 = MathUtils.getRandom().nextInt(100);
+ this.addQuestion(3, new Question(value1 + " - " + value2, (value1 - value2) + ""));
+ }
+
+
+ //generate fourth grade questions
+ for(int i = 0; i < 10; i++)
+ {
+ int value1 = MathUtils.getRandom().nextInt(10);
+ int value2 = MathUtils.getRandom().nextInt(10);
+ this.addQuestion(4, new Question(value1 + " * " + value2, (value1 * value2) + ""));
+ }
+
+ //generate fith grade questions
+ this.addQuestion(5, new Question( "1 / 2", "0.5"));
+ this.addQuestion(5, new Question( "1 / 4", "0.25"));
+ this.addQuestion(5, new Question( "1 / 10", "0.1"));
+ this.addQuestion(5, new Question( "1 / 20", "0.05"));
+ this.addQuestion(5, new Question( "1 / 5", "0.2"));
+ this.addQuestion(5, new Question( "3 / 10", "0.3"));
+
+
+ //generate sixth grade questions
+ this.addQuestion(6, new Question("2^4", "16"));
+ this.addQuestion(6, new Question("5^3", "125"));
+ this.addQuestion(6, new Question("7^2", "49"));
+ this.addQuestion(6, new Question("3^2", "9"));
+ this.addQuestion(6, new Question("301^1", "301"));
+ this.addQuestion(6, new Question("25531^0", "1"));
+
+ //seven grade
+ this.addQuestion(7, new Question("2^7/2^2", "32"));
+ this.addQuestion(7, new Question("2^4/2^2", "4"));
+ this.addQuestion(7, new Question("2^1/2^2", "0.5"));
+
+ //Eight grade
+ this.addQuestion(8, new Question("6 / 2(1 + 2)", "9"));
+ this.addQuestion(8, new Question("(x + 8) / 2 = 10", "12"));
+ this.addQuestion(8, new Question("sin(pi)", "1"));
+ this.addQuestion(8, new Question("cos(pi)", "-1"));
+ this.addQuestion(8, new Question("lim(2/x + 1)", "1"));
+
+ for(int grade = 0; grade < 9; grade++)
+ {
+ shuffleGradeQuestions(grade);
+ }
+ }
+
+
+ @Override
+ protected void onStart()
+ {
+ this.secondsLeft = this.mathSprintSeconds;
+ this.questionIndex = 0;
+ this.grade = 0;
+
+ this.repeat(() -> {
+ if(this.secondsLeft == 0)
+ {
+ Bukkit.getServer().shutdown();
+ return;
+ }
+
+
+ Question question = this.getCurrentQuestion();
+ Bukkit.broadcastMessage(CC.iGray + "Teacher (" + this.secondsLeft + "): " + CC.gray + question.question);
+
+ float precentage = (float) this.secondsLeft / (float) this.mathSprintSeconds;
+
+ this.secondsLeft--;
+ }, 20l);
+ }
+
+ @Override
+ protected void onFinish()
+ {
+
+ }
+
+ private void addQuestion(int grade, Question question)
+ {
+ List questionList = this.questions.getOrDefault(grade, Lists.newArrayList());
+
+ questionList.add(question);
+
+
+ this.questions.put(grade, questionList);
+ }
+
+ public int getSizeInGrade(int grade)
+ {
+ return this.questions.get(grade).size();
+ }
+
+ private void shuffleGradeQuestions(int grade)
+ {
+ List questionList = this.questions.getOrDefault(grade, Lists.newArrayList());
+
+ Collections.shuffle(questionList);
+
+ this.questions.put(grade, questionList);
+ }
+
+ public void correct(Player player)
+ {
+ this.secondsLeft = this.mathSprintSeconds;
+ player.playSound(player.getLocation(), Sound.LEVEL_UP, 1f, 1f);
+ }
+
+ public void wrong(Player player)
+ {
+
+ int punishment = MathUtils.getRandom().nextInt(5);
+ if(punishment == 0)
+ {
+ for(int i = 0; i < 5; i++)
+ player.getWorld().spawn(player.getLocation(), Creeper.class);
+ }
+ else if(punishment == 1)
+ {
+ player.teleport(player.getLocation().add(0, -2, 0));
+ }
+ else if(punishment == 2)
+ {
+ player.setWalkSpeed(0.01f);
+ this.delay(() -> {
+ player.setWalkSpeed(0.2f);
+ }, 20l * 10l);
+ }
+ else if(punishment == 3)
+ {
+ player.getWorld().strikeLightning(player.getLocation());
+ }
+ else if(punishment == 4)
+ {
+ ItemStack dirty = new ItemStack(Material.DEAD_BUSH, 64);
+ dirty.setAmount(64);
+
+ for(int sec = 0; sec < 5; sec++)
+ this.delay(() -> {
+ for(int i = 0; i < 5; i++)
+ player.getWorld().dropItemNaturally(player.getLocation(), dirty);
+ }, 20l * sec);
+
+ }
+ else {
+ Vector vector = player.getEyeLocation().getDirection();
+
+ vector = vector.multiply(10);
+ vector.setY(2.1);
+
+ player.setVelocity(vector);
+ }
+
+ player.playSound(player.getLocation(), Sound.ANVIL_BREAK, 1f, 1f);
+ }
+
+ public Question getCurrentQuestion()
+ {
+ return this.questions.get(this.grade).get(questionIndex);
+ }
+
+ public void guessToQuestion(Player player, String guess)
+ {
+ Question question = getCurrentQuestion();
+ if(question.answer.equalsIgnoreCase(guess.trim()))
+ {
+ //correct
+ this.correct(player);
+ //Next Question
+
+ this.questionIndex++;
+ if(this.getSizeInGrade(this.grade) > this.questionIndex)
+ {
+ this.questionIndex = 0;
+ this.grade++;
+ }
+ }
+ else
+ {
+ //Wrong
+ this.wrong(player);
+ }
+ }
+
+
+ @EventHandler
+ public void onChat(AsyncPlayerChatEvent e)
+ {
+ Player player = e.getPlayer();
+ String message = e.getMessage();
+
+ //lazy
+ try
+ {
+ int value = Integer.parseInt(message);
+ this.guessToQuestion(player, message);
+ } catch(Exception ext) { }
+
+ //lazy
+ try
+ {
+ double value = Double.parseDouble(message);
+ this.guessToQuestion(player, message);
+ } catch(Exception ext) { }
+ }
+
+
+ @AllArgsConstructor
+ class Question
+ {
+ public String question;
+ public String answer;
+ }
+}