SteamWar/FightSystem
Archiviert
13
1

Registered Listeners for WinConditions (only if enabled);

Added PercentSystem (Prozentsystem) as WinCondition;
Added PercentSystem to config.yml;

Signed-off-by: Yaruma3341 <yaruma3341@gmail.com>
Dieser Commit ist enthalten in:
Yaruma3341 2019-02-17 22:39:57 +01:00
Ursprung 2d03c39883
Commit d956ee7353
4 geänderte Dateien mit 97 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -36,10 +36,12 @@ WinConditions:
Timeout: boolean Timeout: boolean
AllDead: boolean AllDead: boolean
CaptainDead: boolean CaptainDead: boolean
PercentSystem: boolean
WinConditionParams: WinConditionParams:
TimeoutTime: 0 TimeoutTime: 0
EnterPhaseBegin: 0 EnterPhaseBegin: 0
PercentWin: 0
Fight: Fight:
Entern: boolean Entern: boolean

Datei anzeigen

@ -8,6 +8,9 @@ import me.yaruma.fightsystem.listener.*;
import me.yaruma.fightsystem.manager.FileManager; import me.yaruma.fightsystem.manager.FileManager;
import me.yaruma.fightsystem.utils.countdown.Countdown; import me.yaruma.fightsystem.utils.countdown.Countdown;
import me.yaruma.fightsystem.utils.countdown.FinishSetupOver; import me.yaruma.fightsystem.utils.countdown.FinishSetupOver;
import me.yaruma.fightsystem.winconditions.WinconditionAllDead;
import me.yaruma.fightsystem.winconditions.WinconditionCaptainDead;
import me.yaruma.fightsystem.winconditions.WinconditionPercentSystem;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
@ -51,6 +54,13 @@ public class FightSystem extends JavaPlugin {
public int team2cornerY; public int team2cornerY;
public int team2cornerZ; public int team2cornerZ;
public int team1SchematicBlocks;
public int team2SchematicBlocks;
public int team1DestroyedBlocks;
public int team2DestroyedBlocks;
public void onEnable() { public void onEnable() {
plugin = this; plugin = this;
@ -155,6 +165,12 @@ public class FightSystem extends JavaPlugin {
pm.registerEvents(new BlockBreakListener(), plugin); pm.registerEvents(new BlockBreakListener(), plugin);
pm.registerEvents(new PlayerMoveListener(), plugin); pm.registerEvents(new PlayerMoveListener(), plugin);
//WinConditions
if(fileManager.getBooleanFromConfig("WinConditions.AllDead")) pm.registerEvents(new WinconditionAllDead(), plugin);
if(fileManager.getBooleanFromConfig("WinConditions.CaptainDead")) pm.registerEvents(new WinconditionCaptainDead(), plugin);
if(fileManager.getBooleanFromConfig("WinConditions.AllDead")) pm.registerEvents(new WinconditionAllDead(), plugin);
if(fileManager.getBooleanFromConfig("WinConditions.PercentWin")) pm.registerEvents(new WinconditionPercentSystem(), plugin);
getCommand("ak").setExecutor(new AkCommand()); getCommand("ak").setExecutor(new AkCommand());
} }
@ -315,4 +331,20 @@ public class FightSystem extends JavaPlugin {
public int getTeam2cornerZ() { public int getTeam2cornerZ() {
return team2cornerZ; return team2cornerZ;
} }
public int getTeam1SchematicBlocks() {
return team1SchematicBlocks;
}
public int getTeam2SchematicBlocks() {
return team2SchematicBlocks;
}
public int getTeam1DestroyedBlocks() {
return team1DestroyedBlocks;
}
public int getTeam2DestroyedBlocks() {
return team2DestroyedBlocks;
}
} }

Datei anzeigen

@ -3,6 +3,7 @@ package me.yaruma.fightsystem.utils;
import com.boydti.fawe.FaweAPI; import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.util.EditSessionBuilder; import com.boydti.fawe.util.EditSessionBuilder;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.bukkit.BukkitWorld;
@ -46,5 +47,17 @@ public class WorldEdit {
} catch (IOException e) { } } catch (IOException e) { }
} }
public static int countBlocks(Player player, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, BaseBlock baseBlock) {
World weWorld = new BukkitWorld(player.getWorld());
EditSession editSession = new EditSessionBuilder(weWorld).fastmode(true).build();
CuboidSelection cuboidSelection = new CuboidSelection(player.getWorld(), new Location(player.getWorld(), minX, minY, minZ), new Location(player.getWorld(), maxX, maxY, maxZ));
Set<BaseBlock> target = new HashSet<>();
target.add(baseBlock);
try {
return editSession.countBlocks(cuboidSelection.getRegionSelector().getRegion(), target);
} catch (IncompleteRegionException e) { }
return 0;
}
} }

Datei anzeigen

@ -0,0 +1,50 @@
package me.yaruma.fightsystem.winconditions;
import me.yaruma.fightsystem.FightSystem;
import me.yaruma.fightsystem.fight.Fight;
import me.yaruma.fightsystem.manager.FileManager;
import me.yaruma.fightsystem.utils.Region;
import me.yaruma.fightsystem.utils.countdown.Countdown;
import me.yaruma.fightsystem.utils.countdown.FinishSpectateOver;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
public class WinconditionPercentSystem implements Listener {
FightSystem instance = FightSystem.getPlugin();
FileManager fileManager = instance.getFileManager();
@EventHandler
public void handleEntityExplode(EntityExplodeEvent event) {
if(!Methods.isEnabled("WinConditions.PercentWin")) return;
Entity entity = event.getEntity();
//Team 1 / Rot
if(Region.isInRegion(entity.getLocation(), instance.getTeam1cornerX(), instance.getTeam1cornerY(), instance.getTeam1cornerZ(), instance.getTeam1cornerX() + instance.getSchemsizeX(), instance.getTeam1cornerY() + instance.getSchemsizeY(), instance.getTeam1cornerZ() + instance.getSchemsizeZ(), fileManager.getIntegerFromConfig("Arena.BorderFromSchematic"))) {
instance.team1DestroyedBlocks = instance.getTeam1DestroyedBlocks() + event.blockList().size();
double destroyPercent = instance.getTeam1DestroyedBlocks() * 100 / instance.getTeam1SchematicBlocks();
if(destroyPercent >= fileManager.getIntegerFromConfig("WinConditionParams.PercentWin")) {
instance.setSpectateState(Fight.blueTeam);
Countdown countdown = new Countdown(fileManager.getIntegerFromConfig("Times.SpectatorDuration"), new FinishSpectateOver());
countdown.startTimer(instance);
}
return;
}
//Team 2 / Blau
if(Region.isInRegion(entity.getLocation(), instance.getTeam2cornerX(), instance.getTeam1cornerY(), instance.getTeam2cornerZ(), instance.getTeam2cornerX() + instance.getSchemsizeX(), instance.getTeam2cornerY() + instance.getSchemsizeY(), instance.getTeam2cornerZ() + instance.getSchemsizeZ(), fileManager.getIntegerFromConfig("Arena.BorderFromSchematic"))) {
instance.team2DestroyedBlocks = instance.getTeam2DestroyedBlocks() + event.blockList().size();
double destroyPercent = instance.getTeam2DestroyedBlocks() * 100 / instance.getTeam2SchematicBlocks();
if(destroyPercent >= fileManager.getIntegerFromConfig("WinConditionParams.PercentWin")) {
instance.setSpectateState(Fight.redTeam);
Countdown countdown = new Countdown(fileManager.getIntegerFromConfig("Times.SpectatorDuration"), new FinishSpectateOver());
countdown.startTimer(instance);
}
return;
}
}
}