Add SlowMoScript and needed utils
Dieser Commit ist enthalten in:
Ursprung
a6fcd312fb
Commit
4d73afffcd
@ -94,7 +94,7 @@ public class MWTeam {
|
||||
Inventory inventory = p.getInventory();
|
||||
for (int i = 0; i <= 35; i++) { //35 is the last normal inventory slot
|
||||
ItemStack itemStack = inventory.getItem(i);
|
||||
if (itemStack != null && itemStack.isSimilar(item) && itemStack.getAmount() != itemStack.getMaxStackSize()) {
|
||||
if (itemStack != null && itemStack.isSimilar(item) && itemStack.getAmount() + item.getAmount() < 64) {
|
||||
itemStack.setAmount(itemStack.getAmount() + item.getAmount());
|
||||
inventory.setItem(i, itemStack);
|
||||
p.updateInventory();
|
||||
|
@ -25,8 +25,10 @@ import de.steamwar.misslewars.commands.CommandSpectate;
|
||||
import de.steamwar.misslewars.countdowns.EndCountdown;
|
||||
import de.steamwar.misslewars.countdowns.ItemCountdown;
|
||||
import de.steamwar.misslewars.countdowns.WaitingCountdown;
|
||||
import de.steamwar.misslewars.items.*;
|
||||
import de.steamwar.misslewars.items.CustomItem;
|
||||
import de.steamwar.misslewars.items.Missile;
|
||||
import de.steamwar.misslewars.listener.*;
|
||||
import de.steamwar.misslewars.slowmo.SlowMoRunner;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
@ -35,7 +37,6 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
@ -99,6 +100,8 @@ public class MissileWars extends JavaPlugin {
|
||||
fightState = FightState.WAITING;
|
||||
StateDependent.setupState(fightState);
|
||||
|
||||
SlowMoRunner.resetSlowMoTime();
|
||||
|
||||
Set<UUID> uuidList = Bukkit.getOnlinePlayers().stream().map(Entity::getUniqueId).collect(Collectors.toSet());
|
||||
if (!uuidList.contains(Config.RedLeader) || !uuidList.contains(Config.BlueLeader)) {
|
||||
Config.RedLeader = null;
|
||||
|
@ -46,7 +46,6 @@ public class Script {
|
||||
if (!runnableScriptList.get(index++).execute(runnableScriptEvent)) return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void execute(RunnableScriptEvent runnableScriptEvent) {
|
||||
@ -84,6 +83,8 @@ public class Script {
|
||||
return new SoundScript(jsonObject);
|
||||
case "summon":
|
||||
return new SummonScript(jsonObject);
|
||||
case "slowmo":
|
||||
return new SlowMoScript(jsonObject);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
44
src/de/steamwar/misslewars/scripts/implemented/SlowMoScript.java
Normale Datei
44
src/de/steamwar/misslewars/scripts/implemented/SlowMoScript.java
Normale Datei
@ -0,0 +1,44 @@
|
||||
/*
|
||||
*
|
||||
* 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.scripts.implemented;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import de.steamwar.misslewars.scripts.RunnableScript;
|
||||
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||
import de.steamwar.misslewars.slowmo.SlowMoRunner;
|
||||
|
||||
public class SlowMoScript implements RunnableScript {
|
||||
|
||||
private int slowMoTime = 0;
|
||||
|
||||
public SlowMoScript(JsonObject jsonObject) {
|
||||
JsonPrimitive jsonPrimitive = jsonObject.getAsJsonPrimitive("time");
|
||||
if (jsonPrimitive.isNumber()) slowMoTime = jsonPrimitive.getAsInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
|
||||
SlowMoRunner.addSlowMoTime(slowMoTime);
|
||||
return true;
|
||||
}
|
||||
}
|
55
src/de/steamwar/misslewars/slowmo/SlowMoRunner.java
Normale Datei
55
src/de/steamwar/misslewars/slowmo/SlowMoRunner.java
Normale Datei
@ -0,0 +1,55 @@
|
||||
/*
|
||||
*
|
||||
* 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.slowmo;
|
||||
|
||||
import de.steamwar.misslewars.MissileWars;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class SlowMoRunner {
|
||||
|
||||
private static long currentTime = 0;
|
||||
private static long current = 0;
|
||||
|
||||
public static void addSlowMoTime(int time) {
|
||||
currentTime += time;
|
||||
}
|
||||
|
||||
public static void resetSlowMoTime() {
|
||||
currentTime = 0;
|
||||
}
|
||||
|
||||
static {
|
||||
Bukkit.getScheduler().runTaskTimer(MissileWars.getPlugin(), () -> {
|
||||
if(currentTime > 0) {
|
||||
current += 1;
|
||||
if (current % 5 == 0) {
|
||||
SlowMoUtils.unfreeze();
|
||||
} else {
|
||||
SlowMoUtils.freeze();
|
||||
}
|
||||
currentTime--;
|
||||
} else {
|
||||
SlowMoUtils.unfreeze();
|
||||
}
|
||||
}, 0, 1);
|
||||
}
|
||||
}
|
76
src/de/steamwar/misslewars/slowmo/SlowMoUtils.java
Normale Datei
76
src/de/steamwar/misslewars/slowmo/SlowMoUtils.java
Normale Datei
@ -0,0 +1,76 @@
|
||||
/*
|
||||
*
|
||||
* 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.slowmo;
|
||||
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class SlowMoUtils {
|
||||
|
||||
private static final Field field;
|
||||
public static final boolean freezeEnabled;
|
||||
|
||||
private static final Reflection.MethodInvoker getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle", null);
|
||||
private static boolean frozen = false;
|
||||
|
||||
private static final World world;
|
||||
|
||||
static {
|
||||
Field temp;
|
||||
try {
|
||||
temp = Reflection.getClass("{nms.server.level}.WorldServer").getField("freezed");
|
||||
} catch (NoSuchFieldException e) {
|
||||
temp = null;
|
||||
}
|
||||
field = temp;
|
||||
if (field != null) field.setAccessible(true);
|
||||
freezeEnabled = field != null;
|
||||
world = Bukkit.getWorlds().get(0);
|
||||
}
|
||||
|
||||
public static void freeze() {
|
||||
setFreeze(world, true);
|
||||
}
|
||||
|
||||
public static void unfreeze() {
|
||||
setFreeze(world, false);
|
||||
}
|
||||
|
||||
public static boolean frozen() {
|
||||
return freezeEnabled && frozen;
|
||||
}
|
||||
|
||||
private static void setFreeze(World world, boolean state) {
|
||||
if (freezeEnabled) {
|
||||
if (frozen == state) return;
|
||||
try {
|
||||
field.set(getWorldHandle.invoke(world), state);
|
||||
frozen = state;
|
||||
} catch (IllegalAccessException e) {
|
||||
// Ignored;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren