Skip to content

Commit

Permalink
Arena settings, V1.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Misat11 committed Jan 12, 2017
1 parent 57c6d51 commit 3707737
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 68 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>misat11.za</groupId>
<artifactId>ZombieApocalypse</artifactId>
<version>1.0.5</version>
<version>1.0.7</version>

<repositories>
<repository>
Expand Down
55 changes: 23 additions & 32 deletions src/main/java/misat11/za/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.io.File;
import java.io.IOException;
import java.util.Set;

import org.bukkit.Bukkit;
import org.bukkit.Location;
Expand All @@ -35,7 +36,7 @@ public class Main extends JavaPlugin {

public void onEnable() {
instance = this;
version = "1.0.5";
version = "1.0.7";

createFiles();

Expand All @@ -61,11 +62,8 @@ public void onEnable() {
this.getConfig().set("help_phaseinfo",
"Display actual phase, countdown to end of phase and day after phase");
}
if (this.getConfig().isSet("help_setpos1") == false) {
this.getConfig().set("help_setpos1", "Admin Command: set arena pos 1");
}
if (this.getConfig().isSet("help_setpos2") == false) {
this.getConfig().set("help_setpos2", "Admin Command: set arena pos 2");
if (this.getConfig().isSet("help_arena") == false) {
this.getConfig().set("help_arena", "Admin Command: Settings of location where i'm putting zombies :)");
}
if (this.getConfig().isSet("help_setspawnloc") == false) {
this.getConfig().set("help_setspawnloc", "Admin Command: set spawn location");
Expand Down Expand Up @@ -115,18 +113,6 @@ public void onEnable() {
if (this.getConfig().isSet("giant_pitch") == false) {
this.getConfig().set("giant_pitch", 0);
}
if (this.getConfig().isSet("arena_pos1_x") == false) {
this.getConfig().set("arena_pos1_x", 0);
}
if (this.getConfig().isSet("arena_pos1_z") == false) {
this.getConfig().set("arena_pos1_z", 0);
}
if (this.getConfig().isSet("arena_pos2_x") == false) {
this.getConfig().set("arena_pos2_x", 0);
}
if (this.getConfig().isSet("arena_pos2_z") == false) {
this.getConfig().set("arena_pos2_z", 0);
}
if (this.getConfig().isSet("zombies_spawn_countdown") == false) {
this.getConfig().set("zombies_spawn_countdown", 10);
}
Expand Down Expand Up @@ -287,20 +273,25 @@ public void run() {
getSaveConfig().set("SERVER.ARENA.countdown",
getSaveConfig().getInt("SERVER.ARENA.countdown") - 1);
zaworld.setTime(20000);
if (getSaveConfig().getInt("SERVER.ARENA.countdown")
% getConfig().getInt("zombies_spawn_countdown") < 1) {
int zombie_x = (int) (Math.random() * (Math
.abs(getConfig().getInt("arena_pos1_x") - getConfig().getInt("arena_pos2_x"))))
+ Math.min(getConfig().getInt("arena_pos1_x"),
getConfig().getInt("arena_pos2_x"));
int zombie_z = (int) (Math.random() * (Math
.abs(getConfig().getInt("arena_pos1_z") - getConfig().getInt("arena_pos2_z"))))
+ Math.min(getConfig().getInt("arena_pos1_z"),
getConfig().getInt("arena_pos2_z"));
int zombie_y = (int) zaworld.getHighestBlockYAt(zombie_x, zombie_z);
Location zombie_location = new Location(zaworld, zombie_x, zombie_y, zombie_z);
Bukkit.getWorld(getConfig().getString("world")).spawnEntity(zombie_location,
EntityType.ZOMBIE);
if (getConfig().isSet("arena_settings")) {
Set<String> arena_settings = getConfig().getConfigurationSection("arena_settings").getKeys(false);
for (String arena_setting : arena_settings) {
if (getSaveConfig().getInt("SERVER.ARENA.countdown")
% getConfig().getInt("arena_settings." + arena_setting + ".countdown") < 1) {
int zombie_x = (int) (Math.random() * (Math.abs(
getConfig().getInt("arena_settings." + arena_setting + ".pos1_x") - getConfig().getInt("arena_settings." + arena_setting + ".pos2_x"))))
+ Math.min((getConfig().getInt("arena_settings." + arena_setting + ".pos1_x")),
getConfig().getInt("arena_settings." + arena_setting + ".pos2_x"));
int zombie_z = (int) (Math.random() * (Math.abs(
getConfig().getInt("arena_settings." + arena_setting + ".pos1_z") - getConfig().getInt("arena_settings." + arena_setting + ".pos2_z"))))
+ Math.min(getConfig().getInt("arena_settings." + arena_setting + ".pos1_z"),
getConfig().getInt("arena_settings." + arena_setting + ".pos2_z"));
int zombie_y = (int) zaworld.getHighestBlockYAt(zombie_x, zombie_z);
Location zombie_location = new Location(zaworld, zombie_x, zombie_y, zombie_z);
Bukkit.getWorld(getConfig().getString("world")).spawnEntity(zombie_location,
EntityType.ZOMBIE);
}
}
}
if (getSaveConfig().getInt("SERVER.ARENA.phase") > 4
&& getConfig().getBoolean("spawn_giant") == true) {
Expand Down
147 changes: 120 additions & 27 deletions src/main/java/misat11/za/commands/ZaCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
if (args.length > 0) {
if (args[0].equalsIgnoreCase("gift")) {
if (Main.instance.getConfig().getBoolean("enabled") == true) {
if (Main.instance.getConfig().getBoolean("enabled") == true) {
if (Main.instance.getSaveConfig().isSet(player.getName() + ".play") == false) {
Main.instance.getSaveConfig().set(player.getName() + ".play", true);
Main.instance.getSaveConfig().set(player.getName() + ".play.points", 100);
Main.instance.getSaveConfig().set(player.getName() + ".play.gift",
new SimpleDateFormat("yyyyMMdd").format(Calendar.getInstance().getTime()));
try {
Main.instance.getSaveConfig().save(Main.instance.savef);
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (player.getWorld() == zaworld) {
String time = new SimpleDateFormat("yyyyMMdd").format(Calendar.getInstance().getTime());
if (Main.instance.getSaveConfig().getString(player.getName() + ".play.gift").equals(time)) {
Expand Down Expand Up @@ -230,31 +243,111 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
} else {
sender.sendMessage("You have not any permissions!");
}
} else if (args[0].equalsIgnoreCase("setpos1")) {
} else if (args[0].equalsIgnoreCase("arena")) {
if (player.hasPermission("misat11.za.admin")) {
Location playerloc = player.getLocation();
Main.instance.getConfig().set("arena_pos1_x", playerloc.getBlockX());
Main.instance.getConfig().set("arena_pos1_z", playerloc.getBlockZ());
try {
Main.instance.getConfig().save(Main.instance.configf);
} catch (IOException e) {
e.printStackTrace();
}
sender.sendMessage("Arena pos 1 set.");
} else {
sender.sendMessage("You have not any permissions!");
}
} else if (args[0].equalsIgnoreCase("setpos2")) {
if (player.hasPermission("misat11.za.admin")) {
Location playerloc = player.getLocation();
Main.instance.getConfig().set("arena_pos2_x", playerloc.getBlockX());
Main.instance.getConfig().set("arena_pos2_z", playerloc.getBlockZ());
try {
Main.instance.getConfig().save(Main.instance.configf);
} catch (IOException e) {
e.printStackTrace();
if (player.getWorld() == zaworld) {
if (args.length > 1) {
if (args[1].equalsIgnoreCase("pos1")) {
if (args.length == 3) {
if (Main.instance.getConfig()
.isSet("arena_settings." + args[2].toString()) == false) {
Main.instance.getConfig()
.set("arena_settings." + args[2].toString() + ".pos1_x", 0);
Main.instance.getConfig()
.set("arena_settings." + args[2].toString() + ".pos1_z", 0);
Main.instance.getConfig()
.set("arena_settings." + args[2].toString() + ".pos2_x", 0);
Main.instance.getConfig()
.set("arena_settings." + args[2].toString() + ".pos2_z", 0);
Main.instance.getConfig()
.set("arena_settings." + args[2].toString() + ".countdown", 10);
}

Location ploc = player.getLocation();
Main.instance.getConfig().set(
"arena_settings." + args[2].toString() + ".pos1_x", ploc.getBlockX());
Main.instance.getConfig().set(
"arena_settings." + args[2].toString() + ".pos1_z", ploc.getBlockZ());

sender.sendMessage("Arena pos 1 set.");
} else {
sender.sendMessage("Too many arguments.");
}
} else if (args[1].equalsIgnoreCase("pos2")) {
if (args.length == 3) {
if (Main.instance.getConfig()
.isSet("arena_settings." + args[2].toString()) == false) {
Main.instance.getConfig()
.set("arena_settings." + args[2].toString() + ".pos1_x", 0);
Main.instance.getConfig()
.set("arena_settings." + args[2].toString() + ".pos1_z", 0);
Main.instance.getConfig()
.set("arena_settings." + args[2].toString() + ".pos2_x", 0);
Main.instance.getConfig()
.set("arena_settings." + args[2].toString() + ".pos2_z", 0);
Main.instance.getConfig()
.set("arena_settings." + args[2].toString() + ".countdown", 10);
}

Location ploc = player.getLocation();
Main.instance.getConfig().set(
"arena_settings." + args[2].toString() + ".pos2_x", ploc.getBlockX());
Main.instance.getConfig().set(
"arena_settings." + args[2].toString() + ".pos2_z", ploc.getBlockZ());

sender.sendMessage("Arena pos 2 set.");
} else {
sender.sendMessage("Too many arguments.");
}
} else if (args[1].equalsIgnoreCase("countdown")) {
if (args.length == 4) {
if (Main.instance.getConfig()
.isSet("arena_settings." + args[2].toString()) == false) {
Main.instance.getConfig()
.set("arena_settings." + args[2].toString() + ".pos1_x", 0);
Main.instance.getConfig()
.set("arena_settings." + args[2].toString() + ".pos1_z", 0);
Main.instance.getConfig()
.set("arena_settings." + args[2].toString() + ".pos2_x", 0);
Main.instance.getConfig()
.set("arena_settings." + args[2].toString() + ".pos2_z", 0);
Main.instance.getConfig()
.set("arena_settings." + args[2].toString() + ".countdown", 10);
}

Main.instance.getConfig().set(
"arena_settings." + args[2].toString() + ".countdown",
Integer.parseInt(args[3]));

sender.sendMessage("Countdown set.");
} else {
sender.sendMessage("Too many arguments.");
}
} else if (args[1].equalsIgnoreCase("delete")) {
if (args.length == 3) {
if (Main.instance.getConfig()
.isSet("arena_settings." + args[2].toString()) == true) {
Main.instance.getConfig().set("arena_settings." + args[2].toString(), null);
}

sender.sendMessage("Customize arena removed.");
} else {
sender.sendMessage("Too many arguments.");
}
} else {
sender.sendMessage("Too many arguments.");
}
} else {
sender.sendMessage("Too many arguments.");
}
try {
Main.instance.getConfig().save(Main.instance.configf);
} catch (IOException e) {
e.printStackTrace();
}
} else {
sender.sendMessage("You aren't in world where is set /za setspawnloc");
}
sender.sendMessage("Arena pos 2 set.");
} else {
sender.sendMessage("You have not any permissions!");
}
Expand Down Expand Up @@ -306,8 +399,8 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
sender.sendMessage("/za enablegame - " + Main.instance.getConfig().getString("help_enablegame"));
sender.sendMessage(
"/za enablegiantgame - " + Main.instance.getConfig().getString("help_enablegiantgame"));
sender.sendMessage("/za setpos1 - " + Main.instance.getConfig().getString("help_setpos1"));
sender.sendMessage("/za setpos2 - " + Main.instance.getConfig().getString("help_setpos2"));
sender.sendMessage("/za arena <pos1|pos2|countdown|delete> - "
+ Main.instance.getConfig().getString("help_arena"));
}
} else {
sender.sendMessage("ZombieApocalypse V" + Main.version + " by Misat11");
Expand All @@ -322,8 +415,8 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
sender.sendMessage("/za enablegame - " + Main.instance.getConfig().getString("help_enablegame"));
sender.sendMessage(
"/za enablegiantgame - " + Main.instance.getConfig().getString("help_enablegiantgame"));
sender.sendMessage("/za setpos1 - " + Main.instance.getConfig().getString("help_setpos1"));
sender.sendMessage("/za setpos2 - " + Main.instance.getConfig().getString("help_setpos2"));
sender.sendMessage("/za arena <pos1|pos2|countdown|delete> - "
+ Main.instance.getConfig().getString("help_arena"));
}
} else {
sender.sendMessage("It's only for players!");
Expand Down
9 changes: 2 additions & 7 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ giant_y: 60
giant_z: 0
giant_yaw: 0
giant_pitch: 0
arena_pos1_x: 0
arena_pos1_z: 0
arena_pos2_x: 0
arena_pos2_z: 0
zombies_spawn_countdown: 10
arena_settings: []
message_prefix: "[ZA]"
message_phase_night: "It's night of phase %phase%. Remaining until the end: %countdown%"
message_phase_day: "It's day after phase %phase%. Remaining until the end: %countdown%"
Expand Down Expand Up @@ -48,7 +44,6 @@ help_gift: "Get daily gift to you"
help_phaseinfo: "Display actual phase, countdown to end of phase and day after phase"
help_setspawnloc: "Admin Command: set spawn location"
help_setgiantloc: "Admin Command: set giant location"
help_setpos1: "Admin Command: set arena pos 1"
help_setpos2: "Admin Command: set arena pos 2"
help_arena: "Admin Command: Settings of location where i'm putting zombies :)"
help_enablegame: "Admin Command: enable/disable game"
help_enablegiantgame: "Admin Command: enable/disable spawning giants"
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: ZombieApocalypse
main: misat11.za.Main
version: 1.0.5
version: 1.0.7
author: Misat11

commands:
Expand Down

0 comments on commit 3707737

Please sign in to comment.