SteamWar/MissileWars
Archiviert
13
0

Merge pull request 'Implement reset after win!' (#36) from Arcade into master

Reviewed-on: #36
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
YoyoNow 2021-10-27 20:44:24 +02:00
Commit 30379591f3
7 geänderte Dateien mit 157 neuen und 39 gelöschten Zeilen

Datei anzeigen

@ -2,7 +2,7 @@ WaitingTime: 600
ItemTime: 300
ShieldFlyTime: 100
PlatformTime: 30
EndTime: 600
EndTime: 200
Arena:
MinX: 0

Datei anzeigen

@ -51,8 +51,8 @@ public class Config {
public static final double MissileChance;
public static final UUID BlueLeader;
public static final UUID RedLeader;
public static UUID BlueLeader;
public static UUID RedLeader;
private static final int EventKampfID;

Datei anzeigen

@ -0,0 +1,102 @@
/*
*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2020 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* /
*/
package de.steamwar.misslewars;
import de.steamwar.core.events.ChunkListener;
import net.minecraft.server.v1_15_R1.Chunk;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import java.util.function.ObjIntConsumer;
public class FightWorld {
private static final World world = Bukkit.getWorlds().get(0);
private static final boolean paper = Bukkit.getVersion().contains("git-Paper");
private static boolean isPaper(){
return paper;
}
private static double posToChunk(int pos){
return pos / 16.0;
}
private static int getMinChunkX(){
return (int) Math.floor(posToChunk(Config.ArenaMinX));
}
private static int getMaxChunkX(){
return (int) Math.ceil(posToChunk(Config.ArenaMaxX));
}
private static int getMinChunkZ(){
return (int) Math.floor(posToChunk(Config.ArenaMinZ));
}
private static int getMaxChunkZ(){
return (int) Math.ceil(posToChunk(Config.ArenaMaxZ));
}
private static void forEachChunk(ObjIntConsumer<Integer> executor) {
for(int x = getMinChunkX(); x <= getMaxChunkX(); x++)
for(int z = getMinChunkZ(); z <= getMaxChunkZ(); z++)
executor.accept(x, z);
}
public static void resetWorld(){
for(Entity entity : world.getEntities()){
if(entity.getType() != EntityType.PLAYER){
entity.remove();
}
}
World backup = new WorldCreator(world.getName() + "/backup").createWorld();
assert backup != null;
forEachChunk((x, z) -> resetChunk(world, backup, x, z));
Bukkit.unloadWorld(backup, false);
}
private static void resetChunk(World world, World backup, int x, int z) {
net.minecraft.server.v1_15_R1.World w = ((CraftWorld) world).getHandle();
Chunk chunk = w.getChunkAt(x, z);
Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z);
System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length);
w.tileEntityListTick.removeAll(chunk.tileEntities.values());
if (!FightWorld.isPaper()) {
w.tileEntityList.removeAll(chunk.tileEntities.values());
}
chunk.tileEntities.clear();
chunk.tileEntities.putAll(backupChunk.tileEntities);
chunk.heightMap.clear();
chunk.heightMap.putAll(backupChunk.heightMap);
for(Player p : Bukkit.getOnlinePlayers()){
ChunkListener.sendChunk(p, x, z);
}
}
}

Datei anzeigen

@ -31,10 +31,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Team;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Objects;
import java.util.Set;
import java.util.*;
public class MWTeam {
private static final ItemStack bow = new ItemStack(Material.BOW);
@ -161,6 +158,14 @@ public class MWTeam {
MissileWars.end(WinReasons.NO_ENEMY, enemy());
}
public void reset() {
openInvitations.clear();
List<Player> tempPlayer = new ArrayList<>(players);
players.clear();
tempPlayer.forEach(this::join);
}
public void invitePlayer(Player p) {
if (enemy().openInvitations.contains(p)) return;
openInvitations.add(p);

Datei anzeigen

@ -88,6 +88,19 @@ public class MissileWars extends JavaPlugin {
Bukkit.getScheduler().runTaskTimer(this, new FightInfoPacketSender(), 20, 20);
}
public static void waiting() {
if (fightState == FightState.END) {
fightState = FightState.WAITING;
StateDependent.setupState(fightState);
Config.RedLeader = null;
Config.BlueLeader = null;
redTeam.reset();
blueTeam.reset();
}
}
/**
* call to change fightstate from WAITING to INGAME
*/

Datei anzeigen

@ -19,10 +19,8 @@
package de.steamwar.misslewars.countdowns;
import de.steamwar.misslewars.Config;
import de.steamwar.misslewars.FightState;
import de.steamwar.misslewars.MissileWars;
import de.steamwar.misslewars.StateDependent;
import de.steamwar.misslewars.*;
import de.steamwar.misslewars.listener.JoinListener;
import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitTask;
@ -30,29 +28,25 @@ import java.util.EnumSet;
public class EndCountdown extends StateDependent {
private BukkitTask task;
private BukkitTask task;
public EndCountdown() {
super(EnumSet.of(FightState.END));
}
public EndCountdown() {
super(EnumSet.of(FightState.END));
}
@Override
public void enable() {
task = Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), this::kickPlayer, Config.EndTime);
}
@Override
public void enable() {
task = Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), this::restart, Config.EndTime);
}
private void kickPlayer(){
if(Bukkit.getOnlinePlayers().isEmpty()){
Bukkit.shutdown();
}else{
Bukkit.getOnlinePlayers().iterator().next().kickPlayer(null);
task = Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), this::kickPlayer, 10);
}
}
private void restart() {
FightWorld.resetWorld();
MissileWars.waiting();
}
@Override
public void disable() {
if(task != null && !task.isCancelled())
task.cancel();
}
@Override
public void disable() {
if (task != null && !task.isCancelled())
task.cancel();
}
}

Datei anzeigen

@ -22,6 +22,7 @@ package de.steamwar.misslewars.listener;
import de.steamwar.misslewars.Config;
import de.steamwar.misslewars.FightState;
import de.steamwar.misslewars.MissileWars;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent;
@ -37,17 +38,20 @@ public class JoinListener extends BasicListener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onJoin(PlayerJoinEvent e){
e.setJoinMessage("§a» " + e.getPlayer().getDisplayName());
join(e.getPlayer());
}
public static void join(Player p) {
if (Config.isChallenge()) {
if (Config.RedLeader.equals(e.getPlayer().getUniqueId())) {
MissileWars.getRedTeam().join(e.getPlayer());
} else if (Config.BlueLeader.equals(e.getPlayer().getUniqueId())) {
MissileWars.getBlueTeam().join(e.getPlayer());
if (Config.RedLeader.equals(p.getUniqueId())) {
MissileWars.getRedTeam().join(p);
} else if (Config.BlueLeader.equals(p.getUniqueId())) {
MissileWars.getBlueTeam().join(p);
} else {
e.getPlayer().teleport(MissileWars.getRedTeam().getSpawn().toVector().midpoint(MissileWars.getBlueTeam().getSpawn().toVector()).toLocation(e.getPlayer().getWorld()));
p.teleport(MissileWars.getRedTeam().getSpawn().toVector().midpoint(MissileWars.getBlueTeam().getSpawn().toVector()).toLocation(p.getWorld()));
}
return;
}
MissileWars.join(e.getPlayer());
MissileWars.join(p);
}
}