Compare commits
1 Commits
dev/module
...
dev/mgf
| Author | SHA1 | Date | |
|---|---|---|---|
|
6f51bedba1
|
45
README.MD
45
README.MD
@@ -62,15 +62,6 @@ YamlConfiguration config = GhastTools.loadConfig(false);
|
|||||||
Если передать параметр `false`, то при отсутствии файла `config.yml` в папке плагина,
|
Если передать параметр `false`, то при отсутствии файла `config.yml` в папке плагина,
|
||||||
будет загруден исключительно встроенный файл настроек.
|
будет загруден исключительно встроенный файл настроек.
|
||||||
|
|
||||||
### copyLocation
|
|
||||||
|
|
||||||
Копирования объекта `Location`
|
|
||||||
|
|
||||||
```java
|
|
||||||
Location location = ...;
|
|
||||||
Location copyLoc = GhastTools.copyLocation(location);
|
|
||||||
```
|
|
||||||
|
|
||||||
## AssetsManager
|
## AssetsManager
|
||||||
|
|
||||||
Методы по работе с файлами плагина (_"ассетами"_).
|
Методы по работе с файлами плагина (_"ассетами"_).
|
||||||
@@ -119,45 +110,11 @@ _По-умолчанию равен `StandardCharsets.UTF_8`_
|
|||||||
|
|
||||||
### placeSkull
|
### placeSkull
|
||||||
|
|
||||||
Установка черепа.
|
|
||||||
|
|
||||||
```java
|
```java
|
||||||
Location location = ...;
|
Location location = ...;
|
||||||
Skull skull = BuildHelper.placeSkull(location, BlockFace.NORTH);
|
Skull skull = BuildHelper.placeSkull(location, BlockFace.NORTH)
|
||||||
skull.update(true); // иначе изменения на карте не применятся и череп будет висеть в воздухе
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### 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
|
### placeSignWall
|
||||||
|
|
||||||
```java
|
```java
|
||||||
|
|||||||
10
build.gradle
10
build.gradle
@@ -1,3 +1,5 @@
|
|||||||
|
import libs.LibsPlugin
|
||||||
|
|
||||||
subprojects {
|
subprojects {
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
apply plugin: LibsPlugin
|
apply plugin: LibsPlugin
|
||||||
@@ -9,12 +11,8 @@ subprojects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
project.group = projectGroup
|
project.group = projectGroup
|
||||||
if (project.hasProperty('moduleVersion')) {
|
project.version = moduleVersion
|
||||||
project.version = project.property('moduleVersion')
|
jar.archiveBaseName.set(moduleName)
|
||||||
}
|
|
||||||
if (project.hasProperty('moduleName')) {
|
|
||||||
jar.archiveBaseName.set(project.property('moduleName') as String)
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
40
buildSrc/src/main/groovy/libs/LibsExtention.groovy
Normal file
40
buildSrc/src/main/groovy/libs/LibsExtention.groovy
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
13
buildSrc/src/main/groovy/libs/LibsPlugin.groovy
Normal file
13
buildSrc/src/main/groovy/libs/LibsPlugin.groovy
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
20
buildSrc/src/main/groovy/libs/ReposExtention.groovy
Normal file
20
buildSrc/src/main/groovy/libs/ReposExtention.groovy
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
dependencies {
|
dependencies {
|
||||||
|
implementation project(':tools')
|
||||||
|
|
||||||
compileOnly libs.bukkit
|
compileOnly libs.bukkit
|
||||||
}
|
}
|
||||||
2
minigame/gradle.properties
Normal file
2
minigame/gradle.properties
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
moduleName=ghast-mg
|
||||||
|
moduleVersion=1.0-SNAPSHOT
|
||||||
29
minigame/src/main/java/ghast/mg/Game.java
Normal file
29
minigame/src/main/java/ghast/mg/Game.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
5
minigame/src/main/java/ghast/mg/stage/GameStage.java
Normal file
5
minigame/src/main/java/ghast/mg/stage/GameStage.java
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package ghast.mg.stage;
|
||||||
|
|
||||||
|
public interface GameStage {
|
||||||
|
|
||||||
|
}
|
||||||
47
minigame/src/main/java/ghast/mg/stage/StageContext.java
Normal file
47
minigame/src/main/java/ghast/mg/stage/StageContext.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
19
minigame/src/main/java/ghast/mg/stage/StandartGameStage.java
Normal file
19
minigame/src/main/java/ghast/mg/stage/StandartGameStage.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package ghast.mg.stage;
|
||||||
|
|
||||||
|
public enum StandartGameStage implements GameStage {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ожидание новой игровой сессии.
|
||||||
|
*/
|
||||||
|
WAIT_NEW_GAME,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Начало игровой сессии.
|
||||||
|
*/
|
||||||
|
START_GAME,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Завершение игровой сессии.
|
||||||
|
*/
|
||||||
|
END_GAME
|
||||||
|
}
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
moduleName=phantom-classes
|
|
||||||
moduleVersion=1.0-SNAPSHOT
|
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package com.mojang.authlib.properties;
|
|
||||||
|
|
||||||
public class Property {
|
|
||||||
|
|
||||||
public Property(String value, String name) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package net.minecraft.server.v1_12_R1;
|
|
||||||
|
|
||||||
public class BlockPosition {
|
|
||||||
|
|
||||||
public BlockPosition(double x, double y, double z) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package net.minecraft.server.v1_12_R1;
|
|
||||||
|
|
||||||
public class TileEntity {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package net.minecraft.server.v1_12_R1;
|
|
||||||
|
|
||||||
public class WorldServer {
|
|
||||||
|
|
||||||
public TileEntity getTileEntity(BlockPosition pos) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package org.bukkit.craftbukkit.v1_12_R1;
|
|
||||||
|
|
||||||
import org.bukkit.command.SimpleCommandMap;
|
|
||||||
|
|
||||||
public class CraftServer {
|
|
||||||
|
|
||||||
public SimpleCommandMap getCommandMap() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
include 'phantom-classes'
|
|
||||||
include 'tools'
|
include 'tools'
|
||||||
|
include 'minigame'
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly project(':phantom-classes')
|
|
||||||
compileOnly libs.bukkit
|
compileOnly libs.bukkit
|
||||||
implementation libs.commons_text
|
implementation libs.commons_text
|
||||||
|
implementation libs.refobj
|
||||||
|
|
||||||
testImplementation libs.bukkit
|
testImplementation libs.bukkit
|
||||||
testImplementation libs.test.h2db
|
testImplementation libs.test.h2db
|
||||||
|
|||||||
@@ -1,106 +1,28 @@
|
|||||||
package ghast;
|
package ghast;
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
import com.mojang.authlib.properties.Property;
|
|
||||||
import lombok.experimental.UtilityClass;
|
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.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.SkullType;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.block.Skull;
|
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
|
@UtilityClass
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class BuildHelper {
|
public class BuildHelper {
|
||||||
|
|
||||||
/**
|
|
||||||
* Установка черепа.
|
|
||||||
* <p>
|
|
||||||
* После установки, необходимо выполнить <code>skull.update(true);</code>
|
|
||||||
*
|
|
||||||
* @param location место установки.
|
|
||||||
* @param face куда будет повёрнут череп.
|
|
||||||
* @return Блок типа {@link Skull}
|
|
||||||
*/
|
|
||||||
public Skull placeSkull(Location location, BlockFace face) {
|
public Skull placeSkull(Location location, BlockFace face) {
|
||||||
Location fixedLocation = GhastTools.copyLocation(location);
|
|
||||||
fixedLocation.setZ(fixedLocation.getZ() - 1);
|
|
||||||
|
|
||||||
Block block = location.getWorld().getBlockAt(location);
|
Block block = location.getWorld().getBlockAt(location);
|
||||||
block.setType(Material.SKULL);
|
block.setType(Material.SKULL);
|
||||||
|
|
||||||
Skull skull = (Skull) block.getState();
|
Skull skull = (Skull) block.getState();
|
||||||
skull.setRotation(face);
|
skull.setRotation(face);
|
||||||
|
|
||||||
org.bukkit.material.Skull skullMaterial = (org.bukkit.material.Skull) skull.getData();
|
org.bukkit.material.Skull skullMaterial = (org.bukkit.material.Skull) skull.getData();
|
||||||
skullMaterial.setFacingDirection(BlockFace.SELF);
|
skullMaterial.setFacingDirection(BlockFace.SELF);
|
||||||
|
|
||||||
return skull;
|
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) {
|
public Sign placeSignWall(Location location, BlockFace face) {
|
||||||
Block block = location.getWorld().getBlockAt(location);
|
Block block = location.getWorld().getBlockAt(location);
|
||||||
block.setType(Material.WALL_SIGN);
|
block.setType(Material.WALL_SIGN);
|
||||||
@@ -111,13 +33,4 @@ public class BuildHelper {
|
|||||||
|
|
||||||
return sign;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package ghast;
|
|||||||
|
|
||||||
import ghast.assets.AssetsManager;
|
import ghast.assets.AssetsManager;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
@@ -55,8 +54,4 @@ public class GhastTools {
|
|||||||
public YamlConfiguration loadConfig() {
|
public YamlConfiguration loadConfig() {
|
||||||
return loadConfig(true);
|
return loadConfig(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location copyLocation(Location location) {
|
|
||||||
return new Location(location.getWorld(), location.getX(), location.getY(), location.getZ());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ import lombok.AccessLevel;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.craftbukkit.v1_12_R1.CraftServer;
|
import org.bukkit.command.Command;
|
||||||
|
import ru.dmitriymx.reflection.ReflectionObject;
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@@ -58,9 +59,12 @@ public class CommandManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void register() {
|
public void register() {
|
||||||
((CraftServer) Bukkit.getServer()).getCommandMap().register(
|
//TODO для Paper такие "извращения" не требуются. Нужно продумать.
|
||||||
name,
|
new ReflectionObject(Bukkit.getServer())
|
||||||
new CommandWrapper(name, this.onlyPlayer, this.deniedMessage, this.executer, this.errorConsumer)
|
.method("getCommandMap").invoke()
|
||||||
|
.method("register", String.class, Command.class).invoke(
|
||||||
|
name, new CommandWrapper(name, this.onlyPlayer, this.deniedMessage,
|
||||||
|
this.executer, this.errorConsumer)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user