1
0
Fork 0

Initial commit

This commit is contained in:
Ryan Fox (flewkey) 2020-01-07 15:53:42 +00:00
commit 26e6077a80
Signed by: flewkey
GPG Key ID: 94F56ADFD848851E
20 changed files with 573 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
.gradle/
build/
run/

21
LICENSE.txt Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 Ryan Fox
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

7
README.txt Normal file
View File

@ -0,0 +1,7 @@
2a03-minecraft-tweaks
This repository contains simple modifications for the 2a03.party Minecraft
server. I have replaced the patches with a Fabric mod.
If you want a new feature added, you can either make an issue here or e-mail
me. Preferably the latter, because I am inactive on GitHub.
You probably want to ignore this.

19
build.gradle Normal file
View File

@ -0,0 +1,19 @@
plugins {
id 'fabric-loom' version '0.2.6-SNAPSHOT'
}
repositories {
mavenCentral()
}
dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modCompile "net.fabricmc:fabric-loader:${project.loader_version}"
modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
compile "org.json:json:20190722"
}
jar {
from "LICENSE.txt"
}

8
gradle.properties Normal file
View File

@ -0,0 +1,8 @@
org.gradle.jvmargs=-Xmx1G
minecraft_version=1.15.1
yarn_mappings=1.15.1+build.1
loader_version=0.7.2+build.175
mod_version = 1.0.0
maven_group = party.2a03.mc
archives_base_name = minecraft-tweaks-2a03
fabric_version=0.4.25+build.282-1.15

9
settings.gradle Normal file
View File

@ -0,0 +1,9 @@
pluginManagement {
repositories {
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
gradlePluginPortal()
}
}

View File

@ -0,0 +1,34 @@
package party._2a03.mc;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.registry.CommandRegistry;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import party._2a03.mc.command.ConfigCommand;
import party._2a03.mc.command.HatCommand;
import party._2a03.mc.command.HeadCommand;
import party._2a03.mc.command.HomeCommand;
import party._2a03.mc.command.SpawnCommand;
import party._2a03.mc.server.Config;
public class MinecraftTweaks2a03 implements ModInitializer {
private static final Logger LOGGER = LogManager.getLogger();
@Override
public void onInitialize() {
try {
Config.loadConfig();
} catch (Exception e) {
e.printStackTrace();
LOGGER.error(e);
}
LOGGER.info("Registering 2a03.party commands");
CommandRegistry.INSTANCE.register(false, dispatcher -> {
ConfigCommand.register(dispatcher);
HatCommand.register(dispatcher);
HeadCommand.register(dispatcher);
HomeCommand.register(dispatcher);
SpawnCommand.register(dispatcher);
});
}
}

View File

@ -0,0 +1,29 @@
package party._2a03.mc.command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.LiteralText;
import party._2a03.mc.server.Config;
public class ConfigCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = CommandManager.literal("config").requires(ctx -> {
return ctx.hasPermissionLevel(2);
});
literalargumentbuilder.then(CommandManager.literal("reload").executes(ctx -> {
ServerCommandSource source = ctx.getSource();
try {
Config.loadConfig();
source.sendFeedback(new LiteralText("Reloaded the configuration"), true);
} catch(Exception e) {
source.sendFeedback(new LiteralText("Failed to reload the configuration"), true);
}
return 1;
}));
dispatcher.register(literalargumentbuilder);
}
}

View File

@ -0,0 +1,24 @@
package party._2a03.mc.command;
import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText;
public class HatCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(CommandManager.literal("hat").executes(ctx -> {
ServerCommandSource source = ctx.getSource();
ServerPlayerEntity sender = source.getPlayer();
ItemStack mainhand = sender.getEquippedStack(EquipmentSlot.MAINHAND);
ItemStack head = sender.getEquippedStack(EquipmentSlot.HEAD);
sender.equipStack(EquipmentSlot.MAINHAND, head);
sender.equipStack(EquipmentSlot.HEAD, mainhand);
source.sendFeedback(new LiteralText("Swapped items between main hand and head"), false);
return 1;
}));
}
}

View File

@ -0,0 +1,35 @@
package party._2a03.mc.command;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.block.Blocks;
import net.minecraft.entity.ItemEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText;
public class HeadCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(CommandManager.literal("head").executes(ctx -> {
return giveHead(ctx.getSource(), ctx.getSource().getPlayer(), ctx.getSource().getName());
}).then(CommandManager.argument("username", StringArgumentType.greedyString()).executes(ctx -> {
return giveHead(ctx.getSource(), ctx.getSource().getPlayer(), StringArgumentType.getString(ctx, "username"));
})));
}
private static int giveHead(ServerCommandSource source, ServerPlayerEntity sender, String skullowner) {
ItemStack itemstack = new ItemStack(Blocks.PLAYER_HEAD.asItem());
CompoundTag compoundtag = new CompoundTag();
compoundtag.putString("SkullOwner", skullowner);
itemstack.setTag(compoundtag);
ItemEntity itementity = sender.dropItem(itemstack, false);
itementity.resetPickupDelay();
itementity.setOwner(sender.getUuid());
source.sendFeedback(new LiteralText("Player head has been given"), false);
return 1;
}
}

View File

@ -0,0 +1,68 @@
package party._2a03.mc.command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText;
import net.minecraft.world.dimension.DimensionType;
import party._2a03.mc.server.Config;
import party._2a03.mc.server.PlayerData;
import party._2a03.mc.server.PlayerPosition;
public class HomeCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = CommandManager.literal("home").executes(ctx -> {
ServerCommandSource source = ctx.getSource();
ServerPlayerEntity sender = source.getPlayer();
PlayerPosition position = Config.getPlayer(sender.getUuid().toString()).getHome();
if (position.dimensiontype == null) {
source.sendFeedback(new LiteralText("Home not found, do /home set"), false);
return -1;
}
sender.teleport(sender.getServer().getWorld(position.dimensiontype), position.x, position.y, position.z, position.yaw, position.pitch);
source.sendFeedback(new LiteralText("Teleported to home"), true);
return 1;
});
literalargumentbuilder.then(CommandManager.literal("set").executes(ctx -> {
ServerCommandSource source = ctx.getSource();
ServerPlayerEntity sender = source.getPlayer();
PlayerData playerdata = Config.getPlayer(sender.getUuid().toString());
double x = sender.getX();
double y = sender.getY();
double z = sender.getZ();
float yaw = sender.yaw;
float pitch = sender.pitch;
DimensionType dimensiontype = sender.getServerWorld().getDimension().getType();
PlayerPosition location = new PlayerPosition(x, y, z, yaw, pitch, dimensiontype);
playerdata.setHome(location);
Config.setPlayer(playerdata);
source.sendFeedback(new LiteralText("Your home has been updated"), true);
return 1;
}));
literalargumentbuilder.then(CommandManager.literal("sudoset").requires(ctx -> {
return ctx.hasPermissionLevel(2);
}).then(CommandManager.argument("UUID", StringArgumentType.word()).executes(ctx -> {
ServerCommandSource source = ctx.getSource();
ServerPlayerEntity sender = source.getPlayer();
PlayerData playerdata = Config.getPlayer(StringArgumentType.getString(ctx, "UUID"));
double x = sender.getX();
double y = sender.getY();
double z = sender.getZ();
float yaw = sender.yaw;
float pitch = sender.pitch;
DimensionType dimensiontype = sender.getServerWorld().getDimension().getType();
PlayerPosition location = new PlayerPosition(x, y, z, yaw, pitch, dimensiontype);
playerdata.setHome(location);
Config.setPlayer(playerdata);
source.sendFeedback(new LiteralText("User's home has been updated (" + StringArgumentType.getString(ctx, "UUID") + ")"), true);
return 1;
})));
dispatcher.register(literalargumentbuilder);
}
}

View File

@ -0,0 +1,51 @@
package party._2a03.mc.command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText;
import net.minecraft.world.dimension.DimensionType;
import party._2a03.mc.server.Config;
import party._2a03.mc.server.PlayerPosition;
public class SpawnCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = CommandManager.literal("spawn").executes(ctx -> {
ServerCommandSource source = ctx.getSource();
ServerPlayerEntity sender = source.getPlayer();
PlayerPosition position = new PlayerPosition(Config.getData("spawn"));
if (position.dimensiontype == null) {
if (source.hasPermissionLevel(2)) {
source.sendFeedback(new LiteralText("Spawn not found, do /spawn set"), false);
} else {
source.sendFeedback(new LiteralText("Spawn not found, ask an admin to set it"), false);
}
return -1;
}
sender.teleport(sender.getServer().getWorld(position.dimensiontype), position.x, position.y, position.z, position.yaw, position.pitch);
source.sendFeedback(new LiteralText("Teleported to the spawn point"), true);
return 1;
});
literalargumentbuilder.then(CommandManager.literal("set").requires(ctx -> {
return ctx.hasPermissionLevel(2);
}).executes(ctx -> {
ServerCommandSource source = ctx.getSource();
ServerPlayerEntity sender = source.getPlayer();
double x = sender.getX();
double y = sender.getY();
double z = sender.getZ();
float yaw = sender.yaw;
float pitch = sender.pitch;
DimensionType dimensiontype = sender.getServerWorld().getDimension().getType();
PlayerPosition location = new PlayerPosition(x, y, z, yaw, pitch, dimensiontype);
Config.setData("spawn", location.getJSON());
source.sendFeedback(new LiteralText("Spawn has been set"), true);
return 1;
}));
dispatcher.register(literalargumentbuilder);
}
}

View File

@ -0,0 +1,22 @@
package party._2a03.mc.mixin;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.command.GameModeCommand;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText;
import net.minecraft.world.GameMode;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(GameModeCommand.class)
public class MixinGameModeCommand {
@Inject(method = "setGameMode", at = @At("HEAD"))
private static void OnSetGameMode(ServerCommandSource source, ServerPlayerEntity player, GameMode gameMode, CallbackInfo ci) {
if (gameMode == GameMode.CREATIVE) {
source.sendFeedback(new LiteralText("<Server> Creative mode? What are you, a cheater?"), false);
}
return;
}
}

View File

@ -0,0 +1,23 @@
package party._2a03.mc.mixin;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.TntEntity;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
@Mixin(TntEntity.class)
public abstract class MixinTntEntity extends Entity {
public MixinTntEntity(EntityType<? extends TntEntity> entityType, World world) {
super(entityType, world);
}
/**
* @reason Disable TNT entity explosions.
* @author flewkey
*/
@Overwrite
private void explode() {
}
}

View File

@ -0,0 +1,86 @@
package party._2a03.mc.server;
import com.google.common.collect.Maps;
import java.io.File;
import java.io.FileWriter;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Map;
import org.json.JSONObject;
import org.json.JSONArray;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import party._2a03.mc.server.PlayerData;
import party._2a03.mc.server.PlayerPosition;
public class Config {
private static final Logger LOGGER = LogManager.getLogger();
private static JSONObject json;
public static void loadConfig() throws Exception {
LOGGER.info("Loading 2a03.party configuration");
File f = new File("2a03.json");
if (f.exists()) {
InputStream is = new FileInputStream("2a03.json");
String jsonRaw = IOUtils.toString(is, "UTF-8");
json = new JSONObject(jsonRaw);
} else {
LOGGER.info("Config not found, creating one");
json = new JSONObject("{\"spawn\":[0,0,0,0,0,-2],\"members\":[]}");
saveConfig();
}
LOGGER.info("Configuration loaded");
}
public static PlayerData getPlayer(String uuid) {
JSONArray members = json.getJSONArray("members");
PlayerPosition home = null;
for (int i = 0; i < members.length(); ++i) {
JSONObject item = members.getJSONObject(i);
String item_uuid = item.getString("uuid");
if (item_uuid.equals(uuid)) {
home = new PlayerPosition(item.getJSONArray("home"));
}
}
if (home == null) {
home = new PlayerPosition();
}
return new PlayerData(uuid, home);
}
public static void setPlayer(PlayerData player) {
JSONArray members = json.getJSONArray("members");
int playerIndex = -1;
for (int i = 0; i < members.length(); ++i) {
JSONObject item = members.getJSONObject(i);
String item_uuid = item.getString("uuid");
if (item_uuid.equals(player.getUUID())) {
playerIndex = i;
}
}
if (playerIndex >= 0) {
members.remove(playerIndex);
}
members.put(player.getJSON());
json.put("members", members);
saveConfig();
}
public static JSONArray getData(String key) {
return json.getJSONArray(key);
}
public static void setData(String key, JSONArray data) {
json.put(key, data);
saveConfig();
}
private static void saveConfig() {
try (FileWriter file = new FileWriter("2a03.json")) {
file.write(JSONObject.valueToString(json));
} catch (Exception e) {
System.out.println("Failed to save config file");
}
}
}

View File

@ -0,0 +1,34 @@
package party._2a03.mc.server;
import org.json.JSONArray;
import org.json.JSONObject;
import party._2a03.mc.server.PlayerPosition;
public class PlayerData {
private String uuid;
private PlayerPosition home;
public PlayerData(String p_uuid, PlayerPosition p_home) {
this.uuid = p_uuid;
this.home = p_home;
}
public PlayerPosition getHome() {
return this.home;
}
public String getUUID() {
return this.uuid;
}
public void setHome(PlayerPosition location) {
this.home = location;
}
public JSONObject getJSON() {
JSONObject json = new JSONObject();
json.put("uuid", uuid);
json.put("home", home.getJSON());
return json;
}
}

View File

@ -0,0 +1,58 @@
package party._2a03.mc.server;
import org.json.JSONArray;
import net.minecraft.world.dimension.DimensionType;
import party._2a03.mc.server.Config;
public class PlayerPosition {
public double x;
public double y;
public double z;
public float yaw;
public float pitch;
public DimensionType dimensiontype;
public PlayerPosition() {
}
public PlayerPosition(JSONArray data) {
int dimension_id = data.getInt(5);
if (dimension_id != -2) {
this.x = data.getDouble(0);
this.y = data.getDouble(1);
this.z = data.getDouble(2);
this.yaw = data.getFloat(3);
this.pitch = data.getFloat(4);
this.dimensiontype = DimensionType.byRawId(dimension_id);
}
}
public PlayerPosition(double p_x, double p_y, double p_z, float p_yaw, float p_pitch, DimensionType p_dimensiontype) {
this.x = p_x;
this.y = p_y;
this.z = p_z;
this.yaw = p_yaw;
this.pitch = p_pitch;
this.dimensiontype = p_dimensiontype;
}
public JSONArray getJSON() {
JSONArray json = new JSONArray();
if (this.dimensiontype != null) {
json.put(this.x);
json.put(this.y);
json.put(this.z);
json.put(this.yaw);
json.put(this.pitch);
json.put(this.dimensiontype.getRawId());
} else {
json.put(0);
json.put(0);
json.put(0);
json.put(0);
json.put(0);
json.put(-2);
}
return json;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -0,0 +1,30 @@
{
"schemaVersion": 1,
"id": "minecraft-tweaks-2a03",
"version": "1.0.0",
"name": "2a03.party Tweaks",
"description": "Simple modifications for the 2a03.party Minecraft server.",
"authors": [
"flewkey"
],
"contact": {
"homepage": "https://flewkey.com/",
"sources": "https://github.com/flewkey/minecraft-tweaks-2a03"
},
"license": "MIT",
"icon": "assets/2a03-minecraft-tweaks/icon.png",
"environment": "*",
"entrypoints": {
"main": [
"party._2a03.mc.MinecraftTweaks2a03"
]
},
"mixins": [
"minecraft-tweaks-2a03.mixins.json"
],
"depends": {
"fabricloader": ">=0.7.2",
"fabric": "*",
"minecraft": "1.15.x"
}
}

View File

@ -0,0 +1,12 @@
{
"required": true,
"package": "party._2a03.mc.mixin",
"compatibilityLevel": "JAVA_8",
"server": [
"MixinGameModeCommand",
"MixinTntEntity"
],
"injectors": {
"defaultRequire": 1
}
}