Skip to content

Commit

Permalink
Merge pull request #24 from ELDEpendenci/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
eric2788 authored Sep 21, 2022
2 parents 0254e8a + 9c7feee commit ec2bf62
Show file tree
Hide file tree
Showing 39 changed files with 306 additions and 101 deletions.
2 changes: 1 addition & 1 deletion eldependenci-addon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>eldependenci</artifactId>
<groupId>org.eldependenci</groupId>
<version>2.0.1</version>
<version>2.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion eldependenci-bukkit-plugin/paper-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>eldependenci-bukkit-plugin</artifactId>
<groupId>org.eldependenci</groupId>
<version>2.0.1</version>
<version>2.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.ericlam.mc.eld;

import com.destroystokyo.paper.profile.ProfileProperty;
import com.ericlam.mc.eld.annotations.Commander;
import com.ericlam.mc.eld.bukkit.CommandNode;
import com.ericlam.mc.eld.commands.CommandProcessor;
import com.ericlam.mc.eld.commands.ELDArgumentManager;
import com.ericlam.mc.eld.commands.BukkitCommandHandler;
import com.ericlam.mc.eld.exceptions.ArgumentParseException;
import com.ericlam.mc.eld.implement.ELDMessageConfig;
import com.ericlam.mc.eld.services.factory.SkullSkinHandler;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
Expand All @@ -15,13 +17,15 @@
import org.bukkit.command.SimpleCommandMap;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.profile.PlayerProfile;

import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.logging.Logger;
import java.util.stream.Collectors;

public class ELDependenci extends BukkitPlugin {
public class ELDependenci extends BukkitPlugin implements SkullSkinHandler {

private static ELDependenciAPI api;

Expand All @@ -32,6 +36,7 @@ public static ELDependenciAPI getApi() {
@Override
public void onLoad() {
super.onLoad();
elDependenciCore.baseModule.bindInstance(SkullSkinHandler.class, this);
api = elDependenciCore;
}
@Override
Expand Down Expand Up @@ -105,4 +110,20 @@ private void printDebug(PluginCommand command, Logger logger){
e.printStackTrace();
}
}

@Override
public PlayerProfile buildProfile(String skullKey) {
String textures = """
{
"textures":{
"SKIN":{
"url": "https://textures.minecraft.net/texture/%s"
}
}
}
""".trim().formatted(skullKey);
com.destroystokyo.paper.profile.PlayerProfile profile = Bukkit.createProfile(UUID.randomUUID());
profile.setProperty(new ProfileProperty("textures", Base64.getEncoder().encodeToString(textures.getBytes(StandardCharsets.UTF_8))));
return profile;
}
}
2 changes: 1 addition & 1 deletion eldependenci-bukkit-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>eldependenci</artifactId>
<groupId>org.eldependenci</groupId>
<version>2.0.1</version>
<version>2.0.2</version>
</parent>

<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion eldependenci-bukkit-plugin/spigot-based/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>eldependenci-bukkit-plugin</artifactId>
<groupId>org.eldependenci</groupId>
<version>2.0.1</version>
<version>2.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.ericlam.mc.eld;

import com.ericlam.mc.eld.module.ELDPluginModule;
import com.ericlam.mc.eld.guice.ELDPluginModule;
import com.ericlam.mc.eld.services.ItemStackService;
import com.ericlam.mc.eld.services.ScheduleService;
import com.ericlam.mc.eld.services.factory.ELDItemStackService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.ericlam.mc.eld.implement.ELDMessageConfig;
import com.ericlam.mc.eld.listener.LifeCycleListener;
import com.ericlam.mc.eld.managers.ItemInteractManager;
import com.ericlam.mc.eld.module.ELDPluginModule;
import com.ericlam.mc.eld.guice.ELDPluginModule;
import com.fasterxml.jackson.databind.module.SimpleModule;
import net.md_5.bungee.api.chat.BaseComponent;
import org.bukkit.Bukkit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
import com.ericlam.mc.eld.ItemInteractListener;
import com.ericlam.mc.eld.managers.ItemInteractManager;
import com.ericlam.mc.eld.services.ItemStackService;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.profile.PlayerProfile;

import javax.inject.Inject;
import java.util.*;
Expand All @@ -22,8 +26,10 @@

@SuppressWarnings("deprecated")
public final class ELDItemStackService implements ItemStackService {



@Inject
private SkullSkinHandler skullSkinHandler;

private final ItemInteractListener itemInteractManager;

@Inject
Expand Down Expand Up @@ -135,6 +141,31 @@ public ItemFactory enchant(Consumer<Map<Enchantment, Integer>> enchantEditor) {
return this;
}

@Override
public ItemFactory head(OfflinePlayer player) {
if (itemStack.getType() != Material.PLAYER_HEAD || itemStack.getType() != Material.PLAYER_WALL_HEAD) {
throw new IllegalStateException("ItemStack is not a head");
}
SkullMeta meta = (SkullMeta) itemStack.getItemMeta();
if (meta == null) return this;
meta.setOwningPlayer(player);
itemStack.setItemMeta(meta);
return this;
}

@Override
public ItemFactory head(String skullKey) {
if (itemStack.getType() != Material.PLAYER_HEAD || itemStack.getType() != Material.PLAYER_WALL_HEAD) {
throw new IllegalStateException("ItemStack is not a head");
}
SkullMeta meta = (SkullMeta) itemStack.getItemMeta();
if (meta == null) return this;
PlayerProfile profile = skullSkinHandler.buildProfile(skullKey);
meta.setOwnerProfile(profile);
itemStack.setItemMeta(meta);
return this;
}

@Override
public ItemFactory unbreakable(boolean unbreakable) {
var meta = itemStack.getItemMeta();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.ericlam.mc.eld.services.factory;

import org.bukkit.profile.PlayerProfile;

public interface SkullSkinHandler {

PlayerProfile buildProfile(String skullKey);

}
2 changes: 1 addition & 1 deletion eldependenci-bukkit-plugin/spigot-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>eldependenci-bukkit-plugin</artifactId>
<groupId>org.eldependenci</groupId>
<version>2.0.1</version>
<version>2.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@
import com.ericlam.mc.eld.bukkit.CommandNode;
import com.ericlam.mc.eld.commands.BukkitCommandHandler;
import com.ericlam.mc.eld.commands.CommandProcessor;
import com.ericlam.mc.eld.services.factory.SkullSkinHandler;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.SimpleCommandMap;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.SimplePluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.profile.PlayerProfile;
import org.bukkit.profile.PlayerTextures;

import java.lang.reflect.Field;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;

public class ELDependenci extends BukkitPlugin {
public class ELDependenci extends BukkitPlugin implements SkullSkinHandler {

private static ELDependenciAPI api;

Expand All @@ -26,6 +32,7 @@ public static ELDependenciAPI getApi() {
@Override
public void onLoad() {
super.onLoad();
elDependenciCore.baseModule.bindInstance(SkullSkinHandler.class, this);
api = elDependenciCore;
}

Expand Down Expand Up @@ -78,4 +85,18 @@ public void registerCommand(JavaPlugin plugin, Set<HierarchyNode<? extends Comma
}
}
}

@Override
public PlayerProfile buildProfile(String skullKey) {
PlayerProfile profile = Bukkit.getServer().createPlayerProfile(UUID.randomUUID());
PlayerTextures textures = profile.getTextures();
try {
URL url = new URL(String.format("https://textures.minecraft.net/texture/%s", skullKey));
textures.setSkin(url);
}catch (MalformedURLException e){
getLogger().warning("Error while setting skull skin: "+e.getMessage());
e.printStackTrace();
}
return profile;
}
}
2 changes: 1 addition & 1 deletion eldependenci-bukkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>eldependenci</artifactId>
<groupId>org.eldependenci</groupId>
<version>2.0.1</version>
<version>2.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ericlam.mc.eld.services;

import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
Expand Down Expand Up @@ -108,6 +109,22 @@ interface ItemFactory {
*/
ItemFactory enchant(Consumer<Map<Enchantment, Integer>> enchantEditor);

/**
* 設置頭顱皮膚, 物品必須為 PLAYER_HEAD
* @deprecated 不建議使用,因為每次使用都會請求 URL, 建議使用 {@link #head(String)}
* @param player 玩家
* @return this
*/
@Deprecated
ItemFactory head(OfflinePlayer player);

/**
* 設置頭顱皮膚, 物品必須為 PLAYER_HEAD
* @param skullKey 皮膚ID
* @return this
*/
ItemFactory head(String skullKey);

/**
* 設置不可破壞
* @param unbreakable 不可破壞
Expand Down
2 changes: 1 addition & 1 deletion eldependenci-bungee-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>eldependenci</artifactId>
<groupId>org.eldependenci</groupId>
<version>2.0.1</version>
<version>2.0.2</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.ericlam.mc.eld;

import com.ericlam.mc.eld.module.ELDPluginModule;
import com.ericlam.mc.eld.guice.ELDPluginModule;
import net.md_5.bungee.api.plugin.Plugin;

public class BungeePluginModule extends ELDPluginModule<Plugin> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.ericlam.mc.eld.exceptions.ArgumentParseException;
import com.ericlam.mc.eld.implement.ELDMessageConfig;
import com.ericlam.mc.eld.listener.LifeCycleListener;
import com.ericlam.mc.eld.module.ELDPluginModule;
import com.ericlam.mc.eld.guice.ELDPluginModule;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
Expand Down
2 changes: 1 addition & 1 deletion eldependenci-bungee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>eldependenci</artifactId>
<groupId>org.eldependenci</groupId>
<version>2.0.1</version>
<version>2.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion eldependenci-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>eldependenci</artifactId>
<groupId>org.eldependenci</groupId>
<version>2.0.1</version>
<version>2.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.ericlam.mc.eld.components.Configuration;
import com.ericlam.mc.eld.components.Overridable;
import com.ericlam.mc.eld.services.ELDMessageService;
import com.ericlam.mc.eld.services.MessageService;
import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.Scopes;
Expand Down Expand Up @@ -53,6 +55,9 @@ private void setScope(ScopedBindingBuilder bindingBuilder) {
@Override
public void configure(Binder binder) {

// bind internal service
binder.bind(MessageService.class).to(ELDMessageService.class).in(Scopes.SINGLETON);

modules.forEach(binder::install);
singleton.forEach(cls -> setScope(binder.bind(cls)));
serviceProviders.forEach((service, provider) -> setScope(binder.bind(service).toProvider(provider)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@
import com.ericlam.mc.eld.implement.ELDMessageConfig;
import com.ericlam.mc.eld.listener.LifeCycleListener;
import com.ericlam.mc.eld.misc.DebugLogger;
import com.ericlam.mc.eld.module.ELDConfigModule;
import com.ericlam.mc.eld.module.ELDLoggingModule;
import com.ericlam.mc.eld.module.ELDPluginModule;
import com.ericlam.mc.eld.services.ArgParserService;
import com.ericlam.mc.eld.services.ELDConfigPoolService;
import com.ericlam.mc.eld.services.ELDReflectionService;
import com.ericlam.mc.eld.services.LoggingService;
import com.ericlam.mc.eld.guice.ELDConfigModule;
import com.ericlam.mc.eld.guice.ELDLoggingModule;
import com.ericlam.mc.eld.guice.ELDPluginModule;
import com.ericlam.mc.eld.services.*;
import com.ericlam.mc.eld.services.logging.ELDLoggingService;
import com.google.inject.Guice;
import com.google.inject.Injector;
Expand Down Expand Up @@ -86,8 +83,9 @@ public void onMainLoad() {
groupConfigService = new ELDConfigPoolService(coreConfig.fileWalker, configHandler);
this.baseModule.setDefaultSingleton(coreConfig.defaultSingleton);
this.sharePluginInstance = coreConfig.sharePluginInstance;
this.baseModule.addModule(new ELDConfigModule(groupConfigService, new ELDReflectionService()));
this.baseModule.addModule(new ELDLoggingModule(new ELDLoggingService(coreConfig, this.mcPlugin.getLogger())));
final ReflectionService reflectionService = new ELDReflectionService();
this.baseModule.addModule(new ELDConfigModule(groupConfigService, reflectionService));
this.baseModule.addModule(new ELDLoggingModule(new ELDLoggingService(coreConfig, this.mcPlugin.getLogger()), reflectionService));
this.customInstallation(AddonInstallation.class, this);
this.installModule(eldPluginModule);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.ericlam.mc.eld.commands.ELDArgumentManager;
import com.ericlam.mc.eld.common.CommonCommandNode;
import com.ericlam.mc.eld.listener.LifeCycleListener;
import com.ericlam.mc.eld.module.ELDPluginModule;
import com.ericlam.mc.eld.guice.ELDPluginModule;

import java.util.Map;
import java.util.Set;
Expand Down
Loading

0 comments on commit ec2bf62

Please sign in to comment.