Update1.0 #11
@ -29,7 +29,10 @@ import java.io.File;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Config {
|
||||
private Config(){}
|
||||
|
||||
private Config() {
|
||||
|
||||
}
|
||||
|
||||
public static final int ArenaMinX;
|
||||
public static final int ArenaMaxX;
|
||||
@ -51,9 +54,9 @@ public class Config {
|
||||
public static final int MissileCount;
|
||||
public static final double MissileChance;
|
||||
|
||||
static{
|
||||
static {
|
||||
File configfile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "config.yml");
|
||||
if(!configfile.exists()){
|
||||
if (!configfile.exists()) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Config fehlt!");
|
||||
Bukkit.shutdown();
|
||||
}
|
||||
|
@ -32,19 +32,21 @@ import java.util.Objects;
|
||||
*/
|
||||
class FightScoreboard {
|
||||
|
||||
private FightScoreboard(){}
|
||||
private FightScoreboard() {
|
||||
|
||||
}
|
||||
|
||||
private static final Scoreboard scoreboard = Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard();
|
||||
private static final Objective objective;
|
||||
|
||||
static{
|
||||
if(scoreboard.getObjective("AAA") == null)
|
||||
static {
|
||||
if (scoreboard.getObjective("AAA") == null)
|
||||
objective = scoreboard.registerNewObjective("AAA", "BBB", "MissleWars");
|
||||
else
|
||||
objective = scoreboard.getObjective("AAA");
|
||||
}
|
||||
|
||||
static void init(){
|
||||
static void init() {
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(MissileWars.getPlugin(), () -> {
|
||||
objective.unregister();
|
||||
scoreboard.registerNewObjective("AAA", "BBB", "MissleWars");
|
||||
@ -63,7 +65,7 @@ class FightScoreboard {
|
||||
return scoreboard;
|
||||
}
|
||||
|
||||
private static void teamScoreboard(MWTeam fightTeam){
|
||||
private static void teamScoreboard(MWTeam fightTeam) {
|
||||
fightTeam.getPlayers().forEach(p -> objective.getScore(fightTeam.getPrefix() + p.getName()).setScore(1));
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ public class MWTeam {
|
||||
|
||||
private Set<Player> players = new HashSet<>();
|
||||
|
||||
public Set<Player> getPlayers(){
|
||||
public Set<Player> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ public class MWTeam {
|
||||
return portalZ;
|
||||
}
|
||||
|
||||
public Location getSpawn(){
|
||||
public Location getSpawn() {
|
||||
return spawn;
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ public class MWTeam {
|
||||
return MissileWars.getRedTeam();
|
||||
}
|
||||
|
||||
public String getPrefix(){
|
||||
public String getPrefix() {
|
||||
return "§" + color.getChar();
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,6 @@ public class MissileWars extends JavaPlugin {
|
||||
new WaitingListener();
|
||||
new FightListener();
|
||||
new ChatListener();
|
||||
new GamemodeListener();
|
||||
getCommand("spectate").setExecutor(new CommandSpectate());
|
||||
|
||||
new WaitingCountdown();
|
||||
|
@ -37,7 +37,7 @@ public class SpawnPlatformCreator {
|
||||
private Block currentBlock;
|
||||
private int ticks;
|
||||
|
||||
public SpawnPlatformCreator(Player player){
|
||||
public SpawnPlatformCreator(Player player) {
|
||||
this.player = player;
|
||||
MWTeam team = MissileWars.getTeam(player);
|
||||
if(team == null)
|
||||
@ -49,31 +49,31 @@ public class SpawnPlatformCreator {
|
||||
task = Bukkit.getScheduler().runTaskTimer(MissileWars.getPlugin(), this::createPlatform, 0, 1);
|
||||
}
|
||||
|
||||
private void createPlatform(){
|
||||
private void createPlatform() {
|
||||
Location playerLoc = player.getLocation();
|
||||
playerLoc.setY(spawn.getY() - 1);
|
||||
|
||||
if(currentBlock == null || !currentBlock.getLocation().equals(playerLoc)){
|
||||
if(currentBlock != null){
|
||||
if(currentBlock.getType() == Material.OBSIDIAN)
|
||||
if (currentBlock == null || !currentBlock.getLocation().equals(playerLoc)) {
|
||||
if (currentBlock != null) {
|
||||
if (currentBlock.getType() == Material.OBSIDIAN)
|
||||
currentBlock.setType(Material.AIR);
|
||||
currentBlock = null;
|
||||
}
|
||||
|
||||
Block newBlock = playerLoc.getBlock();
|
||||
if(newBlock.getType() == Material.AIR){
|
||||
if (newBlock.getType() == Material.AIR) {
|
||||
newBlock.setType(Material.OBSIDIAN);
|
||||
currentBlock = newBlock;
|
||||
}
|
||||
}
|
||||
|
||||
if(currentBlock != null && player.getLocation().getY() - 1 < currentBlock.getY())
|
||||
if (currentBlock != null && player.getLocation().getY() - 1 < currentBlock.getY())
|
||||
player.teleport(playerLoc.add(0, 1, 0));
|
||||
|
||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("Spawnplattform§8: §c§l" + String.format("%.2f", ticks / 20f) + "§8s"));
|
||||
|
||||
if(ticks == 0){
|
||||
if(currentBlock != null && currentBlock.getType() == Material.OBSIDIAN)
|
||||
if (ticks == 0) {
|
||||
if (currentBlock != null && currentBlock.getType() == Material.OBSIDIAN)
|
||||
currentBlock.setType(Material.AIR);
|
||||
|
||||
task.cancel();
|
||||
|
@ -28,7 +28,7 @@ public abstract class StateDependent {
|
||||
private final Set<FightState> active;
|
||||
private boolean running;
|
||||
|
||||
public StateDependent(final Set<FightState> active){
|
||||
public StateDependent(final Set<FightState> active) {
|
||||
this.active = active;
|
||||
running = false;
|
||||
listeners.add(this);
|
||||
@ -37,12 +37,12 @@ public abstract class StateDependent {
|
||||
public abstract void enable();
|
||||
public abstract void disable();
|
||||
|
||||
static void setupState(FightState state){
|
||||
for(StateDependent listener : listeners){
|
||||
if(listener.running && !listener.active.contains(state)){
|
||||
static void setupState(FightState state) {
|
||||
for (StateDependent listener : listeners) {
|
||||
if (listener.running && !listener.active.contains(state)) {
|
||||
listener.disable();
|
||||
listener.running = false;
|
||||
}else if(!listener.running && listener.active.contains(state)){
|
||||
} else if (!listener.running && listener.active.contains(state)) {
|
||||
listener.enable();
|
||||
listener.running = true;
|
||||
}
|
||||
|
@ -42,9 +42,9 @@ public class EndCountdown extends StateDependent {
|
||||
}
|
||||
|
||||
private void kickPlayer(){
|
||||
if(Bukkit.getOnlinePlayers().isEmpty()){
|
||||
if (Bukkit.getOnlinePlayers().isEmpty()) {
|
||||
Bukkit.shutdown();
|
||||
}else{
|
||||
} else {
|
||||
Bukkit.getOnlinePlayers().iterator().next().kickPlayer(null);
|
||||
task = Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), this::kickPlayer, 10);
|
||||
}
|
||||
@ -52,7 +52,6 @@ public class EndCountdown extends StateDependent {
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
if(task != null && !task.isCancelled())
|
||||
task.cancel();
|
||||
if (task != null && !task.isCancelled()) task.cancel();
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ public class ItemCountdown extends StateDependent {
|
||||
super(EnumSet.of(FightState.FIGHTING));
|
||||
}
|
||||
|
||||
private void run(){
|
||||
private void run() {
|
||||
List<Player> blue = new ArrayList<>(MissileWars.getBlueTeam().getPlayers());
|
||||
List<Player> red = new ArrayList<>(MissileWars.getBlueTeam().getPlayers());
|
||||
|
||||
@ -87,7 +87,7 @@ public class ItemCountdown extends StateDependent {
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
if(task != null && !task.isCancelled())
|
||||
task.cancel();
|
||||
if (task != null && !task.isCancelled()) task.cancel();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,4 +36,5 @@ public class Arrows extends SpecialItem {
|
||||
public boolean handleUse(Player p) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -44,4 +44,5 @@ public class Fireball extends SpecialItem {
|
||||
fb.setYield(3f);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -76,4 +76,5 @@ public class LandingPad extends SpecialItem {
|
||||
editSession.flushSession();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,4 +36,5 @@ public class Mine extends SpecialItem {
|
||||
public boolean handleUse(Player p) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -92,24 +92,24 @@ public class Missile extends SpecialItem {
|
||||
private void lore(List<String> lore, String[] args, int index, String tag) {
|
||||
if (args.length > index) {
|
||||
try {
|
||||
lore.add(graph(Integer.parseInt(args[index]), GRAPH_SIZE) + tag);
|
||||
lore.add(graph(Integer.parseInt(args[index])) + tag);
|
||||
return;
|
||||
} catch (NumberFormatException e) {
|
||||
// Ignored
|
||||
}
|
||||
}
|
||||
lore.add(graph(0, GRAPH_SIZE) + tag);
|
||||
lore.add(graph(0) + tag);
|
||||
}
|
||||
|
||||
private String graph(int index, int size) {
|
||||
if (index > size) index = size;
|
||||
private String graph(int index) {
|
||||
if (index > Missile.GRAPH_SIZE) index = Missile.GRAPH_SIZE;
|
||||
StringBuilder st = new StringBuilder();
|
||||
st.append("§8[§e");
|
||||
if (index > 0) {
|
||||
st.append(repeat(index));
|
||||
}
|
||||
st.append("§7");
|
||||
st.append(repeat(size - index));
|
||||
st.append(repeat(Missile.GRAPH_SIZE - index));
|
||||
st.append("§8]");
|
||||
return st.toString();
|
||||
}
|
||||
@ -130,12 +130,12 @@ public class Missile extends SpecialItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(){
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleUse(Player p){
|
||||
public boolean handleUse(Player p) {
|
||||
BlockVector3 dimensions = clipboard.getDimensions();
|
||||
Location location = p.getLocation();
|
||||
BlockVector3 v = BlockVector3.ZERO;
|
||||
@ -168,7 +168,7 @@ public class Missile extends SpecialItem {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void init(){
|
||||
public static void init() {
|
||||
File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "default-missiles");
|
||||
if (!missileFolder.exists() || !missileFolder.canRead() || !missileFolder.isDirectory()) {
|
||||
throw new SecurityException("Missiles could not be loaded");
|
||||
|
@ -36,4 +36,5 @@ public class Shield extends SpecialItem {
|
||||
public boolean handleUse(Player p) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -48,42 +48,37 @@ public class ArenaListener extends BasicListener {
|
||||
Player p = e.getPlayer();
|
||||
|
||||
assert location != null;
|
||||
if(location.getY() < Config.ArenaMinY){
|
||||
if(p.getGameMode() == GameMode.SPECTATOR)
|
||||
if (location.getY() < Config.ArenaMinY) {
|
||||
if (p.getGameMode() == GameMode.SPECTATOR)
|
||||
p.teleport(e.getFrom());
|
||||
else if(MissileWars.getFightState() == FightState.WAITING)
|
||||
else if (MissileWars.getFightState() == FightState.WAITING)
|
||||
p.teleport(Objects.requireNonNull(MissileWars.getTeam(p)).getSpawn());
|
||||
else
|
||||
p.damage(20.0f);
|
||||
}else if(
|
||||
location.getX() < Config.ArenaMinX ||
|
||||
location.getX() > Config.ArenaMaxX ||
|
||||
location.getZ() < Config.ArenaMinZ ||
|
||||
location.getZ() > Config.ArenaMaxZ){
|
||||
} else if (location.getX() < Config.ArenaMinX || location.getX() > Config.ArenaMaxX || location.getZ() < Config.ArenaMinZ || location.getZ() > Config.ArenaMaxZ) {
|
||||
p.teleport(e.getFrom());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onArrowPickup(PlayerPickupArrowEvent e){
|
||||
public void onArrowPickup(PlayerPickupArrowEvent e) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onItemDrop(PlayerDropItemEvent e){
|
||||
public void onItemDrop(PlayerDropItemEvent e) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onHunger(FoodLevelChangeEvent e){
|
||||
public void onHunger(FoodLevelChangeEvent e) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onInventoryOpen(InventoryOpenEvent event) {
|
||||
if(event.getView().getType() != InventoryType.PLAYER &&
|
||||
event.getView().getType() != InventoryType.CRAFTING &&
|
||||
event.getView().getType() != InventoryType.CREATIVE)
|
||||
if(event.getView().getType() != InventoryType.PLAYER && event.getView().getType() != InventoryType.CRAFTING && event.getView().getType() != InventoryType.CREATIVE) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,17 +31,18 @@ import java.util.Set;
|
||||
public abstract class BasicListener extends StateDependent implements Listener {
|
||||
|
||||
|
||||
BasicListener(final Set<FightState> active){
|
||||
BasicListener(final Set<FightState> active) {
|
||||
super(active);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable(){
|
||||
public void enable() {
|
||||
Bukkit.getPluginManager().registerEvents(this, MissileWars.getPlugin());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable(){
|
||||
public void disable() {
|
||||
HandlerList.unregisterAll(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,8 +33,9 @@ public class ChatListener extends BasicListener {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChat(AsyncPlayerChatEvent e){
|
||||
public void onChat(AsyncPlayerChatEvent e) {
|
||||
Bukkit.broadcastMessage(e.getPlayer().getDisplayName() + "§8» §7" + e.getMessage());
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ import java.util.EnumSet;
|
||||
|
||||
public class ConnectionListener extends BasicListener{
|
||||
|
||||
public ConnectionListener(){
|
||||
public ConnectionListener() {
|
||||
super(EnumSet.allOf(FightState.class));
|
||||
}
|
||||
|
||||
|
@ -48,10 +48,10 @@ public class DeathListener extends BasicListener {
|
||||
Player p = e.getPlayer();
|
||||
p.setFireTicks(0);
|
||||
MWTeam team = MissileWars.getTeam(p);
|
||||
if(team == null)
|
||||
return;
|
||||
if(team == null) return;
|
||||
|
||||
e.setRespawnLocation(team.getSpawn());
|
||||
new SpawnPlatformCreator(p);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ import java.util.EnumSet;
|
||||
|
||||
public class EndListener extends BasicListener {
|
||||
|
||||
public EndListener(){
|
||||
public EndListener() {
|
||||
super(EnumSet.of(FightState.END));
|
||||
}
|
||||
|
||||
@ -37,4 +37,5 @@ public class EndListener extends BasicListener {
|
||||
e.setJoinMessage(null);
|
||||
e.getPlayer().setGameMode(GameMode.SPECTATOR);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -34,14 +34,13 @@ public class FightListener extends BasicListener {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamage(EntityDamageByEntityEvent e){
|
||||
if(!(e.getDamager() instanceof Player && e.getEntity() instanceof Player))
|
||||
return;
|
||||
public void onDamage(EntityDamageByEntityEvent e) {
|
||||
if (!(e.getDamager() instanceof Player && e.getEntity() instanceof Player)) return;
|
||||
|
||||
Player damager = (Player)e.getDamager();
|
||||
Player reciever = (Player)e.getEntity();
|
||||
|
||||
if(MissileWars.getTeam(damager) == MissileWars.getTeam(reciever))
|
||||
e.setCancelled(true);
|
||||
if (MissileWars.getTeam(damager) == MissileWars.getTeam(reciever)) e.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -84,13 +84,10 @@ public class ItemListener extends BasicListener {
|
||||
@EventHandler
|
||||
public void onItemClick(PlayerInteractEvent e) {
|
||||
ItemStack item = e.getItem();
|
||||
if (item == null)
|
||||
return;
|
||||
if (item == null) return;
|
||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK && e.getAction() != Action.RIGHT_CLICK_AIR) return;
|
||||
|
||||
if(e.getAction() != Action.RIGHT_CLICK_BLOCK && e.getAction() != Action.RIGHT_CLICK_AIR)
|
||||
return;
|
||||
|
||||
if(SpecialItem.handleUse(item, e.getPlayer())){
|
||||
if (SpecialItem.handleUse(item, e.getPlayer())) {
|
||||
item.setAmount(item.getAmount()-1);
|
||||
e.getPlayer().updateInventory();
|
||||
e.setCancelled(true);
|
||||
|
@ -29,12 +29,12 @@ import java.util.EnumSet;
|
||||
|
||||
public class JoinListener extends BasicListener {
|
||||
|
||||
public JoinListener(){
|
||||
public JoinListener() {
|
||||
super(EnumSet.of(FightState.WAITING, FightState.FIGHTING));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onJoin(PlayerJoinEvent e){
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
MissileWars.join(e.getPlayer());
|
||||
e.setJoinMessage("§a» " + e.getPlayer().getDisplayName());
|
||||
}
|
||||
|
@ -33,14 +33,14 @@ import java.util.EnumSet;
|
||||
|
||||
public class PortalDestructListener extends BasicListener {
|
||||
|
||||
public PortalDestructListener(){
|
||||
public PortalDestructListener() {
|
||||
super(EnumSet.of(FightState.FIGHTING));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockupdate(BlockPhysicsEvent e) {
|
||||
if (e.getBlock().getType() != Material.NETHER_PORTAL)
|
||||
return;
|
||||
if (e.getBlock().getType() != Material.NETHER_PORTAL) return;
|
||||
|
||||
int z = e.getBlock().getZ();
|
||||
if (z == MissileWars.getRedTeam().getPortalZ())
|
||||
MissileWars.end(WinReasons.PORTAL_DESTROYED, MissileWars.getBlueTeam());
|
||||
@ -49,14 +49,13 @@ public class PortalDestructListener extends BasicListener {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onExplosion(EntityExplodeEvent e){
|
||||
if(e.getEntityType() != EntityType.FIREBALL)
|
||||
return;
|
||||
public void onExplosion(EntityExplodeEvent e) {
|
||||
if(e.getEntityType() != EntityType.FIREBALL) return;
|
||||
|
||||
double z = e.getLocation().getZ();
|
||||
double distRed = Math.abs(Config.RedPortalZ + 0.5 - z);
|
||||
double distBlue = Math.abs(Config.BluePortalZ + 0.5 - z);
|
||||
if(distRed < 2 || distBlue < 2)
|
||||
e.setCancelled(true);
|
||||
if(distRed < 2 || distBlue < 2) e.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,19 +28,18 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import java.util.EnumSet;
|
||||
|
||||
public class WaitingListener extends BasicListener {
|
||||
|
||||
public WaitingListener() {
|
||||
super(EnumSet.of(FightState.WAITING));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDisconnect(PlayerQuitEvent e){
|
||||
if(Bukkit.getOnlinePlayers().isEmpty())
|
||||
Bukkit.shutdown();
|
||||
public void onDisconnect(PlayerQuitEvent e) {
|
||||
if(Bukkit.getOnlinePlayers().isEmpty()) Bukkit.shutdown();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamage(EntityDamageEvent e){
|
||||
if(e.getCause() != EntityDamageEvent.DamageCause.VOID)
|
||||
e.setCancelled(true);
|
||||
public void onDamage(EntityDamageEvent e) {
|
||||
if(e.getCause() != EntityDamageEvent.DamageCause.VOID) e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren