0

1 Commits

Author SHA1 Message Date
6f51bedba1 add Minigame project 2021-01-07 09:34:36 +03:00
27 changed files with 194 additions and 308 deletions

View File

@@ -62,15 +62,6 @@ YamlConfiguration config = GhastTools.loadConfig(false);
Если передать параметр `false`, то при отсутствии файла `config.yml` в папке плагина,
будет загруден исключительно встроенный файл настроек.
### copyLocation
Копирования объекта `Location`
```java
Location location = ...;
Location copyLoc = GhastTools.copyLocation(location);
```
## AssetsManager
Методы по работе с файлами плагина (_"ассетами"_).
@@ -119,45 +110,11 @@ _По-умолчанию равен `StandardCharsets.UTF_8`_
### placeSkull
Установка черепа.
```java
Location location = ...;
Skull skull = BuildHelper.placeSkull(location, BlockFace.NORTH);
skull.update(true); // иначе изменения на карте не применятся и череп будет висеть в воздухе
Skull skull = BuildHelper.placeSkull(location, BlockFace.NORTH)
```
### placePlayerHead
Установка головы игрока.
```java
Location location = ...;
Skull playerHead = BuildHelper.placePlayerHead(location, BlockFace.NORTH);
playerHead.update(true); // иначе изменения на карте не применятся и голова будет висеть в воздухе
```
Если третьим параметром передать URL текстуры, то голова будет текстурирована.
```java
Location location = ...;
BuildHelper.placePlayerHead(location, BlockFace.NORTH, "http://...");
```
### setPlayerHeadSkin
Установка текстуры для головы игрока.
```java
Location location = ...;
Skull playerHead = BuildHelper.placePlayerHead(location, BlockFace.NORTH);
playerHead.update(true); // иначе изменения на карте не применятся и голова будет висеть в воздухе
setPlayerHeadSkin(playerHead);
```
Порядок выполнения методов в приведённом выше примере **важен**. Если `playerHead.update(true)` вызвать после
установки текстуры, она собъётся на стандартную.
### placeSignWall
```java

View File

@@ -1,3 +1,5 @@
import libs.LibsPlugin
subprojects {
apply plugin: 'java'
apply plugin: LibsPlugin
@@ -9,12 +11,8 @@ subprojects {
}
project.group = projectGroup
if (project.hasProperty('moduleVersion')) {
project.version = project.property('moduleVersion')
}
if (project.hasProperty('moduleName')) {
jar.archiveBaseName.set(project.property('moduleName') as String)
}
project.version = moduleVersion
jar.archiveBaseName.set(moduleName)
repositories {
mavenLocal()

View File

@@ -1,71 +0,0 @@
import org.gradle.api.Action
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
class LibsPlugin implements Plugin<Project> {
@Override
void apply(Project project) {
project.extensions.create('libs', LibsExtention)
project.extensions.create('repos', ReposExtention)
}
}
class ReposExtention {
final def mavenSpigotMC = createSimpleMavenRepo('SpigotMC repository', 'https://hub.spigotmc.org/nexus/content/groups/public')
final def mavenDmxMcProject = createSimpleMavenRepo('DmitriyMX MC Project repository', 'https://dmx-mc-project.gitlab.io/maven-repository/')
private static Action<MavenArtifactRepository> createSimpleMavenRepo(String name, String url) {
return new Action<MavenArtifactRepository>() {
@Override
void execute(MavenArtifactRepository mavenArtifactRepository) {
mavenArtifactRepository.setName(name)
mavenArtifactRepository.setUrl(url)
}
}
}
}
class LibsExtention {
private def junit_version = '5.5.2'
final def commons_text = 'org.apache.commons:commons-text:1.9'
final def lombok = 'org.projectlombok:lombok:1.18.12'
final def bukkit = filter([
lib : 'org.bukkit:bukkit:1.12.2-R0.1-SNAPSHOT',
exclude: [
'com.google.code.gson:gson',
'com.googlecode.json-simple:json-simple',
'commons-lang:commons-lang',
'org.yaml:snakeyaml'
]])
final def test = [
junit5: [
"org.junit.jupiter:junit-jupiter-api:$junit_version",
"org.junit.jupiter:junit-jupiter-engine:$junit_version"
],
mock : ['org.mockito:mockito-core:1.10.19'],
h2db : 'com.h2database:h2:1.4.200'
]
private static def filter(library) {
Object[] result = new Object[2]
result[0] = library.lib
result[1] = {
library.exclude.each { String excludeLibStr ->
String[] excludeLib = excludeLibStr.split(':', 2)
if (excludeLib.length == 2) {
exclude group: excludeLib[0], module: excludeLib[1]
} else {
exclude group: excludeLib[0]
}
}
}
return result
}
}

View File

@@ -0,0 +1,40 @@
package libs
class LibsExtention {
private def junit_version = '5.5.2'
final def commons_text = 'org.apache.commons:commons-text:1.9'
final def lombok = 'org.projectlombok:lombok:1.18.12'
final def refobj = 'ru.dmitriymx:reflection-object:1.0-BETA'
final def bukkit = filter([
lib : 'org.bukkit:bukkit:1.12.2-R0.1-SNAPSHOT',
exclude: [
'com.google.code.gson:gson',
'com.googlecode.json-simple:json-simple',
'commons-lang:commons-lang',
'org.yaml:snakeyaml'
]])
final def test = [
junit5: [
"org.junit.jupiter:junit-jupiter-api:$junit_version",
"org.junit.jupiter:junit-jupiter-engine:$junit_version"
],
mock : ['org.mockito:mockito-core:1.10.19'],
h2db : 'com.h2database:h2:1.4.200'
]
private static def filter(library) {
Object[] result = new Object[2]
result[0] = library.lib
result[1] = {
library.exclude.each { String excludeLibStr ->
String[] excludeLib = excludeLibStr.split(':')
exclude group: excludeLib[0], module: excludeLib[1]
}
}
return result
}
}

View File

@@ -0,0 +1,13 @@
package libs
import org.gradle.api.Plugin
import org.gradle.api.Project
class LibsPlugin implements Plugin<Project> {
@Override
void apply(Project project) {
project.extensions.create('libs', LibsExtention)
project.extensions.create('repos', ReposExtention)
}
}

View File

@@ -0,0 +1,20 @@
package libs
import org.gradle.api.Action
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
class ReposExtention {
final def mavenSpigotMC = createSimpleMavenRepo('SpigotMC repository', 'https://hub.spigotmc.org/nexus/content/groups/public')
final def mavenDmxMcProject = createSimpleMavenRepo('DmitriyMX MC Project repository', 'https://dmx-mc-project.gitlab.io/maven-repository/')
private static Action<MavenArtifactRepository> createSimpleMavenRepo(String name, String url) {
return new Action<MavenArtifactRepository>() {
@Override
void execute(MavenArtifactRepository mavenArtifactRepository) {
mavenArtifactRepository.setName(name)
mavenArtifactRepository.setUrl(url)
}
}
}
}

View File

@@ -1,3 +1,5 @@
dependencies {
implementation project(':tools')
compileOnly libs.bukkit
}

View File

@@ -0,0 +1,2 @@
moduleName=ghast-mg
moduleVersion=1.0-SNAPSHOT

View File

@@ -0,0 +1,29 @@
package ghast.mg;
import com.google.common.collect.Maps;
import ghast.mg.stage.GameStage;
import ghast.mg.stage.StageContext;
import lombok.Getter;
import java.util.Map;
public abstract class Game {
private final Map<GameStage, StageContext> stageMap = Maps.newHashMap();
@Getter
private GameStage stage;
public StageContext setupStage(GameStage stage) {
return stageMap.computeIfAbsent(stage, stage1 -> new StageContext(this, stage1));
}
public void changeStage(GameStage nextStage) {
StageContext stageContext = stageMap.get(nextStage);
if (stageContext != null && stageContext.getScenario() != null) {
stageContext.getScenario().run();
}
this.stage = nextStage;
}
}

View File

@@ -0,0 +1,5 @@
package ghast.mg.stage;
public interface GameStage {
}

View File

@@ -0,0 +1,47 @@
package ghast.mg.stage;
import ghast.EventContext;
import ghast.mg.Game;
import lombok.Getter;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.EventPriority;
import java.util.function.Consumer;
public class StageContext {
private final EventContext eventContext;
@Getter
private Runnable scenario;
public StageContext(Game gameInstance, GameStage stage) {
eventContext = EventContext.create();
eventContext.filter(() -> gameInstance.getStage() == (stage));
}
public StageContext onSetStage(Runnable scenario) {
this.scenario = scenario;
return this;
}
public <T extends Event> StageContext onEvent(Class<T> eventType, EventPriority eventPriority, Consumer<T> consumer) {
eventContext.onEvent(eventType, eventPriority, consumer);
return this;
}
public <T extends Event> StageContext onEvent(Class<T> eventType, Consumer<T> consumer) {
return onEvent(eventType, EventPriority.NORMAL, consumer);
}
public <T extends Event & Cancellable> StageContext cancelEvent(Class<T> eventType, EventPriority eventPriority) {
eventContext.cancelEvent(eventType, eventPriority);
return this;
}
public <T extends Event & Cancellable> StageContext cancelEvent(Class<T> eventType) {
eventContext.cancelEvent(eventType);
return this;
}
}

View File

@@ -0,0 +1,19 @@
package ghast.mg.stage;
public enum StandartGameStage implements GameStage {
/**
* Ожидание новой игровой сессии.
*/
WAIT_NEW_GAME,
/**
* Начало игровой сессии.
*/
START_GAME,
/**
* Завершение игровой сессии.
*/
END_GAME
}

View File

@@ -1,2 +0,0 @@
moduleName=phantom-classes
moduleVersion=1.0-SNAPSHOT

View File

@@ -1,16 +0,0 @@
package com.mojang.authlib;
import com.mojang.authlib.properties.PropertyMap;
import java.util.UUID;
public class GameProfile {
public GameProfile(UUID id, String name) {
}
public PropertyMap getProperties() {
return null;
}
}

View File

@@ -1,8 +0,0 @@
package com.mojang.authlib.properties;
public class Property {
public Property(String value, String name) {
}
}

View File

@@ -1,12 +0,0 @@
package com.mojang.authlib.properties;
import com.google.common.collect.ForwardingMultimap;
import com.google.common.collect.Multimap;
public class PropertyMap extends ForwardingMultimap<String, Property> {
@Override
protected Multimap<String, Property> delegate() {
return null;
}
}

View File

@@ -1,7 +0,0 @@
package net.minecraft.server.v1_12_R1;
public class BlockPosition {
public BlockPosition(double x, double y, double z) {
}
}

View File

@@ -1,5 +0,0 @@
package net.minecraft.server.v1_12_R1;
public class TileEntity {
}

View File

@@ -1,10 +0,0 @@
package net.minecraft.server.v1_12_R1;
import com.mojang.authlib.GameProfile;
public class TileEntitySkull extends TileEntity {
public void setGameProfile(GameProfile gameprofile) {
}
}

View File

@@ -1,8 +0,0 @@
package net.minecraft.server.v1_12_R1;
public class WorldServer {
public TileEntity getTileEntity(BlockPosition pos) {
return null;
}
}

View File

@@ -1,10 +0,0 @@
package org.bukkit.craftbukkit.v1_12_R1;
import org.bukkit.command.SimpleCommandMap;
public class CraftServer {
public SimpleCommandMap getCommandMap() {
return null;
}
}

View File

@@ -1,10 +0,0 @@
package org.bukkit.craftbukkit.v1_12_R1;
import net.minecraft.server.v1_12_R1.WorldServer;
public class CraftWorld {
public WorldServer getHandle() {
return null;
}
}

View File

@@ -1,2 +1,3 @@
include 'phantom-classes'
include 'tools'
include 'minigame'

View File

@@ -4,9 +4,9 @@ repositories {
}
dependencies {
compileOnly project(':phantom-classes')
compileOnly libs.bukkit
implementation libs.commons_text
implementation libs.refobj
testImplementation libs.bukkit
testImplementation libs.test.h2db

View File

@@ -1,106 +1,28 @@
package ghast;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import lombok.experimental.UtilityClass;
import net.minecraft.server.v1_12_R1.BlockPosition;
import net.minecraft.server.v1_12_R1.TileEntitySkull;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.SkullType;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Sign;
import org.bukkit.block.Skull;
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.UUID;
@UtilityClass
@SuppressWarnings("unused")
public class BuildHelper {
/**
* Установка черепа.
* <p>
* После установки, необходимо выполнить <code>skull.update(true);</code>
*
* @param location место установки.
* @param face куда будет повёрнут череп.
* @return Блок типа {@link Skull}
*/
public Skull placeSkull(Location location, BlockFace face) {
Location fixedLocation = GhastTools.copyLocation(location);
fixedLocation.setZ(fixedLocation.getZ() - 1);
Block block = location.getWorld().getBlockAt(location);
block.setType(Material.SKULL);
Skull skull = (Skull) block.getState();
skull.setRotation(face);
org.bukkit.material.Skull skullMaterial = (org.bukkit.material.Skull) skull.getData();
skullMaterial.setFacingDirection(BlockFace.SELF);
return skull;
}
/**
* Установка головы игрока.
* <p>
* После установки, необходимо выполнить <code>skull.update(true);</code>
*
* @param location место установки.
* @param face куда будет повёрнута голова.
* @return Блок типа {@link Skull}
*/
public static Skull placePlayerHead(Location location, BlockFace face) {
Location fixedLocation = GhastTools.copyLocation(location);
fixedLocation.setZ(fixedLocation.getZ() - 1);
Block block = fixedLocation.getWorld().getBlockAt(fixedLocation);
block.setType(Material.SKULL);
Skull skull = (Skull) block.getState();
skull.setSkullType(SkullType.PLAYER);
skull.setRotation(face);
org.bukkit.material.Skull skullMaterial = (org.bukkit.material.Skull) skull.getData();
skullMaterial.setFacingDirection(BlockFace.SELF);
return skull;
}
/**
* Установка текстурированной головы игрока.
*
* @param location место установки.
* @param face куда будет повёрнута голова.
* @param skinUrl URL на текстуру
* @return Блок типа {@link Skull}
*/
public static Skull placePlayerHead(Location location, BlockFace face, String skinUrl) {
Skull playerHead = placePlayerHead(location, face);
playerHead.update(true);
setPlayerHeadSkin(playerHead, skinUrl);
return playerHead;
}
/**
* Установка текстуры для головы игрока.
*
* @param skull блок головы игрока
* @param skinUrl URL на текстуру
*/
public static void setPlayerHeadSkin(Skull skull, String skinUrl) {
((TileEntitySkull) (((CraftWorld) skull.getWorld())
.getHandle()
.getTileEntity(new BlockPosition(skull.getX(), skull.getY(), skull.getZ()))))
.setGameProfile(generateTexturedPlayerProfile(skinUrl));
}
public Sign placeSignWall(Location location, BlockFace face) {
Block block = location.getWorld().getBlockAt(location);
block.setType(Material.WALL_SIGN);
@@ -111,13 +33,4 @@ public class BuildHelper {
return sign;
}
private GameProfile generateTexturedPlayerProfile(String skinUrl) {
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), null);
gameProfile.getProperties().put("textures",
new Property("textures", Base64.getEncoder().encodeToString(
("{textures:{SKIN:{url:\"" + skinUrl + "\"}}}").getBytes(StandardCharsets.UTF_8))));
return gameProfile;
}
}

View File

@@ -2,7 +2,6 @@ package ghast;
import ghast.assets.AssetsManager;
import lombok.experimental.UtilityClass;
import org.bukkit.Location;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
@@ -55,8 +54,4 @@ public class GhastTools {
public YamlConfiguration loadConfig() {
return loadConfig(true);
}
public Location copyLocation(Location location) {
return new Location(location.getWorld(), location.getX(), location.getY(), location.getZ());
}
}

View File

@@ -4,7 +4,8 @@ import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_12_R1.CraftServer;
import org.bukkit.command.Command;
import ru.dmitriymx.reflection.ReflectionObject;
@UtilityClass
@SuppressWarnings("unused")
@@ -58,9 +59,12 @@ public class CommandManager {
}
public void register() {
((CraftServer) Bukkit.getServer()).getCommandMap().register(
name,
new CommandWrapper(name, this.onlyPlayer, this.deniedMessage, this.executer, this.errorConsumer)
//TODO для Paper такие "извращения" не требуются. Нужно продумать.
new ReflectionObject(Bukkit.getServer())
.method("getCommandMap").invoke()
.method("register", String.class, Command.class).invoke(
name, new CommandWrapper(name, this.onlyPlayer, this.deniedMessage,
this.executer, this.errorConsumer)
);
}
}