Compare commits
7 Commits
dev/mgf
...
feature/ph
| Author | SHA1 | Date | |
|---|---|---|---|
|
f2ab5521d1
|
|||
|
d686f56b0c
|
|||
|
070485e951
|
|||
|
16ae1743c7
|
|||
|
8afba72b77
|
|||
|
002dae285c
|
|||
|
c0f02d20d5
|
45
README.MD
45
README.MD
@@ -62,6 +62,15 @@ YamlConfiguration config = GhastTools.loadConfig(false);
|
||||
Если передать параметр `false`, то при отсутствии файла `config.yml` в папке плагина,
|
||||
будет загруден исключительно встроенный файл настроек.
|
||||
|
||||
### copyLocation
|
||||
|
||||
Копирования объекта `Location`
|
||||
|
||||
```java
|
||||
Location location = ...;
|
||||
Location copyLoc = GhastTools.copyLocation(location);
|
||||
```
|
||||
|
||||
## AssetsManager
|
||||
|
||||
Методы по работе с файлами плагина (_"ассетами"_).
|
||||
@@ -110,11 +119,45 @@ _По-умолчанию равен `StandardCharsets.UTF_8`_
|
||||
|
||||
### placeSkull
|
||||
|
||||
Установка черепа.
|
||||
|
||||
```java
|
||||
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
|
||||
|
||||
```java
|
||||
|
||||
@@ -5,7 +5,6 @@ class LibsExtention {
|
||||
|
||||
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',
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
moduleName=ghast-mg
|
||||
moduleVersion=1.0-SNAPSHOT
|
||||
@@ -1,29 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package ghast.mg.stage;
|
||||
|
||||
public interface GameStage {
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package ghast.mg.stage;
|
||||
|
||||
public enum StandartGameStage implements GameStage {
|
||||
|
||||
/**
|
||||
* Ожидание новой игровой сессии.
|
||||
*/
|
||||
WAIT_NEW_GAME,
|
||||
|
||||
/**
|
||||
* Начало игровой сессии.
|
||||
*/
|
||||
START_GAME,
|
||||
|
||||
/**
|
||||
* Завершение игровой сессии.
|
||||
*/
|
||||
END_GAME
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
dependencies {
|
||||
implementation project(':tools')
|
||||
|
||||
compileOnly libs.bukkit
|
||||
}
|
||||
2
phantom-classes/gradle.properties
Normal file
2
phantom-classes/gradle.properties
Normal file
@@ -0,0 +1,2 @@
|
||||
moduleName=phantom-classes
|
||||
moduleVersion=1.0-SNAPSHOT
|
||||
@@ -0,0 +1,16 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.mojang.authlib.properties;
|
||||
|
||||
public class Property {
|
||||
|
||||
public Property(String value, String name) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package net.minecraft.server.v1_12_R1;
|
||||
|
||||
public class BlockPosition {
|
||||
|
||||
public BlockPosition(double x, double y, double z) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package net.minecraft.server.v1_12_R1;
|
||||
|
||||
public class TileEntity {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package net.minecraft.server.v1_12_R1;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
public class TileEntitySkull extends TileEntity {
|
||||
|
||||
public void setGameProfile(GameProfile gameprofile) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package net.minecraft.server.v1_12_R1;
|
||||
|
||||
public class WorldServer {
|
||||
|
||||
public TileEntity getTileEntity(BlockPosition pos) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.bukkit.craftbukkit.v1_12_R1;
|
||||
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
|
||||
public class CraftServer {
|
||||
|
||||
public SimpleCommandMap getCommandMap() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.bukkit.craftbukkit.v1_12_R1;
|
||||
|
||||
import net.minecraft.server.v1_12_R1.WorldServer;
|
||||
|
||||
public class CraftWorld {
|
||||
|
||||
public WorldServer getHandle() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,2 @@
|
||||
include 'phantom-classes'
|
||||
include 'tools'
|
||||
include 'minigame'
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,28 +1,106 @@
|
||||
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);
|
||||
@@ -33,4 +111,13 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ 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;
|
||||
|
||||
@@ -54,4 +55,8 @@ 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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,7 @@ import lombok.AccessLevel;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import ru.dmitriymx.reflection.ReflectionObject;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.CraftServer;
|
||||
|
||||
@UtilityClass
|
||||
@SuppressWarnings("unused")
|
||||
@@ -59,13 +58,10 @@ public class CommandManager {
|
||||
}
|
||||
|
||||
public void register() {
|
||||
//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)
|
||||
);
|
||||
((CraftServer) Bukkit.getServer()).getCommandMap().register(
|
||||
name,
|
||||
new CommandWrapper(name, this.onlyPlayer, this.deniedMessage, this.executer, this.errorConsumer)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user