Skip to content
Permalink
Browse files

Rogue draft of 1.13 support

  • Loading branch information
DarkArc committed Dec 31, 2019
1 parent 7c3efaa commit 54232590436b567ccc669bcd8cc4f353a30da704
@@ -8,9 +8,9 @@ ask that you make note of the following guidelines.
* **Follow the [Oracle coding conventions](http://www.oracle.com/technetwork/java/codeconv-138413.html).**
We can't stress this enough; if your code has notable issues, it may delay
the process significantly.
* **Target Java 6 for source and compilation.** Make sure to mark methods with
* **Target Java 8 for source and compilation.** Make sure to mark methods with
` @Override` that override methods of parent classes, or that implement
methods of interfaces (Java 6+).
methods of interfaces.
* **Use only spaces for indentation.** Our indents are 4-spaces long, and tabs
are unacceptable.
* **Wrap code to a 89 column limit.** We do this to make side by side diffs
@@ -16,7 +16,7 @@ CommandBook adds essential commands for managing your server, from teleportation
Compiling
---------

The project is written for Java 6 and our build process makes use of [Maven](http://maven.apache.org). Detailed compilation information [can be found on the wiki](http://wiki.sk89q.com/wiki/CommandBook/Development#Compiling).
The project is written for Java 8 and our build process makes use of [Maven](http://maven.apache.org). Detailed compilation information [can be found on the wiki](http://wiki.sk89q.com/wiki/CommandBook/Development#Compiling).

Dependencies are automatically handled by Maven.

22 pom.xml
@@ -34,27 +34,21 @@
</repositories>
<dependencies>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldedit</artifactId>
<version>5.5.9-SNAPSHOT</version>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>7.1.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>com.zachsthings.libcomponents</groupId>
<artifactId>libcomponents-bukkit</artifactId>
<version>1.2.1-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.spout</groupId>
<artifactId>spoutapi</artifactId>
</exclusion>
</exclusions>
<version>1.3.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.9.4-R0.1-SNAPSHOT</version>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

@@ -124,9 +118,9 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerVersion>1.6</compilerVersion>
<source>1.8</source>
<target>1.8</target>
<compilerVersion>1.8</compilerVersion>
</configuration>
</plugin>

@@ -28,6 +28,10 @@
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.world.block.BlockType;
import com.zachsthings.libcomponents.ComponentInformation;
import com.zachsthings.libcomponents.bukkit.BasePlugin;
import com.zachsthings.libcomponents.bukkit.BukkitComponent;
@@ -110,7 +114,7 @@ public LivingEntity spawn(Location loc, EntityType type, String specialTypes,
if (creature instanceof Skeleton) {
creature.getEquipment().setItemInHand(new ItemStack(Material.BOW));
} else if (creature instanceof PigZombie) {
creature.getEquipment().setItemInHand(new ItemStack(Material.GOLD_SWORD));
creature.getEquipment().setItemInHand(new ItemStack(Material.GOLDEN_SWORD));
}

String[] types = specialTypes.split(",");
@@ -177,9 +181,11 @@ public LivingEntity spawn(Location loc, EntityType type, String specialTypes,
}
break;
case ENDERMAN:
ItemStack item = ItemUtil.getItem(specialType);
BaseItem item = ItemUtil.getItem(specialType);
if (item == null) return creature;
((Enderman) creature).setCarriedMaterial(item.getData());
BlockType blockType = item.getType().getBlockType();
if (blockType == null) return creature;
((Enderman) creature).setCarriedBlock(BukkitAdapter.adapt(blockType.getDefaultState()));
break outerloop; // only one set of hands
case IRON_GOLEM:
if (specialType.matches("(?i)(friendly|player(-created)?)")) {
@@ -18,7 +18,6 @@
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.SimpleCommandMap;
import org.bukkit.command.defaults.VanillaCommand;

import java.io.File;
import java.io.IOException;
@@ -156,8 +155,6 @@ public void printCommandHelp(CommandSender sender, org.bukkit.command.Command cm
} else if (cmd instanceof DynamicPluginCommand) {
sender.sendMessage(ChatColor.YELLOW + "Owner: " +
((DynamicPluginCommand) cmd).getOwner().getClass().getSimpleName());
} else if (cmd instanceof VanillaCommand) {
sender.sendMessage(ChatColor.YELLOW + "Vanilla command");
}
}

@@ -28,20 +28,26 @@
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldedit.blocks.ItemType;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.zachsthings.libcomponents.ComponentInformation;
import com.zachsthings.libcomponents.bukkit.BukkitComponent;
import com.zachsthings.libcomponents.config.ConfigurationBase;
import com.zachsthings.libcomponents.config.Setting;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.*;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;

import static com.sk89q.commandbook.util.item.InventoryUtil.giveItem;
import static com.sk89q.commandbook.util.item.InventoryUtil.takeItem;
@@ -65,8 +71,8 @@ public void reload() {

private static class LocalConfiguration extends ConfigurationBase {
@Setting("item-permissions-only") public boolean useItemPermissionsOnly;
@Setting("allowed-items") public Set<Integer> allowedItems = Collections.emptySet();
@Setting("disllowed-items") public Set<Integer> disallowedItems = Collections.emptySet();
@Setting("allowed-items") public Set<String> allowedItems = Collections.emptySet();
@Setting("disllowed-items") public Set<String> disallowedItems = Collections.emptySet();
@Setting("default-item-stack-size") public int defaultItemStackSize = 1;
}

@@ -76,13 +82,14 @@ public void reload() {
* Checks to see if a user can use an item.
*
* @param sender
* @param id
* @param itemStack
* @throws CommandException
*/
public void checkAllowedItem(CommandSender sender, int id, int damage)
public void checkAllowedItem(CommandSender sender, BaseItem itemStack)
throws CommandException {

if (Material.getMaterial(id) == null || id == 0) {
ItemType itemType = itemStack.getType();
if (itemType == null || itemType == ItemTypes.AIR) {
throw new CommandException("Non-existent item specified.");
}

@@ -91,8 +98,9 @@ public void checkAllowedItem(CommandSender sender, int id, int damage)
return;
}

boolean hasPermissions = CommandBook.inst().hasPermission(sender, "commandbook.items." + id)
|| CommandBook.inst().hasPermission(sender, "commandbook.items." + id + "." + damage);
String itemId = itemType.getId();
String namespacedPermission = itemId.replace(":", ".");
boolean hasPermissions = CommandBook.inst().hasPermission(sender, "commandbook.items." + namespacedPermission);

// Also check the permissions system
if (hasPermissions) {
@@ -104,17 +112,17 @@ public void checkAllowedItem(CommandSender sender, int id, int damage)
}

if (config.allowedItems.size() > 0) {
if (!config.allowedItems.contains(id)) {
if (!config.allowedItems.contains(itemId)) {
throw new CommandException("That item is not allowed.");
}
}

if (config.disallowedItems.contains((id))) {
if (config.disallowedItems.contains(itemId)) {
throw new CommandException("That item is disallowed.");
}
}

private ItemStack matchItem(String name) throws CommandException {
private BaseItem matchItem(String name) throws CommandException {
return ItemUtil.getCommandItem(name);
}

@@ -124,7 +132,7 @@ private ItemStack matchItem(String name) throws CommandException {
flags = "do", min = 1, max = 3)
@CommandPermissions({"commandbook.give"})
public void item(CommandContext args, CommandSender sender) throws CommandException {
ItemStack item = null;
BaseItem item = null;
int amt = config.defaultItemStackSize;
Collection<Player> targets = null;

@@ -159,6 +167,7 @@ public void item(CommandContext args, CommandSender sender) throws CommandExcept
if (item == null) {
throw new CommandException("Something went wrong parsing the item info!");
}

giveItem(sender, item, amt, targets, InventoryComponent.this, args.hasFlag('d'), args.hasFlag('o'));
}

@@ -167,7 +176,7 @@ public void item(CommandContext args, CommandSender sender) throws CommandExcept
flags = "do", min = 2, max = 3)
@CommandPermissions({"commandbook.give", "commandbook.give.other"})
public void give(CommandContext args, CommandSender sender) throws CommandException {
ItemStack item = null;
BaseItem item = null;
int amt = config.defaultItemStackSize;
Collection<Player> targets = null;

@@ -345,7 +354,7 @@ public void more(CommandContext args, CommandSender sender) throws CommandExcept
flags = "", min = 2, max = 3)
@CommandPermissions({"commandbook.take"})
public void take(CommandContext args, CommandSender sender) throws CommandException {
ItemStack item = null;
BaseItem item = null;
int amt = config.defaultItemStackSize;
Player target = null;

@@ -414,12 +423,7 @@ public void stack(CommandContext args, CommandSender sender) throws CommandExcep

// Same type?
// Blocks store their color in the damage value
if (item2.getTypeId() == item.getTypeId() &&
((!ItemType.usesDamageValue(item.getTypeId()) && ignoreDamaged)
|| item.getDurability() == item2.getDurability()) &&
((item.getItemMeta() == null && item2.getItemMeta() == null)
|| (item.getItemMeta() != null &&
item.getItemMeta().equals(item2.getItemMeta())))) {
if (item2.isSimilar(item)) {
// This stack won't fit in the parent stack
if (item2.getAmount() > needed) {
item.setAmount(64);
@@ -476,15 +480,23 @@ public void repair(CommandContext args, CommandSender sender) throws CommandExce

if (!repairAll && !repairHotbar && !repairEquipment) {
ItemStack stack = player.getItemInHand();
if (stack != null && !ItemType.usesDamageValue(stack.getTypeId())) {
stack.setDurability((short) 0);
ItemMeta stackMeta = stack.getItemMeta();
if (stackMeta instanceof Damageable) {
((Damageable) stackMeta).setDamage(0);
stack.setItemMeta(stackMeta);
}
} else {
if (repairAll || repairHotbar) {
for (int i = (repairAll ? 36 : 8); i >= 0; --i) {
ItemStack stack = inventory.getItem(i);
if (stack != null && !ItemType.usesDamageValue(stack.getTypeId())) {
stack.setDurability((short) 0);
if (stack == null) {
continue;
}

ItemMeta stackMeta = stack.getItemMeta();
if (stackMeta instanceof Damageable) {
((Damageable) stackMeta).setDamage(0);
stack.setItemMeta(stackMeta);
}
}
}
@@ -493,8 +505,14 @@ public void repair(CommandContext args, CommandSender sender) throws CommandExce
// Armor slots
for (int i = 36; i <= 39; i++) {
ItemStack stack = inventory.getItem(i);
if (stack != null && !ItemType.usesDamageValue(stack.getTypeId())) {
stack.setDurability((short) 0);
if (stack == null) {
continue;
}

ItemMeta stackMeta = stack.getItemMeta();
if (stackMeta instanceof Damageable) {
((Damageable) stackMeta).setDamage(0);
stack.setItemMeta(stackMeta);
}
}
}
@@ -533,7 +551,7 @@ public void enchantments(CommandContext args, CommandSender sender) throws Comma
@Override
public String format(Enchantment entry) {
return ChatColor.BLUE + entry.getName().toUpperCase() + ChatColor.YELLOW
+ " (ID: " + ChatColor.WHITE + entry.getId() + ChatColor.YELLOW
+ " (ID: " + ChatColor.WHITE + entry.getKey() + ChatColor.YELLOW
+ ", Max Level: " + ChatColor.WHITE + entry.getMaxLevel() + ChatColor.YELLOW + ')';
}
}.display(sender, Arrays.asList(Enchantment.values()), args.getFlagInteger('p', 1));
@@ -28,6 +28,8 @@
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.zachsthings.libcomponents.ComponentInformation;
import com.zachsthings.libcomponents.Depend;
import com.zachsthings.libcomponents.InjectComponent;
@@ -74,15 +76,18 @@ public void reload() {
}

private static class LocalConfiguration extends ConfigurationBase {
@Setting("hammer-items") public Set<Integer> thorItems = new HashSet<Integer>(Arrays.asList(278, 285, 257, 270));
@Setting("hammer-items") public Set<String> thorItems = new HashSet<>(Arrays.asList(
ItemTypes.WOODEN_PICKAXE.getId(), ItemTypes.STONE_PICKAXE.getId(), ItemTypes.IRON_PICKAXE.getId(),
ItemTypes.GOLDEN_PICKAXE.getId(), ItemTypes.DIAMOND_PICKAXE.getId()
));
}

@EventHandler
public void onInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();

if (sessions.getSession(UserSession.class, player).hasThor()) {
if (!config.thorItems.contains(player.getItemInHand().getTypeId())) {
if (!config.thorItems.contains(BukkitAdapter.adapt(player.getItemInHand()).getType().getId())) {
return;
}

@@ -19,6 +19,9 @@
package com.sk89q.commandbook.kits;

import com.sk89q.commandbook.util.item.ItemUtil;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import org.bukkit.inventory.ItemStack;

import java.io.*;
@@ -101,28 +104,28 @@ public synchronized void load() {
}

String[] parts = line.split("-");
ItemStack item = ItemUtil.getItem(parts[0].replace(" ", ""));
BaseItem item = ItemUtil.getItem(parts[0].replace(" ", ""));

if (item == null) {
logger().warning(" Unknown kit item '" + parts[0].replaceAll(" ", "") + "'");
continue;
}

int amount = 1;
// Attempt to parse an amount
if (parts.length >= 2) {
try {
item.setAmount(Integer.parseInt(parts[1]));
amount = Integer.parseInt(parts[1]);
} catch (NumberFormatException e) {
logger().warning("Invalid amount: '" + parts[1] + "'");
}
}

kit.addItem(item);
kit.addItem(BukkitAdapter.adapt(new BaseItemStack(item.getType(), item.getNbtData(), amount)));
}

logger().info(kits.size() + " kit(s) loaded.");
} catch (FileNotFoundException ignore) {
} catch (UnsupportedEncodingException ignore) {
} catch (FileNotFoundException | UnsupportedEncodingException ignore) {
} catch (IOException e) {
logger().warning("Failed to load kits.txt: "
+ e.getMessage());

0 comments on commit 5423259

Please sign in to comment.
You can’t perform that action at this time.