Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.modnmetl</groupId>
<artifactId>virtualrealty</artifactId>
<version>2.5.3</version>
<version>2.5.4</version>
<packaging>jar</packaging>

<description>A plot creation and management plugin for Minecraft</description>
Expand Down Expand Up @@ -184,7 +184,7 @@
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api</artifactId>
<version>2.11.3</version>
<version>2.12.0</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,11 @@ public void expiry() {
public void success() {
PlotItem plotItem = DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getKey();
ItemStack plotItemStack = DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack();
int firstPlotItemStack = this.getSender().getInventory().first(plotItemStack);
boolean foundItemStack = firstPlotItemStack != -1;
if (foundItemStack) {
this.getSender().getInventory().clear(firstPlotItemStack);
for (ItemStack content : this.getSender().getInventory().getContents()) {
if (content == null || content.getType() == Material.AIR) continue;
if (PlotItem.getPlotItemUuid(content).equals(PlotItem.getPlotItemUuid(plotItemStack))) {
this.getSender().getInventory().removeItem(content);
}
}
if (plot.isOwnershipExpired())
plot.setOwnedUntilDate(LocalDateTime.now().plusDays(plotItem.getAdditionalDays()));
Expand All @@ -155,8 +156,14 @@ public void success() {

@Override
public void failed() {
this.getSender().getInventory().removeItem(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack());
this.getSender().getInventory().remove(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack());
ItemStack plotItemStack = DraftListener.DRAFT_MAP.get(this.getSender())
.getValue().getValue().getItemStack();
for (ItemStack content : this.getSender().getInventory().getContents()) {
if (content == null || content.getType() == Material.AIR) continue;
if (PlotItem.getPlotItemUuid(content).equals(PlotItem.getPlotItemUuid(plotItemStack))) {
this.getSender().getInventory().removeItem(content);
}
}
this.getSender().getInventory().addItem(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getKey().getItemStack());
DraftListener.DRAFT_MAP.get(this.getSender()).getKey().removeGrid();
DraftListener.DRAFT_MAP.remove(this.getSender());
Expand All @@ -180,7 +187,14 @@ public void expiry() {
return;
}
if (RegionUtil.isCollidingWithAnotherPlot(cuboid)) {
player.getInventory().remove(DraftListener.DRAFT_MAP.get(player).getValue().getValue().getItemStack());
ItemStack plotItemStack = DraftListener.DRAFT_MAP.get(player)
.getValue().getValue().getItemStack();
for (ItemStack content : player.getInventory().getContents()) {
if (content == null || content.getType() == Material.AIR) continue;
if (PlotItem.getPlotItemUuid(content).equals(PlotItem.getPlotItemUuid(plotItemStack))) {
player.getInventory().removeItem(content);
}
}
player.getInventory().addItem(DraftListener.DRAFT_MAP.get(player).getValue().getKey().getItemStack());
DraftListener.DRAFT_MAP.get(player).getKey().removeGrid();
DraftListener.DRAFT_MAP.remove(player);
Expand Down Expand Up @@ -233,10 +247,11 @@ public void success() {
} else {
plot.setOwnedUntilDate(LocalDateTime.now().plusDays(plotItem.getAdditionalDays()));
}
int firstPlotItemStack = this.getSender().getInventory().first(plotItemStack);
boolean foundItemStack = firstPlotItemStack != -1;
if (foundItemStack) {
this.getSender().getInventory().clear(firstPlotItemStack);
for (ItemStack content : this.getSender().getInventory().getContents()) {
if (content == null || content.getType() == Material.AIR) continue;
if (PlotItem.getPlotItemUuid(content).equals(PlotItem.getPlotItemUuid(plotItemStack))) {
this.getSender().getInventory().removeItem(content);
}
}
long timeEnd = System.currentTimeMillis();
BaseComponent textComponent = new TextComponent(VirtualRealty.PREFIX + VirtualRealty.getMessages().creationPlotComponent1);
Expand All @@ -261,8 +276,14 @@ public void run() {
}
@Override
public void failed() {
this.getSender().getInventory().removeItem(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack());
this.getSender().getInventory().remove(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack());
ItemStack plotItemStack = DraftListener.DRAFT_MAP.get(this.getSender())
.getValue().getValue().getItemStack();
for (ItemStack content : this.getSender().getInventory().getContents()) {
if (content == null || content.getType() == Material.AIR) continue;
if (PlotItem.getPlotItemUuid(content).equals(PlotItem.getPlotItemUuid(plotItemStack))) {
this.getSender().getInventory().removeItem(content);
}
}
this.getSender().getInventory().addItem(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getKey().getItemStack());
DraftListener.DRAFT_MAP.get(this.getSender()).getKey().removeGrid();
DraftListener.DRAFT_MAP.remove(this.getSender());
Expand All @@ -285,7 +306,16 @@ public void onPlotItemDraft(PlayerInteractEvent e) {
if (!(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
if (DraftListener.DRAFT_MAP.containsKey(player)) {
e.setCancelled(true);
player.getInventory().remove(DraftListener.DRAFT_MAP.get(player).getValue().getValue().getItemStack());

ItemStack plotItemStack = DraftListener.DRAFT_MAP.get(player)
.getValue().getValue().getItemStack();
for (ItemStack content : player.getInventory().getContents()) {
if (content == null || content.getType() == Material.AIR) continue;
if (PlotItem.getPlotItemUuid(content).equals(PlotItem.getPlotItemUuid(plotItemStack))) {
player.getInventory().removeItem(content);
}
}

player.getInventory().addItem(DraftListener.DRAFT_MAP.get(player).getValue().getKey().getItemStack());
DraftListener.DRAFT_MAP.get(player).getKey().removeGrid();
DraftListener.DRAFT_MAP.remove(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ public static PlotItem fromItemStack(ItemStack itemStack) {
);
}

public static UUID getPlotItemUuid(ItemStack itemStack) {
NBTItem nbtItem = new NBTItem(itemStack);
String string = nbtItem.getString(NBT_PREFIX + "stack_uuid");
if (string == null) return UUID.randomUUID();
return UUID.fromString(string);
}

public static PlotItem fromItemStack(ItemStack itemStack, VItem itemType) {
PlotItem plotItem = fromItemStack(itemStack);
return new PlotItem(itemType, plotItem.getPlotSize(), plotItem.getLength(), plotItem.getHeight(), plotItem.getWidth(), plotItem.floorData, plotItem.borderData, plotItem.isNatural(), plotItem.getAdditionalDays(), plotItem.getUuid());
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/com/modnmetl/virtualrealty/util/data/SkullUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
import org.bukkit.inventory.meta.SkullMeta;

import java.lang.reflect.Field;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Objects;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

public class SkullUtil {

Expand All @@ -24,7 +28,8 @@ public static ItemStack getSkull(String url) {
if (url == null || url.isEmpty())
return skull;
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
GameProfile profile = new GameProfile(UUID.randomUUID(), null);

GameProfile profile = new GameProfile(UUID.randomUUID(), generateRandomUsername(16));
byte[] encodedData = Base64.getEncoder().encode(String.format("{textures:{SKIN:{url:\"%s\"}}}", "http://textures.minecraft.net/texture/" + url).getBytes());
profile.getProperties().put("textures", new Property("textures", new String(encodedData)));
Field profileField = null;
Expand Down Expand Up @@ -54,7 +59,7 @@ public static ItemStack getSkull(String url, UUID uuid) {
if (url == null || url.isEmpty())
return skull;
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
GameProfile profile = new GameProfile(uuid, null);
GameProfile profile = new GameProfile(uuid, generateRandomUsername(16));
byte[] encodedData = Base64.getEncoder().encode(String.format("{textures:{SKIN:{url:\"%s\"}}}", "http://textures.minecraft.net/texture/" + url).getBytes());
profile.getProperties().put("textures", new Property("textures", new String(encodedData)));
Field profileField = null;
Expand All @@ -73,4 +78,14 @@ public static ItemStack getSkull(String url, UUID uuid) {
return skull;
}

private static String generateRandomUsername(int length) {
// Random username for GameProfile
int leftLimit = 'A'; // letter 'a'
int rightLimit = 'Z'; // letter 'z'
return ThreadLocalRandom.current().ints(leftLimit, rightLimit + 1)
.limit(length)
.collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append)
.toString();
}

}