Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.test;
- import com.google.inject.Inject;
- import org.slf4j.Logger;
- import org.spongepowered.api.Game;
- import org.spongepowered.api.block.BlockState;
- import org.spongepowered.api.block.BlockType;
- import org.spongepowered.api.block.BlockTypes;
- import org.spongepowered.api.command.CommandException;
- import org.spongepowered.api.command.CommandResult;
- import org.spongepowered.api.command.CommandSource;
- import org.spongepowered.api.command.args.CommandContext;
- import org.spongepowered.api.command.spec.CommandSpec;
- import org.spongepowered.api.data.key.Key;
- import org.spongepowered.api.data.key.Keys;
- import org.spongepowered.api.event.Listener;
- import org.spongepowered.api.event.block.InteractBlockEvent;
- import org.spongepowered.api.event.game.state.GameInitializationEvent;
- import org.spongepowered.api.plugin.Plugin;
- import org.spongepowered.api.text.Text;
- import java.io.FileNotFoundException;
- import java.io.PrintWriter;
- import java.lang.reflect.Field;
- import java.util.ArrayList;
- import java.util.List;
- @Plugin(id = "mytestplugin42", name = "My Test plugin 42", version = "1.0")
- public class MyTestPlugin42
- {
- @Inject
- private Logger logger;
- @Inject
- private Game game;
- private CommandResult cmdOnPrintBlockData(CommandSource src, CommandContext args) throws CommandException
- {
- StringBuilder sb = new StringBuilder();
- sb.append("\r\n");
- Class<BlockTypes> c = BlockTypes.class;
- try {
- Field[] fields = c.getDeclaredFields();
- for(Field f : fields){
- String blockName = f.getName();
- BlockType blockType = null;
- blockType = (BlockType)f.get(c);
- sb.append(blockName);
- sb.append("\r\n");
- BlockState blockState = blockType.getDefaultState();
- Class<Keys> kc = Keys.class;
- Field[] keyFields = kc.getDeclaredFields();
- for (Field kf : keyFields){
- String keyName = kf.getName();
- Key key = null;
- key = (Key)kf.get(kc);
- if (key == null) continue;
- if (blockState.supports(key)) {
- sb.append(" ");
- sb.append(keyName);
- sb.append("\r\n");
- }
- }
- sb.append("\r\n");
- }
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- String s = sb.toString();
- try {
- PrintWriter out = new PrintWriter("!KeysForBlocks.txt");
- out.println(s);
- out.close();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- return CommandResult.success();
- }
- private CommandResult cmdOnPrintDataOfBlock(CommandSource src, CommandContext args) throws CommandException
- {
- StringBuilder sb = new StringBuilder();
- sb.append("\r\n");
- try {
- Class<Keys> kc = Keys.class;
- Field[] keyFields = kc.getDeclaredFields();
- for (Field kf : keyFields){
- String keyName = kf.getName();
- Key key = null;
- key = (Key)kf.get(kc);
- if (key == null) continue;
- Class<BlockTypes> c = BlockTypes.class;
- List<String> supportedBlocks = new ArrayList<>();
- Field[] fields = c.getDeclaredFields();
- for(Field f : fields){
- String blockName = f.getName();
- BlockType blockType = null;
- blockType = (BlockType)f.get(c);
- BlockState blockState = blockType.getDefaultState();
- if (blockState.supports(key)) {
- supportedBlocks.add(blockName);
- }
- }
- if (supportedBlocks.size()>0) {
- sb.append(keyName);
- sb.append("\r\n");
- for (String supportedBlock : supportedBlocks) {
- sb.append(" ");
- sb.append(supportedBlock);
- sb.append("\r\n");
- }
- sb.append("\r\n");
- }
- }
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- String s = sb.toString();
- try {
- PrintWriter out = new PrintWriter("!BlocksForKeys.txt");
- out.println(s);
- out.close();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- return CommandResult.success();
- }
- @Listener
- public void onGameInitialization(GameInitializationEvent event)
- {
- CommandSpec myCommandSpec = CommandSpec.builder()
- .executor(this::cmdOnPrintBlockData)
- .build();
- CommandSpec myDataSpec = CommandSpec.builder()
- .executor(this::cmdOnPrintDataOfBlock)
- .build();
- game.getCommandManager().register(this, myCommandSpec, "printblockdata", "printbd");
- game.getCommandManager().register(this, myDataSpec, "printdatablock", "printdb");
- logger.info("PEW!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement