Commit 0bdf5933 authored by Ashijin's avatar Ashijin
Browse files

bwabwabwabwa

parent ad00a6d2
package io.lumine.cosmetics.api.cosmetics;
import io.lumine.cosmetics.api.players.CosmeticProfile;
public interface Cosmetic {
public boolean has(CosmeticProfile profile);
public boolean equip(CosmeticProfile profile);
public boolean isEquipped(CosmeticProfile profile);
}
package io.lumine.cosmetics.api.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import io.lumine.cosmetics.api.players.CosmeticProfile;
import lombok.Getter;
public class CosmeticPlayerLoadedEvent extends Event {
@Getter private final Player player;
@Getter private final CosmeticProfile profile;
public CosmeticPlayerLoadedEvent(Player player, CosmeticProfile profile) {
super(false);
this.player = player;
this.profile = profile;
}
/*
* Standard event stuff
*/
private static final HandlerList handlers = new HandlerList();
private boolean canceled = false;
public void setCancelled(boolean bool) {
this.canceled = bool;
}
public boolean isCancelled() {
return this.canceled;
}
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}
\ No newline at end of file
package io.lumine.cosmetics.api.players;
import java.util.UUID;
public interface CosmeticProfile {
public UUID getUniqueId();
public String getName();
}
package io.lumine.cosmetics.api.players;
public interface CosmeticProfileManager {
}
package io.lumine.cosmetics;
import org.bukkit.Bukkit;
import io.lumine.cosmetics.api.MCCosmetics;
import io.lumine.cosmetics.commands.BaseCommand;
import io.lumine.cosmetics.commands.admin.AdminCommand;
import io.lumine.cosmetics.compat.CompatibilityManager;
......@@ -142,7 +144,7 @@ public class MCCosmeticsPlugin extends LuminePlugin {
try {
final Class<?> clazz = Class.forName("io.lumine.cosmetics.nms.VolatileCodeEnabled_" + version);
if (VolatileCodeHandler.class.isAssignableFrom(clazz)) {
VCH = (VolatileCodeHandler) clazz.getConstructor().newInstance();
VCH = (VolatileCodeHandler) clazz.getConstructor(MCCosmetics.class).newInstance(this);
}
} catch (final ClassNotFoundException e) {
MCLogger.error(ColorString.get("&6--====|||| &c&lMCCosmetics &6||||====--"));
......
package io.lumine.cosmetics.managers.hats;
import java.util.Collections;
import java.util.List;
import java.util.function.BiConsumer;
import org.bukkit.Material;
import org.bukkit.block.data.type.Piston;
import org.bukkit.block.data.type.TechnicalPiston;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.google.common.collect.Lists;
import io.lumine.cosmetics.commands.CommandHelper;
import io.lumine.cosmetics.config.Scope;
import io.lumine.cosmetics.players.Profile;
import io.lumine.utils.config.properties.Property;
import io.lumine.utils.config.properties.PropertyHolder;
import io.lumine.utils.config.properties.types.BooleanProp;
import io.lumine.utils.config.properties.types.EnumProp;
import io.lumine.utils.config.properties.types.IntProp;
import io.lumine.utils.config.properties.types.LangListProp;
import io.lumine.utils.config.properties.types.LangProp;
import io.lumine.utils.config.properties.types.StringListProp;
import io.lumine.utils.config.properties.types.StringProp;
import io.lumine.utils.items.ItemFactory;
import io.lumine.utils.menu.Icon;
import io.lumine.utils.menu.IconBuilder;
import io.lumine.utils.menu.MenuData;
import io.lumine.utils.text.Text;
import lombok.Data;
import lombok.Getter;
@Data
public class Hat implements PropertyHolder,MenuData<Profile> {
private static final EnumProp<Material> MATERIAL = Property.Enum(Scope.NONE, Material.class, "Material", Material.EMERALD);
private static final IntProp MODEL = Property.Int(Scope.NONE, "Model");
private static final LangProp DISPLAY = Property.Lang(Scope.NONE, "Display");
private static final LangListProp DESCRIPTION = Property.LangList(Scope.NONE, "Description");
private static final StringProp TEXTURE = Property.String(Scope.NONE, "Texture");
private final String key;
@Getter private List<String> sources = Lists.newArrayList();
private Material material;
private int model;
@Getter private String display;
private List<String> description;
@Getter private ItemStack hatItem;
public Hat(String key) {
this.key = key.toUpperCase();
this.material = MATERIAL.get(this);
this.model = MODEL.get(this);
this.display = DISPLAY.get(this);
this.description = DESCRIPTION.get(this);
if(material == Material.PLAYER_HEAD) {
this.hatItem = ItemFactory.of(this.material)
.name(Text.colorize(this.getDisplay()))
.model(model)
.hideAttributes()
.lore(description)
.skullTexture(TEXTURE.get(this))
.build();
} else {
this.hatItem = ItemFactory.of(this.material)
.name(Text.colorize(this.getDisplay()))
.model(model)
.hideAttributes()
.lore(description)
.build();
}
}
@Override
public String getPropertyNode() {
return "Hats." + this.key;
}
@Override
public Icon<Profile> getIcon() {
return IconBuilder.<Profile>create()
.name(Text.colorize(this.getDisplay()))
.item(this.hatItem)
.hideFlags()
.lore(profile -> {
//if(profile.getUnlockedHats().contains(this.getKey())) {
// return this.description;
//} else {
List<String> desc = Lists.newArrayList(description);
desc.add("");
desc.add(Text.colorizeLegacy("<red>Not Unlocked"));
return desc;
//}
})
.click((prof,p) -> {
if(prof.getPlayer().isOp()) {// || prof.getUnlockedHats().contains(this.getKey())) {
//prof.setHat(this);
CommandHelper.sendSuccess(p, "Set your hat to " + getDisplay());
p.closeInventory();
} else {
CommandHelper.sendError(p, "You haven't unlocked that hat yet!");
}
}).build();
}
}
package io.lumine.cosmetics.managers.hats;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.ItemStack;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import io.lumine.utils.Events;
import io.lumine.utils.Schedulers;
import io.lumine.utils.config.properties.types.NodeListProp;
import io.lumine.utils.logging.Log;
import io.lumine.utils.protocol.Protocol;
import io.lumine.cosmetics.MCCosmeticsPlugin;
import io.lumine.cosmetics.api.events.CosmeticPlayerLoadedEvent;
import io.lumine.cosmetics.api.players.CosmeticProfile;
import io.lumine.cosmetics.managers.MCCosmeticsManager;
import io.lumine.utils.plugin.ReloadableModule;
import io.lumine.cosmetics.players.Profile;
public class HatManager extends MCCosmeticsManager {
private final Map<String,Hat> hats = new ConcurrentHashMap<>();
public HatManager(MCCosmeticsPlugin plugin) {
super(plugin);
}
@Override
public void load(MCCosmeticsPlugin plugin) {
// TODO Auto-generated method stub
//
// TODO: Load Hats
//
Log.info("Loaded " + hats.size() + " hats");
Events.subscribe(CosmeticPlayerLoadedEvent.class)
.handler(event -> {
final CosmeticProfile profile = event.getProfile();
//if(profile.getHat().isPresent()) {
// equipHat(profile);
//}
}).bindWith(this);
Events.subscribe(InventoryCloseEvent.class)
.handler(event -> {
final Player player = (Player) event.getPlayer();
getProfiles().awaitProfile(player).thenAcceptAsync(maybeProfile -> {
if(!maybeProfile.isPresent()) {
return;
}
final Profile profile = maybeProfile.get();
//if(profile.getHat().isPresent()) {
// profile.setHatIsActive(true);
// Schedulers.async().runLater(() -> this.equipHat(profile), 1);
// }
});
}).bindWith(this);
Protocol.subscribe(PacketType.Play.Server.ENTITY_EQUIPMENT)
.handler(event -> {
final PacketContainer packet = event.getPacket();
final Entity entity = packet.getEntityModifier(event.getPlayer().getWorld()).read(0);
if(!(entity instanceof Player)) {
return;
}
final Player player = (Player) entity;
final Profile profile = getProfiles().getProfile(player);
if(profile == null) {
return;
}
//if(profile.getHat().isPresent()) {
// writeHeadItem(packet, profile.getEquippedHat());
//}
}).bindWith(this);
Events.subscribe(InventoryClickEvent.class)
.handler(event -> {
if(event.getRawSlot() == 5) {
final Player player = (Player) event.getWhoClicked();
final Profile profile = getProfiles().getProfile(player);
//if(profile.getHat().isPresent() && profile.getHatIsActive()) {
// player.updateInventory();
// profile.setHatIsActive(false);
//}
}
}).bindWith(this);
}
@Override
public void unload() {
// TODO Auto-generated method stub
hats.clear();
}
public Collection<Hat> getHats() {
return hats.values();
}
public Optional<Hat> getHat(String key) {
return Optional.ofNullable(hats.getOrDefault(key, null));
}
public void equipHat(Player player) {
equipHat(getProfiles().getProfile(player));
}
public void equipHat(Profile profile) {
getPlugin().getVolatileCodeHandler().getHatHelper().applyHatPacket(profile);
}
}
......@@ -2,4 +2,9 @@ package io.lumine.cosmetics.nms;
public class VolatileCodeDisabled implements VolatileCodeHandler {
@Override
public VolatileHatHelper getHatHelper() {
return null;
}
}
......@@ -2,4 +2,5 @@ package io.lumine.cosmetics.nms;
public interface VolatileCodeHandler {
public VolatileHatHelper getHatHelper();
}
package io.lumine.cosmetics.nms;
import io.lumine.cosmetics.players.Profile;
public interface VolatileHatHelper {
public void applyHatPacket(Profile profile);
}
......@@ -4,10 +4,10 @@ import java.util.UUID;
import org.bukkit.entity.Player;
import io.lumine.utils.storage.players.Profile;
import io.lumine.cosmetics.api.players.CosmeticProfile;
import lombok.Getter;
public class CosmeticProfile implements Profile {
public class Profile implements CosmeticProfile,io.lumine.utils.storage.players.Profile {
@Getter private UUID uniqueId;
@Getter private String name;
......@@ -15,9 +15,9 @@ public class CosmeticProfile implements Profile {
@Getter private transient Player player;
public CosmeticProfile() {}
public Profile() {}
public CosmeticProfile(UUID id, String name) {
public Profile(UUID id, String name) {
this.uniqueId = id;
this.name = name;
}
......
......@@ -5,26 +5,29 @@ import java.util.UUID;
import org.bukkit.entity.Player;
import io.lumine.cosmetics.MCCosmeticsPlugin;
import io.lumine.cosmetics.api.events.CosmeticPlayerLoadedEvent;
import io.lumine.utils.storage.players.adapters.file.JsonPlayerStorageAdapter;
import io.lumine.utils.Events;
import io.lumine.utils.storage.players.PlayerRepository;
public class ProfileManager extends PlayerRepository<MCCosmeticsPlugin,CosmeticProfile> {
public class ProfileManager extends PlayerRepository<MCCosmeticsPlugin,Profile> {
public ProfileManager(MCCosmeticsPlugin plugin) {
super(plugin, CosmeticProfile.class, new JsonPlayerStorageAdapter<>(plugin,CosmeticProfile.class));
super(plugin, Profile.class, new JsonPlayerStorageAdapter<>(plugin,Profile.class));
}
@Override
public CosmeticProfile createProfile(UUID id, String name) {
return new CosmeticProfile(id,name);
public Profile createProfile(UUID id, String name) {
return new Profile(id,name);
}
@Override
public void initProfile(CosmeticProfile profile, Player player) {
public void initProfile(Profile profile, Player player) {
profile.initialize(player);
Events.call(new CosmeticPlayerLoadedEvent(player,profile));
}
@Override
public void unloadProfile(CosmeticProfile profile, Player player) {}
public void unloadProfile(Profile profile, Player player) {}
}
......@@ -52,10 +52,9 @@
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<configuration>
<release>16</release>
</configuration>
</plugin>
</plugins>
</build>
......
......@@ -66,6 +66,11 @@
<id>lumine-test</id>
<url>https://mvn.lumine.io/repository/maven-test/</url>
</repository>
<repository>
<id>minecraft-libraries</id>
<name>Minecraft Libraries</name>
<url>https://libraries.minecraft.net</url>
</repository>
</repositories>
<dependencies>
......@@ -113,8 +118,19 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>datafixerupper</artifactId>
<version>1.0.20</version>
</dependency>
<!-- Other -->
<!-- Other -->
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.6.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
......
package io.lumine.cosmetics.nms.v1_18_R1;
import java.util.List;
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import com.google.common.collect.Lists;
import com.mojang.datafixers.util.Pair;
import io.lumine.cosmetics.MCCosmeticsPlugin;
import io.lumine.cosmetics.nms.VolatileHatHelper;
import io.lumine.cosmetics.players.Profile;
import io.lumine.utils.protocol.Protocol;
import lombok.Getter;
import net.minecraft.world.entity.EquipmentSlot;
public class VolatileHatImpl implements VolatileHatHelper {
@Getter private final MCCosmeticsPlugin plugin;
public VolatileHatImpl(MCCosmeticsPlugin plugin) {
this.plugin = plugin;
}
@Override
public void applyHatPacket(Profile profile) {
if(profile == null) {
return;
}
final var player = profile.getPlayer();
final var packet = Protocol.manager().createPacket(PacketType.Play.Server.ENTITY_EQUIPMENT);
packet.getEntityModifier(player.getWorld()).write(0, player);
/*
if(profile.getHat().isPresent()) {
profile.setHatIsActive(true);
writeHeadItem(packet, profile.getEquippedHat());
Protocol.broadcastPacket(packet);
} else if(profile.getHatIsActive()) {
writeHeadItem(packet, player.getInventory().getHelmet());
Protocol.broadcastPacket(packet);
}*/
}
public boolean writeHeadItem(PacketContainer packet, ItemStack item) {
List<Pair<EquipmentSlot,net.minecraft.world.item.ItemStack>> slots = (List<Pair<EquipmentSlot,net.minecraft.world.item.ItemStack>>) packet.getModifier().read(1);
List<Pair<EquipmentSlot,net.minecraft.world.item.ItemStack>> newSlots = Lists.newArrayList();
boolean foundHead = false;
for(Pair<EquipmentSlot,net.minecraft.world.item.ItemStack> pair : slots) {
final EquipmentSlot slot = pair.getFirst();
if(slot == EquipmentSlot.HEAD) {
foundHead = true;
newSlots.add(Pair.of(pair.getFirst(), CraftItemStack.asNMSCopy(item)));
} else {
newSlots.add(pair);
}
}
if(!foundHead) {
newSlots.add(Pair.of(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item)));
}
packet.getModifier().write(1, newSlots);
return true;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment