Commits vergleichen
1 Commits
master
...
item_giver
Autor | SHA1 | Datum | |
---|---|---|---|
|
fcde18f0c8 |
204
build.gradle
204
build.gradle
@ -17,6 +17,11 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
import org.apache.tools.ant.taskdefs.condition.Os
|
||||
|
||||
import java.util.function.BiConsumer
|
||||
|
||||
plugins {
|
||||
// Adding the base plugin fixes the following gradle warnings in IntelliJ:
|
||||
//
|
||||
@ -30,16 +35,47 @@ plugins {
|
||||
id 'application'
|
||||
|
||||
id 'com.github.johnrengelman.shadow' version '5.0.0'
|
||||
id 'de.steamwar.gradle' version 'RELEASE'
|
||||
}
|
||||
|
||||
ext.swdep = { s ->
|
||||
if (file("${rootDir}/lib/${s}.jar").exists()) {
|
||||
return files("${rootDir}/lib/${s}.jar")
|
||||
} else {
|
||||
if (s.contains("-")) {
|
||||
return "de.steamwar:${s.toLowerCase().replace('-', ':')}"
|
||||
} else {
|
||||
return "de.steamwar:${s.toLowerCase()}:RELEASE"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
group 'de.steamwar'
|
||||
version ''
|
||||
|
||||
Properties steamwarProperties = new Properties()
|
||||
if (file("steamwar.properties").exists()) {
|
||||
steamwarProperties.load(file("steamwar.properties").newDataInputStream())
|
||||
}
|
||||
|
||||
ext {
|
||||
buildName = 'MissileWars'
|
||||
artifactName = 'missilewars'
|
||||
|
||||
uberJarName = "${buildName}-all.jar"
|
||||
jarName = "${artifactName}.jar"
|
||||
libs = "${buildDir}/libs"
|
||||
|
||||
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
||||
operatingSystem = "windows"
|
||||
} else {
|
||||
operatingSystem = "unix"
|
||||
}
|
||||
}
|
||||
|
||||
compileJava.options.encoding = 'UTF-8'
|
||||
|
||||
sourceCompatibility = 11
|
||||
targetCompatibility = 11
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
|
||||
mainClassName = ''
|
||||
|
||||
@ -59,11 +95,11 @@ repositories {
|
||||
mavenCentral()
|
||||
|
||||
maven {
|
||||
url = uri("https://repo.codemc.io/repository/maven-snapshots/")
|
||||
url = uri('https://steamwar.de/maven/')
|
||||
credentials {
|
||||
username = steamwarProperties.getProperty("maven.username")
|
||||
password = steamwarProperties.getProperty("maven.password")
|
||||
}
|
||||
|
||||
maven {
|
||||
url = uri('https://hub.spigotmc.org/nexus/content/repositories/snapshots/')
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,9 +109,155 @@ dependencies {
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.22'
|
||||
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
|
||||
|
||||
compileOnly 'org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT'
|
||||
|
||||
compileOnly swdep("Spigot-1.20")
|
||||
compileOnly swdep('FastAsyncWorldEdit-1.18')
|
||||
compileOnly swdep("SpigotCore")
|
||||
compileOnly swdep("Spigot-1.15")
|
||||
compileOnly swdep("WorldEdit-1.15")
|
||||
}
|
||||
|
||||
task buildProject {
|
||||
description 'Build this project'
|
||||
group "Steamwar"
|
||||
|
||||
dependsOn build
|
||||
}
|
||||
|
||||
task finalizeProject {
|
||||
description 'Finalize this project'
|
||||
group "Steamwar"
|
||||
|
||||
doLast {
|
||||
if ("${buildDir}" == null) {
|
||||
return
|
||||
}
|
||||
delete fileTree("${libs}").matching {
|
||||
exclude("${uberJarName}")
|
||||
}
|
||||
file(libs + "/" + uberJarName).renameTo(file(libs + "/" + jarName))
|
||||
}
|
||||
}
|
||||
build.finalizedBy(finalizeProject)
|
||||
|
||||
if (steamwarProperties.containsKey("hostname")) {
|
||||
String hostname = steamwarProperties.get("hostname")
|
||||
String uploadPath = steamwarProperties.getOrDefault("uploadPath", "~")
|
||||
|
||||
String server = steamwarProperties.getOrDefault("server", "DevBungee")
|
||||
String serverStartFlags = steamwarProperties.getOrDefault("serverStartFlags", "")
|
||||
|
||||
task uploadProject {
|
||||
description 'Upload this project'
|
||||
group "Steamwar"
|
||||
|
||||
doLast {
|
||||
await(shell("scp ${libs}/${jarName} ${hostname}:${uploadPath}/${server}/plugins"))
|
||||
if (steamwarProperties.getOrDefault("directStart", "false") == "false" && !answer("Start ${server} server?")) {
|
||||
return
|
||||
}
|
||||
serverStart(server, serverStartFlags, hostname)
|
||||
}
|
||||
}
|
||||
uploadProject.dependsOn(buildProject)
|
||||
|
||||
task startDevServer {
|
||||
description 'Start the DevBungee'
|
||||
group "Steamwar"
|
||||
|
||||
doLast {
|
||||
serverStart(server, serverStartFlags, hostname)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private def await(Process proc) {
|
||||
def out = new StringBuilder()
|
||||
def err = new StringBuilder()
|
||||
proc.waitForProcessOutput(out, err)
|
||||
return [out, err, proc.exitValue()]
|
||||
}
|
||||
|
||||
private def shell(String command) {
|
||||
if (operatingSystem == "unix") {
|
||||
return ['bash', '-c', command].execute()
|
||||
} else {
|
||||
return ["cmd", "/c", command].execute()
|
||||
}
|
||||
}
|
||||
|
||||
private def serverStart(String serverName, String serverFlags, String hostname) {
|
||||
def proc = shell("ssh -t ${hostname} \"./mc ${serverFlags} ${serverName}\"")
|
||||
|
||||
Set<String> strings = new HashSet<>()
|
||||
File file = new File("${projectDir}/ignoredlog");
|
||||
if (file.exists()) {
|
||||
new BufferedReader(new InputStreamReader(new FileInputStream(file))).readLines().forEach({ s ->
|
||||
strings.add(s)
|
||||
})
|
||||
}
|
||||
|
||||
Thread outputThread = new Thread({
|
||||
Reader reader = proc.getInputStream().newReader();
|
||||
Writer writer = System.out.newWriter();
|
||||
try {
|
||||
while (proc.alive) {
|
||||
String s = reader.readLine()
|
||||
if (s == null) {
|
||||
return
|
||||
}
|
||||
if (strings.stream().anyMatch({check -> s.contains(check)})) {
|
||||
continue
|
||||
}
|
||||
writer.write(s + "\n")
|
||||
writer.flush()
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Ignored
|
||||
}
|
||||
})
|
||||
outputThread.setName("${serverName} - OutputThread")
|
||||
outputThread.start()
|
||||
|
||||
Writer writer
|
||||
Thread inputThread = new Thread({
|
||||
Reader reader = System.in.newReader()
|
||||
writer = proc.getOutputStream().newWriter()
|
||||
try {
|
||||
while (proc.alive) {
|
||||
String s = reader.readLine()
|
||||
writer.write(s + "\n")
|
||||
writer.flush()
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Ignored
|
||||
}
|
||||
})
|
||||
inputThread.setName("${serverName} - InputThread")
|
||||
inputThread.start()
|
||||
|
||||
gradle.buildFinished { buildResult ->
|
||||
if (!proc.alive) {
|
||||
return
|
||||
}
|
||||
writer = proc.getOutputStream().newWriter()
|
||||
writer.write("stop\n")
|
||||
writer.flush()
|
||||
awaitClose(proc, outputThread, inputThread)
|
||||
}
|
||||
awaitClose(proc, outputThread, inputThread)
|
||||
};
|
||||
|
||||
private static def awaitClose(Process proc, Thread outputThread, Thread inputThread) {
|
||||
while (proc.alive) {
|
||||
Thread.sleep(10)
|
||||
}
|
||||
proc.closeStreams()
|
||||
outputThread.interrupt()
|
||||
inputThread.interrupt()
|
||||
}
|
||||
|
||||
private def answer(String question) {
|
||||
while (System.in.available() > 0) System.in.read()
|
||||
println(question)
|
||||
boolean valid = "Yy".contains(((char) System.in.read()).toString())
|
||||
while (System.in.available() > 0) System.in.read()
|
||||
return valid
|
||||
}
|
@ -17,13 +17,4 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
maven {
|
||||
url = uri("https://steamwar.de/maven/")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = 'MissileWars'
|
@ -4,9 +4,6 @@ ShieldFlyTime: 100
|
||||
PlatformTime: 30
|
||||
EndTime: 200
|
||||
|
||||
# Special
|
||||
Barrier: true
|
||||
|
||||
Arena:
|
||||
MinX: 0
|
||||
MaxX: 0
|
||||
|
@ -19,9 +19,6 @@
|
||||
|
||||
package de.steamwar.misslewars;
|
||||
|
||||
import de.steamwar.sql.Event;
|
||||
import de.steamwar.sql.EventFight;
|
||||
import de.steamwar.sql.Team;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@ -33,8 +30,7 @@ import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Config {
|
||||
private Config() {
|
||||
}
|
||||
private Config(){}
|
||||
|
||||
public static final int ArenaMinX;
|
||||
public static final int ArenaMaxX;
|
||||
@ -55,25 +51,11 @@ public class Config {
|
||||
|
||||
public static final double MissileChance;
|
||||
|
||||
public static final boolean Barrier;
|
||||
public static final boolean Space;
|
||||
|
||||
// Challenge
|
||||
public static UUID BlueLeader;
|
||||
public static UUID RedLeader;
|
||||
|
||||
private static final int EventKampfID;
|
||||
|
||||
// Event
|
||||
public static final EventFight EventKampf;
|
||||
public static final String TeamBlueName;
|
||||
public static final String TeamRedName;
|
||||
public static final String TeamBlueColor;
|
||||
public static final String TeamRedColor;
|
||||
public static final int EventTeamBlueID;
|
||||
public static final int EventTeamRedID;
|
||||
public static final int MaximumTeamMembers;
|
||||
|
||||
static {
|
||||
File configfile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "config.yml");
|
||||
if (!configfile.exists()) {
|
||||
@ -101,80 +83,33 @@ public class Config {
|
||||
ConfigurationSection red = config.getConfigurationSection("Red");
|
||||
assert red != null;
|
||||
RedPortalZ = red.getInt("PortalZ");
|
||||
RedSpawn = new Location(Bukkit.getWorlds().get(0), red.getDouble("SpawnX"), red.getDouble("SpawnY"), red.getDouble("SpawnZ"), (float) red.getDouble("SpawnYaw"), (float) red.getDouble("SpawnPitch"));
|
||||
RedSpawn = new Location(Bukkit.getWorlds().get(0), red.getDouble("SpawnX"), red.getDouble("SpawnY"), red.getDouble("SpawnZ"), (float)red.getDouble("SpawnYaw"), (float)red.getDouble("SpawnPitch"));
|
||||
|
||||
ConfigurationSection blue = config.getConfigurationSection("Blue");
|
||||
assert blue != null;
|
||||
BluePortalZ = blue.getInt("PortalZ");
|
||||
BlueSpawn = new Location(Bukkit.getWorlds().get(0), blue.getDouble("SpawnX"), blue.getDouble("SpawnY"), blue.getDouble("SpawnZ"), (float) blue.getDouble("SpawnYaw"), (float) blue.getDouble("SpawnPitch"));
|
||||
BlueSpawn = new Location(Bukkit.getWorlds().get(0), blue.getDouble("SpawnX"), blue.getDouble("SpawnY"), blue.getDouble("SpawnZ"), (float)blue.getDouble("SpawnYaw"), (float)blue.getDouble("SpawnPitch"));
|
||||
|
||||
String blueLeader = System.getProperty("blueLeader", null);
|
||||
String redLeader = System.getProperty("redLeader", null);
|
||||
if (blueLeader != null)
|
||||
if(blueLeader != null)
|
||||
BlueLeader = UUID.fromString(blueLeader);
|
||||
else
|
||||
BlueLeader = null;
|
||||
if (redLeader != null)
|
||||
if(redLeader != null)
|
||||
RedLeader = UUID.fromString(redLeader);
|
||||
else
|
||||
RedLeader = null;
|
||||
|
||||
Barrier = config.getBoolean("Barrier", false);
|
||||
Space = config.getBoolean("Space", false);
|
||||
|
||||
EventKampfID = Integer.parseInt(System.getProperty("fightID", "0"));
|
||||
if (EventKampfID >= 1) {
|
||||
EventKampf = EventFight.get(EventKampfID);
|
||||
if (EventKampf == null) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Failed to load EventFight");
|
||||
Bukkit.shutdown();
|
||||
}
|
||||
assert EventKampf != null;
|
||||
|
||||
Team team1 = Team.get(EventKampf.getTeamBlue());
|
||||
Team team2 = Team.get(EventKampf.getTeamRed());
|
||||
|
||||
if (team1 == null || team2 == null) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Failed to load Team");
|
||||
Bukkit.shutdown();
|
||||
}
|
||||
assert team1 != null;
|
||||
assert team2 != null;
|
||||
|
||||
TeamBlueName = team1.getTeamKuerzel();
|
||||
TeamRedName = team2.getTeamKuerzel();
|
||||
TeamBlueColor = "§" + team1.getTeamColor();
|
||||
TeamRedColor = "§" + team2.getTeamColor();
|
||||
EventTeamBlueID = team1.getTeamId();
|
||||
EventTeamRedID = team2.getTeamId();
|
||||
|
||||
Event event = Event.get(EventKampf.getEventID());
|
||||
if (EventTeamBlueID == 0 && EventTeamRedID == 0) {
|
||||
MaximumTeamMembers = Integer.MAX_VALUE;
|
||||
} else {
|
||||
MaximumTeamMembers = event.getMaximumTeamMembers();
|
||||
}
|
||||
} else {
|
||||
EventKampf = null;
|
||||
TeamBlueName = "Blau";
|
||||
TeamRedName = "Rot";
|
||||
TeamBlueColor = "§3";
|
||||
TeamRedColor = "§c";
|
||||
EventTeamBlueID = 0;
|
||||
EventTeamRedID = 0;
|
||||
MaximumTeamMembers = Integer.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isEvent() {
|
||||
return EventKampfID >= 1;
|
||||
}
|
||||
|
||||
public static boolean isChallenge() {
|
||||
return BlueLeader != null && RedLeader != null;
|
||||
}
|
||||
|
||||
public static boolean test() {
|
||||
public static boolean test(){
|
||||
return EventKampfID == -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -37,8 +37,8 @@ public class FightInfoPacketSender implements Runnable {
|
||||
private final String serverName = Bukkit.getServer().getName();
|
||||
private final String gameMode = "missilewars";
|
||||
private final String worldName = world.getName();
|
||||
private final String blueName = Config.TeamBlueColor + Config.TeamBlueName;
|
||||
private final String redName = Config.TeamRedColor + Config.TeamRedName;
|
||||
private final String blueName = "§3blue";
|
||||
private final String redName = "§cred";
|
||||
private final int blueLeader = Config.BlueLeader != null ? SteamwarUser.get(Config.BlueLeader).getId() : 0;
|
||||
private final int redLeader = Config.RedLeader != null ? SteamwarUser.get(Config.RedLeader).getId() : 0;
|
||||
|
||||
|
@ -19,31 +19,24 @@
|
||||
|
||||
package de.steamwar.misslewars;
|
||||
|
||||
import de.steamwar.scoreboard.SWScoreboard;
|
||||
import de.steamwar.scoreboard.ScoreboardCallback;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Modified Version of the Fight-System Scoreboard
|
||||
*/
|
||||
class FightScoreboard implements Listener {
|
||||
class FightScoreboard {
|
||||
|
||||
public FightScoreboard() {
|
||||
Bukkit.getPluginManager().registerEvents(this, MissileWars.getPlugin());
|
||||
}
|
||||
private FightScoreboard(){}
|
||||
|
||||
private static final Scoreboard scoreboard = Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard();
|
||||
private static final Objective objective;
|
||||
private static final SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
|
||||
|
||||
private static long startTime = 0;
|
||||
|
||||
@ -51,37 +44,34 @@ class FightScoreboard implements Listener {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
SWScoreboard.createScoreboard(event.getPlayer(), new ScoreboardCallback() {
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return "§eMissileWars";
|
||||
static{
|
||||
if(scoreboard.getObjective("AAA") == null)
|
||||
objective = scoreboard.registerNewObjective("AAA", "BBB", "MissleWars");
|
||||
else
|
||||
objective = scoreboard.getObjective("AAA");
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, Integer> getData() {
|
||||
HashMap<String, Integer> data = new HashMap<>();
|
||||
data.put("§eSpielzeit", 5);
|
||||
static void init(){
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(MissileWars.getPlugin(), () -> {
|
||||
objective.unregister();
|
||||
scoreboard.registerNewObjective("AAA", "BBB", "MissleWars");
|
||||
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
objective.setDisplayName("§eMissileWars");
|
||||
|
||||
objective.getScore("§eSpielzeit").setScore(5);
|
||||
if (startTime == 0) {
|
||||
data.put("§7??:??:??", 4);
|
||||
objective.getScore("§7??:??:??").setScore(4);
|
||||
} else {
|
||||
long current_time = System.currentTimeMillis() - startTime;
|
||||
data.put(String.format("§7%02d:%02d", current_time / 60000, (current_time / 1000) % 60), 4);
|
||||
objective.getScore(String.format("§7%02d:%02d", current_time / 60000, (current_time / 1000) % 60)).setScore(4);
|
||||
}
|
||||
objective.getScore("").setScore(3);
|
||||
objective.getScore("§eSpieler").setScore(2);
|
||||
MissileWars.getBlueTeam().teamScoreboard(objective);
|
||||
MissileWars.getRedTeam().teamScoreboard(objective);
|
||||
|
||||
data.put("", 3);
|
||||
data.put("§eSpieler", 2);
|
||||
MissileWars.getBlueTeam().teamScoreboard(data);
|
||||
MissileWars.getRedTeam().teamScoreboard(data);
|
||||
return data;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
SWScoreboard.removeScoreboard(event.getPlayer());
|
||||
Bukkit.getOnlinePlayers().forEach(player -> player.setScoreboard(scoreboard));
|
||||
}, 0, 50);
|
||||
}
|
||||
|
||||
static Scoreboard getScoreboard() {
|
||||
@ -91,4 +81,5 @@ class FightScoreboard implements Listener {
|
||||
static void startTime() {
|
||||
startTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,11 +22,11 @@
|
||||
package de.steamwar.misslewars;
|
||||
|
||||
import de.steamwar.core.CraftbukkitWrapper;
|
||||
import net.minecraft.world.level.chunk.Chunk;
|
||||
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_20_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -36,6 +36,11 @@ 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;
|
||||
@ -64,7 +69,11 @@ public class FightWorld {
|
||||
}
|
||||
|
||||
public static void resetWorld(){
|
||||
world.getEntities().stream().filter(entity -> entity.getType() != EntityType.PLAYER).forEach(Entity::remove);
|
||||
for(Entity entity : world.getEntities()){
|
||||
if(entity.getType() != EntityType.PLAYER){
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
|
||||
World backup = new WorldCreator(world.getName() + "/backup").createWorld();
|
||||
assert backup != null;
|
||||
@ -73,12 +82,21 @@ public class FightWorld {
|
||||
}
|
||||
|
||||
private static void resetChunk(World world, World backup, int x, int z) {
|
||||
Chunk chunk = ((CraftWorld) world).getHandle().d(x, z);
|
||||
Chunk backupChunk = ((CraftWorld) backup).getHandle().d(x, 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.d(), 0, chunk.d(), 0, chunk.d().length);
|
||||
|
||||
for(Player p : Bukkit.getOnlinePlayers())
|
||||
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()){
|
||||
CraftbukkitWrapper.impl.sendChunk(p, x, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,23 +19,19 @@
|
||||
|
||||
package de.steamwar.misslewars;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class MWTeam {
|
||||
public static final ItemStack bow = new ItemStack(Material.BOW);
|
||||
private static final ItemStack bow = new ItemStack(Material.BOW);
|
||||
|
||||
static {
|
||||
ItemMeta bowMeta = Objects.requireNonNull(bow.getItemMeta());
|
||||
@ -47,30 +43,27 @@ public class MWTeam {
|
||||
bow.setItemMeta(bowMeta);
|
||||
}
|
||||
|
||||
private final String color;
|
||||
private final ChatColor color;
|
||||
private final String teamName;
|
||||
private final Team sbteam; //scoreboard-Team
|
||||
@Getter
|
||||
private final Location spawn;
|
||||
@Getter
|
||||
private final int portalZ;
|
||||
|
||||
@Getter
|
||||
private final LinkedList<Player> players = new LinkedList<>();
|
||||
private final Set<Player> openInvitations = new HashSet<>();
|
||||
|
||||
MWTeam(String color, Location spawn, String teamName, int portalZ) {
|
||||
MWTeam(ChatColor color, Location spawn, String teamName, int portalZ) {
|
||||
this.teamName = teamName;
|
||||
this.color = color;
|
||||
this.spawn = spawn;
|
||||
this.portalZ = portalZ;
|
||||
if (FightScoreboard.getScoreboard().getTeam(teamName) == null)
|
||||
if(FightScoreboard.getScoreboard().getTeam(teamName) == null)
|
||||
sbteam = FightScoreboard.getScoreboard().registerNewTeam(teamName);
|
||||
else
|
||||
sbteam = FightScoreboard.getScoreboard().getTeam(teamName);
|
||||
assert sbteam != null;
|
||||
sbteam.setAllowFriendlyFire(false);
|
||||
sbteam.setColor(ChatColor.getByChar(color.charAt(1)));
|
||||
sbteam.setColor(color);
|
||||
}
|
||||
|
||||
public void countdown(int timeDelay, int offset) {
|
||||
@ -88,43 +81,6 @@ public class MWTeam {
|
||||
}
|
||||
}
|
||||
|
||||
private int getUsesOfItem(ItemStack itemStack) {
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
if (itemMeta instanceof Damageable) {
|
||||
Damageable damageable = (Damageable) itemMeta;
|
||||
return itemStack.getType().getMaxDurability() - damageable.getDamage();
|
||||
}
|
||||
return 1_000_000;
|
||||
}
|
||||
|
||||
private boolean hasUses(ItemStack itemStack) {
|
||||
switch (itemStack.getType()) {
|
||||
case WOODEN_AXE:
|
||||
case STONE_AXE:
|
||||
case IRON_AXE:
|
||||
case GOLDEN_AXE:
|
||||
case DIAMOND_AXE:
|
||||
case NETHERITE_AXE:
|
||||
// return true;
|
||||
case WOODEN_SHOVEL:
|
||||
case STONE_SHOVEL:
|
||||
case IRON_SHOVEL:
|
||||
case GOLDEN_SHOVEL:
|
||||
case DIAMOND_SHOVEL:
|
||||
case NETHERITE_SHOVEL:
|
||||
// return true;
|
||||
case WOODEN_PICKAXE:
|
||||
case STONE_PICKAXE:
|
||||
case IRON_PICKAXE:
|
||||
case GOLDEN_PICKAXE:
|
||||
case DIAMOND_PICKAXE:
|
||||
case NETHERITE_PICKAXE:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void givePlayerItem(ItemStack item) {
|
||||
if (players.isEmpty()) {
|
||||
return;
|
||||
@ -133,44 +89,42 @@ public class MWTeam {
|
||||
players.addLast(p);
|
||||
|
||||
Inventory inventory = p.getInventory();
|
||||
for (int i = 0; i <= 35; i++) { // 35 is the last normal inventory slot
|
||||
for (int i = 0; i <= 35; i++) { //35 is the last normal inventory slot
|
||||
ItemStack itemStack = inventory.getItem(i);
|
||||
if (itemStack == null) continue;
|
||||
if (itemStack.isSimilar(item) && itemStack.getAmount() + item.getAmount() <= item.getMaxStackSize()) {
|
||||
if (itemStack != null && itemStack.isSimilar(item) && itemStack.getAmount() + item.getAmount() <= itemStack.getMaxStackSize()) {
|
||||
itemStack.setAmount(itemStack.getAmount() + item.getAmount());
|
||||
inventory.setItem(i, itemStack);
|
||||
return;
|
||||
}
|
||||
if (hasUses(itemStack) && hasUses(item) && getUsesOfItem(itemStack) + getUsesOfItem(item) <= itemStack.getType().getMaxDurability()) {
|
||||
int uses = getUsesOfItem(itemStack) + getUsesOfItem(item);
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
Damageable damageable = (Damageable) itemMeta;
|
||||
damageable.setDamage(itemStack.getType().getMaxDurability() - uses);
|
||||
itemStack.setItemMeta(damageable);
|
||||
inventory.setItem(i, itemStack);
|
||||
p.updateInventory();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i <= 35; i++) { // 35 is the last normal inventory slot
|
||||
for (int i = 0; i <= 35; i++) { //35 is the last normal inventory slot
|
||||
ItemStack itemStack = inventory.getItem(i);
|
||||
if (itemStack == null || itemStack.getType().equals(Material.AIR)) {
|
||||
inventory.setItem(i, item);
|
||||
p.updateInventory();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void teamScoreboard(HashMap<String, Integer> data) {
|
||||
players.forEach(player -> {
|
||||
data.put(getColorCode() + player.getName(), 1);
|
||||
});
|
||||
public void teamScoreboard(Objective objective) {
|
||||
players.forEach(p -> objective.getScore(getColorCode() + p.getName()).setScore(1));
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return players.size();
|
||||
}
|
||||
|
||||
public int getPortalZ() {
|
||||
return portalZ;
|
||||
}
|
||||
|
||||
public Location getSpawn(){
|
||||
return spawn;
|
||||
}
|
||||
|
||||
public void join(Player p) {
|
||||
players.add(p);
|
||||
p.teleport(spawn);
|
||||
@ -228,8 +182,8 @@ public class MWTeam {
|
||||
return MissileWars.getRedTeam();
|
||||
}
|
||||
|
||||
public String getColorCode() {
|
||||
return color;
|
||||
public String getColorCode(){
|
||||
return "§" + color.getChar();
|
||||
}
|
||||
|
||||
public boolean hasPlayer(Player p) {
|
||||
@ -241,11 +195,16 @@ public class MWTeam {
|
||||
}
|
||||
|
||||
public String getColoredName() {
|
||||
return color + teamName;
|
||||
return color.toString() + teamName;
|
||||
}
|
||||
|
||||
public LinkedList<Player> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
public static void removeInvitations(Player p) {
|
||||
MissileWars.getRedTeam().openInvitations.remove(p);
|
||||
MissileWars.getBlueTeam().openInvitations.remove(p);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
This file is a part of the SteamWar software.
|
||||
|
||||
Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
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
|
||||
@ -19,23 +19,21 @@
|
||||
|
||||
package de.steamwar.misslewars;
|
||||
|
||||
import de.steamwar.misslewars.commands.AcceptCommand;
|
||||
import de.steamwar.misslewars.commands.DeclineCommand;
|
||||
import de.steamwar.misslewars.commands.InviteCommand;
|
||||
import de.steamwar.misslewars.commands.SpectateCommand;
|
||||
import de.steamwar.misslewars.commands.CommandAcceptDecline;
|
||||
import de.steamwar.misslewars.commands.CommandInvite;
|
||||
import de.steamwar.misslewars.commands.CommandItems;
|
||||
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.CustomItem;
|
||||
import de.steamwar.misslewars.items.Missile;
|
||||
import de.steamwar.misslewars.listener.*;
|
||||
import de.steamwar.misslewars.listener.special.BarrierListener;
|
||||
import de.steamwar.misslewars.listener.special.SpaceListener;
|
||||
import de.steamwar.misslewars.slowmo.SlowMoRunner;
|
||||
import de.steamwar.network.NetworkSender;
|
||||
import de.steamwar.network.packets.common.FightEndsPacket;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -61,8 +59,8 @@ public class MissileWars extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
redTeam = new MWTeam(Config.TeamRedColor, Config.RedSpawn, Config.TeamRedName, Config.RedPortalZ);
|
||||
blueTeam = new MWTeam(Config.TeamBlueColor, Config.BlueSpawn, Config.TeamBlueName, Config.BluePortalZ);
|
||||
redTeam = new MWTeam(ChatColor.RED, Config.RedSpawn, "Rot", Config.RedPortalZ);
|
||||
blueTeam = new MWTeam(ChatColor.DARK_AQUA, Config.BlueSpawn, "Blau", Config.BluePortalZ);
|
||||
new BreakListener();
|
||||
new DeathListener();
|
||||
new ItemListener();
|
||||
@ -74,35 +72,31 @@ public class MissileWars extends JavaPlugin {
|
||||
new WaitingListener();
|
||||
new FightListener();
|
||||
new ChatListener();
|
||||
new SpectateCommand();
|
||||
getCommand("spectate").setExecutor(new CommandSpectate());
|
||||
|
||||
// Invitation Commands
|
||||
new InviteCommand();
|
||||
new AcceptCommand();
|
||||
new DeclineCommand();
|
||||
CommandInvite commandInvite = new CommandInvite();
|
||||
getCommand("invite").setExecutor(commandInvite);
|
||||
getCommand("invite").setTabCompleter(commandInvite);
|
||||
|
||||
getCommand("accept").setExecutor(new CommandAcceptDecline());
|
||||
getCommand("decline").setExecutor(new CommandAcceptDecline());
|
||||
|
||||
new WaitingCountdown();
|
||||
new ItemCountdown();
|
||||
new EndCountdown();
|
||||
|
||||
new FightScoreboard();
|
||||
FightScoreboard.init();
|
||||
|
||||
Missile.init();
|
||||
CustomItem.init();
|
||||
|
||||
StateDependent.setupState(fightState);
|
||||
|
||||
new BarrierListener();
|
||||
new SpaceListener();
|
||||
|
||||
Bukkit.getScheduler().runTaskTimer(this, new FightInfoPacketSender(), 20, 20);
|
||||
|
||||
Bukkit.getWorlds().forEach(world -> {
|
||||
world.setGameRule(GameRule.KEEP_INVENTORY, true);
|
||||
world.setGameRule(GameRule.MOB_GRIEFING, true);
|
||||
world.setGameRule(GameRule.DO_TILE_DROPS, false);
|
||||
});
|
||||
|
||||
// TODO: Enable Item Dropping, and the own team can pick them up! Add config value for that?
|
||||
if(Config.test()) {
|
||||
new CommandItems();
|
||||
}
|
||||
}
|
||||
|
||||
public static void waiting() {
|
||||
@ -149,23 +143,6 @@ public class MissileWars extends JavaPlugin {
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
}
|
||||
|
||||
byte ergebnis = winner == blueTeam ? (byte) 1 : (byte) 2;
|
||||
if (Config.isEvent()) {
|
||||
Config.EventKampf.setErgebnis(ergebnis);
|
||||
}
|
||||
if (Config.isEvent() || Config.isChallenge()) {
|
||||
FightEndsPacket packet = FightEndsPacket.builder()
|
||||
.gameMode("MissileWars")
|
||||
.duration((int)((System.currentTimeMillis() - FightScoreboard.getStartTime()) / 1000))
|
||||
.win(ergebnis)
|
||||
.bluePlayers(blueTeam.getPlayers().stream().map(Player::getUniqueId).map(SteamwarUser::get).map(SteamwarUser::getId).collect(Collectors.toList()))
|
||||
.redPlayers(redTeam.getPlayers().stream().map(Player::getUniqueId).map(SteamwarUser::get).map(SteamwarUser::getId).collect(Collectors.toList()))
|
||||
.blueSchem(-1)
|
||||
.redSchem(-1)
|
||||
.build();
|
||||
NetworkSender.send(packet);
|
||||
}
|
||||
|
||||
switch (reason) {
|
||||
case PORTAL_DESTROYED:
|
||||
Bukkit.getServer().broadcastMessage(winner.getColoredName() + ChatColor.RESET + " §7hat das gegnerische Portal zerstört");
|
||||
@ -209,6 +186,14 @@ public class MissileWars extends JavaPlugin {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void join(Player p) {
|
||||
if (MissileWars.getRedTeam().size() < MissileWars.getBlueTeam().size()) {
|
||||
MissileWars.getRedTeam().join(p);
|
||||
} else {
|
||||
MissileWars.getBlueTeam().join(p);
|
||||
}
|
||||
}
|
||||
|
||||
public static void leave(Player p) {
|
||||
MissileWars.getBlueTeam().leave(p);
|
||||
MissileWars.getRedTeam().leave(p);
|
||||
|
@ -2,7 +2,7 @@
|
||||
*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
* 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
|
||||
@ -16,55 +16,49 @@
|
||||
*
|
||||
* 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.commands;
|
||||
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.TypeValidator;
|
||||
import de.steamwar.misslewars.Config;
|
||||
import de.steamwar.misslewars.MWTeam;
|
||||
import de.steamwar.misslewars.MissileWars;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class AcceptCommand extends SWCommand {
|
||||
public class CommandAcceptDecline implements CommandExecutor {
|
||||
|
||||
public AcceptCommand() {
|
||||
super("accept");
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) return false;
|
||||
Player player = (Player) sender;
|
||||
if (!Config.isChallenge()) {
|
||||
player.sendMessage("§cDieser Command ist deaktiviert.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Register
|
||||
public void onCommand(@Validator Player player, String... varargs) {
|
||||
MWTeam teamInvitation = MissileWars.getInvitation(player);
|
||||
if (teamInvitation == null) {
|
||||
player.sendMessage("§cDu wurdest nicht eingeladen.");
|
||||
} else {
|
||||
teamInvitation.acceptInvite(player);
|
||||
message(teamInvitation, "§7Der Spieler §e" + player.getName() + "§7 ist dem Team §abeigetreten§7.");
|
||||
}
|
||||
}
|
||||
|
||||
@ClassValidator(value = Player.class, local = true)
|
||||
public TypeValidator<Player> validator() {
|
||||
return new TypeValidator<Player>() {
|
||||
@Override
|
||||
public boolean validate(CommandSender commandSender, Player player, MessageSender messageSender) {
|
||||
if (!Config.isChallenge()) {
|
||||
messageSender.send("§cDieser Command ist deaktiviert.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sendMessage(CommandSender sender, String message, Object[] args) {
|
||||
sender.sendMessage(message);
|
||||
if (command.getName().equalsIgnoreCase("accept")) {
|
||||
teamInvitation.acceptInvite(player);
|
||||
message(teamInvitation, "§7Der Spieler §e" + player.getName() + "§7 ist dem Team §abeigetreten§7.");
|
||||
} else {
|
||||
MWTeam.removeInvitations(player);
|
||||
message(teamInvitation, "§7Der Spieler §e" + player.getName() + "§7 hat die Einladung §cabgelehnt§7.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void message(MWTeam mwTeam, String s) {
|
||||
mwTeam.getPlayers().forEach(player -> player.sendMessage(s));
|
||||
}
|
||||
|
||||
}
|
95
src/de/steamwar/misslewars/commands/CommandInvite.java
Normale Datei
95
src/de/steamwar/misslewars/commands/CommandInvite.java
Normale Datei
@ -0,0 +1,95 @@
|
||||
/*
|
||||
*
|
||||
* 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.commands;
|
||||
|
||||
import de.steamwar.misslewars.Config;
|
||||
import de.steamwar.misslewars.MWTeam;
|
||||
import de.steamwar.misslewars.MissileWars;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandInvite implements CommandExecutor, TabCompleter {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) return false;
|
||||
Player player = (Player) sender;
|
||||
if (!Config.isChallenge()) {
|
||||
player.sendMessage("§cDieser Command ist deaktiviert.");
|
||||
return false;
|
||||
}
|
||||
|
||||
MWTeam team = MissileWars.getTeam(player);
|
||||
if (!Config.RedLeader.equals(player.getUniqueId()) && !Config.BlueLeader.equals(player.getUniqueId()) || team == null) {
|
||||
player.sendMessage("§cDu kannst keine Spieler einladen.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.length != 1) {
|
||||
player.sendMessage("§c/invite <PLAYER>");
|
||||
return false;
|
||||
}
|
||||
|
||||
Player invitedPlayer = Bukkit.getPlayer(args[0]);
|
||||
if (invitedPlayer == null) {
|
||||
player.sendMessage("§cDieser Spieler ist nicht online.");
|
||||
return false;
|
||||
}
|
||||
if (MissileWars.getTeam(invitedPlayer) != null) {
|
||||
player.sendMessage("§cDieser Spieler ist bereits in einem Team.");
|
||||
return false;
|
||||
}
|
||||
if (MissileWars.getInvitation(invitedPlayer) != null) {
|
||||
player.sendMessage("§cDieser Spieler wurde bereits eingeladen.");
|
||||
return false;
|
||||
}
|
||||
|
||||
team.invitePlayer(invitedPlayer);
|
||||
player.sendMessage("§7Du hast §e" + invitedPlayer.getName() + " §7eingeladen.");
|
||||
invitedPlayer.sendMessage("§7Du wurdest von §e" + player.getName() + "§7 in das Team §e" + MissileWars.getTeam(player).getColoredName() + "§7 eingeladen.");
|
||||
invitedPlayer.sendMessage("§8/§eaccept §8- §7Zum akzeptieren.");
|
||||
invitedPlayer.sendMessage("§8/§edecline §8- §7Zum ablehnen.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length == 1) {
|
||||
return Bukkit.getOnlinePlayers()
|
||||
.stream()
|
||||
.filter(p -> MissileWars.getTeam(p) != null)
|
||||
.filter(p -> MissileWars.getInvitation(p) != null)
|
||||
.map(Player::getName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
24
src/de/steamwar/misslewars/commands/CommandItems.java
Normale Datei
24
src/de/steamwar/misslewars/commands/CommandItems.java
Normale Datei
@ -0,0 +1,24 @@
|
||||
package de.steamwar.misslewars.commands;
|
||||
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.inventory.SWListInv;
|
||||
import de.steamwar.misslewars.items.SpecialItem;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandItems extends SWCommand {
|
||||
public CommandItems() {
|
||||
super("give");
|
||||
}
|
||||
|
||||
public void genericCommand(Player player, String[] args) {
|
||||
SWListInv<ItemStack> inv = new SWListInv<>(player, "Misslewars Items", SpecialItem.getAllItems().stream().map(item -> new SWListInv.SWListEntry<>(new SWItem(item.getType(), item.getItemMeta().getDisplayName()), item)).collect(Collectors.toList()), (clickType, itemStack) -> {
|
||||
player.closeInventory();
|
||||
player.getInventory().addItem(itemStack);
|
||||
});
|
||||
inv.open();
|
||||
}
|
||||
}
|
55
src/de/steamwar/misslewars/commands/CommandSpectate.java
Normale Datei
55
src/de/steamwar/misslewars/commands/CommandSpectate.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.commands;
|
||||
|
||||
import de.steamwar.misslewars.Config;
|
||||
import de.steamwar.misslewars.MWTeam;
|
||||
import de.steamwar.misslewars.MissileWars;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CommandSpectate implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) return false;
|
||||
Player player = (Player) sender;
|
||||
if (Config.isChallenge()) {
|
||||
player.sendMessage("§cDieser Command ist deaktiviert.");
|
||||
return false;
|
||||
}
|
||||
|
||||
MWTeam mwTeam = MissileWars.getTeam(player);
|
||||
if (mwTeam == null) return false;
|
||||
if (mwTeam.size() == 1) {
|
||||
player.sendMessage("§cDu bist alleine im Team, zuschauen ist daher nicht möglich.");
|
||||
return false;
|
||||
}
|
||||
MissileWars.leave(player);
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
player.getInventory().clear();
|
||||
player.updateInventory();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.commands;
|
||||
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.TypeValidator;
|
||||
import de.steamwar.misslewars.Config;
|
||||
import de.steamwar.misslewars.MWTeam;
|
||||
import de.steamwar.misslewars.MissileWars;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class DeclineCommand extends SWCommand {
|
||||
|
||||
public DeclineCommand() {
|
||||
super("decline");
|
||||
}
|
||||
|
||||
@Register
|
||||
public void onCommand(@Validator Player player, String... varargs) {
|
||||
MWTeam teamInvitation = MissileWars.getInvitation(player);
|
||||
if (teamInvitation == null) {
|
||||
player.sendMessage("§cDu wurdest nicht eingeladen.");
|
||||
} else {
|
||||
MWTeam.removeInvitations(player);
|
||||
message(teamInvitation, "§7Der Spieler §e" + player.getName() + "§7 hat die Einladung §cabgelehnt§7.");
|
||||
}
|
||||
}
|
||||
|
||||
@ClassValidator(value = Player.class, local = true)
|
||||
public TypeValidator<Player> validator() {
|
||||
return new TypeValidator<Player>() {
|
||||
@Override
|
||||
public boolean validate(CommandSender commandSender, Player player, MessageSender messageSender) {
|
||||
if (!Config.isChallenge()) {
|
||||
messageSender.send("§cDieser Command ist deaktiviert.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sendMessage(CommandSender sender, String message, Object[] args) {
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
|
||||
private void message(MWTeam mwTeam, String s) {
|
||||
mwTeam.getPlayers().forEach(player -> player.sendMessage(s));
|
||||
}
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.commands;
|
||||
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.TypeMapper;
|
||||
import de.steamwar.command.TypeValidator;
|
||||
import de.steamwar.misslewars.Config;
|
||||
import de.steamwar.misslewars.MWTeam;
|
||||
import de.steamwar.misslewars.MissileWars;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class InviteCommand extends SWCommand {
|
||||
|
||||
public InviteCommand() {
|
||||
super("invite", "inv");
|
||||
}
|
||||
|
||||
@Register
|
||||
public void onCommand(@Validator Player player, @AllowNull @OptionalValue("") Player invitedPlayer) {
|
||||
MWTeam team = MissileWars.getTeam(player);
|
||||
|
||||
if (!player.getUniqueId().equals(Config.RedLeader) && !player.getUniqueId().equals(Config.BlueLeader) || team == null) {
|
||||
player.sendMessage("§cDu kannst keine Spieler einladen.");
|
||||
} else if (invitedPlayer == null) {
|
||||
player.sendMessage("§cDieser Spieler ist nicht online.");
|
||||
} else if (MissileWars.getTeam(invitedPlayer) != null) {
|
||||
player.sendMessage("§cDieser Spieler ist bereits in einem Team.");
|
||||
} else if (MissileWars.getInvitation(invitedPlayer) != null) {
|
||||
player.sendMessage("§cDieser Spieler wurde bereits eingeladen.");
|
||||
} else {
|
||||
team.invitePlayer(invitedPlayer);
|
||||
player.sendMessage("§7Du hast §e" + invitedPlayer.getName() + " §7eingeladen.");
|
||||
invitedPlayer.sendMessage("§7Du wurdest von §e" + player.getName() + "§7 in das Team §e" + MissileWars.getTeam(player).getColoredName() + "§7 eingeladen.");
|
||||
invitedPlayer.sendMessage("§8/§eaccept §8- §7Zum akzeptieren.");
|
||||
invitedPlayer.sendMessage("§8/§edecline §8- §7Zum ablehnen.");
|
||||
}
|
||||
}
|
||||
|
||||
@ClassMapper(value = Player.class, local = true)
|
||||
public TypeMapper<Player> typeMapper() {
|
||||
return new TypeMapper<>() {
|
||||
@Override
|
||||
public Player map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||
return Bukkit.getPlayer(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
|
||||
return Bukkit.getOnlinePlayers()
|
||||
.stream()
|
||||
.filter(p -> MissileWars.getTeam(p) != null)
|
||||
.filter(p -> MissileWars.getInvitation(p) != null)
|
||||
.map(Player::getName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ClassValidator(value = Player.class, local = true)
|
||||
public TypeValidator<Player> validator() {
|
||||
return (commandSender, player, messageSender) -> {
|
||||
if (!Config.isChallenge()) {
|
||||
messageSender.send("§cDieser Command ist deaktiviert.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sendMessage(CommandSender sender, String message, Object[] args) {
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.commands;
|
||||
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.TypeValidator;
|
||||
import de.steamwar.misslewars.Config;
|
||||
import de.steamwar.misslewars.MWTeam;
|
||||
import de.steamwar.misslewars.MissileWars;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class SpectateCommand extends SWCommand {
|
||||
|
||||
public SpectateCommand() {
|
||||
super("spectate", "spec");
|
||||
}
|
||||
|
||||
@Register
|
||||
public void onCommand(@Validator Player player) {
|
||||
MWTeam mwTeam = MissileWars.getTeam(player);
|
||||
if (mwTeam == null) return;
|
||||
if (mwTeam.size() == 1) {
|
||||
player.sendMessage("§cDu bist alleine im Team, zuschauen ist daher nicht möglich.");
|
||||
}
|
||||
MissileWars.leave(player);
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
player.getInventory().clear();
|
||||
player.updateInventory();
|
||||
}
|
||||
|
||||
@ClassValidator(value = Player.class, local = true)
|
||||
public TypeValidator<Player> validator() {
|
||||
return new TypeValidator<Player>() {
|
||||
@Override
|
||||
public boolean validate(CommandSender commandSender, Player player, MessageSender messageSender) {
|
||||
if (Config.isChallenge()) {
|
||||
messageSender.send("§cDieser Command ist deaktiviert.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sendMessage(CommandSender sender, String message, Object[] args) {
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
}
|
@ -36,29 +36,14 @@ public class EndCountdown extends StateDependent {
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
if (Config.isEvent()) {
|
||||
task = Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), this::stop, 1200);
|
||||
} else {
|
||||
task = Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), this::restart, Config.EndTime);
|
||||
}
|
||||
}
|
||||
|
||||
private void restart() {
|
||||
FightWorld.resetWorld();
|
||||
MissileWars.waiting();
|
||||
}
|
||||
|
||||
private void stop() {
|
||||
//Staggered kick to prevent lobby overloading
|
||||
if(Bukkit.getOnlinePlayers().isEmpty()){
|
||||
Bukkit.shutdown();
|
||||
return;
|
||||
}
|
||||
|
||||
Bukkit.getOnlinePlayers().iterator().next().kickPlayer(null);
|
||||
Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), this::stop, 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
if (task != null && !task.isCancelled())
|
||||
|
@ -41,6 +41,11 @@ public class ItemCountdown extends StateDependent {
|
||||
}
|
||||
|
||||
private void run() {
|
||||
if (currenTime == 0) {
|
||||
ItemStack itemStack = SpecialItem.getRandomItem();
|
||||
MissileWars.getBlueTeam().givePlayerItem(itemStack);
|
||||
MissileWars.getRedTeam().givePlayerItem(itemStack);
|
||||
}
|
||||
currenTime++;
|
||||
|
||||
int teamCount = Math.max(MissileWars.getBlueTeam().size(), MissileWars.getRedTeam().size());
|
||||
|
@ -72,7 +72,7 @@ public class CustomItem extends SpecialItem {
|
||||
new CustomItem(new ScriptedItem(jsonObject));
|
||||
} catch (JsonSyntaxException | IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new SecurityException("Item JSON error " + itemFile, e);
|
||||
throw new SecurityException("Item JSON error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ import java.util.Objects;
|
||||
public class Missile extends SpecialItem {
|
||||
|
||||
private static final World world = new BukkitWorld(Bukkit.getWorlds().get(0));
|
||||
private static final int GRAPH_SIZE = 7;
|
||||
|
||||
private final Clipboard clipboard;
|
||||
private final ItemStack item;
|
||||
@ -69,8 +70,8 @@ public class Missile extends SpecialItem {
|
||||
}
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore(lore, strings, 2, "§7Speed");
|
||||
lore(lore, strings, 3, "§7Size");
|
||||
lore(lore, strings, 2, " §7Speed");
|
||||
lore(lore, strings, 3, " §7Size");
|
||||
|
||||
EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1);
|
||||
BlockTypeMask blockTypeMask = new BlockTypeMask(clipboard, BlockTypes.TNT);
|
||||
@ -81,11 +82,33 @@ public class Missile extends SpecialItem {
|
||||
|
||||
private void lore(List<String> lore, String[] args, int index, String tag) {
|
||||
if (args.length > index) {
|
||||
lore.add(tag + " §8: §e" + Integer.parseInt(args[index]) + "§8/§77");
|
||||
} else {
|
||||
lore.add(tag + " §8: §e0§8/§77");
|
||||
try {
|
||||
lore.add(graph(Integer.parseInt(args[index]), GRAPH_SIZE) + tag);
|
||||
return;
|
||||
} catch (NumberFormatException e) {
|
||||
// Ignored
|
||||
}
|
||||
}
|
||||
lore.add(graph(0, GRAPH_SIZE) + tag);
|
||||
}
|
||||
|
||||
private String graph(int index, int size) {
|
||||
if (index > size) index = size;
|
||||
StringBuilder st = new StringBuilder();
|
||||
st.append("§8[§e");
|
||||
if (index > 0) st.append(repeat(index));
|
||||
st.append("§7");
|
||||
st.append(repeat(size - index));
|
||||
st.append("§8]");
|
||||
return st.toString();
|
||||
}
|
||||
|
||||
private String repeat(int count) {
|
||||
if (count == 0) return "";
|
||||
StringBuilder st = new StringBuilder();
|
||||
for (int i = 0; i < count; i++) st.append("=");
|
||||
return st.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem() {
|
||||
|
@ -40,8 +40,7 @@ import java.util.Random;
|
||||
public abstract class SpecialItem {
|
||||
|
||||
private static final Random random = new Random();
|
||||
private static double count = 0;
|
||||
private static int consecutiveSupportItems = 0;
|
||||
private static boolean lastItemWasSupportItem = false;
|
||||
|
||||
private static List<SpecialItem> supportItems = new ArrayList<>();
|
||||
private static List<SpecialItem> missileItems = new ArrayList<>();
|
||||
@ -111,22 +110,20 @@ public abstract class SpecialItem {
|
||||
}
|
||||
|
||||
public static ItemStack getRandomItem() {
|
||||
if (Config.MissileChance == 0 || consecutiveSupportItems > 1) {
|
||||
consecutiveSupportItems = 0;
|
||||
if (!lastItemWasSupportItem && random.nextDouble() > Config.MissileChance) {
|
||||
lastItemWasSupportItem = true;
|
||||
return supportItems.get(random.nextInt(supportItems.size())).getItem();
|
||||
}
|
||||
if (Config.MissileChance == 1) {
|
||||
lastItemWasSupportItem = false;
|
||||
return missileItems.get(random.nextInt(missileItems.size())).getItem();
|
||||
}
|
||||
|
||||
double missileChance = Config.MissileChance + count * 0.1;
|
||||
if (random.nextDouble() > missileChance) {
|
||||
count += Config.MissileChance;
|
||||
consecutiveSupportItems++;
|
||||
return supportItems.get(random.nextInt(supportItems.size())).getItem();
|
||||
} else {
|
||||
count -= 1 - Config.MissileChance;
|
||||
return missileItems.get(random.nextInt(missileItems.size())).getItem();
|
||||
}
|
||||
public static List<ItemStack> getAllItems() {
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
for (SpecialItem specialItem : supportItems)
|
||||
items.add(specialItem.getItem());
|
||||
for (SpecialItem specialItem : missileItems)
|
||||
items.add(specialItem.getItem());
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
@ -21,15 +21,12 @@ package de.steamwar.misslewars.listener;
|
||||
|
||||
import de.steamwar.misslewars.Config;
|
||||
import de.steamwar.misslewars.FightState;
|
||||
import de.steamwar.misslewars.MWTeam;
|
||||
import de.steamwar.misslewars.MissileWars;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.event.entity.ItemDespawnEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
@ -37,7 +34,6 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerPickupArrowEvent;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ArenaListener extends BasicListener {
|
||||
@ -73,6 +69,11 @@ public class ArenaListener extends BasicListener {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onItemDrop(PlayerDropItemEvent e){
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onHunger(FoodLevelChangeEvent e){
|
||||
e.setCancelled(true);
|
||||
|
@ -31,7 +31,7 @@ import java.util.Set;
|
||||
public abstract class BasicListener extends StateDependent implements Listener {
|
||||
|
||||
|
||||
protected BasicListener(final Set<FightState> active){
|
||||
BasicListener(final Set<FightState> active){
|
||||
super(active);
|
||||
}
|
||||
|
||||
|
@ -20,47 +20,28 @@
|
||||
package de.steamwar.misslewars.listener;
|
||||
|
||||
import de.steamwar.misslewars.FightState;
|
||||
import de.steamwar.misslewars.MWTeam;
|
||||
import de.steamwar.misslewars.MissileWars;
|
||||
import de.steamwar.misslewars.items.SpecialItem;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||
import org.bukkit.event.entity.ItemDespawnEvent;
|
||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
import org.bukkit.event.entity.ProjectileLaunchEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class ItemListener extends BasicListener {
|
||||
|
||||
private Set<Integer> RED_ITEMS = new HashSet<>();
|
||||
private Set<Integer> BLUE_ITEMS = new HashSet<>();
|
||||
|
||||
public ItemListener() {
|
||||
super(EnumSet.of(FightState.FIGHTING));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
super.enable();
|
||||
RED_ITEMS.clear();
|
||||
BLUE_ITEMS.clear();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onItemClick(PlayerInteractEvent e) {
|
||||
ItemStack item = e.getItem();
|
||||
if (item == null)
|
||||
return;
|
||||
if (e.getPlayer().hasCooldown(item.getType())) return;
|
||||
|
||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK && e.getAction() != Action.RIGHT_CLICK_AIR)
|
||||
return;
|
||||
@ -82,42 +63,4 @@ public class ItemListener extends BasicListener {
|
||||
SpecialItem.handleHit(e);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onItemDrop(PlayerDropItemEvent e){
|
||||
MWTeam mwTeam = MissileWars.getTeam(e.getPlayer());
|
||||
if (mwTeam == null) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (e.getItemDrop().getItemStack().isSimilar(MWTeam.bow)) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (mwTeam == MissileWars.getRedTeam()) {
|
||||
RED_ITEMS.add(e.getItemDrop().getEntityId());
|
||||
} else {
|
||||
BLUE_ITEMS.add(e.getItemDrop().getEntityId());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityPickupItem(EntityPickupItemEvent e) {
|
||||
Player player = (Player) e.getEntity();
|
||||
MWTeam mwTeam = MissileWars.getTeam(player);
|
||||
if (mwTeam == null) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (mwTeam == MissileWars.getRedTeam() && !RED_ITEMS.contains(e.getItem().getEntityId())) {
|
||||
e.setCancelled(true);
|
||||
} else if (mwTeam == MissileWars.getBlueTeam() && !BLUE_ITEMS.contains(e.getItem().getEntityId())) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onItemDespawn(ItemDespawnEvent event) {
|
||||
RED_ITEMS.remove(event.getEntity().getEntityId());
|
||||
BLUE_ITEMS.remove(event.getEntity().getEntityId());
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ package de.steamwar.misslewars.listener;
|
||||
import de.steamwar.misslewars.Config;
|
||||
import de.steamwar.misslewars.FightState;
|
||||
import de.steamwar.misslewars.MissileWars;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -43,39 +42,7 @@ public class JoinListener extends BasicListener {
|
||||
}
|
||||
|
||||
public static void join(Player p) {
|
||||
if (Config.isEvent()) {
|
||||
joinEvent(p);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Config.isChallenge()) {
|
||||
joinChallenge(p);
|
||||
return;
|
||||
}
|
||||
|
||||
joinNormal(p);
|
||||
}
|
||||
|
||||
private static void joinEvent(Player p) {
|
||||
if (Config.EventTeamRedID == 0 && Config.EventTeamBlueID == 0) {
|
||||
joinNormal(p);
|
||||
return;
|
||||
}
|
||||
|
||||
int teamId = SteamwarUser.get(p.getUniqueId()).getTeam();
|
||||
if (teamId != Config.EventTeamRedID && teamId != Config.EventTeamBlueID) {
|
||||
teamId = 0;
|
||||
}
|
||||
if (teamId == Config.EventTeamRedID && MissileWars.getRedTeam().size() < Config.MaximumTeamMembers) {
|
||||
MissileWars.getRedTeam().join(p);
|
||||
} else if (teamId == Config.EventTeamBlueID && MissileWars.getBlueTeam().size() < Config.MaximumTeamMembers) {
|
||||
MissileWars.getBlueTeam().join(p);
|
||||
} else {
|
||||
p.teleport(MissileWars.getRedTeam().getSpawn().toVector().midpoint(MissileWars.getBlueTeam().getSpawn().toVector()).toLocation(p.getWorld()));
|
||||
}
|
||||
}
|
||||
|
||||
private static void joinChallenge(Player p) {
|
||||
if (Config.RedLeader.equals(p.getUniqueId())) {
|
||||
MissileWars.getRedTeam().join(p);
|
||||
} else if (Config.BlueLeader.equals(p.getUniqueId())) {
|
||||
@ -83,19 +50,8 @@ public class JoinListener extends BasicListener {
|
||||
} else {
|
||||
p.teleport(MissileWars.getRedTeam().getSpawn().toVector().midpoint(MissileWars.getBlueTeam().getSpawn().toVector()).toLocation(p.getWorld()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
private static void joinNormal(Player p) {
|
||||
if (MissileWars.getRedTeam().size() == MissileWars.getBlueTeam().size()) {
|
||||
if (Math.random() > 0.5) {
|
||||
MissileWars.getRedTeam().join(p);
|
||||
} else {
|
||||
MissileWars.getBlueTeam().join(p);
|
||||
}
|
||||
} else if (MissileWars.getRedTeam().size() < MissileWars.getBlueTeam().size()) {
|
||||
MissileWars.getRedTeam().join(p);
|
||||
} else {
|
||||
MissileWars.getBlueTeam().join(p);
|
||||
}
|
||||
MissileWars.join(p);
|
||||
}
|
||||
}
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* 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.listener.special;
|
||||
|
||||
import de.steamwar.misslewars.Config;
|
||||
import de.steamwar.misslewars.FightState;
|
||||
import de.steamwar.misslewars.listener.BasicListener;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
public class BarrierListener extends BasicListener {
|
||||
|
||||
public BarrierListener() {
|
||||
super(EnumSet.allOf(FightState.class));
|
||||
}
|
||||
|
||||
private int middle = Config.ArenaMinZ + (Config.ArenaMaxZ - Config.ArenaMinZ) / 2;
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPhysics(BlockPhysicsEvent event) {
|
||||
if (!Config.Barrier) return;
|
||||
Block block = event.getBlock();
|
||||
if (block.getZ() > middle - 10 && block.getZ() < middle + 10) {
|
||||
switch (block.getType()) {
|
||||
case SLIME_BLOCK:
|
||||
case HONEY_BLOCK:
|
||||
case TNT:
|
||||
block.setType(Material.AIR);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* 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.listener.special;
|
||||
|
||||
import de.steamwar.misslewars.Config;
|
||||
import de.steamwar.misslewars.FightState;
|
||||
import de.steamwar.misslewars.MissileWars;
|
||||
import de.steamwar.misslewars.listener.BasicListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
public class SpaceListener extends BasicListener {
|
||||
|
||||
public SpaceListener() {
|
||||
super(EnumSet.allOf(FightState.class));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if (!Config.Space) return;
|
||||
Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), () -> {
|
||||
Player player = event.getPlayer();
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE, 3));
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, Integer.MAX_VALUE, 3));
|
||||
player.setHealth(0.5);
|
||||
player.setHealthScale(0.5);
|
||||
}, 5);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
if (!Config.Space) return;
|
||||
Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), () -> {
|
||||
Player player = event.getPlayer();
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE, 3));
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, Integer.MAX_VALUE, 3));
|
||||
player.setHealth(0.5);
|
||||
player.setHealthScale(0.5);
|
||||
}, 5);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntitySpawn(EntitySpawnEvent event) {
|
||||
if (!Config.Space) return;
|
||||
if (event.getEntity() instanceof Player) return;
|
||||
event.getEntity().setGravity(false);
|
||||
Vector vector = event.getEntity().getVelocity();
|
||||
if (event.getEntity() instanceof TNTPrimed) {
|
||||
vector.setY(0);
|
||||
}
|
||||
event.getEntity().setVelocity(vector);
|
||||
}
|
||||
}
|
@ -87,8 +87,6 @@ public class Script {
|
||||
return new SlowMoScript(jsonObject);
|
||||
case "cooldown":
|
||||
return new CooldownScript(jsonObject);
|
||||
case "randomplayer":
|
||||
return new RandomPlayerScript(jsonObject);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
@ -24,9 +24,7 @@ import de.steamwar.misslewars.scripts.utils.JsonUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LingeringPotion;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
@ -46,7 +44,6 @@ public class ScriptedItem {
|
||||
// "lore": Lore array (OPTIONAL STRING.ARRAY)
|
||||
// "amount": Item amount (OPTIONAL [default 1] INT)
|
||||
// "potion": Object with key value pairs for PotionType and Object containing duration and amplifier (OPTIONAL OBJECT)
|
||||
// "uses": Uses of Item (OPTIONAL INT)
|
||||
// "EVENT.<eventName>": Event (OPTIONAL JSONobject.ARRAY)
|
||||
// - onClick
|
||||
// - onHit
|
||||
@ -101,12 +98,6 @@ public class ScriptedItem {
|
||||
});
|
||||
}
|
||||
|
||||
if (jsonObject.has("uses") && itemMeta instanceof Damageable) {
|
||||
int uses = jsonObject.getAsJsonPrimitive("uses").getAsInt();
|
||||
Damageable damageable = (Damageable) itemMeta;
|
||||
damageable.setDamage(itemStack.getType().getMaxDurability() - uses);
|
||||
}
|
||||
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
return itemStack;
|
||||
}
|
||||
@ -124,4 +115,5 @@ public class ScriptedItem {
|
||||
public String getEntityName() {
|
||||
return entityName;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,12 +2,9 @@ package de.steamwar.misslewars.scripts.implemented;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import de.steamwar.misslewars.MissileWars;
|
||||
import de.steamwar.misslewars.scripts.RunnableScript;
|
||||
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class CooldownScript implements RunnableScript {
|
||||
|
||||
@ -20,12 +17,8 @@ public class CooldownScript implements RunnableScript {
|
||||
|
||||
@Override
|
||||
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
|
||||
Material mainHand = runnableScriptEvent.getPlayer().getInventory().getItemInMainHand().getType();
|
||||
Material offHand = runnableScriptEvent.getPlayer().getInventory().getItemInOffHand().getType();
|
||||
Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), () -> {
|
||||
if (mainHand != Material.AIR) runnableScriptEvent.getPlayer().setCooldown(mainHand, cooldown);
|
||||
if (offHand != Material.AIR) runnableScriptEvent.getPlayer().setCooldown(offHand, cooldown);
|
||||
}, 1);
|
||||
if (runnableScriptEvent.getPlayer().getInventory().getItemInMainHand().getType() != Material.AIR) runnableScriptEvent.getPlayer().setCooldown(runnableScriptEvent.getPlayer().getInventory().getItemInMainHand().getType(), cooldown);
|
||||
if (runnableScriptEvent.getPlayer().getInventory().getItemInOffHand().getType() != Material.AIR) runnableScriptEvent.getPlayer().setCooldown(runnableScriptEvent.getPlayer().getInventory().getItemInOffHand().getType(), cooldown);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,54 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* 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 de.steamwar.misslewars.MissileWars;
|
||||
import de.steamwar.misslewars.scripts.RunnableScript;
|
||||
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class RandomPlayerScript implements RunnableScript {
|
||||
|
||||
private Random random = new Random();
|
||||
|
||||
public RandomPlayerScript(JsonObject __) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
|
||||
int size = MissileWars.getBlueTeam().getPlayers().size() + MissileWars.getRedTeam().getPlayers().size();
|
||||
if (size == 0) return true;
|
||||
int index = random.nextInt(size);
|
||||
Player player;
|
||||
if (index >= MissileWars.getBlueTeam().getPlayers().size()) {
|
||||
player = MissileWars.getRedTeam().getPlayers().get(index - MissileWars.getBlueTeam().getPlayers().size());
|
||||
} else {
|
||||
player = MissileWars.getBlueTeam().getPlayers().get(index);
|
||||
}
|
||||
runnableScriptEvent.setLocationType(RunnableScriptEvent.LocationType.CUSTOM);
|
||||
runnableScriptEvent.setCustomLocation(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ(), player.getLocation().getPitch(), player.getLocation().getYaw());
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,9 +1,7 @@
|
||||
setup:
|
||||
- "ln -s /home/gitea/lib"
|
||||
|
||||
build:
|
||||
- "ln -s /home/gitea/lib"
|
||||
- "cp ~/gradle.properties ."
|
||||
- "./gradlew buildProject"
|
||||
- "./gradlew --stop"
|
||||
|
||||
artifacts:
|
||||
"/binarys/missilewars.jar": "build/libs/missilewars.jar"
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren