Skip to content

Commit

Permalink
Add teams command for enable/disable survival players being able to p…
Browse files Browse the repository at this point in the history
…lace vehicles.
  • Loading branch information
GoldSloth committed Apr 30, 2022
1 parent b353941 commit 7926714
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/flansmod/common/driveables/ItemPlane.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.flansmod.common.paintjob.IPaintableItem;
import com.flansmod.common.paintjob.PaintableType;
import com.flansmod.common.parts.PartType;
import com.flansmod.common.teams.TeamsManager;
import com.flansmod.common.types.EnumType;
import com.flansmod.common.types.InfoType;
import cpw.mods.fml.common.registry.GameRegistry;
Expand Down Expand Up @@ -111,6 +112,11 @@ public void addInformation(ItemStack stack, EntityPlayer player, List lines, boo

@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
if (!(TeamsManager.survivalCanPlaceVehicles || entityplayer.capabilities.isCreativeMode)) {
// player isn't allowed to place vehicles.
return itemstack;
}

//Raytracing
float cosYaw = MathHelper.cos(-entityplayer.rotationYaw * 0.01745329F - 3.141593F);
float sinYaw = MathHelper.sin(-entityplayer.rotationYaw * 0.01745329F - 3.141593F);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/flansmod/common/driveables/ItemVehicle.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Collections;
import java.util.List;

import com.flansmod.common.teams.TeamsManager;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.BlockSponge;
Expand Down Expand Up @@ -126,6 +127,10 @@ public void addInformation(ItemStack stack, EntityPlayer player, List lines, boo
@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
{
if (!(TeamsManager.survivalCanPlaceVehicles || entityplayer.capabilities.isCreativeMode)) {
// player isn't allowed to place vehicles.
return itemstack;
}
//Raytracing
float cosYaw = MathHelper.cos(-entityplayer.rotationYaw * 0.01745329F - 3.141593F);
float sinYaw = MathHelper.sin(-entityplayer.rotationYaw * 0.01745329F - 3.141593F);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Collections;
import java.util.List;

import com.flansmod.common.teams.TeamsManager;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
Expand Down Expand Up @@ -84,6 +85,10 @@ private NBTTagCompound getTagCompound(ItemStack stack, World world)
@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
{
if (!(TeamsManager.survivalCanPlaceVehicles || entityplayer.capabilities.isCreativeMode)) {
// player isn't allowed to place vehicles.
return itemstack;
}
//Raytracing
float cosYaw = MathHelper.cos(-entityplayer.rotationYaw * 0.01745329F - 3.141593F);
float sinYaw = MathHelper.sin(-entityplayer.rotationYaw * 0.01745329F - 3.141593F);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/flansmod/common/guns/ItemAAGun.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;

import com.flansmod.common.teams.TeamsManager;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
Expand Down Expand Up @@ -41,6 +42,11 @@ public ItemAAGun(AAGunType type1)
@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
{
if (!(TeamsManager.survivalCanPlaceVehicles || entityplayer.capabilities.isCreativeMode)) {
// player isn't allowed to place vehicles.
return itemstack;
}

//Raytracing
float cosYaw = MathHelper.cos(-entityplayer.rotationYaw * 0.01745329F - 3.141593F);
float sinYaw = MathHelper.sin(-entityplayer.rotationYaw * 0.01745329F - 3.141593F);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/flansmod/common/network/PacketTeamInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void encodeInto(ChannelHandlerContext ctx, ByteBuf data)
data.writeBoolean(TeamsManager.driveablesBreakBlocks);
data.writeBoolean(TeamsManager.allowVehicleZoom);
data.writeBoolean(TeamsManager.survivalCanBreakVehicles);
data.writeBoolean(TeamsManager.survivalCanPlaceVehicles);

if(TeamsManager.getInstance().currentRound == null)
{
Expand Down Expand Up @@ -189,6 +190,7 @@ public void decodeInto(ChannelHandlerContext ctx, ByteBuf data)
TeamsManager.driveablesBreakBlocks = data.readBoolean();
TeamsManager.allowVehicleZoom = data.readBoolean();
TeamsManager.survivalCanBreakVehicles = data.readBoolean();
TeamsManager.survivalCanPlaceVehicles = data.readBoolean();
gametype = readUTF(data);
if(gametype.equals("No Gametype"))
{
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/com/flansmod/common/teams/CommandTeams.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void processCommand(ICommandSender sender, String[] split) {
TeamsManager.overrideHunger = false;
TeamsManager.canBreakGuns = true;
TeamsManager.survivalCanBreakVehicles = true;
TeamsManager.survivalCanPlaceVehicles = true;
TeamsManager.canBreakGlass = true;
TeamsManager.armourDrops = true;
TeamsManager.weaponDrops = 1;
Expand All @@ -79,6 +80,7 @@ public void processCommand(ICommandSender sender, String[] split) {
TeamsManager.overrideHunger = true;
TeamsManager.canBreakGuns = true;
TeamsManager.survivalCanBreakVehicles = true;
TeamsManager.survivalCanPlaceVehicles = true;
TeamsManager.canBreakGlass = false;
TeamsManager.armourDrops = false;
TeamsManager.weaponDrops = 2;
Expand Down Expand Up @@ -479,6 +481,15 @@ public void processCommand(ICommandSender sender, String[] split) {
sender.addChatMessage(new ChatComponentText("Vehicles, Planes, Mechas, AAGuns can " + (TeamsManager.survivalCanBreakVehicles ? "now" : "no longer") + " be broken by players in survival"));
return;
}
if (split[0].equals("survivalCanPlaceVehicles")) {
if (split.length != 2) {
sender.addChatMessage(new ChatComponentText("Incorrect Usage : Should be /teams " + split[0] + " <true/false>"));
return;
}
TeamsManager.survivalCanPlaceVehicles = Boolean.parseBoolean(split[1]);
sender.addChatMessage(new ChatComponentText("Vehicles, Planes, Mechas, AAGuns can " + (TeamsManager.survivalCanPlaceVehicles ? "now" : "no longer") + " be placed by players in survival"));
return;
}
if (split[0].equals("armourDrops") || split[0].equals("armorDrops")) {
if (split.length != 2) {
sender.addChatMessage(new ChatComponentText("Incorrect Usage : Should be /teams " + split[0] + " <true/false>"));
Expand Down Expand Up @@ -719,6 +730,7 @@ public List addTabCompletionOptions(ICommandSender sender, String[] prm) {
"canBreakGuns",
"canBreakGlass",
"survivalCanBreakVehicles",
"survivalCanPlaceVehicles",
"armourDrops",
"weaponDrops",
"fuelNeeded",
Expand Down Expand Up @@ -803,7 +815,8 @@ private void sendHelpInformation(ICommandSender sender, int page) {
sender.addChatMessage(new ChatComponentText("/teams vehiclesCanZoom <true / false>"));
sender.addChatMessage(new ChatComponentText("/teams leaderboard"));
sender.addChatMessage(new ChatComponentText("/teams stats <nickname>"));

sender.addChatMessage(new ChatComponentText("/teams survivalCanBreakVehicles <true / false>"));
sender.addChatMessage(new ChatComponentText("/teams survivalCanPlaceVehicles <true / false>"));

break;
}
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/com/flansmod/common/teams/TeamsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class TeamsManager {
// Player changeable stuff
public static boolean voting = false, explosions = true, roundsGenerator = false, driveablesBreakBlocks = true,
bombsEnabled = true, shellsEnabled = true, bulletsEnabled = true, forceAdventureMode = true, canBreakGuns = true, canBreakGlass = true,
armourDrops = true, vehiclesNeedFuel = true, overrideHunger = true, survivalCanBreakVehicles = true;
armourDrops = true, vehiclesNeedFuel = true, overrideHunger = true, survivalCanBreakVehicles = true, survivalCanPlaceVehicles = true;

public static int weaponDrops = 1; //0 = no drops, 1 = drops, 2 = smart drops
//Life of certain entity types. 0 is eternal.
Expand Down Expand Up @@ -1125,6 +1125,12 @@ private void loadPerWorldData(Event event, World world) {
survivalCanBreakVehicles = true;
}

if (tags.hasKey("SurvivalCanPlaceVehicles")) {
survivalCanPlaceVehicles = tags.getBoolean("SurvivalCanPlaceVehicles");
} else {
survivalCanPlaceVehicles = true;
}

armourDrops = tags.getBoolean("ArmourDrops");
weaponDrops = tags.getInteger("WeaponDrops");
vehiclesNeedFuel = tags.getBoolean("NeedFuel");
Expand Down Expand Up @@ -1199,6 +1205,7 @@ private void savePerWorldData(Event event, World world) {
tags.setBoolean("CanBreakGuns", canBreakGuns);
tags.setBoolean("CanBreakGlass", canBreakGlass);
tags.setBoolean("SurvivalCanBreakVehicles", survivalCanBreakVehicles);
tags.setBoolean("SurvivalCanPlaceVehicles", survivalCanPlaceVehicles);
tags.setBoolean("ArmourDrops", armourDrops);
tags.setInteger("WeaponDrops", weaponDrops);
tags.setBoolean("NeedFuel", vehiclesNeedFuel);
Expand Down

0 comments on commit 7926714

Please sign in to comment.