Skip to content

Commit

Permalink
Update v1.1.0-SNAPSHOT.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Klnsyf-Sun committed Feb 11, 2018
1 parent fc3f5a6 commit 111de62
Show file tree
Hide file tree
Showing 22 changed files with 314 additions and 69 deletions.
26 changes: 23 additions & 3 deletions src/main/java/com/klnsyf/battleroyale/BattleRoyale.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang.SystemUtils;
import org.bukkit.Server;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

import com.klnsyf.battleroyale.battlefield.BattlefieldHandler;
import com.klnsyf.battleroyale.commands.Commands;
Expand All @@ -30,15 +33,32 @@ public void onEnable() {
BattleRoyale.settings = new Settings();

saveDefaultConfig();
saveResource("language\\en_US.yml", false);
saveResource("configuration\\default.yml", false);
if (!new File(dataFolder, "\\language\\en_US.yml").exists()) {
saveResource("language\\en_US.yml", false);
}
if (!new File(dataFolder, "\\configuration\\default.yml").exists()) {
saveResource("configuration\\default.yml", false);
}

if (!SystemUtils.isJavaVersionAtLeast(1.8f)) {
throw new IllegalStateException("[Battle Royale] Required Java Version is at least 1.8!");
}

final String version = getServer().getClass().getPackage().getName().replace("org.bukkit.craftbukkit.", "");
final List<String> compatible = Arrays.asList("v1_9_R1", "v1_9_R2", "v1_10_R1", "v1_11_R1", "v1_12_R1");
if (!(compatible.contains(version))) {
getServer().getPluginManager().disablePlugin(this);
throw new IllegalStateException("[Battle Royale] Required Minecraft Server Version is at least 1.9!");
}

if (Settings.isCheckUpdate) {
new UpdateChecker().checkUpdate();
new BukkitRunnable() {
@Override
public void run() {
new UpdateChecker().checkUpdate();
this.cancel();
}
}.runTaskAsynchronously(this);
}

if (!Messages.language.exists()) {
Expand Down
63 changes: 22 additions & 41 deletions src/main/java/com/klnsyf/battleroyale/commands/Commands.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
package com.klnsyf.battleroyale.commands;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;

import com.klnsyf.battleroyale.BattleRoyale;
import com.klnsyf.battleroyale.battlefield.BattlefieldHandler;
import com.klnsyf.battleroyale.configuration.Configuration;
import com.klnsyf.battleroyale.configuration.ConfigurationKey;
import com.klnsyf.battleroyale.events.BattleEndEvent;
import com.klnsyf.battleroyale.events.BattleLoadEvent;
import com.klnsyf.battleroyale.events.BattlefieldPresetEvent;
import com.klnsyf.battleroyale.events.PlayerJoinBattlefieldEvent;
import com.klnsyf.battleroyale.events.PlayerQuitBattlefieldEvent;
import com.klnsyf.battleroyale.messages.MessageKey;
import com.klnsyf.battleroyale.messages.Messages;

Expand Down Expand Up @@ -76,9 +71,9 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
return false;
}

@SubCommand(command = "preset", premission = "battleroyale.main", arg = "[worldName] [ConfigName] [maxPlayer] [autoStart]", des = "Preset a battlefield")
@SubCommand(command = "preset", premission = "battleroyale.preset", arg = "[worldName] [ConfigName] [maxPlayer] [autoStart]", des = "Preset a battlefield")
public void preset(CommandSender sender, String[] args) {
if (sender.hasPermission("battleroyale.main")) {
if (sender.hasPermission("battleroyale.preset")) {
if (args.length == 1) {
if (sender instanceof Player) {
server.getPluginManager()
Expand Down Expand Up @@ -124,13 +119,27 @@ public void join(CommandSender sender, String[] args) {
} else {
sender.sendMessage("[¡ì6Battle Royale¡ìr] ¡ìcInvaild amount of arguments");
}
} else
} else {
sender.sendMessage("[¡ì6Battle Royale¡ìr] ¡ìcYou do not have permission to use this command");
}
}

@SubCommand(command = "quit", premission = "battleroyale.quit")
public void quit(CommandSender sender, String[] args) {
if (sender.hasPermission("battleroyale.quit")) {
if (sender instanceof Player) {
server.getPluginManager().callEvent(new PlayerQuitBattlefieldEvent((Player) sender));
} else {
sender.sendMessage("[¡ì6Battle Royale¡ìr] ¡ìcOnly Player can use this command");
}
} else {
sender.sendMessage("[¡ì6Battle Royale¡ìr] ¡ìcYou do not have permission to use this command");
}
}

@SubCommand(command = "start", premission = "battleroyale.main", arg = "[worldName]", des = "Game Start!")
@SubCommand(command = "start", premission = "battleroyale.start", arg = "[worldName]", des = "Game Start!")
public void start(CommandSender sender, String[] args) {
if (sender.hasPermission("battleroyale.main")) {
if (sender.hasPermission("battleroyale.start")) {
if (args.length == 2) {
server.getPluginManager()
.callEvent(new BattleLoadEvent(sender, args[1]));
Expand All @@ -142,9 +151,9 @@ public void start(CommandSender sender, String[] args) {
}
}

@SubCommand(command = "reset", premission = "battleroyale.main", arg = "[worldName]", des = "Reset a battlefield")
@SubCommand(command = "reset", premission = "battleroyale.reset", arg = "[worldName]", des = "Reset a battlefield")
public void end(CommandSender sender, String[] args) {
if (sender.hasPermission("battleroyale.main")) {
if (sender.hasPermission("battleroyale.reset")) {
if (args.length == 2) {
server.getPluginManager()
.callEvent(new BattleEndEvent(sender, server.getWorld(args[1]), null));
Expand All @@ -156,32 +165,4 @@ public void end(CommandSender sender, String[] args) {
}
}

@SubCommand(command = "BFT", premission = "battleroyale.main", arg = "???", des = "Just a test")
public void BFT(CommandSender sender, String[] args) {
sender.sendMessage(prefix + "¡ìaBattlefields:");
for (World world : BattlefieldHandler.battlefields.keySet()) {
String statue = "¡ì7>> ¡ìb" + world.getName() + "(" + BattlefieldHandler.battlefields.get(world).getMaxPlayer() + "/"
+ BattlefieldHandler.battlefields.get(world).isAutoStart() + ")" + " ¡ì3> ¡ìd";
for (Player player : BattlefieldHandler.battlefields.get(world).players) {
statue = statue + "[" + player.getName() + "] ";
}
sender.sendMessage(statue);
}
}

@SubCommand(command = "CFG", premission = "battleroyale.main", arg = "???", des = "Just a test")
public void CFT(CommandSender sender, String[] args) {
new YamlConfiguration();
sender.sendMessage(new Configuration().getValue(
YamlConfiguration
.loadConfiguration(new File(BattleRoyale.dataFolder.getPath() + "\\configuration\\default.yml")),
ConfigurationKey.BATTLE_MISC_INIT_SUPPLY) + ", "
+ new Configuration().getValue(
YamlConfiguration
.loadConfiguration(
new File(BattleRoyale.dataFolder.getPath() + "\\configuration\\default.yml")),
ConfigurationKey.BATTLE_MISC_INIT_SUPPLY).getClass());

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public enum ConfigurationKey {
BATTLE_MISC_COMPASS_ENABLED("battle-misc-option.compass-option.enabled", boolean.class, true),
BATTLE_MISC_COMPASS_MODE("battle-misc-option.compass-option.mode", boolean.class, true),
BATTLE_MISC_COMPASS_COOLDOWN("battle-misc-option.compass-option.cooldown", int.class, 100),
BATTLE_MISC_COMPASS_MAX_SHOWN_PLAYER("battle-misc-option.compass-option.max-shown-player", int.class, 4),
BATTLE_MISC_SHRINK_ACCELERATING_ENABLED("battle-misc-option.shrink-accelerating-option.enabled", boolean.class, true),
BATTLE_MISC_SHRINK_ACCELERATING_ITEM("battle-misc-option.shrink-accelerating-option.active-item", String.class,
"IRON_BLOCK"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.bukkit.event.HandlerList;

public class PlayerJoinBattlefieldEvent extends Event implements Cancellable {

private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private final Player player;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.klnsyf.battleroyale.events;

import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;

public class PlayerQuitBattlefieldEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private final Player player;

public PlayerQuitBattlefieldEvent(Player player) {
super(false);
this.player = player;
}

@Override
public boolean isCancelled() {
return cancelled;
}

@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}

@Override
public HandlerList getHandlers() {
return handlers;
}

public static HandlerList getHandlerList() {
return handlers;
}

public Player getPlayer() {
return player;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.klnsyf.battleroyale.listeners.PlayerDeath;
import com.klnsyf.battleroyale.listeners.PlayerJoinBattlefield;
import com.klnsyf.battleroyale.listeners.PlayerQuit;
import com.klnsyf.battleroyale.listeners.PlayerQuitBattlefield;
import com.klnsyf.battleroyale.listeners.PlayerSummonBlaze;
import com.klnsyf.battleroyale.listeners.PlayerThrowPrimedTnt;
import com.klnsyf.battleroyale.listeners.PlayerUseCompass;
Expand All @@ -33,6 +34,7 @@ public void initListeners() {
new PlayerDeath();
new PlayerJoinBattlefield();
new PlayerQuit();
new PlayerQuitBattlefield();
new PlayerSummonBlaze();
new PlayerThrowPrimedTnt();
new PlayerUseCompass();
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/klnsyf/battleroyale/listeners/BattleLoad.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,29 +112,29 @@ private void countDown(World world) {
new BukkitRunnable() {

final int totalTime = configuation.getValue(world, ConfigurationKey.BATTLE_MISC_LOADING_TIME);
final int block = 15;
final int block = 64;
final double totalTick = 20 * totalTime;
double tick = totalTick;

public void run() {
if (BattlefieldHandler.battlefields.get(world) == null) {
this.cancel();
}
String s = Messages.getMessage(MessageKey.EVENTS_BATTLE_START);
String s = Messages.getMessage(MessageKey.EVENTS_BATTLE_START)+" ";

double i = block;
for (; i > Math.round(block * tick / totalTick); i--) {
s = s + "¡ì4¨€";
s = s + "§4§l│";
}
for (i = Math.round(block * tick / totalTick); i > 0; i--) {
s = s + "¡ìa¨€";
s = s + "§a§l│";
}
s = s + " ¡ìr" + new DecimalFormat("0.0").format(tick * totalTime / totalTick) + " "
s = s + " §r" + new DecimalFormat("0.0").format(tick * totalTime / totalTick) + " "
+ Messages.getMessage(MessageKey.EVENTS_SECOND);
new ActionbarMessage().sendActionbarMessage(player, s);
if (tick <= 10 * 20 && tick % 20 == 0) {
player.playEffect(player.getLocation(), Effect.CLICK1, null);
player.sendTitle("[¡ì6Battle Royale¡ìr]", "-= " + (int) (tick / 20) + " =-", 0, 200,
player.sendTitle("[§6Battle Royale§r]", "-= " + (int) (tick / 20) + " =-", 0, 200,
0);
}
player.spawnParticle(Particle.SPELL_WITCH, player.getLocation(), 255, 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.bukkit.Server;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
Expand All @@ -28,7 +29,7 @@ public void onBlockBreak(BlockBreakEvent event) {
}
}

@EventHandler
@EventHandler(priority = EventPriority.HIGH)
public void onEntityDamage(EntityDamageEvent event) {
if (BattlefieldHandler.battlefields.get(event.getEntity().getWorld()) != null) {
if (BattlefieldHandler.battlefields.get(event.getEntity().getWorld()).getStatue() != 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import com.klnsyf.battleroyale.BattleRoyale;
import com.klnsyf.battleroyale.battlefield.BattlefieldHandler;
import com.klnsyf.battleroyale.configuration.Configuration;
Expand Down Expand Up @@ -59,15 +58,15 @@ public void onPlayerDeath(PlayerDeathEvent event) {
}
new AutoRespawnSetup().getAutoRespawn().autoRespawn(event.getEntity(), event.getEntity().getLocation());
BattlefieldHandler.battlefields.get(event.getEntity().getWorld()).alivePlayers.remove(event.getEntity());
if (BattlefieldHandler.battlefields.get(event.getEntity().getWorld()).players.size() == 1) {
if (BattlefieldHandler.battlefields.get(event.getEntity().getWorld()).alivePlayers.size() == 1) {
server.getPluginManager()
.callEvent(new BattleEndEvent(server.getConsoleSender(), event.getEntity().getWorld(),
BattlefieldHandler.battlefields.get(event.getEntity().getWorld()).players.get(0)));
}
if (BattlefieldHandler.battlefields.get(event.getEntity().getWorld()).players.size() < 1) {
BattlefieldHandler.battlefields.get(event.getEntity().getWorld()).alivePlayers.get(0)));
} else if (BattlefieldHandler.battlefields.get(event.getEntity().getWorld()).alivePlayers.size() < 1) {
server.getPluginManager()
.callEvent(new BattleEndEvent(server.getConsoleSender(), event.getEntity().getWorld(),
null));

}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.klnsyf.battleroyale.listeners;

import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

import com.klnsyf.battleroyale.BattleRoyale;
import com.klnsyf.battleroyale.battlefield.BattlefieldHandler;
import com.klnsyf.battleroyale.events.PlayerQuitBattlefieldEvent;
import com.klnsyf.battleroyale.messages.MessageKey;
import com.klnsyf.battleroyale.messages.Messages;

public class PlayerQuitBattlefield implements Listener {
private final BattleRoyale plugin = BattleRoyale.plugin;
private final Server server = BattleRoyale.server;
private final String prefix = BattleRoyale.prefix;

public PlayerQuitBattlefield() {
server.getPluginManager().registerEvents(this, plugin);
}

@EventHandler
public void onPlayerQuitBattlefield(PlayerQuitBattlefieldEvent event) {
if (BattlefieldHandler.battlefields.get(event.getPlayer().getWorld()) != null) {
server.getConsoleSender().sendMessage(prefix
+ Messages.getMessage(MessageKey.PLAYER_QUIT_BATTLEFIELD_SUCCESS, event.getPlayer().getName(),
event.getPlayer().getWorld().getName()));
for (Player player : BattlefieldHandler.battlefields.get(event.getPlayer().getWorld()).players) {
player.sendMessage(prefix
+ Messages.getMessage(MessageKey.PLAYER_QUIT_BATTLEFIELD_SUCCESS, event.getPlayer().getName(),
event.getPlayer().getWorld().getName()));
}
BattlefieldHandler.battlefields.get(event.getPlayer().getWorld()).players.remove(event.getPlayer());
if (BattlefieldHandler.battlefields.get(event.getPlayer().getWorld()).alivePlayers.contains(event.getPlayer())) {
event.getPlayer().damage(11037);
}
}
}
}
Loading

0 comments on commit 111de62

Please sign in to comment.