Merge branch 'master' into multi-stage-entern
Dieser Commit ist enthalten in:
Commit
3b46d45bc0
@ -1,5 +1,6 @@
|
|||||||
package de.steamwar.fightsystem;
|
package de.steamwar.fightsystem;
|
||||||
|
|
||||||
|
import de.steamwar.core.CommandRemover;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.fightsystem.commands.*;
|
import de.steamwar.fightsystem.commands.*;
|
||||||
import de.steamwar.fightsystem.countdown.*;
|
import de.steamwar.fightsystem.countdown.*;
|
||||||
@ -23,6 +24,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class FightSystem extends JavaPlugin {
|
public class FightSystem extends JavaPlugin {
|
||||||
|
|
||||||
@ -47,6 +49,15 @@ public class FightSystem extends JavaPlugin {
|
|||||||
TechHider.init();
|
TechHider.init();
|
||||||
FightScoreboard.init();
|
FightScoreboard.init();
|
||||||
|
|
||||||
|
try {
|
||||||
|
CommandRemover.removeAll("gamemode");
|
||||||
|
CommandInjector.injectCommand(new GamemodeCommand());
|
||||||
|
} catch (Exception e) {
|
||||||
|
getLogger().log(Level.SEVERE, "Failed to replace commands", e);
|
||||||
|
Bukkit.shutdown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
new EntityDamageListener();
|
new EntityDamageListener();
|
||||||
new EntityExplodeListener();
|
new EntityExplodeListener();
|
||||||
new FoodLevelChangeListener();
|
new FoodLevelChangeListener();
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
package de.steamwar.fightsystem.commands;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.SimpleCommandMap;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
public class CommandInjector {
|
||||||
|
|
||||||
|
private CommandInjector(){}
|
||||||
|
|
||||||
|
private static final String PACKAGE_NAME = Bukkit.getServer().getClass().getPackage().getName();
|
||||||
|
private static final String VERSION = PACKAGE_NAME.substring(PACKAGE_NAME.lastIndexOf('.') + 1);
|
||||||
|
|
||||||
|
public static void injectCommand(Command cmd) throws Exception {
|
||||||
|
Class serverClass = Class.forName("org.bukkit.craftbukkit." + VERSION + ".CraftServer");
|
||||||
|
Field f1 = serverClass.getDeclaredField("commandMap");
|
||||||
|
f1.setAccessible(true);
|
||||||
|
SimpleCommandMap commandMap = (SimpleCommandMap) f1.get(Bukkit.getServer());
|
||||||
|
commandMap.register("BauSystem", cmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,88 @@
|
|||||||
|
package de.steamwar.fightsystem.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import de.steamwar.fightsystem.Config;
|
||||||
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.defaults.BukkitCommand;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.StringUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GamemodeCommand extends BukkitCommand {
|
||||||
|
|
||||||
|
private static final List<String> GAMEMODE_NAMES = ImmutableList.of("adventure", "creative", "survival",
|
||||||
|
"spectator");
|
||||||
|
|
||||||
|
public GamemodeCommand() {
|
||||||
|
super("gamemode");
|
||||||
|
List<String> aliases = new ArrayList<>();
|
||||||
|
aliases.add("gm");
|
||||||
|
this.setAliases(aliases);
|
||||||
|
this.description = "Ändert den Spielmodus eines Spielers";
|
||||||
|
this.usageMessage = "/gm [Spielmodus]";
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
|
||||||
|
if (!(sender instanceof Player)) {
|
||||||
|
return false;
|
||||||
|
}else if (args.length == 0) {
|
||||||
|
sender.sendMessage(FightSystem.PREFIX + this.usageMessage);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player p = (Player) sender;
|
||||||
|
|
||||||
|
if (!(Config.test() || p == FightSystem.getEventLeiter())) {
|
||||||
|
p.sendMessage(FightSystem.PREFIX + "§cDu darfst hier deinen Spielmodus nicht ändern");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
GameMode mode = createMode(args[0]);
|
||||||
|
|
||||||
|
if(mode == null){
|
||||||
|
p.sendMessage(FightSystem.PREFIX + "§cUnbekannter Spielmodus");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
p.setGameMode(mode);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
private GameMode createMode(String modeArg){
|
||||||
|
try {
|
||||||
|
return GameMode.getByValue(Integer.parseInt(modeArg));
|
||||||
|
} catch (NumberFormatException ignored) {
|
||||||
|
if ((modeArg.equalsIgnoreCase("creative")) || (modeArg.equalsIgnoreCase("c")))
|
||||||
|
return GameMode.CREATIVE;
|
||||||
|
else if ((modeArg.equalsIgnoreCase("adventure")) || (modeArg.equalsIgnoreCase("a")))
|
||||||
|
return GameMode.ADVENTURE;
|
||||||
|
else if ((modeArg.equalsIgnoreCase("spectator")) || (modeArg.equalsIgnoreCase("sp")))
|
||||||
|
return GameMode.SPECTATOR;
|
||||||
|
else if ((modeArg.equalsIgnoreCase("survival")) || (modeArg.equalsIgnoreCase("s")))
|
||||||
|
return GameMode.SURVIVAL;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
|
||||||
|
Validate.notNull(sender, "Sender cannot be null");
|
||||||
|
Validate.notNull(args, "Arguments cannot be null");
|
||||||
|
Validate.notNull(alias, "Alias cannot be null");
|
||||||
|
|
||||||
|
if (args.length == 1)
|
||||||
|
return StringUtil.copyPartialMatches(args[0], GAMEMODE_NAMES,
|
||||||
|
new ArrayList<>(GAMEMODE_NAMES.size()));
|
||||||
|
if (args.length == 2) {
|
||||||
|
return super.tabComplete(sender, alias, args);
|
||||||
|
}
|
||||||
|
return ImmutableList.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -13,6 +13,7 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
|||||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||||
import org.bukkit.event.inventory.InventoryPickupItemEvent;
|
import org.bukkit.event.inventory.InventoryPickupItemEvent;
|
||||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||||
|
import org.bukkit.event.player.PlayerKickEvent;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
|
||||||
@ -47,6 +48,12 @@ public class FreezeWorldStateListener extends BasicListener {
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void handlePlayerKickEvent(PlayerKickEvent e){
|
||||||
|
if(e.getReason().contains("Flying is not enabled"))
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onInventoryDrag(InventoryDragEvent event) {
|
public void onInventoryDrag(InventoryDragEvent event) {
|
||||||
if(PersonalKitCreator.notInKitCreator(event.getWhoClicked()))
|
if(PersonalKitCreator.notInKitCreator(event.getWhoClicked()))
|
||||||
|
@ -7,51 +7,35 @@ import de.steamwar.fightsystem.fight.FightTeam;
|
|||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import de.steamwar.fightsystem.utils.WaterRemover;
|
import de.steamwar.fightsystem.utils.WaterRemover;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class WinconditionWaterTechKO extends Wincondition {
|
public class WinconditionWaterTechKO extends Wincondition {
|
||||||
|
|
||||||
private static final Set<Location> teamRedWater = new HashSet<>();
|
private static int teamRedWater;
|
||||||
private static final Set<Location> teamBlueWater = new HashSet<>();
|
private static int teamBlueWater;
|
||||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
private static final World WORLD = Bukkit.getWorlds().get(0);
|
||||||
|
|
||||||
private BukkitTask task;
|
private BukkitTask task;
|
||||||
|
|
||||||
public WinconditionWaterTechKO() {
|
public WinconditionWaterTechKO() {
|
||||||
super(Config.WaterTechKO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING, FightState.SPECTATE));
|
super(Config.WaterTechKO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getTeamBlueWater() {
|
public static int getTeamBlueWater() {
|
||||||
return teamBlueWater.size();
|
return teamBlueWater;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getTeamRedWater() {
|
public static int getTeamRedWater() {
|
||||||
return teamRedWater.size();
|
return teamRedWater;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enable() {
|
public void enable() {
|
||||||
checkForWater(teamRedWater,
|
checkTask();
|
||||||
Config.TeamRedCornerX,
|
task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), this::checkTask, 200, 200);
|
||||||
Config.TeamRedCornerY,
|
|
||||||
Config.TeamRedCornerZ,
|
|
||||||
Config.TeamRedCornerX + Config.SchemsizeX,
|
|
||||||
Config.TeamRedCornerY + Config.SchemsizeY,
|
|
||||||
Config.TeamRedCornerZ + Config.SchemsizeZ);
|
|
||||||
checkForWater(teamBlueWater,
|
|
||||||
Config.TeamBlueCornerX,
|
|
||||||
Config.TeamBlueCornerY,
|
|
||||||
Config.TeamBlueCornerZ,
|
|
||||||
Config.TeamBlueCornerX + Config.SchemsizeX,
|
|
||||||
Config.TeamBlueCornerY + Config.SchemsizeY,
|
|
||||||
Config.TeamBlueCornerZ + Config.SchemsizeZ);
|
|
||||||
task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), this::addWater, 200, 200);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -59,25 +43,22 @@ public class WinconditionWaterTechKO extends Wincondition {
|
|||||||
task.cancel();
|
task.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkEmpty(FightTeam team, Set<Location> teamWater){
|
private void checkEmpty(FightTeam team, int teamWater){
|
||||||
if(teamWater.isEmpty()){
|
if(teamWater == 0){
|
||||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§eDas Team " + team.getColoredName() + " §eist Tech K.O.!");
|
Bukkit.broadcastMessage(FightSystem.PREFIX + "§eDas Team " + team.getColoredName() + " §eist Tech K.O.!");
|
||||||
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team), "WaterTechKO"));
|
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team), "WaterTechKO"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addWater() {
|
private void checkTask() {
|
||||||
if(FightSystem.getFightState() != FightState.PRE_RUNNING && FightSystem.getFightState() != FightState.RUNNING)
|
teamRedWater = calcWater(
|
||||||
return;
|
|
||||||
|
|
||||||
checkForWater(teamRedWater,
|
|
||||||
Config.TeamRedCornerX,
|
Config.TeamRedCornerX,
|
||||||
Config.TeamRedCornerY,
|
Config.TeamRedCornerY,
|
||||||
Config.TeamRedCornerZ,
|
Config.TeamRedCornerZ,
|
||||||
Config.TeamRedCornerX + Config.SchemsizeX,
|
Config.TeamRedCornerX + Config.SchemsizeX,
|
||||||
Config.TeamRedCornerY + Config.SchemsizeY,
|
Config.TeamRedCornerY + Config.SchemsizeY,
|
||||||
Config.TeamRedCornerZ + Config.SchemsizeZ);
|
Config.TeamRedCornerZ + Config.SchemsizeZ);
|
||||||
checkForWater(teamBlueWater,
|
teamBlueWater = calcWater(
|
||||||
Config.TeamBlueCornerX,
|
Config.TeamBlueCornerX,
|
||||||
Config.TeamBlueCornerY,
|
Config.TeamBlueCornerY,
|
||||||
Config.TeamBlueCornerZ,
|
Config.TeamBlueCornerZ,
|
||||||
@ -89,16 +70,16 @@ public class WinconditionWaterTechKO extends Wincondition {
|
|||||||
checkEmpty(Fight.getBlueTeam(), teamBlueWater);
|
checkEmpty(Fight.getBlueTeam(), teamBlueWater);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkForWater(Set<Location> teamWater, int minX, int minY, int minZ, int maxX, int maxY, int maxZ){
|
private int calcWater(int minX, int minY, int minZ, int maxX, int maxY, int maxZ){
|
||||||
teamWater.clear();
|
int teamWater = 0;
|
||||||
|
|
||||||
for(int x = minX; x <= maxX; x++) {
|
for(int x = minX; x <= maxX; x++) {
|
||||||
for(int y = minY; y <= maxY; y++) {
|
for(int y = minY; y <= maxY; y++) {
|
||||||
for (int z = minZ; z <= maxZ; z++) {
|
for (int z = minZ; z <= maxZ; z++) {
|
||||||
if (WaterRemover.isWater(WORLD.getBlockAt(x, y, z)))
|
if (WaterRemover.isWater(WORLD.getBlockAt(x, y, z)))
|
||||||
teamWater.add(new Location(WORLD, x, y, z));
|
teamWater++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return teamWater;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren