Skip to content

Commit

Permalink
refactor, finish book builder tags, /appear POC command, close #4
Browse files Browse the repository at this point in the history
  • Loading branch information
insanj committed May 23, 2019
1 parent f3bb5b4 commit 16c32a5
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 36 deletions.
2 changes: 1 addition & 1 deletion plugin/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
loader_version=0.4.0+build.121

# Mod Properties
mod_version = 0.5.5
mod_version = 0.6.0-pre
maven_group = com.insanj
archives_base_name = pride

Expand Down
26 changes: 26 additions & 0 deletions plugin/src/main/java/com/insanj/pride/PrideCommandExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
import com.google.gson.Gson;
import com.google.common.collect.Multimap;

import com.insanj.pride.util.*;
import com.insanj.pride.save.*;

public class PrideCommandExecutor {
private final PrideConfig config;
public PrideCommandExecutor(PrideConfig config) {
Expand All @@ -96,6 +99,7 @@ public void register() {
registerHereCommand();
registerBetweenCommand();
registerNorthCommand();
registerAppearCommand();
}

private void registerPrideCommand() {
Expand Down Expand Up @@ -562,4 +566,26 @@ private void registerBetweenCommand() {
}))
));
}

private void registerAppearCommand() {
CommandRegistry.INSTANCE.register(false, serverCommandSourceCommandDispatcher -> serverCommandSourceCommandDispatcher.register(
CommandManager.literal("appear")
.then(CommandManager.argument("name", StringArgumentType.greedyString())
.executes(context -> {
ServerWorld world = context.getSource().getWorld();
String areaName = StringArgumentType.getString(context, "name");

PridePersistentState persis = PridePersistentState.get(world);
Map<String, Double> area = persis.getPrideArea(world, areaName);

ServerPlayerEntity player = context.getSource().getPlayer();
player.teleport(world, (double)area.get("x"), (double)area.get("y"), (double)area.get("z"), 0, 0);

TextComponent message = new PrideTextComponentBuilder("Welcome to ").build().append(new PrideTextComponentBuilder(areaName).color(TextFormat.BLUE).build()).append(new PrideTextComponentBuilder("!").build());
context.getSource().getPlayer().addChatMessage(message, false);
return 1;
}))
));
}

}
3 changes: 3 additions & 0 deletions plugin/src/main/java/com/insanj/pride/PrideEntityTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@

import com.google.gson.Gson;

import com.insanj.pride.util.*;
import com.insanj.pride.save.*;

public class PrideEntityTracker {
// currently unused config which will be used to configure detection distance, etc
private final PrideConfig config;
Expand Down
3 changes: 3 additions & 0 deletions plugin/src/main/java/com/insanj/pride/PrideMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

import com.google.gson.Gson;

import com.insanj.pride.util.*;
import com.insanj.pride.save.*;

public class PrideMod implements ModInitializer {
public static final String MOD_ID = "pride";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.insanj.pride;
package com.insanj.pride.save;

import java.io.File;
import java.io.FileOutputStream;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.insanj.pride;
package com.insanj.pride.save;

import net.fabricmc.fabric.api.util.NbtType;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.insanj.pride;
package com.insanj.pride.util;

import java.io.File;
import java.io.FileOutputStream;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.insanj.pride;
package com.insanj.pride.util;

import java.io.File;
import java.io.FileOutputStream;
Expand All @@ -11,6 +11,8 @@
import java.util.stream.Collectors;
import java.util.ArrayList;
import java.util.UUID;
import java.util.List;
import java.text.SimpleDateFormat;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.registry.CommandRegistry;
Expand All @@ -25,57 +27,54 @@
import net.fabricmc.fabric.impl.server.EntityTrackerStorageAccessor;

import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.Material;
import net.minecraft.command.EntitySelector;
import net.minecraft.entity.EntityCategory;
import net.minecraft.entity.EntitySize;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.BookItem;
import net.minecraft.item.WrittenBookItem;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerChunkManager;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.chunk.ChunkManager;
import net.minecraft.world.chunk.ChunkPos;
import net.minecraft.server.MinecraftServer;;
import net.minecraft.text.StringTextComponent;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.entity.EntityCategory;
import net.minecraft.entity.EntitySize;
import net.minecraft.entity.EntityType;
import net.minecraft.world.World;
import net.minecraft.text.Style;
import net.minecraft.text.TextComponent;
import net.minecraft.text.TextFormat;
import net.minecraft.text.TranslatableTextComponent;
import net.minecraft.text.NbtTextComponent;
import net.minecraft.text.event.HoverEvent;
import net.minecraft.command.EntitySelector;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.chunk.ChunkManager;
import net.minecraft.world.chunk.ChunkPos;

import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;

import com.google.gson.Gson;

import java.text.SimpleDateFormat;

import net.minecraft.item.BookItem;
import net.minecraft.item.WrittenBookItem;
import net.minecraft.nbt.CompoundTag;

public class PrideBookBuilder {
private ItemStack underlyingItemStack;
private CompoundTag underlyingBookMeta;

public PrideBookBuilder() {
this.underlyingItemStack = new ItemStack(Material.WRITTEN_BOOK, 1);
this.underlyingBookMeta = this.underlyingItemStack.getItem().getTag();
this.underlyingItemStack = new ItemStack(new WrittenBookItem(new WrittenBookItem.Settings()), 1);
this.underlyingBookMeta = this.underlyingItemStack.getTag();
}

public static String dateString() {
/*public static String dateString() {
return new SimpleDateFormat("yyyy-MM-dd").format(new Date());
}
}*/

public PrideBookBuilder name(String displayName) {
TranslatableTextComponent textComponentName = new TranslatableTextComponent(displayName);
Expand All @@ -84,22 +83,27 @@ public PrideBookBuilder name(String displayName) {
}

public PrideBookBuilder author(String authorName) {
this.underlyingBookMeta.putString("Author", authorName);
this.underlyingBookMeta.putString("author", authorName);
return this;
}

public PrideBookBuilder title(String titleString) {
this.underlyingBookMeta.putString("Title", titleString);
this.underlyingBookMeta.putString("title", titleString);
return this;
}

public PrideBookBuilder setPages(List<String> pages) {
this.underlyingBookMeta.put("Pages", pages);
ListTag pagesList = new ListTag();
for (int i = 0; i < pages.size(); i++) {
pagesList.set(i, new StringTag(pages.get(i)));
}

this.underlyingBookMeta.put("pages", pagesList);
return this;
}

public static ItemStack build() {
this.underlyingItemStack.setItemMeta(this.underlyingBookMeta);
public ItemStack build() {
this.underlyingItemStack.setTag(this.underlyingBookMeta);
return this.underlyingItemStack;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.insanj.pride;
package com.insanj.pride.util;

import java.io.File;
import java.io.FileOutputStream;
Expand Down
3 changes: 1 addition & 2 deletions plugin/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

"name": "pride",
"icon": "assets/pride/icon.png",
"description": "keep track of your playmates in minecraft\nSettle your current area to Pride\n/settle <name>\ntrigger:\ndescription: Toggle trigger setting for an area\nusage: |\nToggle trigger setting for an area\n/trigger <name>\nabandon:\ndescription: Abandon a given area in Pride\nusage: |\nAbandon a given area in Pride\n/abandon <name>\nhere:\ndescription: Show every Pride area where you currently are\nusage: |\nShow every Pride area where you currently are\n/here <optional:username>\nfar:\ndescription: Calculate how far away you are from a Pride area\nusage: |\nCalculate how far away you are from a Pride area\n/far <name>\nareas:\ndescription: Show the names of all the Pride areas and how far away they are\nusage: |\nShow the names of all the Pride areas and how far away they are\n/areas\nbetween:\ndescription: Calculate the distance between two pride areas (> 256 for Nether Portals)\nusage: |\nCalculate the distance between two pride areas (> 256 for Nether Portals)\n/between <name_one>,<name_two>\ncompass:\ndescription: Point your compass towards an area. Will reset to original spawn if no argument is given\nusage: |\nPoint your compass towards an area. Will reset to original spawn if no argument is given\n/compass <area>\nnorth:\ndescription: Point your compass towards true north. Will reset if any argument is given\nusage: |\nPoint your compass towards true north. Will reset if any argument is given\n/north <reset>",

"description": "keep track of your playmates in minecraft\n/settle <name>\n/abandon <name>\n/here\n/far <name>\n/areas <page_number>\n/nearby\n/nearbypage <page_number>\n/between <name_one>,<name_two>\n/compass <area>\n/north\n/appear",

"authors": [
{
Expand Down

0 comments on commit 16c32a5

Please sign in to comment.