game stuff
This commit is contained in:
parent
6c85c18080
commit
8e7c82a31d
9 changed files with 305 additions and 6 deletions
16
pom.xml
16
pom.xml
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<groupId>de.lunarakai</groupId>
|
<groupId>de.lunarakai</groupId>
|
||||||
<artifactId>LunarUtils</artifactId>
|
<artifactId>LunarUtils</artifactId>
|
||||||
<version>0.0.1</version>
|
<version>0.0.2</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>LunarUtils</name>
|
<name>LunarUtils</name>
|
||||||
|
|
@ -24,8 +24,8 @@
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.8.1</version>
|
<version>3.8.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>${java.version}</source>
|
<source>14</source>
|
||||||
<target>${java.version}</target>
|
<target>14</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|
@ -59,6 +59,10 @@
|
||||||
<id>sonatype</id>
|
<id>sonatype</id>
|
||||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>brokkonaut</id>
|
||||||
|
<url>https://www.iani.de/nexus/content/groups/public</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
@ -68,5 +72,11 @@
|
||||||
<version>1.21-R0.1-SNAPSHOT</version>
|
<version>1.21-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>de.iani.cubeside</groupId>
|
||||||
|
<artifactId>CubesideUtilsBukkit</artifactId>
|
||||||
|
<version>1.16-SNAPSHOT</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public abstract class MessageUtils {
|
public abstract class SimpleChatMessages {
|
||||||
|
|
||||||
static Pattern langKeyPattern = Pattern.compile("^\\w+\\.\\w+\\.\\w+$");
|
static Pattern langKeyPattern = Pattern.compile("^\\w+\\.\\w+\\.\\w+$");
|
||||||
|
|
||||||
94
src/main/java/de/lunarakai/lunarutils/games/GameArena.java
Normal file
94
src/main/java/de/lunarakai/lunarutils/games/GameArena.java
Normal file
|
|
@ -0,0 +1,94 @@
|
||||||
|
package de.lunarakai.lunarutils.games;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
import java.util.UUID;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
public class GameArena<T extends Plugin> {
|
||||||
|
private final T plugin;
|
||||||
|
private final String name;
|
||||||
|
private final Location location;
|
||||||
|
private BlockFace orientation;
|
||||||
|
private GameArenaStatus gameArenaStatus = GameArenaStatus.INACTIVE;
|
||||||
|
private Player currentPlayer;
|
||||||
|
|
||||||
|
public GameArena(T plugin, ConfigurationSection arenaSection) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.name = Preconditions.checkNotNull(arenaSection.getString("name"));
|
||||||
|
this.location = Preconditions.checkNotNull(arenaSection.getLocation("location"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameArena(T plugin, String name, Location location, BlockFace orientation) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.name = Preconditions.checkNotNull(name, "name");
|
||||||
|
this.location = Preconditions.checkNotNull(location, "location");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save(ConfigurationSection arenaSection) {
|
||||||
|
arenaSection.set("name", name);
|
||||||
|
arenaSection.set("location", location);
|
||||||
|
arenaSection.set("orientation", orientation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startNewGame() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addJoiningPlayer(Player player) {
|
||||||
|
Preconditions.checkNotNull(player);
|
||||||
|
Preconditions.checkState(gameArenaStatus == GameArenaStatus.INACTIVE);
|
||||||
|
this.gameArenaStatus = GameArenaStatus.PRESTART;
|
||||||
|
this.currentPlayer = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removePlayer() {
|
||||||
|
this.gameArenaStatus = GameArenaStatus.INACTIVE;
|
||||||
|
this.currentPlayer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTooFarAway(Player player) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasPlayer() {
|
||||||
|
return currentPlayer != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getCurrentPlayer() {
|
||||||
|
return currentPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameArenaStatus getArenaStatus() {
|
||||||
|
return gameArenaStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setArenaStatus(GameArenaStatus gameArenaStatus) {
|
||||||
|
this.gameArenaStatus = gameArenaStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Plugin getPlugin() {
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getRotationYaw() {
|
||||||
|
return switch (orientation) {
|
||||||
|
case EAST -> 90;
|
||||||
|
case SOUTH -> 180;
|
||||||
|
case WEST -> 270;
|
||||||
|
default -> 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,96 @@
|
||||||
|
package de.lunarakai.lunarutils.games;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
public class GameArenaList<T extends Plugin> {
|
||||||
|
private static final String ARENAS_FILENAME = "arenas.yml";
|
||||||
|
private final Plugin plugin;
|
||||||
|
private File arenaFile;
|
||||||
|
|
||||||
|
private final HashMap<String, GameArena> arenas;
|
||||||
|
private final HashMap<UUID, GameArena> playersInArena;
|
||||||
|
|
||||||
|
public GameArenaList(T plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.arenas = new HashMap<>();
|
||||||
|
this.playersInArena = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load() {
|
||||||
|
arenas.clear();
|
||||||
|
if(!this.arenaFile.isFile()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
YamlConfiguration conf = new YamlConfiguration();
|
||||||
|
try {
|
||||||
|
conf.load(this.arenaFile);
|
||||||
|
} catch (IOException | InvalidConfigurationException e) {
|
||||||
|
plugin.getLogger().log(Level.SEVERE, "Could not load arenas file", e);
|
||||||
|
}
|
||||||
|
ConfigurationSection arenasSection = conf.getConfigurationSection("arenas");
|
||||||
|
if(arenasSection != null) {
|
||||||
|
for (String arenaName : arenasSection.getKeys(false)) {
|
||||||
|
ConfigurationSection arenaSection = arenasSection.getConfigurationSection(arenaName);
|
||||||
|
if(arenaSection != null) {
|
||||||
|
GameArena gameArena = new GameArena(plugin, arenaSection);
|
||||||
|
this.arenas.put(gameArena.getName(), gameArena);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
YamlConfiguration conf = new YamlConfiguration();
|
||||||
|
ConfigurationSection arenasSection = conf.createSection("arenas");
|
||||||
|
int i = 0;
|
||||||
|
for(GameArena gameArena : this.arenas.values()) {
|
||||||
|
gameArena.save(arenasSection.createSection(Integer.toString(i++)));
|
||||||
|
}
|
||||||
|
this.arenaFile.getParentFile().mkdirs();
|
||||||
|
try {
|
||||||
|
conf.save(this.arenaFile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
plugin.getLogger().log(Level.SEVERE, "Could not save arenas file", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameArena getArena(String name) {
|
||||||
|
return arenas.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<GameArena> getArnas() {
|
||||||
|
return arenas.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addArena(GameArena gameArena) {
|
||||||
|
this.arenas.put(gameArena.getName(), gameArena);
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setArenaForPlayer(Player player, GameArena gameArena) {
|
||||||
|
if(gameArena != null) {
|
||||||
|
playersInArena.put(player.getUniqueId(), gameArena);
|
||||||
|
} else {
|
||||||
|
playersInArena.remove(player.getUniqueId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameArena getPlayerArena(Player player) {
|
||||||
|
return playersInArena.get(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeArena(GameArena gameArena) {
|
||||||
|
arenas.remove(gameArena.getName());
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
package de.lunarakai.lunarutils.games;
|
||||||
|
|
||||||
|
public enum GameArenaStatus {
|
||||||
|
INACTIVE,
|
||||||
|
PRESTART,
|
||||||
|
PLAYING,
|
||||||
|
COMPLETED
|
||||||
|
}
|
||||||
24
src/main/java/de/lunarakai/lunarutils/games/GameManager.java
Normal file
24
src/main/java/de/lunarakai/lunarutils/games/GameManager.java
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
package de.lunarakai.lunarutils.games;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
public class GameManager<T extends Plugin> {
|
||||||
|
private final Plugin plugin;
|
||||||
|
|
||||||
|
public GameManager(T plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void joinArena(Player player, GameArena gameArena) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void leaveArena(Player player, boolean message, boolean reset) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startGame(Player player) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearAllArenas() {
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/main/java/de/lunarakai/lunarutils/games/GameObject.java
Normal file
36
src/main/java/de/lunarakai/lunarutils/games/GameObject.java
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
package de.lunarakai.lunarutils.games;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
public abstract class GameObject {
|
||||||
|
private String name;
|
||||||
|
private World world;
|
||||||
|
private Location location;
|
||||||
|
|
||||||
|
public abstract void spawn(Location location);
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public World getWorld() {
|
||||||
|
return world;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWorld(World world) {
|
||||||
|
this.world = world;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocation(Location location) {
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
}
|
||||||
31
src/main/java/de/lunarakai/lunarutils/inventory/GUIItem.java
Normal file
31
src/main/java/de/lunarakai/lunarutils/inventory/GUIItem.java
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
package de.lunarakai.lunarutils.inventory;
|
||||||
|
|
||||||
|
import de.iani.cubesideutils.bukkit.items.ItemBuilder;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.inventory.ItemFlag;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class GUIItem {
|
||||||
|
public static final ItemStack EMPTY_ICON = createGuiItem(Material.GRAY_STAINED_GLASS_PANE, Component.text(" "), true, true);
|
||||||
|
|
||||||
|
public static ItemStack createGuiItem(Material material, Component name, String... lore) {
|
||||||
|
return createGuiItem(material, name, false, lore);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack createGuiItem(Material material, Component name, boolean glowing, boolean showTooltip, String... lore) {
|
||||||
|
ItemBuilder builder = ItemBuilder.fromMaterial(material).displayName(name).lore(lore);
|
||||||
|
if (glowing) {
|
||||||
|
builder.enchantment(Enchantment.UNBREAKING, 1, true).flag(ItemFlag.HIDE_ENCHANTS);
|
||||||
|
}
|
||||||
|
if (!showTooltip) {
|
||||||
|
builder.flag(ItemFlag.HIDE_ADDITIONAL_TOOLTIP);
|
||||||
|
}
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack createGuiItem(Material material, Component name, boolean glowing, String... lore) {
|
||||||
|
return createGuiItem(material, name, glowing, true, lore);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package de.lunarakai.lunarutils;
|
package de.lunarakai.lunarutils.other;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
public abstract class StringUtils {
|
public abstract class URIValidation {
|
||||||
|
|
||||||
public static boolean isValidURL(String urlString) {
|
public static boolean isValidURL(String urlString) {
|
||||||
try {
|
try {
|
||||||
Loading…
Add table
Add a link
Reference in a new issue