Skip to content

Commit

Permalink
Update v1.1.0-SNAPSHOT.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Klnsyf-Sun committed May 17, 2018
1 parent fe21287 commit 26fcbeb
Show file tree
Hide file tree
Showing 25 changed files with 598 additions and 53 deletions.
11 changes: 7 additions & 4 deletions src/main/java/com/klnsyf/battleroyale/commands/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.klnsyf.battleroyale.events.BattlefieldPresetEvent;
import com.klnsyf.battleroyale.events.PlayerJoinBattlefieldEvent;
import com.klnsyf.battleroyale.events.PlayerQuitBattlefieldEvent;
import com.klnsyf.battleroyale.events.PlayerRequestBattlefieldBookEvent;
import com.klnsyf.battleroyale.messages.MessageKey;
import com.klnsyf.battleroyale.messages.Messages;

Expand Down Expand Up @@ -109,15 +110,17 @@ public void preset(CommandSender sender, String[] args) {
@SubCommand(command = "join", premission = "battleroyale.join", arg = "[worldName]", des = "Join into preseted battlefield")
public void join(CommandSender sender, String[] args) {
if (sender.hasPermission("battleroyale.join")) {
if (args.length == 2) {
if (sender instanceof Player) {
if (sender instanceof Player) {
if (args.length == 1) {
server.getPluginManager().callEvent(new PlayerRequestBattlefieldBookEvent((Player) sender));
} else if (args.length == 2) {
server.getPluginManager()
.callEvent(new PlayerJoinBattlefieldEvent((Player) sender, args[1]));
} else {
sender.sendMessage("[¡ì6Battle Royale¡ìr] ¡ìcOnly Player can use this command");
sender.sendMessage("[¡ì6Battle Royale¡ìr] ¡ìcInvaild amount of arguments");
}
} else {
sender.sendMessage("[¡ì6Battle Royale¡ìr] ¡ìcInvaild amount of arguments");
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");
Expand Down
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_IGNORE_INVISIBLE("battle-misc-option.compass-option.ignore-invisible", boolean.class, true),
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,
Expand All @@ -37,7 +38,15 @@ public enum ConfigurationKey {
BATTLE_MISC_SUMMON_BLAZE_ENABLED("battle-misc-option.summon-blaze.enabled", boolean.class, true),
BATTLE_MISC_DEATHMATCH_ENABLED("battle-misc-option.deathmatch.enabled", boolean.class, true),
BATTLE_MISC_KILLER_BONUS_HEALTH("battle-misc-option.killer-bonus.health", int.class, 5),
BATTLE_MISC_KILLER_BONUS_SATURATION("battle-misc-option.killer-bonus.saturation", int.class, 5);
BATTLE_MISC_KILLER_BONUS_SATURATION("battle-misc-option.killer-bonus.saturation", int.class, 5),
BATTLE_MISC_DROP_LIST("battle-misc-option.drop-list", ArrayList.class, ConfigurationKey.DEFAULT_DROP_LIST),
BATTLE_MISC_PLAYER_GLOWING_ENABLED("battle-misc-option.player-glowing-option.enabled", boolean.class, true),
BATTLE_MISC_PLAYER_GLOWING_ITEM("battle-misc-option.player-glowing-option.activate-item", String.class, "GLOWSTONE"),
BATTLE_MISC_PLAYER_GLOWING_DURATION("battle-misc-option.player-glowing-option.duration", int.class, 20),
BATTLE_MISC_PLAYER_GLOWING_RADIUS("battle-misc-option.player-glowing-option.radius", int.class, 32),
BATTLE_MISC_PLAYER_GLOWING_IGNORE_INVISIBLE("battle-misc-option.player-glowing-option.ignore-invisible", boolean.class,
true),
;

private String path;
private Class<?> clazz;
Expand All @@ -48,19 +57,60 @@ public enum ConfigurationKey {
add(new HashMap<String, Integer>() {
private static final long serialVersionUID = 1L;
{
put("REDSTONE", 1);
put("BREAD", 4);
}
});
add(new HashMap<String, Integer>() {
private static final long serialVersionUID = 1L;
{
put("BREAD", 4);
put("BOAT", 1);
}
});
add(new HashMap<String, Integer>() {
}
};

private final static ArrayList<Map<String, ArrayList<Map<String, Integer>>>> DEFAULT_DROP_LIST = new ArrayList<Map<String, ArrayList<Map<String, Integer>>>>() {
private static final long serialVersionUID = 1L;
{
add(new HashMap<String, ArrayList<Map<String, Integer>>>() {
private static final long serialVersionUID = 1L;
{
put("BOAT", 1);
put("STONE",
new ArrayList<Map<String, Integer>>() {
private static final long serialVersionUID = 1L;
{
add(new HashMap<String, Integer>() {
private static final long serialVersionUID = 1L;
{
put("REDSTONE", 1000);
}
});
add(new HashMap<String, Integer>() {
private static final long serialVersionUID = 1L;
{
put("GLOWSTONE_DUST", 1000);
}
});
add(new HashMap<String, Integer>() {
private static final long serialVersionUID = 1L;
{
put("GLOWSTONE_DUST", 1000);
}
});
add(new HashMap<String, Integer>() {
private static final long serialVersionUID = 1L;
{
put("GLOWSTONE_DUST", 1000);
}
});
add(new HashMap<String, Integer>() {
private static final long serialVersionUID = 1L;
{
put("GLOWSTONE_DUST", 1000);
}
});
}
});
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.klnsyf.battleroyale.events;

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

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

public EntityGlowingEvent(World world, Player player) {
super(false);
this.world = world;
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 World getWorld() {
return world;
}

public Player getPlayer() {
return player;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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 PlayerOpenBattlefieldGUIEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private final Player player;

public PlayerOpenBattlefieldGUIEvent(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
@@ -0,0 +1,40 @@
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 PlayerRequestBattlefieldBookEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private final Player player;

public PlayerRequestBattlefieldBookEvent(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 @@ -2,21 +2,25 @@

import com.klnsyf.battleroyale.listeners.AnimalProtection;
import com.klnsyf.battleroyale.listeners.AutoLapis;
import com.klnsyf.battleroyale.listeners.BattleEnd;
import com.klnsyf.battleroyale.listeners.BattleLoad;
import com.klnsyf.battleroyale.listeners.BattleStart;
import com.klnsyf.battleroyale.listeners.BattlefieldPreset;
import com.klnsyf.battleroyale.listeners.BattlefieldProtect;
import com.klnsyf.battleroyale.listeners.DeathMatch;
import com.klnsyf.battleroyale.listeners.OreAutoMelt;
import com.klnsyf.battleroyale.listeners.PlayerAccelerateWorldBorderShrinking;
import com.klnsyf.battleroyale.listeners.PlayerBreakBlock;
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.EntityGlowing;
import com.klnsyf.battleroyale.listeners.PlayerSummonBlaze;
import com.klnsyf.battleroyale.listeners.PlayerThrowPrimedTnt;
import com.klnsyf.battleroyale.listeners.PlayerUseCompass;
import com.klnsyf.battleroyale.listeners.battlefieldGUI.PlayerOpenBattlefieldGUI;
import com.klnsyf.battleroyale.listeners.battlefieldGUI.PlayerRequestBattlefieldBook;
import com.klnsyf.battleroyale.listeners.system.BattleEnd;
import com.klnsyf.battleroyale.listeners.system.BattleLoad;
import com.klnsyf.battleroyale.listeners.system.BattleStart;
import com.klnsyf.battleroyale.listeners.system.BattlefieldPreset;
import com.klnsyf.battleroyale.listeners.system.BattlefieldProtect;
import com.klnsyf.battleroyale.listeners.system.PlayerJoinBattlefield;
import com.klnsyf.battleroyale.listeners.system.PlayerQuit;
import com.klnsyf.battleroyale.listeners.system.PlayerQuitBattlefield;

public class Listeners {

Expand All @@ -31,10 +35,14 @@ public void initListeners() {
new DeathMatch();
new OreAutoMelt();
new PlayerAccelerateWorldBorderShrinking();
new PlayerBreakBlock();
new PlayerDeath();
new EntityGlowing();
new PlayerJoinBattlefield();
new PlayerOpenBattlefieldGUI();
new PlayerQuit();
new PlayerQuitBattlefield();
new PlayerRequestBattlefieldBook();
new PlayerSummonBlaze();
new PlayerThrowPrimedTnt();
new PlayerUseCompass();
Expand Down
90 changes: 90 additions & 0 deletions src/main/java/com/klnsyf/battleroyale/listeners/EntityGlowing.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.klnsyf.battleroyale.listeners;

import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.Server;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;

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.EntityGlowingEvent;

public class EntityGlowing implements Listener {
private final BattleRoyale plugin = BattleRoyale.plugin;
private final Server server = BattleRoyale.server;
private final Configuration configuration = new Configuration();

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

@EventHandler
public void onPlayerGlowing(PlayerToggleSneakEvent event) {
if (BattlefieldHandler.battlefields.get(event.getPlayer().getWorld()) != null) {
if (BattlefieldHandler.battlefields.get(event.getPlayer().getWorld()).getStatue() == 2) {
if ((boolean) configuration.getValue(event.getPlayer().getWorld(),
ConfigurationKey.BATTLE_MISC_PLAYER_GLOWING_ENABLED)) {
if (event.getPlayer().getInventory().getItemInOffHand().getType() == Material
.getMaterial((String) configuration.getValue(event.getPlayer().getWorld(),
ConfigurationKey.BATTLE_MISC_PLAYER_GLOWING_ITEM))) {
if (!event.getPlayer().isSneaking()) {
new BukkitRunnable() {
@Override
public void run() {
if (!(event.getPlayer().getInventory().getItemInOffHand().getType() == Material
.getMaterial((String) configuration.getValue(event.getPlayer().getWorld(),
ConfigurationKey.BATTLE_MISC_PLAYER_GLOWING_ITEM))
&&
event.getPlayer().isSneaking())) {
this.cancel();
} else {
event.getPlayer().getInventory().getItemInOffHand()
.setAmount(event.getPlayer().getInventory().getItemInOffHand().getAmount() - 1);
server.getPluginManager().callEvent(
new EntityGlowingEvent(event.getPlayer().getWorld(), event.getPlayer()));
}
}
}.runTaskTimer(plugin, 0,
(int) configuration.getValue(event.getPlayer().getWorld(),
ConfigurationKey.BATTLE_MISC_PLAYER_GLOWING_DURATION));
}
}
}
}
}
}

@EventHandler
public void onEntityGlowing(EntityGlowingEvent event) {
event.getPlayer().getWorld().spawnParticle(Particle.SPELL_WITCH,
event.getPlayer().getLocation(), 255, 0,
event.getPlayer().getWorld().getMaxHeight()
- event.getPlayer().getLocation().getY(),
0);
for (Entity entity : event.getPlayer().getNearbyEntities(
configuration.getValue(event.getPlayer().getWorld(),
ConfigurationKey.BATTLE_MISC_PLAYER_GLOWING_RADIUS),
configuration.getValue(event.getPlayer().getWorld(),
ConfigurationKey.BATTLE_MISC_PLAYER_GLOWING_RADIUS),
configuration.getValue(event.getPlayer().getWorld(),
ConfigurationKey.BATTLE_MISC_PLAYER_GLOWING_RADIUS))) {
if (entity instanceof LivingEntity) {
((LivingEntity) entity).removePotionEffect(PotionEffectType.GLOWING);
((LivingEntity) entity).addPotionEffect(new PotionEffect(PotionEffectType.GLOWING,
(int) configuration.getValue(event.getPlayer().getWorld(),
ConfigurationKey.BATTLE_MISC_PLAYER_GLOWING_DURATION) + 1,
0, false, false));
}
}
}

}
Loading

0 comments on commit 26fcbeb

Please sign in to comment.