use of net.minecraft.server.v1_14_R1.NBTTagCompound in project MyMaid2 by jaoafa.
the class Event_JoinjaoPoint method OnEvent_JoinjaoPoint.
@EventHandler
public void OnEvent_JoinjaoPoint(PlayerJoinEvent event) {
Player player = event.getPlayer();
String uuid = player.getUniqueId().toString();
Calendar cal = Calendar.getInstance();
cal.setTimeZone(TimeZone.getTimeZone("Asia/Tokyo"));
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
SimpleDateFormat date_full = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
date_full.setTimeZone(TimeZone.getTimeZone("Asia/Tokyo"));
String today = date_full.format(cal.getTime());
SimpleDateFormat date = new SimpleDateFormat("yyyy/MM/dd");
try {
PreparedStatement statement = MySQL.getNewPreparedStatement("SELECT * FROM login WHERE uuid = ? AND date >= cast(? as datetime) AND login_success = ?");
statement.setString(1, uuid);
statement.setString(2, today);
statement.setBoolean(3, true);
ResultSet res = statement.executeQuery();
if (res.next()) {
return;
}
} catch (SQLException | ClassNotFoundException e) {
BugReporter(e);
}
try {
Pointjao Pjao = new Pointjao(player);
Pjao.add(10, date.format(new Date()) + "のログインボーナス");
} catch (NullPointerException e) {
BugReporter(e);
return;
} catch (ClassNotFoundException | SQLException e) {
BugReporter(e);
return;
}
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date start = format.parse("2019/03/05 00:00:00");
Date end = format.parse("2019/03/15 23:59:59");
if (isPeriod(start, end)) {
String group = PermissionsManager.getPermissionMainGroup(player);
if (!group.equalsIgnoreCase("Admin") && !group.equalsIgnoreCase("Moderator") && !group.equalsIgnoreCase("Regular") && !group.equalsIgnoreCase("Default")) {
return;
}
ItemStack item = new ItemStack(Material.POTATO_ITEM);
net.minecraft.server.v1_12_R1.ItemStack nms = CraftItemStack.asNMSCopy(item);
NBTTagCompound nbttag = nms.getTag();
if (nbttag == null) {
nbttag = new NBTTagCompound();
}
UUID item_uuid = UUID.randomUUID();
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException e) {
BugReporter(e);
player.sendMessage("[EscapeJail] " + ChatColor.RED + "新しいEscapeJailアイテムの精製に失敗しました。(2)");
return;
}
byte[] digest = md.digest(item_uuid.toString().getBytes());
String id = DatatypeConverter.printHexBinary(digest);
if (id == null) {
player.sendMessage("[EscapeJail] " + ChatColor.RED + "新しいEscapeJailアイテムの精製に失敗しました。(3)");
return;
}
nbttag.setString("MyMaid_EscapeJailID", id);
nms.setTag(nbttag);
item = CraftItemStack.asBukkitCopy(nms);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("EscapeItem - IMO");
List<String> lore = new ArrayList<String>();
lore.add("このアイテムをインベントリ内に配置しておくと、Jail(EBan除く)を無効化できます!(アイテム1つにつき1回限り)");
lore.add(ChatColor.RED + "NBTデータを削除してしまうと、アイテムは無効となります。また、複製をしても1つしか有効ではありません。");
meta.setLore(lore);
meta.addEnchant(Enchantment.LOOT_BONUS_BLOCKS, 999, true);
item.setItemMeta(meta);
try {
PreparedStatement statement = MySQL.getNewPreparedStatement("INSERT INTO uniqueitem (id, type) VALUES (?, ?)");
statement.setString(1, id);
statement.setString(2, "MyMaid_EscapeJailID");
statement.executeUpdate();
} catch (SQLException | ClassNotFoundException e) {
BugReporter(e);
player.sendMessage("[EscapeJail] " + ChatColor.RED + "新しいEscapeJailアイテムの精製に失敗しました。(3)");
return;
}
player.sendMessage("[EscapeJail] " + ChatColor.RED + "新しいEscapeJailアイテムの精製に成功しました。");
player.sendMessage("[EscapeJail] " + ChatColor.RED + "このアイテムをインベントリの中に配置しておくと、Jail(EBan除く)をアイテム個数分だけ無効化できます!");
if (player.getInventory().firstEmpty() == -1) {
player.getLocation().getWorld().dropItem(player.getLocation(), item);
player.sendMessage("[EscapeJail] " + ChatColor.RED + "インベントリがいっぱいだったため、あなたの足元にアイテムをドロップしました。");
Bukkit.getLogger().info("[EscapeJail] dropped to " + player.getName());
} else {
player.getInventory().addItem(item);
Bukkit.getLogger().info("[EscapeJail] gived to " + player.getName());
}
}
} catch (ParseException e) {
BugReporter(e);
}
}
use of net.minecraft.server.v1_14_R1.NBTTagCompound in project solinia3-core by mixxit.
the class ItemStackUtils method IsDisplayItem.
public static boolean IsDisplayItem(ItemStack itemStack) {
// Also check nbttag
if (itemStack == null)
return false;
boolean isDisplayItem = itemStack.getItemMeta().getDisplayName().startsWith("Display Item: ");
if (isDisplayItem)
return isDisplayItem;
// Classic method
net.minecraft.server.v1_15_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
String isMerchant = compound.getString("merchant");
return Boolean.parseBoolean(isMerchant);
}
use of net.minecraft.server.v1_14_R1.NBTTagCompound in project askyblock by tastybento.
the class NMSHandler method setBook.
@Override
public ItemStack setBook(Tag item) {
ItemStack chestItem = new ItemStack(Material.WRITTEN_BOOK);
// Bukkit.getLogger().info(item.toString());
if (((CompoundTag) item).getValue().containsKey("tag")) {
Map<String, Tag> contents = (Map<String, Tag>) ((CompoundTag) item).getValue().get("tag").getValue();
// BookMeta bookMeta = (BookMeta) chestItem.getItemMeta();
String author = "";
if (contents.containsKey("author")) {
author = ((StringTag) contents.get("author")).getValue();
}
// Bukkit.getLogger().info("Author: " + author);
// bookMeta.setAuthor(author);
String title = "";
if (contents.containsKey("title")) {
title = ((StringTag) contents.get("title")).getValue();
}
// Bukkit.getLogger().info("Title: " + title);
// bookMeta.setTitle(title);
List<String> lore = new ArrayList<String>();
if (contents.containsKey("display")) {
Map<String, Tag> display = (Map<String, Tag>) (contents.get("display")).getValue();
List<Tag> loreTag = ((ListTag) display.get("Lore")).getValue();
for (Tag s : loreTag) {
lore.add(((StringTag) s).getValue());
}
}
// Bukkit.getLogger().info("Lore: " + lore);
net.minecraft.server.v1_9_R2.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
// Pages
// Create the NMS Stack's NBT (item data)
NBTTagCompound tag = new NBTTagCompound();
// Set the book's title
tag.setString("title", title);
tag.setString("author", author);
if (contents.containsKey("pages")) {
NBTTagList pages = new NBTTagList();
List<Tag> pagesTag = ((ListTag) contents.get("pages")).getValue();
for (Tag s : pagesTag) {
pages.add(new NBTTagString(((StringTag) s).getValue()));
}
// Add the pages to the tag
tag.set("pages", pages);
}
// Apply the tag to the item
stack.setTag(tag);
chestItem = CraftItemStack.asCraftMirror(stack);
ItemMeta bookMeta = (ItemMeta) chestItem.getItemMeta();
bookMeta.setLore(lore);
chestItem.setItemMeta(bookMeta);
}
return chestItem;
}
use of net.minecraft.server.v1_14_R1.NBTTagCompound in project askyblock by tastybento.
the class NMSHandler method setBook.
@Override
public ItemStack setBook(Tag item) {
ItemStack chestItem = new ItemStack(Material.WRITTEN_BOOK);
// Bukkit.getLogger().info(item.toString());
if (((CompoundTag) item).getValue().containsKey("tag")) {
Map<String, Tag> contents = (Map<String, Tag>) ((CompoundTag) item).getValue().get("tag").getValue();
// BookMeta bookMeta = (BookMeta) chestItem.getItemMeta();
String author = "";
if (contents.containsKey("author")) {
author = ((StringTag) contents.get("author")).getValue();
}
// Bukkit.getLogger().info("Author: " + author);
// bookMeta.setAuthor(author);
String title = "";
if (contents.containsKey("title")) {
title = ((StringTag) contents.get("title")).getValue();
}
// Bukkit.getLogger().info("Title: " + title);
// bookMeta.setTitle(title);
List<String> lore = new ArrayList<String>();
if (contents.containsKey("display")) {
Map<String, Tag> display = (Map<String, Tag>) (contents.get("display")).getValue();
List<Tag> loreTag = ((ListTag) display.get("Lore")).getValue();
for (Tag s : loreTag) {
lore.add(((StringTag) s).getValue());
}
}
// Bukkit.getLogger().info("Lore: " + lore);
net.minecraft.server.v1_8_R2.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
// Pages
// Create the NMS Stack's NBT (item data)
NBTTagCompound tag = new NBTTagCompound();
// Set the book's title
tag.setString("title", title);
tag.setString("author", author);
if (contents.containsKey("pages")) {
NBTTagList pages = new NBTTagList();
List<Tag> pagesTag = ((ListTag) contents.get("pages")).getValue();
for (Tag s : pagesTag) {
pages.add(new NBTTagString(((StringTag) s).getValue()));
}
// Add the pages to the tag
tag.set("pages", pages);
}
// Apply the tag to the item
stack.setTag(tag);
chestItem = CraftItemStack.asCraftMirror(stack);
ItemMeta bookMeta = (ItemMeta) chestItem.getItemMeta();
bookMeta.setLore(lore);
chestItem.setItemMeta(bookMeta);
}
return chestItem;
}
use of net.minecraft.server.v1_14_R1.NBTTagCompound in project askyblock by tastybento.
the class NMSHandler method getSpawnEgg.
/**
* Get spawn egg
* @param type
* @param amount
* @return
*/
@SuppressWarnings("deprecation")
public ItemStack getSpawnEgg(EntityType type, int amount) {
ItemStack item = new ItemStack(Material.MONSTER_EGG, amount);
net.minecraft.server.v1_9_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
NBTTagCompound tagCompound = stack.getTag();
if (tagCompound == null) {
tagCompound = new NBTTagCompound();
}
NBTTagCompound id = new NBTTagCompound();
id.setString("id", type.getName());
tagCompound.set("EntityTag", id);
stack.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(stack);
}
Aggregations