Skip to content

Commit

Permalink
Version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kivattt committed Oct 13, 2023
1 parent 1503d35 commit fdb0795
Show file tree
Hide file tree
Showing 30 changed files with 155 additions and 48 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ Improved logging for players throwing dynamite
`/home`\
Teleport to home (If home exists)

`/homewhere`\
Show home location without teleporting to it

`/sethome`\
Sets your home location

`/spawn`\
Teleport to spawn (If spawn location specified)

`/spawnwhere`\
Show spawn location without teleporting to it

`/spawnset` (OP-only command)\
Set the location `/spawn` sends the player

Expand All @@ -43,6 +49,9 @@ When player supplied, an OP can force reset a players nickname
`/pronouns <pronouns>`\
Give yourself pronouns in chat

`/pronounslist`\
See everyone's pronouns

`/pronounsset <player> <pronouns>` (OP-only command)\
Force set a players pronouns

Expand All @@ -68,9 +77,6 @@ Shows config for KivaServerUtils
`/kivaversion`\
Displays mod version

# Known issues/bugs
`/home` and `/sethome` don't check the players dimension, teleporting to the coordinate no matter the dimension

# Info for mod developers
`Container.updateInventory` is overwritten by this mod,\
keep this in mind if you are writing mixins for this method
Expand Down
7 changes: 2 additions & 5 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
- Better system for configuration, less confusing commands (something like /gamerule \<key> \<value>)
- In `/spawn`, `/teleport` command check if the target chunk is loaded by the player
- In `/spawn`, `/teleport`, `/home` commands check if the target chunk is loaded by the player
and if not, warn them to try relogging if they're stuck in air

- Improve the 100% CPU fix to not sleep on server close (saving chunks?)

# Chest/crate logging
Username in the logging

More descriptive logging?
- Itemstack amount changed
- Itemstack added
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ buildscript {
maven { url 'https://jitpack.io/' }
}
dependencies {
classpath('com.github.Fox2Code.FoxLoader:dev:1.2.18')
classpath('com.github.Fox2Code.FoxLoader:dev:1.2.19')
}
}

apply plugin: 'foxloader.dev'

version '0.8.0'
version '1.0.0'

foxloader {
// forceReload = true
Expand Down
20 changes: 19 additions & 1 deletion src/main/java/com/kiva/kivaserverutils/Coordinate.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

public class Coordinate {
public double x, y, z;
public Integer dimension;
public static String dimensionToString(final Integer dimension){
switch(dimension){
case -1:
return "nether";
case 0:
return "overworld";
default:
return "unknown dimension";
}
}

public Coordinate(){}

Expand All @@ -11,16 +22,23 @@ public Coordinate(String str){

@Override
public String toString() {
return x + " " + y + " " + z;
return x + " " + y + " " + z + " " + dimension;
}

public String toStringXYZInt(){return (int)x + " " + (int)y + " " + (int)z;}

// TODO Use temporary values?
public void fromString(final String str){
String[] values = str.split(" ");
try {
x = Double.parseDouble(values[0]);
y = Double.parseDouble(values[1]);
z = Double.parseDouble(values[2]);

if (values.length >= 4)
dimension = Integer.parseInt(values[3]);
else
dimension = 0; // Let's assume overworld for old playerhomes.txt format
} catch(NumberFormatException e){
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class KivaServerUtils extends Mod {
public static HashMap<String, String> playerPronouns = new HashMap<>();
public static HashMap<String, Coordinate> playerHomes = new HashMap<>();
public static Coordinate spawnCommandLocation = null;
public static String version = "0.8.0";
public static String version = "1.0.0";
public static HashMap<String, Boolean> config = new HashMap<>();
public static String handleWindowClickLatestPlayerUsername;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
package com.kiva.kivaserverutils;

import java.io.*;
import java.util.Scanner;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class FileWriteAndLoadCoordinate {
public static void writeCoordinateToFile(final Coordinate coordinate, final String filename){
if (coordinate == null)
if (coordinate == null) {
File f = new File(filename);
if (!f.exists())
return;

System.out.println("No spawn set, attempting to delete " + filename);

if (f.delete())
System.out.println("Deleted " + filename + " successfully");
else
System.err.println("Failed to delete " + filename);

return;
}

try {
FileWriter fileWriter = new FileWriter(filename);
fileWriter.write(coordinate.x + " " + coordinate.y + " " + coordinate.z);
fileWriter.write(coordinate.toString());
fileWriter.close();
} catch(IOException e){
System.err.println("Failed to write coordinate to file: " + filename);
Expand All @@ -22,14 +37,10 @@ public static Coordinate loadCoordinateFromFile(final String filename){
Coordinate ret = new Coordinate();

try {
File file = new File(filename);
Scanner scanner = new Scanner(file);
ret.x = scanner.nextDouble();
ret.y = scanner.nextDouble();
ret.z = scanner.nextDouble();
scanner.close();
} catch(FileNotFoundException e){
System.err.println("Failed to load coordinate from file: " + filename);
ret.fromString(Files.readAllLines(Paths.get(filename)).get(0));
} catch(IOException | IndexOutOfBoundsException e) {
// Removed since this is expected when no spawn is set, to avoid confusion
//System.err.println("Failed to load coordinate from file: " + filename);
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static HashMap<String, Boolean> loadStringBooleanHashmapFromFile(final St

String line = reader.readLine();
while (line != null){
if (line.startsWith("#")) {
if (line.startsWith("#") || line.isEmpty()) {
line = reader.readLine();
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ public void onInit(){
CommandCompat.registerCommand(new PronounsReset());
CommandCompat.registerCommand(new Teleport());
CommandCompat.registerCommand(new Spawn());
CommandCompat.registerCommand(new SpawnWhere());
CommandCompat.registerCommand(new SpawnSet());
CommandCompat.registerCommand(new SpawnReset());
CommandCompat.registerCommand(new Home());
CommandCompat.registerCommand(new HomeWhere());
CommandCompat.registerCommand(new SetHome());

System.out.println("KivaServerUtils initialized");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.fox2code.foxloader.network.NetworkPlayer;
import com.fox2code.foxloader.registry.CommandCompat;
import com.kiva.kivaserverutils.KivaServerUtils;
import com.kiva.kivaserverutils.UsageMessage;

import static com.kiva.kivaserverutils.UsageMessage.sendUsageMessage;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.kiva.kivaserverutils.commands;

import com.fox2code.foxloader.loader.ServerMod;
import com.fox2code.foxloader.network.ChatColors;
import com.fox2code.foxloader.network.NetworkPlayer;
import com.fox2code.foxloader.registry.CommandCompat;
import com.kiva.kivaserverutils.Coordinate;
import com.kiva.kivaserverutils.KivaServerUtils;

import static com.kiva.kivaserverutils.KivaServerUtils.spawnCommandLocation;

public class Home extends CommandCompat{
public Home(){
super("home", false);
Expand Down Expand Up @@ -35,6 +34,11 @@ public void onExecute(final String[] args, final NetworkPlayer commandExecutor)
return;
}

if (homeCoordinate.dimension != ServerMod.toEntityPlayerMP(commandExecutor).dimension){
commandExecutor.displayChatMessage(ChatColors.YELLOW + "Your home is in the " + Coordinate.dimensionToString(homeCoordinate.dimension) + ", unable to teleport you");
return;
}

commandExecutor.teleportRegistered(homeCoordinate.x, homeCoordinate.y, homeCoordinate.z);
commandExecutor.displayChatMessage(ChatColors.GREEN + "Teleported to home!");
}
Expand Down
39 changes: 39 additions & 0 deletions src/server/java/com/kiva/kivaserverutils/commands/HomeWhere.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.kiva.kivaserverutils.commands;

import com.fox2code.foxloader.loader.ServerMod;
import com.fox2code.foxloader.network.ChatColors;
import com.fox2code.foxloader.network.NetworkPlayer;
import com.fox2code.foxloader.registry.CommandCompat;
import com.kiva.kivaserverutils.Coordinate;
import com.kiva.kivaserverutils.KivaServerUtils;

public class HomeWhere extends CommandCompat{
public HomeWhere(){
super("homewhere", false);
}

public String commandSyntax(){
return "§e/homewhere";
}

// TODO Make DRY
public void onExecute(final String[] args, final NetworkPlayer commandExecutor) {
if (KivaServerUtils.getConfigValue("homecommandsdisabled")){
commandExecutor.displayChatMessage(ChatColors.RED + "Home commands are disabled");
return;
}

if (KivaServerUtils.playerHomes == null){
commandExecutor.displayChatMessage(ChatColors.RED + "You have no home, use /sethome");
return;
}

Coordinate homeCoordinate = KivaServerUtils.playerHomes.get(commandExecutor.getPlayerName());
if (homeCoordinate == null){
commandExecutor.displayChatMessage(ChatColors.RED + "You have no home, use /sethome");
return;
}

commandExecutor.displayChatMessage(ChatColors.GREEN + "Your home is at [" + ChatColors.RESET + homeCoordinate.toStringXYZInt() + ChatColors.GREEN + "] in the " + ChatColors.RESET + Coordinate.dimensionToString(homeCoordinate.dimension));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kiva.kivaserverutils.commands;

import com.fox2code.foxloader.loader.ServerMod;
import com.fox2code.foxloader.network.ChatColors;
import com.fox2code.foxloader.network.NetworkPlayer;
import com.fox2code.foxloader.registry.CommandCompat;
Expand All @@ -25,13 +26,14 @@ public void onExecute(final String[] args, final NetworkPlayer commandExecutor){
playersCurrentCoordinate.x = commandExecutor.getRegisteredX();
playersCurrentCoordinate.y = commandExecutor.getRegisteredY();
playersCurrentCoordinate.z = commandExecutor.getRegisteredZ();
playersCurrentCoordinate.dimension = ServerMod.toEntityPlayerMP(commandExecutor).dimension;

if (playersCurrentCoordinate.y < 1){
commandExecutor.displayChatMessage(ChatColors.RED + "You can't set a home below y=1");
return;
}

KivaServerUtils.playerHomes.put(commandExecutor.getPlayerName(), playersCurrentCoordinate);
commandExecutor.displayChatMessage(ChatColors.GREEN + "Home location set! [" + ChatColors.RESET + (int)playersCurrentCoordinate.x + " " + (int)playersCurrentCoordinate.y + " " + (int)playersCurrentCoordinate.z + ChatColors.GREEN + "]" + ChatColors.RESET);
commandExecutor.displayChatMessage(ChatColors.GREEN + "Home location set! [" + ChatColors.RESET + playersCurrentCoordinate.toStringXYZInt() + ChatColors.GREEN + "] in the " + ChatColors.RESET + Coordinate.dimensionToString(playersCurrentCoordinate.dimension));
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.kiva.kivaserverutils.commands;

import com.fox2code.foxloader.launcher.ServerMain;
import com.fox2code.foxloader.loader.ServerMod;
import com.fox2code.foxloader.network.ChatColors;
import com.fox2code.foxloader.network.NetworkPlayer;
import com.fox2code.foxloader.registry.CommandCompat;
import com.kiva.kivaserverutils.Coordinate;

import static com.kiva.kivaserverutils.KivaServerUtils.spawnCommandLocation;

public class Spawn extends CommandCompat{
Expand All @@ -19,6 +23,12 @@ public void onExecute(final String[] args, final NetworkPlayer commandExecutor){
commandExecutor.displayChatMessage(ChatColors.RED + "No spawn has been set");
return;
}

if (spawnCommandLocation.dimension != ServerMod.toEntityPlayerMP(commandExecutor).dimension){
commandExecutor.displayChatMessage(ChatColors.YELLOW + "Spawn is in the " + Coordinate.dimensionToString(spawnCommandLocation.dimension) + ", unable to teleport you");
return;
}

commandExecutor.teleportRegistered(spawnCommandLocation.x, spawnCommandLocation.y, spawnCommandLocation.z);
commandExecutor.displayChatMessage(ChatColors.GREEN + "Teleported to spawn!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import com.fox2code.foxloader.network.ChatColors;
import com.fox2code.foxloader.network.NetworkPlayer;
import com.fox2code.foxloader.registry.CommandCompat;
import com.kiva.kivaserverutils.Coordinate;

import static com.kiva.kivaserverutils.KivaServerUtils.spawnCommandLocation;
import static com.kiva.kivaserverutils.UsageMessage.sendUsageMessage;

public class SpawnReset extends CommandCompat{
public SpawnReset(){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kiva.kivaserverutils.commands;

import com.fox2code.foxloader.loader.ServerMod;
import com.fox2code.foxloader.network.ChatColors;
import com.fox2code.foxloader.network.NetworkPlayer;
import com.fox2code.foxloader.registry.CommandCompat;
Expand All @@ -14,26 +15,18 @@ public SpawnSet(){
}

public String commandSyntax(){
return "§e/spawnset <x> <y> <z>";
return "§e/spawnset";
}

public void onExecute(final String[] args, final NetworkPlayer commandExecutor){
if (args.length != 4){
sendUsageMessage(commandSyntax(), commandExecutor);
return;
}

Coordinate pos = new Coordinate();

try {
pos.x = Double.parseDouble(args[1]);
pos.y = Double.parseDouble(args[2]);
pos.z = Double.parseDouble(args[3]);
pos.x = commandExecutor.getRegisteredX();
pos.y = commandExecutor.getRegisteredY();
pos.z = commandExecutor.getRegisteredZ();
pos.dimension = ServerMod.toEntityPlayerMP(commandExecutor).dimension;

spawnCommandLocation = pos;
commandExecutor.displayChatMessage(ChatColors.GREEN + "Spawn location set! [" + ChatColors.RESET + pos.x + " " + pos.y + " " + pos.z + ChatColors.GREEN + "]" + ChatColors.RESET);
} catch (NumberFormatException e){
sendUsageMessage(commandSyntax(), commandExecutor);
}
spawnCommandLocation = pos;
commandExecutor.displayChatMessage(ChatColors.GREEN + "Spawn location set! [" + ChatColors.RESET + pos.toStringXYZInt() + ChatColors.GREEN + "] in the " + ChatColors.RESET + Coordinate.dimensionToString(pos.dimension));
}
}
Loading

0 comments on commit fdb0795

Please sign in to comment.