Initial Commit
This commit is contained in:
commit
ddd8e562cf
18 changed files with 1352 additions and 0 deletions
113
.gitignore
vendored
Normal file
113
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,113 @@
|
||||||
|
User-specific stuff
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
|
||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.nar
|
||||||
|
*.ear
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
*.rar
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
|
||||||
|
*~
|
||||||
|
|
||||||
|
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||||
|
.fuse_hidden*
|
||||||
|
|
||||||
|
# KDE directory preferences
|
||||||
|
.directory
|
||||||
|
|
||||||
|
# Linux trash folder which might appear on any partition or disk
|
||||||
|
.Trash-*
|
||||||
|
|
||||||
|
# .nfs files are created when an open file is removed but is still being accessed
|
||||||
|
.nfs*
|
||||||
|
|
||||||
|
# General
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
.com.apple.timemachine.donotpresent
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
|
|
||||||
|
# Windows thumbnail cache files
|
||||||
|
Thumbs.db
|
||||||
|
Thumbs.db:encryptable
|
||||||
|
ehthumbs.db
|
||||||
|
ehthumbs_vista.db
|
||||||
|
|
||||||
|
# Dump file
|
||||||
|
*.stackdump
|
||||||
|
|
||||||
|
# Folder config file
|
||||||
|
[Dd]esktop.ini
|
||||||
|
|
||||||
|
# Recycle Bin used on file shares
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
|
# Windows Installer files
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# Windows shortcuts
|
||||||
|
*.lnk
|
||||||
|
|
||||||
|
target/
|
||||||
|
|
||||||
|
pom.xml.tag
|
||||||
|
pom.xml.releaseBackup
|
||||||
|
pom.xml.versionsBackup
|
||||||
|
pom.xml.next
|
||||||
|
|
||||||
|
release.properties
|
||||||
|
dependency-reduced-pom.xml
|
||||||
|
buildNumber.properties
|
||||||
|
.mvn/timing.properties
|
||||||
|
.mvn/wrapper/maven-wrapper.jar
|
||||||
|
.flattened-pom.xml
|
||||||
|
|
||||||
|
# Common working directory
|
||||||
|
run/
|
||||||
91
pom.xml
Normal file
91
pom.xml
Normal file
|
|
@ -0,0 +1,91 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>me.firephoenix</groupId>
|
||||||
|
<artifactId>PS3Minigames</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>PS3Minigames</name>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>${java.version}</source>
|
||||||
|
<target>${java.version}</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>spigotmc-repo</id>
|
||||||
|
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>sonatype</id>
|
||||||
|
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>OnARandomBox</id>
|
||||||
|
<url>https://repo.onarandombox.com/content/groups/public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.8.8-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.28</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.onarandombox.multiversecore</groupId>
|
||||||
|
<artifactId>Multiverse-Core</artifactId>
|
||||||
|
<version>4.3.1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
136
src/main/java/me/firephoenix/ps3minigames/PS3Minigames.java
Normal file
136
src/main/java/me/firephoenix/ps3minigames/PS3Minigames.java
Normal file
|
|
@ -0,0 +1,136 @@
|
||||||
|
package me.firephoenix.ps3minigames;
|
||||||
|
|
||||||
|
|
||||||
|
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import me.firephoenix.ps3minigames.commands.BuildMode;
|
||||||
|
import me.firephoenix.ps3minigames.commands.ForceStart;
|
||||||
|
import me.firephoenix.ps3minigames.commands.ForceStop;
|
||||||
|
import me.firephoenix.ps3minigames.commands.MapList;
|
||||||
|
import me.firephoenix.ps3minigames.game.Game;
|
||||||
|
import me.firephoenix.ps3minigames.listener.DeathListener;
|
||||||
|
import me.firephoenix.ps3minigames.listener.JoinQuitListener;
|
||||||
|
import me.firephoenix.ps3minigames.listener.MoveListener;
|
||||||
|
import me.firephoenix.ps3minigames.listener.WorldListener;
|
||||||
|
import me.firephoenix.ps3minigames.states.GameState;
|
||||||
|
import me.firephoenix.ps3minigames.states.LobbyState;
|
||||||
|
import me.firephoenix.ps3minigames.util.Timer;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public final class PS3Minigames extends JavaPlugin {
|
||||||
|
|
||||||
|
public static PS3Minigames INSTANCE;
|
||||||
|
|
||||||
|
public World lobby;
|
||||||
|
|
||||||
|
public ArrayList<UUID> buildModePlayer = new ArrayList<>();
|
||||||
|
|
||||||
|
public ArrayList<Game> games = new ArrayList<>();
|
||||||
|
|
||||||
|
public HashMap<World, Game> worldToGameHashMap = new HashMap<>();
|
||||||
|
|
||||||
|
public LobbyState lobbyState = LobbyState.IDLE;
|
||||||
|
|
||||||
|
public MultiverseCore multiverseCore;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
// Set Instance
|
||||||
|
INSTANCE = this;
|
||||||
|
|
||||||
|
saveDefaultConfig();
|
||||||
|
|
||||||
|
// Load Multiverse-API
|
||||||
|
multiverseCore = (MultiverseCore) getServer().getPluginManager().getPlugin("Multiverse-Core");
|
||||||
|
|
||||||
|
lobby = Bukkit.getServer().getWorld(getConfig().getString("spawn-lobby.world"));
|
||||||
|
|
||||||
|
//Register Commands
|
||||||
|
getCommand("build").setExecutor(new BuildMode());
|
||||||
|
getCommand("forcestart").setExecutor(new ForceStart());
|
||||||
|
getCommand("forcestop").setExecutor(new ForceStop());
|
||||||
|
getCommand("maplist").setExecutor(new MapList());
|
||||||
|
|
||||||
|
//Register Listener
|
||||||
|
getServer().getPluginManager().registerEvents(new JoinQuitListener(), this);
|
||||||
|
getServer().getPluginManager().registerEvents(new WorldListener(), this);
|
||||||
|
getServer().getPluginManager().registerEvents(new MoveListener(), this);
|
||||||
|
getServer().getPluginManager().registerEvents(new DeathListener(), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
// Plugin shutdown logic
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startNewGame(ArrayList<UUID> players, World map) {
|
||||||
|
String newName = map.getName() + "game" + getGames().size() + 1;
|
||||||
|
boolean copydone = getMultiverseCore().getMVWorldManager().cloneWorld(map.getName(), newName);
|
||||||
|
if (copydone) {
|
||||||
|
boolean loadingdone = getMultiverseCore().getMVWorldManager().loadWorld(newName);
|
||||||
|
if (loadingdone) {
|
||||||
|
getMultiverseCore().getMVWorldManager().getMVWorld(newName).setAlias(newName);
|
||||||
|
World gameWorld = Bukkit.getWorld(newName);
|
||||||
|
Game newGame = new Game(getGames().size() + 1, players, gameWorld, GameState.STARTING);
|
||||||
|
games.add(newGame);
|
||||||
|
worldToGameHashMap.put(gameWorld, newGame);
|
||||||
|
int spawnnumber = 1;
|
||||||
|
for (UUID uuid : players) {
|
||||||
|
if (getServer().getPlayer(uuid) == null) return;
|
||||||
|
getServer().getPlayer(uuid).sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("messages.teleporting")));
|
||||||
|
String configpathtospawnloc = "maps." + map.getName() + ".spawn" + spawnnumber++;
|
||||||
|
Location location = new Location(gameWorld, getConfig().getDouble(configpathtospawnloc + ".x"), getConfig().getDouble(configpathtospawnloc + ".y"), getConfig().getDouble(configpathtospawnloc + ".z"), (float) getConfig().getDouble(configpathtospawnloc + ".yaw"), (float) getConfig().getDouble(configpathtospawnloc + ".pitch"));
|
||||||
|
System.out.println(configpathtospawnloc + ".x");
|
||||||
|
Bukkit.getServer().getPlayer(uuid).teleport(location);
|
||||||
|
}
|
||||||
|
Timer timer = new Timer(10, PS3Minigames.INSTANCE);
|
||||||
|
timer.start();
|
||||||
|
timer.eachSecond(() -> {
|
||||||
|
for (UUID uuid : newGame.getPlayers()) {
|
||||||
|
if (Bukkit.getServer().getPlayer(uuid) == null) return;
|
||||||
|
Bukkit.getServer().getPlayer(uuid).sendTitle(ChatColor.translateAlternateColorCodes('&',"&6" + timer.getCounter()), "");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
timer.whenComplete(() -> {
|
||||||
|
newGame.setGameState(GameState.RUNNING);
|
||||||
|
gameWorld.getPlayers().forEach(player -> player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("messages.game-start-no-countdown"))));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
System.out.println("error while trying to load the world!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println("error while trying to copy the world!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopGame(Game game) {
|
||||||
|
if (game.getGameState() != GameState.STOPPING) game.setGameState(GameState.STOPPING);
|
||||||
|
game.getPlayers().forEach(uuid -> Bukkit.getServer().getPlayer(uuid).teleport(new Location(getServer().getWorld(getConfig().getString("spawn-lobby.world")), getConfig().getDouble("spawn-lobby.x"), getConfig().getDouble("spawn-lobby.y"), getConfig().getDouble("spawn-lobby.z"), (float) getConfig().getDouble("spawn-lobby.yaw"), (float) getConfig().getDouble("spawn-lobby.pitch"))));
|
||||||
|
if (game.getMap().getPlayers().size() == 0) {
|
||||||
|
getMultiverseCore().getMVWorldManager().deleteWorld(game.getMap().getName());
|
||||||
|
}
|
||||||
|
games.remove(game);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game getGameByWorld(World world) {
|
||||||
|
return worldToGameHashMap.get(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Game getGameByID(int id) {
|
||||||
|
//we use id - 1 because the id is the absolute size of the list which starts at 1 and the arraylist position starts at 0
|
||||||
|
return getGames().stream().anyMatch(game -> game.getGameid() == id) ? getGames().get(id - 1) : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,64 @@
|
||||||
|
package me.firephoenix.ps3minigames.commands;
|
||||||
|
|
||||||
|
import me.firephoenix.ps3minigames.PS3Minigames;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author NieGestorben
|
||||||
|
* Copyright© (c) 2023, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
public class BuildMode implements CommandExecutor {
|
||||||
|
|
||||||
|
public FileConfiguration config = PS3Minigames.INSTANCE.getConfig();
|
||||||
|
|
||||||
|
public PS3Minigames plugin = PS3Minigames.INSTANCE;
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (!(sender instanceof Player)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Player player = (Player) sender;
|
||||||
|
|
||||||
|
if (!player.hasPermission(command.getPermission())) {
|
||||||
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.no-permission")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length == 0) {
|
||||||
|
if (plugin.getBuildModePlayer().contains(player.getUniqueId())) {
|
||||||
|
plugin.getBuildModePlayer().remove(player.getUniqueId());
|
||||||
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.build-mode-disabled")));
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
plugin.getBuildModePlayer().add(player.getUniqueId());
|
||||||
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.build-mode-enabled")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (args.length == 1) {
|
||||||
|
Player target = Bukkit.getPlayer(args[0]);
|
||||||
|
if (target != null) {
|
||||||
|
if (plugin.getBuildModePlayer().contains(player.getUniqueId())) {
|
||||||
|
plugin.getBuildModePlayer().remove(target.getUniqueId());
|
||||||
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("build-mode-disabled-for-player")));
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
plugin.getBuildModePlayer().add(target.getUniqueId());
|
||||||
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("build-mode-enabled-for-player")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("couldnt-find-player")));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
player.sendMessage("§7Please enter in a player name or leave the arguments empty!");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
package me.firephoenix.ps3minigames.commands;
|
||||||
|
|
||||||
|
import me.firephoenix.ps3minigames.PS3Minigames;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author NieGestorben
|
||||||
|
* Copyright© (c) 2023, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
public class ForceStart implements CommandExecutor {
|
||||||
|
|
||||||
|
public FileConfiguration config = PS3Minigames.INSTANCE.getConfig();
|
||||||
|
|
||||||
|
public PS3Minigames plugin = PS3Minigames.INSTANCE;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (args.length == 1) {
|
||||||
|
World world = Bukkit.getWorld(args[0]);
|
||||||
|
if (world != null) {
|
||||||
|
ArrayList<UUID> players = new ArrayList<>();
|
||||||
|
PS3Minigames.INSTANCE.getLobby().getPlayers().forEach(player -> players.add(player.getUniqueId()));
|
||||||
|
PS3Minigames.INSTANCE.startNewGame(players, world);
|
||||||
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.force-starting-game").replace("%map%", world.getName())));
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.world-not-found")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
package me.firephoenix.ps3minigames.commands;
|
||||||
|
|
||||||
|
import me.firephoenix.ps3minigames.PS3Minigames;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author NieGestorben
|
||||||
|
* Copyright© (c) 2023, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
public class ForceStop implements CommandExecutor {
|
||||||
|
|
||||||
|
public FileConfiguration config = PS3Minigames.INSTANCE.getConfig();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (args.length == 1) {
|
||||||
|
int gameID;
|
||||||
|
try {
|
||||||
|
gameID = Integer.parseInt(args[0]);
|
||||||
|
} catch (NumberFormatException exception) {
|
||||||
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.invalid-game-id").replace("%id%", args[0])));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (PS3Minigames.INSTANCE.getGameByID(gameID) == null || gameID == 0) {
|
||||||
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.cant-find-game")));
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
PS3Minigames.INSTANCE.stopGame(Objects.requireNonNull(PS3Minigames.INSTANCE.getGameByID(gameID)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
package me.firephoenix.ps3minigames.commands;
|
||||||
|
|
||||||
|
import me.firephoenix.ps3minigames.PS3Minigames;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author NieGestorben
|
||||||
|
* Copyright© (c) 2023, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
public class MapList implements CommandExecutor {
|
||||||
|
|
||||||
|
public FileConfiguration config = PS3Minigames.INSTANCE.getConfig();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (args.length == 0) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
PS3Minigames.INSTANCE.getMultiverseCore().getMVWorldManager().getMVWorlds().stream().filter(world -> !world.getName().contains("world")).forEach(world -> sb.append(world.getName()).append(", "));
|
||||||
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.available-maps")));
|
||||||
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6" + sb));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
35
src/main/java/me/firephoenix/ps3minigames/game/Game.java
Normal file
35
src/main/java/me/firephoenix/ps3minigames/game/Game.java
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
package me.firephoenix.ps3minigames.game;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import me.firephoenix.ps3minigames.states.GameState;
|
||||||
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author NieGestorben
|
||||||
|
* Copyright© (c) 2023, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class Game {
|
||||||
|
|
||||||
|
public int gameid;
|
||||||
|
|
||||||
|
public ArrayList<UUID> players;
|
||||||
|
|
||||||
|
public GameState gameState;
|
||||||
|
|
||||||
|
public World map;
|
||||||
|
|
||||||
|
public Game(int gameid, ArrayList<UUID> players, World map, GameState gameState) {
|
||||||
|
this.gameid = gameid;
|
||||||
|
this.players = players;
|
||||||
|
this.gameState = gameState;
|
||||||
|
this.map = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
package me.firephoenix.ps3minigames.listener;
|
||||||
|
|
||||||
|
import me.firephoenix.ps3minigames.PS3Minigames;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author NieGestorben
|
||||||
|
* Copyright© (c) 2023, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
public class DeathListener implements Listener {
|
||||||
|
|
||||||
|
public FileConfiguration config = PS3Minigames.INSTANCE.getConfig();
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onDeath(PlayerDeathEvent e) {
|
||||||
|
Player player = e.getEntity().getPlayer();
|
||||||
|
Player killer = e.getEntity().getKiller();
|
||||||
|
|
||||||
|
player.getWorld().getPlayers().forEach(players -> players.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.player-death").replace("%player%", player.getDisplayName()).replace("%cause%", killer == null ? "enviroment" : killer.getDisplayName()))));
|
||||||
|
if (player.getWorld().getPlayers().size() == 1) {
|
||||||
|
PS3Minigames.INSTANCE.stopGame(PS3Minigames.INSTANCE.getGameByWorld(player.getWorld()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,83 @@
|
||||||
|
package me.firephoenix.ps3minigames.listener;
|
||||||
|
|
||||||
|
import me.firephoenix.ps3minigames.PS3Minigames;
|
||||||
|
import me.firephoenix.ps3minigames.states.LobbyState;
|
||||||
|
import me.firephoenix.ps3minigames.util.Timer;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author NieGestorben
|
||||||
|
* Copyright© (c) 2023, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
public class JoinQuitListener implements Listener {
|
||||||
|
|
||||||
|
public FileConfiguration config = PS3Minigames.INSTANCE.getConfig();
|
||||||
|
|
||||||
|
public PS3Minigames plugin = PS3Minigames.INSTANCE;
|
||||||
|
|
||||||
|
public Timer gameTimer;
|
||||||
|
|
||||||
|
public ArrayList<UUID> lobbyPlayers = new ArrayList<>();
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onJoin(PlayerJoinEvent e) {
|
||||||
|
Player player = e.getPlayer();
|
||||||
|
player.teleport(new Location(plugin.getServer().getWorld(config.getString("spawn-lobby.world")), config.getDouble("spawn-lobby.x"), config.getDouble("spawn-lobby.y"), config.getDouble("spawn-lobby.z"), (float) config.getDouble("spawn-lobby.yaw"), (float) config.getDouble("spawn-lobby.pitch")));
|
||||||
|
player.setHealth(20);
|
||||||
|
player.setFoodLevel(20);
|
||||||
|
player.getInventory().clear();
|
||||||
|
player.setGameMode(GameMode.SURVIVAL);
|
||||||
|
|
||||||
|
// Send all players which are in the lobby the join message
|
||||||
|
for (Player player1 : plugin.getLobby().getPlayers()) {
|
||||||
|
player1.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.join").replace("%player%", player.getDisplayName())));
|
||||||
|
}
|
||||||
|
// Send joined player the join message, because joinevent is 1 tick before the player gets added to the world player list
|
||||||
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.join").replace("%player%", player.getDisplayName())));
|
||||||
|
if (plugin.getLobby().getPlayers().size() == 0) {
|
||||||
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.needed-players")));
|
||||||
|
for (Player player1 : plugin.getLobby().getPlayers()) {
|
||||||
|
player1.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.needed-players")));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (plugin.getLobby().getPlayers().size() >= 3) {
|
||||||
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.game-start").replace("%seconds%", "10")));
|
||||||
|
for (Player player1 : plugin.getLobby().getPlayers()) {
|
||||||
|
player1.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.game-start").replace("%seconds%", "10")));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.game-start").replace("%seconds%", "25")));
|
||||||
|
for (Player player1 : plugin.getLobby().getPlayers()) {
|
||||||
|
player1.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.game-start").replace("%seconds%", "25")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (plugin.getLobbyState() == LobbyState.IDLE) {
|
||||||
|
plugin.setLobbyState(LobbyState.STARTING);
|
||||||
|
lobbyPlayers.add(player.getUniqueId());
|
||||||
|
plugin.getLobby().getPlayers().forEach(player1 -> lobbyPlayers.add(player1.getUniqueId()));
|
||||||
|
|
||||||
|
gameTimer.start();
|
||||||
|
gameTimer = new Timer(plugin.getLobby().getPlayers().size() >= 3 ? 10 : 25, plugin);
|
||||||
|
gameTimer.whenComplete(() -> PS3Minigames.INSTANCE.startNewGame(lobbyPlayers, plugin.getServer().getWorld("cavern")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onQuit(PlayerQuitEvent e) {
|
||||||
|
lobbyPlayers.remove(e.getPlayer().getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
package me.firephoenix.ps3minigames.listener;
|
||||||
|
|
||||||
|
import me.firephoenix.ps3minigames.PS3Minigames;
|
||||||
|
import me.firephoenix.ps3minigames.game.Game;
|
||||||
|
import me.firephoenix.ps3minigames.states.GameState;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author NieGestorben
|
||||||
|
* Copyright© (c) 2023, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
public class MoveListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onMove(PlayerMoveEvent e) {
|
||||||
|
// TODO: Make this less performance intensive. Currently the required performance increases exponentially.
|
||||||
|
for (Game game : PS3Minigames.INSTANCE.getGames()) {
|
||||||
|
if (game.getPlayers().stream().anyMatch(uuid -> e.getPlayer().getUniqueId().equals(uuid))) {
|
||||||
|
if (game.getGameState() == GameState.STARTING) {
|
||||||
|
e.setTo(e.getFrom());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,158 @@
|
||||||
|
package me.firephoenix.ps3minigames.listener;
|
||||||
|
|
||||||
|
import me.firephoenix.ps3minigames.PS3Minigames;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.Action;
|
||||||
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
|
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||||
|
import org.bukkit.event.weather.WeatherChangeEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author NieGestorben
|
||||||
|
* Copyright© (c) 2023, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
public class WorldListener implements Listener {
|
||||||
|
|
||||||
|
public FileConfiguration config = PS3Minigames.INSTANCE.getConfig();
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBlockPlace(BlockPlaceEvent e) {
|
||||||
|
if (!PS3Minigames.INSTANCE.getBuildModePlayer().contains(e.getPlayer().getUniqueId())) {
|
||||||
|
e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.block-place-forbidden")));
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBlockBreak(BlockBreakEvent e) {
|
||||||
|
if (!PS3Minigames.INSTANCE.getBuildModePlayer().contains(e.getPlayer().getUniqueId())) {
|
||||||
|
e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.block-break-forbidden")));
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onAttack(PlayerInteractAtEntityEvent e) {
|
||||||
|
if (e.getPlayer().getWorld().equals(PS3Minigames.INSTANCE.getLobby())) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onDestroyCrops(PlayerInteractEvent e) {
|
||||||
|
if (e.getClickedBlock() == null) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (e.getClickedBlock().getType() == Material.AIR) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!PS3Minigames.INSTANCE.getBuildModePlayer().contains(e.getPlayer().getUniqueId())) {
|
||||||
|
if (e.getPlayer().getWorld() != PS3Minigames.INSTANCE.getLobby() && e.getClickedBlock().getType() == Material.CHEST) return;
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onItemPickUp(PlayerPickupItemEvent e) {
|
||||||
|
if (!PS3Minigames.INSTANCE.getBuildModePlayer().contains(e.getPlayer().getUniqueId())) {
|
||||||
|
if (e.getPlayer().getWorld().equals(PS3Minigames.INSTANCE.getLobby())) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onDrop(PlayerDropItemEvent e) {
|
||||||
|
if (!PS3Minigames.INSTANCE.getBuildModePlayer().contains(e.getPlayer().getUniqueId())) {
|
||||||
|
if (e.getPlayer().getWorld().equals(PS3Minigames.INSTANCE.getLobby())) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerDoorOpen(PlayerInteractEvent e) {
|
||||||
|
if (e.getClickedBlock() == null) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (e.getClickedBlock().getType() == Material.AIR) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!PS3Minigames.INSTANCE.getBuildModePlayer().contains(e.getPlayer().getUniqueId())) {
|
||||||
|
Block clickedBlock = e.getClickedBlock();
|
||||||
|
|
||||||
|
//Left or Right click?
|
||||||
|
if (e.getAction() == Action.LEFT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||||
|
//Door Block?
|
||||||
|
if (clickedBlock.getType().name().endsWith("_DOOR")
|
||||||
|
|| clickedBlock.getType().name().endsWith("_FENCE")
|
||||||
|
|| clickedBlock.getType().name().endsWith("_GATE")) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onItemMove(InventoryClickEvent e) {
|
||||||
|
if (!PS3Minigames.INSTANCE.getBuildModePlayer().contains(e.getWhoClicked().getUniqueId())) {
|
||||||
|
if (e.getWhoClicked().getWorld().equals(PS3Minigames.INSTANCE.getLobby())) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onDamage(EntityDamageEvent e) {
|
||||||
|
if (e.getEntity() instanceof Player) {
|
||||||
|
if (e.getEntity().getWorld().equals(PS3Minigames.INSTANCE.getLobby())) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onDamageByEntity(EntityDamageByEntityEvent e) {
|
||||||
|
if (e.getDamager() instanceof Player) {
|
||||||
|
if (e.getDamager().getWorld().equals(PS3Minigames.INSTANCE.getLobby())) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onWeatherChange(WeatherChangeEvent e) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onFoodLevelChange(FoodLevelChangeEvent e) {
|
||||||
|
if (e.getEntity() instanceof Player) {
|
||||||
|
if (e.getEntity().getWorld().equals(PS3Minigames.INSTANCE.getLobby())) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
Player player = (Player) e.getEntity();
|
||||||
|
if (!(player.getFoodLevel() == 20)) player.setFoodLevel(20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package me.firephoenix.ps3minigames.states;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author NieGestorben
|
||||||
|
* Copyright© (c) 2023, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
public enum GameState {
|
||||||
|
|
||||||
|
STARTING,
|
||||||
|
RUNNING,
|
||||||
|
STOPPING
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
package me.firephoenix.ps3minigames.states;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author NieGestorben
|
||||||
|
* Copyright© (c) 2023, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
public enum LobbyState {
|
||||||
|
IDLE,
|
||||||
|
STARTING,
|
||||||
|
RESET
|
||||||
|
}
|
||||||
301
src/main/java/me/firephoenix/ps3minigames/util/ItemBuilder.java
Normal file
301
src/main/java/me/firephoenix/ps3minigames/util/ItemBuilder.java
Normal file
|
|
@ -0,0 +1,301 @@
|
||||||
|
package me.firephoenix.ps3minigames.util;
|
||||||
|
|
||||||
|
import org.bukkit.Color;
|
||||||
|
import org.bukkit.DyeColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.inventory.ItemFlag;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||||
|
import org.bukkit.inventory.meta.SkullMeta;
|
||||||
|
import org.bukkit.material.MaterialData;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Easily create itemstacks, without messing your hands.
|
||||||
|
* <i>Note that if you do use this in one of your projects, leave this notice.</i>
|
||||||
|
* <i>Please do credit me if you do use this in one of your projects.</i>
|
||||||
|
* @author NonameSL
|
||||||
|
*/
|
||||||
|
public class ItemBuilder {
|
||||||
|
private final ItemStack is;
|
||||||
|
/**
|
||||||
|
* Create a new ItemBuilder from scratch.
|
||||||
|
* @param m The material to create the ItemBuilder with.
|
||||||
|
*/
|
||||||
|
public ItemBuilder(Material m){
|
||||||
|
this(m, 1);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Create a new ItemBuilder over an existing itemstack.
|
||||||
|
* @param is The itemstack to create the ItemBuilder over.
|
||||||
|
*/
|
||||||
|
public ItemBuilder(ItemStack is){
|
||||||
|
this.is=is;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Create a new ItemBuilder from scratch.
|
||||||
|
* @param m The material of the item.
|
||||||
|
* @param amount The amount of the item.
|
||||||
|
*/
|
||||||
|
public ItemBuilder(Material m, int amount){
|
||||||
|
is= new ItemStack(m, amount);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Create a new ItemBuilder from scratch.
|
||||||
|
* @param m The material of the item.
|
||||||
|
* @param amount The amount of the item.
|
||||||
|
* @param durability The durability of the item.
|
||||||
|
*/
|
||||||
|
public ItemBuilder(Material m, int amount, byte durability){
|
||||||
|
is = new ItemStack(m, amount, durability);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Clone the ItemBuilder into a new one.
|
||||||
|
* @return The cloned instance.
|
||||||
|
*/
|
||||||
|
public ItemBuilder clone() {
|
||||||
|
return new ItemBuilder(is);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Change the durability of the item.
|
||||||
|
* @param dur The durability to set it to.
|
||||||
|
*/
|
||||||
|
public ItemBuilder setDurability(short dur){
|
||||||
|
is.setDurability(dur);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Change the amount of the item.
|
||||||
|
* @param amount The amount to set it to.
|
||||||
|
*/
|
||||||
|
public ItemBuilder setAmount(int amount) {
|
||||||
|
is.setAmount(amount);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Set the displayname of the item.
|
||||||
|
* @param name The name to change it to.
|
||||||
|
*/
|
||||||
|
public ItemBuilder setName(String name){
|
||||||
|
ItemMeta im = is.getItemMeta();
|
||||||
|
im.setDisplayName(name);
|
||||||
|
is.setItemMeta(im);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Add an unsafe enchantment.
|
||||||
|
* @param ench The enchantment to add.
|
||||||
|
* @param level The level to put the enchant on.
|
||||||
|
*/
|
||||||
|
public ItemBuilder addUnsafeEnchantment(Enchantment ench, int level){
|
||||||
|
is.addUnsafeEnchantment(ench, level);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Remove a certain enchant from the item.
|
||||||
|
* @param ench The enchantment to remove
|
||||||
|
*/
|
||||||
|
public ItemBuilder removeEnchantment(Enchantment ench){
|
||||||
|
is.removeEnchantment(ench);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Set the skull owner for the item. Works on skulls only.
|
||||||
|
* @param owner The name of the skull's owner.
|
||||||
|
*/
|
||||||
|
public ItemBuilder setSkullOwner(String owner){
|
||||||
|
try{
|
||||||
|
SkullMeta im = (SkullMeta)is.getItemMeta();
|
||||||
|
im.setOwner(owner);
|
||||||
|
is.setItemMeta(im);
|
||||||
|
}catch(ClassCastException ignored){}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Add an enchant to the item.
|
||||||
|
* @param ench The enchant to add
|
||||||
|
* @param level The level
|
||||||
|
*/
|
||||||
|
public ItemBuilder addEnchant(Enchantment ench, int level){
|
||||||
|
ItemMeta im = is.getItemMeta();
|
||||||
|
im.addEnchant(ench, level, true);
|
||||||
|
is.setItemMeta(im);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Add multiple enchants at once.
|
||||||
|
* @param enchantments The enchants to add.
|
||||||
|
*/
|
||||||
|
public ItemBuilder addEnchantments(Map<Enchantment, Integer> enchantments){
|
||||||
|
is.addEnchantments(enchantments);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Sets infinity durability on the item by setting the durability to Short.MAX_VALUE.
|
||||||
|
*/
|
||||||
|
public ItemBuilder setInfinityDurability(){
|
||||||
|
is.setDurability(Short.MAX_VALUE);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Sets the durability to unbreakable
|
||||||
|
*/
|
||||||
|
public ItemBuilder setUnbreakable(boolean unbreakable) {
|
||||||
|
ItemMeta im = is.getItemMeta();
|
||||||
|
im.spigot().setUnbreakable(unbreakable);
|
||||||
|
is.setItemMeta(im);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Re-sets the lore.
|
||||||
|
* @param lore The lore to set it to.
|
||||||
|
*/
|
||||||
|
public ItemBuilder setLore(String... lore){
|
||||||
|
ItemMeta im = is.getItemMeta();
|
||||||
|
im.setLore(Arrays.asList(lore));
|
||||||
|
is.setItemMeta(im);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Re-sets the lore.
|
||||||
|
* @param lore The lore to set it to.
|
||||||
|
*/
|
||||||
|
public ItemBuilder setLore(List<String> lore) {
|
||||||
|
ItemMeta im = is.getItemMeta();
|
||||||
|
im.setLore(lore);
|
||||||
|
is.setItemMeta(im);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Remove a lore line.
|
||||||
|
* @param line The lore to remove.
|
||||||
|
*/
|
||||||
|
public ItemBuilder removeLoreLine(String line){
|
||||||
|
ItemMeta im = is.getItemMeta();
|
||||||
|
List<String> lore = new ArrayList<>(im.getLore());
|
||||||
|
if(!lore.contains(line))return this;
|
||||||
|
lore.remove(line);
|
||||||
|
im.setLore(lore);
|
||||||
|
is.setItemMeta(im);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Remove a lore line.
|
||||||
|
* @param index The index of the lore line to remove.
|
||||||
|
*/
|
||||||
|
public ItemBuilder removeLoreLine(int index){
|
||||||
|
ItemMeta im = is.getItemMeta();
|
||||||
|
List<String> lore = new ArrayList<>(im.getLore());
|
||||||
|
if(index<0||index>lore.size())return this;
|
||||||
|
lore.remove(index);
|
||||||
|
im.setLore(lore);
|
||||||
|
is.setItemMeta(im);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Add a lore line.
|
||||||
|
* @param line The lore line to add.
|
||||||
|
*/
|
||||||
|
public ItemBuilder addLoreLine(String line){
|
||||||
|
ItemMeta im = is.getItemMeta();
|
||||||
|
List<String> lore = new ArrayList<>();
|
||||||
|
if(im.hasLore())lore = new ArrayList<>(im.getLore());
|
||||||
|
lore.add(line);
|
||||||
|
im.setLore(lore);
|
||||||
|
is.setItemMeta(im);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Add a lore line.
|
||||||
|
* @param line The lore line to add.
|
||||||
|
* @param pos The index of where to put it.
|
||||||
|
*/
|
||||||
|
public ItemBuilder addLoreLine(String line, int pos){
|
||||||
|
ItemMeta im = is.getItemMeta();
|
||||||
|
List<String> lore = new ArrayList<>(im.getLore());
|
||||||
|
lore.set(pos, line);
|
||||||
|
im.setLore(lore);
|
||||||
|
is.setItemMeta(im);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Sets the dye color on an item.
|
||||||
|
* <b>* Notice that this doesn't check for item type, sets the literal data of the dyecolor as durability.</b>
|
||||||
|
* @param color The color to put.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public ItemBuilder setDyeColor(DyeColor color){
|
||||||
|
this.is.setDurability(color.getDyeData());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Sets the dye color of a wool item. Works only on wool.
|
||||||
|
* @deprecated As of version 1.2 changed to setDyeColor.
|
||||||
|
* @see ItemBuilder@setDyeColor(DyeColor)
|
||||||
|
* @param color The DyeColor to set the wool item to.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public ItemBuilder setWoolColor(DyeColor color){
|
||||||
|
if(!is.getType().equals(Material.WOOL))return this;
|
||||||
|
this.is.setDurability(color.getDyeData());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Sets the armor color of a leather armor piece. Works only on leather armor pieces.
|
||||||
|
* @param color The color to set it to.
|
||||||
|
*/
|
||||||
|
public ItemBuilder setLeatherArmorColor(Color color){
|
||||||
|
try{
|
||||||
|
LeatherArmorMeta im = (LeatherArmorMeta)is.getItemMeta();
|
||||||
|
im.setColor(color);
|
||||||
|
is.setItemMeta(im);
|
||||||
|
}catch(ClassCastException ignored){}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the itemflag of the item. Works on every item.
|
||||||
|
* @param flag Set a specific itemflag
|
||||||
|
*/
|
||||||
|
public ItemBuilder setItemFlags(ItemFlag flag) {
|
||||||
|
ItemMeta im = is.getItemMeta();
|
||||||
|
im.addItemFlags(flag);
|
||||||
|
is.setItemMeta(im);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the data of the item. Works on every item.
|
||||||
|
* @param data Set a specific data
|
||||||
|
*/
|
||||||
|
public ItemBuilder setData(MaterialData data) {
|
||||||
|
is.setData(data);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the typeId of the item. Works on every item.
|
||||||
|
* @param typeId Set a specific typeId
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public ItemBuilder setTypeId(int typeId) {
|
||||||
|
try {
|
||||||
|
is.setTypeId(typeId);
|
||||||
|
}catch (ClassCastException ignored) {}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the itemstack from the ItemBuilder.
|
||||||
|
* @return The itemstack created/modified by the ItemBuilder instance.
|
||||||
|
*/
|
||||||
|
public ItemStack toItemStack(){
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
}
|
||||||
69
src/main/java/me/firephoenix/ps3minigames/util/Timer.java
Normal file
69
src/main/java/me/firephoenix/ps3minigames/util/Timer.java
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
package me.firephoenix.ps3minigames.util;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tiiita_
|
||||||
|
* Created on Dezember 17, 2022 | 18:21:40
|
||||||
|
* (●'◡'●)
|
||||||
|
*/
|
||||||
|
public class Timer {
|
||||||
|
private final int duration;
|
||||||
|
private final Plugin plugin;
|
||||||
|
int counter;
|
||||||
|
BukkitTask bukkitTask;
|
||||||
|
private boolean running = false;
|
||||||
|
private Runnable whenComplete;
|
||||||
|
private Runnable eachSecond;
|
||||||
|
public Timer(int durationInSeconds, Plugin plugin) {
|
||||||
|
this.duration = durationInSeconds;
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start() {
|
||||||
|
counter = duration;
|
||||||
|
running = true;
|
||||||
|
bukkitTask = Bukkit.getScheduler().runTaskTimer(plugin, () -> {
|
||||||
|
if (counter > 0) {
|
||||||
|
if (eachSecond != null) {
|
||||||
|
eachSecond.run();
|
||||||
|
}
|
||||||
|
counter--;
|
||||||
|
} else {
|
||||||
|
bukkitTask.cancel();
|
||||||
|
running = false;
|
||||||
|
|
||||||
|
if (whenComplete != null) {
|
||||||
|
whenComplete.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}, 0, 20);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
bukkitTask.cancel();
|
||||||
|
bukkitTask = null;
|
||||||
|
counter = duration;
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void whenComplete(Runnable runnable) {
|
||||||
|
this.whenComplete = runnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void eachSecond(Runnable runnable) {
|
||||||
|
this.eachSecond = runnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRunning() {
|
||||||
|
return running;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCounter() {
|
||||||
|
return counter;
|
||||||
|
}
|
||||||
|
}
|
||||||
83
src/main/resources/config.yml
Normal file
83
src/main/resources/config.yml
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
# Lobby Spawn
|
||||||
|
spawn-lobby:
|
||||||
|
x: 0.5
|
||||||
|
y: 67
|
||||||
|
z: 11.5
|
||||||
|
yaw: 180.0
|
||||||
|
pitch: 0.0
|
||||||
|
world: world
|
||||||
|
|
||||||
|
# Messages
|
||||||
|
messages:
|
||||||
|
join: "&6%player% &7joined!"
|
||||||
|
needed-players: "&62 &7Players are required to start the game."
|
||||||
|
block-break-forbidden: "&6You &7can't break blocks here!"
|
||||||
|
block-place-forbidden: "&6You &7can't place blocks here!"
|
||||||
|
no-permission: "&6You &7don't have the right permissions to use this command!"
|
||||||
|
build-mode-enabled: "&6BuildMode &7has been enabled!"
|
||||||
|
build-mode-disabled: "&6BuildMode &7has been disabled!"
|
||||||
|
build-mode-enabled-for-player: "&6BuildMode &7has been enabled for the player &6%player%&7!"
|
||||||
|
build-mode-disabled-for-player: "&6BuildMode &7has been enabled for the player &6%player%&7!"
|
||||||
|
couldnt-find-player: "&6Player &7couldn't be found!"
|
||||||
|
game-start: "&7The game is starting in &6%seconds%&7s!"
|
||||||
|
world-not-found: "&7The world &6%world%&7 couldn't be found!"
|
||||||
|
game-start-no-countdown: "&7The game is &6starting&7 now!"
|
||||||
|
teleporting: "&7Teleporting&6..."
|
||||||
|
player-death: "&6%player%&7 was killed by &6%cause%&7!"
|
||||||
|
invalid-game-id: "&7The game id &6%id%&7 is invalid!"
|
||||||
|
cant-find-game: "&6Game&7 couldn't be found!"
|
||||||
|
available-maps: "&7Available &6Maps&7:"
|
||||||
|
force-starting-game: "&7Starting game on map &6%map%&7..."
|
||||||
|
|
||||||
|
# Maps
|
||||||
|
maps:
|
||||||
|
# Map name needs to be same as world!
|
||||||
|
cavern:
|
||||||
|
spawn1:
|
||||||
|
x: 0.5
|
||||||
|
y: 63.0
|
||||||
|
z: 13.5
|
||||||
|
yaw: 180.0
|
||||||
|
pitch: 0.0
|
||||||
|
spawn2:
|
||||||
|
x: -9.5
|
||||||
|
y: 63.0
|
||||||
|
z: 10.5
|
||||||
|
yaw: -135.5
|
||||||
|
pitch: 0.0
|
||||||
|
spawn3:
|
||||||
|
x: -12.5
|
||||||
|
y: 63.0
|
||||||
|
z: 0.5
|
||||||
|
yaw: -90.0
|
||||||
|
pitch: 0.0
|
||||||
|
spawn4:
|
||||||
|
x: -9.5
|
||||||
|
y: 63.0
|
||||||
|
z: -9.5
|
||||||
|
yaw: -45
|
||||||
|
pitch: 0.0
|
||||||
|
spawn5:
|
||||||
|
x: 0.5
|
||||||
|
y: 63.0
|
||||||
|
z: -12.5
|
||||||
|
yaw: 0.0
|
||||||
|
pitch: 0.0
|
||||||
|
spawn6:
|
||||||
|
x: 10.5
|
||||||
|
y: 63.0
|
||||||
|
z: -9.5
|
||||||
|
yaw: 45.0
|
||||||
|
pitch: 0.0
|
||||||
|
spawn7:
|
||||||
|
x: 13.5
|
||||||
|
y: 63.0
|
||||||
|
z: 0.5
|
||||||
|
yaw: 90.0
|
||||||
|
pitch: 0.0
|
||||||
|
spawn8:
|
||||||
|
x: 10.5
|
||||||
|
y: 63.0
|
||||||
|
z: 10.5
|
||||||
|
yaw: 135.0
|
||||||
|
pitch: 0
|
||||||
18
src/main/resources/plugin.yml
Normal file
18
src/main/resources/plugin.yml
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
name: PS3Minigames
|
||||||
|
version: '${project.version}'
|
||||||
|
main: me.firephoenix.ps3minigames.PS3Minigames
|
||||||
|
author: NieGestorben
|
||||||
|
|
||||||
|
commands:
|
||||||
|
build:
|
||||||
|
permission: ps3minigames.command.buildmode
|
||||||
|
usage: §7/build <PLAYER>
|
||||||
|
forcestart:
|
||||||
|
permission: ps3minigames.command.forcestart
|
||||||
|
usage: §7/forcestart <MAP>
|
||||||
|
forcestop:
|
||||||
|
permission: ps3minigames.command.forcestop
|
||||||
|
usage: §7/forcestop <GAMEID>
|
||||||
|
maplist:
|
||||||
|
permission: ps3minigames.command.maplist
|
||||||
|
usage: §7/maplist
|
||||||
Loading…
Add table
Add a link
Reference in a new issue