Created
February 15, 2019 03:33
-
-
Save aikar/5534b70555ad5da181a435a623906384 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package co.aikar.someplugin; | |
import org.bukkit.Location; | |
import org.bukkit.Material; | |
import org.bukkit.block.BlockState; | |
import org.bukkit.block.Chest; | |
import org.bukkit.command.Command; | |
import org.bukkit.command.CommandSender; | |
import org.bukkit.entity.Player; | |
import org.bukkit.inventory.Inventory; | |
import org.bukkit.inventory.ItemStack; | |
import org.bukkit.inventory.meta.BookMeta; | |
import org.bukkit.plugin.java.JavaPlugin; | |
import java.util.Random; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
public final class SomePlugin extends JavaPlugin { | |
@Override | |
public void onEnable() { | |
// Plugin startup logic | |
} | |
@Override | |
public void onDisable() { | |
// Plugin shutdown logic | |
} | |
@Override | |
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | |
if (!(sender instanceof Player)) { | |
return true; | |
} | |
Player player = (Player) sender; | |
player.getLocation(); | |
int r = Math.min(3, args.length > 0 ? Integer.parseInt(args[0]) : 0); | |
for (int x = -r; x <= r; x++) { | |
for (int y = -r; y <= r; y++) { | |
for (int z = -r; z <= r; z++) { | |
doDupeBlock(player.getLocation().add(x, y, z)); | |
} | |
} | |
} | |
return true; | |
} | |
ExecutorService executorService = Executors.newFixedThreadPool(6); | |
private void doDupeBlock(Location loc) { | |
loc.getBlock().setType(Material.CHEST); | |
Chest state = (Chest) loc.getBlock().getState(false); | |
Inventory blockInventory = state.getBlockInventory(); | |
executorService.submit(() -> { | |
for (int i = 0; i < 27; i++) { | |
blockInventory.addItem(createBook()); | |
} | |
}); | |
} | |
private ItemStack createBook() { | |
ItemStack book = new ItemStack(Material.WRITTEN_BOOK); | |
BookMeta meta = (BookMeta) book.getItemMeta(); | |
for (int i = 0; i < 50; i++) { | |
meta.addPage(createString()); | |
} | |
book.setItemMeta(meta); | |
return book; | |
} | |
Random random = new Random(); | |
private String createString() { | |
StringBuilder builder = new StringBuilder(600); | |
for (int i = 0; i < 300; i++) { | |
builder.append((char)random.nextInt(215) + 40); | |
builder.append((char)random.nextInt(215) + 40); | |
builder.append((char)random.nextInt(215) + 40); | |
} | |
return builder.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment