Allow /spell command to work with multiple players
This commit is contained in:
parent
f40e44e366
commit
d2d33c6159
4
.gitignore
vendored
4
.gitignore
vendored
@ -22,4 +22,6 @@ bin/
|
|||||||
|
|
||||||
# fabric
|
# fabric
|
||||||
|
|
||||||
run/
|
run/
|
||||||
|
|
||||||
|
remappedSrc/
|
@ -1,5 +1,8 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
**1.2.2**
|
||||||
|
* Allow ```/spell``` command to work with multiple players
|
||||||
|
|
||||||
**1.2.1**
|
**1.2.1**
|
||||||
* Fix Launching Without ModMenu
|
* Fix Launching Without ModMenu
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ org.gradle.jvmargs = -Xmx1G
|
|||||||
fabric_loader_version = 0.7.8+build.189
|
fabric_loader_version = 0.7.8+build.189
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 1.2.1
|
mod_version = 1.2.2
|
||||||
maven_group = com.thebrokenrail
|
maven_group = com.thebrokenrail
|
||||||
archives_base_name = sorcerycraft
|
archives_base_name = sorcerycraft
|
||||||
|
|
||||||
|
@ -70,7 +70,9 @@ public class SorceryCraft implements ModInitializer {
|
|||||||
LootTables.JUNGLE_TEMPLE_CHEST,
|
LootTables.JUNGLE_TEMPLE_CHEST,
|
||||||
LootTables.STRONGHOLD_LIBRARY_CHEST,
|
LootTables.STRONGHOLD_LIBRARY_CHEST,
|
||||||
LootTables.PILLAGER_OUTPOST_CHEST,
|
LootTables.PILLAGER_OUTPOST_CHEST,
|
||||||
LootTables.WOODLAND_MANSION_CHEST
|
LootTables.WOODLAND_MANSION_CHEST,
|
||||||
|
LootTables.BURIED_TREASURE_CHEST,
|
||||||
|
LootTables.FISHING_TREASURE_GAMEPLAY
|
||||||
};
|
};
|
||||||
|
|
||||||
public static Identifier INTERACT_WITH_CASTING_TABLE_STAT;
|
public static Identifier INTERACT_WITH_CASTING_TABLE_STAT;
|
||||||
|
@ -13,10 +13,12 @@ import net.minecraft.entity.player.PlayerEntity;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.server.command.CommandManager;
|
import net.minecraft.server.command.CommandManager;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.text.Texts;
|
import net.minecraft.text.Texts;
|
||||||
import net.minecraft.text.TranslatableText;
|
import net.minecraft.text.TranslatableText;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -27,65 +29,75 @@ public class SpellCommand {
|
|||||||
dispatcher.register(CommandManager.literal("spell")
|
dispatcher.register(CommandManager.literal("spell")
|
||||||
.requires(source -> source.hasPermissionLevel(4))
|
.requires(source -> source.hasPermissionLevel(4))
|
||||||
.then(CommandManager.literal("list")
|
.then(CommandManager.literal("list")
|
||||||
.then(CommandManager.argument("player", EntityArgumentType.player())
|
.then(CommandManager.argument("player", EntityArgumentType.players())
|
||||||
.executes(ctx -> {
|
.executes(ctx -> {
|
||||||
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(ctx, "player");
|
||||||
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
for (PlayerEntity player : players) {
|
||||||
Map<Identifier, Integer> spellMap = spellPlayer.getDiscoveredSpells();
|
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
||||||
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.listing_spells", player.getDisplayName(), Texts.join(spellMap.entrySet(), spell -> SpellHelper.getTranslatedSpell(spell.getKey(), spell.getValue()))), false);
|
Map<Identifier, Integer> spellMap = spellPlayer.getDiscoveredSpells();
|
||||||
|
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.listing_spells", player.getDisplayName(), Texts.join(spellMap.entrySet(), spell -> SpellHelper.getTranslatedSpell(spell.getKey(), spell.getValue()))), false);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.then(CommandManager.literal("forget")
|
.then(CommandManager.literal("forget")
|
||||||
.then(CommandManager.argument("player", EntityArgumentType.player())
|
.then(CommandManager.argument("player", EntityArgumentType.players())
|
||||||
.executes(ctx -> {
|
.executes(ctx -> {
|
||||||
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(ctx, "player");
|
||||||
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
for (PlayerEntity player : players) {
|
||||||
Map<Identifier, Integer> spells = spellPlayer.getDiscoveredSpells();
|
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
||||||
for (Map.Entry<Identifier, Integer> entry : spells.entrySet()) {
|
Map<Identifier, Integer> spells = spellPlayer.getDiscoveredSpells();
|
||||||
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.forgotten_spell", player.getDisplayName(), SpellHelper.getTranslatedSpellChat(entry.getKey(), entry.getValue())), true);
|
for (Map.Entry<Identifier, Integer> entry : spells.entrySet()) {
|
||||||
|
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.forgotten_spell", player.getDisplayName(), SpellHelper.getTranslatedSpellChat(entry.getKey(), entry.getValue())), true);
|
||||||
|
}
|
||||||
|
spellPlayer.setDiscoveredSpells(new HashMap<>());
|
||||||
}
|
}
|
||||||
spellPlayer.setDiscoveredSpells(new HashMap<>());
|
|
||||||
return 1;
|
return 1;
|
||||||
})
|
})
|
||||||
.then(CommandManager.argument("spell", SpellArgumentType.spell())
|
.then(CommandManager.argument("spell", SpellArgumentType.spell())
|
||||||
.executes(ctx -> {
|
.executes(ctx -> {
|
||||||
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(ctx, "player");
|
||||||
Identifier spell = SpellArgumentType.getSpell(ctx, "spell");
|
for (PlayerEntity player : players) {
|
||||||
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
Identifier spell = SpellArgumentType.getSpell(ctx, "spell");
|
||||||
Map<Identifier, Integer> spells = spellPlayer.getDiscoveredSpells();
|
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
||||||
if (spells.containsKey(spell)) {
|
Map<Identifier, Integer> spells = spellPlayer.getDiscoveredSpells();
|
||||||
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.forgotten_spell", player.getDisplayName(), SpellHelper.getTranslatedSpellChat(spell, spells.get(spell))), true);
|
if (spells.containsKey(spell)) {
|
||||||
spells.remove(spell);
|
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.forgotten_spell", player.getDisplayName(), SpellHelper.getTranslatedSpellChat(spell, spells.get(spell))), true);
|
||||||
|
spells.remove(spell);
|
||||||
|
}
|
||||||
|
spellPlayer.setDiscoveredSpells(spells);
|
||||||
}
|
}
|
||||||
spellPlayer.setDiscoveredSpells(spells);
|
|
||||||
return 1;
|
return 1;
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.then(CommandManager.literal("discover")
|
.then(CommandManager.literal("discover")
|
||||||
.then(CommandManager.argument("player", EntityArgumentType.player())
|
.then(CommandManager.argument("player", EntityArgumentType.players())
|
||||||
.executes(ctx -> {
|
.executes(ctx -> {
|
||||||
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(ctx, "player");
|
||||||
Map<Identifier, Integer> spellMap = new HashMap<>();
|
for (PlayerEntity player : players) {
|
||||||
Spell[] maxSpells = SpellRegistry.getMaxSpells();
|
Map<Identifier, Integer> spellMap = new HashMap<>();
|
||||||
for (Spell spell : maxSpells) {
|
Spell[] maxSpells = SpellRegistry.getMaxSpells();
|
||||||
spellMap.put(spell.getID(), spell.getLevel());
|
for (Spell spell : maxSpells) {
|
||||||
|
spellMap.put(spell.getID(), spell.getLevel());
|
||||||
|
}
|
||||||
|
SpellHelper.learnSpells(player, spellMap);
|
||||||
}
|
}
|
||||||
SpellHelper.learnSpells(player, spellMap);
|
|
||||||
return 1;
|
return 1;
|
||||||
})
|
})
|
||||||
.then(CommandManager.argument("spell", SpellArgumentType.spell())
|
.then(CommandManager.argument("spell", SpellArgumentType.spell())
|
||||||
.then(CommandManager.argument("level", IntegerArgumentType.integer())
|
.then(CommandManager.argument("level", IntegerArgumentType.integer())
|
||||||
.executes(ctx -> {
|
.executes(ctx -> {
|
||||||
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(ctx, "player");
|
||||||
Identifier spell = SpellArgumentType.getSpell(ctx, "spell");
|
for (PlayerEntity player : players) {
|
||||||
int level = IntegerArgumentType.getInteger(ctx, "level") - 1;
|
Identifier spell = SpellArgumentType.getSpell(ctx, "spell");
|
||||||
Map<Identifier, Integer> spellMap = new HashMap<>();
|
int level = IntegerArgumentType.getInteger(ctx, "level") - 1;
|
||||||
spellMap.put(spell, level);
|
Map<Identifier, Integer> spellMap = new HashMap<>();
|
||||||
SpellHelper.learnSpells(player, spellMap);
|
spellMap.put(spell, level);
|
||||||
|
SpellHelper.learnSpells(player, spellMap);
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@ -93,25 +105,27 @@ public class SpellCommand {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
.then(CommandManager.literal("apply")
|
.then(CommandManager.literal("apply")
|
||||||
.then(CommandManager.argument("player", EntityArgumentType.player())
|
.then(CommandManager.argument("player", EntityArgumentType.players())
|
||||||
.then(CommandManager.argument("spell", SpellArgumentType.spell())
|
.then(CommandManager.argument("spell", SpellArgumentType.spell())
|
||||||
.then(CommandManager.argument("level", IntegerArgumentType.integer())
|
.then(CommandManager.argument("level", IntegerArgumentType.integer())
|
||||||
.executes(ctx -> {
|
.executes(ctx -> {
|
||||||
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(ctx, "player");
|
||||||
Identifier spell = SpellArgumentType.getSpell(ctx, "spell");
|
for (PlayerEntity player : players) {
|
||||||
int level = IntegerArgumentType.getInteger(ctx, "level") - 1;
|
Identifier spell = SpellArgumentType.getSpell(ctx, "spell");
|
||||||
|
int level = IntegerArgumentType.getInteger(ctx, "level") - 1;
|
||||||
|
|
||||||
ItemStack stack = player.getMainHandStack();
|
ItemStack stack = player.getMainHandStack();
|
||||||
|
|
||||||
if (stack.getItem() != SorceryCraft.SPELL_ITEM) {
|
if (stack.getItem() != SorceryCraft.SPELL_ITEM) {
|
||||||
throw NOT_HOLDING_SPELL_EXCEPTION.create(player);
|
throw NOT_HOLDING_SPELL_EXCEPTION.create(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Identifier, Integer> spellMap = SpellHelper.getSpells(stack);
|
||||||
|
spellMap.put(spell, level);
|
||||||
|
SpellHelper.setSpells(stack, spellMap);
|
||||||
|
|
||||||
|
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.applied_spell", SpellHelper.getTranslatedSpell(spell, level)), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<Identifier, Integer> spellMap = SpellHelper.getSpells(stack);
|
|
||||||
spellMap.put(spell, level);
|
|
||||||
SpellHelper.setSpells(stack, spellMap);
|
|
||||||
|
|
||||||
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.applied_spell", SpellHelper.getTranslatedSpell(spell, level)), true);
|
|
||||||
return 1;
|
return 1;
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@ -119,25 +133,26 @@ public class SpellCommand {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
.then(CommandManager.literal("remove")
|
.then(CommandManager.literal("remove")
|
||||||
.then(CommandManager.argument("player", EntityArgumentType.player())
|
.then(CommandManager.argument("player", EntityArgumentType.players())
|
||||||
.then(CommandManager.argument("spell", SpellArgumentType.spell())
|
.then(CommandManager.argument("spell", SpellArgumentType.spell())
|
||||||
.executes(ctx -> {
|
.executes(ctx -> {
|
||||||
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(ctx, "player");
|
||||||
Identifier spell = SpellArgumentType.getSpell(ctx, "spell");
|
for (PlayerEntity player : players) {
|
||||||
|
Identifier spell = SpellArgumentType.getSpell(ctx, "spell");
|
||||||
|
|
||||||
ItemStack stack = player.getMainHandStack();
|
ItemStack stack = player.getMainHandStack();
|
||||||
|
|
||||||
if (stack.getItem() != SorceryCraft.SPELL_ITEM) {
|
if (stack.getItem() != SorceryCraft.SPELL_ITEM) {
|
||||||
throw NOT_HOLDING_SPELL_EXCEPTION.create(player);
|
throw NOT_HOLDING_SPELL_EXCEPTION.create(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Identifier, Integer> spellMap = SpellHelper.getSpells(stack);
|
||||||
|
if (spellMap.containsKey(spell)) {
|
||||||
|
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.removed_spell", SpellHelper.getTranslatedSpell(spell, spellMap.get(spell))), true);
|
||||||
|
spellMap.remove(spell);
|
||||||
|
}
|
||||||
|
SpellHelper.setSpells(stack, spellMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<Identifier, Integer> spellMap = SpellHelper.getSpells(stack);
|
|
||||||
if (spellMap.containsKey(spell)) {
|
|
||||||
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.removed_spell", SpellHelper.getTranslatedSpell(spell, spellMap.get(spell))), true);
|
|
||||||
spellMap.remove(spell);
|
|
||||||
}
|
|
||||||
SpellHelper.setSpells(stack, spellMap);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
@ -47,6 +47,7 @@ public class SpellEntity extends ThrownItemEntity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCollision(HitResult hitResult) {
|
protected void onCollision(HitResult hitResult) {
|
||||||
|
super.onCollision(hitResult);
|
||||||
if (!getEntityWorld().isClient()) {
|
if (!getEntityWorld().isClient()) {
|
||||||
Map<Identifier, Integer> spells = SpellHelper.getSpells(getItem());
|
Map<Identifier, Integer> spells = SpellHelper.getSpells(getItem());
|
||||||
if (!spells.containsKey(Spells.INWARD_SPELL)) {
|
if (!spells.containsKey(Spells.INWARD_SPELL)) {
|
||||||
|
Reference in New Issue
Block a user