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 ItemTime: 300
ShieldFlyTime: 100 ShieldFlyTime: 100
PlatformTime: 30 PlatformTime: 30
EndTime: 600 EndTime: 200
Arena: Arena:
MinX: 0 MinX: 0

Datei anzeigen

@ -51,8 +51,8 @@ public class Config {
public static final double MissileChance; public static final double MissileChance;
public static final UUID BlueLeader; public static UUID BlueLeader;
public static final UUID RedLeader; public static UUID RedLeader;
private static final int EventKampfID; 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.Objective;
import org.bukkit.scoreboard.Team; import org.bukkit.scoreboard.Team;
import java.util.HashSet; import java.util.*;
import java.util.LinkedList;
import java.util.Objects;
import java.util.Set;
public class MWTeam { public class MWTeam {
private static final ItemStack bow = new ItemStack(Material.BOW); private static final ItemStack bow = new ItemStack(Material.BOW);
@ -161,6 +158,14 @@ public class MWTeam {
MissileWars.end(WinReasons.NO_ENEMY, enemy()); 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) { public void invitePlayer(Player p) {
if (enemy().openInvitations.contains(p)) return; if (enemy().openInvitations.contains(p)) return;
openInvitations.add(p); openInvitations.add(p);

Datei anzeigen

@ -88,6 +88,19 @@ 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;
StateDependent.setupState(fightState);
Config.RedLeader = null;
Config.BlueLeader = null;
redTeam.reset();
blueTeam.reset();
}
}
/** /**
* call to change fightstate from WAITING to INGAME * call to change fightstate from WAITING to INGAME
*/ */

Datei anzeigen

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

Datei anzeigen

@ -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;
@ -37,17 +38,20 @@ public class JoinListener extends BasicListener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onJoin(PlayerJoinEvent e){ public void onJoin(PlayerJoinEvent e){
e.setJoinMessage("§a» " + e.getPlayer().getDisplayName()); e.setJoinMessage("§a» " + e.getPlayer().getDisplayName());
join(e.getPlayer());
}
public static void join(Player p) {
if (Config.isChallenge()) { if (Config.isChallenge()) {
if (Config.RedLeader.equals(e.getPlayer().getUniqueId())) { if (Config.RedLeader.equals(p.getUniqueId())) {
MissileWars.getRedTeam().join(e.getPlayer()); MissileWars.getRedTeam().join(p);
} else if (Config.BlueLeader.equals(e.getPlayer().getUniqueId())) { } else if (Config.BlueLeader.equals(p.getUniqueId())) {
MissileWars.getBlueTeam().join(e.getPlayer()); MissileWars.getBlueTeam().join(p);
} else { } 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; return;
} }
MissileWars.join(e.getPlayer()); MissileWars.join(p);
} }
} }