mirror of
https://github.com/songoda/EpicHeads.git
synced 2024-11-26 12:35:37 +01:00
Merge branch 'development' into 'master'
Development See merge request Songoda/epicheads!12
This commit is contained in:
commit
408098cd6d
@ -1,10 +1,7 @@
|
||||
package com.songoda.epicheads.command;
|
||||
|
||||
import com.songoda.epicheads.EpicHeads;
|
||||
import com.songoda.epicheads.command.commands.CommandEpicHeads;
|
||||
import com.songoda.epicheads.command.commands.CommandHelp;
|
||||
import com.songoda.epicheads.command.commands.CommandReload;
|
||||
import com.songoda.epicheads.command.commands.CommandSettings;
|
||||
import com.songoda.epicheads.command.commands.*;
|
||||
import com.songoda.epicheads.utils.Methods;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -33,6 +30,9 @@ public class CommandManager implements CommandExecutor {
|
||||
addCommand(new CommandSettings(commandEpicHeads));
|
||||
addCommand(new CommandHelp(commandEpicHeads));
|
||||
addCommand(new CommandReload(commandEpicHeads));
|
||||
addCommand(new CommandUrl(commandEpicHeads));
|
||||
addCommand(new CommandBase64(commandEpicHeads));
|
||||
addCommand(new CommandGive(commandEpicHeads));
|
||||
|
||||
for (AbstractCommand abstractCommand : commands) {
|
||||
if (abstractCommand.getParent() != null) continue;
|
||||
|
@ -0,0 +1,55 @@
|
||||
package com.songoda.epicheads.command.commands;
|
||||
|
||||
import com.songoda.epicheads.EpicHeads;
|
||||
import com.songoda.epicheads.command.AbstractCommand;
|
||||
import com.songoda.epicheads.utils.Methods;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandBase64 extends AbstractCommand {
|
||||
|
||||
public CommandBase64(AbstractCommand parent) {
|
||||
super(parent, true, "base64");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) {
|
||||
|
||||
Player player = (Player)sender;
|
||||
|
||||
ItemStack item = player.getItemInHand();
|
||||
|
||||
if (!item.hasItemMeta() || !(item.getItemMeta() instanceof SkullMeta)) return ReturnType.FAILURE;
|
||||
|
||||
String encodededStr = Methods.getEncodedTexture(item);
|
||||
|
||||
player.sendMessage(instance.getReferences().getPrefix());
|
||||
player.sendMessage(encodededStr);
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicHeads instance, CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "epicheads.base64";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/epicheads base64";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Gives you the base64 code of the head you are holding.";
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package com.songoda.epicheads.command.commands;
|
||||
|
||||
import com.songoda.epicheads.EpicHeads;
|
||||
import com.songoda.epicheads.command.AbstractCommand;
|
||||
import com.songoda.epicheads.head.Head;
|
||||
import com.songoda.epicheads.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class CommandGive extends AbstractCommand {
|
||||
|
||||
public CommandGive(AbstractCommand parent) {
|
||||
super(parent, false, "give");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) {
|
||||
|
||||
if (args.length != 4) return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
Player player = Bukkit.getPlayer(args[1]);
|
||||
String archive = args[2];
|
||||
int headId = Integer.parseInt(args[3]);
|
||||
|
||||
if (player == null) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.give.notonline", args[1]));
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
List<Head> heads;
|
||||
|
||||
if (archive.equalsIgnoreCase("global"))
|
||||
heads = instance.getHeadManager().getGlobalHeads();
|
||||
else if (archive.equalsIgnoreCase("local"))
|
||||
heads = instance.getHeadManager().getLocalHeads();
|
||||
else {
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
Optional<Head> head = heads.stream().filter(h -> h.getId() == headId).findFirst();
|
||||
|
||||
if (head.isPresent()) {
|
||||
ItemStack item = head.get().asItemStack();
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setLore(new ArrayList<>());
|
||||
item.setItemMeta(meta);
|
||||
|
||||
player.getInventory().addItem(item);
|
||||
} else {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.give.notfound", head.get().getName()));
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.give.success", player.getName(), head.get().getName()));
|
||||
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.give.receive", head.get().getName()));
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicHeads instance, CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "epicheads.give";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/heads give <player> <global/local> <head_id>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Gives the specified player the specified amount of heads.";
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package com.songoda.epicheads.command.commands;
|
||||
|
||||
import com.songoda.epicheads.EpicHeads;
|
||||
import com.songoda.epicheads.command.AbstractCommand;
|
||||
import com.songoda.epicheads.utils.Methods;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandUrl extends AbstractCommand {
|
||||
|
||||
public CommandUrl(AbstractCommand parent) {
|
||||
super(parent, true, "url");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) {
|
||||
|
||||
Player player = (Player)sender;
|
||||
|
||||
ItemStack item = player.getItemInHand();
|
||||
|
||||
if (!item.hasItemMeta() || !(item.getItemMeta() instanceof SkullMeta)) return ReturnType.FAILURE;
|
||||
|
||||
String encodededStr = Methods.getEncodedTexture(item);
|
||||
String url = Methods.getDecodedTexture(encodededStr);
|
||||
|
||||
player.sendMessage(instance.getReferences().getPrefix());
|
||||
player.sendMessage("http://textures.minecraft.net/texture/" + url);
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicHeads instance, CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "epicheads.url";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/epicheads url";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Gives you the texture url for the head you are holding.";
|
||||
}
|
||||
}
|
@ -72,6 +72,10 @@ public class HeadManager {
|
||||
return Collections.unmodifiableList(localRegisteredHeads);
|
||||
}
|
||||
|
||||
public List<Head> getGlobalHeads() {
|
||||
return new ArrayList<>(registeredHeads);
|
||||
}
|
||||
|
||||
public void removeLocalHead(Head head) {
|
||||
localRegisteredHeads.remove(head);
|
||||
}
|
||||
|
@ -33,7 +33,8 @@ public class ItemListeners implements Listener {
|
||||
|
||||
event.getItem().removeMetadata("EHE", plugin);
|
||||
|
||||
String url = Methods.getDecodedTexture(item);
|
||||
String encodededStr = Methods.getEncodedTexture(item);
|
||||
String url = Methods.getDecodedTexture(encodededStr);
|
||||
|
||||
if (url == null) return;
|
||||
Optional<Head> optional = plugin.getHeadManager().getHeads().stream()
|
||||
|
@ -36,7 +36,9 @@ public class LoginListeners implements Listener {
|
||||
meta.setOwningPlayer(player);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
String url = Methods.getDecodedTexture(item);
|
||||
String encodededStr = Methods.getEncodedTexture(item);
|
||||
String url = Methods.getDecodedTexture(encodededStr);
|
||||
|
||||
|
||||
String tagStr = "Player Heads";
|
||||
|
||||
|
@ -36,7 +36,7 @@ public class Methods {
|
||||
return item;
|
||||
}
|
||||
|
||||
public static String getDecodedTexture(ItemStack item) {
|
||||
public static String getEncodedTexture(ItemStack item) {
|
||||
try {
|
||||
SkullMeta localSkullMeta = (SkullMeta) item.getItemMeta();
|
||||
Field localField = localSkullMeta.getClass().getDeclaredField("profile");
|
||||
@ -45,8 +45,7 @@ public class Methods {
|
||||
Iterator localIterator = localGameProfile.getProperties().get("textures").iterator();
|
||||
if (localIterator.hasNext()) {
|
||||
Property localProperty = (Property) localIterator.next();
|
||||
byte[] decoded = Base64.getDecoder().decode(localProperty.getValue());
|
||||
return StringUtils.substringBetween(new String(decoded), "texture/", "\"");
|
||||
return localProperty.getValue();
|
||||
}
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
@ -54,6 +53,10 @@ public class Methods {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getDecodedTexture(String decoded) {
|
||||
return StringUtils.substringBetween(new String(Base64.getDecoder().decode(decoded)), "texture/", "\"");
|
||||
}
|
||||
|
||||
public static ItemStack getGlass() {
|
||||
EpicHeads instance = EpicHeads.getInstance();
|
||||
return Methods.getGlass(instance.getConfig().getBoolean("Interfaces.Replace Glass Type 1 With Rainbow Glass"), instance.getConfig().getInt("Interfaces.Glass Type 1"));
|
||||
|
@ -27,4 +27,9 @@ gui.overview.discord = "&9&lDiscord"
|
||||
gui.overview.discordlore = "&8Add or request new heads|&8in our discord server."
|
||||
|
||||
event.general.nopermission = "&cYou do not have permission to use that command."
|
||||
event.buyhead.cannotafford = "&cYou cannot afford this head."
|
||||
event.buyhead.cannotafford = "&cYou cannot afford this head."
|
||||
|
||||
command.give.notonline = "&cThe player &4%name% &ccould not be found."
|
||||
command.give.notfound = "&cThe head &4%name%&c could not be found."
|
||||
command.give.success = "&7You have been given &6%player% &7a head named &6%name%&7."
|
||||
command.give.receive = "&7You have been given a head named &6%name%&7."
|
Loading…
Reference in New Issue
Block a user