Implement reset after win! #36
102
src/de/steamwar/misslewars/FightWorld.java
Normale Datei
102
src/de/steamwar/misslewars/FightWorld.java
Normale Datei
@ -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");
|
||||||
|
|
||||||
|
public static boolean isPaper(){
|
||||||
|
return paper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
public 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -88,6 +88,15 @@ public class MissileWars extends JavaPlugin {
|
|||||||
Bukkit.getScheduler().runTaskTimer(this, new FightInfoPacketSender(), 20, 20);
|
Bukkit.getScheduler().runTaskTimer(this, new FightInfoPacketSender(), 20, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void waiting() {
|
||||||
|
if (fightState == FightState.END) {
|
||||||
|
fightState = FightState.WAITING;
|
||||||
|
|
||||||
|
redTeam = new MWTeam(ChatColor.RED, Config.RedSpawn, "Rot", Config.RedPortalZ);
|
||||||
|
blueTeam = new MWTeam(ChatColor.DARK_AQUA, Config.BlueSpawn, "Blau", Config.BluePortalZ);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* call to change fightstate from WAITING to INGAME
|
* call to change fightstate from WAITING to INGAME
|
||||||
*/
|
*/
|
||||||
|
@ -23,6 +23,7 @@ import de.steamwar.misslewars.Config;
|
|||||||
import de.steamwar.misslewars.FightState;
|
import de.steamwar.misslewars.FightState;
|
||||||
import de.steamwar.misslewars.MissileWars;
|
import de.steamwar.misslewars.MissileWars;
|
||||||
import de.steamwar.misslewars.StateDependent;
|
import de.steamwar.misslewars.StateDependent;
|
||||||
|
import de.steamwar.misslewars.listener.JoinListener;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
@ -38,16 +39,11 @@ public class EndCountdown extends StateDependent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enable() {
|
public void enable() {
|
||||||
task = Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), this::kickPlayer, Config.EndTime);
|
task = Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), this::restart, Config.EndTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void kickPlayer(){
|
private void restart(){
|
||||||
if(Bukkit.getOnlinePlayers().isEmpty()){
|
Bukkit.getOnlinePlayers().forEach(JoinListener::join);
|
||||||
Bukkit.shutdown();
|
|
||||||
}else{
|
|
||||||
Bukkit.getOnlinePlayers().iterator().next().kickPlayer(null);
|
|
||||||
task = Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), this::kickPlayer, 10);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -22,6 +22,7 @@ package de.steamwar.misslewars.listener;
|
|||||||
import de.steamwar.misslewars.Config;
|
import de.steamwar.misslewars.Config;
|
||||||
import de.steamwar.misslewars.FightState;
|
import de.steamwar.misslewars.FightState;
|
||||||
import de.steamwar.misslewars.MissileWars;
|
import de.steamwar.misslewars.MissileWars;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
@ -50,4 +51,17 @@ public class JoinListener extends BasicListener {
|
|||||||
MissileWars.join(e.getPlayer());
|
MissileWars.join(e.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void join(Player p) {
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
|
|||||||
|
if (Config.isChallenge()) {
|
||||||
|
if (Config.RedLeader.equals(p.getUniqueId())) {
|
||||||
|
MissileWars.getRedTeam().join(p);
|
||||||
|
} else if (Config.BlueLeader.equals(p.getUniqueId())) {
|
||||||
|
MissileWars.getBlueTeam().join(p);
|
||||||
|
} else {
|
||||||
|
p.teleport(MissileWars.getRedTeam().getSpawn().toVector().midpoint(MissileWars.getBlueTeam().getSpawn().toVector()).toLocation(p.getWorld()));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MissileWars.join(p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Codeduplication, bitte diese Methode im Event aufrufen.